akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n;
int flag;
string a;
map<string,int>mp;

int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n;
    mp.clear();
    flag=1;
    cin>>a;n--;
    mp[a]=1;
    char s=a[a.length()-1];
    while(n--)
    {
        cin>>a;
        if(mp[a]==1){flag=0;}
        if(s!=a[0]){flag=0;}
        mp[a]=1;
        s=a[a.length()-1];
    }
    if(flag) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(a>=b){swap(a,b);}
    if(b>=c){swap(b,c);}
    if(a>=b){swap(a,b);}
    cout<<a<<" "<<b<<" "<<c<<endl;
}


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

using namespace std;
typedef long long ll;

ll num_digit(ll n){
    ll nd = 0;
    for(nd = 0; n > 0; ++nd){
        n /= 10;
    }
    return nd;
}

ll sn(ll n){
    ll ret = 0;
    while(n > 0){
        ret += n % 10;
        n /= 10;
    }
    return ret;
}

ll f(ll x){
    ll nd = num_digit(x);
    ll min_n = x;
    ll min_sn = sn(x);
    ll d10 = 1;
    for(ll d = 0; d <= nd + 1; ++d, d10 *= 10){
        ll x2 = d10 * (x / d10 + 1) - 1;
        if(x2 <= x){ continue; }
        ll sx2 = sn(x2);
        if(min_n * sx2 > x2 * min_sn){
            min_n = x2;
            min_sn = sx2;
        }
    }
    return min_n;
}

int main(){
    ll k;
    cin >> k;

    ll x = 1;
    for(int i = 0; i < k; ++i, x = f(x + 1)){
        cout << x << endl;
    }
    return 0;
}


Measured memory_bytes: 504
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std;

ll a,b;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
    freopen("out","w",stdout);
#endif
  cin>>a>>b;
  if(abs(a-b)<=1){
    cout<<"Brown"<<"\n";
  }else{
    cout<<"Alice"<<"\n";
  }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

const int MAXN = 1e2 + 2, V = 1e5 + 5;
int w[MAXN], v[MAXN], dp[MAXN][V];
int n, W;

void input();
void solve();

int main() {
	ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
	input();
	solve();
	return 0;
}

void input() {
	cin >> n >> W;
	for (int i = 0; i < n; i++)
		cin >> w[i] >> v[i];
}

void solve() {
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	for (int i = 1; i <= n; i++)
		for (int j = 0; j < V; j++) {
			if (j >= v[i - 1] && dp[i - 1][j - v[i - 1]] + w[i - 1] <= W && dp[i - 1][j - v[i - 1]] <= W)
				dp[i][j] = dp[i - 1][j - v[i - 1]] + w[i - 1];
			dp[i][j] = min(dp[i][j], dp[i - 1][j]);
			//if (dp[i][j] <= W)
			//	cout << i << " " << j << endl;
		}
	for (int i = V - 1; i >= 0; i--)
		if (dp[n][i] <= W) {
			cout << i << endl;
			return;
		}
}


Measured memory_bytes: 40064
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

from math import ceil

n, k = na()
a = na()

print(ceil((n - 1) / (k - 1)))

Measured memory_bytes: 13876
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int M = sc.nextInt();
    	int Lin = 0;
    	int Rin = Integer.MAX_VALUE;
    	for (int i = 0; i < M; i++) {
    		int L = sc.nextInt();
    		int R = sc.nextInt();
    		if (Lin < L) {
    			Lin = L;
    		}
    		if (R < Rin) {
    			Rin = R;
    		}
    	}
    	System.out.println(Lin <= Rin ? Rin - Lin + 1 : 0);
    }
}

Measured memory_bytes: 63396
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll N,M;
  cin>>N>>M;
  priority_queue<ll> data;
  for(ll i=0;i<N;i++){
    ll tmp;
    cin>>tmp;
    data.push(tmp);
  }
  for(ll i=0;i<M;i++){
    ll tmp=data.top();
    data.pop();
   
    tmp=tmp/2;
    data.push(tmp);
  }
  ll ans=0;
  for(ll i=0;i<N;i++){
    ans+=data.top();
    data.pop();
  }
  cout<<ans<<endl;

}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#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 INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
ll num[100005];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,m;cin >> n >> m;
  rep(i,m){
      ll l,r;cin >>  l >> r;
      l--;
      num[l]++;
      num[r]--;
  }
  FOR(i,1,n){
      num[i] += num[i-1];
  }
  ll ans = 0;
  rep(i,n){
      if(num[i]==m)ans++;
  }
  cout << ans << endl;

}

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

public class Main {
	static FastReader in = new FastReader();

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

	static void solve() {
		long a = in.nextLong(), b = in.nextLong(), c = in.nextLong(), d = in.nextLong();
		
		long fin1 = Math.max(a * c, a * d);
		long fin2 = Math.max(b * c, b * d);
		System.out.println(Math.max(fin1, fin2));
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}

