akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <tgmath.h>
#define MOD 1000000007
using namespace std;
#define INT_MAX 2147000000
#define LONG_MAX 9223372036854775806

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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int count =    1;
    for(int i=0;i<S.length()-1;i++){
        if(S[i]==S[i+1])continue;
        if(S[i]!=S[i+1])count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int N=gi();
	    long[] A=new long[N];

	    long l=0;
	    for (int i=0; i<N; i++) {
	    	A[i]=gl();
	    	l+=A[i];
	    }
	    
	    long min=Long.MAX_VALUE;
	    long a=0;
	    for (int i=0; i<N; i++) {
	    	a+=A[i];
	    	long s=Math.abs(l-2*a);
	    	if(min>s) {
	    		min=s;
	    	}
	    }
        System.out.print(min);
//        if (K<A) {
//        	System.out.println(K);
//        }else if(K<A+B){
//        	System.out.println(A);
//        } else {
//        	System.out.print(A-(K-A-B));
//        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
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 n, m, q;
ll a[51], b[51], c[51], d[51];
ll ans = 0;

void dfs(vector<ll> num, ll now) {
    if (num.size() == n) {
        ll ret = 0;
        for (int i = 0; i < q; i++) {
            if (num[b[i]-1] - num[a[i]-1] == c[i]) ret += d[i];
        }
        chmax(ans, ret);
    } else {
        for (int i = now; i <= m; i++) {
            num.push_back(i);
            dfs(num, i);
            num.pop_back();
        }
    }
}


int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> n >> m >> q;

    for (int i = 0; i < q; i++) cin >> a[i] >> b[i] >> c[i] >> d[i];

    vector<ll> num;

    dfs(num, 1);

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3608
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b=10000000;
string s;
int main(void){
    cin>>s;
    for(auto x:s){
        if('0'<=x&&x<='9'){
            //cout<<x<<endl;
            a+=(x-'0')*b;
            b/=10;
        }
    }
    //cout<<a<<endl;
    if(a<=20190430){
        cout<<"Heisei"<<endl;
    }
    else cout<<"TBD"<<endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
P = list(map(lambda x:int(x) - 1,input().split()))
C = list(map(int, input().split()))
ans = -10**9

for i in range(N):
    tmp_max = [-10**9]*(N+1)
    total = 0
    current_block = P[i]
    for j in range(1, N + 1):
        total += C[current_block]
        tmp_max[j] = max(tmp_max[j-1], total)
        if current_block == i:
            break
        current_block = P[current_block]
    if total <= 0:
        ans = max(ans, tmp_max[j])
    else:
        n = K // j
        r = K % j
        if r == 0:
            ans = max(ans, total*(n-1) + tmp_max[j])
        else:
            ans = max(ans, total*n + tmp_max[r])

print(ans)

Measured memory_bytes: 74764
#!/usr/bin/env python
# coding: utf-8

# In[2]:


import collections


# In[15]:


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


# In[16]:


mycnt = collections.Counter(a)
ans = 0
for x,cnt in mycnt.items():
    if x > cnt:
        ans += cnt
    else:
        ans += cnt - x
print(ans)


# In[ ]:






Measured memory_bytes: 22512
k=int(input())
import sys
if k%2==0 or k%5==0:
  print(-1)
  sys.exit()

a=7
ans=1
while(1):
  if a%k==0:
    print(ans)
    sys.exit()
  else:
    a=a%k
    a=a*10+7
    ans=ans+1
  



Measured memory_bytes: 9008
N = int(input())
AB = [[0]*2 for i in range(N)]

for i in range(N):
    AB[i] = list(map(int, input().split()))

AB = sorted(AB, key=lambda x: x[1])

time = 0
for i in range(N):
    time += AB[i][0]
    if time > AB[i][1]:
        print("No")
        exit(0)

print("Yes")


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

int main(){
  int x,n;
  cin >> x >> n;
  int p[n];
  if(n==0)
    cout << x << endl;
  else{
    for(int i=0; i<n; i++)
      cin >> p[i];
    bool ok=true;
    int a=-1;
    bool small=false;
    int count=0;
    while(ok){
      a++;
      count=0;
      for(int i=0; i<n; i++){
        if(p[i]==x-a){
          ok=false;
          count++;
          small=true;
        }
        if(p[i]==x+a){
          ok=false;
          count++;
          small=false;
        }
      }
      //if(ok==true)
        //ok=false;
      if(ok==false && count==2)
        ok=true;
      else
        ok=false;
    }
    if(small){
      if(count==1){
        cout << x+a << endl;
      }
    }
    else
      cout << x-a << endl;
  }
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

ll modpw(ll x,ll k){
	ll res=1;
	while(k!=0){
		if(k&1)res=res*x%MOD;
		x=x*x%MOD;
		k=k>>1;
	}
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	cin>>n>>k;
	ll ans=0;
	vl cnt(k+1);
	for(ll i=k;i>0;i--){
		ll scr=modpw((k/i),n);
		for(ll j=1;i+j*i<=k;j++){
			scr+=(MOD-cnt[i+j*i]);
		}
		cnt[i]=scr;
	}
	range(i,1,k+1){
		(ans+=i*cnt[i])%=MOD;
	}
	puta(ans);
}


Measured memory_bytes: 4000
#include<iostream>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
typedef long long ll;

int main(){
    int N;
    int l[1000], r[1000];
    int ans=0;
    cin >> N;
    rep(i,N){
        cin >> l[i] >> r[i];
        ans += r[i]-l[i]+1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;
	int n,x,t;
	cin>>n>>x>>t;
	cout<<t*(n%x?n/x+1:n/x);
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
   	int N;
    cin >> N;
  	int a[N];
  	int Alice = 0;
  	int Bob = 0;
    for(int i = 0; i < N; ++i){
      cin >> a[i];
    }
  	sort(a, a + N, greater<int>());
  	for(int i = 0; i < N; ++i){
      if (i % 2 == 0) Alice += a[i];
      else Bob += a[i];
    }
  	
   
    cout << Alice - Bob << endl;
}

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

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

    vector<int> vecP(n);
    for(int i=0; i<n; i++)  cin >> vecP.at(i);

    int count = 0;
    for(int i=0; i<n; i++){
        if(i+1 == vecP[i])
            continue;

        count++;
    }

    int operation = count - 1;
    string ans = (operation<=1) ? "YES" : "NO";
    cout << ans << endl;

    return 0;
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    string s;
    cin >> s;

    if (s[1] == 'B') s[1] = 'R';
    else s[1] = 'B';
    
    cout << s << endl;

    return 0; 
} 


Measured memory_bytes: 3640
// A B C D H F E I G K L M N P S O Q R J U Z Y X T V W
 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ff first
#define ss second
#define int long long
#define pb push_back
#define mp make_pair
#define pq priority_queue<int> 
#define pqs priority_queue<int,vector<int>, greater<int>>
#define setbits(x) __builtin_popcountll(x)  // no of ones in setbit
#define zrobits(x) __builtin_ctzll(x)       //101000 here 3..no of 0 aftrer 1sr right one 
#define mod 1000000007
#define inf 1e18
#define ps(x,y)  fixed<<setprecision(y)<<x  // ans upto 5 decimal place 
#define mk(ar,n,type) type *arr=new type[n];
#define w(x) int x;cin>>x;while(x--)
 
 
 
void fn(int arr[],int n, int k )
{
	int dp[n+1]; 
	dp[0]=0;
	dp[1]= abs(arr[1]-arr[0]);  
	// cout<<dp[1] ;  
 
	for(int i=2; i<n; i++)
	{
		int z=i-k ; 
		if(z<0)
		{
			z=0 ; 
		}
		int ans=INT_MAX  ; 
		for(int j=z ; j<i; j++)
		{
			int x= dp[j]+abs(arr[i]-arr[j])  ; 
			ans=min(ans,x) ;  

		}
		dp[i]=ans ; 
		
	} 

	cout<<dp[n-1]; 
}
 
 
 
int32_t main()
{
	int n, k ; 
	cin>>n>>k  ; 
	int arr[n+1] ; 
 
	for(int i=0 ; i<n ; i++)
	{
		cin>>arr[i] ; 
	}
 
	fn(arr, n, k ) ; 
 
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define ss second
#define ff first
#define Mem(x,val) memset(x,val,sizeof x)
#define pb push_back
#define all(v) v.begin(),v.end()
#define unik(v)  v.erase(unique(v.begin(),v.end()),v.end())
#define cerr(x) cerr << __LINE__ << " th Line : " << #x << " = " << x << "\n"
using namespace std;
typedef pair<int, int> pii;
const ll mod = 998244353;
const int sz = 2 * 1e6 + 10, inf = 1e9 + 10;

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


	int n;
	cin >> n;
	ll g = 0;
	for (int a = 1; a <= n; a++)
	{
		for (int b = 1; b <= n; b++) {
			for (int c = 1; c <= n; c++)
			{
				int x = __gcd(b, c);
				g += __gcd(a, x);
			}
		}
	}
	cout << g << '\n';

	return 0;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	int N;

	cin >> N;

	int k = 1;
	int n = N;
	for (int i = 0; i < 10; i++) {
		if (N / 10 == 0) {
			break;
		} else {
			k++;
		}
		N /= 10;
	}
	int a = 1;
	int c = 0;
	for (int i = 1; i <= k; i += 2) {
		for (int j = a; j < a * 10; j++) {
			if (j <= n) {
				c++;
			}
		}
		a *= 100;
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
while(true){
   var e=Arr.shift()-0;
   if(e==0)break;
   var min=Infinity;
   for(var z=0;z<=100;z++){
      for(var y=0;y<=1000;y++){
         var x=e-(Math.pow(z,3)+Math.pow(y,2));
         if(x<0)break;
         min=Math.min(min,z+y+x)
      }
   }
   console.log(min);
}

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

#define lp(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define ff first
#define ss second

const int maxn=105 ;
const int maxv=1005 ;
const int inf=1e9+10 ;

using namespace std ;

ll dp[maxn*maxv] ;
pair<ll,ll> v[maxn] ;
int ans ;

int main()
{
  lp(i,1,maxn*maxv) dp[i]=inf ;
  dp[0]=0;

  int n, w ;

  scanf("%d%d",&n,&w) ;
  lp(i,0,n) scanf("%lld%lld", &v[i].ff, &v[i].ss) ;

  lp(i,0,n)
  {
    for(int j=ans+v[i].ss ; j >= v[i].ss ; j -- )
    {
      if(dp[ j-v[i].ss ] + v[i].ff <= w )
      {
        dp[j] = min(dp[j] , dp[ j-v[i].ss ] + v[i].ff ) , ans=max(ans,j) ;
      }
    }
  }
  printf("%d\n", ans) ;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long c=0;
     for(int i=1;i<=(n/2);i++){
         for(int j=i;j<=(n/i);j++){
             if(i*j<n&i!=j)c+=2;
             else if(i==j&&i*j<n)c++;
         }
     }
     cout<<c<<"\n";
}

Measured memory_bytes: 3668
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	while (scan.hasNext()) {
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    int l = scan.nextInt();
	    int[][] a = new int[n][m];
	    int[][] b = new int[m][l];
	    long[][] c = new long[n][l];
	    for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
		    a[i][j] = scan.nextInt();
		}
	    }
	    for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
		    b[i][j] = scan.nextInt();
		}
	    }
	    for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
		    for (int k = 0; k < m; k++) {
			c[i][j] += (long)(a[i][k] * b[k][j]);
		    }
		}
	    }
	    for (int i = 0; i < n; i++) {
		System.out.print(c[i][0]);
		for (int j = 1; j < l; j++) {
		    System.out.print(" " + c[i][j]);
		}
		System.out.println();
	    }
	}
    }
}

