akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

typedef long long ll;

const double PI = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;
const int INF_INT = 1e9;


int main(){
    ll N,M;
    cin >> N >> M;
    vector<pair<ll,ll>> drink(N);
    for(int i = 0; i < N; i++){
        cin >> drink[i].first >> drink[i].second;
    }
    sort(drink.begin(),drink.end());
    ll count = 0;
    ll sum = 0;
    int index = 0;
    while(count < M){
        count += drink[index].second;
        sum += drink[index].first * drink[index].second;
        index++;
    }
    cout << sum - (count - M) * drink[index - 1].first << endl;
    return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	cout<<a+b/2;



	cout<<endl;
} 


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	static int n;

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		// n = Integer.parseInt(br.readLine());
		String str[] = br.readLine().split(" ");

		int h = Integer.parseInt(str[0]);
		int a = Integer.parseInt(str[1]);

		int count = 0;
		while (h > 0) {
			h -= a;
			count++;
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 21204
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:https://beta.atcoder.jp/contests/arc082/tasks/arc082_d>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solve(){
    ll X,K; cin >> X >> K;
    vector<ll> R(K+2);
    R[0] = 0;
    for(int i = 1; i <= K;i++) cin >> R[i];
    R[K+1] = LINF;
    
    pll la,ua;  // { lim , val }
    ua = {X,X};
    la = {0,0};
    int Q; cin >> Q;
    int idx = 0;
    ll sum = 0;
//    cout << la << " " << ua << endl;
    while(Q--){
        ll t,a; cin >> t >> a;
        while(R[idx+1] <= t){
            ll D = R[idx+1] - R[idx];
            if(idx%2 == 0){ // dec
                sum -= D;
                ua = {ua.first,max(ua.second-D,0LL)};
                la = {min(la.first+max(0LL,D-la.second),X),max(la.second-D,0LL)};
            }else{ // inc
                sum += D;
                ua = {max(ua.first-max(0LL,ua.second-(X-D)),0LL),min(ua.second+D,X)};
                la = {la.first,min(la.second+D,X)};
            }
            idx++;
           // cout << sum << endl;
           // cout << la << " " << ua << endl;
        }
        
        ll nowa = a;
        if(la.first < a && a < ua.first){
            nowa = a + sum;
        }
        if(a <= la.first){
            nowa = la.second;
        }
        if(a >= ua.first){
            nowa = ua.second;
        }
        
        ll D = t - R[idx];
        if(idx%2==0){ // dec
            cout << max(0LL,nowa-D) << endl;
        }else{ // inc
            cout << min(X,nowa+D) << endl;
        }
    }
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


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

int main() {
	
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n){
		int tmp;
		cin >> tmp;
		a[i] = tmp - (i + 1);
	}
	sort(all(a));
	
	ll sum_pos = 0, sum_neg = 0;
	{
		ll mn = a[0];
		rep(i, n){
			a[i] -= mn;
			sum_pos += a[i];
		}
	}
	ll ans = sum_pos;
	int ub, lb;
	for(int i = 0; i < n; ){
		ub = upper_bound(all(a), a[i]) - a.begin();
		lb = lower_bound(all(a), a[i]) - a.begin();
		if(i > 0){
			sum_neg += lb * (a[i] - a[i - 1]);
			sum_pos -= (n - lb) * (a[i] - a[i - 1]);
		}
		ans = min(ans, sum_neg + sum_pos);
		// printf("i:%d a[i]:%lld ub:%d lb:%d sum_neg:%lld sum_pos:%lld ans:%lld\n", i, a[i], ub, lb, sum_neg, sum_pos, ans);
		i += ub - lb;
	}
	cout << ans << endl;
	
	// rep(i, n) printf("%lld%c", a[i], (i == n-1) ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Scanner;

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

		//配列hogeの要素合計の変数
		long sum = 0;

		//入力
		int n  = src.nextInt();

		//配列hoge
		ArrayList<Integer> hoge = new ArrayList<Integer>();

		//nに入力された数だけ繰り返し、配列に数値を代入
		for(int i = 0; i < n; i++) {
			int x  = src.nextInt();
			hoge.add(x);
			sum += x;
		}

		//最小値と最大値の変数を宣言
		int min, max = 0;
		max	=	hoge.get(0);
		min = max;
	
		//最小値と最大値を算出
		for(int i = 0; i < n; i++)
            min = Math.min(min,hoge.get(i));

		for(int i = 0; i < n; i++)
            max = Math.max(max,hoge.get(i));


		//出力
		System.out.println(String.format("%d %d %d",min, max, sum));

	}
}


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

namespace my {
/*汎用*/
template <typename T>
void input_vec(vector<T> &a, ll n) {
  assert(a.empty());
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
}
template <typename T>
void input_set(set<T> &a, ll n) {
  assert(a.empty());
  for (ll i = 0; i < n; i++) {
    T tmp;
    cin >> tmp;
    a.insert(tmp);
  }
}

char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }

