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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  string s;getline(cin,s);
  rep(i,0,s.size()){
    if(isupper(s[i])==0)cout<<(char)toupper(s[i]);
    else cout<<(char)tolower(s[i]);
  }
  cout<<endl;

  return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
const long long INF = 1LL << 60;
// const int INF=1010101010;
using Graph = vector<vector<int>>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> v;
  rep(i, n) {
    int a;
    cin >> a;
    v.push_back({a, 1});
  }
  rep(i, m) {
    int b, c;
    cin >> b >> c;
    v.push_back({c, b});
  }
  SORT(v);
  RSORT(v);

  ll res = 0;
  ll num = 0;

  for (auto p : v) {
    if (num + p.second <= n) {
      res += p.first * p.second;
      num += p.second;
    } else {
      res += p.first * (n - num);
      num = n;
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 6512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

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

	LL N,T;
	cin >> N >> T;
	LL ans = 0;
	LL last = LL_MIN;
	for(int i=0; i<N; i++){
		LL t;
		cin >> t;
		if(t-last >= T) ans += T;
		else ans += t - last;
		last = t;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int M, K;
    cin >> M >> K;
    int MM = 1 << M;
    if (K == 0) {
        for (int i = 0; i < MM; ++i) {
            printf("%d %d%c", i, i, i == MM-1 ? '\n' : ' ');
        }
        return 0;
    }
    if (MM > 3 && K < MM) {
        for (int i = 0; i < MM; ++i) {
            if (i != K) printf("%d ", i);
        }
        printf("%d ", K);
        for (int i = MM-1; i >= 0; --i) {
            if (i != K) printf("%d ", i);
        }
        printf("%d\n", K);
        return 0;
    }
    puts("-1");
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define inf 1000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define int long long
using namespace std;
int n,A[30][30],dp[23][(1<<22)];
inline int add(int a,int b){
	if(a+b>=md) return a+b-md;
	return a+b;
}
int dfs(int node,int msk){
	int cev=0;
	if(node==n+1){
		if(msk==(1<<n)-1) return 1;
		return 0;
	}
	if(~dp[node][msk]) return dp[node][msk];
	for(int i=1;i<=n;i++){
		int go=i-1;
		if(((msk&(1<<go))==0) && A[node][i]==1) cev=add(cev,dfs(node+1,msk|(1<<go)));
	}
	return dp[node][msk]=cev;
}
main(){
	memset(dp,-1,sizeof(dp));
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			scanf("%lld",&A[i][j]);
		}
	}
	int ty=dfs(1,0);
	printf("%lld\n",ty);
	return 0;
}




Measured memory_bytes: 753920
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e9)
using namespace std;
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;
typedef struct{
    ll to;
    ll cost;
} edge;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    ll a[30], b[30];
    cin >> N >> M;
    ll tree[10][10] = {};
    rep(i,0,M){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        tree[a[i]][b[i]] = 1;
        tree[b[i]][a[i]] = 1;
    }
    vector<ll> v(N);
    iota(v.begin(), v.end(), 0);
    ll ans = 0;
    do {
        if(v[0] == 0){
            bool is_ok = true;
            rep(i,0,N-1){
                if(tree[v[i]][v[i+1]] == 0){
                    is_ok = false;
                }
            }
            if(is_ok){
                ans++;
            }

        }
    }while(next_permutation(v.begin(), v.end()));
    print(ans);





}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define mod 1000000007
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl
#define trace2(x, y) cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z) cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define sa(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define inf 2e18
#define scan() int n; cin>>n ; int a[n]; for(int i = 0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define pii pair<int,int>
#define mkp make_pair
using namespace std;
#define N 2e5+5


int32_t main(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        int n,i;
        cin >> n;
        int a[n+1],b[n+1],c[n+1];
        for(i=1; i<=n; i++) cin >> a[i];
        for(i=1; i<=n; i++) cin >> b[i];
        for(i=1; i<n; i++) cin >> c[i];
        int ans=0;
        a[0]=-1;
        for(i=1; i<=n; i++){
            int x=a[i];
            ans=ans+b[x];
            if(i!=n)
            if(a[i+1]==a[i]+1){
                int y=a[i];
                ans=ans+c[y];
            }
        }
        cout << ans << '\n';
        

}

Measured memory_bytes: 256
# Graph I - Breadth First Search
from collections import deque
def bfs(A,d):
    dq = deque()
    dq.append(0)
    d[0] = 0
    while len(dq):
        v = dq.pop()
        for i in range(len(A[v])-1,-1,-1):
            f = A[v][i]
            if f == 1 and d[i] == -1:
                d[i] = d[v] + 1
                dq.appendleft(i)

n = int(input())
A = []
for _ in range(n):
    ss = list(map(int, input().split()))
    u = ss[0] - 1
    row = [0 for _ in range(n)]
    for i in range(ss[1]):
        idx = 2 + i
        row[ss[idx]-1] = 1
    A.append(row)

d = [-1 for _ in range(n)]
bfs(A,d)

for i,t in enumerate(d): print(i+1,t)


Measured memory_bytes: 8060
#include<bits/stdc++.h>
 