Measured memory_bytes: 54024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author ParsaAlizadeh
 */

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

typedef long long int   ll;
typedef long double     ld;
typedef pair<ll, ll>    pll;

#define all(x)          x.begin(), x.end()
#define kill(x)         return cout << x << endl, 0;
#define X               first
#define Y               second
#define sep             ' '
#define endl            '\n'
#define file_io         freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ld_io           cout << setprecision(10) << fixed;

ll pw(ll a, ll b, ll mod) {
    if (!b)    return 1;
    if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
    return pw(a * a % mod, b / 2, mod) % mod;
}

const ll MAXN  = 3e5 + 10;
const ll INF   = 8e18;
const ll MOD   = 1e9 + 7; // 998244353;

ll n, m, s, t, mark[MAXN], dist[MAXN];
vector<ll> adj[MAXN];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    fill(dist, dist + MAXN, INF);

    cin >> n >> m;
    for (ll i = 0; i < m; i++) {
        ll u, v;
        cin >> u >> v;
        adj[u * 3].push_back(v * 3 + 1);
        adj[u * 3 + 1].push_back(v * 3 + 2);
        adj[u * 3 + 2].push_back(v * 3);
    }
    cin >> s >> t;
    queue<ll> q;
    q.push(s * 3);
    dist[s * 3] = 0;

    while (!q.empty()) {
        ll u = q.front();
        q.pop();
        if (mark[u]) continue;
        mark[u] = 1;
        for (ll v : adj[u]) if (!mark[v]) {
            q.push(v);
            dist[v] = min(dist[v], dist[u] + 1);
        }
    }
    cout << (dist[t * 3] == INF ? -1 : dist[t * 3] / 3) << endl;

    return 0;
}



