akhauriyash/Code-Regression huggingface dataset:
#2<=N<=100
#1<=W_i<=100

N = int(input())

weight_list = list(map(int,input().split()))

minWeight = 1000
for i in range(N):
    S_1=0
    S_2=0
    for j in range(i):
       S_1 += weight_list[j]
    for j in range(i,N):
       S_2 += weight_list[j]

    if(minWeight>(abs(S_1 - S_2))):
        minWeight = abs(S_1-S_2)

print(minWeight)

Measured memory_bytes: 38896
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<cstdio>
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
string s;
int n,a[300010],cnt;
int main(){
	cin>>n>>s;
	cnt=0;
	for(int i=0;i<s.size();i++){
		a[i]+=cnt;
		if(s[i]=='E'){
			cnt++;
		}
	}
	cnt=0;
	for(int i=s.size()-1;i>=0;i--){
		a[i]+=cnt;
		if(s[i]=='W'){
			cnt++;
		}
	}
	int ans=0;
	for(int i=0;i<n;i++){
		if(a[i]>a[ans]){
			ans=i;
		}
	}
	cout<<n-a[ans]-1<<endl;
	return 0;
}

Measured memory_bytes: 1796
mod = 10 ** 9 + 7
b, w = map(int, input().split())
def comb(n, r):
    if n < r:return 0
    if n < 0 or r < 0:return 0
    return fa[n] * fi[r] % mod * fi[n - r] % mod
n = b + w + 10
inv = [1] * (n + 1)
fa = [1] * (n + 1)
fi = [1] * (n + 1)
for i in range(1, n):
    inv[i] = ((inv[i - 1] % 2) * mod + inv[i - 1]) // 2
    fa[i] = fa[i - 1] * i % mod
    fi[i] = pow(fa[i], mod - 2, mod)
p, q = 0, 0
for i in range(b + w):
    if i >= b:
        p *= 2
        p += comb(i - 1, b - 1)
        p %= mod
    if i >= w:
        q *= 2
        q += comb(i - 1, w - 1)
        q %= mod
    print(((q - p) * inv[i + 1] + inv[1]) % mod)

Measured memory_bytes: 32276
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>

#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
using namespace std;

int main()
{
    int n; cin >> n;
    cout << n / 3 << endl;
}

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

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

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
  int n, k;
  cin >> n >> k;
  vector<ll>h(n);
  rep(i, 0, n)cin >> h[i];
  sort(h.begin(),h.end());
  ll ans= inf;
  for(int i=0; i+k-1<n; i++){
      ll tempans = h[i+k-1]-h[i];
      ans = min(tempans,ans);
  }
  cout << ans << endl;
}

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

struct AWT{
    int ac;
    int wa;
    int t_id;
    bool operator<(const AWT &another)const{
        if(ac!=another.ac){
            return ac > another.ac;
        }else if(wa!=another.wa){
            return wa < another.wa;
        }else{
            return t_id < another.t_id;
        }
    }
};

int main(){

    while(1){
        int T,P,R;
        cin >> T >> P >> R;
        if(T==0&&P==0&&R==0)break;
        vector<AWT> awt(T);
        vector<vector<int>> pen(T,vector<int>(P,0));
        for(int i=0;i<T;i++){
            awt[i].ac=0;
            awt[i].wa=0;
            awt[i].t_id=i+1;
        }
        for(int i=0;i<R;i++){
            int tid,pid,t;
            string msg;
            cin >> tid >> pid >> t >> msg;
            tid--;pid--;
            if(msg=="WRONG"){
                pen[tid][pid]++;
            }else{
                awt[tid].ac++;
                awt[tid].wa+=t+1200*pen[tid][pid];
            }
        }
        sort(awt.begin(),awt.end());
        for(int i=0;i<T-1;i++){
            cout << awt[i].t_id << " " << awt[i].ac << " " << awt[i].wa << endl;
        }
        cout << awt.back().t_id << " " << awt.back().ac << " " << awt.back().wa << endl;
    }

    return 0;
}


Measured memory_bytes: 3212
///Coder ---->>>> Kael (Joan Marcos Rivera)
///Team ACM : CyberSpace ____ IPVCE FEDERICO ENGELS
///KingOfString
///Copyright

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;

typedef long long ll;
typedef pair < int , int > par;

#define pb push_back
#define mp make_pair
#define s second
#define f first
#define maxn 100010
#define mod 1000000007
#define less(n) order_of_key(n)
#define en_pos(n) find_by_order(n) /// --- >> iterador --- >> empieza en 0

