akhauriyash/Code-Regression huggingface dataset:
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define endl '\n'
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(), (a).end()
#define bit(s,i) (((s)>>(i))&1LL)
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
const int MAXN    = 2e5+9;
/*-----------------------------------------------------------------------------------------------------*/

signed main() {
	EmiliaMyWife

	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a+3);
	if(a[0]==a[1] && a[1]!=a[2]) cout << "Yes";
	else if(a[0]!=a[1] && a[1]==a[2]) cout << "Yes";
	else cout << "No";
	
	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(c) (c).begin(),(c).end()
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}
void print() {}
template <class H, class... T>void print(H&& head, T&&... tail)
{cout << head << (sizeof...(tail)==0 ? "\n" : " "); print(forward<T>(tail)...);}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, ans = 0;
  cin >> n;
  vector<deque<int>> a(n,deque<int>());

  for(int i=0; i<n; i++){
    for(int j=0; j<n-1; j++){
      int t;
      cin >> t; t--;
      a[i].push_back(t);
    }
  }

  set<P> st;
  vector<int> target;
  for(int i=0; i<n; i++){
    target.push_back(i);
  }
  while(!target.empty()){
    vector<int> nxt;
    for(auto i : target){
      int t = a[i].front();
      a[i].pop_front();
      P nx = P(min(i,t), max(i,t));
      if(st.find(nx) == st.end()){
        st.insert(nx);
      }else{
        st.erase(nx);
        if(!a[i].empty()) nxt.push_back(i);
        if(!a[t].empty()) nxt.push_back(t);
      }
    }
    target = nxt;
    ans++;
  }
  for(int i=0; i<n; i++){
    if(!a[i].empty()){
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MAXC 10
#define MAXN
int H,W,N;
long long cont[MAXC+5],x,y;
map<int, map<int,int> >C;
int main()
{
    scanf("%d%d%d",&H,&W,&N);
    cont[0]=(long long)(H-2)*(W-2);
    for(int i=1;i<=N;i++)
    {
        scanf("%d%d",&x,&y);
        for(int k1=0;k1<=2;k1++)
            for(int k2=0;k2<=2;k2++)
            if(x+k1>=3&&y+k2>=3&&x+k1<=H&&y+k2<=W)
            {
                //printf("::%lld %lld\n",x+k1,y+k2);
                C[x+k1][y+k2]++;
                int A=C[x+k1][y+k2];
                cont[A-1]--;
                cont[A]++;
            }
    }
    for(int i=0;i<=9;i++)
        printf("%lld\n",cont[i]);
}


Measured memory_bytes: 70528
def main():
    n, m = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(n)]
    b = [int(input()) for _ in range(m)]
    for i in range(n):
        ans = 0
        for j in range(m):
            ans += a[i][j] * b[j]
        print(ans)


main()



Measured memory_bytes: 6004
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
using namespace std;
int main(){
    int n;
    cin>>n;
    long long int l;
    for(int i=1;i<100000000;i++){
        l=i*i;
        if(l>n){
            l=(i-1)*(i-1);
            cout<<l<<endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
N = gets.to_i
S = gets.chomp

if N % 2 == 1
  puts 'No'
else
  first = S[0, N / 2]
  second = S[N / 2, S.length]

  result = 'Yes'
  first.each_char.with_index do |char, i|
    if first[i] != second[i]
      result = 'No'
      break
    end
  end

  puts result
end

Measured memory_bytes: 1788
from collections import Counter

def prime(x):
    l = []
    while x%2 == 0:
        x //= 2
        l.append(2)
    f = 3
    while f**2 <= x:
        if x%f == 0:
            l.append(f)
            x //= f
        else:
            f += 2
    if x != 1:
        l.append(x)
    return l

n, p = map(int, input().split())
m = Counter(prime(p)).most_common()
ans = 1
for i in m:
    ans *= i[0]**(i[1]//n)
print(ans)

Measured memory_bytes: 9372
#include <stdio.h>
#include <string.h>

#define min(a, b) ((a) < (b) ? (a): (b))
#define max(a, b) ((a) > (b) ? (a): (b))

int n;
int down[1024][1024];
int right[1024][1024];

int side(int y, int x, int maxi)
{
    int d;
    int r;
    int s = min(down[y][x], right[y][x]);
    int i;

    for (i = 1; maxi < s && i < s; i++){
        int t = min(down[y][x + i], right[y + i][x]);
        s = min(s, t);
    }

    return max(maxi, s);
}

int main(void)
{
    while (scanf("%d", &n), n){
        char map[1024][1024];
        int maxi = 0;
        int i, j, k;

        for (i = 0; i < n; i++){
            scanf("%s", map[i]);
        }
        // for (i = 0; i < n; i++) puts(map[i]);

        for (i = 0; i < n; i++){
            int d = 0;
            int r = 0;

            for (j = n - 1; j >= 0; j--){
                d = map[j][i] == '.' ? d + 1 : 0;
                down[j][i] = d;
                r = map[i][j] == '.' ? r + 1 : 0;
                right[i][j] = r;
            }
        }
        // for (i = 0; i < n; i++){
        //     for (j = 0; j < n; j++) printf(" %2d", down[i][j]);
        //     puts("");
        // }
        // puts("");
        // for (i = 0; i < n; i++){
        //     for (j = 0; j < n; j++) printf(" %2d", right[i][j]);
        //     puts("");
        // }

        for (i = 0; i < n - maxi; i++){
            for (j = 0; j < n - maxi; j++){
                maxi = side(i, j, maxi);
            }
        }

        printf("%d\n", maxi);
    }

    return 0;
}

Measured memory_bytes: 9800
import sys
from itertools import accumulate as acc

def main():
    N, W = map(int, input().split())
    V = [[] for _ in '1234']

    w, v = map(int, input().split())
    w0 = w
    V[0].append(v)
    for e in sys.stdin:
        w, v = map(int, e.split())
        V[w - w0].append(v)

    for i in range(4):
        V[i] = [0] + list(acc(sorted(V[i], reverse=True)))

    ans = 0
    a, b, c, d = map(len, V)
    for i in range(a):
        wi = w0 * i
        if wi > W:
            break
        vi = V[0][i]
        for j in range(b):
            wj = wi + (w0 + 1) * j
            if wj > W:
                break
            vj = vi + V[1][j]
            for k in range(c):
                wk = wj + (w0 + 2) * k
                if wk > W:
                    break
                vk = vj + V[2][k]

                l = min((W - wk) // (w0 + 3), d - 1)
                v = vk + V[3][l]
                ans = max(ans, v)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var md = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var count = 0;

            for (var i = 1; i <= md[0]; i++)
            {
                for (var j = 10; j <= md[1]; j++)
                {
                    var one = j % 10;
                    var two = (j / 10) % 10;
                    if (one >= 2 && two >= 2 && one * two == i) count++;
                }
            }

            Console.WriteLine(count);
        }
    }
}


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

#define ff first
#define endl "\n"
#define ss second
using namespace std;
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fr(i,x,n) for(ll i=x;i>=n;i--)
inline ll min(ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a, ll b, ll c) { return max(max(a, b), c);}
inline void fastio(){ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);}

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



int main(){
	fastio();

	int n; cin>>n;
	int p[n+1]; f(i,1,n) cin>>p[i];

	int curr_min=INT_MAX;
	int ans=0;
	f(i,1,n){
		curr_min=min(curr_min,p[i]);
		if(curr_min>=p[i]) ans++;
	}

	cout<<ans;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
	int H, W, A, B;
	cin >> H >> W >> A >> B;
	rep(i, H){
      rep(j, W){
        bool h, w, anstmp;
        if(i < B)
          h=1;
        else
          h=0;
        if(j < A)
          w=1;
        else
          w=0;
        anstmp = h ^ w;
        if(anstmp)
          cout << '1';
        else
          cout << '0';
      }
      cout << endl;
    }
	return 0;
}


Measured memory_bytes: 1280
#include <cstdio>
#include <algorithm>
int n, lp[109], rp[109], l[109], r[109];
int gcd(int x, int y) {
	if (y == 0) return x;
	return gcd(y, x % y);
}
int solve(int pos) {
	if (pos == -1) return 1;
	int ls = solve(l[pos]) * lp[pos];
	int rs = solve(r[pos]) * rp[pos];
	int p = ls / gcd(ls, rs) * rs;
	return p / lp[pos] + p / rp[pos];
}
int main() {
	while (scanf("%d", &n), n) {
		for (int i = 0; i < n; i++) scanf("%d%d%d%d", &lp[i], &rp[i], &l[i], &r[i]), l[i]--, r[i]--;
		int ret = 0;
		for (int i = 0; i < n; i++) ret = std::max(ret, solve(i));
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 2620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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() {
    ll n, m;
    cin >> n >> m;
    vector< vector<ll> > a(n, vector<ll>(2));
    rep1(i, n) cin >> a[i][0] >> a[i][1];
    ll ans = 0, num = 0, add = 0;
    sort(a.begin(), a.end());
    rep1(i, n){
        ans += a[i][0] * min(a[i][1], m-num);
        num += min(a[i][1], m-num);
        if (num == m) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8808
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int W, a, b;
  cin >> W >> a >> b;
 
  if (a > b)
    swap(a, b);
 
  int ans = b - (a + W);
 
  if (ans > 0)
    cout << ans << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	string s;
	cin>>s;
	string t;
	for(int i=0;i<=3;i++)t[i]=s[i];
	t[4]=' ';
	for(int i=5;i<=12;i++)t[i]=s[i-1];
	rep(i,13)cout<<t[i];
  cout<<endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    if a[i] % 2 == 0:
        if a[i] % 3 == 0 or a[i] % 5 == 0:
            continue
        else:
            print('DENIED')
            exit(0)
print('APPROVED')

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

const int maxn = 100010;
vector<int> g[maxn];

int vis[maxn], col[maxn];

tuple<int,int,int> op[maxn];

void dfs(int v,int d,int c) {
	if(vis[v] >= d) return; vis[v] = d;
	if(col[v] == 0) col[v] = c;
	if(d) for(auto x: g[v]) dfs(x, d-1, c);
}

int main() {
	int n, m, q, u, v;
	scanf("%d%d", &n, &m);
	while(m--) {
		scanf("%d%d", &u, &v);
		g[u].push_back(v);
		g[v].push_back(u);
	}
	scanf("%d", &q);
	for(int i = 0; i < q; ++i) {
		int v, d, c; scanf("%d%d%d", &v, &d, &c);
		op[i] = tuple<int,int,int>(v, d, c);
	}
	memset(vis, -1, sizeof(vis));
	for(int i = q-1; i>=0; --i) {
		int v, d, c; 
		tie(v, d, c) = op[i];
		dfs(v, d, c);
	}
	for(int i = 1; i <= n; ++i) printf("%d\n", col[i]);
	return 0;
}


Measured memory_bytes: 8440
#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
  int n;
  int a[100];

  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=n-1;i>=0;i--){
    cout<<a[i];
    if(i)cout<<" ";
  }
  cout<<endl;
  return 0;

}


Measured memory_bytes: 3100
N, A, B = map(int, input().split())
S = input()
a, b = 0, 0
ans = []
for i in range(N):
    if S[i] == 'a':
        if a+b < A+B:
            a += 1
            ans.append("Yes")
        else:
            ans.append("No")
    elif S[i] == 'b':
        if a+b < A+B and b < B:
            b += 1
            ans.append("Yes")
        else:
            ans.append("No")
    else:
        ans.append("No")
for i in range(N):
    print(ans[i])


Measured memory_bytes: 4784
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,ans,a[N],b[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	n=read();
	for(int i=1;i<=n+1;i++)a[i]=read();
	for(int i=1;i<=n;i++)b[i]=read();
	int x=min(a[1],b[1]);
	ans+=x;
	a[1]-=x;b[1]-=x;
	for(int i=2;i<=n;i++)
	{
		int x=min(a[i],b[i-1]);
		ans+=x;
		a[i]-=x;b[i-1]-=x;
		x=min(a[i],b[i]);
		ans+=x;
		a[i]-=x;b[i]-=x;		
	}
	x=min(a[n+1],b[n]);
	ans+=x;
	a[n+1]-=x;b[n]-=x;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

char b, e;
string s;
int sum;

int main()
{
	cin >> s;
	sum = s.size() - 2;
	cout << s[0] << sum << s[sum + 1]; 
 	return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")
int table[365][26];
int main()
{
	int D;
	cin >> D;
	vec(C);
	vec(Las);
	fx(26) {
		vecp(C);
		Las.push_back(0);
	}

	fx(D) {
		fy(26) {
			cin >> table[x][y];
		}
	}

	vec(T);
	srand((time(NULL)));
	fx(D) {
		pb(T, rand() % 26 + 1);
	}
	ll sum = 0,preSum=0;
	vector<int> S(D,0);

	int preDay = 0;
	fx(5000) {
		int d;
		 
		 int dif = INT_MAX, ind = 0;
		 fw(D-1) {
			 if (S[w+1]-S[w]<dif) {
				 ind = w + 1;
				 dif = S[w + 1] - S[w];
			 }
		 }
		 d = ind;
		 if (d==preDay || sum==preSum) {
			 int d1 = rand() % D+1, d2 = d1;
			 while (d1==d2) {
				 d2 = rand() % D + 1;
			 }
			 T[d1 - 1] ^= T[d2 - 1];
			 T[d2 - 1] ^= T[d1 - 1];
			 T[d1 - 1] ^= T[d2 - 1];
		 }

		 for (int q = 1; q <= 26; q++) {
			 int pre = T[d - 1];
			 if (q == pre) { continue;}
			 T[d - 1] = q;
			 ll ans = 0;
			 vector<int> G(S);
			 fy(26) {
				 Las[y] = 0;
			 }
			 fw(D) {

				 ans += table[w][T[w] - 1];
				 Las[T[w] - 1] = w + 1;
				 fz(26) {
					 ans -= C[z] * (w + 1 - Las[z]);
				 }
				 S[w] = ans;
			 }
			 if (ans > sum) {
				 sum = ans;
				 S = G;
			 }
			 else {
				 T[d - 1] = pre;
			 }
		 }
	
	}

	fx(D) {
		ce(T[x])
	}
    return 0;
}



Measured memory_bytes: 3668
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>

using namespace std;

const int N_MAX = 200000;
vector<int> to[N_MAX];
vector<int> ans;

void solve(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    solve(u, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  for(int i = 0; i < n-1; i++) {
    int a,b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for(int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    ans[p-1] += x;
  }
  
  solve(0);
  
  for(int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 23552
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
ll n, m;
ll ans;

int main() {
	scanf("%lld%lld", &n, &m);
	if (n > m) swap(n, m);
	if (n == 1) printf("1\n");
	else {
		ans = ((n + 1) / 2) * ((m + 1) / 2) + (n / 2) * (m / 2);
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPP(i, n) for(int i = 1; i <= n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const ll MOD = 1000000007;

int main() {
    int n,x;cin >> n >> x;
    int d = 0;
    int ans = 1;
    REPP(i,n) {
        int l; cin >> l;
        d += l;
        ans += (d<=x);
    }
    cout << ans << endl;
    return 0;
}

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

void swap(int *x, int *y) {
	int tmp;
	tmp = *x;
	*x = *y;
	*y = tmp;
}

int gcd(int a, int b) {
	int c;
	
	if( a < b ) swap(&a, &b);
	
	while( b ) {
		c = a % b;
		a = b;
		b = c;
	}
	
	return a;
}

int main() {
	int n, x, y;
	int z;

	cin >> n >> x;

	cin >> y;
	z = abs(x - y);
	for( int i = 1; i < n; i++ ) {
		cin >> y;
		z = gcd( abs(y - x), z );
	}

	cout << z << endl;

	return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  APG4b
//
//  Created by 安藤光希 on 2020/03/21.
//  Copyright © 2020 安藤光希. All rights reserved.
//


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

int main() {
    ll N;
    cin >> N;
        
    if(N==0){
        cout << 2 << endl;
    } else if (N == 1){
        cout << 1 << endl;
    } else {
        vector<ll> S(N+1, 0);
        S[0] = 2;
        S[1] = 1;
        
        for(int i = 2; i < N + 1; i++){
            S[i] += S[i-1];
            S[i] += S[i-2];
        }
        cout << S[N] << endl;

    }
}


Measured memory_bytes: 256
/*Author: Tom Riddle*/


#include<bits/stdc++.h>
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define MODULO 1000000007
#define ull unsigned long long int
#define newline cout<<endl


/* TYPE DEFINITIONS */
typedef		long long		i64;
typedef		vector<int>		vi;
typedef		pair<int,int>	pi;



/* ALGEBRA */
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 

int f;
/* MACROS */

#define  all(A)			(A).begin() , (A).end()
#define  rall(A)		(A).rbegin() , (A).rend()
#define  sz(A)			(int)(A).size()
#define  pb				push_back
#define  ppb			pop_back
#define  mp				make_pair
#define  ln(X)			(int)(X).length()
#define  square(X)		((X)*(X))
#define  cube(X)		((X)*(X)*(X))
#define  forn(i, n)  for (int i = 0; i < int(n); i++)
#define  forr(i, n)  for (int i = int(n - 1); i >= 0; i--)
#define  fora(i, a, b)  for (int i = int(a); i <= int(b); i++)
#define  forb(i, a, b)  for (int i = int(a); i >= int(b); i--)
#define  fore(it, a)	for(__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++) 

ull lcm(ull a,ull b)
{
    ull x=__gcd(a,b);
    return (a*b)/x;
}
ull calc(ull x, ull y, ull z) {
  return x - (x/y + x/z - x/lcm(y, z));
}
void solve(){
    ull a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<calc(b,c,d)-calc(a-1,c,d);
    newline;
}
int main()
{
	FastIO;
	i64 t=1;
   // cin>>t;
	while(t--)solve();
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int r,c,n;
int main(){
	scanf("%d%d%d",&r,&c,&n);
	int maxx=max(r,c);
	int ans;
	if(n%maxx==0){
		ans=n/maxx;
	}
	else{
		ans=n/maxx+1;
	}
	printf("%d",ans);
	return 0; 
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while (true) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            Team[] teams = new Team[n];
            for (int i = 0; i < n; i++) {
                teams[i] = new Team(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
            }
            HashMap<Integer, Integer> teamCount = new HashMap<>();
            ArrayList<Team> winner = new ArrayList<>();
            Arrays.sort(teams);
            for (Team t : teams) {
                boolean flag = false;
                if (winner.size() < 10) {
                    flag = !teamCount.containsKey(t.group) || teamCount.get(t.group) < 3;
                } else if (winner.size() < 20) {
                    flag = !teamCount.containsKey(t.group) || teamCount.get(t.group) < 2;
                } else if (winner.size() < 26) {
                    flag = !teamCount.containsKey(t.group);
                }
                if (flag) {
                    winner.add(t);
                    if (teamCount.containsKey(t.group)) {
                        teamCount.put(t.group, teamCount.get(t.group) + 1);
                    } else {
                        teamCount.put(t.group, 1);
                    }
                }
            }
            for (Team t : winner) {
                sb.append(t.id).append("\n");
            }
        }
        System.out.print(sb);
    }
    
    static class Team implements Comparable<Team> {
        int id;
        int group;
        int ok;
        int pn;
        
        public Team(int id, int group, int ok, int pn) {
            this.id = id;
            this.group = group;
            this.ok = ok;
            this.pn = pn;
        }
        
        public int compareTo(Team another) {
            if (ok != another.ok) {
                return another.ok - ok;
            } else if (pn != another.pn) {
                return pn - another.pn;
            } else {
                return id - another.id;
            }
        }
        
    }
}


Measured memory_bytes: 29852
#include<iostream>
using namespace std;
int main()
{
    int n;cin >> n;
    long int arr[n],check[n] = {0};
    for(int i = 0;i < n;i++)cin >> arr[i];
    for(int i = 0;i < n - 1;i++)
    {
        if(arr[i] > arr[i + 1])
        {
            if(check[i] != 1)
            {
                arr[i]--;
                check[i] = 1;
                i = i - 2;
            }
            else{
                cout << "No" << endl;
                return 0;
            }
        }
        else if(arr[i] == arr[i+1])continue;
    }
    cout << "Yes" << endl;
    return 0;
 }


Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)
	log.SetFlags(log.Lshortfile)
	a := nextInt()
	s := nextString()
	if a >= 3200 {
		fmt.Println(s)
	} else {
		fmt.Println("red")
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 640
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long x = sc.nextLong();
    long y = sc.nextLong();
    long cnt1 = 1;
    long cnt2 = 1;
    long cnt3 = 2;
    if(x==-y){
      System.out.println(1);
      return;
    }
    if(x<y){
      if(x>=0||y<=0){
        System.out.println(y-x);
        return;
      }else if(-x>y){
        System.out.println(1-y-x);
        return;
      }else{
        System.out.println(1+y+x);
        return;
      }
    }
    if(y>=0){
      cnt1+=(long)Math.pow(10,15);
      cnt2+=y+x;
      cnt3+=x-y;
    }
    else if(x<=0){
      cnt1+=-x-y;
      cnt2+=(long)Math.pow(10,15);
      cnt3+=x-y;
    }
    else if(-y<x){
      cnt1+=(long)Math.pow(10,15);
      cnt2+=y+x;
      cnt3+=x-y;
    }
    else{
      cnt1+=-y-x;
      cnt2+=(long)Math.pow(10,15);
      cnt3+=x-y;
    }
    System.out.println(Math.min(cnt1,Math.min(cnt2,cnt3)));
  }
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans=0;
void rec(ll rest,ll total,string temp){
    if(rest==0){
        if(temp=="")ans+=total;
        return;
    }
    int keta=rest%10;
    rec(rest/10,total+stoll(char(keta+'0')+temp),"");
    rec(rest/10,total,char(keta+'0')+temp);
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    rec(n,0,"");
    cout<<ans<<endl;
    return 0;
}

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

int main() {
    int N, M, a, b;
    cin >> N >> M;
    vector<vector<bool>> edge(N, vector<bool>(N, false));
    rep(i, M) {
        cin >> a >> b;
        a--;
        b--;
        edge[a][b] = true;
        edge[b][a] = true;
    }
    vector<int> p(N - 1);
    rep(i, N - 1) p[i] = i + 1;
    int ans = 0;
    do {
        //rep(i, N - 1) cout << p[i];
        //cout << endl;
        if (!edge[0][p[0]]) continue;
        bool f = false;
        rep(i, N - 2) {
            if (!edge[p[i]][p[i + 1]]) {
                f = true;
                break;
            }
        }
        if (!f) ans++;
    } while(next_permutation(p.begin(), p.end()));
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a,b;
    cin>>a>>b;
    int m=a.size();
    int n=b.size();
    int dp[m+1][n+1];
    for(int i=0;i<=n;i++)
        dp[0][i]=0;
    for(int i=0;i<=m;i++)
        dp[i][0]=0;
    for(int i=1;i<=m;i++)
    {
        for(int j=1;j<=n;j++)
        {
            if(a[i-1]==b[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else
                dp[i][j]=max(dp[i-1][j], max(dp[i][j-1], dp[i-1][j-1]));
        }
    }
    string ans="";
    int i=m;
    int j=n;
    while(i>0 && j>0)
    {
        if(a[i-1]==b[j-1])
        {
            ans=a[i-1]+ans;
            i--;
            j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
            {
                i--;
            }
            else
                j--;
        }
    }

    cout<<ans<<endl;
}


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

#define N 500000 

struct node{
    struct node *r;
    struct node *l;
    struct node *p;
    int key;
};

typedef struct node * Node ;
Node root;
void insert(int k){
    Node y = NULL;
    Node x = root;
    Node z;
 
    z = malloc(sizeof(struct node));
    z->key = k;
    z->l = NULL;
    z->r = NULL;
 
    while(x != NULL){
        y = x;
        if((z->key) < (x->key)) x = x->l;
        else x = x->r;
    } 
    
    z->p = y;
 
    if(y == NULL){
        root = z;
    }
    else if((z->key) < (y->key)){
        y->l = z;
    }
    else y->r = z;
}

void inorder(Node u){
    if(u != NULL){
        inorder(u->l);
        printf(" %d",u->key);
        inorder(u->r);
    }
}
 
void preorder(Node u){
    printf(" %d",u->key);
    if(u->l != NULL){
        preorder(u->l);
    }
    if(u->r != NULL){
        preorder(u->r);
    }
}

int main(){
    int n,i,x;
    char c[10];

    scanf("%d",&n);
  
    for(i=0;i<n;i++){
        scanf("%s",c);
        if(c[0] == 'i'){
            scanf("%d",&x);
        insert(x);
        }
        else if(c[0] == 'p'){
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 24040
#include<iostream>
using namespace std;
int main(){
	int n,max=0,res=0;
	string a;
	cin>>n>>a;
	for(int i=0;i<n;i++){
		if(a[i]=='I'){
			res++;
			if(max<res){
				max=res;
			}
		}else{
			res--;
		}
	}
	cout<<max;
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    if S[0] == S[1] or S[1] == S[2] or S[2] == S[3]:
        print('Bad')
    else:
        print('Good')

main()


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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  ll A[N], B[N]; rep(i,N) cin >> A[i] >> B[i];
  ll result = 0;
  for (int i=N-1; i>=0; i--) {
    A[i] += result;
    result += (B[i]-A[i]%B[i])%B[i];
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.List;
import java.util.ArrayList;

public class Main {
    static int MAX_INF = Integer.MAX_VALUE;
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        String line;
        int[] a = new int[101];
        while ((line = in.readLine()) != null) {
            st = new StringTokenizer(line);
            int n = Integer.parseInt(st.nextToken());
            a[n]++;
        }
        
        int c = 0;
        for (int i = 1; i <= 100; i++) {
            if (c < a[i]) {
                c = a[i];
            }
        }
        
        for (int i = 1; i <= 100; i++) {
            if (c == a[i]) {
                System.out.println(i);
            }
        }
    }
}


Measured memory_bytes: 24240
#include<stdio.h>
int main(){
  int a,b,final;
  char op;
  scanf("%d %c %d\n",&a,&op,&b);
  if(op=='+') final = a+b;
  if(op == '-') final = a-b;
  printf("%d\n",final);
  return 0;
}

Measured memory_bytes: 1708
a, b = map(int, input().split())
ans = []
for i in range(a, b+1):
    str_i = str(i)
    f = True
    for j in range(len(str_i)//2):
        if str_i[j] == str_i[-j-1]:
            continue
        else:
            f = False
    if f:
        ans.append(f)

print(len(ans))

Measured memory_bytes: 3060
#include <cstdio>           // printf(), scanf()
#include <stack>
#include <algorithm>        // max()

using namespace std;
static const int MAX_M = 1400;

struct Rectangle
{
	int height;
	int pos;
};

int G[MAX_M][MAX_M];
int dp[MAX_M][MAX_M + 1];
int H, W;

int
getLargestRectangle(int size, int H[])
{
	Rectangle rect;
	stack<Rectangle> S;

	int maxv = 0;
	H[size] = 0;

	for (int i = 0; i <= size; ++i)
	{
		rect.height = H[i];
		rect.pos = i;
		if (S.empty())
			S.push(rect);
		else
		{
			if (S.top().height < rect.height)
				S.push(rect);
			else if (S.top().height > rect.height)
			{
				int target = i;
				while (!S.empty() && S.top().height >= rect.height)
				{
					Rectangle pre = S.top(); S.pop();
					int area = pre.height * (i - pre.pos);
					maxv = max(maxv, area);
					target = pre.pos;
				}

				rect.pos = target;
				S.push(rect);
			}
		}
	}

	return maxv;
}

int
getLargestRectangle()
{
	for (int j = 0; j < W; ++j)
	{
		for (int i = 0; i < H; ++i)
		{
			if (G[i][j])
				dp[i][j] = 0;
			else
				dp[i][j] = (i > 0) ? dp[i - 1][j] + 1 : 1;
		}
	}

	int maxv = 0;
	for (int i = 0; i < H; ++i)
	{
		int t = getLargestRectangle(W, dp[i]);
		maxv = max(maxv, t);
	}

	return maxv;
}

int
main(int argc, char** argv)
{
	scanf("%d %d", &H, &W);
	for (int i = 0; i < H; ++i)
	{
		for (int j = 0; j < W; ++j)
			scanf("%d", &G[i][j]);
	}

	printf("%d\n", getLargestRectangle());
	return 0;
}

Measured memory_bytes: 18016
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	public static class Walk implements Comparable<Walk>{
		int cur;
		int cost;
		int remain;
		int taxi;
		
		private Walk(int cur, int cost, int remain, int taxi) {
			super();
			this.cur = cur;
			this.cost = cost;
			this.remain = remain;
			this.taxi = taxi;
		}

		@Override
		public int compareTo(Walk arg0) {
			if(this.cost - arg0.cost != 0){
				return this.cost - arg0.cost;
			}else{
				return arg0.remain - this.remain;
			}
		}
	}
	
	public static void main(String[] args) throws IOException {
		//Scanner sc = new Scanner(System.in);
		
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int k = sc.nextInt();
		
		int[] costs = new int[n];
		int[] times = new int[n];
		for(int i = 0; i < n; i++){
			costs[i] = sc.nextInt();
			times[i] = sc.nextInt();
		}
		
		ArrayList<LinkedList<Integer>> adj_list = new ArrayList<LinkedList<Integer>>();
		for(int i = 0; i < n; i++){
			adj_list.add(new LinkedList<Integer>());
		}
		for(int i = 0; i < k; i++){
			final int from = sc.nextInt() - 1;
			final int to = sc.nextInt() - 1;
			
			adj_list.get(from).add(to);
			adj_list.get(to).add(from);
		}
		
		PriorityQueue<Walk> queue = new PriorityQueue<Walk>();
		queue.add(new Walk(0, 0, 0 ,0));
		boolean[][] visited = new boolean[n][n];
		while(!queue.isEmpty()){
			Walk walk = queue.poll();
			
			if(visited[walk.taxi][walk.cur]){
				continue;
			}else if(walk.cur == n - 1){
				System.out.println(walk.cost);
				break;
			}
			//
			//System.out.println(walk.cur + " " + walk.cost + " " + walk.remain + " " + walk.taxi);
			visited[walk.taxi][walk.cur] = true;
			
			for(int next : adj_list.get(walk.cur)){	
				if(walk.remain >= 1){
					queue.add(new Walk(next, walk.cost, walk.remain - 1, walk.taxi));
				}
				
				queue.add(new Walk(next, walk.cost + costs[walk.cur], times[walk.cur] - 1, walk.cur));
			}
		}
		
	}
}

Measured memory_bytes: 77448
import java.util.*;
public class Main {
    /**
     * @param args
     */
    public static void main(final String[] args) {
 		Scanner sc = new Scanner(System.in);
 		final String aStr = sc.next();;
 
        /** 不一致件数カウント */
        int aCount = 0;
        /** インクリメント変数 */
        int aI = 0;
 
        while (aI * 2 < aStr.length()) {
            if (aStr.charAt(aI) == aStr.charAt(aStr.length() - aI - 1)) {
                // 何もしない
            } else {
                aCount++;
            }
            aI++;
        }
        System.out.println(aCount);
    }
}

Measured memory_bytes: 22740
#include <iostream>
#include <stdio.h>
using namespace std;

int main() {
    int x,y;
    while(1){
        cin>>x;cin>>y;
        if(x==0 && y==0)break;
        if(x >= y)printf("%d %d\n",y,x);
        else if(y >x) printf("%d %d\n",x,y);
    }
    return 0;
}


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

int max(int a, int b);
int min(int a, int b);
int cmp(const void *p, const void *q);

int main(int argc, char const *argv[])
{
    double t, x;

    scanf("%lf %lf", &t, &x);

    printf("%f", t / x);

    return 0;
}

int max(int a, int b) {
    return a > b ? a : b;
}

int min(int a, int b) {
    return a < b ? a : b;
}

int cmp(const void *p, const void *q) {
    return *(int*)p - *(int*)q;
}

Measured memory_bytes: 128
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

A, B, C, D = map(int, input().split())

c1 = B // C
c2 = (A-1) // C
c = c1 - c2

d1 = B // D
d2 = (A-1) // D
d = d1- d2

numl = lcm(C, D)
num1 = B // numl
num2 = (A-1) // numl
num = num1 - num2

tmp1 = c + d - num
tmp2 = B - A + 1
print(tmp2 - tmp1)

Measured memory_bytes: 5076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=205,INF=1<<30;

int dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int H,W;cin>>H>>W;
    vector<string> S(H);
    for(int i=0;i<H;i++) cin>>S[i];
    
    for(int i=0;i<MAX;i++){
        for(int j=0;j<MAX;j++){
            dp[i][j]=INF;
        }
    }
    
    if(S[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;
    
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(i){
                if(S[i-1][j]!=S[i][j]) dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
                else dp[i][j]=min(dp[i][j],dp[i-1][j]);
            }
            if(j){
                if(S[i][j-1]!=S[i][j]) dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
                else dp[i][j]=min(dp[i][j],dp[i][j-1]);
            }
        }
    }
    
    if(S[H-1][W-1]=='#') dp[H-1][W-1]++;
    
    cout<<(dp[H-1][W-1]+1)/2<<endl;
}


Measured memory_bytes: 384
n, k = map(int, input().split())
a = list(map(int, input().split()))
idx_appearence = [False] * n
idx_appearence[0] = True
arrival_idx = a[0] - 1
idx_appearence[arrival_idx] = True
idx_lst = [0, arrival_idx]
if k <= n:
    for i in range(max(0, k-1)):
        arrival_idx = a[arrival_idx] - 1
    print(arrival_idx + 1)
else:
    for i in range(min(k, n)):
        arrival_idx = a[arrival_idx] - 1
        if idx_appearence[arrival_idx] == False:
            idx_lst.append(arrival_idx)
            idx_appearence[arrival_idx] = True
        else:
            idx_lst.append(arrival_idx)
            break
    former_part_len = idx_lst.index(idx_lst[-1])
    recursive_len = len(idx_lst) - 1 - former_part_len
    print(idx_lst[former_part_len + ((k - former_part_len) % recursive_len)] + 1)


Measured memory_bytes: 32188
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        
        // 標準入力の取得
        int N = Integer.parseInt(scan.nextLine());

        List<String> W = new ArrayList<String>(N);
        for (int i = 0; i < N; i++) {
            W.add(scan.nextLine());
        }

        // 重複チェック
        Set<String> Wst = new HashSet<String>(W);
        if(!(Wst.size() == W.size())){
            System.out.println("No");
            return ;
        }
        
        // しりとりできてるかチェック
        for (int i = 0; i < N-1; i++) {            
            if(W.get(i).charAt(W.get(i).length() - 1) != W.get(i+1).charAt(0)){
                System.out.println("No");
                return ; 
            }
        }
        System.out.println("Yes");
        return ; 
    }
}


Measured memory_bytes: 21972
#include "bits/stdc++.h"
#define int long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define inf 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define gcd __gcd
using namespace std;

signed main() {
  int n;
  string s;
  cin>>n>>s;
  vector<bool>vec(26);
  int cnt=0;
  int d=0;
  for(int i=1;i<n;i++) {
    string a=s.substr(0,i);
    string b=s.substr(i,n-i);
    rep(j,a.size()) {
      rep(k,b.size()) {
        if(a.at(j)==b.at(k)) {
          vec.at((a.at(j)-'0')-49)=true;
          break;
        }
      }
    }
    rep(j,26) if(vec.at(j)) d++;
    cnt=max(d,cnt);
    d=0;
    rep(j,26) vec.at(j)=false;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := ReadInt()
	ans := make([][]int, 0)
	if N%2 == 1 {
		for i := 1; i <= N; i++ {
			for j := i + 1; j <= N; j++ {
				if j != N-i {
					ans = append(ans, []int{i, j})
				}
			}
		}
	} else {
		for i := 1; i < N; i++ {
			for j := i + 1; j <= N; j++ {
				if j != N-i+1 {
					ans = append(ans, []int{i, j})
				}
			}
		}
	}
	fmt.Println(len(ans))
	for _, ary := range ans {
		fmt.Println(ary[0], ary[1])
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 2552
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>
#include<set>
#include<cstdio>

using namespace std;

#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

typedef vector<int> vec;
typedef vector<vec> mat;

const ll mod = 1000000007;

int main(){
    int n;
    cin >> n;
    int a[n], b[n], c[n-1];
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }
    rep(i, n) cin >> b[i];
    rep(i, n-1) cin >> c[i];
    int ans = 0;
    int bef = -2;
    rep(i, n){
        ans += b[a[i]];
        if(bef + 1 == a[i]) ans += c[bef];
        bef = a[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3572
n = int(input())

ans = [0] * 10050
for x in range(1,105):
    for y in range(1,105):
        for z in range(1,105):
            tmp = x*x + y*y + z*z + x*y + y*z + z*x
            if tmp<10050:
                ans[tmp] += 1

for i in range(n):
    print(ans[i+1])

Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
#define anuj ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define ll long long int
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%I64d",&x)
#define ss(s)	scanf("%s",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define endl '\n'
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pll>		vpll;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
const int mod = 1000000007;
const int N = 2e5;
const int LG = 20;
int a[N];

int main(){
	anuj;

	int n;
	cin >> n;

	ll sum=0;
	fo(i,n){
		cin >> a[i];
		sum+=a[i];
	} 

	ll dp[n][n];

	for(int gap=0;gap<n;gap++){
		for(int i=0,j=gap;j<n;i++,j++){
			ll x=i+2<=j?dp[i+2][j]:0;
			ll y=((i+1)<=(j-1))?dp[i+1][j-1]:0;
			ll z=i<=j-2?dp[i][j-2]:0;

			dp[i][j]=max(a[i]+min(x,y),a[j]+min(y,z));
		}
	}

	cout << 2*dp[0][n-1]-sum;;

}


Measured memory_bytes: 70400
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<cctype>
#include<math.h>
using namespace std;
#define ll long long
int main(){
    ll N,T;
    cin >> N >> T;
    ll i,r=0,sum=0,t;
    for(i=0;i<N;i++){
        cin >> t;
        sum+=min(T,t+T-r);
        r=t+T;
    }
    cout << sum;
    return 0;
}


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

int main() {
	int k,x;
	cin>>k>>x;
    for(int i=x-(k-1);i<x+(k);i++){
        if(i!=x+(k)-1)
            cout<<i<<' ';
        else
            cout<<i<<'\n';
    }
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod (long)(1e9 + 7)
using namespace std;

vector<vector<long>> multiply(vector<vector<long>> &a, vector<vector<long>> &b) {
	int n = a.size();
	vector<vector<long>> c(n, vector<long>(n, 0));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			for(int k = 0; k < n; ++k) {
				c[i][j] = (c[i][j] + ((a[i][k] * b[k][j]) % mod)) % mod;
			}
		}
	}
	return c;
}

vector<vector<long>> compute(vector<vector<long>> &a, long k) {
	if(k == 1) {
		return a;
	}
	vector<vector<long>> res = compute(a, k/2);
	res = multiply(res, res);
	if(k & 1) {
		res = multiply(res, a);
	}
	return res;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int n;
	long k;
	cin >> n;
	cin >> k;
	vector<vector<long>> a(n, vector<long>(n, 0));
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			cin >> a[i][j];
		}
	}
	auto res = compute(a, k);
	long ans = 0;
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j < n; ++j) {
			ans = (ans + res[i][j]) % mod;
		}
	}
	cout << ans;

	return 0;
}

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

void ioinit() { ios::sync_with_stdio(0); cin.tie(0); }

int main() {
  ioinit();
  long N,sum = 0;
  cin >> N;
  for(long q = 1; q < pow(N+0.25,0.5) - 0.5; q++){
    if((N - q) % q == 0) sum += (N - q) / q;
  }
  
  cout << sum << endl;
}


Measured memory_bytes: 512