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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int D;
    ll G;
    cin >> D >> G;
    vector<ll> P(D), C(D);
    REP(i, D) {
        cin >> P[i] >> C[i];
    }
    int ans = INT_MAX;
    REP(subset, 1 << D) {
        ll tot = 0;
        int probs = 0;
        REP(i, D) {
            if (subset & (1 << i)) {
                tot += P[i] * (i + 1) * 100 + C[i];
                probs += P[i];
            }
        }
        FORD(i, D - 1, 0) {
            if (tot >= G) break;
            if (subset & (1 << i)) continue;
            ll k = G - tot;
            ll left = P[i] - 1;
            ll todo = k / (100LL * (i + 1));
            todo += (k % (100LL * (i + 1))) > 0;
            if (todo <= left) {
                probs += todo;
                tot += todo * 100 * (i + 1);
                break;
            }
            probs += left;
            tot += left * 100 * (i + 1);
        }
        if (tot < G) continue;
        ans = min(ans, probs);
    }
    cout << ans << '\n';

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] imos = new int[n];
    for(int i = 0; i < m; i++) {
      int l = sc.nextInt();
      int r = sc.nextInt();
      imos[l - 1]++;
      if(r < n) imos[r]--;
    }
    for(int i = 1; i < n; i++) {
      imos[i] = imos[i] + imos[i - 1];
    }
    int ans = 0;
    for(int i = 0; i < n; i++) {
      if(imos[i] == m) ans++;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 63940
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
using namespace std;

int main(){
    while(1){
        int n, m;
        cin >> n >> m;
        if(n + m == 0)  break;
        
        vector<int> p(n);
        for(int i = 0; i < n; i++)  cin >> p[i];
        sort(p.begin(), p.end());
        
        for(int i = n-m; i >= 0; i -= m){
            p[i] = 0;
        }
        
        cout << accumulate(p.begin(), p.end(), 0) << endl;
    }
    return 0;
}



Measured memory_bytes: 3072
w, h, n = map(int, input().split())
field = [[1] * w for _ in range(h)]
for i in range(n):
    x, y, a = map(int,input().split())
    if a == 1:
        for i in range(h):
            for j in range(x):
                field[i][j] = 0
    elif a == 2:
        for i in range(h):
            for j in range(x, w):
                field[i][j] = 0
    elif a == 3:
        for i in range(y):
            for j in range(w):
                field[i][j] = 0
    elif a == 4:
        for i in range(y,h):
            for j in range(w):
                field[i][j] = 0

count = 0
for i in field:
    count += i.count(1)
print(count)


Measured memory_bytes: 9236
#include <stdio.h>

int main(){

  int n,ai,min,max;
  long long int sum;
  scanf("%d %d",&n,&ai);
  n--;
  min = ai;
  max = ai;
  sum = ai;

  while(n--){

     scanf("%d",&ai);
	   if(min > ai)min = ai;
	   if(max < ai)max = ai;
	   sum += ai;

  }

  printf("%d %d %lld\n",min,max,sum);

}



Measured memory_bytes: 2740
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	string S;
	cin >> S;

	int N = S.size();

	rep(i, N) cout << 'x';
	cout << endl;


	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

int main(){
    string S,T;
    cin >> S >> T;
    int ans = 0;

    for(int i = 0;i < S.size();i++){
        if(S.at(i) == T.at(i))
            ans++;
    }

    cout << ans << endl;


}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-3
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
const ll mod = 1e9 + 9;
const db pi = acos(-1.0);
const ll maxn = 2e5+10;
int pre[maxn], suf[maxn];
int a[maxn];
signed main(){
    int n;
    cin >> n;
    _rep(i, 1, n){
        cin >> a[i];
    }
    _rep(i, 1, n){
        pre[i] = pre[i-1]^a[i];
    }
    for(int i = n;i>=1;i--){
        suf[i] = suf[i+1]^a[i];
    }

    _rep(i, 1, n){
        cout << (pre[i-1] ^ suf[i+1]) << " ";
    }

}

Measured memory_bytes: 5936
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
  long long int N,M;
  cin>>N>>M;
  cout<<abs((N-2)*(M-2))<<endl;

  return 0;
}

Measured memory_bytes: 256
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
const ll mod = 1000000007;
const ll mod9 = 1000000009;

ll d[109];
ll u[109];
ll k[109];
ll v[109][109];
struct Point{
    ll s,t;
};
queue<Point> S;

ll  bfs(){
    while(!S.empty()){
        ll n = S.front().s;
        ll t = S.front().t;
        S.pop();
        if(d[n]==0){
            d[n]=t;
        // cout<<" d "<<n<<" "<<t<<endl;
        }
        rep(i,k[n]){
            if(d[v[n][i]-1]==0) S.push({v[n][i]-1,t+1});
        }
    }
    return 0;
}

signed main(){
    ll n;
    cin>>n;
    rep(i,n){
        ll a;
        cin>>u[i]>>k[i];
        rep(j,k[i]){
            cin>>v[i][j];
        }
    }
    S.push({0,1});
    bfs();
    rep(i,n){
        d[i]--;
        printf("%lld %lld\n",i+1,d[i]);
    }
}




