akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }

ll score(int N ,int i, int j, vll& Seven, vll& Sodd) {
    if(i - 1 < 0) return Sodd[N] - Sodd[j] + Seven[j - 1] - Seven[i];
    return Sodd[i - 1] + Sodd[N] - Sodd[j] + Seven[j - 1] - Seven[i];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];
    int M = 1 + N % 2;
    v2ll dp(N + 1, vll(M + 1, -LINF));
    dp[0][0] = 0;
    REP(i, 0, N) {
        REP(j, 0, M + 1) {
            if(j < M)
                dp[i + 1][j + 1] =max(dp[i + 1][j + 1], dp[i][j]);
            if ((i + 1 + j) % 2 == 1)
                dp[i + 1][j] =max(dp[i + 1][j], dp[i][j] + A[i]);
            else
                dp[i + 1][j] =max(dp[i + 1][j], dp[i][j]);
        }
    }
    cout << dp[N][M] << endl;
    return 0;
}

Measured memory_bytes: 15876
<?php

$n = (int)trim(fgets(STDIN));

for ($i = 3; $i <= $n; $i++) {
    if ($i % 3 == 0) {
        echo ' ' . $i;
    } else {
        $x = $i;
        while ($x >= 3) {
            if ($x % 10 == 3) {
                echo ' ' . $i;
                break;
            }
            $x = intval($x / 10);
        }
    }
}

echo "\n";


Measured memory_bytes: 9212
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    ll Q,H,S,D;
    cin >> Q >> H >> S >> D;
    ll N;
    cin >> N;
    N *= 4;
    ll ans = 0;
    ll phase_1 = N / 8;
    
    ans += min(D, min(S * 2, min(H * 4, Q * 8))) * phase_1;
    
    N -= phase_1 * 8;
    
    ll phase_2 = N / 4;
    
    ans += min(S, min(H * 2, Q * 4)) * phase_2;
    
    N -= phase_2 * 4;
    
    ll phase_3 = N / 2;
    
    ans += min(H, Q * 2) * phase_3;
    
    N -= phase_3 * 2;
    
    ll phase_4 = N;
    
    ans += Q * phase_4;
    
    cout << ans << endl;
}


Measured memory_bytes: 3668
import java.util.Scanner;


// 137_b
public class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);

        int k = scan.nextInt();
        int x = scan.nextInt();

        for (int i = 1; i <= 2 * k - 1; i++) {
            System.out.print(x - k + i);
            if (!(i == 2 * k - 1)) {
                System.out.print(" ");
            }
        }
        System.out.println();

    }

}


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

int main()
{
    ll N, T, X;

    cin >> N >> X >> T;

    ll ans = 0;

    while(true){
        N -= X;
        ans +=T;

        if(N <= 0)
        break;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<vector>
using namespace std;
typedef long long s64;

const int ONE = 200005;
const int INF = 214748364;

#define next nxt

int get()
{
		int res = 1, Q = 1; char c;
		while( (c = getchar()) < 48 || c > 57)
			if(c == '-') Q = -1;
		if(Q) res = c - 48;
		while( (c = getchar()) >= 48 && c <= 57)
			res = res * 10 + c - 48;
		return res * Q;
}

struct power
{
		int l, r;
}val[ONE];

int n, k;
int x, y;
int pd[ONE];
int next[ONE], first[ONE], go[ONE], tot;

void Add(int u, int v)
{
		next[++tot] = first[u], first[u] = tot, go[tot] = v;
		next[++tot] = first[v], first[v] = tot, go[tot] = u;
}

void dfs(int u, int father)
{
		if(val[u].l == val[u].r) pd[u] = val[u].l % 2;
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs(v, u);
			if(pd[v] == 2) continue;
			if(pd[u] == 2) {pd[u] = pd[v] ^ 1; continue;}
			if(pd[u] != (pd[v] ^ 1)) {printf("No"); exit(0);}
		}
}

void dfs1(int u, int father)
{
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			dfs1(v, u);
			val[u].l = max(val[u].l, val[v].l - 1);
			val[u].r = min(val[u].r, val[v].r + 1);
			if(val[u].l > val[u].r) {printf("No"); exit(0);}
		}
}

int A[ONE];

void dfs2(int u, int father)
{
		if(!(val[u].l <= A[u] && A[u] <= val[u].r)) {printf("No"); exit(0);}
		for(int e = first[u]; e; e = next[e])
		{
			int v = go[e];
			if(v == father) continue;
			if(val[v].l <= A[u] - 1 && A[u] - 1 <= val[v].r) A[v] = A[u] - 1;
			if(val[v].l <= A[u] + 1 && A[u] + 1 <= val[v].r) A[v] = A[u] + 1;
			dfs2(v, u);
		}
}

int main()
{
		n = get();
		for(int i = 1; i < n; i++) x = get(), y = get(), Add(x, y);
		for(int i = 1; i <= n; i++) val[i] = (power){-INF, INF}, pd[i] = 2;
		k = get();
		for(int i = 1; i <= k; i++) x = get(), y = get(), val[x] = (power){y, y};

		dfs(1, 0);
		dfs1(1, 0);

		A[1] = val[1].l;
		if(pd[1] != 2 && A[1] % 2 != pd[1]) A[1]++;

		dfs2(1, 0);

		printf("Yes\n");
		for(int i = 1; i <= n; i++)
			printf("%d\n", A[i]);
}

Measured memory_bytes: 9856
import java.util.*;

