akhauriyash/Code-Regression huggingface dataset:
#include<bits//stdc++.h>
using namespace std;
int n,a[200005];long long ans;
int main(){
	cin >>n;for(int i=1;i<=n;++i)cin >> a[i];a[0]=-1;
	for(int i=1;i<=n+1;++i) {
		if(a[i]==a[i-1]+1) continue;
		else if(a[i]>a[i-1]+1) {cout << -1 <<endl;return 0;}
		else ans+=(long long)a[i-1];
	}cout << ans<<endl;
}

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

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

using namespace std;

int main()
{
    int N, D, C, Sum, flag = 0;
    cin >> N;
    vector<int> v;

    if (N >= 4)
    {
        for (int i = 0; 4 * i <= 100; i++)
        {

            for (int a = 0; 7 * a <= 100; a++)
            {
                Sum = 4 * i + 7 * a;
                v.push_back(Sum);
            }
        }

        for (int i = 0; i < v.size(); i++)
        {
            if (v[i] == N)
            {
                cout << "Yes";
                flag = 1;
                break;
            }

            else
            {
                flag = 2;
            }
        }
    }

    if (N < 4)
    {
        flag = 2;
    }

    if (flag == 2)
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int a, b;
	scanf("%d%d", &a, &b);
	int n = b - a;
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		sum +=i;
	}
	printf("%d", sum - b);
	return 0;

}

Measured memory_bytes: 128
def get_temp(t, x):
    return t - x * 0.006


def get_abs(x, y):
    return abs(x - y)


def main():
    n = int(input())
    t, a = [int(e) for e in input().split()]
    h = [int(e) for e in input().split()]
    # print(n, t, a, h)

    ans_diff = None
    ans = 0

    for i, height in enumerate(h):
        temp = get_temp(t, height)
        diff = get_abs(a, temp)
        if (ans_diff is None) or diff < ans_diff:
            ans_diff = diff
            ans = i + 1

    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    String k = scan.next();
    char[] b = new char[n+1];
    for (int i=0;i<n;i++){
      b[i] = k.charAt(i);
    }
    b[n] = '1';

    ArrayList<String> a = new ArrayList<String>();

    int al = 0;
    int ar = 0;

    String current = "";
    int left = 0;
    for (int j=0;j<n;j++){
      if (b[j] == '('){
        left += 1;
        current = current +"(";
      }
      else{
        left -= 1;
        current = current + ")";
      }

      if ((b[j+1] == '(') && (left < 0)){
        a.add(current);
        al -= left;
        left = 0;
        current = "";
      }
    }


    if (current.length() > 0){
      if (left < 0){
        al -= left;
      }
      else{
        ar += left;
      }

      while (al > 0){
        System.out.print("(");
        al -= 1;
      }

      for (String g : a){
        System.out.print(g);
      }

      System.out.print(current);
      while (ar > 0){
        System.out.print(")");
        ar -= 1;
      }
      System.out.println("");

    }

  }

}


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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int md = (int)1e9+7;
void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }

