akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n);
  for (int i = 0;i<n;i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  ll sum = a[0]*2, last=0;
  for (int i = 1; i < n;i++){
    if(sum>=a[i]){
      sum += a[i] * 2;
    }else{
      last = i;
      sum += a[i]*2;
    }
    //cout << "sum=" << sum <<" last="<<last<< endl;
  }
  ans = n - last;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

const int MOD = 1e9 + 7;

int n,i,j,cnt[1005];

int main(){
	scanf("%d", &n);
	for(i = 2; i <= n; i++){
		int tmp = i;
		for(j = 2; j <= i; j++){
			while(tmp % j == 0){
				cnt[j]++;
				tmp /= j;
			}
		}
	}
	long long res = 1;
	
	for(i = 1; i <= n; i++)
	res = (res * (cnt[i] + 1)) % MOD;
	
	printf("%lld\n", res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define repf(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    ll n;
    cin>>n;
    ll a[n+1];
    repf(i,1,n+1) cin>>a[i];
    ll b[n+1];
    memset(b,0,sizeof b);
    bool f[n+1];
    memset(f,0,sizeof f);
    ll c=0;
    repb(i,n,1)
    {
        if(b[i]!=a[i]) 
        {
            b[i]+=1;
            f[i]=true;
            c++;
            for(ll j=1;j*j<=i;j++)
            {
                if(i%j==0)
                {
                    b[j]=(b[j]+1)%2;
                    if(j!=1 && j*j!=i) b[i/j]=(b[i/j]+1)%2;
                }
            }
        }
        // cout<<i<<" "<<b[1]<<" "<<b[2]<<" "<<b[3]<<" "<<b[4]<<endl;
    }
    cout<<c<<endl;
    repf(i,1,n+1)
    {
        if(f[i]) cout<<i<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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;
}

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  vector<int> B(M);
  rep(i, M) cin >> B[i];
  vector<vector<int>> A(N, vector<int>(M));
  rep(i, N) {
    rep(j, M) {
      cin >> A[i][j];
    }
  }

  int ans = 0;
  rep(i, N) {
    int temp = 0;
    rep(j, M) {
      temp += A[i][j] * B[j];
    }
    temp += C;
    if (temp > 0)
      ans++;
  }
  cout << ans << endl;
}

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

int main() {
  int N;
  cin >> N;
  map<string, int> polls;
  int max = 0;
  rep(i,N) {
    string S;
    cin >> S;
    polls[S]++;
  }
  
  for (auto p : polls) {
    if (p.second > max) max = p.second;
  }
  
  for (auto p : polls) {
    if (p.second == max) cout << p.first << "\n";
  }
  return 0;
}


Measured memory_bytes: 25216
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<cmath>
#include<cstring>
#include<climits>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
#define LL long long
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
inline int read() {
	bool f=0;int x=0;char c=getchar();
	while(c<'0'||'9'<c){if(c==EOF)exit(0);if(c=='-')f=1;c=getchar();}
	while('0'<=c&&c<='9') x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return !f?x:-x;
}
#define MAXN 15
#define INF 0x3f3f3f3f
#define Mod (int)(1e9+7)
int G[MAXN+5];
LL f[(1<<MAXN)+5];
int bitcnt(int x){
	int ret=0;
	while(x)
		ret++,x-=(x&(-x));
	return ret;
}
int main(){
	int n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read()-1,v=read()-1;
		G[u]|=(1<<v);
	}
	f[0]=1;
	for(int U=0;U<=(1<<n)-1;U++)
		if((U&1)==((U>>1)&1)){
			for(int S=U;S;S=(S-1)&U)
				if((S&1)==((S>>1)&1)){
					int T=U^S;
					LL cnt=1;
					for(int i=0;i<n;i++)
						if((U>>i)&1){
							if((S>>i)&1)
								cnt=(1ll<<bitcnt(G[i]&T))*cnt%Mod;
							else cnt=((1ll<<bitcnt(G[i]&S))-1)*cnt%Mod;
						}
					f[U]=(f[U]+cnt*f[T]%Mod)%Mod;
				}
		}
	LL sum=1;//
	for(int i=1;i<=m;i++)
		sum=(sum<<1)%Mod;
	printf("%lld\n",(sum-f[(1<<n)-1]+Mod)%Mod);
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>

#define ll long long
#define FOR(i,j,k) for(int i=j;i<=k;i++)
#define REV(i,j,k) for(int i=j,i>=k;i--)
#define min (long long) -1000000000000000
#define max (long long) 1000000000000000

using namespace std;

int main()
{
   double  a,b;
   cin>>a>>b;
   int c=a;
   int d=b;
   double f=(a+b)/2;

   int e=(c+d)/2;

   double p= f-e;
   if(p>=0.5)
   cout<<e+1;
   else cout<<e;

}



Measured memory_bytes: 256
#include <cstdio>

using namespace std;

#define MH 20
#define MW 20

char F[MH][MW];

int W, H;
bool input() {
    scanf("%d %d", &W, &H);
    if (W == 0 && H == 0) return false;
    for (int i = 0; i < H; i++) {
        scanf("%s", F[i]);
    }
    return true;
}

int dfs(int y, int x) {
    static const int dy[] = {0, 1, 0, -1},
                     dx[] = {1, 0, -1, 0};
    int count = 1;
    for (int i = 0; i < 4; i++) {
        int ny = y + dy[i],
            nx = x + dx[i];
        if (ny < 0 || ny >= H) continue;
        if (nx < 0 || nx >= W) continue;
        if (F[ny][nx] == '.') {
            F[ny][nx] = '@';
            count += dfs(ny, nx);
        }
    }
    return count;
}

void solve() {
    for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
            if (F[y][x] == '@') {
                printf("%d\n", dfs(y, x));
                return;
            }
        }
    }
}

int main() {
    while (input()) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1044
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		Integer[] a = new Integer[n];
		int num1 = 0;
		int num2 = 0;
		for(int i = 0;i < n;i++){
			a[i] = saori.saori_hayami();
		}
		Arrays.sort(a, Collections.reverseOrder());
		for(int i = 0;i < n;i++){
			if(i%2 == 0){
				num1 += a[i];
			} else {
				num2 += a[i];
			}
		}
		System.out.println(num1 - num2);
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 21204
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <ctime>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <memory.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long double LD;
typedef long long LL;
typedef pair<LL, LL> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#ifdef LOCAL
#define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
#define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/
const int MAXN = 2e5 + 10;
int nums[MAXN];

bool check(int n, int k, int length) {
  for (int i = 0; i < n && k >= 0; i++) {
    k -= nums[i] / length - 1;
    if (nums[i] % length != 0) k--;
  }
  return k >= 0;
}




int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cout.precision(10); cout << fixed;
#ifdef LOCAL
  freopen("../test.txt", "r", stdin);
    // freopen("../output.txt", "w", stdout);
#endif
  int n, k; cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> nums[i];
  }
  LL a = 1, b = 1e9;
  while (a < b) {
    LL mid = (a+b) >> 1;
    if (check(n, k, mid)) b = mid;
    else a = mid + 1;
  }
  cout << a << '\n';







/*---------------------------------------Coding Space End------------------------------------------*/
#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
#endif
  return 0;
}
/* author:  txingml */
/* picture is from hamayanhamayan(CF handle) */


