akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef int int__;
#define int long long
#define pb push_back
#define pi pair<int,int>
#define vpi vector<pi>
#define vi vector<int>
#define vvi vector<vi>
#define fi first
#define se second
#define forn(i, n)for(int i=0;i<int__(n);i++) 
#define sz(a)int__(a.size())
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a){return out << "(" << a.first << ", " << a.second << ")";}
template<class A>ostream& operator<<(ostream& out,const vector<A>&v){out<<"[";forn(i,sz(v)){if(i)out<<", ";out<<v[i];}return out<<"]";}
int mm;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
int Mod(int x){x%=mm;if(x<0)x+=mm;return x;}
int Pow(int x,int n){if(n==0)return 1;int t=Pow(x,n/2);t=Mod(t*t);if(n&1)t=Mod(t*x);return t;}
#define watch(x) cout << #x << " : " << x << endl;
int gcd(int a,int b){if(b==0)return a;return gcd(b,a%b);}
#define all(x) x.begin(), x.end()


int__ main() {
	fast;
	int n,p; cin >> n >> p;
	mm = p;
	string s; cin >> s;

	int ans = 0;

	if(p == 2 or p == 5) {
		for(int i=0;i<n;i++) {
			int x = s[i]-'0';
			if((p == 2 and x%2==0) or (p==5 and (x==0 or x==5))) ans += (i+1);
		}

		cout << ans << endl; return 0;
	}

	map<int,int> mp;
	mp[0] = 1;
	reverse(all(s));
	int r = 0;
	for(int i=0;i<n;i++) {
		int x = s[i]-'0';
		int dig = Mod(x * Pow(10,i));
		r = Mod(r + dig);

		ans += mp[r];
		mp[r]++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 1044
from math import ceil


def check(x):
    # 全てを長さx以下にするために必要な回数
    cnt = 0
    for a in A:
        # 切る回数は-1した回数。a=20 x=4 20/4=5 だが切る箇所は4。
        cnt += ceil(a/x)-1
    return cnt <= K


N, K = map(int, input().split())
A = list(map(int, input().split()))

left = 0
right = max(A)
while left < right-1:
    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid
print(right)


Measured memory_bytes: 30900
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int FindRoad( vector<vector<int> > &road, int x, int y);

int h,w;
int n;
int dummy = 0;
int result = 0;

int main(void)
{

  int x,y;

  vector<vector<int> > road( 18,vector<int>(18));

  cin >> w >> h;

  while(w != 0 && h != 0)
    {
      cin >> n;

      for(int i = 0; i < n; i++)
        {
          cin >> x >> y;
          road[x][y] = 1;
        }


      cout << FindRoad(road,1,1) << endl;

      for(int x = 0; x < 18; x++)
        {
          for(int y = 0; y < 18; y++)
            {
              if(road[x][y] == 1)  road[x][y] = 0;
            }
        }

      result = 0;

      cin >> w >> h;

    }


  return 0;
}

int FindRoad( vector<vector<int> > &road, int x, int y)
{

  if( (x - 1 == w || y - 1 == h) || road[x][y] == 1) return 0;
  if( x == w && y == h) result++;

  dummy = FindRoad( road, x, y + 1);
  dummy = FindRoad( road, x + 1, y);

  return result;

}

Measured memory_bytes: 1212
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<ll,ll> P;

int main(){
  int n;
  cin >> n;
  int x[n],y[n];
  rep(i,n)cin >> x[i] >> y[i];
  int mx1=-INF,mn1=INF,mx2=-INF,mn2=INF;
  rep(i,n){
    chmax(mx1,x[i]+y[i]);
    chmin(mn1,x[i]+y[i]);
    chmax(mx2,x[i]-y[i]);
    chmin(mn2,x[i]-y[i]);
  }
  cout << max(mx1-mn1,mx2-mn2) << endl;
}

Measured memory_bytes: 5168
#include <bits/stdc++.h>
using namespace std;

const int MOD = (int)1e9+7;

long long gcd(long long a,long long b){
  if(b==0)  return a;
  return gcd(b,a%b);
}

long long lcm(long long a,long long b){
  return a/gcd(a,b)*b;
}

int main(){
	int N;
	cin >> N;
	vector<long long> T(N);
	for(int i=0;i<N;i++)	cin >> T.at(i);

	long long ans=1;
	for(int i=0;i<N;i++){
		ans=lcm(ans,T.at(i));
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main(){
  char s[256];
  int count =0;
  scanf("%s",s);
  int length = strlen(s);    
  for(int i= 0;i<strlen(s);i++){
    if(s[i]!=s[length-i-1]){
      s[i]=s[length-i-1];
      count++;
    }
  }
    
  printf("%d\n",count);
  return 0;
}
  
 



Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
  
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef node* Node;
#define NIL NULL
 
node array[500000];
int size=0;
 
Node root = NIL;
  
Node treeMinimum(Node x){
  while(x->left!=NIL)x=x->left;
  return x;
}
  
Node treeSearch(Node u, int k){
  Node i=u;
  while(i!=NIL){
    if(i->key==k)return i;
    else if(i->key<k)i=i->right;
    else i=i->left;     
  }
  return NIL;
}
  
Node treeSuccessor(Node x){
  if(x->right!=NIL)return treeMinimum(x->right);
  Node y=x->parent;
  while(y!=NIL&&x==y->right){
    x=y;
    y=y->parent;
  }
  return y;
}
  
void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left==NIL||z->right==NIL)y=z;
  else y=treeSuccessor(z);
    
  if(y->left!=NIL)x=y->left;
  else x=y->right;
  
  if(x!=NIL)x->parent=y->parent;
    
  if(y->parent==NIL)root=x;
  else if(y==y->parent->left)y->parent->left=x;
  else y->parent->right=x;
  
  if(y!=z)z->key=y->key;
    
  //free(y);
}
  
void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = &array[size++];
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
  z->parent=y;
  if(y==NIL)root=z;
  else if(z->key<y->key)y->left=z;
  else y->right=z;   
}
 
 
void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
 
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
 
 
int main(){
  int n,x;
  char str[20];
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%s", str);
    if(str[0]=='f'){
      scanf("%d",&x);
      Node t=treeSearch(root,x);
      if (t!=NIL) printf("yes\n");
      else printf("no\n");
    }else if(str[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }else if(str[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }else if(str[0]=='d'){
      scanf("%d",&x);
      treeDelete(treeSearch(root,x));
    }
  }
 
  return 0;
}


Measured memory_bytes: 15184
#include<iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>
using namespace std;

void fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main()
{
	fast();

	int a, b, c, x,count=0;
	cin >> a >> b >> c >> x;
	for (int i = 0; i <= a; i++)
	{
		for (int j = 0; j <= b; j++)
		{
			for (int k = 0; k <= c; k++)
			{
				if ((i * 500 )+ (j * 100 )+( k * 50) == x)
					count++;
			}
		}
	}
	cout << count << endl;
}



Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  string S; cin >> S;
  string ans = "AC";

  if (S[0] != 'A') ans = "WA";

  ll cnt = 0;
  for (ll i = 2; i < S.size() - 1; i++) {
    if (S[i] == 'C') cnt++;
  }
  if (cnt != 1) ans = "WA";
  
  for (ll i = 1; i < S.size(); i++) {
    if (S[i] == 'C' || (S[i] >= 'a' && S[i <= 'z'])) continue;
    ans = "WA";
  }

  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 256
import operator
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

n, m = ril()
ls = ril()
ls2 = rils(m)
ls.sort()
ls2.sort(key=operator.itemgetter(1), reverse=True)
res = sum(ls)
index = 0
b, c = ls2[0]
for x in ls:
    if x < c:
        res += c - x
        b -= 1
        if b == 0:
            index += 1
            if index < m:
                b, c = ls2[index]
            else:
                c = -1
print(res)

Measured memory_bytes: 32932
#include<stdio.h>
#define N 100

int arr[N],m[N][N];

int min(int x,int y)
{
  if(x<0) return y;
  else if( y < 0 ) return x;
  else if( x < y ) return x;
  else return y;
  
}

int main()
{
  int i,j,k,l,n,res;
  scanf("%d",&n);
  for(i = 0; i <= n; i++) scanf("%d %d",&arr[i],&arr[i+1]);

  for(i = 1; i <= n; i++) m[i][i] = 0;

  for(l = 1; l <= n; l++)
    {
        for(i = 1; i <= n - l; i++)
	        {
	            j = i + l;
	            m[i][j] = -1;
	    for(k = i; k < j; k++)
	        {
	            m[i][j] = min(m[i][j],m[i][k] + m[k+1][j] + arr[i-1]*arr[k]*arr[j]);
	        }
	    }
    }
  printf("%d\n",m[1][n]);
  
  return 0;
}


Measured memory_bytes: 2112
using System;
class Program
    {
     
        static void Main(string[] args)
            {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);
            int N1=N*(N-1)/2;//関数呼び出し
            int M1 =M*(M-1)/2;
            int ans = N1 + M1;
            Console.WriteLine(ans);
            Console.ReadLine();



            }
        }

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  int p = 1, count = 0;
  for(int i = 0; i < n; i++){
    if(a[i] == p){
      p++;
      count++;
    }
  }
  cout << (count == 0 ? -1 : n - count) << endl;
}

