akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int a[55], b[55], dp[(1 << 18) + 10][20];
int bitcnt(int n) {
	int ret = 0;
	while (n > 0) { ret += n % 2; n /= 2; }
	return ret;
}

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

	int N;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> a[i];
	for (int i = 0; i < N; i++)cin >> b[i];
	for (int i = 0; i < (1 << 18) + 10; i++)for (int j = 0; j < 20; j++)dp[i][j] = (int)1e7;



	for (int i = 1; i < (1 << N); i++) {
		for (int j = 0; j < N; j++) {
			if (!(i & (1 << j)))continue;
			int cnt = bitcnt(i - (1 << j));
			if (cnt == 0) { dp[i][j] = 0; continue; }
			for (int k = 0; k < N; k++) {
				if (!((i-(1 << j))&(1 << k)))continue;
				int mxj = (abs(cnt - j) % 2 == 0) ? a[j] : b[j];
				int mxk = (abs(cnt - 1 - k) % 2 == 0) ? a[k] : b[k];
				if (mxj < mxk)continue;
				int add = 0;
				for (int l = j + 1; l < N; l++) {
					add += (1 & (i >> l));

				}
				dp[i][j] = min(dp[i][j],dp[i - (1 << j)][k] + add);
			}
		}
	}


	int ans = (int)1e7;
	for (int j = 0; j < N; j++)ans = min(ans, dp[(1 << N) - 1][j]);
	if (ans > 1e6)puts(-1);
	else puts(ans);

	return 0;
}

Measured memory_bytes: 20864
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <sstream>
#include <bitset>
#include <memory>
#include <string>
#include <vector>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <deque>
#include <algorithm>
#include <random>
#include <iomanip>
using namespace std;

int main(int argc, char *argv[]) {
	int k, d;
	cin >> k >> d;
	if (k * 500 >= d) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}









Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std ;

    int main(){

        int N ;
        
        double D , x , y ;

        int points {0};

       

        cin>>N>>D;
        cout<<endl;

        for(int i {0}; i < N ; i++){
            cin>>x>>y;

             double mDistance {sqrt(((x*x) + (y*y)))};

            if(mDistance <= D){
                points++;
            }
        }

        cout<<points;

        
    } 

Measured memory_bytes: 3812
#include<iostream>
#include <algorithm>
#include<string>
#include <bitset>
#include <vector>
#include <functional>
#include <climits>
#include <iomanip>
#include <utility>
#include <string.h>
#include <cmath>
using namespace std;
using ll = long long;
typedef pair <int, int> pii;

int main()
{

	double a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0, ans = 0;
	//cout << LONG_MAX << endl;
	//long long n, A[1000000000];
	//ll n, m, q;
	cin >> a;
	cin >> b;
	cin >> c;
	double z[1003];
	for (ll i = 0; i < a; i++)
	{
		cin >> z[i];
	}
	d = 100000000;
	for (ll i = 0; i < a; i++)
	{
		if (abs(-z[i] * 0.006 + b - c)<d)
		{
			d = abs(-z[i] * 0.006 + b - c);
			e = i;
		}
	}


	cout << e + 1 << endl;
	////std::cout << std::fixed;
	//cout << std::setprecision(20) << << endl;
	//cout << d+1 << endl;
	//cout << "" << endl;

	return 0;
}
//lower_bound(A, A + n, d)//配列のなかからd以上のなかの最小値を探して配列番号を返す関数


Measured memory_bytes: 256
/*
 * Author: .-O_O-.
 */
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define rep0(a,b) for(int a=0;a<b;a++)
#define rep1(a,b) for(int a=1;a<=b;a++)
#define repp(a,b,c) for(int a=b;a<c;a++)
#define in insert
#define len length()
#define si size()
#define lb lower_bound
#define ub upper_bound
#define beg begin()
#define en end()
#define f first
#define s second
#define pr(a) cout<<a
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define nx cout<<"\n"
#define int long long
const ll mod = 1000000007;
const ll maxn = 200005;
const ll mm = 1e+18;
void solve()
{
    string s;
    cin>>s;
    if(s=="ABC") cout<<"ARC";
    else cout<<"ABC";
}
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    //srand(time(0));
    //freopen("sp.txt","w",stdout);
    //cin>>t;
    rep1(_i,t){
        //cout<<"Case #"<<_i<<": ";
        solve();
        //nx;
    }
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>

int main(int argc, const char * argv[]) {
    
    int top1=0, top2=0, top3=0 ;
    
    for (int i=0; i<10; i++) {
        int inputNum ;
        std::cin >> inputNum ;
        if ( inputNum > top1 ) {
            top3 = top2 ;
            top2 = top1 ;
            top1 = inputNum ;
        } else if ( inputNum > top2 ) {
            top3 = top2 ;
            top2 = inputNum ;
        } else if ( inputNum > top3 ) {
            top3 = inputNum ;
        }
    }
    
    printf("%d\n%d\n%d\n", top1, top2, top3) ;
    
    return 0;
}


Measured memory_bytes: 3220
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

typedef pair<int,int> edge;

class Union_Find {
public:
  vector<int> par;

