akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N, M;
    vector<vector<int> > G;
    vector<int> depth;

    void input() {
        cin >> N >> M;
        G.resize(N);
        depth.resize(N, -1);

        rep(i, 0, M) {
            int a, b;
            cin >> a >> b;
            a--, b--;
            G[a].push_back(b);
        }
    }

    int dfs(int v) {
        if (depth[v] != -1) return depth[v];

        if (G[v].size() == 0) {
            return depth[v] = 0;
        }

        int ret = 0;
        for (auto nv : G[v]) {
            int tmp = dfs(nv);
            chmax(ret, tmp + 1);
        }

        return depth[v] = ret;
    }

    void solve() {
        input();

        int ans = 0;
        for (int i = 0; i < N; ++i) {
            int tmp = dfs(i);
            chmax(ans, tmp);
        }

        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 8192
#include<cstdio>
#include<cstdlib>
using namespace std;

int sum[100000];

int main(){
  int n,m,plan;

  while(scanf("%d %d",&n,&m)!=EOF && (m||n)){
    sum[0] = 0;
    for(int i=0;i<n-1;i++){
      int tmp; scanf("%d",&tmp);
      sum[i+1] = sum[i] + tmp;
    }

    int dis = 0,pos = 0;
    for(int i=0;i<m;i++){
      scanf("%d",&plan);
      dis += abs(sum[pos] - sum[pos+plan]);
      dis %= 100000;
      pos += plan;
    }
    printf("%d\n",dis);
  }
}

Measured memory_bytes: 1104
#include<iostream>
using namespace std;
int main()
{
	char a,b;
	cin>>a>>b;
	if(a=='H')
	{
		if(b=='H')
			cout<<"H"<<endl;
		else
			cout<<"D"<<endl;
	}
	else
		if(b=='H')
			cout<<"D"<<endl;
		else
			cout<<"H"<<endl;
}

Measured memory_bytes: 256
def max_sub(array):
    x = max(array[0], 0)
    ans = 0
    for a in array[1:]:
        x = max(0, x+a)
        ans = max(ans, x)
    return ans

while True:
    n = int(input())
    if n == 0:
        break
    array = [int(input()) for _ in range(n)]
    ans = max_sub(array)
    ans = max(array) if ans <= 0 else ans
    print(ans)



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

int main() {
  int n;
  cin >> n;
  vector<long long> t(n), t_cp(n);
  int i;
  for (i = 0; i < n; i++) {
    cin >> t[i];
  }
  t_cp = t;

  long long gcd = t[0], lcm = t[0];
  for (i = 1; i < n; i++) {
    while (t_cp[i] != 0) {
      if (gcd < t_cp[i]) {
        swap(gcd, t_cp[i]);
      }
      gcd %= t_cp[i];
      swap(gcd, t_cp[i]);
    }
    lcm *= t[i] / gcd;
    gcd = lcm;
  }
  cout << lcm << endl;
  return 0;
}


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    long long x, k, d;
    cin >> x >> k >> d;
    
    long long ans;
    if (x < 0){
        long long div = abs(x) / d, mn = min(k, div);
        x += mn * d;
        k -= mn;
        if (k % 2 == 0)
            ans = abs(x);
        else
            ans = abs(x + d);
    }
    else if (x > 0){
        long long div = abs(x) / d, mn = min(k, div);
        x -= mn * d;
        k -= mn;
        if (k % 2 == 0)
            ans = abs(x);
        else
            ans = abs(x - d);
    }
    else{
        if (k % 2 == 0)
            ans = 0;
        else
            ans = min(abs(x + d), abs(x - d));
    }

    cout << ans << '\n';

    return 0;
}


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

int main(){
  int N,A;
  int cnt=0;
  int swap=30;//制約による最大操作数
  
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> A;
    cnt = 0;
    while(A%2 ==0){
      A /= 2;
      cnt++;
    }
    if(swap >= cnt) swap = cnt;//Aで操作が最も少ない値
  }
  
  cout << swap << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ld PI=abs(acos(-1));
string s;