/*整数*/
ll gcd(ll a, ll b) {  // O( log(max(a,b)) )
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
ll lcm(ll a, ll b) { return a * (b / my::gcd(a, b)); }  // O( log(max(a,b)) )
ll modinv(ll n, ll mod) {                               // O( log(max(n,mod)) )
  assert(mod > 0 && my::gcd(n, mod) == 1);
  n %= mod;
  if (n < 0) n += mod;
  ll a = mod, b = n, x = 1, y = 0;
  while (b != 0) {
    ll q = a / b, r = a % b;
    a = b;
    b = r;
    y -= q * x;
    swap(x, y);
  }
  y %= mod;
  if (y < 0) y += mod;
  return y;
}

bool is_prime(ll n) {  // O( sqrt(n) )
  bool flag = true;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
vector<pair<ll, ll>> prime_factorize(ll n) {  // O( sqrt(n) )
  vector<pair<ll, ll>> ret;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll exp = 0;
    while (n % i == 0) {
      n /= i;
      exp++;
    }
    ret.push_back(make_pair(i, exp));
  }
  if (n != 1) ret.push_back(make_pair(n, 1));
  return ret;
}

/*union find*/
class unionfind {
 private:
  /*根のparの値は「-(その木の要素数)」とする*/
  ll n_;
  vector<ll> par;

  ll root(ll a) {  // O( log(n) )
    if (par.at(a) < 0)
      return a;
    else {
      par.at(a) = root(par.at(a));  //経路圧縮
      return par.at(a);
    }
  }

 public:
  unionfind(ll n) : n_(n), par(n, -1) {}  // O(n)

  void unite(ll a, ll b) {  // O( log(n) )
    assert(0 <= a && a < n_);
    assert(0 <= b && b < n_);
    if (root(a) == root(b))
      return;
    else {
      ll ra = root(a), rb = root(b);
      if (-par.at(ra) < -par.at(rb)) swap(ra, rb);  //サイズによる併合
      par.at(ra) += par.at(rb);
      par.at(rb) = ra;
    }
  }

  bool is_same(ll a, ll b) {  // O( log(n) )
    assert(0 <= a && a < n_);
    assert(0 <= b && b < n_);
    return root(a) == root(b);
  }

  ll size(ll a) {  // O( log(n) )
    assert(0 <= a && a < n_);
    return -par.at(root(a));
  }
};
}  // namespace my
////////////////////////////////////////////////

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    if (a == b) {
      cnt++;
      if (cnt == 3) break;
    } else
      cnt = 0;
  }
  if (cnt == 3)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>

using namespace std;

int main(){

  int D;

  cin >> D;

  if(D == 25){
    cout << "Christmas" << "\n";
  }
  else if(D == 24){
    cout << "Christmas Eve" << "\n";
  }
  else if(D == 23){
    cout << "Christmas Eve Eve" << "\n";
  }
  else{
    cout << "Christmas Eve Eve Eve" << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
typedef long long ll;
#define int ll
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
using namespace std;
int MOD = 1000000007;

signed main(){
    int r,n;
    while(1){
        cin >> r >> n;
        if(r == 0 && n == 0)break;
        int x1[20],x2[20],h[20];
        int up[50]={0};
        int rup[50]={0};
        int lup[50]={0};
        rep(i,n){
            cin >> x1[i] >> x2[i] >> h[i];
            lup[25+x1[i]] = max(lup[25+x1[i]],h[i]);
            rup[25+x2[i]] = max(rup[25+x2[i]],h[i]);
            for(int j = x1[i]+1;j < x2[i];j++){
                up[25+j] = max(up[25+j],h[i]);
            }
        }
        double ans = 10000.0;
        for(int i = -r+1;i < r;i++){
            //cerr << i << " " << r-sqrt(r*r-i*i)+max(up[25+i],min(lup[25+i],rup[25+i])) << endl;
            ans = min(ans,r-sqrt(r*r-i*i)+max(up[25+i],min(lup[25+i],rup[25+i])));
        }
        cout << ans << endl;
    }


    
    return 0;
}

// g++ -std=c++14 icpc2014_a.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://agc034.contest.atcoder.jp/tasks/agc034_b



Measured memory_bytes: 3276
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }
using Graph = vector<vector<pair<int,int>>>;
void assign_color(Graph &g, vector<int>&c, int s) {
	queue<int>q;
	q.push(s);
	while (!q.empty()) {
		int x = q.front(); q.pop();
		if (c[x] == 0)c[x] = 1;
		else continue;
		
		rep(i, 0, g[x].size()) {
			q.push(g[x][i].first);
		}
	}
}
// O( ( |V| + |E| ) * log|V| )
const int W = 0, B = 1;
//重み付き有効グラフの隣接リスト表現
vector<int> dijkstra(const vector<vector<pair<int, int>>> &g, int s) {
	int n = g.size();
	priority_queue<pair<int, int>>pq;// cost, node
	vector<int>color(n, W), d(n, INF);
	d[s] = 0;
	pq.push(make_pair(0, s));

	while (!pq.empty()) {
		pair<int, int>f(pq.top()); pq.pop();// d[v], v
		color[f.second] = B;

		if (d[f.second] < (-1)*f.first)continue; // 最小値を取り出し、それが最短でなければ無視

		rep(i, 0, g[f.second].size()) {
			pair<int, int>v(g[f.second][i]);
			if (color[v.first] != B&&d[f.second] + v.second < d[v.first]) {
				d[v.first] = d[f.second] + v.second;
				pq.push(make_pair(d[v.first] * (-1), v.first)); // priority_queueはデフォルトで大きい値を優先するため-1を掛ける
			}
		}
	}
	return d;
}
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	Graph g(N);
	rep(i, 0, N-1) {
		int a, b; cin >> a >> b;
		a--, b--;
		g[a].emplace_back(make_pair(b,1)); g[b].emplace_back(make_pair(a,1));
	}
	vector<int>b(N, 0), w(N, 0);
	b[N - 1] = -1, w[0] = -1;
	assign_color(g, b, 0); assign_color(g, w, N - 1);
	
	auto d_from1 = dijkstra(g, 0), d_fromN = dijkstra(g, N - 1);
	int cntb(0), cntw(0), cntelse(0);
	rep(i, 0, N) {
		if (b[i] == 1 && w[i] == 1) {
			if (d_from1[i] <= d_fromN[i])cntb++;
			else cntw++;
		}
		else if (b[i] == 1 && w[i] != 1)cntb++;
		else if (b[i] != 1 && w[i] == 1)cntw++;
	}
	cout << (cntb > cntw ? "Fennec" : "Snuke") << endl;
	return 0;
}