Measured memory_bytes: 3492
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b, k;
	cin >> a >> b >> k;
	int up = max(a, b);
	int cnt = 0;
	vector<int> vec;
	for (int i = up; i >= 1; --i) {
		if (a % i == 0 && b % i == 0)
			vec.push_back(i);
	}
	cout << vec[k - 1] << '\n';
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int x[25],y[25],n,m,p,c;
int main(){
	while(true){
		cin>>n>>m;if(n==0)break;
		for(int i=0;i<25;i++)x[i]=0;
		x[0]=n;p++;c=0;
		while(x[m]<1){
			c++;for(int i=0;i<25;i++)y[i]=0;
			for(int i=0;i<m;i++){
				y[i]+=x[i]%2;
				y[0]+=x[i]/2;
				y[i+1]+=x[i]/2;
			}
			for(int i=0;i<=m;i++){x[i]=y[i];}
		}
		cout<<"Case "<<p<<": "<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <algorithm>
using namespace std;
bool b[1000001], c[1000001];
int main(){
	int n;
	scanf("%d", &n);
	int a[n + 1], ans = 0;
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	sort(a, a + n), a[n] = -1;
	for (int i = 0; i < n; i++){
		if (i != 0 && a[i] == a[i - 1] && a[i] != a[i + 1] && c[a[i]]) ans--;
		if (b[a[i]]) continue;
		ans++, c[a[i]] = true;
		for (int j = a[i]; j <= 1000000; j += a[i]) b[j] = true;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 4368
#include <bits/stdc++.h>
#define ll long long
#define M 1000000007
#define f(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define endc "\n"
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
 
using namespace std;




int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    ll ans=0;
    f(i,1,n+1)
    {
        ll k=(n/i);
        ans+=i*((k)*(k+1))/2;
    }
    cout<<ans<<endc;
	return 0;
}


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


int absolute(int a, int b,int c, int d){
  
  if (a > b&&c > d){
    return a-b +c -d;
  }
  else if (a > b && c <= d){
    return a- b + d -c ;
  }
  else if (a <= b && c <= d ){
    return b -a + d - c;
  }
  else if (a <= b && c > d){
    return b -a + c -d;
  }
}
    
int main(){
  int N;
  cin >> N;
  vector<int>time(N);
  vector<int>placex(N);
  vector<int>placey(N);
  for (int i = 0; i<N;i++){
    cin >> time.at(i) >> placex.at(i) >> placey.at(i) ;
  }
  bool can = true;
  if((absolute(placex.at(0),0,placey.at(0),0)-time.at(0))%2 == 0 && (absolute(placex.at(0),0,placey.at(0),0)-time.at(0))<=0){
   
  
    for (int i = 0; i<N-1;i++){
      if ((absolute(placex.at(i+1),placex.at(i),placey.at(i+1),placey.at(i))-time.at(i+1)+time.at(i))%2 == 0 &&
          (absolute(placex.at(i+1),placex.at(i),placey.at(i+1),placey.at(i))-time.at(i+1)+time.at(i))<=0){
        continue;
      }
      else{
        can = false;
        break;
      }
    }
  }
  else
    can = false;
  if (can) 
    cout << "Yes" << endl;
  else 
    cout << "No" << endl;
}

  

      

    
    

    
  
    
    
    
    
    
    
    
  

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
#define e18 1000000000000000000

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

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

    int a = 0;

    REP(i, 5)
    {
        a++;
        int tmp;
        cin >> tmp;
        if(tmp == 0) cout << a <<endl;
    }

    return 0;
}

Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inp = new Scanner(System.in);
        int rows = inp.nextInt();
        int cols = inp.nextInt();

        int aMatrix[][] = new int[rows][cols];
        int bMatrix[][] = new int[cols][1];


        for (int k = 0; k < rows; k++) {
            for (int j = 0; j < cols; j++) {
                aMatrix[k][j] = inp.nextInt();
            }
        }

        for (int j = 0; j < cols; j++) {
            bMatrix[j][0] = inp.nextInt();
        }

        int total[][] = matrixCalc(aMatrix, bMatrix, rows, cols);
        for (int[] item : total) {
            for (int secondItem : item) {
                System.out.println(secondItem);
            }
        }
    }

    public static int[][] matrixCalc(int[][] aMatrix, int[][] bMatrix, int rows, int cols) {
        int totals[][] = new int[rows][1];
        for (int k = 0; k < rows; k++) {
            int total = 0;
            for (int j = 0; j < cols; j++) {
                total += aMatrix[k][j] * bMatrix[j][0];
            }

            totals[k][0] = total;
        }

        return totals;
    }
}



Measured memory_bytes: 39968
n = int(input())
w = list(map(int,input().split()))

ans = 10**9
for x in range(n-1):
  s1 = sum(w[:x+1])
  s2 = sum(w[x+1:])
  if abs(s1-s2) < ans:
    ans = abs(s1-s2)
    
print(ans)
  

