akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
 int i, c;
 printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

 if(T[u].p==NIL) printf("root, ");
 else if(T[u].l==NIL) printf("leaf, ");
 else printf("internal node, ");

 printf("[");
 for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
   if(i) printf(", ");
   printf("%d", c);
 }
 printf("]\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
 if(T[u].p!=NIL&&T[u].r!=NIL) calcDepth(T[u].r,p);
}

int main(){
 int i, j, k;
 int n;
 int id, sib, child;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

 for(i=0; i<n; i++){
   scanf("%d %d", &id, &k);
   for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
     scanf("%d", &child);
     T[child].p = id;
     if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
     else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
     sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
   }
 }

 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);

 //出力 (output)
 for(i=0; i<n; i++) print(i);

 return 0;
}


Measured memory_bytes: 4764
import java.io.*; import java.util.*;
public class Main {
    static ArrayList<Long> arl;
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        long N=2*Long.parseLong(br.readLine());
        arl=new ArrayList<>();
        fact(N);
        int n=arl.size();
        
        long ans=N-1;
        for (int i = 0; i < (1<<n); i++) {//WLOG, n-1 is in the second set
            long A=1;
            for (int j = 0; j < n; j++) {
                if((i&(1<<j))>0){
                    A*=arl.get(j);
                }
            }
            long B=N/A;
            long x=inv(B,A);
            //System.out.println(A+" "+B+" "+x);
            if(x*B>1){
                ans=Math.min(ans,x*B-1);
            }
            
        }
        System.out.println(ans);
    }
    public static void fact(long i){
        for (int j = 2; j <= Math.sqrt(i); j++) {
            long cur=1;
            while(i%j==0){
                i/=j; cur*=j;
            }
            if(cur>1){
                arl.add(cur);
            }
            
        }
        if(i>1){
            arl.add(i);
        }
    }
    public static long inv(long a, long b){//Computes modular inverse of a mod b
        //Assume b>a and gcd(a,b)=1, 
        if(a==1)return 1;
        long q=b/a;
        long r=b-q*a;
        long y=-inv(r,a);
        return ((b*y+1)/a)+b;
        
    }
}


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

int main()
{
  int n;
  cin>>n;
  int number =n;
  int sum=0;
  while(number>0)
  {
    int temp=number%10;
    sum+=temp;
    number/=10;
  }
  if(n%sum==0)cout<<"Yes";
  else cout<<"No";


}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] A = new int[n];
			for(int i=0; i<n;i++) {
				A[i] = sc.nextInt();
			}
			int q = sc.nextInt();
			for(int i=0; i<q;i++) {
				int com = sc.nextInt();
				int b = sc.nextInt();
				int e = sc.nextInt();
				int result = A[b];
				switch(com) {
				case 0:
					for(int j=b+1;j<e;j++) {
						result = Math.min(result,A[j]);
					}
					break;
				case 1:
					for(int j=b+1;j<e;j++) {
						result = Math.max(result,A[j]);
					}
					break;
				}
				System.out.println(result);
			}
		}
	}
}


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

#define REP(i, l, n) for(int i=(l), i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define pb push_back

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;}

char alpha[26] = {'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'};

int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, 1, -1};

int main(){
    int n, k; cin >> n >> k;
    string s; cin >> s;
    int sum = 0;
    int r = 1;
    int ans = 0;
    if(s[0] == '0'){
        sum++;
    }
    REP(l, 0, n){
        while(sum < k+1){
            //cout << l << r << endl << sum << endl;
            if(r == n){
                break;
            }else{
                if(s[r-1] == '1' && s[r] == '0'){
                    sum++;
                }
                r++;
            }
        }
        if(r == n){
            if(s[n-1] == '0' && s[n-2] == '1'){
                ans = max(ans, r-l-1);
            }else{
                ans = max(ans, r-l);
            }
        }else{
            ans = max(ans, r-l-1);
        }
        if(l+1 < n && s[l] == '0' && s[l+1] == '1'){
            sum--;
        }
    }
    cout << ans << endl;
}

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

using P = pair<int, int>;
using L = pair<P, P>;
long long r, c, n;
vector<L> v;

bool solve();
int main() {
  cin >> r >> c >> n;
  for (int i = 0; i < n; ++i) {
    int a, b, d, e;
    cin >> a >> b >> d >> e;
    if ((a == 0 || a == r || b == 0 || b == c) &&
        (d == 0 || d == r || e == 0 || e == c))
      v.emplace_back(P(a, b), P(d, e));
  }
  if (solve())
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}

bool solve() {
  n = v.size();
  vector<set<P>> memo(4);
  auto pin = [&](P& p, int& id) {
    int x = p.first, y = p.second;
    if (x == 0)
      memo[0].insert(P(y, id));
    else if (y == c)
      memo[1].insert(P(x, id));
    else if (x == r)
      memo[2].insert(P(-y, id));
    else if (y == 0)
      memo[3].insert(P(-x, id));
  };
  for (int i = 0; i < n; ++i) {
    pin(v[i].first, i);
    pin(v[i].second, i);
  }
  stack<int> st;
  for (int i = 0; i < 4; ++i)
    for (auto p : memo[i])
      if (st.size() && st.top() == p.second)
        st.pop();
      else
        st.push(p.second);
  return !st.size();
}

