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

using namespace std;

#define pb push_back
#define in insert
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 1; i < (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 
const double PI =  3.141592653589793;

int main(){
	IO;
	string s,t;
	cin>>s>>t;
	ll ans = 0;
	forn(i,s.length()){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<"\n";
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""


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

#define LL long long
#define RG register

using namespace std;
template<class T> T gi() {
	T x = 0; bool f = 0; char c = getchar();
	while (c != '-' && (c < '0' || c > '9')) c = getchar();
	if (c == '-') f = 1, c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f ? -x : x;
}
const int N = 200010;
int f[N];
struct node {
	int to, nxt;
} g[N];
int lst[N], gl;
void add(int x, int y) { g[++gl] = (node) {y, lst[x]}; lst[x] = gl; }
void dfs(int u, int ff) {
	int c1 = 0, c2 = 0;
	for (int i = lst[u]; i; i = g[i].nxt) {
		int v = g[i].to; if (v == ff) continue;
		dfs(v, u);
		f[u] ^= f[v] + 1;
//if (f[v]) c1++;
		//else c2++;
	}	
/*	if (!c1) {
		if (c2) f[u] = c2 & 1;		
	}
	else f[u] = c1 & 1;*/
//	printf("[%d] %d\n", u, f[u]);
}
int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int n = gi<int>();
	for (int i = 1; i < n; i++) {
		int x = gi<int>(), y = gi<int>();
		add(x, y); add(y, x);
	}
	dfs(1, 0);
	puts(f[1] ? "Alice" : "Bob");
	return 0;
}


Measured memory_bytes: 7296
import           Control.Monad
import qualified Data.ByteString.Char8       as BS
import           Data.Maybe
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  [n, m] <- getIntList

  let (x, y) = if n >= m then (n, m) else (m, n)
      p = 10^9 + 7 :: Int

  d <- VM.new (x+1)
  VM.set d (0::Int)

  let fac :: Int -> IO Int
      fac x | x == 1    = return 1
            | otherwise = do
                t <- VM.read d x
                if t > 0
                  then return t
                  else do fx_1 <- fac (x-1)
                          let r = x * fx_1 `mod` p
                          VM.write d x r
                          return r

      solve :: Int -> Int -> IO Int
      solve a b | a - b >= 2 = return 0
                | a - b == 1 = do fa <- fac a
                                  fb <- fac b
                                  return $ fa * fb `mod` p
                | otherwise  = do -- a == b
                    fa <- fac a
                    return $ fa * fa `mod` p * 2 `mod` p

  ans <- solve x y
  print ans

Measured memory_bytes: 4220
using System;
using System.Collections.Generic;
using System.Text;

namespace AOJ
{
    class Program
    {
        static double distance(double[] x, double[] y, int p)
        {
            if (x.Length != y.Length)
            {
                throw new Exception("invalid input");
            }

            double sum = 0;
            for (int i = 0; i < x.Length; ++i)
            {
                sum += Math.Pow(Math.Abs(x[i] - y[i]), p);
            }
            return Math.Pow(sum, 1.0 / p);
        }
        // どこからpが十分大きいかを判定できなかったので悲しい関数分けを行った
        static double distanceAsLargeP(double[] x, double[] y)
        {
            if (x.Length != y.Length)
            {
                throw new Exception("invalid input");
            }

            double max = 0; // かなりいい加減なことしていてすみません
            for (int i = 0; i < x.Length; ++i)
            {
                var v = Math.Abs(x[i] - y[i]);
                max = Math.Max(max, v);
            }
            return max;
        }
        static void Main(string[] args)
        {
            var input = Console.In.ReadLine();
            var count = int.Parse(input);

            var xStrings = Console.In.ReadLine().Split(' ');
            var yStrings = Console.In.ReadLine().Split(' ');

            var xs = new double[count];
            var ys = new double[count];
            for (int i = 0; i < count; ++i)
            {
                xs[i] = double.Parse(xStrings[i]);
                ys[i] = double.Parse(yStrings[i]);
            }

            var manhattan = distance(xs, ys, 1);
            var eucledian = distance(xs, ys, 2);
            var minkowski3 = distance(xs, ys, 3);
            var chebyshev = distanceAsLargeP(xs, ys);

            Console.Out.WriteLine("{0:0.########}", manhattan);
            Console.Out.WriteLine("{0:0.########}", eucledian);
            Console.Out.WriteLine("{0:0.########}", minkowski3);
            Console.Out.WriteLine("{0:0.########}", chebyshev);
        }
    }
}



Measured memory_bytes: 20044
#include <cstdio>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

typedef long long LL;
int n;
double d,x,ans;

int main()
{
    for (scanf("%d%lf%lf",&n,&d,&x); n; n--)
    {
        ans+=d+(n*2-1)*x*0.5;
        d=(d*(n+1)+2.5*x)/n;
        x*=1+2.0/n;
    }
    printf("%.10f\n",ans);
    return 0;
}

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

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;


class Solver {
  public:
    bool solve() {
        int N; cin >> N;
        if(N == 0) return 0;
        vector<int> K(N); cin >> K;
        string S; cin >> S;
        string alpha;
        repeat(i, 'a', 'z' + 1) alpha.push_back(i);
        repeat(i, 'A', 'Z' + 1) alpha.push_back(i);
        string ans;
        rep(i, S.size()) {
            int n = isupper(S[i]) ? S[i] - 'A' + ('z' - 'a' + 1): S[i] - 'a';            
            int k = K[i % K.size()];
            n = (n - k + alpha.size()) % alpha.size();
            ans.push_back(alpha[n]);
        }
        cout << ans << endl;
        return 1;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(Solver().solve());
    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,K;
    cin>>N>>K;
    vector<int> A(N,0);
    REP(i,N){
        int a;cin>>a;
        A[a-1]++;
    }
    sort(A.begin(),A.end(),greater<int>());
    int sum=0;
    REP(i,K){
        sum+=A[i];
    }
    cout<<N-sum<<endl;
}

Measured memory_bytes: 1152
def choose2(n):
    return n * (n-1) // 2

n = int(input())
a = list(map(int, input().split()))
dct = {}
for i in range(n):
    if a[i] in dct:
        dct[a[i]] += 1
    else:
        dct[a[i]] = 1
tot = 0
for key, value in dct.items():
    tot += choose2(value)
# print(tot)
for i in range(n):
    ans = tot
    ans -= choose2(dct[a[i]])
    ans += choose2(dct[a[i]]-1)
    print(ans)

Measured memory_bytes: 86732
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX_K=5000;

int main(){
    long long N, K;
    cin >> N >> K;
    long long a[N];
    long long sets[MAX_K]={}, sets_next[MAX_K]={};
    long long tmp;
    long long ans;
    long long imax, imin, ii, ians;
    bool flag;

    for(long long i=0; i<N; i++){
        cin >> a[i];
    }

    sort( a, a+N );

    ans=0;
    imin=0;
    imax=N-1;
    while( imin<=imax ){
        ii = (long long) ( imin + imax )/2;
        //cout << "imin ii imax= " << imin << " " << ii << " " << imax << endl;

        for(long long i=0; i<MAX_K; i++){
            sets[i]=0;
            sets_next[i]=0;
        }
        if( a[ii] < K ){
            sets[a[ii]]++;
            sets_next[a[ii]]++;
        }else{
            imax=ii-1;
            if( imin > imax ){
                ians=ii-1;
            }            
            continue;
        }

        vector <long long> gsets;

        for(long long i=0; i<N; i++){
            for(long long j=0; j<MAX_K; j++){

                if(i==ii){
                    break;
                }
                if( sets[j]>0 ){
                    tmp= j+a[i];
                    if( tmp >= K ){
                        //cout << "push back: ii i j tmp= " << ii << " " << i << " " << j << " " <<  tmp << endl;
                        gsets.push_back(tmp);
                    }else{
                        sets_next[tmp]++;
                    }
                }
            }

            for(long long k=0; k<MAX_K; k++ ){
                if( sets_next[k] > sets[k] ){
                    sets[k]= sets_next[k];
                }
            }

        }

        flag=true;
        for(auto v: gsets){
            if( v-a[ii] < K ){
                //cout << "ii v " << ii << " " << v << endl;
                flag=false;
            }
        }
        if(flag){
            imin=ii+1;
            if( imin > imax ){
                ians=ii;
                //cout << "last ians= " << ians << endl;
            }
        }else{
            imax=ii-1;
            if( imin > imax ){
                ians=ii-1;
            }
        }

    }

    ans = ians+1;
    cout << ans << endl;

    return 0;
}

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

if N == 1:
    print(1)
elif N < 4:
    print(2)
elif N < 8:
    print(4)
elif N < 16:
    print(8)
elif N < 32:
    print(16)
elif N < 64:
    print(32)
elif N < 101:
    print(64)


Measured memory_bytes: 2940
#include<stdio.h>
int main()
{
    int X,N,i,D=0,count=1;
    int a;
    scanf("%d %d",&N,&X);

    for(i=0; i<N; i++)
    {
        scanf("%d",&a);
        D = D + a;
        if(D <= X)
        {
            count++;
        }
    }
    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main() {
	char character;
	cin>>character;
	int storeAscii=character;
	if (storeAscii>=65 && storeAscii<=90) {
		cout<<"A"<<endl;;
	} else if (storeAscii>=97 && storeAscii<=122) {
		cout<<"a"<<endl;;
    }
    return 0;
}

Measured memory_bytes: 3628
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int x; cin >> x;
        vector<bool>ans(x+1);
        ans[1]=1;
        for(int b=2; b<=x; b++){
            int v = b*b;
            while(v<=x){
                ans[v] = 1;
                v *= b;
            }
        }
       for(int i = x; i>=1;i--){
            if(ans[i]){
                cout<<i<<endl;
                return 0;
            }
       }

return 0;
}



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

int main(void) {
    double a, b, c, d, e, f;
    double x, y;
    
    while(cin >> a >> b >> c >> d >> e >> f) {
        y = (c*d - a*f) / (b*d - a*e);
        x = (c - b * y) / a;
        
        printf("%.3lf %.3lf", x, y);
        cout << endl;
    }
}


Measured memory_bytes: 3220
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"rprint.hpp"
#else
template <ostream& out = cout, class... T> void prints(T&&...){ }
template <ostream& out = cout, class... T> void printd(T&&...){ }
template <ostream& out = cout, class... T> void printde(T&&...){ }
template <ostream& out = cout, class... T> void printb(T&&...){ }
template <ostream& out = cout, class... T> void printArr(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    int two = 0, four = 0;
    for(int i = 0; i < n; i++){
        int a; cin >> a;
        if(a % 4 == 0){
            four++;
        }else if(a % 2 == 0){
            two++;
        }
    }
    if(two == 1){
        two--;
    }
    // cout << (n <= four * 2 + two ? "Yes" : "No") << '\n';
    cout << (n - four * 2 <= 1 || n - four * 2 - two <= 0 ? "Yes" : "No") << '\n';
    return 0;
}


Measured memory_bytes: 256
#require 'pp'
#require 'set'

n = gets.chomp!.to_i
s_n = []
ana = {}
n.times do |i|
    s = gets.chomp!.chars.sort.join
    ana[s] ||= 0
    ana[s] += 1
end

memo = {
    1 => 0,
    2 => 1,
}

3.upto(10 ** 5) do |i|
    memo[i] = (i - 1) + memo[i - 1]
end

sum = 0
ana.each do |a, b|
    sum += memo[b]
end

puts sum


Measured memory_bytes: 23580
#include <bits/stdc++.h>
using namespace std;
#define FAST                     \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);

int frogBU(vector<int> &v,int n)
{
	vector<int> dp(n);
	dp[0] = 0 ;
	for( int i = 1 ; i < n ; i ++)
	{
		int a = abs(v[i]-v[i-1]) + dp[i-1];
		int b = (i==1) ? INT_MAX : abs(v[i]-v[i-2]) + dp[i-2];
		dp[i] = min(a,b);
	}
	return dp[n-1];
}
int main()
{
	FAST
	int n ; cin >> n ;
	vector<int> v(n) ;
	for(auto &p:v) cin >> p ;
	cout << frogBU(v,n) << endl;
	return 0 ;
}	

Measured memory_bytes: 3896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<vector<int>> a(n+1,vector<int>(n+1,0));
  rep(i,n){
      rep(j,n){
          cin>>a[i][j];
      }
  }
  vector<int> dp((1ull<<n),0);
  dp[0]=1;
  for(int bit=0;bit<(1ull<<n);++bit){
      int i=__builtin_popcount(bit);
      rep(j,n){
          if((!(bit&(1ull<<j)))&&a[i][j]==1){
              dp[bit|(1ull<<j)]+=dp[bit];
              dp[bit|(1ull<<j)]%=MOD;
          }
      }
  }
  /*
  rep(i,n){
      rep(bit,(1<<n)){
          //cout<<dp[i][bit]<<" ";
      }
      //cout<<endl;
  }*/
  cout<<dp[(1ull<<n)-1]<<endl;
  return 0;
}

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

int main() {
  long long a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(c > d)
    swap(c, d);
  
  int p, q;
  p = d;
  q = c;
  bool flag = true;
  while(flag) {
    int temp = q;
    q = p % q;
    p = temp;
    if(q == 0)
      flag = false;
  }
  
  long long l = c * d / p;
  
  long long bd = b - (b / c + b / d - b / l);
  long long ad = (a - 1) - ((a - 1)/ c + (a - 1)/ d - (a - 1)/ l);
  
  cout << bd - ad << endl;
}

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

#define rep(i, n)for((i) = 0;(i) < (n);++(i))


int main(void){
	string s;
	
	cin >> s;
	cout << s[0];
	cin >> s;
	cout << s[0];
	cin >> s;
	cout << s[0] << "\n";
	
	return 0;
}

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

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
if n == 1:
    print(0)
    exit()
li = factorization(n)
for i in li:
    ii = i[0]
    loop = True
    while(loop):
        if n % ii == 0:
            n = n / ii
            cnt += 1
            ii *= i[0]
        else:
            loop = False
print(cnt)

Measured memory_bytes: 9440
using System;

namespace abc169
{
    class Program
    {
        static void Main()
        {
            var ab = Console.ReadLine().Split(' ');
            var a = long.Parse(ab[0]);
            var b = Decimal.Parse(ab[1]);
            Console.WriteLine(Math.Floor(Decimal.Multiply(a, b)));
        }
    }
}


Measured memory_bytes: 27612
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0;i < n;i++)
#define REP(i,n,k) for(ll i = n;i < k;i++)
#define P(p) cout << (p) << endl;
#define sP(p) cout << setprecision(15) << fixed << p << endl;
#define vi vector<int>
#define printv(v) for(int i = 0;i < v.size();i++)P(v[i]);
#define printt(a,b) cout << a << " " << b << endl; 
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0};
int dy[] = { 0,  0,  1, -1};
int MOD = 1e9 + 7;
 
