akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int lmin(long long a, long long b){
  if(b>a)return a;
  else return b;
}

int n,i;
long long a[300][300];
long long mindist[300][300];

int main(){
  int j,k;
  scanf("%d", &n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%lld", &a[i][j]);
      mindist[i][j] = a[i][j];
    }
  }
  long long res = 0;
  for(k=0;k<n;k++){
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
        mindist[i][j] = lmin(mindist[i][j], a[i][k]+a[k][j]);
      }
    }
  }

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      if(mindist[i][j]!=a[i][j]){
        printf("-1\n");return 0;
      }
    }
  }

  for(i=0;i<n;i++){
    for(j=i+1;j<n;j++){
      int t=1;
      for(k=0;k<n;k++){
        if(k!=j&&k!=i&&a[i][j] == a[i][k]+a[k][j]){
          t=0;
        }
      }
      if(t)res+=a[i][j];
    }
  }
  printf("%lld\n",res);
  return 0;
}


Measured memory_bytes: 3136
#include<bits/stdc++.h>
using namespace std;
int n,a[200100],b[200100];
int main(){
	#ifndef DavidLaptop
		#ifdef FILIN
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++) cin>>a[i]>>b[i];
	sort(a+1,a+n+1);sort(b+1,b+n+1);
	if(n%2==1){
		cout<<b[(n+1)/2]-a[(n+1)/2]+1<<endl;
		return 0;
	}
	else{
		cout<<(b[n/2]+b[n/2+1])-(a[n/2]+a[n/2+1])+1<<endl;
		return 0;
	}
	return 0;
}



Measured memory_bytes: 5180
#include<iostream>
#include<string>
using namespace std;
 int main()
 {
	 string deck;
	 int n,m;
	 while(true)
	 {
		cin>>deck;
		if(deck == "-") break;
		cin>>n;
		for(int i=0; i<n; i++)
		{
			cin>>m;
			deck = deck.substr(m,deck.size()-m) + deck.substr(0,m);
		}
		cout<<deck<<endl;
	 } 
 }



Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<double,ll> mp;
double inf =1e9;
#define EPS 1e-10
struct point{
	double x,y;
	void make(){
		cin>>x>>y;
	}
	point(){};
	point(double x,double y):x(x),y(y){};
	point operator + (point &p) { return point(x+p.x,y+p.y)  ; }
	point operator - (point &p) { return point(x-p.x,y-p.y)  ; }
	double norm() { return x*x+y*y;}
	double abs() { return sqrt(norm()) ;}
};

typedef pair<int,point> mmp;

struct line{
	point s,e;
};

double cross(point a,point b){
	return a.x*b.y-a.y*b.x;
}
double dot(point a,point b){
	return a.x*b.x+a.y*b.y;
}

struct circle{
	point p;
	double r;
	void make(){
		p.make();
		cin>>r;
	}
};

double abs(point a){
	return a.abs();
}
double distance(line l,point p){
	point tmp = l.e-l.s;
	if(dot(tmp,p-l.s) < EPS) return abs(p-l.s);
	if(dot(l.s-l.e,p-l.e) < EPS ) return abs(p-l.e);
	return abs(cross(l.e-l.s,p-l.s ) / abs(l.e-l.s) );
}

typedef pair<mp,int> mpp;
vector<mp> daikus(vector<vector<double> > &g,int s){
	vector<mp> cost(g.size(),mp( inf,g.size() ) );
	vector<bool> used(g.size(),false);
	priority_queue<mpp,vector<mpp>,greater<mpp> > q;
	q.push( mpp(mp(0.0,s),g.size())  );
	cost[s] = mp( 0.0,g.size() );
	while(!q.empty()){
		mp now = q.top().first;
		int prev = q.top().second;
		double nowc = now.first;
		int nn = now.second;
		q.pop();
		if(used[nn])continue;
		used[nn] = true;
		cost[nn] = mp(nowc,prev);
		for(int i=0;i<g.size();i++){
			double nextc = g[nn][i];
			if(nextc>50.0){
				continue;
			}
			if(used[i]) continue;
			q.push(mpp(mp(nowc+nextc,i),nn) );
		}
	}
	return cost;
}

int main(){
	while(1){
		int n;
		cin>>n;
		if(n==0)break;
		vector<mmp> a(n);
		map<int,int> hen;
		for(int i=0;i<n;i++){
			cin>>a[i].first;
			a[i].second.make();
			hen[a[i].first] = i;
		}
		vector<vector<double> > g(n,vector<double>(n,inf) );
		for(int i=0;i<n;i++)for(int j=0;j<n;j++) g[i][j] = abs(a[i].second-a[j].second);
		vector<vector<mp> > cost(n);
		for(int i=0;i<n;i++){
			cost[i] = daikus(g,i);
		}
		int m;
		cin>>m;
		/*for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].first<<' ';
			}
			cout<<endl;
		}
		cout<<endl;

		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<g[i][j]<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				cout<<cost[i][j].second<<' ';
			}
			cout<<endl;
		}
		cout<<endl;
		*/

		for(int i=0;i<m;i++){
			int s,t;
			cin>>s>>t;
			s = hen[s];
			t = hen[t];
			//cout<<"ok"<<s<<' '<<t<<endl;
			vector<int> kei;
			if(cost[s][t].first == inf||cost[s][t].second == n) {
				cout<<"NA"<<endl;
				continue;
			}
			kei.push_back(t);			
			while(t!=s){
		    	//cout<<t<<' '<<cost[s][t].first<<' '<<cost[s][t].second<<endl;
				t = cost[s][t].second;
				kei.push_back(t);
				//cout<<t<<endl;
			}
			//cout<<"ok"<<endl;
			cout<<a[kei[kei.size()-1]].first;
			for(int j=kei.size()-2;j>=0;j--){
				cout<<' '<<a[kei[j]].first;
			}
			cout<<endl;
		}
	}
	return 0;
}



