akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

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

int merge(vi &a, int left, int mid, int right) {
  int n_comp = 0, n1 = mid - left, n2 = right - mid;

  vi l(n1 + 1), r(n2 + 1);
  rep(i, n1) l[i] = a[left + i];
  rep(i, n2) r[i] = a[mid + i];

  l[n1] = INT_MAX;
  r[n2] = INT_MAX;
  
  int i = 0, j = 0;
  for (int k = left; k < right; k++) {
    n_comp++;
    if (l[i] <= r[j]) {
      a[k] = l[i];
      i++;
    } else {
      a[k] = r[j];
      j++;
    }
  }

  return n_comp;
}

int merge_sort(vi &a, int left, int right) {
  int n_comp = 0;
  if (right > left + 1) {
    int mid = (right + left) / 2;
    n_comp += merge_sort(a, left, mid);
    n_comp += merge_sort(a, mid, right);
    n_comp += merge(a, left, mid, right);
  }

  return n_comp;
}

int main() {
  int n;
  cin >> n;
  vi s(n);
  rep(i, n) cin >> s[i];

  int nc = merge_sort(s, 0, n);

  rep(i, n) {
    cout << s[i];
    i != n - 1 ? cout << " " : cout << endl;
  }

  cout << nc << endl;
}



Measured memory_bytes: 6804
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
#define INF 0x7FFFFFFF
#define ll long long

int get_ans(string t);
int get_num();

string s,ss,t,tt;
vector<int> a;
int k;

//  [ -1
//  ] -2
//  + -3
//  * -4
//  ^ -5

int main(){
  cin >> ss;
  while(ss!="."){
    k=0;
    cin >> tt;
    s=ss;
    t=tt;
    int num=get_ans(t);
    int ans=0;
    t="0000";
    for(int i=0;i<10000;i++){
      k=0;
      if(get_ans(t)==num){
        ans++;
      }
      t[0]++;
      for(int l=0;l<3;l++){
        if(t[l]>'9'){
          t[l]-=10;
          t[l+1]++;
        }
      }
    }
    cout << num << " " << ans << endl;
    cin >> ss;
  }
}

int get_ans(string t){
  a.assign(s.size(),0);
  for(int i=0;i<(int)s.size();i++){
    if('a'<=s[i]&&s[i]<='d'){
      a[i]=t[s[i]-'a']-'0';
    }
    else{
      switch(s[i]){
        case '[':
          a[i]=-1;
          break;
        case ']':
          a[i]=-2;
          break;
        case '+':
          a[i]=-3;
          break;
        case '*':
          a[i]=-4;
          break;
        case '^':
          a[i]=-5;
          break;
      }
    }
  }
  return get_num();
}


int get_num(){
  if(a[k]>=0){
    k++;
    return a[k-1];
  }
  else if(a[k]==-1){
    k++;
    int x;
    int y;
    switch(a[k]){
      case -3:
        k++;
        x=get_num();
        y=get_num();
        k++;
        return x|y;
        break;
      case -4:
        k++;
        x=get_num();
        y=get_num();
        k++;
        return x&y;
        break;
      case -5:
        k++;
        x=get_num();
        y=get_num();
        k++;
        return x^y;
        break;
    }
  }
  return 0;
}



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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define endl '\n'
#define mod 1000000007
#define maxN 1e5
const int inf=0x3f3f3f3f;

int main() {
	Omar45
    int n; cin >> n;
    vector <ll> arr(n+1), brr(n);
    for (int i=0; i<n+1; i++)
        cin >> arr[i];
    for (int i=0; i<n; i++)
        cin >> brr[i];
    ll res = 0;
    for (int i=0; i<n; i++) {
        if ( arr[i] > brr[i] ) {
            res += brr[i];
            arr[i] -= brr[i];
        }
        else if ( arr[i] + arr[i+1] > brr[i] ) {
            res += arr[i] + ( brr[i] - arr[i] );
            arr[i+1] -= (brr[i] - arr[i]);
            arr[i] = 0;
        }
        else if ( arr[i] + arr[i+1] <= brr[i] ) {
            res += (arr[i] + arr[i+1]);
            arr[i] = arr[i+1] = 0;
        }
    }
    cout << res << endl;
    return 0;
}



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

using namespace std;