public class Main {
    static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        while(true){
            int n=Integer.parseInt(sc.nextLine());
            if(n==0)break;
            run(n);
        }
    }
    static void run(int n){
        int ans=1;
        int max=0;
        int t;
        String[] s=sc.nextLine().split(" ");
        for(int i=0;i<n;i++){
            t=Integer.parseInt(s[i]);
            if(max<t)max=t;
            if(t>0)ans++;
        }
        if(max<2){
            System.out.println("NA");
        }else{
            System.out.println(ans);
        }
    }
}

Measured memory_bytes: 60916
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debugg cout<<"debugged\n";
#define setpr(xval) cout<<fixed<<setprecision(12)<<xval<<endl;
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll n,k,ans;
void solve()
{
    cin>>k>>n; vector<ll>ar(n),arr(n-1);
    if(k>=n)
    {cout<<0<<endl;return;}
    for(ll i=0;i<n;i++)
    {
        cin>>ar[i];
    }
    sort(ar.begin(),ar.end());
    for(ll i=0;i<n-1;i++)
        arr[i]=ar[i+1]-ar[i];
    sort(arr.begin(),arr.end());
    k--;
    for(ll i=0;i<arr.size()-k;i++)
        ans+=arr[i];
    cout<<ans<<endl;
}

int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 1792
package main

import "fmt"

var graph [][]int
var N, X, Y int
var ans []int

func bfs(s int) {
	// fmt.Printf("-------- bfs en: %d\n", s)
	d := make([]int, N+1)
	seen := make([]bool, N+1)
	var q container
	q.queue(s)
	var v int
	for q.dequeue(&v) {
		// fmt.Printf("dq %d\n", v)
		seen[v] = true
		vl := graph[v]
		for _, vv := range vl {
			if !seen[vv] {
				seen[vv] = true
				d[vv] = d[v] + 1
				// fmt.Printf("set d[%d] to %d\n", vv, d[v]+1)
				q.queue(vv)
				if vv > s {
					ans[d[vv]]++
				}
			}
		}
	}
	return
}

func main() {
	fmt.Scan(&N, &X, &Y)
	ans = make([]int, N)
	graph = make([][]int, N+1)
	for i := 0; i < len(graph); i++ {
		graph[i] = make([]int, 0)
	}
	for i := 1; i < N; i++ {
		graph[i] = append(graph[i], i+1)
		graph[i+1] = append(graph[i+1], i)
	}
	graph[X] = append(graph[X], Y)
	graph[Y] = append(graph[Y], X)
	// fmt.Println("graph:")
	// fmt.Println(graph)
	for i := 1; i < N; i++ {
		bfs(i) // 1~(N-1)まで幅優先探索する
	}
	for i := 1; i < N; i++ {
		fmt.Println(ans[i])
	}
}

type container struct {
	data []int
}

func (c *container) queue(v int) {
	c.data = append(c.data, v)
}
func (c *container) dequeue(v *int) bool {
	if len(c.data) == 0 {
		return false
	}
	*v = c.data[0]
	c.data = c.data[1:]
	return true
}


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