Measured memory_bytes: 9168
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <random>
#include <climits>

#define mod 1000000007
#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)

using namespace std;
using ll = long long;

int X[] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Y[] = {1, 1, 1, 0, -1, -1, -1, 0};

void solve() {
    int k, s, res = 0;
    cin >> k >> s;
    for(int i = 0; i <= k; i++){
        for(int j = 0; j <= k; j++){
            int x = s-(i+j);
            //printf("%d %d %d\n",i, j, x);
            if(x >= 0 && x <= k){
                res++;
            }
        }
    }
    cout << res << endl;
}

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

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int i,j,k;
  int v;
  int N;
  
  scanf("%d",&N);
  int A[N];

  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=0;i<N;i++){
    
    v = A[i];
    j=i-1;

    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }
    for(k=0;k<N;k++){
      if(k!=N-1)printf("%d ",A[k]);
      if(k==N-1)printf("%d\n",A[k]);
    }
     
  }

  return 0;
}



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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    string s, ans = "Yes";
    cin >> s;
    int n = s.size();
    if(n % 2 == 0){
        for(int i = 0; i < n; i += 2){
            if(s[i] != 'h' || s[i + 1] != 'i'){
                ans = "No";
                break;
            }
        }
    }else{
        ans = "No";
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
        int a,b;
        cin>>a;
        cin>>b;

        if(a<b){
                cout<<"a < b\n";
        }else if(a>b){
                cout<<"a > b\n";
        }else {
                cout<<"a == b\n";
        }
}

Measured memory_bytes: 1128
a,b,c,x=int(input()),int(input()),int(input()),int(input())
x//=50
ans=0
for i in range(x//10+1):
    k=x-i*10
    for j in range(k//2+1):
        l=k-j*2
        ans+=(0<=i<=a and 0<=j<=b and 0<=l<=c)
print(ans)

Measured memory_bytes: 38896
#include <iostream>
#include <string>
using namespace std;
int main(){
	int N,M;
	int frag = 0;
	string U[256];
	string T; 
	cin >> N;
	for(int i = 0;i<N;i++){
		cin >> U[i];
	}
	cin >> M;
	for(int j=0;j<M;j++){
		cin >>T;
		for(int i = 0;i<N;i++){
			if(T==U[i]){
				frag +=1;
				
				if(frag%2==0){
					cout << "Closed by "<< T << endl;
				}
				
				else{
					cout << "Opened by " << T <<endl;
				}
				
				break;
			}
			if(i==N-1){
				cout << "Unknown " << T << endl;
			}
		}
	}


	return 0;
}

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

using namespace std;
const int N = 2e6;

#define Maxn 1000000	

int n, a[N], vis[N];

int main() {
	scanf("%d", &n);
	for(int i = 1;i <= n; ++i) scanf("%d", &a[i]), vis[a[i]] += 1;
	int A = 1, B = 0;
	for(int j = 2;j <= Maxn; ++j) {
		int num = j, tmp = 0;
		for(int i = num; i <= Maxn; i += num)
			if(vis[i])
				tmp += vis[i];
		if(tmp > 1) B = 1;
		if(tmp == n) A = 0;
	}
	if(A == 0) puts("not coprime");
	else if(B == 1) puts("setwise coprime");
	else puts("pairwise coprime");
	return 0;
}

Measured memory_bytes: 11432
#include<bits/stdc++.h>
#define N 1000000
using namespace std;
typedef pair<int,int> P;
int t,x,y,T;
bool mp[201][201];
int dx[]={1,0,-1,-1,0,1},dy[]={0,-1,-1,0,1,1};
int bfs(){
  queue<P> Q;
  int cnt=0;
  Q.push(P(0,(x+100)*N+y+100));
  while(!Q.empty()){
    P p=Q.front();
    Q.pop();
    T=p.first;
    x=p.second/N,y=p.second%N;
    if(T>t)return cnt;
    if(mp[x][y])continue;
    mp[x][y]=1;
    cnt++;
    for(int i=0;i<6;i++){
      int nx=x+dx[i],ny=y+dy[i];
      Q.push(P(T+1,nx*N+ny));
    }
  }
  return cnt;
}

int main(){
  int n;
  while(cin>>t>>n&&(t||n)){
    memset(mp,0,sizeof(mp));
    while(n--){
      cin>>x>>y;
      mp[x+100][y+100]=1;
    }
    cin>>x>>y;
    cout<<bfs()<<endl;
  }
  return 0;
}

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

int main() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<double> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i] = t - v[i] * 0.006;
  }
  double dif = 1000000;
  int ans = -1;
  for (int i = 0; i < n; i++) {
    if (dif > abs(a - v[i])) {
      dif = abs(a - v[i]);
      ans = i + 1;
    }
  }
  cout << ans << endl;
}


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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)):((m)-(n))),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;
typedef vector<int> vi;
typedef vector<string> vs;
typedef map<string,int> Dictionary;
const Real PI = acos(-1);

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  if (v.size() == 0) {
    os << "(empty)";
    return os;
  }
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

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

