akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
    
    static final int MAX = (int)1e9+1;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());
        
        int[][] dist = new int[n][n];
        for(int[] tmp : dist){
            Arrays.fill(tmp, MAX);
        }
        for(int i=0; i<n; i++){
            dist[i][i] = 0;
        }
        
        for(int i=0; i<m; i++){
            int a = Integer.parseInt(sc.next())-1;
            int b = Integer.parseInt(sc.next())-1;
            int c = Integer.parseInt(sc.next());
            dist[a][b] = c;
            dist[b][a] = c;
        }
        
        for(int k=0; k<n; k++){
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    int sum = dist[i][k]+dist[k][j];
                    if(dist[i][j] > sum){
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }
        
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(dist[i][j] <= l){
                    dist[i][j] = 1;
                }else{
                    dist[i][j] = MAX;
                }
            }
        }
        
        for(int k=0; k<n; k++){
            for(int i=0; i<n; i++){
                for(int j=0; j<n; j++){
                    int sum = dist[i][k]+dist[k][j];
                    if(dist[i][j] > sum){
                        dist[i][j] = dist[i][k] + dist[k][j];
                    }
                }
            }
        }
        
        int q = Integer.parseInt(sc.next());
        for(int i=0; i<q; i++){
            int s = Integer.parseInt(sc.next())-1;
            int t = Integer.parseInt(sc.next())-1;
            if(dist[s][t] != MAX){
                System.out.println(dist[s][t]-1);
            }else{
                System.out.println(-1);
            }
        }
        
    }
}



Measured memory_bytes: 63268
class BIT:
    def __init__(self,N):
        self.N=N
        self.bit=[0]*N
    def add(self,a,w):
        x=a
        while(x<self.N):
            self.bit[x]+=w
            x|=x+1
    def get(self,a):
        ret,x=0,a-1
        while(x>=0):
            ret+=self.bit[x]
            x=(x&(x+1))-1
        return ret
    def cum(self,l,r):
        return self.get(r)-self.get(l) 

def check(k):
    li=[]
    for i in range(N):
        li.append(1 if A[i]<=k else 0)

    c=[0]*(N+1)
    for i in range(N):
        c[i+1]=c[i]+li[i]
        
    d=[]
    for i in range(N+1):
        d.append(2*c[i]-i)
        
    S=sorted(set(d))
    dic={}
    for i,x in enumerate(S):
        dic[x]=i
    
    bit=BIT(N+1)
    res=0
    for i in range(N+1):
        bit.add(dic[d[i]],1)
        res+=bit.get(dic[d[i]])
    
    if res>M:
        return True
    else:
        return False

N=int(input())
A=list(map(int,input().split()))
M=N*(N+1)//4
l,r=-1,max(A)+1
while(r-l>1):
    k=(l+r)//2
    if check(k):
        r=k
    else:
        l=k

print(r)

Measured memory_bytes: 245656
loop do
  m = gets.to_i
  break if m == 0
  pat = []
  minpx = 9999999
  minpy = 9999999
  m.times do
    po = gets.split.map(&:to_i)
    if minpx > po[0]
      minpx = po[0]
      minpy = po[1]
    end
    pat << po
  end
  pat = pat.map { |pos| [ pos[0] - minpx, pos[1] - minpy ] }
  pat.delete [0, 0] # ?????????0, 0???
  n = gets.to_i
  pht = []
  n.times { pht << gets.split.map(&:to_i) }

  memo =
  pht.each do |(x, y)|
    flag = true
    pat.each do |(dx, dy)|
      unless pht.find { |pos| pos == [x + dx, y + dy] }
        flag = false
        break
      end
    end

    if flag
      puts "#{x - minpx} #{y - minpy}"
      break
    end
  end

end

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

int mat[1005][1005];
int step[1005][1005];
bool visited[1005][1005];

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            char c;
            cin >> c;
            if(c == '#'){
                mat[i][j] = 1;
                visited[i][j] = true;
            }else{
                mat[i][j] = 0;
            }
        }
    }

    queue<pair<pair<int, int>, int>> q;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            if(mat[i][j] == 1){
                if(i > 0 && !visited[i-1][j]){
                    visited[i-1][j] = true;
                    q.push({{i-1, j}, 1});
                }
                if(i < n - 1 && !visited[i+1][j]){
                    visited[i+1][j] = true;
                    q.push({{i+1, j}, 1});
                }
                if(j > 0 && !visited[i][j-1]){
                    visited[i][j-1] = true;
                    q.push({{i, j-1}, 1});
                }
                if(j < m - 1 && !visited[i][j+1]){
                    visited[i][j+1] = true;
                    q.push({{i, j+1}, 1});
                }
            }
        }
    }

    while(!q.empty()){
        int x = q.front().first.first;
        int y = q.front().first.second;
        int cs = q.front().second;
        q.pop();

        step[x][y] = cs;

        if(x > 0 && !visited[x-1][y]){
            visited[x-1][y] = true;
            q.push({{x-1, y}, cs + 1});
        }
        if(x < n - 1 && !visited[x+1][y]){
            visited[x+1][y] = true;
            q.push({{x+1, y}, cs + 1});
        }
        if(y > 0 && !visited[x][y-1]){
            visited[x][y-1] = true;
            q.push({{x, y-1}, cs + 1});
        }
        if(y < m - 1 && !visited[x][y+1]){
            visited[x][y+1] = true;
            q.push({{x, y+1}, cs + 1});
        }
    }

    int mx = 0;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < m; ++j){
            mx = max(mx, step[i][j]);
        }
    }

    cout << mx << "\n";
    return 0;
}