Measured memory_bytes: 21376
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _0148
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;
                Console.WriteLine("3C" + (int.Parse(line) % 39 == 0 ? 39 : int.Parse(line) % 39).ToString().PadLeft(2, '0'));
            }
        }

        static string RSt() { return Console.ReadLine(); }
        static int RInt() { return int.Parse(Console.ReadLine().Trim()); }
        static long RLong() { return long.Parse(Console.ReadLine().Trim()); }
        static double RDouble() { return double.Parse(Console.ReadLine()); }
        static string[] RStAr(char sep = ' ') { return Console.ReadLine().Trim().Split(sep); }
        static int[] RIntAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => int.Parse(e)); }
        static long[] RLongAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => long.Parse(e)); }
        static double[] RDoubleAr(char sep = ' ') { return Array.ConvertAll(Console.ReadLine().Trim().Split(sep), e => double.Parse(e)); }
        static string WAr<T>(IEnumerable<T> array, string sep = " ") { return string.Join(sep, array.Select(x => x.ToString()).ToArray()); }
    }

}



Measured memory_bytes: 17924
#!/usr/bin/env python3
import sys


def solve(N: int, K: int, h: "List[int]"):
    count = 0
    for hi in h:
        if hi >= K:
            count += 1
    print(count)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, K, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 12004
import java.math.BigDecimal;
import java.util.Scanner;

/**
 * A - Odds of Oddness
 * 整数 N が与えられます。
 * 高橋君は、N 以下の正整数の中から等確率で 1 つを選んでa とします。
 * このとき、a が奇数である確率を答えてください。
 */
public class Main {

    public static void main( String[] args ) {
        Scanner sc = new Scanner( System.in );
        // 文字列の入力
        int n = sc.nextInt();
        int oddCnt = 0;
        if( n % 2 == 0 ) {
            oddCnt = n / 2;
        } else {
            oddCnt = ( n / 2 ) + 1;
        }
        BigDecimal result = new BigDecimal( oddCnt ).divide( new BigDecimal( n ), 10, BigDecimal.ROUND_HALF_UP );
        System.out.println( result );
    }
}