Measured memory_bytes: 8512
def fac(n):
    ans = 1
    for k in range(n):
         ans *= k+1
    return ans     
def order(n,p):
  count = 1
  for i in range(n):
    pi = sorted(p[i:])
    count += fac(n-i-1)*pi.index(p[i])
  return count
n = int(input())
p = list(input().split())
q = list(input().split())
print(abs(order(n,p)-order(n,q)))

Measured memory_bytes: 3064
N,D,A=map(int,input().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,input().split()))

X=sorted(X,key=lambda x:x[0])
lastX=X[-1][0] # 最後のモンスターの場所
from collections import defaultdict
damage=defaultdict(int)
ans=0
for i in range(len(X)):
  x=X[i][0]
  if X[i][1]>0:
    dele=set()
    for d in damage.items():
      if d[0]<x:
        dele.add(d[0])
      else:
        X[i][1]-=d[1]
    for p in dele:
      del damage[p]
  if X[i][1]>0:
    turn=(X[i][1]+A-1)//A
    if x+D>lastX:
      damage[lastX]+=turn*A
    else:
      damage[x+D]=turn*A
    ans+=turn
print(ans)


Measured memory_bytes: 79064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(i = 0; i < n; i++)
//2D::rep(i,j)rep(j,j)cin>>bin[i][j];
//vector<int> a(n)
#define Graph vector<vector<int>>
#define A1 cout<<"No"<<endl
#define A2 cout<<"Yes"<<endl
#define A3 cout<<ans<<
#define AA(i) cout<<i<<endl;
const int U=2e5+5;
const ll MOD=1000000007;
const int INF = 1001001001;

int main(){
    int N; cin >> N;
    AA((10000-N)%1000);
    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

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

		if(Character.isUpperCase(S.charAt(0))) {
			System.out.println("A");
		}else {
			System.out.println("a");
		}


	}

}


Measured memory_bytes: 35800
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef struct {
    int to;
    int num;
} edge;
typedef long long ll;

void dfs(int s, vector<ll> &c, vector<vector<int> > &G, int &i, vector<int> &ans) {
    ans[s] = c[i];
    i++;
    for (auto u: G[s]) {
        if (ans[u] != -1)
            continue;

        dfs(u, c, G, i, ans);
    }
}

