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

int n;
int memo[2001];
int a[21];

void saiki(int i,int now);

int main(){
  int q;
  //初期化
  for(int i=0;i<2001;i++){
    memo[i]=0;
  }
  //入力
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }

  //全パターン確認
  saiki(0,0);


  cin>>q;
  for(int i=0,x;i<q;i++){
    cin>>x;
    if(memo[x]){
      cout<<"yes"<<endl;
    }
    else{
      cout<<"no"<<endl;
    }
  }
}

void saiki(int i,int now){
  if(i){
    memo[now]=1;
  }
  if(i==n)return;
  saiki(i+1,now+a[i]);
  saiki(i+1,now);
  return;
}
    
  

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

int main()
{

   string a;
   cin>>a;
   int m,c=0,d=0;
   m=a.length();
   for(int i=0;i<m;i++)
   {
       if(a[i]=='A')
       {
           c++;
       }
       else if(a[i]=='B')
       {
           d++;
       }
   }
   if(c!=0&&d!=0)
   {
       cout<<"Yes";
   }
   else cout<<"No";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stdio.h>
using namespace std;

int p[100010];
int n,m,ans=0;
bool used[100010];

int find_set(int x){
	if(p[x]==x) return x;
	return p[x]=find_set(p[x]);
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		p[i]=i;
	for(int i=1;i<=m;i++){
		int x,y,z;
		cin>>x>>y>>z;
		int fx=find_set(x),fy=find_set(y);
		if(fx!=fy) p[fy]=fx;
	}
	for(int i=1;i<=n;i++){
		int fi=find_set(i);
		if(!used[fi]){
			used[fi]=true;
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n)  for(int i=0;i<n;i++)
#define per(i,n)  for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
using namespace std;

int check(){
    int A, B,price1 = 0, price2 = 0;
    cin >> A >> B;
    rep1(i, 1000){
        price1 = floor(i * 0.08);
        price2 = floor(i * 0.1);
        if (price1 == A && price2 == B) return i;
    }
    return -1;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int result = check();
    cout << result;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
const double pi = acos(-1);
const int SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
long long fac[100005], finv[100005], inv[100005];

int main() {
	int n;
	char c;
	cin >> n >> c;
	for (int i = 0; i < n - 1; ++i) {
		char s;
		cin >> s;
		if (c == 'T'&&s == 'F') { c = 'F'; }
		else { c = 'T'; }
	}
	cout << c << endl;
}


Measured memory_bytes: 3108
// in the name of Allah

#include <bits/stdc++.h>

#define endl '\n'
#define ll long long
#define pb push_back
#define ld long double
#define sz(x) ((int) (x.size()))

#define max_n 123456
#define mod 1000000007
// #define mod 998244353
#define myPrime 97654321
#define inf 1e9
#define eps 1e-9

#define fr first
#define se second

using namespace std;

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll x, ll y) {
	if(y == 0) return 1;
	ll foo = power(x, y/2);
	foo = mul(foo, foo);
	if(y&1) return mul(x, foo);
	return foo;
}

int main() {
	// ll start_time = clock();
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// cout << fixed << setprecision(12);
	int n;
	cin >> n;
	if(n == 1) cout << "Hello World" << endl;
	else {
		ll a, b;
		cin >> a >> b;
		cout << a + b << endl;
	}
	return 0;
}

// sorted or not
// mutiset vs set
// clear when it's multi-testcase

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
  int N, H, W;
  cin >> N >> H >> W;
  int ans = 0;
  rep(i, N)
  {
    int a, b;
    cin >> a >> b;
    if (a >= H && b >= W)
      ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N,X=map(int,input().split())
Length=[1]
for i in range(1,51):
    Length.append(Length[i-1]*2+3)
def DP(N,point):
    if N == 0:
        return 1
    if point==1:
        return 0
    if 2<=point<=Length[N]//2:
        return DP(N-1,point-1)
    if point==Length[N]//2+1:
        return DP(N-1,point-2)+1
    if Length[N]//2+2<=point and\
            point <=Length[N]-1:
        return DP(N-1,point-Length[N-1]-2)+\
                DP(N-1,Length[N-1])+1
    if point==Length[N]:
        return DP(N-1,Length[N-1])*2+1
print(DP(N,X))


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



int main(){

   int a,b,k;
   cin>>a>>b>>k;
   int c=0;
   for(int i=min(a,b);i>=1;i--){
        if(a%i==0 && b%i==0){
            c++;
        }
        if(c==k){
            cout<<i;
            break;
        }
   }


return 0;
}


Measured memory_bytes: 3552
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
  }
  
  macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
  
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
  }
  
  macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
  
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
  
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
  
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };
  
    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
  }

use std::cmp::max;
fn main() {
    input!{
        s: chars,
        t: chars,
    }
    let mut ans = 0;
    let d = s.len() - t.len();
    for i in 0..d+1 {
        let mut count = 0;
        for j in 0..t.len() {
            if s[i+j] == t[j] {
                count += 1;
            }
        }
        ans = max(count,ans);
    }
    println!("{}",t.len() - ans);
}