Measured memory_bytes: 14488
#include<stdio.h>
int main(void){
   int a,b,c,d,n,co;
   while(scanf("%d",&n)!=EOF){
   for(co=0,a=0;a<=9;a++){
      for(b=0;b<=9;b++){
         for(c=0;c<=9;c++){
            for(d=0;d<=9;d++){
               if(n==a+b+c+d)
               co=co+1;
               else{
               }
   }}}}
   printf("%d\n",co);
   }
   return 0;
}

Measured memory_bytes: 596
import sys
n=int(input())
a=[-1]*n
print(0)
sys.stdout.flush()
a[0]=input()
l=0
print(n-1)
sys.stdout.flush()
r=n-1
a[n-1]=input()
while l!=r:
  if r==l+1:
    try1=r
  else:
    try1=(l+r)//2
  print(try1)
  sys.stdout.flush()
  a[try1]=input()
  if a[try1]=='Vacant':
    sys.exit()
  if ((r-try1)%2==0 and a[try1]!=a[r]) or ((r-try1)%2==1 and a[try1]==a[r]):
    l=try1
  else:
    r=try1


Measured memory_bytes: 77088
import java.awt.geom.Point2D;
import java.util.*;
public class Main {	
	Scanner in = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}

	public Main(){		
		new AOJ0012();
	}

	class AOJ0012{
		void run(){
			Point2D point[] = new Point2D[3];
			for(int i=0;i<3;i++)point[i] = new Point2D.Double(in.nextDouble(),in.nextDouble());
			Point2D target = new Point2D.Double(in.nextDouble(),in.nextDouble());
			int memo = right_left(point[0],point[1], target);
			boolean sw = true;
			for(int i=0;i<3;i++)if(memo!=right_left(point[i],point[(i+1)%3], target))sw=false;
			if(sw)System.out.println("YES");
			else System.out.println("NO");
		}
		public AOJ0012() {
			while(in.hasNext())run();
		}

		int right_left(Point2D a,Point2D b,Point2D target){ //a-bの直線はtargetの右か左か
			Point2D q = new Point2D.Double(b.getX()-a.getX(),b.getY()-a.getY());
			Point2D r = new Point2D.Double(target.getX()-a.getX(),target.getY()-a.getY());
//			System.out.println("q= "+q);
//			System.out.println("r= "+r);
//			System.out.println(cross(q, r));
			if(cross(q, r)>0)return -1;//左側
			else if(cross(q,r)<0)return 1;//右側
			else return 0;//重なっている
		}
		double cross(Point2D p1,Point2D p2){
			return p1.getX()*p2.getY()-p1.getY()*p2.getX();
		}
	}


}

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
    ll A, B, K;
    cin >> A >> B >> K;
    vector<ll> ans;
    REP(i, K)
    {
        if (A + i <= B)
            ans.push_back(A + i);
        if (B - i >= A)
            ans.push_back(B - i);
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());
    REP(i, ans.size())
    {
        cout << ans[i] << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  cout << max(max(a + b, a - b), a * b) << "\n";
}

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

int main() {
  int N;
  cin >> N;
  double a;
  double total = 0;
  for(int i = 0; i < N; ++i) {
    cin >> a;
    total += 1 / a;
  }
  cout << setprecision(12) << 1 / total << endl;
  return 0;
}

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

int main(){
	int n;
	int out[1000];
	cin >> n;
	for(int i = 0; i < n; i++){
		double t;
		bool irekae = {false};
		double xa, ya, ra, xb, yb, rb;
		cin >> xa >> ya >> ra >> xb >> yb >> rb;
		t = sqrt((xa-xb)*(xa-xb)+(ya-yb)*(ya-yb));
		if((ra+rb) < t){
			out[i] = 0;
			continue;
		}
		if(ra < rb){
			swap(xa,xb);
			swap(ya,yb);
			swap(ra,rb);
			irekae = {true};
		}
		if(t+rb < ra){
			if(irekae == true){
				out[i] = -2;
				continue;
			}
			else{
				out[i] = 2;
				continue;
			}
		}
		else{
			out[i] = 1;
		}
	}
	for(int i = 0; i < n; i++){
		cout << out[i] << endl;
	}
}

Measured memory_bytes: 1240
import java.util.*;
import java.awt.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        String s=sc.next();
        TreeSet<Integer> ts=new TreeSet<>();
        for (int i = 0; i <= s.length()-3; i++) {
            ts.add(abs(753-Integer.parseInt(s.substring(i, i+3))));
        }
        out.println(ts.pollFirst());
    }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans*x)%mod;
            }
            x=(x*x)%mod;
            n>>=1;
        }
        return ans;
    }
    //最大公約数
    static int gcd (int a, int b) {
        int temp;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return b;
    }
//※最小公倍数はa*b/gcd(a,b)である
}


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

const int MOD = 1e9 + 7;
const int MAXN = 112345;

int n;
long long v[MAXN];
long long sum = 0LL;
long long ans[MAXN];

map<long long,long long> freq;
stack<pair<long long,long long> > st;

int main(){
	
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	
	st.push(make_pair(0,0));
	
	cin >> n;
	for(int i = 1 ; i <= n ; i ++){
		cin >> v[i];
		freq[v[i]]++;
		sum += v[i];
		if(v[i] > st.top().second)
			st.push(make_pair(i, v[i]));
	}
	
	long long prev = 0LL;
	
	while(st.size() != 1){
		
		int id = st.top().first;
		int x = st.top().second;
		st.pop();
		
		long long middle = 0LL;
		long long cnt = 0LL;
		map<long long,long long> :: iterator it, jt;
		it = freq.lower_bound(st.top().second + 1);
		
		for( ; it != freq.end() ; it++){
          	cnt += it->second;
			if(it->first == x){
              	middle += (it->first - st.top().second) * (prev + it->second);
              	break;
            }
			middle += (it->first - st.top().second) * (it->second);
		}
		
		ans[id] = middle;
		sum -= ans[id];
		if(st.size() == 1) ans[id] += sum;
		prev += cnt;
	}
	
	for(int i = 1 ; i <= n ; i ++)
		cout << ans[i] << "\n";
	
	return 0;
}