Measured memory_bytes: 3980
//Graph

#include<stdio.h>
#define N 100

int main()
{
  int i,j,n,k,remain,l,b;
  int arr[N][N];
  
  //input data
  scanf("%d",&n);

  //initialize array
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  arr[i][j] = 0;
	}
    }

  //input line number
  //and,how many node does node connected?
  for(i = 0; i < n; i++)
    {
      scanf("%d %d",&l,&remain);

      l--;

      //input column number which has "1"
      for(j = 0; j < remain; j++)
	{
	  scanf("%d",&b);

	  b--;

	  arr[l][b] = 1;
	}
    }

  //output data
  for(i = 0; i < n; i++)
    {
      for(j = 0; j < n; j++)
	{
	  printf("%d",arr[i][j]);
	  if(j < n - 1) printf(" ");
	}
      printf("\n");
    }
  
  
  
  return 0;
}



Measured memory_bytes: 2112
N,M = map(int,input().split())
s = sorted([list(map(str,input().split())) for i in range(M)], key = lambda x: x[0])
for i in range(M):
    s[i][0] = int(s[i][0])
clear = 0
pena = 0
pena_pre = 0
if(M == 0):
    print("0 0")
else:
    problem = s[0][0]
    AC_flag = 0
    for i in range(M):
        if(s[i][0] != problem):
            problem = s[i][0]
            AC_flag = 0
            pena_pre = 0
        if(s[i][1] == "AC" and AC_flag == 0):
            clear += 1
            AC_flag = 1
            pena += pena_pre
            pena_pre = 0
        elif(s[i][1] == "WA" and AC_flag == 0):
            pena_pre += 1

    print(str(clear) + " " + str(pena))

Measured memory_bytes: 35412
#include <stdio.h>
#include <math.h>

int main(void){
  int n,a,b,c,i;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d%d%d",&a,&b,&c);

    if(a>b && a>c)
      printf( (a==sqrt(b*b+c*c)) ? "YES\n" : "NO\n");
    else if(b>c && b>a)
      printf( (b==sqrt(a*a+c*c)) ? "YES\n" : "NO\n");
    else
      printf( (c==sqrt(b*b+a*a)) ? "YES\n" : "NO\n");

  }

  return 0;
}

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

#ifdef ONLINE_JUDGE
#define endl "\n"
#endif
using namespace std;
typedef unsigned long long int lu;
typedef long long int ll;
typedef long double ld;
typedef vector <ll> v;
typedef vector <v> vv;
typedef vector <ld> vld;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef pair <ll, ll> pll;
typedef vector <pll> vpll;
const ll MOD = 1e9 + 7;
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
#define yes cout << "YES\n";
#define no cout << "NO\n";
#define yesno(f) \
    if (f)       \
        yes else no;
#define noo \
    { no return; }
#define amax(x, y) \
    if (y > x)     \
        x = y;
#define amin(x, y) \
    if (y < x)     \
        x = y;