Measured memory_bytes: 22228
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int p,q,r;
    int result = 0;

    if(scanf("%d %d %d", &p, &q, &r) <3){
        exit(1);
    }
    
    
  
   if((p+q) < (q+r)){
       if((p+q) < (p+r)){
           result = p+q;
       }else{
           result = p+r;
       }
   }else{
       if((q+r) < (p+r)){
           result = q+r;
       }else{
           result = p+r;
       }
   }

   
    printf("%d", result);

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	A[N] = 0;
	for (int i = 0; i < N; i++) {
		if (A[i] > i) {
			cout << -1 << endl;
			return 0;
		}
		if (A[i] < A[i + 1] - 1) {
			cout << -1 << endl;
			return 0;
		}
	}
	ll ans = 0;
	ll num = 0;
	for (int i = N - 1; i >= 0; i--) {
		if (A[i] != 0) {
			if (A[i] == A[i + 1] - 1) {
				num = max(num, A[i]);
			}
			else {
				ans += num;
				num = A[i];
			}
		}
		else {
			ans += num;
			num = 0;
		}
	}
	cout << ans << endl;
}

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

void Main() {
  int A, B;
  cin >> A >> B;
  if (B % A == 0) cout << A + B << endl;
  else cout << B - A << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    if(a>=13){
        cout<<b<<endl;
    }else if(6<=a and a<=12){
        cout<<b/2<<endl;
    }else{
        cout<<0<<endl;
    }
}

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

argList = list(map(int, input().split()))
argList2 = argList.copy()
argList2.sort()

med_before = argList2[int(len(argList2)/2)-2]
med = argList2[int(len(argList2)/2)-1]
med_after = argList2[int(len(argList2)/2)]

for a in argList:
    if( a <= med):
        print(med_after)
    else:
        print(med)

Measured memory_bytes: 25224
N = int(input())
a = [int(i) for i in input().split()]

a2 = [0]
for i in a:a2.append(a2[-1]+i)

total_sum = a2[-1]

a2.pop(0)
sum_n = a2[-1]

output = []
for i in range(N-1):
    output.append(abs(sum_n - (2 * a2[i])))
    
print(min(output))
    

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

int main() {
	int cards[4][13];
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			cards[i][j] = 0;
		}
	}
	int n;
	cin >> n;
	for (int h = 0; h < n; h++) {
		int num;
		char mar;
		cin >> mar >> num;
		if (mar == 'S') {
			cards[0][num - 1] = 1;
		}
		if (mar == 'H') {
			cards[1][num - 1] = 1;
		}
		if (mar == 'C') {
			cards[2][num - 1] = 1;
		}
		if (mar == 'D') {
			cards[3][num - 1] = 1;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (cards[i][j] == 0) {
				if (i == 0) { cout << "S " << j + 1 << endl; }
				if (i == 1) { cout << "H " << j + 1 << endl; }
				if (i == 2) { cout << "C " << j + 1 << endl; }
				if (i == 3) { cout << "D " << j + 1 << endl; }
			}
		}
	}
	return 0;
}



Measured memory_bytes: 3080
#include <stdio.h>

