akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1ll << 60;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

string S, T;


int main(){
  cin >> S >> T;

  for (int i = S.length() - T.length(); i >= 0; i--){
    bool flag = true;
    for (int j = 0; j < T.length(); j++){
      if (S[i + j] != T[j] && S[i + j] != '?') {
        flag = false; break;
      }
    }
    if (!flag) continue;

    for (int j = 0; j < T.length(); j++) S[i + j] = T[j];
    for (int j = 0; j < S.length(); j++){
      if (S[j] == '?') S[j] = 'a';
    }
    cout << S << endl;
    return 0;
  }
  
  cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = s; i < n; i++)
const int maxn = 3005;
int N;
double p[maxn];
double prob[maxn][maxn];

int main(){
	cin>>N;
	rep(i,0,N) cin>>p[i];
	prob[0][1] = p[0];
	prob[0][0] = 1-p[0];
	rep(i,1,N){
		//head for i
		double tmp = p[i];
		rep(j,1,i+2){
			prob[i][j]+=prob[i-1][j-1]*tmp;
		}
		tmp = 1-p[i];
		rep(j,0,i+1) prob[i][j]+=prob[i-1][j]*tmp;
		// rep(j,0,i+1) cout<<prob[i][j]<<" ";
		// cout<<endl;
	}
	double ans = 0;
	int start = N/2+1;
	rep(i,start, N+1){
		ans+=prob[N-1][i];
		// cout<<prob[N-1][i]<<endl;
	}
	cout<<fixed<<setprecision(15)<<ans<<endl;
}
		

Measured memory_bytes: 68992
use std::collections::*;

fn main() {
    use std::io::Read;
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    
    let x: usize = iter.next().unwrap().parse().unwrap();
    let y: usize = iter.next().unwrap().parse().unwrap();
    let z: usize = iter.next().unwrap().parse().unwrap();
    let t: usize = iter.next().unwrap().parse().unwrap();
    let mut a: Vec<u64> = (&mut iter).take(x).map(|x| x.parse().unwrap()).collect();
    let mut b: Vec<u64> = (&mut iter).take(y).map(|x| x.parse().unwrap()).collect();
    let mut c: Vec<u64> = (&mut iter).take(z).map(|x| x.parse().unwrap()).collect();
    
    a.sort();
    b.sort();
    c.sort();
    a.reverse();
    b.reverse();
    c.reverse();

    let mut heap = BinaryHeap::new();
    let mut set = HashSet::new();
    let init = (a[0]+b[0]+c[0], 0, 0, 0);
    heap.push(init);

    while let Some((p, i, j, k)) = heap.pop() {
        if set.contains(&(i,j,k)) {continue;}
        if set.len() == t {break;}
        println!("{}", p);
        if i+1<x {
            heap.push((a[i+1]+b[j]+c[k], i+1,j,k));
        }
        if j+1<y {
            heap.push((a[i]+b[j+1]+c[k], i,j+1,k));
        }
        if k+1<z {
            heap.push((a[i]+b[j]+c[k+1], i,j,k+1));
        }
        set.insert((i,j,k));
    }
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	string s;
	cin>>n;
	cin>>s;
	int l=s.size();
	for(int i=0;i<l;i++){
        if(s[i]+n>90)
        s[i]-=26;
		 s[i]+=n;		
	}
	for(int i=0;i<l;i++)
	cout<<s[i];
	
	
	
	
	
	
	
	
	
	return 0;
} 

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

struct shop {
	int id;
	vector<int>prices;
};
struct Edge {
	int from;
	int to;
	int cost;
};
struct aa {
	int now;
	bitset<11>came;
	int cost;
};

class Compare {
public:
	bool operator()(const aa&l, const aa&r) {
		return l.cost > r.cost;
	}
};
int N, Q;
int solve(const vector<vector<Edge>>&edges, const bitset<11>&fst_came) {
	vector<vector<int>>memo(N + 1, vector<int>(1 << (N + 1), 1e9));
	priority_queue<aa, vector<aa>, Compare>que;
	que.push(aa{ 0,fst_came,0 });
	while (!que.empty()) {
		aa atop(que.top());
		que.pop();
		if (atop.now == 0 && atop.came.count() == N + 1)return atop.cost;
		else {
			for (auto e : edges[atop.now]) {
				bitset<11>nextcame(atop.came);
				nextcame[e.to] = true;
				const int nextcost = atop.cost + e.cost;
				if (memo[e.to][nextcame.to_ulong()] > nextcost) {
					memo[e.to][nextcame.to_ulong()] = nextcost;
					que.push(aa{ e.to,nextcame,nextcost });
				}
			}
		}
	}
	return 1e9;
}