int main(){
	int n;
	cin >>n;
	
	VI kn6={6};
	VI kn9={9};
	rep(i,20) if(kn6.back()*6<=100000) kn6.push_back(kn6.back()*6);
	rep(i,20) if(kn9.back()*9<=100000) kn9.push_back(kn9.back()*9);
	
	VI kn ={};
	rep(i,sz(kn6)) kn.push_back(kn6[i]);
	rep(i,sz(kn9)) kn.push_back(kn9[i]);
	sort(all(kn));
	//for(auto x :kn) printf("%d, ",x); puts("");
	int ans =0, cr=0;
	VI dd(100008);
	rep(i,100008) dd[i] = i;
	rep(i, sz(kn)) rep(j,100001){
		if(j+kn[i] <=100000){
			dd[j+kn[i]] = min(dd[j+kn[i]] , dd[j] + 1);
		}
	}
	
	cout << dd[n] <<"\n";
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
#include<math.h>
#include<array>
#include<algorithm>
#include<queue>
//#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>
#include<bitset>
#include<iomanip>

using namespace std;
using LLI = long long int;
LLI N;

//array<int, 8>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//array<int, 8>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//array<int, 4>dir_x2 = { 0,0,1,-1 };
//array<int, 4>dir_y2 = { 1,-1,0,0 };
//char alp[] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI  r;
//	if (x < y) {
//		swap(x, y);
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x, LLI y) {
//	return x / gcd(x, y) * y;
//}

//long nCr(int n, int r) {
//	long ans = 1;
//	for (int i = n; i > n - r; i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; i++) {
//		ans = ans / i;
//	}
//	return ans;
//}
//long nHr(int n,int r) {
//	n = n + r - 1;
//	return nCr(n,r);
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

//#define debug(x) cerr << #x << " : " << x << endl
//#define debugv(x) cerr << #x << " : "; for(auto i:x) cerr << i << ", "; cerr<<endl

int main(void) {
	LLI N;
	cin >> N;
	vector<LLI>vec(N);
	for (int i = 0; i < N;i++) {
		cin >> vec[i];
		vec[i] -= (i + 1);
	}
	sort(vec.begin(),vec.end());
	LLI m = vec[N / 2];
	for (int i = 0; i < N;i++) {
		vec[i] -= m;
		vec[i] = abs(vec[i]);
	}
	LLI sum = 0;
	for (int i = 0; i < N;i++) {
		sum += vec[i];
	}
	cout << sum << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
int zettai(int x);

int main(void){
    int N,L,sum=0,i,min;

    scanf("%d %d",&N,&L);
    min=zettai(L);
    
    for(i=1;i<=N;i++){
        sum+=i-1+L;
        if(min>zettai(i-1+L))
            min=zettai(i-1+L);
    }
    if(N+L-1 > 0)
        printf("%d\n",sum-min);
    else
        printf("%d\n",sum+min);
    return 0;
}

int zettai(int x){
    if(x<0)
        return -x;
    return x;
}

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

int main() {
  int N, sum, left, right, hikaku, ans = 10000;
  cin >> N;
  vector<int> vec(N);
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
    sum += vec.at(i);
  }

  for (int j = 0; j < N - 1; j++) {
    //左側
    left = 0;
    for (int k = 0; k < j + 1; k++) {
      left += vec.at(k);
    }
    right = sum - left;
    hikaku = abs(right - left);

    if (ans > hikaku) {
      ans = hikaku;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const ll MOD = 1000000007;

int n;
ll k;
ll arr[100100];
bool vis[100100];
vector<int> adj[100100];

ll dfs(int v, ll init, int type) {
    // printf("AWAL: %d %lld %d\n", v, init, type);
    vis[v] = true;
    ll ans = init;
    ll choice = k + type - 2;
    // printf("CHOICE: %lld\n", choice);
    type = max(0, type - 1);
    int idx = 0;
    for (int i = 0; i < (int) adj[v].size(); i++) {
        if (!vis[adj[v][i]]) {
            ans = (ans * dfs(adj[v][i], max(0LL, choice - idx++), type)) % MOD;
        }
    }

    // printf("AKHIR: %d %lld %lld\n", v, init, ans);
    return ans;
}

int main() {
    scanf("%d %lld", &n, &k);
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        scanf("%d %d", &a, &b);
        a--; b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    printf("%lld\n", dfs(0, k, 1));
}


Measured memory_bytes: 11648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int X;
    cin >> X;
    cout << X * X * X << endl;
}



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

int main() {
  int N;
  double A, S = 0.0;
  cin >> N;
  for (int i = 0.0; i < N; i++) {
    cin >> A;
    S += 1/A;
  }
cout << 1/S << endl;
}


Measured memory_bytes: 256
//                        Bismillahir Rahmanir Rahim
//ALGO:
#include<bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define FILL(a, x) memset(a, x, sizeof(a))
#define ll long long
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define INF ll_MAX
#define MX 1000010
#define mod  998244353
#define dout if(debug) cout
#define FR(i, n) for(ll i=0; i<n; i++)
#define FOR(i, n) for(ll i=1; i<=n; i++)
const double Pi=acos(-1);
using namespace std;
ll debug=01;
void solve(){
    ll n, x, m;
    cin>>n>>x>>m;
    ll a[m+10];
    a[1]=x;
    ll sum=x, len, start;
    map<ll, ll>f;
    f[x]=1;
    for(ll i=2;i<=n;i++){
        x=(x*x)%m;
        a[i]=x;
        if(f[x]){
            len=i-f[x];
            start=f[x];
            goto circle;
        }
        sum+=x;
        f[x]=i;
    }
    cout<<sum; return;
    circle: ;
    sum=0;
    for(ll i=1; i<start; i++)sum+=a[i];
    n-=(start-1);
    ll y=n/len;
    for(ll j=1; j<=len; j++){
        sum+=a[start+j-1]*y;
        if(j<=(n%len))sum+=a[start+j-1];
    }
    cout<<sum;
}
int main() {
    Fast
    ll tst=1;
    //cin>>tst;
    for(ll T=1; T<=tst; T++){
        //cout<<"Case "<<T<<": ";
        solve();
    }
}


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


/* macro */
#define rep(i,a,b) for(int i=a;i<b;i++)
#define revrep(i,a,b) for(int i = a; i > b; i--)
#define int long long
#define exist(s,e) ((s).find(e)!=(s).end())
#define all(v) (v).begin(), (v).end()
#define each(s,itr) for(auto (itr) = s.begin(); (itr) != s.end(); (itr)++)
#define sum(v) accumulate(all(v), (0LL))
#define sec second
#define fir first
#define pb push_back



/* alias */
template<class T> using vec = vector<T>;
typedef vector<int> vi;
typedef pair<int, int> pi;


/* constant */
//const int inf = pow(2, 62);
//const int mod = 1e9 + 7;
const int mod = 100000;
int dx[8]={1,0,-1,0,-1,1,-1,1};
int dy[8]={0,1,0,-1,-1,-1,1,1};



/* io_method */
int input(){int tmp;cin >> tmp;return tmp;}
string raw_input(){string tmp;cin >> tmp;return tmp;}
string readline(){string s;getline(cin, s);return s;}
template<class T> void printx(T n){cout << n;}
template<class T, class U> void printx(pair<T, U> p){cout << "(" << p.first << "," << p.second << ")";}
template<class T> void printx(vector<T> v){cout << "{";rep(i,0,v.size()){printx(v[i]);if(i != v.size()-1)printx(",");}cout << "}";}
template<class T> void print(T n){printx(n);cout << endl;}
template<class T> void print(set<T> s){cout << "{";each(s, e){if(e != s.begin()) printx(",");printx(*e);}cout << "}" << endl;}
template<class T, class U> void print(map<T, U> mp){cout << "{";each(mp, e){cout << "(" << e -> first << "," << e -> second << ")";}cout << "}" << endl;}


/* general_method */
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; }




/* main */
int ceil(int a, int b){
    if(a % b == 0) return a /b;
    else return a /b + 1;
}


signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

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

    print((a + b) % 24);




    
    



    
    

    







   




    

    

    




    



    



    

 
    
    


    

    
   
    













}






    










    




    










Measured memory_bytes: 256
import scala.io.Source

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines.toList.map(_.toInt)
    }yield if(isPrime(in)) in else -1

    println(lines.tail.filter(_ != -1).length)
  }

  def isPrime(n: Int): Boolean = (2 to Math.sqrt(n).toInt).forall(n % _ != 0)
}