int main(void) {
	char buff[255];
	char ball[255];
	ball['A'] = 1;
	ball['B'] = ball['C'] = 0;
	char t;
	char i;
	
	while(scanf("%s\n", buff)==1) {
		t = ball[buff[0]];
		ball[buff[0]] = ball[buff[2]];
		ball[buff[2]] = t;
	}
	
	for(i='A';i<='C';i++) {
		if(ball[i]) {
			printf("%c\n", i);
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 544
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define End return 0;
#define pi acos(-1)

int main ()
{
    ll n;
    cin>>n;
    ll aa[n];
    for(ll i=0; i<n; i++)
        cin>>aa[i];
    bool f=true;
    for(ll i=0; i<n; i++){
        if(aa[i]%2==0){
            if(aa[i]%3!=0 && aa[i]%5!=0){
                f=false;
                break;
            }
        }
    }
    if(!f)
        cout<<"DENIED"<<endl;
    else
        cout<<"APPROVED"<<endl;
    End;
}
/* pray for me
All is well
*/





Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
#include <fstream>
//#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = (1 << 30);
const ll inf = (1LL << 60LL);
const int maxn = 200006;

int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= 3; i ++){
        if((a * b * i) & 1){
            return 0 * printf("Yes\n");
        }
    }
    cout << "No\n";
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
static const ll mod = 1000000007;
/* ちゃんと考えて実装して問題なくACできた時嬉しいよ！！ */

int main(void){
    int k,t;
    cin >> k >> t;
    vector<int> a;
    for(int i=0; i<t; i++){
        int x;
        cin >> x;
        a.push_back(x);
    }

    // 小さい順に並び替え
    sort(a.begin(), a.end());
    int a_len = a.size();
    int rest = 0;
    for(int i=0; i<a_len-1; i++){
        rest += a[i];
    }
    if(a[a_len-1] <= rest+1){
        cout << 0;
    }
    else{
        int ans = a[a_len-1]-rest-1;
        cout << ans;
    }
    return 0;
}

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

int main(){
	char s[4];
	cin >> s;
	sort(s, s+4);
	if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2])
		cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define each(e,v) for(auto&& e:(v))
#define DEBUG(x) cout<<#x<<": "<<x<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;

int main() {
    int a, b, c; cin >> a >> b >> c;
    vint s(11, 0);
    s[a]++; s[b]++; s[c]++;
    if(s[5] == 2 && s[7] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


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

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
const int MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
struct edge { int i, v; };

int main() {
	int a, b, c, d, e, f;
	cin >> a >> b >> c >> d >> e >> f;
	double ma = -1;
	int ans1, ans2;
	for (int x = 1; x * a * 100 <= f; x++)
		for (int y = 0; x * a * 100 + y * b * 100 <= f; y++)
			for (int z = 0; x * a * 100 + y * b * 100 + z * c <= f; z++)
				for (int w = 0; x * a * 100 + y * b * 100 + z * c + w * d <= f; w++) {
					int A = x * a * 100 + y * b * 100;
					int B = z * c + w * d;
					if (A * e >= B * 100) {
						if ((double)B / (A + B) > ma) {
							ma = (double)B / (A + B);
							ans1 = A + B;
							ans2 = B;
						}
					}
				}
	cout << ans1 << ' ' << ans2 << endl;
}


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

using namespace std;

const int mod = 1e9 + 7;

int main(){
	int n, m;
	cin >> n >> m;
	bool p[n+1][m+1];
	char t;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			cin >> t;
			p[i][j] = (t=='.'?true:false);
		}
	}
	vector<vector<int>> v(n+1, vector<int>(m+1, 0));
	v[1][1] = 1;
	for (int i = 1; i <= n; ++i)
	{
		for (int j = 1; j <= m; ++j)
		{
			if(p[i][j]){
				v[i][j] += v[i-1][j] + v[i][j-1];
				v[i][j] %= mod;
			}
		}
	}
	cout << v[n][m];
}

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

int main() {
	int n,k,q;
	cin>>n>>k>>q;
	int ans[n+1];
	for(int i=0;i<=n;i++)
	{
		ans[i]=0;
	}
	for(int i=0;i<q;i++)
	{
		int x;
		cin>>x;
		ans[x]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(ans[i]>q-k)
		{
			cout<<"Yes\n";
		}
		else
		{
			cout<<"No\n";
		}
	}
	return 0;
}

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

using namespace std;

const int MSIZE  = 3003;

int dp[MSIZE][MSIZE];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    memset(dp, 0, sizeof dp);
    
    int n = s.size();
    int m = t.size();

    s = " " + s;
    t = " " + t;



    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            dp[i][j] = max({
                        dp[i - 1][j],
                        dp[i][j - 1],
                        dp[i - 1][j - 1] + (s[i] == t[j])
                    });
        }
    }
    
    int x = n;
    int y = m;

    string answer = "";

    while (dp[x][y]) {
        while (x && dp[x - 1][y] == dp[x][y]) x--;
        while (y && dp[x][y - 1] == dp[x][y]) y--;
        answer.push_back(s[x]);
        x--, y--;
    }
    reverse(answer.begin(), answer.end());
    cout << answer << endl;
}


Measured memory_bytes: 35456
import std.stdio, std.string, std.conv;

void main() {
	auto input = getStdin!(string[]);
	foreach (line; input) {
		auto num = line.split(" ");
		int w = num[0].to!(int);
		int h = num[1].to!(int);
		if (w == 0 && h == 0) {
			break;
		}
		for (int i_w = 0; i_w < w; i_w++) {
			for (int j_h = 0; j_h < h; j_h++) {
				"#".write;
			}
			"".writeln;
		}
		"".writeln;
	}
}

T getStdin(T)() {
    string[] cmd;
    string line;
    while ((line = chomp(stdin.readln())) != "") cmd ~= line;
    return to!(T)(cmd);
}

Measured memory_bytes: 2492
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>

using namespace std;

void solve(int n, int z, int w, vector<int> a) {
    vector< vector<int> > dp(2, vector<int> (n, 0));
    if (n == 1) {
        std::cout << abs(a[0] - w) << std::endl;
        return;
    }
    dp[0][n-1] = abs(a[n-2] - a[n-1]);
    dp[1][n-1] = abs(a[n-2] - a[n-1]);
    for (int i = n-2; i > 0; i--) {
        int tmp = *max_element(dp[1].begin()+i+1, dp[1].end());
        tmp = max(tmp, abs(a[i-1]-a[n-1]));
        dp[0][i] = tmp;
        tmp = *min_element(dp[0].begin()+i+1, dp[0].end());
        tmp = min(tmp, abs(a[i-1]-a[n-1]));
        dp[1][i] = tmp;
    }
    dp[0][0] = max(*max_element(dp[1].begin()+1, dp[1].end()), abs(w-a[n-1]));
    std::cout << dp[0][0] << std::endl;
}

int main() {
    struct timeval start,end;
    long long span;
    int n, z, w;

    gettimeofday(&start,NULL);

    std::cin >> n >> z >> w;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
    }
    solve(n, z, w, a);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 888
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

int main() {
    int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    rep(i, N) cin >> x.at(i);
    rep(i, M) cin >> y.at(i);

    // ソート（昇順）
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());

    bool isExist = false;
    for (int z = X + 1; z <= Y; z++) {
        if (x.back() < z && z <= y.front()) isExist = true;
    }

    string ans = isExist ? "No War" : "War";

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
n, w = gets.split.map &:to_i

cost = Array.new(w + 1, 0)

(1..n).each.with_index(0){ |nn, i| 
	w_temp, v_temp = gets.split.map &:to_i

	w.downto(w_temp).each{ |ww|
		temp = cost[ww - w_temp] + v_temp
		if cost[ww] < temp then
			cost[ww] = temp
		end
	}
}