Measured memory_bytes: 13040
#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>;

#include <atcoder/all>
using namespace atcoder;

int main() {
  int k;
  cin >> k;
  string s = "ACL";
  string ans;
  rep(i, k) ans += s;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    vector<ll> all_target, odd_target;
    rep2(i, 1, 500) {
        ll r = (i * (i + 1) * (i + 2)) / 6;
        if (r % 2) {
            odd_target.push_back(r);
        }
        all_target.push_back(r);
    }
    vector<ll> dp1(1e6, INF);
    vector<ll> dp2(1e6, INF);
    dp1[0] = 0;
    dp2[0] = 0;
    rep(i, 1e6) {
        for (ll a : all_target) {
            if (i + a < 1e6) {
                dp1[i + a] = min(dp1[i + a], dp1[i] + 1);
            }
        }
    }
    rep(i, 1e6) {
        for (ll o : odd_target) {
            if (i + o < 1e6) {
                dp2[i + o] = min(dp2[i + o], dp2[i] + 1);
            }
        }
    }
    while (true) {
        ll n;
        cin >> n;
        if (!n) return;
        cout << dp1[n] << ' ';
        cout << dp2[n] << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}



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

#define int long long

signed main(){
  int n;
  cin >> n;

  int a[n+1];
  for(int i = 1;i<=n;i++)cin >> a[i];

  int sum1 = 0, sum2 =0;
  for(int i = 1;i<=n;i++){
    if(i%2==0)sum2+=a[i];
    sum1+=a[i];
  }

  int x[n+1];
  x[1] = sum1 - 2*sum2;

  for(int i = 2;i<=n;i++){
    x[i] = 2*a[i-1] - x[i-1];
  }

  for(int i = 1;i<=n;i++)cout << x[i] << " ";
    cout << endl;
  return 0;
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int n, k, x, y;
   cin >> n >> k >> x >> y;
   int ans = 0;

   if (n <= k)
   {
      ans += x * n;
   }
   else
   {
      ans += x * k;
      ans += y * (n - k);
   }
   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	int a, b, c, d, e, f;
	char zyunkai[1023] = {0};
	char train[27]={0};
	char X[27]={0};
	while (scanf("%d", &a) != EOF)
	{
		for (b = 0; b < a; b++)
		{
			scanf("%s", &zyunkai);
			train[0] = zyunkai[0];
			d = 1;
			for (c = 3; ; c += 3)
			{
				if (strchr(train, zyunkai[c]) == NULL && zyunkai[c-1] == '>')
				{
					train[d] = zyunkai[c];
					d++;
				}
				else if(strchr(train, zyunkai[c]) == NULL && zyunkai[c-2] == '<')
				{
					X[0] = zyunkai[c];
					strcat(X, train);
					strcpy(train, X);
					d++;
				}
				f = strlen(X);
				for (e = 0; e < f; e++)
					X[e] = NULL;
				if (zyunkai[c+1] == NULL)
					break;
			}
			printf("%s\n", train);
			f = strlen(train);
			for (e = 0; e < f; e++)
				train[e] = NULL;
			f = strlen(zyunkai);
			for (e = 0; e < f; e++)
				zyunkai[e] = NULL;
		}
	}

	return 0;
}

Measured memory_bytes: 608
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;



#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)

ll debugFlag = false;
template<typename T> void debug(T&);
template<typename T> void debug(T&, bool);
template<typename T> void debug(vector<T>&);
template<typename T> void debug(vector<T>&, bool);
template<typename T, typename U> void debug(pair<T, U>&);
template<typename T, typename U> void debug(pair<T, U>&, bool);

template<typename T>
void debug(T& obj) {
	debug(obj, true);
}

template<typename T>
void debug(T& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << obj;
	if (lnFlag) cout << endl;
}

template<typename T>
void debug(vector<T>& obj) {
	debug(obj, true);
}

template<typename T>
void debug(vector<T>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "[";
	rep(i, obj.size()) {
		if (i != 0) cout << ",";
		debug(obj[i], false);
	}
	cout << "]";
	if (lnFlag) cout << endl;
}

template<typename T, typename U>
void debug(pair<T, U>& obj) {
	debug(obj, true);
}

template<typename T, typename U>
void debug(pair<T, U>& obj, bool lnFlag) {
	if (!debugFlag) return;
	cout << "(";
	debug(obj.first, false);
	cout << ",";
	debug(obj.second, false);
	cout << ")";
	if (lnFlag) cout << endl;
}

void solve() {

	int A, B;
	cin >> A >> B;

	if (A < 10 && B < 10) {
		cout << A * B;
	}
	else {
		cout << "-1";
	}

}


int main(int argc, char* argv[]) {
	if (argc == 2 && string(argv[1]) == "debug") debugFlag = true;
	solve();
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
import java.io.*;

public class Main{
	int INF = 1 << 24;
	int MAX = 300000 + 1000;
	boolean [] isMS = new boolean[MAX + 1];
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		init();
		while(true){
			int n = sc.nextInt();
			if(n == 1) break;
			System.out.print( n + ":");
			for(int i = 0; i * 7 < n; i++){
				int a = i * 7 + 1;
				if(a != 1 && a <= n && n % a == 0 && isMS[a]){
					System.out.print(" " + a);
				}
				int b = i * 7 + 6;
				if(b <= n && n % b == 0 && isMS[b]){
					System.out.print(" " + b);
				}
			}
			System.out.println();
		}
		
	}

	private void init() {
		
		for(int i = 0; i * 7 < MAX; i++){
			int a = i * 7 + 1;
			if(a != 1 && a < MAX){
				isMS[a] = true;
			}
			int b = i * 7 + 6;
			if(b < MAX){
				isMS[b] = true;
			}
		}
		
		for(int i = 0; i <= MAX; i++){
			if(isMS[i]){
				for(int j = i * 2; j <= MAX; j+= i){
					isMS[j] = false;
				}
			}
		}
	}

	private void debug(Object... o) {
		System.out.println("debug = " + Arrays.deepToString(o));
	}

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

Measured memory_bytes: 24292
import java.util.Scanner;
import java.util.concurrent.ForkJoinPool;

import static java.lang.Integer.*;

public class Main {


    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[][] nums = new int[n][3];
        int[] dp = new int[3]; //
        for (int i = 0; i < n; i++) {
           int[] c = new int[3];
           int[] newDp = new int[3];
            for (int j = 0; j < 3; j++) {
               c[j] = scan.nextInt();
            }

            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 3; k++) {
                    if(j != k) {
                       newDp[k] = max(newDp[k], dp[j] + c[k]);
                    }
                }
            }
            dp = newDp;
        }
        System.out.println(max(dp[2], max(dp[0], dp[1])));

    }

}