Measured memory_bytes: 98512
import sys
x = input()
x1 = list(x)
h = len(x)
x = int(x)

if x>2000:
  print('1')
  sys.exit()

a1 = int(x1[h-1])
a2 = int(x1[h-2])

if 0 < a1 <= 5:
  c1 = 1
elif a1 == 0:
  c1 = 0
else:
  c1 = 2

c2 = a2*2
#print(x1[0],x1[1])
if h>3:
  if 10*int(x1[0])+int(x1[1]) < c1+c2:
    print('0')
  else:
    print('1')
else:
  if int(x1[0]) < c1+c2:
    print('0')
  else:
    print('1')

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

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

    static class ABC109B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            String[] arr = new String[N];
            Set<String> set = new HashSet<String>();
            char last = ' ';
            for (int i = 0; i < N; i++) {
                String s = in.next();
                if (set.contains(s)) {
                    out.println("No");
                    return;
                } else {
                    set.add(s);
                }
                if (i == 0) {
                    last = s.charAt(s.length() - 1);
                } else {
                    char nlast = s.charAt(s.length() - 1);
                    if (s.charAt(0) == last) {
                        last = nlast;
                    } else {
                        out.println("No");
                        return;
                    }
                }
            }
            out.println("Yes");
        }

    }
}



Measured memory_bytes: 22608
n = gets.to_i

if n == 0 then
  ans = "0"
else
  ans = ""
end

i = 1
until n == 0 do
  tmp = n.modulo(-2) * (-1)
  #p "tmp: " + tmp.to_s
  n = (n - tmp) / (-2)
  ans = (tmp).to_s + ans
  i += 1
end

puts ans


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
    int X, Y, N, M;
    int x, y;
    int xmax = -101, ymin = 101;
    cin >> N >> M >> X >> Y;
    for (int i = 0; i < N; i++){
        cin >> x;
        if (xmax <= x){
            xmax = x;
        }
    }
    for (int i = 0; i < M; i++){
        cin >> y;
        if (ymin >= y){
            ymin = y;
        }
    }
    int j = 0;
    if (xmax < ymin){
    for (int i = xmax+1; i <= ymin; i++){
        if (i > X && i <= Y){
            cout << "No War" << endl;
            break;
        }
        j++;
        if (j == ymin-xmax){
            cout << "War" << endl;
        }
    }
    } else {
        cout << "War" << endl;
    }
        
    
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
p = [int(i) for i in input().split()]
q = [i+1 for i in range(N)]

count = 0
for i in range(N):
    if p[i] != q[i]:
        count += 1

if count <= 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3060
#include <map>
#include <cstdio>
using namespace std;
int main(){for(int T;~scanf("%d",&T)&&T;puts("")){
	map<pair<int,int>,int>m;
	char C[2];
	int n,k;
	for(;T--;){
		scanf("%s%d",C,&n);
		if(*C=='D'){
			for(auto it=m.begin();it!=m.end();)if(it->second==n)m.erase(it++);else	++it;
		}else if(*C=='R'){
			auto it=m.lower_bound(make_pair(n,2000000000));
			printf("%d\n",it==m.begin()||n<(--it)->first.first||it->first.second<n ? -1 : it->second);
		}else if(*C=='W'){
			int c=0;
			scanf("%d",&k);
			for(auto it=m.begin();it!=m.end();++it){
				int d=it->first.first-c;
				if(d>k)d=k;
				if(d)m[make_pair(c,c+d-1)]=n;
				k-=d;
				if(k==0)break;
				c=it->first.second+1;
			}
			if(k)m[make_pair(c,c+k-1)]=n;
		}
	}
}}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
 
