akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

struct Node {
  int parent;
  int r_sibling;
  int l_child;
  int depth;
};

Node T[100000];
const int NIL = -1;

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

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    T[i].parent = T[i].r_sibling = T[i].l_child = NIL;
  }

  for (int i = 0; i < n; i++) {
    int id, degree;
    cin >> id >> degree;
    for (int j = 0; j < degree; j++) {
      if (j == 0) {
        cin >> T[id].l_child;
        id = T[id].l_child;
      } else {
        cin >> T[id].r_sibling;
        id = T[id].r_sibling;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (T[i].l_child == NIL) continue;
    int cid = T[i].l_child;
    T[cid].parent = i;
    while (1) {
      if (T[cid].r_sibling == NIL) break;
      T[T[cid].r_sibling].parent = T[cid].parent;
      cid = T[cid].r_sibling;
    }
  }

  for (int i = 0; i < n; i++) {
    int d = 0;
    int pn = T[i].parent;
    while(1) {
      if (pn == NIL) {
        T[i].depth = d;
        break;
      }
      d++;
      pn = T[pn].parent;
    }
  }

  for (int i = 0; i < n; i++) {
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", ";
    cout << "depth = " << T[i].depth << ", ";
    //cout << "l = " << T[i].l_child << ", ";
    //cout << "r = " << T[i].r_sibling << ", ";

    if (T[i].parent == NIL) {
      cout << "root";
    } else if (T[i].l_child == NIL) {
      cout << "leaf";
    } else {
      cout << "internal node";
    }
    cout << ", ";

    cout << "[";
    int cn = T[i].l_child;
    while(1) {
      if (cn == NIL) break;
      if (cn != T[i].l_child) cout << ", ";
      cout << cn;
      cn = T[cn].r_sibling;
    }
    cout << "]";
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 4760
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Dice dice = new Dice(sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt(),sc.nextInt());
        int a = sc.nextInt();
        for(int i = 0; i < a; i++) {
            int T = sc.nextInt();
            int S = sc.nextInt();
            Dice copy = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
              
            int ans = solv(T,S,copy,0); 
            System.out.println(ans);
        }
    }
    
    public static int solv(int a, int b, Dice dice,int count) {
        if(dice.Top == a && dice.S == b) return dice.E;
        if(count == 4) return -1;
        int ans = -1;
        Dice tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnN();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnS();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnE();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
        tmp = new Dice(dice.Top,dice.S,dice.E,dice.W,dice.N,dice.Bottom);
        tmp.TurnW();
        ans = Math.max(solv(a,b,tmp,count+1),ans);
          
        return ans;
    }
      
      
      
}
  
class Dice {
    int Top; 
    int Bottom;
    int N;
    int S;
    int W;
    int E;
    Dice(int a, int b, int c, int d, int e, int f) {
        Top = a;
        S = b;
        E = c;
        W = d;
        N = e;
        Bottom = f;
    }
    
    public void TurnN() {
        int tmp = Top;
        Top = S;
        S = Bottom;
        Bottom = N;
        N = tmp;
    }
    
    public void TurnW() {
        int tmp = Top;
        Top = E;
        E = Bottom;
        Bottom = W;
        W = tmp;
    }
    
    public void TurnE() {
        int tmp = Top;
        Top = W;
        W = Bottom;
        Bottom = E;
        E = tmp;
    }
    
    public void TurnS() {
        int tmp = Top;
        Top = N;
        N = Bottom;
        Bottom = S;
        S = tmp;
    }   
}



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

public class Main {
	private int[] mode = new int[100];

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		Arrays.fill(mode, 0);
		while (scan.hasNext()) {
			int a = scan.nextInt() - 1;
			mode[a]++;
		}
		for (int i = 0; i < 100; i++) {
			boolean flag = false;
			int max = mode[i];
			for (int j = 0; j < 100; j++) {
				if(max < mode[j]) flag = true;
			}
			if (!flag) System.out.println(i+1);
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

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

int main() {
  long long w,h,x,y;
  cin>>w>>h>>x>>y;
  if(w%2==0&&h%2==0&&w==2*x&&h==y*2){
    double kotae=w*h/2;
    cout<<fixed<<setprecision(12)<<kotae<<" "<<1<<endl;
  }else {
    double kotae=(double)w*(double)h/(double)2;
    cout<<fixed<<setprecision(12)<<kotae<<" "<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[] c = new int[1000];
		int[] t2 = new int[1000];
		int n = sc.nextInt();
		int t1 = sc.nextInt();
		int count = 1001;
		int answer = 0;
		int i;
		for(i = 0;i < n; i++){
			c[i] = sc.nextInt();
			t2[i] = sc.nextInt();


			if((t2[i] <= t1) && (c[i] < count)){
				answer  = i;
				count = c[i];
			}

		}
		if(count == 1001){
			System.out.println("TLE");
		}else{
			System.out.println(count);
		}
		
	}
}


Measured memory_bytes: 22100
#include<cstdio>
using namespace std;
int h, w, a[500][500], A[500][500];
int main() {
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &A[i][j]);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i][j] = A[i][j];
  int counter = 0;
  for (int i = 0; i < h; i++) {
    bool flag = false;
    for (int j = 0; j < w - 1; j++) {
      if (!flag && a[i][j] % 2 == 1) flag = true;
      else if (flag && a[i][j] % 2 == 0) flag = false;
      if (flag) {
        counter++;
        a[i][j]--; a[i][j+1]++;
      }
    }
  }
  bool flag = false;
  for (int i = 0; i < h - 1; i++) {
    if (!flag && a[i][w-1] % 2 == 1) flag = true;
    else if (flag && a[i][w-1] % 2 == 0) flag = false;
    if (flag) {
      counter++;
      a[i][w-1]--; a[i+1][w-1]++;
    }
  }
  printf("%d\n", counter);
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) a[i][j] = A[i][j];
  for (int i = 0; i < h; i++) {
    flag = false;
    for (int j = 0; j < w - 1; j++) {
      if (!flag && a[i][j] % 2 == 1) flag = true;
      else if (flag && a[i][j] % 2 == 0) flag = false;
      if (flag) {
        printf("%d %d %d %d\n", i+1, j+1, i+1, j+2);
        a[i][j]--; a[i][j+1]++;
      }
    }
  }
  flag = false;
  for (int i = 0; i < h - 1; i++) {
    if (!flag && a[i][w-1] % 2 == 1) flag = true;
    else if (flag && a[i][w-1] % 2 == 0) flag = false;
    if (flag) {
      printf("%d %d %d %d\n", i+1, w, i+2, w);
      a[i][w-1]--; a[i+1][w-1]++;
    }
  }
}

