akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
    int A[100], N, v, j;
    cin >> N;
    
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    
    for(int i = 0; i < N; i++){
        v = A[i];
        j = i - 1;
        
        while(j >= 0 && A[j] > v){
            A[j + 1] = A[j];
            j--;
        }
        A[j + 1] = v;
        for(int i = 0; i < N - 1; i++){
            cout << A[i] << ' ';
        }
        cout << A[N - 1] << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
from collections import defaultdict

N, X, Y = map(int, input().split())
ctr = defaultdict(int)

for i in range(1, N + 1):
    for j in range(i + 1, N + 1):
        d = min(j - i, abs(i - X) + 1 + abs(j - Y))
        ctr[d] += 1

for i in range(1, N):
    print(ctr[i])



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

using namespace std;

int main(){
  int n;
  int data[1000]={};
  int a,b;
  int min;

  while(1)
    {
      cin >> n;
      if(n ==0)break;
      
      for(int i = 0;i<n;i++)
	{
	  cin >> data[i];
	}

      sort(data,data+n);

      min = data[1]-data[0];

      for(int j = n-1;j > 0;j--)
	{
	  a = data[j]-data[j-1];
	  if(a < min)
	    {
	      min = a;
	    }
	}
      cout << min << endl;
    }
}



Measured memory_bytes: 3144
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  string s, res="";
  cin >> s;
  
  for(int i = 0 ; i < s.size() ; i++){
    if(s[i] == '0' && s[i+1] == 'U'){
      res += "nn";
      i++;
      continue;
    } 
    if(s[i] == '2') res += 'k';
    if(s[i] == '3') res += 's';
    if(s[i] == '4') res += 't';
    if(s[i] == '5') res += 'n';
    if(s[i] == '6') res += 'h';
    if(s[i] == '7') res += 'm';
    if(s[i] == '8') res += 'y';
    if(s[i] == '9') res += 'r';
    if(s[i] == '0') res += 'w';
    
    if(s[i] == 'T') res += 'a';
    if(s[i] == 'L') res += 'i';
    if(s[i] == 'R') res += 'e';
    if(s[i] == 'U') res += 'u';
    if(s[i] == 'D') res += 'o';
  }
  cout << res << endl;
  return 0;
}

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