int dp[maxn];
main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,d;

    cin >> n >> d;

    int tot = maxn-10;

    for(int i=1;i<=tot;i++)
        dp[i] = mod;

    dp[0] = 0;

    int sol = 0;

    for(int i=1;i<=n;i++){
        int w,c;
        cin >> w >> c;
        for(int j=tot;j>=c;j--){
            dp[j] = min(dp[j] , dp[j-c] + w);
            if(dp[j] <= d)sol = max(sol , j);
        }
    }

    cout << sol << '\n';

}
/*
5 5
5 1
5 4
4 3
5 2
3 2
10
3 4
2 2
5 4
5 3
3 5
5 1
5 3
3 4
2 3
3 4*/


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

int main() {
int n;
cin >> n;
int a[100010][3];
for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
    cin >> a[i][j];}
}
long long dp[150000][3];
dp[0][0]=0;
dp[0][1]=0;
dp[0][2]=0;

for(long i=0;i<n;i++){
    for(int j=0;j<3;j++){
        for(int k=0;k<3;k++){
            if(j==k)continue;
            dp[i+1][k]=max(dp[i+1][k],dp[i][j]+a[i][k]);
        }
    }
}
long long ans=0;
for(int i=0;i<3;i++){
    ans=max(ans,dp[n][i]);}
cout << ans;
}



Measured memory_bytes: 4736
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
 