Measured memory_bytes: 15104
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<list>
#include<set>
using namespace std;
#define fr first
#define sc second
#define INFTY 1000000
typedef pair< int,int > iiP;
typedef pair< int,iiP > P;
int main(){
  int K,sum;
  while(cin >> K,K){
    sum = 0;
    for(int i=0,v;i<(K*(K-1)/2);i++){
      cin >> v;
      sum += v;
    }
    cout << sum / (K-1) << endl;
  }
}

Measured memory_bytes: 1160
package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main() { 
    var input []string
    
    sc := bufio.NewScanner(os.Stdin)
    for sc.Scan() {
        input = append(input, sc.Text())
    }
    
    N, _ := strconv.Atoi(input[0])
    A, _ := strconv.Atoi(input[1])
    
    if N%500 <= A {
        fmt.Println("Yes")
    } else {
        fmt.Println("No")                                                                          
    }
}

Measured memory_bytes: 640
n = int(input())
A = list(map(int, input().split()))

q = int(input())
M = list(map(int, input().split()))


def solve(index, value):
  if value == 0:
    return True
  if index > n - 1:
    return False
  return solve(index + 1, value) or solve(index + 1, value - A[index])

for m in M:
  if sum(A) < m:
    print("no")
  else:
    print("yes" if solve(0, m) else "no")


Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

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

    ll n, m;
    cin >> n >> m;
    vll a(n, -1);
    ll s, c;
    REP(i, m) {
        cin >> s >> c;
        s--;
        if (a[s] != c && a[s] != -1) {
            cout << -1 << endl;
            return 0;
        }
        if (s == 0 && c == 0) {
            if (n != 1) {
                cout << -1 << endl;
                return 0;
            }
        }
        a[s] = c;
    }
    if (n == 1 && a[0] == -1) {
        cout << 0 << endl;
        return 0;
    }
    REP(i, n) {
        if (a[i] == -1) {
            if (i == 0) a[i] = 1;
            else a[i] = 0;
        }
        cout << a[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApplication1
{

    class Program
    {

        static void Main(string[] args)
        {


            string str = Console.ReadLine();

            string alf = "abcdefghijklmnopqrstuvwxyz";

            bool[] f = new bool[alf.Length];

            for(int i = 0; i < str.Length; i++)
            {
                f[alf.IndexOf(str[i])] = true;
            }

            for(int i = 0; i < alf.Length; i++)
            {
                if (!f[i])
                {
                    Console.WriteLine(alf[i]);
                    break;
                }
                if(i == alf.Length - 1)
                {
                    Console.WriteLine("None");
                }
            }


        }
    }
}


Measured memory_bytes: 11232
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
int c[105];
int main()
{
	int N,T,cnt=0,c1,t1;
	scanf("%d%d",&N,&T);
	for(int i=0;i<N;++i)
	{
		scanf("%d%d",&c1,&t1);
		if(t1<=T)
		c[cnt++]=c1;
	}
	if(cnt==0) printf("TLE");
	else
	{
		int min=c[0];
		for(c1=1;c1<cnt;++c1)
		{
			if(min>c[c1])
			min=c[c1];
		}
		printf("%d",min);
	}
	return 0;
}

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

int main() {
    ll n, m, acNum, waNum, qNum;
    string res;
    cin >> n >> m;
    map<int, string> mp;
    //map<int, int> waNum;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        mp[i] = "no";
    }
    for(int i = 0;i < n; i++){
        p[i] = 0;
    }
    acNum = 0;
    waNum = 0;
    for(int i = 0; i < m; i++){
        cin >> qNum >> res;
        if(mp[qNum-1] == "AC"){
            continue;
        }else{
            if(res == "AC"){
                acNum++;
                mp[qNum-1] = "AC";
            }else{
                p[qNum-1]++;
            }
        }
    }
    for(int i = 0; i < n; i++){
        if(mp[i] == "AC")waNum += p[i];
    }
    cout << acNum << " " << waNum << endl;
    return 0;
}

Measured memory_bytes: 11520
#!/usr/bin/python
i = input()
n = map(int, raw_input().split())
cnt=0

for i in xrange(len(n)):
    min = i
#    flag = False
    flag = 0
    for j in xrange(i, len(n)):
        if n[j] < n[min]:
            min=j
#            flag = True
            flag = 1
    n[i],n[min] = n[min],n[i]
    cnt+=flag

print ' '.join(map(str,n))
print cnt

Measured memory_bytes: 4224
n,m = map(int,input().split())
a = [list(map(int,input().split())) for _ in range(n)]

a.sort()
now = m
ans = 0
for i in range(n):
    ans += a[i][0] * min(now,a[i][1])
    now -= a[i][1]
    if now <= 0:
        break
print(ans)

Measured memory_bytes: 27756
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)