#define reps(i,f,n) for(int i = f; i < n; ++i)
#define rep(i,n) reps(i,0,n)
 typedef long long ll;
using namespace std;
 
int main(void){
    vector<ll> a;
    ll n;
    ll m = 10000000000000000LL;
    cin >> n;
    a.resize(5);

    rep(i,a.size()){
        cin >> a[i];
        if(a[i] < m) m = a[i];
    }

    ll ans = 0;
    ans = n/m;
    if(n%m == 0)ans--;
    ans += 5;
    cout << ans << endl;
    return 0;
}

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

string s;
int ans;

int main()
{
    cin >> s;
    int n = s.size();
    rep(i, n/2)
    {
        if (s[i] != s[n-1-i])
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
using namespace std;

int main(){
int n;cin>>n;
while(n){
    bool a=true;
    for(int i=2;i<=sqrt(n);i++)if(n%i==0)a=false;
    if(a){cout<<n;return 0;}
    n++;
}
}

Measured memory_bytes: 256
from collections import defaultdict

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

if D[0] != 0:
    print(0)
else:
    count = defaultdict(int)
    for d in D:
        count[d] += 1
    if count[0] != 1:
        print(0)
    else:
        maxcount = max(count)
        S = 1
        for i in range(1, maxcount+1):
            S *= count[i-1]**count[i]
        M = int(S % 998244353)
        print(M)

Measured memory_bytes: 19936
#include <stdio.h>

#define N_MAX 100

int bubbleSort(int A[], int N) {
  int cnt = 0, i, j, flag;

  flag = 1;
  i = 0;
  while (flag) {
    flag = 0;
    for (j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        cnt++;
        flag = 1;
      }
    }
    i++;
  }

  return cnt;
}

int main(void) {
  int N, i, cnt;
  int A[N_MAX];

  scanf("%d", &N);
  for (i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }

  cnt = bubbleSort(A, N);

  printf("%d", A[0]);
  for (i = 1; i < N; i++) {
    printf(" %d", A[i]);
  }
  printf("\n%d\n", cnt);

  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define pb(a) push_back(a)
#define eraser(v,i) (v).erase(v.begin()+(i))
#define pbpair(a,b) push_back(make_pair(a,b))
#define MOD 1000000007
#define INF 9223372036854775807
#define pairint pair<int,int>
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
signed main(){
  int x=0,y=0,z=0,w=0,n=0,m=0;
  string s;
  std::cin >> x>>y;
  std::vector<int> v(x);
  rep(i,x){
    std::cin >> v[i];
  }
  sort(all(v));
  rep(i,x-y){
    z+=v[i];
  }
  std::cout << z << '\n';
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;scanf("%d",&n);
	int xr=0;
	for(int i=1;i<=n;++i){
		int a,k;scanf("%d %d",&a,&k);
		if(k==1){xr^=a;continue;} 
		if(a<k)continue;
		a-=k-2;
		for(;;){
			if(a-2<k){xr^=(a&1)^1;break;}
			int T=2+(a-2)/k,D=(a-2)%k/T;
			a-=D*T;if((a-2)%k==0){xr^=(a-2)/k+1;break;}
			a-=T;
		}
	}
	printf(xr?"Takahashi":"Aoki");
}

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

using namespace std;

int main(){
  bool hoge = false;
  while(1)
    {
  int a,b;
  cin>>a>>b;
    if(a==0)break;
    if(hoge)puts("");
    hoge = true;
  vector<int> ans;

  for(int i=min(a,b);i<=max(a,b);i++){
    if(i%400 == 0 || (i%100!=0 && i%4==0)){
      ans.push_back(i);
    }
  }


  if(ans.size()!=0)
    {
      for(auto i:ans){
	cout<<i<<endl;
      }
    }
  else{
    puts("NA");
  }
    }
}

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

int main(void) {
    char ipt;
    cin >> ipt;
    if (ipt == 'A')
        cout << "T\n";
    else if (ipt == 'G')
        cout << "C\n";
    else if (ipt == 'C')
        cout << "G\n";
    else if (ipt == 'T')
        cout << "A\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in ma,mb;
in sc;
in sm;
in ts,tx,ty;
const in mdl=1000000007;
VI amax,amay,ambx,amby;
void sup(in x, in y, in s){
  if(amax[s]*x+amay[s]*y>ma)
    return;
  if(ambx[s]*x+amby[s]*y>mb)
    return;
  if(s==sc){
    sm+=(ma-x)/y+1;
    if(x<=mb){
      ++sm;
    }
    sm%=mdl;
    return;
  }
  sup(x+y,y,s);
  sup(x+y,x,s+1);
}
void slv(){
  if(mb>ma)
    swap(mb,ma);
  if(mb==1){
    cout<<1<<" "<<ma%mdl<<"\n";
    return;
  }
  if(mb==2 && ma==2){
    cout<<1<<" "<<4<<"\n";
    return;
  }
  in x=2;
  in y=1;
  sc=2;
  while(x+y<=ma && x<=mb){
    y+=x;
    swap(x,y);
    ++sc;
  }
  amax[sc]=1;
  amay[sc]=0;
  ambx[sc]=0;
  amby[sc]=1;
  for(in i=sc-1;i>=2;--i){
    amax[i]=amax[i+1]+amay[i+1];
    amay[i]=amax[i+1];
    ambx[i]=ambx[i+1]+amby[i+1];
    amby[i]=ambx[i+1];
  }
  cout<<sc-1<<" ";
  sm=0;
  sup(2,1,2);
  cout<<sm<<"\n";
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  amax=amay=ambx=amby=VI(200);
  in q;
  cin>>q;
  forn(z,q){
    cin>>ma>>mb;
    slv();
  }
  return 0;
}


Measured memory_bytes: 4096
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

frag, loop, lsum = set(), [], []
for i in range(n):
    if i in frag:
        continue
    now, tmpl, tmps = i, [], 0
    while (now not in frag):
        frag.add(now), tmpl.append(now)
        now = p[now] - 1
        tmps += c[now]
    else:
        loop.append(tmpl * 2)
        lsum.append(tmps)

lacc = []
for l in loop:
    tmp = [0]
    for li in l[1:]: 
        tmp.append(tmp[-1] + c[li])
    lacc.append(tmp)

ans = min(c)
for l, la, ls in zip(loop, lacc, lsum):
    llen = len(l) // 2
    for cnt in range(1, min(llen, k) + 1):
        for i in range(len(l) - cnt - 1):
            tmp = la[i + cnt] - la[i]
            tmp2 = ls * (k // llen - (cnt > k % llen))
            ans = max(ans, tmp, tmp + tmp2)
print(ans)


Measured memory_bytes: 69424
#include<stdio.h>
int main()
{
  int n, a, b;
  
  scanf("%d", &n);
  if(n == 1){
    printf("Hello World\n");
  }else{
    scanf("%d %d", &a, &b);
    printf("%d\n", a + b);
  }
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) begin(x)+(a), begin(x)+(n)
#define ADD(a, b) ((((a)%MOD+MOD)%MOD+((b)%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) ((((a)%MOD+MOD)%MOD-((b)%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) (((((a)%MOD+MOD)%MOD)*(((b)%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int X;


signed main(){
    cin >> X;

    cout << 1000*(X/500)+5*((X%500)/5) << endl;

    return 0;
}

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

int main(){
  int A, B;
  cin >> A >> B;
  int ans=0;
  for(int i=A; i<=B; i++){
    int a, b, c, d, e;
    a=i/10000;
    b=(i-a*10000)/1000;
    c=(i-a*10000-b*1000)/100;
    d=(i-a*10000-b*1000-c*100)/10;
    e=i%10;
    if(a==e && b==d) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000001

//aのb乗
int beki(int a,int b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}


//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int H,W,N;
	cin>>H>>W>>N;
	
	vector<pair<int,int>> V;
	V.emplace_back(1,1);
	V.emplace_back(H,W);
	
	for(int i=0;i<N;i++){
		int r,c;
		cin>>r>>c;
		V.emplace_back(r,c);
	}
	
	sort(V.begin(),V.end());
	
	vector<vector<int>> dp(V.size(),vector<int>(2,0));
	
	combi C(1000000);
	
	dp[0][0] = 1;
	
	for(int i=0;i<V.size();i++){
		for(int j=i+1;j<V.size();j++){
			int a = V[j].first-V[i].first;
			int b = V[j].second-V[i].second;
			if(a<0||b<0)continue;
			for(int k=0;k<2;k++){
				dp[j][k^1] = mod(dp[j][k^1] + mod(dp[i][k]*C.junretsu(a,b)));
			}
		}
	}
	cout<<mod(dp.back()[1]-dp.back()[0])<<endl;
	
    return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

const int n=1e6;
int nn;
int a[n];
void dfs(int cur, int count){
  if(count == nn+1){
    cout << -1 << endl;
  }
  else if(a[cur]!=1){    
    count++;
    dfs(a[cur],count);
  }
  else{
    cout << count << endl;
  }
}




int main(){
  cin >> nn;
  rep(i,nn){ cin >> a[i]; a[i]--;}
  dfs(0,1);
  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,mod,fac[3005],inv[3005];
int f[3005][3005];
inline int qpow(int a,int b,int mod)
{int res=1,tp=a;
while (b)
{if (b&1) res=1ll*res*tp%mod;
tp=1ll*tp*tp%mod;b>>=1;
}
return res;
}
int main (){
	int i,j,k,ans=0;
	fac[0]=inv[0]=1;
	scanf ("%d%d",&n,&mod);
	for (i=1;i<=n;i++)
	{fac[i]=1ll*fac[i-1]*i%mod;
	inv[i]=qpow(fac[i],mod-2,mod);
	}
	f[0][0]=1;
	for (i=1;i<=n;i++)
	{f[i][0]=1;
	for (j=1;j<=i;j++)
	{f[i][j]=1ll*f[i-1][j]*(j+1)%mod;
	f[i][j]=(f[i][j]+f[i-1][j-1]>=mod?f[i][j]+f[i-1][j-1]-mod:f[i][j]+f[i-1][j-1]);
	}
	}
	for (i=0;i<=n;i++)
	{int wys=qpow(2,n-i,mod),now=1,res=0;
	int rm=qpow(2,qpow(2,n-i,mod-1),mod);
	for (j=0;j<=i;j++)
	{res+=1ll*f[i][j]*now%mod;
	if (res>=mod) res-=mod;
	now=1ll*now*wys%mod;
	}
	res=1ll*res*rm%mod;
	res=1ll*res*fac[n]%mod;
	res=1ll*res*inv[i]%mod;
	res=1ll*res*inv[n-i]%mod;
	if (i&1) {ans-=res;}
	else {ans+=res;}
	if (ans<0) ans+=mod;
	if (ans>=mod) ans-=mod;
	}
	printf ("%d\n",ans);
	return 0;
}

Measured memory_bytes: 34176
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

#define rep(i, e) for(int i = 0; i < e; i++)
#define repp(i, s, e) for(int i = s; i < e; i++)
#define MAX_N 100
#define Card_Max 36
#define p(a) printf("%d\n", a);
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define NIL -1
typedef pair<ll, ll> P;

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

int main() {
    ll x1,y1,x2,y2;

    cin>>x1>>y1>>x2>>y2;
    cout << x2 - y2 + y1 << " " << y2 + x2 - x1 << " " << x1 - y2 + y1 << " " << y1 + x2 - x1 << endl; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_ll.hpp>
//typedef boost::multiprecision::cpp_ll ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
string alp="abcdefghijklmnopqrstuvwxyz";
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

bool comp(l_l i,l_l j){
    if(i.first<j.first){
        return true;
    }else if(i.first>j.first){
        return false;
    }else{
        return i.second>j.second;
    }
}

int main(){fastio
    ll n;cin>>n;
    ll A[n],B[n],C[n];
    vector<l_l> v;
    rep(i,0,n-1){
        cin>>A[i];
        v.pb(make_pair(A[i],0));
    }
    rep(i,0,n-1){
        cin>>B[i];
        v.pb(make_pair(B[i],1));
    }
    rep(i,0,n-1){
        cin>>C[i];
        v.pb(make_pair(C[i],2));
    }
    sort(v.begin(),v.end(),comp);
    ll ans[3];rep(i,0,2)ans[i]=0;
    rep(i,0,v.size()-1){
        if(v[i].second==0){
            ans[0]++;
        }else if(v[i].second==1){
            ans[1]+=ans[0];
        }else if(v[i].second==2){
            ans[2]+=ans[1];
        }
    }
    cout<<ans[2]<<endl;
    
    
    return 0;
}



Measured memory_bytes: 12652
#include<stdio.h>
int main(void)
{
	int n,m,i,x,cnt;
	scanf("%d %d",&n,&m);
	while(n!=0) {
	cnt=0;
		for(i=n;i<=m;i++) {
			x=i;
			while(x%5==0 || x%3==0 || x%2==0) {
				if(x%5==0) {
					x=x/5;
				}
				else if(x%3==0) {
					x=x/3;
				}
				else if(x%2==0) {
					x=x/2;
				}
			}
			if(x==1) {
				cnt++;
			}
		}
		printf("%d\n",cnt);
	scanf("%d %d",&n,&m);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#include<string>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
int main()
{
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
    string a,b;
   cin>>n>>m;
   m*=2;
   cout<<max((LL)0,n-m)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
signed main(){
  int a,b,c[10000000],d=0;
  cin>>a>>b;
  for(int i=0;i<b;i++) {
    cin>>c[i];
    d+=c[i];
  }
  sort(c,c+a);
  b-=d;
  cout<<a+(b/c[0])<<"\n";
}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int R = sc.nextInt();
        int G = sc.nextInt();

        System.out.println(solve(R, G));

        sc.close();
    }

    static int solve(int R, int G) {
        return 2 * G - R;
    }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll x,k,d;
  cin>>x>>k>>d;
  ll m=abs(x)%d;
  ll n=abs(x)/d;
  if(k<n)
  {
    cout<<abs(abs(x)-k*d)<<endl;
  }
  else if( (k-n)%2 ==0)
  {
    cout<<m<<endl;
  }
  else
  {
    cout<<abs(m-d)<<endl;
  }
}

Measured memory_bytes: 3632
N, Y = map(int, input().split())
x, y, z = -1, -1, -1

for a in range(N+1):
    for b in range(N+1-a):
        c = N-a-b
        if 10000*a + 5000*b + 1000*c == Y:
            x, y, z = a, b, c
            break

print(x, y, z)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = int(n) - 1; (i) >= 0; -- (i))
using namespace std;
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

string solve(int n, int k, vector<string> const & s) {
    auto required = vectors(n + 1, k + 1, false);
    required[n][k] = true;
    REP_R (i, n) {
        int len = s[i].length();
        REP (j, k + 1) if (required[i + 1][j]) {
            required[i][j] = true;
            if (j - len >= 0) {
                required[i][j - len] = true;
            }
        }
    }

    string t;
    vector<int> cur(k + 1, -1), prv;
    cur[0] = 0;
    REP (i, n) {
        int len = s[i].length();
        cur.swap(prv);
        cur.assign(k + 1, -1);

        int modified = INT_MAX;
        int clear = INT_MAX;
        REP_R (j, k + 1) if (required[i + 1][j]) {
            if (j - len >= 0 and prv[j - len] != -1) {
                int l = j - len, r = t.length();

                if (len <= r - l and t.compare(l, len, s[i]) == 0) {  // if s[i] is a prefix of t[l, r)
                    cur[j] = j;

                } else if (r - l < len and t.compare(l, r - l, s[i], 0, r - l) == 0) {  // if t[l, r) is a prefix of s[i]
                    t += s[i].substr(r - l);
                    cur[j] = j;

                } else if (s[i].compare(0, len, t, l, r - l) < 0) {  // if you should truly replace t[l, r) with s[i]
                    for (int j1 = j - len, j2 = 0; j1 < t.length() and j2 < len; ++ j1, ++ j2) {
                        if (t[j1] != s[i][j2]) {
                            modified = j1;
                            break;
                        }
                    }
                    clear = j;
                    cur[j] = j;
                    t.erase(t.begin() + j - len, t.end());
                    t += s[i];
                }

            }
            if (prv[j] != -1 and j <= modified) {
                cur[j] = j;
            }
        }

        // execute clearing
        REP (j, k + 1) {
            if (cur[j] > clear) {
                cur[j] = -1;
            }
        }
    }
    assert (t.length() == k);
    return t;
}

int main() {
    int n, k; cin >> n >> k;
    vector<string> s(n);
    REP (i, n) cin >> s[i];
    cout << solve(n, k, s) << endl;
    return 0;
}


Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int a[3005], n, tot;

int main() {
  scanf("%d", &n);
  for(int i = 1; i <= n; i++)
    scanf("%d", &a[i]), tot += a[i] - 1;
  printf("%d\n", tot);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std; 

//しゃくとり方でとく//
int main(void){
 int N,K;
 string S;
 vector<int> A;

 cin>>N>>K;
 cin>>S;

 int cnt=0;
 int now=0;

 for(int i=0; i<S.length();i++){
  if(S[i]==char('1'-now)){
   cnt++;
  }
  else{
   now=1-now;
   A.push_back(cnt);
   cnt=1;
  }
 }
 A.push_back(cnt);          
 
 if(A.size()%2==0)A.push_back(0);
 
 int sum,left,right,ans,nowleft,nowright;
 sum=0;
 left=0;
 right=0;
 nowleft=0;
 nowright=0;
 ans=0;

 while(nowright<A.size()){
  right=min(left+2*K+1,(int)A.size());

  while(nowleft<left){
   sum-=A[nowleft];
   nowleft++;
  }
  while(nowright<right){
   sum+=A[nowright];
   nowright++;
  }
  left+=2;
  ans=max(sum,ans);
 }

 cout<<ans<<endl; 
 return 0;
}

Measured memory_bytes: 1020
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define pb push_back
#define eb emplace_back
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;


ll n;
class neig {
    public:
    neig(){};
    template<class T>
    neig(T id){
        if(id == 0){pre = n-1; nex = 1;}
        else if(id == n-1){pre = n-2; nex = 0;}
        else{pre = id - 1; nex = id + 1;}
    }
    ll pre, nex;
};

ll ceil(ll a,ll b){
    return (a + b - 1) / b;
};

int main(){
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    priority_queue<Pll> pq;
    vector<ll> b(n);
    rep(i,n) {
        cin >> b[i];
        if(b[i] != a[i])pq.push({b[i], i});
    }
    bool ok = true;
    ll ans = 0;
    while(pq.size()){
        Pll temp = pq.top();pq.pop();
        neig tn = neig(temp.second);
        ll sum = b[tn.pre] + b[tn.nex];
        // debug(temp.first);debug(temp.second);
        // debug(sum);
        if(temp.first < sum){ok = false;break;}
        if(temp.first == a[temp.second])continue;
        if(temp.first > max(a[temp.second], sum)){
            ll t = temp.first % sum;
            if(t < a[temp.second] ){
                if((b[temp.second] - a[temp.second]) % sum != 0){
                    ok = false;
                    break;
                }
            }
            ans += (b[temp.second] - max(t, a[temp.second])) / sum;
            b[temp.second] = max(t, a[temp.second]);
        }
        if(b[temp.second] != a[temp.second])pq.push({b[temp.second], temp.second});
    }

    cout << (ok ? ans : -1) << endl;
}

Measured memory_bytes: 9584
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;


int main(){
  string s;
  cin >> s ;
  
  for (int i=0; i<s.size(); i++){
    for (int j=i+1; j<s.size(); j++){
      if (s[i] == s[j]){
        cout << "no";
        return 0;
      }
    }
  }
  cout << "yes";
}

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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./in/01-02.txt");
    ll n,k; cin >> n >> k;
    vi a(n);
    rep(i,n) cin >> a[i];

    vvl next(41, vl(n, -1));
    vl nexta(200010, -1);
    rrep(i,n) nexta[a[i]] = n+i;
    rrep(i,n){
        ll ne = nexta[a[i]];
        next[0][i] = ne-i + 1;
        nexta[a[i]] = i;
    }
    rep(i,40){
        rep(j,n){
            next[i+1][j] = next[i][j] + next[i][(j+next[i][j])%n];
        }
    }

    ll num = n*k;
    int now = 0;
    while(next[0][now] <= num){
        rrep(i,40){
            if(next[i][now] <= num){
                num -= next[i][now];
                now = (now + next[i][now]) % n;
                break;
            }
        }
    }

    vi used(200010, 0);
    vi ans;
    rep(i,num){
        int idx = (now+i) % n;
        if(used[a[idx]]){
            while(ans.back() != a[idx]){
                used[ans.back()] = 0;
                ans.pop_back();
            }
            ans.pop_back();
            used[a[idx]] = 0;
        }else{
            ans.push_back(a[idx]);
            used[a[idx]] = 1;
        }
    }
    if(ans.size()) cout << join(ans, " ") << endl;
    return 0;
}

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

using namespace std;

#define ll long long int

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> r(n+1), g(n+1), b(n+1);
	if(s[n-1] == 'R') {
		r[n] = 1;
		g[n] = 0;
		b[n] = 0;
	}
	if(s[n-1] == 'G') {
		r[n] = 0;
		g[n] = 1;
		b[n] = 0;
	}
	if(s[n-1] == 'B') {
		r[n] = 0;
		g[n] = 0;
		b[n] = 1;
	}	
	for(int i = n-1; i >= 1; i--) {
		r[i] = r[i+1] + ((s[i-1] == 'R') ? 1:0);
		g[i] = g[i+1] + ((s[i-1] == 'G') ? 1:0);
		b[i] = b[i+1] + ((s[i-1] == 'B') ? 1:0);
	}
//	for(int i = 1; i <= n; i++)  cerr << r[i] << ' ';
//	cerr << '\n';
//	for(int i = 1; i <= n; i++)  cerr << g[i] << ' ';
//	cerr << '\n';
//	for(int i = 1; i <= n; i++)  cerr << b[i] << ' ';
//	cerr << '\n';
	ll ans = 0;
	for(int i = 1; i <= n-2; i++) {
		for(int j = i + 1; j <= n-1; j++) {
			int k = 2*j - i;
			string c;
			c += s[i-1];
			c += s[j-1];
			sort(c.begin(), c.end());
//			cerr << c << ' ' << k << '\n';
			if(c == "BG") {
				if(k > j && k <= n) {
					if(s[k-1] == 'R') ans += r[j+1]-1;
					else ans += r[j+1];	
				}
				else if(k > j) ans += r[j+1];
			}	
			if(c == "GR") {
				if(k > j && k <= n) {
					if(s[k-1] == 'B') ans += b[j+1]-1;
					else ans += b[j+1];
				}
				else if(k > j) ans += b[j+1];
			}
			if(c == "BR") {
				if(k > j && k <= n) {
					if(s[k-1] == 'G') ans += g[j+1]-1;
					else ans += g[j+1];
				}
				else if(k > j) ans += g[j+1];
			}
		}
//		cerr << ans << '\n';
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <cstring>

using namespace std;

map<int, int> elem[52];
int size[52];

int conv(char c){
  if('a' <= c && c <= 'z') return c - 'a' + 26;
  if('A' <= c && c <= 'Z') return c - 'A';
  return -1;
}

int calc(string str){
  if(conv(str[0]) == -1) return atoi(str.c_str());
  int tmp = calc(str.substr(2, (int)str.size()-3));
  if(tmp == -1) return -1;
  int idx = conv(str[0]);
  if(elem[idx].find(tmp) == elem[idx].end()) return -1;
  return elem[idx][tmp];
}

bool solve(string str){
  for(int i=0;i<str.size();i++){
    if(str[i] == '='){
      string a = str.substr(0, i);
      string b = str.substr(i+1);
      int res = calc(b);
      if(res == -1) return false;
      int idx = calc(a.substr(2, (int)a.size()-3));
      if(idx == -1) return false;
      if(size[conv(a[0])] <= idx) return false;
      elem[conv(a[0])][idx] = res;
      return true;
    }
  }
  size[conv(str[0])] = atoi((str.substr(2, (int)str.size()-3)).c_str());
  return true;
}

void init(){
  for(int i=0;i<52;i++){
    elem[i].clear();
    size[i] = 0;
  }
}

main(){
  string in;
  while(1){
    bool first = true;
    bool bug = false;
    int line = 1;
    init();
    while(cin >> in){
      if(in == ".") break;
      if(bug) continue;
      first = false;
      if(!solve(in)){
        bug = true;
        continue;
      }
      line++;
    }
    if(first) break;
    if(bug) cout << line << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 0
//3つの整数a, b, c を読み取り、aとbの間のcの約数を出力する

#include <stdio.h>

int main(void)
{
  int a = 0,b = 0,c = 0;
  int i = 0;        //for文用
  int ans = 0;      //約数

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

  if(a < 1 || a > 10000 || 
       b < 1 || b > 10000 || 
       c < 1 || c > 10000 || 
       a > b)
    {
        //エラーメッセージを表示して終了する
        printf("Invalid Input\n");
        return 0;
    }

  //余りがゼロになる個数を調べる
  for(i=a; i <= b; i++)
    {
      if(c%i == 0){
          ans++;
      }
    }

  printf("%d\n",ans);

  return 0;
}


Measured memory_bytes: 2064
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct BiMatch{
  Int L,R;
  vector<vector<Int> > G;
  vector<Int> match,level;

  BiMatch(){}
  BiMatch(Int L,Int R):L(L),R(R),G(L+R),match(L+R,-1),level(L+R){}

  void add_edge(Int u,Int v){
    G[u].emplace_back(v+L);
    G[v+L].emplace_back(u);
  }

  bool bfs(){
    fill(level.begin(),level.end(),-1);
    queue<Int> q;
    for(Int i=0;i<L;i++){
      if(match[i]<0){
        level[i]=0;
        q.emplace(i);
      }
    }
    bool found=false;
    while(!q.empty()){
      Int v=q.front();q.pop();
      for(Int u:G[v]){
        if(~level[u]) continue;
        level[u]=level[v]+1;
        Int w=match[u];
        if(w==-1){
          found=true;
          continue;
        }
        if(~level[w]) continue;
        level[w]=level[u]+1;
        q.emplace(w);
      }
    }
    return found;
  }

  bool dfs(Int v){
    for(Int u:G[v]){
      if(level[v]+1!=level[u]) continue;
      level[u]=-1;
      Int w=match[u];
      if(w<0||dfs(w)){
        match[v]=u;
        match[u]=v;
        level[v]=-1;
        return true;
      }
    }
    level[v]=-1;
    return false;
  }

  Int build(){
    Int res=0;
    while(bfs())
      for(Int i=0;i<L;i++)
        if(match[i]<0&&dfs(i))
          res++;
    return res;
  }

};


template<typename V>
V compress(V v){
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  return v;
}
template<typename T>
map<T, Int> dict(const vector<T> &v){
  map<T, Int> res;
  for(Int i=0;i<(Int)v.size();i++)
    res[v[i]]=i;
  return res;
}
map<char, Int> dict(const string &v){
  return dict(vector<char>(v.begin(),v.end()));
}

//INSERT ABOVE HERE
const Int MAX = 101;
Int as[MAX][MAX];
Int bs[MAX][MAX];
Int cs[MAX][MAX];
signed main(){
  Int n,m;
  cin>>n>>m;
  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      cin>>as[i][j],as[i][j]--;

  for(Int i=0;i<n;i++)
    for(Int j=0;j<m;j++)
      bs[i][j]=as[i][j];

  for(Int j=0;j<m;j++){
    BiMatch G(n,n);
    for(Int i=0;i<n;i++){
      vector<Int> vs;
      for(Int k=j;k<m;k++) vs.emplace_back(bs[i][k]/m);
      vs=compress(vs);
      for(Int v:vs) G.add_edge(i,v);
    }
    Int mch=G.build();
    assert(mch==n);
    for(Int i=0;i<n;i++){
      Int v=G.match[i]-n;
      for(Int k=j;k<m;k++)
        if(bs[i][k]/m==v) swap(bs[i][j],bs[i][k]);
    }
  }

  for(Int j=0;j<m;j++){
    vector<Int> vs;
    for(Int i=0;i<n;i++)
      vs.emplace_back(bs[i][j]);
    sort(vs.begin(),vs.end());
    for(Int i=0;i<n;i++)
      cs[i][j]=vs[i];
  }

  // print ans
  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++){
      if(j) cout<<" ";
      cout<<bs[i][j]+1;
    }
    cout<<endl;
  }
  for(Int i=0;i<n;i++){
    for(Int j=0;j<m;j++){
      if(j) cout<<" ";
      cout<<cs[i][j]+1;
    }
    cout<<endl;
    vector<Int> vs;
    for(Int j=0;j<m;j++) vs.emplace_back(cs[i][j]);
    sort(vs.begin(),vs.end());
    for(Int j=0;j<m;j++) assert(vs[j]==i*m+j);
  }
  return 0;
}


Measured memory_bytes: 748
n,a,b,c,d = map(int,input().split())
s = input()
for i in range(a,max(c,d)):
    if s[i-1:i+1] == "##":
        print('No')
        exit()
if c < d:
    print('Yes')
    exit()
for i in range(b-1,d):
    if s[i-1:i+2] == "...":
        print("Yes")
        exit()
print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;

int main()
{
    int n;
    cin >> n;

    vector<int> sosu;
    for(int i = 2; i <= n; i++){
        int flag = 0;
        for(int j = 2; j < i; j++){
            if(i % j == 0){
                flag = 1;
                break;
            }
        }
        if(flag == 0) sosu.push_back(i);
    }

    int num[168] = {};
    for(int i = 2; i <= n; i++){
        for(int j = 0; j < sosu.size(); j++){
            int cnt = 0;
            if(i % sosu[j] == 0){
                int ii = i;
                while(ii % sosu[j] == 0){
                    ii /= sosu[j];
                    cnt++;
                }
            }
            num[j] += cnt;
        }
    }

    ll ans = 1;
    for(int i = 0; i < 168; i++){
        ans *= num[i] + 1;
        ans %= mod;
    } 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

N,C=[int(i) for i in input().split()]
stc=[list(map(int,input().split())) for i in range(N)] #N行分の入力を二重配列にする

sort_stc = sorted(stc)

#print(sort_stc)

counter = 0
rokuga_joutai = []
for bangumi in range(N):
    flag = -1
    for rokugaki in range(counter):
        if ((rokuga_joutai[rokugaki][2] == sort_stc[bangumi][2] and rokuga_joutai[rokugaki][1]-0.1 < sort_stc[bangumi][0]) or rokuga_joutai[rokugaki][1] + 0.5 < sort_stc[bangumi][0]):
            flag = rokugaki
    if flag != -1:
#        print(flag)
        rokuga_joutai[flag][0] = sort_stc[bangumi][0]
        rokuga_joutai[flag][1] = sort_stc[bangumi][1]
        rokuga_joutai[flag][2] = sort_stc[bangumi][2]
    else:
        rokuga_joutai.append([sort_stc[bangumi][0],sort_stc[bangumi][1],sort_stc[bangumi][2]])
        counter += 1
#    print(rokuga_joutai)
print(counter)
    

Measured memory_bytes: 30288
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  int x=0,N, out=0;
  string S;
  cin >> N >> S;
  for (int i=0; i < N; i++) {
    if (S[i] == 'I') x++;
    else x--;
    out = max(out ,x);
  }
  cout << out << endl;
  return 0;
}


Measured memory_bytes: 3552
import java.util.Scanner;

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

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		
		if(0 > x - r || x + r > W
		|| 0 > y - r || y + r > H) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

Measured memory_bytes: 26328
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	
	 a := make([]int, n+1)
	 b := make([]int, n)
	 
	 for i := range a {
	 	fmt.Scan(&a[i])
	 }
	 
	 for i := range b {
	 	fmt.Scan(&b[i])
	 }
	 
	 ans := 0
	 for i := 0; i < n; i++ {
	 	
	 	t := min(a[i], b[i])
	 	ans += t
	 	b[i] -= t
	 	
	 	t = min(a[i+1], b[i])
	 	a[i+1] -= t
	 	ans += t
	 }
	 fmt.Println(ans)
}

func min(a, b int)int {
	if a < b {
		return a
	}
	return b
}

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

using namespace std;

int main() {
	int rta,x, y;
	scanf("%d %d", &x, &y);
	rta = max(abs(x), abs(y)) - min(abs(x), abs(y));
	if(x == y) printf("0\n");
	else if(x >= 0 && y >= x) printf("%d\n", rta);
	else if(x >= 0 && y > 0) printf("%d\n", rta + 2);
	else if(x >= 0 && y <= 0) printf("%d\n", rta + 1);
	else if(x < 0 && y > x && y <= 0) printf("%d\n", rta);
	else if(x < 0 && y > x && y > 0) printf("%d\n", rta + 1);
	else if(x < 0 && y < x) printf("%d\n", rta + 2);

	return 0;
}


Measured memory_bytes: 256
n = int(input())
s = [int(input()) for _ in range(n)]
s.sort()
ans = sum(s)
x = [ans]
if ans % 10 == 0:
    i = 0
    while(True):
        for j in range(len(x)):
            x.append(x[j] - s[i])
        x = list(set(x))
        x.sort(reverse=True)
        flag = False
        for xi in x:
            if xi % 10 > 0:
                print(xi)
                flag = True
                break
        if flag:
            break
        elif i == n - 1:
            print(0)
            break
        else:
            i += 1
else:
    print(ans)


Measured memory_bytes: 3064
a=[]
n=int(input())
i=1
c=0
while i <= n:
    if c==0:
        x=i
        if x%3==0:
            a.append(i)
            i+=1
            continue
    c=0
    if x%10==3:
        a.append(i)
        i+=1
        continue
    x//=10
    if x == 0:
        i+=1
        continue
    else:
        c=1
print(' ', end='')
print(*a)

Measured memory_bytes: 8152
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
x = I()
ans = 2*(x//11)+1
x %= 11
if x == 0:
    ans -= 1
if x > 6:
    ans += 1
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39408
N=int(input())
A = list(map(int, input().split()))
A.sort()
sa = []
for i in range(N-1):
    diff = A[i+1]-A[i]
    if diff > 0:
        sa.append(diff)
sa.sort()

if len(sa)>=2:
    score = sa[1] - sa[0]
    if score <= 0:
        print(sa[0])
    else:
        dai = max(score, sa[0])
        sho = min(score, sa[0])
        while dai-sho > 0:
            dai, sho = sho, dai-sho
            if dai <= sho:
                dai, sho = sho, dai
        print(dai-sho if dai-sho > 0 else sho)
elif len(sa) == 1:
    dai = max(A[0], sa[0])
    sho = min(A[0], sa[0])
    while dai-sho > 0:
        dai, sho = sho, dai-sho
        if dai <= sho:
            dai, sho = sho, dai
    print(dai-sho if dai-sho > 0 else sho)
else:
    print(A[0])




Measured memory_bytes: 63512