int main() {

  for (int n,s; cin >> n >> s && (n||s);) {

    int ans = 0;

    for (int b = 0; b < (1<<10); ++b) {
      int sum = 0;
      int cx = 0;
      rep(i, 10) {
        if (b & (1 << i)) {
          ++cx;
          sum += i;
        }
      }
      if (cx == n && sum == s) {
        ++ans;
      }
    }

    cout << ans << endl;

  }

  return 0;
}

Measured memory_bytes: 1160
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに作成したソースコード
 * 
 * https://atcoder.jp/contests/abc091/submissions/5275478 にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[] b = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[] na = new int[n], nb = new int[n];
			int answer = 0;
			for (int k = 0; k < 30; k++) {
				int mask = (1 << (k + 1)) - 1;
				for (int i = 0; i < n; i++) {
					na[i] = a[i] & mask;
					nb[i] = b[i] & mask;
				}
				Arrays.sort(nb);
				int count = 0;
				for (int i = 0; i < n; i++) {
					count += lowerBound(nb, (2 << k) - na[i]) - lowerBound(nb, (1 << k) - na[i]);
					count += n - lowerBound(nb, (3 << k) - na[i]);
					count &= 1;
				}
				if (1 == (count & 1)) {
					answer |= 1 << k;
				}
			}
			System.out.println(answer);
		}
	}

	/**
	 * 配列aにおける値vのlowerBoundを計算する
	 * 
	 * @param a
	 * @param v
	 * @return 配列aにおける値vのlowerBound
	 */
	private static int lowerBound(int a[], int v) {
		int l = 0, r = a.length - 1;
		while (r - l >= 0) {
			int c = (l + r) / 2;
			if (v <= a[c]) {
				r = c - 1;
			} else {
				l = c + 1;
			}
		}
		return l;
	}
}


Measured memory_bytes: 67972
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <climits>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define ye cout<<"YES";
#define no cout<<"NO";
#define ln cout<<"\n";
// cout<<"Case #"<<ts<<": “;
//priority_queue < pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> pq;


using namespace std;

ll mod(ll x, ll m) {
	return (x % m + m) % m;
}

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t = 1, r, n, a, d, c, b, x, y, sum, cnt, i, j, k, m, l, q, maxx, minn, temp, ans, flag, g, ts;
	ll mod = 1000000007;
	char ch, chh;
	double dans;
	string str, ttr;

	//cin >> t;


	for (ts = 1; ts <= t; ts++)
	{
		flag = 0; sum = 0; cnt = 0; ans = 0; k = 0; maxx = 0; minn = 0; a = 0; b = 0; temp = 0;

		n = 5;
		ll arr[n]; for (i = 0; i < n; i++) {cin >> arr[i];}

		for (i = 0; i < n; i++)
		{
			if (arr[i] == 0)
			{
				temp = i + 1;
				break;
			}

		}
		cout << temp;




		ln
	}
	return 0;
}


Measured memory_bytes: 3648
//#include "pch.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <queue>
#include <algorithm>
#include <functional>
#include <string>
#include <bitset>

#define ll long long
#define fri(n) for(i=0;i<(n);i++)
#define frj(n) for(j=0;j<(n);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000000000//10^18
#define INFINT 2000000001//2*10^9+1
#define MOD 1000000007
#define MODANOTHER 998244353
#define PI acos(-1)

#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vvvd vector<vector<vector<double>>>


//#define int long long

using namespace std;


const int MAX = 510000;