Measured memory_bytes: 3968
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, M;
    pii BA[100000];
    cin >> N >> M;
    REP(i, N) {
        int A, B;
        cin >> A >> B;
        BA[i] = {B, A};
    }
    sort(BA, BA + N, [](const pii& a, const pii& b) { return a.second < b.second; });

    int BA_i = 0;
    ll ans = 0;
    priority_queue<pii> que;
    FOR(i, 1, M + 1) {
        while (BA_i < N && BA[BA_i].second <= i) {
            que.push(BA[BA_i++]);
        }
        if (que.empty()) continue;

        pii t = que.top(); que.pop();
        ans += t.first;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <vector>

const int S = 100001;
bool f[S];

int readInt()
{
    int v;
    std::cin >> v;
    return v;
}

int main() {
    f[1] = true;
    for (int i = 2; i < S; i++) {
        if (!f[i])
            for (int j = i + i; j < S; j += i)
                f[j] = true;
    }

    // 2017 like
    std::vector<bool> c(S);
    for (int i = 1; i < S; i += 2) {
        if (!f[i] && !f[(i + 1) / 2])
            c[i] = true;//c[i]++;
    }

    std::vector<int> d(S);
    int wd = 0;
    for (int i = 1; i < S; i++) {
        int temp = c[i]? wd + 1: wd;
        d[i] = temp;
        wd = temp;
    }

    int N = readInt();

    while (N--) {
        const int L = readInt(); const int R = readInt();
        printf("%d\n", d[R] - d[L-1]);
    }

    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;++i) cin>>A[i];
  for(int i=1;i<N;++i) A[i] += A[i-1];
  int index1, index2;
  int index11, index22;
  ll P, Q, R, S;
  ll ans = big;
  ll maxnum, minnum;
  for(int i=0;i<N;++i) {
    index1 = upper_bound(A.begin(), A.begin()+i, A[i]/2) - A.begin();
    index2 = upper_bound(A.begin()+i+1, A.end(), A[i]+(A[N-1]-A[i])/2) - A.begin();
    for(int j=-1;j<=1;++j) {
      for(int k=-1;k<=1;++k) {
        index11 = index1 + j;
        index22 = index2 + k;
        if(0<=index11 && index11<i && i<index22 && index22<N-1) {
          P = A[index11];
          Q = A[i] - A[index11];
          R = A[index22] - A[i];
          S = A[N-1] - A[index22];
          maxnum = max(P, max(Q, max(R, S)));
          minnum = min(P, min(Q, min(R, S)));
          ans = min(ans, maxnum-minnum);
        }
      }
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    char c[4];
    for(int i=0;i<4;i++){
        cin>>c[i];
    }
    if(c[0]==c[1]&&c[1]==c[2]){cout<<"Yes";}
    else if(c[2]==c[1]&&c[3]==c[2]){cout<<"Yes";}
    else{cout<<"No";}
}

Measured memory_bytes: 256
def main():
    L, R = map(int, input().split())
    d = dict()
    for i in range(L, min(R+1, L+2019*2)):
        v = i % 2019
        if v not in d: d[v] = 1
        else: d[v] += 1

    min_r = 2018
    for i in d:
        if i in d and d[i] > 1:
            min_r = min(min_r, (i*i) % 2019)

    for i in d:
        for j in d:
            if i < j: min_r = min(min_r, (i*j) % 2019)

    return min_r



if __name__ == '__main__':
    print(main())

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい

#define ALL(x) x.begin(),x.end()
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<int, vector<int>, greater<int> > gpq; //逆順priority_queue
typedef priority_queue<int> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const double PI=3.1415926535;

int main(){    
    string S;
    cin>>S;
    ll ans=0;
    //reverse(ALL(S));
    int N=S.size();
    int cur_val;
    int mod2019_10=1;
    vll modcount(2019,0);
    for(int i=N-1;i>=0;i--){
        if(i==N-1){
            cur_val=S[N-1]-'0';
        }else{
            cur_val=cur_val+(S[i]-'0')*mod2019_10;
        }
        mod2019_10=(mod2019_10*10)%2019;
        cur_val%=2019;
        modcount[cur_val]++;
        //cout<<cur_val<<endl;
    }
    ans+=(modcount[0]+1)*modcount[0]/2;
    for(int i=1;i<2019;i++){
        if(modcount[i]>=2){
            ans+=modcount[i]*(modcount[i]-1)/2;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
   ll t,n,temp,x=0;
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    if(a<k)
    {
        x+=a;
        k-=a;
        if(b<k)
        {
            k-=b;
                    x-=k;
        }

    }
    else
    x+=k;
    cout<<x<<endl;


    return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
int main(void){
    int i,len;
    char str[1200];
    fgets(str,sizeof str,stdin);
    len=strlen(str);   
    for(i=0;i<len;i++){
        if( isupper(str[i]) ){ 
            str[i]=tolower(str[i]);
        }
        else{
            str[i]=toupper(str[i]);
        }
    }
     
    printf("%s",str);
     
     
     
    return 0;
}



Measured memory_bytes: 2044
#include <stdio.h>

int main(void)
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a==c&&b!=c&&a!=b) {
        printf("Yes");
    }
    else if(a==b&&b!=c&&a!=c) {
        printf("Yes");
    }
    else if(b==c&&a!=b&&a!=c) {
        printf("Yes");
    }
    else if(a!=b&&b!=c&&c!=a) { 
        printf("No");
    }
    else if(a==b&&b==c&&c==a) {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1696
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> heightList = new ArrayList<>();

        for (int i = 0; i < n; i++){
            int value = sc.nextInt();
            heightList.add(value);
        }

        int highest = 0;
        int count = 0;

        for (int height : heightList){
            if (height >= highest){
                count += 1;
                highest = height;
            }
        }

        System.out.println(count);

    }
}

Measured memory_bytes: 23764
double M[12][4096],r,t;D[12],n;
double dfs(p,f){if(M[p][f]<0){
int i=0;
for(M[p][f]=0;i<n;i++)if(!(f&1<<i)&&(t=dfs(i,f|1<<i)+D[p]+D[i]-2*sqrt(D[p]*D[i]),M[p][f]<t))M[p][f]=t;
}return M[p][f];}
main(l,i,j,d){for(;~scanf("%d",&l);puts(d-r>l?"NA":"OK")){
for(d=n=0;getchar()-10;d+=D[n++]*2)scanf("%d",D+n);
for(i=0;i<n;i++)for(j=0;j<1<<n;j++)M[i][j]=-1;
for(r=i=0;i<n;i++)t=dfs(i++,1<<i),r=r>t?r:t;
}exit(0);}

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


int main() {
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t ans = N-1LL;
  if ((B - A)%2LL == 0){
    ans = (B - A)/2LL;
  }
  if (ans > B-1LL){
    ans = B-1LL;
  }
  if (ans > N-A){
    ans = N-A;
  }
  if (ans > A + (B-A-1LL)/2LL){
    ans = A + (B-A-1LL)/2LL;
  }
  if (ans > N- B+1LL+(B-A-1LL)/2LL){
    ans = N- B+1LL+(B-A-1LL)/2LL;
  }
  
  cout << ans << endl;
}


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

int main(){
    int A, B, K;
    cin >> A >> B;
    cin >> K;
    int n = 0;
    int i = 1;
for(size_t i = 100; i != 0; i--)
{
    if(A % i == 0)
    {
        if(B % i == 0){
            n++;
            if(n == K){
                cout << i << endl;
                return 0;
            }
        }
    }
}
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        char egara[] = new char[N];
    	char egara1[] = new char[N];
    	char egara2[] = new char[N];
        int suuji[] = new int[N];
    	int suuji1[] = new int[N];
    	int suuji2[] = new int[N];
        for(int i = 0; i < N; i++){
            String str = sc.next();
            egara[i] = str.charAt(0);
        	egara1[i] = egara[i];
        	egara2[i] = egara[i];
        	suuji[i] = str.charAt(1)-'1'+1;
        	suuji1[i] = suuji[i];
        	suuji2[i] = suuji[i];
        }
    	
    	for(int i = 0; i < N; i++){
    		bubble(i, suuji1, egara1);
    	}
    	
    	for(int i = 0; i < N; i++){
    		Selection(N, i, suuji, egara);
    	}
    	
    	for(int i = 0; i < N; i++){
    		System.out.print(egara1[i]);
    		System.out.print(suuji1[i]);
    		if(i == N-1){
    			System.out.println("");
    		}else{
    			System.out.print(" ");
    		}
    	}
    	check(N,suuji1, suuji2, egara1, egara2);
    	
    	for(int i = 0; i < N; i++){
    		System.out.print(egara[i]);
    		System.out.print(suuji[i]);
    		if(i == N-1){
    			System.out.println("");
    		}else{
    			System.out.print(" ");
    		}
    	}
    	check(N, suuji, suuji2, egara, egara2);
    }
	
	private static void bubble(int i, int suuji1[], char egara1[]){
		for(int j = i; j > 0; j--){
    		if(suuji1[j] < suuji1[j-1]){
    			int j0;
    			char j1;
    			j0 = suuji1[j];
    			suuji1[j] = suuji1[j-1];
    			suuji1[j-1] = j0;
    			j1 = egara1[j];
    			egara1[j] = egara1[j-1];
    			egara1[j-1] = j1;
    		}
    	}
	}
	
	private static void Selection(int N, int i, int suuji[], char egara[]){
		int minj = i;
		for(int j = i; j < N; j++){
			if(suuji[j] < suuji[minj]){
				minj = j;
			}
			
		}
		int j0;
		char j1;
		j0 = suuji[i];
    	suuji[i] = suuji[minj];
    	suuji[minj] = j0;
    	j1 = egara[i];
    	egara[i] = egara[minj];
    	egara[minj] = j1;
	}
	
	private static void check(int N,int suuji1[], int suuji2[], char egara1[], char egara2[]){
		String hantei = "Stable";
		for(int j = 0; j < N; j++){
			for(int k = j+1; k < N; k++){
				for(int j1 = 0; j1 < N; j1++){
					for(int k1 = j1+1; k1 < N; k1++){
				        if(suuji2[j] == suuji2[k] && egara2[j] == egara1[k1] && suuji2[j] == suuji1[k1] && egara2[k] == egara1[j1] && suuji2[k] == suuji1[j1]){
				        	hantei = "Not stable";
				        }
					}
				}
			}
		}
		System.out.println(hantei);
	}
}


Measured memory_bytes: 26952
using System;

namespace ABC080_B
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var c = 0;
            var t = n;
            for(var i=0;i<9;i++)
            {
                c += t % 10;
                t /= 10;
            }
            if (n % c == 0)
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;

int main() {
    int n;
    ll k;
    cin>>n>>k;
    ll maxN=100000+1, sum=0;
    vector<ll> num(maxN,0);
    rep(i,n){
        int a,b;
        cin>>a>>b;
        num[a]+=b;
    }
    for(ll i=0;i<maxN;i++){
        sum+=num[i];
        if(k<=sum){
            cout << i << endl;
            return 0;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1024
# coding: utf-8
A, B = map(int, input().split())
S = input()
for i in range(len(S)):
    if i == A:
        if S[i] != '-':
            print('No')
            exit()
    else:
        if not ('0' <= S[i] <= '9'):
            print('No')
            exit()
else:
    print('Yes')

Measured memory_bytes: 3060
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def yakusu(n):
    ans = []
    for i in range(1, int(n**(1/2)//1) + 1):
        if n % i == 0:
            ans.append(i)
            ans.append(int(n / i))
    return list(set(ans))


def factorize(n):
    factorial_list = []

    b = 2
    while b * b <= n:
        while n % b == 0:
            n //= b
            factorial_list.append(b)
        b += 1

    if n > 1:
        factorial_list.append(n)
    return factorial_list


MOD = 10 ** 9 + 7


def main():
    N = II()

    fractals = [0] * (N + 1)

    for i in range(1, N+1):
        tmp = factorize(i)
        for fact in tmp:
            fractals[fact] += 1

    ans = 1
    for i in fractals:
        ans *= i + 1
        ans %= MOD

    print(ans)


main()


Measured memory_bytes: 74284
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = 1e18;
constexpr double PI = 3.14159265358979;

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

  string s;
  cin >> s;
  string t = "";
  for(size_t i = 0; i < s.size(); i++){
    if(s[i] == 'B' and i < s.size()-1){
      if(s[i+1] == 'C'){
        t += 'D';
        i++;
      }else{
        t += s[i];
      }
    }else{
      t += s[i];
    }
  }
  long long ans = 0, cnt = 0;
  for(int i = 0; i < (int)t.size(); i++){
    if(t[i] == 'A'){
      cnt++;
    }else if(t[i] == 'D'){
      ans += cnt;
    }else{
      cnt = 0;
    }
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, N) for (int i = 0; i < (int)N; i++)
const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N, A, B; cin >> N >> A >> B;
  int rmax = min(A, B);
  int rmin = max(0,A+B-N);
  cout << rmax << " " << rmin << endl;
  return 0;
}

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++ i)
#define ALL(r) r.begin(), r.end()
#define DUP(x, y) (((x) + (y) - 1) / (y))
#define YES puts("YES")
#define NO puts("NO")
#define Yes puts("Yes")
#define No puts("No")

using ll = std::int64_t;
using vint = std::vector<int>;
using vll = std::vector<ll>;
using pint = std::pair<int, int>;

constexpr std::int32_t INF = 1001001001;

ll n;

bool f(const string& s) {
    bool flag[3] = { false, false, false };
    rep(i, s.length()) {
        if (s[i] == '3') flag[0] = true;
        if (s[i] == '5') flag[1] = true;
        if (s[i] == '7') flag[2] = true;
    }
    if (flag[0] && flag[1] && flag[2])return true;
    else return false;
}

int dfs(const string& s) {
    if (s != "" && stoll(s) > n)return 0;
    int ret = f(s) ? 1 : 0;
    for (string x : { "3", "5", "7" }) {
        ret += dfs(s + x);
    }
    return ret;
}

void Main() {
    cin >> n;

    int ans = dfs("");
    cout << ans << endl;
}

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



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



int main()
{   
    int a,b;
    cin >> a >> b;
    double fa, fb;
    fa = a;
    fb = b;
    int d = a/b;
    int r = a%b;
    int f = fa/fb;
    // cout << d << " " << r << " "  <<  f << endl;
    printf("%d %d %.5f\n", (a/b),(a%b),(fa/fb));
    return 0;
    
    
    
    


}



Measured memory_bytes: 3220
/*
Author : samjia2000
Source : code festival 2016 qual A E.LRU Puzzle
*/
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 100005;

int n,m,q;
int a[N];
bool bz[N];
int w[N],lst[N];
int Rig[N];
int a1[N],a2[N],k1,k2;
int be[N];
int num[N];

int main(){
	n=get();m=get();
	q=get();
	fo(i,1,q)a[i]=get();
	fo(i,1,q){
		lst[i]=w[a[i]];
		w[a[i]]=i;
	}
	fo(i,1,n)Rig[i]=q+1;
	fd(i,q,1)
	if (!bz[a[i]]){
		int x=1,w=i;
		for(;x<=n&&w;w=lst[w]){
			if(w<Rig[x]){
				Rig[x]=w;
				x++;
			}
		}
		if (x>n)bz[a[i]]=1;
		else{
			fo(x,1,m)if (!bz[x])a1[++k1]=x;
			fd(x,i,1)if (!bz[a[x]])bz[a2[++k2]=a[x]]=1;
			bool pd=1;
			fo(x,1,k2)pd&=(a1[x]==a2[x]);
			if (!pd)return printf("No\n"),0;
			return printf("Yes\n"),0;
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2688
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.*;

public class Main {
	
	static final private String DATE_FORMAT = "yyyy/MM/dd";

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		LocalDate date = string2LocalDate(s);
		if(date.isAfter(LocalDate.of(2019, 4, 30))) {
			System.out.println("TBD");
		}else {
			System.out.println("Heisei");
		}
		
	}
	
	public static LocalDate string2LocalDate(final String date) {
		  return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT));
		}
}

Measured memory_bytes: 28756
#include <stdio.h>
#include <limits.h>
#define MAX 101
void prim(int,int);
int a[MAX][MAX];
  int color[MAX];
  int d[MAX];
  int pi[MAX];
int main(){
  int i,j,n,tmp,sum=0;

  for(i =1 ;i<=MAX;i++){
    color[i]=0;
    d[i]=0;
    pi[i]=0;
  }
  scanf("%d",&n);
  
  for(i = 1 ; i <= n;i++){
    for(j = 1;j<=n;j++){
    scanf("%d" ,&a[i][j]);
    if(a[i][j] ==-1){
      a[i][j] = INT_MAX;
    }
    }
  }

  prim(n,1);
  for(i = 1;i<=n;i++){
    sum+=d[i];
  }
  printf("%d\n",sum);
  return 0;
}
void prim(int w,int r){
  int u,mincost;
  int i,j;
  for(i = 1;i<=w;i++){
    d[i] = INT_MAX;
    pi[i] =-1;
    color[i] = 0;
  }
  d[r] = 0;
  while(1){
    mincost = INT_MAX;
    for(i = 1;i<=w;i++){
      if(color[i]!=1 && d[i]<mincost){
	mincost = d[i];
	u = i;
      }
    }
      if(mincost == INT_MAX){
	  break;
      }
      color[u]=1;

	for(j = 1 ;j<=w;j++){
	  if(color[j] !=1 && a[u][j]<d[j]){
	    pi[j] = u;
	    d[j] = a[u][j];
	  }
	}

      }
  }



Measured memory_bytes: 2112
from itertools import accumulate
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
cum = list(accumulate(A))
ans = float('inf')
for i in range(1, N-2):
    lb, ub = 0, i + 1
    while ub - lb > 2:
        m1 = (lb * 2 + ub) // 3
        m2 = (lb + ub * 2) // 3
        v1 = abs(2*cum[m1] - cum[i])
        v2 = abs(2*cum[m2] - cum[i])
        if v1 >= v2:
            lb = m1
        else:
            ub = m2
    P = min(cum[lb], cum[lb+1], key=lambda x: abs(2*x - cum[i]))
    Q = cum[i] - P

    lb, ub = i+1, N
    while ub - lb > 2:
        m1 = (lb * 2 + ub) // 3
        m2 = (lb + ub * 2) // 3
        v1 = abs(2*(cum[m1]-cum[i]) - (cum[-1]-cum[i]))
        v2 = abs(2*(cum[m2]-cum[i]) - (cum[-1]-cum[i]))
        if v1 >= v2:
            lb = m1
        else:
            ub = m2
    R = min(cum[lb] - cum[i], cum[lb+1] - cum[i], key=lambda x: abs(2*x - (cum[-1] - cum[i])))
    S = cum[-1] - cum[i] - R

    ans = min(ans, max(P, Q, R, S) - min(P, Q, R, S))
print(ans)

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

int main() {
  int N; cin >> N;
  int sum = 0;
  vector<int> V(N);
  vector<int> C(N);
  for( int i = 0; i < N; i++ )
    cin >> V.at(i);
  for( int i = 0; i < N; i++ )
    cin >> C.at(i);
  for( int i = 0; i < N; i++ ) {
    if( V.at(i) > C.at(i) )
      sum = sum + V.at(i) - C.at(i);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
nums = list(map(int, input().split()))
a = nums[0]
b = nums[1]
c = nums[2]

count = 0
for x in range(a, b + 1):
    r = c % x
    # print("%d ?? %d ... %d"%(c, x, r))
    if r == 0:
        count += 1

print(str(count))

Measured memory_bytes: 7660
N = gets.chop.to_i
S = []
N.times { S << gets.chomp }

aaa = {}
taiou = {}
('a'..'z').each_with_index do |str, ind|
  taiou[str] = 10**ind
end
base_num = taiou['z']*10

S.each do |s|
  hoge = base_num
  s.chars do |moji|
    hoge += taiou[moji]
  end
  if aaa[hoge]
    aaa[hoge] += 1
  else
    aaa[hoge] = 1
  end
end

count = 0
aaa.values.each do |num|
  count += num * (num -1) / 2
end

print count

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

int main(){
    long long int n;
    cin >> n;
    for(long long int i=1;i<=3500;++i){
        for(long long int j=i;j<=3500;++j){
            if(4*i*j - n*i - n*j == 0)continue;
            long long int h = (n*i*j)/(4*i*j - n*i - n*j);
            if(h > 0 && 4*i*j*h == n*(i*j+j*h+h*i)){
                cout << i << " " << j << " " << h << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    V<ll> a(n);
    map<ll,ll> mp;
    set<ll> s,t;
    rep(i,n){
        cin>>a[i];
        s.insert(a[i]);
        mp[a[i]]++;
    }
    ll ans=0;
    while(!s.empty()){
        ll x=*rbegin(s);
        s.erase(x);
        if(mp[x]>=4&&t.empty()){
            ans=x*x;
            break;
        }else if(mp[x]>=2){
            t.insert(x);
            if(t.size()>=2){
                ll y=*rbegin(t);
                t.erase(y);
                ans=y*(*rbegin(t));
                break;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main()
{
    int K,N;
    cin >> K >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    vector<int> space(N);
    for (int i=0;i<N-1;i++) {
        space.at(i) = A.at(i+1)-A.at(i);
    }
    space.at(N-1) = K - A.at(N-1) + A.at(0);

    sort(space.begin(),space.end());
    cout << K - space.back() << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<cstdlib>
//#include<vector>
//#include<algorithm>

using namespace std;

struct point {
	int x;
	int y;
	//point() {x=0;y=0;}
	//point(int nx, int ny) {x=nx;y=ny;}
};

point cele[200];
point sky[1000];

/*
boolean operator<( const point& a, const point& b) {
	if ( a.x == b.x )
		return a.y < b.y;
	return a.x < b.x;
}

boolean operator>( const point& a, const point& b) {
	if ( a.x == b.x )
		return a.y > b.y;
	return a.x > b.x;
}
*/

int compare ( const void * a, const void * b ) {
	const point c = *((point*)a);
	const point d = *((point*)b);

	if ( c.x == d.x )
		return c.y - d.y;
	return c.x - d.x;
}

int main () {

	while ( true ) {
		int n,m;
		cin >> m;

		if ( m == 0 )
			break;

		for ( int i=0; i<m; i++ ) {
			cin >> cele[i].x >> cele[i].y;
		}

		cin >> n;
		for ( int i=0; i<n; i++ ) {
			cin >> sky[i].x >> sky[i].y;
		}

		qsort(cele,m,sizeof(point), compare);
		qsort(sky,n,sizeof(point), compare);

		/*
		for ( int i=0; i<n; i++ ) {
			for ( int j=0; j<
		*/
		/*
		cout << "NM: " << n<< " " << m << endl;
		for ( int i=0; i<m; i++ )
			cout << cele[i].x << " " << cele[i].y << endl;
		for ( int i=0; i<n; i++)
			cout << sky[i].x << " " << sky[i].y << endl;
		*/	

		int index = 0;
		int count = 0;
		int dx, dy;
		bool pass = false;;
		for ( int i=0; i<n; i++ ) {
			dx = sky[i].x-cele[0].x;
			dy = sky[i].y-cele[0].y;

			index = 1;

			bool passall = false;
			int count = 1;
			for ( int j = i+1; j < n; j++ ) {
				
				if ( sky[j].x - dx == cele[index].x 
					 && sky[j].y - dy == cele[index].y) {
					count ++;
					index ++;
				}
				if ( count == m ) {
					passall = true;
					break;
				}
			}
			if ( passall ) 
				break;
		}
		cout << dx << " " <<  dy << endl;
					
	}
}

Measured memory_bytes: 0
while True:
    m, f, r = map(int, input().split())
    if m == -1 and f == -1 and r == -1:
        break
    if m == -1 or f == -1:
        g = "F"
    else:
        total_m_f = m + f
        if total_m_f >= 80:
            g = "A"
        elif total_m_f >= 65:
            g = "B"
        elif total_m_f >= 50:
            g = "C"
        elif total_m_f >= 30:
            if r >= 50:
                g = "C"
            else:
                g = "D"
        else:
            g = "F"
    print(g)



Measured memory_bytes: 5592
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x,y;
    cin >> n >> m >> x >> y;
    vector<int> xs(n);
    vector<int> ys(m);
    for(int i = 0; i < n; i++){
        cin >> xs[i];
    }
    for(int i = 0; i < m; i++){
        cin >> ys[i];
    }
    sort(xs.begin(),xs.end());
    sort(ys.begin(),ys.end());
    int z = x;
    bool peace = false;
    for(; z < y + 1;z++){
        if(z > xs[n- 1] && z <= ys[0] && x < z && z <= y)
        peace = true;
    }
    if(peace) 
    cout << "No War" << endl;
    else
    {
        cout << "War" << endl;
    }
    
}

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

typedef long long ll;
#define pb push_back
#define ii pair<int ,int >
#define vi vector<int >
#define vii vector < pair<int ,int > >
#define IO ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define IOfiles freopen("input.txt","r+",stdin) ; freopen("output.txt","w+",stdout)
#define PI 3.14159265
const double eps = 1e-9;

int main()
{
	IO;
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
		cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 100000 + 10;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

struct people {
    int a, b, c;
    void input() {
        cin >> a >> b >> c;
    }
}p[maxn];

bool cmp(const people& a, const people& b) {
    return a.a - a.b < b.a - b.b;
}

int n, x, y, z;
LL Ans[maxn], _Ans[maxn];

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif
    
    cin >> x >> y >> z;

    n = x + y + z;
    for(int i = 0; i < n; ++i) { p[i].input(); }

    LL ans = 0;
    for(int i = 0; i < n; ++i) 
        p[i].a -= p[i].c, p[i].b -= p[i].c, ans += p[i].c;

    sort(p, p + n, cmp);

    priority_queue<int, vector<int>, greater<int> > q;

    for(int i = 0; i < y; ++i) {
        q.push(p[i].b);
        Ans[y-1] += p[i].b;
    }

    for(int i = y; i < n; ++i) {
        q.push(p[i].b); 
        Ans[i] = Ans[i-1] + p[i].b - q.top(); 
        q.pop();
    }

    while(!q.empty()) q.pop();

    for(int i = n-1; i >= n-x; --i) {
        q.push(p[i].a);
        _Ans[n-x] += p[i].a;
    }

    for(int i = n-x-1; i >= 0; --i) {
        q.push(p[i].a);
        _Ans[i] = _Ans[i+1] + p[i].a - q.top();
        q.pop();
    }

    LL res = -LLONG_MAX;
    for(int i = y-1; i < n-x; ++i) chkmax(res, Ans[i] + _Ans[i+1]);
    printf("%lld\n", res + ans);

    return 0;
}


Measured memory_bytes: 2944
import java.util.Scanner;


public class Main{

	static Scanner sc = new Scanner(System.in);
	
	static double xp, yp;
	static double point_x[] = new double[3], point_y[] = new double[3];
	static boolean result[] = new boolean[3];
	
	
	public static void main(String[] args) {
		
		while(read()){
			solve();
		}

	}
	
	public static boolean read(){
		if(!sc.hasNext()) return false;
	
		for(int i=0; i < point_x.length; i++){
			point_x[i] = sc.nextDouble();
			point_y[i] = sc.nextDouble();
		}
		
		xp = sc.nextDouble();
		yp = sc.nextDouble();
		
		return true;
	}
	
	public static void solve(){
		double io;
		
		for(int i=0; i < 3; i++){
			io = (point_x[i%3] - point_x[(i+1)%3]) * (point_y[i%3] - yp) - (point_y[i%3] - point_y[(i+1)%3]) * (point_x[i%3] - xp);
			if(io > 0){
				result[i] = true;
			}
			else if(io < 0){
				result[i] = false;
			}
		}
		
		if((result[0] && result[1] && result[2])||(!result[0] && !result[1] && !result[2])){
			System.out.println("YES");
		}
		else{
			System.out.println("NO");
		}
	}

}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    if (n % 2 == 0)
    {
        cout << n << endl;
    } else {
        cout << 2*n << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


n = int(input())
A = list(map(int, input().split()))

s = sum(A)

CNT = [0] * (10**5 + 1)
for a in A:
    CNT[a] += 1

q = int(input())
for _ in range(q):
    b, c = map(int, input().split())
    s += (c - b) * CNT[b]
    CNT[c] += CNT[b]; CNT[b] = 0
    print(s)


Measured memory_bytes: 20380
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N = int(input())
march = ['M','A','R','C','H']
nums = [0]*5

for _ in range(N):
	s = input()
	if s[0] in march:
		nums[march.index(s[0])] +=1

def next_com(bit):
	x = bit & -bit
	y = bit + x
	return (((bit & ~y) // x) >> 1) | y

n,k = 5,3
bit = (1<<k)-1
ans = 0
while bit < (1<<n):
	tmp = 1
	for i in range(5):
		if (bit>>i) & 1:
			tmp *= nums[i]
	ans += tmp
	bit = next_com(bit)

print(ans)


Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string s,t;
int S,T;

bool check(int a)
{
    bool ok = true;
    int idx = 0;
    for(int i=a; i<S; i+=2)
    {
        bool update = false;
        while(idx<T)
        {
            if(t[idx]==s[i])
            {
                ++idx;
                update = true;
                break;
            }
            ++idx;
        }
        if(!update)
        {
            ok=false;
            break;
        }
    }
    return ok;
}

string solve()
{
    cin >>s >>t;
    S = s.size();
    T = t.size();
    rep(i,2)if(check(i)) return "Yes";
    return "No";
}

int main()
{
    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 3180
import java.util.*;
import java.util.Collections;
import java.util.ArrayList;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        int N = sc.nextInt();
        int M = sc.nextInt();
        if(N>=M){
            System.out.println(0);
            return;
        }
        int[] X = new int[M];
        ArrayList<Integer> list = new ArrayList<Integer>();

        for(int i=0; i<M; i++){
            X[i] = sc.nextInt();
            list.add(X[i]);
        }

        Collections.sort(list);

        int[] L = new int[M - 1];
        ArrayList<Integer> al = new ArrayList<Integer>();

        for(int i=0; i<M-1; i++){
            L[i] = list.get(i + 1) - list.get(i);
            al.add(L[i]);
        }

        Collections.sort(al);
        int sum = 0;
        for(int i=M-2; i>M-2-N+1; i--){
            sum += al.get(i);
        }
        System.out.println(list.get(M - 1) - list.get(0) - sum);
    }
}

Measured memory_bytes: 64476
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int judge = 0;
        
        if(N<10){
            if(N == 3){
                judge = 3;
            }else if(N == 0 ||N == 1 ||N == 6 ||N == 8){
                judge = 2;
            }else{
                judge = 1;
            }
        }else{
            if(N%10 == 3){
                judge = 3;
            }else if(N%10 == 0 ||N%10 == 1 ||N%10 == 6 ||N%10 == 8){
                judge = 2;
            }else{
                judge = 1;
            }
        }
        
        if(judge == 1) System.out.println("hon");
        if(judge == 2) System.out.println("pon");
        if(judge == 3) System.out.println("bon");
    }
}

Measured memory_bytes: 35840
import java.util.Scanner;

public class Main {
    static boolean binary_search (int x, int[] data) {
        int left = 0, right = data.length;
        while (true) {
            int mid = (left + right) / 2;

            if (left > right) return false;

            if (data[mid] == x) {
                return true;
            } else if (data[mid] < x) {
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
    }

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

        int n = scanner.nextInt();

        int[] s = new int[n];
        for (int i = 0; i < n; ++i) {
            s[i] = scanner.nextInt();
        }

        int q = scanner.nextInt();

        int cnt = 0;
        for (int i = 0; i < q; ++i) {
            int t = scanner.nextInt();
            if (binary_search(t, s)) ++cnt;
        }

        System.out.println(cnt);
    }
}


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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  int D=A.size()-1;
  int E=B.size()-1;
  if(A.at(D)==B.at(0)&&B.at(E)==C.at(0)){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for _ in range(j)] for _ in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from itertools import accumulate #list(accumulate(A))

## 4/25

V, E = mi()
rel = [[] for _ in range(V)]
inv_rel = [[] for _ in range(V)]
for i in range(E):
    s, t, c = mi()
    rel[s].append((t, c))
    #inv_rel[t].append((s, c))

B = 2**V
dp = dp2(-1, V, B)

# 前向きメモ化再帰
def rec_for(state, now):
    if dp[state][now] != -1:
        return dp[state][now]
    if state == B-1:
        dp[state][now] = 0
        return 0
    res = float('inf')
    for v, c in rel[now]:
        if v==0 and state|(1<<v)!=B-1:
            continue
        if not state & (1<<v):
            res = min(res, rec_for(state|(1<<v), v)+c)
    dp[state][now] = res
    return res

# 後ろ向きメモ化再帰
def rec_back(state, now):
    if dp[state][now] != -1:
        return dp[state][now]
    if state==now==0:
        dp[state][now] = 0
        return 0
    res = float('inf')
    for pv, c in inv_rel[now]:
        if pv==0 and state!=1:
            continue
        if state & (1<<pv):
            res = min(res, rec_back(state^(1<<pv), pv)+c)
    dp[state][now] = res
    return res

ans = rec_for(0, 0)
#ans = rec_back(B-1, 0)
if ans == float('inf'):
    print(-1)
    exit()
print(ans)

'''
# DP
dp = dp2(float('inf'), V, B)
dp[0][0] = 0

for state in range(B-1):
    for now in range(V):
        if dp[state][now] != float('inf'):
            for nv, c in rel[now]:
                #if nv == 0 and state|1 != B-1:
                    #continue
                if not state & 1<<nv:
                    dp[state|(1<<nv)][nv] = min(dp[state|(1<<nv)][nv], dp[state][now]+c)

if dp[B-1][0] == float('inf'):
    print(-1)
    exit()
print(dp[B-1][0])
'''


Measured memory_bytes: 15476
import math
import sys
from collections import Counter

n = int(input())
a = list(map(int,input().split()))
ma = max(a)
pc = True

if ma == 1:
    print("pairwise coprime")
    sys.exit()
    
bb = Counter(a)
    
if len(bb) - 1 == n - bb[1]:
    pc = True
elif len(bb) != n :
    pc = False
    
cu = [0]*(ma+1)
for i in a:
    cu[i] = 1

for i in range(2,ma+1):
    aa = 0
    for j in range(i,ma+1,i):
        aa += cu[j]
    if aa > 1:
        pc = False
        break

gc = a[0]
for i in a[1:]:
    gc = math.gcd(i,gc)
    
if pc:
    print("pairwise coprime")
elif gc == 1:
    print("setwise coprime")
else:
    print("not coprime")

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

using namespace std;
using ll = long long;

int n;
vector<ll> a, csum;
vector<vector<ll>> dp;

ll sum(int l, int r){
    if(l == 0) return csum[r];
    return csum[r] - csum[l-1];
}

// ll solve(int l, int r){
//     if(l >= r) return 0;
//     ll res = LLONG_MAX;
//     for(int k = l; k < r; k++){
//         res = min(res, solve(l, k) + solve(k+1, r) + sum(l, r));
//     }
//     return res;
// }

int main(){
    cin>>n;
    a.resize(n); csum.resize(n);
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    csum[0] = a[0];
    for(int i = 1; i < n; i++){
        csum[i] = csum[i-1] + a[i];
    }
    // ll res = solve(0, n-1);
    dp.resize(n, vector<ll>(n));
    for(int l = n - 1; l >= 0; l--){
        for(int r = l + 1; r < n; r++){
            dp[l][r] = LLONG_MAX;
            for(int k = l; k < r; k++){
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k+1][r] + sum(l, r));
            }

        }
    }
    ll res = dp[0][n-1];
    cout<<res<<endl;
    return 0;
}

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

public class Main {
	public static void main(String[] args) {

		int[] hight;
		hight = new int[10];
	
		Scanner sc = new Scanner(System.in);
		
		for(int i=0; i < 10; i++)
		{
			hight[i] = sc.nextInt();
		}
		
		Arrays.sort(hight);
		
		System.out.println(hight[9]);
		System.out.println(hight[8]);
		System.out.println(hight[7]);
	}

}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int a[1000];

int f(int n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main() {
  int s;
  cin >> s;

  a[0] = s;
  int i = 1;
  while (i < 1000) {
    a[i] = f(a[i-1]);
    i++;
  }

  for (i = 0; i < 1000; i++) {
    for (int j = i + 1; j < 1000; j++) {
      if (a[i] == a[j]) {
        cout << j + 1 << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256