int main(){
	cin >> s;
	
	ll sum=0;
	REP(i,0,(1<<s.size())){
		string pos="0";
		REP(j,0,s.size()){
			if((i>>j)&1) sum+=stoll(pos),pos="0";
			else pos+=s[j];
		}
		sum+=stoll(pos);
	}
	
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b) f(i,0,n){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/


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

	int n, k, d[9];
	cin >> n >> k;
	st s;
	f(i, 0, k)cin >> d[i];
	for (int i = n;; i++) {
		s = to_string(i);
		f(j, 0, size(s)) {
			f(l, 0, k) {
				if (s[j] - '0' == d[l])goto out;
			}
		}
		cout << s;
		return 0;
	out:;
	}
	return 0;
}

Measured memory_bytes: 256
import numpy as np
N,L=map(int,input().split())
a=[]
for i in range(1,N+1):
  b=L+i-1
  a.append(b)
c=sum(a)
if L>0:
  d=min(a)
  print(c-d)
elif L<=0 and L>-N:
  print(c)
elif L<=-N:
  d=max(a)
  print(c-d)


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

use proconio::input;

fn main() {
    input! {
        n: usize,
    }

    let mut v = Vec::with_capacity(n);
    for _ in 0..n {
        input! {
            a: u64,
            b: u64,
        }
        v.push((a, b));
    }
    v.sort_by(|a, b| a.1.cmp(&b.1));
    // println!("{:?}", v);

    let mut total_time = 0;
    for ab in &v {
        total_time += ab.0;
        if total_time > ab.1 {
            println!("No");
            return;
        }
    }
    println!("Yes");
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define rep(i, n) REP(i, 0, n)
const ll INF=1e9+5;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    Vec l;
    Vec r;

    priority_queue<ll, vector<P>, function<bool(P, P)>> q([](P a, P b)->ll {
        if(a.first==b.first) {
            return a.second<b.second;
        } else {
            return a.first>b.first;
        }
    });


    ll tmp1,tmp2;
    rep(i,n){
        cin>>tmp1>>tmp2;
        q.push(mp(tmp1,tmp2));
    }

    while (!q.empty()){
        P now = q.top();
        l.pb(now.fi);
        r.pb(now.se);
        q.pop();
    }
    Vec minl(n);
    Vec minr(n);

    ll tmp=INF;
    rep(i,n){
        minl[i] = min(r[i],tmp);
        tmp = minl[i];
    }

    reverse(ALL(r));
    tmp2=INF;

    rep(i,n){
        minr[n-1-i] = min(r[i],tmp2);
        tmp2 =  minr[n-1-i];
    }

    ll ans=0;
    REP(i,0,n-1){
        ll ans1 = minl[i]-l[i]>-1?minl[i]-l[i]+1:0;
        ll ans2 = minr[i+1]-l[n-1]>-1? minr[i+1]-l[n-1]+1:0;
        ans = max(ans,ans1+ans2);
    }


    reverse(ALL(r));
    ll maxi =-1;
    ll maxlr=0;

    rep(i,n){
        if(r[i]-l[i]>maxlr){
            maxi = i;
            maxlr = r[i]-l[i]+1;
        }
    }

    ll l2 = 0LL;
    ll r2 = INF;
    rep(i,n){
        if(i==maxi){
            continue;
        }
        l2 = max(l2,l[i]);
        r2 = min(r2,r[i]);
    }
    ll ans3 = r2-l2>-1?r2-l2+1:0;
    ans = max(ans,maxlr+ans3);

    cout<<ans<<endl;
    return  0;
}