ll mod_inverse(int a,int M){
	int x=M-2;
	ll temp=a;
	ll ret=1;
	//a^(MOD-1)==1(mod MOD)を利用
	//a^-1==a^(MOD-2) (mod MOD)を繰り返し二乗法で求める

	while(x!=0){
		if(x%2==1){
			ret=(ret*temp)%M;
		}
		temp=(temp*temp)%M;
		x=x/2;
	}
	return ret;
}

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k){
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed compare_ll(const void *a, const void *b)
{
	ll *A = (ll *)a;
	ll *B = (ll *)b;
	if (*A < *B) return 1;
	if (*A > *B) return -1;
	return 0;
}


signed main(void)
{
	//変数の宣言
	int n,m;
	int h,w;
	int x,y,z;
	static int a[200010];
	static int b[200010];
	static int v[100010];
	static int p[100010];

	//よく使う変数
	int i,j,k,l;
	int flag=0;
	int ans=0;
	int count=0;
	int temp=0;
	int temp1=0;
	int temp2=0;
	int temp3=0;
	vector<int> vec;
	vector<int> vtemp;
	int max=0;
	int min=INFINT;
	int len=0;
	int sum=0;
	int ok=0;
	int ng=0;
	char dummy;
	static char stemp[100010];
	vvi graph;
	
	//データの読み込み


	scanf("%d %d %d",&x,&y,&z);
	//scanf_s("%d %d %d",&x,&y,&z);


	//scanf("%s",&s);
	//scanf_s("%s",&s,20);


	/*for(i=0;i<n-1;i++){
		//scanf("%lld %lld",&a[i],&b[i]);
		scanf_s("%lld %lld",&a[i],&b[i]);
	}*/



	//	printf("nは%dです\n", n);
	//	printf("データの読み込み終了\n");
	//実際の処理

//	clock_t start=clock();
//	COMinit();

	printf("%d %d %d",z,x,y);

//	clock_t end=clock();

	//	printf("計算部分終了\n");

	//出力
	
	//printf("%d",(d[i-1][j-1]+1)/2);

//	printf("time=%lf",(double)(end-start)/CLOCKS_PER_SEC);
	//	printf("結果の出力終了\n");

	return 0;
}



Measured memory_bytes: 256
from collections import Counter

N = int(input())
items = list(map(int, input().split()))

# 偶数列と奇数列に分ける
even_num = items[::2]
odd_num = items[1::2]

# それらの配列で一番数が多いものを判定、それに合わせる
dev = Counter(even_num).most_common(2)
dod = Counter(odd_num).most_common(2)

if dev[0][0] == dod[0][0] :
    if len(dev) == len(dod) == 1 :
        print(N//2)
    elif len(dev) < len(dod) :
        print(N//2 - dod[1][1])
    elif len(dev) > len(dod) :
        print(N//2 - dev[1][1])
    else :
        print(N - max(dod[1][1] + dev[0][1], dod[0][1] + dev[1][1]))
else :
    print(N - dod[0][1]- dev[0][1])



Measured memory_bytes: 16092
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
// dfmt on

void main()
{
    auto S = sread();
    auto L = new long[](S.length);
    L[0] = 0;
    foreach (i; 1 .. S.length)
        L[i] = S[i] == 'L' ? L[i - 1] : i;
    auto R = new long[](S.length);
    R[$ - 1] = S.length - 1;
    foreach_reverse (i; 0 .. S.length - 1)
        R[i] = S[i] == 'R' ? R[i + 1] : i;

    auto ans = new long[](S.length);
    // writeln(R, L);
    foreach (i; 0 .. S.length)
    {
        if (S[i] == 'L')
        {
            long d = i - L[i];
            // writeln("L",d);
            ans[L[i] + (d & 1)]++;
        }
        else if (S[i] == 'R')
        {
            long d = R[i] - i;
            // writeln("R",d);
            ans[R[i] - (d & 1)]++;
        }
    }
    write(ans[0]);
    foreach (v; ans[1 .. $])
        write(" ", v);
    writeln();
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 

int mod=1e9+7;
int min(int a,int b){
    return (a<b)?a:b;
}
int max(int a,int b){
    return (a>b)?a:b;
}
int fp(int a,int b){
    if(b==0) return 1;
    int x=fp(a,b/2);
    x=(x*x)%mod;
    if(b&1) x=(x*a)%mod;
    return x;
}
int n,ans=0;
int b[100];
map<array<int,3>,bool> mp;
void solve(int pos,int a,int stock)
{
    if(a<0)
        return;
    if(pos==n+1)
    {
        ans=max(ans,a);
        return;
    }
    auto it=mp.find({pos,a,stock});
    if(it!=mp.end())
      return;
    mp[{pos,a,stock}];
   solve(pos+1,a,stock);
   int x=a/b[pos];
   solve(pos+1,a%b[pos],stock+x);
   solve(pos+1,a+b[pos]*stock,0);
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 srand(time(0));

 cin>>n;
 for(int i=1;i<=n;i++)
 {
  //b[i]=100+rand()%100;
 // cout<<b[i]<<" ";
    cin>>b[i];
 }
// cout<<endl;
 // solve(1,1000,0);
 int dp[n+1][205];
 memset(dp,0,sizeof(dp));

 for(int i=1;i<=n;i++)
 {
    dp[i][1000%b[i]]=1000/b[i];
 }

 int ans=1000;
 for(int i=1;i<=n;i++)
 {  
  int mx=0;
   for(int j=1;j<i;j++)
   {  
      for(int k=0;k<b[j];k++)
      {
        if(dp[j][k]){
          int x=k+dp[j][k]*b[i];
          ans=max(ans,x);
          mx=max(mx,x);
           for(int l=i;l<=n;l++)
           {
              dp[l][x%b[l]]=max(dp[l][x%b[l]],x/b[l]);
           }
         }
      }
   }




 }
    



 


 cout<<ans;


}

Measured memory_bytes: 3736
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)){
			int daily = sc.nextInt();
			int weekly = sc.nextInt();
			int target = sc.nextInt();

			int week = 7*daily+weekly;

			int days = (target/week)*7;
			if ((target%week)/daily >= 7 ) days+= 7;
			else {
				days += (target%week)/daily;
				if ((target%week)%daily != 0) days++;
			}
			System.out.println(days);
		}
	}
}



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

// GNU C Compiler
//template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

// type
using ll = int_fast64_t;
using ull = uint_fast64_t;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
//using pair<T1, T2> = p12;

//container
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
#define ALL(v) v.begin(),v.end()

//repetition
#define REP(n) for(ll i=0; i<(n); i++)
#define REPj(n) for(ll j=0; j<(n); j++)
#define REPinit(i,a,n) for(int i=(a); i<(n); i++)
#define REPinitj(j,a,n) for(int j=(a); j<(n); j++)

//algorithm
#define SORT(c) sort((c).begin(),(c).end())
#define CONTAINER_ALL(a) a.begin(),a.end()

//constant

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//Optimizer
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")


bool judge(int a, int b, int c) {
    if ((a > b && b > c) || (a < b && b < c)) return true;
    return false;
}

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

    int A, B;
    cin >> A >> B;

    cout << (max(max(A + B, A - B), A * B)) << endl;

    return 0;
}


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