#define sz(x) (ll) x.size()
#define sq(x) ((x) * (x))

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

template<typename T = ll>
vector <T> ga(ll n, bool oneIndexed = false) {
    vector <T> a = vector<T>(n + oneIndexed);

    for (ll i = 0; i < n; i++) {
        T p;
        cin >> p;
        a[i + oneIndexed] = p;
    }

    return move(a);
}

template<typename T, typename A>
void pa(vector < T, A >
const &a,
ll begin = 0, ll
end = -1
) {
if (end == -1)
end = sz(a) - 1;
for (
ll i = begin;
i <=
end;
i++) {
cout << a[i] << " ";
}
cout <<
endl;
}

void solve() {
    ll n;
    cin >> n;
    cout << fixed << setprecision(10) << n * n * n / (ld) 27.0;
}

int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    // ll t;cin >> t;while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define int long long
#define endl '\n'

int32_t main()
{
    IOS;
    int x;
    cin>>x;
    cout<<(x*360)/__gcd(x,(int)360)/x;
}


Measured memory_bytes: 3636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int sdkys(int a,int b){
    if(b==0) return a;
    return sdkys(b,a%b);
}
int sskbs(int a,int b){
    return a*b/sdkys(a,b);
}
int sosu(int a){
    if(a==2){
        return 1;
    }
    for(int i=2;i<sqrt(a)+1;i++){
        if(a%i==0){
            return 0;
        }
    }
    return 1;
}
vector<int> v;
int n,m,cnt=0,ans=0,aa[220000];
pair<int,int> pp[220000];
string s,ss[220000];
char ch;
double d[220000];
queue<int> que;
signed main(){
    cin>>n>>m>>cnt;
    if(n<0){
        if(abs(n)/cnt+1<=m){
            cout<<abs(n+abs(n)/cnt*cnt+(m-abs(n)/cnt)%2*cnt)<<endl;
        }else{
            cout<<abs(n+m*cnt)<<endl;
        }
    }else{
        if(n/cnt<=m){
            cout<<abs(n-(n/cnt)*cnt-(m-n/cnt)%2*cnt)<<endl;
        }else{
            cout<<n-m*cnt<<endl;
        }
    }
}

Measured memory_bytes: 10604
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007
//#define mod 998244353

int N;
signed main(){
    scanf("%lld",&N);
    int ans=0;
    for(int A=1;A<=N-1;A++){
        int B=(int)(N-1)/A;
        ans+=B;
    }
    printf("%lld\n",ans);
}

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

int main(){
	int n;
	cin >> n;
	vector<int> h(n+2);
	for(int i = 0; i < n; ++i){
		cin >> h[i];
	}
	vector<int> dp(n+2,INT_MAX);
	dp[0]=0;
	for(int i = 0; i < n;++i){
		dp[i+2] = min(dp[i] + abs(h[i] - h[i+2]), dp[i+2]);
		dp[i+1] = min(dp[i] + abs(h[i] - h[i+1]), dp[i+1]);
	}
	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024
# include <stdio.h>
int main()
{
	int a,b,c;
	while(scanf("%d",&a)!=EOF)
	{
		b=a;c=0;
		while(b)
		{
			c+=b%10;
			b=b/10;
		}
		if(a%c==0)printf("Yes\n");
		else printf("No\n");
	}
} 

Measured memory_bytes: 128
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())

G = [[] for i in range(N)]
indegree = [0] * N

for i in range(M):
  x,y = map(int,readline().split())
  G[x - 1].append(y - 1)
  indegree[y - 1] += 1
  
start = set()
for i in range(len(indegree)):
  if indegree[i] == 0:
    start.add(i)
    
cnt = 0
while start:
  nex = set()
  hasnext = False
  for s in start:
    for y in G[s]:
      indegree[y] -= 1
      if indegree[y] == 0:
        nex.add(y)
        hasnext = True
  if hasnext:
    cnt += 1
  start = nex

print(cnt)  
  

Measured memory_bytes: 27480
#include<cstdio>