Measured memory_bytes: 94932
# coding: utf-8
# Your code here!

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline

#n = int(input())
#n,a = [int(i) for i in readline().split()]
n = int(input())
s = int(input())

def digit_sum(n,b):
    res = 0
    while n:
        n, r = n//b, n%b
        res += r
    return res


c = int(n**0.5)+2
for b in range(2,c):
    if digit_sum(n,b) == s:
        print(b)
        exit()

for p in range(c,0,-1):
    q = s-p
    if q < 0: continue
    if (n-q)%p: continue
    b = (n-q)//p
    if p >= b: continue
    if q >= b: continue
    
    print(b)
    exit()
if n==s:
    print(n+1)
    exit()


print(-1)







Measured memory_bytes: 3064
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<int64_t> A(N);
  vector<int64_t> B(N);
  vector<int64_t> C(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> A[i];
  }
  for (int64_t i = 0; i < N; ++i) {
    cin >> B[i];
  }
  for (int64_t i = 0; i < N; ++i) {
    cin >> C[i];
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  vector<int64_t> sum_count_B(N, 0);
  for (int64_t i = N - 1; i >= 0; --i) {
    int64_t b = B[i];
    auto itr = upper_bound(C.begin(), C.end(), b);
    const int64_t c_count = static_cast<int64_t>(C.end() - itr);
    if (i == N - 1) {
      sum_count_B[i] = c_count;
    } else {
      sum_count_B[i] = sum_count_B[i + 1] + c_count;
    }
  }
  vector<int64_t> sum_count_A(N, 0);
  for (int64_t i = N - 1; i >= 0; --i) {
    int64_t a = A[i];
    auto itr = upper_bound(B.begin(), B.end(), a);
    const int64_t b_index = static_cast<int64_t>(itr - B.begin());
    const int64_t c_count = (itr == B.end()) ? 0 : sum_count_B[b_index];
    if (i == N - 1) {
      sum_count_A[i] = c_count;
    } else {
      sum_count_A[i] = sum_count_A[i + 1] + c_count;
    }
  }

  cout << sum_count_A[0] << endl;
  return 0;
}