		int[] readarr(int abc) {
			int[] temp = new int[abc];
			for (int i = 0; i < abc; i++)
				temp[i] = nextInt();
			return temp;
		}
	}
}


Measured memory_bytes: 25396
/*
...........__________    							 |										    ___  __
.............|       |     						     |											 |   /
.............|       |     						     |									  		 |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
.........  __|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int 				long long
#define ull 				unsigned long long int
#define ld 					long double
#define vi 					vector<int>
#define vii 				vector<pair<int,int>>
#define vvi 				vector<vector<int>>
#define pf 					push_front
#define popb 				pop_back
#define pb 					push_back
#define eb 					emplace_back
#define pii 				pair<int,int>
#define prec(x) 			fixed<<setprecision(15)<<x
#define all(x) 				x.begin(),x.end()
#define rall(x) 			x.rbegin(),x.rend()
#define mset(a,b) 			memset(a,b,sizeof(a))
#define mcpy(a,b) 			memcpy(a,b,sizeof(a))
#define fo0(i,n) 			for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n) 			for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b) 			for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)			for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)			for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
#define inf 1e18
const int mod=1e9+7;
const int N=4e5+10;

void raushan_kumar(){
	string s;cin>>s;
	fo0(i,s.length()){
		s[i]='x';
	}
	cout<<s;
}

int32_t main()
{
	
	fast;int t=1;
	//cin>>t;
	while(t--){
		raushan_kumar();
	}

}

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

void swap(int &x, int &y) {
  int t = x;
  x = y;
  y = t;
}

int x[200];

int main() {
  int ans = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  for (int i = 0; i < n - 1; i++) {
    for (int j = n - 1; j >= i + 1; j--) {
      if (x[j - 1] > x[j]) {
        swap(x[j - 1], x[j]);
        ans++;
      }
    }
  }
  for (int i = 0; i < n - 1; i++) {
    cout << x[i] << " ";
  }
  cout << x[n - 1] << endl;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3088
import java.util.*;
public class Main{
    static Scanner kbd = new Scanner(System.in);
    public static void main(String[] args){
	int[] p = new int[1000000];
	setP(p);
	while(kbd.hasNext()){
	    int n = kbd.nextInt();
	    if(n!=0) solve(p, n);
	}
    }

    static void solve(int[] p, int n){
	int sum=0, i;
	for(i=0; p[i]<=n; i++){
	    if(p[i]!=-1) {
		sum+=i;
		//System.out.println(i);
	    }
	}

	System.out.println(sum);
    }

    static void setP(int[] p){
	int a=1, i, j;
	Arrays.fill(p, 1);
	p[0] = -1;
	p[1] = -1;
	for(i=2; i<p.length; i++){
	    if(p[i] == 1){
		//System.out.println(i+" "+a);
		p[i] = a;
		a++;	
	    }
	    for(j=i+i; j<p.length; j+=i){
		p[j] = -1;
	    }
	}
    }
}

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

int main()
{
	int a,b;
	cin >> a >>b;
	
	if (a < b){
		cout <<"a < b" <<endl;
	}if (a > b){
		cout <<"a > b" <<endl;
	}if (a == b){
		cout <<"a == b"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include <cstdio>
#include <algorithm>

int main() {
    int T[100000];
    int N, C, K;
    scanf("%d %d %d", &N, &C, &K);
    for (int i = 0; i < N; i++) 
        scanf("%d", &T[i]);
    if (K == 1) {
        printf("%d\n", N);
        return 0;
    }
    std::sort(T, T + N);
    int th1 = T[0], sum = 0;
    int th2 = 0;
    for (int i = 0; i < N; i++) {
        if ((T[i] - th1) > K) {
            sum++;
            th1 = T[i];
            th2 = i;
        }
        else if ((i - th2) >= C) {
            sum++;
            th1 = T[i];
            th2 = i;
        }
    }

    printf("%d\n", sum + 1);
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <sstream>
#include <string>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cmath>

using namespace std;
typedef long long ll;

bool isPali(ll N){
  stringstream ss;
  ss<<N;
  string s=ss.str();
  for(int i=0;i<(int)s.size();i++)
    if(s[i]!=s[(int)s.size()-1-i])
      return false;
  return true;
}

int main(){
  ll N;
  cin>>N;
  ll res=-1;
  for(int i=1;i<=100000;i++){
    if(isPali(i)){
      if(abs(res-N)>abs(i-N)){
        res=i;
      }
    }
  }
  cout<<res<<endl;
  

  return 0;
}

Measured memory_bytes: 1216
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;  //to use policy based data structures like indexed_set  "never used yet !! "
#define vi vector<int>
#define f first
#define s second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define ll unsigned long long int
#define test long int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
#define mm 1000000007

bool check_prime(long long n)
{
    int flag=0;
    for(long long i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            flag=1;
            break;
        }
    }
    if(n==1)
	   return false;
    else if(flag==0 || n==2 ||n==3)
    {
        return true;
    }
    else
    {
        return false;
    }

}

int binaryExponentiation(int x,int n)//function to calculate x raise to power n
{
    int result=1;
    while(n>0)
    {
        if(n % 2 ==1)
            result=result * x;
        x=x*x;
        n=n/2;
    }
    return result;
}

int main()
{
   ios_base::sync_with_stdio(false);
   cin.tie(NULL);
   cout.tie(0);
   #ifndef ONLINE_JUDGE
    if(fopen("INPUT.txt","r"))
    {
    freopen ("INPUT.txt" , "r" , stdin);
    freopen ("OUTPUT.txt" , "w" , stdout);
    }
 #endif
    //_______________________________-code starts-______________________________________________________________________________

int k;
cin>>k;
ll sum=0;
rep(i,1,k)
{
	rep(j,1,k)
	{
		rep(t,1,k)
		{
			sum+=__gcd(i,__gcd(j,t));
		}
	}
}
cout<<sum<<en;

  return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll dp[100001];
int cost(int * a,int i,int n)
{
  if(i==n-1)
    return 0;
  if(i>n-1)
  {
    return 1000000;
  }
  if(dp[i]!=-1)
  {
    return dp[i];
  }
  if(dp[i]==-1)
  {
    ll total=0;
    total+=min(abs(a[i+1]-a[i])+cost(a,i+1,n),abs(a[i+2]-a[i])+cost(a,i+2,n));
    dp[i]=total;
    return dp[i];
  }
}
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    dp[i]=-1;
  }
  cout<<cost(a,0,n);
}


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

using namespace std;
#define ll long long

ll INF = 1e9 + 7;
const int N = 1e4 + 7;

vector<bool> pm(N, false);

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

void getPrimes( vector<int> &primes)
{
    for(int i=2;i<N;i++)
    {
        if(!pm[i])
        {
            primes.push_back(i);
            for(int j = i; j<N; j+=i)
            {
                pm[j] = true;
            }
        }
    }
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin>>n;

    vector<int> primes;
    getPrimes(primes);

    vector<int> arr(n);
    for(int i=0;i<n;i++)
        {
            cin>>arr[i];
            //arr[i] = rand() % ( 1000000);
        }

    int ans = arr[0];
    for(int i=1; i<n;i++)
    {
        ans = gcd(ans, arr[i]);
    }

    if(ans > 1)
    {
        cout<<"not coprime"<<endl;
    }
    else
    {
        bool flag = true;
        unordered_set<int> hset;
        for(int j = 0; j<n; j++)
        {
            for(int i = 0; primes[i] * primes[i] <= arr[j]; i++)
            {
                if(arr[j] %primes[i] == 0)
                {
                    if(hset.find(primes[i]) != hset.end())
                    {
                        flag = false;
                        break;
                    }
                    hset.insert(primes[i]);
                        
                    while(arr[j]%primes[i] == 0)
                    {
                        arr[j] = arr[j]/primes[i];
                    }

                }
            }

            if(arr[j] > 1)
            {
                if(hset.find(arr[j]) != hset.end())
                {
                    flag = false;
                    break;
                }
                hset.insert(arr[j]);
            }

            if(!flag)
            {
                break;
            }
        }

        if(flag)
            cout<<"pairwise coprime"<<endl;
        else
            cout<<"setwise coprime"<<endl;
    }
    
}

Measured memory_bytes: 7116
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int N,i;
cin>>N>>i;
cout<<N-i+1<<endl;
//system("pause");
return 0;
}

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

using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

signed main() {
  IOS;
  int n, k;
  cin >> n >> k;
  cout << (k == 1 ? 0 : n-k) << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    DP = [[0 for i in range(3)] for j in range(N+1)]
    
    for i in range(N):
        a = list(map(int, input().split()))
        for x in range(3):
            for y in range(3):
                if x != y:
                    DP[i+1][y] = max(DP[i+1][y],DP[i][x]+a[y])
    print(max(DP[-1]))

if __name__ == "__main__":
    main()
    pass

Measured memory_bytes: 24384
let rec seq a b = if a >= b then [] else a :: seq (a+1) b

let sqrt_int x = int_of_float (sqrt (float_of_int x))

let rec sum_dig x b = if x <= 0 then 0 else x mod b + sum_dig (x/b) b

(*
 * `b >= sqrt(n)`
 * n = p*b + q, s = p + q
 * n = p*b + s - p
 * b = (n - s)/p + 1
 *)

let () =
  Scanf.scanf "%d %d" begin fun n s ->
    if n = s then n+1 else
    let b0 =
      seq 2 (sqrt_int n + 1) |> List.fold_left (fun v b ->
        match v with
        | Some _ -> v
        | None -> begin
          let s' = sum_dig n b in
          if s = s' then Some b else None
        end) None
    in
    match b0 with
    | Some b -> b
    | None -> begin
      seq 1 (sqrt_int n + 1) |> List.fold_left (fun v p ->
        if (n-s) >= p && (n-s) mod p = 0 && sum_dig n ((n-s)/p + 1) = s then
          Some ((n-s)/p + 1)
        else
          v
      ) None
    end |> function None -> -1 | Some b -> b
  end |> Printf.printf "%d\n"

Measured memory_bytes: 20736
# https://atcoder.jp/contests/abc068/tasks/arc079_b
# 重要な考察
# すべての要素がNを超えているとき、N回操作するすべての要素は-1される。
# つまりN*(K//N)回操作されたときに、すべての要素はN+K//N-1(=base)になってほしい
# 残りのK%N回の操作でこの数列がどう変化するかは愚直にシミュレーションしてもいいし、計算しても求まる

ra = range
enu = enumerate
K = int(input())
N = 50

base = N + K // N - 1
n_operate = K % N

ans = []
# はじめのK%N要素はbase-K%N-1となる
for _ in ra(K % N):
    ans.append(base + N - K % N + 1)

for _ in ra(N - K % N):
    ans.append(base - K % N)
print(N)
print(*ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 1e9+7;
const int N=2e5+9;
int main()
{
    FASTINOUT;
    int a,b;
    cin>>a>>b;
    cout<<(a*3+b)/2;
    return 0;
}


Measured memory_bytes: 256
let x = stdin.ReadLine() |> int64

// -1000 < A,B < 1000 なので全網羅で十分間に合うはず

let candidate = {-1000L..1000L} |> Seq.allPairs {-1000L..1000L}
candidate |> Seq.find (fun (a, b) -> pown a 5 - pown b 5 = x) |> fun (a, b) -> (string a, string b) |> fun (a, b) -> a + " " + b |> stdout.WriteLine 

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

int main() {

        string S;
        cin >> S;

        int ans;

        //n = m % 10;

        rep(i,2) {
                if (S == "SSS") {
                        ans = 0;
                        //cout << "Yes" << endl;
                }
                else if (S == "RRS" || S == "SRR") {
                        ans = 2;
                }
                else if (S == "RSS" || S == "SRS" || S == "SSR" || S == "RSR") {
                        ans = 1;
                }
                else ans = 3;
        }

        cout << ans << endl;

        return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T>
using vec = vector<T>;

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

int main(){
  int n;
  cin >>n;
  vec<int> d(n);
  REP(i,n) cin >>d[i];

  vec<int> num(101,0);
  REP(i,n) ++num[d[i]];

  int ans=0;
  REP(i,101){
    if(num[i] > 0) ++ans;
  }

  cout <<ans <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int A[N];
  for (int i = 0; i < N; ++i)
  {
    cin >> A[i];
  }
  int nowBtn = 1;	// 現在の点灯ボタン番号
  int tmpBtn = 0;	// 消灯するボタン番号保存用
  int cntPush = 0;	// 押下回数
  // ボタン2が点灯したら終了
  while(nowBtn != 2)
  {
    if(A[nowBtn - 1] == -1)
    {
      // 消灯済みボタンに戻ってきた時点でボタン2の点灯は不可能なので終了
      cout << -1 << endl;
      return 0;
    }
    tmpBtn = nowBtn - 1;	// 消灯するボタン番号を保存
    nowBtn = A[nowBtn - 1];	// 次に点灯するボタン番号を取得
    A[tmpBtn] = -1;			// 消灯したボタンは-1を代入
    ++cntPush;				// 押下数をカウント
  }
  cout << cntPush << endl;
  return 0;
}

Measured memory_bytes: 640
#include<stdio.h>

int main(){
  int x,y,r;

  scanf("%d",&x);
  scanf("%d",&y);

  if(x < y){
    r = x;
    x = y;
    y = r;
  }

  r = x % y;

  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }

  printf("%d\n",y);

  return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<vector>
using namespace std;
int main() {
	vector<long long int> v;
	long long int n;
	cin >> n;
	for (long long int i = 1; i <= n; i++) {
		if (i % 3 != 0 and i % 5 != 0) {
			v.push_back(i);
		}
	}
	long long int sum = 0;
	for (long long int i = 0 ; i < v.size(); i++) {
		sum += v[i];
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 11656
def solve(ab,i):
    return (ab - 1) // i
    
q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    if a > b:
        a, b = b, a
    ans = a - 1
    
    start_a = a + 1
    num = int((a * b) ** 0.5)
    while True:
        if solve(a*b, num) == solve(a*b, num + 1):
            break
        else:
            num += 1
    ans = num - 1
    ans += (solve(a*b, num) - 1)
    if a == b:
        ans += 1
    print(ans)


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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007

//ここから編集する
string rev(string s) {
    reverse(all(s));
    return s;
}

void solve(string s) {
    set<string> set1;
    rep(i, 0, s.size()) {
        string s1 = s.substr(0, i);
        string s2 = s.substr(i, s.size());
        set1.insert(s1 + s2);
        set1.insert(rev(s1) + s2);
        set1.insert(rev(s1) + rev(s2));
        set1.insert(s1 + rev(s2));

        set1.insert(s2 + s1);
        set1.insert(rev(s2) + s1);
        set1.insert(rev(s2) + rev(s1));
        set1.insert(s2 + rev(s1));
    }
//    cout << "case " << s << endl;
//    for (auto e : set1) {
//        cout << e << endl;
//    }

    cout << set1.size() << endl;
}


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


    int n;
    cin >> n;
    rep(i, 0, n) {
        string s;
        cin >> s;
        solve(s);
    }

    return 0;
}



Measured memory_bytes: 3240
n, d = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(n)]
ans = 0
def check(i, j):
  d2 = 0
  for k in range(d):
    d2 += (x[i][k] - x[j][k]) ** 2
  for j in range(d2 + 1):
    if j ** 2 > d2:
      return False
    if j ** 2 == d2:
      return True
  return False

for i in range(n):
  for j in range(i + 1, n):
    if check(i, j):
      ans += 1

print(ans)


Measured memory_bytes: 38512
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
d = {}
x = [0, 0]
k = 0
for ai in a:
    if ai in d:
        d[ai] += 1
    else:
        d[ai] = 1
    if d[ai] == 2 or d[ai] == 4:
        x[k] = ai
        k += 1
    if k == 2:
        break
print(x[0] * x[1])


Measured memory_bytes: 14244
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
    int N, X, Y;
    cin >> N >> X >> Y;
    X--;
    Y--;

    //vector<vector<int>> D(N,vector<int>(N,0))
    vector<int> A(N-1,0);

    for(int i=0; i<N-1; i++) {
        for(int j=i+1; j<N; j++) {
            int d;
            d = min(j-i, abs(X-i) + 1 + abs(Y-j));
            A[d-1]++;
        }
    }

    rep(k,N-1) cout << A[k] << endl;
}

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

#define say(obj) (cout << (obj) << endl)
#define endline (cout << endl)
#define all(container) (container).begin(), (container).end()
#define sortall(container) (sort((container).begin(), (container).end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
T getSum(std::vector<T>& v) {
	T ret = 0;
	for (T& x : v) ret += x;
	return ret;
}

template <typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;  return is;
}

template <typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second; return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;          return is;
}

template <typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " "; return os;
}

template <typename T>
ostream& operator << (ostream& os, const vector<vector<T>>& mat) {
	for (const vector<T>& m : mat)
		os << m << endl; return os;
}
template <typename S, typename T>
ostream& operator << (ostream& os, const pair<S, T>& p) {
	os << "{" << p.first << " : " << p.second << "}";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/

int main()
{
	ll X;
	cin >> X;

	ll m = 100;
	ll y = 0;
	while (true)
	{
		m *= 1.01;
		y++;
		if (m >= X) {
			say(y);
			break;
		}
	}

	return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1e9 + 7;



int main() {
    double l;
    cin>>l;
    printf("%f",l*l*l/27);
    cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double dp[3009][3009];
double ara[3000];
double n;
double call(int i,int t)
{
 //   cout<<i<<"  "<<t<<endl;
    if(i==n&&t>(n-t))return 1;
   // if(i==n&&t<=(n-t))return 0;
    //cout<<dp[i][t]<<"  KJDSF"<<endl;
    if(dp[i][t]!=-1)return dp[i][t];
    double inc,exc;
    inc=exc=0;
    inc=ara[i]*call(i+1,t+1);
    if(((n-i)+t-1)>(n-((n-i)+t-1)))
        exc=(1-ara[i])*call(i+1,t);
    double ans=inc+exc;
    dp[i][t]=ans;
    return ans;
}
int main()
{
    cout<<setprecision(10);

    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>ara[i];
    }
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=n;j++)
        {
            dp[i][j]=-1;
        }
    }
    double ans=call(0,0);
    cout<<ans<<endl;
}


Measured memory_bytes: 70912
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fast  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define w(t)            int t; cin>>t; while(t--)
const int mod = 1000000007;
bool comp(pair<ll,ll>& a, pair<ll,ll>& b)
{
    if(a.second == b.second)
    return a.first > b.first;
    else
    return b.second < a.second;
}
int main()
{
    fast
    ll n,q,b,c;
    cin>>n;
    ll a[n+1];
    vector<ll> cnt(100001,0);
    
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        cnt[a[i]]++;
    }

    ll sum =0;
    for(ll i=0;i<n;i++)
      {
          
          sum += a[i];
      }
     cin>>q;
    for(ll i=0;i<q;i++)
    {
      cin>>b>>c;
      ll s = cnt[b];
      ll p = cnt[c];
      sum = sum-(s*b)+(c*s);
      cnt[b]=0;
      cnt[c]=s+p;
      
      cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 4708
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	vi v(5);
	rep(i,0,5){
		cin>>v[i];
	}
	int k; cin>>k;
	sort(all(v));
	if(v[4]-v[0]>k) cout<<":(";
	else cout<<"Yay!";
	
	return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using  namespace std;
int main(){
	string s;
	cin>>s;
	int q=0;
	int l=s.size();
	for(int i=0;i<l/2;i++){
		if(s[i]!=s[l-i-1]) q++;
	}
	cout<<q<<"\n";
	return 0;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define pb push_back
#define mk make_pair
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef pair<int, pair<int, int> >piii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
const int inf = 1e9;
const LL INF = 1e18;
const int M = 1e9 + 7;
//__int128
const int maxn = 3e5;
char s[maxn];
int a[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	cin >> s;
	int n = strlen(s), m = 0;
	for(int i = 0; i < n; ){
		if(s[i] == 'A'){
			a[m++] = 1;
			++i;
		} else if(i < n - 1 && s[i] == 'B' && s[i + 1] == 'C'){
			a[m++] = 0;
			i += 2;
		} else {
			a[m++] = -1;
			++i;
		}
	}
	/*for(int i = 0; i < m; ++i){
		cout << a[i] << ' ';
	}
	cout << endl;*/
	LL t0 = 0, res = 0, t1 = 0, f = 0;
	for(int i = 0; i < m; ++i){
		if(a[i] == 1){
			if(t0){
				res += t0 * t1;
				t0 = 0;
			}
			++t1;
		} else if(a[i] == 0){
			if(t1 > 0) {
				++t0;
			}
		} else if(a[i] == -1){
			res += t0 * t1;
			t0 = t1 = 0;
		}
	}
	res += t0 * t1;
	cout << res << endl;
	return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vll = vector<long long>;

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