int main() {
	while (1) { cin >> N;
		if (!N)break;
		vector<shop>shops;
		{
			map<string, int>mp;
			int num = 0;
			vector<vector<int>>sells(N,vector<int>(2000,1e7));
			for (int i = 0; i < N; ++i) {
				int k; cin >> k;
				shop ash;
				ash.id = i;
				for (int j = 0; j < k; ++j) {
					string st; cin >> st;
					int price; cin >> price;
					if (mp.find(st) == mp.end())mp[st] = num++;
					sells[i][mp[st]] = min(sells[i][mp[st]],price);
				}
			}
			 cin >> Q;
			vector<int>needs(Q);
			for (int i = 0; i < Q; ++i) {
				string st; cin >> st;
				if (mp.find(st) == mp.end())mp[st] = num++;
				needs[i] = mp[st];
			}
			for (int i = 0; i < N; ++i) {
				shop sh;
				sh.id = i;
				for (int j = 0; j < Q; ++j) {
					sh.prices.push_back(sells[i][needs[j]]);
				}
				shops.push_back(sh);
			}
		}
		vector<vector<Edge>>edges(N+1);
		{
			int M; cin >> M;
			for (int i = 0; i < M; ++i) {
				int s, t, d; cin >> s >> t >> d;
				edges[s].push_back(Edge{ s,t,d });
				edges[t].push_back(Edge{ t,s,d });
			}
		}
		pair<int, int>ans(1e7,1e8);
		for (int b = 0; b < (1 << N); ++b) {
			bitset<10>bs(b);
			int price_sum = 0;
			int aprice = 1e8;
			for (int j = 0; j < Q; ++j) {
				int aprice = 1e8;
				for (int i = 0; i < N; ++i) {
					if (bs[i])aprice = min(aprice, shops[i].prices[j]);
				}
				price_sum += aprice;
			}
			if (ans.first < price_sum)continue;
			else {
				bitset<11>came;
				came[0] = true;
				for (int i = 0; i < N; ++i) {
					if (!bs[i])came[i + 1] = true;
				}
				int cost = solve(edges, came);
				if (cost > 5e8)continue;
				else {
					ans = min(ans, make_pair(price_sum, cost));
				}
			}
		}
		if (ans.first > 6e6) {
			cout << "impossible" << endl;
		}
		else {
			cout << ans.first << " " << ans.second << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3276
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
using namespace std;

int main(){

	int N,E,limit,tmp,minimum;
	scanf("%d %d",&N,&E);

	limit = pow(2,N);

	int cost[N][N];

	for(int i = 0; i < N; i++){
		for(int k = 0; k < N; k++)cost[i][k] = BIG_NUM;
	}

	int from,to,value;

	for(int i = 0; i < E; i++){
		scanf("%d %d %d",&from,&to,&value);
		cost[from][to] = value;
	}

	int*** dp = new int**[N+1];
	for(int i = 0; i <= N; i++){
		dp[i] = new int*[N];
		for(int k = 0; k < N; k++){
			dp[i][k] = new int[limit];
			for(int p = 0; p < limit; p++)dp[i][k][p] = BIG_NUM;
		}
	}

	minimum = BIG_NUM;
	for(int start = 0; start <= 0; start++){

		tmp = pow(2,start);

		dp[0][start][tmp] = 0;

		for(int i = 1; i <= N; i++){
			for(int k = 0; k < N; k++){
				for(int p = 0; p < limit; p++){
					if(dp[i-1][k][p] != BIG_NUM){
						for(int a = 0; a < N; a++){
							if(p & (1 << a)){
								if(i == N && a == start){
									if(cost[k][start] != BIG_NUM)dp[i][start][limit-1] = min(dp[i][start][limit-1],dp[i-1][k][p]+cost[k][start]);
								}
							}else{
								if(cost[k][a] != BIG_NUM){
									tmp = p + pow(2,a);
									dp[i][a][tmp] = min(dp[i][a][tmp],dp[i-1][k][p]+cost[k][a]);
								}
							}
						}
					}
				}
			}
		}

		minimum = min(minimum,dp[N][start][limit-1]);
	}

	if(minimum == BIG_NUM){
		printf("-1\n");
	}else{
		printf("%d\n",minimum);
	}

}

Measured memory_bytes: 34508
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

void merge(const vector<int> &a, const vector<int> &b, vector<int> &c) {
  bool used[SIZE] = {};

  for(int p : a) {
    c.push_back(p);
    used[p] = true;
  }

  for(int p : b) {
    if(used[p]) {
      while(used[p]) {
        int q = c.back();
        c.pop_back();
        used[q] = false;
      }
    } else {
      used[p] = true;
      c.push_back(p);
    }
  }
}

set<int> ss[SIZE];

int main(){
  int N;
  ll K;
  vector<int> vec;

  scanf("%d%lld", &N, &K);

  bool used[SIZE] = {};
  for(int i=0; i<N; i++) {
    int a;
    scanf("%d", &a);
    a--;
    vec.push_back(a);
    ss[a].insert(i);
  }

  int loop = 0;
  int idx = 0;

  int pos[SIZE] = {};

  while(idx != N) {
    int p = vec[idx];
    pos[loop] = idx;
    if (ss[p].size() == 1) {
      idx++;
      loop++;
    } else {
      auto it = ss[p].lower_bound(idx+1);

      if (it == ss[p].end()) {
        it = ss[p].begin();
      }

      if (idx > *it) loop++;
      idx = (*it) + 1;
    }
  }

  loop++;
  K = K % loop;

  debug(loop);

  for(int i=0; i<loop; i++) debug(pos[i]);


  vector<int> ans;

  if (K > 0) {
    bool used[SIZE] = {};
    for(int i=pos[K-1];i<N;i++) {
      if (used[vec[i]]) {
        while(used[vec[i]]) {
          int p = ans.back();
          ans.pop_back();
          used[p] = false;
        }
      } else {
        ans.push_back(vec[i]);
        used[vec[i]] = true;
      }
    }
  }

  for(int i=0; i<ans.size(); i++) {
    printf("%d%c", ans[i] + 1, " \n"[ans.size() == i+1]);
  }


  return 0;
}


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }
template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	string S; cin >> S;
	if (S == "ABC") {
		cout << "ARC" << el;
	} else {
		cout << "ABC" << el;
	}
}

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


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

typedef long long ll;
const int INF = 1e8;
// const ll INF = 1LL << 60;
typedef pair<int, int> P;

ll X;
int main() {
    cin >> X;
    ll syo = X / 500;
    ll tmp = X - syo * 500;
    ll syo_5 = tmp / 5;

    ll ans = syo * 1000 + syo_5 * 5;
    cout << ans << endl;
}

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

apple = []
diff = 1001001001
minus = False
for i in range(1, n+1):
    apple.append(l+i-1)
    if abs(l+i-1) < diff:
        diff = abs(l+i-1)
        if l+i-1 < 0:
            minus = True
        else:
            minus = False

if minus:
    print(sum(apple) + diff)
else:
    print(sum(apple) - diff)

Measured memory_bytes: 9112
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<ll, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 100010;
const int MAXM = 110;
const int MAXK = 510;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    int pre = 0, res = 0;
    FOR(i,1,n) {
        int u;
        cin >> u;
        if (u >= pre) {
            pre = u;
            res++;
        }
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    std::map<string, int> balls;

    balls[s] = a;
    balls[t] = b;

    balls[u] = balls[u] - 1;

    cout << balls[s] << " " << balls[t] << endl;
    return 0;
}


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

dp = [2e9] * (H+1)
dp[0] = 0

for i in range(N):
  for h in range(H+AB[i][0]):
    if h - AB[i][0] < 0:
      continue
    else:
      dp[min(h, H)] = min(dp[min(h, H)], dp[h-AB[i][0]] + AB[i][1])

print(dp[H])

Measured memory_bytes: 51932
#include<iostream>
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    ll sum = 0;
    while(n-- > 0){
        int x; char c;
        cin >> x >> c >> x;
        if(c == '(')    sum += x;
        else            sum -= x;
        cout << (sum==0 ? "Yes" : "No") << endl;
    }
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
const ll MOD = 1000000007;

int main() {
  int n, x = 0, mx = 0;
  string s;
  cin >> n >> s;
  REP(i, n) {
    if (s[i] == 'I') ++ x;
    else --x;
    mx = max(x, mx);
  }
  cout << mx << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n;
    cin >> n;

    map<ll,ll> mp;
    rep(i,n-1){
        ll tmp;
        cin >> tmp;
        mp[tmp]++;
    }

    rep(i,n){
        cout << mp[i+1] << endl;
    }
    /*
    for(auto i: mp){
        cout << i.second << endl; //value
    }
    */

}

Measured memory_bytes: 16128
#include <stdio.h>
#include <string.h>
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char c){
  if(c=='A')return 1;
  else if(c=='C')return 2;
  else if(c=='G')return 3;
  else if(c=='T')return 4;
  else return 0;
}