  Union_Find(int n) : par(n, -1) {}
  void init(int n) {
    par.assign(n, -1);
  }

  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool issame(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (par[x] > par[y]) swap(x,y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }

  int size(int x) {
    return -par[root(x)];
  }
};

int main() {
  ll n,m;
  cin >> n >> m;
  vector<int> A(m), B(m);
  for (int i = 0; i < m; ++i) {
    cin >> A[i] >> B[i], --A[i], --B[i];
  }

  Union_Find uf(n);
  ll cur = n * (n - 1) / 2;
  vector<ll> res;
  for (int i = 0; i < m; ++i) {
    res.push_back(cur);

    int ta = A[m-1-i], tb = B[m-1-i];
    if (uf.issame(ta,tb)) continue;
    
    ll sa = uf.size(ta), sb = uf.size(tb);
    // cout << sa << " " << sb << endl;
    cur -= sa * sb;
    uf.merge(ta,tb);
  }

  for (int i = m-1; i >= 0; --i) {
    cout << res[i] << endl;
  }
}


Measured memory_bytes: 3444
N = int(input())
a = list(map(int, input().split()))

S = [0 for _ in range(N + 1)]
for i in range(1, N + 1):
    S[i] = S[i - 1] + a[i - 1]

ans = float("inf")
for i in range(1, N):
    snuke = S[i] - S[0]
    kuma = S[N] - S[i]
    score = abs(snuke - kuma)
    ans = min(ans, score)

print(ans)

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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout<< #i<< "= "<< i << endl
using namespace std;

int fact( int n){
    int ret = 1;
    FORB(i, n, 2) ret *= i;
    return ret;
}
int main(){
    int n;
    cin >> n;
    int p[n],q[n],ansp=0,ansq=0;
    bool check[n] = {};

    REP(i,n) cin >> p[i];
    REP(i,n) cin >> q[i];
    
    REP(i,n){
        int count = 0;
        REP(j,n){
            if(j+1 == p[i]){
                check[j] = true;
                break;
            } 
            if(check[j] == 0) count++;
        }
        
        ansp += count * fact(n - 1 - i);
    }
    REP(i,n) check[i] = false;

        REP(i,n){
        int count = 0;
        REP(j,n){
            if(j+1 == q[i]){
                check[j] = true;
                break;
            } 
            if(check[j] == 0) count++;
        }
        ansq += count * fact(n - 1 - i);
       // debug(count);
    }
    cout << abs(ansp - ansq) << endl;
    //debug(ansp); debug(ansq);
}


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

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

    int n;
    cin >> n;
    vector<vector<pair<int, int>>> A(n);
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        for(int j = 0; j < a; j++){
            int x, y;
            cin >> x >> y;
            A[i].push_back(make_pair(x - 1, y));
        }
    }

    // 正直者をbit全探索
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        vector<int> F(n, false);
        set<int> st;
        for(int j = 0; j < n; j++){
            if((i >> j) & 1){
                // bitが立っている時の処理
                F[j] = true;
                st.insert(j);
            }
        }

        bool f = true;
        for(int j = 0; j < n; j++){
            if(st.count(j) != 1) continue;
            for(int k = 0; k < int(A[j].size()); k++){
                pair<int, int> p = A[j][k];
                int person = p.first;
                int honest = p.second;
                if(honest == 1 and F[person] == false){
                    f = false;
                    break;
                }
                if(honest == 0 and F[person] == true){
                    f = false;
                    break;
                }
            }
            if(!f) break;
        }

        if(f){
            int cnt = 0;
            for(int j = 0; j < n; j++){
                if(F[j]) cnt++;
            }
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<map>
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
long long s[100007];
int m;
unsigned long long ans=0;
map<long long,int>mp;
void merge(int l,int r)
{
    if(l==r){if((s[r]-s[l-1]+m)%m==0)ans++;return;}
    int mid=(l+r)>>1;
    merge(l,mid);
    merge(mid+1,r);
    mp.clear();
    for(int i=l;i<=mid;++i)
    {
    mp[(m+s[i-1])%m]++;
    //cout<<i<<" "<<mid<<" "<<(s[mid]-s[i-1]+m)%m<<endl;
    }
    for(int i=mid+1;i<=r;++i)
    {
        if(mp.find((s[i])%m)!=mp.end())
        {
            ans+=mp[(s[i])%m];
        }
    }
    return;
}
int main()
{
    int n;
    scanf("%d%d",&n,&m);
    int x;
    for(int i=1;i<=n;++i)
    {
        scanf("%d",&x);
        s[i]=s[i-1]+x;
        if(s[i]>=m)s[i]-=m;
    }
    merge(1,n);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int a = 1, b = 1;
        while (a != 0 && b != 0) {
            a = scanner.nextInt();
            b = scanner.nextInt();
            if (a == 0 && b == 0) {
                break;

            }

            for (int i = 1; i <= a; i++) {
                for (int j = 1; j <= b ; j++) {
                    if (i == 1 && j != b) {
                        System.out.print("#");
                    }
                    else if (i == a && j != b ) {
                        System.out.print("#");
                    }
                    else if (j == b) {
                        System.out.println("#");
                    }
                    else if(j==1){
                        System.out.print("#");
                    }
                    else{
                        System.out.print(".");
                    }
                    
                }
            }System.out.println("");
        }
        
    }
}

Measured memory_bytes: 33580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
#define arrlen(arr) (sizeof(arr)/sizeof(arr[0]))
#define Sort(arr) sort(arr, arr+arrlen(arr))
#define For(i,s,n) for(int i=s;i<n;i++)
	
int main(){
	int P,Q,R;
	cin >> P >> Q >> R;
	cout << min(P+Q,min(Q+R,R+P));
}

Measured memory_bytes: 764
for i in range(4) :
    t, n = map(int, input().split())
    if t == 1 :
        print(6000 * n)
    elif t == 2 :
        print(4000 * n)
    elif t == 3 :
        print(3000 * n)
    elif t == 4 :
        print(2000 * n)


Measured memory_bytes: 5596
#include<iostream>
#include<string>
#include<string.h>
#include<math.h>
#include<vector>
#include<algorithm>	

using namespace std; 

int main() 
{ 
//	ios::sync_with_stdio(0);
//	cin.tie(0);
	
	long long x,b=100,y=0;
	cin>>x;
	
	while(b<x){
		b = 1.01*b;
		y++;
	}
	cout<<y;
	
	return 0; 
} 


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
using ll = long long int;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main()
{
   IOS;
   //freopen("inputfile.txt","r",stdin);
  int n;cin>>n;
  ll sum = 0;
  for(int i=1;i<=n;i++)
  {
      for(int j=1;j<=n;j++)
      {
          for(int k=1;k<=n;k++)sum+=__gcd(__gcd(i,j),k);
      }
  }
  cout<<sum<<endl;
    return 0;
}
//<!...........ALHAMDULILLAH.............!!>>



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