constexpr long long mod = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    ll x = 0, y = 0, z = 0;
    rep(i, n) {
        if (a[i] % 4 == 0) {
            x++;
        } else if (a[i] % 4 == 2) {
            y++;
        } else {
            z++;
        }
    }

    bool b = true;
    if (z - 1 <= x) {
        x -= (z - 1);
        if (y % 2) {
            if(x==0){
                b = false;
            }
        }
    }else{
        b = false;
    }

    if(b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
//________
#define pb        emplace_back
#define fi        first
#define se        second
#define ALL(x)    x.begin(),x.end()
#define err(...)  fprintf(stderr, __VA_ARGS__ )
#define show(x)   cerr << #x << ':' << (x) << endl
#define outl(x)   cout << (x) << '\n'
#define FAST()    cin.tie(0), ios::sync_with_stdio(false)
#define rep(i,n)     for(int i=0; i<(n); ++i)
#define reps(i,f,n)  for(int i=(f); i<=(n); ++i)
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
constexpr int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
typedef long long ll;
#define let const auto
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

typedef pair<ll,bool> pii;

int N;
pii a[100010];

signed main()
{
   FAST();
   cin >> N;
   rep(i, N) {
      cin >> a[i].fi;
   }

   sort(a, a+N, greater<pii>());
   const ll n = a[0].fi;

   for (int i=1; i<N; ++i) {
      int dif = n - a[i].fi;
      if (dif < a[i].fi) {
         a[i] = pii(dif, true);
      }
   }

   sort(a, a+N, greater<pii>());

   const pii &p = a[1];
   int c = p.fi;
   if (p.se) {
      c = n - c;
   }

   cout << n << ' ' << c << '\n';
}



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

#define F first
#define S second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define in(x) insert(x)
#define forr(i, a, b) for(int i = a;i <= b;i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define did_you_calis_enough ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define int long long

using namespace std;

const int INF =  4294967295;
const int  N = 2e6 + 667;
const int mod = 1e9 + 7;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double PI = acos(-1.0);


main() {
	did_you_calis_enough
	int n = 3,mx = 0, cnt = 0;
	for(;n--;){
		char t;cin >> t;
		cnt = (t == 'R') ? cnt + 1 : 0;
		mx = max(mx, cnt);
	}
	cout << mx;
}

//Coded by LoliThief

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

#define FOR(i,a,b) for (ll i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (ll i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
ll INF = LLONG_MAX;
 
using vc = vector<char>;
using vi = vector<ll>;

vi tree;

void modify(ll i, ll v) {
    i += tree.size()/2;
    tree[i] = v;
    for (i /= 2; i >= 1; i /= 2) tree[i] = tree[2*i] + tree[2*i+1];
}

ll query(ll a, ll b) {
    a += tree.size() / 2; b += tree.size() / 2;
    ll s = 0;
    while (a <= b) {
        if (a % 2 == 1) s += tree[a++];
        if (b % 2 == 0) s += tree[b--];
        a /= 2; b /= 2;
    }
    return s;
}

vi XS, HS;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll N, D, A; cin >> N >> D >> A;

    tree.resize(2 * N);
    XS.resize(N);
    HS.resize(N);

    vi perm (N);

    F0R(i, N) {cin >> XS[i] >> HS[i]; perm[i] = i;}

    sort(perm.begin(), perm.end(), [] (const ll& lhs, const ll& rhs) {
        return XS[lhs] < XS[rhs];
    });

    ll previous = 0;
    F0R(i, N) {
        
        ll p = perm[i];
        modify(i, HS[p] - previous);
        previous = HS[p];
    }

    // cout << "BEFORE: " << query(0, 0) << " " << query(0, 1) << " " << query(0, 2) << endl;
    
    ll count = 0;
    F0R(i, N) {
        ll p = perm[i];
        if (query(0, i) <= 0) continue;
        
        ll l = 0;
        ll h = N - 1;
        while (l < h) {
            ll m = l + (h - l + 1) / 2;
            // cout << "BIN: " << l << " " << m << " " << h << endl;
            if (XS[perm[m]] > XS[p] + 2 * D) {
                h = m - 1;
            } else {
                l = m;
            }
        }

        ll uses = query(0, i) / A + (query(0, i) % A != 0);
        count += uses;
        modify(i, query(i, i) - uses * A);
        if (l + 1 < N) modify(l+1, query(l+1, l+1) + uses * A);
        // cout << i << " " << uses << " " << l << endl;
        // cout << query(0, 0) << " " << query(0, 1) << " " << query(0, 2) << endl;
    }

    cout << count << endl;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;

  if (A + B > C + D) {
    cout << "Left" << endl;
  }
    else if (A + B < C + D) {
      cout << "Right" << endl;
    }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
const int mod = (int)1e9 + 7;

int mult(int a, int b) {
    return (1LL * a * b) % mod;
}

int pw(int a, int b) {
    if (b == 0) return 1;
    if (b & 1) return mult(a, pw(a, b - 1));
    int res = pw(a, b / 2);
    return mult(res, res);
}

int sub(int a, int b) {
    int s = a - b;
    if (s < 0) s += mod;
    return s;
}

int sum(int a, int b) {
    int s = a + b;
    if (s >= mod) s -= mod;
    return s;
}

const int maxN = (int)1e3 + 100;

int fact[maxN], invfact[maxN], inv[maxN];

void init() {
    inv[1] = invfact[1] = invfact[0] = fact[0] = fact[1] = 1;
    for (int i = 2; i < maxN; i++) {
        fact[i] = mult(fact[i - 1], i);
        inv[i] = mult(inv[mod % i], mod - mod / i);
        invfact[i] = mult(invfact[i - 1], inv[i]);
    }
}

int cnk(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return mult(fact[n], mult(invfact[k], invfact[n - k]));
}

int invNumber(int a) {
    return pw(a, mod - 2);
}
int n;
int dp[maxN][maxN];
int a, b, c, d;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    init();
    cin >> n >> a >> b >> c >> d;
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int sz = 0; sz <= n; sz++) {
            if (!dp[i][sz]) continue;
            int coef = 1;
            for (int j = 0; j * (i + 1) <= (n - sz); j++) {
                if (!(a <= i + 1 && (i + 1) <= b) && j > 0) break;
                if (j == 0 || (c <= j && j <= d)) {
                    dp[i + 1][sz + j * (i + 1)] = sum(dp[i + 1][sz + (j * (i + 1))], mult(dp[i][sz], coef));
                }
                coef = mult(coef, invfact[i + 1]);
                coef = mult(coef, inv[j + 1]);
            }
        }
    }
    cout << mult(fact[n], dp[n][n]);
    return 0;
}

