akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back

using namespace std;
int n;
vector<int>vec;
void input();

void solve(){
    unordered_map<int,int>f;
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            for(int k=1;k<=100;k++){
                int res = i*i+j*j+k*k+i*j+j*k+i*k;
                f[res]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout<<f[i]<<"\n";
    }
}

void Clear(){

}

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

    input();
    solve();
    Clear();
}

void input(){
    cin>>n;

}


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

int main()
{
  int N, X;
  int L[101];
  int dist=0;
  cin >> N >> X;

  rep(i,N) cin >> L[i];

  int cnt=1;
  rep(i,N){
    dist += L[i];
    if(dist > X) break;
    cnt++;
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <string>
#include <string.h>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t int64;
typedef int64_t ll;

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

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

using namespace std;

class D {
	int n, c;
	vector<vector<int>> d;
	vector<vector<int>> info;
public:
	D()
	{
		cin >> n >> c;

		d.resize(c, vector<int>(c));
		REP(i, c)
			REP(j, c)
			cin >> d[i][j];

		info.resize(3, vector<int>(c, 0));
		int inp;
		REP(i, n)
			REP(j, n)
		{
			cin >> inp;
			++info[(i + j) % 3][--inp];
		}
	}

	void debug()
	{
		REP(i, 3)
		{
			REP(j, c)
				cout << info[i][j] << " ";
			cout << endl;
		}
	}

	void solve()
	{
		ll ans{ 9223372036854775807 };

		REP(col_0, c)
		{
			ll val_0{ 0 };
			REP(i, c)
				val_0 += (ll)info[0][i] * d[i][col_0];

			REP(col_1, c)
			{
				if (col_1 == col_0)
					continue;

				ll val_1{ 0 };
				REP(i, c)
					val_1 += (ll)info[1][i] * d[i][col_1];

				REP(col_2, c)
				{
					if (col_2 == col_0 || col_2 == col_1)
						continue;

					ll val_2{ 0 };
					REP(i, c)
						val_2 += (ll)info[2][i] * d[i][col_2];

					chmin(ans, val_0 + val_1 + val_2);

				}
			}
		}

		cout << ans << endl;
	}
};


int main()
{
	D solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize "trapv"
#include<bits/stdc++.h>
#define ll long long int
#define fab(a,b,i) for(int i=a;i<b;i++)
#define pb push_back
#define db double
#define mp make_pair
#define endl "\n"
#define f first
#define se second
#define all(x) x.begin(),x.end()
#define MOD 1000000007
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main()
{ quick;


    {
        int n;
        cin>>n;
        ll mat[n][3];
        fab(0,n,i)
        {
            fab(0,3,j)
            cin>>mat[i][j];
        }
        ll dp[n][3];
        memset(dp,0,sizeof(dp));
        fab(0,3,i)
        dp[0][i]=mat[0][i];
        fab(1,n,i)
        {
            fab(0,3,j)
            {
                fab(0,3,k)
                {
                    if(k!=j)
                    dp[i][j]=max(dp[i][j],dp[i-1][k]+mat[i][j]);
                }
                
            }
            

        }
        cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
    }
    
    

 cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
    return 0;
}

Measured memory_bytes: 8428
from collections import deque
def bfs(start, g, visited):
    q = deque([start])
    visited[start] = 0
    while q:
        curr_node = q.popleft()
        for next_node in g[curr_node]:
            if visited[next_node] >= 0: continue
            visited[next_node] = visited[curr_node] + 1
            q.append(next_node)
    

def main():
    n,u,v = map(int, input().split())
    gl = [ [] for _ in range(n+1)]
    visited_u = [-1] * (n+1)
    visited_v = [-1] * (n+1)
    for i in range(n-1):
        a, b = map(int, input().split()) 
        gl[a].append(b)
        gl[b].append(a)
    bfs(u, gl, visited_u)
    bfs(v, gl, visited_v)

    # print(visited_u)
    # print(visited_v)

    # target_i = 0
    # max_diff_v = 0
    ans = 0
    for i in range(1,n+1):
        if visited_u[i] < visited_v[i] and visited_v[i]:
            # if (visited_v[i]-visited_u[i])%2 == 0:
            val = visited_v[i]-1
            ans = max(ans,val)
            # else:
                # val = visited_v[i]
                # ans = max(ans,val)
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 89504
#include <stdio.h>

void printarray(int array[],int n){
	int i;
	for(i=0;i<n;++i){
		if(i)printf(" ");
		printf("%d",array[i]);
	}
	printf("\n");
}

int main(void){
	int n,i,j,key;
	int array[100];
	scanf("%d",&n);
	
	for(i=0;i<n;++i)
		scanf("%d",&array[i]);
  printarray(array,n);		
	for(i=1;i<n;++i){
		key = array[i];
		j=i-1;
		while(j>=0&&array[j]>key){
			array[j+1] = array[j];
			j--;
		}
		array[j+1] = key;
		printarray(array,n);
	}
	return 0;
}

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

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for i in 1..100000 {
        if i * 108 / 100 == n {
            ans = i ;
            break;
        }
    }

    if ans <= 0 {
        println!("{}", ":(");
    }else{
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
n, k = map(int, input().split())
if n < 2*k-1:
  print(-1)
else:
  A1 = [k+i for i in range(n)]
  A2 = [k+n+i for i in range(n)]
  A3 = [k+2*n+i for i in range(n)]
  l = (n+1)//2
  for i in range(l):
    print(A1[l-1-i], A2[i*2], A3[i])
  for i in range(n-l):
    print(A1[n-1-i], A2[i*2+1], A3[l+i])

Measured memory_bytes: 17064
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64


int main(){
    llong k;
    cin >> k;
    cout << 50 << endl;
    llong a,b;
    a= k / 50;
    b=k%50;
    REP(i,b) cout << 49 + a + 50 - (b - 1) << " ";
    REP(i,50-b) cout << 49 + a - b << " ";
    cout <<endl;
}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	bool f = false;
	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		if (t % 2 == 1) {
			f = true;
		}
	}

	if (f) {
		cout << "first" << endl;
	} else {
		cout << "second" << endl;
	}

	return 0;
}

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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> cnt;
  for(int i=0, x; i<n; i++){
    cin >> x;
    cnt[x]++;
    cnt[x+1]++;
    cnt[x-1]++;
  }
  int ans = 0;
  for(auto x : cnt) ans = max(ans, x.second);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
const int MOD = 1000000007;

#define v_exists(elem, v) find(v.begin(),v.end(),elem)!=v.end()
#define s_exists(elem, s) s.find(elem)!=s.end()
#define mod_mul(x, y) x*y%MOD
#define mod_add(x, y) (x+y)%MOD
#define mod_sub(x, y) (x-y)%MOD
#define INF_INT 2147483647

long gcd(long a, long b) {
    return b == 0 ? a : gcd(b, a % b);
}

long lcm( long m, long n ){
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;

    return ((m / gcd(m, n)) * n);
}


long nCr(long n, long r){
    if(n==r || r==0){
        return 1;
    } else {
        return mod_add(nCr(n-1,r),nCr(n-1,r-1));
    }
}


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

    std::vector<long long> v;

    for(int i=0; i<N; i++){
        long long temp; cin >> temp;
        v.push_back(temp);
    }

    sort(v.begin(),v.end());

    long long ans = 9223372036854775807;
    for(int i=0; i+K-1<N; i++){
        ans = min(ans, v[i+K-1]-v[i]);
    }

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 1400
#include<stdio.h>

int min(int a,int b){
  if(a>b) return b;
  return a;
}

int main(void){
  int tmp,a,b,c,x,y,ans;
  scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
  if((a+b)<=2*c){
    ans=a*x+b*y;
  }else{
    tmp=min(x,y);
    ans=2*tmp*c+a*(x-tmp)+b*(y-tmp);
    if(tmp==x) tmp=2*y*c;
    else tmp=2*x*c;
    ans=min(ans,tmp);
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>

#define MOD 1e9+7;
#define INF 1e17+9;
#define PI acos(-1);

using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	int ans=0;
	
	if(a==b && b==c){
		ans=1;
	}else if(a!=b && b!=c && c!=a){
		ans=3;
	}else{
		ans=2;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};



int main(){
  int a;
  string s;
  cin >> a >> s;
  if(a>=3200) cout  << s << endl;
  else cout << "red" << endl;
}



Measured memory_bytes: 256
import math

A,B,H,M=map(int, input().split())


MM = M*6

HH = ((H*30) + (M/2))



rad = abs(MM-HH)

if rad >= 181:
    rad = 360 - rad

rad = math.radians(rad)

ans = math.sqrt((A**2 + B**2) - 2*A*B* math.cos(rad))

print(ans)



Measured memory_bytes: 9504
n = int(input())
l = [ int(x) for x in input().split() ]
l.sort()

if n < 3:
    print(0)
    exit()

c = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1,n):
            if l[i] != l[j] and l[j] != l[k] and l[i] != l[k]:
                if l[i]+l[j] > l[k]:
                    c += 1

print(c)


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

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { std::cout << #a << " = " << a << "\n"; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }
template<class T, class V> istream& operator>> (istream& ist, pair<T, V>& p) { return ist >> p.first >> p.second; }
template<class T> ostream& operator<< (ostream& ost, pair<T, T>& p) { return ost << p.first << ", " << p.second; }
template<class T> istream& operator>> (istream& ist, vector<T>& vs) { for(auto& e: vs) ist >> e; return ist; }

typedef long long ll;
int const inf = INT_MAX / 2;

int main() {
  int a, b; cin >> a >> b;
  cout << (a % 10 == a && b % 10 == b ? a * b : -1) << endl;
}


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

int main(){
  int n,a,b,c,N;
  int matrix[110][110];
  int sum[110],Min;
  map<int,bool> index;
  while(cin >> n && n){
    index.clear();
    for(int i=0;i<110;i++)for(int j=0;j<110;j++)matrix[i][j] = i==j?0:1<<20;
    for(int i=0;i<n;i++){
      cin >> a >> b >> c;
      index[a] = true;
      index[b] = true;
      matrix[a][b] = matrix[b][a] = c;
    }
    N = index.size();
    for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)matrix[i][j] = min(matrix[i][j],matrix[i][k]+matrix[k][j]);
    Min=1<<22;
    for(int i=0;i<N;i++){
      sum[i]=0;
      for(int j=0;j<N;j++){
	sum[i]+=matrix[i][j];
      }
      Min = min(Min,sum[i]);
    }
    for(int i=0;i<N;i++){
      // cout << sum[i] << endl;
      if(Min == sum[i]){
	cout << i << " " << sum[i] << endl; 
	  break;
      }
    }

  }
  return 0;
}

Measured memory_bytes: 1248
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# 本番中には解けなかった。解説pdfにある3つの場合分けはできた。
# B個の購入を可能なかぎりしたあとの個数が、「Cより大きくBより小さい」値に
# なることがあるとNoになる、ということには気づいたのだが、
# どう解いてよいか混乱して手がつけられなかった
#
#
# 解説pdf https://img.atcoder.jp/agc026/editorial.pdf を見た
#
# B個の購入を行った直後の個数の遷移を、mod Bの世界で考える。
#   最初は A mod B個。
#   B個の購入を可能な限り行った後も A mod B個で変わらず。
#   D個入荷すると    (A + D) mod B個。
# つまり、入荷するたびに、
# A からスタートして (A + D) mod B, (A + 2D) mod B, ... と遷移していく。
# 
# 遷移を無限に繰り返すと、mod Bの世界でのとりうる値は、g = gcd(B, D)として
#   (A % g), g + (A % g), 2g + (A % g), ..., kg + (A % g) (kは、kg + (A % g)がB未満となる最大の整数) のどれかとなる。
# ここでkを直接求めるのは難しい。
# かわりに、mを整数として、mg + (A % g)が最初にB以上となるのを求めるのは簡単で、それは B + (A % g)。
# これよりひとつ分小さいのは、B + (A % g) - gで、これが kg + (A % g)に等しい。
# 
# (A % g) + B - g が、C を超える場合、次に入荷が行われない。次もBを引くと個数が負になってしまうので No。
# (A % g) + B - g が、C 以下の場合、次に入荷が行われる。Yes。
#
#
# 解説PDFの、「また，(B/g − 1) × inv(D/g, B/g) 回 D を足したときにこの上界が達成できます」
# については理解できていない。
#



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def solve(A, B, C, D):
    if B > A:
        return "No"
    if B > D:
        return "No"
    if B <= C:
        return "Yes"

    g = gcd(B, D)
    if B - g + (A % g) > C:
        return "No"
    else:
        return "Yes"


T = int(input())
for t in range(T):
    A, B, C, D = map(int, input().split())
    print(solve(A, B, C, D))
    



Measured memory_bytes: 5548
import java.util.*

fun main(args: Array<String>){

    //var (N,M) = readLine()!!.split(" ").map{it.toInt()}
    var N = readLine()!!.toInt()
    var C = LongArray(N)
    var S = LongArray(N)
    var F = LongArray(N)

    for(i in 0 until N-1){
        var (ci,si,fi) = readLine()!!.split(" ").map{it.toLong()}
        C[i] = ci
        S[i] = si
        F[i] = fi
    }

    for(i in 0 until N-1){
        var time = 0L
        for(j in i until N-1){
            when(time <= S[j]){
                true -> time += (S[j] - time)
                false -> if(time % F[j] != 0L){
                    time += F[j] - (time % F[j])
                }
            }
            time += C[j]
        }
        println(time)
    }
    println("0")

}


Measured memory_bytes: 38668
//code by: @thesagniksaha
    #include<bits/stdc++.h>
    #include "chrono"
    #include "random"

    #define ll long long int
    #define mkp make_pair
    #define pb push_back
    #define ff first
    #define ss second
    #define makefast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    #define rep(i,n) for(int i=0;i<n;i++)
    #define repre(i,a,b)for(int i=a;i<=b;i++)
    #define clr1(arr) memset(arr,-1,sizeof(arr));
    #define clr0(arr) memset(arr,0,sizeof(arr));

    using namespace std;

    int main()
    {
        makefast
        ll a, b, c, d; cin >> a >> b >> c >> d;
        ll e, f, g, h, k;
        e = max(a,b); f = min(a,b); g = max(c,d); h = min(c,d);
        if(a>0 && b>0 && c>0 && d>0) cout << e*g << endl;
        else{
        k = max(max(a*c, b*c), max(a*d, b*d));
        cout << k << endl;}
        return 0;
    }

Measured memory_bytes: 3644
{-# LANGUAGE OverloadedStrings #-}
import Data.List
import Data.Ord
import Data.Char
import Data.Ratio
import Data.Maybe
import Data.String
import qualified Data.Text as T
import qualified Data.ByteString.Char8 as BS
---------------------------------------------------------------------------------
main = do
  list <- getIntListw'
  let ab = take 2 list
  let cd = drop 2 list
  print $ maximum [xy|x<-ab, y<-cd, let xy=x*y]
  
  
  
---------------------------------------------------------------------------------

{-ByteString関連-}
--IO
getLine' = BS.getLine
getContents' = BS.getContents
getLineList = BS.words <$> getLine'
getContentList = BS.words <$> getContents'
getInt' = fst . fromJust . BS.readInt <$> getLine'
getIntListw' = map (fst . fromJust. BS.readInt) .BS.words <$> getLine'
getIntListl' = map (fst . fromJust. BS.readInt) .BS.lines <$> getContents'
getInteger' = fst . fromJust. BS.readInteger <$> getLine'
putStr' = BS.putStr
putStrLn' = BS.putStrLn
--演算子
bs1 |++| bs2 = BS.append bs1 bs2
chr |:+| bs2 = BS.cons chr bs2
bs1 |+:| chr = BS.snoc bs1 chr

{-elem関連-}
--elemの第一引数をリストにしたもの。
--elemList "abc" "atcoder" -> [True,False,True]
elemList [] _ = []
elemList (x:xs) list  = elem x list : elemList xs list

--elemIndexの第一引数をリストにしたもの。
elemIndexList [] list = []
elemIndexList (x:xs) list  = elemIndex x list : elemIndexList xs list

--elemIndicesの第一引数をリストにしたもの。
elemIndicesList [] list = []
elemIndicesList (x:xs) list  = elemIndices x list : elemIndicesList xs list

--length . nubの代わり
count _ [] c = c
count [] (y:ys) c = count [y] ys (c+1)
count (x:xs) (y:ys) c
  |y==x = count (y:x:xs) ys c
  |y/=x = count (y:x:xs) ys (c+1)

Measured memory_bytes: 3804
H,W=gets.split.map(&:to_i)
N=gets.to_i
a=gets.split.map(&:to_i)
n=0
r=Array.new(H){Array.new(W)}
H.times{|h|
    W.times{|w|
        if h%2==1
            w=W-1-w
        end
        r[h][w]=n+1
        a[n]-=1
        if a[n]==0
            n+=1
        end
    }
}
#warn r.inspect
puts r.map{|a|a*" "}*"\n"


Measured memory_bytes: 14996
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const int INF = 2000000000;
using namespace std;

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

    map<int, int> m;
    rep(i,n){
        int a;
        cin >> a;
        m[a]++;
    }
    int cnt = 0;
    for(auto it = m.begin(); it != m.end(); it++){
        if((it->second - 1) % 2) cnt++;
    }
    if(cnt % 2) cout << m.size() - 1 << endl;
    else cout << m.size() << endl;
}


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

int main() {
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    int dx = tx - sx, dy = ty - sy;
    for (int i = 0; i < dx; i++) {
        cout << 'R';
    }
    for (int i = 0; i < dy; i++) {
        cout << 'U';
    }
    for (int i = 0; i < dx; i++) {
        cout << 'L';
    }
    for (int i = 0; i <= dy; i++) {
        cout << 'D';
    }
    for (int i = 0; i <= dx; i++) {
        cout << 'R';
    }
    for (int i = 0; i <= dy; i++) {
        cout << 'U';
    }
    cout << "LU";
    for (int i = 0; i <= dx; i++) {
        cout << 'L';
    }
    for (int i = 0; i <= dy; i++) {
        cout << 'D';
    }
    cout << 'R' << endl;
    return 0;
}


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

int main() {
  int x;
  cin>>x;
  if(x==2) cout<<2<<endl;
  else{
  bool con=true;
  while(con){
    int n=sqrt(x);
    for(int i=2;i<=n;i++){
      if(x%i==0){
        break;
      }
      else if(i==n){
        con=false;
        break;
      }
    }
    if(con) x++;
  }
  cout<<x<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int main() {
    int a; cin >> a;
    cout << (a%2 == 0 ? a: a*2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>

using namespace std;

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

  for (int i = 0; i < (int)S.size(); ++i) cout << "x";
}

Measured memory_bytes: 256
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define REP(i, n) for (int i = 0; i < n; i++)
const int MOD = 1e9 + 7;
typedef long long ll;
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

int main() {
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.Scanner;

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

//    	File file = new File("src/in.txt");
//    	Scanner sc = new Scanner(file);

    	Scanner sc = new Scanner(System.in);

    	Long A = sc.nextLong();
    	Long B = sc.nextLong();
    	Long N = sc.nextLong();
    	Long max = A*Math.min(B-1,N)/B;
    	System.out.println(max);
    }
}

Measured memory_bytes: 27004
K = int(input())
A = list(map(int,input().split()))
A.reverse()

for i in range(K):
    if i == 0:
        if A[i] != 2:
            print(-1)
            exit()
        else:
            m,M = 2,3
    else:
        m0 = m//A[i]
        M0 = M//A[i]
        if m0*A[i] >= m:
            m = m0*A[i]
        else:
            m = (m0+1)*A[i]
        M = (M0+1)*A[i]-1
        if m > M:
            print(-1)
            exit()

print(m,M)

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

#define df(b, e) ((b) > (e))
#define fore(i, b, e) for(auto i = (b) - df(b, e); i != e - df(b, e); i += 1 - 2 * df(b, e))
#define sz(x) (int) x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define pb push_back

typedef long long lli;
typedef long double ld;
typedef pair<int, int> ii;

template <class T>
struct rge { T b, e; };

template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}

template <class T> auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T> char dud(...);

struct debug {
#ifdef LOCAL
  ~debug() { cout << endl; }

  template <class T>
  typename enable_if<sizeof dud<T>(0) != 1, debug &>::type operator << (T i) {
    cout << boolalpha << i;
    return *this;
  }

  template <class T>
  typename enable_if<sizeof dud<T>(0) == 1, debug &>::type operator << (T i) {
    return *this << range(begin(i), end(i));
  }

  template <class A, class B>
  debug & operator << (pair<A, B> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }

  template <class T>
  debug & operator << (rge<T> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
      *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
#else
  template <class T> 
  debug & operator << (const T&) {
    return *this; 
  }
#endif
};

#define deb(...) " " << #__VA_ARGS__ ": " << (__VA_ARGS__) << " "

const int N = 1e3 + 5;
const lli mod = 1e9 + 7;

bitset<N> isp;
vector<int> primes;
int n;

lli factorialFactors(int n) {
  lli divs = 1LL;
  for (lli p: primes) {
    if (n < p)
      break;
    lli mul = 1LL, k = 0;
    while (mul <= n / p) {
      mul *= p;
      k += n / mul;
    }
    (divs *= (k + 1)) %= mod;
  }
  return divs;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  isp.set();
  fore (i, 2, N) if (isp[i]) {
    primes.pb(i);
    if (1LL * i * i < N)
      for (int j = i * i; j < N; j += i)
        isp[j] = 0;
  }
  while (cin >> n)
    cout << factorialFactors(n) << '\n';
  return 0;
}


Measured memory_bytes: 256
a, b = map(int,input().split())
if a > 0 and b > 0:
    print('Positive')
if a > 0 and b < 0:
    print('Zero')
if a < 0 and b > 0:
    print('Zero')
if a < 0 and b < 0:
    if (b-a) % 2 == 0:
        print('Negative')
    else:
        print('Positive')

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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]B - Traveling AtCoDeer Problem
            int n = int.Parse(Console.ReadLine());
            var a = ReadLine();

            a = a.OrderBy(x => x).ToList();
            int distance = a[n - 1] - a[0];

            Console.WriteLine(distance);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 11348
main = do
    n <- getLine 
    putStrLn $ concat (map (disp) (calc 1 (read n)))

disp :: Int -> String
disp x = " " ++ (show x)

calc :: Int -> Int -> [Int]
calc x n
    | x > n = []
    | x `mod` 3 == 0 = x : (calc (x+1) n)
    | x `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 10) `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 100) `mod` 10 == 3 = x : (calc (x+1) n)
    | (x `div` 1000) `mod` 10 == 3 = x : (calc (x+1) n)
    | otherwise = calc (x+1) n




Measured memory_bytes: 4128
s = input()

n = len(s)
'''
for i in range(n-1, 1, -1):
    if i % 2 == 0:
        if s[0:i//2] == s[i//2:i]:
            print(i)
'''
for i in range(1, n//2):
    k = (n-i*2)
    if s[:k//2] == s[k//2:k]:
        print(k)
        break


Measured memory_bytes: 2940
import java.util.*;
public class Main
{ public static void main(String args[])
  { Scanner sc=new Scanner(System.in);
     int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
     int b=sc.nextInt();
     System.out.println(a[b-1]);
    }
}

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

//使用flag的冒泡排序法(升序),返回交换次数
int bubblesort(int A[], int N)
{
	int sw = 0;//记录次数
	bool flag = 1;
	for( int i = 0; flag; i++)
	{
		flag = 0;
		for (int j = N - 1; j >= i + 1; j--)//从最后一项查找
		{
			if (A[j] < A[j-1]) 
			{
				//交换相邻元素
				swap(A[j], A[j - 1]);
				flag = 1;
				sw++;
			}
		}
	}
	return sw;
}

int main()
{
	int A[100], N, sw;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];

	sw = bubblesort(A, N);
	for (int i = 0; i < N; i++)
	{
		if (i)cout << " ";
		cout << A[i];
	}
	cout << endl;
	cout << sw << endl;
	return 0;

}



Measured memory_bytes: 3108
N=int(input())
A=[]
for i in range(N):
    A.append(int(input()))
A.sort()
total=0
for i in range(N):
    total+=A[i]

if total%10!=0:
    print(total)
else:
    for i in range(N):
        if (total-A[i])%10!=0:
            print(total-A[i])
            exit(0)
    print(0)

Measured memory_bytes: 3064
import java.util.*;


public class Main {
	
	Scanner cin = new Scanner(System.in);
	
	public static void main(String[] args) {
		new Main().run(); 
	}
	
	
	public void run() {
		
		String A = cin.next();
		String B = cin.next();
		String C = cin.next();
		
		System.out.println(A.charAt(0) +""+ B.charAt(0) +""+ C.charAt(0));
	}
}



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

#define VMAX 10001

int main()
{
    int i, n, val, max, C[VMAX];
    cin >> n;
    max = 0;

    for(val = 0; val < VMAX; val++) C[val] = 0;

    for(i = 0; i < n; i++){
        cin >> val;
        C[val] = C[val] + 1;
        if(max < val) max = val;
    }
    for(val = 0; C[val] == 0; val++);
    cout << val;
    C[val] = C[val] - 1;

    while(val <= max){
        if(C[val] > 0){
            cout << " " << val;
            C[val] = C[val] - 1;
        }else{
            val++;
        }
    };
    cout << endl;    

    return 0;
}

Measured memory_bytes: 1200
import sys
readline = sys.stdin.readline

N, A, B = map(int, readline().split())
P = list(map(int, readline().split()))

INF = 1<<64

dp = [INF]*(N+1)
dp[0] = 0

for i in range(N):
    p = P[i]
    dp2 = [INF]*(N+1)
    for j in range(N+1):
        if p < j:
            dp2[j] = dp[j] + B
        if j < p:
            dp2[p] = min(dp2[p], dp[j])
            dp2[j] = dp[j] + A
    dp = dp2
print(min(dp))

Measured memory_bytes: 122204
function main(input) {
    const args = input.split(' ');
    var A = parseInt(args[0], 10);
    var B = parseInt(args[1], 10);
    var C = parseInt(args[2], 10);

    var ans = 0;

    if ( C - (A + 1) >= 0) {
        ans += A + 1;
        C = C - (A + 1);
    } else {
        ans += C;
        C = 0;
    }

    if( C > B) {
        ans += B * 2;
    } else {
        ans += B + C;
    }
    console.log(ans);

}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 21064
import math
import fractions

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

def ValueToBits(x,digit):
    res = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        res[i]=now%2
        now = now >> 1
    return res

def BitsToValue(arr):
    n = len(arr)
    ans = 0
    for i in range(n):
        ans+= arr[i] * 2**i
    return ans

def ValueToArray10(x, digit):
    ans = [0 for i in range(digit)]
    now = x
    for i in range(digit):
        ans[digit-i-1] = now%10
        now = now //10
    return ans
'''
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n-r] % p

p = 2
N = 10 ** 6 + 2
fact = [1, 1]  # fact[n] = (n! mod p)
factinv = [1, 1]  # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1]  # factinv 計算用

for i in range(2, N + 1):
    fact.append((fact[-1] * i) % p)
    inv.append((-inv[p % i] * (p // i)) % p)
    factinv.append((factinv[-1] * inv[-1]) % p)
'''


#a = list(map(int, input().split()))

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

dp = [[0 for i in range(6002)]for j in range(n+1)]
ans = 0
for i in range(n):
    now = a[i]
    dp[i+1][now] = i+1
    for jj in range(s-1):
        j = jj+1
        dp[i+1][j] += dp[i][j]
        dp[i+1][j+now] += dp[i][j]
        dp[i+1][j] %= 998244353
    ans += dp[i+1][s] * (n - i)
    ans %= 998244353
    #print(ans)


print(ans)








Measured memory_bytes: 187636
using System;

class DCaracalVsMonster {
    static void Main(string[] args) {
        long H = long.Parse(System.Console.ReadLine());
        long rtn = 0;
        int i = 0;
        while(H > 1) {
            H = H / 2;
            rtn = rtn + ((long)(Math.Pow(2, i + 1)));
            i++;
        }
        rtn = rtn + 1;
        System.Console.WriteLine(rtn.ToString());
    }
}


Measured memory_bytes: 13140
n,m=map(int,input().split())
drink=[list(map(int,input().split())) for i in range(n)]
#print(drink)

drink.sort()
#print(drink)
money=0
number=0
for i in range(n):
    if number+drink[i][1]<=m:
        money+=drink[i][0]*drink[i][1]
        number+=drink[i][1]
    elif m<number+drink[i][1]:
        money+=drink[i][0]*(m-number)
        number+=m-number
        break
    if m==number:
        break
print(money)

Measured memory_bytes: 27320
#include <iostream>
#include <vector>
#include <iterator>

using namespace std;

int gcd(int x, int y) {
  if (x < y) {
    int t = x;
    x = y;
    y = t;
  }
  if (y == 0) return x;
  else return gcd(y, x%y);
}

int main(void) {
  int n;
  vector<int> v;

  cin >> n;

  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }

  vector<int> l(n), r(n);
  l[0] = 0;
  r[n-1] = 0;
  for (int i = 1; i < n; i++) {
    l[i] = gcd(l[i-1], v[i-1]);
  }
  for (int i = n-2; i >= 0; i--) {
    r[i] = gcd(r[i+1], v[i+1]);
  }

  // l[i]: gcd(v[0], ... , v[i-1])
  // r[i]: gcd(v[i+1], ... , v[n-1])

  int result = 0;
  for (int i = 0; i < n; i++) {
    int result_l = gcd(l[i], r[i]);
    if (result_l > result) result = result_l;
  }

  cout << result << endl;

  return 0;
}


Measured memory_bytes: 1528
#include<iostream>
#include <algorithm>
#include<math.h>
int main(void){
    int a;
    int sum=0;

    using namespace std;

    cin>>a;
    int *w=(int*)malloc(a*sizeof(int));
    for(int i=0;i<a;i++){
        cin>>*(w+i);
        
    }
     for(int i=0;i<a;i++){
       
        sum+= *(w+i);
    }

    int diff0=0;
    int diff1=0;
    
    int dsum=0;
  
    diff0=(sum-*(w));
        
    int i=0;
    for(i=0;i<a;i++){
        dsum+=*(w+i);
        diff1=(sum-dsum);

        if(diff1<sum/2 ){
         
            break;
        }else{
            diff0=diff1;
        }
    }
    int ans=0;
     if(pow(diff0-(dsum-*(w+i)),2) < pow(diff1-dsum,2)){
        if((diff0-(dsum-*(w+i)))<0){ans=(diff0-(dsum-*(w+i)))*-1;}
        else{ans=diff0-(dsum-*(w+i));}  
          
     }else{
          if((diff1-dsum)<0){ans=(diff1-dsum)*-1;}
          else{ans=(diff1-dsum);}  
           
     }
  cout<<ans<<endl;


  

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

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

    // dp[i][j][k]; i桁目までで、0以外の数字をj個使って、k=1: kより小さい／k=0: kと等しい、を満たす個数
    vector<vvi> dp(n+1, vvi(4, vi(2, 0)));
    dp[0][0][0] = 1;
    rep(i, n){
        rep(j, 4){
            rep(k, 2){
                ll nd = s[i]-'0';
                for(ll num=0; num<10; num++){
                    ll ni=i+1, nj=j, nk=k;
                    if(num != 0) nj++;
                    if(nj > K) continue;
                    if(k == 0){
                        if(num > nd) continue;
                        if(num < nd) nk = 1;
                    }
                    dp[ni][nj][nk] += dp[i][j][k];
                }
            }
        }
    }
    cout << dp[n][K][0]+dp[n][K][1] << endl;
}

Measured memory_bytes: 3660
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

#define SUM(vec) accumulate(all(vec),0LL) // 配列の中身を全部足す
template<typename T>void print(T&& x){cout<<x<<endl;}// 改行付き出力
ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int ctoi(char c){return c-'0';}

// TODO: write
int main() {   
  string s;cin>>s;
  string notx;
  rep(i,s.size()){
    if(s[i] != 'x')notx.pb(s[i]);
  }
  rep(i,notx.size()/1){
    if(notx[i] != notx[notx.size()-i-1]){
      print(-1);
      return 0;
    }
  }
  
  vector<int> mae(notx.size()/2+1),ato(notx.size()/2+1);
  int cnt = 0;
  int tmp = 0;
  rep(i,s.size()){
    if(s[i] == 'x')++cnt;
    else{
      mae[tmp] = cnt;
      cnt = 0;
      ++tmp;
      if(tmp >= mae.size())break;
    }
  }


  tmp = 0;
  for(int i = s.size()-1;i >= 0;--i){
    
    if(s[i] == 'x')++cnt;
    else{
      ato[tmp] = cnt;
      cnt = 0;
      ++tmp;
      if(tmp >= ato.size())break;
    }
  }

  int ans = 0;
  rep(i,mae.size()){
    ans += abs(mae[i] - ato[i]);
  }
  print(ans);
  return 0;
}



Measured memory_bytes: 1024
import java.util.Scanner;

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

Measured memory_bytes: 26092
#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> a(100000);
vector<int> b(100000);
vector<int> c(100000);
vector<int> ha(100000);
vector<int> hb(100000);
vector<int> hc(100000);

int ans_a(int n);
int ans_b(int n);
int ans_c(int n);

int ans_a(int n)
{
    if (ha.at(n) != -1)
        return ha.at(n);
    ha.at(n) = max(ans_b(n - 1) + a.at(n), ans_c(n - 1) + a.at(n));
    return ha.at(n);
}

int ans_b(int n)
{
    if (hb.at(n) != -1)
        return hb.at(n);
    hb.at(n) = max(ans_a(n - 1) + b.at(n), ans_c(n - 1) + b.at(n));
    return hb.at(n);
}

int ans_c(int n)
{
    if (hc.at(n) != -1)
        return hc.at(n);
    hc.at(n) = max(ans_a(n - 1) + c.at(n), ans_b(n - 1) + c.at(n));
    return hc.at(n);
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> a.at(i) >> b.at(i) >> c.at(i);
        ha.at(i) = -1;
        hb.at(i) = -1;
        hc.at(i) = -1;
    }
    ha.at(0) = a.at(0);
    hb.at(0) = b.at(0);
    hc.at(0) = c.at(0);
    cout << max(ans_a(n - 1), max(ans_b(n - 1), ans_c(n - 1))) << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
#define INF 1<<21
using pii = std::pair<int, int>;
#define SORT(v) std::sort(v.begin(), v.end())
int F[100][15];
int main(void) {
	int N,L;
	std::cin >> N >> L;
	std::vector<std::string> a(N);
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
		
	}
	SORT(a);
	for (int i = 0; i < N; i++) {
		std::cout << a[i];

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

Measured memory_bytes: 256
class Combinatorics:
    def __init__(self, N, mod):
        '''
        Preprocess for calculating binomial coefficients nCr (0 <= r <= n, 0 <= n <= N)
        over the finite field Z/(mod)Z.
        Input:
            N (int): maximum n
            mod (int): a prime number. The order of the field Z/(mod)Z over which nCr is calculated.
        '''
        self.mod = mod
        self.fact = {i: None for i in range(N+1)}         # n!
        self.inverse = {i: None for i in range(1, N+1)}   # inverse of n in the field Z/(MOD)Z
        self.fact_inverse = {i: None for i in range(N+1)} # inverse of n! in the field Z/(MOD)Z
        
        # preprocess
        self.fact[0] = self.fact[1] = 1
        self.fact_inverse[0] = self.fact_inverse[1] = 1
        self.inverse[1] = 1
        for i in range(2, N+1):
            self.fact[i] = i * self.fact[i-1] % self.mod
            q, r = divmod(self.mod, i)
            self.inverse[i] = (- (q % self.mod) * self.inverse[r]) % self.mod
            self.fact_inverse[i] = self.inverse[i] * self.fact_inverse[i-1] % self.mod
    
    def perm(self, n, r):
        '''
        Calculate nPr = n! / (n-r)! % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return (self.fact[n] * self.fact_inverse[n-r]) % self.mod
    
    def binom(self, n, r):
        '''
        Calculate nCr = n! /(r! (n-r)!) % mod
        '''
        if n < r or n < 0 or r < 0:
            return 0
        else:
            return self.fact[n] * (self.fact_inverse[r] * self.fact_inverse[n-r] % self.mod) % self.mod
        
    def hom(self, n, r):
        '''
        Calculate nHr = {n+r-1}Cr % mod.
        Assign r objects to one of n classes.
        Arrangement of r circles and n-1 partitions:
            o o o | o o | | | o | | | o o | | o
        '''
        if n == 0 and r > 0:
            return 0
        if n >= 0 and r == 0:
            return 1
        return self.binom(n + r - 1, r)

N, M = map(int, input().split())
MOD = 10**9 + 7
if abs(N-M) > 1:
    print(0)
else:
    com = Combinatorics(max(N, M), MOD)
    if N != M:
        ans = (com.fact[N] * com.fact[M]) % MOD
    else:
        ans = (2 * (com.fact[N] * com.fact[M]) % MOD) % MOD
    print(ans)

Measured memory_bytes: 40560
import java.util.*;
public class Main
{
	public static void main(String[] args) 
	{
		Scanner in=new Scanner(System.in);
		int N=in.nextInt();
		in.nextLine();
		while(N-->0)
		{
			char ch[]=in.nextLine().toCharArray();
			char re[]=new char[ch.length];
			boolean judge=false;
			for(int a=0;a<100;a++)
			{
				for(int b=0;b<26;b++)
				{
					for(int i=0;i<ch.length;i++)
					{
						if(ch[i]==' ')
						{
							re[i]=' ';
							continue;
						}
						int m=(a*((int)ch[i]-97)+b)%26;
						re[i]=(char)(m+97);
					}
					for(int i=0;i<re.length-1;i++)
						if(i+3<re.length)
							if((re[i]=='t'&&re[i+1]=='h'&&re[i+2]=='a'&&re[i+3]=='t')
									||(re[i]=='t'&&re[i+1]=='h'&&re[i+2]=='i'&&re[i+3]=='s'))
								judge=true;
					if(judge)
						break;
				}
				if(judge)
					break;
			}
			for(int i=0;i<re.length-1;i++)
				System.out.print(re[i]);
			System.out.println(re[re.length-1]);
		}
	}
	static public void debug(Object... o)
	{
		System.out.println(Arrays.deepToString(o));
	}
}

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

int main(){
    int x,y,i;
    while(1){
        cin>>x>>y;
        if(y==0 && x==0){
            break;
        }
        if(x>y){
            cout<<y<<" "<<x<<endl;
        }
        else {
            cout<<x<<" "<<y<<endl;
        }
        
        i++;
    }
    return 0;
}


Measured memory_bytes: 3016
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=(ll)1e9+7;


int main() {
    int a,b;
    cin>>a>>b;

    int cnt=1;
    int ans=0;
    while(b>cnt){
        cnt+=a-1;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

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

int n,s;
int dfs(int cou,int now,int before);

int main(){
  while(1){
    cin >> n >> s;
    if(n == 0 && s == 0) break;
    int ans = 0;
    for(int i=0;i<10;i++){
      ans = dfs(0,0,-1);
    }
    cout << ans << endl;
  }
}

int dfs(int cou,int now,int before){
  if(cou==n) {
    if(now == s) {
      return 1;
      cout << before << endl;
    }
    else return 0;
  }
  int num = 0;
  for(int i=before+1;i<10;i++){
      num += dfs(cou+1,now+i,i);
  }
  return num;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> H(A), W(B);
  int mh = 0, mw = 0;
  set<pair<int, int>> S;
  for (int h, w; cin >> h >> w;) {
    mh = max(mh, ++H.at(--h));
    mw = max(mw, ++W.at(--w));
    S.insert({h, w});
  }
  set<int> X, Y;
  for (int i = 0; i < A; i++) if (H.at(i) == mh) X.insert(i);
  for (int i = 0; i < B; i++) if (W.at(i) == mw) Y.insert(i);
  int cnt = 0;
  for (auto [x, y] : S) if (X.count(x) && Y.count(y)) cnt++;
  int siz = X.size() * Y.size();
  cout << mh + mw - (cnt == siz) << "\n";
}

Measured memory_bytes: 47784
import queue

n,m = list(map(int, input().split()))
puted = [1]*(n+1)

ab = [[] for i in range(n+1)]
for i in range(m):
	a,b = map(int, input().split())
	ab[a].append(b)
	ab[b].append(a)

q = queue.Queue()
flg = [-1]*n
flg[0] = 0
q.put(1)

while not q.empty():
	item = q.get()
	for i in ab[item]:
		if puted[i]:
			flg[i-1]=item
			q.put(i)
			puted[i]=0

if -1 in flg:
	print("No")
	exit()

print("Yes")
for i in range(1,len(flg)):
	print(flg[i])


Measured memory_bytes: 35128
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const double eps = 1E-18;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

bool ch(ll t, ll X, ll N) {

	if (t > X) { return false; }
	
	ll s = 1;
	rep(i, t) {
		ll mul = X / t;
		if (i < X % t) { mul++; }
		if (s >= (N - 1) / mul + 1) { return true; }

		s *= mul;
	}
	return false;
}


int main() {
	ll N, A;
	cin >> N >> A;

	ll ans = INF;
	repn(t, 60) {
		ll l = 0;
		ll r = INF;

		while (r - l > 1) {
			ll m = (r + l) / 2;
			if (ch(t, m, N)) { r = m; }
			else { l = m; }
		}

		ll now = r + A * (t - 1);
		ans = min(now, ans);
	}

	cout << ans << endl;
	
}


Measured memory_bytes: 256