bool sample(string s){
  string t(s.rbegin(),s.rend());
  return s==t;
}
int main()
{
  string s;
  cin >> s;
  int n = s.size();
  if(sample(s) && sample(s.substr(0,(n-1)/2)) && sample(s.substr((n+1)/2))){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
 
using namespace std; 
 
#define NOT_FOUND -1
#define rep(i,n) for(int i=0;i<(int)(n); i++)
/*for文のマクロ定義
rep(i,回数){
    処理
}
*/
 
void swap(int *a, int *b){
	*b=*a-*b;
	*a-=*b;
	*b+=*a;
}
 
int sosu_judge(int N){
	/*素数ならば1
	  素数でなければ0を返す
	*/
	int i,j;
 
	if(N==2)   return 1;
	if(N%2==0) return 0;
 
	for(i=3;i<N && N%i!=0;i+=2);
 
	if(i>=N) return 1;
	
	return 0;
}
 
int factorial(int N){  //Nの階乗を求める関数
	int ans=1;
 
	while(N--) ans*=(N+1);
	return ans;
}
 
//クイックソートをする関数
void q_sort(int a[], int first, int last){
    int i,j;
    int x,t;
 
    x = a[(first + last) / 2];
    i = first; j=last;
 
    while(1){
        while( a[i] < x) i++;
        while( x < a[j]) j--;
        
        if( i >= j) break;
        
        swap(&a[i],&a[j]);
        i++; j--;
    }
    if(first < i-1) q_sort(a, first,i-1 );
    if(last > j+1)  q_sort(a, j+1,  last);
}
 
int b_search(int target, int array[],int right, int left){
    /*二分探索を行う関数である。
      戻り値は探索したい値の格納されている位置である。
      もし値が存在しない場合、NOT_FOUND(-1)を返す
    */
    int mid;
    while(left<right){
        mid=(right+left)/2;
        if(array[mid]<target) left =mid+1;
        else                  right=mid;
    }
    if(array[mid]==target) return mid;
    return NOT_FOUND;
}
 
unsigned long combination(int n, int r){
    /*nCrの値を求める関数である。
      値が巨大になる可能性があるため、戻り地はunsigned longである
    */
    int i,j;
    unsigned long a[17];
 
    if(n-r<r) r=n-r;
    if(r==0 ) return 1;
    if(r==1 ) return n;
    if(r>17 ) return 0;
    for(i=1;i<r;i++) a[i]=i+2;
    for(i=3;i<=n-r+1;i++){
        a[0]=i;
        for(j=1;j<r;j++)a[j]+=a[j-1];
    }
    return a[r-1];
}

int main(){
    long H,W,ans;
    
    cin>>H>>W;

    if(H==1 || W==1){
        cout<<"1"<<endl;
        return 0;
    }

    if(H%2==0) ans=H/2*W;
    if(H%2==1 && W%2==1){
        H=H/2+1;
        ans=H*(W/2+1);
        H--;
        ans+=H*(W/2);
    }
    if(H%2==1 && W%2==0){
        W/=2;
        H=H/2+1;
        ans=H*W;
        H--;
        ans=ans+H*W;
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, t;
    cin >> n >> t;
    vi a(n);
    rep(i, n) cin >> a[i];
    vi mx(n);
    mx[n-1] = a[n-1];
    for (int i = n-2; i >= 0; --i) {
        mx[i] = max(mx[i+1], a[i]);
    }
    vi b(n);
    int x = 0;
    rep(i, n) {
        b[i] = mx[i] - a[i];
        chmax(x, b[i]);
    }
    int cnt = 0;
    rep(i, n) if (b[i] == x) cnt++;
    cout << cnt << endl;
}

Measured memory_bytes: 1408
K,S=[ int(r) for r in input().split(' ') if r != '' ]
max_loop=min(K,S)+1
cnt=0
for x in range(max_loop):
    for y in range(max_loop):
        z= S-x-y
        if 0 > z:
            break
        if z <= K:
            cnt+=1
print(cnt)


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

int main() {
long long k,p,q,a;
cin>>k;
p=k/50;
q=k%50;
cout<<50<<endl;
for(int i=1;i<=49;i++){
    a=p-q+48;
    if(i<=q){
        a+=51;
    }
    cout<<a<<" ";
}
cout<<p-q+49<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main() {
    int i,j,n,m,p,q,a,b,r,d,x,temp;
    int flag=0;
    int maxl=0;
    int minr=100000;
    string s;
    cin>>n>>m;
    int lr[m][2];
    for(i=0; i<m; ++i){
        cin>>lr[i][0]>>lr[i][1];
    }
    for(i=0; i<m; ++i){
        if(maxl<lr[i][0]){maxl=lr[i][0];}
        if(minr>lr[i][1]){minr=lr[i][1];}
    }
    if(minr>n){minr=n;}
    flag=minr-maxl+1;
    if(flag>=0){cout<<flag;}
    else{cout<<0;}

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
constexpr ll mod = 998244353;
int main(){
    int N;cin>>N;
    vector<int> D(N);
    REP(i, N) cin >> D[i];
    ll ans=1;
    if(D[0]!=0) ans=0;
    sort(All(D));
    vector<ll> v(N);
    v[0]=1;
    
    rep(i,1,N){
        if(D[i]==0){
            ans=0;
        }
        ans*=v[D[i]-1];
        ans%=mod;
        v[D[i]]++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1408
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
constexpr ll MOD=1e9+7;

const int MAX = 2000*2;
//const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll N,K; cin>>N>>K;    
    COMinit();
    for(ll i=1;i<=K;++i){
        ll r=N-K;
        ll rin=r+1;
        ll c1=COM(rin,i);
        ll c2=COM(K-1,i-1);
        ll ans=(c1*c2)%MOD;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 384
a = gets.chomp.split("")#.map(&:to_i)
if ((a.select{|t| t == "N"}.size !=0 && a.select{|t| t=="S"}.size != 0) ||
    (a.select{|t| t == "N"}.size ==0 && a.select{|t| t=="S"}.size == 0) ) &&
   ((a.select{|t| t == "E"}.size !=0 && a.select{|t| t=="W"}.size != 0) ||
    (a.select{|t| t == "E"}.size ==0 && a.select{|t| t=="W"}.size == 0) ) 
puts "Yes"
else
puts "No"
end


Measured memory_bytes: 1788
using System;
class Program{
	static void Main(){
		string s;
		while((s = Console.ReadLine()) != null){
			int n = int.Parse(s);
			if(n>36) Console.WriteLine(0);
			else{
				if(n>18) n = 36-n;
				int ans = (n+1)*(n+2)*(n+3)/6;
				if(n>9) ans -= 2*(n-9)*(n-8)*(n-7)/3;
				Console.WriteLine(ans);
			}
		}
	}
}

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}


int main(int argc, char const* argv[])
{
    int n,m,x;
    cin >> n >> m >> x;

    vector<int> A(n+1,0);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        A[a]=1;
    }
    vector<int> B;
    B = cumsum(A);
    if (B[x] < B[n] - B[x]) {
        cout << B[x] << endl;
    }else{
        cout << B[n] - B[x] << endl;
    }


    return 0;
}


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

int main() {
  string S;
  cin >> S;

  if (S[0] != 'A') {
    cout << "WA" << endl;
    return 0;
  }

  int idx = 0;
  map<char, int> m;
  for (int i = 2; i < S.size() - 1; i++) {
    if (S[i] == 'C') idx = i;
    m[S[i]]++;
  }
  if (m['C'] != 1) {
    cout << "WA" << endl;
    return 0;
  }

  for (int i = 1; i < S.size(); i++) {
    if (i == idx) continue;
    if (isupper(S[i])) {
      cout << "WA" << endl;
      return 0;
    }
  }
  cout << "AC" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ll INF = 1e18;
#define pu push
#define pb push_back
#define mp make_pair
#define print(x) cout << (x) << endl;
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define SORT(x) sort(x.begin(),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
#define fi first
#define sc second

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    vector<int> dx = {-1,0,1,0};
    vector<int> dy = {0,-1,0,1};
    int H, W, sharp = 0;
    cin >> H >> W;
    vector<vector<char>> s(H,vector<char>(W));
    vector<vector<int>> dist(H,vector<int>(W,-1));
    dist.at(0).at(0) = 0;
    rep(i,H) {
        rep(j,W) {
            cin >> s.at(i).at(j);
            if (s.at(i).at(j)=='#') {
                sharp++;
            }
        }
    }
    queue<P> que;
    que.push(make_pair(0,0));
    while(!que.empty()) {
        P p = que.front();
        que.pop();
        int x = p.first, y = p.second;
        if (x==W-1&&y==H-1) break;
        rep(i,4) {
            int nx = x + dx.at(i);
            int ny = y + dy.at(i);
            if(nx>=0&&ny>=0&&nx<W&&ny<H&&s.at(ny).at(nx)=='.'&&dist.at(ny).at(nx)==-1){
                que.push(make_pair(nx,ny));
                // s.at(ny).at(nx)=='#';
                dist.at(ny).at(nx) = dist.at(y).at(x)+1;
            }
        }
    }
    if(dist.at(H-1).at(W-1)==-1) cout << -1 << endl;
    else cout << H*W-dist.at(H-1).at(W-1)-sharp-1 << endl;
}

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

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


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

long long int exp(long long int a,long long int b){
	long long int p=a;
		for(int i=1;i<b;i++){
			a*=p;
			
			}
		return a;
	}

int main(){

	long long int n,m,a,b,c,k,memo,number,cou,check=0;
	cin>>k>>n;
	if(k==1)
	{
		for(int i=0;i<(n+1)/2;i++)
		{
			cout<<"1 ";
		}
		return 0;
	}
	
	
	if(k%2==0)
	{
		cout<<k/2<<" ";
		for(int i=1;i<n;i++)
		{
			cout<<k<<" ";
		}
	}else{
	
		for(int i=1;i<=n;i++)
		{
			if(exp(k,i)>n-i){
					memo=i;
					break;
				}
				
		}
		
			for(int i=1;i<=n-memo;i++)
		{
			
			cout<<k/2+1<<" ";
				
		}
		number=n-memo;
			for(int i=1;i<=memo;i++)
		{
			number+=exp(k,i);
			check+=exp(k,i);	
		}
		if(number%2==1){number++;}
		number/=2;
		number-=(n-memo);
		//numberは下i桁辞書順number目
		
		cou=1;
		while(cou!=memo+1&&number!=0)
		{
			cout<<(number-1)/(check/k)+1<<" ";
			number%=(check/k);
			if(number==0)
			{
				number=check/k;
			}
			if(number==1)
			{
				return 0;
			}
			check/=k;
			check--;
			cou++;
			number--;
		}
	}
	
}


Measured memory_bytes: 2304
//https://atcoder.jp/contests/abc162/tasks/abc162_d


import java.io.PrintWriter;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here

        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int N = Integer.parseInt(in.nextLine());
        String S = in.nextLine();

        long rCount = 0, gCount = 0, bCount = 0;
        for (int i = 0; i < S.length(); i++) {
            if(S.charAt(i) == 'R') rCount++;
            else if (S.charAt(i) == 'G') gCount++;
            else bCount++;
        }

        long anti =0;
        for (int i = 0; i < S.length(); i++) {
            for (int j = i+1; j < S.length(); j++) {
                int k = 2 * j - i;
                if(k >= S.length()) continue;

                if(S.charAt(i) != S.charAt(j) && S.charAt(j) != S.charAt(k) & S.charAt(i) != S.charAt(k)) anti++;


            }
        }


        out.println(rCount * gCount * bCount - anti);





        in.close();
        out.close();
    }
}


Measured memory_bytes: 37644
import java.util.Scanner;
import java.io.*;

public class Main{
	public static void main(String args[]){
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		try{
			while(1>0){
				String line=reader.readLine();
				if(line.equals("."))break;
				int len=line.length();
				int flag=0;
				int[][] data;
				int[] rank_n;
				int rank=0;
				data=new int[120][120];
				rank_n=new int[120];
				for(int i=0;i<len;i++){
					if(rank<0 || flag==1)continue;
					String s=line.substring(i,i+1);
					if("(".equals(s)){
						rank_n[rank]++;
						data[rank][rank_n[rank]]=1;
						rank++;
					}
					if("[".equals(s)){
						rank_n[rank]++;
						data[rank][rank_n[rank]]=2;
						rank++;
					}
					if(")".equals(s)){
						rank--;
						if(rank<=-1)flag=1;
						else{
							if(data[rank][rank_n[rank]]==1)rank_n[rank]--;
							else flag=1;
						}
					}
					if("]".equals(s)){
						rank--;
						if(rank<=-1)flag=1;
						else{
							if(data[rank][rank_n[rank]]==2)rank_n[rank]--;
							else flag=1;
						}
					}
				}
				if(rank!=0)flag=1;
				System.out.printf("%s\n",flag==0?"yes":"no");
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 92036
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  int n = sz(s);

  set<char> st;
  st.insert('A');
  st.insert('C');
  st.insert('G');
  st.insert('T');

  int ans = 0;
  bool acgt = false;
  rep(i,n) {
    if (st.count(s[i])) {
      int cnt = 0;
      while (i < n && st.count(s[i])) {
        cnt++;
        i++;
      }
      chmax(ans, cnt);
    }
  }

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

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll X,N,a;
	while(cin>>X>>N) {
		map<ll, ll> h;
		REP(i, N) {
			cin>>a;
			h[a]=1;
		}
		ll ans=-100;
		RANGE(v, -10, 1000) {
			if(!h.count(v) && abs(v-X)<abs(ans-X)) ans=v;
		}
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int x, n;
    cin >> x >> n;
    map<int, bool> e;
    int p[n];
    rep(i, n) {
        cin >> p[i];
        e[p[i]] = true;
    }
    vector<P> v;
    for (int i = -200; i <= 200; i++){
        if (e[i]) continue;
        v.emplace_back(abs(x - i), i);
    }
    sort(ALL(v));
    cout << v[0].second << endl;
    return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>

int main(){
  int x = 0;
  int y = 0;
  int men = 0;
  int shui = 0;

  scanf("%d %d",&x,&y);
  men = x*y;
  shui =  2*(x+y);
  printf("%d %d\n",men,shui);

    return 0;
}

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

const int N = 110;

char s[N][N];
int n, m;

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++ i){
		scanf("%s", s[i] + 1);
	}
	for (int i = 0; i <= n + 1; ++ i){
		s[i][0] = s[i][m + 1] = '#';
	}
	for (int i = 0; i <= m + 1; ++ i){
		s[0][i] = s[n + 1][i] = '#';
	}
	for (int i = 0; i <= n + 1; ++ i){
		printf("%s\n", s[i]);
	}
	return 0;
}

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

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        String S;
        S = sc.next();
        String T;
        T = sc.next();
        long A;
        A = sc.nextLong();
        long B;
        B = sc.nextLong();
        String U;
        U = sc.next();

        final Solver solver = new Solver();
        solver.solve(S, T, A, B, U);
    }
}

class Solver {
    public void solve(String S, String T, long A, long B, String U) {
        long ansA = A;
        long ansB = B;
        if (U.equals(S)) {
            ansA--;
        }
        if (U.equals(T)) {
            ansB--;
        }
        System.out.println(String.format("%d %d", ansA, ansB));
    }
}



Measured memory_bytes: 21844
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    int n = s.size();

    bool ans = true;
    for (int i=0; i<n; i+=2) {
        if (s.substr(i,2) != "hi") ans = false;
    }

    cout << (ans? "Yes" : "No") << endl;
}

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

vector<vector<int>> d(200010,vector<int>(21,0));
vector<int> sum(20,0);

bool jud(int i){
  for(int j=0;j<20;j++){
    if(sum[j]>0&&d[i][j]>0){
      return true;
    }
  }
  return false;
}

int main(){
  int N; cin>>N;
  int A;
  for(int i=0;i<N;i++){
    cin>>A;
    for(int j=0;j<20;j++){
      d[i][j]=A%2; A/=2;
    }
  }
  ll lf=0,ans=0;
  for(ll i=0;i<N;i++){
    while(jud(i)){
      for(int j=0;j<20;j++){
        sum[j]-=d[lf][j];
      }
      lf++;
    }
    for(int j=0;j<20;j++)
      sum[j]+=d[i][j];
    
    ans+=(i+1-lf);
    //cout<<ans<<endl;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 25728
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		String word[] = str.split("");
		for(int i = 0; i < 12; i++) {
			System.out.print(word[i]);
			if (i == 3) System.out.print(" ");
		}
			System.out.println("");
	}
}

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

ll N, X;
ll two[52];

ll ans(ll n, ll x){
	if(n == 0){
		if(x == 0){
			return 0;
		}else{
			return 1;
		}
	}
	if(x == 2*two[n+1] - 3){
		return two[n+1] - 1;
	}else if(x > two[n+1]-1){
		return two[n] + ans(n-1, x-two[n+1]+1);
	}else if(x == two[n+1]-1){
		return two[n];
	}else if(x == 0){
		return 0;
	}else{
		return ans(n-1, x-1);
	}
}

int main(){
	cin >> N >> X;
	two[0] = 1;
	for(int i=1; i<N+2; i++){
		two[i] = two[i-1]*2;
	}
	cout << ans(N, X) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{ 
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in); 
		for(int count = 0; count<7; count++){
		int a = sc.nextInt();
		int b = sc.nextInt();
		int sa = a - b;
		System.out.println(sa);
		}
		
	}
	}	

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

signed main() {
  int K, A, B;
  cin >> K >> A >> B;
  
  int ans = 0;
  if( B-A <= 2 ||  K < A ){
    cout << K+1 << endl;
  }else{
    ans = A + ( (K-(A-1))/2 )*(B-A) + (K-(A-1))%2;
    cout << ans << endl;
  }
            
}


Measured memory_bytes: 256
#include <iostream>
 
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <random>
#include <chrono>

#include <cstdio>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
 
#define itn int
#define fro for
#define lowbit(x) (x & (-x))
#define Fast freopen("in.txt", "r", stdin)

using namespace std;
typedef long long ll;


/*------------------------------------------------------------------------------------*/
template <typename _t>
inline void read(_t &x){
    x = 0; _t fu = 1; char ch = getchar();
    while(ch < '0' || ch > '9'){if(ch == '-') fu = - 1; ch = getchar();}
    while(ch >= '0' && ch <= '9'){
        x = (x << 3) + (x << 1) + (ch & 15);
        ch = getchar();
    }
    x *= fu ;
}
/*------------------------------------------------------------------------------------*/
ll gcd(ll x, ll y){return !x? y: gcd(y % x, x);}
void exgcd(ll a, ll b, ll &x, ll &y){
    if(!b){x = 1; y = 0;return;}
    exgcd(b, a % b, y, x);
    y -= a / b * x;
}
/*------------------------------------------------------------------------------------*/
struct Mart{
    int a, b, c, d;
    Mart operator *(Mart &m){
        Mart temp;
        temp.a = a * m.a + b * m.c;
        temp.b = a * m.b + b * m.d;
        temp.c = c * m.a + d * m.c;
        temp.d = c * m.b + d * m.d;
        return temp;
    }
    Mart(){a = b = c = d = 0;}
    Mart(int x[4]){a = x[0]; b = x[1]; c = x[2]; d = x[3];}
    Mart(int u, int v, int w, int x){a = u; b = v; c = w; d = x;}
    int det(){return a * d - b * c;}
};
/*------------------------------------------------------------------------------------*/

//const int maxn = 1e4 + 10;


int main(){
//    Fast;
    int n, m; scanf("%d %d", &n, &m);
    int sum = 0;
    for(int i = 0, x; i < m; i++){
        scanf("%d", &x); sum += x;
    }
    printf(sum > n? "-1": "%d\n", n - sum);
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <algorithm>
typedef long long ll;
using namespace std;

int main() {
    int n;
    cin >> n;
    double a[n];
    for(int i=0; i<n; i++) cin >> a[i];
    sort(a, a+n);

    double ans=0;
    ans = (a[0] + a[1])/2;
    for(int i=2; i<n; i++) ans = (ans + a[i])/2;

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split()))
B = [0 for i in range(N+1)]
for i in range(1, N+1):
    B[1] += int(((-1)**(i-1))*A[i])
for i in range(1, N+1):
    if i == 1:
        print(B[i], end= ' ')
    else:
        B[i] = int(2*(A[i-1] - (1/2)*B[i-1]))
        if i != N:
            print(B[i], end = ' ')
        else:
            print(B[i])


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int N;
vector <int> GraphX[int(1e5+5)], GraphY[int(1e5+5)];
map <Pii, bool> mp;

ll ans, edge_cnt, x_cnt, y_cnt;
bool usedX[int(1e5+5)], usedY[int(1e5+5)];

int DFS(int num, bool flag){
  if (flag){
    for (int i = 0; i < GraphX[num].size(); i++){
      int next = GraphX[num][i];

      if (!mp[{num, next}]) edge_cnt++;
      mp[{num, next}] = true;

      if (usedY[next]) continue;
      usedY[next] = true; y_cnt++;
      DFS(next, false);
    }
  }else{
    for (int i = 0; i < GraphY[num].size(); i++){
      int next = GraphY[num][i];

      if (!mp[{next, num}]) edge_cnt++;
      mp[{next, num}] = true;

      if (usedX[next]) continue;
      usedX[next] = true; x_cnt++;
      DFS(next, true);
    }
  }
  return 0;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++){
    int x, y; cin >> x >> y;
    GraphX[x].push_back(y);
    GraphY[y].push_back(x);
  }

  for (int i = 0; i <= int(1e5); i++){
    if (usedX[i]) continue;
    edge_cnt = 0; x_cnt = 0; y_cnt = 0;
    DFS(i, true);
    if (x_cnt <= 1 || y_cnt <= 1) continue;
    ans += x_cnt * y_cnt - edge_cnt;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23612
M=2e6;char*s,T['   '],*r=T;U['dd`'];i;k;main(n){for(;gets(r+1);k=0)for(--n;*++r&=31;)U[r-T]=k|=!!n<<*r;for(;s>T||(s=r,i++-2);k=U[k]=U[k-=~-~*s*M]?:*s?s-T:0)n+=__builtin_popcount(U[--s-T]&(U[k+M]^=!s[-1]<<*s));printf("%d",n);}

Measured memory_bytes: 135236
#include<cstdio>
#include<cstdlib>
#include<cstring>

struct Node {
  int key;
  Node *next, *prev;	
};

Node *nil;

Node* listSearch(int key) {
	Node *cur = nil->next;
	while (cur != nil && cur->key != key) {
		cur = cur->next;
	}
    return cur;
}

void init() {
	nil = (Node *)malloc(sizeof(Node));
	nil->next = nil;
	nil->prev = nil;
}

void printList() {
	Node *cur = nil->next;
	int isf = 0;
	while(1) {
		if (cur == nil) break;
		if (isf++ > 0) printf(" ");
		printf("%d", cur->key);
		cur = cur->next;
	}
	printf("\n");
}

void deleteNode(Node *t) {
	if(t==nil) return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst() {
	deleteNode(nil->next);
}

void deleteLast() {
	deleteNode(nil->prev);
}

void deleteKey(int key) {
	deleteNode(listSearch(key));
}

void insert(int key) {
    Node *x = (Node *)malloc(sizeof(Node));
	x->key = key;
	x->next = nil->next;
	nil->next->prev = x;
 	x->prev = nil;
	nil->next = x;
    x->prev = nil;	
}

int main() {
	int key, n, i;
	int size = 0;
	char com[20];
    int np = 0, nd = 0;
	scanf("%d", &n);
	init();
	for(i=0; i<n; i++) {
		scanf("%s%d", com, &key);
		if(com[0] == 'i') {
			insert(key);
			np++;
			size++;
		} else if(com[0] == 'd'){
			if(strlen(com) > 6) {
				if(com[6] == 'F') deleteFirst();
				else if (com[6] == 'L') deleteLast(); 
			} else {
				deleteKey(key);
			}
			nd++;
			size++;
		}
	}
	
	printList();
    
	return 0;	
	
}

Measured memory_bytes: 33988
a, b = gets.split.map(&:to_i)
grid = []
100.times do
  x = []
  100.times do |i|
    x << (i < 50 ? '#' : '.')
  end
  grid << x
end
(a-1).times do |i|
  grid[(i/25)*2][(i%25)*2] = '.'
end
(b-1).times do |i|
  grid[(i/25)*2][(i%25)*2+51] = '#'
end
puts '100 100'
100.times do |i|
  puts grid[i].join
end

Measured memory_bytes: 4220
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int s = a*b;
		if(s%2==0) {
			System.out.println("Even");
		}
		else {
			System.out.println("Odd");
		}
}
}


Measured memory_bytes: 21716
Scanf.scanf "%d" (fun a ->
    let isprime a =
        let rec loop i =
            if i * i > a then true else
                if a mod i = 0 then false else
                    loop (i + 1)
        in
        loop 2
    in
    let rec loop k =
        if isprime k then k else loop (k + 1)
    in
    loop a |> Printf.printf "%d\n"
)

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

using namespace std;


int main(){
    int N, Pc, Qc;
    cin >> N;
    vector<int> i(N), P(N), Q(N);
    for(int n=0; n<N; n++){
        cin >> P[n];
    }
    for(int n=0; n<N; n++){
        cin >> Q[n];
    }
    iota(i.begin(), i.end(), 1);
    int count = 0;
    do{
        if(i==P){
            Pc = count;
        }
        if(i==Q){
            Qc = count;
        }
        count++;
    }while(next_permutation(i.begin(), i.end()));
 
    cout << abs(Pc - Qc) << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdlib>
#include<utility>
#include<tuple>
#include<string>
#include<vector>
#include<numeric>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
using namespace std;

int main() {

	int a, b, c;

	cin >> a >> b >> c;

	if (a == b && b == c && c == a) {
		cout << "No" << endl;
	}
	else if (a != b && b != c && c != a) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;
const int MAX =400010;
ll inv[MAX],fact[MAX],fi[MAX];
constexpr ll mod = 1000000007;
void inverse(){
	int i;
	inv[1] = 1;
	for(i=2;i<MAX;i++){
		inv[i] = mod - (mod/i)*inv[mod%i]%mod;
	}
	fact[0] = fi[0] = 1;
	for(i=1;i<MAX;i++){
		fact[i] = fact[i-1]*i%mod;
		fi[i] = (fi[i-1]*inv[i])%mod;
	}
}

ll comb(int n,int k){
	if(n<0 || k<0 || n<k){
		return 0;
	}else{
		return fact[n]%mod*fi[k]%mod*fi[n-k]%mod;
	}
}

int main(){
	ll i,n,k;
	cin >> n >> k;
	inverse();
	if(k>=n){
		cout << comb(2*n - 1,n) << endl;
	}else{
		ll ans = 0;
		for(i=0;i<=k;i++){
			(ans += comb(n,i)*comb(n - 1,i)%mod) %= mod;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 9600
import math

N = int(input())
ck = math.floor(N/4)
dk = math.floor(N/7)

c = 4
d = 7
result = False

for i in range(ck+1):
    for j in range(dk+1):
        if (N == c * i + d * j):
            result = True
            break

if result == True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9136
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define MAX 100100
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
int n,a[MAX];
int b[MAX],s;
vector<pair<int,int> > T;
int main()
{
	n=read();
	for(int i=1;i<=n;++i)a[i]=read();
	sort(&a[1],&a[n+1]);
	for(int i=2;i<n;++i)
		if(a[i]<0)b[i]=1;
		else b[i]=0;
	b[1]=1;b[n]=0;
	for(int i=2;i<n;++i)
		if(b[i])
		{
			T.push_back(make_pair(a[n],a[i]));
			a[n]-=a[i];
		}
		else
		{
			T.push_back(make_pair(a[1],a[i]));
			a[1]-=a[i];
		}
	T.push_back(make_pair(a[n],a[1]));
	printf("%d\n",a[n]-a[1]);
	for(auto a:T)printf("%d %d\n",a.first,a.second);
	return 0;
}


Measured memory_bytes: 3572
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cctype>
#define int long long 
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 4e3+5, P = 924844033;
int n, k;
int ille[N], t;
int f[N][N][2], fac[N];
int ans;
signed main()
{
    n = read(), k = read(); fac[0] = 1;
    for(int i = 1; i <= n; ++i) fac[i] = 1ll*fac[i-1]*i%P;
    for(int i = 1; i <= k; ++i)
    {
        int j = (n-i)/k+1;
        t += j; ille[t] = true;
        t += j; ille[t] = true;
    }
    f[1][0][0] = 1;
    for(int i = 1; i <= n<<1; ++i)
        for(int j = 0; j <= n; ++j)
        {
            f[i+1][j][0] = (f[i][j][0]+f[i][j][1])%P;
            if(!ille[i]) f[i+1][j+1][1] = f[i][j][0];
        }
    for(int i = 0; i <= n; ++i)
    {
        int g = 1ll*(f[n<<1][i][0]+f[n<<1][i][1])%P*fac[n-i]%P;
        if(i&1) ans = ((ans-g)%P+P)%P;
        else ans = (ans+g)%P;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 249472
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};

struct Prime {
    int n;
    vector<int> p;
    vector<bool> is_prime;
    Prime(int n): n(n), is_prime(n+1, true) {
        rep(i, n+1) {
            if (i<=1) {
                is_prime[i] = false;
                continue;
            }
            if (!is_prime[i]) continue;
            for (int j=2*i; j<=n; j+=i) {
                is_prime[j] = false;
            }
        }
        rep(i, n+1) {
            if (is_prime[i]) p.push_back(i);
        }
    }
};
const int MX = 100005;
int main(){
    int q;
    cin >> q;
    Prime pr(MX);
    vector<int> v;
    rep(i, MX) {
        if (i%2==0) continue;
        if (pr.is_prime[i] && pr.is_prime[(i+1)/2]) v.push_back(i);
    }
    rep(qi, q) {
        int l, r;
        cin >> l >> r;
        auto it1 = lower_bound(whole(v), l);
        auto it2 = upper_bound(whole(v), r);
        int ans = it2 - it1;
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    string S;
    cin >> S;
    int N = S.size();
    string s1 = S.substr(0, (N - 1) / 2), s2 = S.substr((N + 3) / 2 - 1), S1 = s1, S2 = s2;
    reverse(all(S1));
    reverse(all(S2));
    string S_ = S;
    reverse(all(S_));
    if (S == S_ and s1 == S1 and s2 == S2)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
S=input()
M=0
if len(S)%2==0:
    for i in range(len(S)//2):
        if S[i]!=S[len(S)-1-i]:
            M+=1
    print(M)
elif len(S)%2==1:
    for i in range((len(S)-1)//2):
        if S[i]!=S[len(S)-1-i]:
            M+=1
    print(M)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize(3,"Ofast","inline")
using namespace std;
inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')w=-1;ch=getchar();
	}
	while(ch>='0'&&ch<='9') 
		s=s*10+ch-'0',ch=getchar();
	return s*w;
}
#define maxn 1009
bool vis[maxn];
int a[maxn][maxn],dd[maxn];
signed main()
{
	int n,cnt=0;
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	{
		dd[i]=1;
		for (int j=1;j<n;j++)
			a[i][j]=read();
	}
	int ans=0;
	bool flag=1;
	while (flag)
	{
		ans++;
		bool vis[maxn]={};
		flag=0;
		for (int i=1;i<=n;i++)
		{
			int temp=a[i][dd[i]];
			if (dd[i]==n||vis[i]||vis[temp]||a[temp][dd[temp]]!=i||dd[temp]==n) continue;
			flag=1;
			vis[i]=vis[temp]=1;
			dd[i]++;
			dd[temp]++;
		}
	}
	for (int i=1;i<=n;i++)
		if (dd[i]!=n)
		{
			puts("-1");
			return 0;
		}
	printf("%lld\n",ans-1);
	return 0;
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define N 200010
const ll mod=1e9+7;
ll Sqrt(ll x)
{
    ll t=sqrt(x);
    if((t+1)*(t+1)<=x) return t+1;
    else if(t*t<=x) return t;
    else return t-1;
}

int main()
{
    ll s;
    cin>>s;
    ll x1=0,y1=0,x2,y2,x3,y3;

    x2=y3=Sqrt(s);
    if(x2*y3==s)
    {
        x3=0,y2=1;
    }
    else
    {
        x2++,y3++;
        s-=x2*y3;
        s=-s;

        x3=1;
        y2=s;

    }
    printf("%lld %lld %lld %lld %lld %lld\n",x1,y1,x2,y2,x3,y3);
    return 0;
}


Measured memory_bytes: 256
def compare(x, y): 
    for i in range(6):
        order = [0, 0, 0]
        for j in range(3):
            if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
                break
            if x[j] == y[z[i][j]]:
                order[j] = 1 
                if x[j] == x[-j-1]:
                    order[j] = 2 
        else:
            if 2 in order:
                return True
                break
            if z[i][3] in [0, 3] and sum(order) % 2:
                return True
                break
            if z[i][3] == 1 and not sum(order) % 2:
                return True
                break
    return False

n = int(input())
x = [[] for i in range(n)]
for i in range(n):
    x[i] = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]] 
different = True
for i in range(n):
    for j in range(i+1, n, 1): 
        if compare(x[i], x[j]):
            different = False
            break
    if not different:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 7764
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<int>>;
 
const double PI = 3.14159265358979323846;
/*Graph t;
void dfs(int v, int pv=-1){
    for(int vn: t[v]){
        if (vn == pv) continue;
        dfs(vn, v);
    }
}*/
int main() {
  ll n;
  cin >> n;
  ll k[n];
  rep(i,n)cin >> k[i];
  sort(k,k+n);
  ll z[n];
  z[0]=k[0];
  rep(i,n-1)z[i+1]=z[i]+k[i+1];
  ll ans=0;
  rep(i,n-1){
    if(z[i]*2<k[i+1])ans=i+1;
  }
  cout << n-ans << endl;
}


Measured memory_bytes: 1920
from sys import stdin
data = int(stdin.readline().rstrip())

list = [0]*10000
for x in range(1,10**2):
    for y in range(1, 10**2):
        for z in range(1, 10**2):
            a = x**2+y**2+z**2+x*y+y*z+z*x
            if a <= 10**4:
                list[a-1] += 1

for i in range(1,data+1):
    print(list[i-1])

Measured memory_bytes: 9184
(let* ((n (read))
       (a (make-array '(100001) :initial-element 0))
       (s 0)
       (q 0))
  ;; read
  (loop :for _ :from 1 :to n
        :do (let ((i (read)))
              (incf s i)
              (incf (aref a i))))
  (setf q (read))
  ;;
  (loop :for i :from 1 :to q
        :do (let ((b (read))
                  (c (read)))
              (incf (aref a c) (aref a b))
              (incf s (* (aref a b) (- c b)))
              (format t "~A~%" s)
              (setf (aref a b) 0))))


Measured memory_bytes: 77852
#include <iostream>
#include <math.h>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,T;
  cin>>N>>T;
  int t[N];
  REP(i,N)cin>>t[i];
  lint ans=T;
  REP(i,N-1){
    if(t[i+1]-t[i]<T)ans+=t[i+1]-t[i];
    else ans+=T;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024