using namespace std;
 
template <typename A, typename B>
string to_string(pair<A, B> p);
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
 
string to_string(const string& s) {
  return '"' + s + '"';
}
 
string to_string(const char* s) {
  return to_string((string) s);
}
 
string to_string(bool b) {
  return (b ? "true" : "false");
}
 
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
 
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}
 
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
 
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
 
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}
 
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
 
void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif


typedef long long ll; 
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
 
#define mp make_pair
#define pb push_back

bool palindrome(string s) {
  for (int i = 0 ; i < s.length() ; i++) {
    if (s[i] != s[s.length() - 1 - i]) return false;
  }
  return true;
}
void solve() {
  string s;
  cin >> s;
  int n = s.length();
  if (palindrome(s) && palindrome(s.substr(0, (n - 1) / 2)) && palindrome(s.substr((n + 3) / 2 - 1, n - 1))) cout << "Yes"; else cout << "No";
}
 
int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
 
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N=1e5+20,MOD=1e9+7;
int n,k,u,v,ans=1;
vector <int> adj[N];

void dfs(int node,int parent,int choices)
{
	ans=(1ll*ans*choices)%MOD;
	choices=k-1;
	if(parent!=0) choices--;
	for(auto child:adj[node])
		if(child!=parent)
			dfs(child,node,choices--);
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=0;i<n-1;i++)
	{
		scanf("%d%d",&u,&v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1,0,k);
	printf("%d",ans);
}

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

const long long MAXprime=250000;
bool bp[MAXprime];
vector<int> p;
void boolprime()
{
	for (long long i = 0; i < MAXprime; ++i) bp[i]=1;
	bp[0]=0, bp[1]=0;
	for (long long i = 2; i*i < MAXprime; ++i)
	{
		if(bp[i])
		{
			p.push_back(i);
			for (long long j = 2; i*j < MAXprime; ++j) bp[i*j]=0;
		}
	}
	for (long long i = p.at(p.size()-1)+1; i < MAXprime; ++i) if(bp[i]) p.push_back(i);
}

int main(int argc, char const *argv[])
{
	boolprime();
	int n;
	while(cin>>n,n)
	{
		cout<<upper_bound(p.begin(), p.end(),2*n)-upper_bound(p.begin(), p.end(),n)<<endl;
	}
	return 0;
}



Measured memory_bytes: 3472
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;


namespace AtCodeeeer
{
    class AtCOOOOOOOOOOOder
    {
        static void Main(string[] args)
        {
            string s = ReadLine();
            long ans = 0;
            for (int i = 0; i < (1<<s.Length-1); i++)
            {
                var sb = new StringBuilder();
                for (int j = 0; j < s.Length; j++)
                {
                    sb.Append(s[j]);
                    if (((i >> j) & 1) == 1)
                    {
                        sb.Append("+");
                    }
                }
                ans += Array.ConvertAll(sb.ToString().Split('+'),long.Parse).Sum();
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
N = int(input())
slis = []
slis.append(list(map(int,input().split())))
slis.append(list(map(int,input().split())))
dp=[]
dp.append([0]*N)
dp.append([0]*N)
dp[0][0] = slis[0][0]
for i in range(1,N):
  dp[0][i] = dp[0][i-1] + slis[0][i]
for i in range(N):
  if i == 0:
    dp[1][0] = dp[0][0] + slis[1][0]
  else:
    dp[1][i] = max(dp[0][i],dp[1][i-1]) + slis[1][i]
print(dp[1][N-1])

Measured memory_bytes: 3064
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

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

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

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)


/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))
#define each(itr,v) for(auto (itr):(v))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
	os << "[";
	for (auto vv : v)
		os << vv << ",";
	return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
	return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
	return a * a;
}

template <typename T>
T gcd(T a, T b) {
	if (a > b) return gcd(b, a);
	return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
	if (n == 0) return 1;
	if (n == 1) return b /* % MOD */;
	if (n % 2 == 0) {
		return mypow(b * b /* % MOD */, n / 2);
	}
	else {
		return mypow(b, n - 1) * b /* % MOD */;
	}
}

ll pcnt(ll b) {
	return __builtin_popcountll(b);
}


// const ll dx[4] = {0, -1, 1, 0};
// const ll dy[4] = {-1, 0, 0, 1};
// const ll dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const ll dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	ll A[N];
	ll B[N];
	REP(i, N) {
		cin >> A[i];
	}
	B[0] = A[0];
	FOR(i, 1, N) {
		B[i] = B[i - 1] + A[i];
	}
	ll C[N - 1];
	REP(i, N - 1) {
		C[i] = abs(B[N - 1] - 2*B[i]);
	}
	sort(C, C + N - 1);
	cout << C[0] << endl;
	return 0;

}