int main() {
	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int ans = 0;
	rep(i, n + 1) rep(j, n + 1) {
		if ((n - (r * i + g * j)) % b == 0) {
			int k = (n - (r * i + g * j)) / b;
			if (k >= 0) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
//#define int long long
#define str string
#define rep(i,j) for(int i=0;i<(int)(j);i++)
typedef long long ll;
typedef long double ld;
const ll inf = 4523372036854775807;
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//??£??\???????????¨???
	ll to, cost;
};
struct S {//???????????±?????\???????????°
	int from, to, cost;
};
struct H {
	int x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(ld a, ld b, ld c, ld d) {
	return sqrt(pow(a - c, 2) + pow(b - d, 2));
}//rad?????§?¨???????2??????????????¢
int ari(int a, int b, int c) {
	return (a + b)*c / 2;
}//????????°?????????
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, m, s, dp[3001][50];
signed main() {
	while (cin >> n >> m >> s&&n + m + s > 0) {
		n *= n;
		for (int i = 0; i <= s; i++)
			for (int j = 0; j <= n; j++)
				dp[i][j] = 0;
		dp[0][0] = 1;
		for (int i = 1; i <= m; i++) {
			for (int j = s; j >= 0; j--) {
				if (i + j > s) continue;
				for (int z = 0; z < n; z++) {
					dp[i+j][z + 1] += dp[j][z];
					dp[i + j][z + 1] %= 100000;
				}
			}
		}
		cout << dp[s][n] << endl;
	}
	getchar(); getchar();
}

Measured memory_bytes: 3572
s=input()
sr=s[::-1]
cntl=0
cntr=0
ll=[0]
rl=[0]

for i in range(len(s)):
    if s[i]=="<":
        cntl+=1
    else:
        cntl=0
    
    if sr[i]==">":
        cntr+=1
    else:
        cntr=0
    ll.append(cntl)
    rl.append(cntr)
    
rrl=rl[::-1]
ans=[]
for i in range(len(s)+1):
    ans.append(max(rrl[i],ll[i]))

print(sum(ans))

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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    REP(i, n){
        cin >> a.at(i) >> b.at(i);
    }
    ll ans = 0;
    for(ll i = n - 1; i >= 0; --i){
        if((a.at(i) + ans) % b.at(i) != 0){
            ans += b.at(i) - (a.at(i) + ans) % b.at(i);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

ll cul(ll x){
  return x * x * x * x * x;
}

int main(){
  ll x = in();

  rep(i,-120,120){
    rep(j,-120,120){
      if(cul(i)-cul(j)==x){
        cout << i << " " << j << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3768
#include<bits/stdc++.h>
#define pb push_back 
using namespace std;
const int N=305;
char s[N][N];
int col[N][N],ok[N];
int h,w,k,fi;
int main()
{ 
	scanf("%d%d%d",&h,&w,&k);
	fi=-1;
	for(int i=0;i<h;++i)
	{
		scanf("%s",s[i]);
		for(int j=0;j<w;++j)
		{
			if(s[i][j]=='#')
			{
				if(fi==-1)fi=i;
				ok[i]++;
			}
		}
	}
	int l,r,now=0,cnt=1;
	for(l=0;l<w;l++)
	{
		if(s[fi][l]=='.')col[fi][l]=cnt;
		else
		{
			if(!now)col[fi][l]=cnt;
			else col[fi][l]=++cnt;
			now++;
		}
	}
	for(int i=fi-1;i>=0;--i)
	{
		for(int j=0;j<w;++j)
		{
			col[i][j]=col[i+1][j];
		}
	}
	for(int i=fi+1;i<h;++i)
	{
		if(!ok[i])
		{
			for(int j=0;j<w;++j)
			col[i][j]=col[i-1][j];
		}
		else
		{
			++cnt;now=0;
			for(int j=0;j<w;++j)
			{
				if(s[i][j]=='.')col[i][j]=cnt;
				else
				{
					if(!now)col[i][j]=cnt;
					else col[i][j]=++cnt;
					now++;
				}
			}
		}
	}
	for(int i=0;i<h;++i)
	{
		for(int j=0;j<w;++j)
		{
			printf("%d%c",col[i][j]," \n"[j==w-1]);
		}
	} 
	return 0;
}

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

int main() {
  string S;
  string T;
  string U;
  int A;
  int B;
  int ans=0;
  cin >> S >> T;
  cin >> A >> B ;
  cin >> U;
  
  if(S==U){
  ans=A-1;
  cout << ans << ' ' << B << endl;
  }
  if(T==U){
  ans=B-1;
  cout << A << ' ' << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(void){
    ll L,R;
    cin>>L>>R;
    if(R-L>3000) cout<<0<<endl;
    else{
        ll res=2018;
        for(ll i=L;i<R;i++){
            for(ll j=i+1;j<=R;j++){
                res=min(res,(i*j)%2019);
            }
        }
        cout<<res<<endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define M(a,b)a>b?a:b
#define R(i,b)for(i=0;i<b;i++)
double C[100][100],P[100],Q[100],A;int n,m,i,j,k;int s(){R(i,n)P[i]=1;R(k,m-1){R(i,n){Q[i]=0;R(j,n)Q[i]=M(Q[i],P[j]*C[j][i]);}memcpy(P,Q,n*8);}A=0;R(i,n)A=M(A,P[i]);}main(){while(scanf("%d%d",&n,&m)&&n&&m){R(i,n)R(j,n)scanf("%lf",&C[i][j]);s();printf("%.2lf\n",A);}}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MOD=1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main() {
  IOS;
  ll n;
  cin>>n;
  ll dp[n+1][5][5][5];
  rep(i,n+1) rep(j,5) rep(k,5) rep(l,5) dp[i][j][k][l]=0;
  dp[0][0][0][0]=1;
  rep(_,n) rep(i,5) rep(j,5) rep(k,5) Rep(l,5){
    if(j==1 && k==3 && l==2) continue;
    if(j==1 && k==2 && l==3) continue;
    if(j==3 && k==1 && l==2) continue;
    if(i==1 && j==3 && l==2) continue;
    if(i==1 && k==3 && l==2) continue;
    //貰う方に注目、j,k,lで場合分けする
    dp[_+1][j][k][l]+=dp[_][i][j][k];
    dp[_+1][j][k][l]%=MOD;
  }
  ll ans=0;
  rep(i,5) rep(j,5) rep(k,5) ans+=dp[n][i][j][k],ans%=MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <chrono> //1e+9で割る auto end= chrono::system_clock::now()-st;  cout<<end.count()%1e+9<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef long double db;

#define fr first
#define sc second
#define pb push_back
#define rep(i,x) for(ll i=0;i<x;i++)
#define rep1(i,x) for(ll i=1;i<=x;i++)
#define rrep(i,x) for(ll i=x-1;i>=0;i--)
#define rrep1(i,x) for(ll i=x;i>0;i--)
string ans;
ll N;
string s[50];
ll kosu[50][26];
priority_queue<ll,vector<ll>, greater<ll> > q;
int main()
{
	cin>>N;
	rep(i,N){
		cin>>s[i];
		rep(j,s[i].size()){
			kosu[i][s[i][j]-'a']++;
		}
	}
	rep(i,26){
		ll x=0xfffffffff;
		rep(j,N){
			x=min(kosu[j][i],x);
		}
		rep(j,x){
			printf("%c",'a'+i);
		}
	}
	cout<<endl;
}

Measured memory_bytes: 256
import Control.Applicative

main = do
    [a,b,c] <- map (read :: String -> Int) . words <$> getLine
    print $ length $ findDivisors a b c

findDivisors :: Int -> Int -> Int -> [Int]
findDivisors a b c = [n | n <- [a..b], c `mod` n == 0]


Measured memory_bytes: 4128
#include <iostream>
#include <map>
#include <set>
#include <utility>
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
    ll n, b, r; cin >> n >> b >> r;
    if(b == 0) cout << 0 << endl;
    else{
        ll t = b+r;
        ll ans = 0;
        ans = n/t * b;
        ll rem = n%t;
        ans += min(rem,b);
        cout << ans << endl;
    }
	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    ld w,h;cin>>w>>h;
    ld x,y;cin>>x>>y;
    cout<<h*w/2<<endl;
    int ans = (h/2==y && w/2==x)?1:0;
    cout<<ans<<endl;
}

Measured memory_bytes: 3784
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const n = input[0];

let top = -1;
for (let i = 0; i < n.length; i++) {
	if (n[i] !== "9") {
		top = Math.max(i-1, 0);
		break;
	}
}

let result = 0;
for(let i=0; i<n.length; i++){
	if(i<top) result += +n[i];
	else if(i===top) result += +n[i]-1;
	else result += 9;
}

let tmp = 0;
for(let i=0; i<n.length; i++){
	tmp += +n[i];
}

result = Math.max(result, tmp);
console.log(result);


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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll ai, ao, at, aj, al, as, az;
  cin >> ai >> ao >> at >> aj >> al >> as >> az;
  ll t = 0;
  t += (ai / 2) * 2;
  t += ao;
  t += (aj / 2) * 2;
  t += (al / 2) * 2;
  ll bi = ai % 2;
  ll bj = aj % 2;
  ll bl = al % 2;
  if (bi + bj + bl == 3) {
    t += 3;
  }else if ((bi == 1 && bj == 1 && al >= 2) ||
            (bj == 1 && bl == 1 && ai >= 2) ||
            (bl == 1 && bi == 1 && aj >= 2)) {
    t += 1;
  }


  cout << t << endl;

  return 0;
}


Measured memory_bytes: 256
//quming
#include<bits/stdc++.h>
#define R register
#define fi first
#define se second
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef pair<int,int> pi;
const int N=305,inf=0x3f3f3f3f;
struct eg{int v,nx,w;}e[N*N];int head[N],tot;
inline void add(R int u,R int v,R int w){e[++tot]={v,head[u],w},head[u]=tot;}
struct node{
	int u;pi d;
	inline node(R int uu,R pi dd):u(uu),d(dd){}
	inline bool operator <(const node &b)const{return d>b.d;}
};priority_queue<node>q;
pi dis[N][N];int vis[N],n,m,L,Q;
inline pi operator +(const pi &a,const int &b){
	return a.se+b>L?pi(a.fi+1,b):pi(a.fi,a.se+b);
}
void find(R int s){
	memset(dis[s],0x3f,sizeof(dis[s]));
	memset(vis,0,sizeof(vis));
	R int u;dis[s][s]=pi(0,0),q.push(node(s,pi(0,0)));
	while(!q.empty()){
		u=q.top().u,q.pop();if(vis[u])continue;
		vis[u]=1;
		go(u)if(e[i].w<=L&&cmin(dis[s][v],dis[s][u]+e[i].w))
			q.push(node(v,dis[s][v]));
	}
	fp(i,1,n)if(dis[s][i]==pi(inf,inf))dis[s][i]=pi(-1,-1);
}
int main(){
//	freopen("testdata.in","r",stdin);
	scanf("%d%d%d",&n,&m,&L);
	for(R int i=1,u,v,w;i<=m;++i){
		scanf("%d%d%d",&u,&v,&w);
		add(u,v,w),add(v,u,w);
	}
	fp(i,1,n)find(i);
	scanf("%d",&Q);
	for(R int i=1,s,t;i<=Q;++i){
		scanf("%d%d",&s,&t);
		printf("%d\n",dis[s][t].fi);
	}
	return 0;
}

Measured memory_bytes: 2176
k = int(input())
s = list(map(int, input().split()))
a = s[0]
b = s[1]

flg = 0

for i in range(a, b+1):
    if i % k == 0:
        flg = 1

if flg == 1:
    print("OK")
else:
    print("NG")

Measured memory_bytes: 9128
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
const char bn = '\n';
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

vector<tuple<int,int,int,int>> query;
int N,M;
int f(vector<int>& A){
    int res = 0;
    for(auto e:query){
        int a,b,c,d; tie(a,b,c,d) = e;
        if(A[b]-A[a]==c) res += d;
    }

    return res;
}
int dfs(int now, int before, vector<int>& A){
    if(N==now){
        return f(A);
    }
    int res = 0;
    for(int x=before; x<=M;x++){
        A[now] = x;
        int tmp = dfs(now+1,x,A);
        chmax(res, tmp);
    }
    return res;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int Q;
    cin >> N >> M >> Q;
    REP(i,Q){
        int a,b,c,d;
        cin >> a >> b >> c >> d;
        query.emplace_back(--a,--b,c,d);
    }
    vector<int> A(N,-1);
    int ans=dfs(0,1,A);


    cout << ans << endl;
}

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

int main() {

  int N;
  cin >> N;

  priority_queue<ll, vector<ll>, greater<ll>> a;
  priority_queue<ll> b;
  vector<ll> c(3 * N, 0);
  ll a_sum = 0, b_sum = 0;

  rep(i, 3 * N) {
    int _c;
    cin >> _c;
    c[i] = _c;
    if (i < N) {
      a.push(_c);
      a_sum += _c;
    } else if (i >= 2 * N) {
      b.push(_c);
      b_sum += _c;
    }
  }

  vector<ll> a_sum_k(N + 1, 0);
  a_sum_k[0] = a_sum;
  for (int k = 1; k <= N; k++) {
    ll _c = c[k + N - 1];
    a.push(_c);
    a_sum += _c;
    ll _a = a.top();
    a_sum -= _a;
    a.pop();
    a_sum_k[k] = a_sum;
  }

  vector<ll> b_sum_k(N + 1, 0);
  b_sum_k[N] = b_sum;
  for (int k = N - 1; k >= 0; k--) {
    ll _c = c[N + k];
    b.push(_c);
    b_sum += _c;
    ll _b = b.top();
    b_sum -= _b;
    b.pop();
    b_sum_k[k] = b_sum;
  }

  ll sum = LLONG_MIN;
  rep(k, N + 1) { sum = max(sum, a_sum_k[k] - b_sum_k[k]); }

  cout << sum << endl;
}

Measured memory_bytes: 5876
N = int(input())
foods = []
for i in range(N):
    food = list(map(int,input().split()))
    foods.append(food)
foods.sort(key=lambda x: -(x[0]+x[1]))
#print(foods)
ans = 0
for i in range(N):
    if i%2 == 0:
        ans += foods[i][0]
    else:
        ans -= foods[i][1]
print(ans)

Measured memory_bytes: 32296
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
const int P=998244353,maxn=1e6+10;
int fac[maxn],ifac[maxn],n,m,ans;
int ksm(int a,int b){
    int ans=1;
    for(;b;b>>=1,a=1ll*a*a%P) if(b&1) ans=1ll*ans*a%P;
    return ans;
}
void init(int n){
    fac[0]=1;
    rep(i,1,n) fac[i]=1ll*fac[i-1]*i%P;
    ifac[n]=ksm(fac[n],P-2);
    per(i,n-1,0) ifac[i]=1ll*ifac[i+1]*(i+1)%P;
}
int C(int n,int k){
    if(n<k||k<0) return 0;
    return 1ll*fac[n]*ifac[k]%P*ifac[n-k]%P;
}
int iC(int n,int k){
    if(n<k||k<0) return 0;
    return 1ll*ifac[n]*fac[k]%P*fac[n-k]%P;
}
int main(){
    scanf("%d%d",&n,&m);init(n+m);
    if(n<m) swap(n,m);
    rep(i,1,m) ans=(ans+1ll*C(i*2,i)*C(n+m-i*2,n-i)%P)%P;
    ans=1ll*ans*ifac[2]%P*iC(n+m,n)%P;
    printf("%d\n",(ans+n)%P);
    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define whlie while
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repr(i,N) for(int i = (N) - 1; i >= 0; i--)
#define rep1(i,N) for(int i = 1; i <= (N) ; i++)
#define repr1(i,N) for(int i = (N) ; i > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; using vl = vector<ll>;
using vi = vector<int>; using vvi = vector< vector<int> >;
constexpr int inf = 1001001001;
constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(10);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);cout << endl;} while(0)
#else
  #define trc(...)
  #define trca(...)
  int main(){solve();}
#endif
using P = pair<int,int>; using vp = vector<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
////////////////

void solve(){
  ini(N); ins(S);
  int left = 0 , right = 0;
  for(int i = 0 , l = 0 , r = 0 ; i < N ; i++){
    (S[i] == '(' ? l : r) += 1;
    trc(left , l , r);
    amax(left , r - l);
  }
  for(int i = N - 1 , l = 0 , r = 0 ; i >= 0 ; i--){
    (S[i] == '(' ? l : r) += 1;
    amax(right , l - r);
  }

  int nya = 0 , nyaa = 0;
  rep(i,N) (S[i]=='('?nya:nyaa) += 1;
  trc(left , right , nya , nyaa);
  // 左に最低left個の'('、右に最低right個の')'が必要
  // 一方'('はnya個 ')'はnyaa個
  if(nya + left > nyaa + right) right += nya + left - (nyaa + right);
  else left += (nyaa + right) - (nya + left);

  rep(_,left) S.insert(begin(S) , '(');
  rep(_,right) S.pb(')');
  out(S);
}

Measured memory_bytes: 256
N, M = map(int, input().split())

S = [[0]*2 for i in range(N)]
for i in range(N):
    S[i] = list(map(int, input().split()))
     
S = sorted(S)

quantitys = 0
total = 0

for i in range(N):
    # この店を買い尽くしてもまだ足りなければ、全部買う
    if((M - quantitys) - S[i][1])>=0:
        quantitys += S[i][1]
        total += S[i][0] * S[i][1]
    else:
        quantity = M - quantitys
        quantitys += quantity
        total += S[i][0] * quantity
    if M-quantitys == 0:
        break

print(str(total))

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

int main(){
	string s;
	cin >> s;
	int length = s.size();
	int i;
	long long int sum=0;
	for(i=0;i<length;i++){
		sum = sum + (s[i] - '0');
	}
	if((sum %9)==0){
		cout << "Yes" << endl;
		return 0;
	}
	else{
		cout << "No" << endl;
		return 0;
	}
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a,b;
	int count=0;
	cin >> a;
	while(1){
		cin >> b;
		if(b=="END_OF_TEXT"){
			break;
		}
		for(int i=0;i<b[i]!='\0';i++){
			if(isupper(b[i])!=0){
				b[i]=tolower(b[i]);
			}
		}
		if(b==a){
			count++;
		}
	}
	cout << count << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int>x(n,0),a(n);
  for(int i=1; i<n; i++){
   cin >> a[i]; 
   x[a[i]-1]++;
  }
  
  for(int i=0; i<n; i++){
   cout << x[i] << endl; 
  }
  
  
  
  
  
  
  
}

Measured memory_bytes: 4840
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] p = new int[N];
        for (int i = 0; i < p.length; ++i) {
            p[i] = sc.nextInt();
        }

        System.out.println(solve(p));

        sc.close();
    }

    static int solve(int[] p) {
        int result = 0;
        for (int i = 0; i < p.length; ++i) {
            if (p[i] == i + 1) {
                if (i != p.length - 1) {
                    swap(p, i, i + 1);
                } else {
                    swap(p, i, i - 1);
                }

                ++result;
            }
        }

        return result;
    }

    static void swap(int[] a, int index1, int index2) {
        int temp = a[index1];
        a[index1] = a[index2];
        a[index2] = temp;
    }
}

Measured memory_bytes: 49960
data class City(
    val index: Int,
    val p: Int,
    val y: Int
) {
    var order = -1

    val no: String
        get() = "${p.toString().padStart(6, '0')}${order.toString().padStart(6, '0')}"
}

fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val cities = Array<City>(m) {
        val (p, y) = readLine()!!.split(" ").map(String::toInt)
        City(it, p, y)
    }
    val partByP = mutableMapOf<Int, MutableList<City>>()
    cities.forEach {
        val c = partByP[it.p]
        if (c == null) {
            partByP[it.p] = mutableListOf(it)
        } else {
            c.add(it)
        }
    }
    partByP.forEach {
        it.value.sortBy { c -> c.y }
        it.value.forEachIndexed { i, c -> c.order = i + 1 }
    }
    cities.forEach { println(it.no) }
}


Measured memory_bytes: 80908
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
  	var my_string = input[0]
	console.log(my_string.substring(0, my_string.length - 1)
      + String.fromCharCode(my_string.charCodeAt(my_string.length - 1) + 1))
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
package main

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

func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	tmp, _ := reader.ReadString('\n')
	tmp = strings.Trim(tmp, "\n")
	tmp2 := strings.Split(tmp, " ")

	n, _ := strconv.Atoi(tmp2[0])
	l, _ := strconv.Atoi(tmp2[1])

	result1 := n*(1+n)/2 + (l-1)*n

	diff := Abs(l)
	pos := 1
	for i := 2; i < n+1; i++ {
		if Abs(l+i-1) < diff {
			diff = Abs(l + i - 1)
			pos = i
		}
	}

	fmt.Println(result1 - (l + pos - 1))

}


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

int main()
{
    std::string in;
    std::cin >> in;
    char eachIn;
    int maxLen = 0;
    int tmpLen = 0;
    for(int i = 0; i < in.size(); i++)
    {
        eachIn = in [i];
        if(eachIn == 'A' || eachIn == 'C' || eachIn == 'G' || eachIn == 'T')
        {
            tmpLen++;
        }
        else
        {
            tmpLen = 0;
        }
        if(tmpLen > maxLen)
        {
            maxLen = tmpLen;
        }
    }
    std::cout << maxLen << std::endl;
    
    return 0;
}

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

const int MAX = 55; // 頂点数と辺数の最大値
int N, M;
int a[MAX], b[MAX];
bool graph[MAX][MAX]; // グラフを表す隣接行列
bool visit[MAX]; // 頂点を訪れたか否か

void dfs(int n) {
  if (visit[n]) return;

  visit[n] = true;
  for (int i = 0; i < N; i++) {
    if (!graph[n][i]) continue;
    dfs(i);
  }
}

int main() {
  // 入力
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i];
    a[i]--; b[i]--;
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  // グラフからある一辺を除いて、深さ優先探索でそれが連結かどうかを確かめる
  int ans = 0;
  for (int i = 0; i < M; i++) {
    graph[a[i]][b[i]] = graph[b[i]][a[i]] = false;
    fill(visit, visit + N, false);

    dfs(0);
    for (int j = 0; j < N; j++) {
      if (!visit[j]) {
        ans++;
        break;
      }
    }

    graph[a[i]][b[i]] = graph[b[i]][a[i]] = true;
  }

  // 解答
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    int a,b;
    cin>>a>>b;
    int ans;
    for(int i=0;;i++){
        if((a-1)*i+1>=b){
            ans=i;
            break;
        }
    }
    out(ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
//#define MAX(a,b) a>b?a:b
#define MIN(a,b) a<b?a:b

int main() {
	int dp[10001] = {};
	int i,j;
	for (i = 1; i < 10001; i++) dp[i] = 1 << 20;
	int n,a;
	S(d, n);
	for (i = 1; i < n; i++) {
		S(d, a);
		for (j = 0; j <= i / 2; j++) {
			dp[j] = MIN(dp[j], dp[i - j] + a);
			dp[i - j] = MIN(dp[i - j], dp[j] + a);
		}
	}
	P(d, dp[n / 2]);
	return 0;
}

Measured memory_bytes: 648
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    cin >> x;
    ll ans = 0;
    for(int i = 1; i < n; i++) {
        ans += min(a * (x[i] - x[i - 1]), b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
<?php

$a = array();
fscanf(STDIN, "%d %d %d", $a[0], $a[1], $a[2]);
$max = 0;
$maxkey = 0;
$sum = 1;
foreach ($a as $key => $num) {
	if ($num % 2 == 0) {
		echo "0"."\n";
		exit;
	}
	if ($max < $num) {
		$max = $num;
		$maxkey = $key;
	}
}
foreach ($a as $key => $num) {
	if ($key != $maxkey) {
		$sum *= $num;
	}
}
echo $sum . "\n";


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

int main(){
	int n;
	cin>>n;
	vector<int> t(n+1);
	vector<int> x(n+1);
	vector<int> y(n+1);
	t.at(0)=0;
	x.at(0)=0;
	y.at(0)=0;
	REP(i,n){
		cin>>t.at(i+1)>>x.at(i+1)>>y.at(i+1);
	}
	
	REP(i,n){
		//遠すぎる場所には行けない
		if(abs(x.at(i+1)-x.at(i))+abs(y.at(i+1)-y.at(i))>t.at(i+1)-t.at(i)){
			cout<<"No\n";
			return 0;
		}
		//同じ場所に居続けられない
		if(x.at(i)==x.at(i+1)&&y.at(i)==y.at(i+1)){
			cout<<"No\n";
			return 0;
		}
		//偶奇が違うと行けない
		if(abs((x.at(i+1)-x.at(i))+abs(y.at(i+1)-y.at(i)))%2!=(t.at(i+1)-t.at(i))%2){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	
	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
using namespace std;
#define lli long long int

int main() {
lli n, sum = 0;
cin >> n;
for(lli i = 1; i <= n; i++) {
	if(i % 3 != 0 && i %5 != 0) {
    sum += i;
    }
}
  cout << sum << endl;
}


Measured memory_bytes: 3164
/*
この問題はABC_50_Aである
*/
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    String op = sc.next();
    int b = sc.nextInt();
    String plus = "+";
    String minus = "-";
    if(op.equals(plus)){
      System.out.println(a+b);
    }
    else if(op.equals(minus)){
      System.out.println(a-b);
    }
  }
}


Measured memory_bytes: 21844
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
#include <cstdarg>
#include <sstream>
#include <functional>
using namespace std;

int const MAX_N = 512 * 1024;

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	int n;
	string s[3];
	cin >> n;
	for (int i = 0; i < 3; i++) cin >> s[i];
	int ans = 0;
	for (int i = 0; i < (int) s[0].length(); i++) {
		if (s[0][i] != s[1][i] && s[1][i] != s[2][i] && s[0][i] != s[2][i]) ans += 2;
		else if (s[0][i] == s[1][i] && s[1][i] == s[2][i]) ans += 0;
		else ans++;
	}
	cout << ans;
	return 0;
}


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

using namespace std;
typedef long long ll;

int main(void) {
    ll N, Y;
    cin >> N >> Y;

    for(int i = 0; i <= Y / 10000 && i <= N; i++) {
        ll balance_x = Y - 10000 * i;

        for(int j = 0; j <= balance_x / 5000 &&  j <= N - i; j++) {
            ll balance_y = balance_x - 5000 * j;
            int z = balance_y / 1000;
            if(z == N - i - j) {
                cout << i << " " << j << " " << z << endl;
                return 0;
            }
        }
    }

    cout << "-1 -1 -1" << endl;
}

Measured memory_bytes: 256
//int -> ll
//http://web.mit.edu/~ecprice/acm/acm08/notebook.html#file12
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include<bits/stdc++.h>
typedef long long ll;
#define x first
#define y second
#define REP(i,sss,eee) for(int i=sss;i<=eee;++i)
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define speed ios_base::sync_with_stdio(0);cin.tie(0);
#define N 1000000007
using namespace __gnu_pbds;
using namespace std;
template <class T>
T MAX(T a, T b){return ((a>b)?a:b);}
template <class T>
T MIN(T a, T b){return ((a<b)?a:b);}
template <class T>
T MOD(T a){return ((a>=0)?a:(-1*a));}
template <class T>
void SWAP(T &a,T &b){T temp=a;a=b;b=temp;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
long long ex(long long a, long long b){
	if(b==0||a==1){return 1;}
	if(a==0||b==1){return a;}
	long long tmp=ex(a,(b/2));
	if(b%2){return ((((tmp*tmp)%N)*a)%N);}
	else{return ((tmp*tmp)%N);}
}
long long inv(long long k){
	if(k==1){return 1;}
	else{return ex(k,N-2);}
}
/*****************default********************/
std::vector<std::vector<int>> g;
std::vector<bool> vis;
std::vector<int> dp;
int dfs(int s)
{
	if(vis[s]){return dp[s];}
	vis[s]=1;
	int ans=1;
	for(auto it:g[s])
	{
		ans=MAX(ans,1+dfs(it));
	}
	dp[s]=ans;
	return dp[s];
}
int main(){
	int n,m;cin>>n>>m;
	g.resize(n);
	dp.resize(n,0);
	vis.resize(n,0);
	REP(i,0,m-1)
	{
		int a,b;cin>>a>>b;--a;--b;
		g[a].pb(b);
	}
	REP(i,0,n-1)
	{
		if(!vis[i]){dfs(i);}
	}
	int ans=0;
	for (int i = 0; i < n; ++i)
	{
		ans=MAX(dp[i],ans);
	}
	cout<<(ans-1)<<"\n";
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

//最大公約数
int gcd(int x, int y) { return y ? gcd(y, x%y) : x; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
//最大公約数 複数個
int gcd(const vector<int> &v) {
    int ret = v[0];
    for (int i = 1; i < v.size(); i++)
        ret = gcd(ret, v[i]);
    return ret;
}
//最小公倍数 複数個
int lcm(const vector<int> &v) {
    int ret = v[0];
    for (int i = 1; i < v.size(); i++)
        ret = lcm(ret, v[i]);
    return ret;
}

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

    Int(t);
    while (t--) {
        int2(a, b); int2(c, d);
        if (a < b) {
            cout << "No" << endl;
            continue;
        }
        if (d < b) {
            cout << "No" << endl;
            continue;
        }
        if (b <= c) {
            std::cout << "Yes" << std::endl;
            continue;
        }

        int g = gcd(b, d);
        if (b - g + a % g > c) {
            std::cout << "No" << std::endl;
        } else {
            std::cout << "Yes" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
# Problem C - When I hit my pocket...

import math

# input
K, A, B = map(int, input().split())

# initialization
koho_1 = 1 + K
koho_2 = 0
if B-A>2:
    koho_2 = A
    K -= A - 1
    if K%2==1:
        koho_2 += 1
        K -= 1
    koho_2 += (B - A) * (K // 2)

# calc
ans = max(koho_1, koho_2)

# output
print(ans)


Measured memory_bytes: 3060
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            ans += i;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    int64 tmp;
    vector<int64> H(N);
    for(int64 i=0;i<N;i++){
        cin>>H[i];
    }
    tmp=H[N-1];
    // for(int64 i=0;i<N-1;i++){
    //     if(H[i+1]-H[i]<=-2){
    //         cout<<"No"<<endl;
    //         return 0;
    //     }else if(H[i+1]-H[i]==-1){
    //         H[i]--;
    //     }
    // }
    // for(int64 i=0;i<N-1;i++){
    //     if(H[i+1]<H[i]){
    //         cout<<"No"<<endl;
    //         return 0;
    //     }
    // }
    // cout<<"Yes"<<endl;

    for(int64 i=N-1;i>=0;i--){
        if(H[i]>=tmp+2){
            cout<<"No"<<endl;
            return 0;
        }
        tmp=min(tmp,H[i]);
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define MAX 300111
#define mod 1000000007
const int inf = 1000000007;
using namespace std;
int a[MAX];
int main(){ 
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
    int n,c = 1,ans = 0;
    cin>>n;
    for(int i =0 ; i < n ;i++){
    	cin>>a[i];
    	if(i == 0)continue;
    	if(a[i] == a[i-1])c++;
    	else {
    		ans += c/2;
    		c = 1;
    	}
    }
    ans += c/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

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

int main() {
	LL N,K;
	cin >> N >> K;
	LL ret=0;
	for(LL b=K+1;b<=N;b++){
		LL p=N/b*(b-K);
		LL r=N%b;
		//cout << p << endl;
		if(r>=K){
			p+=r-max(K,1LL)+1;
		}
		ret+=p;
		//cout << b << ": " << p << endl;
	}
	cout << ret << endl;

	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
	int n;
	long long int a;
	int i;
	string s1,s2;
	cin >> n >> s1 >> s2;
	if(s1[0] == s2[0])
	{
		a = 3;
		i = 0;
	}
	else
	{
		a = 6;
		i = 1;
	}
	for(;i < n - 1;i++)
	{
		if(s1[i] == s2[i])
		{
			a*=2;
			if(s1[i + 1] != s2[i + 1])
			{
				i++;
			}
		}
		else
		{
			if(s1[i + 1] != s2[i + 1])
			{
				a*=3;
				i++;
			}
		}
	}
	cout << (a%1000000007) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    int a,b;
    cin >> a >> b;

    if(a+b<10) cout << a+b << endl;
    else cout << "error" << endl;

    return 0;
}


Measured memory_bytes: 3608
/**
 *    author:  math2do
 *    created: 05.04.2020 14:24:51
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int k;
  cin >> k;

  auto bfs = [&]() -> long long {
    queue <long long> q;
    for (int i = 1; i <= 9; i++) {
      q.push(i);
    } 
    
    int cnt = 0;
    long long ans = -1;
    while (!q.empty()) {
      int size = (int) q.size();
      while (size--) {
        long long u = q.front(); q.pop();
        cnt++;
        if (cnt == k) {
          ans = u;
          goto end;
        } 
        int d = int(u % 10);
        long long a = u * 10 + (d - 1);
        long long b = u * 10 + (d + 0);
        long long c = u * 10 + (d + 1);

        if (d == 0) {
          q.push(b);
          q.push(c);
        } else if (d == 9) {
          q.push(a);
          q.push(b);
        } else {
          q.push(a);
          q.push(b);
          q.push(c);
        } 
      }
    }

    end : {
      return ans;
    } 
  };

  long long ans = bfs();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int l = s.nextInt();
        int flag=-1;
        int sum=0;
        int j=l;
        for (int i=0;i<n;i++){
            if(j==0){
                flag=1;
            }
            sum+=j;
            j++;
        }
        if(flag==1){
            System.out.println(sum);
        }else{
            if(l<0){
                System.out.println(sum-(l+n-1));
            }else{
                System.out.println(sum-l);
            }
        }
    }
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
#define el '\n'
#define ull unsigned long long
#define ui unsigned int
#define ll long long
#define sf(n) scanf("%d",&n)
#define pf(n) printf("%d",n)
int main()
{
    int n;
    cin>>n;
    if(n<1200)
        cout<<"ABC"<<el;
    else if(n<2800)
        cout<<"ARC"<<el;
    else
        cout<<"AGC"<<el;
    
    
    return 0;
}


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

int main() {
    vector<int> a(3);
    cin >> a.at(0) >> a.at(1) >> a.at(2);
    
    sort(a.begin(), a.end());
    
    for (int i = 0; i < 3; i++) {
        cout << a.at(i);
        if (i != 2) {
            cout << " ";
        }
        else{
            cout << endl;
        }
    }
}


Measured memory_bytes: 3112
a = int(input())
b = int(input())
c = int(input())
d = int(input())

if (a >= b)and(c >= d):
    print(b + d)
elif(a >= b)and(c <= d):
    print(b + c)
elif(a <= b)and(c <= d):
    print(a + c)
else:
    print(a + d)

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

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N, L; cin >> N >> L;
  vector<string> S(N);
  for (ll i = 0; i < N; i++) cin >> S.at(i);
  sort(S.begin(), S.end());
  string ans;
  for (ll i = 0; i < N; i++) ans += S.at(i);
  cout << ans << endl;
       

  return 0;
}



Measured memory_bytes: 3664
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct RollingHash {
  static const ll base1 = 1007, base2 = 2009;
  static const ll mod1 = 1000000007, mod2 = 1000000009;
  vector<ll> hash1, hash2, power1, power2;

  // construct
  RollingHash(const string &S) {
    ll n = (ll)S.size();
    hash1.assign(n + 1, 0);
    hash2.assign(n + 1, 0);
    power1.assign(n + 1, 1);
    power2.assign(n + 1, 1);
    for (ll i = 0; i < n; ++i) {
      hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
      hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
      power1[i + 1] = (power1[i] * base1) % mod1;
      power2[i + 1] = (power2[i] * base2) % mod2;
    }
  }

  // get hash of S[left:right]
  inline pair<long long, long long> get(ll l, ll r) const {
    long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
    if (res1 < 0) res1 += mod1;
    long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
    if (res2 < 0) res2 += mod2;
    return {res1, res2};
  }

  // get lcp of S[a:] and T[b:]
  inline ll getLCP(ll a, ll b) const {
    ll len = min((ll)hash1.size() - a, (ll)hash1.size() - b);
    ll low = 0, high = len;
    while (high - low > 1) {
      ll mid = (low + high) >> 1;
      if (get(a, a + mid) != get(b, b + mid))
        high = mid;
      else
        low = mid;
    }
    return low;
  }
};

int main() {
  int N;
  string str;

  cin >> N >> str;

  RollingHash rh(str);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i+1; j < N; j++) {
      ll lcp = min(rh.getLCP(i, j), (ll)(j-i));
      ans = max(ans, lcp);
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 512