Measured memory_bytes: 3280
// DP.
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

const int maxn = 10;
const int maxtot = 300;

int n, m, targets[3], l[maxn], cost[3][maxtot], f[3][maxtot];

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n;
	for (int i = 0; i < 3; ++i)
		cin >> targets[i];

	for (int i = 0; i < n; ++i)
		cin >> l[i];

	int tot = 1<<n;
	for (int i = 1; i < tot; ++i) {
		int cnt = 0, len = 0;
		for (int j = 0; j < n; ++j)
			if (i&(1<<j)) {
				++cnt;
				len += l[j];
			}

		cnt = (cnt-1) * 10;
		for (int j = 0; j < 3; ++j)
			cost[j][i] = abs(targets[j] - len) + cnt;
	}

	int ans = INT_MAX;
	for (int i = 0; i < 3; ++i)
		for (int j = 1; j < tot; ++j) {
			if (i == 0)
				f[i][j] = cost[0][j];
			else {
				f[i][j] = INT_MAX / 2;
				// int kk = 0;
				for (int k = 1; k < j; ++k)
					if ((k&j) == k) {
						if (f[i-1][j-k] == INT_MAX / 2)
							continue;

						// if (f[i-1][j-k] + cost[i][k] < f[i][j]) {
						// 	f[i][j] = f[i-1][j-k] + cost[i][k];
						// 	kk = k;
						// }
						f[i][j] = min(f[i][j], f[i-1][j-k] + cost[i][k]);
					}

				// printf("%d %d:%d %d\n", i, j, f[i][j], kk);

				if (i == 2)
					ans = min(ans, f[i][j]);
			}
		}

	cout << ans << endl;

	return 0;
}

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

int main(){
	int r, c;
	int data[120][120],box = 0;

	cin >> r >> c;

	for (int rr = 0; rr < r; rr++){
		for (int cc = 0; cc < c; cc++){
			cin >> data[rr][cc];
		}
	}

	for (int rrr = 0; rrr < r; rrr++){
		for (int ccc = 0; ccc < c; ccc++){
			box += data[rrr][ccc];
		}
		data[rrr][c] = box;
		box = 0;
	}
	for (int cccc = 0; cccc <= c; cccc++){
		for (int rrrr = 0; rrrr < r; rrrr++){
			box += data[rrrr][cccc];
		}
		data[r][cccc] = box;
		box = 0;
	}

	for (int i = 0; i <= r; i++){
		for (int o = 0; o <= c; o++){
			cout << data[i][o];
			if (o != c){
				cout << " ";
			}
		}
		cout << endl;
	}
	cin >> r;
}


