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

#define ll long long
#define ld long double
#define COIN const int
#define ite iterator
#define PII pair<int,int>
#define PSI pair<string,int>
#define PIS pair<int,string>

#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define REPD(i,n) for((i)=(n)-1;(i)>=0;(i)--)

#define ALL(c) (c).begin(), (c).end()
#define sz(s) (s).size()
#define CLEAR(x) memset(x,0,sizeof x);

#define MP make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define X first
#define Y second

#define VI vector<int>
#define VS vector<string>
#define VII vector<PII>
#define VVI vector<VI>

#define PIII 3.1415926
#define PI 3.14
/*****************************************************************************/
const ll mod=1e9+7;
const ll INF=1e18;
/*****************************************************************************/

using namespace std;

int a[200004];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int n; cin >>n;
	ll sum=0,ans=0;
	for (int i=0;i<n;i++) {
		cin >>a[i];
		sum+=a[i];
		sum%=mod;
		sum+=mod;
	}
	ll s=0;
	for (int i=0;i<n;i++) {
		s+=a[i];
		s%=mod;
		ans+=(((sum-s)%mod)*a[i]);
		ans%=mod;
	}
	cout <<ans;
	return 0;
}
/******************************************************************************
******************************************************************************/


Measured memory_bytes: 4348
class UnionFind
  def initialize(n)
    @data = Array.new(n, &:itself)
  end

  def root(i)
    _compact!(i, _root(i))
  end

  def same?(i, j)
    root(i) == root(j)
  end

  def unite!(i, j)
    _compact!(i, root(j))
  end

  def _root(i)
    i = @data[i] until i == @data[i]
    i
  end

  def _compact!(i, r)
    until @data[i] == r
      tmp = @data[i]
      @data[i] = r
      i = tmp
    end
    r
  end
end

n, m = gets.split.map(&:to_i)
uf = UnionFind.new(n + 1)
m.times do
  a, b = gets.split.map(&:to_i)
  uf.unite!(a, b)
end
g = (1..n).group_by { |i| uf.root(i) }
puts g.transform_values(&:size).values.max