Measured memory_bytes: 4992
N,Q=map(int,input().split())
S=input()
t=[0]*N
for i in range(0,N-1):
  t[i + 1] = t[i] + (1 if S[i : i + 2] == 'AC' else 0)
for i in range(0,Q):
  l,r=map(int,input().split())
  print(t[r-1]-t[l-1])

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

int main() {
    int N;
    cin >> N;
    vector<string> S(N);
    rep(i,N) cin >> S.at(i);
    string T = "MARCH";

    map<char, ll> mp;
    rep(i,N) {
        rep(j,5) {
            if (S.at(i).at(0) == T.at(j)) ++mp[T.at(j)];
        }
    }
    ll ans = 0;
    if (mp.size() >= 3) {
        for (int bit = 0; bit < (1<<mp.size()); bit++) {
            bitset<5> s(bit);
            if (s.count() == 3) {
                ll add = 1;
                for (int i = 0; i < mp.size(); i++) {
                    if (bit & (1<<i)) {
                        add *= mp[T.at(i)];
                    }
                }
                ans += add;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 6428
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int H, A;
	cin >> H >> A;

	cout << (H + A - 1) / A << "\n";

	return 0;
}

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

#define MOD (1000 * 1000 * 1000 + 7)
#define INF (1LL << 60)
#define pb push_back
#define po pop_back
#define fi first
#define se second

typedef long long ll;
typedef long double ld;

int main() {
    char c;
    while ((c = getchar()) != '\n') {
        if (c == ',')
            cout << " ";
        else
            cout << c;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 1e9;
const ll INFll = 1e18;
#define put(n) cout<<(n)<<endl
#define Cout(n) cout<<(n)
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);++(i))
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);--(i))
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()
#define MP make_pair
#define pb(q) push_back(q)
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H,W,N;
    cin>>H>>W>>N;
    vector<vector<char>> town(H,vector<char>(W));
    vector<vector<int>> step;
    int sy,sx;
    int gy,gx;
    int now = 0;

    FOR(i,0,H){
        FOR(j,0,W){
            cin>>town[i][j];
            if(town[i][j] == 'S'){
                sy = i;
                sx = j;
            }
            if(town[i][j] == '0'+N){
                gy = i;
                gx = j;

            }
        }
    }

    FOR(HP,1,N+1){
        queue<pair<int,int>> Q;
        step.assign(H,vector<int>(W,-1));
        step[sy][sx] = now;
        Q.push(MP(sy,sx));
        bool found = false;
        while(!Q.empty()){
            pair<int,int> P = Q.front(); Q.pop();
            FOR(i,0,4){
                int y = P.first + dy[i];
                int x = P.second + dx[i];

                if(y>=0 && y<H && x>=0 && x<W && town[y][x] != 'X' && step[y][x] == -1){
                    step[y][x] = step[P.first][P.second] + 1;
                    Q.push(MP(y,x));
                    if(town[y][x] == ('0' + HP)){
                        sy = y;
                        sx = x;
                        now = step[y][x];
                        found = true;
                        break;
                    }
                }
            }
            if(found) break;
        }
    }
    
    put(step[gy][gx]);

}


Measured memory_bytes: 7860
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <functional>
#include <cstring>
#include <set>
using namespace std;

typedef long long ll;
#define MAX 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int w, h;
	cin >> w >> h;

	vector<int>p(w), q(h);
	for (int i = 0; i < w; i++) {
		cin >> p[i];
	}
	for (int i = 0; i < h; i++) {
		cin >> q[i];
	}
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());

	ll ans = 0;
	while(p.size() && q.size()){
		if (p[0] < q[0]) {
			ans += p[0] * (1 + q.size());
			p.erase(p.begin());
		}
		else if (p[0] > q[0]) {
			ans += q[0] * (1 + p.size());
			q.erase(q.begin());
		}
		else {
			ans += p[0] * (p.size() + q.size() + 1);
			p.erase(p.begin());
			q.erase(q.begin());
		}
	}
	if (p.size() == 0) {
		for (int i = 0; i < q.size(); i++) {
			ans += q[i];
		}
	}
	if (q.size() == 0) {
		for (int i = 0; i < p.size(); i++) {
			ans += p[i];
		}
	}

	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

int main(){
    ll A, B;
    cin >> A >> B;
    cout << A * B << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
const int MOD = 1000000007;
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; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int a;cin >> a;
    string s;cin >> s;
    if(a >= 3200){
        cout << s << endl;
    }
    else{
        cout << "red" << endl;
    }
}