Measured memory_bytes: 4608
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    std::string s;
    std::cin >> s;

    std::string ans;
    if(s == "A"){
        ans = "T";
    }else if(s == "T"){
        ans = "A";
    }else if(s == "C"){
        ans = "G";
    }else{
        ans = "C";
    }

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


Measured memory_bytes: 256
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.8.2)

import math
import statistics
import numpy as np
import queue
import itertools
import functools 

n = int(input())
print(0 if n % 1000 == 0 else 1000 - (n % 1000))


Measured memory_bytes: 27224
#include <bits/stdc++.h>
using namespace std;
int n, m, ans;
string s, t;
int dp[2][2010][2010];
int main()
{
	cin >> n >> m >> s >> t;
	memset(dp[1], -1, sizeof(dp[1]));
	for(int i = 0; i <= n; ++i)
	{
		for(int j = 0; j <= m; ++j)
		{
			bool get;
			if(i != n)
			{
				get = (s[i] == 'I');
				dp[get][i + 1][j] = max(dp[get][i + 1][j], dp[get ^ 1][i][j] + 1);
			}
			if(j != m)
			{
				get = (t[j] == 'I');
				dp[get][i][j + 1] = max(dp[get][i][j + 1], dp[get ^ 1][i][j] + 1);
			}	
			ans = max(ans, dp[1][i][j]);
		}
	}
		cout << ans << endl;
}