Measured memory_bytes: 2136
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, p;
	while (cin >> n >> p, n)
	{
		int w = p;
		int a[50] = {};
		int cnt = 0, pos = 0;
		while (w || cnt!=1)
		{
			if (w)
			{
				cnt += !a[pos%n];
				a[pos%n]++;
				w--;
			}
			else
			{
				if (a[pos%n])w += a[pos%n], a[pos%n] = 0, cnt--;
			}
			pos++;
		}
		for (int i = 0;i < n;i++)if (a[i])cout << i << endl;
	}
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 1e5;
lli ans[maxN + 1];
const lli mod = 1e9 + 7;

lli modPow(lli x, lli y)
{
  lli ans = 1;
  while (y)
  {
    if (y & 1LL) ans = ans * x % mod;
    x = x * x % mod, y >>= 1LL;
  }
  return ans;
}

int main()
{
  int n, k;
  while (scanf("%d %d", &n, &k) != EOF)
  {
    for (int i = k; i >= 1; i--)
    {
      ans[i] = modPow(k / i, n);
      for (int j = 2; i * j <= k; j++)
        ans[i] = (ans[i] - ans[i * j] + mod) % mod;
    }
    for (int i = 1; i <= k; i++)
      ans[i] = ans[i] * i % mod;

    lli total = 0;
    for (int i = 1; i <= k; i++)
      total = (total + ans[i]) % mod;
    printf("%lld\n", total);
  }
  return 0;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> a( N );
	for( int i = 0; i < N; i++ ) {
		cin >> a[i];
	}

	int s = 0;
	for( int i = 0; i < N; i++ ) {
		s ^= a[i];
	}

	string ans = "No";
	if( s == 0 ) {
		ans = "Yes";
	}

	cout << ans << endl;
}


Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace ConsoleApplication15
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                int a = int.Parse(Console.ReadLine());
                if (a == -1)
                    break;
                if (a < 11)
                    Console.WriteLine(4280-1150);
                if (a < 21 && a > 10)
                    Console.WriteLine(4280-(1150 + (a - 10) * 125));
                if (a < 31 && a > 20)
                    Console.WriteLine(4280-(2400 + (a - 20) * 140));
                if (a > 30)
                    Console.WriteLine(4280-(3800 + (a - 30) * 160));
            }
        }
    }
}

Measured memory_bytes: 9088
li = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())
print(li[k-1])

Measured memory_bytes: 3316
MOD = 10**9+7
MAXN = 5*(10**5)+5
f = [1]
for i in range(MAXN):
    f.append(f[-1] * (i+1) % MOD)
def nCr(n, r, mod=MOD):
    return f[n] * pow(f[r], mod-2, mod) * pow(f[n-r], mod-2, mod) % mod

def nPr(n, r, mod=MOD):
    return f[n] * pow(f[n-r], mod-2, mod) % mod

n, m = map(int, input().split())
ans = 0
for k in range(n+1):
    # tmp = pow(nPr(m-k, n-k), 2, MOD) * nPr(m, k) * nCr(n,k) % MOD
    tmp = nPr(m-k, n-k) * nPr(m, n) * nCr(n,k) % MOD
    if k%2:
        ans -= tmp
    else:
        ans += tmp
ans = (ans + MOD) % MOD
print(ans)


Measured memory_bytes: 122596
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
for i in range(1,n-1):
    three = [l[i-1],l[i],l[i+1]]
    three_sort_list = sorted(three)
    if three[1] == three_sort_list[1]:
        cnt += 1

print(cnt)



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

using namespace std;

#define int long long