int m [10000001];

void find(int n) 
{ 
    for (int i = 1; i <= n; i++) { 
        for (int j = 1; j * i <= n; j++) {
        	int x = i*j;
            m[x]++; 
        }
   
    } 
 
}

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	int n;
	cin>>n;

	find(n);
	
	long long int ans = 1;
	for(int i=2;i<=n;i++){
		ans += (long long int)i*m[i];
	}
	
	cout<<ans;
	return 0;
}

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

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#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

const int N=1e5+5;
int dp[N];

int32_t main()
{
	fast;
	int n,x,m;cin>>n>>x>>m;
	dp[1]=x;
	mii exist;
	exist[x]=1;
	int last=x;
	int id=-1;
	int i=2;

	while(true)
	{
		int num=(last*last)%m;

		//trace1(num);

		if(exist.count(num))
		{
			id=exist[num];
			break;
		}

		exist[num]=i;
		dp[i]=num;
		last=num;
		i++;
	}

	for(int j=1;j<i;j++)
		dp[j]+=dp[j-1];


	int len=i-id;

	if(n<i)
	{
		cout<<dp[n]<<endl;
		return 0;
	}

	int rep_sum=dp[i-1]-dp[id-1];

	n-=(i-1);
	int ans=dp[i-1];
	int val=n/len;
	ans+=rep_sum*val;
	n-=val*len;

	ans+=dp[id+n-1]-dp[id-1];

	cout<<ans<<endl;
}


Measured memory_bytes: 7116
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int yuzu=1e5;
typedef int fuko[yuzu|10];
fuko a,fa;
int n=read(),m=read();

void init(int n){for (int i=1;i<=n;++i) fa[i]=i;}
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
void mg(int u,int v){fa[find(u)]=find(v);}

int main(){
int i;
init(n);
for (i=1;i<=n;++i) a[i]=read();
for (i=1;i<=m;++i){
  int u=read(),v=read();
  mg(u,v);
  }
int ans=0;
for (i=1;i<=n;++i) ans+=find(a[i])==find(i);
write(ans);
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1e18;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};

ll n,m,s,t,x,y,a,b;
vector<P> to[2][M];
ll dist[2][M];
priority_queue<P,vector<P>,greater<P>> que[2];
void dijkstra(int z,int start){
	rep(i,0,M)dist[z][i]=INF;
	dist[z][start]=0;
	que[z].push(P(0,start));
	while(que[z].size()){
		P p=que[z].top();que[z].pop();
		ll cost=p.first,now=p.second;
		if(dist[z][now]<cost)continue;
		for(auto e:to[z][now]){
			ll cost=e.first,next=e.second;
			if(dist[z][next]>dist[z][now]+cost){
				dist[z][next]=dist[z][now]+cost;
				que[z].push(P(dist[z][next],next));
			}
		}
	}
}


int main(){
	cin>>n>>m>>s>>t;
	rep(i,0,m){
		cin>>x>>y>>a>>b;
		to[0][x].push_back(P(a,y));
		to[0][y].push_back(P(a,x));
		to[1][x].push_back(P(b,y));
		to[1][y].push_back(P(b,x));
	}
	//to1は円の時のdijkstra.
	dijkstra(0,s);
	//to2の時はスヌークの時のdijkstra.
	dijkstra(1,t);
	ll cur[M];
	fill(cur,cur+M,INF);
	for(int i=n;i>0;i--){
		ll tmp=dist[0][i]+dist[1][i];
		cur[i]=min(cur[i+1],tmp);
	}
	rep(i,1,n+1)print(1000000000000000-cur[i]);
}

Measured memory_bytes: 20344
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<utility>
using namespace std;
int main() {
	long int n,sum=0;
	cin >> n;
	vector<long>a(n + 1);
	vector<long>b(n);
	for (int i = 0; i < n + 1; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);

	}
	for (int i = 0; i < n; i++) {
		if (b.at(i) <= a.at(i)) {
			sum += b.at(i);
		}
		else if(b.at(i)<a.at(i)+a.at(i+1)) {
			sum += a.at(i);
			a.at(i+1) -= b.at(i) - a.at(i);
			sum += b.at(i) - a.at(i);
		}
		else {
			sum += a.at(i);
			sum += a.at(i + 1);
			a.at(i + 1) = 0;
		}
	}

	cout << sum << endl;

}

Measured memory_bytes: 1792
n = gets.to_i
a = gets.chomp
b = gets.chomp
c = gets.chomp