int main()
{
	long long int n;
	while(scanf("%lld",&n)!=EOF)
	{
		if(n==0)break;
		int ans=0;
		for(int i=5;true;i*=5)
		{
			if((n-(n%i))/i==0)break;
			else
			{
				ans+=(n-(n%i))/i;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let h: usize = input();
    let w: usize = input();
    let n: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    let mut c = vec![vec![0; w]; h];
    let mut i = 0;
    let mut j = 0;
    for x in 0..n {
        let mut cnt = 0;
        while cnt < a[x] {
            c[i][j] = x + 1;
            cnt += 1;
            j += 1;
            if j == w {
                j = 0;
                i += 1;
            }
        }
    }

    for i in 0..h {
        if i % 2 > 0 {
            c[i].reverse();
        }
    }

    let out = std::io::stdout();
    let mut buf = std::io::BufWriter::new(out.lock());
    for i in 0..h {
        write!(buf, "{}", c[i][0]).unwrap();
        for j in 1..w {
            write!(buf, " {}", c[i][j]).unwrap();
        }
        writeln!(buf, "").unwrap();
    }
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    int A[N];

    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        sum += A[i];
    }

    vector<int> list;
    int cnt = 0;

    for(int i = 1; i<= sum; i++){
        if(sum % i == 0){
            list.emplace_back(i);
            cnt++;
        }
    }

    int ans = 0;
    for(int i = cnt-1; i >= 0; i--){
        int p[N];
        int n[N];
        int rev[N];
        int divsum = 0;
        for(int j = 0; j<N; j++){
            rev[j] = A[j] % list[i];
        }

        sort(rev, rev + N);


        p[0] = rev[0];
        for(int j = 0; j < N-1; j++){
            p[j +  1] = p[j] + rev[j+1];
        }

        n[N-1] = list[i] - rev[N-1];
        for(int j = N-1; j>0; j--){
            n[j-1] = n[j] + list[i] - rev[j-1];
            if(n[j] == p[j-1]){
                divsum = n[j];
            }
        }

        if(divsum <=K){
            ans = list[i];
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int L[500000/2+2],R[500000/2+2],count=0,n;

void merge(int A[],int left,int mid,int right){
	int n1,n2,i,j,k,s,t;
	n1=mid-left;
	n2=right-mid;
	for(i=0;i<n1;i++)
		L[i]=A[left+i];
	for(i=0;i<n2;i++)
		R[i]=A[mid+i];
	L[n1]=2000000000;
	R[n2]=2000000000;
	i=j=0;
	for(k=left;k<right;k++){
		count++;
		if(L[i]<=R[j]){
			s=A[k];
			A[k]=L[i];
			L[i]=s;
			i=i+1;
		}
		else{
			t=A[k];
			A[k]=R[j];
			R[j]=t;
			j=j+1;
		}
	}
}

void mergeSort(int A[],int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,left,mid);
		mergeSort(A,mid,right);
		merge(A,left,mid,right);
	}
}

int main(){
	int i,A[500000];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	mergeSort(A,0,n);
	for(i=0;i<n;i++){
		printf("%d",A[i]);
		if(i<n-1)
			printf(" ");
	}
	printf("\n%d\n",count);
	return 0;
}


Measured memory_bytes: 5608
n = int(input())
A = [*map(int, input().split())]
mx = max(A)
c = [0]*(mx+1)
l = [0]*(mx+1)
for a in A:
    c[a] += 1
    for i in range(a*2, mx+1, a): l[i] = 1
ans = 0
for a in A:
    if not l[a] and c[a] <= 1: ans += 1
print(ans)


Measured memory_bytes: 34936
//
//  main.cpp

#include <iostream>
using namespace std;
const int White = 0;
const int Red = 1;
const int Blue = 2;

int main(){
	int n,m;
	int color[51][4];
	for(int i=0;i<51;i++){
		for(int j=0;j<4;j++){
			color[i][j] = 0;
		}
	}
	
	string input[51];
	cin >> n >> m;
	for(int i=1;i<=n;i++){
		cin >> input[i];
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			switch(input[i][j-1]){
				case 'W':
					color[i][White] ++;
					break;
				case 'B':
					color[i][Blue] ++;
					break;
				case 'R':
					color[i][Red] ++;
					break;
			}
		}
	}
	int answer = 1000000;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			for(int k=1;k<=n;k++){
				if(i+j+k != n)continue;
				int white,blue,red;
				white = blue = red = 0;
				for(int w=1;w<=i;w++){
					white += color[w][Blue] + color[w][Red];
				}
				for(int b=i+1;b<=i+j;b++){
					blue += color[b][White] + color[b][Red];
				}
				for(int r=i+j+1;r<=i+j+k;r++){
					red += color[r][Blue] + color[r][White];
				}
				
				answer = min(answer,white+blue+red);
				
			}
		}
	}
	
	cout << answer << endl;
	return 0;
}

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

using namespace std;



int main(){


	int n; cin >> n;

	vector < pair <int, int> > h(n);


	for(int i = 0; i < n; i++){
		cin >> h[i].first;

		h[i].second = i;
	}


	sort(h.begin(), h.end());


	for(int i = 0; i < n; i++){
		cout << h[i].second + 1 << " ";
	}
	cout << endl;






	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> X(N,vector<int>(2));
  for (int i=0;i<N;i++){
    cin >> X[i][0];
    X[i][1]=i;
  }
  sort(X.begin(),X.end());
  map<int,int> m;
  for (int i=0;i<N;i++){
    m[X[i][1]]=i;
  }
  for (int i=0;i<N;i++){
    if (m[i]<N/2){
      cout << X[N/2][0] << endl;
    }
    else {
      cout << X[N/2-1][0] << endl;
    }
  }
}