int main(){
  int N;
  cin >> N;
  vector<long long> H(N);
  cin >> H.at(0);
  int ans = 0, tmp = 0;
  for (int i = 1; i < N; i++){
    cin >> H.at(i);
    if (H.at(i - 1) >= H.at(i)) tmp++;
    if (H.at(i - 1) < H.at(i) || i == N - 1){
      ans = max(ans, tmp);
      tmp = 0;
    }
    //cout << ans << " " << tmp << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4020
import math
from decimal import Decimal
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]

for k in range(n):
    if k:
        m0 = math.ceil(Decimal(a[k-1][0])/Decimal(a[k][0]))
        m1 = math.ceil(Decimal(a[k-1][1])/Decimal(a[k][1]))
        m = max(m0, m1)
        a[k] = [m*a[k][0], m*a[k][1]]
print(sum(a[n-1]))


Measured memory_bytes: 5076
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.stream.Stream;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BIrohaLovesStringsABCEdition solver = new BIrohaLovesStringsABCEdition();
        solver.solve(1, in, out);
        out.close();
    }

    static class BIrohaLovesStringsABCEdition {
        public void solve(int testNumber, LightScanner in, PrintWriter out) {
            int n = in.ints();
            in.voids();
            String[] s = in.string(n);
            Arrays.sort(s);
            out.println(String.join("", s));
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String[] string(int length) {
            return IntStream.range(0, length).mapToObj(x -> string()).toArray(String[]::new);
        }

        public void voids() {
            string();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

    }
}



Measured memory_bytes: 27860
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <utility>
#include <vector>
using namespace std;

int main(){
  int W,H;
  while(scanf("%d%d", &H, &W)){
    if ((H == 0) && (W == 0)){
      break;
    }
    vector<vector<char> > m(H, vector<char>(W, ' '));
    vector<vector<int> > v(H, vector<int>(W, 0));
    for (int i = 0; i < H; i++){
      for (int j = 0; j < W; j++){
        scanf(" %c", &(m[i][j]));
      }
    }
    int x = 0, y = 0;
    bool loop = false;
    while(m[y][x] != '.'){
      if (v[y][x] != 0){
        loop = true;
        printf("LOOP\n");
        break;
      }else{
        v[y][x] = 1;
        if (m[y][x] == '>'){
          x++;
	}else if (m[y][x] == 'v'){
          y++;
	}else if (m[y][x] == '<'){
          x--;
	}else if (m[y][x] == '^'){
          y--;
	}
      }
    }
    if (!loop){
      printf("%d %d\n", x, y);
    }
  }
  return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

ll n;
vector<vector<P>> a;
vector<ll> ans;

void dfs(ll v,ll p){
	for(auto itr : a[v]){
		ll u = itr.fs;//子
		ll w = itr.sc;//辺の長さ
		if (itr.fs == p){
			continue;
		}
		else{
			if (w % 2 == 0){
				ans[u] = ans[v];
			}
			else{
				ans[u] = ans[v]^(w % 2);
			}
			dfs(u,v);
		}
	} 
}




int main(){
	cin >> n;
	a.resize(n);
	ll u,v,w;
	for(int i = 0; i < n-1; i++) {
		cin >> u  >> v >> w;
		a[u - 1].pb(mp(v-1,w));
		a[v - 1].pb(mp(u-1,w));
	}

	for(int i = 0; i < n; i++) {
		ans.pb(0);
	}
	dfs(0,-1);
	
	for(int i = 0; i < n; i++) {
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 10100
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main()
{
  int a;
  string s;
  cin >> a >> s;
  if (a < s.size())
  {
    s = s.erase(a, s.size() - a) + "...";
  }
  cout << s;
}


Measured memory_bytes: 3624
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007
#define pb(i) push_back(i)
#define pp() pop_back()
#define f first
#define s second
#define mk(l,r) make_pair(l,r)
#define all(vc) vc.begin(),vc.end()
#define bg(vc) vc.begin()
#define ed(vc) vc.end()
#define w(t) while(t--)
const ll MAX=3e5+5;
const ll INF=2e18;
int h,w;
int ans=INT_MAX;
void solve(string s[],int i,int j,int count)
{
   if(i==h-1&&j==w-1)
   {
    	ans=min(count,ans);
       return;
   }
   if(i<h-1)
   {
       if(s[i+1][j]=='#')
           solve(s,i+1,j,count+1);
       else solve(s,i+1,j,count);
   }
    if(j<w-1)
    {
        if(s[i][j+1]=='#')
            solve(s,i,j+1,count+1);
        else solve(s,i,j+1,count);
    }
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    w(t)
    {
        
        cin>>h>>w;
        string s[h];
        for(int i=0;i<h;i++)
            cin>>s[i];
       	int dp[h][w];
        memset(dp,0,sizeof dp);
        
        for(int i=0;i<h;i++)
            for(int j=0;j<w;j++)
            {
                int count1=0,count2=0;
                int acth=0,actw=0;
                if(s[i][j]=='#')
                    count1=1,count2=1;
               
                if(i==0&&j==0)
                    dp[i][j]=count1;
                else if(i-1>=0&&j-1>=0){
                   if(s[i-1][j]=='#')
                        count1=0;
                    if(s[i][j-1]=='#')
                        count2=0;
                    dp[i][j]=min(dp[i-1][j]+count1,dp[i][j-1]+count2);}
                else if(i-1>=0){if(s[i-1][j]=='#')
                        count1=0;
                    dp[i][j]=dp[i-1][j]+count1;}
                else if(j-1>=0){if(s[i][j-1]=='#')
                        count2=0;
                    dp[i][j]=dp[i][j-1]+count2;}
            }
        cout<<dp[h-1][w-1]<<endl;
    }
}
/*ll msb(ll x)
{
	ll k=(ll)log2(x);
	return (ll)(pow(2,k));
}
#define gc getchar_unlocked
void scanint(int &x)
{
    register int c = gc();
    x = 0;
    int neg = 0;
    for(;((c<48 || c>57) && c != '-');c = gc());
    if(c=='-') {neg=1;c=gc();}
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
    if(neg) x=-x;
}*/

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

int main(){
 int n;
 cin >> n;
 int count[4] = {0, 0, 0, 0};
 string temp[4] = {"AC", "WA", "TLE", "RE"};
 for(int i = 0; i < n; ++i){
   string s;
   cin >> s;
   for(int j = 0; j < 4; ++j){
     if(s == temp[j]){
       count[j]++;
       break;
     }
   }
 }
 for(int j = 0; j < 4; ++j){
   cout << temp[j] << " x " << count[j] << endl;
 }
}


Measured memory_bytes: 3168
#include <iostream>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <climits>
using namespace std;
#define Rep(i,n) for(int i = 0; i < n; ++i)
#define For(i, s, e) for(int i = s; i <= e; ++i)
string s;
int K;

namespace
{
	struct StCompare
	{
		bool operator()(const string& a, const string& b) {
			if (a.empty() && b.empty()) return false;
			if (a.empty()) return true;
			if (b.empty()) return false;
			int n = a.size();
			int m = b.size();
			int s = min(n, m);
			for (int i = 0; i < s; ++i)
				if (a[i] != b[i]) return (a[i] < b[i]);
			return (n < m);
		}
	};
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> s >> K;

	StCompare cp;
	vector<string> vSub;
	vSub.reserve(200);
	int n = s.size();
	Rep(i, n) {
		For(j, 0, K - 1) {
			string t = s.substr(i, j + 1);
			if (vSub.empty())
				vSub.push_back(t);
			else {
				auto it = lower_bound(vSub.begin(), vSub.end(), t, cp);
				if (it == vSub.end())
					vSub.push_back(t);
				else if (*it != t)
					vSub.insert(it, t);
			}
		}
	}
	cout << vSub[K - 1] << endl;
	return 0;
}

Measured memory_bytes: 1152
//ac(1:44 + 0:14 + (9:44) = 11:42)

#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back

using namespace std;

typedef long long ll;

ll const INF = 1e9;

int n, m, x;
ll c[12];
int a[12][12];

ll cost(int i, vector<int> curr){
	if(i==n){
		int level[12];
		ll costx = 0;
		memset(level, 0, sizeof level);
		for(int i=0;i<curr.size();i++){
			for(int j=0;j<m;j++){
				level[j] += a[curr[i]][j];
			}
			costx += c[curr[i]];
		}
		for(int i=0;i<m;i++){
			if(level[i] < x)
				return INF;
		}
		return costx;
	}
	else{
		curr.pb(i);
		ll ans = cost(i+1, curr);
		curr.ppb();
		ans = min(ans, cost(i+1, curr));
		return ans;
	}
}

int main(){
	cin>>n>>m>>x;
	for(int i=0;i<n;i++){
		cin>>c[i];
		for(int j=0;j<m;j++){
			cin>>a[i][j];
		}
	}
	vector<int> blank;
	ll costx = cost(0, blank);
	(costx == INF)?cout<<-1<<"\n":cout<<costx<<"\n";
	return 0;
}

Measured memory_bytes: 3528
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	
	double r,m,s;
	Scanner scan = new Scanner(System.in);
	
	r= scan.nextDouble();
	
	m=r*r*Math.PI;
	s=2*r*Math.PI;
	System.out.printf("%f %f",m,s);
	}
	
}

Measured memory_bytes: 28456
#include<stdio.h>
#include<stdlib.h>
 
#define NIL -1
#define MAX 500001
 
typedef struct{
  int right;
  int left;
  int key;
  int parent;
} Node;
 
void Insert(Node*,int,int);
void PreOrder(Node*,int);
void InOrder(Node*,int);
void Find(Node*,int, int);
void Delete(Node*,int);
int Successor(Node*, int);
 
int main(void){
  int i, n, k, f, del, count=0;
  char state[8];
  Node T[MAX];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%s", state);
 
    if(state[0] == 'i'){
 
      scanf("%d",&k);
      Insert(T, count, k);
      count++;
 
    } else if(state[0] == 'p'){
 
      if(count > 0){
        InOrder(T, 0);
        printf("\n");
        PreOrder(T, 0);
        printf("\n");
      }
 
    } else if(state[0] == 'f'){
 
      scanf("%d", &f);
      Find(T, f, 0);
 
    } else if(state[0] == 'd'){
 
      scanf("%d", &del);
      Delete(T, del);
 
    }
  }
  return 0;
}
 
void Insert(Node *T,int count, int k){
  int x, y;
 
  T[count].key = k;
  T[count].left = NIL;
  T[count].right = NIL;
  //T[count].parent = NIL;
 
  if(count == 0) return;
 
  x = 0;
  while(x!=NIL){
    y = x;
 
    if(k < T[x].key) x = T[x].left;
    else x = T[x].right;
 
  }
 
  T[count].parent = y;
 
  if(k < T[y].key) T[y].left = count;
  else T[y].right = count;
 
  return;
}
 
void PreOrder(Node *T, int u){
 
  if(u == NIL) return;
 
  printf(" %d", T[u].key);
  PreOrder(T, T[u].left);
  PreOrder(T, T[u].right);
 
  return;
}
 
void InOrder(Node *T, int u){
 
  if(u == NIL) return;
 
  InOrder(T, T[u].left);
  printf(" %d", T[u].key);
  InOrder(T, T[u].right);
 
  return;
}
 
void Find(Node *T, int f, int u){
 
  if(u == NIL) printf("no\n");
  else if(T[u].key == f) printf("yes\n");
  else if(T[u].key > f && T[u].left != NIL) Find(T, f, T[u].left);
  else Find(T, f, T[u].right);
 
  return;
}
 
void Delete(Node *T, int k){
  int x, y, z = 0;
 
  while(1){
    if(T[z].key == k) break;
    else if(k < T[z].key) z = T[z].left;
    else z = T[z].right;
 
  }
 
  if(T[z].left == NIL || T[z].right == NIL) y = z;
  else y = Successor(T, z);
 
  if(T[y].left != NIL) x = T[y].left;
  else x = T[y].right;
 
  if(x != -1) T[x].parent = T[y].parent;
 
  if(T[y].parent != NIL){
    if(y == T[T[y].parent].left) T[T[y].parent].left = x;
    else T[T[y].parent].right = x;
  }
 
  if(y != z) T[z].key = T[y].key;
 
  return;
 
}
 
int Successor(Node *T,int x){
  int y;
 
  if(T[x].right != NIL){
    x = T[x].right;
    while(T[x].left != NIL) x = T[x].left;
    return x;
  } else {
    y = T[x].parent;
    while(y != NIL && x == T[y].right){
      x = y;
      y = T[y].parent;
    }
    return y;
  }
 
}

Measured memory_bytes: 7380
#include <bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin >>n;
  int p[n],su=0;
  for (int i=0;i<n;i++){
  cin >>p[i];
  su+=p[i];
  }
  sort(p,p+n);
  su-=p[n-1]/2;
  cout << su<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#define ll long long
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
template <typename T>
inline void w(T x) {
	if (x > 9) w(x / 10);
	putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x, char c) {
	w(x);
	putchar(c);
}
template <typename T>
inline void read(T &x) {
	x = 0;
	T f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;
}
int main(){
	char s[10];
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5])printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
  int h,w,x=0,i,j;
  char a[8][9];
  scanf("%d %d",&h,&w);
  for (i=0;i<h;i++) {
    scanf("%s",a[i]);
  }
  for (i=0;i<h;i++) {
    for (j=0;j<w;j++) {
      if (a[i][j]=='#') {
        x++;
      }
    }
  }
  if (x==h+w-1) {
    printf("Possible\n");
  } else {
    printf("Impossible\n");
  }
  return 0;
}