Measured memory_bytes: 256
public class Main{
    Main(){
	for(int i = 1; i < 10; i++)
	    for(int j = 1; j < 10; j++)
		System.out.println(Integer.toString(i) + "x" + Integer.toString(j)+"="+Integer.toString(i*j));
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 9340
// 3_abc142_c
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    rep(i, n){
        int a;
        cin >> a;
        v[i] = make_pair(a, i + 1);
    }
    sort(v.begin(), v.end());
    rep(i, n){
        cout << v[i].second << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1664
#ifdef _WIN32
#define NOMINMAX
#define _CRT_SECURE_NO_WARNINGS
#include <Windows.h>
#define DEBUGBREAK() ::DebugBreak()
#else
#define DEBUGBREAK() static_cast<void>(0)
#endif

#include <iostream>
#include <sstream>
#include <iomanip>
#include <valarray>
#include <vector>
#include <string>
#include <fstream>
#include <cstdlib>
#include <queue>
#include <array>
#include <functional>
#include <stack>
#include <bitset>
#include <random>
#include <algorithm>
#include <unordered_map>

using namespace std;

const int64_t dx4[4] = { 0, -1, 1, 0 };
const int64_t dy4[4] = { -1, 0, 0, 1 };
const int64_t dx5[5] = { 0, -1, 0, 1, 0 };
const int64_t dy5[5] = { -1, 0, 0, 0, 1 };
const int64_t dx8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int64_t dy8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
const int64_t dx9[9] = { -1, 0, 1, -1, 0, 1, -1, 0, 1 };
const int64_t dy9[9] = { -1, -1, -1, 0, 0, 0, 1, 1, 1 };

#define REP(i, K) for (int64_t i = 0; i < K; ++i)
#define REPYX() for (int64_t y = 0; y < H; ++y) for (int64_t x = 0; x < W; ++x)
#define REPX() REP(x, W)
#define REPY() REP(y, H)
#define INSIDE(x_, y_) (0 <= (x_) && 0 <= (y_) && (x_) < W && (y_) < H)
#define INSIDE_MARGIN(x_, y_, m_) ((m_) <= (x_) && (m_) <= (y_) && (x_) < W - (m_) && (y_) < H - (m_))

int get_assert_level() {
    const char* s = getenv("ASSERT_LEVEL");
    if (s) { return atoi(s); }
    return 0;
}
static int g_assert_level = get_assert_level();

#define LV_1() if (g_assert_level >= 1)
#define LV_2() if (g_assert_level >= 2)
#define LV_3() if (g_assert_level >= 3)
#define ASSERT_1(expr) do { const bool b = bool(expr); if (g_assert_level >= 1 && !b) { std::cerr << "[ASSERT 1] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_2(expr) do { const bool b = bool(expr); if (g_assert_level >= 2 && !b) { std::cerr << "[ASSERT 2] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)
#define ASSERT_3(expr) do { const bool b = bool(expr); if (g_assert_level >= 3 && !b) { std::cerr << "[ASSERT 3] (" << #expr << ") failed." << std::endl; exit(-1); } } while (false)

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int X, Y;
    cin >> X >> Y;

    //  crane + turtle = X
    // 2crane + 4turtle = Y
    // => 2turtle = Y - 2X
    //    2creane = 4X - Y
    const bool turtle_ok = (0 <= Y - 2 * X) && ((Y - 2 * X) % 2 == 0);
    const bool crane_ok = (0 <= 4 * X - Y) && (4 * X - Y ) % 2 == 0;
    if (turtle_ok && crane_ok) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}



Measured memory_bytes: 3652
X,N=list(map(int,input().split()))

if N != 0:
    P=list(map(int,input().split()))
    P.sort()
    if X < P[0]:
        imin = X
    elif X > P[N-1]:
        imin = X 
    else:
        imin = 0
        max_diff = 1000
        for i in range(P[0]-1,P[N-1]+2):
            if i not in P:
                if abs(i-X) < max_diff:
                    max_diff = abs(i-X)
                    imin = i
else:
    imin = X

print(imin)

Measured memory_bytes: 9204
PROGRAM IhateFactorization
      IMPLICIT NONE
      integer(16) :: x
      integer(16) :: a,b
      
      read*,x
      
      do a = -200,200
        do b = -200,200
          if( a**5-b**5==x )then
            print*,a,b;stop
          end if
        end do
      end do
      
      
      
      
      END PROGRAM

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

const ll mod = 1e9 + 7;
const int Inf = 1e9 + 5;
vector<int> phi;

void phi_1_to_n(int n) {
    phi[0] = 0;
    phi[1] = 1;
    for (int i = 2; i <= n; i++)
        phi[i] = i - 1;

    for (int i = 2; i <= n; i++)
        for (int j = 2 * i; j <= n; j += i)
              phi[j] -= phi[i];
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    vector<ll> sum1(n), sum2(m);
    sum1[0] = a[0];
    sum2[0] = b[0];
    for (int i = 1; i < n; i++) {
        sum1[i] = sum1[i - 1] + a[i];
    }
    for (int i = 1; i < m; i++) {
        sum2[i] = sum2[i - 1] + b[i];
    }
    int best = 0;
    for (int i = 0; i < n; i++) {
        if (sum1[i] <= k) {
            int lo = 0, hi = m - 1;
            ll k_dash = k - sum1[i];
            int ans = -1;
            while (lo <= hi) {
                int mid = (lo + hi) / 2;
                if (sum2[mid] <= k_dash) {
                    ans = mid;
                    lo = mid + 1;
                } else {
                    hi = mid - 1;
                }
            }
            best = max(best, ans + 2 + i);
        }
    }
    for (int i = 0; i < m; i++) {
        if (sum2[i] <= k) {
            best = max(best, i + 1);
        }
    }
    cout << best;
    return 0;
}

Measured memory_bytes: 7952
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)

const ll MOD = 1e9 + 7;

vector<vector<int>> e;

void DFS(int n, ll *b, ll *w, int p) {
  *b = 1;
  *w = 1;
  EACH(v, e[n]) {
    ll lb, lw;
    if (v == p) {
      continue;
    }
    DFS(v, &lb, &lw, n);
    *b *= lw;
    *b %= MOD;
    *w *= lw + lb;
    *w %= MOD;
  }
}

void solve(istream& cin, ostream& cout) {
  int n;
  cin >> n;
  e = vector<vector<int>>(n);
  REP(i, n - 1) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  ll b, w;
  DFS(0, &b, &w, -1);
  cout << (b + w) % MOD << endl;
}

#ifndef TEST
int main() {
  solve(cin, cout);
}
#endif


Measured memory_bytes: 14080
import java.util.Scanner;

public class Main {
	