int main(){
    int x,a;
    cin>>x>>a;
    cout<<(x<a?0: 10)<<endl;
}

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

int main(){

        int S,h,m,s;
        int r,x;

        cin >> S;

        h=S/3600;
        x=S%3600;

        m=x/60;
        s=x%60;

        cout << h << ":" << m << ":" <<s<<endl;



        return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<stdlib.h>
#define LARGE 100000
#define INF 2000000000
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int id_to_heapid[LARGE];
int V,E;

typedef struct list{
	int id;
	int cost;
	struct list *next;
}list;

typedef struct node{
	int id;
	int cost;
}node;

void swap(node N[],int a,int b){/*a,bはheap番号*/
	node temp=N[a];
	N[a]=N[b];
	N[b]=temp;
	
	int TEMP=id_to_heapid[N[a].id];
	id_to_heapid[N[a].id]=id_to_heapid[N[b].id];
	id_to_heapid[N[b].id]=TEMP;
	
	return;
}

void Make_AdjList(list* L[],int s,int t,int d){
	list *new=malloc(sizeof(list));
	list **p=&L[s];
	/*card作成*/
	new->id=t;	new->cost=d;  new->next=NULL;
	
	while((*p)!=NULL)p=&((*p)->next);
	(*p)=new;
	
	return;
}


void down_to_heap(node N[],int last){
	int i=0;
	while(i<last){
		
		if(i*2+1 > last && i*2+2 >last)break;/*子なし*/
		
		else if(i*2+1==last){/*子1つ*/
			if(N[i].cost > N[i*2+1].cost){
				swap(N,i,i*2+1);
				i=last;
			}
			else break;;
		}
		
		else if(i*2+1 <= last && i*2+2 <= last){/*子2つ*/
			if(N[i*2+1].cost <= N[i*2+2].cost && N[i*2+1].cost < N[i].cost){
				swap(N,i,i*2+1);
				i=i*2+1;
			}
			
			else if(N[i*2+1].cost > N[i*2+2].cost && N[i*2+2].cost < N[i].cost){
				swap(N,i,i*2+2);
				i=i*2+2;
			}
			
			else break;
		}
		
	}
	
	return;
	
}

void up_to_heap(node N[],int i){
	
	while(i>0){
		if(i%2==0){
			if(N[i/2-1].cost > N[i].cost){
				swap(N,i/2-1,i);
				i=i/2-1;
			}
			else break;
		}
		else {
			if(N[i/2].cost > N[i].cost){
				swap(N,i/2,i);
				i=i/2;
			}
			else break;
		}
	}
	
	return;
}


int Dijkstra(list* L[],node N[],int num){
	int u=N[0].id;
	list *p=L[u];
	
	swap(N,0,num-1);
	num--;
	down_to_heap(N,num-1);
	
	while(p!=NULL){
		if(N[ id_to_heapid[p->id] ].cost > N[ id_to_heapid[u] ].cost+(p->cost)){
			N[ id_to_heapid[p->id] ].cost=N[id_to_heapid[u] ].cost+(p->cost);
			up_to_heap(N,id_to_heapid[p->id]);
		}
		p=p->next;
	}
	
	return num;
	
}


int main(){
	int i,j;
	int s,t,d;
	int num,start;
	list *L[LARGE];
	node N[LARGE];
	
	scanf("%d %d %d",&V,&E,&start);
	num=V;
	
	for(i=0;i<V;i++){
		L[i]=NULL;
		N[i].id=i;
		N[i].cost=INF;
		id_to_heapid[i]=i;
	}
	N[id_to_heapid[start]].cost=0;
	swap(N,0,id_to_heapid[start]);
	
	for(i=0;i<E;i++){
		scanf("%d %d %d",&s,&t,&d);
		Make_AdjList(L,s,t,d);
	}
	
	while(num>0){
		num=Dijkstra(L,N,num);
	}
	
	for(i=0;i<V;i++){
		if(N[id_to_heapid[i]].cost==INF)printf("INF\n");
		else printf("%d\n",N[id_to_heapid[i]].cost);
	}
	
	return 0;
	
}


Measured memory_bytes: 19072
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
  int x1,x2,y1,y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x = x2-x1,y = y2-y1;
  cout << x2-y << " " << y2+x << " " <<  x1-y << " " << y1+x << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long

#define y second
#define pi pair <int, int>
#define pii pair <pi, pi>
#define vi vector <int>
#define int long long
const ll mod = 1e9 + 7;
ll n, n1;
int s[18];

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n;
    if(n==1) rc(1);
    int i=0;
    for(i=0; pow(10, i)<=n; i++);
    if(n==pow(10, i-1)) rc(9*i-9);
    i--;
    int mx=0;
    n1=n;
    int j=1;
    while(n1){
        s[j]=s[j-1]+n1%10;
        j++;
        n1/=10;
    }
    for(int k=0; k<=i; k++){
        mx=max(mx, s[i+1]-s[k]-1+9*k);
    }
    cout<<max(mx, max(s[i+1], 9*i));
}