Measured memory_bytes: 128
/*input
6
1 2 3 1 3 2
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
    out<<'('<<P.F<<','<<P.S<<')';
    return out;
}
#define version 20190713
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        
        b>>=1;
    }
    return res;
}

map<int,int> mp;
vector<pii> v;
int main(){
    IOS;
    int n;
    cin>>n;
    REP(i,n){
        int x;
        cin>>x;
        mp[x]++;
    }
    if(mp[0]>0){
        if(mp[0]==n){
            cout<<"Yes\n";
        }
        else if(SZ(mp)==2&&mp[0]*3==n){
            cout<<"Yes\n";
        }
        else cout<<"No\n";
    }
    else{
        vector<pii> v;
        for(auto i:mp) if(i.S) v.pb(i);

        if(SZ(v)!=3){
            cout<<"No\n";
        }
        else{
            if(v[0].F^v[1].F^v[2].F){
                cout<<"No\n";
            }
            else if(v[0].S==v[1].S&&v[1].S==v[2].S){
                cout<<"Yes\n";
            }
            else cout<<"No\n";
        }
    }
    return 0;
}


Measured memory_bytes: 4988
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 2000010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = inv[1] = 1;
    fact[0] = invfact[0] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i * fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}

//--- main関数でinit()を呼び出すのを忘れるな ---//

// 素因数分解。計算量はO(√n)
map<ll, ll> primefactor(ll n) {  // (nのi番目の素因数, その素因数の個数)のmapを返す(n = 720 = (2^4)*(3^2)*(5^1)なら{(2, 4), (3, 2), (5, 1)}のように)
    map<ll, ll> res;
    for(ll i = 2; i*i <= n; i++) {
        while(n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if(n != 1) {
        res[n] = 1;
    }
    return res;
}
 
int main() {
    ll n;
    cin >> n;

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    map<ll, ll> mp1;
    rep(i, n) {
        map<ll, ll> mp2 = primefactor(a[i]);
        for(auto p : mp2) {
            chmax(mp1[p.first], p.second);
        }
    }

    ll lcm = 1;
    for(auto p : mp1) {
        rep(i, p.second) {
            lcm *= p.first;
            lcm %= mod;
        }
    }

    init();

    ll ans = 0;
    rep(i, n) {
        ans += lcm*inv[a[i]];
        ans %= mod;
    }

    out(ans);
    re0;
}

Measured memory_bytes: 47872
n=int(input())
a=[int(i) for i in input().split()]
b=0
for j in range(n):
  if a[j]%2==0 and a[j]%3!=0 and a[j]%5!=0:
    b+=1
if b==0:
  print('APPROVED')
if b>=1:
  print('DENIED')

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

void printArray(int,int[]);
int merge(int,int[],int,int,int);
int merge_sort(int,int[],int,int);

int main(int argc, char** argv) {
    int size;
    scanf("%d\n", &size);
    int array[size];
    for(int i = 0; i < size; i++)
        scanf("%d", &array[i]);
    
    int returnVal = merge_sort(size, array, 0, size);
    printArray(size, array);
    printf("%d\n", returnVal);
    
    return (EXIT_SUCCESS);
}

int merge(int size, int a[size], int left, int mid, int right){
    int count = 0;
    int i = 0;
    int j = 0;
    int n1 = mid - left;
    int n2 = right - mid;
    int lArray[n1], rArray[n2];
    for(; i < n1; i++)
        lArray[i] = a[left + i];
    for(; j < n2; j++)
        rArray[j] = a[mid + j];
    i = 0;
    j = 0;
    for(int k = left; k < right; k++){
        if(i < n1 && lArray[i] <= rArray[j] || j >= n2)
            a[k] = lArray[i++];
        else
            a[k] = rArray[j++];
        count++;
    }
    return count;
}

int merge_sort(int size, int a[size], int left, int right){
    int count = 0;
    if(left+1 < right){
        int mid = (left + right)/2;
        count += merge_sort(size, a, left, mid);
        count += merge_sort(size, a, mid, right);
        count += merge(size, a, left, mid, right);
        //printArray(size, a);
    }
    return count;
}

void printArray(int size, int a[size]){
    for(int i = 0; i < size; i++){
        if(i != size - 1)
            printf("%d ", a[i]);
        else printf("%d\n", a[i]);
    }
}


Measured memory_bytes: 5600
n=int(input())
s1=input()
s2=input()
mod=10**9+7

def rle(string):
    rle_str = string[0]
    rle_cnt = 1
    ans_l = []
    for i in range(1, len(string)):
        if rle_str == string[i]:
            rle_cnt += 1
        else:
            ans_l.append([rle_str, rle_cnt])
            rle_str = string[i]
            rle_cnt = 1
    ans_l.append([rle_str, rle_cnt])
    return ans_l

rle_s=rle(s1)

if rle_s[0][1]==1:
    ans=3
    left=1
elif rle_s[0][1]==2:
    ans=6
    left=2

for s, i in rle_s[1:]:
    if left==1 and i==1:
        ans*=2
    elif left==1 and i==2:
        ans*=2
    elif left==2 and i==1:
        ans*=1
    elif left==2 and i==2:
        ans*=3
    left=i

print(ans%mod)


Measured memory_bytes: 9180
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */


ll f(ll a, ll k, ll x) {
	if ((x > k) || (x < 1)) {
		return -1;
	}
	return x * (a + k + 1 - x);
}

bool ok(ll k, ll b, ll a) {	
	if (k == 0) {
		return true;
	}
	if (k == b) {
		return false;
	}
/*	for (ll i = 1; i <= k; i++) {
		ll cur = i * (a + k + 1 - i);
		if (cur >= a * b) {
			return false;	
		}
	}	*/
	ll r1 = max(f(a, k, 1), f(a, k, k));
	ll m1 = (a + k + 1) / 2;
	ll m2 = (a + k + 2) / 2;
	ll r2 = max(f(a, k, m1), f(a, k, m2));
	ll r = max(r1, r2);
	return (r < a * b);
}

int match(int a, int b) {
	ll l = 0;
	ll r = a;
	while (r - l > 1) {
		ll m = (r + l) / 2;
		if (ok(m, a, b)) {
			l = m;
		} else {
			r = m;
		}
	}
	return l;
}

int solve(int a, int b) {
	int m1 = match(a, b);
	int m2 = match(b, a);
	int nm1 = a - 1 - m1;
	int nm2 = b - 1 - m2;
	return m1 + m2 + min(nm1, nm2);
}

int main() {
	cout << fixed << setprecision(12);	
	int q, a, b;
	cin >> q;
	while (q--) {
		cin >> a >> b;
		if (a > b) {
			swap(a,b);
		}
		cout << solve(a, b) << endl;
	}
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



Measured memory_bytes: 3656
import sys
input = sys.stdin.readline
n = int(input())
kx = list(map(int,input().split()))
k = kx[::2]
x = kx[1::2]
ans = [0]*n
ans[0] = sum(k)-sum(x)
for i in range(0,n-1):
  ans[i+1] = kx[i]*2-ans[i]
print(*ans)

Measured memory_bytes: 14476
#include <iostream>
using namespace std;
int main(void){
    int h,w,i;
    char odd[301], even[301];
    while(1){
        cin >> h >> w;
        if(!(h+w)) break;
        for(i=0;i<w;i++){
            odd[i]=(i&1)?'#':'.';
            even[i]=(i&1)?'.':'#';
        }
        odd[i]=0, even[i]=0;
        for(i=0;i<h;i++){
            if(i&1) cout << odd << endl;
            else cout << even << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h> 
 
#define INF (1<<31)//INT_MAX/2
#define MOD 1000000007
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int A, B;
    std::cin >> A >> B;

    if ((A+B) % 3 == 0 || A % 3 == 0 || B % 3 == 0) {
        std::cout << "Possible" << std::endl;
    } else {
        std::cout << "Impossible" << std::endl;
    }
    return 0;
}

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

struct sector { ll l, r, f; };

ll N, I, S, P;
char C;
sector a[20000];
int k;

void write() {
  cin >> I >> S;
  REP(i, 0, k) if(a[i].f == -1 && S > 0) {
    if(S >= a[i].r - a[i].l) {
      a[i].f = I;
      S -= a[i].r - a[i].l;
    } else {
      for(int j = k; j > i; j--) {
        a[j + 1].l = a[j].l;
        a[j + 1].r = a[j].r;
        a[j + 1].f = a[j].f;
      }
      a[i + 1].r = a[i].r;
      a[i + 1].f = -1;
      a[i].f = I;
      a[i].r = a[i].l + S;
      a[i + 1].l = a[i].r;
      S = 0;
      k++;
      break;
    }
  }
  if(S > 0) {
    int l = k > 0 ? a[k - 1].r : 0;
    a[k++] = (sector) { l, l + S, I };
  }
}

void destroy() {
  cin >> I;
  REP(i, 0, k) if(a[i].f == I) a[i].f = -1;
}

ll read() {
  cin >> P;
  REP(i, 0, k) if(a[i].l <= P && P < a[i].r) return a[i].f;
  return -1;
}

int main(void) {
  while(cin >> N, N) {
    k = 0;
    REP(i, 0, N) {
      cin >> C;
      if(C == 'W') write();
      if(C == 'D') destroy();
      if(C == 'R') cout << read() << endl;

      // cout << i << ": " << C << " " << k << endl;
      // REP(i, 0, k) {
      //   cout << a[i].l << " - " << a[i].r << ": " << a[i].f << endl;
      // }
      // cout << endl;
    }
    cout << endl;
  }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
#define ll long long
#define debug(x) cerr << #x << ": " << x << "\n"
#define debugv(x) cerr << #x << ": \n" << rep(i,)
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
#define INF 1e9

#define mod 1000000007
int i, j, k, l, m;
int N, M, K,X;
int W,H,x,y;
int dp[100005][2];
double ans;
signed main()
{
    cin>>W>>H>>x>>y;

    ans = W * H / 2.0;

    int multiple = 0; // 
    
    if (x == W/2.0 && y == H/2.0) {
        multiple = 1;
    }
    else multiple = 0;

    cout<<ans<<" "<<multiple<<endl;


    return 0;
}

Measured memory_bytes: 256
def main():
    l, r = map(int, open(0).read().split())
    MOD = 2019
    if r - l >= MOD:
        print(0)
        return()
    l %= MOD
    r %= MOD
    if l == 0 or r == 0:
        print(0)
        return()
    if l > r:
        r += MOD

    ans = float('inf')
    for i in range(l, r):
        for j in range(i+1, r+1):
            ans = min(ans, i * j % MOD)

    print(ans)
    return()

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        String[] str = sc.next().split("");
        int n = Integer.parseInt(sc.next());
        String target = str[n - 1];
        String result = "";
        for (int i = 0; i < a; i++) {
            if (!str[i].equals(target)) {
                str[i] = "*";
            }
            result += str[i];
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 23764
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>

int main() {
  using namespace std;
  
  int N, Y;
  cin >> N >> Y;
  
  for (int x = 0; x <= N; x++) {
    for (int y = 0; x + y <= N; y++) {
      if (x * 10000 + y * 5000 + max(0, (N - x - y)) * 1000 == Y) {
        printf("%d %d %d\n", x, y, (N - x - y));
        return 0;
      }
    }
  }
  printf("-1 -1 -1\n");
}

Measured memory_bytes: 256
def Int():
    return int(input())
def Ints():
    return map(int,input().split())
def IntList():
    return list(Ints())
def IntMat(N):
    return [IntList() for i in range(N)]

S = input()
L = len(S)
S = S[::-1]

T = [-1]*L
mod = 2019
now = 0
for i in range(L):
    s = S[i]
    now += int(s)*pow(10,i,mod)
    T[i] = now%mod
    
Nlist = [0]*2019
Nlist[0] = 1

for i in T:
    Nlist[i] += 1
    
ans = 0
for i in Nlist:
    ans += i*(i-1)//2
print(ans)

Measured memory_bytes: 75664
#include<iostream>

using namespace std;

int main()
{
  long long X;
  long long money(100);
  cin >> X;
  long long year(0);
  while(money < X)
  {
    year++;
    money = static_cast<long long>(money *  1.01);
  }
  cout << year << endl;
  return 0;
}

Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

h,w = map(int, input().split())
a = [['.'] * (w+2) for i in range(h+2)]

for i in range(1,h+1):
    temp = list(input())
    for j in range(1,w+1):
        a[i][j] = temp[j-1]

#print(a)
ok =1
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]== "#":
            if a[i-1][j]=="." and a[i+1][j]=="." and a[i][j-1]=="." and a[i][j+1]==".":
                ok = 0
                break
    if ok == 0:
        break

if ok == 0:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 12456
#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(){
  int N,tmp;
  cin >> N;

  tmp = N%10;

  if(tmp==3){
    cout << "bon" << endl;
  } else if(tmp==2 || tmp==4 || tmp==5 || tmp==7 || tmp==9){
    cout << "hon" << endl;
  } else {
    cout << "pon" << endl;
  }

  return 0;
}

Measured memory_bytes: 3624
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-


def main():
    S = [(True if c == '1' else False) for c in input() ]

    min_ = float('inf')

    for c in (True, False):
        num = 0
        for s in S:
            if s != c:
                num += 1
            c = not c
        min_ = min(num, min_)

    print(min_)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define debug(a) cout << #a ": " << a << endl
#define int long long
using namespace std;
typedef long long ll;
const int N = 2e5 + 7;
int a[N], vis[N];
signed main(void){ 
    IOS;
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    int now = 1;
    while (1){
        vis[now] = 1;
        int nxt = a[now];
        if (!vis[nxt]){
            now = nxt;
            k--;
            if (k == 0){
                cout << now << endl; return 0;
            }
        }else{
            break;
        }
    }
    int loop = 1;
    for (int i = a[now]; i != now; i = a[i]) loop++;
    //debug(loop);
    k %= loop;
    for (int i = 0; i < k; ++i){
        now = a[now];
    }
    cout << now << endl;
    return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  int a[m];
  for(int i=0;i<m;i++){
    cin >> a[i];
    n-=a[i];
  }
  if(n<0){
    cout << -1 << endl;
  }else{
    cout << n << endl;
  }
}

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

using namespace std;

int k[]={5,7,5,7,7};

int main(){
	
	while(1){
		
		int n;
		cin >> n;
		if(n==0) break;
		
		string a;
		int t[n]={};
		
		for(int i=0;i<n;i++){
			cin >> a;
			t[i]=(int)a.size();
		}
		int c,ans=0;
		for(int i=0;i<n;i++){
			c=i;
			int j;
			for(j=0;j<5;j++){
				int b=0;
				while(b<k[j]){
					b+=t[c];
					c++;
				}
				if(b>k[j]) break;
			}
			if(j==5){
				ans=i;
				break;
			}
		}
		cout << ans+1 << endl;
	}
		
		
	return 0;
}


Measured memory_bytes: 3136
x,n=map(int,input().split())
if n!=0:
  s=set(list(map(int,input().split())))
else:
  s=[]
diff=10**18
ans=10**18
for i in range(-10000,10000):
  if i in s:
    continue
  else:
    if abs(x-i)<diff:
      ans=i
      diff=abs(x-i)
print(ans)

Measured memory_bytes: 64540
#include <stdio.h>
#include <string.h>
int max(int a,int b){
  if(a<b)return b;
  else return a;
}
int lcs(char *x,char *y){
 
  int i,j;
  int xlen,ylen;
  int dp[1001][1001];
   
  xlen=strlen(x);
  ylen=strlen(y);
  for(i=0;i<=xlen;i++)dp[i][0]=0;
  for(j=0;j<=ylen;j++)dp[0][j]=0;
  for(i=0;i<xlen;i++){
    for(j=0;j<ylen;j++){
      if(x[i]==y[j]) dp[i+1][j+1]=dp[i][j]+1;
      else dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1]);
    }
  }
  return dp[xlen][ylen];
}
int main(){
  int q;
  char x[1001];
  char y[1001];
  int leng;
  scanf("%d",&q);
  while(q>0){
    scanf("%s",x);
    scanf("%s",y);
 
    printf("%d\n",lcs(x,y));
    q--;
  }
  return 0;
}



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

int main() {
  int n;
  cin >>n;
  map<long long,long long>mp;
  for(long long i=0;i<n;i++){
    long long x;
    cin>>x;
    x*=-1;
    if(mp.count(x))mp.at(x)++;
    else mp[x]=1;
  }
  long long tate=0;
  long long yoko=0;
  long long kotae=0;
  auto begin=mp.begin(),end=mp.end();
  for(auto iter=begin;iter!=end;iter++){
    if(iter->second >=2 && tate==0){
      tate=iter->first;
      mp[iter->first]-=2;
    }
    if(iter->second >=2 && tate!=0 && yoko==0){
      yoko=iter->first;
    }
    if(tate!=0&&yoko!=0)break;
  }
  kotae=tate*yoko;
  cout<<kotae<<endl; 
  return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

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

    int alice=0;
    int bob=0;
    sort(a.begin(),a.end(),std::greater<int>());

    for(int i=0;i<N;i++){
        if(i%2==0){
            alice+=a[i];
        }
        else{
            bob+=a[i];
        }
    }

    cout << (alice-bob) << endl;
    return 0;
}



Measured memory_bytes: 256
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#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) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10 , P = 1e9 + 7;
int H , W , A , B;
int fac[N] , ifac[N];
int comb(int a,int b) {
  return ll(fac[a])*ifac[b]%P*ifac[a-b]%P;
}
int go(int a,int b,int c,int d) {
  return comb(c + d - a - b , c - a);
}

int main(){
  fac[0] = 1;
  rep(i,1,N) fac[i]=ll(fac[i-1])*i%P;
  ifac[0] = ifac[1] = 1;
  rep(i,2,N) ifac[i]=P-ll(P/i)*ifac[P%i]%P;
  rep(i,1,N) ifac[i]=ll(ifac[i-1])*ifac[i]%P;
  cin >> H >> W >> A >> B;
  int ans = 0;
  rep(i,1,H-A+1) {
    ans += ll(go(1 , 1 , i , B)) * go(i , B + 1 , H , W) % P;
    if(ans >= P)
      ans -= P;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n,pm,pe,pj;
	while(cin>>n,n){
		for(;n;--n){
			cin>>pm>>pe>>pj;
			
			int avr = pm+pe+pj;
			
			if(pm==100 || pe==100 || pj==100)cout<<"A";
			else if(pm+pe>=180)cout<<"A";
			else if(avr>=240)cout<<"A";
			else if(avr>=210)cout<<"B";
			else if(avr>=150 && (pm>=80||pe>=80))cout<<"B";
			else cout<<"C";
			
			cout<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;

int so[1000001];

int n,a,d;

int main(){
	
	so[0]=so[1]=1;
	
	for(int i=2;i*i<1000001;i++){
		if(so[i]==1)continue;
		//printf("%d\n",i);
		for(ll j=i;j*i<1000001;j++){
			//printf("%d\n",i*j);
			//if(i>=46349)printf("%d\n",i*j);
			so[i*j]=1;
		}
	}
	
	//puts("prime complete");
	
	while(cin>>a>>d>>n){
		if(a==0 && d==0 && n==0)break;
		
		int i=-1;
		
		while(n){
			++i;
			if(so[a+d*i]==0){
				--n;
			}
		}
		
		printf("%d\n",a+d*i);
	}
	return 0;
}

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

int main()
{
    string str;
    cin >> str;
    string pat1, pat2;

    pat1 = '0';
    pat2 = '1';

    int count1 = 0, count2 = 0;

    for (int i = 1; i < str.size(); i++) {
        if (i % 2 == 1) {
            pat1 += '1';
            pat2 += '0';
        }
        else {
            pat1 += '0';
            pat2 += '1';
        }
    }

    for (int i = 0; i < str.size(); i++) {
        if (str[i] == pat1[i]) {
            count1++;
        }
        if (str[i] == pat2[i]) {
            count2++;
        }
    }

    cout << min(count1, count2) << endl;
    return 0;
}

Measured memory_bytes: 768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(I, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using ll = long long;

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> v1(n);
  vector<bool> ok(n,true);
  int mx = 0;
  
  REP(i,n){
    cin >> v[i];
    v1[i] = v[i];
  }
  sort(v1.begin(),v1.end());
  REP(i,n){
    if(v[i] != v1[n-1]){
      mx = max(mx,v[i]);
    }
  }
  
  if(v1[n-1] == v1[n-2]){
    REP(i,n){
      cout << v1[n-1] << endl;
    }
  }
  else{
    REP(i,n){
      if(v[i] == v1[n-1]){
        cout << mx << endl;
      }
      else{
        cout << v1[n-1] << endl;
      }
    }
  }
	
  
  
}

Measured memory_bytes: 4876
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a,b,c=0;
	bool f=true;
	vector<pair<int,int> >v;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	for(int i=0;i<n;i++)
	{
		if(v[i].first==v[i].second)
		{
			c++;
			
			if(c>=3)
			{				
				f=false;
				break;
			}
		}
		else
		{
			c=0;
		}
	
	}
	if(f)cout<<"No"<<endl;
	else cout<<"Yes"<<endl;
}

Measured memory_bytes: 3556
def main():
    N = 3
    c = []
    for i in range(N):
        c.append([int(j) for j in input().split()])
    for i in range(N-1):
        for j in range(N-1):
            if c[i][j] + c[i+1][j+1] != c[i][j+1] + c[i+1][j]:
                print('No')
                return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060