akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define PI pair<int,int>
#define poly vector<ll>
#define For(i,l,r) for(int i=(int)(l);i<=(int)(r);i++)
#define Rep(i,r,l) for(int i=(int)(r);i>=(int)(l);i--)
#define pb push_back
#define fi first
#define se second
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
inline ull rnd(){
	return ((ull)rand()<<30^rand())<<4|rand()%4;
}
const int N=200005;
int k,A[N],lx[N],rx[N],a[N],nxt[N],pre[N];
ll ycl[N];
priority_queue<PI,vector<PI>,greater<PI> > q;
ll solve(int l,int r){
	r=nxt[r];
	int dq=l;
	ll ans=0;
	int sum=0;
	For(i,1,k-1){dq=nxt[dq]; ans++; if(dq==r)return ans;}
	while(dq!=r){
		sum+=lx[l]; l=nxt[l]; 
		ans+=(ll)sum*rx[dq]+1;
		dq=nxt[dq];
	}
	return ans;
}
int main(){
	int n=read(); k=read();
	For(i,k,n)ycl[i]=ycl[i-1]+(i-k+1);
	For(i,1,n){
		a[i]=read(); lx[i]=1; rx[i]=1;
	}
	nxt[0]=1; pre[n+1]=n;
	For(i,1,n){pre[i]=i-1; nxt[i]=i+1; q.push(mp(a[i],i)); }
	//For(i,1,n)wri(ycl[i]); puts("");
	ll ans=0;
	while(q.size()){
		PI t=q.top();  q.pop();
		int l=t.se,r=l,cnt=1;
		while(a[nxt[r]]==a[l]){r=nxt[r]; cnt++; q.pop(); } 
		//cout<<q.size()<<" "<<cnt<<" "<<t.fi<<" "<<t.se<<" "<<l<<" "<<r<<" "<<" "<<ycl[cnt]<<endl;
		l=pre[l]; r=nxt[r];
		ans+=solve(nxt[l],pre[r]);
		if(cnt<k)continue;
		int zs=cnt,jb=l;
		zs-=k; For(i,1,k)jb=nxt[jb];
		For(i,1,cnt/k){
			int meiju=min(k,zs+1);
			rx[l+i]=0; For(j,1,meiju){rx[l+i]+=rx[jb]; jb=nxt[jb];} zs-=k;
		}
		zs=cnt-k; jb=r; For(i,1,k)jb=pre[jb];
		Rep(i,cnt/k,1){
			int meiju=min(k,zs+1);
			A[i]=0; For(j,1,meiju){A[i]+=lx[jb]; jb=pre[jb];} zs-=k;
		}
		For(i,1,cnt/k)lx[l+i]=A[i];
		For(i,1,cnt/k){nxt[l+i]=l+i+1; pre[l+i]=l+i-1; a[l+i]=t.fi+1; q.push(mp(a[l+i],l+i));}
		nxt[l]=l+1; pre[r]=l+cnt/k; nxt[l+cnt/k]=r;
		//cout<<ans<<endl;
		ans-=solve(nxt[l],pre[r]);
		//For(i,1,cnt/k)wri(lx[l+i]); puts("");
		//cout<<ans<<" "<<nxt[jb]<<" "<<pre[r]<<endl;
	}
	cout<<ans<<endl;
}

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

int main() {
  
  int sum = 0;
  
  rep(i,4) {
    char a;
    cin >> a;
    if(a == '+') sum += 1;
    else sum -= 1;
  }
  
  cout << sum << endl;
  
  
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
     
    #define pb push_back
     
    const int mn=39;
    typedef long long ll;
     
    int n;
    char s[mn];
     
    unordered_map<size_t,int> h;
    hash<string> hs;
     
    string t;
    inline size_t gethash(string &s){
        return hs(s);
    }
     
    int main() {
        scanf("%d",&n);
        scanf("%s",s);
     
        ll ans=0;
     
        for(int i=0;i<(1<<n);i++){
            t.clear();
            for(int j=0;j<n;j++){
                if ((1<<j)&i) t+=s[j];
            }
            for(int j=n-1;j>=0;j--){
                if (((1<<j)&i)==0) t+=toupper(s[j]);
            }
            h[gethash(t)]++;
        }
     
        reverse(s,s+n*2);
        for(int i=0;i<(1<<n);i++){
            t.clear();
            for(int j=0;j<n;j++){
                if ((1<<j)&i) t+=s[j];
            }
            for(int j=n-1;j>=0;j--){
                if (((1<<j)&i)==0) t+=toupper(s[j]);
            }
            ans+=h[gethash(t)];
        }
        printf("%lld\n",ans);
        return 0;
    }

Measured memory_bytes: 28788
s = input()
X, Y = map(int, input().split())
fs = s.split("T")
nsx = list(map(len, fs[0::2]))
nsy = list(map(len, fs[1::2]))
ssx = []
ssx.append({ 0 })
ssx.append({ nsx[0] })
for i in range(1, len(nsx)):
  s = ssx[i]
  n = nsx[i]
  s2 = set()
  for x in s:
    s2.add(x+n)
    s2.add(x-n)
  ssx.append(s2)
#print(ssx)
ssy = [{ 0 }]
for i in range(0, len(nsy)):
  s = ssy[i]
  n = nsy[i]
  s2 = set()
  for y in s:
    s2.add(y+n)
    s2.add(y-n)
  ssy.append(s2)
#print(ssy)
if X in ssx[-1] and Y in ssy[-1]:
  print("Yes")
else:
  print("No")


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    for(int i=0; i<s.size(); i+=2){
        cout<<s[i];
    }cout<<endl;
    return 0;
}


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