long long getKey(char str[]){
  long long sum =0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
  long long key,h,i;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main() {
  int i,n,h;
  char str[L],com[9];
  for(i=0;i<M;i++)H[i][0]==0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s%s",com,str);
    if(com[0]=='i')insert(str);
    else {
      if(find(str)){
	printf("yes\n");
      }else {
	printf("no\n");
      }
    }
  }
  return 0;
}



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

using namespace std;
 
typedef long long int ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector <string> vs;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pi;

#define int ll
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238
#define MOD 1000000007
#define loop(n) for(int i = 0; i < n; i++)
#define rloop(n) for(int i = n-1; i >= 0; i--)

void io() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve() {
    int x, k, d;
    cin>>x>>k>>d;
    x = abs(x);
    int dd = x/d;
    if(k <= dd) x -= k*d;
    else {
        k -= dd;
        if(k%2==0) x -= d*dd;
        else {
            x -= d*(dd+1);
        }
    }
    x = abs(x);
    cout<<x<<"\n";
    return;
}
int32_t main() {
    io();
    int t=1;
    //cin>>t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int all[1000][1000];
int a,b,c,d,N;
int main(){
    cin>>N;
    for(int i=0;i<N*(N-1)/2;i++){
        cin>>a>>b>>c>>d;
        a=a-1;b=b-1;
        if(c>d){all[a][0]=all[a][0]+3;}
        if(c<d){all[b][0]=all[b][0]+3;}
        if(c==d){all[a][0]=all[a][0]+1;all[b][0]=all[b][0]+1;}
    }
    for(int u=0;u<N;u++){ all[u][1]=1; }
    for(int i=0;i<N;i++){
        for(int u=0;u<N;u++){
            if(all[i][0]>all[u][0]){ all[u][1]++;}
        }
    }
    for(int o=0;o<N;o++){ cout<<all[o][1]<<endl; }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --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 (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

ll f(ll A, ll B, ll x) {
    return A * x / B - A * (x / B);
}

int main(){
    ll A, B, N;
    cin >> A >> B >> N;

    // for (int a = 1; a <= 100; ++a) {
    //     for (int b = 1; b <= 100; ++b) {
    //         rep(x, 101) {
    //             cout << a << " " << b << " " << x << " " << f(a, b, x) << endl;
    //         }
    //     }
    // }
    cout << f(A, B, min(N, B-1)) << endl;
}

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

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

using namespace std;


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n;
    cin >> n;
    vector<ll> p(n);
    rep(i, n) cin >> p[i];

    ll minn = n-1;
    vector<bool> hmemo(n+5, false);

    map<ll, ll> m;
    rep(i, n) m[p[i]] = i;
    m[0] = 1e10;
    m[n+1] = -1;

    for(ll x = 1; x <= n; x++){
        ll xi = m[x];
        ll ri = m[x+1];
        if(ri < xi) hmemo[x] = true;
    }

    for(ll x = 1; x <= n; x++){
        if(!hmemo[x]){
            ll hcnt = 0;
            ll h = x;
            ll i = m[h];
            while(0 <= i && i < 1e10){
                if(p[i] == h){
                    hcnt++;
                    h++;
                    if(i < m[h]) i = m[h];
                    else         break;
                }
            }
            
            for(ll i = x; i < h; i++) hmemo[i] = true;
            minn = min(minn, n-hcnt);
        }
    }

    cout << minn << endl;



    return 0;
}

Measured memory_bytes: 14336
S = input()
Q = int(input())
top_str = ""
last_str = ""
s_parity = 0
for i in range(Q):
    q_list=input().split(" ")
    if q_list[0] == "1":
        s_parity += 1
    elif (s_parity%2) == 0:
        if q_list[1] == "1":
            top_str = q_list[2] + top_str
        else:
            last_str = last_str + q_list[2]
    else:
        if  q_list[1] == "1":
            last_str = last_str + q_list[2]
        else:
            top_str = q_list[2] + top_str


if s_parity % 2 ==1:
    S = S[::-1]
    S = last_str[::-1] + S + top_str[::-1]
else :
    S = top_str + S + last_str
print(S)


Measured memory_bytes: 4504
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INF 1000000000000000
#define MOD 1000000007

int main(){
  int N,K;
  cin>>N>>K;
  vector<vector<int>> black(K+1,vector<int>(K+1,0)),white(K+1,vector<int>(K+1,0));
  for(int i=0;i<N;i++){
    int x,y;
    char c;
    cin>>x>>y>>c;
    x%=(2*K);
    y%=(2*K);
    if(x<K&&y<K){
      if(c=='W'){
        white.at(x+1).at(y+1)++;
      }else{
        black.at(x+1).at(y+1)++;
      }
    }else if(x<K||y<K){
      if(c=='W'){
        black.at(x%K+1).at(y%K+1)++;
      }else{
        white.at(x%K+1).at(y%K+1)++;
      }
    }else{
      if(c=='W'){
        white.at(x%K+1).at(y%K+1)++;
      }else{
        black.at(x%K+1).at(y%K+1)++;
      }
    }
  }

  for(int i=0;i<K;i++){
    for(int j=0;j<K;j++){
      black.at(i+1).at(j+1)+=black.at(i+1).at(j);
      white.at(i+1).at(j+1)+=white.at(i+1).at(j);
    }
    for(int j=0;j<K;j++){
      black.at(i+1).at(j+1)+=black.at(i).at(j+1);
      white.at(i+1).at(j+1)+=white.at(i).at(j+1);
    }
  }

  int ans=0;
  for(int i=0;i<=K;i++){
    for(int j=0;j<=K;j++){
      ans=max(ans,black.at(K).at(K)-black.at(i).at(K)-black.at(K).at(j)+2*black.at(i).at(j)+white.at(i).at(K)+white.at(K).at(j)-2*white.at(i).at(j));
      ans=max(ans,white.at(K).at(K)-white.at(i).at(K)-white.at(K).at(j)+2*white.at(i).at(j)+black.at(i).at(K)+black.at(K).at(j)-2*black.at(i).at(j));
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 8192
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

S = str(input())

count = 0
max_count = 0
for i in range(3):
    if S[i] == 'R':
        if i >= 1 and S[i-1] == 'R':
            count += 1
        else:
            count = 1
    max_count = max(count,max_count)

print(max_count)

Measured memory_bytes: 65572
#pragma region head
    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    using vi = vector<int>;
    using vll = vector<ll>;
    using pi = pair<int, int>;
    using pll = pair<ll,ll>;
    template <class T> using vv = vector<vector<T>>;
    #define rep(i,n) for(int i = 0; i < (int)(n); i++)
    #define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
    #define rrep(i,n) for(int i = (int)(n)-1; i >= 0; i--)
    #define rrepi(i,a,b) for(int i = (int)(b)-1; i >= (int)(a); i--)
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()    
    #define bit(n) (1LL<<(n))
    template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
    template<class T> inline bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
#pragma endregion head

#pragma region library
// Complexity: sum:O(logn), add:O(logn)
template<typename T>
struct BinaryIndexedTree{
    int sz;
    vector<T> data;
    BinaryIndexedTree(int sz): sz(sz),data(sz+1) {}
    T sum(int k){
        // [0, k]
        T res = 0;
        for(k++; k > 0; k -= k & -k) res += data[k];
        return res;
    }
    T sum(int l, int r){
        // [l, r)
        return sum(r-1)-sum(l-1);
    }
    void add(int k, T x){
        for(k++; k <= sz; k += k & -k) data[k] += x;
    }
};
#pragma endregion library

int main(){
    int n,q; cin >> n >> q;
    vi c(n); rep(i,n) cin >> c[i];
    vi prv(n+1,-1);
    vector<pi> query;
    vector<map<int,int>> ans(n+1);
    BinaryIndexedTree<int> bt(n+1);
    rep(i,q){
        int l,r; cin >> l >> r;
        query.emplace_back(l,r);
        ans[r].emplace(l,0);
    }
    rep(i,n){
        int r = i+1;
        if(prv[c[i]]!=-1){
            bt.add(prv[c[i]],1);
        }
        prv[c[i]] = i;
        for(auto it=ans[r].begin();it!=ans[r].end();it++){
            int l = it->first;
            int val = r - l + 1 - bt.sum(l-1,r);
            it->second = val;
        }
    }
    rep(i,q){
        int l,r;
        tie(l,r) = query[i];
        cout << ans[r][l] << '\n';
        
    }
    
}


Measured memory_bytes: 60512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<functional>
using namespace std;
long long n, k, q, a, b, c, dist[120000]; vector<pair<long long, long long>>x[120000];
void dfs(long long pos, long long depth) {
	if (dist[pos] != -1)return;
	dist[pos] = depth;
	for (int i = 0; i < x[pos].size(); i++)dfs(x[pos][i].first, depth + x[pos][i].second);
}
int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		cin >> a >> b >> c;
		x[a].push_back(make_pair(b, c));
		x[b].push_back(make_pair(a, c));
	}
	for (int i = 1; i <= n; i++)dist[i] = -1;
	cin >> q >> k;
	dfs(k, 0);
	for (int i = 0; i < q; i++) {
		long long x, y;
		cin >> x >> y;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 14720
#include <stdio.h>
  
int main(){
  
  int a,b;
  
  scanf("%d %d",&a,&b);
  
  if(a>b){
    printf("a > b\n",a,b);
  }else if(a<b){
    printf("a < b\n",a,b);
  }else{
    printf("a == b\n",a,b);
  }
  return 0;
}


Measured memory_bytes: 2044
#include<iostream>
#include<algorithm>
#include<vector>
#include <cassert>

using namespace std;

int N, k, sum, A[100];

int bubble_sort_count(int r){
	sum = 0;
	for (int i = 0; i < r - 1;i++){
		for (int j = 0; j < r - i - 1;j++){
			if (A[j] > A[j + 1]){
				k = A[j + 1];
				A[j + 1] = A[j];
				A[j] = k;
				sum += 1;
			}
		}
	}
	return sum;
}

int main()
{
	cin >> N;
	while (N != 0){
		for (int n = 0; n < N; n++){
			cin >> A[n];
		}
		cout << bubble_sort_count(N) << endl;
		cin >> N;
	}
}

Measured memory_bytes: 1160
import sys
sys.setrecursionlimit(10**9)
K=int(input())
la=[]
tmp=0
sans=""
def f(tmp,K,i,j):
    global sans
    #if tmp==K:

    if j==9:
        ra=range(8,10)
    elif j==0:
        ra=range(2)
    else:
        ra=range(j-1,j+2)
    #for k in range(10):
    for k in ra:
        tmp+=la[i-1][k]
        if tmp==K and i==1:
            sans+=str(k)
            return
        elif tmp>=K:
            #print("tmp:",tmp)
            #print("K:",K)
            sans+=str(k)
            #f(0,tmp-K,i-2,k)
            #f(tmp-la[i-1][k],K,i-2,k)
            f(tmp-la[i-1][k],K,i-1,k)
            return
        """
        elif tmp==K and i==1:
            sans+=str(k)
            return
        """



for i in range(100):#keta=i+1
    la.append([0 for _ in range(10)])
    if i==0:
        #la[i][0]=0
        la[i][0]=1
        for j in range(1,10):
            la[i][j]=1
            tmp+=1
            if tmp==K:
                sans=str(j)
                break
        else:
            continue
        break
    else:
        #la[i][0]=sum(la[i-1])#
        la[i][0]=sum(la[i-1][:2])
        for j in range(1,10):
            if j==9:
                la[i][9]=sum(la[i-1][8:])
            else:
                la[i][j]=sum(la[i-1][j-1:j+2])
            tmp+=la[i][j]
            if tmp>=K:
                #print("tmp:",tmp)
                #print("j:",j)
                sans+=str(j)
                #K=tmp-K
                #tmp=0
                tmp-=la[i][j]
                f(tmp,K,i,j)
                break
        else:
            continue
        break
#print("la:",la)
#print(sans)
print(int(sans))

#la[0][0]直す
#初めて数字決定したあとの数字探し関数における
#、MSBに関するfor
#K,tmpの更新式を直す
#再帰f後のbreakまわり
#再帰fの終了条件_36_100の例
#ai[0]がおかしい_38_110の例


Measured memory_bytes: 3188
//ABC153 D

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

long long H;
long long ans = 0;

int main() {
  cin >> H;

  long long max_H = H;
  long long tmp = 1;
  while(H > 1){
    H = floor((double)H/2);
    ans += tmp;
    tmp <<= 1;
  }
    ans += tmp;

  printf("%lld\n",ans);

}


Measured memory_bytes: 256
import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(n, m) = sc.nextLine.split(" ").map(_.toInt)

    def go(n: Int, acc: Set[Int]): Set[Int]= {
      if (n == 0) acc
      else {
        go(n - 1, acc.intersect(sc.nextLine.split(" ").map(_.toInt).drop(1).toSet))
      }
    }
    println(go(n, (1 to m).toSet).size)
  }
}

Measured memory_bytes: 25528
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7,maxn = 3e5+100;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
int N,val[maxn],cnt[20];
int d[maxn],ss[maxn];
int main(){
    read(N);
    for(int i = 0;i<N-1;i++){
        int x,y,a;
        read(x),read(y),read(a);
        val[x]^=a;
        val[y]^=a;
    }
    for(int i = 0;i<N;i++){
        if(val[i])cnt[val[i]]++;
    }
    int ans = 0,st = 0;
    for(int i = 0;i<16;i++){
        ans+=cnt[i]/2;
        if(cnt[i]&1)st = st|(1<<i);
    }
    for(int i = 1;i<=(1<<16);i++)d[i] = d[i>>1]+(i&1);
    for(int i = 1;i<=(1<<16);i++)d[i]--;
    for(int i = 1;i<=(1<<16);i++){
        for(int j = 0;j<=15;j++){
            if(i&(1<<j))ss[i]^=(j);
        }
    }
    for(int i = 1;i<=(1<<16);i++){
        if(ss[i]!=0)continue;
        for(int k = (i-1)&i;k;k = (k-1)&i){
            if(ss[k]==0)d[i] = min(d[i],d[k]+d[i^k]);
        }
    }
    printf("%d\n",ans+d[st]);
    return 0;
}

Measured memory_bytes: 1152
while True:
    H, W = map(int, input().split())
    if H == 0 and W == 0:
        break
    for i, h in enumerate((range(H - 1))):
        if i == 0:
            print('#' * W)
        else:
            print('#' + '.' * (W - 2) + '#')
    print('#' * W)
    print()


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

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

int main(void){
   int answer = 0;
   string S,T;
   cin >> S >> T;
   for(int i = 0; i < S.size(); i++){
     if(S.at(i) != T.at(i) ){
       answer++;
     }
   }
  cout << answer;
}

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

int main(){
  char moji;
  cin >> moji;
  if(moji == 'a') cout << 'a' << endl;
  else if(moji == 'b') cout << 'a' << endl;
  else if(moji == 'c') cout << 'a' << endl;
  else if(moji == 'd') cout << 'a' << endl;
  else if(moji == 'e') cout << 'a' << endl;
  else if(moji == 'f') cout << 'a' << endl;
  else if(moji == 'g') cout << 'a' << endl;
  else if(moji == 'h') cout << 'a' << endl;
  else if(moji == 'i') cout << 'a' << endl;
  else if(moji == 'j') cout << 'a' << endl;
  else if(moji == 'k') cout << 'a' << endl;
  else if(moji == 'l') cout << 'a' << endl;
  else if(moji == 'm') cout << 'a' << endl;
  else if(moji == 'n') cout << 'a' << endl;
  else if(moji == 'o') cout << 'a' << endl;
  else if(moji == 'p') cout << 'a' << endl;
  else if(moji == 'q') cout << 'a' << endl;
  else if(moji == 'r') cout << 'a' << endl;
  else if(moji == 's') cout << 'a' << endl;
  else if(moji == 't') cout << 'a' << endl;
  else if(moji == 'u') cout << 'a' << endl;
  else if(moji == 'v') cout << 'a' << endl;
  else if(moji == 'w') cout << 'a' << endl;
  else if(moji == 'x') cout << 'a' << endl;
  else if(moji == 'y') cout << 'a' << endl;
  else if(moji == 'z') cout << 'a' << endl;
  else cout << 'A' << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <cmath>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, q; cin >> n >> q;
    int initial = pow(2, 31) - 1;
    int a[n]; REP(i, n) a[i] = initial;
    int com, s, t;

    REP(i, q) {
        cin >> com >> s >> t;
        if (com) {
            initial = pow(2, 31) - 1;
            for (int i = s; i <= t; i++) {
                if (initial > a[i]) {
                    initial = a[i];
                }
            }
            cout << initial << endl;
        } else {
            a[s] = t;
        }
    }

    return 0;
}


Measured memory_bytes: 3492
// duck is bad
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;

const int mod = 998244353;

typedef unsigned long long lu;
typedef bitset<120> Bitset;

bool operator < (const Bitset &a, const Bitset &b) {
  lu *p = (lu*)(&a), *q = (lu*)(&b);
  return p[1] == q[1] ? p[0] < q[0] : p[1] < q[1];
}

bool operator <= (const Bitset &a, const Bitset &b) {
  lu *p = (lu*)(&a), *q = (lu*)(&b);
  return p[1] == q[1] ? p[0] <= q[0] : p[1] < q[1];
}

struct Cmp {
  bool operator () (const Bitset &a, const Bitset &b) const {
    return a < b;
  }
};

int n;
char str[101];
map<Bitset, int, Cmp> dp;

// void Print(Long s) {
//   printf("%d ", (int)s);
//   while (s > 1) {
//     putchar('0' + (s & 1));
//     s >>= 1;
//   }
//   putchar('@');
// }

inline int Add(int a) {
  return a >= mod ? a - mod : a;
}

inline int Mul(int a, int b) {
  return (int)((long long)a * b % mod);
}

int Dfs(Bitset s) {
  if (dp.count(s)) {
    return dp[s];
  }
  dp[s] = Dfs(s >> 1);
  if (s[0]) {  // if (s & 1) {
    dp[s] = Add(dp[s] << 1);
  }

  int len = 0;
  Bitset single_bit;
  single_bit[1] = 1;
  while (single_bit <= s) {
    ++len;
    single_bit <<= 1;
  }

  Bitset one_d;
  for (int d = 1; d < len; ++d) {
    // Long t = s & ((Long)1 << d) - 1;
    one_d[d - 1] = 1;
    Bitset t = s & one_d;

    for (int k = 2; k * d <= len; ++k) {
      // t &= s >> (k - 1) * d & ((Long)1 << d) - 1;
      t &= s >> (k - 1) * d & one_d;
      // dp[s] = Add(dp[s] + Mul(Dfs(t | (Long)1 << d), Dfs(s >> k * d)));
      Bitset t2 = t;
      t2[d] = 1;
      dp[s] = Add(dp[s] + Mul(Dfs(t2), Dfs(s >> k * d)));
    }
  }

  // Print(s);
  // printf(" %d\n", dp[s]);
  return dp[s];
}

int main(void) {
  scanf("%s", str);
  n = (int)strlen(str);
  Bitset s;
  s[0] = 1;
  dp[s] = 1;
  for (int i = 0; i < n; ++i) {
    // s = s << 1 | (str[i] - '0');
    s <<= 1;
    s[0] = (int)(str[i] - '0');
  }
  
  printf("%d\n", Dfs(s));
  return 0;
}


Measured memory_bytes: 3072
n = input()
lst = list(map(int,input().split()))
even = []
deny = 0

for i in lst:
    if i % 2 == 0:
        even.append(i)

for j in even:
    if j % 3 == 0 or j % 5 == 0:
        continue
    else:
        deny = 1

if deny == 0:
    print("APPROVED")
else:
    print("DENIED")
    

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,m;
string S,T;
int main()
{
	cin>>S>>T;
	n=S.size();
	m=T.size();
	if (n+1==m && S==T.substr(0,n)) puts("Yes"); else puts("No");
	return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  string s1, s2, s3;
  cin >> s1 >> s2 >> s3;
  cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
  }


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  string in;
  while(getline(cin,in)){
    if(in=="") break;
    stringstream ss;
    ss<<in;
    int l,tmp;
    vector<int> r;
    ss>>l;
    while(ss>>tmp)r.push_back(tmp);
    bool able = false;
    REP(i,r.size()){
      vector<int> tmp = r;
      int prev = r[i];
      double alen = r[i];
      tmp.erase(tmp.begin()+i);
      while(!tmp.empty()){
        PII maxp = PII(-1,0);
        REP(i,tmp.size()){
          if(abs(prev-tmp[i])>maxp.first){
            maxp = PII(abs(prev-tmp[i]),i);
          }
        }
        int next = tmp[maxp.second];
        alen += 2*sqrt(next*prev);
        prev = next;
        tmp.erase(tmp.begin()+maxp.second);
      }
      alen += prev;
      if(alen<=(double)l){
        able = true;
        break;
      }
    }
    if(able) cout<<"OK"<<endl;
    else cout<<"NA"<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		int[] a = new int[n+1];
		for(int i = 1; i <= n; i++){
			a[i] = sc.nextInt();
		}
		int[] fst = new int[n+1];
		int idx = 1, pnt = 1, tmp;
		long zan = k;
		fst[1] = 1;
		while(zan > 0){
			idx++;
			zan--;
			pnt = a[pnt];
			if(fst[pnt] > 0){
				tmp = idx - fst[pnt];
				zan %= (long)tmp;
				Arrays.fill(fst, 0);
			} else {
				fst[pnt] = idx;
			}
		}
		System.out.println(pnt);
	}
}


Measured memory_bytes: 60012
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,s,e) for(int i=s;i<e;i++)
#define endl '\n'
int main(){
    int N;cin>>N;
    vector<int>X(N+1),Y(N+1),T(N+1);
    X[0]=0;
    Y[0]=0;
    T[0]=0;
    rep(i,0,N)cin>>T[i+1]>>X[i+1]>>Y[i+1];
    rep(i,0,N){
        int dt=T[i+1]-T[i];
        int dist=abs(X[i+1]-X[i])+abs(Y[i+1]-Y[i]);
        if(dt<dist){
            cout<<"No"<<endl;
            return 0;
        }
        if(dt%2!=dist%2){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 4176
#include <iostream>
#include <string.h>
using namespace std;

void popBack2(char *str);

int main() {
	char s[200];
	cin >> s;
	popBack2(s);
	while(strncmp(s, s + strlen(s)/2, strlen(s)/2)) {
		popBack2(s);
	}
	cout << strlen(s) << endl;
	return 0;
}

void popBack2(char *str) {
	const int len = strlen(str);
	if(len == 0 || len == 1) {
		return;
	} else {
		str[len-1] = '\0';
		str[len-2] = '\0';
		return;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main ()
{
  string S,T;
  cin >> S >> T;
  int a,b;
  cin >> a >> b;
  string U;
  cin >> U;
  if(U==S) a--;
  else if(U==T) b--;
  cout << a << " " << b;
  return 0;


 return 0;
}

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

using namespace std;

const int N = 100010;
const int MOD = 1e9 + 7;

int n, f[N][2];
bitset <N> vis[2];
vector <int> g[N];

int call (int u = 1, int from = -1, int last = 0) {
  if (vis[last][u]) return f[u][last];
  vis[last][u] = f[u][last] = 1;
  for (int v : g[u]) if (v - from) {
    f[u][last] = f[u][last] * 1LL * call(v, u, 0) % MOD;
  }
  if (!last) {
    int add = 1;
    for (int v : g[u]) if (v - from) {
      add = add * 1LL * call(v, u, 1) % MOD;
    }
    f[u][last] += add;
    if (f[u][last] >= MOD) f[u][last] -= MOD;
  }
  return f[u][last];
}

int main() {
  cin >> n;
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  cout << call() << endl;
  return 0;
}



Measured memory_bytes: 14848
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <vector>

#define INF (2000000000000000000L)

using namespace std;

long mod(long n, long k) { return n % k >= 0 ? n % k : n % k + k; }

long pow(long x, long k, long num_mod) {
  long ret = 1, p = mod(x, num_mod);
  while (k > 0) {
    if (k & 1) {
      ret = mod(ret * p, num_mod);
    }
    p = mod(p * p, num_mod);
    k /= 2;
  }
  return ret;
}

long calc_e(long l, long r, long num_mod) {
  if (l == 0) {
    return 0;
  }
  if (l % 2 == 0) {
    const long l0 = l / 2, rpowl0 = pow(r, l0, num_mod),
               e0 = calc_e(l0, r, num_mod);
    return mod((rpowl0 + 1) * e0, num_mod);
  } else {
    const long l0 = l - 1, rpowl0 = pow(r, l0, num_mod),
               e0 = calc_e(l0, r, num_mod);
    return mod(e0 + rpowl0, num_mod);
  }
}

long calc_d(long l, long a, long b, long r, long num_mod) {
  if (l == 0) {
    return 0;
  }
  if (l % 2 == 0) {
    const long l0 = l / 2, rpowl0 = pow(r, l0, num_mod),
               bl0 = mod(mod(b, num_mod) * mod(l0, num_mod), num_mod),
               d0 = calc_d(l0, a, b, r, num_mod), e0 = calc_e(l0, r, num_mod);
    const long t1 = mod((rpowl0 + 1) * d0, num_mod),
               t2 = mod(bl0 * e0, num_mod);
    return mod(t1 + t2, num_mod);
  } else {
    const long l0 = l - 1, rpowl0 = pow(r, l0, num_mod),
               bl0 = mod(mod(b, num_mod) * mod(l0, num_mod), num_mod);
    const long t1 = mod(r * calc_d(l0, a, b, r, num_mod), num_mod),
               t2 = mod(a, num_mod), t3 = bl0;
    return mod(t1 + t2 + t3, num_mod);
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  long L, A, B, M;
  scanf("%ld %ld %ld %ld", &L, &A, &B, &M);

  // calculate vs[k]
  //     vs[k] : min(min_i {i | s_i >= 10^{k-1}}, L)
  vector<long> vs;
  vs.push_back(0);  // let vs[0] = 0
  for (long k = 1; k <= 19; k++) {
    const long ten_pow_km1 = pow(10, k - 1, INF);
    long le = -1, ri = L;
    while (ri - le > 1) {
      const long m = (le + ri) / 2;
      if (A + B * m >= ten_pow_km1) {
        ri = m;
      } else {
        le = m;
      }
    }
    vs.push_back(ri);
    // printf("k = %ld, vs[k] = %ld\n", k, vs[k]);
  }

  // solve
  long ans = 0;
  for (long k = 1; k < 19; k++) {
    // we need to be very careful taking the mod of l
    const long v_kp1 = vs[k + 1], v_k = vs[k], n_k = v_kp1 - v_k;
    const long l = n_k, a = mod(A + B * v_k, M), b = mod(B, M),
               r = pow(10, k, M), c_k = calc_d(l, a, b, r, M);
    ans = mod(mod(pow(r, n_k, M) * ans, M) + c_k, M);
    // printf("k = %ld, n_k = %ld, times = %ld\n", k, n_k, k * n_k);
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 100005
#define NIL -1

typedef struct Node{
  int dim;
  int *child;
  int p;
  int dep;
} node;

node tree[MAX];
void calcDep(int r){
  int i;
  for(i=0;i<tree[r].dim;i++){
    tree[tree[r].child[i]].dep+=1+tree[r].dep;

    calcDep(tree[r].child[i]);
  }
}

int main(){
  int n,i,j,k;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    tree[i].p=NIL;
    tree[i].dep=0;
  }
  for(k=0;k<n;k++){
    scanf("%d",&i);
    scanf("%d",&tree[i].dim);
    tree[i].child=(int *)malloc(sizeof(int)*tree[i].dim);
    for(j=0;j<tree[i].dim;j++){
      scanf("%d",&tree[i].child[j]);
      tree[tree[i].child[j]].p=i;
    }
  }
  for(i=0;i<n;i++){
    if(tree[i].p==NIL) k=i;
  }
  calcDep(k);
  for(i=0;i<n;i++){
    printf("node %d: parent = %d, depth = %d, ",i,tree[i].p,tree[i].dep); 
    if(tree[i].p==NIL){
      printf("root, [");
      for(j=0;j<tree[i].dim;j++){
	printf("%d",tree[i].child[j]);
	if(j!=tree[i].dim-1) printf(", ");
      }
    }
    else if(tree[i].dim==0){
      printf("leaf, [");
    }
    else{
      printf("internal node, [");
      for(j=0;j<tree[i].dim;j++){
	printf("%d",tree[i].child[j]);
	if(j!=tree[i].dim-1) printf(", ");
      }
    }
    printf("]\n");
  }
  return 0;
}



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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T> void operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) cin >> e; }

typedef long long ll;

int64_t Q, H, S, D, N;
int64_t const Alpha = 4;

/*
int64_t greedy(int64_t M) {
  vector<pair<int64_t, int64_t>> vs{{Q, 1}, {H, 2}, {S, 4}, {D, 8}};
  sort(vs.begin(), vs.end(), [](auto const& l, auto const &r) {
    return l.first * r.second < r.first * l.second;
  });
  int64_t cost, perL; tie(cost, perL) = vs[0];
  return M * cost * 4 / perL;
}
*/

pair<int64_t, double> greedy(int64_t M) {
  vector<pair<int64_t, int64_t>> vs{{Q, 1}, {H, 2}, {S, 4}, {D, 8}};
  sort(vs.begin(), vs.end(), [](auto const &l, auto const &r) {
    return l.first * r.second < r.first * l.second;
  });
  int64_t cost, perL; tie(cost, perL) = vs[0];
  auto buynum = (4 * M + perL - 1) / perL;
  return {buynum * cost, M + Alpha - (buynum * perL / 4.0)};
}

int64_t bf(double r) {
  auto constexpr MAX = std::numeric_limits<int64_t>::max();
  if (r == 0) return 0;
  if (r < 0) return MAX;
  auto a = bf(r - 0.25); if (a < MAX) a += Q;
  auto b = bf(r - 0.5);  if (b < MAX) b += H;
  auto c = bf(r - 1.0);  if (c < MAX) c += S;
  auto d = bf(r - 2.0);  if (d < MAX) d += D;
  return min({a, b, c, d});
}

int main() {
  cin >> Q >> H >> S >> D >> N;

  if (N <= Alpha) {
    cout << bf(N) << endl;
    exit(0);
  }

  int M = N - Alpha;
  auto x = greedy(M);
  auto y = bf(x.second);
  cout << x.first + y << "\n";
}


Measured memory_bytes: 256