puts cost[w]


Measured memory_bytes: 2556
#include <stdio.h>
int main(void){
    int i, a;
    char S[10];
    scanf("%s", &S);
    a=0;
    for (i=1; i<=3; i++) {
        if (S[i] == S[i-1]) a=1;
    }
    if (a==0) printf("Good");
    else printf("Bad");
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;


long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main(){
    int n;
    cin>>n;
    int c00=0,c01=0;
    map<pair<ll,ll>,pii>m;
    rep(i,0,n){
        ll a,b;
        cin>>a>>b;
        if(a==0 and b==0){
            c00++;
            continue;
        }
        ll const g=__gcd(a,b);
        //cout<<g<<endl;
        //cout<<abs(__gcd(a,b))<<endl;
        a/=g,
        b/=g;
        //cout<<a<<' '<<b<<endl;
        if(b<0)a=-a, b=-b;
        if(a<=0) m[{b,-a}].second++;
        else m[{a,b}].first++;
        /*for(auto p:m){
         cout<<'{'<<p.first.first<<','<<p.first.second<<"} "<<p.second.first<<' '<<p.second.second<<endl;
    }*/
    }
    /*     for(auto p:m){
         cout<<'{'<<p.first.first<<','<<p.first.second<<"} "<<p.second.first<<' '<<p.second.second<<endl;
    }*/
    ll ans=1;
    for(auto p:m){
        ans=(ans*(mod+modpow(2,p.second.first,mod)+modpow(2,p.second.second,mod)-1)%mod)%mod;
    }

    cout<<(mod+ans+c00-1)%mod<<endl;
return 0;
}

Measured memory_bytes: 16012
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int N; cin >> N;
	vector<int> x(N), y(N), h(N);
	for (int i = 0; i < N; ++i) {
		cin >> x[i] >> y[i] >> h[i];
	}
	for (int cx = 0; cx <= 100; ++cx) {
		for (int cy = 0; cy <= 100; ++cy) {
			int needH = -1;
			for (int i = 0; i < N; ++i) {
				if (h[i] > 0) {
					int tmpH = h[i] + abs(y[i] - cy) + abs(x[i] - cx);
					if (needH == -1) {
						needH = tmpH;
					} else if (needH != tmpH) {
						needH = -2;
					}
				}
			}
			if (needH == -2) continue;
			for (int i = 0; i < N; ++i) {
				if (h[i] == 0) {
					int tmpH = abs(y[i] - cy) + abs(x[i] - cx);
					if (needH > tmpH) {
						needH = -2;
					}
				}
			}
			if (needH == -2) continue;
			cout << cx << " " << cy << " " << needH << endl;
		}
	}
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main()
{
    char c;
    cin>>c;

    if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
        cout<<"vowel"<<endl;
    }else{
        cout<<"consonant"<<endl;
    }

    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int>a(N);
  for(int i=0; i<N; i++){
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  cout << a[N-1]-a[0] << endl;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define int int64_t
#define rep(i, N) for(int i=0; i<N; i++)
#define repr(i, N) for(int i=N-1; i>=0; --i)
using namespace std;
//using pair = pair<int, int>;
using tup  = tuple<int, int, int>;
using vec  = vector<int>;
using vvec = vector<vec>;

//プロトタイプ宣言
//int myfunc(int, vvec);

//グローバル変数
//int N, M;
//vvec data(N, vec(M));



signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	cout<<n*n<<endl;
	return 0;
}

Measured memory_bytes: 256
n=int(input())
a=[list(map(int,input().split())) for _ in range(n)]
b=[(i,sum(j)) for i,j in enumerate(a)]
b.sort(key=lambda x:x[1],reverse=True)
ans=0
for i in range(n):
	ans+=a[b[i][0]][i%2]*(-1)**(i%2)
print(ans)

Measured memory_bytes: 42592
#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++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll K;
  cin >> K;
  cout << 50 << endl;
  rep(i,50){
    if(K%50LL==0) cout << K/50LL + 49LL << " ";
    else if(i<K%50LL) cout << K/50LL+50LL << " ";
    else cout << K/50LL + 49LL - i%50LL<< " ";
  }
  cout << "" <<endl;
  return 0;
    

}


Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
using namespace std;
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;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

int main(){
    int x; cin >> x;
    for(int i=1;i*i<=x;i++){
        if(x%i==0||i==1){
            int ii=x/i;
            rep(a,1000){
                if(pow(a+i,5)-pow(a,5)==x){
                    cout << a+i << " " << a << endl;
                    return 0;
                }
                if(pow(a-i,5)-pow(a,5)==x){
                    cout << a-i << " " << a << endl;
                    return 0;
                }
                if(pow(a+ii,5)-pow(a,5)==x){
                    cout << a+ii << " " << a << endl;
                    return 0;
                }
                if(pow(a-ii,5)-pow(a,5)==x){
                    cout << a-ii << " " << a << endl;
                    return 0;
                }
                
                if(pow(-a+i,5)-pow(-a,5)==x){
                    cout << -a+i << " " << -a << endl;
                    return 0;
                }
                if(pow(-a-i,5)-pow(-a,5)==x){
                    cout << -a-i << " " << -a << endl;
                    return 0;
                }
                if(pow(-a+ii,5)-pow(-a,5)==x){
                    cout << -a+ii << " " << -a << endl;
                    return 0;
                }
                if(pow(-a-ii,5)-pow(-a,5)==x){
                    cout << -a-ii << " " << -a << endl;
                    return 0;
                }
            }
        }
    }
    cout << 0 << endl;
}