	public long solve(long N, long X) {
		long longEdge = Math.max(X, N-X);
		long shortEdge = Math.min(X, N-X);
		
		long length = X + N - X;
		
		long times = 1;
		while (shortEdge > 0) {
			long num = longEdge / shortEdge;
			long left = longEdge - (shortEdge * num);

			length += (shortEdge * num * 2);
			longEdge = shortEdge;
			shortEdge = left;
			
			times++;
		}
		length -= longEdge;
		
		return length;
	}
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long N = in.nextLong();
		long X = in.nextLong();
		in.close();
		
		Main main = new Main();
		long result = main.solve(N, X);
		
		System.out.println(result);
	}
}

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

using namespace std;

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

    vector<pair<long long, long long> > vt;
    for (int i = 0; i < n; i++) {
        long a;
        cin >> a;
        vt.emplace_back(make_pair(a, 1));
    }
    for (int i = 0; i < m; i++) {
        long b, c;
        cin >> b >> c;
        vt.emplace_back(make_pair(c, b));
    }
    sort(vt.begin(), vt.end(), greater<>());

    long long ans = 0;
    long long cnt = n;
    for (auto x:vt) {
        ans += min(cnt, x.second) * x.first;
        cnt -= x.second;
        if (cnt <= 0) break;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 6000
# ABC 120: B – K-th Common Divisor
a, b, k = map(int, input().split())
divisors = [1]

for i in range(2, min(a, b) + 1):
    if a % i == 0 and b % i == 0:
        divisors.append(i)

print(divisors[len(divisors) - k])

Measured memory_bytes: 2940
from heapq import heappush, heappop
N = int(input())
heap = []
for v in map(int, input().split()):
    heappush(heap, v)

for _ in range(N-1):
    x = heappop(heap)
    y = heappop(heap)
    heappush(heap, (x+y)/2)

print(heappop(heap))

Measured memory_bytes: 3060
def read_int():
    return int(input())

def read_int_map():
    return map(int,input().split(' '))

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

def read_s_list_loop(n):
    return [input() for _ in range(n)]

from bisect import bisect_right
from bisect import bisect_left
import copy

N = read_int()
An = read_int_list()

An_diff = [0]*N
for i,a in enumerate(An):
    An_diff[i] = a - i
An_store = copy.deepcopy(An_diff)
An_diff.sort()
count_map = {}
ans = 0
for i,a in enumerate(An):
    target = (a+i)*(-1)
    shoud_be_minus_cnt = An_store[i]
    if shoud_be_minus_cnt not in count_map:
        count_map[shoud_be_minus_cnt] = 1
    else:
        count_map[shoud_be_minus_cnt] += 1
    cnt = bisect_right(An_diff,target) - bisect_left(An_diff,target)
    if target in count_map:
        cnt -= count_map[target]
    ans += cnt
print(ans)

Measured memory_bytes: 114880
q=int(input())
part=[list(map(int,input().split())) for i in range(q)]

cumsum=[0]*(10**5+1)

plst=[1]*(10**5+1)

plst[0]=0
plst[1]=0

i=2

while i*i<=10**5:
    for j in range(2,10**5//i+1):
        plst[i*j]=0
    
    i+=1
    while plst[i]==0:
        i+=1

for i in range(2,10**5+1):
    if plst[i]==1 and plst[(i+1)//2]==1:
        cumsum[i]=cumsum[i-1]+1
    else:
        cumsum[i]=cumsum[i-1]

for l,r in part:
    print(cumsum[r]-cumsum[l-1])

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

constexpr int inf = 1e9;

int levenshtein_distance(string s1, string s2) {
    const int n = s1.size(), m = s2.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, inf));
    for(int i = 0; i <= n; ++i) dp[i][0] = i;
    for(int j = 0; j <= m; ++j) dp[0][j] = j;
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= m; ++j) {
            dp[i][j] = min({dp[i][j],
                            dp[i - 1][j] + 1,
                            dp[i][j - 1] + 1,
                            dp[i - 1][j - 1] + (s1[i - 1] != s2[j - 1])});
        }
    }
    return dp[n][m];
}

