akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  map<int, int> m;
  REP(i, 0, n) {
    int a;
    cin >> a;

    ++m[a];
    ++m[a - 1];
    ++m[a + 1];
  }
  int ma = 0;
  for (auto c : m) {
    if(c.second>ma){
      ma = c.second;
    }
  }
  cout << ma << endl;

  return 0;
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

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

  rep(i,a,b+1) {
    if (i%k==0) return cout << "OK\n", 0;
  }

  cout << "NG\n";
}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
//素因数分解
map<ll,ll> get_div(ll n){
    map<ll,ll> div;
    ll num = n;
    for (ll i=2; i * i < n; i++)
    {
        while(num%i==0){
            div[i]++;
             num /= i;
             }
    }
    if(num>1)
        div[num]++;

    return div;
}

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n;
cin>>n;
map<ll,ll> div=get_div(n);
ll ans=0;
for(auto v:div){
    int a=1;
    while(a<=v.second){
        v.second-=a;
        a++;
        ans++;
    }
}
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3660
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cstring>
using namespace std;
int main(){
    int n;
    cin >> n;
    int in[n][26];
    memset(in,0,sizeof(in));
    for(int i=0;i<n;i++){
        string s;
        cin >> s;
        for(int j=0;j<s.size();j++){
            in[i][(int)(s[j]-'a')] ++;
        }   
    }
    /*for(int i=0;i<n;i++){
        for(int j=0;j<26;j++){
            cout <<i << " " << j << " " <<  in[i][j] << endl;
        }
    }*/
    for(int j=0;j<26;j++){
        int ans = 5000;
        for(int i=0;i<n;i++){
            if(ans >in[i][j]){
                ans = in[i][j];
            }
        }
       // cout << j << " " << ans[j] << endl;
        for(int i=0;i<ans;i++){
            cout << (char)(j+'a');
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i, n) for (ll i = 1; i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
void Main()
{
    ll n;
    cin >> n;

    ll res = 0;
    for (ll j= 1; j <= n; j++){
        // sum of (j, 2j, 3j, ..., [n/j]*j)
        ll m = n/j;
        res += j * m * (1 + m) / 2;
    }

    put(res);
}
signed main(){ Main();return 0;}

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

int main() {
    string s;
    cin >> s;
    int c1 = 0;
    int n = s.size();
    string t = s;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == '0' && s[i] == '0') {
            c1++;
            s[i] = '1';
        } else if (s[i - 1] == '1' && s[i] == '1') {
            c1++;
            s[i] = '0';
        }
    }
    cout << c1 << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

string board[12];
const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
const int H = 12;
const int W = 6;

void print_board()
{
  for (int y = 0; y < H; y++) {
    for (int x = 0; x < W; x++)
      cout << board[y][x];
    cout << endl;
  }
  cout << endl;
}


int dfs(int x, int y, bool flag)
{
  char ch = board[y][x];
  int ret = 1;

  board[y][x] = '.';
  for (int i = 0; i < 4; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    
    if (nx < 0 || nx >= W || ny < 0 || ny >= H)
      continue;
    
    if (flag && board[ny][nx] == 'O') {
      board[ny][nx] = '.';
      ret++;
    }

    if (board[ny][nx] == ch)
      ret += dfs(nx, ny, flag);
  }
  if (!flag)
    board[y][x] = ch;
  
  return ret;
}

void drop()
{
  for (int x = 0; x < W; x++) {
    int s, i;
    s = i = H - 1;
    while (s >= 0) {
      if (board[s][x] != '.') {
	swap(board[s][x], board[i][x]);
	i--;
      }
      s--;
    }
  }
}

int main()
{
  int T;
  
  cin >> T;
  while (T--) {
    // Input
    for (int i = 0; i < H; i++)
      cin >> board[i];

    int ans = 0;
    while (true) {
      bool flag = false;

      for (int y = 0; y < H; y++) 
	for (int x = 0; x < W; x++)
	  if (board[y][x] != '.' && board[y][x] != 'O')
	    if (dfs(x, y, false) > 3) {
	      flag = true;
	      dfs(x, y, true);
	    }

      if (!flag)
	break;
      drop();
      ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1208
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>

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

#define REP(var,n) for(int var=0;var<(n);var++)
#define REPP(var,n) for(int var=1;var<(n);var++)
#define ALL(c) (c).begin(),(c).end()
#define PRIN(var) cout << "---------------------" << var << "------------------------------" << endl;


int main(){
    int N,M;
    vector<P> ab;
    //N: the number of island
    //M: the number of bulidge
    cin >> N >> M;
    
    REP(i,M){
        int a,b;
        cin >> a >> b;
        ab.push_back(make_pair(b,a)); 
    }
    sort(ab.begin(), ab.end());

    int ans=0, t=0;

    REP(i,ab.size()){
        if(t<=ab[i].second){
            t = ab[i].first;
            ans++;
        }
    }
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep3(i, s, n) for (int i = (s); i <= (int)(n); i++)
int rcv[3005][3005];
long long p[3005][3005][4];
 
int main() {
	int R;
	int C;
	int K;
	int x;
	int y;
	int z;
	long long zz;
	long long ans;
 
 
	cin >> R >> C >> K;
 
 
	rep(i, R+2){
		rep(j, C+2){
			rcv[i][j]=0;
			rep(kk, 4) p[i][j][kk]=0;
		}
	}
 
	rep3(i, 1, K) {
		cin >> x >> y >> z;
		rcv[x][y]=z;
	}
 
	rep3(i, 1, R) {
		rep3(j, 1, C) {
			zz=rcv[i][j];
			p[i][j][3]=max(p[i][j][3],p[i][j][2]+zz);
			p[i][j][2]=max(p[i][j][2],p[i][j][1]+zz);
			p[i][j][1]=max(p[i][j][1],p[i][j][0]+zz);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][0]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][1]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][2]);
			p[i+1][j][0]=max(p[i+1][j][0],p[i][j][3]);
			p[i][j+1][0]=max(p[i][j+1][0],p[i][j][0]);
			p[i][j+1][1]=max(p[i][j+1][1],p[i][j][1]);
			p[i][j+1][2]=max(p[i][j+1][2],p[i][j][2]);
			p[i][j+1][3]=max(p[i][j+1][3],p[i][j][3]);
		}
	}
	ans=max(p[R][C][0],p[R][C][1]);
	ans=max(ans,p[R][C][2]);
	ans=max(ans,p[R][C][3]);
	cout << ans << endl;
}

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

using namespace std;

unordered_map<int,vector<int>> graph;
vector<int> visited(200005);

int dfs(int i) {
    int conn = 1;
    for(int j = 0; j < graph[i].size(); j++) {
        if(!visited[graph[i][j]]) {
            visited[graph[i][j]] = 1;
            conn += dfs(graph[i][j]);
        }
    }
    return conn;
}

int main() {
    int n,m;
    cin>>n>>m;
    for(int i = 0; i < m; i++) {
        int x,y;
        cin>>x>>y;
        graph[x].push_back(y);
        graph[y].push_back(x);
    }
    int ans = INT_MIN;
    for(int i = 1; i <= n; i++) {
        if(!visited[i]) {
            visited[i] = 1;
            int temp = dfs(i);
            ans = max(ans, temp);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 34152
import sys

readline = sys.stdin.buffer.readline


def main():
    N, K = map(int, readline().split())
    X = list(map(int, readline().split()))

    if N == 1:
        print(abs(X[0]))
        sys.exit()

    dm = 10**9
    for i in range(0, N-K+1):
        d = X[i+K-1] - X[i] + min(abs(X[i+K-1]), abs(X[i]))
        if d < dm:
            dm = d

    print(dm)


main()


Measured memory_bytes: 12492
s = str(input())
ans1=0
for i in range(len(s)):
  if(i%2==0 and s[i]!='0'):ans1+=1
  if(i%2==1 and s[i]!='1'):ans1+=1
ans2=0
for i in range(len(s)):
  if(i%2==0 and s[i]!='1'):ans2+=1
  if(i%2==1 and s[i]!='0'):ans2+=1
ans=min(ans1,ans2)
print(ans)


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


int main() {
  int n;
  cin >> n;
  bool ch=true;
  rep(i,n+1){
    if((int)((double)i*1.08)==n){
      cout<<i<<endl;
      ch=false;
    }
  }
  if(ch){
    cout<<":("<<endl;
  }
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int n ;
  cin >> n;
  int m=n;
  int ans = 0;
  while( m !=0){
    ans += m%10;
    m /=10;
  }
  cout << (n%ans ==0 ? "Yes":"No");
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,m,i,j,e,mi,min,a,b,o;
  while(scanf("%d %d",&n,&m),n||m){
    int d[110][110]={0};
    while(m--){
      scanf("%d",&o);
      if(o){
	scanf("%d %d %d",&a,&b,&e);
	if(d[a][b]==0||d[a][b]>e)d[a][b]=d[b][a]=e;
      }
      else{
	int c[110]={0};
	int f[110]={0};
	scanf("%d %d",&mi,&e);
	for(i=0;i<n;i++){
	  f[mi]=1;
	  for(j=1;j<=n;j++){
	    if(d[mi][j]==0||f[j])continue;
	    if(c[j]==0||c[j]>c[mi]+d[mi][j])c[j]=c[mi]+d[mi][j];
	  }
	  min=2100000000;
	  for(j=1;j<=n;j++){
	    if(f[j]||c[j]==0)continue;
	    if(min>c[j])min=c[mi=j];
	  }
	}
	if(c[e]==0)printf("-1\n");
	else       printf("%d\n",c[e]);
      }
    }
  }
  return 0;
}

Measured memory_bytes: 668
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int N;
ll A, B;
int X[100005];

int main(int argc, char const *argv[]) {
	cin >> N >> A >> B;
	ll cur, past, res = 0;
	for (int i = 0; i < N; i++) cin >> X[i];


	for (int i = 1; i < N; i++) {
		ll dif = X[i] - X[i-1];
		res += min(dif * A, B);
	}
	// cin >> cur;
	// past = cur;
	// for (int i = 1; i < N; i++) {
	// 	cin >> cur;
	// 	ll hirou = (cur - past) * A;
	// 	if (hirou < B) res += hirou;
	// 	else res += B;
	// 	past = cur;
	// }
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
bool debug = false;

int main() {
  uint64_t Ans = 0;  // 回答：

  uint64_t N; cin >> N; // ボールの個数
  map<uint64_t,uint64_t> M; // ボールの数字毎の個数
  vector<int> A(N);
  for(uint64_t i =0;i<N;i++){
    cin >> A.at(i);
    M[A.at(i)]++;   // ボールの数字毎の個数を足しておく。
  }

  uint64_t P1 = 0;
  for(auto m:M){  // ボールを取り除かない場合の、パターン数を出しとく。
    if (m.second >=2){
      P1 += ( m.second * (m.second-1)) /2 ;
    }
  }

  for(uint64_t i =0;i<N;i++){   // i 番目のボールを取り除く
    if( M[A.at(i)] >= 2 ){  // 該当のボールの数字が２つ以上に書かれている場合
      // 引く数：P * (P-1) /2 
      // 足す数：(P-1) * (P-2) /2 
      // → -P*(P-1)/2 + (P-1)(P-2)/2 = 1/2 * (P-1)(P-2-P) = 1-P
      Ans = P1 - M[A.at(i)] + 1;
    } else {
      Ans = P1;
    }
    cout << Ans << endl;
  }

}

Measured memory_bytes: 10240
s = input()[::-1]
size = len(s)
s += "4"

a, b = 0, 0

for i in range(size):
    v1, v2 = int(s[i]), int(s[i+1])
    if v1+b>=6 or (v1+b>=5 and v2>=5):
        a += 10-v1-b
        b = 1
    else:
        a += v1+b
        b = 0

print(a+b)


Measured memory_bytes: 62320
import itertools

num_list = input()
rule = '+-'

for ops in itertools.product(rule, repeat=3):
    ans = '{}{}{}{}{}{}{}'.format(num_list[0], ops[0], num_list[1], ops[1], num_list[2], ops[2], num_list[3])
    res = eval(ans)
    if res == 7:
        print('{}=7'.format(ans))
        break


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define inf (int)(1e9)

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

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

int main(){
	int N, i, evensum = 0, oddsum = 0;
	scanf("%d", &N);
	int *a = (int *)malloc(sizeof(int) * N);
	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		if(i % 2 == 0){
			evensum += a[i];
		}
		else{
			oddsum += a[i];
		}
	}
	if(N % 2 == 0){
		printf("%d %d\n", max(evensum, oddsum), min(evensum, oddsum));
		return 0;
	}
	int *dp = (int *)malloc(sizeof(int) * ((N + 1) / 2));
	dp[0] = a[0];
	int l = -inf, h, r = inf;
	while(r - l > 1){
		h = (l + r) / 2;
		for(i = 1; 2 * i < N; i++){
			dp[i] = dp[i - 1] + a[2 * i] - a[2 * i - 1];
			if(dp[i - 1] >= h){
				dp[i] = max(dp[i], a[2 * i]);
			}
		}
		if(dp[N / 2] >= h){
			l = h;
		}
		else{
			r = h;
		}
	}
	int ans = max(evensum, oddsum + l);
	printf("%d %d\n", ans, evensum + oddsum - ans);
	return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll n, m, k, a, b, found, found1;
vi adjList[100001];
int visited[100001];
vi ans, ans1;

void dfs(int x, vi& ans){
    if(!found){
        visited[x] = 1;
        ans.pb(x);
        int finished = 1;
        for(int i = 0; i < adjList[x].size(); i++){
            if(!visited[adjList[x][i]]){
                finished = 0;
                dfs(adjList[x][i], ans);
            }
        }
        if(finished){
            found = 1;
        }
    }
}
void dfs1(int x, vi& ans){
    if(!found1){
        visited[x] = 1;
        ans.pb(x);
        int finished = 1;
        for(int i = 0; i < adjList[x].size(); i++){
            if(!visited[adjList[x][i]]){
                finished = 0;
                dfs1(adjList[x][i], ans);
            }
        }
        if(finished){
            found1 = 1;
        }
    }
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        adjList[a].pb(b);
        adjList[b].pb(a);
    }
    if(adjList[1].size() == 1){
        dfs(1, ans);
        cout << ans.size() << endl;
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i] << " ";
        }
    }
    else{
        dfs(1,ans);
        for(int i = 1; i < adjList[1].size(); i++){
            if(!visited[adjList[1][i]]){
            dfs1(adjList[1][i], ans1);
            }
        }
        cout << ans.size() + ans1.size() << endl;
        for(int i = ans.size() - 1; i >= 0; i--){
            cout << ans[i] << " ";
        }
        for(int i = 0; i < ans1.size(); i++){
            cout << ans1[i] << " ";
        }
    }
}


Measured memory_bytes: 11512
package main

import (
	"fmt"
	"math"
)

func main() {
	// 入力の受け取り
	var N, K int
	fmt.Scanf("%d%d", &N, &K)
	xs := make([]int, N)

	for i := 0; i < N; i++ {
		var c int
		fmt.Scanf("%d", &c)
		xs[i] = c
	}

	allPosi := xs[0] >= 0
	allNega := xs[len(xs)-1] < 0

	// 処理
	minDist := math.MaxInt64

	if allPosi {
		minDist = xs[K-1]
	} else if allNega {
		minDist = abs(xs[len(xs)-K])
	} else {
		for l := 0; l < N-K+1; l++ {
			r := l + K - 1
			dist := abs(xs[l]-xs[r]) + min(abs(xs[l]), abs(xs[r]))
			minDist = min(minDist, dist)
		}

	}
	fmt.Printf("%d", minDist)
}

func min(x int, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

func abs(x int) int {
	if x < 0 {
		return -x
	} else {
		return x
	}
}


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

using namespace std;
#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
using lint=long long;
typedef pair<int,int> P;
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  string s;cin>>s;
  int n=s.length();
  int rem=0;
  if(s[0]==s[n-1])++rem;
	if((n-rem)%2==1){
        cout<<"First"<<endl;
    }
    else{
        cout<<"Second"<<endl;
    }
  return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
queue<int> qT,QT;
queue<string> qN,QN;
/*	q.empty();q.size();q.pop();q.front();q.push();q/back();*/
void init(){
	while(!qN.empty()){
		qN.pop();
	}
	while(!qT.empty()){
		qT.pop();
	}
	while(!QN.empty()){
		QN.pop();
	}
	while(!QT.empty()){
		QT.pop();
	}
}
int main(){
	int n,q;
	cin>>n>>q;
	string name;
	int time,cnt=0;
	for(int i=0;i<n;i++){
		cin>>name>>time;
		qN.push(name);
		qT.push(time);
	}
	string tmpN;
	int tmpT;
	while(!qT.empty()){
		tmpN = qN.front();
		qN.pop();
		tmpT = qT.front();
		qT.pop();
		
		if(tmpT<=q){
			cnt+=tmpT;
			tmpT=cnt;
			QT.push(tmpT);
			QN.push(tmpN);
		}
		else{
			tmpT=tmpT-q;
			cnt+=q;
			qT.push(tmpT);
			qN.push(tmpN);
		}
	}
	while(!QT.empty()){
		cout<<QN.front()<<" "<<QT.front()<<endl;
		QN.pop();
		QT.pop();
	} 
	return 0;
}


Measured memory_bytes: 5604
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define mod 1000000007
#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define REP(i,a,b) for(int i=a;i<b;i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    FASTIO
    int a,b,c,k,ans=0;
    cin>>a>>b>>c>>k;
    if(a>=k&&a)
        ans+=k;
    else{
        ans+=a;k-=a;
        if(b>=k&&b) k=0;
        else{
            k-=b;
            ans-=k;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <utility>
#include <map>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <array>
#include <math.h>
#include <numeric>
#include <sstream>
typedef long long ll;
using namespace std;
int main(int argc, char const *argv[]) {
    string s, t;
    cin >> s >> t;
    bool br = false;
    for (int i = s.length()-t.length(); i >= 0; --i) {
        bool match = true;
        for (int j = 0; j < t.length(); ++j) if(t[j] != s[i+j] && s[i+j] != '?') match = false;
        if (match) {
            for (int j = 0; j < t.length(); ++j) s[i+j] = t[j];
            br = true;
        }
        if (br) break;
    }
    if (!br) {
        cout << "UNRESTORABLE" << std::endl;
            return 0;
    }
    for (int i = 0; i < s.length(); ++i) if (s[i] == '?') s[i] = 'a';
    cout << s << std::endl;
    return 0;
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll L,R,d;
    cin >> L >> R >> d;
    ll ans = 0;
    rep(i,L,R+1){
        if(i % d == 0) ans++;
    }
    print(ans);

    

}

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

Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans;
int work(int a,int k)
{
	while(1)
	{
		if(a%k==0)return a/k;
		if(a<k)return 0;
		int b=a/k*k,c=a/k;
		a-=(a-b+c)/(c+1)*(c+1);
	}
}
int main()
{
	scanf("%d",&n);
	int x,y;
	for(int i=1;i<=n;++i)scanf("%d %d",&x,&y),ans^=work(x,y);
	if(ans)printf("Takahashi");
	else printf("Aoki");
	return 0;
}

Measured memory_bytes: 256
import Data.List(sort)
-- after editorial
main = do
    n <- readLn
    ai <- (fmap read . words) <$> getLine
    let i = iterate (+1) 1
    let bi = zipWith (-) ai i
    let bi' = sort bi
    let b = bi'!!(div n 2)
    print $ sum $ fmap (abs.subtract b) bi


Measured memory_bytes: 109564
#include <bits/stdc++.h>
using namespace std;
int n;
int tt;
long long ans = 0;
int cal(int x,int y)
{
	int yy = 0;
	int k = 1;
	for(int i = 1;i<= n;i++)
	{
		if(i / (k * 10))k *= 10;
		if(i % 10 == y && i / k == x)yy++;
	}
	return yy;
}
int mk[20][20];
int csl(int x)
{
	int t1 = 1;
	int ttt = x;
	while(ttt)
	{
		t1 *= 10;
		ttt /= 10;
	}
	t1 /= 10;
	return mk[x % 10][x / t1];
}
int main()
{
	scanf("%d",&n);
	for(int i = 1;i <= 9;i++)
	{
		for(int j = 1;j <= 9;j++)
			mk[i][j] = cal(i,j);
	}
	for(int i = 1;i <= n;i++)
	{
		ans += csl(i);
	}
	printf("%lld",ans);
	return 0;
}

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	repi(i,a,b+1){
		if(i%k==0){
			cout<<"OK"<<endl;
			return 0;
		}
	}
	cout<<"NG"<<endl;
	return 0;
}

Measured memory_bytes: 3608
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    int ans = 1;
    for(int i=1; i*i<=m; ++i){
        if(m % i == 0){
            if(i >= n)
                ans = max(ans, m / i);
            if(m / i >= n)
                ans = max(ans, i);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
H, W = list(map(int, input().split()))
S = ['.'*(W+2)]
for _ in range(H):
  S.append('.' + input() + '.')
S.append('.'*(W+2))

for h in range(1,H+1):
  for w in range(1,W+1):
    if S[h][w] == '#':
      if '#' not in [S[h-1][w], S[h][w-1], S[h][w+1], S[h+1][w]]:
        print('No')
        exit()
print('Yes')

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

int main(){
	string s1,s2;
	getline(cin,s1);
	getline(cin,s2);
	int i,j;
	if(s1.size()>s2.size()){
		cout<<"GREATER";
	}else if(s1.size()<s2.size()){
		cout<<"LESS";
	}else{
		for(i=0;i<s1.size();i++){
			if(s1[i]>s2[i]){
				cout<<"GREATER";
				return 0;
			}else if(s1[i]<s2[i]){
				cout<<"LESS";
				return 0;
			}
		}
		cout<<"EQUAL";
	}
	return 0;
}


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

int a,b,c,d,e;

int main(){
    while(cin>>a>>b){
        c = a+b;
        d = a-b;
        e = a*b;

        c = max(c,d);
        c = max(c,e);

        cout<<c<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>

using namespace std;

using ll = long long;
using ld = long double;

//const int inf=1<<29;
constexpr ll inf = ((1<<30)-1)*2+1;
const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const double eps=1e-15;
const ll MOD = 1000000007;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define repi(it,ar) for(auto it = ar.begin(), end = ar.end(); it != end;++it)
#define repa(n,ar) for(auto &n : (ar))

#define dec(n) fixed<<setprecision(n)
#define zfl(n)  setfill(‘0’) << setw(n)
#define debug(x) cerr << #x << ": " << (x) << endl

int n;

ld x[100], y[100], d[100];

ld norm(ld p) {
    ld s = 0;
    rep(i, n)s += pow(d[i], p);
    return pow(s, 1/p);
}

signed main(){
	cin.tie(nullptr);
	cout.tie(nullptr);
	ios::sync_with_stdio(false);
	
	cin>>n;
	rep(i, n)cin>>x[i];
	rep(i, n)cin>>y[i];
	rep(i, n)d[i] = abs(x[i]-y[i]);
	
	cout<<dec(6);
	rep(i, 3)cout<<norm(i+1)<<endl;
	
	ld m = 0.0;
	rep(i, n) if(m < d[i])m = d[i];
	cout<<m<<endl;
	
	return 0;
}



Measured memory_bytes: 3484
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] nx = sc.nextLine().split(" ");
        int n = Integer.parseInt(nx[0]);
        long x = Long.parseLong(nx[1]);

        List<Long> burger = new ArrayList<>();
        List<Long> putty  = new ArrayList<>();
        burger.add(1L);
        putty.add(1L);
        for (int i = 0; i < n; i++) {
            burger.add(2 * burger.get(i) + 3);
            putty.add(2 * putty.get(i) + 1);
        }

        System.out.println(fnx(n, x, burger, putty));
    }

    public static long fnx(int n, long x, List<Long> a, List<Long> p) {
        if (n == 0) {
            return (x <= 0) ? 0 : 1;
        }
        if (x <= a.get(n - 1) + 1) {
            return fnx(n - 1, x - 1, a, p);
        }
        if (x == a.get(n - 1) + 2) {
            return p.get(n - 1) + 1;
        }
        if (a.get(n - 1) + 2 < x && x <= a.get(n) + 2) {
            return p.get(n - 1) + 1 + fnx(n - 1, x - 2 - a.get(n - 1), a, p);
        }
        return 2 * p.get(n - 1) + 1;
    }
}

Measured memory_bytes: 23636
n, a, b = STDIN.gets.split(" ").map { |i| i.to_i }
xs = STDIN.gets.split(" ").map { |i| i.to_i }
dists = []
xs.each_cons(2) { |a, b|
  dists.push(b - a)
}

result = dists.inject(0) { |acc, dist|
  acc + [a * dist, b].min
}

print(result)

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

int main(){
  int n, i, j;
  char s[200001][11];
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%s", s[i]);

  qsort(s, n, 11, strcmp);

  int counter = 1;
  for(i=1; i<n; i++){
    if(strcmp(s[i-1], s[i]) != 0) counter++;
  }

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


Measured memory_bytes: 5684
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<int> a(4);
  rep(i, 4) {
    char c;
    cin >> c;
    a[i] = c-'0';
  }
  rep(i, 2) rep(j, 2) rep(k, 2) {
    int num = a[0];
    if (i) num -= a[1];
    else num += a[1];
    if (j) num -= a[2];
    else num += a[2];
    if (k) num -= a[3];
    else num += a[3];
    if (num == 7) {
      cout << a[0];
      if (i) cout << '-';
      else cout << '+';
      cout << a[1];
      if (j) cout << '-';
      else cout << '+';
      cout << a[2];
      if (k) cout << '-';
      else cout << '+';
      cout << a[3] << "=7\n";
      return 0;
    }
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

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

	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}

	for i := 0; i < n-2; i++ {
		if (p[i] > p[i+1] && p[i+1] > p[i+2]) || (p[i] < p[i+1] && p[i+1] < p[i+2]) {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
int main() {
    int N; 
    cin >> N; 
	int A[200010] = {}; 
	int B[200010] = {};
	for(int i = 0; i < N; i++){
		cin >> A[i]; 
	}
	for(int i = 0; i < N; i++){
		cin >> B[i]; 
	}
	int C[200010] = {}; 
	int ans = 0; 
	for(int d = 1; d <= 29; d++){
		for(int i = 0; i < N; i++){
			C[i] = B[i] % (1 << d); 
		}
		sort(C, C+N); 
		int count = 0; 
		for(int i = 0; i < N; i++){
		int P = lower_bound(C, C+N, (1 << d) - (A[i] % (1 << d))) - C; 
		int Q = lower_bound(C, C+N, (1 << (d-1)) - (A[i] % (1 << d))) - C; 
		int R = lower_bound(C, C+N, (1 << (d+1)) - (A[i] % (1 << d))) - C; 
		int S = lower_bound(C, C+N, (1 << (d-1)) * 3 - (A[i] % (1 << d))) - C; 
		count += ((2 + P % 2 + R % 2 - Q % 2 - S % 2) % 2); 
		}
	ans += (count % 2) * (1 << (d-1)); 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 2560
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);       
        String s = sc.next();
        int ans = 0;
        int count = 0;        
        for(int i=0;i<s.length();i++){
          if(s.charAt(i)=='A'||s.charAt(i)=='T'||s.charAt(i)=='G'||s.charAt(i)=='C')
          {count++;}
          else{ans=Math.max(ans,count);
               count=0;}
        }	       
        System.out.println(Math.max(ans,count));
  }
}

Measured memory_bytes: 25044
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int ans=INT_MAX;
    string s;
    cin>>s;
    for(int i=0; i<=s.length()-3; i++)
    {
        int val=0;
        for(int j=0; j<3; j++)
        {
            val*=10;
            val+=(s[j+i]-'0');
        }
        ans=min(ans,abs(753-val));
    }
    cout<<ans<<endl;


    return 0;
}


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;


int main(){
  ll N,K;
  cin>>N>>K;
  vector<ll> A(N+1);
  for(int i(1);i<=N;i++) cin>>A[i];
  ll dp[200001] = {0};
  ll now = 1;
  for(ll i(0);i<K;i++){
    if(dp[now] != 0){
      ll syuuki = i - dp[now];
      ll amari = (K - i)%syuuki;
      for(int j(0);j<amari;j++){
        now = A[now]; 
      }
      cout << now << endl;
      return 0;
    }
    dp[now] = i;
    now = A[now];
  }
  cout << now << endl;
  return 0;
}



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

ll funk(ll x) {
    //ベースケース
    if(x==1) {
        return 1;
    }

    //再帰ステップ
    ll f = funk(x/2);
    return 2*f + 1;
}

int main() {
  ll H;
  cin >> H;

  cout << funk(H) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; Next(a); return a; }
  template<class A, class B>void Next(pair<A, B>& a) { cin >> a.first >> a.second; }
  template<class A>void Next(A& a) { cin >> a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) (*this), i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;
/*---------------------------------------------------------------------*/


void Calc() {

  var(int, n, k);

  auto a = in.Array<ll>(n);

  vector<ll> x(n + 1);
  rep(i, n)x[i + 1] += x[i] + a[i];

  vector<ll> y(n + 1);
  rep(i, n) y[i + 1] += (y[i] + max(0ll, a[i]));

  err(x, y);
  ll ans = 0;
  k--;
  rep(i, k, n) {
    ll tmp = y[n] - (y[i + 1] - y[i - k]);
    amax(ans, tmp);
    err(tmp);
    tmp += x[i + 1] - x[i - k];
    err(tmp);
    amax(ans, tmp);
  }

  cout << (ans) << endl;

}


Measured memory_bytes: 2560
while 1:
    m,f,r=map(int,raw_input().split())
    if m+f+r==-3:break
    if min(m,f)==-1 or m+f<30:print'F'
    elif m+f>=80:print'A'
    elif m+f>=65:print'B'
    elif max(m+f,r)>=50:print'C'
    else:print'D'

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

int D;
vector<int> c(26);
vector<vector<int>> s;

void init(){
	cin>>D;
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	
	s.resize(D,vector<int>(26));
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++)scanf("%d",&s[i][j]);
	}
}

int calc_score(vector<int> &t){
	int ret = 0;
	vector<int> last(26,0);
	for(int i=0;i<t.size();i++){
		int temp = t[i]-1;
		ret += s[i][temp];
		last[temp] = i+1;
		
		for(int j=0;j<26;j++){
			ret -= c[j] * ((i+1)-last[j]);
		}
	}
	return ret;
}

int main(){
	
	init();
	
	vector<int> t;
	for(int i=0;i<D;i++){
		int x;
		cin>>x;
		t.push_back(x);
		cout<<calc_score(t)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 3740
#include<cstdio>


using ll=long long;


ll calc(ll x[3])
{
	ll b, s;

	b=s=x[0];
	for(int i=1;i<3;i++)
	{
		if(b<x[i]) b=x[i];
		if(s>x[i]) s=x[i];
	}
	return b-s;
}


int min_u(ll& m, ll v)
{
	if(m>v)
	{
		m=v;
		return 1;
	}
	return 0;
}


int main(void)
{
	ll w, h, w2, h2, x, y;
	ll s[3], d_min;


	while(scanf("%lld%lld", &h, &w)==2)
	{
		if(h%3==0 || w%3==0)
		{
			printf("0\n");
			continue;
		}

		d_min=(ll)w*h;
		for(x=1;x<w;x++)
		{
			s[0]=x*h;
			w2=w-x;
			if(w2>=2)
			{
				s[1]=w2/2*h;
				s[2]=(w2-w2/2)*h;
				min_u(d_min, calc(s));
			}
			s[1]=h/2*w2;
			s[2]=(h-h/2)*w2;
			min_u(d_min, calc(s));
		}
		for(y=1;y<h;y++)
		{
			s[0]=y*w;
			h2=h-y;
			if(h2>=2)
			{
				s[1]=h2/2*w;
				s[2]=(h2-h2/2)*w;
				min_u(d_min, calc(s));
			}
			s[1]=w/2*h2;
			s[2]=(w-w/2)*h2;
			min_u(d_min, calc(s));
		}
		printf("%lld\n", d_min);
	}

	return 0;
}


Measured memory_bytes: 128
from collections import deque

H, W = map(int, input().split())
m = ["#" * (W+2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W+2)]
q = deque()
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

step = [[float("inf") for _ in range(W+2)] for _ in range(H+2)]

for h in range(1, H+1):
	for w in range(1, W+1):
		if m[h][w] == "#":
			q.appendleft([h, w])
			step[h][w] = 0

while q:
	label = q.pop()

	for i in range(4):
		h, w = label[0] + dx[i], label[1] + dy[i]
		if m[h][w] != "#" and step[h][w] > step[label[0]][label[1]] + 1:
			q.appendleft([h, w])
			step[h][w] = step[label[0]][label[1]] + 1

ans = 0
for h in range(1, H+1):
	for w in range(1, W+1):
		ans = max(ans, step[h][w])
print(ans)

Measured memory_bytes: 151004
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K;
  cin >> K;
  long long int ans=0;
  for(int i=1;i<=K;i++){
    for(int j=1;j<=K;j++){
      for(int k=1;k<=K;k++){
        ans+=__gcd(__gcd(i,j),k);
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 3616
#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.at(i);
    }

    bool can = false;
    int count = 0;
    int i = 0;
    while (a.at(i) != 2) {
        count++;
        i = a.at(i) - 1;
        if (a.at(i) == 2) {
            can = true;
            count++;
            break;
        }
        if (count > N) {
            break;
        }
    }
    if (a.at(0) == 2) {
        can = true;
        count++;
    }

    if (can) {
        cout << count << endl;
    }
    else {
        cout << -1 << endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
long long a[3];
cin>>a[1]>>a[2]>>a[3];
if((a[1]%2==0)||(a[2]%2==0)||(a[3]%2==0))cout<<0;
else 
{sort(a+1,a+4);
 cout<<a[1]*a[2];
}
return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int K;;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.K = sc.nextInt();
    }
    
    //解答処理
    private String solve() {
        String answer = "";
        for (int i = 0; i < K; i++) {
        	answer += "ACL";
        }
        
        return answer;
    }
    
    //出力
    public void show(String answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 38628
for t in xrange(input()):
    x0, y0, x1, y1, x2, y2, x3, y3 = map(int, raw_input().split())
    dx0 = x1 - x0
    dy0 = y1 - y0
    dx1 = x3 - x2
    dy1 = y3 - y2

    s = (y0-y2)*dx1 - (x0-x2)*dy1
    sm = dx0*dy1 - dy0*dx1
    if s < 0:
        s = -s
        sm = -sm
    t = (y2-y0)*dx0 - (x2-x0)*dy0
    tm = dx1*dy0 - dy1*dx0
    if t < 0:
        t = -t
        tm = -tm
    if s == 0:
        x = x0
        y = y0
    else:
        x = x0 + s*dx0/float(sm)
        y = y0 + s*dy0/float(sm)
    print "%.09f %.09f" % (x, y)

Measured memory_bytes: 6464
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))
n = int(input())
x = l()

a = 0

b = 0

co = sum(x)

for i in range(100):
	a = 0
	b = 0
	for j in range(n):
		if j <= i:
			a += x[j]
		else:
			b += x[j]
	if co >= abs(a-b):
		co = abs(a-b)
print(co)

Measured memory_bytes: 39920
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    string str;
    cin >> str;
    sort(str.begin(), str.end());
    if (str[0] == str[1] && str[2] == str[3] && str[1] != str[2]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}

int main(){

    ll N, M;
    cin >> N >> M;
    V a(N), b(N);
    set<ll>S;
    rep(i, N){
        cin >> a[i];
        b[i] = a[i] / 2;
        ll cnt = 0;
        for(ll j = b[i]; j % 2 == 0; j /= 2)cnt++;
        S.insert(cnt);
    }
    if(S.size() > 1){
        cout << 0 << endl;
        return 0;
    }
    ll l = 1;
    rep(i, N){
        l = lcm(l, b[i]);
        if(l > M){
            cout << 0 << endl;
            return 0;
        }
    }
    cout << (M + l) / (l * 2) << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    char s[10000];
    scanf("%s", s);
    for (int i=0;s[i]!='\0';i++) {
        int oldChar=s[i]-'A';
        int newChar=(oldChar+n)%26;
        printf("%c", newChar+'A');
    }
    printf("\n");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,k,ans;
int a[200001],b[200001];
int find(int x)
{
	int l=1,r=m,mid,tnt=0;
	while(l<=r)
	{
		mid=(l+r)>>1;
		if(b[mid]<=x)
		tnt=mid,l=mid+1;
		else
		r=mid-1;
	}
	return tnt;
}
signed main()
{
	scanf("%lld%lld%lld",&n,&m,&k);
	for(int i=1;i<=n;i++)
	scanf("%lld",&a[i]),a[i]+=a[i-1];
	for(int i=1;i<=m;i++)
	scanf("%lld",&b[i]),b[i]+=b[i-1];
	for(int i=0;i<=n;i++)
	if(a[i]<=k)
	ans=max(ans,i+find(k-a[i]));
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 6848
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int dp[100010];
bool visited[100010];
vector<int> G[100010];
int ans = 0;

int dfs(int x) {
    if (visited[x]) return dp[x];
    visited[x] = true;
    for(auto next : G[x]) {
        dp[x] = max(dp[x], dfs(next) + 1);
    }
    ans = max(ans, dp[x]);
    return dp[x];
}


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M; cin >> N >> M;
    bool used[100010] = {};
    rep(i, M) {
        int s, t; cin >> s >> t;
        s--; t--;
        G[s].push_back(t);
        used[t] = true;
    } 
    rep(i, N) {
        if (!used[i]) dfs(i);
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 9472
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define lld long long int
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   long long int t;
lld x;lld k;lld d;
cin>>x>>k>>d;
x=abs(x);
    lld a= min(k,x/d);
    x=x-(a*d);
    k=k-a;
    if (k% 2== 0) 
        cout<<x<<"\n";
     else 
        cout <<d-x<<"\n";

	return 0;
}



Measured memory_bytes: 3584
#include<bits/stdc++.h>
#include<cmath>
#define SZ(x) ((int)x.size())
#include<vector>
#include<set>
#include<map>
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define pb push_back
#include<string>
#include<cctype>
#include<queue>
#define ii pair<int,int>
#include <sstream>
#define lli long long int
#define pairs pair<int,int>
#define mod 1000000007
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
using namespace std;
ll pows(ll a,ll n,ll m)
{
	ll res=1;
	while(n)
	{
	if(n%2!=0)
	{
		res=(res*a)%m;
		n--;
		}
		else
		{
			a=(a*a)%m;
			n=n/2;
			}	
	}
	return res%m;
}
ll  gcd(ll a,ll b)
{
	if(b==0)
	return a;
	else 
	return gcd(b,a%b);
}
bool isprime(ll n)
{
	if(n==1)
	{
		return false;
	}
	for(ll i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			return false;
		}
	}
	return true;
}
bool istrue(string s)
{
	int i=0;
	int j=s.size()-1;
	while(i<j)
	{
	if(s[i]==s[j])
	{
		i++;
		j--;
		}
		else
		{
			return false;
			}	
	}
	return true;
}
int main()
{
   ios::sync_with_stdio(false);
	 cin.tie(0);
    cout.tie(0);
int n;
cin>>n;
ll  arr[n+1]={0};
for(int i=1;i<=n;i++)
{
	for(int j=i;j<=n;j=j+i)
	{
		arr[j]++;
	}
}
ll sum=0;
for(ll i=1;i<=n;i++)
{
	sum+=arr[i]*i;
}
cout<<sum<<endl;
}




Measured memory_bytes: 81700
# coding: utf-8
class Case01

  def initialize
  end

  def show
    p self.instance_variables
        .map{ |sym| [sym, self.instance_variable_get(sym)] }
        .to_h
  end
  
  # 実行する
  def execute
    read
    solve
    output
  end

  # 読込
  def read
    @s = gets.chomp
  end

  # 回答
  def solve
    @result = (@s <= '2019/04/30')
  end
  
  # 出力
  def output
    puts @result ? 'Heisei' : 'TBD'
  end

end

# 
Case01.new.execute if $0 == __FILE__



Measured memory_bytes: 1788
#include<bits/stdc++.h>
#define Int int64_t
#define ll long long
#define pb push_back
using namespace std;
const Int MAXN=2005;
const int ALPHA=26;

Int N,K,M;
Int X,Y,Z;
Int A,B,C;
vector<Int> ID;
vector<Int> SZ;
int find(int x){
    if(ID[x]==x) return x;
    return find(ID[x]);
}
void Union(int x,int y){
    x=find(x);y=find(y);
    if(x==y) return;
    if(SZ[x]>SZ[y]){
        ID[y]=x;
        SZ[x]+=SZ[y];
    }
    else{
        ID[x]=y;
        SZ[y]+=SZ[x];
    }
    return;
}
string common_prefix(string s,string t){
    string ans="";
    for(int i=0;i<min(s.length(),t.length());++i){
        if(s[i]==t[i]) ans.pb(s[i]);
        else break;
    }
    return ans;
}
string LCP(vector<string> A,int l,int r){
    if(l>r) return "";
    if(l==r) return A[l];
    int mid=(l+r)/2;
    string left=LCP(A,l,mid);
    string right=LCP(A,mid+1,r);
    return common_prefix(left,right);
}
int main()
{
    int t;
    t=1;
    while(t--){
       cin>>X;
       if(X>=400&&X<=599) cout<<8<<"\n";
       else if(X>=600&&X<=799) cout<<7<<"\n";
       else if(X>=800&&X<=999) cout<<"6"<<"\n";
       else if(X>=1000&&X<=1199) cout<<"5"<<"\n";
       else if(X>=1200&&X<=1399) cout<<"4"<<"\n";
       else if(X>=1400&&X<=1599) cout<<"3"<<"\n";
       else if(X>=1600&&X<=1799) cout<<"2"<<"\n";
       else if(X>=1800&&X<=1999) cout<<"1"<<"\n";
    }
}

Measured memory_bytes: 3632