Measured memory_bytes: 4048
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use itertools::Itertools;
use proconio::*;
use text_io::*;

const U_INF: usize = 1 << 60;
const I_INF: isize = 1 << 60;

fn main() {
    let n: usize = read!();
    
    let mut ans = U_INF;
    for i in 1..n{
        ans = (ans).min(calc(i) + calc(n - i));
    }
    
    println!("{}", ans);
}

fn calc(mut n: usize) -> usize {
    let mut ans = 0;

    while n != 0 {
        ans += n % 10;
        n /= 10;
    }

    ans
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;

struct block{
    double xr;
    double xl;
    double g;
    set<int> chil;
};


int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
int w,h;
int inde=1;

bool isrange(int i,int j){ 
    return 0<=i && i<h && 0<=j && j<w;
}

void draw(int i,int j,char x,vector<string> &f,vector<vector<int>> &c){
    f[i][j]='.';
    c[i][j]=inde;
    for(int dir=0;dir<4;dir++){
        int toi=i+dx[dir];
        int toj=j+dy[dir];        
        if(isrange(toi,toj) && f[toi][toj]==x){
            draw(toi,toj,x,f,c);
        }
    }
    return;
}

vector<block> bs;
pair<double,double> gggg(int x){
            double gg=bs[x].g;
            double wei=4;
            for(auto b:bs[x].chil){
                auto ret=gggg(b);
                gg=(ret.first*ret.second+wei*gg)/(wei+ret.first);
                wei+=ret.first;
            }
            return make_pair(wei,gg);
}

int main(){
    
    while(cin>>w>>h,w){
        vector<string> f(h);
        
        for(int i=0;i<h;i++) cin>>f[i];
        
        vector<vector<int>> c(h,vector<int>(w,0));
        inde=1;        
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(isdigit(f[i][j])){
                    draw(i,j,f[i][j],f,c);
                    inde++;
                }
            }
        }
        bs.clear();
        bs.resize(inde);
        for(int i=0;i<inde;i++){
            bs[i].xl=400000;
            bs[i].xr=0;
            bs[i].g=0;
        }
        for(int i=0;i<h;i++){
            for(int j=0;j<w;j++){
                if(c[i][j]!=0){
                    
                    bs[c[i][j]].g+=j;
                    for(int dir=0;dir<2;dir++){
                        int toi=i+dx[dir];
                        int toj=j;
                        if(isrange(toi,toj)&&c[toi][toj]!=0 && c[toi][toj]!=c[i][j]){
                            if(dir==0){
                                bs[c[i][j]].xl=min<double>(bs[c[i][j]].xl,j);
                                bs[c[i][j]].xr=max<double>(bs[c[i][j]].xr,j);
                            }
                            else{
                                
                                bs[c[i][j]].chil.insert(c[toi][toj]);
                            }
                        }
                        else if(!isrange(toi,toj) && dir==0){
                            bs[c[i][j]].xl=min<double>(bs[c[i][j]].xl,j);
                            bs[c[i][j]].xr=max<double>(bs[c[i][j]].xr,j);
                        }
                    }
                }
            }
        }
        for(int i=0;i<inde;i++) {
            bs[i].g/=4;

            bs[i].xl-=0.5;
            bs[i].xr+=0.5;
        }

        

        bool isok=true;
        for(int i=1;i<inde;i++){
                            auto ret=gggg(i);
            isok&=(bs[i].xl<ret.second && ret.second<bs[i].xr);
        }
        cout<<(isok ? "STABLE" : "UNSTABLE")<<endl;
}   

    return 0;
}   