const int MAX_N = 300000;
vector<int> prime;
bool is_prime[MAX_N+1];

int main(void) {

    for (int i = 0; i <= MAX_N; i++) is_prime[i] = true;
    is_prime[0] = is_prime[1] = false;
    for (int i = 2; i <= MAX_N; i++) {
        if (is_prime[i] && (i%7 == 1 || i%7 == 6)) {
            prime.push_back(i);
            for (int j = 2*i; j <= MAX_N; j+=i) is_prime[j] = false;
        }
    }

    int n;
    while (cin >> n) {
        if (n == 1) break;

        cout << n << ":";
        for (auto d : prime) {
            if (n % d == 0) cout << " " << d;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3428
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i,m, n) for(int i = m; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<int>(n,a)));
typedef long long ll;
const int INF = 2000000000;
const long INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
long ggd(long a, long b) {//最小公倍数，最大公約数
	if(a<b)swap(a,b);
	if (b == 0) {
		return a;			
	}
	return ggd(b, a % b);
}
long lcm(long number1,long number2){
	return number1/ggd(number1,number2)*number2;	
}

int main(){
    int n;
    std::cin >> n;
    std::vector<ll> a(n);
    rep(i,n)std::cin >> a[i];
    ll ans=1;
    rep(i,n){
        ans=lcm(ans,a[i]);
    }
    std::cout << ans << std::endl;
}

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

using namespace std;


long long gcd2(long long x,long long y) {
    if(y == 0) return x;
    return gcd2(y,x % y);
}

long long lcm2(long long x,long long y) {
    return x / gcd2(x,y) * y;
}

int main() {
    int a,b;
    cin >> a >> b;
    cout << lcm2(a,b) << "\n";
    return 0;
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MAX_V 100000

#define MOD 1000000007L
#define INF 2147483647

signed main() {
	string s;
	cin >> s;
	cout << (s.find("9") == string::npos ? "No" : "Yes") << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
x = list(map(int, input().split()))

ans = 10 ** 9

for i in range(n-k+1):

    l = abs(x[i]) + abs(x[i+k-1] - x[i])
    r = abs(x[i+k-1]) + abs(x[i+k-1] - x[i])

    if l < r:
        ans = min(ans, l)
    else:
        ans = min(ans, r)

print(ans)

Measured memory_bytes: 14252
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>
#include <iterator>

typedef long long ll;
typedef unsigned long long ull;
constexpr ll mop = 1000000007;
constexpr ll mop2 = 998244353;

using namespace std;


ll check(vector<ll> v, vector<vector<ll>>& Qs) {
	ll rev = 0;
	for (ll i = 0; i < Qs.size(); i++) {
		ll a = Qs[i][0] - 1;
		ll b = Qs[i][1] - 1;
		ll c = Qs[i][2];
		ll d = Qs[i][3];
		if (v[b] - v[a] == c) {
			rev += d;
		}
	}
	return rev;

}


int main() {
	ll n,m,Q;
	cin >> n >> m >> Q;
	vector<vector<ll>> Qs(Q);
	for (ll i = 0; i < Q; i++) {
		Qs[i].resize(4);
		cin >> Qs[i][0] >> Qs[i][1] >> Qs[i][2] >> Qs[i][3];
	}
	
	string s;
	for (ll i = 0; i < m - 1; i++) {
		s += '0';
	}
	for (ll i = 0; i < n; i++) {
		s += '1';
	}
	ll ans = 0;
	do {
		vector <ll> v;
		ll now = 1;
		ll j = 0;
		while (j < n + m - 1) {
			if (s[j] == '1') {
				v.push_back(now);
			}
			else {
				now++;
			}
			j++;
		}
		ll tmp = check(v, Qs);
		if (ans < tmp) {
			ans = tmp;
		}

	} while (next_permutation(s.begin(), s.end()));
	cout << ans << endl;
}


Measured memory_bytes: 3600
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(n):
    if i!=n-1:
        if p[i]==i+1:
            d=p[i+1]
            p[i+1]=p[i]
            p[i]=d
            c+=1
    else:
        if p[i]==i+1:
            c+=1
print(c)

Measured memory_bytes: 13880
#include <bits/stdc++.h>
# define ll int64_t
#define rep(i,n) for(ll i=0;i<n;i++)
#define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

int main(){
    ll n,maxi=-10000000;
    ll sum=0;
    cin>>n;
    vector<ll> a(n),b(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    
    rep(i,n){
        rep(k,n){
            if(k<i) sum+=a[k];
            else if(k==i) sum=sum+a[k]+b[k];
            else if(k>i) sum+=b[k];
        }
        if(sum>=maxi) maxi=sum;
        sum=0;
    }
    cout<<maxi<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;



int main(){
	int l,r,d;
	cin>>l>>r>>d;
	int x=l/d,y=r/d;
	if(l%d==0)x--;
	cout<<y-x;
    return 0;
}

Measured memory_bytes: 3632
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main(){
	auto Q=readln.split.to!(int[]),A=Q[0],B=Q[1],C=Q[2],D=Q[3];
	if(A*B>C*D)writeln(A*B);
	else writeln(C*D);

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>//random,NULL
#include <string.h>
#include <time.h>
#include <unistd.h>//sleep()
#include <math.h>
#include <stdbool.h>

#define rep(i,n) for(int i=0; i<((int)n); i++)
#define REP(i,n) for(int i=0; i<=((int)n); i++)
#define srep(i,a,n) for(int i=a; i<((int)n); i++)
#define SREP(i,a,n) for(int i=a; i<=((int)n); i++)
#define rrep(i,n) for(int i=n-1; i>=0; i--)
#define RREP(i,n) for(int i=n; i>=0; i--)
#define INF 1000000000


int main(){
  char buf[1024];
  int A,B,C;

  fgets(buf,sizeof(buf),stdin);
  sscanf(buf, "%d %d %d", &A, &B, &C);

  if(A==B && B==C){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;

}


Measured memory_bytes: 128
op = ""

while op != "?":
  input = raw_input().split(" ")

  a = int(input[0])
  op = input[1]
  b = int(input[2])

  result = 0
  if op == "+":
    result = a + b
  elif op == "-":
    result = a - b
  elif op == "*":
    result = a * b
  elif op == "/":
    result = a / b
  else:
    break

  print "%d" % result
  

Measured memory_bytes: 4216
import java.io.BufferedReader;
import java.io.*;
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;
import java.util.Arrays;

public class Main {
	public static void main(final String[] args){
    
    final Scanner sc = new Scanner(System.in);
    final List<Integer> list = new ArrayList<>();
    //final List<Integer> list2 = new ArrayList<>();
    //final List<Long> list3 = new ArrayList<>();

    String s = sc.next();

    if(s.charAt(s.length() - 1) == 's'){
        System.out.println(s + "es");
    }else{
        System.out.println(s + "s");
    }

   

    

    




    







}
}

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

const double pi = acos(-1.0);

struct pt {
    double x, y;

    pt(double x=0, double y=0) : x(x), y(y) {}

    pt rotateCCW(double ang) { return pt(x * cos(ang) - y * sin(ang), x * sin(ang) + y * cos(ang)); }
};

double sq(double x) { return x * x; }

double dist(pt a, pt b) {
    return sqrt(sq(a.x - b.x) + sq(a.y - b.y));
}

int main() {
    int a, b, h, m;
    scanf("%d%d%d%d", &a, &b, &h, &m);

    pt H(a, 0), M(b, 0);

    double delta = pi / 6;
    double angH = delta * (1.0 * (h * 60 + m) / 60.0);

    H = H.rotateCCW(angH);

    double angM = pi / 30. * (1.0 * (h * 60 + m));

    M = M.rotateCCW(angM);

    printf("%.10lf\n", dist(H, M));

    return 0;
}

Measured memory_bytes: 4192
#include <iostream>
using namespace std;
int main() {
  unsigned long long K;
  cin >> K;
  if (K % 2 == 0 || K % 5 == 0) {
    cout << -1;
    return 0;
  }
  unsigned long long x = 7;
  int c = 1;
  while (true) {
    if (x % K == 0) break;
    if (c > K + 2) {
      c = -1;
      break;
    }
    x = (10 * x + 7) % K;
    c++;
  }
  cout << c;
  return 0;
}

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

int main()
{
	cin.sync_with_stdio(false);
	int n;
	while (cin >> n, n) {
		vector<int> w(n), sum(n);
		for (int i = 0; i < n; i++) {
			cin >> w[i];
			sum[i] = i ? sum[i - 1] + w[i] : w[i];
		}
		vector<vector<int>> dp(n + 1, vector<int>(n + 1));
		for (int i = 0; i + 1 <= n; i++) {
			dp[i][i + 1] = 0;
		}
		for (int i = 0; i + 2 <= n; i++) {
			dp[i][i + 2] = abs(w[i] - w[i + 1]) <= 1 ? 2 : 0;
		}
		for (int k = 3; k <= n; k++) {
			for (int i = 0; i + k <= n; i++) {
				for (int j = i + 1; j + 1 <= i + k; j++) {
					if (k % 2 == 0 && dp[i + 1][i + k - 1] == k - 2 && abs(w[i + k - 1] - w[i]) <= 1) dp[i][i + k] = dp[i + 1][i + k - 1] + 2;
					else dp[i][i + k] = max(dp[i][i + k], dp[i][j] + dp[j][i + k]);
				}
			}
		}
		cout << dp[0][n] << endl;
	}
	return 0;
}

Measured memory_bytes: 3260
from statistics import median

n = int(input())
a = [None] * n
b = [None] * n
for i in range(n):
    A, B = map(int, input().split())
    a[i], b[i] = A, B

if n % 2 == 1:
    print(abs(median(b) - median(a)) + 1)
else:
    print(int(abs(median(b) - median(a)) * 2) + 1)

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

int main(){
  int N;
  cin >> N;
  int loop;
  vector<int> A(N);
  vector<int> B(N);
  vector<int> C(N);
  for(loop=0;loop<N;loop++){
    cin >> A[loop];
  }
  for(loop=0;loop<N;loop++){
    cin >> B[loop];
  }
  for(loop=0;loop<N;loop++){
    cin >> C[loop];
  }
  int ans;
  for(loop=0;loop<N;loop++){
    ans+=B[A[loop]-1];
    if(loop&&(A[loop]-A[loop-1])==1){
      ans+=C[A[loop-1]-1];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double w = sc.nextDouble();
        double h = sc.nextDouble();
        double x = sc.nextDouble();
        double y = sc.nextDouble();

        System.out.println(w*h/2);
        if(w/2 == x && h/2 == y) System.out.println(1);
        else System.out.println(0);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
const int infty = (int)((1LL << 31) - 1);
struct segment_tree {
  public:
    int n, N;
    vector<int> tr, lz;
    segment_tree (vector<int> v) {
      n = v.size();
      N = 1;
      while (N < n) N <<= 1;
      tr.resize(2 * N);
      lz.resize(2 * N, 0);
      for (int i = 0; i < n; i++) tr[N + i] = v[i];
      for (int i = N - 1; i >= 1; i--) tr[i] = min(tr[2 * i], tr[2 * i + 1]);
    }
    inline void pg (int k, int L, int R) {
      if (lz[k]) {
        if (k < N) {
          lz[2 * k] += lz[k];
          lz[2 * k + 1] += lz[k];
        }
        tr[k] += lz[k];
        lz[k] = 0;
      }
    }
    void add (int l, int r, int x, int k = 1, int L = 0, int R = -1) {
      if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return;
      } else if (l <= L && R <= r) {
        lz[k] += x;
        pg(k, L, R);
      } else {
        int C = (L + R) / 2;
        add(l, r, x, 2 * k, L, C);
        add(l, r, x, 2 * k + 1, C, R);
        tr[k] = min(tr[2 * k], tr[2 * k + 1]);
      }
    }
    int getMin (int l, int r, int k = 1, int L = 0, int R = -1) {
      if (R == -1) R = N;
      pg(k, L, R);
      if (r <= L || R <= l) {
        return infty;
      } else if (l <= L && R <= r) {
        return tr[k];
      } else {
        int C = (L + R) / 2;
        return min(getMin(l, r, 2 * k, L, C), getMin(l, r, 2 * k + 1, C, R));
      }
    }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  segment_tree sgt(vector<int>(n, 0));
  while (q--) {
    int c;
    cin >> c;
    if (c == 0) {
      int s, t, x;
      cin >> s >> t >> x;
      sgt.add(s, ++t, x);
    } else {
      int s, t;
      cin >> s >> t;
      int ret = sgt.getMin(s, ++t);
      cout << ret << '\n';
    }
  }
  return 0;
}


Measured memory_bytes: 5232
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int s1 = sc.nextInt();
		int s2 = sc.nextInt();
		int cnt = 0;
		int sa =0;

		for (int x=0; x<= s1; x++){
			for (int y=0; y <= s1; y++){
				sa = s2 - x- y ;
				if ( sa >= 0 && sa <= s1){
					cnt++;
				}
			}
		}
		System.out.println(cnt);

		sc.close();
	}

}

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
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(){
  ll int ans = 1;
int n;
cin >> n;
FOR(i,1,n+1){
ans *= i;
ans %= 1000000007;
}
cout << ans << endl;
}


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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef pair<ll, ll> P;

#define rep(a,n) for(int a = 0;a < n;a++)
#define repi(a,b,n) for(int a = b;a < n;a++)

const ll mod = 1000000007;

int main(void)
{
	ll n;
	cin >> n;
	vector <ll> p(n);
	rep(i, n) cin >> p[i];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++)
		{
			swap(p[i], p[j]);
			int prev = -1;
			bool ok = true;
			rep(k, n) {
				if (p[k] != k + 1) {
					ok = false;
					break;
				}
			}
			if (ok) {
				cout << "YES" << endl;
				return 0;
			}
			swap(p[i], p[j]);
		}
	}
	cout << "NO" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    bool isswap = false;
    if (x1 > x2) {
        swap(x1, x2),swap(y1, y2);
        isswap = true;
    }

    int dx = x2 - x1;
    int dy = y2 - y1;

    int x3, y3, x4, y4;
    if (isswap) {
        x3 = x1 + dy;
        y3 = y1 - dx;
        x4 = x2 + dy;
        y4 = y2 - dx;
    }
    else {
        x3 = x2 - dy;
        y3 = y2 + dx;
        x4 = x1 - dy;
        y4 = y1 + dx;
    }


    printf("%d %d %d %d\n", x3, y3, x4, y4);

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

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

int main() {
    long long int n, m;
    cin >> n >> m;
    priority_queue<long long int, vector<long long int>, greater<long long int> > pq;
    long long int a;
    for (long long int i = 0; i < n; i++) {
        cin >> a;
        pq.push(a);
    }
    vector<P> cb(m);
    for (long long int i = 0; i < m; i++) {
        cin >> cb[i].second >> cb[i].first;
    }
    sort(cb.begin(), cb.end(), greater<P>());
    for (long long int i = 0; i < m; i++) {
        bool h = false;
        for (long long int j = 0; j < cb[i].second; j++) {
            long long int pqa = pq.top();
            pq.pop();
            if (pqa < cb[i].first) {
                pq.push(cb[i].first);
            } else {
                pq.push(pqa);
                h = true;
                break;
            }
        }
        if (h) {
            break;
        }
    }
    long long int ans = 0;
    while (!pq.empty()) {
        long long int pqq = pq.top();
        pq.pop();
        ans += pqq;
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int vacation(int table_of_happiness[][3], int j, int r[][4], int nxt){
	if(j==-1){
		return 0;
	}
	if(r[j][nxt] >= 0){
		return r[j][nxt];
	}
	else{
		int t[3];
		for(int i=0; i<3; i++)
			if(nxt != i)
				t[i] = vacation(table_of_happiness, j-1, r, i) + table_of_happiness[j][i];
		int best=0;
		for(int i=0; i<3; i++){
			if(nxt != i && t[i] > best){
				best = t[i];
			}
		}
		r[j][nxt] = best;
		return r[j][nxt];
	}
}

int main(){
	int N;
	scanf("%d", &N);
	int table_of_happiness[N][3];
	int r[N][4];
	for(int i=0; i<N; i++){
		for(int j=0; j<3; j++){
			scanf("%d", &table_of_happiness[i][j]);
		}
	}

	for(int i=0; i<N; i++){
		for(int j=0; j<4; j++){
			r[i][j] = -1;
		}
	}

	r[N-1][3] = vacation(table_of_happiness, N-1, r, 3);

	printf("%d\n", r[N-1][3]);
}

Measured memory_bytes: 12416
#include "bits/stdc++.h" 
using namespace std;

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

ll L,R;

void solve(){
  int min_v = 9999;
  int r = L / 2019;
  L -= r * 2019;
  R -= r * 2019;
  if (R - L >= 2019)
  {
    R = L + 2019;
  }
  int min_mod = 2019;
  for(int i=L; i < R; i++){
    for(int j=i+1; j <= R; j++){
      int num = (i*j) % 2019;
      min_v = min(min_v, num);
      if(min_v == 0){
        // cout << i << ":" << j << endl;
        cout << min_v << endl;
        return ;
      }
    }
  }
  cout << min_v << endl;
}

int main(){
  cin >> L >> R;
  solve();
}

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

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 1e3 + 10;

struct CC{
	int x, y, r;
	CC(int xx, int yy, int rr) : x(xx), y(yy), r(rr) {}
	CC() {CC(0, 0, 0);}
	double getDis(const CC &o) {
		int dx = x - o.x, dy = y - o.y;
		double oo = sqrt(1ll * dx * dx + 1ll * dy * dy);
		return oo < r + o.r ? 0 : oo - r - o.r;
	}
};

vector<CC> Cs;
int N;

using pid = pair<double, int>;

int main() {
	int xs, ys, xt, yt; scanf("%d%d%d%d", &xs, &ys, &xt, &yt);
	Cs.emplace_back(xs, ys, 0);
	Cs.emplace_back(xt, yt, 0);
	cin >> N; N += 2;
	for(int i=2; i<N; i++) {
		int x, y, r; scanf("%d%d%d", &x, &y, &r);
		Cs.emplace_back(x, y, r);
	}
	vector<bool> vis(N, 0);
	vector<double> dis(N, LINF);
	priority_queue<pid, vector<pid>, greater<pid>> Q; Q.emplace(dis[0] = 0., 0);
	while(!Q.empty()) {
		int v; double d; tie(d, v) = Q.top(); Q.pop();
		if(vis[v]) continue; vis[v] = true;
		for(int w=0; w<N; w++) if(w != v) {
			double nd = d + Cs[v].getDis(Cs[w]);
			if(!vis[w] and dis[w] > nd) Q.emplace(dis[w] = nd, w);
		}
	}
	printf("%.20f\n", dis[1]);
	return 0;
}


Measured memory_bytes: 6520
#include<stdio.h>

int main(){
  int N;
  int a[10001];
  int i;
  int count = 0;

  scanf("%d", &N);
  for(i=0;i<N;i++){
    scanf("%d ", &a[i]);
  }

  for(i=0;i<N;i++){
    while(a[i]%2 == 0){
      count++;
      a[i]/=2;
    }
  }

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

}


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

int main(int argc, char** argv) {
    int n, ma, mb; cin >> n >> ma >> mb;
    int c[n], d[n];
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b >> c[i];
        d[i] = a * mb - b * ma;
    }
    map<int, int> v1; // (diff -> cost)
    vector<int> diff(1<<20), cost(1<<20);
    int ans = 1<<30;
    for (int i = 0; i < min(20, n); i++)
        for (int s = 0; s < 1 << i; s++) {
            int s1 = (1<<i) | s;
            diff[s1] = diff[s] + d[i];
            cost[s1] = cost[s] + c[i];
            if (diff[s1] == 0) ans = min(ans, cost[s1]);
            else if (v1.find(diff[s1]) == v1.end()) v1[diff[s1]] = cost[s1];
            else v1[diff[s1]] = min(v1[diff[s1]], cost[s1]);
        }
    if (n > 20) {
        map<int, int> v2;
        for (int i = 20; i < n; i++)
            for (int s = 0; s < 1 << i-20; s++) {
                int s1 = (1<<i-20) | s;
                diff[s1] = diff[s] + d[i];
                cost[s1] = cost[s] + c[i];
                if (diff[s1] == 0) ans = min(ans, cost[s1]);
                else if (v2.find(diff[s1]) == v2.end()) v2[diff[s1]] = cost[s1];
                else v2[diff[s1]] = min(v2[diff[s1]], cost[s1]);
            }
        auto it1 = v1.begin();
        auto it2 = v2.rbegin();
        while (it1 != v1.end() && it2 != v2.rend()) {
            if (it1->first == 0) { it1++; continue; }
            if (it2->first == 0) { it2++; continue; }
            int diff = it1->first + it2->first;
            int cost = it1->second + it2->second;
            if (diff > 0) it2++;
            else if (diff < 0) it1++;
            else { ans = min(ans, cost); it1++; it2++; }
        }
    }
    cout << (ans == 1<<30 ? -1 : ans) << endl;
}


Measured memory_bytes: 8576
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
typedef long long				ll;
#define ALL(x)					(x).begin(),(x).end()
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define M_PI					3.14159265358979323846
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	int H, N;
	cin >> H >> N;

	ll sum = 0;
	REP(i, N) {
		ll one;
		cin >> one;
		sum += one;
	}

	if (sum < H) {
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
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 n: usize = input();
    let txy: Vec<(i64, i64, i64)> = (0..n)
        .map(|_| {
            let t = input();
            let x = input();
            let y = input();
            (t, x, y)
        })
        .collect();

    let mut cur = (0, 0, 0);
    let mut ok = true;
    for (t, x, y) in txy {
        let dt = (cur.0 - t).abs();
        let dx = (cur.1 - x).abs() + (cur.2 - y).abs();
        if dx > dt || (dt - dx) % 2 == 1 {
            ok = false;
        }
        cur = (t, x, y);
    }
    println!("{}", if ok { "Yes" } else { "No" });
}


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

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

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

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
    }
    ll num = 0;
    rep(i, n) {
        ll v = a[i];
        ll temp = 0;
        while(v%2==0) {
            temp++;
            v /= 2;
        }
        if (i==0) num = temp;
        else {
            if (temp!=num) {
                cout << "0" << endl;
                return 0;
            }
        }
    }
    
    ll l = 1;
    rep(i, n) {
        l = lcm(l, a[i]);
    }
    l /= 2;
    ll ans = m/l;
    ans = (ans+1)/2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <functional>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
ll gcd(ll x,ll y){
	if(x>y) swap(x,y);
	while(x>0){
		y%=x;
		swap(x,y);
	}
	return y;
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
vector<ll> divs;
ll ex(ll x,ll p,ll mod){
	ll ret=1;
	while(p>0){
		if(p%2) ret=x*ret%mod;
		x=x*x%mod;
		p/=2;
	}
	return ret;
}
ll extgcd(ll a,ll b,ll &x,ll &y){
	if(b==0){
		x=a,y=0;
		return a;
	}
	ll d=extgcd(b,a%b,x,y),xx=y,yy=x-a/b*y;
	x=xx,y=yy;
	return d;
}
ll inv(ll a,ll mod){
	ll x,y;
	extgcd(a,mod,x,y);
	return (x%mod+mod)%mod;
}
int main(){
	ll m,n,a,b,c,d;
	cin>>m>>n>>a>>b>>c>>d;
	ll x=lcm(m/gcd(m,a),n/gcd(n,b));
	for(ll i=1;i*i<=m*n;i++) if(m*n%i==0) divs.pb(i),divs.pb(m*n/i);
	sort(all(divs));
	for(ll y:divs){
		ll p=y*c;
		ll g=gcd(a,m);
		if(p%g>0) continue;
		ll pc=p/g,ac=a/g,mc=m/g;
		ll e=pc*inv(ac,mc);
		ll q=y*d;
		g=gcd(b,n);
		if(q%g>0) continue;
		ll qc=q/g,bc=b/g,nc=n/g;
		ll f=qc*inv(bc,nc);
		g=gcd(mc,nc);
		if(e%g==f%g){
			cout<<x*y-1<<endl;
			break;
		}
	}
}

Measured memory_bytes: 1244
#include "bits/stdc++.h"

using namespace std;

#pragma optimization_level 3

constexpr int INF = numeric_limits<int>::max() / 2;

int b[510][510];
int sum[510], mask[510];

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

    int n, m;
    while (cin >> n >> m, n || m)
    {
        for (int i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            for (int j = 0; j < m; j++)
            {
                if (s[j] == '1')
                    b[i][j] = 1;
                else
                    b[i][j] = 0;
            }
        }
        if (n <= 22)
        {
            int ret = 0;
            for (int i = 0; i < (1 << n); i++)
            {
                int cnt = 0;
                for (int j = 0; j < m; j++)
                    sum[j] = 0;
                for (int j = 0; j < n; j++)
                {
                    if ((i >> j) & 1)
                    {
                        cnt++;
                        for (int k = 0; k < m; k++)
                            if (b[j][k])
                                sum[k]++;
                    }
                }
                bool f = true;
                for (int j = 0; j < m; j++)
                    if (sum[j] % 2)
                        f = false;
                if (f)
                    ret = max(ret, cnt);
            }
            cout << ret << endl;
        }
        else
        {
            vector<vector<int>> dp(n + 1, vector<int>(1 << m, -INF));
            for (int i = 0; i < n; i++)
            {
                mask[i] = 0;
                for (int j = 0; j < m; j++)
                {
                    if (b[i][j])
                        mask[i] += (1 << j);
                }
            }
            dp[0][0] = 0;
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < (1 << m); j++)
                {
                    dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
                    dp[i + 1][j ^ mask[i]] = max(dp[i + 1][j ^ mask[i]], dp[i][j] + 1);
                }
            }
            cout << dp[n][0] << endl;
        }
    }
}



Measured memory_bytes: 208732
import sys
sys.setrecursionlimit(10**6)
n = int(input())
edge = [[] for i in range(n)]
colors = [0] * n
for i in range(n-1):
    u, v, w = [int(item) for item in input().split()] 
    u -= 1
    v -= 1
    edge[u].append([v, w % 2])
    edge[v].append([u, w % 2])
    
def dfs(frm, n, d):
    for tv, tw in edge[n]:
        if tv == frm:
            continue
        else:
            td = (d + tw) % 2
            if td == 1:
                colors[tv] = 1 
            else:
                colors[tv] = 0 
            dfs(n, tv, td)
    return True

colors[0] = 0
dfs(0, 0, 0)
for item in colors:
    print(item)

Measured memory_bytes: 82224
N = int(input())
A = list(map(int,input().split()))

def solve():
    q = N * (N + 1) // 2
    if sum(A) % q:
        return False
    times = sum(A) // q
    cnt = 0
    for i, j in zip(A, A[1:] + [A[0]]):
        dif = times + i - j
        if dif % N or dif < 0:
            return False
        cnt += dif // N
    return times == cnt

print('YES' if solve() else 'NO')


Measured memory_bytes: 14228
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL A, B, N;
    cin >> A >> B >> N;

    LL k = (N+1-B)/B;
    LL x = min(N, B*k+B-1);
    LL ans = (A*x/B) - A*(x/B);

    cout << ans << endl;

    return 0;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;
const ll INF = 1LL<<60;
//int INF = numeric_limits<int>::max();

int main(int, char**) {
	int r; cin >> r;
	cout << r * r << endl;
	return 0;
}

Measured memory_bytes: 256
s = list(map(int,input()))
e = []
o = []
for i in range(len(s)):
    if i%2==0:
        e.append(0)
    else:
        e.append(1)
for i in range(len(s)):
    if i%2==1:
        o.append(0)
    else:
        o.append(1)
x = 0
y = 0
for i in range(len(s)):
    if s[i]!=e[i]:
        x += 1
    if s[i]!=o[i]:
        y += 1
print(min(x,y))


Measured memory_bytes: 5536
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################

signed main(){
    int n,k;cin >> n >> k;
    int a[n+1];
    
    
    rep(i,n){
        cin >> a[i+1];
    }
    vector<int> lamp(n+100);
    if(n*k >= 10000000){
        rep(i,n)cout << n << endl;
        return 0;
    }
    
    
    rep(j,k){
        bool end = true;
        rep(i,n){
            int l = max((i+1) - a[i+1],1ll);
            int r = min((i+1) + a[i+1]+1,n+1);
            if(l !=1 || r != n)end = false;
            lamp[l]++;
            lamp[r]--;
        }
        if(end){
            rep(i,n)cout << n << endl;
            return 0;
        }
    
        rep(i,n){
            //trace(lamp[i],i);   
            lamp[i+1] += lamp[i];
            a[i+1] = lamp[i+1];
            //trace(a[i+1],i+1);
        }
        if(j != k-1)rep(i,n+1)lamp[i] = 0;
        
    }
    rep(i,n)cout <<lamp[i+1] << endl;
    return 0;
}


Measured memory_bytes: 6432
#include <stdio.h>

int main()
{
	int N;
	char X[200001];
	scanf("%d", &N);
	scanf("%s", X);
	
	int i, sum = 0;
	for (i = 0; X[i] != 0; i++) sum += X[i] - '0';
	if (sum == 0) {
		for (i = 0; i < N; i++) printf("1\n");
		fflush(stdout);
		return 0;
	} else if (sum == 1) {
		if (X[N-1] == '0') {
			for (i = 0; i < N - 1; i++) {
				if (X[i] == '0') printf("1\n");
				else printf("0\n");
			}
			printf("2\n");
		} else {
			for (i = 0; i < N - 1; i++) printf("2\n");
			printf("0\n");
		}
		fflush(stdout);
		return 0;
	}
	
	int res[2][200001] = {}, total[2] = {X[N-1] - '0', X[N-1] - '0'}, Y, Z, pop, count;
	for (i = N - 2, res[0][N-1] = 1, res[1][N-1] = 1; i >= 0; i--) {
		res[0][i] = res[0][i+1] * 2 % (sum + 1);
		res[1][i] = res[1][i+1] * 2 % (sum - 1);
		total[0] = (total[0] + (X[i] - '0') * res[0][i]) % (sum + 1);
		total[1] = (total[1] + (X[i] - '0') * res[1][i]) % (sum - 1);
	}
	for (i = 0; i < N; i++) {
		if (X[i] == '0') Y = (total[0] + res[0][i]) % (sum + 1);
		else Y = (total[1] - res[1][i] + sum - 1) % (sum - 1);
		count = 1;
		while (Y > 0) {
			for (Z = Y, pop = 0; Z > 0; Z >>= 1) pop += Z % 2;
			Y %= pop;
			count++;
		}
		printf("%d\n", count);
	}
	fflush(stdout);
	return 0;
}

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

int main()
{
    int a,b;
    cin >> a >> b;
    int ans = 0;
    if(a>b)
    {
       ans+=a;
       a--; 
    }
    else
    {
        ans+=b;
        b--;
    }
    if(a>b)
    {
       ans+=a;
       a--; 
    }
    else
    {
        ans+=b;
        b--;
    }
    cout << ans;
}

Measured memory_bytes: 256
solve :: [Double] -> Double
solve [a,b,h,m] = sqrt((a * a) + (b * b) - (2 * a * b * cos(angle * pi / 180.0)))
 where angle = abs $ (h * 30) + (0.5 * m) - (m * 6)
main = print =<< solve . map read . words <$> getLine

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

#define ll long long
using namespace std;

ll mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<vector<ll>> dp(n + 1, vector<ll>(13));
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        if (s[i] == '?') {
            for (int j = 0; j < 13; j++) {
                for (int k = 0; k < 10; k++) {
                    dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
                    dp[i + 1][(j * 10 + k) % 13] %= mod;
                }
            }
        } else {
            int num = s[i] - '0';
            for (int j = 0; j < 13; j++) {
                dp[i + 1][(j * 10 + num) % 13] += dp[i][j];
                dp[i + 1][(j * 10 + num) % 13] %= mod;
            }
        }
    }

    cout << dp[n][5] << endl;
    return 0;
}

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

int N;
char s[400][400];
char c[400][400];

bool check(){
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            if(s[i][j]==s[j][i]) continue;
            else return false;
        }
    }
    return true;
}

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> c[i][j];
        }
    }
    int ans=0;
    for(int d=0;d<N;d++){
        for(int i=0;i<N;i++){
            for(int j=0;j<N;j++){
                if(j+d<N){
                    s[i][j+d]=c[i][j];
                }else{
                    s[i][j+d-N]=c[i][j];
                }
            }
        }
        if(check()) ans++;
    }
    cout << ans*N << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;