int main() {
    int n;
    while(cin >> n, n) {
        int d;
        cin >> d;
        vector<string> name(n);
        for(int i = 0; i < n; ++i) {
            cin >> name[i];
        }

        vector<string> ans;
        for(int i = 0; i < n; ++i) {
            for(int j = i + 1; j < n; ++j) {
                auto s1 = name[i], s2 = name[j];
                if(s1.size() < s2.size()) swap(s1, s2);
                const int m = s1.size();

                int min_d = levenshtein_distance(s1, s2);

                // swap -> levenshtein
                for(int k = 0; k + 1 < m; ++k) {
                    swap(s1[k], s1[k + 1]);
                    min_d = min(min_d, levenshtein_distance(s1, s2) + 1);
                    swap(s1[k], s1[k + 1]);
                }

                // swap -> swap
                for(int k = 0; k + 1 < m && min_d >= 3; ++k) {
                    swap(s1[k], s1[k + 1]);
                    for(int l = 0; l + 1 < m; ++l) {
                        swap(s1[l], s1[l + 1]);
                        if(s1 == s2) min_d = 2;
                        swap(s1[l], s1[l + 1]);
                    }
                    swap(s1[k], s1[k + 1]);
                }

                // delete -> swap
                for(int k = 0; k < m && min_d >= 3; ++k) {
                    auto ss1 = (k == 0 ? string("") : s1.substr(0, k)) + (k + 1 == m ? string("") : s1.substr(k + 1));
                    for(int l = 0; l + 1 < m - 1; ++l) {
                        swap(ss1[l], ss1[l + 1]);
                        if(ss1 == s2) min_d = 2;
                        swap(ss1[l], ss1[l + 1]);
                    }
                }

                if(min_d <= d) {
                    ans.push_back(min(name[i], name[j]) + "," + max(name[i], name[j]));
                }
            }
        }

        sort(begin(ans), end(ans));
        for(auto x : ans) {
            cout << x << endl;
        }
        cout << ans.size() << endl;
    }
}


Measured memory_bytes: 2996
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
typedef pair<int, int> P;
int compress(int *, int *, int);
void bfs(int, int);
int n, W, H;
int xa[1000], xb[1000], ya[1000], yb[1000];
bool pt[5000][5000] = {};
int main() {
	int w, h, ans = 0;
	while (cin >> w >> h&&w&&h) {
		cin >> n;
		ans = 0;
		memset(pt, 0, sizeof(pt));
		for (int i = 0; i < n; i++) {
			scanf("%d%d%d%d", &xa[i], &ya[i], &xb[i], &yb[i]);
		}
		W = compress(xa, xb, w);
		H = compress(ya, yb, h);
		for (int i = 0; i < n; i++) {
			for (int j = xa[i]; j < xb[i]; j++) {
				for (int k = ya[i]; k < yb[i]; k++) {
					pt[k][j] = 1;
				}
			}
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (!pt[i][j]) {
					bfs(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

int compress(int *x1, int *x2, int lim) {
	vector<int> vec;
	for (int i = 0; i < n; i++) {
		for (int j = -1; j <= 1; j++) {
			int a = x1[i] + j, b = x2[i] + j;
			if (a >= 0 && a < lim) vec.push_back(a);
			if (b >= 0 && b < lim) vec.push_back(b);
		}
	}
	sort(vec.begin(), vec.end());
	vec.erase(unique(vec.begin(), vec.end()), vec.end());
	for (int i = 0; i < n; i++) {
		x1[i] = find(vec.begin(), vec.end(), x1[i]) - vec.begin();
		x2[i] = find(vec.begin(), vec.end(), x2[i]) - vec.begin();
	}
	return vec.size();
}

void bfs(int x, int y) {
	queue<P> que;
	que.push(P(x, y));
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		for (int i = -1; i <= 1; i++) {
			if (i) {
				int a = p.first + i, b = p.second + i;
				if (a >= 0 && a < H && !pt[a][p.second]) {
					pt[a][p.second] = 1;
					que.push(P(a, p.second));
				}
				if (b >= 0 && b < W && !pt[p.first][b]) {
					pt[p.first][b] = 1;
					que.push(P(p.first, b));
				}
			}
		}
	}
}

Measured memory_bytes: 25716