Measured memory_bytes: 22528
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  ll n,h,w,ans=0,a,b;
  cin>>n>>h>>w;
  while(n--){
    cin>>a>>b;
    if(h<=a && w<=b){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
//Author : pakhandi
//
using namespace std;

#include <bits/stdc++.h>

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int

#define IGNORE cin.ignore (std::numeric_limits<std::streamsize>::max(), '\n');

const ll INF = (1LL << 58);

#ifdef BUGGY
	bool DEBUG = 1;
#endif
#ifndef BUGGY
	bool DEBUG = 0;
#endif

const int MAX_LIMIT = 100005;

int cumAns[MAX_LIMIT], isAns[MAX_LIMIT];
int queries;

bool isPrime[MAX_LIMIT];
std::vector<int> prime;
void sieve()
{
	int limit = MAX_LIMIT, i, j;
	memset(isPrime, 0, sizeof(isPrime));
	for(i = 2; i < limit + 1; i++)
		isPrime[i] = 1;

	int inLimit = sqrt(limit);
	inLimit++;

	for(i = 2; i < inLimit; i++)
	{
		if(isPrime[i]==1)
		{
			for(j=i*i; j<limit; j+=i)
				isPrime[j] = 0;
		}
	}

	for(i = 2; i < MAX_LIMIT; i++)
		if(isPrime[i])
			prime.push_back(i);

	return;
}

int main()
{
	sieve();

	for(int i = 1; i < 100005; i+=2) {
		if(isPrime[i] && isPrime[(i + 1) / 2]) {
			isAns[i] = 1;
		}
	}

	for(int i = 1; i < MAX_LIMIT; i++) {
		cumAns[i] = cumAns[i - 1] + isAns[i];
	}

	scanf("%d", &queries);

	while(queries--) {
		int l , r;
		scanf("%d %d", &l, &r);

		int ans = cumAns[r] - cumAns[l - 1];
		printf("%d\n", ans);
	}

	return 0;
}
/*
	Powered by Buggy Plugin
*/

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

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

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

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

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

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    sort(a.begin(), a.end());
    vll b(n / 2), c(n / 2);

    if (n % 2) {
        vll sum(4, 0);

        for (int i = 0; i < n / 2; i++) {
            b[i] = a[i];
            c[i] = a[i + n / 2 + 1];
        }

        ll t = a[n / 2];

        for (int i = 0; i < n / 2; i++) {
            sum[0] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[0] += abs(b[i] - c[i + 1]);
            }
            if (i == 0) {
                sum[0] += abs(t - c[i]);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[1] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[1] += abs(b[i] - c[i + 1]);
            } else {
                sum[1] += abs(b[i] - t);
            }
        }

        sort(b.begin(), b.end(), greater<ll>());

        for (int i = 0; i < n / 2; i++) {
            sum[2] += abs(b[i] - c[i]);

            if (i + 1 < n / 2) {
                sum[2] += abs(c[i] - b[i + 1]);
            } else {
                sum[2] += abs(c[i] - t);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[3] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[3] += abs(b[i] - c[i + 1]);
            } else {
                sum[3] += abs(b[i] - t);
            }
        }

        cout << *max_element(sum.begin(), sum.end()) << endl;

    } else {
        vll sum(4, 0);

        for (int i = 0; i < n / 2; i++) {
            b[i] = a[i];
            c[i] = a[i + n / 2];
        }

        for (int i = 0; i < n / 2; i++) {
            sum[0] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[0] += abs(b[i] - c[i + 1]);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[1] += abs(b[i] - c[i]);

            if (i + 1 < n / 2) {
                sum[1] += abs(c[i] - b[i + 1]);
            }
        }

        sort(b.begin(), b.end(), greater<ll>());

        for (int i = 0; i < n / 2; i++) {
            sum[2] += abs(c[i] - b[i]);

            if (i + 1 < n / 2) {
                sum[2] += abs(b[i] - c[i + 1]);
            }
        }

        for (int i = 0; i < n / 2; i++) {
            sum[3] += abs(b[i] - c[i]);

            if (i + 1 < n / 2) {
                sum[3] += abs(c[i] - b[i + 1]);
            }
        }

        cout << *max_element(sum.begin(), sum.end()) << endl;
    }
}

Measured memory_bytes: 1792
#!/usr/bin/env python3

import sys

DEBUG = False

def read(t):
    return t(sys.stdin.readline().rstrip())


def read_list(t, sep = " "):
    return [t(s) for s in sys.stdin.readline().rstrip().split(sep)]


def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return


def main():
    n = read(int)
    ans = 0
    for i in range(1, n + 1):
        if i % 3 != 0 and i % 5 != 0:
            ans += i
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 67176
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datA,datB,datC,datD) = readLine.split(" ").map(_.toLong)

    val ans = Array(datA * datC, datA * datD, datB * datC, datB * datD).max
    println(ans)
  }
}


Measured memory_bytes: 54800
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/quo.hpp
#ifndef QUO_H
#define QUO_H

/*
a == tools:quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T quo(const T lhs, const T rhs) {
    return lhs > 0 ? lhs / rhs : rhs > 0 ? -((-lhs - 1 + rhs) / rhs) : (-lhs - 1 + -rhs) / -rhs;
  }
}

#endif

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/mod.hpp
#ifndef MOD_HPP
#define MOD_HPP


/*
a == tools:quo(a, b) * b + tools::mod(a, b)
0 <= tools::mod(a, b) < std::abs(b)
*/

namespace tools {
  template <typename T>
  constexpr T mod(const T lhs, const T rhs) {
    return lhs - quo(lhs, rhs) * rhs;
  }
}