void solve() {
    string s;
    cin >> s;
    stack<ll> pos;
    rep(i,s.length()){
        if(s[i] == 'B'){
            pos.push(i+1);
        }
    }
    ll sum = 0;
    ll p = s.length();
    while(!pos.empty()){
        sum += p - pos.top();
        pos.pop();
        p--;
    }
    P(sum);
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 2052
<>;@a=glob<>;$\=1e9;map{$b[$s=@a]=@b=$N=$c=0;$c+=$N+=2*$_>$l+$\?-$b[++$s]:$b[$s--],$b[$s]++for@a;$c>@a*(@a+1)/4?$\:$l=$l+$\>>1}1..35;print

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

using namespace std;
int main()
{
    long long n,ans,count;
    string buf;
    std::vector<string> s;
    long long i = 0;
    long long mod = 1000000007;
    
    ans = 0;
    cin >> n;

    while(i<n){
        cin >> buf;
        s.push_back(buf);
        i++;
    }
    std::sort(s.begin(), s.end());
    s.erase(std::unique(s.begin(), s.end()), s.end());

    cout << s.size();
    

}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
ll N,W;
typedef struct it{
  ll weight,cost;
}Item;
ll knapsack(ll n,ll w,Item item[]){
  ll ret=-1;
  ll dp[n+10][w+10];
  for(int i=0;i<n+10;i++)
    for(int j=0;j<w+10;j++)
      dp[i][j]=llINF;
  dp[0][0]=0;
  for(int i=1;i<=n;i++){
    //cout<<item[i-1].weight<<" "<<item[i-1].cost<<endl;
    for(int j=0;j<=w;j++){
      if(dp[i-1][j]!=llINF){
	if(j+item[i-1].weight<=w){
	  dp[i][j+item[i-1].weight]=min(dp[i][j+item[i-1].weight],dp[i-1][j]+item[i-1].cost);
	}
	dp[i][j]=min(dp[i][j],dp[i-1][j]);
      }
    }
  }

  for(ll i=0;i<=w;i++){
    if(dp[n][i]<=W)ret=i;
  }
  return ret;
}
int main(){
  cin>>N>>W;
  Item item[N+10]={};
  for(int i=0;i<N;i++){
    cin>>item[i].cost>>item[i].weight;
  }
  cout<<knapsack(N,100010,item)<<endl;
  return 0;
}


Measured memory_bytes: 86144
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <vector>
using namespace std;

// デバッグ用
#define _DEBUG
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
// ここまで
#define INF 999999999
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))