int main() {
  int h, n;
  cin>>h>>n;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  long sum = 0;
  for (int i=0; i<n; i++) sum += a[i];
  if (sum >= h) {
    cout<<"Yes"<<endl;
  } else {
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&!(1<<i);}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mul(int a, int b) {return ((a%MOD)*(b%MOD))%MOD;}
int add(int a, int b) {return (a+b)%MOD;}
int sub(int a, int b) {return (((a-b)%MOD)+MOD)%MOD;}
int __div(int a, int b) {return mul(a, powmod(b, MOD-2, MOD));} //if MOD is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
int getInvCount(vi& arr) 
{ 
	int n = arr.size();
    int inv_count = 0; 
    for (int i = 0; i < n - 1; i++) 
        for (int j = i + 1; j < n; j++) 
            if (arr[i] > arr[j]) 
                inv_count++; 
  
    return inv_count; 
} 
int32_t main(void)
{
	IOS;
	int mod=1000000007;
	int n; cin>>n;
	string s;
	cin>>s;
	int dn[2*n];
	if(s[0]=='B') dn[0]=0;
	else dn[0]=1;
	for(int i = 1; i < 2*n; i++){
		if(s[i] != s[i-1]) dn[i]=dn[i-1];
		else dn[i]=(dn[i-1]^1);
	}
	// for(int i = 0; i  <2*n; i++) cout<<dn[i]<<" ";
	// cout<<endl; 
	int ct=0, i=0;
	int ans=1;
	while(i < 2*n) {
		if(dn[i]) {
			if(!ct) { cout<<0<<endl; return 0;}
			else { 
				ans = (ans*ct)%mod;
				ct--;
			}
		} else ct++;
		i++;
	}
	int fac=1;
	for(int i = 1; i <= n; i++) fac=(fac*i)%mod;
	// cout<<"GOOD"<<endl;
	if(ct) cout<<0<<endl;
	else cout<<(ans*fac)%mod<<endl;
 	time();
	return 0;
}

Measured memory_bytes: 2196
n = gets.to_s.to_i
a = gets.to_s.split.map{|t|t.to_i}
q = gets.to_s.to_i
bcs = Array.new(q){ gets.to_s.split.map{|t|t.to_i} }

s = a.sum
t = a.tally
t.default = 0

bcs.each do |b, c|
  
  s -= b * t[b]
  s += c * t[b]
  
  t[c] += t[b]
  t[b] = 0
  
  puts s
end

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

int A[2000];
int KK[2000000];
int N,M;
int k;
void getK()
{
	k = 0;
	for(int i =0; i<=N; i++)
		for(int j = i; j<=N; j++)
			KK[k++] = A[i]+A[j];	
	
	sort(KK,KK+k);		

}


int binarySearch(int a)
{
	int left = 0;
	int right = k;
	int mid;
	while(left+1<right)
	{
		mid = (left+right)/2;
		if(KK[mid] <= a) left = mid;
		else right = mid;
	}

	return KK[left];
}
void solve()
{
	
	int maxS = 0;
	for(int i =0; i<=N;i++)
		for(int j = 0; j <=N; j++)
		{
			int temp = binarySearch(M-A[i]-A[j])+A[i]+A[j];	
			if(temp > maxS && temp <= M)
				maxS = temp;
		}
	cout << maxS << endl;
}

int main()
{
	A[0] = 0;
	while(cin >>N>>M && N||M)
	{
		
		for(int i = 1; i<=N;i++)
			cin >> A[i];
		sort(A,A+N+1);
		getK();
		solve();
	}
}

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

int main(){
    int n,m,x,a;
    int A[1000];
    cin >> n >> m >> x;
    for(int i = 0; i < m; i++){
        cin >> A[i];
    }
    for(int i = 0; i < m; i++){
        if(A[i]<x){
            a++;
        }
    }
    int b = m-a;
    cout << min(a,b)  << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <iomanip>

#define PI 3.14159265359	

using namespace std;

int main(){
	int h, w;
	while (1){
		cin >> h >> w;
		if (h == 0 && w == 0) break;
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				if((i + j) % 2) cout << ".";
				else cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

}

Measured memory_bytes: 3068
n,m=map(int,input().split())
h_list=list(map(int,input().split()))
lst=[0]*n
for _ in range(m):
  a,b=map(int,input().split())
  if h_list[a-1]<=h_list[b-1]:
    lst[a-1]-=1
  if h_list[a-1]>=h_list[b-1]:
    lst[b-1]-=1
print(lst.count(0))

Measured memory_bytes: 20016
<?php
    $input1 = fgets(STDIN);
    $input2 = str_split(fgets(STDIN));
    $count = 0;
    $max = 0;

    for ($i=0;$i<$input1;$i++) {
        if ($input2[$i] == "I") {
            $count++;
            if($count > $max) {
                $max = $count;
            }
        } else if ($input2[$i] == "D") {
            $count--;
        }
    }

    if ($max>0) {
        echo $max;
    } else {
        echo "0";
    }
?>

Measured memory_bytes: 3704
# input
n = int(input())
edges = set(tuple(int(i) for i in input().split()) for _ in range(n-1))


from collections import deque


def make_connection(tree):
    con = [[] for _ in range(n+1)]
    for edge in tree:
        con[edge[0]].append(edge[1])
        con[edge[1]].append(edge[0])
    return con


def diameter(tree):
    c = make_connection(tree)
    _, s = farest(tree, c, 1)
    diam, _ = farest(tree, c, s)
    return diam


def farest(tree, con, i):
    dp = [None for _ in range(n+1)]
    dp[i] = 0
    cand_q = deque()
    cand_q.append(i)

    while len(cand_q) > 0:
        u = cand_q.popleft()

        for v in con[u]:
            if dp[v] is None:
                cand_q.append(v)
                dp[v] = dp[u] + 1
    max_ = max(dp[1:])
    i_max = dp.index(max_)
    return max_, i_max


d = diameter(edges)


print('Second' if d % 3 == 1 else 'First')


Measured memory_bytes: 123216
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;

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

	long long n, i, j, k, a, b, id, t, x, s;
	cin >> n >> t;
	vector<vector<long long>> adj(n + 1);
	vector<long long> ans(n + 1, 0), pos, parent(n + 1, -1), start(n + 1, 0), end(n + 1, 0), in(n + 1, 0), out(n + 1, 0);
	for (i = 0; i < n - 1; i++) {
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}

	stack<int> sq;
	stack<int> st;
	parent[1] = 0;
	sq.push(1);

	while (!sq.empty()) {
		id = sq.top();
		sq.pop();
		start[id] = pos.size();
		end[id] = pos.size();
		pos.push_back(id);

		for (auto p : adj[id]) {
			if (parent[p] == -1) {
				parent[p] = id;
				sq.push(p);
				st.push(p);
			}
		}
	}

	while (!st.empty()) {
		id = st.top();
		st.pop();
		end[parent[id]] = max(end[parent[id]], end[id]);
	}

	while (t--) {
		cin >> id >> x;
		in[start[id]] += x;
		out[end[id]] -= x;
	}

	s = 0;
	for (i = 0; i < n; i++) {
		s += in[i];
		ans[pos[i]] = s;
		s += out[i];
	}

	for (i = 1; i <= n; i++) cout << ans[i] << " ";
	cout << "\n";

	return 0;
}


Measured memory_bytes: 27380
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;

typedef pair<ll,int> PL;

vl d;
void dijkstra(v(vp) &G,int V,int s) {
// G[f][i] = P(t,c) means that from `f` to `t` 's cost is `c` 
  d = vl(V,LINF);
  PQ(PL) que;
  d[s] = 0;
  que.emplace(0,s);
  while(!que.empty()) {
    PL p = que.top();
    que.pop();
    int tar = p.second;
    if(d[tar] < p.first) continue;
    rep(i,sz(G[tar])) {
      P e = G[tar][i];
      if(d[e.first] > d[tar] + e.second) {
        d[e.first] = d[tar] + e.second;
        que.emplace(d[e.first],e.first);
      }
    }
  }
}

class RMQ {
  public:
  int N;
  vl segtree;
  RMQ(int n) {
    N = 1;
    int len = 1;
    while(N < n) {
      N *= 2;
      len += N;
    }
    segtree = vl(len,LINF);
  }
  void build(int idx,ll val) {
    int s = sz(segtree) - (N-idx);
    segtree[s] = val;
    while(1) {
      if(s == 0) break;
      s = (s-1)/2;
      segtree[s] = min(segtree[s*2+1],segtree[s*2+2]);
    }
  }
  ll _query(int a,int b,int idx,int l,int r) {
    if(a <= l && r <= b) return segtree[idx];
    if(r <= a || b <= l) return LINF;
    ll vl = _query(a,b,idx*2+1,l,(l+r)/2);
    ll rl = _query(a,b,idx*2+2,(l+r)/2,r);
    return min(vl,rl);
  }
  // min(A[i] | l <= i < r)
  ll query(int l,int r) {
    return _query(l,r,0,0,N);
  }
};
  
int main() {
  int N,M,s,t;
  cin >> N >> M >> s >> t;
  s--;t--;
  v(vp) ag(N),bg(N);
  rep(i,M) {
    int x,y,a,b;
    cin >> x >> y >> a >> b;
    x--;y--;
    ag[x].emplace_back(y,a);
    ag[y].emplace_back(x,a);
    bg[x].emplace_back(y,b);
    bg[y].emplace_back(x,b);
  }
  dijkstra(ag,N,s);
  vl ad(d);
  dijkstra(bg,N,t);
  vl bd(d);
  RMQ seg(N);
  rep(i,N) {
    seg.build(i,ad[i]+bd[i]);
  }
  auto ans = [&]() {
    cout << ll(10e14)-seg.query(0,N) << endl;
  };
  ans();
  rep(i,N-1) {
    seg.build(i,LINF);
    ans();
  }
  return 0;
}

Measured memory_bytes: 19508
#include<bits/stdc++.h>
using namespace std;
char arr[100005];
int main(){
	int n,ind=0,a,b,c;
	string cur;
	cin>>n>>a>>b>>c>>cur;
	for(int i=0;i<n;i++)
		if(cur=="AB")
			if(a>b){
				arr[ind++]='B';
				if(i<n-1)
					cin>>cur;
				a--;
				b++;
				continue;
			}
			else if(a<b){
				arr[ind++]='A';
				if(i<n-1)
					cin>>cur;
				a++;
				b--;
				continue;
			}
			else if(a==b&&a==0){
				cout<<"No"<<endl;
				return 0;
			}
			else{
				if(i<n-1)
					cin>>cur;
				else{
					arr[ind++]='A';
					break;
				}
				if(cur=="AB"){
					arr[ind++]='A';
					arr[ind++]='B';
					i++;
					if(i<n-1)
						cin>>cur;
					continue;
				}
				else if(cur=="AC"){
					arr[ind++]='A';
					a++;
					b--;
					continue;
				}
				else{
					arr[ind++]='B';
					b++;
					a--;
					continue;
				}
			}
		else if(cur=="BC")
			if(b>c){
				arr[ind++]='C';
				if(i<n-1)
					cin>>cur;
				c++;
				b--;
				continue;
			}
			else if(c>b){
				arr[ind++]='B';
				if(i<n-1)
					cin>>cur;
				b++;
				c--;
				continue;
			}
			else if(c==b&&c==0){
				cout<<"No"<<endl;
				return 0;
			}
			else{
				if(i<n-1)
					cin>>cur;
				else{
					arr[ind++]='C';
					break;
				}
				if(cur=="BC"){
					arr[ind++]='C';
					arr[ind++]='B';
					i++;
					if(i<n-1)
						cin>>cur;
					continue;
				}
				else if(cur=="AC"){
					arr[ind++]='C';
					c++;
					b--;
					continue;
				}
				else{
					arr[ind++]='B';
					b++;
					c--;
					continue;
				}
			}
		else
			if(a>c){
				arr[ind++]='C';
				if(i<n-1)
					cin>>cur;
				c++;
				a--;
				continue;
			}
			else if(c>a){
				arr[ind++]='A';
				if(i<n-1)
					cin>>cur;
				a++;
				c--;
				continue;
			}
			else if(c==a&&c==0){
				cout<<"No"<<endl;
				return 0;
			}
			else{
				if(i<n-1)
					cin>>cur;
				else{
					arr[ind++]='A';
					break;
				}
				if(cur=="AC"){
					arr[ind++]='C';
					arr[ind++]='A';
					i++;
					if(i<n-1)
						cin>>cur;
					continue;
				}
				else if(cur=="BC"){
					arr[ind++]='C';
					c++;
					a--;
					continue;
				}
				else{
					arr[ind++]='A';
					a++;
					c--;
					continue;
				}
			}
	cout<<"Yes"<<endl;
	for(int i=0;i<ind;i++)
		cout<<arr[i]<<endl;
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
typedef long long int lli;
using namespace std;
 int main(){
    int w,h,n,x,y,a;
    cin >> w >> h >> n;
    int max_x=w;
    int min_x=0;
    int max_y=h;
    int min_y=0;

    for(int i=0; i<n; i++){
        cin >> x >> y >> a;
        if(a==1){
            min_x=max(min_x,x);
        }else if(a==2){
            max_x=min(max_x,x);
        }else if(a==3){
            min_y=max(min_y,y);
        }else{
            max_y=min(max_y,y);
        }
    }
    if(max_x - min_x < 0 )
        cout << 0;
    else if(max_y - min_y < 0)
        cout << 0;
    else
        cout << (max_x - min_x)*(max_y - min_y);


     return 0;
 }


Measured memory_bytes: 3604
N, M, Q = [int(n) for n in input().split()]
a, b, c, d = [list(x) for x in zip(*[[int(n) for n in input().split()] for _ in range(Q)])]
ans = 0
def dfs(A):
    global ans
    if len(A) == N+1:
        now = 0
        for i in range(Q):
            if A[b[i]] - A[a[i]] == c[i]:
                now += d[i]
        ans = max(ans, now)
        return
    tail = A[-1] if len(A) > 0 else 1
    for v in range(tail, M+1):
        A.append(v)
        dfs(A)
        A.pop()

dfs([])
print(ans)

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

int N;
int A1[100010];
int A2[100010];

int main()
{
    scanf("%d",&N);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d",A1 + i);
        A1[i] += A1[i - 1];
    }
    for(int i = 1; i <= N; i++)
    {
        scanf("%d",A2 + i);
    }
    for(int i = N - 1; i >= 0; i--)A2[i] += A2[i + 1];
    int ans = 0;
    for(int i = 0; i <= N; i++)
    {
        ans = max(ans,A1[i] + A2[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
n=int(input())

import random
def is_prime3(q,k=50):
    q = abs(q)
    #計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q&1 == 0: return False

    #n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q-1)>>1
    while d&1 == 0:
        d >>= 1
    
    #判定をk回繰り返す
    for i in range(k):
        a = random.randint(1,q-1)
        t = d
        y = pow(a,t,q)
        #[0,s-1]の範囲すべてをチェック
        while t != q-1 and y != 1 and y != q-1: 
            y = pow(y,2,q)
            t <<= 1
        if y != q-1 and t&1 == 0:
            return False
    return True

while True:
     if is_prime3(n):
         break
     n+=1
print(n)

Measured memory_bytes: 5224
from collections import defaultdict
import sys
sys.setrecursionlimit(100005)

class Graph:
    def __init__(self, N):
        self.in_degree = [0] * (N+1)
        self.dist = [0] * (N+1)
        self.visited = [False] * (N+1)
        self.edges = defaultdict(list)
        self.N = N

    def add_edge(self, x, y):
        self.edges[x].append(y)
        self.in_degree[y] += 1

    def dfs(self, x):
        self.visited[x] = True
        for y in self.edges[x]:
            self.dist[y] = max(self.dist[y], self.dist[x] + 1)
            self.in_degree[y] -= 1
            if self.in_degree[y] == 0:
                self.dfs(y)

    def longest_path(self):
        for i in range(1, self.N+1):
            if not self.visited[i] and self.in_degree[i] == 0:
                self.dfs(i)

        ans = 0
        for i in range(1, self.N+1):
            ans = max(ans, self.dist[i])

        return ans


def main():
    N, M = map(int, input().split())
    graph = Graph(N)
    for _ in range(M):
        x, y = map(int, input().split())
        graph.add_edge(x, y)

    ans = graph.longest_path()
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 190808
#include<stdio.h>
int main( ){
  int H,W;
  while( 1 ){
    scanf("%d %d",&H,&W);
    if( H==0&&W==0 )break;
    for( int i = 0 ; i < H ; i++ ){
      for( int j = 0 ; j < W ; j++ ){
	printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 2576
#include<stdio.h>
int a(int a){return a>0?a:-a;}
int main(){
  int n,x,y,v=0,w=0,t,s=0,i,u;
  scanf("%d",&n);
  for(i=0;i<n;i++){scanf("%d%d%d",&t,&x,&y);u=t-s-a(v-x)-a(w-y);if(u<0||u%2){printf("No");return 0;}v=x;w=y;s=t;}
  printf("Yes");
}


Measured memory_bytes: 1700
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;

const int mod=1e9+7;
const int maxn=100111;
int qpow(int x,int y)
{
	int ret=1;
	while(y)
	{
		if(y&1)ret=(LL)ret*x%mod;
		x=(LL)x*x%mod;
		y>>=1;
	}
	return ret;
}

inline void add(int&x,int y){x+=y;if(x>=mod)x-=mod;}

int fac[maxn],invf[maxn];
int n,m,a[20],dp[1<<16];

int main()
{
	fac[0]=1;for(int i=1;i<maxn;i++)fac[i]=(LL)i*fac[i-1]%mod;
	invf[maxn-1]=qpow(fac[maxn-1],mod-2);for(int i=maxn-1;i>=1;i--)invf[i-1]=(LL)i*invf[i]%mod;
	
	scanf("%d%d",&n,&m);for(int i=1;i<=m;i++)scanf("%d",a+i);
	sort(a+1,a+m+1);
	
	dp[0]=1;
	for(int i=m;i>=1;i--)
	{
		for(int j=(1<<n)-1;j>=0;j--)
		{
			int have=(1<<n)-a[i]+1-j;
			if(have<0)continue;
			for(int k=0;k<n;k++)if((have>>k)&&((j>>k)&1)==0)
				add(dp[j|(1<<k)],(LL)dp[j]*fac[have-1]%mod*invf[have-(1<<k)]%mod*(1<<k)%mod);
		}
	}
	int ans=0;
	for(int j=0;j<(1<<n);j++)
	{
		int coef=(LL)dp[j]*fac[(1<<n)-j-1]%mod;
		if(__builtin_popcount(j)&1)add(ans,mod-coef);
		else add(ans,coef);
	}
	ans=(LL)ans*(1<<n)%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#define inf 1e9
using namespace std;
int solve(vector<int> ar, int n)
{
    vector<int> dp(n+1);
    dp[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        int option1 = abs(ar[i] - ar[i-1]) + dp[i-1];
        int option2 = (i == 2) ? inf : abs(ar[i] - ar[i-2]) + dp[i-2];
        dp[i] = min(option1, option2);
    }
    return dp[n];
}
int main() {
    int n;
    cin >> n;
    vector<int> ar(n+1);
    for(int i = 1; i <= n; i++)
    {
        cin >> ar[i];
    }
    cout << solve(ar, n);
}


Measured memory_bytes: 1408
/// Updated! https://www.youtube.com/watch?v=U07_n9xGIlM
#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define dbug printf("I am here\n");
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int maxn = 2e5+100;

const ll inf = 1e18;

int a[33];

int main()
{
    fast;
    ll a , b;
    cin >> a >> b;
    ll gg = __gcd(a,b);

    cout << (a*b)/gg << endl;

    return 0;
}
/*



*/



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define Maxn 1000000 + 7
using namespace std;
int n,step,tt,a[Maxn],x[Maxn],y[Maxn],t[Maxn];
bool f = true;
int main()
{
    cin>>n;
    x[0] = 0; y[0] = 0; t[0] = 0;
    for (int i = 1; i <= n; i++)
        cin>>t[i]>>x[i]>>y[i];
    for (int i = 1; i <= n; i++)
    {
        step = abs(x[i] - x[i-1]) + abs(y[i] - y[i-1]);
        tt = t[i] - t[i-1];
        if(step == 0 && tt % 2 != 0)
        {
            f = false;
            break;
        }
        if(step > tt)
        {
            f = false;
            break;
        }
        if(tt % step != 0)
        {
            f = false;
            break;
        }
    }
    // cout<<t[1]<<x[0]<<y[0]<<tt<<endl;
    if(f == true)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 8832
N = int(input())
A = list(map(int, input().split()))
Ll, Lr, Rl, Rr = 0, A[0], A[1], sum(A[2:])
idx_l = 0  # 次に足すもの
idx_r = 2  # 次に足すもの
ans = float("inf")
for i, a in enumerate(A[1:-2], 1):
    Lr += a
    Rl -= a
    while True:
        a_ = A[idx_l]
        if abs((Ll+a_)-(Lr-a_)) < abs(Ll-Lr):
            Ll += a_
            Lr -= a_
            idx_l += 1
        else:
            break
    while True:
        a_ = A[idx_r]
        if abs((Rl+a_)-(Rr-a_)) < abs(Rl-Rr):
            Rl += a_
            Rr -= a_
            idx_r += 1
        else:
            break
    ans = min(ans, max(Ll, Lr, Rl, Rr)-min(Ll, Lr, Rl, Rr))
print(ans)


Measured memory_bytes: 24684
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<vector>
using namespace std;
#define MAX_V 100001
#define INF (1e9 + 1)

int V,E,r,a,b,c;
vector<int> G_t[MAX_V];
vector<int> G_c[MAX_V];

int d[MAX_V];
void dijkstra(){
  int i;
  for(i=0;i<MAX_V;i++)d[i]=INF;
  d[r]=0;
  priority_queue< pair<int,int> > Q;
  Q.push( make_pair(-d[r],r) );
  while(!Q.empty()){
    pair<int ,int > p=Q.top();
    Q.pop();
    int pos=p.second,cost=-p.first;
    if(cost > d[pos] )continue;
    for(i=0;i<G_t[pos].size();i++){
      int to=G_t[pos][i];
      int newcost=cost+G_c[pos][i];
      if(newcost <d[to]){
	d[to]=newcost;
	Q.push( make_pair(-d[to],to) );
      }
    }
  }
  for(i=0;i<V;i++){
    if(d[i]==INF)printf("INF\n");
    else printf("%d\n",d[i]);
  }
}
int main(){
  int i;
  scanf("%d%d%d",&V,&E,&r);
  for(i=0;i<E;i++){
    scanf("%d%d%d",&a,&b,&c);
    G_t[a].push_back(b);
    G_c[a].push_back(c);
  }
  dijkstra();
  return 0;
}

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

int n, k;
int arr[100001][3];
int dp[100001][3];

int main(){
    cin>>n;
    for(int x=1;x<=n;x++)
        cin>>arr[x][0]>>arr[x][1]>>arr[x][2];

    for(int x=1;x<=n;x++){
        dp[x][0] = arr[x][0] + max(dp[x-1][1], dp[x-1][2]);
        dp[x][1] = arr[x][1] + max(dp[x-1][0], dp[x-1][2]);
        dp[x][2] = arr[x][2] + max(dp[x-1][1], dp[x-1][0]);
    }
    cout<<max({dp[n][0], dp[n][1], dp[n][2]});
}


Measured memory_bytes: 5940
#include<cstdio>
#include<algorithm>
#define ls k<<1,l,mid
#define rs k<<1|1,mid+1,r
#define ROF(i,s,t) for(register int i=s;i>=t;--i)
#define FOR(i,s,t) for(register int i=s;i<=t;++i)
using namespace std;
int n,m,tail;
const int N=800011;
int ans[N];
namespace Segment_Tree{
	int tr[N];
	inline void modify(int x,int y,int v,int k=1,int l=0,int r=m){
		if(x<=l&&r<=y){
			tr[k]+=v;
			return;
		}
		int mid=(l+r)>>1;
		if(x<=mid)modify(x,y,v,ls);
		if(mid<y)modify(x,y,v,rs);
	}
	inline int query(int x,int k=1,int l=0,int r=m){
		if(l==r)return tr[k];
		int mid=(l+r)>>1;
		if(x<=mid)return query(x,ls)+tr[k];
		return query(x,rs)+tr[k];
	}
}
using namespace Segment_Tree;
struct node{
	int l,r,len;
	inline bool operator<(node A)const{
		return len>A.len;
	}
}q[N];
int main(){
	//freopen("train.in","r",stdin);
	//freopen("train.out","w",stdout);
	scanf("%d%d",&n,&m);
	FOR(i,1,n){
		scanf("%d%d",&q[i].l,&q[i].r);
		q[i].len=q[i].r-q[i].l+1;
		modify(q[i].l,q[i].r,1);
	}
	sort(q+1,q+n+1);
	ROF(i,m,1){
		while(tail<=n&&q[tail+1].len>=i)++tail,modify(q[tail].l,q[tail].r,-1);
		ans[i]=tail; 
		for(register int j=0;j<=m;j+=i)
			ans[i]+=query(j);
	}
	FOR(i,1,m)
		printf("%d\n",ans[i]);
	return 0;
} 

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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 60;

int mod = 1000000007;

map<ll, ll> mp;

ll A, B, C, D;

ll solve(ll n){
    if(n == 0) return mp[0] = 0;
    if(n == 1) return mp[1] = D;
    if(mp.count(n)) return mp[n];

    ll ret = (n >= LLINF/D) ? LLINF : n*D;
    vector<ll> work(6, n), cnt(6, 0);
    while(work[0] % 2){work[0]--; cnt[0]++;}
    while(work[1] % 2){work[1]++; cnt[1]++;}
    while(work[2] % 3){work[2]--; cnt[2]++;}
    while(work[3] % 3){work[3]++; cnt[3]++;}
    while(work[4] % 5){work[4]--; cnt[4]++;}
    while(work[5] % 5){work[5]++; cnt[5]++;}
    ret = min(ret, solve(work[0]/2) + D*cnt[0] + A);
    ret = min(ret, solve(work[1]/2) + D*cnt[1] + A);
    ret = min(ret, solve(work[2]/3) + D*cnt[2] + B);
    ret = min(ret, solve(work[3]/3) + D*cnt[3] + B);
    ret = min(ret, solve(work[4]/5) + D*cnt[4] + C);
    ret = min(ret, solve(work[5]/5) + D*cnt[5] + C);
    return mp[n] = ret;
}

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    rep(i, T){
        mp.clear();
        ll N; cin >> N >> A >> B >> C >> D;
        cout << solve(N) << endl;
    }
    return 0;
}

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

if(g<=d&&e<=d||f<=d) printf("Yes");
else printf("No");

return 0;
}

Measured memory_bytes: 128
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    A = LI()

    A.sort(reverse=True)

    ans = 0
    for i in range(N - 1):
        j = (i + 1) // 2
        ans += A[j]

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 32468
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
    int N, K;
    cin >> N >> K;
    vector<bool> A(N,true);
    for (int i = 0; i < K; i++ ){
        int d_i;
        cin >> d_i;
        for (int n=0; n<d_i; n++) {
            int a;
            cin >> a;
            A[a-1]=false;
        }
    }
    cout << count(A.begin(), A.end(), true) << endl;
    return 0;
} 

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

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

int main() {
  int A, B;
  std::cin >> A >> B;
  if (A<10 && B<10) {
    cout << A*B << endl;
  } else {
    cout << -1 << endl;
  }
}


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

#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define endl '\n'

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

const ll INF = 1e18;
const int MAXN = 1e6 + 5;
const int MOD = 20200429;

ll N, K;

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> N >> K;
	cout << min(N % K, abs(N % K -K)) << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,b;

    scanf("%d %d", &a, &b);

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

    return 0;
}


Measured memory_bytes: 2040
import java.util.*;

public class Main {
	public Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new aoj1160().doIt();
	}
	class aoj1160{
		boolean map[][];
		int x[] = {-1,1,0,0,-1,1,-1,1};
		int y[] = {0,0,-1,1,-1,1,1,-1};
		int H,W;
		void dfs(int h,int w){
			map[h][w] = false;
			for(int i = 0;i < 8;i++){
				if(h + y[i] < H && w + x[i] < W && h + y[i] >= 0 && w + x[i] >= 0){
					if(map[h + y[i]][w + x[i]] == true){
						dfs(h + y[i],w + x[i]);
					}
				}
			}
		}
		void doIt() {
			while (true) {
				int cnt = 0;
				W = sc.nextInt();
				H = sc.nextInt();
				if(W+H == 0)break;
				map = new boolean[H][W];
				for (int h = 0; h < H; h++) {
					for (int w = 0; w < W; w++) {
						int n = sc.nextInt();
						if (n == 1) map[h][w] = true;
						else map[h][w] = false;
					}
				}
				for (int h = 0; h < H; h++) {
					for (int w = 0; w < W; w++) {
						if (map[h][w]) {
							cnt++;
							dfs(h, w);
						}
					}
				}
				System.out.println(cnt);
			}
		}
	}
}

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

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

	string S;
	cin >> S;

	char kisuu[3] = { 'R', 'U', 'D' };
	char guusuu[3] = { 'L', 'U', 'D' };

	string ans = "Yes";
	int count = 0;
	for (int i = 0; i < S.size()+1; i++)
	{
		count++;
		if (count % 2 == 0)
		{
			if (S[i] == 'R')
			{
				cout << "No";
				return 0;
			}
		}
		else
		{
			if (S[i] == 'L')
			{
				cout << "No";
				return 0;
			}
		}
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int [] hi = new int[N];

        for (int i = 0; i < N; i++) {

            hi[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        int[] dp = new int[100000+1];

        //dp[i+2] = Math.min(Math.abs(hi[i+1] - hi[i]) + Math.abs(hi[i+2] - hi[i+1]), Math.abs(hi[i+2] - hi[i])) )
        dp[0] = 0;
        dp[1] = Math.abs(hi[1] - hi[0]);

        if(N == 2) {

        	System.out.println(dp[1]);
        	System.exit(0);
        }
        dp[2] = Math.min(Math.abs(hi[2] - hi[1]) + Math.abs(hi[1] - hi[0]), Math.abs(hi[2] - hi[0]));

        if(N == 3) {

        	System.out.println(dp[2]);
        	System.exit(0);
        }
        dp[3] = Math.min(Math.abs(hi[3] - hi[1]) + Math.abs(hi[1] - hi[0]), Math.abs(hi[2] - hi[0]) + Math.abs(hi[3] - hi[2]) );

        if(N == 4) {

        	System.out.println(dp[3]);
        	System.exit(0);
        }
//        dp[4] = Math.min(dp[2] + Math.abs(hi[4] - hi[2]), dp[3] + Math.abs(hi[4] - hi[3]));

        for (int i = 4; i < N; i++) {

            dp[i] = Math.min(dp[i-2] + Math.abs(hi[i] - hi[i-2]), dp[i-1] + Math.abs(hi[i] - hi[i-1]));
        }

        System.out.println(dp[N-1]);
    }

}

Measured memory_bytes: 47240
#include<cstdio>
#include<map>

using namespace std;
int main(){

  int n,m;
  scanf("%d %d",&n,&m);
  map<int,bool> M;
  int data[n];
  for(int i = 0; i < n; i++) scanf("%d",&data[i]);
  for(int i = n-1; i>=0&&m; i--){
    if(M[data[i]]) continue;
    printf("%d\n",data[i]);
    M[data[i]] = true;
    m--;
  }
  return 0;
}

Measured memory_bytes: 3920
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <stack>
#include <algorithm>
#include <climits>
#include <cmath>
#include <functional>
#include <utility>
#include <numeric>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define FOR(i, m, n) for (int i = (int)m; i < (int)n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.endl(); itr++)
#define REPe(e, mp) for (auto& e : mp)
#define all(x) x.begin(), x.end()
#define MOD 1000000007  // 1e9+7
using namespace std;
using ll = long long int;
using vecint = vector<int>;
using vecll = vector<ll>;
using vec2int = vector<vector<int>>;
using P = pair<int, int>;
////////////////////////////////////////////////
////////////////////////////////////////////////
int main() {
  ////////////////////////////////////////////////
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ////////////////////////////////////////////////
  int k;
  string s;
  cin >> k >> s;
  if (s.size() > k) {
    cout << s.substr(0, k) << "..." << endl;
  } else {
    cout << s << endl;
  }
}


Measured memory_bytes: 3660
import sys
input = sys.stdin.readline
N = int(input())
abc = [[int(j) for j in input().split()] for _ in range(N-1)]
Q,K = map(int, input().split())
xy = [ [int(j) for j in input().split()] for _ in range(Q)]

inf = float("inf")
con = [ [] for _ in range(N+1)]
# cost = [ [inf] * (N+1) for _ in range(N+1)]
# cost = {}
from collections import defaultdict
# cost =  defaultdict(  )

for i in range(N-1):
    a,b,c = abc[i]
    con[a].append((b, c))
    con[b].append((a, c))

q = [(K,0)]
visited = [False] * (N+1)
visited[K] = True
costmap = [inf] * (N+1)
costmap[K] = 0
while q:
    n,cst = q.pop()
    for ch,chcst in con[n]:
        if visited[ch]:
            continue
        q.append( (ch, cst+chcst))
        visited[ch] = True
        costmap[ch]  = cst+ chcst
    
# def dfs(a,b, par):
#     if cost[a][b] != inf :
#         return cost[a][b]
# 
#     if len(list(filter(lambda x: x!=par, con[a]))) == 0:
#         return inf
# 
#     cst = inf
#     idx= -1
#     for e,ch in enumerate(con[a]):
#         if ch == par:
#             continue
#         if cst > cost[a][ch] + dfs(ch,b,a):
#             cst = cost[a][ch] + dfs(ch,b,a)
#             
#             idx = e
#     if idx != -1:
#         cost[a][b] = cst
#         cost[b][a] = cst
#     return cst
# 
for i in range(Q):
    x,y = xy[i]
    print( costmap[x] + costmap[y])
# for i in range(Q):
#     x,y = xy[i]
#     # _ = dfs(K,x,None)
#     # _ = dfs(y,K, None)
#     print(dfs(x,K,None) + dfs(K,y,None))
    


Measured memory_bytes: 105308
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

template<class T = int>
class Dinic {
  struct edge {
    int to;
    T cap;
    int rev;
  };
  vector<vector<edge>> graph;
  vector<int> level;
  vector<int> iter;

  void bfs(int s) {
    level.assign(level.size(), -1);
    queue<int> que;
    level[s] = 0;
    que.push(s);
    while(!que.empty()) {
      int v = que.front();
      que.pop();
      for(const edge &e: graph[v]) {
        if(e.cap > 0 && level[e.to] < 0) {
          level[e.to] = level[v] + 1;
          que.push(e.to);
        }
      }
    }
  }

  T dfs(int v, int t, T f) {
    if(v == t) return f;
    for(int &i = iter[v]; i < (int)graph[v].size(); i++) {
      edge &e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]) {
        T new_f = f < 0 ? e.cap : min(f, e.cap);
        int d = dfs(e.to, t, new_f);
        if(d > 0) {
          e.cap -= d;
          graph[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }

public:
  Dinic(int n) : graph(n), level(n), iter(n) {}

  void add_edge(int from, int to, T cap) {
    graph[from].push_back({to, cap, (int)graph[to].size()});
    graph[to].push_back({from, 0, (int)graph[from].size() - 1});
  }

  T max_flow(int s, int t) {
    T flow = 0;
    while(true) {
      bfs(s);
      if(level[t] < 0) return flow;
      iter.assign(iter.size(), 0);
      T f;
      while((f = dfs(s, t, -1)) > 0) {
        flow += f;
      }
    }
  }
};

const ll INF = 1L << 60;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  Dinic<ll> din(N + 2);
  ll pos = 0;
  REP(i,0,N) {
    ll a, b;
    cin >> a;
    if(a >= 0) {
      pos += a;
      b = 0;
    } else {
      b = -a;
      a = 0;
    }
    din.add_edge(0, i+1, b);
    din.add_edge(i+1, N+1, a);
  }
  REP(i,1,N+1) {
    for(int j=i*2; j<=N; j+=i) {
      din.add_edge(i, j, INF);
    }
  }
  ll ans = pos - din.max_flow(0, N+1);
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256