using namespace std;
int MOD = 1000000007;
signed main(){
 
    int u[4] = {0};
    rep(i,3){
        int a,b;
        cin >> a >> b;
        u[a-1]++;
        u[b-1]++;
    }
    sort(u,u+4);
    if(u[0] == 1 && u[1] == 1 && u[2] == 2 && u[3] == 2)cout << "YES" << endl;
    else cout << "NO" << endl; 
    
    
    
    return 0;   
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://ddcc2019-final.contest.atcoder.jp/tasks/ddcc2019_final_a
// rm -r -f test;oj dl http://arc060.contest.atcoder.jp/tasks/arc060_a

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int list[1000000];
  list[n]++;
  rep(i,1000000){
    if(n%2==0){
      n = n/2;
    }else{
      n = 3*n + 1;
    }
    list[n]++;
    if(list[n]==2){
      cout << i+2 << endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 2304
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) begin(a),end(a)
typedef long long ll;
typedef pair<int,int> P;
const int inf=1000000007;
const ll mod=1000000007;
const double PI=3.14159265358979323846;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
ll gcd(ll a, ll b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
int cans(bool f){
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

vector<pair<ll,ll>> p;

int main() {
  int N,M;
  cin >> N >> M;
  p.resize(N);
  rep(i,N){
    ll a,b;
    cin >> a >> b;
    p[i] = make_pair(a,b);
  }
  sort(all(p));
  ll ans = 0;
  ll cnt = 0;
  rep(i,N){
    if(p[i].second + cnt > M){
      while(1){
	ans += p[i].first;
	cnt++;
	if(cnt == M) break;
      
      }
      break;
    }
    else{
      cnt += p[i].second;
      ans += p[i].first * p[i].second;
   
    }
  }
  
  cout << ans << endl;
  return 0;
}










Measured memory_bytes: 1792
#include<stdio.h>
#define NIL -1

int dp[45];

int Fib(int n){
  if(n==0||n==1) return 1;
  else if(dp[n]!=NIL) return dp[n];
  else return dp[n]=Fib(n-1)+Fib(n-2);
}

int main(){
  int i,ans,n;
  scanf("%d",&n);
  for(i=0;i<45;i++) dp[i]=NIL;
  ans=Fib(n);
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
typedef long long int ll;
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) for (unsigned int i=0;i<(n);i++)
#define EREP(i,n) for (int i=1;i<=(n);i++)
#define ALL(a) (a).begin(),(a).end()
//#define EVEL 1

#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const int MOD =  1000000007 ;
const int INF = 2000000000;


    int A,B,C,D;
    string S,T;
int main(){
    cin>>A;
    if(A<1000)printf("ABC");
    else printf("ABD");
    return 0;

}


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

#define int long long 

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}
 
void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 
#define pb push_back

const int maxn = 1e5+10;
const int inf = 1e9;
const lf eps = 1e-8;

int n;

vector<int > s,t;

signed main() {
    read(n);int p=101;n++;
    while(n>1) {if(n&1) t.pb(--p),n--;else s.pb(--p),n>>=1;}
    int m=s.size()+t.size();printf("%lld\n",m<<1);
    for(int i=0;i<(int)t.size();i++) printf("%lld ",t[i]);
    for(int i=s.size()-1;~i;i--) printf("%lld ",s[i]);
    for(int i=100-m+1;i<=100;i++) printf("%lld ",i);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    string s;
    cin>>s;
    int c=0;
    for(int i=0;i<s.size()-1;i++){
        if(s[i]!=s[i+1])c++;
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int h, w;
  cin >> h >> w;
  VEC<string> s(h);
  REP(i, 0, h) cin >> s[i];
  queue<int> nh;
  queue<int> nw;
  LL answer = 0;
  auto visit = MATINIT(bool, h, w, 0);
  REP(i, 0, h) {
    REP(j, 0, w) {
      int blcnt=0;
      if (s[i][j] == '.') continue;
      nh.push(i);
      nw.push(j);
      LL ans = 0;
      while (!nh.empty() && !nw.empty()) {
        int ch = nh.front();
        int cw = nw.front();
        nh.pop();
        nw.pop();
        char cc = s[ch][cw];
        if (visit[ch][cw]) continue;
        visit[ch][cw] = 1;
        if (cc == '.') {
          ++ans;
          // DUMP(i,j,"to",ch,cw);
        }else{
          ++blcnt;
        }
        if (ch + 1 < h && cc != s[ch + 1][cw]) {
          nh.push(ch + 1);
          nw.push(cw);
        }
        if (ch - 1 >= 0 && cc != s[ch - 1][cw]) {
          nh.push(ch - 1);
          nw.push(cw);
        }
        if (cw + 1 < w && cc != s[ch][cw + 1]) {
          nh.push(ch);
          nw.push(cw + 1);
        }
        if (cw - 1 >= 0 && cc != s[ch][cw - 1]) {
          nh.push(ch);
          nw.push(cw - 1);
        }
      }
      answer += blcnt*ans;
    }
  }
  cout << answer;

  return 0;
}


Measured memory_bytes: 512
import math
d, g = map(int, input().split())
p = [0 for _ in range(d+1)]
c = [0 for _ in range(d+1)]
ans = 10 ** 10
for i in range(d):
    pi, ci = map(int, input().split())
    p[i+1] = pi
    c[i+1] = ci     
for bit in range ( 1 << d):
    score = 0
    cnt = 0
    tokanai_saidai = 0
    for i in range(d):
        if bit & (1 << i):
            score += p[i+1] * 100 * (i+1) + c[i+1]
            cnt += p[i+1]
        else:
            tokanai_saidai = i + 1
    if score >= g:
        if cnt < ans:
            ans = cnt
    else:
        nokori_score = g - score
        if nokori_score < 100 * (tokanai_saidai) * p[tokanai_saidai]:
            cnt += math.ceil(nokori_score / (100 * tokanai_saidai))
            if cnt < ans:
                ans = cnt 
print(ans)

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

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

int color(int n) {
  if (n < 400) return 1;
  else if (n < 800) return 2;
  else if (n < 1200) return 3;
  else if (n < 1600) return 4;
  else if (n < 2000) return 5;
  else if (n < 2400) return 6;
  else if (n < 2800) return 7;
  else if (n < 3200) return 8;
  else return 0;
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  set<int> s;
  int c = 0;
  for (int i = 1; i <= n; i++) {
    int t;
    cin >> t;
    t = color(t);
    if (t) s.insert(t);
    else c++;
  }
  cout << max((int) s.size(), 1LL) << ' ' << s.size() + c << '\n';
}


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

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static string Solve(string S)
        {
            if (S.Length == 26)
            {
                for (int i = 25; i >= 0; --i)
                {
                    string s = S.Substring(0, i);
                    for (char c = (char)(S[i] + 1); c <= 'z'; ++c)
                    {
                        if (!s.Contains(c)) { return s + c.ToString(); }
                    }
                }
                return "-1";
            }
            else
            {
                return S + Enumerable.Range(0, 26).Select(i => (char)('a' + i)).First(c => !S.Contains(c)).ToString();
            }
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve(Read()));
        }
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};




int main(){
    string s;cin >> s;
    int ans = 0;
    string t="";
    for (int i = 0; i < s.length(); i++) {
        string tt="";
        tt = s[i];
        if(t!=tt){
            t=s[i];
            ans++;
        }
        else{
            t="";
            if(i!=s.length()-1)ans++;
            i++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int R, G;
    cin >> R >> G;
    cout << 2*G - R << endl;
}

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

int main(){
  int n, l;
  cin >> n >> l;
  
  vector<int> flavor(n);
  
  for (int i = 0; i < n; i++) {
    flavor.at(i) = l + i ;
  }
  
  int minAbsPos = 0;
  
  for (int i = 0; i < n; i++) {
    if (abs(flavor.at(i)) < abs(flavor.at(minAbsPos))) {
      minAbsPos = i;
    }
  }
  int sum = 0;
  
  for (int i = 0; i < n; i++) {
    if (i == minAbsPos) continue;
    sum += flavor.at(i);
  }
    
 cout << sum << endl;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  long long x;
  cin>>n>>x;
  long long a[n],sum=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  long long qb=a[n-1]+a[n-2]-x;
  if(qb>0){
      sum+=qb;
      if(qb<=a[n-2]){
	a[n-2]-=qb;
      }else{
	qb-=a[n-2];
	a[n-2]=0;
	a[n-1]-=qb;
      }
  }

  for(int i=1;i<n-1;i++){
    long long nor=(a[i]+a[i-1])-x;
    if(nor>0){
      sum+=nor;
      if(nor<=a[i]){
	a[i]-=nor;
      }else{
	nor-=a[i];
	a[i]=0;
	a[i-1]-=nor;
      }
    }
  }
  cout<<sum<<endl;
  return(0);
}


Measured memory_bytes: 1024
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p == NIL) printf("root, ");
  else if(T[u].l == NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l != NIL) calcDepth(T[u].l ,p + 1);
  if(T[u].r != NIL) calcDepth(T[u].r ,p);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



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

using namespace std;
typedef long long ll;


ll ans=1e18,mx,mn=1e8,sum,cnt;
int main(){
	ll n;
	cin>>n;
	ll time[n],total[n];
	for(ll i=0; i<n; i++){
		ll x,y;
		cin>>time[i]>>x>>y;
		total[i]=x+y;
	}
	if(time[0]<total[0]){
		cout<<"No";
		return 0;
	}
	if(time[0]>total[0]){
		ll time1 = time[0];
		time1 -= total[0];
		if(time1%2!=0){
			cout<<"No";
			return 0;
		}
	}
	for(ll i=0; i<n; i++){
		if(i>0){
			ll time1 = time[i]-time[i-1];
			ll total1 = abs(total[i]-total[i-1]);
			if(time1<total1){
				cout<<"No";
				return 0;
			}
			time1 -= total1;
			if(time1%2!=0){
				cout<<"No";
				return 0;
			}
		}
	}
	cout<<"Yes";
}

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

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
#define INF 1e9

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef vector < pair<int, int> > vii;
typedef long double ld;
typedef tree<pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

string s1, s2, reply;
int dir, cur, n;
string t1="..##";
string t2=".##.";

int main()
{
	cin >> n;
	dir=1;
	while(reply!="end"){
		if(dir==1){
			cout << s1+t1[cur] << endl;
			cout << s2+t2[cur] << endl;
			cin >> reply;
			if(reply=="F"){
				if(cur==3){
					dir=-1;
					cur=0;
				}
				else{
					cur++;
				}
			}
			else{
				s1+=t1[cur];
				s2+=t2[cur];
				cur=0;
			}
		}
		else{
			cout << t1[cur]+s1 << endl;
			cout << t2[cur]+s2 << endl;
			cin >> reply;
			if(reply=="F"){
				cur++;
			}
			else{
				s1=t1[cur]+s1;
				s2=t2[cur]+s2;
				cur=0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 724
#include<iostream>
#include<algorithm>
#include <string>
#include<vector>

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	if (s.back() == 's') {
		cout << s << "es";
	}
	else {
		cout << s << "s";
	}
	return 0;
}

Measured memory_bytes: 3620
#include<stdio.h>
int main ()
{
    int a[3];
    int b[3];
    int c[3];
    int in, x;
    scanf ("%d %d %d", &a[0], &a[1], &a[2]);
    scanf ("%d %d %d", &b[0], &b[1], &b[2]);
    scanf ("%d %d %d", &c[0], &c[1], &c[2]);
    scanf("%d", &in);
    for(int i=0; i<in; i++)
    {
      scanf("%d", &x);
      for (int j=0; j<3; j++)
      {
          if (x==a[j]){a[j]=0;}
          else if (x==b[j]){b[j]=0;}
          else if (x==c[j]){c[j]=0;}
      }
    }
    for (int k=0; k<3; k++)
    {
     if (a[k]+b[k]+c[k]==0){printf("Yes"); return 0;}
    }
    if (a[0]+a[1]+a[2]==0 || b[0]+b[1]+b[2]==0 || c[0]+c[1]+c[2]==0)
    {
     printf("Yes"); return 0;
    }
    else if (a[0]+b[1]+c[2]==0 || c[0]+b[1]+a[2]==0 )
    {
     printf("Yes"); return 0;
    }
    else {printf("No"); return 0;}

}


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

int main() 
{

    int N;
    cin >> N;
    vector<int> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D.at(i);
    }
    
    int sum = 0;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            sum += D.at(i) * D.at(j);
        } 
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

const int INF = 1001001001;
int n;
int f[105][10];
int p[105][15];

int calc(int bit) {
    vi cnt(n, 0);
    rep(d, 10) {
        if (bit>>d&1) {
            rep(i, n) {
                if (f[i][d] == 1) cnt[i]++;
            }
        }
    }
    int res = 0;
    rep(i, n) {
        res += p[i][cnt[i]];
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    rep(i, n) {
        rep(j, 10) {
            cin >> f[i][j];
        }
    }

    rep(i, n) for (int j = 0; j <= 10; ++j) cin >> p[i][j];

    int mx = -INF;
    rep(bit, 1<<10) {
        if (bit == 0) continue;
        chmax(mx, calc(bit));
    }
    cout << mx << endl;
}

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

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;

        private class Data
        {
            public long prime;
            public long cnt;
            public Data(long prime, long cnt)
            {
                this.prime = prime;
                this.cnt = cnt;
            }
        }
        static void Solve()
        {
            var n = ReadAndParseLong();
            var list = new List<long>();

            int ans = CalcDigit(n);
            for(long i=1;i*i<=n;++i)
            {
                if (n % i != 0) { continue; }
                long b = n / i;
                int digit = Math.Max(CalcDigit(i), CalcDigit(b));
                ans = Math.Min(ans, digit);
            }
            Console.WriteLine(ans);
        }
        private static int CalcDigit(long n)
        {
            int digit = 0;
            while (n > 0)
            {
                n /= 10;
                digit++;
            }
            return digit;
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int b, r, g, c, s, t;

int main(){
	while (cin >> b >> r >> g >> c >> s >> t&&b + r + g + c + s + t){
		cout << 100 - (t - s) * 3 + (b + r) * 15 
			+ g * 7 + c * 2 + (b * 5 + r * 3) * 16 << endl;
	}
}

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

using namespace std;

typedef long long ll;

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

int n, k, r, s, p;

int main(){

    int x, flag, i;

    cin >> x;

    while(1){

        flag = 1;

        for(i = 2; i*i < x; i++){
            
            if(x % i ==  0) {
                flag = 0;
                break;
            }

        }

        if(flag) break;

        x++;

    }

   cout << x;

    return 0;

}

Measured memory_bytes: 256
MOD = 1000000007

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

color = [-1,-1,-1]
ans = 1
for i in range(N):
    if A[i]-1 in color:
        num1 = 0
        num2 = 0
        for j in range(3):
            if color[j]==A[i]-1:
                num1 += 1
            if color[j]==A[i]:
                num2 += 1
        if num1==3 and num2==0:
            ans *= 3
            ans %= MOD
        elif num1==2 and num2==1:
            ans *= 2
            ans %= MOD
        elif num1==1 and num2==2:
            ans *= 1
            ans %= MOD
        elif num1==2 and num2==0:
            ans *= 2
            ans %= MOD
        elif num1==1 and num2==1:
            ans *= 1
            ans %= MOD
        elif num1==1 and num1==1:
            ans *= 1
            ans %= MOD
        for j in range(3):
            if color[j]==A[i]-1:
                color[j]+=1
                break
    else:
        print(0)
        break
else:
    print(ans)

Measured memory_bytes: 54824
#include <stdio.h>
int main(void) {
	int a, b, sum, count;
	while(scanf("%d %d", &a, &b) != EOF){
		sum = a + b;
		count = 0;
		while(sum > 0){
			sum = sum / 10;
			count++;
		}
		printf("%d\n", count);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;

#define REP(k, n) for (ll k = 0; k < (ll)(n); ++k)
#define REPREV(k, n) for (ll k = (ll)(n)-1; k >= 0; --k)
#define FOR(k, a, b) for (ll k = (ll)(a); k < (ll)(b); ++k)
#define FORREV(k, a, b) for (ll k = (ll)(b)-1; k >= (ll)(a); --k)
#define FOREACH(e, v) for (auto& e : v)

#define TGET(t, i) get<i>(t)
#define TSET(t, i, a) get<i>(t) = a
// MinHeap - priority_queue<ll, vll, greater<ll>> pq;

#define EVEN(n) ((n)&1) == 0
#define ODD(n) ((n)&1) == 1

#define SORT(v) sort(v.begin(), v.end())
#define SORTREV(v) sort(v.rbegin(), v.rend())
#define SHUFFLE(v) random_shuffle(v.begin(), v.end())
//srand(unsigned(time(0)));

#define REMOVEAT(v, i) v.erase(v.begin() + i)
#define REVERSE(v) reverse(v.begin(), v.end())
#define UNIQUE(v) \
    SORT(v);      \
    v.resize(distance(v.begin(), unique(v.begin(), v.end())))

ostream& operator<<(ostream& str, const pll& p) {
    str << p.first << " " << p.second;
    return str;
}

template <typename T>
void join(T& arr, string sep) {
    bool first = true;
    for (auto t : arr) {
        if (first) {
            first = false;
            cout << t;
        } else {
            cout << sep << t;
        }
    }
    cout << "\n";
}

const ll md = 1e9 + 7;
ll MOD(ll x) {
    ll r = x % md;
    if (r < 0) {
        r += md;
    }
    return r;
}

#define POS "POSSIBLE"
#define IMPOS "IMPOSSIBLE"

// #define INF DBL_MAX
// #define INF LLONG_MAX
// #define MINF LLONG_MIN
#define INF 1e18
#define MINF -INF

void solve() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll res = -INF;
    res = max(res, a * c);
    res = max(res, a * d);
    res = max(res, b * c);
    res = max(res, b * d);
    if ((a <= 0 && 0 <= b) || (c <= 0 && 0 <= d))
        res = max(res, 0ll);
    

    // cout << fixed << setprecision(6);
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tt = 1;
    // cin >> tt;
    for (int t = 1; t <= tt; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    //cin.rdbuf()->in_avail()
    return 0;
}

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

int N,M;
int a,b;
vector <int> H;
vector <int> A;
//vector <int> B;

void input(){
  cin >> N >> M ;
  H.resize(N);
  for(int i=0;i<N;i++){
    cin >> H[i] ;
  }
  A.resize(N);
  //  B.resize(N);
  for(int i=0;i<N;i++){
    A[i]=0;
    //    B[i]=0;
  }

  for(int i=0;i<M;i++){
    cin >> a >> b ;
    A[a-1]=max(A[a-1],H[b-1]);
    A[b-1]=max(A[b-1],H[a-1]);
  }
}

void solve(){
  int d=0;
  for(int i=0;i<N;i++){
    //    if((H[i]>A[i])&&H[i]>B[i]){
    if(H[i]>A[i]){
      d+=1;
    }
  } 
  cout << d << endl;
}

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


Measured memory_bytes: 3964
#include<cstdio>
int main()
{
	int a,b,c,d;scanf("%d%d%d%d",&a,&b,&c,&d);
	if(a+b==c+d) printf("Balanced\n");
	else if(a+b>c+d) printf("Left\n");
	else printf("Right\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef vector<int> vint;
typedef vector<float> vfloat;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vstr> vvstr;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

string s;
int l;
ll ans = 0;

ll calc(string s_t) {
    ll res = 0;
    string tmp = "";
    rep(i, s_t.length()) {
        if (s_t[i] == '+') {
            res += stoll(tmp);
            tmp = "";
        } else {
            tmp += s_t[i];
        }
    }
    res += stoll(tmp);
    return res;
}

void dfs(string s_t, int i) {
    if (i == l) {
        
        ans += calc(s_t);
        return;
    } 
    dfs(s_t + s[i], i+1);
    if (i > 0) dfs(s_t + '+' + s[i], i+1);
}

int main(void){
    cin >> s;
    l = s.length();
    
    dfs("", 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{

    string s;
    while(cin>>s)
    {

     int sum=1;
        for(int i=0;i<3;i++)
        {
            if(s[i]!=s[i+1]&&sum<3)
                sum=1;
            else
                sum++;

        }

        if(sum>=3)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vec vector<int>
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	vector<ll> v;
	v.push_back(a*c);
	v.push_back(b*c);
	v.push_back(a*d);
	v.push_back(b*d);
	sort(v.begin(),v.end(),greater<ll>());
	cout<<v[0];
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
typedef pair<int,int> Pi; typedef priority_queue<int> Pr; typedef vector<int> Vi; typedef vector<Pi> Vp;
typedef map<int,int> MPi; typedef pair<Int,Int> Pl; typedef vector<Int> VI;
const int mod = 1000000007; const Int INF = 1145141919810893931;
#define END {cout<<ans<<'\n'; return 0;}
#define ALL(v) v.begin(),v.end()
template<class T> inline bool cmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool cmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    int a,b,q; cin>>a>>b>>q; VI s(a),t(b);
    for (int i = 0; i < a; i++)cin>>s[i];
    for (int i = 0; i < b; i++)cin>>t[i];
    s.push_back(-1e10); t.push_back(-1e10); s.push_back(2e10); t.push_back(2e10);
    sort(ALL(s)); sort(ALL(t));
    for (int i = 0; i < q; i++){
        Int x,ans=2e10; cin>>x;
        auto is=lower_bound(ALL(s),x); auto it=lower_bound(ALL(t),x);
        Int sa=*(is-1),sb=*is,ta=*(it-1),tb=*it;
        cmin(ans,abs(x-sa)+abs(sa-ta));
        cmin(ans,abs(x-sa)+abs(sa-tb));
        cmin(ans,abs(x-sb)+abs(sb-ta));
        cmin(ans,abs(x-sb)+abs(sb-tb));
        cmin(ans,abs(x-ta)+abs(ta-sa));
        cmin(ans,abs(x-ta)+abs(ta-sb));
        cmin(ans,abs(x-tb)+abs(tb-sa));
        cmin(ans,abs(x-tb)+abs(tb-sb));
        cout<<ans<<'\n';
    }
}

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

int main(int argc, char* argv[]) {
  int a, b;
  char op;
  cin >> a >> op >> b;
  while(op != '?'){
    if(op=='+'){
      cout << a + b << endl;
    }else if(op=='-'){
      cout << a - b << endl;
    }else if(op=='*'){
      cout << a * b << endl;
    }else if(op=='/'){
      cout << a / b << endl;
    }
    cin >> a >> op >> b;
  }

  return 0;
}

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

int main() {
  string s;
  cin >> s;
  if ((s[2] == s[3]) && (s[4] == s[5])) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    // 各文字の出現位置を取得
    // 最後の出現が、文字列の最後からどれくらいか
    // 各出現の間隔はどれくらいか、の最大値を使用する
    // -1と最後 + 1にその文字があると仮定して計算すると楽か
    let s: String = read();
    use std::collections::HashMap;
    let mut map: HashMap<char, Vec<usize>> = HashMap::new();
    for (i, c) in s.chars().enumerate() {
        let entry = map.entry(c).or_insert_with(|| vec![s.len()]);
        entry.push(i);
    }
    let mut ans = std::usize::MAX;
    use std::cmp::{max, min};
    for v in map.values_mut() {
        v.sort();
        let mut ans_now = v[0];
        for vec in v.windows(2) {
            let a = vec[0];
            let b = vec[1];
            ans_now = max(ans_now, b - a - 1);
        }
        ans = min(ans, ans_now);
    }
    println!("{}", ans);
}


Measured memory_bytes: 4476
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1 << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
struct query {
	int v, d, c;
};
void dfs(vector< vector< int > > &G, vector< int > &dp, vector< int > &ans, int x, int d, int c) {
	if (d <= dp[x])
		return;
	dp[x] = d;
	if (ans[x] == 0)
		ans[x] = c;
	rep(i, G[x].size()) {
		int j = G[x][i];
		dfs(G, dp, ans, j, d - 1, c);
	}
}
signed main() {
	cin >> N >> M;
	vector< vector< int > > G(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	cin >> Q;
	vector< query > querys(Q);
	rep(i, Q) {
		cin >> querys[i].v >> querys[i].d >> querys[i].c;
		querys[i].v--;
	}
	reverse(querys.begin(), querys.end());
	vector< int > dp(N, -1);
	vector< int > ans(N, 0);
	rep(i, Q) {
		dfs(G, dp, ans, querys[i].v, querys[i].d, querys[i].c);
	}
	rep(i, N) cout << ans[i] << endl;
	return 0;
}

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

#define RAPIDA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int main(){
    RAPIDA
    int k,i;cin>>k;
    string s;cin>>s;
    if(s.length()<=k)
        cout<<s<<"\n";
    else{
        string z="";
        for(i=0;i<k;i++){
            z=z+s[i];
        }
        z+="...";
        cout<<z<<"\n";
    }
    return 0;
}

Measured memory_bytes: 3660
import numpy as np
n,m,c = map(int,input().split())
b = np.array(list(map(int, input().split())))
count = 0
for _ in range(n):
  a = np.array(list(map(int, input().split())))
  if sum(a*b) + c > 0:
    count += 1
print(count)

Measured memory_bytes: 12424
#include <iostream>
#include <algorithm>
#include <map>
#include <string>

using namespace std;
 
int main(void){
	
	int N, count, count2=0;
	
	cin >> N;
	
	int A[N];
	
	for(int i=0; i<N; i++)
		cin >> A[i];
	
	for(int i=0; i<200; i++){
		count = 0;
		for(int j=0; j<N; j++){
			if(A[j]%2 == 0){
				count++;
				A[j] /= 2;
			}else
				break;
		}
		if(count == N){
			count2++;
		}
	}
	
	cout << count2;
	
	return 0;
}

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

using namespace std;
using i64 = int64_t;

signed main(){
    
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& x : a)
        cin >> x;
    auto f = [&](int val){
        int cnt = 0;
        for(auto& x : a)
            cnt += (x >= val);
        return cnt >= val;
    };
    int ok = 0;
    int ng = 1000;
    while(ng - ok > 1){
        int mid = (ng + ok) >> 1;
        (f(mid) ? ok : ng) = mid;
    }
    cout << ok << endl;
    
    
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A + B < C + D)cout << "Right" << endl;
	else if (A + B > C + D)cout << "Left" << endl;
	else cout << "Balanced" << endl;
	return 0;
}

Measured memory_bytes: 256
def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] < s2[i]:
            return s1
        elif s1[i] > s2[i]:
            return s2
    return s1
        

def s(a, l):
    for i in range(len(a)):
        m_step = 'z' * l
        ind = -1
        for j in range(i, len(a)):
            m_step = check(m_step, a[j])
            if m_step == a[j]:
                ind = j
        a[i], a[ind] = a[ind], a[i]
    return a
        
        
            

n, l = map(int, input().split())
strs = []
for i in range(n):
    strs.append(input())
print(''.join(s(strs, l)))




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

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(v) cout<<v<<"\n"
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  string S; cin >> S;

  rep(bit, 1 << 3) {
    int sum = S[0] - '0';
    rep(i, 3)
      sum += (bit & (1 << i) ? 1 : -1) * (S[i+1] - '0');
    if (sum == 7) {
      cout << S[0];
      rep(i, 3)
        cout << (bit & (1 << i) ? '+' : '-') << S[i+1];
      cout << "=7\n";
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


def nC2(n):
    if n < 2:
        return 0
    return n*(n-1)//2


N = int(input())
*A, = map(int, input().split())

h = defaultdict(int)
for a in A:
    h[a] += 1

total = 0
for k, v in h.items():
    total += nC2(v)

for k in range(N):
    t = A[k]
    print(total - h[t] + 1)


Measured memory_bytes: 94612
#include<bits/stdc++.h>
#include<string>
#include<string.h>
using namespace std;
typedef long long ll;
int main() {
	string str,str2;
	cin>>str;
	str2 = str;
	int cnt = 0;
	reverse(str2.begin(),str2.end());
	for(int i = 0; str[i]!='\0'; ++i){
		if(str[i]!=str2[i])
			++cnt;
	}
	//cout<<str2<<endl;
	cout<<cnt/2<<endl;
	return 0;
}

Measured memory_bytes: 256
(let ((l (concatenate 'list (read-line))))

  (defun f (lst &optional (cnt 0))
    (if (>= cnt 3)
      t
      (if (null lst)
        nil
        (if (char= (car lst) (cadr lst))
          (f (cdr lst) (1+ cnt))
          (f (cdr lst) 0)))))




  (format t "~A~%"
          (if (or (and (eq (nth 0 l) (nth 1 l)) (eq (nth 1 l) (nth 2 l)))
                  (and (eq (nth 1 l) (nth 2 l)) (eq (nth 2 l) (nth 3 l))))
            "Yes"
            "No")))


Measured memory_bytes: 23568
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<unordered_map>

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[(1 << 22)];

int main(){
  int N;
  cin >> N;
  int a[25][25];
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      cin >> a[i][j];
    }
  }
  DP[0] = 1;
  for(int i = 0; i < (1 << N); i++){
    int cnt = 0;
    for(int j = 0; j < N; j++){
      if(i & (1 << j)){
        cnt += 1;
      }
    }
    for(int j = 0; j < N; j++){
      if((i & (1 << j)) && a[cnt - 1][j]){
        DP[i] += DP[i - (1 << j)];
        DP[i] %= MOD;
      }
    }
  }
  cout << DP[(1 << N) - 1] << endl;
  return 0;
}


Measured memory_bytes: 18688