Measured memory_bytes: 512
def is_odd(n):
    return(n<40)

a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())

m=[a, b, c, d, e]
k=filter(is_odd, m)
t=list(k)
f=len(t)

def is_odd(x):
    return(x>=40)
s=filter(is_odd, m)
l=list(s)
print((sum(l)+f*40)//5)


Measured memory_bytes: 5596
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	c1, c2 := ReadString(), ReadString()

	if reverse(c1) == c2 && c1 == reverse(c2) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func reverse(s string) string {
	t := []byte(s)
	t[0], t[2] = t[2], t[0]
	return string(t)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1840
N = int(input())

A = [0]
A.extend(map(int, raw_input().strip().split(' ')))

B = [0]
B.extend(map(int, raw_input().strip().split(' ')))

for i in range(0,N):
	A[i+1] += A[i]
	B[i+1] += B[i]

ans = 0
for i in range(0,N):
	ans = max(ans, A[i+1] - A[0] + B[N] - B[i])
print ans

Measured memory_bytes: 2692
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
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 main(){
    int a, b;
    cin >> a >> b;
    if((a+b) % 2 == 1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    cout << (a + b) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

ll N, K, A[500];

bool check(ll n) {
    ll r[500];
    REP(i, N) r[i] = A[i] % n;
    sort(r, r + N);
    ll s1 = 0, s2 = 0;
    REP(i, N) s2 += n - r[i];
    REP(i, N) {
        s1 += r[i];
        s2 -= n - r[i];
        if (s1 == s2 && s1 <= K) return true;
    }
    return false;
}

vector<int> factors(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            ret.push_back(n / i);
        }
    }
    sort(ALL(ret), greater<int>());
    return ret;
}

int main() {
    ll sum = 0;
    cin >> N >> K;
    REP(i, N) {
        cin >> A[i];
        sum += A[i];
    }

    vector<int> fs = factors(sum);
    for (int f : fs) {
        if (check(f)) {
            cout << f << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define vi vector<int>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool a)
{
    if (a == true)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main()
{
    int n;
    cin >> n;
    double x;
    string u;
    double ys = 0, bs = 0;
    rep(i, 0, n)
    {
        cin >> x >> u;
        if (u == "JPY")
            ys += x;
        else
            bs += x;
    }
    ys += bs * 380000;
    cout << ys << endl;
}


Measured memory_bytes: 256
while True:
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for j in range(W):
            if j == 0 or j == W-1 or i == 0 or i == H-1:
                print('#',end = '')
            else:
                print('.',end = '')
        print()
    
    print()


Measured memory_bytes: 7004
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto nmxy = readints;
    int x = nmxy[2], y = nmxy[3];
    auto xs = readints;
    auto ys = readints;

    int xmax = (xs ~ [x]).reduce!((a, b) => max(a, b));
    int ymin = (ys ~ [y]).reduce!((a, b) => min(a, b));
    writeln(xmax < ymin ? "No War" : "War");
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h , w;
    cin >> h >> w;
    string board[h];
    rep(i,h) cin >> board[i];
    int num[h][w];
    rep(i,h)rep(j,w) num[i][j] = 0;
    deque<PII> que;
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(board[i][j] == '#'){
                rep(dir,4){
                    int ny = i + dy[dir];
                    int nx = j + dx[dir];
                    if(nx >= 0 && ny >= 0 && nx < w && ny < h && num[ny][nx] == 0 && board[ny][nx] != '#'){
                        num[ny][nx] = 1;
                        ans = 1;
                        que.push_back(make_pair(ny,nx));
                    }
                }
            }
        }
    }

    while(que.empty() == false){
        PII current = que.front();
        que.pop_front();
        rep(dir,4){
            int ny = current.first + dy[dir];
            int nx = current.second + dx[dir];
            if(nx >= 0 && ny >= 0 && nx < w && ny < h && num[ny][nx] == 0 && board[ny][nx] != '#'){
                num[ny][nx] = num[current.first][current.second] + 1;
                ans = max(num[ny][nx],ans);
                que.push_back(make_pair(ny,nx));
            }
        }
    }

    // rep(i,h){
    //     rep(j,w){
    //         cout << num[i][j] ;
    //     }
    //     cout << endl;
    // }
    cout << ans << endl;
    return 0;
}


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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

vector<ll> fac(300001); 
vector<ll> ifac(300001); 

ll mpow(ll x, ll n){ //x^
    ll ans = 1;
    while(n != 0){
        if(n&1) ans = ans*x % MOD;
        x = x*x % MOD;
        n = n >> 1;
    }
    return ans;
}

ll comb(ll a, ll b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    ll tmp = ifac[a-b]* ifac[b] % MOD;
    return tmp * fac[a] % MOD;
}

void init()
{
    fac[0] = 1;
    ifac[0] = 1;
    for(ll i = 0; i<300000; i++){
        fac[i+1] = fac[i]*(i+1) % MOD; // n!(mod M)
        ifac[i+1] = ifac[i]*mpow(i+1, MOD-2) % MOD; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}

int main(int argc, char **argv)
{
	ll N, K; cin >> N >> K;

	ll res{0};
	ll R = N - K;
	ll B = R + 1;
	init();
	for (ll i = 1; i <= K; ++i)
	{
		std::cout << (comb(B, i) * comb(K-1, i-1))%MOD  << std::endl;
	}
}


Measured memory_bytes: 4992
import java.util.Arrays;
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt(), m = sc.nextInt();
        int req[][] = new int[m][2];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt(), b = sc.nextInt();
            req[i][0] = a;
            req[i][1] = b;
        }
        Arrays.sort(req, (a, b) -> {
            if (a[0] > b[0]) {
                return 1;
            }
            if (a[0] == b[0] && a[1] > b[1]) {
                return 1;
            } else {
                return -1;
            }
        });
        int count = 1;
        int start = req[0][0], end = req[0][1];
        for (int i = 1; i < m; i++) {
            start = Math.max(start, req[i][0]);
            end = Math.min(end, req[i][1]);
            if (end <= start) {
                count++;
                start = req[i][0];
                end = req[i][1];
            }
        }
        System.out.println(count);

    }
}


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

