akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
const ll inf = 1000000000000000000, moder = 1000000007;
//Library!
ll pow_mod(ll a, ll b, ll n) {
	if (b == 0)return a % n;
	if (b % 2)return pow_mod(a, b - 1, n)*a%n;
	else return pow_mod(pow_mod(a, b / 2, n), 2, n) % n;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++)if (!(n%i))return false;
	return true;
}
ll comb(ll n, ll r) {
	if (n == r) return 1;
	else if (r == 0) return 1;
	else if (r == 1) return n % moder;
	else return (comb(n - 1, r - 1) + comb(n - 1, r)) % moder;
}
//ライブラリゾーン終了
int main() {
	ll n, cnt = 0, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if (!a) {
			ans += cnt / 2;
			cnt = 0;
		}
		else cnt += a;
	}
	ans += cnt / 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define mod (ll)(1e9+7)
#define d(x) cerr<<#x<<"="<<x<<endl;
#define p(x) cout<<(x)<<endl
#define ps(x) cout<<(x);
#define pk(x) cout<<(x)<<" ";
#define pfix(d,x) cout << fixed << setprecision(d) << x << endl;
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define minel(v) *min_element(all(v))
#define minind(v) distance((v).begin(), min_element(all(v)))
#define maxel(v) *max_element(all(v))
#define maxind(v) distance((v).begin(), max_element(all(v)))
#define p2d(v,n,m) rep(i,n){rep(j,m){pk(v[i][j]);}p("");}
#define fi first
#define se second
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
ll a[100001],b[100001],c[100001],d,n,m,x,y,z,h,w,k,mi=inf,ma=-inf,ans,s,t,l,r,res,tmp,itr,p,q;
bool flag;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int dx8[8]={1,1,0,-1,-1,-1,0,1},dy8[8]={0,1,1,1,0,-1,-1,-1};
char cha;
string st;
typedef map<ll, ll> imap;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<pair<ll,ll> > VP;
P pa;

int main(){
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,1,n)b[i]=inf;
    rep(i,0,n){
        b[i+2]=min(b[i+2],b[i]+abs(a[i+2]-a[i]));
        b[i+1]=min(b[i+1],b[i]+abs(a[i+1]-a[i]));
    }
    p(b[n-1]);
    return 0;
}


Measured memory_bytes: 1792
a = [input().split() for _ in range(3)]
n = int(input())
b = [input() for _ in range(n)]

if (a[0][0] in b) and (a[0][1] in b) and (a[0][2] in b):
    print('Yes')
elif (a[1][0] in b) and (a[1][1] in b) and (a[1][2] in b):
    print('Yes')
elif (a[2][0] in b) and (a[2][1] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][0] in b) and (a[1][0] in b) and (a[2][0] in b):
    print('Yes')
elif (a[0][1] in b) and (a[1][1] in b) and (a[2][1] in b):
    print('Yes')
elif (a[0][2] in b) and (a[1][2] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][0] in b) and (a[1][1] in b) and (a[2][2] in b):
    print('Yes')
elif (a[0][2] in b) and (a[1][1] in b) and (a[2][0] in b):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9244
#include <iostream>
#include <map>
#include <algorithm>
 
using namespace std;
 
typedef pair<int, int> P;
 
int get_first(int hi, int wi, int w) {
    int f;
    if ((hi+wi)%2 == 0) {
        if (wi >= hi) {
            f = wi-hi;
        }
        else {
            f = hi-wi-1;
        }
    }
    else {
        f = wi+hi;
    }
    if (f/w%2 == 0) {
        return f%w;
    }
    else {
        return w-f%w-1;
    }
}
 