#endif

// main.cpp

int main() {
  i64 A, B;
  std::cin >> A >> B;
  if (tools::mod<i64>(A + B, 2) == 0) {
    std::cout << (A + B) / 2 << std::endl;
  } else {
    std::cout << "IMPOSSIBLE" << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> grh;
vector<int> ord;
vector<int> low;
vector<int> prt;
vector<bool> is_art;
int cnt = 0;
void dfs(int s) {
  for (int t : grh[s]) {
    if (t == prt[s]) {
      continue;
    } else if (prt[t] != -1) {
      low[s] = min(low[s], ord[t]);
    } else {
      if (s == 0 && cnt > 0) {
        is_art[0] = true;
      }
      prt[t] = s;
      ord[t] = ++cnt;
      low[t] = cnt;
      dfs(t);
      low[s] = min(low[s], low[t]);
      if (s != 0 && ord[s] <= low[t]) {
        is_art[s] = true;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  grh.resize(n);
  for (int i = 0; i < m; i++) {
    int s, t;
    cin >> s >> t;
    grh[s].push_back(t);
    grh[t].push_back(s);
  }
  ord.resize(n, 0);
  low.resize(n, 0);
  prt.resize(n, -1);
  is_art.resize(n, false);
  prt[0] = 0;
  dfs(0);
  for (int i = 0; i < n; i++) {
    if (is_art[i]) {
      cout << i << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 4684
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
using namespace std;
const int maxd=1000000007,N=100000;
const double pi=acos(-1.0);
typedef long long ll;
ll n,k,cnt[100100],powe[100],num[100100];

ll read()
{
	ll x=0,f=1;char ch=getchar();
	while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
	while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
	return x*f;
}

void calc(ll x)
{
	int i=0;
	while (x)
	{
		i++;
		int tmp=x%2;x/=2;
		cnt[i]+=tmp;
	}
}

int main()
{
    n=read();k=read();
    memset(cnt,0,sizeof(cnt));
    int i;
    for (i=1;i<=n;i++)
    {
    	num[i]=read();
    	calc(num[i]);
    }
    powe[1]=1;
    for (i=2;i<=60;i++) powe[i]=powe[i-1]<<1;
    //for (i=1;i<=5;i++) cout << powe[i] << " ";cout << endl;
    ll ans=0;
    int sam=(n+1)/2;
    for (i=60;i>=0;i--)
    {
    	if (cnt[i]>=sam) continue;
    	if (ans+powe[i]>k) continue;
    	ans+=powe[i];
    }
    ll sum=0;
    for (i=1;i<=n;i++) sum+=(ans^num[i]);
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
inline int read() {
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9') {
        if (ch=='-') f=-1;
        ch=getchar();
    }
    while (ch>='0'&&ch<='9') {
        x=(x*10)+(ch-'0');
        ch=getchar();
    }
    return x*f;
}
int main(){
	int n=read(),m=read(),k=read();
	for (register int i=0;i<=n;++i){
		for (register int j=0;j<=m;++j){
			if (i*m+j*n-i*j-i*j==k){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <queue>
#include <vector>
#define ll long long
const int N=1e6+10;
using namespace std;
int n,k;
int sc[N];
string t;
int ans=0;
int main() {
 cin>>n>>k;                            
 cin>>sc['s']>>sc['p']>>sc['r'];
 cin>>t;
for(int i=0;i<n;i++){
    if(i-k>=0 && t[i-k]==t[i]){
        t[i]='#';
        continue;
    }
    ans+=sc[t[i]];
}
  cout<<ans<<endl;
    return 0;
}

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

using namespace std;

int main(){
	#ifdef EVAL
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int N;
	cin >> N;
	vector <int> v(N);
	long long int s = 0;
	for(int &i : v){
		cin >> i;
		s += i;
	}
	long long int cur = 0,ans = LLONG_MAX;
	for(int i = 0; i < N - 1; i++){
		s -= v[i];
		cur += v[i];
		ans = min(ans,abs(cur - s));
	}
	cout << ans;
}

Measured memory_bytes: 1024
#include <string>
#include <iostream>

using namespace std;

int main(void){
    string S;
    string T;
    
    cin >> S;
    cin >> T;

    int n = S.length();
    int k = T.length();

    int ans = 1e9;

    for(int i=0; i < n - k + 1; i++){
        int ret = 0;
        for(int j=0; j < k; j++){
            if(T[j] != S[i+j]){
                ret++;
            }
        }
        ans = min(ans,ret);
    }

    cout << ans << endl;

    return 0;
}

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

                            typedef long long ll;
                            typedef double ld;
                            #define rep(i,a,n) for(ll i=(a); i<(n); i++)
                            #define per(i,a,n) for(ll i=(n-1); i>=(a); i--)
                            #define F first
                            #define S second
                            #define maxx(a,b) a=max(a,b)
                            #define minn(a,b) a=min(a,b)
                            #define db(x) cerr<<#x<<" = "<<x<<endl
                            #define N 1111111
                            #define mod 1000000007
                            #define rt return
                            #define inf 1000000000

                            using namespace std;

                            ll dp[3456][3456],a[3456];

                            ll getmax(ll l, ll r)
                            {
                                if(l==r)rt dp[l][r]=a[l]-a[l-1];
                                if(dp[l][r])rt dp[l][r];
                                rt dp[l][r]=max(a[r]-a[l-1]-getmax(l+1,r),a[r]-a[l-1]-getmax(l,r-1));
                            }

                            int main(){

                                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

                                //freopen("Ulug'bek","r",stdin);
                                //freopen("Abdimanabov","w",stdout);

                               int n; cin>>n;
                               ll s=0;
                               rep(i,1,n+1)cin>>a[i],a[i]+=a[i-1];

                               cout<<getmax(1,n)-(a[n]-getmax(1,n));

                            rt 0;
                            }



















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

int main(){
    string s;
    int y=0,m=0,d=0;
    cin>>s;

    y+= (s[0]-'0')*1000 + (s[1]-'0')*100 + (s[2]-'0')*10 + s[3]-'0';
    
    m += (s[5]-'0')*10 + s[6]-'0';
    
    d+= (s[8]-'0')*10 + s[9]-'0';
    
    pair<int,pair<int,int> >p1,p2;
    p1 = make_pair(y,make_pair(m,d));
    p2 = make_pair(2019,make_pair(4,30));
    
   if( p1<=p2)
    puts("Heisei");
    else puts("TBD");
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust" << endl;
    else
        cout << "win" << endl;
    GAME_OVER;
}

Measured memory_bytes: 256
import time
start = time.time()
N = int(input())
A = [list(map(lambda x:int(x)-1,input().split())) for i in range(N)]
B = [0]*N
S = 0
ans = 0
while True:
    C = [0]*N
    for n in range(N):
        if C[n]==0 and B[n]!=N-1:
            b = A[n][B[n]]
            if C[b]==1: continue
            if A[b][B[b]]==n:
                B[n]+=1
                B[b]+=1
                C[n],C[b]=1,1
    if sum(C)==0:break
    ans +=1
    if time.time()-start>1.7:
        print(N*(N-1)//2)
        exit()
print(ans if sum(B)==N*(N-1) else -1)

Measured memory_bytes: 35056
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int digit_100, digit_10, digit_1;
  
  // 変数aで入力を受け取る
  cin >> a;
  
  digit_100 =  a / 100 ;
  digit_10 = (a - 100* digit_100) / 10;
  digit_1 = (a - 100 * digit_100 -10 * digit_10) /1;
  
  cout << digit_100 + digit_10 + digit_1<< endl;
}

Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>

#define ll long long int
#define MOD 1000000007
#define pb push_back
#define ub upper_bound
#define lb lower_bound

using namespace std;

int main(){
    int n,p;
    int j=0;
    int p_cnt[51];
    int table=0;
    while(1){
        for(int i=0;i<51;i++){
            p_cnt[i]=0;
        }
        cin >> n >> p;
        table=p;
        if(n==0||p==0){
            break;
        }
        j=0;
        while(1){
            if(table==0&&p_cnt[j]==p){
                cout << j << endl;
                break;
            }
            if(table!=0){
                table--;
                p_cnt[j]++;
            }
            else{
                table=p_cnt[j];
                p_cnt[j]=0;
            }
            if(j<n-1){
                j++;
            }
            else if(j==n-1){
                j=0;
            }
        }
    }
    return 0;
}



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

using namespace std;

int n;
char str[6050];
string dp[6050];
int a[3050],b[3050],ink[6050];

int main()
{
	scanf("%d",&n);
	scanf("%s",str + 1);
	int ac = 0,bc = 0;
	for(int i = 1;i <= 2 * n; ++ i)
	{
		if(str[i] == 'a')
			a[++ ac] = i,ink[i] = ac;
		else
			b[++ bc] = i,ink[i] = bc;
	}
	for(int i = n;i >= 1; -- i)
	{
		dp[i] = dp[i + 1];
		if(a[i] < b[i])
		{
			int fk = i;
			for(int j = a[i] + 1;j < b[i]; ++ j)
				if(str[j] == 'a')
					fk = max(fk,ink[j]);
			dp[i] = max(dp[i],"ab" + dp[fk + 1]);
		}
		else
		{
			int fk = i; bool mark[6050] = {0};
			int r = a[i];
			mark[b[i]] = mark[a[i]] = 1;
			for(int j = b[i] + 1;j <= r; ++ j)
				if(str[j] == 'b')
					mark[j] = mark[a[ink[j]]] = 1,
					r = max(r,a[ink[j]]);
			string tmp = "";
			for(int j = b[i];j <= 2 * n; ++ j)
				if(mark[j]) (tmp = tmp + str[j]);
			int zjk = i + 1;
			while(zjk <= n && min(a[zjk],b[zjk]) <= r) zjk ++;
			dp[i] = max(dp[i],tmp + dp[zjk]);
		}
	}
	cout << dp[1] << endl;
}

Measured memory_bytes: 20136
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <utility> 
#include <tuple>
#include <iterator>
#include <functional>
using namespace std;
#define rep(i,n) for(long i=0; i<n; i++)





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

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.io.*;

/**
 * Copyright © 2018 Chris. All rights reserved.
 *
 * @author Chris
 * 2018/6/23 11:55
 * @see meituan.n2018.Bturn
 */
public class Main {


    private static BufferedReader br;
    private static StreamTokenizer st;
    private static PrintWriter pw;


    private static void solve() throws IOException {
        int h = nextInt();
        int w = nextInt();
        
        char a[][] = new char[h][w];
        for (int i = 0; i < h; i++) {
            a[i] = nextLine().toCharArray();
        }
        
        boolean vstH[] = new boolean[h];
        boolean vstW[] = new boolean[w];

        for (int i = 0; i < h; i++) {
            boolean flag = true;
            for (int j = 0; j < w; j++) {
                if (a[i][j] == '#') {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                vstH[i] = true;
            }
        }
        for (int i = 0; i < w; i++) {
            boolean flag = true;
            for (int j = 0; j < h; j++) {
                if (a[j][i] == '#') {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                vstW[i] = true;
            }
        }

        for (int i = 0; i < h; i++) {
            if (vstH[i]) {
                continue;
            }
            for (int j = 0; j < w; j++) {
                if (!vstW[j]) {
                    pw.print(a[i][j]);
                }
            }
            if (i < h - 1) {
                pw.println();
            }
        }
    }

    public static void main(String args[]) throws IOException {
//        boolean oj = System.getProperty("ONLINE_JUDGE") != null;
//        if (!oj) {
//            System.setIn(new FileInputStream("src/in.txt"));
//        }
        br = new BufferedReader(new InputStreamReader(System.in));
        st = new StreamTokenizer(br);
        pw = new PrintWriter(new OutputStreamWriter(System.out));
        st.ordinaryChar('\''); //指定单引号、双引号和注释符号是普通字符
        st.ordinaryChar('\"');
        st.ordinaryChar('/');

        long t = System.currentTimeMillis();
        solve();
//        if (!oj) {
//            pw.println("[" + (System.currentTimeMillis() - t) + "ms]");
//        }
        pw.flush();
    }


    private static int nextInt() throws IOException {
        st.nextToken();
        return (int) st.nval;
    }

    private static long nextLong() throws IOException {
        st.nextToken();
        return (long) st.nval;
    }

    private static double nextDouble() throws IOException {
        st.nextToken();
        return st.nval;
    }

    private static String[] nextSS(String reg) throws IOException {
        return br.readLine().split(reg);
    }

    private static String nextLine() throws IOException {
        return br.readLine();
    }
}

Measured memory_bytes: 23892
#include <stdio.h>
int par[100001];
int hei[100001];
int degree[100001];
int ans[100001];
int find(int x){
	if(par[x]!=x) return par[x]=find(par[x]);
	else return x;
}
int uni(int a, int b){
	a=find(a);
	b=find(b);
	if(a!=b){
		par[b]=a;
		hei[a]+=hei[b];
		return 1;
	}
	else return 0;
}

int main(){
	int N,M,K;
	scanf("%d %d %d",&N,&M,&K);
	for(int i=1;i<=N;i++){
		par[i]=i;
		hei[i]=1;
	}
	for(int i=0;i<M;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		uni(a,b);
		degree[a]++;
		degree[b]++;
	}
	for(int i=1;i<=N;i++) ans[i] = hei[find(i)]-1-degree[i];
	for(int i=0;i<K;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		if(find(a)==find(b)){
			ans[a]--;
			ans[b]--;
		}
	}
	for(int i=1;i<=N;i++) printf("%d ",ans[i]);
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define loop(i, a, b) for(lli i=a; i<b; i++)
#define loopb(i, a, b) for(lli i=a; i>=b; i--)
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
#define pb push_back
typedef long long int lli;
typedef pair<lli, lli> pii;
typedef vector<lli> vll;
#define umap unordered_map
#define all(x) x.begin(), x.end()
// use to avoid collision
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
// for pair in unordered_map
struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
lli M = 1e9 + 7;
lli power(lli x, lli y){
    lli res = 1;
    x = x%M;
    while (y > 0) {
        if (y & 1)
            res = (res*x)%M ;
        y = y>>1;
        x = (x*x)%M ;
    }
    return res%M;
}
lli solve(){
    string s, t;
    cin>>s>>t;
    lli n = s.length();
    lli m = t.length();
    lli dp[3002][3002];
    memset(dp, 0, sizeof(dp));
    loop(i, 1, n+1){
        loop(j, 1, m+1){
            if(s[i-1] == t[j-1])
                dp[i][j] = max(dp[i-1][j], max(dp[i][j-1], dp[i-1][j-1]+1));
            else
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    string res;
    lli i = n;
    lli j = m;
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i][j-1])
            j--;
        else if(dp[i][j] == dp[i-1][j])
            i--;
        else{
            res.push_back(s[i-1]);
            i--;
            j--;
        }
    }
    reverse(res.begin(), res.end());
    cout<<res<<"\n";
    return 0;
}
int main(){
    fastio;
    lli t;
	// cin>>t;
    t = 1;
    while(t>0){ 
        t--;
        solve();
    }
}

Measured memory_bytes: 74092