Measured memory_bytes: 7164
#include <iostream>
using namespace std;
int main() {
    int a,b;
    int m = 0;
    cin >> a >> b;
    for (int i = 0; i < 4; ++i) {
        int c = a * b * i;
        if(c % 2 !=0){
            cout << "Yes";
            m = 1;
            break;
        }
    }
    if (m == 0){
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 256
import math
A, B, H, M = map(int, input().split())

mins = H * 60 + M

# 分速の差は何度か
diff_s = 5.5

# 鋭角の角度を計算
tmp = diff_s * mins % 360
diff = min(tmp, 360 - tmp)

# ラジアンに変換
diff = math.radians(diff)

# 余弦定理
a2 = A**2 + B**2 - 2 * A * B * math.cos(diff)
ans = a2**0.5

print(ans)

Measured memory_bytes: 9508
import sys
sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
N = int(input())
G = [[] for i in range(N + 1)]
for i in range(1, N):
    a = int(input())
    G[a - 1].append(i)


def dfs(v):
    if len(G[v]) == 0:
        return 0
    D = []
    for w in G[v]:
        D.append(dfs(w))

    D = sorted(D, reverse=True)

    num = 0
    for i in range(len(D)):
        num = max(num, D[i] + i + 1)

    return num


print(dfs(0))

Measured memory_bytes: 118960
import math
n = int(input())
c_t = 0
c_a = 0
for i in range(n):
    t, a = [int(x) for x in input().split(" ")]
    #print(min(c_t / t, c_a / a))
    init = int(max(c_t // t, c_a // a, 1))
    for j in range(init,10**18):
        if t*j >= c_t and a*j >= c_a:
            c_t = t*j
            c_a = a*j
            #print("->" + str(j))
            break
print(c_t + c_a)


Measured memory_bytes: 3064
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=100005;
bool t[N],s[4];
int n,a[4][N],id[N];

int getint()
{
	char ch;
	while(!isdigit(ch=getchar()));
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x;
}

int get(int a,int b,int c)
{
	if(a%3==0 && b==a-1 && c==b-1) return -a/3;
	if(c%3==0 && b==c-1 && a==b-1) return c/3;
	return 0;
}

void ins(int x)
{
	for(int i=x; i; i-=i&-i) t[i]^=1;
}

bool query(int x)
{
	bool rt=0;
	for(int i=x; i<=n; i+=i&-i) rt^=t[i];
	return rt;
}

int main()
{
	n=getint();
	rep(i,1,3) rep(j,1,n) a[i][j]=getint();
	rep(i,1,n)
	{
		int t=get(a[1][i],a[2][i],a[3][i]);
		if(!t || (t^i)&1) return puts("No"),0;
		id[i]=abs(t);
		if(t<0) s[i&1]^=1;
	}
	for(int i=1; i<=n; i+=2)
		s[2]^=query(id[i]),ins(id[i]);
	memset(t,0,sizeof(t));
	for(int i=2; i<=n; i+=2)
		s[3]^=query(id[i]),ins(id[i]);
	if(s[0]==s[2] && s[1]==s[3]) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
  int data[10];
  int work;
  for(int i=0;i<10;i++)
    scanf("%d",&data[i]);
  for(int i=0;i<10;i++)
  {
    for(int k=i+1;k<10;k++)
    {
        if(data[i]<data[k])
          {
            work=data[i];
            data[i]=data[k];
            data[k]=work;
          }
    }
  }

  for(int k=0;k<3;k++)
  {
    printf("%d\n",data[k]);
  }


}

Measured memory_bytes: 1752
import sys
import math
def get_array(): return list(map(int,sys.stdin.readline().strip().split()))
def get_ints(): return map(int,sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()
a,b,h,m=get_ints()
a1=abs(h*30+m*0.5)-m*6 
ang=min(360-a1,a1)
ang1=math.radians(ang)
ans=a*a+b*b-2*a*b*math.cos(ang1)
print(math.sqrt(ans))

        
    
    
    
            
            
            
    
    
    
    
        
        
    
    
        
            
    
    
    
    
    
    
            
            
            
    

    

Measured memory_bytes: 62620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define vi vector<long long>
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define min3(a, b, c) min(a, min(b, c))
#define min4(a, b, c, d) min(min(a, d), min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define max4(a, b, c, d) max(max(a, d), max(b, c))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

int a[201][201], ans=0, x;
int dp[10][10];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("A.txt", "r", stdin);
    #endif
    int n, m;
    cin >> n >> m;
    for(int i=0; i<10; i++)
    {
        for(int j=0; j<10; j++)
        {
            cin >> dp[i][j];
        }
    }
    for(int i=0; i<10; i++)
    {
        for(int j=0; j<10; j++)
        {
            for(int k=0; k<10; k++)
            {
                dp[j][k] = min(dp[j][k], dp[j][i] + dp[i][k]);
            }
        }
    }
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<m; j++)
        {
            cin >> x;
            ans += (x==-1?0:dp[x][1]);
        }
    }
    cout << ans;
}



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n, d;
    cin >> n >> d;
    int ans = (n + (2*d+1) - 1) / (2*d + 1);
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>


int main() {

    int a,b;
    scanf("%d %d", &a, &b);

    if(a == 1 && a != b) {
        printf("%s\n", "Alice");
    } else if (b == 1 && a != b) {
        printf("%s\n", "Bob");
    } else if(a > b) {
        printf("%s\n", "Alice");
    } else if (a < b) {
        printf("%s\n", "Bob");
    } else {
        printf("%s\n", "Draw");
    }

    return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007 * 1000000007;

ll rep_square(ll a, ll b) {
    // return a^b
    ll ans = 1;
    ll base = a;
    while (b != 0) {
        if (b & 1) {
            ans *= base;
        }
        base *= base;
        b >>= 1;
    }
    return ans;
}

int main() {
source:
    ll n, p;
    cin >> n >> p;
    ll a[n];
    rep(i, n) { cin >> a[i]; }
    ll odd = 0, even = 0;
    rep(i, n) {
        if (a[i] % 2) {
            odd++;
        } else {
            even++;
        }
    }
    ll ans = 0;

    if (odd == 0) {
        if (p) {
            cout << 0 << endl;
        } else {
            cout << rep_square(2, n) << endl;
        }
        return 0;
    }

    ans = rep_square(2, n - 1);

    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll gcd(ll a, ll b) 
{ 
    // Everything divides 0  
    if (a == 0) 
       return b; 
    if (b == 0) 
       return a; 
   
    // base case 
    if (a == b) 
        return a; 
   
    // a is greater 
    if (a > b) 
        return gcd(a-b, b); 
    return gcd(a, b-a); 
} 
int main () {
	ll k;cin>>k;
	ll dp[k+1][k+1];ll i,j,k1;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		dp[i][j]=gcd(i,j);
	}
	ll s=0;
	for(i=1;i<=k;i++)
	{
		for(j=1;j<=k;j++)
		{
			for(k1=1;k1<=k;k1++)
			{
				s+=gcd(i,dp[j][k1]);
			}
		}
	}
	cout<<s<<endl;
	return 0;
}


Measured memory_bytes: 3904
S = list(input())[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1  # If 2019 is exist, count number
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current]
    mods[current] += 1
    x = x * 10 % 2019

print(ans)

Measured memory_bytes: 11700
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
	static void Main(string[] args)
	{
		int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
		int[] N = new int[intArray[0]];
		int K = intArray[1];
		int Q = intArray[2];

		List<int> A = new List<int>();
		for(int i = 0;i < Q; i++)
        {
			N[int.Parse(Console.ReadLine()) - 1] += 1;
        } 
		for(int i = 0;i < N.Length; i++)
        {
			if(N[i] > Q - K)
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
		Console.ReadKey();
	}
}


//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();
//Console.WriteLine(cnt);

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


Measured memory_bytes: 17888
#include <stdio.h>

int min(int a, int b) {

    if(a <= b) return a;
    else return b;
}

/* 
int gcd(int a, int b, int c) {
    if (c == 0) return a;
    return gcd(c, a % c, b % c); 
}
*/

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

int main() {

int i;
int a, b, c;
int K;
int sum;

scanf("%d", &K);

sum = 0;

    for (a = 1; a <= K; a++) {
        //sum++;
        for (b = 1; b <= K; b++) {
            //sum++;
            for (c = 1; c <= K; c++) {
                sum += gcd(gcd(a, b), c);
                //sum += gcd(a, b, c);
            }
        }
    }

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



Measured memory_bytes: 1732
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b) {System.out.println("a < b");}
		else if (a > b) {System.out.println("a > b");}
		else {System.out.println("a == b");}
	}
}


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

ll max_score(vector<ll>&score, ll i, ll j, vector<vector<ll>>&dp)
{
	if (i > j)
	{
		return 0;
	}

	//Lookup
	if (dp[i][j] != -1)
	{
		return dp[i][j];
	}

	ll op1 = score[i] + min(max_score(score, i + 2, j, dp), max_score(score, i + 1, j - 1, dp));
	ll op2 = score[j] + min(max_score(score, i + 1, j - 1, dp), max_score(score, i, j - 2, dp));
	ll ans = max(op1, op2);
	return dp[i][j] = ans;

}
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	vector<ll>score(n);
	ll sum = 0;
	for (ll i = 0; i < n; i++)
	{
		ll d;
		cin >> d;
		score[i] = d;
		sum += d;
	}
	vector<vector<ll>>dp(n + 1, vector<ll>(n + 1, -1));
	//cout << sum;
	ll T_score = max_score(score, 0, n - 1, dp);
	ll J_score = sum - T_score;
	cout << T_score - J_score << endl;
	return 0;

}