int main() {
    int n;  cin >> n;
    vector<int> ans(n, -1);
    vector<vector<int> > G(n);
    for (int i = 0; i < n-1; i++) {
        int a, b;   cin >> a >> b;  a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<ll> c(n);
    for (int i = 0; i < n; i++)
        cin >> c[i];
    sort(c.begin(), c.end(), greater<ll>());
    ll sum = 0;
    for (int i = 1; i < n; i++)
        sum += c[i];
    cout << sum << endl;


    int i = 0;
    dfs(0, c, G, i, ans);
    for (int i = 0; i < n; i++)
        cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 4648
#include <iostream>                                                             
using namespace std;                                                            
                                                                                
int main() {                                                                    
  int num;                                                                      
  cin >> num;                                                                   
  string word[100];                                                             
  bool is_keeped = true;                                                        
  for (size_t i = 0; i < num; ++i) {                                            
    cin >> word[i];                                                             
    if (i > 0) {                                                                
      if (word[i][0] != word[i-1][word[i-1].size()-1]) {                        
        is_keeped = false;                                                      
      }                                                                         
      for (size_t j = 0; j < i; ++j) {                                          
        if (word[i] == word[j]) {                                               
          is_keeped = false;                                                    
        }                                                                       
      }                                                                         
    }                                                                           
  }                                                                             
  if (is_keeped) {                                                              
    cout << "Yes" << endl;                                                      
  } else {                                                                      
    cout << "No" << endl;                                                       
  }                                                                             
  return 0;                                                                     
}      

Measured memory_bytes: 256
#include<stdio.h>
#include<cstring>
#include<algorithm> 
#include<iostream> 
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main(){
	string s;
	cin>>s;
	if(s=="ABC"){
		cout<<"ARC"<<endl;
	}
	else cout<<"ABC"<<endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main () {
    map<int, int> m;
    for (int i = 0; i < 6; i++) {
        int a;
        cin >> a;
        if (++m[a] > 2) {
            puts("NO");
            return 0;
        }
    }
    puts("YES");
}

Measured memory_bytes: 256
/////////////////////////////////
//                             //
//           /(.^.)\           //
//                             //
/////////////////////////////////

#include <iostream>
using namespace std;

#define LL long long

//modは素数
const int mod = 1000000007;
const int N   = 100002;
//const int N   = 5;

char buf[N];



//a+b
inline int add(int a, int b)
{
    a += b;
    if(a >= mod) a -= mod;
    return a;
}

//a-b
inline int sub(int a, int b)
{
    a -= b;
    if(a < 0) a += mod;
    return a;
}

//a*b
inline int mul(int a, int b)
{
    return (((LL) a) * b) % mod;
}

//a^bのかっこいいやつ
inline int pwr(int a, LL b)
{
	int x = 1;
	while(b)
    {
		if(b & 1) x = mul(x, a);
		a = mul(a, a);
		b >>= 1;
	}
	return x;
}

//なんか(m-2)乗したら逆数になるやつ
inline int inv(int a)
{
    return pwr(a, mod - 2);
}



//main
int main()
{
    int rtn;
    int xx,yy;
    char* bufp;

    rtn = 0;
    xx = 1;
    yy = 2;

    cin >> buf;

    bufp = buf + 1;
    while(*bufp)
    {
        if (*bufp == '1')
        {
            xx = add(mul(xx, 3), yy);
            yy = mul(yy, 2);
        }
        else
        {
            xx = mul(xx, 3);
        }
        
        ++bufp;
    }

    rtn = add(xx, yy);

    cout << rtn;
    //cout << "/(.^.)\\" << endl;

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int main()
{
	int n, m;
	
	scanf("%d %d", &n, &m);
	
	int arr[n];	
	for(int i = 0; i < n; i++){
		scanf("%d", &arr[i]);
	}
	int term = n - m;
	for(int i = 0; i < term; i++){
		int flag = 0;
		if(arr[i] < arr[i + m]){
			flag = 1;
		}
		if(flag == 1){
			printf("Yes\n");
		}else{
			printf("No\n");
		}
	}
}

Measured memory_bytes: 2436
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    string s; cin >> s;
    rep(i, 3) cout << s[i];
    cout << endl;
}


Measured memory_bytes: 3596
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();
        int[] A = new int[N];
        boolean[] jumped = new boolean[N];

        for(int i = 0 ; i < N ; i++){
            A[i] = sc.nextInt()-1;
            jumped[i] = false;
        }

        jumped[0] = false;
        int now = 0;
        ArrayList<Integer> list = new ArrayList<>(N);
        while(!jumped[now]){
            jumped[now] = true;
            list.add(now);
            now = A[now];
        }

        int loopFirst = 0;
        for(int i = 0 ; i < list.size() ; i++){
            if(list.get(i) == now){
                loopFirst = i;
            }
        }
        int loopLength = list.size() - loopFirst;

        if(K <= loopFirst){
            System.out.println(list.get((int)K)+1);
        }else{
            K -= loopFirst;
            K %= loopLength;
            K += loopFirst;
            System.out.println(list.get((int)K)+1);
        }
    }
}


Measured memory_bytes: 62004
#include <stdio.h>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0, now;
  scanf("%lld", &n);
  ll a[n], b[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < n; ++i) scanf("%lld", &b[i]);
  priority_queue< pair<ll, ll> > q;
  pair<ll, ll> p;
  for(i = 0; i < n; ++i) {
    if(a[i] > b[i]) {
      printf("-1");
      return 0;
    }
    if(a[i] < b[i]) q.push(make_pair(b[i], i));
  }
  while(q.size()) {
    p = q.top(), q.pop();
    now = b[(p.second + 1) % n] + b[(p.second + n - 1) % n];
    if(now > p.first) {
      printf("-1");
      return 0;
    }
    ans += (p.first - a[p.second]) / now;
    b[p.second] = p.first - (p.first - a[p.second]) / now * now;
    if(b[p.second] != a[p.second]) q.push(make_pair(b[p.second], p.second));
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 9584
import java.util.*;
import java.util.Arrays;
public class Main{
    
    public static boolean keta(int k){
        int ans =0;
        while(k>0){
            k /=10;
            ans++;

        }
        if(ans%2==0){
            return false;

        }
        else{
            return true;
        }
    }
    public static void main(String[] args){
       Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int count = 0;
        int sum = 1;
        int temp =a;
        for(int i=0;sum<b;i++){
            sum += a-1;
            count++;
        }
        System.out.println(count);

        
        
    }
   
    
       
    
}

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

int main() {
  int N;
  cin >> N;
  vector <int> A(N);
  
  for (int i = 1;i<N;i++){
    cin >> A.at(i);
  }
  
  vector <vector<int>> vec (N,vector<int> (0));
  for (int i=1;i<N;i++){
    vec.at(A.at(i)-1).push_back(i);
  }
  for (int i=0;i<N;i++){
    cout << vec.at(i).size() << endl;
  }
  
  
}

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

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

const int INF = 10000000;
const int MAX_V = 100;
int d[2][MAX_V][MAX_V];

void solve() {
    while (true) {
        int E, V;
        cin >> E >> V;

        if (E == 0 && V == 0) break;

        //initialize
        REP(h, 2) {
            REP(i, V) {
                REP(j, V) {
                    if (i == j) d[h][i][j] = 0;
                    else        d[h][i][j] = INF;
                }
            }
        }

        //make graph
        REP(i, E) {
            int u, v, c1, c2;
            cin >> u >> v >> c1 >> c2;
            u--; v--;
            d[0][u][v] = c1; d[0][v][u] = c1;
            d[1][u][v] = c2; d[1][v][u] = c2;
        }

        //Warshall-Floyd
        REP(h, 2) {
            REP(k, V) {
                REP(i, V) {
                    REP(j, V) {
                        d[h][i][j] = min(d[h][i][j], d[h][i][k] + d[h][k][j]);
                    }
                }
            }
        }

        int K;
        cin >> K;

        REP(i, K) {
            int p, q, r;
            cin >> p >> q >> r;
            p--; q--;
            cout << d[r][p][q] << endl;
        }
    }
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 1236
package main

import (
	"fmt"
)

func main() {
	var n int
	var x int
	var t int
	fmt.Scanf("%d", &n)
	fmt.Scanf("%d", &x)
	fmt.Scanf("%d", &t)

	times := n / x
	if n%x > 0 {
		times++
	}

	fmt.Println(times * t)
}

Measured memory_bytes: 1836
#include <bits/stdc++.h>
using namespace std;
const int64_t MAXN = 100010;
const int64_t MOD = 1000000007;
vector<vector<int64_t>> Graph(MAXN);
vector<int64_t> Colors(MAXN, -1);

int main()
{
  int64_t N, K, a, b, ans = 1;
  cin >> N >> K;
  for (int i = 0; i < N - 1; i++)
  {
    cin >> a >> b;
    a--, b--;
    Graph.at(a).push_back(b);
    Graph.at(b).push_back(a);
  }
  queue<int64_t> Q;
  Q.push(0);
  Colors.at(0) = K;
  while (Q.size())
  {
    int64_t cur = Q.front();
    Q.pop();
    int64_t cnt = 1;
    if (cur)
      cnt++;
    for (auto next : Graph.at(cur))
    {
      if (Colors.at(next) >= 0)
        continue;
      if (K - cnt <= 0)
      {
        cout << 0 << endl;
        return 0;
      }
      Colors.at(next) = (K - cnt);
      Q.push(next);
      cnt++;
    }
  }
  for (int i = 0; i < N; i++)
  {
    (ans *= Colors.at(i)) %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11224
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>

using namespace std;
typedef long long ll;
const ll mol=1000000007;
const int maxn=1000000;
const double PI=acos(-1.0);
char ch[maxn];
int main()
{
#ifdef LOCAL
freopen("3.h","r",stdin);
#endif
    scanf("%s",ch);
    int len=strlen(ch);int num=0;
    int dp1=0,dp2=0;
    for(int i=1;i<len-1;i++)
    if(ch[i+1]!=ch[i-1])num++;
    /*for(int i=2;i<len-2;i++)
    {
        if(ch[i+1]!=ch[i-1])
        {
            if(ch[i-2]==ch[i]&&ch[i+2]==ch[i])dp1=1;
            else if(ch[i-2]==ch[i+1]&&ch[i+2]==ch[i-1])dp1=1;
            else if((ch[i-2]==ch[i]||ch[i+2]==ch[i])&&(ch[i-2]==ch[i+1]||ch[i+2]==ch[i-1]))dp2=1;
            else dp1=1;
        }
    }
    if((num%2)==0&&dp2==0)printf("Second");
    else printf("First");*/
    if(num==0)printf("Second");
    //else if(num==1)printf("First");
    else if(ch[0]==ch[len-1])
    {
        if(!(len%2))printf("First");
        else printf("Second");
    }
    else
    {
        if(len%2)printf("First");
        else printf("Second");
    }
    return 0;
}


Measured memory_bytes: 384
T = int(input())

def hakidasi(L):
  n = len(bin(max(L))) - 2
  k, end = 0, len(L)
  for i in range(n - 1, -1, -1):
    for j in range(k, end):
      if (L[j] >> i) & 1:
        L[k], L[j] = L[j], L[k]
        break
    else:
      continue
    k += 1
    for j in range(end):
      if j == k - 1: continue
      if (L[j] >> i) & 1:
        L[j] ^= L[k - 1]
  return L

def judge(L, x):
  if L == []:
    return False
  n = len(bin(max(L))) - 2
  m = len(L)
  for i in range(m):
    a = len(bin(x))
    b = len(bin(L[i]))
    if a == b:
      x ^= L[i]
    elif a > b:
      return False
    if x == 0:
      return True
  return False

def main():
  N = int(input())
  A = list(map(int, input().split()))
  S = input()
  U = 60
  
  L = []
  for i in range(N - 1, -1, -1):
    if A[i] == 0:
      continue
    n = int(S[i])
    if n == 0:
      L.append(A[i])
      L = hakidasi(L)
      if L[-1] == 0:
        L.pop()
    else:
      m = judge(L, A[i])
      if m == False:
        return 1
  return 0

for i in range(T):
  print(main())


Measured memory_bytes: 70452
# -*- coding: utf-8 -*-

import sys
import os
import pprint
from queue import Queue

"""Diameter of Tree"""

#fd = os.open('GRL_5_A.txt', os.O_RDONLY)
#os.dup2(fd, sys.stdin.fileno())


class Edge:
    def __init__(self, to, weight):
        self.to = to
        self.weight = weight

    def __str__(self):
        return '{} {}'.format(self.to, self.weight)


N = int(input())
G = [[] for i in range(N)]
for i in range(N-1):
    start, end, weight = list(map(int, input().split()))

    # ??????
    edge = Edge(end, weight)
    G[start].append(edge)

    # ??°???
    edge = Edge(start, weight)
    G[end].append(edge)


# ???i??????1????????????????±???????
def bfs(index):
    d = [float('inf')] * N
    visited = [False] * N
    queue = Queue()
    queue.put(index)
    d[index] = 0

    while not queue.empty():
        u = queue.get()
        visited[u] = True

        for edge in G[u]:
            if d[u] + edge.weight < d[edge.to]:
                d[edge.to] = d[u] + edge.weight
            if not visited[edge.to]:
                queue.put(edge.to)

    max_i = 0
    max_d = 0
    for i in range(N):
        if max_d < d[i]:
            max_i = i
            max_d = d[i]
    #print('farthest i {} d {}'.format(max_i, max_d))
    return max_i, max_d

# ?§???????????????§????????????????????????1???????????????????????????
temp_i, temp_d = bfs(0)
# ?¬????????????????1???????????????????????????
temp_i, temp_d = bfs(temp_i)

# diameter
print(temp_d)

Measured memory_bytes: 68816
def INT():
    return int(input())

def LI():
    return list(map(int, input().split()))

def MI():
    return map(int, input().split())

N, K = MI()
p = LI()

def E(x):
    return (x + 1) / 2

for i in range(N):
    p[i] = E(p[i])
    
ans = sum(p[:K])
E_K = ans

for i in range(N - K):
    E_K += p[i + K] - p[i]
    ans = max(ans, E_K)

print(ans)

Measured memory_bytes: 99032
D,G = gets.split.map(&:to_i)
N = 1001
dp = Array.new(N,0)

1.upto(D) do |i|
  pi,c = gets.split.map(&:to_i)
  (N-1).downto(0) do |j|
    max = dp[j]
    pi.times do |k|
      if (j-k >= 0) && (max < dp[j-k] + i*k*100)
        max = dp[j-k] + i*k*100 
      end
    end
    if (j-pi >= 0) && (max < dp[j-pi] + i*pi*100 + c)
      max = dp[j-pi] + i*pi*100 + c
    end
    dp[j] = max
  end
end
#p dp
N.times do |i|
  if dp[i] >= G
    p i
    break
  end
end


Measured memory_bytes: 1788
#include<stdio.h>
void swap(int*, int*);

int main(void){
  int  a, b, c, s=0, t;

  scanf("%d %d %d", &a, &b, &c);
  if(a > b)
    swap( &a, &b);
  if(b > c)
    swap( &b, &c);
  if(a > b)
    swap( &a, &b);
  
  printf("%d\n", c - a);
  
  return 0;
}

void swap( int *x, int *y){
  int t;
  t = *x;
  *x = *y;
  *y = t;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
# define ll int64_t
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
#define dump(x) cerr<<#x<<"="<<x<<endl

using namespace std;

bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) x*=i;
    return x;
}

ll gcd(ll a,ll b)
{
   if (a%b == 0) return(b);
   else return(gcd(b,a%b));
}

ll lcm(ll a,ll b)
{
   return a/gcd(a,b)*b;
}

ll modinv(ll a,ll m) {
    ll b=m,u=1,v=0;
    while(b){
        ll t=a/b;
        a-=t*b; swap(a,b);
        u-=t*v; swap(u,v);
    }
    u%=m;
    if (u<0) u+=m;
    return u;
}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    
    ll ans=0;
    rep(i,n){
        ans+=a[i];
        ll tmp=a[i];
        for(ll j=i;j<n;j++){
            if(tmp>a[j]) tmp=a[j];
            a[j]-=tmp;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
#define REP(i, x, y) for(ll i = x; i < y; i++)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

int main() {
    ll N;
    cin >> N;
    ll a[N], b[N];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    ll ans = 0;
    REP (i, 0, 29) {
        ll acut[N];
        REP(j, 0, N) {
            acut[j] = a[j] % ((ll)1 << (i + 1));
        }
        ll bcut[N];
        REP(j, 0, N) {
            bcut[j] = b[j] % ((ll)1 << (i + 1));
        }
        sort(bcut, bcut + N);
        ll t = 1 << i;
        ll num = 0;
        REP (j, 0, N) {
            ll p = lower_bound(bcut, bcut + N, t - acut[j]) - bcut;
            ll q = lower_bound(bcut, bcut + N, 2 * t - acut[j]) - bcut;
            ll r = lower_bound(bcut, bcut + N, 3 * t - acut[j]) - bcut;
            ll s = lower_bound(bcut, bcut + N, 4 * t - acut[j]) - bcut;
            // cout << acut[j] << " " << t << " " << p << q << r << s << endl;
            // cout << (q - p) + (s - r) << endl;
            num = (num + ((q - p) + (s - r)) % 2) % 2;
        }
        ans += num * ((ll)1 << i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 6656
#include <stdio.h>

int main(void) {
	unsigned long long prm[78499]={};
	unsigned long long int n,i,num=0,cnt=0;
	for(n=2;n<=1000003;n++) {
		for(i=2;i*i<=n;i++) {
			if(n%i==0) {
				cnt=1;
				break;
			}
		}
		if(cnt==0){
			prm[num]=n;
			num++;
		}
		cnt=0;
	}
	
	while (scanf("%lld",&n)!=EOF) {
		for(i=0;i<78499;i++) {
			if(n<prm[i]) {
				printf("%lld\n",i);
				break;
			}
		}
	}
	return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;


void solve(long long N){
    for(i64 X = 1; X <= 100000; ++X){
        if(((X * 108) / 100) == N){
            cout << X << endl;
            return;
        }
    }
    cout << ":(" << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#import bisect
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	n=int(input())
	ans=[]
	
	if n==0:
		print(0)
		exit(0)
	
	while True:
		if -1<n<1:
			break
		elif n%(-2)==-1:
			ans.append(1)
			n=n//(-2)+1
		elif n%(-2)==1:
			ans.append(1)
			n=n//(-2)
		else:
			ans.append(0)
			n //= (-2)
	ans=ans[::-1]
	ans="".join(map(str,ans))
	
	print(ans)
	
	

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<int, int>;
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const int INF = 1e9;

int n, cc;

int main() {
    cin >> n >> cc;
    vector< vector<int> > Dmap(cc, vector<int>(cc, 0));
    vector< vector<int> > cmap(n, vector<int>(n, 0));
    vector< vector<int> > ccnt(3, vector<int>(cc, 0));
    for(int i = 0; i < cc; ++i) {
        for(int j = 0; j < cc; ++j) {
            cin >> Dmap.at(i).at(j);
        }
    }
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> cmap.at(i).at(j);
            cmap.at(i).at(j)--;
            int ch = (i+j)%3;
            ccnt.at(ch).at(cmap.at(i).at(j))++;
        }
    }

    /*cout << "ccnt" << endl;
    for(int i = 0; i < 3; ++i) {
        for(int j = 0; j < cc; ++j) {
            cout << ccnt.at(i).at(j) << " ";
        }
        cout << endl;
    }
    cout << endl;*/

    int ans = INF;
    for(int i = 0; i < cc; ++i) {
        for(int j = 0; j < cc; ++j) {
            if(j != i) {
                for(int k = 0; k < cc; ++k) {
                    if(k != i && k != j) {
                        int sum = 0;
                        // cout << i << " " << j << " " << k << endl;
                        for(int l = 0; l < cc; ++l) {
                            if(l != i) {
                                sum += ccnt.at(0).at(l)*Dmap.at(l).at(i);
                            }
                        }
                        for(int l = 0; l < cc; ++l) {
                            if(l != j) {
                                sum += ccnt.at(1).at(l)*Dmap.at(l).at(j);
                            }
                        }
                        for(int l = 0; l < cc; ++l) {
                            if(l != k) {
                                sum += ccnt.at(2).at(l)*Dmap.at(l).at(k);
                            }
                        }
                        // cout << sum << endl;
                        chmin(ans, sum);
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 1280
package main

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

func main() {
	sc := NewScanner()
	N, M := sc.NextInt(), sc.NextInt()

	if abs(N-M) > 1 {
		fmt.Println(0)
		return
	}

	A := N - M

	ans := 1
	for i := 1; i <= N; i++ {
		ans *= i
		ans %= 1e9 + 7
	}

	for i := 1; i <= M; i++ {
		ans *= i
		ans %= 1e9 + 7
	}
	if A == 0 {
		ans *= 2
		ans %= 1e9 + 7
	}
	fmt.Println(ans)

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

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
// https://abc106.contest.atcoder.jp/tasks/abc106_d

#include <iostream>
#include <string.h>
using namespace std;

int N, K, ans = 0;

int main(){
    
    cin >> N >> K;
    if (N%K>0) ans = 1;
    cout << ans << endl;
    return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

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

	ll mini = LLONG_MAX;
	for (ll x = 1; x * x <= N;x++) {
		if (N%x==0) {
			mini = min(x + N / x - 2, mini);
		}
	}
	ce(mini)
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

main(){

int x,y,r,W,H,x1,x2,y1,y2;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

x1=x-r;
x2=x+r;
y1=y-r;
y2=y+r;

if(x1>=0&&x2<=W&&y1>=0&&y2<=H) printf("Yes\n");

else printf("No\n");

return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head


const int N = 1e6+10;
int n, m, sum, c[N], vis[N];
char s[N];
vector<int> g[N];
void add(int x, int y) {
	g[x].pb(y),g[y].pb(x);
}
void dfs(int x) {
	if (vis[x]) return;
	vis[x] = 1;
	sum = (sum+c[x])%26;
	for (int y:g[x]) dfs(y);
}
int main() {
	cin>>s+1;
	m = strlen(s+1);
	REP(i,1,m+1) { 
		c[i]=(s[i]-s[i-1])%26;
		add(i,m+2-i);
	}
	cin>>n;
	while (n--) {
		int l,r;
		cin>>l>>r;
		add(l,r+1);
	}
	REP(i,1,m+1) {
		sum = 0;
		dfs(i);
		if (sum) return puts("NO"),0;
	}
	puts("YES");
}









Measured memory_bytes: 36864
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dd double
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first    
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define ovp(a,n) for(ll i=0;i<n;i++)cout<<a[i].ff<<" "<<a[i].ss<<endl;
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int,int> pii;
ll powe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);if(m%2==0)return (t*t);return (((t*t))*n);}
ll mpowe(ll n,ll m){if(m==0)return 1;ll t=powe(n,m/2);t%=MOD;if(m%2==0)return (t*t)%MOD;return (((t*t)%MOD)*n)%MOD;}
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
ll A[200000+1];

int main()
{
    ll n,i,flag=0;
    cin >> n;
    ll a[n];
    cn(a,n);
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            if(a[i]%3==0||a[i]%5==0)
                continue;
            else
               { flag=-1;break;}
        }
    }
    if(flag==0)
        cout <<"APPROVED";
    else
        cout <<"DENIED";
}


Measured memory_bytes: 256
N = int(input())
A = sorted([int(a) for a in input().split()])
print(A[-1]-A[0]+sum([abs(a) for a in A[1:-1]]))

p = A[-1]
for i in range(N-1):
    a, b = max(p, A[i]), min(p, A[i])
    if i == N-2 or A[i+1] < 0:
        print(a, b)
        p = a - b
    else:
        print(b, a)
        p = b - a

Measured memory_bytes: 62628
#include <stdio.h>
#include <stdlib.h>
#define int long long
#define p (int)(1e9 + 7)

int MOD(int a){
	a %= p;
	return a >= 0 ? a : a + p;
}

int element_count(int n){
	n = (0x55555555 & n) + (0x55555555 & (n >> 1));
	n = (0x33333333 & n) + (0x33333333 & (n >> 2));
	n = (0x0f0f0f0f & n) + (0x0f0f0f0f & (n >> 4));
	n = (0x00ff00ff & n) + (0x00ff00ff & (n >> 8));
	n = (0x0000ffff & n) + (0x0000ffff & (n >> 16));
	return n;
}

signed main(){
	int N, i, j, k;
	scanf("%lld", &N);
	int **a = (int **)malloc(sizeof(int *) * N);
	for(i = 0; i < N; i++){
		a[i] = (int *)malloc(sizeof(int) * N);
		for(j = 0; j < N; j++){
			scanf("%lld", &a[i][j]);
		}
	}
	int **dp = (int **)malloc(sizeof(int *) * (N + 1));
	for(i = 0; i <= N; i++){
		dp[i] = (int *)malloc(sizeof(int) * (1 << N));
		for(j = 0; j < (1 << N); j++){
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	for(i = 1; i <= N; i++){
		for(j = 0; j < (1 << N); j++){
			if(element_count(j) == i){
				for(k = 0; k < N; k++){
					if(((1 << k) | j) == j && a[i - 1][k] == 1){
						dp[i][j] = MOD(dp[i][j] + dp[i - 1][j - (1 << k)]);
					}
				}
			}
		}
	}
	printf("%lld\n", dp[N][(1 << N) - 1]);
	return 0;
}

Measured memory_bytes: 360704