Measured memory_bytes: 5488
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int key(char c) {
	if (c == 'R') { return 0; }
	if (c == 'G') { return 1; }
	return 2;
}

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

	vector<vector<Int>> d(N, vector<Int>(3, 0));
	d[N - 1][key(s.back())] = 1;
	for (int i = N - 2; i >= 0; --i) {
		d[i][key(s[i])] += 1;
		for (int j = 0; j < 3; ++j) {
			d[i][j] += d[i + 1][j];
		}
	}

	Int ans = 0;
	for (int j = 1; j + 1 < N; ++j) {
		for (int i = 0; i < j; ++i) {
			if (s[i] == s[j]) { continue; }

			char sk;
			if (s[i] == 'R' && s[j] == 'G') { sk = 'B'; }
			if (s[i] == 'B' && s[j] == 'G') { sk = 'R'; }
			if (s[i] == 'B' && s[j] == 'R') { sk = 'G'; }
			if (s[i] == 'G' && s[j] == 'R') { sk = 'B'; }
			if (s[i] == 'R' && s[j] == 'B') { sk = 'G'; }
			if (s[i] == 'G' && s[j] == 'B') { sk = 'R'; }
			ans += d[j + 1][key(sk)];
			if (2 * j - i < N && s[2 * j - i] == sk) {
				ans -= 1;
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 () {
  int A, B; cin >> A >> B;

  int x = 1;
  int ans = 0;
  while (x < B) {
    x--;
    x += A;
    ans++;
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll k;
char s[110];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	cin>>s>>k;
	int i,cnt=0,a[110];
	a[cnt]=1;
	for(i=1;s[i];i++)
	{
		if(s[i]==s[i-1])
			a[cnt]++;
		else
			a[++cnt]=1;
	}
	int len=i;
	ll ans=0;
	if(cnt==0)
	{
		cout<<(k*len)/2<<endl;
		return 0;
	}
	if(s[0]==s[len-1])
	{
		ans+=a[0]/2+a[cnt]/2;
		ans+=((a[0]+a[cnt])/2)*(k-1);
		for(i=1;i<cnt;i++)
			ans+=k*(a[i]/2);
	}
	else
		for(i=0;i<=cnt;i++)
			ans+=k*(a[i]/2);
	cout<<ans<<endl;
	return 0;
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int mx = 0;
    int l = s.size();
    int c = 0;
    for(int i = 0; i < l; ++i){
    	if(s[i] == 'S'){
    		mx = max(mx, c);
    		c = 0;
    	}else{
    		c++;
    	}
    }
    mx = max(mx, c);
    cout << mx;
    
	return 0;
}

Measured memory_bytes: 3632
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();
	static int cnt = 0;

	public static void main(String[] args) {
		int n = sc.nextInt();
		
		int[] A = new int[n];
		for(int i=0; i<n; i++) {
			A[i] = sc.nextInt();
		}
		
		mergeSort(A, 0, n);
		
		for(int i=0; i<n; i++) {
			System.out.print(A[i]);
			if(i != n-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		
		System.out.println(cnt);
	}
	
	static void merge(int A[], int left, int mid, int right) {
		int n1 = mid - left;
		int n2 = right - mid;
		int[] L = new int[n1 + 1];
		int[] R = new int[n2 + 1];
		for(int i=0; i<n1; i++) {
			L[i] = A[left + i];
		}
		for(int i=0; i<n2; i++) {
			R[i] = A[mid + i];
		}
		L[n1] = Integer.MAX_VALUE;
		R[n2] = Integer.MAX_VALUE;
		int i = 0;
		int j = 0;
		for(int k=left; k<right; k++) {
			if(L[i] <= R[j]) {
				A[k] = L[i];
				i++;
			} else {
				A[k] = R[j];
				j++;
			}
			cnt++;
		}
	}
	
	static void mergeSort(int[] A, int left, int right) {
		if(left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(A, left, mid);
			mergeSort(A, mid, right);
			merge(A, left, mid, right);
		}
	}
	
	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

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

int main(){

    size_t n, m;
    std::cin >> n >> m;

    std::vector<std::string> a(n);
    std::vector<std::string> b(m);

    for(auto&& e : a){
        std::cin >> e;
    }

    for(auto&& e : b){
        std::cin >> e;
    }

    for(size_t i = 0; i <= n - m; i++){
        for(size_t j = 0; j <= n - m; j++){
            bool flag = true;
            for(size_t k = 0; k < m; k++){
                for(size_t l = 0; l < m; l++){
                    if(a[i + k][j + l] != b[k][l]) flag = false;
                }
            }
            if(flag == true){
                std::cout << "Yes" << std::endl;
                return 0;
            }  
        }
    }

    std::cout << "No" << std::endl;
    
    return 0;
}


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main(){
    string s1, s2;
    cin >> s1;
    cin >> s2;
    rep(i,3){
        if(s1[i]!=s2[2-i]){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n; cin >> n;
  int t[110000], x[110000], y[110000];
  t[0] = x[0] = y[0] =0;
  REP(i,n) cin >> t[i+1] >> x[i+1] >> y[i+1];
  
  bool can = true;
  REP(i,n){
    int dt = t[i+1] - t[i];
    int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
    if (dt < dist) can = false;
    if (dist %2 != dt %2) can = false;
  }
  
  if(can) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 4576
#ifndef LOCAL
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#endif
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
signed main(){
    fastio
    int x , k , d ;
    cin >> x >> k >> d ;
    x = abs(x) ;
    int c = (x + d - 1) / d ;
    int ans = 0 ;
    if ( c <= k ) {
        int cur = x - c * d ;
        k -= c ;
        if ( k & 1 ) cur += d ;
        ans = cur ;
    }
    else {
        ans = x - k * d ;
    }
    cout << abs(ans) << endl;
    return 0; 
}

Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <tuple>
#include <set>
#include <cmath>
#include <bits/stdc++.h>

using namespace std;

int main(){
    int N;
    cin >> N;
    pair<pair<string, int>, int> x[101];
    for(int i=0; i<N; i++){
        string s;
        int p;
        cin >> s >> p;
        auto z = make_pair(s, -p);
        x[i] = make_pair(z, i+1);
    }
    sort(x, x+N);
    for(int i=0; i<N; i++){
        cout << x[i].second << endl;
    }
}

Measured memory_bytes: 256
using System;

class A
{
    static void Main(string[] args)
    {
        var val = new int[3];

        for(int i = 0; i < 3; i++)
        {
            val[i] = int.Parse(Console.ReadLine());
        }
        Console.WriteLine((val[0] + val[1]) * val[2] / 2);
    }
}

Measured memory_bytes: 11092
#include<stdio.h>
int last[1000000];
int main(){
	int a,b;
	while(~scanf("%d%d",&a,&b)){
		for(int i=0;i<b;i++)last[i]=-1;
		int now=a;
		last[now]=0;
		int at=0;
		while(1){
			now*=10;
			printf("%d",now/b);
			if(~last[now%b]){
				printf("\n");
				for(int i=0;i<last[now%b];i++)printf(" ");
				for(int i=last[now%b];i<=at;i++)printf("^");
				printf("\n");
				break;
			}
			now%=b;
			last[now]=++at;
			if(now==0){
				printf("\n");
				break;
			}
		}
	}
}

Measured memory_bytes: 0
n,t=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]

c=0
dif=0
m=a[0]
for i in range(1,n):
    if(m>a[i]):
        m=a[i]
    if(dif<a[i]-m):
        c=1
        dif=a[i]-m
    elif(dif==a[i]-m):
        c+=1
print(c)

Measured memory_bytes: 15060
//{{{
#include <bits/stdc++.h>
using namespace std;
#define repX(a,b,c,x,...) x
#define repN(a) repX a
#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop))(__VA_ARGS__)
#define rrep(...) repN((__VA_ARGS__,rrep3,rrep2))(__VA_ARGS__)
#define loop(n) rep2(i_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i=(int)(begin),i##_end=(int)(end);i<i##_end;++i)
#define rrep2(i,n) rrep3(i,n,0)
#define rrep3(i,begin,end) for(int i=(int)(begin-1),i##_end=(int)(end);i>=i##_end;--i)
#define foreach(x,a) for(auto&x:a)
using ll=long long;
const ll mod=(ll)1e9+7;
//}}}

int dp[3][100000];
int abc[3][100000];

int main(){
  int N;
  cin >> N;
  rep(i, N){
    rep(j, 3){
      cin >> abc[j][i];
    }
  }
  rep(j, 3){
    dp[j][0] = abc[j][0];
  }
  rep(i, 1, N){
    rep(j, 3){
      rep(k, 1, 3){
        int abcId = (j + k) % 3;
        dp[j][i] = max(dp[j][i], dp[abcId][i - 1] + abc[j][i]);
      }
    }
  }

  int ans = 0;
  rep(j, 3){
    ans = max(ans, dp[j][N - 1]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
	long long N, D;
	cin >> N >> D;
	vector<long long> X(N), Y(N);
	for (long long i = 0; i < N; i++)
		cin >> X[i] >> Y[i];

	long long n = 0;
	for (long long i = 0; i < N; i++) {
		if (sqrt((double)(X[i] * X[i]) + (double)(Y[i] * Y[i])) <= (double)D)
			n++;
	}
	cout << n << endl;

	return 0;
}

Measured memory_bytes: 6484
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
int main() {
    ll n, m; cin >> n >> m;
    ll ans = 0;
    if (n >= m / 2) { //imagine n is very big
        ans = m / 2;
    } else {
        ans = n;
        m -= 2 * n;
        ans += m / 4;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long x;
	cin>>x;
	long long m=100;
	for(int i=1;;i++)
	{
		m=m/100+m;
		if(m>=x)
		{
			cout<<i;
			return 0;
		}
		//cout<<m<<" "; 
	}
 }

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define max(v) *max_element(v.begin(), v.end())
#define min(v) *min_element(v.begin(), v.end())
#define PI 3.141592653589793
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    int x[n];
    rep(i, n){
        cin>>x[i];
    }
    long long ans = 99999999;
    long long tmp;
    for(int i = 0; i < 100; i++){
        tmp = 0;
        for(int j = 0; j < n; j++){
            tmp += (x[j]-(i+1))*(x[j]-(i+1));
        }
        if(tmp < ans){
            ans = tmp;
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
c1 = [int(n) for n in input().split()]
c2 = [int(n) for n in input().split()]
c3 = [int(n) for n in input().split()]
if ((c1[0]-c1[1]) == (c2[0]-c2[1])) and ((c1[0]-c1[1]) == (c3[0]-c3[1])) and ((c2[0]-c2[1]) == (c3[0]-c3[1])):
    pass
else:
    print("No")
    exit()
if ((c1[1]-c1[2]) == (c2[1]-c2[2])) and ((c1[1]-c1[2]) == (c3[1]-c3[2])) and ((c2[1]-c2[2]) == (c3[1]-c3[2])):
    pass
else:
    print("No")
    exit()
if ((c1[0]-c1[2]) == (c2[0]-c2[2])) and ((c1[0]-c1[2]) == (c3[0]-c3[2])) and ((c2[0]-c2[2]) == (c3[0]-c3[2])):
    pass
else:
    print("No")
    exit()
print("Yes")

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


int main(){
  int n;
  int c[12345], b[12345];
  for(;;){
    cin >> n;
    if(n==0) break;
    for(int i=0; i<n; i++){
      cin >> c[i];
    }
    b[0] = 0;
    for(int i=0; i<n; i++){
      b[i+1] = b[i]+c[i];
    }
    
    int mx = -123456;
    for(int i=0; i<n+1; i++){
      for(int j=i+1; j<n+1; j++){
        if(mx < b[j]-b[i]){
          mx = b[j]-b[i];
        }
        
      }
    }
    cout << mx << endl;
  }
  return 0;
}

Measured memory_bytes: 1192
#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;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

ll f(vector<pair<int,int>> p){
	int n = p.size();
	for(int i = 0 ; i < n ; i++){
		p[i].first = min(p[i].first,n);
	}
	vector<vector<int>> s(n+1);
	for(int i = 0 ;i  < n ; i++)
		s[p[i].first].push_back(p[i].second);
	ll res = 0;
	priority_queue<int> q;
	for(int i = n ; i >= 1 ; i--){
		for(int x : s[i]) q.push(x);
		if(q.size() > 0){
			res += q.top();
			q.pop();
		}
	}
	return res;
}

void test_case(){
	int n ; cin >> n;
	ll ans = 0;
	vector<pair<int,int>> pl,pr;
	for(int i = 0 ; i < n ; i++){
		int k , l , r;
		cin >> k >> l >> r;
		int m = min(l,r);
		ans+=min(l,r);
		l-=m;
		r-=m;
		if(l > 0)
			pl.emplace_back(k,l);
		else
			pr.emplace_back(n-k,r);
	}
	ans+=f(pl);
	ans+=f(pr);
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T;
	cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 10468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

vector<ll> tree[200001];
ll ans[200001];
bool did[200001];



int main(){
	
	ll N,Q;
	cin >> N >> Q;
	FOR(i,0,N-1){
		ll a,b;
		cin >> a >> b;
		a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}
	FOR(i,0,Q){
		ll p,x;
		cin >> p >> x;
		ans[p-1] += x;
	}
	did[0] = true;
	queue<ll> q;
	q.push(0);
	while(q.size()){
		ll pa = q.front();
		q.pop();
		for(auto to:tree[pa]){
			if(not did[to]){
				did[to] = true;
				ans[to] += ans[pa];
				q.push(to);
			}
		}
	}
	cout << ans[0];
	FOR(i,1,N) cout << " " << ans[i];
	cout << "\n";
}


Measured memory_bytes: 18032
#include <stdio.h>
            int main(){
             
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
             
            int min;
            min=a+b; 
            if(min>a+c) min=a+c;
           
            if(min>b+c) min=b+c;
            
            printf("%d",min);
             
             
            return 0;  
            }

Measured memory_bytes: 128
#include <functional>
#include <list>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <deque>
#include <stack>
#include <cassert>
using namespace std;
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define ALL(x) (x).begin(),(x).end()
#define CASET2 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d:\n", case_n++) : 0), ___T-- > 0)
#define CASET1 int ___T, case_n = 1; scanf("%d ", &___T); while ((___T > 0 ? printf("Case #%d: ", case_n++) : 0), ___T-- > 0)
#define CASET int ___T; scanf("%d ", &___T); while (___T-- > 0)
#define SZ(X) ((int)(X).size())
#define LEN(X) strlen(X)
#define REP(i,n) for(int i=0;i<int(n);i++)
#define REP1(i,a,b) for(int i=(a);i<=int(b);i++)
#define PER1(i,a,b) for(int i=(a);i>=(b);i--)
#define REPL(i,x) for(int i=0;x[i];i++)
#define PER(i,n) for(int i=(n)-1;i>=0;i--)
#define RI1(x) scanf("%d",&x)
#define RI2(x,y) RI1(x), RI1(y)
#define RI3(x,y...) RI1(x), RI2(y)
#define RI4(x,y...) RI1(x), RI3(y)
#define RI5(x,y...) RI1(x), RI4(y)
#define RI6(x,y...) RI1(x), RI5(y)
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define RI(argv...) GET_MACRO(argv, RI6, RI5, RI4, RI3, RI2, RI1)(argv)
#define DRI(argv...) int argv;RI(argv)
#define WRI(argv...) while (RI(argv) != EOF)
#define DWRI(x...) int x; WRI(x)
#define RS(x) scanf("%s",x)
#define MP make_pair
#define PB push_back
#define MS0(x) memset(x,0,sizeof(x))
#define MS1(x) memset(x,-1,sizeof(x))
#define X first
#define Y second
#define V(x) vector<x >

typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef long long LL;
const int INF = 1000000000;

void print(int i) { printf("%d", i); }
template<class T> void PI(T i) { print(i); puts(""); }
template<class T> void PIS(T i) { print(i); printf(" "); }

template<class T>
void PV(T const &v, int N) {
    REP(i, N) {
        print(v[i]);
        printf("%c", i == N-1 ? '\n' : ' ');
    }
}

template<class T> void PV(T const &v) { PV(v, SZ(v)); }

template<class T, class S> bool has_bit(T mask, S i) { return (mask >> i) & 1; }
long long shift(int i) { return 1ll << i; }

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
int popcount(int x) { return __builtin_popcount(x); } 
int popcount(long long x) { return __builtin_popcountll(x); } 

#include <unordered_set>
#include <unordered_map>
#define EB emplace_back
#define RL(x) scanf("%lld", &(x))
#define PL(x) printf("%lld\n", x)
#define DRL(x) LL x; RL(x)

bool box[100001];
int num[100001];

int main() {
    DRI(N, M);
    box[1] = true;
    REP1(i, 1, N) {
        num[i] = 1;
    }
    REP(i, M) {
        DRI(x, y);
        num[x]--;
        num[y]++;
        if (box[x]) {
            box[y] = true;
            if (num[x] == 0) {
                box[x] = false;
            }
        }
    }
    int ans = 0;
    REP1(i, 1, N) {
        if (box[i])
            ans++;
    }
    PI(ans);
    return 0;
}


Measured memory_bytes: 768
t = input()
n = len(t)
moji = ""
res = ""
if t[-1] ==  "?":
    moji = "P"
    
for i in range(n-1, 0, -1):
    if t[i] == "?":
        if moji == "D" and t[i -1] == "D":
            res += "P"
        elif moji == "P" or moji == "D" and t[i -1] == "P" :
            res += "D"           
        elif moji == "D"  and t[i -1] == "?" :
            res += "P"
           
    else:
        res += t[i]
    moji = res[-1]
if t[0] ==  "?":
    if moji == "P":
        res += "D"
    else:
        res += "P"
else:
    res += t[0]

res = res[::-1]
print(res)

Measured memory_bytes: 9520
#include <bits/stdc++.h>
#define int int64_t
using namespace std;

const int mod = 1e9+7;
const int N = 1e5+1;

vector<vector<int>> adj(N);
bitset<N> vu;

pair<int,int> dfs(int node){
	int w = 1, b = 1;
	for (int i:adj[node]){
		if (!vu[i]){
			vu[i] = true;
			auto p = dfs(i);
			w *= (p.first+p.second)%mod;
			w %= mod;
			b *= p.first;
			b %= mod;
		}
	}
	return make_pair(w,b);
}

int32_t main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	for (int i=0; i<n-1; ++i){
		int a,b;
		cin >> a >> b;
		adj[a].emplace_back(b);
		adj[b].emplace_back(a);
	}
	vu[1] = true;
	auto p = dfs(1);
	cout << (p.first+p.second)%mod;
	return 0;
}


Measured memory_bytes: 14180
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
	string s;
	cin >> s;
	string ans;
	for (size_t i = 0; i < s.size(); i++)
	{
		if (s[i] == '0' || s[i] == '1') {
			ans += s[i];
		}
		else {
			if (ans.size() > 0)
			ans.erase(ans.size() - 1);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 #define int long long

using namespace std;


signed main(){

	int n;

	cin>>n;
	
	int count=0;
	int a[n];



	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i]%2==1)count++;
	}

	if (count%2==0){	
		cout<<"YES"<<endl;
	}else{
		cout<<"NO"<<endl;
	}

	return 0;

}

Measured memory_bytes: 1024
#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 a, b, c, x;
    cin >> a >> b >> c >> x;
    int res = 0;

    for(int i=0; i<=a; ++i){   
        for(int j=0; j<=b; ++j){
            for(int k=0; k<=c; ++k){
                int total = 500*i + 100*j + 50*k;
                 if(total == x) ++res;
            }    
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  N = int(input())
  A = [tuple(map(int,input().split())) for _ in range(N)]
  MOD =10**9+7
  N2 = 1<<N

  dp = [1] + [0 for _ in range(N2-1)]

  for i in range(N):
    nextdp = [0 for _ in range(N2)]
    for j in range(N2):
      if dp[j] != 0:
        for k in range(N):
          if (j>>k)&1 == 0 and A[i][k] == 1:
            idx = j|(1<<k)
            nextdp[idx] += dp[j]
            #nextdp[idx] %= MOD
    dp = nextdp

  print(dp[N2-1]%MOD)

if __name__ == '__main__':
    main()

Measured memory_bytes: 147208
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll MODPOW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = MODPOW(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * MODPOW(n, m - 1)) % MOD;
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vl A(N);
  vl DP(65, 0);
  REP(i, N) cin >> A[i];
  REP(i, N) {
    ll count = 0;
    while (A[i] > 0) {
      DP[count] += A[i] % 2;
      A[i] /= 2;
      count++;
    }
  }
  ll ans = 0;
  REP(i, 63) {
    ans += (((MODPOW(2, i) * DP[i]) % MOD) * (N - DP[i])) % MOD;
    ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
const int MAX = 100001;
const int MOD = 1000000007;
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 main(){
  int N,K; cin>>N>>K;
  vi A(N);
  rep(i,0,N) cin>>A[i];
  sort(ALL(A));
  int ans=0;
  COMinit();
  rep(i,K-1,N){
    int P=COM(i,K-1);
    ans+=P*A[i]%MOD;
    ans%=MOD;
  }
  REP(i,0,N-K){
    int P=COM(N-i-1,K-1);
    ans+=MOD;
    ans-=P*A[i]%MOD;
    ans%=MOD;
  }
  cout<<ans<<endl;
  }



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

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

int main() {
	int K;
	string S;
	cin >> K >> S;

	if (K >= S.size()) {
		cout << S;
	}
	else {
		cout << S.substr(0, K) << "...";
	}
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

using vvll = vector< vector<ll> >;
using vll = vector<ll> ;

#define IOS ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'
#define all(x) x.begin(), x.end()
#define sz(x) ((long long)x.size())

const ll maxs = 1e6+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;


void pre(){



}


void solve(){  

    int x;
    cin >> x;
    int ans = 360/__gcd(x,360);
    cout << ans << endl;
    
}   

int main(){
   
    IOS;
    pre();
    ll T = 1;   
    //cin>>T;
    ll tt = 1;
    while(T--){  
        //cout << "Case #" << tt << ": "; 
        tt++;
        solve();
    }
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N,K;cin >> N >> K;
  int ans = 1;
  while(N--){
    if(ans<<1 < ans+K) ans<<=1;
    else ans+=K;
  }
  cout << ans << endl;
  return 0;
}


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

C = [0 for _ in range(N + 1)]

for i in reversed(range(N)):

    C[i + 1] += min(A[i + 1], B[i])
    B[i] -= min(A[i + 1], B[i])
    C[i] += min(A[i], B[i])
    A[i] -= min(A[i], B[i])
        
print(sum(C))

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

typedef long long ll;

int main()
{
    int N;
    int A[10005];
    ll add = 0, sub = 0;

    cin >> N;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < N; i++) {
        int B;
        cin >> B;
        if(B > A[i]) add += (B - A[i]) / 2;
        if(A[i] > B) sub += A[i] - B;
    }
    if(add >= sub) cout << "Yes" << endl;
    else cout << "No" << endl;

    return (0);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define iin(x) scanf("%d", &x)
#define lin(x) scanf("%lld", &x)
#define fin(x) scanf("%lf", &x)

#define iout(x) printf("%d", x)
#define lout(x) printf("%lld", x)
#define fout(x) printf("%.10f", x)
#define _ putchar(' ')
#define endl puts("")

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

int dp[55];

int fib(int n) {
  if(~dp[n]) return dp[n];
  if(n < 2) return dp[n] = 1;
  return dp[n] = fib(n-1) + fib(n-2);
}

int main() {
  int n;
  iin(n);
  memset(dp, -1, sizeof(dp));
  iout(fib(n)),endl;
  return 0;
}

Measured memory_bytes: 608
#include <stdio.h>

int main( void ){

    int m_1st,m_2nd,m_3rd;  /* 山の高さ1番目2番目3番目 */
    int input;              /* 入力値 */
    int i;                  /* loopcounter */

    /* init */
    m_1st = 0;
    m_2nd = 0;
    m_3rd = 0;

    for( i = 0; i < 10; i++ ){
        /* 山の高さ入力 */
        scanf( "%d",&input );

        /* 上位3と比較・入れ替え */
        if( input > m_1st ){
            m_3rd = m_2nd;
            m_2nd = m_1st;
            m_1st = input;
        }
        else if( input > m_2nd ){
            m_3rd = m_2nd;
            m_2nd = input;
        }
        else if( input > m_3rd ){
            m_3rd = input;
        }
    }

    /* 上位１～３の高さを出力 */
    printf("%d\n%d\n%d\n", m_1st, m_2nd, m_3rd );


    return 0;
}


Measured memory_bytes: 2044
n, q = map(int, input().split())
s = input()
 
t = [0] * (n + 1)
for i in range(n):
    t[i + 1] = t[i] + (1 if s[i:i+2] == 'AC' else 0)
 
for i in range(q):
    l, r = map(int, input().split())
    print(t[r - 1] - t[l - 1])

Measured memory_bytes: 7748
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdarg.h>
#include<malloc.h>

int main()
{
	int i, j, n, sum;

	while(1){
		scanf("%d", &n);
		if(n==0)
			break;
		sum=0;
		for(j=1; j<=14; j++){
			sum += n / (int)pow(5,j);
		}
		printf("%d\n", sum);
	}

	return 0;
}

Measured memory_bytes: 644
#include<iostream>
#include<vector>
#include<functional>
using namespace std;

typedef long long ll;

int comb[1001][1001] = {};
const int mod = 1e6;

int main(){
    comb[0][0] = 1;
    for(int i = 1; i <= 1000; i++){
        for(int j = 0; j <= i; j++){
            comb[i][j] += comb[i-1][j];
            if(j)   comb[i][j] += comb[i-1][j-1];
            comb[i][j] %= mod;
        }
    }
    int n;
    cin >> n;
    vector<int> v[n];
    vector<bool> lose(n, 0);
    for(int i = 0; i < n-1; i++){
        int a, b;
        cin >> a >> b;
        a--, b--;
        v[a].push_back(b);
        lose[b] = true;
    }
    vector<int> csum(n, 0);
    vector<ll> dp(n, 1);
    function<void(int)> f = [&](int u){
        for(int child : v[u]){
            f(child);
            (dp[u] *= comb[csum[u]+csum[child]][csum[u]] * dp[child]) %= mod;
            csum[u] += csum[child];
        }
        csum[u]++;
    };
    for(int i = 0; i < n; i++){
        if(!lose[i]){
            f(i);
            cout << dp[i] << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 7132