int main() {
    int N;
    int sum = 0;
    cin >> N;
    vector<int> v;
    vector<int> c;
    REP(i, N) {
        int V;
        cin >> V;
        v.push_back(V);
    }
    REP(i, N) {
        int V;
        cin >> V;
        c.push_back(V);
    }
    REP(i, N) {
        if(v[i] > c[i])
            sum += v[i] - c[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();

    int[] l = new int[N];
    int[] r = new int[N];

    for (int i = 0; i < N; i++) {
      l[i] = sc.nextInt();
      r[i] = sc.nextInt();
    }

    sc.close();

    int count = 0;

    for (int i = 0; i < N; i++) {
      count += r[i] - l[i] + 1;
    }

    System.out.println(count);

  }

}

Measured memory_bytes: 26708
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define PP pair<P,P>
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define mkt make_tuple
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define vecunique(vec) sort(vec.begin(), vec.end());decltype(vec)::iterator result = std::unique(vec.begin(), vec.end());vec.erase(result, vec.end())
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	random_device rnd;
	mt19937_64 mt64(rnd());
	uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt64);
}
/*--------Library Zone!--------*/



int n, k;
int ans;
string s;
int rl = 1;
signed main() {
	cin >> n >> k >> s;
	rep(i, n - 1) {
		if (s[i] == s[i + 1])ans++;
		else rl++;
	}
	if (rl % 2) {
		cout << ans + min(k, rl / 2) * 2 << endl;
	}
	else {
		ans += min(k, rl / 2 - 1) * 2;
		k -= rl / 2 - 1;
		if (k > 0)ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 512
#include<stdio.h>
int main(){
  int a,b,c;
  scanf("%d %d %d",&a,&b,&c);
  if((a==b&&a!=c)||(b==c&&b!=a)||(c==a&&c!=b))printf("2");
  if((a==b)&&(b==c))printf("1");
  if((a!=b)&&(b!=c)&&(c!=a))printf("3");
  return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(s) for s in input().split()]
B = [int(s) for s in input().split()]

ans = 0
for i in range(N):
    cnt0 = min(A[i], B[i])
    A[i] -= cnt0
    B[i] -= cnt0
    ans += cnt0
    cnt1 = min(A[i+1], B[i])
    A[i+1] -= cnt1
    B[i] -= cnt1
    ans += cnt1
print(ans)


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

using namespace std;

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

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

int main(int argc,char* argv[]){
    string s;
    cin >> s;

    set<char> c;
    for(int i=0;i<26;i++){
        c.insert((char)('a'+i));
    }

    bool ans=true;
    for(int i=0;i<s.size();i++){
        if(c.count(s[i]))c.erase(s[i]);
        if(c.empty())ans=false;
    }

    if(ans){
        auto it = c.begin();
        cout << *it << endl;
    }
    else cout << "None" << endl;

    return 0;
}


Measured memory_bytes: 3736
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	N := nextInt()
	K := nextInt()
	if N%K == 0 {
		fmt.Println("0")
	} else {
		fmt.Println("1")
	}
}
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 {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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

const double EPS=1E-12;

int main(){
  int n;
  cin>>n;
  complex<double> a, b, c, d;
  while(n--){
    cin>>a.real()>>a.imag()>>b.real()>>b.imag()>>c.real()>>c.imag()>>d.real()>>d.imag();
    a=a-b;
    c=c-d;
    cout<<(fabs(a.real()*c.imag()-a.imag()*c.real())<=EPS?"YES":"NO")<<endl;
  }

  return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define uii             unordered_map<int,int>
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(x)            int x; cin>>x; while(x--)
void S_K_S()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}
int32_t main()
{
	S_K_S();
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
	cin>>a[i];
	int dp[n];
	int ans=INT_MAX;
	dp[0]=0;
	for(int i=1;i<n;i++){
		int j=min(i,k);
		dp[i]=INT_MAX;
		for(int l=1;l<=j;l++){
			dp[i]=min(dp[i],dp[i-l]+abs(a[i]-a[i-l]));
		}
	}
	cout<<dp[n-1];
}


Measured memory_bytes: 5156
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        if (n == 1) {
            System.out.println("Hello World");
            return;
        }
        if (n == 2) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            System.out.println(a + b);
            return;
        }
    }
}