Measured memory_bytes: 3076
s=input()
n=len(s)
ans=''

for bit in range(1<<(n-1)):
    f=int(s[0])
    g=s[0]
    for i in range(n-1):
        if bit&(1<<i):
            f+=int(s[i+1])
            g+='+'+s[i+1]
        else:
            f-=int(s[i+1])
            g+='-'+s[i+1]
    if f==7:
        ans=g
    
print(ans+'=7')

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string in;
pair<pair<string, int>, int> p[110];
int main(){
  int a;
  cin >> a;
  for (int i = 0; i < a; i++)
  {
    int t;
    cin >> in >> t;
    string tmp = in;
    p[i] = make_pair(make_pair(in, -t), i);
  }
  std::sort(p,p+a);
  for(int i=0;i<a;i++)
    cout << p[i].second + 1 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  ll n;
  cin>> n ;
  cout<<2*n/gcd11(2,n)<<endl;  
}

Measured memory_bytes: 256
a  = [s.split() for s in open(0)][0][0]
if len(a) % 2 != 0:
    a_half = a[:int((len(a) - 1)/2)]
    a_q = a[int((len(a) + 3) / 2) - 1:len(a) + 1]
    
    if a == a[::-1] and a_half == a_half[::-1] and a_q == a_q[::-1]:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
int GCD(int a,int b){return b?GCD(b,a%b):a;}
int LCM(int a,int b){return (a*b)/GCD(a,b);}
int abs(int x){return x>0?x:-x;}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	int a[n];
	ll b[n+1];
	b[0] = 0;
	ll ans = 0;
	REP(i, n) cin >> a[i];
	FOR(i, 1, n+1){
		b[i] = b[i-1] + a[i-1];
	}

	ll cnt = 0;
	sort(b, b+n+1);
	REP(i, n){
		if (b[i] == b[i+1]) cnt++;
		else {
			ans += cnt * (cnt+1) / 2;
			cnt = 0;
		}
	}
	ans += cnt * (cnt+1) / 2;

	cout << ans << endl;

}


Measured memory_bytes: 2560
#include<iostream>
using namespace std;