Measured memory_bytes: 4304
type v =
    | WHITE
    | BLACK
    | NA

module M = Map.Make (struct type t = int let compare = compare end)

let () =
    let main () =
        let n = Scanf.sscanf (read_line ()) "%d" (fun a -> a) in
        let arr = Array.init (n - 1) (fun _ -> Scanf.sscanf (read_line ()) "%d %d %d" (fun u v w -> u, v, w)) in
        let vertex = Array.make n NA in
        vertex.(0) <- WHITE;
        let map =
            Array.fold_left (fun map (u, v, w) ->
                let map = M.add u ((v, w) :: try M.find u map with _ -> []) map in
                          M.add v ((u, w) :: try M.find v map with _ -> []) map) M.empty arr
        in

        let rec fill cur dist =
            if vertex.(cur - 1) = NA then (
                vertex.(cur - 1) <- if dist mod 2 = 0 then WHITE else BLACK;
                List.iter (fun (v, w) -> fill v (w + dist)) (M.find cur map)
            )
        in

        List.iter (fun (v, w) -> fill v w) (M.find 1 map);
        Array.iter (function
            | WHITE -> print_endline "0"
            | BLACK -> print_endline "1"
            | NA    -> failwith "??") vertex
    in
    main ()


Measured memory_bytes: 37128
# coding: utf-8

# In[13]:


s = str(input())


# In[15]:


if int(s[:4]) < 2019:
    print("Heisei")
elif int(s[:4]) == 2019:
    if int(s[5:7]) < 5:
        print("Heisei")
    else:
        print("TBD")
else:
    print("TBD")



Measured memory_bytes: 2940
#include <stdio.h>

int main(void)
{
  int a,b,c,n1,n2,n3;
  
  scanf("%d%d%d",&a,&b,&c);

  if (a>b) 
    {n2 = a;
     a  = b;
     b = n2;}
  if (b>c)
    {n3 = b;
     b  = c;
     c = n3;}
  if (a>b) 
    {n2 = a;
     a = b;
     b = n2;}
  printf("%d %d %d\n",a,b,c);

  return 0;
}

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

int main() {
	//a+b=x 4a+2b=y
	//a=y/2 - x b=2x - y/2
	int x,y;
	string k = "Yes";
	cin >> x >> y;
	int h1 = y % 2;
	int h2 = (y / 2) - x;
	int h3 = 2 * x - (y/2);
	if(h1!=0)
	{
		k = "No";
	}
	if(h2 < 0)
	{
		k = "No";
	}
	if(h3 < 0)
	{
		k = "No";
	}
	cout << k << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = 1001002003004005006ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; ll k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		a[i]--;
	}
	vector<int> def(n, 0);
	int res = 0;
	def[0] = 0;
	int cnt = 0;
	int rs = -1;
	for (ll i = 0; i < k; ++i) {
		cnt++;
		res = a[res];
		if (def[res]) {
			k -= def[res];
			rs = cnt - def[res];
			break;
		}
		else {
			def[res] = cnt;
		}
	}
	if (rs == -1) {
		cout << res + 1 << endl;
		return 0;
	}
	k %= rs;
	rep(i, k) {
		res = a[res];
	}
	cout << res + 1 << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

ll A, B, C;

