akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <deque>
#include <functional>
#include <iostream>
#include <iterator>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N, P;
    cin >> N >> P;

    vector<long> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];

    vector<long> dp = {1, 0};
    for (long a : A) {
        vector<long> ndp = {0, 0};

        if (a % 2 == 0) {
            ndp[0] = dp[0] * 2;
            ndp[1] = dp[1] * 2;
        } else {
            ndp[0] = dp[0] + dp[1];
            ndp[1] = dp[1] + dp[0];
        }

        dp.swap(ndp);
    }

    cout << dp[P] << '\n';

    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(unused_imports)]
use proconio::input;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::VecDeque;

fn main() {
    input! {
        L: i64,
        R: i64,
    }

    const MOD: i64 = 2019;

    // 0 * X = 0 (MOD p)
    if L == 0 {
        println!("0");
        return;
    }

    // 2019 * X = 0 (MOD p)
    if R - L >= MOD {
        println!("0");
        return;
    }

    // ここは2019 ** 2の探索でOK
    let mut ans = std::i64::MAX;
    for i in L..=R {
        for j in i + 1..=R {
            let cand = (i * j) % MOD;
            ans = min(ans, cand);
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
 
const int MX = 2005;
bool d[3][3][MX];

int main(){
	vector<string> s(3);
  	rep(i, 3) cin >> s[i];
  	sort(s.begin(), s.end());
  	int ans = MX * 3;
  
  	do{
    	rep(i, 3) rep(j, 3) rep(k, s[i].size()){
          	if(i >= j) continue;
        	bool ok = true;
          
          	for(int ni = k; ni < s[i].size(); ni++){
            	int nj = ni - k;
              	if(nj >= s[j].size()) break;
              	if(s[i][ni] == '?' || s[j][nj] == '?') continue;
              	if(s[i][ni] != s[j][nj]) ok = false;
            }
          	d[i][j][k] = ok;
        }
      
      	auto f = [&](int i, int j, int k){
        	if(k >= s[i].size()) return true;
          	return d[i][j][k];
        };
      
      	rep(x, MX)rep(y, MX){
        	if(!f(0, 1, x)) continue;
          	if(!f(1, 2, y)) continue;
          	if(!f(0, 2, x + y)) continue;
          	
          	int now = 0;
          	now = max<int>(now, s[0].size());
          	now = max<int>(now, x + s[1].size());
          	now = max<int>(now, x + y + s[2].size());
          
          	ans = min(ans, now);
        }
    } while(next_permutation(s.begin(), s.end()));
  	
  	cout << ans << endl;
}

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

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

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

const int MAX = 100;

int ans;
int W, H;
int a[MAX][MAX];
bool done[MAX][MAX];

bool inside(int x, int y) {
    return 0 <= x && x < H && 0 <= y && y < W;
}

void dfs(int x, int y, int c) {
    if (!inside(x, y) || !a[x][y] || done[x][y]) return;

    done[x][y] = true;
    c++;
    rep(k, 4) {
        dfs(x + dx[k], y + dy[k], c);
    }
    done[x][y] = false;
    ans = max(ans, c);
}

void init() {
    rep(i, MAX) {
        rep(j, MAX) {
            a[i][j] = -1;
            done[i][j] = false;
        }
    }
}

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

    while (cin >> W >> H, W) {

        init();

        rep(i, H) {
            rep(j, W) {
                cin >> a[i][j];
            }
        }

        ans = 0;
        rep(i, H) {
            rep(j, W) {
                if (a[i][j]) {
                    dfs(i, j, 0);
                }
            }
        }

        cout << ans << endl;

    }

}

Measured memory_bytes: 3076
arr = gets.chomp.split('').map(&:to_i)

(0...(1 << 3)).each do |i|
  strs = [arr[0].to_s]
  cur = arr[0]
  (0...3).each do |j|
    if 1 & (i >> j) == 1
      strs.push('+')
      cur += arr[j + 1]
    else
      strs.push('-')
      cur -= arr[j + 1]
    end
    strs.push(arr[j + 1].to_s)
  end
  if cur == 7
    puts strs.join('') + '=7'
    exit 0
  end
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;



int main(){
    ll h,w;cin>>h>>w;
    map<char,ll> m;
    rep(i,0,h){
        rep(j,0,w){
            char c;cin>>c;
            m[c]++;
        }
    }
    if(h!=1&&w!=1){
    if(h%2==0&&w%2==0){
        for(auto i:m){
            if(i.second%4!=0){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    else if(h*w%2==1){
        int cn=0,cn4=0;
        for(auto i:m){
            if(i.second%2==1)cn++;
            cn4+=i.second/4;
        }
        if(cn!=1||cn4<((h-1)/2*(w-1)/2)){
            cout<<"No"<<endl;
            return 0;
        }
    }
    else{
        int cn4=0;
        for(auto i:m){
            if(i.second%2==1){
                cout<<"No"<<endl;
                return 0;
            }
            cn4+=i.second/4;
        }
        if(h%2==1){
            if(cn4<((h-1)/2*w/2)){
                cout<<"No"<<endl;
                return 0;
            }
        }
        else{
            if(cn4<((w-1)/2*h/2)){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    }
    else{
        if(h*w%2==0){
            for(auto i:m){
                if(i.second%2==1){
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
        else{
            ll cn=0;
            for(auto i:m){
                if(i.second%2==1)cn++;
            }
            if(cn!=1){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    
    cout<<"Yes"<<endl;
}







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    char x[100], y[100],z[100];
    cin>>x>>y>>z;
    if(x[0]>='a' && x[0]<='z')
    x[0]-=32;
    if(y[0]>='a' && y[0]<='z')
    y[0]-=32;
    if(z[0]>='a' && z[0]<='z')
    z[0]-=32;
    cout<<x[0]<<y[0]<<z[0];
   	
}
    

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

int main() {
  double L;
  cin >> L;
  double h = L / 3;
  double w = (L - h) / 2;
  double c = L - h - w;
  double result = h * w * c;
  cout << setprecision(10) << result << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define S_MAX 10

int n;
int s;
int balls[S_MAX];

int solve(void){
	int max_of_b = 0;
	int max_of_c = 0;
	int i = 0;
	int flag;
	for(i = 0; i < s; i++){
		if(!i){
			max_of_b = balls[i];
			continue;
		}
		flag = 0;
		flag |= ((balls[i] > max_of_b)? 1 : 0);
		flag |= ((balls[i] > max_of_c)? 2 : 0);
		switch(flag){
		case 0:
			return puts("NO");
		case 1:
			max_of_b = balls[i];
			break;
		case 2:
			max_of_c = balls[i];
			break;
		case 3:
			if(max_of_b > max_of_c){
				max_of_b = balls[i];
			} else {
				max_of_c = balls[i];
			}
		}
	}
	return puts("YES");
}

void in(void){
	int i;
	for(i = 0; i < s; i++){
		scanf("%d", &balls[i]);
	}
	return;
}

int main(void){
	scanf("%d", &n);
	while(n--){
		s = 10;
		in();
		solve();
	}
	return 0;
}

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

int main() {
    long long n;
    long long x;
    cin >> n >> x;
    long long a[n];
    for(int i=0;i<n;i++) cin >> a[i];
    long long ans=0;
    for(int i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x&&a[i]>=x){
            ans+=a[i+1]+a[i]-x;
            a[i]=x;
            a[i+1]=0;
        }
        else if(a[i]+a[i+1]>x&&a[i]<x){
            ans+=a[i+1]+a[i]-x;
            a[i+1]=x-a[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
long long R=1,C=1,H[2000010],N[2000010];
char S[100010][20];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return strcmp(S[N[H[a]]],S[N[H[b]]])<0?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
int main(){
  int n,i,j,k,r,bb[300]={};
  long long a,b=-1,c=0,m=0;
  char s[20],sa[20],sb[20]={};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    for(j=0;s[j];j++)bb[s[j]]++;
    for(j=r=0;j<260;j++){
      for(k=0;k<bb[j];k++)S[R][r++]=j;
      bb[j]=0;
    }
    S[R][r]=0;//printf("%s\n",S[R]);
    hin(R);
  }
  for(i=0;i<n;i++){
    strcpy(sa,S[N[hout()]]);
    if(strcmp(sa,sb)==0)c++;
    else{
      m+=(c*(c-1)/2);
      c=1;
    }//printf("%lld\n",c);
    strcpy(sb,sa);
  }
  m+=(c*(c-1)/2);
  printf("%lld\n",m);
  return 0;
}


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

int main() {
  int N,K;
  cin>>N>>K;
  
  vector<int>A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  for(int i=0;i<N-K;i++){
    if(A[i]<A[i+K]){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}



Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
int main() {
   int n,k;
   int a[100003]={};
   cin>>n>>k;
   for(int i=1;i<=n;i++)
   cin>>a[i];

   long long int dp[n+2]={};
   for(int i=2;i<=k;i++)
   dp[i]=abs(a[i]-a[1]);
   for(int i=k+1;i<=n;i++)
   {
       dp[i]=INT_MAX;
       for(int j=1;j<=k;j++)
       {
           dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
       }
   }

   cout<<dp[n];

}


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

typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

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

int main(){
    int n;
    cin >> n;
    int a[n], sum = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 1e9;
    for (int i = -100; i <= 100; i++){
        int cost = 0;
        for (int j = 0; j < n; j++){
            cost += pow(a[j] - i, 2);
        }
        ans = min(ans, cost);
        // cout << ans << endl;
    }
    cout << ans << endl;
    return 0;
}

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

bool seisuu(double a) {
	int b = a;
	double c = b;
	return a == c;
}
int main() {
	double a;
	while (cin >> a, a >= 0) {
		a *= 16;
		if (seisuu(a) && a < (1 << 12)) {
			int b = a;
			for (int i = 0,c=(1<<11); i < 12; i++,c>>=1) {
				if (i == 8)cout << '.';
				if (b&c)cout << 1;
				else cout << 0;
			}
			cout << endl;
		}
		else puts("NA");
	}
}

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

int main(){
  int a;
  cin >> a;
  
  if( a % 1111 == 0 ){
    cout << "Yes" << endl;
  }else{
   	if( a/10 % 111 ==  0 ){
	    cout << "Yes" << endl;
    }else if( a % 10 % 111 == 0 ){
	    cout << "Yes" << endl;
    }else{
	    cout << "No" << endl;           
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#define rep(i,a,b) for(int i=a;i<b;i++)
//#define T int t ;cin >> t;while(t--)
using namespace std ;
typedef long long ll;
//typedef unsigned long long ull;
int main()
{
    ll n,d;
    scanf("%lld%lld",&n,&d);
    d*=d;
    ll s=0;
    for(ll i=1;i<=n;i++)
    {
        double x,y;
        scanf("%lf%lf",&x,&y);
        x=x*x+y*y;
        if(x<=d)
            s++;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
#define LL long long
#define INF (1LL << 60)
using namespace std;

template<class T> inline
void read(T& x) {
	int f = 1; x = 0;
	char ch = getchar();

	while (ch < '0' || ch > '9')   {if (ch == '-') f = -1; ch = getchar();}
	while (ch >= '0' && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}

/*============ Header Template ============*/

const int N = 100000 + 5;

int n, k;
LL a[N], s[N], f[N], g[N];

int main() {
	read(n), read(k);
	for (int i = 1; i <= n; i++) read(a[i]);
	for (int i = 1; i <= n; i++) s[i] = s[i - 1] + a[i];
	for (int i = 1; i <= n; i++) f[i] = (a[i] > 0 ? f[i - 1] + a[i] : f[i - 1]);
	for (int i = n; i; i--) g[i] = (a[i] > 0 ? g[i + 1] + a[i] : g[i + 1]);
	LL ans = -INF;
	for (int i = 1; i + k - 1 <= n; i++) {
		LL tmp = s[i + k - 1] - s[i - 1];
		ans = max(ans, f[i - 1] + max(tmp, 0LL) + g[i + k]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int dig = -1;
        for (int i = 0, x = 9; i < 9; i++, x = x * 10 + 9) {
            System.out.println(String.format("? %d", x));
            System.out.flush();
            if (sc.next().charAt(0) == 'Y') {
                dig = i;
                break;
            }
        }
        if (dig == -1) {
            System.out.println(String.format("! %d", 1000000000));
            sc.close();
            return;
        }
        if (dig == 0) {
            long x = 1;
            for (int i = 0; i < 10; i++, x *= 10) {
                System.out.println(String.format("? %d", x));
                if (sc.next().charAt(0) == 'N') {
                    if (i == 1) {
                        break;
                    } else {
                        long l = x / 10 - 10;
                        long r = x;
                        while (r - l > 1) {
                            long m = (l + r) >> 1;
                            System.out.println(String.format("? %d", m * 10));
                            System.out.flush();
                            if (sc.next().charAt(0) == 'N') {
                                l = m;
                            } else {
                                r = m;
                            }
                        }
                        System.out.println(String.format("! %d", r));
                        sc.close();
                        return;
                    }
                }
            }
            for (x = 10; x < 100; x += 10) {
                System.out.println(String.format("? %d", x));
                if (sc.next().charAt(0) == 'Y') {
                    System.out.println(String.format("! %d", x / 10));
                    sc.close();
                    return;
                }
            }
            sc.close();
            throw new Exception();
        }
        long l = 1;
        for (int i = 0; i < dig; i++) {
            l *= 10;
        }
        long r = l * 10;
        l -= 1;
        while (r - l > 1) {
            long m = (l + r) >> 1;
            System.out.println(String.format("? %d", m * 10));
            System.out.flush();
            if (sc.next().charAt(0) == 'N') {
                l = m;
            } else {
                r = m;
            }
        }
        System.out.println(String.format("! %d", r));
        sc.close();
    }
}


Measured memory_bytes: 35868
def test():
    n = int(input())
    a = list(map(int,input().split()))
    a.insert(0,0); a.append(0);
    sum_1 = 0
    for i in range(n+1):
        sum_1 += abs(a[i]-a[i+1])
    for i in range(n):
        sum = sum_1 + abs(a[i]-a[i+2]) - (abs(a[i]-a[i+1])+abs(a[i+1]-a[i+2]))
        print(sum)


if __name__ == "__main__":
    test()


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

using namespace std;

int main(){
	int N, M;
	while(cin >> N >> M){
		vector<int> num(N, 0);
		for(int i=0;i<2*M;i++){
			int a; cin >> a;
			num[a-1]++;
		}
		bool ok = true;
		for(int i=0;i<N;i++) if(num[i]%2) ok = false;
		cout << (ok ? "YES" : "NO") << endl;
	}
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    if(s.length()>=6)
    {
        if(s[2]==s[3] && s[4]==s[5])
            cout<<"Yes";
        else cout<<"No";
    }
    else cout<<"No";
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = 1e9;
const LL LLINF = 1e18;

void solve()
{
    int N;
    cin >> N;
    LL sum_s = 0;
    LL sum_a = 0;
    vector<int> a(N);
    REP0(i, N)
    { // まず すぬけくん が 0 枚とるとして和を考えておく
        cin >> a[i];
        sum_a += a[i];
    }
    LL ans = LLINF; // 0枚のときに最適にならないように
    REP0(i, N - 1) //すぬけくんが  N 枚全部とらないように
    {
        sum_a -= a[i];
        sum_s += a[i];
        ans = min(ans, abs(sum_s - sum_a));
    }
    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
#define pb push_back
const int MAX = 2e5 + 10; 
const ll MOD = 1e9 + 7;
vector<ll> a[MAX];

ll mod(ll x){
	x %= MOD;
	return x;
}

ll res; ll n,k; 

void dfs(ll v,ll u){
	ll i=0; ll adder = k-2;
	if(v == 1) adder += 1;

	for(ll x : a[v]){
		if(x != u){
			res = mod(res * adder);
			adder--;
			dfs(x,v);
		}
	}
}

int main()
{
	cin>>n>>k; res = k;

	for(ll i=0;i<n-1;i++){
		ll u,v; cin>>u>>v;
		a[u].pb(v); a[v].pb(u);
	}

	dfs(1,1);

	cout<<res;
}


Measured memory_bytes: 12800
import java.util.*;
import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		Integer[] a = new Integer[n];
		Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
		List<Integer> list = new ArrayList<>(Arrays.asList(a));
		System.out.println(list.size() == list.stream().distinct().collect(Collectors.toList()).size() ? "YES" : "NO");
	}
}


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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{

    int N, M;
    cin >> N;
    vector<int> A(N);
    rep(i, N - 1)
    {
        cin >> A[i];
        A[i]--;
    }

    vector<int> B(200000 + 100, 0);
    rep(i, N - 1)
    {
        B[A[i]]++;
    }

    rep(i, N)
    {
        cout << B[i] << endl;
    }

    return 0;
}


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

int main() {
  
  int a, b;
  cin >> a >> b;
  
  if (abs(a-b) % 2 == 1){
    cout << "IMPOSSIBLE" << endl;
  }
  else {
  	int x = abs(a-b) / 2;
  
  	if (a < b) cout << a+x << endl;
  	else cout << b+x << endl;
  }
  
}


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

int main() {
	long long int n,m,a,b,c,d,e;
	long double z,w;
	string str;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a;
	if(a<1200){cout<<"ABC";}
	else if(a<2800){cout<<"ARC";}
	else{cout<<"AGC";}
	



	cout<<endl;
} 


Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let x: usize = iterator.next().unwrap().parse().unwrap();
    let a: usize = iterator.next().unwrap().parse().unwrap();

    if x < a {
        return "0".to_string();
    }

    return "10".to_string();
}


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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

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;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

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

int main(){
    int N,X;
    cin>>N>>X;
    vector<int> x(N+1);
    rep(i,N)cin>>x[i];
    x[N]=X;
    sort(x.begin(),x.end());
    vector<int> A(N);
    rep(i,N){
        A[i]=x[i+1]-x[i];
    }
    int ANS=A[0];
    for(int i=0;i<N-1;i++){
        ANS=GCD(ANS,A[i+1]);
    }
    cout<<ANS<<endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 1024
import numpy as np
 
n = int(input())
a = list(int(i) for i in input().split()) 
a.sort()
minCount = 0
maxCount = 0
count = np.zeros(9)

for i in range(n) :
    if a[i] < 400 :
        count[0] = count[0] + 1
    elif a[i] < 800 :
        count[1] = count[1] + 1
    elif a[i] < 1200 :
        count[2] = count[2] + 1
    elif a[i] < 1600 :
        count[3] = count[3] + 1
    elif a[i] < 2000 :
        count[4] = count[4] + 1
    elif a[i] < 2400 :
        count[5] = count[5] + 1
    elif a[i] < 2800 :
        count[6] = count[6] + 1
    elif a[i] < 3200 :
        count[7] = count[7] + 1
    elif a[i] < 4801 :
        count[8] = count[8] + 1

for i in range(8) :
    if count[i] > 0 :
        minCount = minCount + 1
        maxCount = maxCount + 1

maxCount = maxCount + count[8]
if minCount == 0 :
    minCount = 1

#print (a)
print (minCount, end =' ')
print (int(maxCount))

Measured memory_bytes: 21208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
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;}

int main(){
    string s; cin >> s;
    deque<char> ans;
    for(char a : s) ans.push_back(a);
    int q; cin>> q;
    bool rev = false;
    rep(i, q) {
        int t; cin >> t;
        if(t==1) {
            rev = !rev;
        } else {
            int f; cin>>f;
            char c; cin >> c;
            if((rev==false && f==1) || (rev==true && f==2)){
                ans.push_front(c);
            } else {
                ans.push_back(c);
            }
        }
    }
    string ansstr;
    while(ans.size()) {
        ansstr += ans.front(); ans.pop_front();
    }
    if(rev) reverse(ansstr.begin(), ansstr.end());
    cout << ansstr << endl;
}

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

using namespace std;

typedef long long lli;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<vector<lli>> mat;

lli n;
mat tree;
vll dist;
lli black = 0;

void dfs(lli x,lli d,lli p){
  dist[x] = d;
  for(lli i = 0;i < tree[x].size();i++){
    if(tree[x][i] != p) dfs(tree[x][i],d+1,x);
  }
}
void dfs2(lli x,lli d,lli p){
  if(dist[x] <= d) black++;
  for(lli i = 0;i < tree[x].size();i++){
    if(tree[x][i] != p) dfs2(tree[x][i],d+1,x);
  }
}


int main(){
  cin >> n;
  tree = mat(n+1);
  dist = vll(n+1);
  for(lli i = 0;i < n-1;i++){
    lli a,b;
    cin >> a >> b;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  dfs(1,0,0);
  dfs2(n,0,0);
  if(black > n-black) cout << "Fennec" << endl;
  else cout << "Snuke" << endl;
  return 0;
}


Measured memory_bytes: 11136
W,H,N=map(int,input().split())
L,R = 0,W
D,T = 0,H
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1:
        if R <= x:
            L,R = 0,0
        elif L <= x:
            L = x
    elif a == 2:
        if x <= L:
            L,R = 0,0
        elif x <= R:
            R = x
    elif a == 3:
        if T <= y:
            D,T = 0,0
        elif D <= y:
            D = y
    else:
        if y <= D:
            D,T = 0,0
        elif y <= T:
            T = y
print( ( R - L ) * ( T - D ) )


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define double long double
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), end(x))
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) ((x)/gcd(x,y)*(y))
#define isin(x, l, r) ((l) <= (x) and (x) < (r))
#define fcout cout << fixed << setprecision(10)
#define rcout(n) cout << right << setw(n)
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define INF32 INT32_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using TIII = tuple<int, int, int>;
using VPII = vector<PII>;
using VTIII = vector<TIII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b, bool t = false){ if(a<b or (t and a == b)){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b, bool t = false){ if(a>b or (t and a == b)){ a=b; return true; } return false; }


int N, K;
int R, S, P;
string T;
int dp[100010][3];


int enc(char c){
    if(c == 'r') return 2;
    if(c == 's') return 0;
    return 1;
}


int enc2(char c){
    if(c == 'r') return P;
    if(c == 's') return R;
    return S;
}


signed main(){
    cin >> N >> K;
    cin >> R >> S >> P;
    cin >> T;

    rep(i, 0, K) dp[i][enc(T[i])] = enc2(T[i]);
    rep(i, 0, K) repif(j, 1, i+j*K < N) rep(k, 0, 3){
        rep(l, 0, 3) if(l != k) chmax(dp[i+j*K][k], dp[i+j*K-K][l]);
        if(k == enc(T[i+j*K])) dp[i+j*K][k] += enc2(T[i+j*K]);
    }

    int ans = 0;
    rep(i, N-K, N) ans += *max_element(dp[i], dp[i]+3);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2816
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  var line, lines = chunk.split("\n");
  var i, j, len = lines[0];
  var pro, epi, proRev, epiRev, res, arr;
  for (i = 1; i <= len; i++) {
    line = lines[i];
    arr = [];
    for (j = 0; j < line.length; j++) {
      pro = line.substr(0, j).split('').join('');
      epi = line.substr(j).split('').join('');
      proRev = line.substr(0, j).split('').reverse().join('');
      epiRev = line.substr(j).split('').reverse().join('');
      (res = pro + epi) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = pro + epiRev) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = proRev + epi) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = proRev + epiRev) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = epi + pro) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = epiRev + pro) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = epi + proRev) && arr.indexOf(res) == -1 ? arr.push(res) : '';
      (res = epiRev + proRev) && arr.indexOf(res) == -1 ? arr.push(res) : '';
    }
    console.log(arr.length);
  }
});

Measured memory_bytes: 19816
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define endl '\n'
#define ll long long
#define mod 1000000007
#define inf 1000000000000000000
int main()
{
	fastio;
	#ifdef APNA_IO
		freopen("input.txt" , "rt" ,stdin);
		freopen("output.txt" , "wt" ,stdout);
	#endif
	ll n,m;
	cin>>n>>m;
	ll arr[n],arr1[m];
	for(ll &i:arr)
		cin>>i;
	for(ll &i:arr1)
		cin>>i;
	ll dp[n+1][m+1];
	for(ll i=0;i<=n;i++)
		dp[i][0]=1;
	for(ll i=0;i<=m;i++)
		dp[0][i]=1;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=m;j++)
		{
			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
			if(arr[i-1]==arr1[j-1])
				dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
			dp[i][j]=(dp[i][j]-dp[i-1][j-1])%mod;
		}
	}
	cout<<(dp[n][m]+mod)%mod<<endl;
	return 0;
}





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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int H,W;
    Scd2(H,W);

    int A,B;
    Scd2(A,B);

    bool ok = true;

    vector<vi> ans(H,vi(W,0));

    Rep(i,H)Rep(j,W){
        ans[i][j] = (j>=A) xor (i>=B);
    }

    if( ok )
    Rep(i,H){
        Rep(j,W){
            printf ("%d", ans[i][j]);
        }
        printf ("\n");
    }
    else{
        YesNo(ok);
    }

    return 0;
}





Measured memory_bytes: 5248
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
int main() {
    int N, ans = 0; string S; cin >> N >> S;
    for (int i = 1; i < N; i++) {
        string a = S.substr(0, i), b = S.substr(i, N - i);
        set<char> counter;
        for (int j = 0; j < a.length(); j++) {
            for (int k = 0; k < b.length(); k++) {
                if (a[j] == b[k]) counter.insert(a[j]);
            }
        }
        if (ans < counter.size()) ans = counter.size();
    }
    cout << ans << endl;
}


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

struct pos {
  int x;
  int y;
};

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  int blacks = 0;
  for (auto &row : s) {
    cin >> row;
    blacks += count(begin(row), end(row), '#');
  }

  vector<vector<uint64_t>> m(h, vector<uint64_t>(w, INT_MAX));
  m[0][0] = 0;
  deque<pos> q;
  int dx[] = {1, 0, -1, 0};
  int dy[] = {0, 1, 0, -1};
  q.push_back(pos{0, 0});
  while (!q.empty()) {
    auto p = q.front();
    q.pop_front();
    auto &now = p;
    if (now.x == w - 1 && now.y == h - 1) {
      break;
    }
    for (int i = 0; i < 4; ++i) {
      int nx = now.x + dx[i];
      int ny = now.y + dy[i];
      if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] == '.' &&
          m[now.y][now.x] + 1 < m[ny][nx]) {
        m[ny][nx] = m[now.y][now.x] + 1;
        q.push_back(pos{nx, ny});
      }
    }
  }
  if (m[h - 1][w - 1] == INT_MAX) {
    cout << "-1\n";
  } else {
    cout << h * w - blacks - m[h - 1][w - 1] - 1<< "\n";
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<queue>
#include<algorithm>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)
#define MAX_V 10100
#define MAX_E 101000
using namespace std;

struct P
{
  int to,cost;
  P(int to=inf,int cost=inf):to(to),cost(cost){}
  bool operator < (const P &a)const
  {
    return cost > a.cost;
  }
};

int V,E;
vector<P> G[MAX_V];
bool used[MAX_V];
int mincost[MAX_V];

int prim()
{
  rep(i,V)used[i] = false,mincost[i] = inf;
  mincost[0] = 0;

  priority_queue<P> Q;
  Q.push(P(0,0));

  int ans = 0;
  while(!Q.empty())
    {
      P p = Q.top(); Q.pop();
      int cur = p.to;

      if(used[cur])continue;
      used[cur] = true;

      ans += p.cost;

      for(int i=0;i<G[cur].size();i++)
	{
	  int next = G[cur][i].to;
	  if(used[next])continue;
	  if(mincost[next] > G[cur][i].cost)
	    {
	      mincost[next] = G[cur][i].cost;
	      Q.push(P(next,mincost[next]));
	    }
	}
    }
  return ans;
}

int main()
{
  while(cin >> V,V)
    {
      rep(i,V)G[i].clear();
      cin >> E;
      rep(i,E)
	{
	  int from,to,w;
	  //cin >> from >> to >> w;
	  scanf("%d,%d,%d",&from,&to,&w);
	  G[from].push_back(P(to,w));
	  G[to].push_back(P(from,w));
	}
      
      cout << prim()/100 - (V-1) << endl;
      
    }
  return 0;
}

Measured memory_bytes: 1604
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int h = sc.nextInt();
            int w = sc.nextInt();
            String pushs = "";
            
            if(h == 0 && w == 0){
                break;
            } else{
                for(int i = 0; i < h; i++){
                    pushs = "";
                    for(int j = 0; j < w; j++){
                        pushs += "#";
                    }
                    System.out.println(pushs);
                }
                System.out.println("");
            }
        }
    }
}



Measured memory_bytes: 55016
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
lli ans=0;
  lli N;
  cin >> N;
  rep(i, N){
  if((i+1)%3!=0){
    if((i+1)%5!=0){
  ans+=i+1;
  }
  
  }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>		//UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>		//do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)
#define ALL(u) (u).begin(),(u).end()

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

typedef pair<int, int> PII;

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;

const int MR = 40;
bool done[MR][MR][MR][MR];

int A, B, C, D, E, F;

int lb, mb;

int s1, s2;

void go(int a, int b, int c, int d)
{
	if (done[a][b][c][d])
		return;

	done[a][b][c][d] = 1;

	if (a*A * 100 + b*B * 100 + c*C + d*D > F)
		return;
	if ((c*C + d*D) * 100 > E*(a*A * 100 + b*B * 100))
		return;

	int lv = 100 * (c*C + d*D), mv = max(a*A * 100 + b*B * 100 + c*C + d*D, 1);

	if (lv*mb > lb*mv)
	{
		lb = lv;
		mb = mv;
		s1 = a*A * 100 + b*B * 100 + c*C + d*D;
		s2 = c*C + d*D;
	}

	go(a + 1, b, c, d);
	go(a, b + 1, c, d);
	go(a, b, c + 1, d);
	go(a, b, c, d + 1);
}

int main()
{
	mb = 1;
	scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);

	go(0, 0, 0, 0);

	if (!s1)
		s1 = 100 * A;

	printf("%d %d\n", s1, s2);

	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <functional>
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int x, y, z;
    cin >> x >> y >> z;
    int rest = x - z;
    int cnt = 0;
    while (rest >= y+z) {
        rest -= (y + z);
        cnt++;
    }
    cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
fscanf(STDIN,"%d",$n);
$count_case['AC'] = 0;
$count_case['WA'] = 0;
$count_case['TLE'] = 0;
$count_case['RE'] = 0;



for($i=0;$i<$n;$i++){
  fscanf(STDIN,"%s",$s);
  $count_case[$s]++;
}

//print_r($count_case);

foreach($count_case as $re => $count){
  echo $re." x ".$count."\n";
}

Measured memory_bytes: 16228
#include <iostream>
#include <stdio.h>
#include <stack>
#include <string>
#include <stdlib.h>
using namespace std;
int main(){
    stack<int>data;
    string ss;
    while(cin>>ss){
        
        if(ss == "+"){
            int a,b;
            b = data.top();
            data.pop();
            a = data.top();
            data.pop();
            data.push(a+b);
        }
        else if(ss == "-"){
            int a,b;
            b = data.top();
            data.pop();
            a = data.top();
            data.pop();
            data.push(a-b);  
        }
        else if(ss == "*"){
            int a,b;
            b = data.top();
            data.pop();
            a = data.top();
            data.pop();
            data.push(a*b);
        }else{
            int num = atoi(ss.c_str());
            data.push(num);
        }
    }
    printf("%d\n",data.top());
}


Measured memory_bytes: 3296
import java.util.Scanner;

public class Main implements Runnable {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Thread(null, new Main(), "", 128 * 1024 * 1024).start();
    }

    public void run() {
        int n = sc.nextInt();
        String s = sc.next();
        char[] ss = new char[s.length()];
        for (int i = 0; i < s.length(); i++) {
            ss[i] = s.charAt(i);
        }

        int[] countE = new int[ss.length];
        int[] countW = new int[ss.length];
        int currentE = 0, currentW = 0;
        for (int i = ss.length - 1; i >= 0; i--) {
            if (ss[i] == 'E') {
                currentE += 1;
            }
            countE[i] = currentE;
        }
        for (int i = 0; i < ss.length; i++) {
            if (ss[i] == 'W') {
                currentW += 1;
            }
            countW[i] = currentW;
        }

        int min = Integer.MAX_VALUE;
        for (int i = 0; i < ss.length; i++) {
            int count = 0;
            if (i != ss.length - 1) {
                count += countE[i + 1];
            }
            if (i != 0) {
                count += countW[i - 1];
            }
            min = Math.min(count, min);
        }
        System.out.println(min);
    }
}


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

n = int(input())
t, a = map(int, input().split())
heights = list(map(int, input().split()))

temps = {}
for i in range(len(heights)):
    temp = t - heights[i] * 0.006
    temps[i] = abs(a - temp)

ranking = sorted(temps.items(), key = lambda x: x[1])
# print(ranking)
print(ranking[0][0] + 1)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)


template <typename T>
void calcFactional_mod( size_t size, 
	vector<T>& fac, vector<T>& inv, vector<T>& facInv, T mod )
{
	for( T i = 2; i < size; ++i )
	{
		fac[i] = fac[i - 1] * i % mod; // n! % mod
		inv[i] = mod - inv[mod % i] * ( mod / i ) % mod; // 逆元計算 (n)^-1 % mod
		facInv[i] = facInv[i - 1] * inv[i] % mod; // (n!)^-1 % mod
	}
}
template <typename T>
T pow_mod(T x, T n, T mod)
{
	T res = 1;
	while (n > 0)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = (x * x) % mod;
		n >>= 1;
	}
	return res;
}

int main()
{
	cin.tie( 0 ); ios::sync_with_stdio( false );
	const ll maxN = 1000010;
	vector<ll> fac( maxN, 1 ), inv( maxN, 1 ), facInv( maxN, 1 );
	calcFactional_mod<ll>( maxN, fac, inv, facInv, cMOD);
	auto mod = cMOD;
	auto add = [mod]      ( ll a, ll b ) { return ( a + b ) % mod; };
	auto sub = [mod]      ( ll a, ll b ) { return ( a + mod -b ) % mod; };
	auto mul = [mod]      ( ll a, ll b ) { return a * b % mod; };
	auto div = [&inv, mod]( ll a, ll b ) { return a * inv[b] % mod; };
	auto pow = [mod]      ( ll a, ll b ) { return pow_mod<ll>( a, b, mod ); };
	
	ll n, k; cin >> n >> k;
	ll n2 = std::sqrt(n);
	vector<ll> dpsum( 2 * (n2+1), 1 ), dpsum2( 2 * (n2+1), 1 );

	auto* pdpsum = &dpsum;
	auto* pdpsum2 = &dpsum2;

	auto idx = [ &n, &n2 ]( ll a )
	{
		return ( 2 * n2 + 1 ) - ( n / a );
	};
	REP( kk, k )
	{
		(*pdpsum2)[0] = 0;
		REP( i, n2 )
		{
			ll a = (*pdpsum)[ idx(  n / ( i + 1 ) ) ];
			(*pdpsum2)[i+1] = add( a, (*pdpsum2)[i] );
			//cout << i+1 << " " << (*pdpsum2)[i+1] << endl;
		}
		BREP( i, n2 )
		{
			ll d = idx( n / (i + 1) );
			if( i + 1 > n / ( n2 + 1 ) )
			{
				(*pdpsum2)[d] = (*pdpsum2)[d - 1]; 
			}
			else
			{
				ll a = mul( (*pdpsum)[i+1], n/(i+1) - n/(i+2) );
				(*pdpsum2)[d] = add( a, (*pdpsum2)[d-1] );
			}
			//cout << d << " " << (*pdp2)[d] << " " << (*pdpsum2)[d] << endl;
		}

		swap( pdpsum, pdpsum2 );
	}

	cout << (*pdpsum)[idx(n)] << endl;
	
	return 0;
}

Measured memory_bytes: 24704
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
int n,l;
string s[110];

int main(){
	cin >> n >> l;
	REP(i,0,n) cin >> s[i];
	sort(s,s+n);
	REP(i,0,n) cout << s[i];
	cout << endl;
	return 0;
}


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

int main()
{
	int K, S;
	cin >> K >> S;
	int A, BC, B, C, count = 0;
	for (size_t i = (S - K * 2) < 0 ? 0 : (S - K * 2); i <= S&&i <= K; i++)
	{
		A = i;
		BC = S - A;
		if (BC > K * 2) { continue; }
		for (size_t n = 0; n <= BC&&n<=K; n++)
		{
			B = n;
			C = BC - B;
			if (C <= K) count++;
		}
	}
	cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    a*b>=c*d ? cout<<a*b : cout<<c*d;
    cout<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func scanInts(n int) []int {
	sl := make([]int, n)
	for i := range sl {
		sl[i] = scanInt()
	}
	return sl
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	h := scanInts(n)

	dp := make([]int, n)
	dp[0] = 0
	dp[1] = abs(h[0] - h[1])
	for i := 2; i < n; i++ {
		dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]), dp[i-2]+abs(h[i-2]-h[i]))
	}
	fmt.Println(dp[n-1])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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


Measured memory_bytes: 2688
#include<stdio.h>
#include<string.h>
int main()
{

    char s[500];
    int l;
    gets(s);
    l=strlen(s);
    for(int i=l-1;i>=0;i--)
        {
            printf("%c",s[i]);
        }


    printf("\n");

    return 0;

}

Measured memory_bytes: 908
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define F first
#define S second


int main()
{

//#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
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin >> s;
	if (s.length()==6 and s[2] == s[3] and s[4] == s[5])
		cout << "Yes\n";
	else
		cout << "No\n";

	return 0;
}


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

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

int parent[101010];
int t[101010];

int get_parent(int x) {
        if (parent[x] == -1) return x;
        return parent[x] = get_parent(parent[x]);
}

int main() {
        int n, q;
        while (cin >> n >> q && n) {
                memset(parent, -1, sizeof(parent));
                memset(t, -1, sizeof(t));
                for (int i = 1; i < n; i ++) {
                        int p;
                        cin >> p;
                        p --;
                        parent[i] = p;
                        t[i] = p;
                }
                vector<char> s(q);
                vector<int> node(q);
                int cnt[101010] = { 0 };
                rep(i, q) {
                        cin >> s[i] >> node[i];
                        node[i] --;
                        if (s[i] == 'M') {
                                cnt[node[i]] ++;
                                parent[node[i]] = -1;
                        }
                }
                long long ans = 0;
                for (int i = q - 1; i >= 0; i --) {
                        if (s[i] == 'Q') {
                                ans += get_parent(node[i]) + 1;
                        } else {
                                if (cnt[node[i]] > 1) {
                                        cnt[node[i]] --;
                                        continue;
                                }
                                parent[node[i]] = t[node[i]];
                        }
                        //cout << "====================" << endl;
                        //rep(i, n) cout << parent[i] << endl;
                }
                cout << ans << endl;
        }
}

//bool mark[101010];
//int g[101010];
//
//int dfs(int s) {
//        return mark[s] ? s : dfs(g[s]);
//}
//
//int main() {
//        int n, q;
//        while (cin >> n >> q && n) {
//                memset(mark, 0, sizeof(mark));
//                for (int i = 1; i < n; i ++) {
//                        int p;
//                        cin >> p;
//                        p --;
//                        g[i] = p;
//                }
//                mark[0] = true;
//                long long ans = 0;
//                rep(i, q) {
//                        char s;
//                        int v;
//                        cin >> s >> v;
//                        v --;
//                        if (s == 'M') mark[v] = true;
//                        else ans += dfs(v) + 1;
//                }
//                cout << ans << endl;
//        }
//}

Measured memory_bytes: 4900
#include "iostream"
#include "math.h"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
using namespace std;

int main() {
	int ans = 0;
	string s, t;
	cin >> s >> t;
	for (int i = 0; i <= 2; i++) {
		if (s[i] == t[i])ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256