Measured memory_bytes: 34728
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;
    
    public static void main(String[] args) {
        int N = ni();
        int K = ni();
        int maxK = (N-1)*(N-2)/2;
        if (K > maxK) {
            so.println("-1");
            return;
        }
        
        boolean[][] g = new boolean[N+1][N+1];
        for (int i = 1; i < N; i++) {
            g[i][N] = g[N][i] = true;
        }
        
        int edgeToAdd = maxK - K;
        
        loop: for (int i = 1; i < N; i++) {
            for (int j = i+1; j < N; j++) {
                if (edgeToAdd <= 0) {
                    break loop;
                }
                g[i][j] = g[j][i] = true;
                edgeToAdd--;
            }
        }
        
        so.println(N*(N-1)/2 - K);
        for (int i = 1; i <= N; i++) {
            for (int j = 1; j <= N; j++) {
                if (i > j && g[i][j]) {
                    so.println(i + " " + j);
                }
            }
        }
    }
    
    static class Task implements Comparable<Task>{
        public int cost;
        public int due;
        public Task(int cost, int due) {
            this.cost = cost;
            this.due = due;
        }
        @Override
        public int compareTo(Task that) {
            return this.due - that.due;
        }
        
        @Override
        public String toString() {
            return "cost: " + cost + ", due: " + due;
        }
    }
    
    
    static int gcd(int m, int n) {
        if(m < n) return gcd(n, m);
        if(n == 0) return m;
        return gcd(n, m % n);
    }
    
    static long lcm(int m, int n) {
        return (long) m * (long) n / gcd(m, n);
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int offset) {
        long[] a = new long[offset + n];
        for (int i = 0; i < n; i++)
            a[offset + i] = nl();
        return a;
    }
}