signed main()
{
    cin >> A >> B >> C;
    vector<ll> v;
    v.push_back(A);
    v.push_back(B);
    v.push_back(C);
    sort(v.begin(), v.end(), greater<ll>());
    ll ans = 0;
    while(1) {
        // 判定
        if(v[0] == v[1] && v[0] == v[2]) { break; }
        else if(v[0] == v[1] && v[0] == v[2] + 1) {
            ans += 2;
            break;
        }
        else if(v[0] == v[1] + 1 && v[0] == v[2] + 1) {
            ans++;
            break;
        }
        ll tmp = (v[0] - v[1]) / 2;
        ans += tmp;
        v[1] += tmp * 2;
        tmp = (v[0] - v[2]) / 2;
        ans += tmp;
        v[2] += tmp * 2;
        sort(v.begin(), v.end(), greater<ll>());
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;	
typedef long long ll;
typedef long double ld;
typedef complex<ld> pt;
#define X real()
#define Y imag()
void pin(pt& p){
	ld x,y; 
	cin>>x>>y; 
	p={x,y};
}
ostream& operator<<(ostream& os, pt p){
	return os<<p.X<<" "<<p.Y<<endl;
} 
ld dot(pt p,pt q){
	return (p.X*q.X + p.Y*q.Y);
}
pt solve(pt p,pt q,pt x){
	ld l = dot((q-p),(x-p))/abs(q-p);
	pt on = l*(q-p)/abs(q-p);
	pt prj = p+on;
	return (prj+(prj-x));
}
int main (){
	cout<<fixed<<setprecision(12);
	pt p,q,x;
	pin(p);
	pin(q);
	int t; 
	cin>>t;
	while(t--){
		pin(x);
		cout<<solve(p,q,x); 
	}
	return 0;
}



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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using namespace std;

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

string s[2010];

string cs[2010];
int dp[2010][10010];

// Description: Z[i]=sとs[i..]の最長共通部分列の長さ
// TimeComplexity: $\mathcal{O}(N)$ 
// Verifyed: ARC 060 D

auto z_algorithm(const string &s){
	int n=s.size(),i=1,j=0,k;
	vector<int> z(n,n);
	while(i<n){
		while(i+j<n&&s[i+j]==s[j]) j++;
		z[i]=j,k=!!j;
		while(i+k<n&&k+z[k]<j) z[i+k]=z[k],k++;
		i+=k+!j,j-=k;
	}
	return z;
}

int main(void){
	int n,k;
	cin >> n >> k;
	rep(i,n) cin >> s[i];

	dp[0][0]|=1;
	rep(i,n)rep(j,k+1){
		if(dp[i][j]&1) dp[i+1][j]|=1;
		const int sn=int(s[i].size());
		if(j+sn<=k and dp[i][j]&1) dp[i+1][j+sn]|=1;
	}

	dp[n][k]|=2;
	rrep(i,n)rep(j,k+1){
		if(dp[i+1][j]&2) dp[i][j]|=2;
		const int sn=int(s[i].size());
		if(j+sn<=k and dp[i+1][j+sn]&2) dp[i][j]|=2;
	}

	//rep(i,n+1)rep(j,k+1) cout << i << " " << j << " " << dp[i][j] << endl;
	dp[0][0]|=4;
	cs[0]="";
	rep(i,n){
		string tar=s[i]+"$"+cs[i];
		vector<int> z=z_algorithm(tar);
		const int zn=z.size();
		const int sn=s[i].size();
		const int cn=cs[i].size();
		cs[i+1]=cs[i];

		rep(j,k+1){
			bool ok=false;
			//if(i==6 and j==1) cout << i << " " << j << " " << dp[i][j] << endl;
			if(j+sn<=k and dp[i][j]==7 and dp[i+1][j+sn]==3){
				//cout << i << " " << j << endl;
				if(sn+1+j<zn){
					int diff=z[sn+1+j];
					if(diff<min(sn,cn)){
						char sc=s[i][diff],zc=cs[i][j+diff];
						//if(i==6 and j==1) cout << j+diff << endl;
						if(sc<=zc){
							ok=true;
							cs[i+1]=cs[i].substr(0,j)+s[i];
							dp[i+1][j+sn]|=4;
							rep(hoge,j,j+diff+1) if(dp[i][hoge]==7) dp[i+1][hoge]|=4;
						}
					}
				}else{
					ok=true;
					cs[i+1]=cs[i]+s[i];
					dp[i+1][j+sn]|=4;
				}
			}
			if(dp[i][j]==7) dp[i+1][j]|=4;
			if(ok) j=k;
		}
	}
	//rep(i,n+1) cout << cs[i] << endl;
	cout << cs[n] << endl;
	return 0;
}

Measured memory_bytes: 99584
#include <stdio.h>

int main()
{
    int x;
    int i = 1;
    do
    {
        scanf("%d", &x);
        if (x != 0)
        {
            printf("Case %d: %d\n", i, x);
        }
        i++;
    } while (x != 0);

    return 0;
}



Measured memory_bytes: 2028
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <bitset>
#include <climits>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RFOR(i,a,b) for (int i=(a)-1;i>=(b);i--)
#define ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const int INF = 1e9;
const ll LL_INF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

const int DEF = 8010;


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int x,y;
  cin >> s;
  cin >> x >> y;
  int N = s.size();
  bool first = true;
  bool first_exist = false;
  bool isX = false;
  int first_x = 0;
  int dx = 0, dy = 0;
  vector<vector<int> > ds(2,vector<int>());
  REP(i,N){
    if(s[i] == 'F'){
      if(first) first_x++;
      else if(isX) dx++;
      else dy++;
    }else{
      if(first){
        first = false;
        if(first_x > 0){
          ds[0].push_back(first_x);
          first_exist = true;
        }
      }else if(isX){
        isX = false;
        if(dx > 0){
          ds[0].push_back(dx);
          dx = 0;
        }
      }else{
        isX = true;
        if(dy > 0){
          ds[1].push_back(dy);
          dy = 0;
        }
      }
    }
  }
  if(first && first_x > 0){
    ds[0].push_back(first_x);
    first_exist = true;
  }else if(isX && dx > 0) ds[0].push_back(dx);
  else if(!isX && dy > 0) ds[1].push_back(dy);

  int dp[2][DEF * 2 + 100];
  REP(isy, 2){
    int d = 0;
    int max_dist = 0;
    fill(dp[0], dp[2], 0);  
    dp[0][DEF] = 1;
    REP(i,ds[isy].size()){
      for(int j = -max_dist; j <= max_dist; j++){
        if(dp[d][DEF+j] > 0){
          dp[d^1][DEF+j + ds[isy][i]] = 1;
          if(isy == 0 && i == 0 && first_exist) continue;
          dp[d^1][DEF+j - ds[isy][i]] = 1;
        }
      }
      max_dist += ds[isy][i];
      fill(dp[d], dp[d + 1], 0);
      d ^= 1;
    
    }
    int target = isy == 0 ? x : y;
    if(dp[d][DEF + target] == 0){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 384