Measured memory_bytes: 20948
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;
typedef long long ll;

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

int main(){
    string S;
    cin>>S;
    if(S=="ABC")cout<<"ARC"<<endl;
    else cout<<"ABC"<<endl;


return 0;

}

Measured memory_bytes: 3596
#include<stdio.h>
int main()
{
  int a,b[10000],c,d,s,i;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  d=a-1;
  for(i=d;i>=0;i--){
    if (i>0)printf("%d ",b[i]);
    else printf("%d",b[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    string s,t;cin>>s>>t;int ans=0;
    REP(i,3){
        if(s[i]==t[i])ans++;
    }cout<<ans<<endl;
}

int main()
{
    cin.tie(0);
	ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int dig(int n){
  int mod,sum=0;
  while(n){
    mod=n%10;
    sum+=mod;
    n/=10;
  }
  return sum;
}
int main(void){
  int n;
  cin>>n;
  int digit=dig(n);
  if(n%digit==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<limits.h>
#include<vector>
#include<algorithm>
struct P{int x,y;P(int x,int y):x(x),y(y){}};

int D(P a,P b){return abs(a.x-b.x)+abs(a.y-b.y);}
std::vector<P>v[5];
int X=INT_MAX/10;
int F(int n,P s,P g)
{
	std::vector<int>dp[5];
	int i,j,k,res=X;
	for(i=0;i<5;++i)dp[i].resize(v[i].size()),fill(dp[i].begin(),dp[i].end(),X);
	for(i=0;i<dp[(n+1)%5].size();++i)dp[(n+1)%5][i]=D(s,v[(n+1)%5][i]);
	for(k=1;k<4;++k)
	{
		int next=(n+k+1)%5,pre=(n+k)%5;
		for(i=0;i<dp[next].size();++i)for(j=0;j<dp[pre].size();++j)
		{
			dp[next][i]=std::min(dp[next][i],D(v[next][i],v[pre][j])+dp[pre][j]);
		}
	}
	int last=(n+4)%5;
	for(i=0;i<dp[last].size();++i)res=std::min(res,dp[last][i]+D(v[last][i],g));
	return res;
}
int main()
{
	int h,w,sx,sy,gx,gy,i,j,r,a,t;
	char c;
	while(scanf("%d%d",&w,&h),h)
	{
		for(i=0;i<5;++i)v[i].clear();
		for(i=0;i<h;++i)for(j=0;j<w;++j)
		{
			scanf(" %c",&c);
			if(isdigit(c))v[c-'1'].push_back(P(j,i));
			if(c=='S')sx=j,sy=i;
			if(c=='G')gx=j,gy=i;
		}
		r=X;
		for(i=0;i<5;++i)
		{
			t=F(i,P(sx,sy),P(gx,gy));
			if(r>t)r=t,a=i;
		}
		if(r-X)printf("%d %d\n",a+1,r);
		else puts("NA");
	}
	return 0;
}

Measured memory_bytes: 884
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		int ans = 0;
		for(int i=1;i<=N;i++){
			int x = sc.nextInt();
			if(x<(K-x)){
				ans += x * 2;
			}else{
				ans += (K-x) * 2;
			}
		}
		System.out.println(ans);
	}

}


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

#define ll long long int
#define ld long double
#define pb push_back

ll mod = 1000000007;

using namespace std;

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 
	 string str;
	 cin>>str;

	 if(str[0] == str[1])
	 {
	 	cout<<"Bad\n";
	 	return 0;
	 }

	 if(str[2] == str[1])
	 {
	 	cout<<"Bad\n";
	 	return 0;
	 }

	 if(str[2] == str[3])
	 {
	 	cout<<"Bad\n";
	 	return 0;
	 }

	
	cout<<"Good\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int a,b,c,z;
	scanf("%d %d %d",&a,&b,&c);
	if(a > b){
		z = a;
		a = b;
		b = z;
	}
	if(b > c){
		z = b;
		b = c;
		c = z;
	}
	if(a > b){
		z = a;
		a = b;
		b = z;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}


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

int main(){
  int k;
  string s;
  cin >> k;
  cin >> s;
  if(s.size()<=k){
    cout << s;
  }
  else{
    cout << s.substr(0,k) << "...";
  }
  return 0;
}

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

int main() {
    ll N, X, T;
    cin >> N >> X >> T;
    ll ans = (N + X - 1) / X * T;
    cout << ans << endl;
}

Measured memory_bytes: 3620
def gen():
    print("1000 1000")
    print("#"+"."*999)
    for i in range(1000-1):
        print("."*1000)

def main():
    from collections import deque
    import sys
    from heapq import heappush, heappop
    input = sys.stdin.readline
    H, W = map(int, input().split())
    D = [None]*H
    Q = deque()
    for h in range(H):
        D[h] = [10e10]*W
        l = input()
        for w in range(W):
            if l[w] == "#":
                D[h][w] = 0
                Q.append((h, w))
    m = 0
    while Q:
        h, w = Q.popleft()
        alt = D[h][w] + 1
        for dx, dy in [(-1,0), (1,0), (0,-1), (0, +1)]:
            h1, w1 = h+dx, w+dy
            if 0 <= h1 < H and 0 <= w1 < W:
                if D[h1][w1] > alt:
                    D[h1][w1] = alt
                    m = max(m, alt)
                    Q.append((h1, w1))

    print(m)
main()




Measured memory_bytes: 104412
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;

vector<pair<long long, long long>> prime_factorize(long long n) {
    vector<pair<long long, long long>> res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.emplace_back(p, num);
    }
    if (n != 1) res.emplace_back(n, 1);
    return res;
}

int main() {
    int n; cin >> n;
    vector<int> cnt(n + 1, 0);
    for (int i = 1; i <= n; i++) {
        for (auto p : prime_factorize(i)) {
            cnt[p.first] += p.second;
        }
    }
    long long ans = 1;
    for (int i = 0; i <= n; i++) {
        (ans *= (cnt[i] + 1)) %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val n = s.length + 1
    val lw = Array(n - 1) {0}
    val gr = Array(n - 1) {0}
    for (i in s.indices) {
        if (s[i] == '<') {
            lw[i] = (if(i > 0) lw[i - 1] else 0) + 1
        }
    }
    for (i in s.length - 1 downTo 0) {
        if (s[i] == '>') {
            gr[i] = (if(i < n - 2) gr[i + 1] else 0) + 1
        }
    }

    println((0 until n).map {
        Math.max(
            if (it > 0) lw[it - 1].toLong() else 0L,
            if (it < n - 1) gr[it].toLong() else 0L)
    }.sum())
}

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

using namespace std;

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

    vector<int> apple(N);
    unsigned int min_abs = -1;
    int total = 0;
    int min_index = -1;
    for (int i = 0; i < N; i++) {
        apple[i] = L+i;
        total += apple[i];
        if (min_abs > abs(apple[i])) {
            min_abs = abs(apple[i]);
            min_index = i;
        }
    }

    cout << total - apple[min_index] << endl;

    return 0;
}


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

namespace AtCoder
{
	class Program
	{
		static void Main(string[] args)
		{
			var Instance = new Question();
			Instance.Exec();
		}
	}

	public class Question
	{
		public void Exec()
		{
			long h = -1;
			long w = -1;
			List<long[]> hwlist = new List<long[]>();

			while (h != 0 && w != 0) {
				var array = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
				h = array[0];
				w = array[1];
				if (h == 0 && w == 0) {
					break;
				}

				hwlist.Add(new[] { h, w });
			}

			foreach (var item in hwlist) {
				for (int i = 0; i < item[0]; ++i) {
					for (int j = 0; j < item[1]; ++j) {
						if ((i % 2 == 0 && j % 2 == 1) || (i % 2 == 1 && j % 2 == 0)) {
							Console.Write(".");
						} else {
							Console.Write("#");
						}
					}
					Console.WriteLine("");
				}

				Console.WriteLine("");
			}

			Console.ReadKey();
		}
	}
}


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

int main(){
    int N, K; cin >> N >> K;
    vector<int> H(N),dp(N,1000000000);
    for( int &k : H ) cin >> k;
    dp[0] = 0;

    for( int i = 0; i < N; i++ ){
        for( int j = 1; j <= K; j++ ){
            if( i + j >= N ) break;
            dp[i+j] = min(dp[i+j], dp[i] + abs(H[i+j] - H[i]));
        }
    }

    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
package main

import "fmt"

func main() {
	var n, y int
	fmt.Scan(&n, &y)

	for i := 0; i <= n; i++ {
		for j := 0; j <= n-i; j++ {
			k := n - i - j
			if y == 10000*i+5000*j+1000*k {
				fmt.Println(i, j, k)
				return
			}
		}
	}
	fmt.Println(-1, -1, -1)
}


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

int main(){
    int n;
    cin >> n;
    int num;
    vector<int>ans;
    
    for(int i = 0;i < n;i++){
        cin >> num;
        if(i%2 == 0){
            ans.push_back(num);
        }else{
            ans.insert(ans.begin(),num);
        }
    }
    

    int check = (int)ans.size();
    if((check % 2) == 0){
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i];
            if(i != ans.size()-1){
                cout << " ";
            }
        }
    }else{
        for(int i = check-1; i >= 0; i--){
            cout << ans[i];
            if(i != 0){
                cout << " ";
            }
        }
    }
    
    cout << "\n";
    return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()

int main(){
	int d;
	while(~scanf("%d",&d)){
		int sum = 0;
		for(int i=0; i<600; i+=d){
			sum += i*i*d;
		}
		printf("%d\n",sum);
	}
	return 0;
}

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

vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}

void Main()
{
  ll N, K; cin >> N >> K;
  vector<ll> A(N);
  rep(i,N) cin >> A[i];
  unordered_map<ll,ll> umap;
  ll curCity = 1;
  ll cnt = 0;
  while (umap.find(curCity) == umap.end() && cnt < K) {
    umap[curCity] = cnt;
    cnt++;
    curCity = A[curCity-1];
  }
  if (cnt == K) {cout << curCity << endl; return;}
  ll res = (K-umap[curCity])%(cnt - umap[curCity]);
  ll newCity = curCity;
  rep(i,res) {
   newCity = A[newCity-1];
  }
  cout << newCity << endl;
}

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


Measured memory_bytes: 11852
#include<stdio.h>

int main(void)
{
    int N,i,j,flag,count;
    
        scanf("%d",&N);
        int A[N];
        for(i=0;i<N;i++)
        {
            scanf("%d",&A[i]);
        }

        flag=1;
        count=0;
        while(flag)
        {
            flag=0;
            for(j=N-1;j>0;j--)
            {
                if(A[j]<A[j-1])
                {
                    int a=A[j];
                    A[j]=A[j-1];
                    A[j-1]=a;
                    flag=1;
                    count++;
                }
            }
        }
        
        
        for(i=0;i<N;i++)
        {
            printf("%d",A[i]);
            if(i==N-1) printf("\n");
            else printf(" ");
        }
        printf("%d\n",count);

}



Measured memory_bytes: 1992
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const ll INFL = (1LL << 60);
 const int INFI = (1 << 30);

 int main() {
   int K, A, B; cin >> K >> A >> B;

   string ans = "NG";
   if (A % K == 0) ans = "OK";
   else if ((A / K + 1) * K <= B) ans = "OK";
   cout << ans << endl;
 }


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

using namespace std;

signed main()
{
    int n, m, k;
    cin >> n >> m >> k;
    for(int a = 0; a <= n; a++)
        for(int b = 0; b <= m; b++)
            if(k == a * m + b * n - 2 * a * b)
            {
                cout << "Yes" << endl;
                return 0;
            }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int max = 100000001;
		boolean [] sosuu = new boolean [max];
		int [] n = new int [10000];
		int count = 0;
 
		for (int i = 1; i <= max - 1; i++) {
			sosuu[i] = true;
		}
		sosuu[0] = false;
		sosuu[1] = false;
 
		for (int i = 2; i <= Math.sqrt(max); i++) {
			if (sosuu[i] == true) {
				for (int j = i + i; j <= max - 1; j += i) {
					sosuu[j] = false;
				}
			}
 
		}
 
		Scanner cin = new Scanner (System.in);
		int x = cin.nextInt();
 
		for (int i = 0; i < x; i++) {
			n[i] = cin.nextInt();
			if (sosuu[n[i]] == true) count++;
		}
 
		System.out.println(count);
	}
 
	//private static void sosuulist() {
	//	
	//}
}

Measured memory_bytes: 140280
# AOJ 0082 Flying Jenny
# Python3 2018.6.21 bal4u


h = [4,1,4,1,2,1,2,1,4,1,4,1,2,1,2,1]
d = [41412121, 14121214, 41212141, 12121414, 21214141, 12141412, 21414121, 14141212]

while 1:
	try: p = list(map(int, input().split()))
	except: break
	max, id = 0, 3
	for i in range(8):
		c = 0
		for j in range(8):
			if p[j] >= h[i+j]: c += h[i+j]
			else: c += p[j]
		if max < c: max, id = c, i
		elif max == c and d[id] > d[i]: id = i
	print(*list(str(d[id])))



Measured memory_bytes: 5608
import java.util.Scanner;

class Main {
    static final Scanner IN = new Scanner(System.in);
    static final String S = IN.next();
    public static void main(String... args) {
        if (S.matches("A[a-z]+C[a-z]+")) {
            puts("AC");
        } else {
            puts("WA");
        }
    }
    static <T> void puts(T arg) { System.out.println(arg);}
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
    return string(1, val);
}

int main(){
    vector<vector<int>> c(3, vector<int>(3));
    REP(i, 3) {
        REP(k, 3) {
            cin >> c[i][k];
        }
    }

    string res = "Yes";

    if(c[1][0] - c[0][0] == c[1][1] - c[0][1] &&
    c[1][0] - c[0][0] == c[1][2] - c[0][2]) {
    } else {
        res = "No";
    }

    if(c[2][0] - c[1][0] == c[2][1] - c[1][1] &&
    c[2][0] - c[1][0] == c[2][2] - c[1][2]) {
    } else {
        res = "No";
    }

    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
bool comp(int a,int b)
{
    return a>b;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n,k;
    cin>>n>>k;

    n=min(n%k,k-n%k);
    cout<<n;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int sz=2e6+9;
string s;
int ans;

int main(){
	cin>>s;
	int n=s.size();
	for(int i=0;i<n/2;i++) ans+=(s[i]!=s[n-i-1]);
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	var n int
	fmt.Scan(&n)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	l := make([]int, n, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		tmp, _ := strconv.Atoi(sc.Text())
		l[i] = tmp
	}

	sort.Ints(l)

	answer := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a := l[i]
			b := l[j]
			k := sort.SearchInts(l, a+b)
			if k > j {
				answer += k - (j + 1)
			}
		}
	}
	fmt.Println(answer)
}


Measured memory_bytes: 640
#include<cstdio>
int a[233333];
inline int read()
{
	register char ch;register bool aa=1;
	while(ch=getchar(),ch>57||ch<48)ch=='-'?aa=0:0;register int x=ch^48;
	while(ch=getchar(),ch>47&&ch<58)x=x*10+(ch^48);
	return aa?x:-x;
}
int gcd(int a,int b)
{
	return b?gcd(b,a%b):a;
}
int abs_(int x)
{
	return x>0?x:-x;
}
int main()
{
	register int n=read(),k=read(),ans;
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		a[i]=abs_(a[i]-k);
	}
	ans=a[1];
	for(int i=2;i<=n;i++)
		ans=gcd(a[i],ans);
	return!printf("%d",ans);
}

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

int main(void){
   string s,t;
   cin>>s>>t;
   int count=0;
   for(int i=0;i<s.size();i++){
      if(s[i]==t[i]) count++;
   }
   if(count==s.size()) cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   return 0;
}



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


int main(){
    
    ll N, C, K;
    cin >> N >> C >> K;
    vector<ll>T(N);
    for(int i = 0; i < N; i++)cin >> T[i];
    sort(T.begin(), T.end());
    ll ans = 0;
    for(ll l = 0; l < N; l++){
        ll r = l;
        for(;;r++){
            if(r + 1 == N)break;
            if(r + 1 - l + 1 > C)break;
            if(T[r + 1] > T[l] + K)break;
        }
        ans++;
        l = r;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024