ans = 0
n.times do |i|
    if a[i] == b[i] && a[i] == c[i]
        next
    elsif a[i] != b[i] && b[i] != c[i] && c[i] != a[i]
        ans += 2
    else
        ans += 1
    end
end

puts ans

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include<limits.h>
using namespace  std;
typedef long long int ll;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define sz(a) a.size()
#define fi first
#define se second
#define rsz(a,n) a.resize(n)
#define test(t) ll t;cin>>t;while(t--)
#define forn(i,e) for(int i = 0; i < e; i++)
#define forsn(i,s,e) for(int i = s; i < e; i++)
#define rforn(i,s) for(int i = s; i >= 0; i--)
#define rforsn(i,s,e) for(int i = s; i >= e; i--)
#define fillv(a,k) memset(a,k,sizeof(a))
#define filla(a,k,n) memset(a,k,sizeof(a[0])*n)
#define leadzero(a) __builtin_clz(a) //count leading zeros
#define trailzero(a) __builtin_ctz(a) //count trailing zeros
#define bitcount(a) __builtin_popcount(a) // count set bits (add ll)
#define ln cout<<"\n"
#define sp cout<<" "
#define spaceprint(a,i,s,n) {forsn(i,s,n) { cout<<a[i]; sp;}}
#define lineprint(a,i,s,n) {forsn(i,s,n) {cout<<a[i]; ln;}}
#define maxe(a) *max_element(a.begin(),a.end())
#define maxi(a) max_element(a.begin(),a.end())-a.begin()
#define mine(a) *min_element(a.begin(),a.end())
#define mini(a) min_element(a.begin(),a.end())-a.begin()
#define all(c) c.begin(),c.end()
#define trav(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element)  (find(all(container),element) != container.end())// check the presence of element
//copy(from_begin, from_end, to_begin); copy function
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<string> vs;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM = 1e5+5, MOD = 1e9+7;
#define sumv(v) accumulate(all(v),ll(0))
#define productv(v) accumulate(all(v), ll(1), multiplies< ll >())
int main()
{
	ll n,W;
	cin>>n>>W;
	ll w[n+1];
	ll v[n+1];
	for(ll i=1;i<=n;i++)
	{
		cin>>w[i];
		cin>>v[i];
	}
	ll dp[n+1][W+1];
	fillv(dp,0);

	for(ll i=1;i<=n;i++)
	{
		for(ll j=0;j<=W;j++)
		{
			if(j-w[i]<0)
				dp[i][j]=dp[i-1][j];
			else
			{
				dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			}
		}
	}
	cout<<dp[n][W]<<endl;

}

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){

    map<string,int> S;

    int N;
    cin >> N;

    repo(i,N){
        string s;
        cin >> s;
        S[s] += 1;
    }
    
    int max = 0;

    for(auto & memo : S){
        if(memo.second > max)
            max = memo.second;
    } 

    for(auto & memo : S){
        if(memo.second == max){
            cout << memo.first << endl;
        }
    }
//    ll N;
//     cin >> N;
//
//     string s;
//     vector<string> S;
//     vector<int> num;
//     repo(i,N){
//        cin >> s;
//        S.push_back(s);
//        int count = 0;
//        repo(j,S.size()){
//
//            if(s == S[j]){
//                count++;
//
//        } 
//     }
//     ll max_length = 0;
//
//     for(ll i = 0; i < N; i++){
//         cin >> S[i];   
//         max_length = max( (ll)S[i].length() ,max_length);    
//     }
//
//     sort(S.begin(), S.end());
//     S.erase(unique(S.begin(),S.end()),S.end());
//     repo(i,S.size()){
//         if(S[i].size() == max_length)
//         cout << S[i] << endl;
//     }
//     return 0;
}



Measured memory_bytes: 25216
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int rs[200000];