Measured memory_bytes: 24148
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int N = input.nextInt();
        String S = input.next();
        String T = input.next();

        String result = "";

        for (int i = 0; i < N; i++){
            result += S.substring(i, i+1) + T.substring(i, i+1);
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 23892
package main

import (
  "fmt"
  "sort"
)

func main() {
  a := make([]int, 3)
  for i := 0; i < 3; i++ {
    fmt.Scan(&a[i])
  }
  sort.Sort(sort.Reverse(sort.IntSlice(a)))
  fmt.Println(a[0]*10 + a[1] + a[2])
}

Measured memory_bytes: 512
from collections import Counter
n = int(input())
e = list(map(int, input().split()))

if e[0] != 0:
  ans = 0
else:
  ce = Counter(e)
  sce = sorted(ce.items())
  # keyの数が連番であることを確認
  if sce[-1][0] != len(sce) - 1 or sce[0][1] != 1:
    ans = 0
  else:
    ans = 1
    pre = 1
    for i, j in sce:
      if pre != 1:
        ans = (ans * (pre ** j)) % 998244353
      pre = j
      
print(ans)


Measured memory_bytes: 21468
//
// Created by 绔ユ闃?on 2018/9/14.
//
#include <iostream>
using namespace std;
typedef long long ll;
const int N = 200010;
const ll MOD = 1000000007;
int h, w, a, b;
ll fac[N], inv[N];
void init() { //棰勫鐞嗛樁涔樺拰闃朵箻鐨勯€嗗厓
    fac[0] = inv[0] = 1;
    for (int i = 1; i < N; i++) {
        fac[i] = fac[i-1] * i %MOD;
    }
    inv[1] = 1;
    for (int i = 2; i < N; i++) {
        inv[i] = 1ll * (MOD - MOD/i) * inv[MOD%i] %MOD;
    }
    for (int i = 1; i < N; i++) {
        inv[i] = inv[i-1] * inv[i] %MOD;
    }
}
inline ll C(int n, int k) { //璁＄畻缁勫悎鏁癈(n,k)=n! / (k! * (n-k)!)
    return fac[n] * inv[k] %MOD * inv[n-k] %MOD;
}
int main() {
    init();
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for (int i = 1; i <= h-a; i++) {
        ans += 1ll * C(i+b-2, i-1) * C(h-i+w-b-1, h-i) %MOD;
        ans %= MOD;
    }
    cout << ans;
    return 0;
}


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

int main(){
    int A, B, C, K;
    int n = 0;

    std::cin >> A >> B >> C >> K;

    while(B <= A){
        B = B * 2;
        n++;
    }

    while(C <= B){
        C = C * 2;
        n++;
    }

    //debug print
    //std::cout << n << "\n";
    if(n <= K){
        std::cout << "Yes";
    }else{
        std::cout << "No";
    }

}

Measured memory_bytes: 3636
char s[65536],t[65536];
int n,i,r,w,c;
int main()
{
	for(;scanf("%d",&n),n;puts(s)){
		scanf("%s",s);
		for(i=0;i++<n;strcpy(s,t)){
			for(r=w=0;r<strlen(s);t[w++]=s[r],r+=c){
				for(c=0;s[r+c]==s[r];++c);
				for(sprintf(t+w,"%d\0",c);t[++w];);
			}
			t[w]=0;
		}
	}
	exit(0);
}

Measured memory_bytes: 500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int MAX = 1000000000;
int main(){
    int k, a, b;
    cin >> k >> a >> b;
    for (int i = k; i <= b;i += k){
        if(i >= a && i <= b){
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
}

Measured memory_bytes: 3568