Measured memory_bytes: 40844
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    map<string,int>mp;
    string str[n];
    bool duplicate = false;
    REP(i,n){
        cin >> str[i];
        if(mp.find(str[i])!=mp.end()){
            duplicate = true;
        }
        mp[str[i]]++;
    }
    if(duplicate){
        cout << "No" << endl;
        return 0;
    }
    FOR(i,1,n){
        if(str[i-1][str[i-1].length()-1] != str[i][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout <<"Yes" << endl;
    return 0;
}

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

using namespace std;

int main(){

	string in;

	while(getline(cin,in)){
		if(in == "END OF INPUT") break;
		in+=" ";
		int sum = 0;
		for(int i = 0; i < in.length(); i++){
			if(in[i] == ' '){
				cout << i-sum;
				sum = i+1;
			}
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <math.h>
#include <stack>
#include <climits>
#include <bitset>

using namespace std;
typedef long long ll;

ll gcd(ll x, ll y) {
  ll tmp = 0;
  if (x < y){
    tmp=x;
    x=y;
    y=tmp;
  }
  while (y > 0) {
    ll r = x % y;
    x = y;
    y = r;
  }
  return x;
}


//for(int i = ; i < ; i++){}

int main(){
  ll l,r;
  cin>>l>>r;
  if(r-l>=2018){
    cout<<0<<endl;
  }
  else{
    l%=2019;
    r%=2019;
    if(l>=r){
      cout<<0<<endl;
    }
    else{
      int ans = 2019;
      for(int i = l; i <= r; i++){
        for(int j = i+1; j <= r; j++){
            ans = min(ans,(i*j)%2019);
        }
      }
      cout<<ans<<endl;
    }
  }

  return 0;
}




Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [0] * N
    for i in range(N):
        AB[i] = map(int, input().split())

    n_press = 0
    for A, B in reversed(AB):
        r = (A + n_press) % B
        n_press += B - r if r > 0 else 0

    ans = n_press
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 50420
#include <iostream>
using namespace std;
int main(void){
  string s;
  int a,b,c,d,e,f ;
  cin >> a;
  cin >> b;
  cin >> c;
  cin >> d;
  cin >> e;
  cin >> f;
  if (a+5*b+10*c+50*d+100*e+500*f < 1000){
      cout << "0";
  }
  else if (a+5*b+10*c+50*d+100*e+500*f >= 1000){
      cout << "1";
  }
  cout << endl ;
}



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

const int mnx = 1e6 + 9;
const int mod = 1e9 + 7;

ll n;
ll a[mnx];

int main() {

cin >> n;

for(int i = 1; i <= n; i++){
    cin >> a[i];
}

sort(a + 1, a + n + 1);

ll sum = 0, id;

for(int i = 1; i <= n; i++){
    sum += a[i];
    if(2 * sum < a[i + 1]) id = i;
}

cout << n - id << '\n';

return 0;

}


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

using namespace std;

struct solve {
    int ans[201][201];
    
    constexpr solve() : ans() {
        for (int i = 0; i < 201; i++) {
            for (int j = 0; j < 201; j++) {
                int N = i, A = j - 100;
                
                int L = A;
                int R = A + N - 1;
    
                int eat = 0;
                if (R <= 0)eat = R;
                else if (L >= 0)eat = L;
                
                int answer = (R + L) * (R - L + 1) / 2 - eat;
                
                ans[i][j] = answer;
            }
        }
    }
};

int main() {
    int N, L;
    cin >> N >> L;
    solve s;
    cout << s.ans[N][L+100] << endl;
}

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

#include <fstream>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  int a, b;
  cin >> a >> b;
  cout << (b - a) * (b - a - 1) / 2 - a<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define NUM 1000000007
#define MAX 100001
#define INF LLONG_MAX
ll dp[101][MAX];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,tmp;
    cin>>n>>k;
    vector<ll> v;
    for(int i=0;i<n;i++){
        cin>>tmp;
        v.pb(tmp);
    }
    //memset(dp,0,sizeof(dp));
    for(int i=0;i<=v[0];i++){
        dp[0][i]=1;
    }
    for(int i=1;i<n;i++){
        vector<ll> prf(k+1);
        prf[0]=dp[i-1][0];
        for(int j=1;j<=k;j++){
            prf[j]=(prf[j-1]+dp[i-1][j])%NUM;
        }
        for(int j=0;j<=k;j++){
            if(j>v[i]){
                dp[i][j]=(prf[j]+NUM-prf[j-v[i]-1])%NUM;
            }
            else
                dp[i][j]=prf[j];
        }
    }
    cout<<dp[n-1][k]<<endl;
    return 0;
}


Measured memory_bytes: 82404
x, y, a, b, c = $stdin.readline.chomp.split.map(&:to_i)
p = $stdin.readline.chomp.split.map(&:to_i).sort![-x..-1]
q = $stdin.readline.chomp.split.map(&:to_i).sort![-y..-1]
r = $stdin.readline.chomp.split.map(&:to_i)
puts (p + q + r).sort![-(x + y)..-1].sum

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

template<typename T> void setmax(T& x, T y) {x = max(x, y);}
template<typename T> void setmin(T& x, T y) {x = min(x, y);}

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 6;
int n, m;
VI g[N];
PII e[N];
bitset<N> ye[N];
char used[N];
vector<int> Path;
map<PII, int> mp;
bitset<N> Zero;

void dfs(int v, int goal, vector<int>& path)
{
	path.PB(v);
	used[v] = 1;
	if (v == goal)
		Path = path;
		
	for(auto i: g[v]) if (used[i] == 0) dfs(i, goal, path);
	path.pop_back();
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n;
	FOR(i, 0, n - 1)
	{
		int u, v;
		cin >> u >> v;
		--u; --v;
		g[u].PB(v);
		g[v].PB(u);
		mp[MP(u, v)] = mp[MP(v, u)] = i;
	}
	
	cin >> m;
	FOR(i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		--u; --v;
		vector<int> P;
		FILL(used, 0);
		dfs(u, v, P);
		FOR(j, 0, SZ(Path) - 1)
		{
			u = Path[j], v = Path[j + 1];
			ye[i][mp[MP(u, v)]] = true;
		}
	}

	
	LL ans = 0;
	FOR(mask, 0, 1 << m)
	{
		bitset<N> full = Zero;
		FOR(j, 0, m) if (mask & (1 << j))
			full |= ye[j];
		
		LL tut = 1LL << (n - 1 - (int) full.count());		
		if (__builtin_popcount(mask) & 1) ans -= tut;
		else ans += tut;
	}
	
	cout << ans << endl;
	
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

using namespace std;

int main()
{	

	int n;
	cin>>n;
	int a[n];
	long long sum=0;
	for(int i=0;i<n;i++)
	{cin>>a[i];
	 sum+=a[i];
	}	

	cout<<sum-n<<'\n';

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
    // <algorithm> std::reverse
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define pl(s) cout << s << endl;

int main(void){
    // Your code here!
    string s;cin>>s;
    int q;cin>>q;
    bool flg;flg=true;
    
    string sl,sr;
    sl="";sr="";
    
    rep(qi,q){
        int x;cin>>x;
        if (x==1){
            if (flg){
                flg=false;
            }
            else{
                flg=true;
            }
        }
        else{
            int f;cin>>f;
            char c;cin>>c;
            if (f==1){
                if (flg==true){
                    // s=c+s;
                    sl=c+sl;
                }
                else{
                    // s=s+c;
                    sr=sr+c;
                }
            }
            else{
                if (flg==false){
                    // s=c+s;
                    sl=c+sl;
                }
                else{
                    // s=s+c;
                    sr=sr+c;
                }
            }
        }
    }
    
    s=sl+s+sr;


    if (flg==false){
        reverse(s.begin(),s.end());
    }
    pl(s);
}




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

#ifdef _DEBUG
inline void dump() { cerr << endl; }
template<typename Head> void dump(Head&& head) { cerr << head; dump(); }
template<typename Head, typename... Tail> void dump(Head&& head, Tail&&... tail) { cerr << head << ", "; dump(forward<Tail>(tail)...); }
#define debug(...) do {cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; dump(__VA_ARGS__); } while (false)
#else
#define dump(...)
#define debug(...)
#endif

template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  ll n; cin>>n;
  ll m; cin>>m;
  vector<vector<ll>> d(m, vector<ll>(m));
  rep(i, m) rep(j, m) cin>>d[i][j];
  vector<vector<ll>> c(n, vector<ll>(n));
  rep(i, n) rep(j, n) {
    cin>>c[i][j];
    c[i][j]--;
  }

  vector<map<ll, ll>> mp(3);

  rep(i, n) rep(j, n) {
    mp[(i+j)%3][c[i][j]]++;
  }

  vector<vector<ll>> sum(3, vector<ll>(m));
  rep(k, 3) {
    rep(i, m) {
      rep(j, m) {
        sum[k][i] += d[j][i]*mp[k][j];
      }
    }
  }

  ll ans = inf;
  rep(i, m) rep(j, m) rep(k, m) {
    if (i == j || j == k || k == i) continue;
    ll tmp = sum[0][i] + sum[1][j] + sum[2][k];
    ans = min(ans, tmp);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5592
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

int n;
long long a[200010];
long long lSum[200010];
long long rSum[200010];
long long d[200010];

int main()
{
	scanf("%d", &n);
	
	for (int i = 0 ; i < n ; i++)
		scanf("%lld", &(a[i]));		
		
	lSum[0] = a[0];
	for (int i = 1 ; i < n ; i++)
		lSum[i] = lSum[i - 1] + a[i];
		
	rSum[n - 1] = 0;
	for (int i = n - 2 ; i >= 0 ; i--)
		rSum[i] = rSum[i + 1] + a[i + 1];
	
	long long min = -1;
	for (int i = 0 ; i < n ; i++)
	{
		if (lSum[i] > rSum[i])
			d[i] = lSum[i] - rSum[i];
		else
			d[i] = rSum[i] - lSum[i];
			
		if ((min == -1) || (min >= d[i]))
			min = d[i];
	}
	
	printf("%lld\n", min);
	
	return 0;
}


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

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define D(x) cerr << #x << " is " << (x) << "\n";

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}

int main()
{
	int n,h,w;
	scanf("%i %i %i",&n,&h,&w);
	int sol=(n-h+1)*(n-w+1);
	if(sol<=0)
        printf("0\n");
    else
        printf("%i\n",sol);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  char b;
  cin >> b;
  if(b == 'A')puts("T");
  if(b == 'T')puts("A");
  if(b == 'G')puts("C");
  if(b == 'C')puts("G");
}


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

bool isprime(ll  val) {
    if (val <= 1)return false;
    for (ll  i = 2; i*i <= val; i++) {
        if (val%i == 0LL)return false;
    }
    return true;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
    
    
    ll n;
    cin>>n;
    for(int i=n;i<=n*5;i++){
        if(isprime(i)){
            cout << i << endl;
            return 0;
        }
    }
}


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


int A[200100];

int main(){
	int n,k,a,sum=0;
	set<int> se;
	
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> a;
		A[a]++;
		se.insert(a);
	}
	
	if(se.size()<=k){
		cout << 0 << endl;
		return 0;
	}
	else{
		int cnt=0;
		sort(A,A+200001);
		for(int i=0;i<200010;i++){
			if(A[i]>0){
				sum+=A[i];
				cnt++;
			}
			if(cnt==se.size()-k) break;
		}
		
	}
	cout << sum << endl;
	return 0;
}

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

const int nmax = 40, abmax = 10, inf = 100000000;

int a[nmax], b[nmax], c[nmax];
int dp[nmax + 1][nmax*abmax + 1][nmax*abmax + 1];

int main(void){
    int n, ma, mb;
    cin >> n >> ma >> mb;

    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i] >> c[i];
    }
    for(int i = 0; i <= n; i++){
        for(int ca = 0; ca <= nmax*abmax; ca++){
            for(int cb = 0; cb <= nmax*abmax; cb++){
                dp[i][ca][cb] = inf;
            }
        }
    }

    dp[0][0][0] = 0;

    for(int i = 0; i < n; i++){
        for(int ca = 0; ca <= nmax*abmax; ca++){
            for(int cb = 0; cb <= nmax*abmax; cb++){
                if(dp[i][ca][cb] == inf) continue;
                dp[i+1][ca][cb] = min(dp[i+1][ca][cb], dp[i][ca][cb]);
                dp[i+1][ca+a[i]][cb+b[i]] = min(dp[i+1][ca+a[i]][cb+b[i]], dp[i][ca][cb] + c[i]);
            }
        }
    }

    int ans = inf;
    for(int ca = 1; ca <= nmax*abmax; ca++){
        for(int cb = 1; cb <= nmax*abmax; cb++){
            if(ca*mb == cb*ma) ans = min(ans, dp[n][ca][cb]);
        }
    }

    if(ans == inf) ans = -1;
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 25984
#include<stdio.h>
#include<stdlib.h>

int main() {
	int sum=0;
	char s[10];
	char c[10];
	scanf("%s", s);
	scanf("%s", c);
	if (s[0] == c[0])
		sum++;
	if (s[1] == c[1])
		sum++;
	if (s[2] == c[2])
		sum++;
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K;
  int ans = 1;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    if(2 * ans < ans + K)
      ans = 2 * ans;
    else
      ans += K;
  }
  printf("%d\n",ans);
} 

Measured memory_bytes: 3744
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int ans=0;
    int N;
    cin >> N;
    long long int A;
    long long int preA;
    cin >> preA;
    
    int flag=0;
    for(int n=1; n<N; n++) {
        cin >> A;
        // cout << flag << endl;
        if(preA>A) {
            if(flag>0) {
                ans++;
                flag=0;
            } else {
                flag=-1;
            }
        } else if(preA<A) {
            if(flag<0) {
                ans++;
                flag=0;
            } else {
                flag=1;
            }
        }

        preA = A;
    }
    
    cout << ans+1 << endl;


    return 0;
    
}

Measured memory_bytes: 256
N, M = map(int, input().split())
data = [list(map(int, input().split())) for _ in range(M)]

now = 0
num = 0
d = dict()
for p, y in sorted(data):
    if now != p:
        now = p
        num = 1
    d[(p,y)] = num
    num += 1

for p, y in data:
    print('{:06d}{:06d}'.format(p, d[(p,y)]))

Measured memory_bytes: 45832
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;
using System.Diagnostics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            //ここに記述
            //データはストリームによて読み込まれており、' 'によって分割されている場合はキュー型のリストに蓄積れる
            // ' 'によって区切られていない場合、次の行を読み込むようになるので、そのまま記述してよい
            //var = cin.ReadInt; イント型

            var n = cin.ReadInt;
            var s = cin.Read;


            int r = 0;
            int b = 0;

            for(int i = 0; i < n; i++)
            {
                if (s[i] == 'R') r++;
                else b++;
            }

            if (r > b) WriteLine("Yes");
            else WriteLine("No");

        }

        public class ConsoleInput
        {
            private readonly System.IO.TextReader _stream;
            private char _separator = ' ';
            private Queue<string> inputStream;
            public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
            {
                this._separator = separator;
                this._stream = stream;
                inputStream = new Queue<string>();
            }
            public string Read
            {
                get
                {
                    if (inputStream.Count != 0) return inputStream.Dequeue();
                    string[] tmp = _stream.ReadLine().Split(_separator);
                    for (int i = 0; i < tmp.Length; ++i)
                        inputStream.Enqueue(tmp[i]);
                    return inputStream.Dequeue();
                }
            }
            public string ReadLine { get { return _stream.ReadLine(); } }
            public int ReadInt { get { return int.Parse(Read); } }
            public long ReadLong { get { return long.Parse(Read); } }
            public double ReadDouble { get { return double.Parse(Read); } }
            public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
            public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
            public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long n, m;
    cin >> n >> m;
    if (n == 1 && m == 1) cout << 1;
    else if (n == 1)  cout << m - 2;
    else if (m == 1) cout << n - 2;
    else cout << n * m - (2 * n + 2 * (m - 2));
}

Measured memory_bytes: 3608
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int H, W;
    int i, j;
    
    while (1) {
        scanf("%d %d", &H, &W);
        
        if(H==0 && W==0){
            break;
        }
        else{
            for(i=0;i<H;i++){
                for(j=0; j<W; j++){
                    printf("#");
                }
                printf("\n");
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 2044
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::collections::HashSet;

fn main() {
    input! {
        n: usize,
        d: [usize;n],
    }

    let mut a: HashSet<usize> = HashSet::new();

    for x in d {
        a.insert(x);
    }
    println!("{}", a.len());
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline
from collections import defaultdict, deque
from itertools import accumulate
n,m,s,t= map(int,input().split())
uvab = [list(map(int,input().split())) for i in range(m)]

g = defaultdict(list)
c = {}
'''
for i in range(1,n+1):
    g[i].append(n+i)
    c[(i,n+i)] = 0
    '''
for u,v,a,b in uvab:
    g[u].append(v)
    g[v].append(u)
    g[n+u].append(n+v)
    g[n+v].append(n+u)
    c[(u,v)] = a
    c[(v,u)] = a
    c[(n+u,n+v)] = b
    c[(n+v,n+u)] = b

inf = 10**15
ds2t = [inf for i in range(2*n+1)]
ds2t[s] = 0

dq = deque([s])
while dq:
    v = dq.popleft()
    for nv in g[v]:
        if ds2t[nv] > ds2t[v] + c[(v,nv)]:
            ds2t[nv] = ds2t[v] + c[(v,nv)]
            dq.append(nv)


dt2s = [inf for i in range(2*n+1)]
dt2s[n+t] = 0

dq = deque([n+t])
while dq:
    v = dq.popleft()
    for nv in g[v]:
        if dt2s[nv] > dt2s[v] + c[(v,nv)]:
            dt2s[nv] = dt2s[v] + c[(v,nv)]
            dq.append(nv)

ds = []
for i in range(1,n+1):
    ds.append(ds2t[i] + dt2s[n+i])

ds = accumulate(ds[::-1], min)

for d in reversed(list(ds)): 
    print(10**15-d)




Measured memory_bytes: 199552
#include<iostream>
using namespace std;
int main(void){
	int n;
	cin >> n;
	char s[n + 1];
	cin >> s;
	int cnt = 0;
	char c = s[0];
	for (int i =1; i < n; i++){
		if (c != s[i]){
			cnt++;
			c = s[i];
		}
	}
	cnt++;
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
const int M = 10100;
const int N = 2100;
bitset<M> ok[N];
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, k; cin >> n >> k;
	vector<string> vs(n);
	for(auto &s : vs) cin >> s;
	ok[n][0] = 1;
	for(int i = n - 1; i; i--) {
		ok[i] = ok[i + 1] | (ok[i + 1] << vs[i].size());
	}
	vector<pii> q[2];
	int now = 0;
	for(int i = 0; i < n; i++) {
		if(ok[i + 1][k - vs[i].size()]) {
			q[now].emplace_back(i, 0);
		}
	}
	string ans;
	const int S = 10000;
	for(int i = 0; i < k; i++) {
		char z = 'z' + 1;
		for(auto &e : q[now]) {
			z = min(z, vs[e.fi][e.se]);
		}
		ans.push_back(z);
		int zz = n;
		for(auto &e : q[now]) {
			if(vs[e.fi][e.se] == z) {
				if(e.se == vs[e.fi].size() - 1) {
					zz = min(zz, e.fi);
				} else {
					e.se++;
					q[now^1].emplace_back(e);
				}
			}
		}
		int need = k - i - 1;
		for(int i = zz + 1; i < n; i++)
			if(need >= vs[i].size() && ok[i + 1][need - vs[i].size()])
				q[now^1].emplace_back(i, 0);
		q[now].clear();
		if(q[now^1].size() > S) q[now^1].resize(S);
		now ^= 1;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
	int n, team[101] = { 0 };
	cin >> n;

	int a, b, c, d;
	for (int i = 0; i < n * (n - 1) / 2; i++) {
		cin >> a >> b >> c >> d;

		if (c > d) {
			team[a] += 3;
		}
		else if (c == d) {
			team[a]++;
			team[b]++;
		}
		else {
			team[b] += 3;
		}
	}

	for (int i = 1; i <= n; i++) {
		int rank = 1;
		for (int j = 1; j <= n; j++) {
			if (team[i] < team[j]) {
				rank++;
			}
		}
		cout << rank << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using P = pair<int,int>;
int main(void) {
    vector<int> x(3);
    rep(i, 3) cin >> x[i];
    sort(x.begin(), x.end());
    int mi = 1001001001;
    do{
        int res = abs(x[1]-x[0]) + abs(x[2]-x[1]);
        mi = min(res, mi);
    } while (next_permutation(x.begin(), x.end()));
    cout << mi;
}


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

int main(){
  int n,k,x,y;
  cin >> n >> k >> x >> y;
  if(n <= k){
    cout << n * x << endl;
  }
  else{
    int cost = k * x + (n - k) * y;
    cout << cost << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>

using namespace std;
typedef long long LL;
int _max(int x, int y) {return x > y ? x : y;}
int _min(int x, int y) {return x < y ? x : y;}
LL read() {
	LL s = 0, f = 1; char ch = getchar();
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
	return s * f;
}
void put(int x) {
	if(x >= 10) put(x / 10);
	putchar(x % 10 + '0');
}

LL a[100001], hh[61], bin[61];

int main() {
//	freopen("a.in", "r", stdin);
//	freopen("a.out", "w", stdout);
	int n = read(); LL sum = 0;
	bin[0] = 1LL; for(int i = 1; i <= 60; i++) bin[i] = bin[i - 1] << 1;
	for(int i = 1; i <= n; i++) a[i] = read(), sum ^= a[i];
	for(int i = 1; i <= n; i++) {
		bool bk = 0;
		for(int j = 60; j >= 0; j--) if(!(bin[j] & sum) && (a[i] & bin[j])){
			if(!hh[j]) {hh[j] = a[i]; bk = 1; break;}
			else a[i] ^= hh[j];
		} if(bk) continue;
		for(int j = 60; j >= 0; j--) if((bin[j] & sum) && (a[i] & bin[j])){
			if(!hh[j]) {hh[j] = a[i]; break;}
			else a[i] ^= hh[j];
		}
	} LL ans = 0;
	for(int i = 60; i >= 0; i--) if(!(sum & bin[i]) && !(ans & bin[i])) ans ^= hh[i];
	for(int i = 60; i >= 0; i--) if((sum & bin[i]) && (ans & bin[i])) ans ^= hh[i];
	printf("%lld\n", (sum ^ ans) + ans);
	return 0;
}

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

typedef long long ll;
const int INF = 2e9;
//const ll INF = 9e18;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    vector<int> pos(26,-1);
    vector<int> len(26);
    int N = s.size();
    for (int i=0;i<N;i++){
        int p = s[i]-'a';
        len[p] = max(len[p], i-pos[p]-1);
        pos[p] = i;
    }
    for (int i=0;i<26;i++){
        len[i] = max(len[i],N-1-pos[i]);
    }
    int ans = INF;
    for (int i=0;i<26;i++){
        ans = min(ans, len[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#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[i];
  }
  
  sort(d.begin(),d.end());
  
  int num = N / 2;
  num = num - 1;
  int num2 = 0;
  
  for(int i = d[num] + 1;i <= d[num + 1];++i){
    num2++;
  }
  
  cout << num2 << endl;
}



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

int n, k;
int cha;

int main () {
    cin >> k >> n;
    int a, b, first;
    for (int i = 1; i <= n; i++) {
	    if (i % 2) cin >> a;
		else cin >> b;
		if (i == 1) {
			first = a;
	    	continue;
		} else if (i == n) {
			cha = max (cha, abs (a - b));
	    	cha = max (cha, k - max (a, b) +first);
		} else {
		    cha = max (cha, abs (a - b)); 
		}  
	} 
	cout << k - cha;
	return 0;
} 

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j, k) for (int i = j; i < k; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 60);

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

    string s;
    cin >> s;
    reverse(all(s));

    int ans = 0;
    int d = 1, sum = 0;
    // vi v(s.size() + 1, 0);
    map<int, int> mp;
    rep(i, 0, s.size()) {
        sum += (s[i] - '0') * d;
        sum %= 2019;
        // v[i] = sum;
        // debug2(i, sum);
        if (sum == 0) ans++;
        // debug(mp[sum]);
        ans += mp[sum];
        mp[sum]++;
        d = (d * 10) % 2019;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3788
N = int(input())
A = list(map(int, input().split()))
mon = 1000  #所持金
cnt = 0  #株の所持数
cur = A[0]
for i in range(1,len(A)):
  sec = A[i]
  #値上がりする前に購入
  if cur < sec:
    #買えるだけ買う
    if mon > cur:
      cnt = mon//cur
      mon = mon%cur
  #値が下がる前に売却
  elif cur > sec:
    mon += cur * cnt
    cnt = 0
  cur = sec
if cnt > 0:
  mon += A[-1]*cnt
print(mon)


Measured memory_bytes: 9196
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  ll a[n],b[n],c[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<n;i++){
    cin>>c[i];
    }
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  reverse(c,c+n); 
  ll ans=0;
   for(int i=0;i<=n;i++){
     ll la=-1,lc=-1,ra=n,rc=n;
     ll mida,midc;
     while(ra-la>1){
       mida=(la+ra)/2;
       if(b[i]>a[mida])
         la=mida;
       else
         ra=mida;
       }
    while(rc-lc>1){
       midc=(lc+rc)/2;
       if(b[i]<c[midc])
         lc=midc;
       else
         rc=midc;
       } 
     
     ans+=ra*rc;
     }
  cout<<ans<<endl;
  return 0;
       
    }


Measured memory_bytes: 2688
#include <iostream>

using namespace std;

int main() {
    int H1, M1, H2, M2, K, ans;
    cin >> H1 >> M1 >> H2 >> M2 >> K;
    ans = H2 * 60 + M2 - (H1 * 60 + M1);
    if (ans - K < 0) cout << 0 << endl;
    else cout << ans - K << endl;
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    int an=0;
    for(int A=1;A<=N;A++){
        for(int B=1;B<=N/A;B++){
            int C=N-A*B;
            if(C>0)an++;
        }
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 3632
# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


def read():
    N = II()
    a = ILI()
    return (N, a)


def solve(N, a):
    count = [0] * 9
    for ele in a:
        if 1 <= ele <= 399:
            count[0] = 1
        elif 400 <= ele <= 799:
            count[1] = 1
        elif 800 <= ele <= 1199:
            count[2] = 1
        elif 1200 <= ele <= 1599:
            count[3] = 1
        elif 1600 <= ele <= 1999:
            count[4] = 1
        elif 2000 <= ele <= 2399:
            count[5] = 1
        elif 2400 <= ele <= 2799:
            count[6] = 1
        elif 2800 <= ele <= 3199:
            count[7] = 1
        elif ele >= 3200:
            count[8] += 1

    num_else = sum(count[0: 8])
    ans_max = sum(count)
    if num_else == 0:
        ans_min = 1
    else:
        ans_min = num_else
    
    ans = (ans_min, ans_max)
    return ans


def main():
    params = read()
    ans = solve(*params)
    print("{} {}".format(ans[0], ans[1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 6252
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    long long sum=0;
    cin>>n;
    while(n>0){
        if(!(n%3==0||n%5==0)){
            sum+=n;
        };
        n--;
    }
	cout<<sum<<"\n";
	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int a;
    bool b = false,c = false,d = false,e = false;
    rep(i, 4){
        cin >> a;
        switch (a) {
            case 1:
                b = true;
                break;
            case 9:
                c = true;
                break;
            case 7:
                d = true;
                break;
            case 4:
                e = true;
                break;
        }
    }
    if (b&&c&&d&&e) {
        YES;
    }else{
        NO;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int a[200] = {0};
  
  for (int i = 0; i < n; i++) a[i] = 2;
  for (int i = 0; i < m; i++) a[i+n] = 1;

  int ans = 0;
  for (int i = 0; i < n+m-1; i++) {
    for (int j = i + 1; j < n+m; j++) {
      int x = a[i] + a[j];
      if (x % 2 == 0) ans++;
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
<?php 
fscanf(STDIN, "%d %d", $a,$b);
$flag = 0;
if($b == 1){
  $flag = 1 ;
  echo "0";
}
$prev = 1;
if($flag == 0){
  for ($i=0; $i <= 20; $i++) {
    if($prev+($a-1)*$i >= $b){
      echo $i;
      break;
    }
  }
}
?>

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

ctr_4 = 0
ctr_2 = 0

for a in A:
	if a % 4 == 0:
		ctr_4 += 1
	elif a % 2 == 0:
		ctr_2 += 1
		
N -= ctr_2		
# print(ctr_4, ctr_2)
if ctr_2 == 0:
	need = N // 2
else:	
	need = (N + 1) // 2

if ctr_4 >= need:
	print("Yes")
else:
	print("No")

Measured memory_bytes: 62576
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include<map>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  map<string,int> mp;
  rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
  }
  int mx = 0;
  for (auto p : mp) mx = max(mx, p.second);
  for (auto p : mp) {
    if (p.second != mx) continue;
    cout << p.first << endl;
  }
  return 0;
}



Measured memory_bytes: 25216
N,W = map(int,input().split())
val = [0]*N
wei = [0]*N
for i in range(N): val[i],wei[i] = map(int,input().split())
dp = [[0]*(W+1) for _ in range(N+1)]

for i in range(N):
    for w in range(W+1):
        if w - wei[i] < 0: dp[i+1][w] = dp[i][w]
        else: dp[i+1][w] = max(dp[i][w],dp[i+1][w-wei[i]]+val[i])
print(dp[N][W])


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

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<LL, LL> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 200200;

vector<PII> g[MAX];
vector<PII> A[MAX];

vector<PII> s, t;

void add(vector<PII>& c, PII val)
{
	/*c.PB(val);
	return;*/
	while(SZ(c))
	{
		if (val.first <= c.back().first && val.second <= c.back().second) c.pop_back();
		else break;
	}
	if (c.empty() || c.back().second > val.second) c.PB(val);
}

void merge(vector<PII>& a, vector<PII>& b, vector<PII>& c)
{
	c.clear();
	int ind = 0;
	FOR (i, 0, SZ(a))
	{
		while(ind < SZ(b) && b[ind] < a[i])
		{
			add(c, b[ind]);
			ind++;
		}

		add(c, a[i]);
	}

	while(ind < SZ(b))
	{
		add(c, b[ind]);
		ind++;
	}
}

void go(int x, LL m)
{
	A[x].clear();
	if (SZ(g[x]) == 0)
	{
		A[x].PB(MP(0, 0));
		return;
	}

	go(g[x][0].first, m);
	go(g[x][1].first, m);

	int w1 = g[x][0].second;
	int w2 = g[x][1].second;

	vector<PII>& a = A[g[x][0].first];
	vector<PII>& b = A[g[x][1].first];

	s.clear();
	t.clear();

	int ind = 0;

	FOR (i, 0, SZ(a))
	{
		LL x = a[i].first;
		LL y = a[i].second;

		LL mn = LINF;
		if (ind < 0) ind = 0;

		while(ind < SZ(b))
		{
			LL u = b[ind].first;
			LL v = b[ind].second;

			if (y + u + w1 + w2 <= m)
			{
				mn = min(mn, v);
				ind++;
			}
			else break;
		}
	//	ind--;

		if (mn != LINF)
		{
			s.PB(MP(x + w1, mn + w2));
			t.PB(MP(mn + w2, x + w1));
		}
	}

	reverse(ALL(t));

	merge(s, t, A[x]);

	FOR (i, 1, SZ(A[x]))
	{
	//	if (A[x][i].first <= A[x][i-1].first) throw -1;
	//	if (A[x][i].second >= A[x][i-1].second) throw -1;
	}

	//sort(ALL(A[x]));


}

bool ok(LL m)
{
	go(0, m);

	if (SZ(A[0])) return true;
	return false;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);


	int n;
	scanf("%d", &n);
	FOR (i, 1, n)
	{
		int p, a;
		scanf("%d%d", &p, &a);
		p--;

		g[p].PB(MP(i, a));
	}

/*	cout<<ok(1441051)<<endl;

	FOR (i, 0, n)
	{
		cout<<i + 1<<": ";
		FOR (j, 0, SZ(A[i]))
		{
			cout<<"("<<A[i][j].first<<", "<<A[i][j].second<<") ";
		}
		cout<<endl;
	}

	return 0;*/

	LL l = -1, r = MAX * (LL)MAX;
	while(r - l > 1)
	{
		LL m = (l + r) / 2;

	//	cout<<l<<' '<<r<<' '<<m<<endl;

		if (ok(m)) r = m;
		else l = m;
	}

	cout<<r<<endl;

}



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

int main() {
    int N;
    cin >> N;
    vector<int> t(N), x(N), y(N);
    for (int i = 0; i < N; i++) {
        cin >> t[i] >> x[i] >> y[i];
    }
    {//i = 0のとき
        int time = t[0];
        int dx = abs(x[0]);
        int dy = abs(y[0]);
        if (time < dx + dy || (time - dx + dy) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = 1; i < N; i++) {
        int time = t[i] - t[i - 1];
        int dx = abs(x[i] - x[i - 1]);
        int dy = abs(y[i] - y[i - 1]);
        if (time < dx + dy || (time - dx + dy) % 2 == 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define clr(x) memset(x, 0, sizeof(x))
#define sz(x) (int)x.size()

using namespace std;

typedef long long ll;
typedef pair<long , long> pll;

const ll mx = 105;
const ll maxn = 1000001;
const ll mod = 1000000007;

vector<vector<int>> adj;
vector<ll> lis;


int main(){
       
 
  ll t = 1;

  //cin>>t;

  while(t--){
     ll n, i, j ,k, a, b, c ,d;

     cin>>a>>b>>c>>d;
     int tu = 1;
     while(a >= 0 && c >= 0)
     {
         if(tu == 1){
             if(b >= c){
                 cout<<"Yes\n";
                 c = 0;
                 break;
             }
             else{
                 c -= b;
             }
             tu = 0;
         }
         else{
             if(d >= a){
                 cout<<"No\n";
                 a = 0;
                 break;
             }
             else{
                 a -= d;

             }
             tu = 1;
         }
     }

    
  }     
        
}


Measured memory_bytes: 3624
// 速度比較のためにkeymoonさんの提出をお借りしました。
// middleBitの計算にKaratsuba法を使いました。
// https://atcoder.jp/contests/abc141/submissions/7717102

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var s = Console.ReadLine();
        int curMaxLength = 0;
        var hash = new RollingHash(s);
        for (int i = 0; i < s.Length; i++)
            for (int j = i; j < s.Length; j++)
                while (curMaxLength < j - i && j + curMaxLength < n && hash.Slice(i, curMaxLength + 1) == hash.Slice(j, curMaxLength + 1)) curMaxLength++;
        Console.WriteLine(curMaxLength);
    }
}

class RollingHash
{
    const ulong MASK30 = (1UL << 30) - 1;
    const ulong MASK31 = (1UL << 31) - 1;
    const ulong MOD = (1UL << 61) - 1;
    const ulong POSITIVIZER = MOD * ((1UL << 3) - 1);
    static uint Base;
    static ulong[] powMemo = new ulong[5000 + 1];
    static RollingHash()
    {
        Base = (uint)new Random().Next(129, int.MaxValue);
        powMemo[0] = 1;
        for (int i = 1; i < powMemo.Length; i++)
            powMemo[i] = CalcMod(Mul(powMemo[i - 1], Base));
    }

    ulong[] hash;

    public RollingHash(string s)
    {
        hash = new ulong[s.Length + 1];
        for (int i = 0; i < s.Length; i++)
            hash[i + 1] = CalcMod(Mul(hash[i], Base) + s[i]);
    }

    public ulong Slice(int begin, int length)
    {
        return CalcMod(hash[begin + length] + POSITIVIZER - Mul(hash[begin], powMemo[length]));
    }

    private static ulong Mul(ulong l, ulong r)
    {
        var lu = l >> 31;
        var ld = l & MASK31;
        var ru = r >> 31;
        var rd = r & MASK31;
        var u = lu * ru;
        var d = ld * rd;
        var middleBit = (ld + lu) * (rd + ru) - u - d;
        return ((u) << 1) +
            d +
            ((middleBit & MASK30) << 31) +
            (middleBit >> 30);
    }

    private static ulong CalcMod(ulong val)
    {
        val = (val & MOD) + (val >> 61);
        if (val > MOD) val -= MOD;
        return val;
    }
}


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

#define ll long long
#define rep(i,x,y) for(int i=x;i<y;i++)
#define rel(i,x,y) for(int i=x-1;i>=y;i--)
#define all(x) x.begin(),x.end()
ll mod = 1e9+7;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n; cin >> n;
    ll ans=1;
    ll a[3]={};
    rep(i,0,n){
        ll tmp;cin >> tmp;
        ll hogo;
        if(a[0]==tmp)hogo=0;
        else if(a[1]==tmp)hogo=1;
        else if(a[2]==tmp)hogo=2; 
        else{ cout << "0" << endl; return 0; }
        ll cnt=0;
        rep(j,0,3) if(a[hogo]==a[j])cnt++;
        (ans *= cnt)%=mod;
        a[hogo]++;
    }
    cout << ans << endl;

}

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

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	if (n % 1000 == 0)
		cout << 0 << "\n";
	else
		cout << 1000 - (n % 1000) << "\n";
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String str = sc.nextLine();
		String befhalf,afthalf;
		while(str.length() > 0){
			str = str.substring(0, str.length()-1);
			befhalf = str.substring(0, str.length()/2);
			afthalf = str.substring((str.length()/2), str.length());
			//System.out.println(str+" "+befhalf+" "+afthalf);
			if(befhalf.equals(afthalf)){
				System.out.println(str.length());
				str = "";
			}
		}

	}

	private static int calc(int[] a,int ans,int n) {
		int sum=a[0];
		boolean plusFlag;
		// TODO 自動生成されたメソッド・スタブ
		if(a[0] > 0){
			plusFlag = true;
		}else{
			plusFlag = false;
		}



		for(int i = 1;i<n;i++){
			sum += a[i];
			if(plusFlag){
				if(sum >= 0){
					ans += Math.abs(sum)+1;
					sum = -1;

				}
			}else{
				if(sum <= 0){
					ans += Math.abs(sum)+1;
					sum = 1;
				}
			}
			plusFlag = !plusFlag;
		}


		return ans;
	}


}

Measured memory_bytes: 23892