Measured memory_bytes: 73960
n, a, b = map(int, input().split())
if (a-b)%2 == 0:
  print(abs(a-b)//2)
else:
  if a > b:
    a, b = b, a
  a1, b1 = a, b
  s, t = 0, 0
  s += a1-1
  b1 -= s+1
  s += (b1-1)//2
  t += n-b
  a += t+1
  t += (n-a)//2
  print(min(s+1, t+1))

Measured memory_bytes: 3064
N , Y = list(map(int, input().split()))
Y = Y/1000
Z = Y - N
A = 9*N - Z
if Z < 0 or Z > 9*N:
  X = [-1,-1,-1]
elif 24 <= Z <= 9*N - 32:
  X = [(Z-27)//9+((Z%9)%4-1)%4,(9-2*(Z%9))%9,N-((Z-27)//9+((Z%9)%4-1)%4+(9-2*(Z%9))%9)]
  X = list(map(int, X))
elif 0 <= Z <= 23:
  if Z%4 == 0:
    X = [0,Z/4,N-(Z/4)]
  elif Z%9 == 0:
    X = [Z/9,0,N-(Z/9)]
  elif Z == 13 or Z == 17 or Z == 21:
    X = [1,(Z-9)/4,N-((Z-5)/4)]
  elif Z == 22:
    X = [2,1,N-3]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
else:
  if A%5 == 0:
    X = [N-(A/5),A/5,0]
  elif A%9 == 0:
    X = [N-(A/9),0,A/9]
  elif A == 14 or A == 19 or A == 24 or A == 29:
    X = [N-((A-4)/5),(A-9)/5,1]
  elif A == 23 or A == 28:
    X = [N-((A-8)/5),(A-18)/5,2]
  else:
    X = [-1,-1,-1]
  X = list(map(int, X))
print(X[0],X[1],X[2])

Measured memory_bytes: 3188
#include <stdio.h> 
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a[n+1];
	int i;
	int k;
	k=n/2;
	for(i=1;i<=n;i++){
		cin>>a[i];
	}
	int b[n+1];
	if(n%2==0){
		for(i=1;i<=k;i++){
			b[i]=a[n+2-2*i];
			b[i+k]=a[2*i-1];
		}
	}
	if(n%2==1){
		for(i=1;i<=k;i++){
			b[i]=a[n+2-2*i];
			b[i+k+1]=a[2*i];
		}
		b[k+1]=a[1];
	}
	for(i=1;i<=n-1;i++){
		cout<<b[i]<<" ";
	}
	cout<<b[n];
	return 0;
}

Measured memory_bytes: 3712
/*  /$$                                     /$$
      | $$                                    | $$
  /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$$  /$$$$$$   /$$$$$$
 /$$__  $$ /$$__  $$ /$$_____/ /$$__  $$ /$$__  $$ /$$__  $$ /$$__  $$
| $$  | $$| $$$$$$$$| $$      | $$  \ $$| $$  | $$| $$$$$$$$| $$  \__/
| $$  | $$| $$_____/| $$      | $$  | $$| $$  | $$| $$_____/| $$
|  $$$$$$$|  $$$$$$$|  $$$$$$$|  $$$$$$/|  $$$$$$$|  $$$$$$$| $$
 \_______/ \_______/ \_______/ \______/  \_______/ \_______/|__//$$$$$$ /$$$$$$
                                                               |______/|______/

*/
#include <bits/stdc++.h>
#define fastio        ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ln            cout<<endl;
#define vi            vector<int>
#define vll           vector<long long>
#define sortl(vec)    sort(vec.begin(), vec.end());
#define sortr(vec)    sort(vec.rbegin(), vec.rend());
#define forn(i, x, n) for(long long i = x; i < n; i++)
#define revn(i, n, x) for(long long i = n; i >= x ; i--)
#define in(vec)       for(auto &it : vec) cin >> it;
#define loop(vec)     for(auto &it : vec)
#define	out(vec)      for(auto &it : vec) cout << it << " "; ln
#define ll            long long
#define mod           1000000007
#define debug(x)      cout << x << endl;
#define pb            emplace_back
#define mp            make_pair
#define um            unordered_map
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define f             first
#define s             second
#define pi            3.14159265359
#define CLOCK         cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
using namespace std;

ll power(ll x, ll y, ll p) {
	ll res = 1;
	x = x % p;

	while (y > 0) {
		if (y & 1)
			res = (res * x) % p;

		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

ll modulo(ll a, ll b) {
	ll c = a % b;
	return (c < 0) ? c + b : c;
}

int main() {
// in(vec) works for size-defined type vectors

#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input1.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output1.txt", "w", stdout);
#endif

	fastio
	ll t = 1;
	while (t--) {
		ll n;
		cin >> n;
		vll vec(100005, 0);
		ll sum = 0;

		forn(i, 0, n) {
			ll a;
			cin >> a;
			sum += a;
			vec[a]++;
		}

		ll q;
		cin >> q;
		while (q--) {
			ll b, c;
			cin >> b >> c;

			if (vec[b] > 0) {


				sum = sum - b * vec[b] + vec[b] * c;
				vec[c] += vec[b];
				vec[b] = 0;
			}

			cout << sum << endl;
		}



	}
	CLOCK
	return 0;
}



Measured memory_bytes: 3976
#include<stdio.h>
int main(void) {

	int A, B;
	scanf("%d%d", &A, &B);
	if (A > B) {
		printf("%d\n", A + A - 1);
	}
	else if (A == B) {
		printf("%d\n", A + B);
	}
	else {
		printf("%d\n", B + B - 1);
	}


	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define INF 1e9

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

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

    ll N, X;
    cin >> N >> X;

    ll x[N];

    ll tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        x[i] = abs(tmp - X);
    }
    if (N==1) {
        cout << x[0] << endl;
        exit(0);
    }

    ll ans = gcd(x[0], x[1]);
    for (int i = 2; i < N; i++) {
        ans = gcd(x[i], ans);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int a, b;
int pal(int x) {
  for(int i=0; i<2; i++){
    if(x / 10000 == x % 10){
      int x1 = (x % 10000) / 1000;
      int x2 = (x % 100) / 10;
      if(x1 == x2) return 1;
    }
  }
  return 0;
}
int main() {
  cin >> a >> b;
  int sum=0;
  for(int i=a; i<=b; i++){
    sum += pal(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()

const int MOD = 1e9 + 7;
const int N = 2e5 + 5;

int n;
int arr[N];

int main()
{
  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++)
    cin >> arr[i];
  sort(arr, arr + n, greater<int>());
  long long ans = 0;
  for(int i = 0 ; i < n ; i++){
    ans += (1LL * arr[i] * (i + 2)) % MOD;
    ans %= MOD;
  }
  for(int i = 1 ; i < n ; i++)
    ans = (ans * 4) % MOD;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> L(N * 2);
  for (int i = 0; i < N * 2; i++) cin >> L[i];
  sort(L.begin(),L.end());
  int ans = 0;
  for (int i = 0; i < N * 2; i += 2){
    ans += L[i];
  }
  cout << ans;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int a,b;
    cin >> a >> b;
    cout<< a*b << " " << a*2+b*2 <<'\n';
    return 0;
}


Measured memory_bytes: 3132
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}


//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var D = nextInt();
	var clist = nextIntArray();
	var output = new Array(D);
	var lastContest = new Array(26).fill(0);
	for(var i = 1; i <= D; i++){
		var list = nextIntArray();
		var max = -1;
		var maxIndex = -1;
		for(var j = 0; j < list.length; j++){
			if(max < list[j]){
				max = list[j];
				maxIndex = j;
			}
		}
		lastContest[maxIndex] = i;
		for(var j = 0; j < 26; j++){
			max -= clist[j] * (i - lastContest[j]);
		}
		myerr(max);
		//output[i] = maxIndex + 1;
		output[i] = Math.ceil(Math.random() * 26);
	}
	myout(myconv(output,9));
}


Measured memory_bytes: 35080
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int main(void) {
    int dist, _time, speed;
    scanf("%d %d %d", &dist, &_time, &speed);
    if (speed*_time >= dist) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
   int n;
   cin>>n;

   set<int>s;
   for(int i=0;i<n;i++)
   {
   int x;
   cin>>x;
   s.insert(x);

   }
   if(s.size()==n)
   {
       cout<<"YES\n";
   }
   else
    cout<<"NO\n";
}


Measured memory_bytes: 9600
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

int main(){
    int n;
    cin >> n;
    vector<int> rnum(n+1);
    for(int i = 0; i < n; i++){
        cin >> rnum[i] >> rnum[i+1];
    }

    vector<vector<int>> memo(n, vector<int>(n, INF));
    for(int i = 0; i < n; i++) memo[i][i] = 0;

    for(int i = n-1; i >= 0; i--){
        for(int j = i; j < n; j++){
            for(int k = i; k+1 < n; k++){
                if(memo[i][j] > memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1]){
                    memo[i][j] = memo[i][k] + memo[k+1][j] + rnum[i]*rnum[k+1]*rnum[j+1];
                }
            }
        }
    }

    cout << memo[0][n-1] << endl;
    return 0;
}


Measured memory_bytes: 3204
n = int(input())
march =[]

for i in range(n):
    a = input()
    ai = a[0]
    march.append(ai)

import collections
c = collections.Counter(march)

mm = c["M"]
aa = c["A"]
rr = c["R"]
cc = c["C"]
hh = c["H"]

import itertools
seq = [mm,aa,rr,cc,hh]
mmm = list(itertools.combinations(seq,3))

res= 0
for i in range(10):
    aaa = mmm[i]
    res += aaa[0]*aaa[1]*aaa[2]

print(res)

Measured memory_bytes: 10008
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		String[] g = new String[h];
		char[][] grid = new char[h][w];
		for (int i = 0; i < h; i++) {
			g[i] = sc.next();
			for (int j = 0; j < w; j++) {
				grid[i][j] = g[i].charAt(j);
			}
		}
		sc.close();
		int[][] tate = new int[h][w];// 縦列の累積和もどき
		for (int i = 0; i < w; i++) {
			for (int j = 0; j < h; j++) {
				if (grid[j][i] == '.') {
					int tmp = j;
					while (true) {
						j++;
						if (j >= h || grid[j][i] == '#') {
							int ans = j - tmp;
							for (int k = tmp; k < j; k++) {
								tate[k][i] = ans;
							}
							break;
						}
					}
				}
			}
		}
		int[][] yoko = new int[h][w];// 横列の累積和もどき
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (grid[i][j] == '.') {
					int tmp = j;
					while (true) {
						j++;
						if (j >= w || grid[i][j] == '#') {
							int ans = j - tmp;
							for (int k = tmp; k < j; k++) {
								yoko[i][k] = ans;
							}
							break;
						}
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				int tmp = tate[i][j] + yoko[i][j] - 1;
				if (ans < tmp) {
					ans = tmp;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 74468
import java.util.*;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while(sc.hasNext()){
			String[] data=sc.next().split(",");
			int id=Integer.parseInt(data[0]);
			double weight=Double.parseDouble(data[1]);
			double height=Double.parseDouble(data[2]);
			if(weight>=height*height*25){
				ln(id);
			}
		}

	}

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

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
a_count = gets.chomp.to_i
a = gets.chomp.split(" ").map { |i| i.to_i }
b_count = gets.chomp.to_i
b = gets.chomp.split(" ").map { |i| i.to_i }

count = 0
b.each do |i|
  a.each do |v|
    if i == v
      count += 1
      break
    end
  end
end
puts count



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

int main() {
  int A, B;
  cin >> A >> B;
  A == 1 ? B == 2 ? cout << 3 << endl : cout << 2 << endl : A == 2 ? B == 3 ? cout << 1 << endl : cout << 3 << endl : B == 1 ? cout << 2 << endl : cout << 1 << endl;
}


Measured memory_bytes: 256
midExam, finalExam, reExam = list(map(int, input().split()))
addedResult = midExam + finalExam

while True :
    if midExam == -1 and finalExam == -1 and reExam == -1 :
        break;
    
    if midExam == -1 or finalExam == -1 or addedResult < 30 :
        print("F")
    elif addedResult >= 80 :
        print("A")
    elif addedResult >= 65 and addedResult < 80 :
        print("B")
    elif addedResult >= 50 and addedResult < 65 :
        print("C")
    elif addedResult >= 30 and addedResult < 50 :
        if reExam >= 50 :
            print("C")
        else :
            print("D")
    midExam, finalExam, reExam = list(map(int, input().split()))
    addedResult = midExam + finalExam

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

class Main{

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String word = br.readLine();

		str += str;

		if(str.contains(word)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}

	}
}

Measured memory_bytes: 24300
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int N,i,j=-1,Y,cnt=0;
    map<int,int>m;
  cin>>N;
           
      for(i=0;i<N;i++){cin>>m[i];}
            for(i=0;i<N;i++){
          if(m[i]==1){j=i;break;}
      }
    int x=m[j];
    if(j!=-1){cnt=1;
    for(i=j+1;i<N;i++){
       if(m[i]-m[j]==x){cnt++;x++;}
    }
        }
    if(j==-1){cout<<"-1\n";}
    else{cout<<N-cnt<<endl;}
    
    

     
 
    
    
    

    }

Measured memory_bytes: 9600