int main() {
    int h, w, n;
    int index[200000], inv[200000];
    P ab[200000];
    cin >> h >> w >> n;
    for (int i=0; i<n; i++) {
        cin >> ab[i].first >> ab[i].second;
    }
    sort(ab, ab+n);
    for (int i=0; i<w; i++) {
        index[i] = i;
    }
    for (int i=0; i<n; i++) {
        int a = get_first(ab[i].first, ab[i].second-1, w);
        int b = get_first(ab[i].first, ab[i].second, w);
        int tmp = index[a];
        index[a] = index[b];
        index[b] = tmp;
    }
    for (int i=0; i<w; i++) {
        int f = get_first(h, i, w);
        inv[index[f]] = i;
    }
    for (int i=0; i<w; i++) {
        cout << inv[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 4288
/*
https://leetcode.com/problems/maximum-of-absolute-value-expression/discuss/339968/JavaC++Python-Maximum-Manhattan-Distance

Intuition
Take |x[i] - x[j]| + |y[i] - y[j]| as Manhattan distance of two points.
x is the coordinate of points on the x-axis,
y is the coordinate of points on the y-axis.


Explanation 1: Math
Assume i < j, there are four possible expression:
|x[i] - x[j]| + |y[i] - y[j]| = (x[i] - x[j]|) + (y[i] - y[j]) = (x[i] + y[i]|) - (x[j] + y[j])
|x[i] - x[j]| + |y[i] - y[j]| = (x[i] - x[j]|) - (y[i] - y[j]) = (x[i] - y[i]|) - (x[j] - y[j])
|x[i] - x[j]| + |y[i] - y[j]| = -(x[i] - x[j]|) + (y[i] - y[j]) = (-x[i] + y[i]|) - (-x[j] + y[j])
|x[i] - x[j]| + |y[i] - y[j]| = -(x[i] - x[j]|) - (y[i] - y[j]) = (-x[i] - y[i]|) - (-x[j] - y[j])

So we can see, the expression
|x[i] - x[j]| + |y[i] - y[j]| + |i - j| = f(j) - f(i)

where f(i) = p * x[i] + q * y[i] + i
with p = 1 or -1, q = 1 or -1


Explanation 2: Graph
For 3 points on the plane, we always have |AO| - |BO| <= |AB|.
When AO and BO are in the same direction, we have ||AO| - |BO|| = |AB|.

We take 4 points for point O, left-top, left-bottom, right-top and right-bottom.
Each time, for each point B, and find the smallest A point to O,
the Manhattan distance |AB| >= |AO| - |BO|.


*/
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#include <bits/stdc++.h>
using namespace std;
#define debug(...) 42
#endif

void solve() {
	int n, x, y;
	cin >> n;
	vector<int> sum(n), diff(n);
	for (int i = 0; i < n; i++) {
		cin >> x >> y;
		sum[i] = x + y;
		diff[i] = x - y;
	}
	int maxone = INT_MIN, maxtwo = INT_MIN;
	int minone = INT_MAX, mintwo = INT_MAX;
	int ans = INT_MIN;
	for (int i = 0; i < n; i++) {
		maxone = max(maxone, sum[i]);
		maxtwo = max(maxtwo, diff[i]);
		minone = min(minone, sum[i]);
		mintwo = min(mintwo, diff[i]);
		ans = max({ans, maxone - minone, maxtwo - mintwo});
	}
	cout << ans;
}

int32_t main() {
	ios::sync_with_stdio(0); 		cin.tie(0); cout.tie(0);

	solve();
}



Measured memory_bytes: 4784
#!/usr/bin/perl
#= CPAN mocules =====================================================#
use strict;				# strictモード
use warnings;			# 警告有効

#= Global values ====================================================#
#= Local routines ===================================================#
sub main(){
	my $n = <>;chomp $n;
	my $s = <>;chomp $s;
	my @data = unpack("C*", $s);

	my @rgbCnt = (0,0,0,0,0);
	my $count = 0;

	# R = 82 = 0x52 = 0b0101 0010 => Index=4
	# G = 71 = 0x47 = 0b0100 0111 => Index=1
	# B = 66 = 0x42 = 0b0100 0010 => Index=0
	for (my $center = 0; $center < $n; $center++){
		my $cval = $data[$center];

		my $idx = ($cval & 0x14) >> 2;
		$rgbCnt[$idx]++;

		my $left = $center - 1;
		my $right = $center + 1;
		my $sum = 219 - $cval;	# 82 + 71 + 61 = 219

		while ((0 <= $left) && ($right < $n)){
			if (($sum - $data[$left] - $data[$right]) == 0){
				$count--;
			}
			$left--;
			$right++;
		}
	}

	$count += ($rgbCnt[0] * $rgbCnt[1] * $rgbCnt[4]);
	print $count, "\n";
	return 0;
}

#----- 実行 -----#
exit( main() );


Measured memory_bytes: 5224
n,k=map(int,input().split())
a=list(map(int,input().split()))
ok=set()
now=0
l=[]
while now not in ok and k:
    l.append(now)
    ok.add(now)
    now=a[now]-1
    k-=1
if k==0:print(now+1);exit()
length=len(ok)-(h:=l.index(now))
l=l[h:]

k=(k)%length

print(l[k]+1)

Measured memory_bytes: 35196
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<int,int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int fun(int n, int k) {
  return (((ll)n>>(ll)k)&1);
}


void solve(){
    

  ll n,m,x;
  cin>>n>>m>>x;


  vecl c(n);

  vector<vecl> a(n,vecl(m));


  rep(i,n){
      cin>>c[i];
      rep(j,m)cin>>a[i][j];
  }



  ll ans=INF;

  rep(bit,1<<n){
      vecl ok(m,0);
      ll cost=0;

      
      rep(i,n){
        if(fun(bit,i)){
            cost+=c[i];
            rep(j,m)ok[j]+=a[i][j];
        }
      }


      bool check=true;


      rep(i,m){
          if(ok[i]<x)check=false;
      }


      if(check)
        ans=min(ans,cost);
  }


  if(ans>=INF)
    cout<<-1<<endl;
  else cout<<ans<<endl;


 
}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

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

using namespace std;

int k,a,b,c;

int main()
{
    cin>>a>>b>>c>>k;
    for (int i=0;i<=k;++i)
    {
        for (int j=0;j+i<=k;++j)
        {
            if (a<(b*(1<<i)) && (b*(1<<i))<(c*(1<<j)))
            {
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
    return 0;
}


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

int main(){
  ll t1,t2;
  cin>>t1>>t2;
  ll a1,a2;
  cin>>a1>>a2;
  ll b1,b2;
  cin>>b1>>b2;
  ll d1=(a1-b1)*t1;
  ll d2=(a2-b2)*t2;
  if(d1+d2==0){
    cout<<"infinity"<<endl;
    return 0;
  }
  if((d1>0&&(d1+d2)>0)||(d1<0&&(d1+d2)<0)){
    cout<<0<<endl;
  }else{
    ll cross=-d1/(d1+d2);
    if(abs(d1)%abs(d1+d2)==0){
      cout<<cross*2<<endl;
    }else{
      cout<<cross*2+1<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

#define MAXN 300000
int prime[MAXN];/* i番目の素数 */
bool is_prime[MAXN]; /*iは素数か？*/
int num_prime[MAXN]; /* i番目までの素数の数 */
int sieve(int n){
  int p=0;
  for(int i=0;i<=n;i++) is_prime[i]=true;
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      prime[p++]=i;
      for(int j=2*i;j<=n;j+=i) is_prime[j]=false;
    }
  }
  for(int i=1;i<MAXN;i++){
    num_prime[i]=num_prime[i-1]+is_prime[i];
  }
  return p; 
}

int main(){
  int n;
  cin>>n;
  
  sieve(5000);
  int m,i;
  m=i=0;
  while(m!=n){
    if(prime[i]%5==2){
      cout<<prime[i];
      m++;
      if(m!=n) cout<<" ";
    }
    i++;
  }
  cout<<endl;
  return 0;
}


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

using namespace std;

int main(void){
    vector<vector<char>>mat(2,vector<char>(3));
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> mat.at(i).at(j);
        }
    }
    for(int i=0;i<mat.size();i++){
        for(int j=0;j<mat.at(0).size();j++){
            if( mat.at(i).at(j) != mat.at(1-i).at(2-j) ){
                goto OUT;
            }
        }
    }
    cout<<"YES"<<endl;
    return 0;
    OUT:
        cout<<"NO"<<endl;
        return 0;
}


Measured memory_bytes: 256
// When you are hungry for something and you're determined and you're focused 
// and you're committed to something it's hard to surrender, isn't it?

#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define ll long long 
#define int ll
#define mod 1000000007
#define mod1 1000000006
#define modi 998244353
#define setbit(x) __builtin_popcount(x)
#define fff(i,n) for(int i=0;i<n;i++)
#define ff first
#define ss second
#define pb push_back
vector<ll> vi[300005];
int color[100005];
ll pa[500005];
ll si[500005];
#define pb push_back
bool visi[1000005]={false};
bool is[100005];
ll fac[10000001];
ll prime[400005];
ll bit[100005];
const long double eps = 1.0e-14;      // allowable error
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
 
 
void fact(){
    fac[0]=1;
    for(int i=1;i<=10000000;i++){
        fac[i]=(fac[i-1]*i)%mod;
    }
    return ;
}
void sieve(){
    prime[0]=0;
    prime[1]=0;
    for(int i=2;i<400005;i++){
        prime[i]=1;
    }
    for(int i=2;i*i<400005;i++){
        if(prime[i]==1){
            for(int j=i*i;j<400005;j+=i){
                prime[j]=0;
            }
        }
    }
    
}
 
ll power(ll n , ll p ){
    if(p==0)
        return 1;
    
    ll res = power((n*n)%mod,p/2);
    if(p%2==1)
        res = (n*res)%mod;
    
    return res;
}
 
 
void upd(ll i,ll val,ll n) {
    for(;i<=n;i+=i&(-i))
        bit[i]+=val;
}
 
ll qry(ll i) {
    ll sum=0;
    for(;i>0;i-=i&(-i))
        sum+=bit[i];
    return sum;
}
 
 
ll fin(ll u) {
    if(pa[u]==u)
        return u;
    return fin(pa[u]);
}
 
void uni(ll u,ll v) {
    ll p1=fin(u);
    ll p2=fin(v);
    if(p1==p2)
        return;
    if(si[p1]<si[p2])
        swap(p1,p2);
    si[p1]+=si[p2];
    pa[p2]=p1;
    return;
}
 
int32_t main() {
    fio
    
    int n;
    cin >> n;
    int a[n],b[n],c[n-1];
    
    fff(i,n)
    cin >> a[i];
    
    fff(i,n)
    cin >> b[i];
    
    fff(i,n-1)
    cin >> c[i];
    
    int ans=0;
    ans+=b[a[0]-1];
    
    for(int i=1;i<n;i++) {
        if(a[i-1]+1==a[i]) {
            ans+=(b[a[i]-1]+c[a[i]-2]);
        }
        else
        ans+=(b[a[i]-1]);
    }
    
    cout << ans;
    
	return 0;
    
}

Measured memory_bytes: 8832
N = int(input())
S = input()
cnt = 0

for i in range(100):
    num_set = set()
    target = str(i).zfill(2)
    j = 0
    for s in S:
        if j<2 and s == target[j]:
            j += 1
        elif j==2:
            num_set.add(s)
    cnt += len(num_set)
print(cnt)

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n, m;
li a[1010];

int main() {
    cin >> n >> m;
    li sum = 0;
    rin{
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n);
    cout << (a[n - m] * 4 * m >= sum ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=A[0]
if N%2==1:
  n=int((N-1)/2)
  ans+=A[n]
  for i in range(1,n):
    ans+=2*A[i]
elif N==2:
  ans+=0
elif N%2==0 and N>2:
  n=int((N-2)/2)
  for i in range(1,n+1):
    ans+=2*A[i]
print(ans)

Measured memory_bytes: 31540
N = int(input())

ans = []
sm = 0
for i in range(1, N+1):
    sm += i
    ans.append(i)
    if sm >= N:
        exclusion = -1
        if sm-N != 0:
            exclusion = sm-N

        for a in ans:
            if a != exclusion:
                print(a)
        break


Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
using namespace std;
int A[100000+1];
bool binary_search(int key,int n)
{
	int left = 0;
	int right = n;
	int mid = 0;
	while(left <= right){
		mid = (left + right) / 2;
		if(key == A[mid]){
			return true;
		}
		else if(key < A[mid]){
			right = mid - 1;
		}
		else if(key > A[mid]){
			left = mid + 1;
		}
	}
	return false;
}

int main()
{
	int q,n,cnt = 0;
	int key;
	scanf("%d",&n);
	for(int i = 0;i < n;i++){
		scanf("%d",&A[i]);
	}
	scanf("%d",&q);
	for(int i = 0;i < q;i++){
		scanf("%d",&key);
		if(binary_search(key,n)){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	
	return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  bool flag=false;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    cin >> v[i];
  }
  sort(v.begin(),v.end());
  for(int i=0;i<n;i++){
    if(v[i]==v[i+1]){
      flag = true;
    }
  }
  if(flag){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }

}


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

int main(){
    long long int t,s,n;
    cin>>n;
    cin>>t>>s;
    for(int i=0; i<n-1; i++){
        long long int in1,in2;
        cin>>in1>>in2;
        long long int baisu=max(t/in1+!!(t%in1),s/in2+!!(s%in2));
        t=baisu*in1;
        s=baisu*in2;
    }
    cout<<t+s<<endl;
    return 0;
}


Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int N=6005;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
string S,F[N];
int n,m,id[N],PosA[N],PosB[N],nxt[N];
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();cin>>S;S=" "+S;
	for(int i=1,n1=0,n2=0;i<=n*2;i++){
		if(S[i]=='a')PosA[id[i]=++n1]=i;
		if(S[i]=='b')PosB[id[i]=++n2]=i;
	}
	id[PosA[n+1]=PosB[n+1]=n*2+1]=n+1;
	for(int i=1,j=1;i<=n+1;i++)while(j<min(PosA[i],PosB[i])){nxt[j]=i;j++;}
	for(int i=n;i>=1;i--){
		if(PosA[i]<PosB[i])F[i]="ab"+F[nxt[PosB[i]]];
		else{
			int j=PosB[i],k=PosA[i];
			while(j<=k&&(id[j]<=i||PosB[id[j]]<=k)){
				if(id[j]>=i){F[i]+=S[j];k=max(k,PosA[id[j]]);}
				j++;
			}
			F[i]+=F[id[j]];
		}
		F[i]=max(F[i],F[i+1]);
	}
	cout<<F[1]<<'\n';
	return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vpii> vvpii;
typedef long long ll;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define fi first
#define se second

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

    int n;
    cin >> n;
    vi v(n);

    for(auto &z : v)
        cin >> z;

    int ans = v[0];

    for(auto z : v)
        ans = __gcd(ans,z);
    cout << ans << '\n';
}


Measured memory_bytes: 3704
import java.util.Scanner;

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

	private void solveG() {
//		https://beta.atcoder.jp/contests/abc065/tasks/abc065_a
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		if(A>=B){
			System.out.println("delicious");
		}else if(X + A < B){
			System.out.println("dangerous");
		}else{
			System.out.println("safe");
		}
	}

	private void solveH() {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc);
	}

	private void solveA() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();

		int NA = N * A;

		if (NA > B) {
			System.out.println(B);
		} else {
			System.out.println(NA);
		}
	}

	private void solveB() {
		Scanner sc = new Scanner(System.in);

		String N = sc.nextLine();

		int iN = Integer.parseInt(N);

		String[] str = N.split("");

		int I = 0;
		for (int i = 0; i < str.length; i++) {
			int I2 = Integer.parseInt(str[i]);
			I += I2;
		}
		if (iN % I == 0) {
			System.out.println("Yes");
		} else if (iN % I != 0) {
			System.out.println("No");
		}

	}

	private void solveC() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int X = sc.nextInt();
		int Y = sc.nextInt();

		int NX = N * X;
		int NKY = (N - K) * Y;

		if (N <= K) {
			System.out.println(NX);
		} else {
			System.out.println(K * X + (N - K) * Y);
		}
	}

	private void solveD() {
		Scanner sc = new Scanner(System.in);

		String W = sc.nextLine();
		String[] str = W.split("");

		String word = "abcdefghijklmnopqrstuvwxyz";
		String[] w = word.split("");

		int math = 0;

		for (int i = 0; i < w.length; i++) {
			for (int j = 0; j < str.length; j++) {
				if (w[i].equals(str[j])) {
					math++;
				}
			}
			if (math % 2 != 0) {
				break;
			}
		}
		if (math % 2 == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

	private void solveE() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int min = 1000000;

		for (int i = 0; i < N; i++) {
			int a = sc.nextInt();
			int c = 0;
			while (a % 2 == 0) {
				a = a / 2;
				c++;
			}
			min = Math.min(min, c);
		}
		System.out.println(min);

	}

	private void solveF() {
//		https://beta.atcoder.jp/contests/abc081/tasks/abc081_a
		Scanner sc = new Scanner(System.in);
		char c[] = sc.nextLine().toCharArray();

		int num1 = Character.getNumericValue(c[0]);
		int num2 = Character.getNumericValue(c[1]);
		int num3 = Character.getNumericValue(c[2]);

		int num = num1 + num2 + num3;

		System.out.println(num);
	}


	private void solveI() {
		Scanner sc = new Scanner(System.in);
		System.out.println(sc);
	}

}

Measured memory_bytes: 21972
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
typedef long long ll;
int main() {
	int n, l;
	string a[100];
	cin >> n >> l;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	for (int i = 0; i < n; i++)
		cout << a[i];
	cout << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int N;
    cin>>N;
    string s;
    int cAC=0,cWA=0,cTLE=0,cRE=0;
    while(N--){
        cin>>s;
        if(s.compare("AC")==0){
            cAC++;
        }
        if(s.compare("WA")==0){
            cWA++;
        }
        if(s.compare("TLE")==0){
            cTLE++;
        }
        if(s.compare("RE")==0){
            cRE++;
        }
    }
    cout<<"AC x "<<cAC<<endl;
    cout<<"WA x "<<cWA<<endl;
    cout<<"TLE x "<<cTLE<<endl;
    cout<<"RE x "<<cRE<<endl;
}

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

using namespace std;

const int maxn = 200010;

typedef pair<int,int> pi;

int p[maxn], lef[maxn], rig[maxn], n, k;
pi tree[maxn<<2];
set<pi> st;

pi Merge(pi p1, pi p2) {
	return pi(min(p1.first, p2.first), max(p1.second, p2.second));
}

void build(int l, int r, int rt) {
	if (l == r) {
		tree[rt] = pi(p[l], p[l]);
		return;
	}
	int m = (l + r) >> 1;
	build(l, m, rt<<1);
	build(m+1, r, rt<<1|1);
	tree[rt] = Merge(tree[rt<<1], tree[rt<<1|1]);
}

pi query(int L, int R, int l, int r, int rt) {
	if (L <= l && r <= R) return tree[rt];
	pi ret(1e9, -1e9);
	if (L > R) return ret;
	int m = (l + r) >> 1;
	if (L <= m) ret = Merge(ret, query(L, R, l, m, rt<<1));
	if (R > m) ret = Merge(ret, query(L, R, m+1, r, rt<<1|1));
	return ret;
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) scanf("%d", &p[i]);
	build(1, n, 1);
	lef[1] = 1; rig[n] = 1;
	for (int i = 2; i <= n; i++) {
		if (p[i] > p[i-1]) lef[i] = lef[i-1] + 1;
		else lef[i] = 1;
	}
	for (int i = n-1; i >= 1; i--) {
		if (p[i] < p[i+1]) rig[i] = rig[i+1] + 1;
		else rig[i] = 1;
	}
	for (int s = 1; s+k-1 <= n; s++) {
		int l = s, r = s + k - 1;
		int vl = 0, vr = 0;
		{
			int L = 1, R = min(rig[l], k);
			while (L <= R) {
				int mid = (L + R) >> 1;
				if (query(l, l+mid-1, 1, n, 1).second < query(l+mid, r, 1, n, 1).first) {
					vl = mid;
					L = mid+1;
				} else R = mid-1;
			}
		}
		{
			int L = 1, R = min(lef[r], k);
			while (L <= R) {
				int mid = (L + R) >> 1;
				if (query(l, r-mid, 1, n, 1).second < query(r-mid+1, r, 1, n, 1).first) {
					vr = mid;
					L = mid+1;
				} else R = mid-1;
			}
		}
		if (vl == k) st.insert(pi(0, 0));
		else st.insert(pi(l+vl, r-vr));
	}
	printf("%d\n", int (st.size()));
	return 0;
}

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

int main() {
    int X, A;
    cin >> X >> A;

    if(X < A) {
        cout << 0;
    }
    else {
        cout << 10;
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        AFiftyFifty solver = new AFiftyFifty();
        solver.solve(1, in, out);
        out.close();
    }

    static class AFiftyFifty {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            char[] s = in.next().toCharArray();
            Arrays.sort(s);
            boolean answer = s[0] == s[1] && s[2] == s[3] && s[1] != s[2];

            out.println(answer ? "Yes" : "No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

    }
}



Measured memory_bytes: 21460
N = int(input())
testimony = [[-1]*N for i in range(N)]
count = 0
for i in range(N):
  A = int(input())
  for j in range(A):
    x,y = map(int,input().split())
    testimony[i][x-1]=y
for i in range(2**N):
  honest = [0]*N
  for j in range(N):
    if(i>>j)&1:
      honest[j]=1
  flag=True
  for j in range(N):
    if honest[j]==1:
      for k in range(N):
        if testimony[j][k]==-1:
          continue
        if testimony[j][k]!=honest[k]:
          flag=False
  if flag==True:
    count=max(count,honest.count(1))
print(count)

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

int main(){
    vector<int> h(10) ;
    for(int i=0;i<10;i++) cin >> h.at(i) ;
    sort(h.begin(),h.end()) ;
    reverse(h.begin(),h.end()) ;
    for(int i=0;i<3;i++){
        cout << h.at(i) << endl ;
    }
}


Measured memory_bytes: 3168
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	rdr   = bufio.NewReaderSize(os.Stdin, 1000000)
	reply string
)

func main() {
	in := nextSlice()
	solve(in)
}

func solve(buf []string) {
	reply = buf[1] + buf[0]
	fmt.Println(reply)
}

func readLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func nextSlice() []string {
	return strings.Split(readLine(), " ")
}

func atoi(a []string) (b []int) {
	b = make([]int, len(a))
	for i := range a {
		b[i], _ = strconv.Atoi(a[i])
	}
	return
}

func atof(a []string) (b []float64) {
	b = make([]float64, len(a))
	for i := range a {
		b[i], _ = strconv.ParseFloat(a[i], 64)
	}
	return
}

func scanSlice2(n int) (a []int, b []int) {
	a = make([]int, n)
	b = make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

func scanFloatSlice2(n int) (a []float64, b []float64) {
	a = make([]float64, n)
	b = make([]float64, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i], &b[i])
	}
	return
}

// ---------------------------------------------------

func abs(a int) int {
	if a > 0 {
		return a
	}
	return -a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func min(a ...int) int {
	min := a[0]
	for i := 1; i < len(a); i++ {
		if min > a[i] {
			min = a[i]
		}
	}
	return min
}

func max(a ...int) int {
	max := a[0]
	for i := 1; i < len(a); i++ {
		if max < a[i] {
			max = a[i]
		}
	}
	return max
}

func sum(a []int) (ans int) {
	for i := range a {
		ans += a[i]
	}
	return
}

// ---------------------------------------------------

func yesOrNo(b bool) {
	if b {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func yesorNO(b bool) {
	if b {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

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

string S; int cnt[26];

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); i++) cnt[S[i] - 'A']++;
	for (int i = 0; i < 26; i++) {
		if (cnt[i] != 0 && cnt[i] != 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(int argc, char const *argv[]) {
  int a=0,b=0,c=0;
  std::cin >> a >> b >> c;

  if(a < b && b < c){
    std::cout << "Yes" << std::endl;
  }else std::cout << "No" << std::endl;
  return 0;
}

Measured memory_bytes: 3088
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))


def solve():
    n = ini()
    a = inl()
    x = 0
    for y in a:
        x ^= y
    b = [x ^ y for i, y in enumerate(a)]
    return b


print(*solve())


Measured memory_bytes: 31500
using static System.Math;
using System;

public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var p = Array.ConvertAll(line, int.Parse);
        line = Console.ReadLine().Trim().Split(' ');
        var t = Array.ConvertAll(line, int.Parse);
        getAns(n, p, t);
    }
    static void getAns(int n, int[] p, int[] t)
    {
        var ans = int.MaxValue;
        var amax = (n + t[0] - 1) / t[0];
        var bmax = (n + t[1] - 1) / t[1];
        var cmax = (n + t[2] - 1) / t[2];
        for (int i = 0; i <= amax; i++)
            for (int j = 0; j <= bmax; j++)
                for (int k = 0; k <= cmax; k++)
                {
                    var w = i * t[0] + j * t[1] + k * t[2];
                    if (w < n)
                    {
                        var d = (n - w + t[3] - 1) / t[3];
                        ans = Min(ans, i * p[0] + j * p[1] + k * p[2] + d * p[3]);
                    }
                    else
                        ans = Min(ans, i * p[0] + j * p[1] + k * p[2]);
                }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 17936
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    int r; cin>>r;
    int ans;
    if(n>=10) ans = r;
    else ans = r+100*(10-n);
    print(ans);

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sp, t := []rune(getString()), []rune(getString())
	sAns := "UNRESTORABLE"

	idx := -1
	for i := 0; i < (len(sp) - len(t) + 1); i++ {
		ss := sp[i : i+len(t)]
		flag := true

		for j, s := range ss {
			if (s != '?') && (s != t[j]) {
				flag = false
				break
			}
		}

		if flag {
			idx = i
		}
	}

	if idx != -1 {
		sAns = ""
		for i := 0; i < len(sp); i++ {
			switch {
			case i == idx:
				sAns += string(t)
				i += len(t) - 1
			case sp[i] == '?':
				sAns += "a"
			default:
				sAns += string(sp[i])
			}
		}
	}

	fmt.Println(sAns)
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll f(ll x,ll res)
{
    ll ans=1;
    while(x)
    {
        if(x&1)ans=ans*res;
        res*=res;x/=2;
    }
    return ans;
}
int main()
{
   ll n,p;
   ll ans=1;
   cin>>n>>p;
   if(n==1){cout<<p;return 0;}
   if(p==1){cout<<"1";return 0;}
   if(n>=p){cout<<"1";return 0;}
   if(n>1000000){cout<<"1";return 0;}
   for(ll i=2;;i++)
   {
        ll k=f(n,i);
        if(p<k)break;
         if(p%k==0)ans=i;
   }
   printf("%lld\n",ans);
    return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<endl


int main(){
    int n;
    cin >> n;
    ll ans = 0;
    for(int i=1;i<n+1;i++){
        if(i%3==0)continue;
        else if(i%5==0)continue;
        else ans += i;
    }
    COUT(ans);
    return 0;
} 


Measured memory_bytes: 3624
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <cassert>
#include <string>
#include <cmath>
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
using namespace std;
typedef long long ll;
const int MAX = 0x7ffffff;
int t;

int _gcd(int a,int b)
{
	return b == 0 ? a : _gcd(b , a % b);
}
int gcd(int a,int b,int c)
{
	return _gcd(_gcd(a , b) , c);
}

void slove()
{
	int k = 0;
	cin >> k;
	ll sum = 0;
	for(int i = 1;i <= k;i ++)
	{
		for(int j = 1;j <= k;j ++)
		{
			for(int o = 1;o <= k ;o ++)
			{
				sum += gcd(i , j ,o);
			}
		}
	}
	cout << sum << endl;
}
int main()
{
	SIS;
	slove();
}

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

int gcd(int a, int b)
{
    if(b==0) return a;
    return gcd(b, a%b);
}

int main()
{
  long long a, b, gc, c;
  cin >> a >> b;
  gc = gcd(a, b);
  c = (a*b)/gc;
  cout << c << "\n";

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define LL long long
using namespace std;
const int maxn=(int)1e4+10;
struct Node{
    int dis,to,nxt;
}edg[maxn],fedg[maxn];
int head[maxn],num,fhead[maxn],fnum;
void add(int a,int b,int c){
    edg[++num].to=b;
    edg[num].dis=c;
    edg[num].nxt=head[a];
    head[a]=num;
    swap(a,b);
    fedg[++fnum].to=b;
    fedg[fnum].dis=c;
    fedg[fnum].nxt=fhead[a];
    fhead[a]=fnum;
}
int Q[20000200],inq[maxn],tim[maxn],n;
long long dis[maxn];
bool F[maxn];
void spfa(int root){
    int fr=0,en=0;
    Q[en++]=root;
    tim[root]=1;
    dis[root]=0;
    while(fr<en){
        int cur=Q[fr++];
        int t=head[cur];
        inq[cur]=0;
        while(t!=0){
            if(dis[cur]+edg[t].dis>dis[edg[t].to]&&F[edg[t].to]){
                dis[edg[t].to]=dis[cur]+edg[t].dis;
                if(!inq[edg[t].to]){
                    tim[edg[t].to]++;
                    if(tim[edg[t].to]>n){
                        cout<<-1;
                        exit(0);
                    }
                    inq[edg[t].to]=1;
                    Q[en++]=edg[t].to;
                }
            }
            t=edg[t].nxt;
        }
    }
}
void dfs(int root){
    F[root]=1;
    int t=fhead[root];
    while(t!=0) {
        if (!F[fedg[t].to]) dfs(fedg[t].to);
        t = fedg[t].nxt;
    }
}
int main(){
    ios::sync_with_stdio(false);
    int m,p; cin>>n>>m>>p;
    for(int i=1;i<=m;i++){
        int a,b,c; cin>>a>>b>>c;
        add(a,b,c-p);
    }
    for(int i=1;i<=n;i++) dis[i]=-1e18;
    dfs(n);
    if(F[1]==0) cout<<0;
    else {
        spfa(1);
        cout<<max(0ll,dis[n]);
    }
    return 0;
}


Measured memory_bytes: 26880
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		ArrayList<Integer> p = new ArrayList<>();

		for(int i=0;i<N;i++) {
			p.add(sc.nextInt());
		}

		//pの最大値
		int pmax = Collections.max(p);
		//pの中でのpmaxのインデックス
		int pind = p.indexOf(pmax);
		//pの中のpmaxを半額にする
		p.set(pind, pmax/2);

		int sum=0;
		for(int i=0;i<N;i++) {
			sum += p.get(i);
		}

		System.out.println(sum);
	}
}

Measured memory_bytes: 23124
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <cstdint>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <cstring>
#include <assert.h>

using namespace std;

const int MAXN = 5010;
pair<int, int> A[MAXN];
long long memo[MAXN][MAXN];

/* if we are at index i, having used
 * exactly j elements, what is
 * the minimum possible weight
 * we can stack
 */

const long long INF = (long long)(1e15);

long long get(int i, int j) {
  if (j > i) {
    return INF;
  }
  if (j == 0) {
    return 0;
  }
  long long& ref = memo[i][j];
  if (ref != -1) {
    return ref;
  }
  long long X = get(i - 1, j - 1); /* let us take i */
  long long Y = get(i - 1, j); /* let us not take i */
  if (A[i].first < X) {
    ref = Y;
  } else {
    ref = min((long long)A[i].second + X, Y);
  }
  return ref;
}
int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A[i].first;
    cin >> A[i].second;
  }
  sort(A + 1, A + N + 1, [&](pair<int, int> x, pair<int, int> y) {
    return x.first + x.second < y.first + y.second;
  });
  
  memset(memo, -1, sizeof(memo));
  int ans = 0;
  for (int take = 0; take <= N; take++) {
    long long weight = get(N, take);
    if (weight != INF) {
      ans = take;
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 196608
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        MCandies solver = new MCandies();
        solver.solve(1, in, out);
        out.close();
    }

    static class MCandies {
        private static final long mod = (long) (1e9 + 7);

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            int k = in.scanInt();
            long dp[] = new long[k + 5];

            dp[0] = 1;

            for (int i = 0; i < n; i++) {
                long x = in.scanInt();
                long aux[] = new long[k + 5];
                for (int used_ = k; used_ >= 0; --used_) {
                    long tmp = dp[used_];
                    int l = used_ + 1;
                    int r = (int) (used_ + Math.min(x, k - used_));
                    aux[l] += (aux[l] + tmp) % mod;
                    if (r + 1 <= k + 1) {
                        aux[(r + 1)] -= tmp;
                        while (aux[(r + 1)] < 0) aux[r + 1] += mod;
                    }
                }
                for (int j = 1; j <= k; j++) aux[j] = (aux[j] + aux[j - 1]) % mod;
                for (int j = 0; j <= k; j++) dp[j] = (dp[j] + aux[j]) % mod;
            }
            out.println(dp[k]);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 58636
n,k = map(int, input().split())
lr=[list(map(int,input().split())) for i in range(k)]
mod=998244353

imos=[0]*(n+10)
imos[0]=1

now=0
for i in range(n):
    now+=imos[i]
    for j in range(k):
        l,r=lr[j]
        if i+l>n:
            continue
        imos[i+l]+=now
        imos[i+l]%=mod
        if i+r>n:
            continue
        imos[i+r+1]-=now
        imos[i+r+1]%=mod

print(imos[n-1]%mod)

Measured memory_bytes: 70032
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> sp;
    rep(i, N) {
        string s;
        int p;
        cin >> s >> p;
        sp.emplace_back(mp(s, p), i + 1);
    }

    sort(all(sp), [](auto & a, auto & b) { return a.first.first == b.first.first ? a.first.second > b.first.second : a.first < b.first; });

    rep(i, N) {
        write(sp[i].second);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
ll N,M;
ll rank_[100005];
ll par[100005];
ll size_[100005];
void uf_init(ll n_){
for(ll i=0;i<n_;i++){
rank_[i]=0;
  par[i]=i;
  size_[i]=1;
}
}
ll find(ll x){
if(par[x]==x)
  return x;
  else{
  return par[x]=find(par[x]);
  }
}
void unite(ll x,ll y){
x=find(x);y=find(y);
  if(x==y)
    return;
  else if(rank_[x]<rank_[y]){
    par[x]=y;size_[y]+=size_[x];
  }else{
  par[y]=x;size_[x]+=size_[y];
    if(rank_[x]==rank_[y])rank_[x]++;
  }
}
bool same(ll x,ll y){
x=find(x);y=find(y);
  return x==y;
}
ll SIZE(ll x){
x=find(x);
  return size_[x];
}
int main(){
  cin>>N>>M;uf_init(N);
  vector<P>A(M);
  for(int i=0;i<M;i++){
  ll a,b;cin>>a>>b;a--;b--;
    P p(a,b);
    A[i]=p;
  }vector<ll>ans(M);
  ans[M-1]=(N*(N-1))/2;
  for(ll i=M-2;0<=i;i--){
  ll ans1=ans[i+1];
    ll a=A[i+1].first;
    ll b=A[i+1].second;
    if(!same(a,b)){
    ll x=SIZE(a);ll y=SIZE(b);
      ans1-=(x*y);unite(a,b);
    }ans[i]=ans1;
  }for(int i=0;i<M;i++)
    cout<<ans[i]<<endl;
  return 0;
}

Measured memory_bytes: 7948
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <set>
#include <math.h>
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
typedef long long ll;
using namespace std;

int main() {
    string n;
    cin >> n;
    if (n.back()=='2'||n.back()=='4'||n.back()=='5'||n.back()=='7'||n.back()=='9') {
        cout << "hon" << endl;
        return 0;
    }
    else if (n.back()=='0'||n.back()=='1'||n.back()=='6'||n.back()=='8'){
        cout << "pon" << endl;
        return 0;
    }
    else cout << "bon" << endl;
}

Measured memory_bytes: 3128