int32_t main()
{
  int n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  int ans=0;
  if(k==2){
     for(int i=0;i<n;i++){
        if((s[i]-'0')%2==0)ans+=i+1;
     }
  }
  else if(k==5){
     for(int i=0;i<n;i++){
        if((s[i]-'0')%5==0)ans+=i+1;
     }
  }
  else{
    vector<int>cnt(10005);
    ++cnt[0];
    int curr=0,prev=1;
    for(int i=n-1;i>=0;i--){
        curr=(curr+(s[i]-'0')*prev)%k;
        ans+=cnt[curr];
        ++cnt[curr];
        prev=prev*10%k;
    }
  }
  cout<<ans<<endl;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,K;
vector<int> E[101010];
int D[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N-1) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	
	MINUS(D);
	priority_queue<pair<int,int>> P;
	
	cin>>K;
	FOR(i,K) {
		cin>>x>>y;
		D[x-1]=y;
		P.push({-y,x-1});
	}
	while(P.size()) {
		int cur=P.top().second;
		P.pop();
		
		FORR(e,E[cur]) {
			if(D[e]==-1) {
				D[e]=D[cur]+1;
				P.push({-D[e],e});
			}
			else {
				if(abs(D[e]-D[cur])!=1) return _P("No\n");
			}
		}
	}
	_P("Yes\n");
	FOR(i,N) _P("%d\n",D[i]);
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 7924
main=do
 n<-readLn
 ps<-map(read::String->Int).words<$>getLine
 print$length[1|i<-[1..n-2],(ps!!(i-1))<(ps!!i)&&(ps!!i)<(ps!!(i+1))||(ps!!(i-1))>(ps!!i)&&(ps!!i)>(ps!!(i+1))]

Measured memory_bytes: 508
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;

int main(void){
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
     transform (s1.begin (), s1.end (), s1.begin (), ::toupper);
     transform (s2.begin (), s2.end (), s2.begin (), ::toupper);
     transform (s3.begin (), s3.end (), s3.begin (), ::toupper);
    string ans;
    ans[0] = s1[0];
    ans[1] = s2[0];
    ans[2] = s3[0];
   
    for(int i = 0; i < 3; i++)
    cout << ans[i];
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdint>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int A, B; std::cin >> A >> B;
  fin(std::max(std::max(A+B, A-B), A*B));
  return 0;
}


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

using namespace std;

string str;

int main(void) {
  cin >> str;
  int posa = -1, posz = -1;
  for (int i = 0; i < str.length(); i ++)
    if (str[i] == 'A') {
      posa = i;
      break;
    }
  for (int i = str.length() - 1; i >= 0; i --)
    if (str[i] == 'Z') {
      posz = i;
      break;
    }
  if (posa == -1 || posz == -1 || posa > posz)
    cout << "-1\n";
  else
    cout << posz - posa + 1 << "\n";
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
#define MPlus(x,y) {x=(x+y)%M;}
#define MSub(x,y) {x=(x-y+M)%M;}
#define MMul(x,y) {x=(x*y)%M;}


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

  int n;
  string s;
  cin>>n>>s;
  int a[30]={},b[30]={};
  rep(i,n){
    a[s[i]-'a']++;
  }

  int ans=0;
  string t;
  rrep(i,n-1){
    t=t+s[i];
    b[s[i]-'a']++;
    a[s[i]-'a']--;
    s.erase(s.begin()+s.size()-1);
    int res=0;
    rep(j,30){
      res+=(a[j]>0&&b[j]>0);
    }
    ans=max(ans,res);
  }

  cout<<ans<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

class UnionFind {
public:

  vector<int> Parent;

  UnionFind(int N) {
    Parent = vector<int>(N, -1);
  }

  int root(int A) {
    if (Parent[A] < 0) return A;
    return Parent[A] = root(Parent[A]);
  }

  int size(int A) {
    return -Parent[root(A)];
  }

  bool connect(int A, int B) {
    A = root(A);
    B = root(B);
    if (A == B) return false;

    if (size(A) < size(B)) swap(A, B);

    Parent[A] += Parent[B];
    Parent[B] = A;

    return true;
  }

};

int main() {
  int N, M; cin >> N >> M;
  vector<int> X(M), Y(M), Z(M);
  rep(i, M) cin >> X[i] >> Y[i] >> Z[i];

  UnionFind uf(N+1);

  rep(i, M) {
    uf.connect(X[i], Y[i]);
  }

  set <pair<int, int>> st;
  for (int i = 1; i <= N; i++) {
    int x = uf.root(i);
    int y = uf.size(i);
    if (y == 1) continue;
    st.insert(make_pair(x, y));
  }

  int ysum = 0;
  for (auto x : st) {
    ysum += x.second;
  }

  int ans = st.size() + N - ysum;

  cout << ans << endl;



  return 0;
}

Measured memory_bytes: 2048
import java.io.*

val pw = PrintWriter(System.out)
const val MOD = 1000000007L
const val INF = 2147483647
const val LINF = 9223372036854775807L

fun main(args: Array<String>) {
    solve()
    pw.flush()
}

fun solve() {
    val nums = nextIntList()
    val max = nums.max()!!

    for (i in max..2000){
        var sum = 0
        for (j in nums.indices){
            sum += i - nums[j]
        }
        if(sum % 2 != 0) continue
        println(sum / 2)
        return
    }

}

fun println(v: String) {
    pw.println(v)
}

fun print(v: String) {
    pw.print(v)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ").toMutableList()
fun nextIntList(index: Int = 0) = next().split(" ").map { it.toInt() + index }.toMutableList()
fun nextLongList(index: Long = 0L) = next().split(" ").map { it.toLong() + index }.toMutableList()
fun nextDoubleList() = next().split(" ").map { it.toDouble() }.toMutableList()

fun ary(n: Int, init: String = "") = Array(n) { init }
fun intAry(n: Int, init: Int = 0) = IntArray(n) { init }
fun longAry(n: Int, init: Long = 0L) = LongArray(n) { init }
fun doubleAry(n: Int, init: Double = 0.0) = DoubleArray(n) { init }
fun ary2(n: Int, m: Int, init: String = "") = Array(n) { Array(m) { init } }
fun intAry2(n: Int, m: Int, init: Int = 0) = Array(n) { IntArray(m) { init } }
fun longAry2(n: Int, m: Int, init: Long = 0) = Array(n) { LongArray(m) { init } }
fun doubleAry2(n: Int, m: Int, init: Double = 0.0) = Array(n) { DoubleArray(m) { init } }
fun ary3(n: Int, m: Int, k: Int, init: String = "") = Array(n) { Array(m) { Array(k) { init } } }
fun intAry3(n: Int, m: Int, k: Int, init: Int = 0) = Array(n) { Array(m) { IntArray(k) { init } } }
fun longAry3(n: Int, m: Int, k: Int, init: Long = 0L) = Array(n) { Array(m) { LongArray(k) { init } } }
fun doubleAry3(n: Int, m: Int, k: Int, init: Double = 0.0) = Array(n) { Array(m) { DoubleArray(k) { init } } }

fun abs(n: Int): Int = Math.abs(n)
fun abs(n: Long): Long = Math.abs(n)
fun abs(n: Double): Double = Math.abs(n)
fun max(vararg values: Int) = if (values.isEmpty()) -INF else values.max()!!
fun max(vararg values: Long) = if (values.isEmpty()) -LINF else values.max()!!
fun min(vararg values: Int) = if (values.isEmpty()) INF else values.min()!!
fun min(vararg values: Long) = if (values.isEmpty()) LINF else values.min()!!
fun swap(a: String, b: String) = Pair<String, String>(b, a)
fun swap(a: Int, b: Int) = Pair<Int, Int>(b, a)
fun swap(a: Long, b: Long) = Pair<Long, Long>(b, a)
fun swap(a: Double, b: Double) = Pair<Double, Double>(b, a)



Measured memory_bytes: 37864
import sys
table={}
def dfs(a,b):
    global table
    if not a in table:
        if a==0:return 1
        elif b==0 or a < 0:return 0
        table[(a,b)]=sum([dfs(a-i,b-1) for i in xrange(10)])
    return table[(a,b)]
for i in sys.stdin.readlines():
    print dfs(int(i.strip()),4)

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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

int main()
{
    int N;
    cin >> N;
    ll total = 0;
    vector<ll> D(N), ans(N);
    
    rep(i, N) {
        cin >> D[i];
        total += D[i];
    }

    ll x1 = 0;
    for (int i = 1; i < N - 1; i += 2) {
        x1 += D[i];
    }

    ans[0] = total - 2 * x1;

    repd(i, 1, N) {
        ans[i] = 2 * D[i-1] - ans[i - 1];
    }

    rep(i, N - 1) {
        cout << ans[i] << " ";
    }
    cout << ans[N - 1] << endl;

    return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>
#include <string.h>
#include <algorithm>

#define rep(i,st,ed) for (int i=st;i<=ed;++i)

const int INF=0x3f3f3f3f;
const int N=2000005;

int a[N];

int read() {
	int x=0,v=1; char ch=getchar();
	for (;ch<'0'||ch>'9';v=(ch=='-')?(-1):v,ch=getchar());
	for (;ch<='9'&&ch>='0';x=x*10+ch-'0',ch=getchar());
	return x*v;
}

bool check(int l,int r) {
	int mx=0,mn=INF;
	rep(i,l,r) {
		mx=std:: max(mx,a[i]);
		mn=std:: min(mn,a[i]);
	}
	if (mn<l||mx>r) return true;
	int r1=0,r2=0;
	rep(i,l,r) if (a[i]!=i) {
		if (a[i]<i) {
			if (r1<a[i]) r1=a[i];
			else return true;
		} else {
			if (r2<a[i]) r2=a[i];
			else return true;
		}
	}
	return false;
}

int main(void) {
	int n=read(),x;
	rep(i,1,n) a[i]=read();
	rep(i,1,n) if (a[i]!=i) {
		for (x=i;a[x+1]==x+1&&a[x+2]!=x+2;) x+=2;
		x=std:: min(x,n);
		if (check(i,x)) return puts("No"),0;
		i=x;
	}
	return puts("Yes"),0;
}

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

using namespace std;

vector<vector<int>> E;
vector<int> ans;
vector<int> N(4), C(4);

int dfs(int i, int par, int prev){
    prev = 1 - prev;
    ans[i] = prev + 1;
    int res = prev;
    for (const auto &e: E[i]){
        if (e == par)
            continue;
        res += dfs(e, i, prev);
    }
    return res;
}

int main(){
    int n;
    cin >> n;
    E.resize(n);
    ans.resize(n);
    for (int i = 0; i < n - 1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    C[1] = n / 3; C[2] = n / 3; C[3] = n / 3;
    if (n % 3 != 0)
        C[1]++;
    if (n % 3 == 2)
        C[2]++;

    int res = dfs(0, -1, 0);
    int a = n - res, b = res; // 0 1
    if (a < b){
        swap(a, b);
        for (auto &ans_: ans){
            if (ans_ == 1)
                ans_ = 2;
            else if (ans_ == 2)
                ans_ = 1; 
        }
    }
    N[1] = a - C[1];
    N[2] = b - C[2];
    
    if (N[1] < 0 or N[2] < 0){
        int cnt2 = 0, cnt3 = 0;
        for (auto &an: ans){
            if (an == 2){
                an = 3;
                cnt3++;
            }
            else if (an == 1 and cnt2 < C[2]){
                an = 2;
                cnt2++;
            }
        }
        for (auto &an: ans){
            if (an == 1 and cnt3 < C[3]){
                an = 3;
                cnt3++;
            }
        }
    } else {
        for (auto &an: ans){
            if (N[an] > 0){
                N[an]--;
                an = 3;
            }
        }
    }

    vector<int> cnt = {0, 0, 0, 0};
    for (auto &an: ans){
        int z = an;
        an = 3 * cnt[an] + an;
        cnt[z]++; 
    }
    
    copy(ans.begin(), ans.end(), ostream_iterator<int>(cout, " "));
    cout << endl;
}


Measured memory_bytes: 19712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int INF = 1e9;

#define PB push_back
#define PF push_front
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vpi vector<pii>
#define vll vector<ll>
#define vpl vector<pll>
#define vvi vector<vector<int>>
#define vvl vector<vector<ll>>
#define MX(x) *max_element(all(x))
#define MN(x) *min_element(all(x))
#define ios ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pr_d(x) cout << fixed << setprecision(15) << x << endl
#define ud(c, x) distance(c.begin(), upper_bound(all(c), x))
#define ld(c, x) distance(c.begin(), lower_bound(all(c), x))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define rep3(i, n) for (int i = (n - 1); i >= 0; --i)
#define rep4(i, a, b) for (int i = (a); i > (b); --i)
#define pb push_back
#define out(x) cout << x << "\n"
bool odd(int i)
{
    return i % 2;
}

#define all(v) v.begin(), v.end()

int gcd(int a, int b)
{
    return __gcd(a, b);
}
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
void Yes_No(bool f)
{
    if (f)
        printf("Yes\n");
    else
        printf("No\n");
}
void YES_NO(bool f)
{
    if (f)
        printf("YES\n");
    else
        printf("NO\n");
}

template <typename T>
void deb1(T x)
{
    cout << x << "\n";
}

template <typename T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
bool chmin(T &a, const T &b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
//-------------------ここから回答する-----------------------

void solve(void)
{
    int n, m;
    cin >> n >> m;
    vector<set<int>> g(n);
    rep(i, m)
    {
        int a, b;
        cin >> a >> b;
        --a, --b;
        g[a].insert(b);
        g[b].insert(a);
    }
    vector<int> dist(n, INF);
    int ans = 0;
    rep(i, n)
    {
        if (dist[i] == INF)
        {
            int res = 1;
            queue<int> q;
            dist[i] = 1;
            q.push(i);
            while (!q.empty())
            {
                auto x = q.front();
                q.pop();
                for (auto j : g[x])
                {
                    if (dist[j] == INF)
                    {
                        res++;
                        dist[j] = dist[x] + 1;
                        q.push(j);
                    }
                }
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
}
int main(void) { solve(); }

Measured memory_bytes: 32312
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    string S, T;
    cin>>S>>T;
    int cnt = 0;
    rep(i, 3) if (S[i] == T[i]) cnt++;
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#define INF 10000000000
#define MOD 1000000007

#if 1   // use_templates

#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define rep(i, up) for (ll i = 0; i < up; ++i)
#define repp(i, up) for (ll i = 0; i <= up; ++i)
#define rrep(i, lo, up) for (ll i = lo; i < up; ++i)
#define rrepp(i, lo, up) for (ll i = lo; i <= up; ++i)
#define eep(i, lo, up) for ((i) = (lo); (i) < (up); ++(i))
#define eepp(i, lo, up) for ((i) = (lo); (i) <= (up); ++(i))


ll gcd(ll a, ll b);

ll gcd(ll a, ll b)
{
    if (a < b) {
        return gcd(b, a);
    }
    ll r;
    while (r = a % b) {
        a = b;
        b = r;
    }
    return b;
}

#endif  // end of use_templates

#include <bits/stdc++.h>

int main()
{
    ll n;
    cin >> n;
    string x;
    cin >> x;
    vector<ll> work(n);
    work[0] = 0;
    rrep(i, 1, n) {
        ll tmp = i % __builtin_popcount(i);
        work[i] = work[tmp] + 1;
    }
    ll pc = 0;
    rep(i, n) {
        if (x[i] == '1') {
            ++pc;
        }
    }

    if (pc == 1) {
        rep(i, n) {
            if (x[i] == '1') {
                cout << 0 << endl;
            } else if (i != n-1){
                cout << work[(x[n - 1] - '0') % 2] + 1 << endl;
            } else {
                cout << work[(x[n - 1] - '0' + 1) % 2] + 1 << endl;
            }
        }
        return 0;
    }

    ll pcp = pc + 1, pcn = pc - 1;
    ll mp = 0, mn = 0;
    rep(i, n) {
        mp = (mp * 2 + x[i] - '0') % pcp;
        mn = (mn * 2 + x[i] - '0') % pcn;
    }

    vector<ll> result(n);
    ll ap = 1, an = 1;
    for (ll i = n - 1; i >= 0; --i) {
        if (x[i] == '0') {
            result[i] = work[(mp + ap) % pcp] + 1;
        } else {
            result[i] = work[(mn - an + pcn) % pcn] + 1;
        }
        ap = ap * 2 % pcp;
        an = an * 2 % pcn;
    }
    rep(i, n) {
        cout << result[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 6824
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    h,w=map(int,input().split())
    if h==1 or w==1:
        print(1)
        sys.exit()
    if h*w%2==0:print(h*w//2)
    else:print((h*w+1)//2)

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main() {
	int N;
	cin >> N;
	int freq[26];
    fill(freq, freq + 26, 100);
    while(N--> 0) {
        string input;
        cin >> input;
        for(char c = 'a'; c <= 'z'; c = char(c + 1)) {
            int curr = 0;
            for(auto i : input) if(i == c) curr++;
            freq[c-'a'] = min(freq[c-'a'], curr);
        }
    }
    for(char c = 'a'; c <= 'z'; c = char(c + 1)) {
        while(freq[c-'a']--> 0) {
            cout << c;
        }
    }
    cout << endl;
}

Measured memory_bytes: 256
def getInt():
	return int(input())

A = getInt()
B = getInt()
C = getInt()
X = getInt()

ans = 0
for i in range(0,A+1):
	for j in range(0,B+1):
		for k in range(0,C+1):
			if i * 500 + j * 100 + k * 50 == X:
				ans += 1
print ans

Measured memory_bytes: 2568
a,b = map(int,input().split())
aaa = list(map(int,input().split()))

aaa.sort(reverse=True)
result = [0]*b
for i in range(b):
    h = aaa[i]
    j = sum(aaa) / (4*b)

    if h >= j:
        result[i] = 1
    else:
        result[i] = 0

if result.count(1) >= b:
    ans = "Yes"
else:
    ans = "No"

print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=205;

int grundy(int x,int y){
	if(x<y){
		return 0;
	}
	if(x%y==0){
		return x/y;
	}
	while(x>=y){
		if(x%y==0){
			return x/y;
		}
		int d=x/y;
		int lst=y*d;
		int mx=(x-lst+d)/(d+1);
		x-=mx*(d+1);
	}
	return 0;
}

void solve(){
	int n;
	cin>>n;
	vector<pair<int,int>>a(n);
	cin>>a;
	int xr=0;
	for(int i=0;i<n;i++){
		xr^=grundy(a[i].F,a[i].S);
	}
	if(xr){
		cout<<"Takahashi";
	}
	else{
		cout<<"Aoki";
	}
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 384
/*
Author : Harsh AKA Codula
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define rep(n) for(ll i=0;i<n;++i)


class google
{

    public:
        void run()
        {
            ll a;
            cin>>a;
            int i=0;
            while(a--)
            {
                i+=1;
                cout<<"Cases #"<<i<<": ";
                cout<<"\n";
            }
        }
};
class codechefpattern
{

    public:
        void run()
        {
            ll a;
            cin>>a;
            while(a--)
            {
                cout<<"\n"; 
            } 

        }
};
class other
{
    public:
        void run()
        {
            ll a;
            cin>>a;
            if (a>=30)
            {
                /* code */
                cout<<"Yes";
            }
            else
            {
                cout<<"No";
            }
        }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    google g;
    codechefpattern c;
    other o;

    o.run();
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include<math.h>
using namespace std;

int main() {
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = a; i > 0; i--) {
		if (a % i == 0 && b % i == 0)k--;
		if (k == 0) {
			cout << i;
			return 0;
			break;
		}
	}
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int a, b;
    cin >> a >> b;
    cout << (a * a - b) << endl;

    return 0;
}


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

unsigned long long int dp[405][405];
unsigned long long int color[405][405];

unsigned long long int mcm(int i,int j)
{ 
   if(i==j)
   return 0;
   
   if(dp[i][j]!=-1)
   return dp[i][j];
   
   unsigned long long int count=1000000000000000,p;

  for(int k=i;k<=j-1;k++)
    {
	  p=mcm(i,k)+mcm(k+1,j)+color[i][k]+color[k+1][j];
	   if(p<count)
	   {
	   	  count=p;
	   	  color[i][j]=color[i][k]+color[k+1][j];
	   }
    }
	return dp[i][j]=count;
}

int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
     int n;
     cin>>n;
     for(int i=1;i<=n;i++)
     cin>>color[i][i];
     
     for(int i=1;i<=n;i++)
       for(int j=1;j<=n;j++)
         dp[i][j]=-1;
     
     cout<<mcm(1,n)<<endl;
     
	return 0;
} 

Measured memory_bytes: 2816
import java.util.*;
 public class Main {
	public static void main(String[] args){
      Scanner sc = new Scanner(System.in);

      int S = sc.nextInt();
      int W = sc.nextInt();

      if(W >= S){
         System.out.println("unsafe");
      }else{
         System.out.println("safe");
      }
   }
 }
      


Measured memory_bytes: 35584
#include <bits/stdc++.h>
 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define EPS ((ld)(1e-9))
 
#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define rep(i, e) for (int i = 0, _##i = (e); i < _##i; i++)
#define repp(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)
#define repr(i, s, e) for (int i = (s)-1, _##i = (e); i >= _##i; i--)
#define repi(i, x) for (auto &i : (x))
#define ARR(...) vector<int>({__VA_ARGS__})
#define ARS(...) vector<string>({__VA_ARGS__})
 
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef complex<double> base;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    return os << '(' << pai.first << ' ' << pai.second << ')';
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    cout << '[';
    for (auto p : v) cout << p << ",";
    cout << "]";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const set<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
template<typename T, typename V>
ostream &operator<<(ostream &os, const map<T, V> v) {
    cout << "{";
    for (auto p : v) cout << p << ",";
    cout << "}";
    return os;
}
 
#ifndef __DJKIM613
#define debug(...) 0
#define endl '\n'
#else
#define debug(...) cout << " [-] ", _dbg(#__VA_ARGS__, __VA_ARGS__)
template<class TH> void _dbg(const char *sdbg, TH h){ cout << sdbg << '=' << h << endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
    while(*sdbg != ',') cout << *sdbg++;
    cout << '=' << (h) << ','; 
    _dbg(sdbg+1, a...);
}
#endif
 
template<typename T> void get_max(T &a, T b) {a = max(a, b);}
template<typename T> void get_min(T &a, T b) {a = min(a, b);}

const int MAXN = 1e5 + 10;
int N;
int A[MAXN][3];
int DP[MAXN][3];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    cin >> N;
    rep(i, N) cin >> A[i + 1][0] >> A[i + 1][1] >> A[i + 1][2];

    rep(i, N + 1){
        rep(j, 3) DP[i][j] += A[i][j];
        rep(j, 3) rep(k, 3) if(j != k)get_max(DP[i + 1][j], DP[i][k]);
    }

    cout << max({DP[N][0], DP[N][1], DP[N][2]}) << '\n';
    return 0;
}

Measured memory_bytes: 2560
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = 0;
		String str = sc.next();
		
		for(int i = 0; i < 4; i++) {
			if(str.charAt(i) == '+')		n++;
			else	n--;
		}
		
		System.out.println(n);

	}

}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[4]={0},cnt,n,p[5000],a[5000];
  cin>>n;
  for(int i=0;i<n;++i) cin>>p[i];
  for(int i=0;i<=p[0];++i){
    for(int j=0;j<n;++j) a[j]=p[j];
    a[0]-=i;
    c[i]+=i;
    for(int j=0;j<n-1;++j){
      c[i]+=a[j]*2;
      a[j+1]-=a[j];
      a[j]=0;
      if(a[j+1]<0) a[j+1]=0;
    }
    c[i]+=a[n-1];
  }
  cnt=c[0];
  for(int i=1;i<=p[0];++i)
    cnt=min(cnt,c[i]);
  cout<<cnt<<endl;
  return 0;
}
      



Measured memory_bytes: 3156
// Copyright 2020 yaito3014
#include <iostream>
#include <chrono>
#include <vector>
#include <array>
#include <random>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  using namespace chrono_literals;
  chrono::high_resolution_clock clock;
  auto be = clock.now();
  int D;
  cin >> D;
  array<int, 26> c;
  for (auto& e : c) cin >> e;
  vector<array<int, 26>> d(D);
  for (auto& r : d)
    for (auto& e : r) cin >> e;
  auto eval = [&](vector<int> t) {
    int S = 0;
    array<int, 26> last = {};
    for (int i = 0; i < D; ++i) {
      S += d[i][t[i]];
      last[t[i]] = i + 1;
      for (int j = 0; j < 26; ++j) S -= c[j] * (i + 1 - last[j]);
    }
    return S;
  };
  mt19937 mt(random_device{}());
  uniform_int_distribution<int> dist_type(0, 25), dist_day(0, D - 1);
  vector<int> t(D);
  for (int i = 0; i < D; ++i) t[i] = i % 26;
  int S = eval(t);
  while (clock.now() - be < 1950ms) {
    int day1 = dist_day(mt);
    int day2 = dist_day(mt);
    swap(t[day1], t[day2]);
    int score = eval(t);
    if (score > S) {
      S = score;
      continue;
    }
    swap(t[day1], t[day2]);
  }
  for (const auto& e : t) cout << (e + 1) << '\n';
}


Measured memory_bytes: 3224
#include<stdio.h>
#define N 100000
typedef struct{
    char name[11];
    int time_process;
    int time_count;
} queue_in;
void enqueue(queue_in data1);
void dequeue(queue_in data2);
queue_in A[N],B[N],tmp;
int first = 0;
int n;

int main(){
    int q,i,j,tmp_sort,k=0,count=0,tmp_i,flag;
    queue_in sortfor;
    scanf("%d%d",&n,&q);
    tmp_sort = n;
    for(i=0;i<n;i++){
        scanf("%s%d",A[i].name,&A[i].time_process);
    }
    while(n>0){
        if((A[first].time_process -q) <=0){
            A[first].time_count = (A[first].time_process) + count;
            count += A[first].time_process;
            B[k] = A[first];
            k++;
            dequeue(A[first]);
            continue;
        }
        A[first].time_process -= q;
        count += q;
        dequeue(A[first]);
        enqueue(tmp);
    }
    for(i=0;i<tmp_sort;i++){
        tmp_i = i;
        flag = 0;
        for(j=i;j<n;j++){
            if(B[j].time_count<B[tmp_i].time_count){
                tmp_i = j;
                flag = 1;
            }
        }
        if(flag==1){
            sortfor = B[i];
            B[i] = B[tmp_i];
            B[tmp_i] = sortfor;
        }
    }
    for(i=0;i<tmp_sort;i++){
        printf("%s %d\n",B[i].name,B[i].time_count);
    }
}

void enqueue(queue_in data1){
    if(n<N){
        A[(first+n) % N] = data1;
        n++;
    }
}
void dequeue(queue_in data2){
    if(n>0){
        tmp = data2;
        first = (first+1) % N;
        n--;
    }
}


Measured memory_bytes: 4616
#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int A,B,K;
	cin >> A >> B >> K;
	set<int> s;
	for (int i=0; i<K; ++i){
		if (A+i > B) break;
		s.emplace(A+i);
   }
	for (int i=0; i<K; ++i){
		if (B-i < A) break;
		s.emplace(B-i);
	}
	for (auto& i:s) cout << i << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0;i<n;i++)
using namespace std;
int main() {
  int X, A, B;
  cin >> X >> A >> B;
  if (A >= B) {cout << "delicious" << endl;}
  else if (B - A <= X) {cout << "safe" << endl;}
  else {cout << "dangerous" << endl;}
}

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

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

	string before = to_string(n);
	string after = "";
	for (int i = before.size() - 1; 0 <= i; i--)
	{
		after += before.at(i);
	}

	if (before == after)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<int> a;
	vector<int> b;
	a.reserve(N);
	b.reserve(N);
	for (int i = 0; i < N; i++)
	{
		int x;
		cin >> x;
		a.push_back(x);
		b.push_back(x - (i + 1));
	}
	sort(b.begin(), b.end());
	int b_mid = b[b.size() / 2];
	long long int sum=0;
	for (int i = 0; i < N; i++)
	{
		sum += abs(a[i] - (b_mid + 1 + i));
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1792
//
//  main.cpp
//  C
//
//  Created by zzh on 22/04/2017.
//  Copyright © 2017 zzh. All rights reserved.
//

#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
int n;
ll anss ,a[110000];
void work(bool f){
    //ll d=0;
    ll ans=0; ll sum=0;
    for (int i=1; i<=n; i++){
        sum+=a[i];
        //printf("%lld ", sum);
        if (f) {
            if (sum>=0) ans+=sum+1, sum=-1;
        }
        if (!f){
            if (sum<=0) ans+=1-sum,sum=1;
        }
        f=(!f);
    }
    anss=min(anss, ans);
}
int main(){
    scanf("%d", &n);
    for (int i=1; i<=n; i++) scanf("%lld", &a[i]);
    anss=100000000000000LL;
    work(0); work(1);
    printf("%lld", anss);
    return 0;
}

Measured memory_bytes: 896
/*
 ╔═══╦═══╦═══╗
 ║╔═╗║╔══╩╗╔╗║
 ║║░║║╚══╗║║║║
 ║║░║║╔══╝║║║║
 ║╚═╝║╚══╦╝╚╝║
 ╚══╗╠═══╩═══╝
 ░░░╚╝░░░░░░░░
 */

#include <bits/stdc++.h>
#define ll					long long
#define debug(x)			{ cerr << #x << " = " << x << endl; }
#define MOD					1000000007
#define MAX					1e9
#define MIN                 -1e9
#define vi					vector<int>
#define vii					vector<vi>
#define max(x,y)			(x>y)?x:y
#define min(x,y)			(x<y)?x:y
#define mid(s,e)			(s+(e-s)/2)

using namespace std;
ll gcd(ll a, ll b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
}
ll lcm(ll a, ll b) {
	return (a*b) / gcd(a,b);
}
int main() {
	ios::sync_with_stdio(false);
 	cin.tie(0);
	ll a,b;
	cin>>a>>b;
	cout<<lcm(a,b);

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


int n, ans=0;

void solve()
{
    cin >> n;
    for (int i=1; i<=n; i++) {
        string s = to_string(i);
        if (s.size()%2==1) ans++;
    }nout(ans);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n, q = list(map(int, input().split()))
edge = []
for i in range(n-1):
    tempa, tempb = list(map(int, input().split()))
    edge.append((tempa-1, tempb-1))
 
node = [0] * n
 
## 自分のところだけ、カウンターを更新
for i in range(q):
    p, x = list(map(int, input().split()))
    node[p-1] += x
 
edge.sort()
for e in edge:
    node[e[1]] += node[e[0]]


for n in node:
    print(n)

Measured memory_bytes: 41772
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int n = X;
        int a =0;
        int sum = 0;

        while (n > 0){
            a = n % 10;
            n =n / 10;
            sum = sum + a;
        }

        if(X % sum == 0){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

#define rep(i, n) for (ll i=0;i<(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define fi first
#define se second

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;

//vector<vector<ll> > comb(ll n, ll b){
void comb(vector<vector <ll> > &v, ll n){
  cout << v.size();
  rep(i, n){
    v[i][0] = 1;
    v[i][i] = 1;
  }

  rep(j, n) {
    rep(k,j) {
      v[j][k] = (v[j-1][k-1] + v[j-1][k]);
    }
  }
}


int main(){
  ll n,a,b,c;
  cin >> n ;

  ll dp[3][n+1];
  dp[0][0]=0;
  dp[1][0]=0;
  dp[2][0]=0;
  rep(i,n){
    cin >> a >> b >> c;
    dp[0][i+1] = max(dp[1][i], dp[2][i]) + a;
    dp[1][i+1] = max(dp[2][i], dp[0][i]) + b;
    dp[2][i+1] = max(dp[0][i], dp[1][i]) + c;
  }

  cout << max(max(dp[0][n], dp[1][n]), dp[2][n]) << endl;


}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
long long a[200005],mp[2100],ans;
int main(){
	string s;
	cin>>s;
	reverse(s.begin(),s.end());
	long long y=1;
	for(int i=0;i<s.size();i++){
		a[i]=(y*(s[i]-'0'))%2019;
		y=(y*10)%2019;
	}
	y=0;
	for(int i=0;i<s.size();i++){
		y=(y+a[i])%2019;
		mp[y]++;
	}
	for(int i=0;i<2019;i++)
		ans+=mp[i]*(mp[i]-1)/2;
	ans+=mp[0];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5268
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        new Main().run();
    }

    private void run() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int X = scanner.nextInt();
        int num = 1;
        int sum = 0;
        int[] L = new int[N];
        for(int i = 0; i < N; i++) {
            L[i] = scanner.nextInt();
            sum += L[i];
            if(sum <= X) {
                num++;
            }
        }
        System.out.println(num);
    }
}


Measured memory_bytes: 22996