int main() {
	int a, b; cin >> a >> b; a--; b--;
	cout << "100 100" << endl;

	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 100; j++) {
			if (a > 0 && i % 2 == 0 && j % 2 == 1) { cout << '.'; a--; }
			else cout << '#';
		}
		cout << endl;
	}
	for (int i = 0; i < 50; i++) {
		for (int j = 0; j < 100; j++) {
			if (b > 0 && i % 2 == 1 && j % 2 == 1) { cout << '#'; b--; }
			else cout << '.';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

const int MOD = 1e9+7;

int main(){
    int N,M;cin >> N >> M;
    if(N==M){
        ll ord = 1;
        FOR(i,1,N+1){
            ord = (ord*i)%MOD;
        }
        cout << (2*ord*ord)%MOD << endl;
    }
    else if(abs(N-M)==1){
        ll dord = 1,mord = 1;
        FOR(i,1,N+1){
            dord = (dord*i)%MOD;
        }
        FOR(i,1,M+1){
            mord = (mord*i)%MOD;
        }
        cout << (dord*mord)%MOD << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
    char s[1001], t[1001];

    scanf("%s %s", s, t);

    int max = 0;
    for(int i = 0; i < strlen(s) - strlen(t) + 1; ++i){
        int cnt = 0;
        for(int j = 0; j < strlen(t); ++j){
            if(s[i+j] == t[j]) cnt++;
        }
        if(max < cnt) max = cnt;
    }

    printf("%d\n", (int)strlen(t) - max);

    return 0;
}


Measured memory_bytes: 1708
from scipy.sparse.csgraph import dijkstra as di

n,m,l = map(int, input().split())

inf = float('INF')
road = [[0 for i in range(n)] for j in range(n)]
for i in range(m):
    a,b,c = map(int, input().split())
    a -= 1
    b -= 1
    road[a][b] = road[b][a] = c

def warshall(d, n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][k] + d[k][j] < d[i][j]:
                    d[i][j] = d[i][k] + d[k][j]

roads = di(road, n)
# [print(cost) for cost in road]
# print()
costs = [[1 if roads[i][j] <= l and i != j else 0 for j in range(n)] for i in range(n)]
costs = di(costs, n)

# [print(cost) for cost in costs]
q = int(input())
for i in range(q):
    s,t = map(int, input().split())
    
    print(int(costs[s-1][t-1]-1) if costs[s-1][t-1] < inf else -1)


Measured memory_bytes: 19676
import java.io.InputStream;
import java.io.IOException;
import java.util.NoSuchElementException;

public class Main {
    public static void main(String[] args) {
        final MyScanner sc = new MyScanner();
        final char[] sArray = sc.next().toCharArray();
        final char[] tArray = sc.next().toCharArray();

        int counter = 0;
        for (int i = 0; i < sArray.length; i++) {
            if (sArray[i] != tArray[i]) {
                counter++;
            }
        }

        System.out.println(counter);
    }
}

class MyScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int pointer = 0;
    private int bufLength = 0;

    private boolean hasNextByte() {
        if (pointer < bufLength) {
            return true;
        } else {
            pointer = 0;
            try {
                bufLength = in.read(buffer);
            } catch (final IOException e) {
                e.printStackTrace();
            }
            if (bufLength <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[pointer++];
        } else {
            return -1;
        }
    }

    private static boolean isNumberChar(final int c) {
        return '0' <= c && c <= '9';
    }

    private static boolean isPrintableChar(final int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[pointer])) {
            pointer++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        final StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long num = 0;
        boolean isNegative = false;
        int b = readByte();
        if (b == '-') {
            isNegative = true;
            b = readByte();
        }
        if (!isNumberChar(b)) {
            throw new NumberFormatException();
        }
        while (true) {
            if (isNumberChar(b)) {
                num *= 10;
                num += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return isNegative ? -num : num;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        final long temp = nextLong();
        if (temp < Integer.MIN_VALUE || Integer.MAX_VALUE < temp) {
            throw new NumberFormatException();
        }
        return (int) temp;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 36288
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
//typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int main()
{
	int a,b; cin>>a>>b; cout<<a*b;

    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin>>n;
  vector<ll> a(n);
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(all(a), greater<ll>());
  ll ans=a[0];
  int i=1;
  while(i<(n/2))
    ans+=2*a[i], i++;
  if(n%2)
    ans+=a[i];
  cout<<ans<<"\n";
  return 0;
}

Measured memory_bytes: 4772
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
T = input()
if S == T:
	print("Yes")
	exit()

for i in range(1, len(S)):
	if S[i:]+S[0:i] == T :
		print("Yes")
		break
else:
	print("No")

Measured memory_bytes: 5148
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n; cin>>n;
    vector<int> array(n);
    rep(i,n)cin>>array[i];
    ll ans = INF;
    for(int i= 1; i<101; ++i){
        ll sum = 0;
        rep(j,n){
            sum += (array[j]-i)*(array[j]-i);
        }
        ans = min(ans,sum);
    }
    cout<< ans <<endl; 
}

Measured memory_bytes: 256
import sys
l = sys.stdin.readlines()
n, m = l[0].split()

from_1, to_n = set(), set()
for a, b in (l[i].split() for i in range(1, int(m)+1)):
    if a == '1': from_1.add(b)
    elif b == n: to_n.add(a)

print("POSSIBLE" if from_1 & to_n else "IMPOSSIBLE")


Measured memory_bytes: 37232
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  string S;
  cin >> S;
  int ans = 0;
  rep(i, S.size()){
    if(S[i] == '+') ans++;
    else ans--;
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;

int main()
{
    int N, D;

    cin >> N >> D;

    vector<vector<int>> X;

    X.resize(N);
    for(int i=0; i<N; i++)
    {
        X[i].resize(D);
        for(int j=0; j<D; j++)
        {
            cin >> X[i][j];
        }
    }

    int count = 0;

    for(int i=0; i<N; i++)
    {
        for(int j=i+1; j<N; j++)
        {
            if(i != j)
            {
                double d = 0.0;
                for(int k=0; k<D; k++)
                {
                    d += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
                }

                d = sqrt(d);

                if(abs(d - (int)d) > 0.0)
                {

                }
                else
                {
                    count++;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long lli;
typedef pair<int,int> pii;

int n;
pii arr[1<<18][2];
int main() {
	scanf("%d",&n);
	for(int i=0;i<1<<n;i++) {
		scanf("%d",&arr[i][0].first);
		arr[i][0].second=i;
	}

	int ans=0;
	for(int i=1;i<1<<n;i++) {
		pii m1(0,0),m2(0,0);
		for(int j=0;j<n;j++) if(i>>j&1) {
			int s=i^(1<<j);
			for(int j=0;j<2;j++) {
				if(m1<arr[s][j]) {
					m2=m1;m1=arr[s][j];
				} else if(m1!=arr[s][j] && m2<arr[s][j]) {
					m2=arr[s][j];
				}
			}
		}

		ans=max(ans,max(m1.first+arr[i][0].first,m1.first+m2.first));
		printf("%d\n",ans);

		if(m1>arr[i][0]) {
			if(m2>arr[i][0]) arr[i][0]=m1,arr[i][1]=m2;
			else arr[i][1]=arr[i][0],arr[i][0]=m1;
		} else arr[i][1]=m1;
	}
	
	return 0;
}


Measured memory_bytes: 7040
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1000

int N,num_query;
queue<int> Q[NUM];

int main(){

	scanf("%d %d",&N,&num_query);

	int command,A,B;

	for(int loop = 0; loop < num_query; loop++){

		scanf("%d",&command);

		switch(command){
		case 0:

			scanf("%d %d",&A,&B);
			Q[A].push(B);
			break;

		case 1:

			scanf("%d",&A);
			if(!Q[A].empty()){
				printf("%d\n",Q[A].front());
			}
			break;

		case 2:

			scanf("%d",&A);
			if(!Q[A].empty()){
				Q[A].pop();
			}
			break;
		}
	}
	return 0;
}




Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>

using namespace std;

int main() {
    int a, b, c;
    cin >>a >> b >> c;
    
    cout << ((a - b) > c ? 0 : c - (a - b)) << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
using namespace std;
typedef long long ll;

int A[200001];
map<int, int> D;

int main(){
  int N;
  cin >> N;
  rep(i, N-1) cin >> A[i];
  rep(i, N-1) D[A[i]]++;
  rep(i, N) cout << D[i+1] << endl;
}


Measured memory_bytes: 13756
#include <bits/stdc++.h>
using namespace std;
long long int mod = 998244353;
typedef long long int lli;
typedef pair<lli,lli> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

//############################ENDOFTEMPLATE############################



void solve(){
  int n,W;
  cin>>n>>W;

  vi v(n),w(n);
  int max_val = 0;
  lli max_cost = 0;
  for(int i = 0;i<n;i++){
    cin>>w[i]>>v[i];
    max_val+=v[i];
    max_cost+=w[i];
  }

  vector<vlli> dp(n,vlli(max_val+1,max_cost));

  dp[0][0] = 0;
  dp[0][v[0]] = w[0];

  for(int i = 1;i<n;i++){
    for(int j = 0;j<=max_val;j++){
      if(j-v[i]>=0)
        dp[i][j]  = min(dp[i-1][j],dp[i-1][j-v[i]]+w[i]);
      else
        dp[i][j] = dp[i-1][j];
    }
  }

  lli ans = 0;
  for(int i = 0;i<n;i++){
    for(int j = 0;j<=max_val;j++){
      if(dp[i][j]<=W)
        ans = max(ans,j);
    }
  }

  cout<<ans;

}


int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("input_custom.txt","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 82276
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll n;cin>>n;
    ll arr[n];
    map<ll,ll>right;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        right[i-arr[i]]++;
    }
    ll cnt=0;
    for(int i=0;i<n;i++){
        cnt+=right[i+arr[i]];
        right[i-arr[i]]--;
    }
    cout<<cnt<<"\n";
}




Measured memory_bytes: 27760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int A = Integer.parseInt(sc.next());
		sc.close();

		int check = N % 500;
		if(A >= check) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 23764
/* Simplicity and Goodness */

#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>

// using namespace __gnu_pbds;
using namespace std;
// typedef tree<int, null_type, less<int>, rb_tree_tag,
//             tree_order_statistics_node_update> indexed_set;

void my_dbg() { cout << endl; }
template<typename Arg, typename... Args> void my_dbg(Arg A, Args... B)
{ cout << ' ' << A; my_dbg(B...); }
#define dbg(...)  cout << "(" << #__VA_ARGS__ << "):", my_dbg(__VA_ARGS__)

#define scn(n) scanf("%d", &n)
#define lscn(n) scanf("%lld", &n)
#define pri(n) printf("%d ", (int)(n))
#define prin(n) printf("%d\n", (int)(n))
#define lpri(n) printf("%lld ", n)
#define lprin(n) printf("%lld\n", n)
#define rep(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

const int inf = INT_MAX;
const int ninf = INT_MIN;
const int mod = 1e9+7;
const int N = 2e5+2;

/* N - mx = x
 * N = x * (m+1), where m >=2 and m <= N-1
*/
void solve()
{
    ll n;
    lscn(n);

    ll sum = 0;

    for(ll i=1; i*i<=n; i++) {
        if(n % i == 0) {
            ll here = i;
            if(here >= 3) {
                ll remainder = n % (here - 1);
                ll quotient = n / (here - 1);

                if(remainder == quotient)
                    sum += here - 1;
            }
            here = n / i;
            if(here >= 3 and here != i) {
                ll remainder = n % (here - 1);
                ll quotient = n / (here - 1);

                if(remainder == quotient)
                    sum += here - 1;
            }
        }
    }

    lprin(sum);
}

int main()
{
    int t = 1;
    // scn(t);
    
    while(t --) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3788
import kotlin.*
import kotlin.math.*

fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val n = sc.nextInt()
        val dir = "URDL"

        val p = Array(n) { Triple(sc.nextLong(), sc.nextLong(), dir.indexOf(sc.nextChar())) }

        fun ud(): Long {
            // u 0
            // d 2
            var result = Long.MAX_VALUE
            val map = mutableMapOf<Long, Long>()
            p.forEach {
                if (it.third == 0) map[it.first] = it.second
                else if (it.third == 2 && map.containsKey(it.first)) result = min(result, (it.second - map[it.first]!!) * 5)
            }
            return result
        }

        fun ur(): Long {
            // u = 0
            // r = 1
            var result = Long.MAX_VALUE
            val map = mutableMapOf<Long, Long>()
            p.forEach {
                if (it.third == 0) map[it.first + it.second] = it.second
                else if (it.third == 1 && map.containsKey(it.first + it.second)) result = min(result, (it.second - map[it.first + it.second]!!) * 10)
            }
            return result
        }

        var ans = Long.MAX_VALUE
        for (t in 1..4) {
            for (i in 0 until n) {
                p[i] = Triple(p[i].second, -p[i].first, (p[i].third + 1) % 4)
            }
            p.sortBy { it.second }
            if (t <= 2) ans = min(ans, ud())
            ans = min(ans, ur())
        }

        println(if (ans == Long.MAX_VALUE) "SAFE" else ans.toString())
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


Measured memory_bytes: 112320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n, m;
    cin >> n >> m;

    vector<int> a(n);
    int sum = 0;
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    double st = sum/4.0/m;
    int num = 0;
    rep(i, n) {
        if (a[i]>=st) num++;
    }
    if (num>=m) cout << "Yes" << endl;
    else cout << "No" << endl;
    
 
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template <int MD>
struct ModInt {
    typedef ModInt M;
    int v;
    ModInt(int _v = 0) : v(_v) {}
    M& operator += (const M &r) {
        if ((v += r.v) >= MD) v -= MD;
        return *this;
    }
    M& operator -= (const M &r) {
        if ((v -= r.v) < 0) v += MD;
        return *this;
    }
    M& operator *= (const M &r) {
        v = ll(v) * r.v % MD;
        return *this;
    }
    M operator + (const M &r) const { return M(*this) += r; }
    M operator - (const M &r) const { return M(*this) -= r; }
    M operator * (const M &r) const { return M(*this) *= r; }
    M pow(int n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
};
typedef ModInt<1000000007> Mint;

const int MN = 1000010;
int N;
Mint fac[MN], ifac[MN];
Mint f[MN];

void first() {
    fac[0] = 1;
    for (int i = 1; i < MN; i++) {
        fac[i] = Mint(i) * fac[i - 1];
    }
    ifac[MN - 1] = fac[MN - 1].pow(1000000005);
    for (int i = MN - 2; i >= 0; i--) {
        ifac[i] = ifac[i + 1] * Mint(i + 1);
    }
}

Mint C(int n, int k) {
    if (n < 0 || k < 0 || n < k) return Mint(0);
    return fac[n] * ifac[k] * ifac[n - k];
}

Mint g(int k) {
    return C(k - 1, N - k - 1) * fac[k] * fac[N - 1 - k];
}

int main() {
    first();
    cin >> N;
    Mint ans = 0;
    for (int k = 1; k < N; k++) {
        ans += (g(k) - g(k - 1)) * k;
    }
    cout << ans.v << endl;
    return 0;
}

Measured memory_bytes: 11904
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint cnt(26,1e9);
    REP(i,N){
        string s; cin>>s;
        REP(j,26){
            cnt[j]=min(cnt[j],(int)count(ALL(s),'a'+j));
        }
    }
    string ans;
    REP(i,26){
        REP(j,cnt[i]) ans+='a'+i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
char cheese[1002][1002];
bool done[1002][1002];


int main(){
	int n,w,h;
	while(cin >> n , n){
		int dp[501][501] = {0};
		cin >> w >> h;
		rep(i,n){
			int x,y;cin >> x >> y;
			dp[y][x] = 1;
		}
		int s,t; cin >> s >> t;
		rep(i,h){
			rep(j,w){
				dp[i+1][j+1] = max(dp[i+1][j+1],dp[i+1][j+1]+dp[i+1][j]);
			}
		}
		rep(j,w){
			rep(i,h){
				dp[i+1][j+1] += dp[i][j+1];
			}
		}
		int ret = 0;
		rep(i,h-t+2){
			if(i==0)continue;
			rep(j,w-s+2){
				if(j==0)continue;
				int x1 = j ,   y1 = i;
				int x2 = j+s-1, y2 = i+t-1;
				int sum = dp[y2][x2] - dp[y2][x1-1] - dp[y1-1][x2] + dp[y1-1][x1-1];
				ret = max(ret,sum);
			}
		}
		cout << ret << endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#define rep(i, n)	for(int i = 0; i < (n); i++)
using namespace std;

int main(){
	/*input*/
	int a, b, c, d;	cin >> a >> b >> c >> d;
	/*calculation*/
	int l = a + b, r = c + d;
	/*output*/
	if(l < r)cout << "Right" << endl;
	else if(l == r) cout << "Balanced" << endl; 
	else cout << "Left" << endl;
}


Measured memory_bytes: 256
def move_dice(d, dir):
    if(dir == 'N'):
        d[0], d[1], d[4], d[5] = d[1], d[5], d[0], d[4]
    if(dir == 'S'):
        d[0], d[1], d[4], d[5] = d[4], d[0], d[5], d[1]
    if(dir == 'E'):
        d[0], d[2], d[3], d[5] = d[3], d[0], d[5], d[2]
    if(dir == 'W'):
        d[0], d[2], d[3], d[5] = d[2], d[5], d[0], d[3]

def rotate_right_dice(d):
    d[1], d[2], d[3], d[4] = d[3], d[1], d[4], d[2]

def to_up_dice(d, num):
    num_index = d.index(num)
    if(num_index==2 or num_index==3):
        move_dice(d, 'E')
    while(d[0] != num):
        move_dice(d, 'N')

def to_front_dice(d, num):
    while(d[1] != num):
        rotate_right_dice(d)

dice = list(map(int, input().split()))
q = int(input())
for _ in range(q):
    up, front = map(int, input().split())
    to_up_dice(dice, up)
    to_front_dice(dice, front)
    print(dice[2])

Measured memory_bytes: 7780
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);

        double n = (double) (s.nextInt());
        double probability;

        probability = n % 2 == 0 ? (n / (2 * n)) : (Math.floor(n / 2) + 1) / n;

        System.out.println(probability);
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<ll,ll> P;


int main(){
	
	int n,a,b;cin >> n >> a >> b;
	cout << min(a,b) << " " << max(0,a + b - n) << endl;
	
	return 0;
}


Measured memory_bytes: 256
<?php
$k = (int)trim(fgets(STDIN));

$list = [];
$sum = 0;
for ($i=1; $i <= $k; $i++) { 
	for ($j=1; $j <= $k; $j++) { 
		$tmp = gcd($i, $j);
		for ($m=1; $m <= $k; $m++) { 
			$sum += gcd($tmp, $m);
		}
	}
}
echo $sum;


// 最大公約数（ユークリッドの互除法）
function gcd($n1, $n2){
	$large = max($n1, $n2);
	$small = min($n1, $n2);
	if ($small === 1) {
		return 1;
	}
	while($small !== 0){
		$tmp_n = $small;
		$small = $large % $small;
		$large = $tmp_n;
	}
	return $large;
}

Measured memory_bytes: 16300
N = int(input())
S = input()
assert len(S) == N

# leftB[i] == S[:i]中の'#'の個数
leftB = [0] * (N + 1)
for i in range(1, N + 1):
    leftB[i] = leftB[i - 1] + (1 if S[i - 1] == '#' else 0)

# rightW[i] == S[i:]中の'.'の個数
rightW = [0] * (N + 1)
for i in range(N - 1, -1, -1):
    rightW[i] = rightW[i + 1] + (1 if S[i] == '.' else 0)

# bはS[:i]を'.'にするコスト. wはS[i:]を'#' にするコスト
m = min(b + w for b, w in zip(leftB, rightW))
print(m)

Measured memory_bytes: 21096
class Union_Find():
    def __init__(self,n):
        self.n=n
        self.par=[-1]*n
    def root(self,x):
        if self.par[x]<0:
            return x
        else:
            self.par[x]=self.root(self.par[x])
            return self.par[x]
    def union(self,x,y):
        rx=self.root(x)
        ry=self.root(y)
        if rx==ry:
            return
        if self.par[rx]>self.par[ry]:
            rx,ry=ry,rx
        self.par[rx]+=self.par[ry]
        self.par[ry]=rx

    def size(self,x):
        return -self.par[self.root(x)]

    def same(self,x,y):
        return self.root(x)==self.root(y)
N,M,K=map(int,input().split())
deg=[0]*N
bro=[[]*N for _ in range(N)]
uf=Union_Find(N)
for i in range(M):
    a,b=map(int,input().split())
    a-=1
    b-=1
    deg[a]+=1
    deg[b]+=1
    uf.union(a,b)
for j in range(K):
    a,b=map(int,input().split())
    a-=1
    b-=1
    bro[a].append(b)
    bro[b].append(a)

for q in range(N):
    ans=uf.size(q)-deg[q]-1
    for w in bro[q]:
        if uf.same(q,w):
            ans-=1
    print(ans,end=" ")

Measured memory_bytes: 26272
import sys
a = [int(i) for i in input().split()]
N = a[0]
K = a[1]

if K == 1:
    print(0)
    sys.exit()


def resZ(i, K):
    return abs(i - K)

ab = resZ(N, K)
# print(ab)
if N < ab:
    print(N)
    # print('end')
    sys.exit()

N = N % K
while True:
    ab = resZ(N, K)
    # print(ab)
    if N < ab:
        print(N)
        # print('end')
        sys.exit()

    N = ab
# def


Measured memory_bytes: 3064
using System;
namespace q1
{
    class q2
    {
        static void Main()
        {
            string a = Console.ReadLine();
            string b = Console.ReadLine();
            b = b.Remove(b.Length -1);
            if (a==b)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 25740
#include<iostream>
#include<ios>
#include<algorithm>
using namespace std;
int a[5];
main()
{
	while(~scanf("%d,%d,%d,%d,%d",a,a+1,a+2,a+3,a+4))
	{
		sort(a,a+5);
		if(a[1]==a[4]||a[0]==a[3])cout<<"four card"<<endl;
		else if(a[0]==a[1]&&a[2]==a[4]||a[0]==a[2]&&a[3]==a[4])cout<<"full house"<<endl;
		else if((a[0]+1==a[1]||a[0]+9==a[1])&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4])
			cout<<"straight"<<endl;
		else if(a[0]==a[2]||a[1]==a[3]||a[2]==a[4])cout<<"three card"<<endl;
		else if(a[0]==a[1]&&(a[2]==a[3]||a[3]==a[4])||a[1]==a[2]&&a[3]==a[4])cout<<"two pair"<<endl;
		else if(a[0]==a[1]||a[1]==a[2]||a[2]==a[3]||a[3]==a[4])cout<<"one pair"<<endl;
		else cout<<"null"<<endl;
	}
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin>>N;
    vector<int64_t> L(N+1);
    L.at(0)=2ll, L.at(1)=1ll;
    for(int i=2;i<=N;i++){
        L.at(i)=L.at(i-1)+L.at(i-2);
    }
    cout<<L.at(N)<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){

int N, K, i, ans = 1 ;    /*N, K  < 10*/

scanf("%d %d", &N, &K);

for(i = 0; i < N; i++){
	if(ans < K)
		ans *= 2;		
	else
   		ans += K;
}

printf("%d", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main(){
    int T[4][3][10] = {0};
    
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        a--; b--; c--;
        T[a][b][c] += d;
    }
    
    for(int j = 0; j < 4; j++){
        for(int k = 0; k < 3; k++){
            for(int l = 0; l < 10; l++){
                cout << ' ' << T[j][k][l];
                if(l == 9) cout << endl;
            }
        }
        if(j != 3 ) cout << "####################" << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int row[300010], col[300010];
map<pair<int, int>, bool> ma;
int Mr[300010], Mc[300010];
int main() {
  int h, w, m, maxrow = 0, maxcol = 0;
  cin >> h >> w >> m;

  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    ma[{x, y}] = 1;
    row[x]++;
    col[y]++;
    maxrow = max(maxrow, row[x]);
    maxcol = max(maxcol, col[y]);
  }
  for (int i = 1; i <= h; i++) if (row[i] == maxrow) Mr[++Mr[0]] = i;
  for (int i = 1; i <= w; i++) if (col[i] == maxcol) Mc[++Mc[0]] = i;
  int ans = maxrow + maxcol;
  for (int i = 1; i <= Mr[0]; i++) for (int j = 1; j <= Mc[0]; j++) {
    if (ma[{Mr[i], Mc[j]}] == 0) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << --ans << endl;
  return 0;
}

Measured memory_bytes: 27064
import numpy as np
n, m, c = map(int, input().split())
B = np.array([list(map(int, input().split()))])
count = 0
for i in range(n):
  ab = np.array([list(map(int, input().split()))])
  if int(np.dot(ab, B.T)) + c > 0:
    count += 1
print(count)

Measured memory_bytes: 12500
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

use std::cmp;

fn main() {
    let n = get!(usize);
    let aa = get!(String).split_whitespace().map(|i| i.parse::<i64>().unwrap()).collect::<Vec<_>>();
    let mut ll = vec![0; n];
    ll[0] = aa[0];
    let mut rr = vec![0; n];
    rr[n-1] = aa[n-1];
    for i in 1..n {
        ll[i] = ll[i-1] + aa[i];
        let j = n - i - 1;
        rr[j] = rr[j+1] + aa[j];
    }
    let mut r = i64::max_value();
    for i in 0..n-1 {
        r = cmp::min(r, (ll[i] - rr[i+1]).abs());
    }
    println!("{}", r);
}

Measured memory_bytes: 13044