Measured memory_bytes: 3120
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u64; n],
    }

    let mut ans = 0;
    for i in &a {
        let mut current = *i;
        while current % 2 == 0 {
            ans += 1;
            current /= 2;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2308
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 5 + 1e2;
int n,a[N],b[N],c[N],t;
LL ans;
int main()
{
	cin>>n;
	n--;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	ans=a[1];
	for(int i=2;i<=n;i++)
	{
		ans+=min(a[i],a[i-1]);
	}
	ans+=a[n];
	cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
bool t[100001][2];
int main()
{
    ll n,k;
    cin>>n>>k;
    memset(t,false,sizeof(t));
    ll a[n+1];
    for(int x=1;x<=n;x++)
        cin>>a[x];
        for(int x=1;x<=n;x++)
            {t[a[x]][0]=true;
            t[a[x]][1]=true;}
    for(int x=1;x<=k;x++)
    {for(int y=1;y<=n;y++)
       {   if(x>=a[y])
           {t[x][0]=t[x][0]|!t[x-a[y]][1];
           t[x][1]=t[x][1]|!t[x-a[y]][0];
           }
       }}
       if(t[k][0])
        cout<<"First"<<endl;
       else
        cout<<"Second"<<endl;
}


Measured memory_bytes: 384
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect
import itertools
import heapq


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(N, S, T):
    ret = ""
    for i in range(N):
        ret += S[i] + T[i]
    return ret



def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    N = int(input())
    [S, T] = input().split()
    ret = solve(N, S, T)
    print(ret)


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class DModSum
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
             
            Console.WriteLine(n * (n - 1) / 2);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(6);

    double w,h,x,y;
    cin >> w >> h >> x >> y;
    if(x == w / 2 && y == h / 2){
        cout << w * h / 2 << " " << "1" <<endl;
    }else{
        cout << w * h / 2 << " " << "0" <<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    char S[3], T[3];
    int c = 0;
    scanf("%s", S);
    scanf("%s", T);
    for(int i = 0; i < 3; i++){
        if(S[i] == T[i]){
            c++;
        }
    }
    printf("%d", c);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
k = 2
while k * (k - 1) // 2 < N:
  k += 1
if k * (k - 1) // 2 == N:
  print('Yes')
  print(k)
  V = [[] for i in range(k)]
  idx = 1
  for i in range(k - 1):
    for j in range(i + 1, k):
      V[i].append(idx)
      V[j].append(idx)
      idx += 1
  for i in range(k):
    print(' '.join([str(x) for x in [k - 1] + V[i]]))
else:
  print('No')

Measured memory_bytes: 9068
#include<bits/stdc++.h> 
#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string S; cin >> S;
    REP(i, S.length()) cout << "x";
    cout << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())


def calc(x):
    cnt = 1
    while x < K:
        cnt += 1
        x *= 2
    return cnt - 1


ans = 0
for i in range(1, N + 1):
    ans += (1 / N) * (1 / (2 ** calc(i)))

print(ans)

Measured memory_bytes: 39664
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n, x = MI()
l = LI()
cnt = 0
ans = []
ans.append(0)
z = 0
for i in range(n):
    z += l[i]
    ans.append(z)
for num in ans:
    if num <= x:
        cnt += 1
print(cnt)



Measured memory_bytes: 68076
#include<iostream>

int n;
int pw[10] = {1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000};

int solve(){
	int tmp = n;
	int ans = 0;
	for(int i=0;; i++){
		if(tmp%-10 < 0){
			ans += (10+tmp%-10)*pw[i];
			tmp -= 10;
		}else
			ans += tmp%-10*pw[i];
		tmp = tmp/(-10);
		if(!tmp)
			break;
	}
	return ans;
}

int main(){
	while(true){
		std::cin >> n;
		if(!n)
			return 0;
		std::cout << solve() << std::endl;
	}
}

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

template<typename T>
T power(T a, T b) {
	if (b == 0) return 1;
	T res = power(a * a, b / 2);
	if (b % 2) res *= a;
	return res;
}

int main() {
	double N, K;
	cin >> N >> K;
	vector<int> a;
	for (double i = 1; i <= N; ++i) {
		double j = i;
		int b = 0;
		while (j < K) {
			j *= 2;
			++b;
		}
		a.push_back(b);
	}
	vector<pair<int, int>> c;
	int tmp = a[0], sum = 1;
	for (int i = 1; i < a.size(); ++i) {
		if (tmp != a[i]) {
			c.emplace_back(tmp, sum);
			tmp = a[i];
			sum = 1;
		}
		else ++sum;
	}
	if (sum) c.emplace_back(tmp, sum);
	// for (int i = 0; i < a.size(); ++i) cout << a[i] << ' ';
	// cout << endl;
	// for (int i = 0; i < c.size(); ++i) cout << c[i].first << ' ' << c[i].second << ' ';
	double ans = 0.0;
	for (pair<int, int>& i : c) {
		ans += i.second * pow(0.5, i.first);
		// ans += pow(0.5, i);
	}
	ans /= N;
	printf("%.20f", ans);
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

int main() {
  ll x, k, d;
  cin >> x >> k >> d;
  x = abs(x);
  ll ans;

  if ((x / d) <= k) {
    k -= x / d;
    x -= d * (x / d);
    if (k % 2 == 1) {
      x = min(abs(x - d), abs(x + d));
    }
    ans = abs(x);
  } else {
    ans = abs(x - k * d);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3616
import math
N,D = map(int,input().split())

A = [list(map(int, input().split()))  for i in range(N)]
count = 0
for i in range(N):
    a = math.sqrt((A[i][0]**2+(A[i][1])**2))
    if a <= D:
        count += 1

print(count)


Measured memory_bytes: 45468
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
template<typename T>
void chmax(T& a, T b) {
	a = max(a, b);
}

template<typename T>
void chmin(T& a, T b) {
	a = min(a, b);
}

template<typename T>
void IN(vector<T> &A,int N=-1) {
	if (N == -1) {
		N = A.size();
	}
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
}

template<typename T>
void SO(vector<T> &A,bool F=false) {
	sort(A.begin(), A.end());
	if (F) {
		reverse(A.begin(), A.end());
	}
}
//////////////

void solve() {
	int N;
	cin >> N;
	vector<int> L(N);
	IN(L); SO(L);
	reverse(L.begin(), L.end());
	for (int i = 0; i < N; ++i) {
		int sum = 0;
		int cnt = 0;
		for (int j = 0; j < N && cnt<N-1; ++j) {
			if (i == j)continue;
			sum += L[j];
			++cnt;
		}
		if (L[i] >= sum) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
from statistics import mean, median,variance,stdev
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#n = ip()                              #入力整数1つ
n,m= (int(i) for i in input().split())      #入力整数横2つ
#x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列

#jの変数はしようできないので注意

if n>=m:
    print(0)
    exit(0)
a.sort()
b =[]
for i in range(m-1):
    b.append(a[i+1]-a[i])
b.sort()
print(sum(b[:m-n]))

Measured memory_bytes: 16052
def resolve():
    n = int(input())
    s = input()
    max_common = 0
    for i in range(n):
        s1, s2 = s[:i + 1], s[i + 1:]
        common = len(set(set(s1) & set(s2)))
        if common > max_common:
            max_common = common
    print(max_common)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque, Counter
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
INF = 10 ** 20

def main():
    n = getN()
    arr = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    print(arr[n-1])

if __name__ == "__main__":
    main()

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

using namespace std;

using ll = long long;
using P = pair<int, int>;

const long long MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N + 1, 0);
    for (int i = 0; i < N; ++i) {
        ll a;
        cin >> a;
        A[i + 1] += A[i] + a;
    }
    ll ans = ((ll)1 << 60);
    for (int i = 1; i < N; ++i) {
        ll snuke = A[i];
        ll arai  = A[N] - A[i];
        ans = min(ans, abs(snuke - arai));
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
 
bool prime[100001];
void furui() {
    prime[0]=true;
    prime[1]=true;
	int i = 2;
	while (i <= 100000) {
		int j = 2;
		while (j <= sqrt(i) && !prime[i]) {
			if (i%j == 0) {
				prime[i] = true;
				break;
			}
			else j++;
		}
		int z = 2;
		while (!prime[i]) {
			if (i*z <= 100000) {
				prime[i*z] = true;
				z++;
			}
			else break;
		}
		i++;
	}
}



int main(void){
    furui();
    int n;
    cin>>n;
    vector<int>ans;
    for(int i=2;i<=55555;i++){
        if(!prime[i]){
            if(i%5==1)ans.push_back(i);
        }
    }
    for(int i=0;i<n;i++){
        if(i==n-1)cout<<ans[i]<<endl;
        else cout<<ans[i]<<" ";
    }
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int X;
    cin >> X;
    int max = 1999;
    int min = 1800;
    for(int i = 0; i < 8; i++){
        if(max >= X && min <= X){
            cout << i + 1 << endl;
        }

        max -= 200;
        min -= 200;
    }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  string s ;
  ll k ;
  
  cin >> s >> k ;
  
  ll cnt1 =  0 ;
  ll cnt2 = 0 ;
  ll cnt3 = 0 ;
  ll ans ;
  ll n = SZ(s) ;
  
  s = s+s+s ;
  
  REP(i,n-1){
    if(s.at(i)==s.at(i+1)){
      cnt1++ ;
      s.at(i+1) = '0' ;
    }
  }
  
  if(s.at(n-1)==s.at(n)){
    s.at(n)='0' ;
    cnt2++ ;
  }
  
  FOR(i,n,2*n-1){
    if(s.at(i)==s.at(i+1)){
      cnt2++ ;
      s.at(i+1) = '0' ;
    }
  }
  
  if(s.at(2*n-1)==s.at(2*n)){
    s.at(2*n)='0' ;
    cnt3++ ;
  }
  
  FOR(i,2*n,3*n-1){
    if(s.at(i)==s.at(i+1)){
      cnt3++ ;
      s.at(i+1) = '0' ;
    }
  }
  
  if(k%2==0){
    ans = cnt1+cnt2*(k/2)+cnt3*(k/2-1) ;
  }
  else{
    ans = cnt1+cnt2*(k/2)+cnt3*(k/2) ;
  }
  
  cout << ans <<endl ;
  
  


  return 0 ;
}



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

using namespace std;

int n, a, b, c;
int data[101];

main(){
  cin >> n;
  cin >> a >> b >> c;
  for(int i=0;i<n;i++){
    cin >> data[i];
  }
  sort(data, data+n);
  reverse(data, data+n);
  int ans = c/a;
  int sum = c;
  for(int i=1;i<=n;i++){
    sum += data[i-1];
    ans = max(ans, sum / (a+b*i));
  }
  cout << ans << endl;
  return 0;
}

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

#include <iostream>

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#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, a, b) for(int i = a;i < b;++i)
#define FORR(i, a, b) for(int i = b;i >= a;--i)
#define ALL(x) (x).begin(),(x).end()
#define INF 999999999
using namespace std;
#define lint long long

int main()
{
  int a,b; cin >> a >> b;
  int ab = a+b;
  
  if(ab==3) cout<<3;
  else if(ab==5) cout <<1;
  else cout <<2;
  return 0;
}



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

const int MOD = 1000000007;
long long fac[2000000], finv[2000000], inv[2000000];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < 2000000; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}


long long COM(int n, int m){
    return fac[n+m] * (finv[n] * finv[m] % MOD) % MOD;
}

int main(){
int  x,y,n,m;
cin >> x >> y;
if(((2*x-y) % 3) > 0 || ((2*y-x) % 3) > 0||2*y<x || 2*x<y){
    cout << 0 <<endl;
    return 0;
}
n = (2*y-x)/3;
m = (2*x-y)/3;
if(n>m){
swap(n,m);
}
COMinit();

cout << COM(n, m) << endl;

}

Measured memory_bytes: 47104
#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
#define int long long
using namespace std;
int cnt;
typedef struct a{
    int to,nex,w;
};
a edge[1000007];
int head[1000007];
void add(int u,int v,int w){
    edge[++cnt].nex=head[u];
    edge[cnt].to=v;
    edge[cnt].w=w;
    head[u]=cnt;
}
int cost[307][307];
int l;
queue<int>q;
int dis[1000007],vis[1000007],f[1000007];
int inf;
void spfa(int x){
    q.push(x);
    memset(dis,127/3,sizeof(dis));
    memset(vis,0,sizeof(vis));
    memset(f,0,sizeof(f));
    inf=dis[x];
    dis[x]=0;
    vis[x]=l;
    f[x]=0;
    while(!q.empty()){
        int now=q.front();
        f[now]=0;
        q.pop();
        for(int i=head[now];i;i=edge[i].nex){
            int v=edge[i].to;
            if(dis[v]>dis[now]+(vis[now]<edge[i].w)){
                dis[v]=dis[now]+(vis[now]<edge[i].w);
                if(vis[now]<edge[i].w)
                    vis[v]=l-edge[i].w;
                else
                    vis[v]=vis[now]-edge[i].w;
                if(!f[v]){
                    q.push(v);
                    f[v]=1;
                }
            }
            else if(dis[v]==dis[now]+(vis[now]<edge[i].w)){
                if(l-edge[i].w>vis[v]&&vis[now]<edge[i].w){
                    vis[v]=l-edge[i].w;
                    if(!f[v]){
                        q.push(v);
                        f[v]=1;
                    }
                }
                if(vis[now]>edge[i].w&&vis[now]-edge[i].w>vis[v]){
                    vis[v]=vis[now]-edge[i].w;
                    if(!f[v]){
                        q.push(v);
                        f[v]=1;
                    }
                }
            }
        }
    }
}
main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m>>l;
    for(int i=1;i<=m;++i){
        int a,b,c;
        cin>>a>>b>>c;
        if(c<=l){
            add(a,b,c);
            add(b,a,c);
        }
    }
    for(int i=1;i<=n;++i){
        spfa(i);
        for(int j=1;j<=n;++j)
            cost[i][j]=dis[j];
    }
    int q;
    cin>>q;
    while(q--){
        int s,t;
        cin>>s>>t;
        if(cost[s][t]==inf)
            cout<<-1<<"\n";
        else
            cout<<cost[s][t]<<"\n";
    }
    return 0;
}


Measured memory_bytes: 29184
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF            1e9
#define INFLL          1e18
#define EPS            1e-9
#define REP(i,n)       for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)      for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)      for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)     for(ll i=(n);i>0;--i)
#define REPC(i,obj)    for(auto i:obj)
#define ALL(obj)       (obj).begin(),(obj).end()
#define SETP(n)        cout<<fixed<<setprecision(n)
#define VEC2(T,h,w)    move(vector<vector<T>>(h,vector<T>(w)))
#define VEC2I(T,h,w,i) move(vector<vector<T>>(h,vector<T>(w,i)))
using namespace std;
using ll = long long;
template<typename T, ll h, ll w>using vec2 = vector<vector<T>>;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

class union_find {
private:
	vector<ll> par, sz, rank;
	ll cnt;
public:
	union_find(ll n) : par(n), sz(n), rank(n)
	{
		cnt = n;
		REP(i, n) {
			par[i] = i;
			sz[i] = 1;
			rank[i] = 0;
		}
	}
	ll find(ll x)
	{
		return par[x] == x ? x : par[x] = find(par[x]);
	}
	void unite(ll x, ll y)
	{
		x = find(x);
		y = find(y);
		if (x != y) {
			if (rank[x] < rank[y]) {
				par[x] = y;
				sz[y] += sz[x];
			} else {
				par[y] = x;
				sz[x] += sz[y];
				if (rank[x] == rank[y]) {
					rank[x]++;
				}
			}
			cnt--;
		}
	}
	bool same(ll x, ll y)
	{
		return find(x) == find(y);
	}
	ll size(ll n)
	{
		return sz[find(n)];
	}
	ll count()
	{
		return cnt;
	}
};
signed main()
{
	ll h, w;
	while (cin >> h >> w, h) {
		auto fr = VEC2(char, h, w);
		REP(i, h)REP(j, w)fr[i][j] = in<char>();
		union_find uf(h * w);
		REP1(i, h - 1)if (fr[i - 1][0] == fr[i][0])uf.unite((i - 1) * w, i * w);
		REP1(j, w - 1)if (fr[0][j] == fr[0][j - 1])uf.unite(j - 1, j);
		REP1(i, h - 1) {
			REP1(j, w - 1) {
				if (fr[i - 1][j] == fr[i][j]) uf.unite((i - 1) * w + j, i * w + j);
				if (fr[i][j - 1] == fr[i][j]) uf.unite(i * w + j, i * w + j - 1);
			}
		}
		cout << uf.count() << endl;
	}
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int H,A;
    cin >> H >> A;
    if (H % A == 0) cout << H / A << endl;
    else cout << (H / A) + 1 << endl;
}



Measured memory_bytes: 256
MOD=10**9+7
n,m=map(int,input().split())
a=set([int(input()) for _ in range(m)])
if 1 in a:
  ans=[1,0]
else:
  ans=[1,1]

for i in range(1,n):
  if i+1 in a:
    ans.append(0)
  else:
    s=(ans[-1]+ans[-2])%MOD
    ans.append(s)
print(ans[-1]%MOD)

Measured memory_bytes: 18748
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		ABC11X_A();
		// ABC11X_B();
		// ABC11X_C();
		// ABC11X_D();
	}

	private static void ABC11X_A() {
		Scanner scanner = null;
		int nenrei = 0;

		try {
			scanner = new Scanner(System.in);
			nenrei = scanner.nextInt();
			switch (nenrei) {
			case 3:
			case 5:
			case 7:
				System.out.println("YES");
				break;
			default:
				System.out.println("NO");
				break;
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC11X_B() {
		Scanner scanner = null;
		int lineAB = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC11X_C() {
		Scanner scanner = null;
		int lineAB = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private static void ABC11X_D() {
		Scanner scanner = null;
		int lineAB = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println();

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 20820
n,m,X,Y = (int(x) for x in input().split())
x_list = [int(x) for x in input().split()]
y_list = [int(x) for x in input().split()]
x_list.sort(reverse=True)
y_list.sort()
for z in range(X+1,Y):
    if x_list[0] < z and y_list[0] >= z:
        print("No War")
        break
else:
    print("War")

Measured memory_bytes: 3064
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())
if w>=v:
    print("NO")
    exit()
x=abs(a-b)
n=x//(v-w)
if  (v-w)*t>=x:
    print("YES")
else:
    print("NO")
        



Measured memory_bytes: 9116
// ok

#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

bool judge(vector<vector<char>> &mat, int &h, int &w) {
    if (h == 0) {
        return false;
    }

    bool bflag = false;
    // simple search
    vector<bool> line_bflag(w);
    for (int j = 0; j < w; j++) {
        line_bflag[j] = false;
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (mat[i][j] == '#') {
                if (!bflag && (j == w - 1 || mat[i][j + 1] == '.') &&
                    !line_bflag[j] && (i == h - 1 || mat[i + 1][j] == '.')) {
                    return false;
                }
                bflag = true;
                line_bflag[j] = true;

            } else {
                bflag = false;
                line_bflag[j] = false;
            }
        }
        bflag = false;
    }

    return true;
}

int main() {
    int h, w;

    cin >> h >> w;
    vector<vector<char>> mat;
    char s;
    for (int i = 0; i < h; i++) {
        vector<char> line;
        for (int j = 0; j < w; j++) {
            cin >> s;
            line.push_back(s);
        }
        mat.push_back(line);
    }

    if (judge(mat, h, w)) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
   int n,m,i,w=0;

   scanf("%d",&n);
   m=n;
   for(i=0;i<10;i++){
      w+=n%10;
      n/=10;
   }

   if(m%w==0) printf("Yes\n");
   else printf("No\n");

// printf("%d",w);
   return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int sum = 0;
        int answer = 0;
        for (int j = 0; j < n; j++) {
            int d = in.nextInt();
            sum += d;
            answer -= d * d;
        }
        answer += sum * sum;
        answer /= 2;
        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
import heapq

n, m, r = list(map(int, input().split()))
V = [i for i in range(n)]
E = [{} for _ in range(n)]

for _ in range(m):
    ef, et, ed = list(map(int, input().split()))
    E[ef][et] = ed
    # E[et][ef] = ed

INF = int(1e18)
dist = {i: INF for i in range(n)}
pred = {i: None for i in range(n)}
dist[r] = 0

update = True
count = 0
while update:
    update = False
    count += 1

    if count > n:
        print("NEGATIVE CYCLE")
        exit()

    for u in range(n):
        for v in E[u]:
            d = E[u][v]
            if dist[u] == INF or dist[u] + d >= dist[v]:
                continue
            else:
                dist[v] = dist[u] + d
                pred[v] = u
                update = True

# check negative cycle
# for u in range(n):
#     for v in E[u]:
#         if dist[u] + E[u][v] < dist[v]:
#             print("NEGATIVE CYCLE")
#             exit(0)

for v in range(n):
    if dist[v] == INF:
        print("INF")
    else:
        print(dist[v])


Measured memory_bytes: 6368
#include<bits/stdc++.h>
using namespace std;
int main(){
  long int N,c=0;
  long int L[N];
  cin>>N;
  for(long int i=0;i<N;i++){
    cin>>L[i];
  }
  for(long int i=0;i<N;i++){
    c=max(c,L[i]);
  }
  long int sum=0;
  for(long int i=0;i<N;i++){
    sum+=L[i];
  }
  if((sum-c)<=c){
    cout<<"No";
  }
  else{
    cout<<"Yes";
  }
  return 0;
}


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

int main(){
	long long ans = 0,n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n;i++) cin >> a[i];
	for(int i = 0;i < n;i++){
		if(i > 0 && a[i - 1] > 0 && a[i] > 0){
			ans++;
			a[i - 1]--;
			a[i]--;
		}
		ans += a[i] / 2;
		a[i] %= 2;
	}
	cout << ans << endl;
}

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

#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,a,b) for(int i=a; i<b; i++)
#define vector<int> vi
#define pb push_back
#define ll long long 

int main()
{
    FASTIO
    int s, w;
    cin >> s >> w;
    if(w >= s) cout << "unsafe\n";
    else cout << "safe\n";
    
    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
#include <string.h>
int main() {
    char s[101], t[101], buf;
    scanf("%s%s", s, t);
    int len = strlen(s);
    for (int i = 0; i < len; i++) {
        buf = s[len - 1];
        for (int j = len-1; j > 0; j--) {
            s[j] = s[j - 1];
        }
        s[0] = buf;
        if (strcmp(s, t) == 0) {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> red(n, 0), cnt(n, 1);
  red[0] = 1;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;y--;
    if (red[x] == 1) {
      if (cnt[x] == 1) red[x] = 0;
      red[y] = 1;
    }
    cnt[x]--;cnt[y]++;
  }
  
  int ans = 0;
  for (int i = 0; i < n; i++) ans += red[i];
  
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void)
{
	int i,cnt=0;
	char N[3];
	scanf("%s",&N);
	for(i=0;i<4;i++){
		if('2'==N[i]){
			cnt+=1;
		}
		
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc141/abc141_b.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  string S;
  cin >> S;

  int N = S.size();
  bool oddOk = true, evenOk = true;
  rep(i, N) {
    if ((i + 1) % 2 == 1 && S[i] == 'L') {
      cout << "No" << endl;
      return 0;
    } else if ((i + 1) % 2 == 0 && S[i] == 'R') {
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}

Measured memory_bytes: 3632
def rot_func_list(rot, dice):

    if rot == "N":
        keys=['T','S','B','N']
        items=dice['S'],dice['B'],dice['N'],dice['T']
        new_dice=dict(zip(keys,items))
        dice.update(new_dice)

    if rot == "S":
        keys=['T','S','B','N']
        items=dice['N'],dice['T'],dice['S'],dice['B']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "E":
        keys=['T','E','B','W']
        items=dice['W'],dice['T'],dice['E'],dice['B']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)

    if rot == "W":
        keys=['T','E','B','W']
        items=dice['E'],dice['B'],dice['W'],dice['T']
        new_dice=dict(zip(keys, items))
        dice.update(new_dice)


input_data=input().split(" ")
items=[int(cont)  for cont in input_data]
keys=['T', 'S', 'E', 'W', 'N', 'B']

controls=list(input())
dice=dict(zip(keys, items))

for i in controls:
    rot_func_list(i, dice)

print(dice["T"])




Measured memory_bytes: 5616
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

from functools import lru_cache,reduce
@lru_cache()
def dfs(n):
    if n == 0:
        return 0
    popcnt = bin(n).count('1')
    if n%popcnt == 0:
        return 1
    return dfs(n%popcnt) + 1

def main():
    N = int(input())
    X = input()
    cnt = 0
    for i in range(N):
        if X[i] == '1':
            cnt += 1
    
    if cnt == 0:
        for i in range(N):
            print(1)
        return 
    
    power1 = [0] * N
    power2 = [0] * N
    for i in range(N):
        if cnt > 1:
            power1[i] = pow(2,i,cnt - 1)
        power2[i] = pow(2,i,cnt + 1)
    
    modu1 = 0
    modu2 = 0
    ans = [0] * N
    for i in range(N):
        if X[N - i - 1] == '1':
            if cnt > 1:
                modu1 += power1[i]
                modu1 %= (cnt - 1)
            modu2 += power2[i]
            modu2 %= (cnt + 1)
    
    for i in range(N):
        if X[i] == '1':
            if cnt == 1:
                ans[i] = 0
                continue
            now = modu1
            now -= power1[N - i - 1]
            now %= (cnt - 1)
            ans[i] = dfs(now) + 1
        else:
            now = modu2
            now += power2[N - i - 1]
            now %= (cnt + 1)
            ans[i] = dfs(now) + 1
    print('\n'.join(map(str,ans)))
if __name__ == '__main__':
    main()

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

int main(){
    int N,T,A;
    cin >> N >> T >> A;
    vector<int> height(N);
    for (int i = 0; i < N; i++){
        cin >> height.at(i);
    }
    vector<pair<int,int> > vec(N);
    for (int i = 0; i < N; i++){
        vec.at(i).first = i + 1;
    }
    for (int i = 0; i < N; i++){
        int temp = 1000 * T - height.at(i) * 6;
        int sa = max(1000 * A - temp, temp - 1000 * A);
        vec.at(i).second = sa;
    }
    int min_sa = vec.at(0).second;
    for (int i = 1; i < N; i++){
        min_sa = min(min_sa, vec.at(i).second);
    }
    for (int i = 0; i < N; i++){
        if (min_sa == vec.at(i).second){
            cout << vec.at(i).first << endl;
            break;
        }
    }
}


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

int main(void){
    int n, x, y, *mat[2000], *count = new int[2000], now;
    bool *v = new bool[2000];
    cin >> n >> x >> y;
    --x;--y;
    for(int i = 0; i < n; ++i) count[i] = 0;
    queue<int> que;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < n; ++j) v[j] = false;
        que.push(i);
        v[i] = true;
        int num[2] = {1, 0};
        int k = 1;
        while (!que.empty()){
            now = que.front();
            que.pop();
            num[0]--;
            if(now-1 >= 0 && !v[now-1]){
                que.push(now-1);
                count[k]++;
                v[now-1] = true;
                num[1]++;
            }
            if(now+1 < n && !v[now+1]){
                que.push(now+1);
                count[k]++;
                v[now+1] = true;
                num[1]++;
            }
            if(now == x && !v[y]){
                que.push(y);
                count[k]++;
                v[y] = true;
                num[1]++;
            }
            if(now == y && !v[x]){
                que.push(x);
                count[k]++;
                v[x] = true;
                num[1]++;
            }
            if(!num[0]) {
                k++;
                num[0] = num[1];
                num[1] = 0;
            }
        }
    }
    for(int i = 1; i < n; ++i) cout << (count[i]/2) << endl;
    return 0;

}

Measured memory_bytes: 256
import math

input1 = input().split()
A = int(input1[0])
B = int(input1[1])
N = int(input1[2])

x = 0
result = 0
if N >= B-1:
    x = B-1
    result = (A*(x%B) - (A*x)%B)/B
elif N < B-1:
    x = N
    result = (A*(x%B) - (A*x)%B)/B

print(int(result))

Measured memory_bytes: 9072
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long ll;

ll gcd(ll x, ll y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}
ll kai(ll x, ll y, ll m) {
	ll res = 1;
	for (ll i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
ll mod_pow(ll x, ll y, ll m) {
	ll res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

ll comb(ll x, ll y, ll m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
ll a[310];

signed main() {
	cin >> n;
	ll x = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (2 <= i)x ^= a[i];
	}
	ll p = a[0] + a[1] - x;
	if (p < 0 || p % 2) {
		cout << -1 << endl;
		return 0;
	}
	p /= 2;
	if (p&x) {
		cout << -1 << endl;
		return 0;
	}
	ll q = a[0] - p;
	if (q < 0) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 39; i >= 0; i--)if ((x&(1LL << i)) && (1LL << i) <= q)q -= (1LL << i);
	if (!p&&q == a[0]) {
		cout << -1 << endl;
		return 0;
	}
	cout << q << endl;
}

Measured memory_bytes: 3636
import java.util.*;
class Main
{
    static int MOD = 1000000007;
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        int ans = 100000;
        for(int i = 0; i < n - 2; i++){
            int x = Integer.parseInt(String.valueOf(s.charAt(i))) * 100 + 
            Integer.parseInt(String.valueOf(s.charAt(i+1))) * 10 + Integer.parseInt(String.valueOf(s.charAt(i + 2)));
            ans = Math.min(ans, Math.abs(753 - x));
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << endl;
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int D;
    cin >> D;

    vi c(26);
    REP(i, 26) cin >> c[i];

    vi last(26, 0);

    vi ans(D);
    REP(i, D) {
        vll s(26);
        REP(j, 26) cin >> s[j];

        REP(j, 26) s[j] += c[j] * (i - last[i] + 1);

        int idx = max_element(ALL(s)) - s.begin();

        last[idx] = i + 1;
        ans[i] = idx + 1;
    }

    for(auto &e: ans) {
        print(e);
    }
    
}


Measured memory_bytes: 3684
using System;

public class Hello
{
    public static void Main()
    {
        var sa = Console.ReadLine().Trim();
        var sb = Console.ReadLine().Trim();
        var sc = Console.ReadLine().Trim();
        var pa = 0; var pb = 0; var pc = 0;
        var ba = sa[pa++];
        char ret;
        while (true)
        {
            if (ba == 'a')
                if (pa == sa.Length) { ret = 'A'; break; }
                else ba = sa[pa++];
            else if (ba == 'b')
                if (pb == sb.Length) { ret = 'B'; break; }
                else ba = sb[pb++];
            else if (pc == sc.Length) { ret = 'C'; break; }
            else ba = sc[pc++];
        }
        Console.WriteLine(ret);
    }
}


Measured memory_bytes: 11092
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    ans=N+1
    for i in range(1,10**6+1):
        if N%i==0:
            j=N//i
            #print(i,j)
            if j>0:
                ans=min(ans,i+j)
    print(ans-2)
    #print(B)
#%%submit!
resolve()

Measured memory_bytes: 38640
#include <iostream>
#include <cstring>
int main() {
    int h,w;
    while (scanf("%d %d", &h, &w)) {
        if (h == 0 & w == 0) break;
        char s[w+1], r[w+1];
        std::fill(s, s+w, '#');
        s[w] = '\0';
        memcpy(r, s, w+1);
        for (int i = 1; i < w-1; i++) r[i] = '.';
        puts(s);
        for (int i = 0; i++ < h-2;) puts(r);
        puts(s);
        puts("");
    }
    return 0;
}

Measured memory_bytes: 3224
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int A=0,B=0;
  rep(i,N){
    if(i%2){
      B += a.at(i);
    }else{
      A += a.at(i);
    }
  }
  cout << A - B << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  char X,Y;
  cin >> X >> Y;
  
  if (X-'0' < Y-'0'){
    cout << '<' << endl;
  }
  else if (X-'0' > Y-'0'){
    cout << '>' << endl;
  }
  else {
    cout << '=' << endl;
  }
}
  
 

Measured memory_bytes: 3628
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int num[] = new int[6];
		int answer = 0;
		String dec = "";
		diceClass dice =new diceClass();

		for (int i=0;i<6;i++){
			num[i] = scan.nextInt();
			dice.pos[i] = num[i];
		}
		dec = scan.next();
		char[] decChar = dec.toCharArray();
		for(int i=0;i<dec.length();i++){
			answer = dice.move(decChar[i]);
		}

		System.out.println(answer);
	}
}
class diceClass{	//?????????????????¢?????????????????´?????????
	int pos[] = new int[6];

	public void diceClass(){

	}
	
	public int move(char direction){
		int[] temp = (int[])pos.clone();
		if(direction == 'N'){
			pos[0] = temp[1];
			pos[1] = temp[5];
			pos[2] = temp[2];
			pos[3] = temp[3];
			pos[4] = temp[0];
			pos[5] = temp[4];
		}
		else if(direction == 'E'){
			pos[0] = temp[3];
			pos[1] = temp[1];
			pos[2] = temp[0];
			pos[3] = temp[5];
			pos[4] = temp[4];
			pos[5] = temp[2];
		}
		else if(direction == 'W'){
			pos[0] = temp[2];
			pos[1] = temp[1];
			pos[2] = temp[5];
			pos[3] = temp[0];
			pos[4] = temp[4];
			pos[5] = temp[3];
		}
		else if(direction == 'S'){
			pos[0] = temp[4];
			pos[1] = temp[0];
			pos[2] = temp[2];
			pos[3] = temp[3];
			pos[4] = temp[5];
			pos[5] = temp[1];
		}
		return pos[0];
	}
}

Measured memory_bytes: 26240