int main() {
    int n = gi();
    for (int i = 0; i < 17; i++)
        if ((1 << i) == n) {
            printf("No\n");
            return 0;
        }

    int a = n, b = 1, c;
    while (a > 1) {
        a /= 2;
        b *= 2;
    }

    printf("Yes\n");
    switch(n%4) {
        case 1:
            for (int i = 2; i < n; i++)
                printf("%d %d\n", i, i+1);
            for (int i = n + 2; i < 2*n; i++)
                printf("%d %d\n", i, i+1);
            printf("1 2\n%d 3\n%d %d\n", n+1, n, n+2);
            break;
        case 3:
            for (int i = 1; i < 2*n; i++)
                printf("%d %d\n", i, i+1);
            break;
        case 0:
            rs[0] = b;
            rs[1] = n-b;
            c = 2;
            for (int i = 1; i < n; i++)
                if (i != b && i != n-b)
                    rs[c++] = i;
            for (int i = 0; i < n-1; i++)
                rs[n-1+i] = rs[i] + n;
            printf("%d %d\n%d %d\n", n, b, 2*n, n-b);
            for (int i = 1; i < 2*n-2; i++)
                printf("%d %d\n", rs[i-1], rs[i]);
            break;
        case 2:
            rs[0] = n-b;
            rs[1] = b;
            rs[2] = b+1;
            c = 3;
            for (int i = 2; i < n; i++)
                if (i != n-b && i != b && i != b+1)
                    rs[c++] = i;
            for (int i = 0; i < n-2; i++)
                rs[n-2+i] = rs[i] + n;
            printf("%d %d\n%d %d\n%d %d\n%d %d\n", 1, b, n+1, b+1, n, n-b, 2*n, b);
            for (int i = 1; i < 2*n-4; i++)
                printf("%d %d\n", rs[i-1], rs[i]);
            break;
    }

    return 0;
}


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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string t = s;
    reverse(s.begin(), s.end());
    if (s != t) {
        cout << "No" << endl;
        return 0;
    }
    string u = t.substr(0, (n - 1) / 2);
    string v = u;
    reverse(u.begin(), u.end());
    if (u != v) {
        cout << "No" << endl;
        return 0;
    }
    string w = t.substr((n + 3) / 2 - 1);
    string x = w;
    reverse(w.begin(), w.end());
    if (w != x) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c,e,f,g;
    scanf("%d %d",&a,&b);
    e=a+b;
    f=a-b;
    g=a*b;

     if(a==0 && b==0){
     printf("0\n");
     }
    else if(e>=f && e>=g){
    printf("%d\n",e);
    }
    else if(f>=e && f>=g){
    printf("%d\n",f);
    }
    else if(g>=f &&g >=e){
    printf("%d\n",g);
    }
    return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>

int main() {
	char s[201], t[101], p[101];

	scanf("%s %s", s, p);
	strcpy(t, s);
	strcat(s, t);

	if (strstr(s, p) == NULL)printf("No\n");
	else printf("Yes\n");

	return 0;
}

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

int main(){
    ll N,X,T;
    cin>>N>>X>>T;
    ll i=0;
    while(0<N){
        N-=X;
        i++;
    }
    cout<<T*i;
}

Measured memory_bytes: 3616
N=int(input())
S=input()

R=S.count("R")
G=S.count("G")
B=S.count("B")

if R==0 or G==0 or B==0:
    print(0)
    exit()

ans=R*G*B
for i in range(N-2):
    for j in range(i+1,N-1):
        if S[i]==S[j]:continue
        n=2*j-i
        if n>=N:continue
        if S[i]!=S[n] and S[j]!=S[n]:
            ans-=1

print(ans)


Measured memory_bytes: 9216
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>

typedef long long ll;
const ll INF = 1e18 + 1;
const ll MOD = 1e9 + 7;

// print(x, y, z);
// print(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

int main(int argc, char* argv[])
{
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  ll N;
  std::string s,t;
  std::cin >> N >> s >> t;

  ll ans = 2 * N;

  // 重なっている文字数を固定
  for (ll i = 1; i <= N; ++i) {
    bool is_same = true;
    for (ll j = 0; j < i; ++j) {
      if (s[N-i+j] != t[j]) {
	is_same = false;
	break;
      }
    }
    if (is_same) {
      ans = std::min(ans, 2 * N - i);
    }
  }

  print(ans);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main(){
    string n;
    cin>>n;
    ll sum = 0;
    ll len = n.length(),i;
    for(i=0;i<len;i++){
        sum+=n[i]-'0';
    }
    sum%9==0?cout<<"Yes":cout<<"No";
    return 0;
}

Measured memory_bytes: 3692
import std;
void main () {
	int n;
	while (readf !(" %s") (n) > 0) {
		readln;
		auto a = readln.splitter.map !(to !(int)).array;
		int [int] v;
		foreach (ref c; a) {
			v[c] += 1;
		}
		auto s = a.sum (0L);
		int q;
		readf !(" %s") (q);
		foreach (j; 0..q) {
			int b, c;
			readf !(" %s %s") (b, c);
			if (b in v) {
				s += (c - b) * 1L * v[b];
				v[c] += v[b];
				v.remove (b);
			}
			writeln (s);
		}
	}
}


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

int Qsum[200005];
int Csum[200005];
vector<int> edges[200005];
bool visited[200005];

void dfs(int v, int q) {
  if(visited[v]) return;
  visited[v] = true;
  Csum[v] = q;
  rep(i, edges[v].size()) {
    dfs(edges[v][i], q+Qsum[edges[v][i]]);
  }
}

int main() {
  int N, Q;
  cin >> N >> Q;
  int a,b,p,x;
  rep(i, N-1) {
    cin >> a >> b;
    a--; b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  rep(i, Q) {
    cin >> p >> x;
    p--;
    Qsum[p] += x;
  }
  dfs(0, Qsum[0]);
  rep(i, N-1) {
    cout << Csum[i] << " " << flush;
  }
  cout << Csum[N-1] << endl;
  return 0;
}


Measured memory_bytes: 25624
n, m = map(int, input().split())
X = list(map(int, input().split()))

ans = 0
if n < m:
    X.sort()
    L = sorted([X[i + 1] - X[i] for i in range(m - 1)], reverse=True)
    ans = sum(L[n - 1: ])

print(ans)

Measured memory_bytes: 13960