P visit(int v, int prev, vector< vector<P> > &G) {
  P res(v, 0);
  REP(i, G[v].size()){
    if(G[v][i].first != prev){
      P t = visit(G[v][i].first, v, G);
      t.second += G[v][i].second;
      if (res.second < t.second) res = t;
    }
  }
  return res;
}
int diameter(vector< vector<P> > &G) {
  P r = visit(0, -1, G);
  P t = visit(r.first, -1, G);
  return t.second; // (r.first, t.first) is farthest pair
}

int main() {
  int N; cin >>N;
  vector< vector<P> > G(N);
  REP(i, N - 1){
    int s, t, w; cin >>s >>t >>w;
    G[s].push_back(P(t, w));
    G[t].push_back(P(s, w));
  }
  cout <<diameter(G) <<endl;
  return 0;
}

Measured memory_bytes: 14204
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ull unsigned long long
#define endl '\n'
#define mod 1000000007

using namespace std;

int main()
{

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

    ll s=-1e9, e=1e9, mid1, mid2, ans=1e18;
    for(int i=0;i<300;i++)
    {
        mid1=s+(e-s)/3;
        mid2=e-(e-s)/3;
        ll ans1=0, ans2=0;
        for(int j=0;j<n;j++)
            ans1+=abs(arr[j]-(j+1+mid1)),
            ans2+=abs(arr[j]-(j+1+mid2));

        ans=min(ans, min(ans1, ans2));

        if(ans1>ans2)
            s=mid1;
        else e=mid2;

    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        List<Integer> kudamonoSyuruiList = new ArrayList<>();
        for (int i = 0 ;i < N ; i++) {
            kudamonoSyuruiList.add(scanner.nextInt());
        }
        Collections.sort(kudamonoSyuruiList);
//        for (Integer info : kudamonoSyuruiList) {
//            System.out.println(info);
//        }
        int sum = 0;
        for (int i = 0;i < K ; i++) {
            sum = sum + kudamonoSyuruiList.get(i);
        }
        System.out.println(sum);
    }
}


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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    sort(a.begin(),a.end());
    int num = n / 2;
    int ans = a[num]-a[num-1];
    cout << ans << endl;

    return 0;
}

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

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

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

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

  vector<long long> T(N);
  rep(i, N) {
    cin >> T[i];
  }

  long long t = 1;
  rep(i, N) {
    t = lcm(T[i], t);
  }

  cout << t << endl;

  return 0;
}


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMinimum(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T>
inline bool changeMaximum(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {


    string in;
    vector< pair <pair <string, int>, int> > p;

    int N;
    cin >> N;


    for (int i = 0; i < N; ++i) {
        int t;
        cin >> in >> t;
        string temp = in;
        p.push_back(make_pair(make_pair(in, -t), i));
    }

     sort(p.begin(), p.end());
    for (int i = 0; i < N; i++) {
        cout << p[i].second + 1 << endl;
    }

}

Measured memory_bytes: 256