long long A[100005];

int main()
{
    int N;
    long long x;
    cin >> N >> x;

    for(int i=1; i<=N; i++)
        cin >> A[i];

    long long ans = 0;

    for(int i=1; i<=N; i++)
    {
        if(A[i]+A[i-1]>x)
        {
            ans += ((A[i]+A[i-1])-x);
            A[i] -= ((A[i]+A[i-1])-x);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << "\n";
#define debug_v(x) cerr << #x << " ="; for(auto in : x) {cerr << " [" << in << "]";} cerr << '\n';
using namespace std;
using ll = long long;
using ld = long double;
const double PI = acos(-1);
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 1e18 + 100;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(20);
	ll a, b;
	cin >> a >> b;
	ll tiv1 = (a * a - b * b);
	ll tiv2 = (2 * a - 2 * b);
	if(tiv1 % tiv2 != 0){
		cout << "IMPOSSIBLE\n";
		return 0;
	}
	cout << (a * a - b * b) / (2 * a - 2 * b) << '\n';
	return 0;
}


Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    auto a = readln.split.to!(int[]).sort();

    writeln(a.any!"!(a & 1)" ? 0L : 1L * a[0] * a[1]);
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

#define pb emplace_back
#define fi first
#define se second
#define m_p make_pair
#define vi vector<int>
#define pi pair<int, int>
#define mem(a,b) memset(a,b,sizeof(a))
#define el cout<<endl
#define sz(a) (int)a.size()
const int mod = (int)1e9+7;
typedef long long int ll;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
const int N = (int)1e5+5;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int a,b;
	cin>>a>>b;
	cout<<max(a+b, max(a-b, a*b));el;
}

ll power(ll a,ll b, ll md=mod){
	ll r=1;
	while(b){
		if(b%2) 
			r=(r*a)%md;
		a=(a*a)%md;
		b>>=1;
	}
	return r;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, s, e) for (int i = (int)(s); i < (int)(e); i++)
#define _rep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define _REP(i, e, s) for (int i = (int)(e - 1); i >= (int)(s); i--)

#define yes cout << "yes" << endl;
#define Yes cout << "Yes" << endl;
#define YES cout << "YES" << endl;

#define no cout << "no" << endl;
#define No cout << "No" << endl;
#define NO cout << "NO" << endl;

#define AC cout << "AC" << endl;
#define WA cout << "WA" << endl;

#define out(s) cout << s << endl;

#define ll long long
#define ull unsigned long long
#define vi vector<int>

const double PI = 3.14159265358979323846;

int main() {
    int N, v, cnt, sum = 0;
    cin >> N;
    REP(i, 1, N + 1) {
        v = i;
        cnt = 0;
        while (v > 0) {
            v /= 10;
            cnt++;
        }
        if (cnt % 2 == 1) {
            sum++;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,m;cin>>n>>m;
    if (n==m) {
        cout << "Yes" << '\n';
    }
    else cout << "No" << '\n';
    return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

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

#define mem(dp,a)           memset(dp,a,sizeof dp)
#define rep(i,a,b)          for(ll i=a;i<b;i++)
#define pb(x)               push_back(x)
#define mp(x,y)             make_pair(x,y)
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
#define F                   first
#define S                   second
#define all(v)              (v).begin(),(v).end()
#define pi					3.14159265359
ll INF=1e18+10;
ll MOD=1000000007;

const ll siz=1<<(12);
ll dp[siz];

int main()
{
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	fastio;
    ll n,m;cin>>n>>m;
    rep(i,0,siz)dp[i]=INF;

    rep(i,0,m)
    {
        ll a,b;cin>>a>>b;
        ll cur=0;
        rep(j,0,b)
        {
            ll k;cin>>k;k--;
            cur=cur|(1<<k);
        }
        dp[cur]=min(a,dp[cur]);
        rep(j,0,siz)
            if(dp[j]!=INF)
            dp[j|cur]=min(dp[j|cur],dp[j]+dp[cur]);
    }
    ll ans=dp[(1<<n)-1];
    if(ans!=INF)
        cout<<ans;
    else
        cout<<-1;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) cout << (x) << endl;
#define ENDL cout << endl;
using namespace std;
using namespace boost::multiprecision;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

template <class T> inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;}
template <class T> inline bool chmax(T& a, T b){if(a<b){a=b; return true;} return false;}
struct Init_On{
    Init_On(){
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(16);
    }
};

u64 pow1018(){
    u64 ret = 1;
    for(int i = 0 ; i < 18 ; ++i){
        ret *= 10;
    }
    return ret;
}

signed main(){
    int n;
    cin >> n;
    vector<int128_t> a(n);
    int128_t mul = 1;
    rep(i , n){
        cin >> a[i];
    }
    rep(i , n){
        if(a[i] == 0 ) { PRINT(0); return 0; }
    }
    u64 limit = pow1018();
    rep(i , n){
        mul *= a[i];
        if(mul > limit ) { PRINT(-1); return 0; }
    }
    PRINT(mul);
}

Measured memory_bytes: 6440
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

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


int main() {
	int i, j, k;
	int N, M, K;


	int A, B, C;
	cin >> A >> B >> C >> K;
	int a = Min(K, A);
	int b = Max((K - a - B), 0);
	cout << a- b;

	return 0;

}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define MAX 10005
using namespace std;
 
int main(){
  int d, g, p[10], c[10], i, j, ans = 1005, cnt, scr, b;
  scanf("%d%d", &d, &g);
  g /= 100;
  for(i = 0; i < d; i++){
    scanf("%d%d", &p[i], &c[i]);
    c[i] /= 100;
  }
  for(i = 0; i < 1<<d; i++){
    cnt = 0; scr = 0; b = 0;
    for(j = 0; j < d; j++){
      if(i&(1<<j)){
        scr += (j+1)*p[j] + c[j];
        cnt += p[j];
      }else b = j;
    }
    if(scr < g){
      if(scr + (b+1)*(p[b]-1) < g) continue;
      cnt += (g - scr - 1) / (b+1) +1;
    }
    ans = min(cnt, ans);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 256
import fractions


def GCD(a, b):
    if b == 0:
        return a
    else:
        return GCD(b, a % b)


N = int(input())
clock = [0] * N
for j in range(N):
    clock[j] = int(input())
gcd = clock[0]

ans = clock[0]
for i in range(1, N):
    gcd = GCD(ans, clock[i])
    ans = ans//gcd
    ans = ans * clock[i]

print(int(ans))


Measured memory_bytes: 5048
import math
x = int(input())

def is_prime(x):
    n = math.floor(math.sqrt(x))
    ans = True
    for i in range(2,n):
        if x % i == 0:
            ans = False
            break
    return ans

while True:
    if is_prime(x) == True:
        ans = x
        break
    x += 1
print(ans)    

Measured memory_bytes: 3060
use proconio::*;

fn main() {
    input! {
        a: u32,
        b: u32,
        c: u32,
        x: u32
    };
    let mut ans = 0;
    for i in 0..a+1 {
        for j in 0..b+1 {
            for k in 0..c+1 {
                if i * 500 + j * 100 + k * 50 == x {
                    ans += 1;
                }
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2092
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
#include<cstring>
#include<set>
using namespace std;
using ll = long long;
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
const ll mod = 1e9+7;
const int INF = 1e9;
const ll INFLONG = 1e18;
int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  cout << min(n*a,b);
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<i64> a(n);
    for (auto &e : a) std::cin >> e;

    std::vector<std::map<int, i64>> dp(n + 1);
    for (int i = 0; i < n; i++) {
        for (int k = 0; k < 2; k++) {
            const int c = i / 2 + k;
            for (int j = 2; j <= 4; j++) {
                const int p = i - j;
                if (p < 0) {
                    if (c == 0) dp[i][c] = 0;
                    else if (c == 1) dp[i][c] = a[i];
                } else {
                    const auto it = dp[p].find(c - 1);
                    if (it == dp[p].end()) continue;
                    if (dp[i].find(c) == dp[i].end()) dp[i][c] = a[i] + it->second;
                    else dp[i][c] = std::max(dp[i][c], a[i] + it->second);
                }
            }
        }
    }

    i64 ret = std::numeric_limits<i64>::min();
    for (int i = 0; i < n; i++) {
        const auto it = dp[i].find(n / 2);
        if (it != dp[i].end() && it->second > ret) ret = it->second;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 39148
using System;
using System.Linq;

namespace ITP1_2_C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            
            Array.Sort(x);
            Console.WriteLine(x[0] + " " + x[1] + " " + x[2]);
        }
    }
}



Measured memory_bytes: 18408
n = int(input())
stocks = [int(x) for x in input().split()]
mymoney = 1000
mystock = 0

for i in range(0,len(stocks)-1):     # コメントアウト部分はデバッグ用コード
      #print(stocks[i],stocks[i+1],end=":")
      if stocks[i] < stocks[i+1]:    # 明日の方が株価が高くなる場合は、今日のうちに株を買えるだけ買う
            #print("buying",end=" ")
            mystock += mymoney//stocks[i]
            mymoney = mymoney%stocks[i]
      elif stocks[i] >= stocks[i+1]:  # 明日の方が株価が安くなる場合には、今日のうちに手持ちの株を売却
            #print("selling",end=" ")
            mymoney += mystock*stocks[i]
            mystock = 0
      #print(mymoney,mystock)

i += 1
mymoney += mystock * stocks[i]      # 最終日に手持ちの株をすべて売却して現金化
mystock = 0

print(mymoney)

Measured memory_bytes: 9192
n, k, q = gets.chomp.split(' ').map(&:to_i)
a = []
q.times { a << gets.chomp.to_i }
points = Array.new(n).fill(0)
a.each { |i| points[i-1] += 1 }
points.each do |p|
  if p > q - k
    puts 'Yes'
  else
    puts 'No'
  end
end

Measured memory_bytes: 5244
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long

int n;
string s;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> s;
    int l = 0, r = n - 1;
    int ans = 0;
    while(l < r){
        if(s[l] == 'R'){
            l++;
            continue;
        }
        if(s[r] == 'W'){
            r--;
            continue;
        }
        ans++;
        l++;
        r--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3772
//59
#include<iostream>

using namespace std;

int main(){
  int t[15]={1};
  int a[15]={1};
  for(int i=1;i<=14;i++){
    t[i]=t[i-1]*3;
    a[i]=a[i-1]+t[i];
  }
  for(int n;cin>>n;){
    if(n<=1){
      cout<<n<<endl;
    }else if(n%2){
      cout<<1+4*a[n/2-1]<<endl;
    }else{
      cout<<2*a[n/2-1]<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<array>
#define nguyendz the_best


#define ll long long
#define ld long double
#define pb push_back
#define all(n) n.begin(),n.end()
#define eb emplace_back
#define endl "\n"
#define pll pair<ll,ll>
#define YES cout <<"YES"<<endl;
#define NO cout <<"NO"<<endl;
#define ff first
#define ss second
#define setpre(x) fixed<<setprecision(x)
//do not use "\n" in interactive problem
// ((x|y)-y) (x&(~y))
// __gcd(fibo(x),fibo(y)=fibo(__gcd(x,y))
//so luong tap hop gom d phan tu khac nhau dc tao tu k so phan biet la k mu d
// a+b=(a^b)+2*(a&b)
using namespace std;
const ll maxn=1e6+100;

const ll maxx=1e13;
const ll mod1=1000000007;
const ll mod2=998244353;
priority_queue<pll,vector<pll>,greater<pll>> q;
ll a[maxn];
ll gt[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("test.txt","r",stdin);
    //   freopen("PHONGHAU.INP", "r", stdin);
    //  freopen("PHONGHAU.OUT", "w", stdout);
    ll n;
    cin>>n;
    bool y=false;
    for (int i=1; i<=n; i++)
    {

        char x;
        cin>>x ;
        a[i]=x-'0';
        a[i]--;
        if (a[i]==1)
            y=true;
    }
    gt[0]=0 ;
    for (int i=1; i<maxn; i++)
    {
        gt[i]=gt[i-1];
        ll cnt=0;
        ll j=i;
        while (j%2==0)
        {
            j/=2;
            cnt++;
        }
        gt[i]+=cnt;
    }

    ll dem=0;
    for (int i=1; i<=n; i++)
    {
        if (a[i]%2==0)
        {
            dem=(dem^0) ;
            continue;
        }
        ll t=gt[n-1];
        ll t1= gt[i-1];
        ll t2=gt[n-i];
        if (t==t1+t2)
        {
            dem=(dem^1);
        }
        else
        {
            dem=(dem^0) ;
        }
       // cout <<dem<<endl;
    }
  //  cout <<dem ;
    if (dem==1)
    {
        cout <<1;
    }
    else if (y)
    {
       //  cout <<34;
        cout <<0;
    }
    else
    {
        ll dem=0;
        for (int i=1; i<=n; i++)
        {
            a[i]/=2;
            if (a[i]%2==0)
            {
                dem=(dem^0) ;
                continue;
            }
            ll t=gt[n-1];
            ll t1= gt[i-1];
            ll t2=gt[n-i];
            if (t==t1+t2)
            {
                dem=(dem^1);
            }
            else
            {
                dem=(dem^0) ;
            }
        }
        if (dem==1)
        {
            cout <<2;
        }
        else
        {
            cout <<0;
        }
    }


}


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

int n;
long long g[300][300];
bool calc[300][300];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    cin >> n;
    for(int i=0; i < n; ++i) 
        for(int j=0; j < n; ++j) cin >> g[i][j];

    for(int k = 0; k < n; ++k)
        for(int i = 0; i < n; ++i)
            for(int j = 0; j < n; ++j) {
                if(i == j || j == k || k == i) continue;
                if(g[i][j] > g[i][k] + g[k][j]) {cout << -1 << '\n'; return 0;}
                if(g[i][j] == g[i][k] + g[k][j]) calc[i][j] = true;
            }

    long long ans = 0;
    for(int i=0; i < n; ++i) 
        for(int j=0; j < i; ++j) 
            if(!calc[i][j]) ans += g[i][j];
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <cstdio>
using namespace std;

inline int getint()
{
	int x = 0, c = getchar();
	while (c > 47 && c < 58)
	{
		x = x * 10 + c - 48;
		c = getchar();
	}
	return x;
}

constexpr int MAX = 300000;
int res[MAX * 4];

int main()
{
	int H = getint();
	int W = getint();
	int M = getint();

	int h, w, ans, x, y;
	int mxr = 0;
	int mxc = 0;
	int ctrow = 0;
	int ctcol = 0;
	for (int i = 0; i < M; ++i)
	{
		h = getint() - 1, w = getint() - 1;
		res[i + 2 * MAX] = h, res[i + 3 * MAX] = w;
		x = ++res[h], y = ++res[w + MAX];

		if (x == mxr) ++ctrow;
		else if (x > mxr) mxr = x, ctrow = 1;

		if (y == mxc) ++ctcol;
		else if (y > mxc) mxc = y, ctcol = 1;
	}
	ans = mxr + mxc;

	long ct = ctrow;
	ct *= ctcol;
	if (ct > M)
	{
		printf("%d\n", ans);
		return 0;
	}

	for (int i = 0; i < M; ++i) if (res[res[i + 2 * MAX]] == mxr && res[res[i + 3 * MAX] + MAX] == mxc) --ct;
	if (ct <= 0) --ans;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 6284
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
        y[i]=x[i];
    }
    sort(y.begin(),y.end());
    for(int i=0;i<n;i++){
        if(x[i]<y[n/2])cout<<y[n/2]<<endl;
        else cout<<y[n/2-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>

using namespace std;

int N, v[110], count = 0;

int main(void) {
    cin >> N;
    for(int i = 0; i < N; i++) cin >> v[i];

    for(int i = 0; i < N; i++) {
        for(int j = N - 1; j >= i + 1; j--) {
            if(v[j] < v[j - 1]) {
                swap(v[j], v[j - 1]);
                ::count += 1;
            }
        }
    }
    for(int i = 0; i < N; i++) {
        if(i == N - 1) {
            cout << v[i] << endl;
        } else {
            cout << v[i] << " ";
        }
    }
    cout << ::count << endl;
    return 0;
}

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

int main() 
{
    string s="";
    for (int i=0; i<9; i++)
    {
        char c;
        cin >> c;
        if (i==0 || i == 4 || i == 8)
            s+=c;
    }
    cout << s;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int 
	fmt.Scanf("%d", &n)

	var a [200]int
	for i := 0; i < n; i++ {
		fmt.Scanf("%d", &a[i])
	}

	var result int = 0
	var b bool = true


	for b {
		for i := 0; i < n; i++ {
			if a[i] % 2 != 0 {
				b = false
				result--
				break
			}else{
				a[i] = a[i] >> 1
			}
		}
		result++
	}
	fmt.Println(result)
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
using namespace std;



int main()
{
	string S, a;
	int  m, mi;
	mi = 10000;
	cin >> S;
	for (int i = 0; i < S.length() - 2; i++){
		a = S.substr(i, 3);
		m = abs(753 - stoi(a));
		mi = min(m, mi);
	}
	cout << mi << endl;
}


Measured memory_bytes: 256
fn main() {
    let n: usize = read();
    let mut dn: Vec<u64> = read_vec();

    let mid = n / 2;

    dn.sort();

    println!("{:?}", dn[mid] - dn[mid - 1]);
}




fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 6396
using System;
using System.Linq;

namespace practice6
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string c = Console.ReadLine().ToString();
            string A = "5 5 7";
            string B = "5 7 5";
            string C = "7 5 5";
            if (c == A)
                Console.WriteLine("YES");
            else if (c == B)
                Console.WriteLine("YES");
            else if (c == C)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");

        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
const int N = 2e6 + 10;
typedef long long ll;
vector<ll>v[N];
int main(){
	ll n;
	cin >> n;
	ll ans = 1e12;
	for (ll i = 1; i*i <= n; i++){
		v[i].push_back(n / i);
		if ((n / i)*i == n){
			ans = min(i - 1 + (n / i - 1), ans);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 78336
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>


int main(){
    int ret,tmp=0;
    int x=0,y=0;

    scanf("%d %d",&x,&y);

    /*while(!(d>x)&&!(d>y)){
        if(x%d==0&&y%d==0){
            ret=d;
        }
        d++;
    }*/

    if(x>y){
        tmp=y;
        y=x;
        x=tmp;
    }
    while(true){
        tmp=y%x;
        if(tmp==1){
            ret=tmp;
            break;
        }
        else if(tmp==0){
            ret=x;
            break;
        }
        y=x;
        x=tmp;
    }


    printf("%d\n",ret);
    return 0;
}



Measured memory_bytes: 2100