akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll 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;
  }
};
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());

  combination c(n+5);

  mint ans = 0;
  rep(ri,2) {
    rep(i,n) {
      mint now = c(i,k-1);
      if (ri == 1) now = -now;
      ans += now*a[i];
    }
    reverse(a.begin(), a.end());
  }

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


Measured memory_bytes: 2176
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
typedef long long ll;
const ll longinf=1LL<<60;
using namespace std;
int n;
int a[30],b[30],c[30];


int main()
{
    cin>>n;
    int ans=0;
    for (int i=1; i<=n; ++i)
        cin>>a[i];
    for (int i=1; i<=n; ++i)
        cin>>b[i];
    for (int i=1; i<=n-1; ++i)
        cin>>c[i];
    for (int i=1; i<=n; ++i)
    {
        ans+=b[a[i]];
        if (i!=1 && a[i-1]+1 == a[i])
            ans+=c[a[i-1]];
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string.h>

int n, s;
int used[10];
int ans = 0;

void func( int num, int sum )
{
	if( num == n ){
		if( sum == s ){
			ans++;
		}
		return;
	}
	
	for( int i = used[num]; i <= 9; i++ ){
		used[num+1] = i + 1;
		func( num + 1, sum + i );
		used[num+1] = 0;
	}
}

int main()
{
	while( 1 ){
		memset( used, 0, 10 );
		ans = 0;
		
	 	std::cin >> n >> s;
		if( !n && !s ) break;
		
		func( 0, 0 );
		
		std::cout << ans << std::endl;
	}

 	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>

int main(){
	int unsigned a,b,sum=0;
	int i,j;
	while(scanf("%u %u",&a,&b)!=EOF){
		sum=a+b;
		for(i=1000000000,j=10;i>=1;i/=10,j--){
			if(sum>=i){
				printf("%d\n",j);
				break;
			}
		}
		if(sum==0){
			printf("1\n");
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
unsigned long long getSumD ( unsigned long long x ) {
    return x == 0 ? 0 : x%10 + getSumD( x/10 );
}

long double getSN ( unsigned long long x ) {
    return x*1./getSumD( x );
}
vector < unsigned long long > posn;
int main () {

    for ( unsigned long long cd = 0 ; cd <= 14 ; cd ++ ) {
        for ( unsigned long long i = 1 ; i < 1000 ; i ++ ) {
            unsigned long long x = i;
            for ( unsigned long long k = 0 ; k < cd ; k ++ ) { x *= 10; x += 9;}
            posn.push_back( x );
        }
    }
    sort( posn.begin(), posn.end() );
    unique( posn.begin(), posn.end() );

    int k;
    cin >> k;

    for ( unsigned long long i = 0 ; i < posn.size() ; i ++ ) {
        bool b = 0;
        for ( unsigned long long j = i+1 ; j < posn.size() ; j ++ ) {
            if ( posn[i]*getSumD( posn[j] ) > posn[j] *getSumD(posn[i] ) ) { b = 1; break; }
        }
        if ( !b ) {
            k --;
            cout << posn[i] << "\n";
            if ( k == 0 ) { return 0; }
        }
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main() {
    int W, H, x, y, r;
    cin>>W>>H>>x>>y>>r;
    if ((x-r<0) || (y-r<0) || (x+r>W) || (y+r>H)) 
      cout<<"No"<<endl;
    else 
      cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
    string s;
    cin >> s;
    vector<int> cnt(300);
    for(char c : s)
        cnt[c] ++ ;
    ll ans = 1;
    for(int i = 0; i < 300; ++i)
        for(int j = i+1; j < 300; ++j)
            ans += cnt[i]*(ll)cnt[j];
    cout << ans << '\n';
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using i64=long long;

int main(){
	i64 N;
	cin>>N;
	vector<pair<double,i64>> vec;
	vector<double> x(N),y(N);	
	for(i64 i=0;i<N;i++){
		double s,t;
		cin>>s>>t;
		x[i]=s*1e6/(1e6-100.0);
		y[i]=t*1e6/(1e6-100.0);
	}
	double Gx=0,Gy=0;
	for(i64 i=0;i<N;i++)
	{
		Gx+=x[i]/N;
		Gy+=y[i]/N;
	}
	for(i64 i=0;i<N;i++)
	{
		x[i]-=Gx;
		y[i]-=Gy;
		vec.push_back({atan2(y[i],x[i]),-i-1});
	}
	i64 Q;
	cin>>Q;
	vector<double> a(Q),b(Q);
	for(i64 i=0;i<Q;i++){
		cin>>a[i]>>b[i];
		a[i]-=Gx;
		b[i]-=Gy;
		vec.push_back({atan2(b[i],a[i]),i});
	}
	sort(begin(vec),end(vec));
	vector<i64> ans(Q);
	
	{
		i64 before=0;
		i64 after=0;
		i64 ai=0;
		for(i64 i=vec.size();i-->0;)
		{
			if(vec[i].second<0){
				before = vec[i].second*-1-1;
				break;
			}
		}
		for(i64 i=0;i<vec.size();i++)
		{
			if(vec[i].second<0){
				after=vec[i].second*-1-1;
				ai=i;
				break;
			}
		}
		for(i64 i=0;i<vec.size();i++){
			if(vec[i].second>=0){
				i64 idx=vec[i].second;
				double A=a[idx];
				double B=b[idx];
				double X1=x[before];
				double Y1=y[before];
				double X2=x[after];
				double Y2=y[after];
				if((X2-X1)*(B-Y1)-(Y2-Y1)*(A-X1)>=0){
					ans[idx]=1;
				}
				else{
					ans[idx]=0;
				}
			}
			else{
				before=after;
				while(ai=(ai+1)%vec.size(),vec[ai].second>=0){
				}
				after=vec[ai].second*-1-1;
			}
		}
	}	
	for(i64 i=0;i<Q;i++){
		cout<<ans[i]<<endl;
	}
}


Measured memory_bytes: 6664
import java.util.*;

public class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int m = sc.nextInt();
      int sum = 0;
      for(int i = 0; i < m; i++) sum += sc.nextInt();
      if(sum > n) System.out.println(-1);
      else System.out.println(n - sum);
    }
}

Measured memory_bytes: 46296
n = int(input())
s = str(input())

l = list(s)

alpha2num = lambda c: ord(c) - ord('A') + 1
num2alpha = lambda c: chr(c+64)

ans = []

for _ in l:
  num = alpha2num(_) + n
  if num > 26:
    num -= 26
  ans.append(num)

ans2 = [num2alpha(_) for _ in ans]

print(''.join(ans2))

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

using namespace std;
#define lint long long
#define P pair<lint, int>

int main() {
    int N, M;
    cin >> N >> M;
    
    lint A[N]; int B[N];
    
    vector<P> lis;
    for(int i = 0; i < N; ++i){
        cin >> A[i] >> B[i];
        lis.push_back(make_pair(A[i], B[i]));
    }
    
    sort(lis.begin(), lis.end());
    
    lint ans = 0;
    
    for(int i = 0; i < N; ++i){
        if(M - lis[i].second > 0){
            ans += lis[i].first * lis[i].second;
            M -= lis[i].second;
        } else {
            ans += lis[i].first * M;
            break;
        }
    }
    
    cout << ans << endl;
    
    
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int a1=0,a2=0;
    char x='0',y='1';
    string s;
    cin>>s;
    for (int i=0;i<s.size();i++){
        if(s[i]==x){
            a1++;
        }
        
        if(s[i]==y){
            a2++;
        }
        swap(x,y);
    }
    if (a1>a2){a1=a2;}
    cout<<a1;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <iomanip>
using namespace std;

int main(){
    // input
    int N; cin >> N;
    
    // compute
    bool can = false;
    string S = to_string(N);
    int sum = 0;
    for (int i = 0; i < S.size(); i++){
        int n = (int)(S.at(i)-'0');
        sum += n;
    }
    if (N%sum == 0) can = true;
    // output
    cout << (can ? "Yes":"No") << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll =  long long ;
using P = pair<int,int> ;
const int INF = 1e9;
const int MOD = 1000000007;

int main(){
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << " " << y << " " << z << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
typedef long long int LLI;
LLI y=0,visited,count1,ar[22][22],n,dp[1<<22][22];
LLI func(LLI mask,LLI row)
{
    LLI i,j;
    if(row==n)
    {
        return 1;
    }
    if(dp[mask][row]!=-1)
    {
        return dp[mask][row];
    }
    LLI temp=0;
    for(i=0;i<n;i++)
    {
        if(ar[row][i]==1 && (mask&(1<<i))==0)
        {

            temp+=func((mask|(1<<i)),row+1);
        }
    }

    dp[mask][row]=temp;
    return temp;
}
int main()
{
    LLI i,j,t;
    //freopen("C:\\Users\\suman\\Desktop\\input.txt","r",stdin);
    //cin>>t;
    //while(t--)
    //{
        count1=0;
        cin>>n;
        for(i=0;i<=(1<<n)-1;i++)
            for(j=0;j<n;j++)
            dp[i][j]=-1;
       for(i=0;i<n;i++)
        {
            for(j=0;j<n;j++)
                cin>>ar[i][j];
        }
        for(i=0;i<n;i++)
        {
            if(ar[0][i]==1)
            {
                count1+=func((1<<i),1);
                dp[(1<<i)][0]=count1;
                count1%=mod;
            }
        }
        /*for(i=0;i<=(1<<n)-1;i++)
        {
            cout<<"\n";
            for(j=0;j<n;j++)
            cout<<dp[i][j]<<"\t";
        }*/
        cout<<count1<<"\n";
    //}
    return 0;
}


Measured memory_bytes: 362752
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

ll gcd(ll a,ll b){
    if(a<b){
        swap(a,b);
    }
    //a>=b
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}

#define MOD ((ll)1e+9 + 7)



//cout<<fixed<<setprecision(10);
int main(){
    int n;
    cin>>n;
    vector<int> d(n);
    rep(i,n){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    n/=2;
    int ans=d[n]-d[n-1];
    cout<<ans<<endl;



    return 0;
}



Measured memory_bytes: 3764
#pragma region RegionDefs
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include "boost/multi_array.hpp"
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,j,n) for(int i=(j),i##_len=(n);i<i##_len;++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T=int> using P  = pair<T, T>;
template<class T=int> using V  = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) int __VA_ARGS__; in(__VA_ARGS__)
//オーバーフロー対策
#define INL(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
#pragma endregion RegionDefs

void solve()
{
    INL(n);
    for (ll i = sqrt(n); i > 0; --i)
    {
        if (n % i == 0)
        {
            cout << n / i + i - 2 << endl;
            return;
        }
    }
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a,b;
		while(true){
			a = sc.nextInt();
			b = sc.nextInt();
			if(a==0&&b==0)break;
			for(int i=0;i<a;i++){
				for(int j=0;j<b;j++){
					if((i+j)%2==0)System.out.print("#");
					else System.out.print(".");
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}



Measured memory_bytes: 38252
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }


//CODE
void solve(void)
{
  string str;
  cin>>str;
  if(str == "AAA" || str =="BBB")
  {
    cout<<"No"<<endl;
  }
  else
  {
    cout<<"Yes"<<endl;
  }
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();
  

 
  return 0;
}


Measured memory_bytes: 256
// AOJ 2889: Internet Protocol Address
// 2019.2.19 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int ans, len;
char S[15];

void combi(int n, int idx)
{
	if (idx == len && n == 4) {
		ans++;
		return;
	}
	if (n >= 4) return;
	if (idx >= len) return;

	combi(n + 1, idx + 1);
	if (S[idx] != '0') combi(n + 1, idx + 2);
	if (S[idx] == '1') combi(n + 1, idx + 3);
	else if (S[idx] == '2') {
		if (idx + 2 < len) {
			if (S[idx + 1] == '5' && S[idx + 2] <= '5') combi(n + 1, idx + 3);
			if (S[idx + 1] < '5') combi(n + 1, idx + 3);
		}
	}
}

int main()
{
	scanf("%s", S);
	len = strlen(S);
	ans = 0;
	combi(0, 0);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;	
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;


void solve() {
	ll x, y, z, p, q, r;
	string s, t;
	cin >> s >> t;
	n = s.size(), m = t.size();
	ll dp[n+1][m+1];
	f(i, n+1) {
		f(j, m+1) {
			if(i == 0 || j == 0) {
				dp[i][j] = 0;
			} else if (s[i-1] == t[j-1]) {
				dp[i][j] = 1 + dp[i-1][j-1];
			} else {
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	
	string ans = "";
	ll i = n - 1, j = m - 1;
	while (i >= 0 && j >= 0) {
		if(s[i] == t[j]) {
			ans = s[i] + ans;
			i--, j--;
		} else if (dp[i][j + 1] > dp[i + 1][j]) {
			i--;
		} else {
			j--;
		}
	}
	cout << ans << endl;
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
		solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 70656
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pli pair<LL, int>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head

const int N = 1e5 + 10;
char s[N], t[N];
map<LL, char> mp;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    scanf("%s", s+1);
    scanf("%s", t+1);
    LL d = n /__gcd(n, m) * 1LL * m;
    if(s[1] != t[1]) return 0*puts("-1");
        bool  f = true;
        for (int i = 1; i < n; i++) {
            if(mp.find(d/n*i) == mp.end()) {
                mp[d/n*i] = s[i+1];
            }
            else {
                if(mp[d/n*i] != s[i+1]) return 0*puts("-1");
            }
        }
        for (int i = 1; i < m; i++) {
            if(mp.find(d/m*i) == mp.end()) {
                mp[d/m*i] = t[i+1];
            }
            else {
                if(mp[d/m*i] != t[i+1]) return 0*puts("-1");
            }
        }
        if(f) return 0*printf("%lld\n", d);
    return 0;
}


Measured memory_bytes: 10880
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

vector<string> ans;
int n;
int a[10];

void dfs(int k,int u){
    if(k == n){
        string t = "";
        for (int i = 0; i < n; i++) {
            t += 'a' + a[i];
        }
        ans.pb(t);
        return;
    }
    for (int i = 0; i <= u+1; i++) {
        a[k] = i;
        dfs(k+1, max(u,i));
    }
    return;
}

int main(){
    cin >> n;
    dfs(0,-1);
    sort(ALL(ans));
    for (int i = 0; i < ans.size(); i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 9588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <array>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  ll n;
  cin >> n;
  vector<string> s(n);
  map<string, ll> p;
  rep(i, n) {
    array<char, 26> arr;
    cin >> s[i];
    sort(s[i].begin(), s[i].end());
    p[s[i]] += 1;
  }
  
  ll ans = 0;
  for (auto itr : p) {
    // cout << itr.second << endl;
    ans += itr.second * (itr.second - 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 18176
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define ll long long
#define REP(a,b,c) for(int a=b;a<=c;a++)
#define re register
#define file(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout)
typedef pair<int,int> pii;
#define mp make_pair
inline int gi()
{
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=100010,Mod=1e9+7;
int n,k,a[N],fac[N],fai[N],inv[N],ans;
int C(int n,int m)
{
	if(n<m||n<0||m<0)return 0;
	return 1ll*fac[n]*fai[m]%Mod*fai[n-m]%Mod;
}
int main()
{
	n=gi();k=gi();
	for(int i=1;i<=n;i++)a[i]=gi();
	fac[0]=fai[0]=inv[0]=inv[1]=1;
	for(int i=1;i<=n;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<=n;i++)inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(int i=1;i<=n;i++)fai[i]=1ll*fai[i-1]*inv[i]%Mod;
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)
	{
		int j=i;while(a[j+1]==a[i])j++;
		int s=0;
		for(int p=i;p<=j;p++)
			s=(s+1ll*C(n-j,k-(p-i+1))*C(j-i+1,p-i+1)%Mod)%Mod;
		ans=(ans-1ll*(a[i]+Mod)%Mod*s%Mod+Mod)%Mod;
		i=j;
	}
	sort(a+1,a+n+1,greater<int>());
	for(int i=1;i<=n;i++)
	{
		int j=i;while(a[j+1]==a[i])j++;
		int s=0;
		for(int p=i;p<=j;p++)
			s=(s+1ll*C(n-j,k-(p-i+1))*C(j-i+1,p-i+1)%Mod)%Mod;
		ans=(ans+1ll*(a[i]+Mod)%Mod*s%Mod+Mod)%Mod;
		i=j;
	}
	printf("%d\n",ans);
	return 0;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

// 最大公約数
ll gcd(ll a,ll b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));
}

// 最小公倍数
ll lcm(ll a, ll b){
    return a/gcd(a, b) * b;
}

int main()
{
    cout << fixed << setprecision(15);
    string A, B, C;
    cin >> A >> B >> C;

    cout << char(toupper(A[0])) << char(toupper(B[0])) << char(toupper(C[0])) << endl;
    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
import java.io.*; 
import java.text.*;
//Solution Credits: Taranpreet Singh
public class Main{
    //SOLUTION BEGIN
    void solve(int TC) throws Exception{
        int k = ni();
        pn((k/2)*((k+1)/2));
    }
    //SOLUTION ENDS
    long mod = (int)1e9+7, IINF = (long)1e18;
    final int MAX = (int)1e5+1, INF = (int)1e9, root = 3;
    DecimalFormat df = new DecimalFormat("0.00000000");
    double PI = 3.141592653589793238462643383279502884197169399375105820974944, eps = 1e-8;
    static boolean multipleTC = false, memory = true;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        in = new FastReader();
        out = new PrintWriter(System.out);
        int T = (multipleTC)?ni():1;
        //Solution Credits: Taranpreet Singh
        for(int i = 1; i<= T; i++)solve(i);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n(){return in.next();}
    String nln(){return in.nextLine();}
    int ni(){return Integer.parseInt(in.next());}
    long nl(){return Long.parseLong(in.next());}
    double nd(){return Double.parseDouble(in.next());}

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

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

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

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


Measured memory_bytes: 24660
/*-----rk_98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
ll n;
ll arr[22][22];
ll memo[22][1<<22];
ll dfs( ll u, ll mask)
{
	if(u == n +1)
	{
		if (__builtin_popcount(mask) == n )
				return 1;
		else
			return 0;
	}
	if(memo[u][mask] !=-1) return memo[u][mask];
	ll ans=0;
	for( ll i=1 ; i<=n ; i++  )
	{
		if(arr[u][i] == 1 && ((1<<(i-1))&mask) == 0 )
			ans+=dfs(u+1 , mask | (1<<(i-1)) );
		ans%=mod;
	}
	return memo[u][mask] = ans;
}
int main()
{
    //fast();
    memset(memo, -1,sizeof memo);
    cin>>n;
    for(ll i=1 ;i <=n ; i++)
    	for(ll j=1 ; j<= n ;j++)
    		cin>>arr[i][j];
    cout<<dfs(1,0)<<endl;
}


Measured memory_bytes: 721152
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    string s; cin >> s;
    cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
    return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
a=list(map(int,input().split()))

if a[N-1]<0:
    a=list(reversed(list(map(abs,a))))
if N == K:
    print(a[N-1]-a[0]+min(abs(a[0]),abs(a[N-1])))
else:
    ans=10000000000
    for i in range(N-K):
        ans = min(ans,a[K+i-1]-a[i]+min(abs(a[i]),abs(a[K+i-1])))
    print(ans)

Measured memory_bytes: 14252
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

using namespace std;

typedef long long ll;

int main()
{
	ll N = 0;
	ll M = 0;
	ll ans = 0;

	cin >> N >> M;

	if (N == 1 && M == 1) {
		ans = 1;
	}
	else if (N == 1 || M == 1) {
		ans = N * M - 2;
	}
	else {
		ans = N * M - (2 * N + 2 * M - 4);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        String[] lines = getStdin();
        String str = lines[0];
        int length = Integer.parseInt(str);
        String str1 = lines[1];
        String[] number = str1.split(" ");

        int[] ary = new int[length];
        for (int i = 0; i < length; i++){
            int num = Integer.parseInt(number[i]);
            ary[length - i - 1] = num;
        }
        for (int i = 0; i < length; i++){
            if (i == length - 1){
                System.out.println(ary[i]);
            } else{
                System.out.print(ary[i] + " ");
            }
        }
        
    
    }

  
  private static String[] getStdin() {
    Scanner scanner = new Scanner(System.in);
    ArrayList<String> lines = new ArrayList<>();
    while (scanner.hasNext()) {
      lines.add(scanner.nextLine());
    }
    return lines.toArray(new String[lines.size()]);
  }
  
}




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

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    string s1;
    cin >> s1;
    string s2;
    cin >> s2;
    int size = s1.size();
    s2.resize(size);
    if(s1==s2){
    	cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long 
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back 
#define mp make_pair
#define inf 2000000009
#define mod 1000000007
using namespace std;

int main()
{ 
fast;
	
	ll n,k;
	cin>>n>>k;

	ll a[n];
	for(ll i=0;i<n;i++)
	cin>>a[i];

   sort(a,a+n);
	
	bool dp[k+1][2];
	// 0 odd 1 even
	for(ll i=0;i<k+1;i++)
		for(ll j=0;j<2;j++)
			dp[i][j]=0;
	
	dp[0][1]=1;

	for(ll i=1;i<=k;i++)
	{
		bool f=0,f1=0,t1=0,t2=0;
		for(ll j=0;a[j]<=i;j++)
		{
			if(dp[i-a[j]][0]==0 and dp[i-a[j]][1]==1)
			dp[i][0]=1;
		
			else if(dp[i-a[j]][0]==1 and dp[i-a[j]][1]==0)
			dp[i][1]=1;
		}

		if(dp[i][0]==0 and dp[i][1]==0 )
			dp[i][0]=dp[i-1][0],dp[i][1]=dp[i-1][1];
	}

	if(dp[k][0]==1 )
		cout<<"First"<<endl;
	else 
		cout<<"Second"<<endl;

}


Measured memory_bytes: 512
use std::io;
use std::str::FromStr;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
                assert!(_it.next().is_none());
        }
    };
}

fn main() {

    let mut univ: [[[i64; 10]; 3]; 4] = [[[0; 10]; 3]; 4];

    from_line!(n: i32);

    for i in 0..n {
        let stdin = io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).ok();
        let mut it = buf.split_whitespace().map(|n| usize::from_str(n).unwrap());

        let mut v: Vec<i64> = buf.split_whitespace()
            .map(|n| i64::from_str(n).unwrap())
            .collect();
        univ[(v[0] - 1) as usize][(v[1] - 1) as usize][(v[2] - 1) as usize] += v[3];
    }
    for i in 0..4 {
        for j in 0..3 {
            for k in 0..10 {
                print!(" {}", univ[i][j][k]);
            }
            println!("");
        }
        if i != 3 {
            println!("####################");
        }
    }
}



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

# define sc second
# define fr first

using namespace std;

long long n, mx, w;
pair<long long, long long> ar[100001];
vector<long long> vec[1001];

int main()
{
    cin >> n >> w;
    vec[0].push_back(0);
    vec[1].push_back(0);
    vec[2].push_back(0);
    vec[3].push_back(0);

    cin >> ar[1].fr >> ar[1].sc;
    long long x = ar[1].fr;
    vec[0].push_back(ar[1].sc);

    for(long long i = 2; i <= n; i++)
    {
        cin >> ar[i].fr >> ar[i].sc;
        vec[ar[i].fr - x].push_back(ar[i].sc);
    }

    sort(vec[0].begin() + 1, vec[0].end(), greater<int>());
    sort(vec[1].begin() + 1, vec[1].end(), greater<int>());
    sort(vec[2].begin() + 1, vec[2].end(), greater<int>());
    sort(vec[3].begin() + 1, vec[3].end(), greater<int>());

    for(int i = 1; i < vec[0].size(); i++)
        vec[0][i] += vec[0][i - 1];
    for(int i = 1; i < vec[1].size(); i++)
        vec[1][i] += vec[1][i - 1];
    for(int i = 1; i < vec[2].size(); i++)
        vec[2][i] += vec[2][i - 1];
    for(int i = 1; i < vec[3].size(); i++)
        vec[3][i] += vec[3][i - 1];

    long long ans = 0;
    for(long long k = 0; k < vec[3].size(); k++)
        for(long long i = 0; i < vec[2].size(); i++)
            for(long long j = 0; j < vec[1].size(); j++)
                for(long long c = 0; c < vec[0].size(); c++)
                    if((x + 3) * k + (x + 2) * i + (x + 1) * j + (x) * c <= w)
                        ans = max(ans, vec[3][k] + vec[2][i] + vec[1][j] + vec[0][c]);

    cout << ans;
    return 0;
}



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

#define int long long

typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
template<class T,class U>void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>void chmax(T &t,U f){if(t<f)t=f;}

signed main(){
    int a,b;
    cin>>a>>b;
    if(a==1)a+=100;
    if(b==1)b+=100;

    if(a>b)cout<<"Alice"<<endl;
    else if(a<b)cout<<"Bob"<<endl;
    else cout<<"Draw"<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

int main() {
	
	int n;
	cin >> n;
	
	int res = 1;
	
	while(n--){
	    int a;
	    cin >> a;
	    
	    res &= a^1;
	}
	
	if(res) cout << "second" << endl;
	else cout << "first" << endl;
	
	return 0;
}


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


Measured memory_bytes: 3100
use std::io;
use std::cmp;


fn main() {
    let n = read_one::<usize>();
    let wn = read::<isize>();
    let mut ans = 1_000_000_000;
    for i in 0..n {
        let c = wn[0..i].iter().sum::<isize>() - wn[i..n].iter().sum::<isize>();
        ans = cmp::min(ans, c.abs());
    }
    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4476
n=int(input())
list=[1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7, 8, 9]
def pair(parameter):
        pairedList = []
        for iterater1 in range(len(parameter)):
                for iterater2 in range(iterater1+1,len(parameter)):
                        pairedList.append([parameter[iterater1],parameter[iterater2]])
        return pairedList

pairings = pair(list)
count=0
mul=[]
for i in pairings:
    x=i[0]*i[1]
    mul.append(x)
if n in mul:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9072
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	int a,b,c,k;
	cin >> a >> b >> c >> k;
	int ans=0;
	if(a>k)
	{
		ans=k;
	}
	else
	{
		ans+=a;
		k-=a;
		k-=b;
		ans-=max(0,k);
	}
	cout << ans << endl;
		
		




}

Measured memory_bytes: 3192
# Problem: https://atcoder.jp/contests/abc081/tasks/arc086_a
# Python 3rd Try

import sys
from collections import Counter
# import heapq,copy
# import pprint
# from collections import deque
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]


def solver(ball_count, limit_num, ball_write_nums):
    result = 0
    total_count = Counter(ball_write_nums)
    count_list = list(total_count.values())
    count_list.sort()
    change_num = len(count_list) - limit_num
    for j in range(0, change_num, +1):
        result += count_list[j]
    return result


if __name__ == "__main__":
    K, N = MI()
    SI = LI()
    print("{}".format(solver(K, N, SI)))


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

int main(){
	int n;
	cin>>n;
	int a[n];
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int dp[n];
	dp[1]=0;
	dp[2]=abs(a[2]-a[1]);
	for(int i=3;i<=n;i++)
		dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
	cout<<dp[n]<<"\n";
}


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

int read(){
	int x=0; char c=getchar(); int flag=1;
	while(!isdigit(c)) { if(c=='-') flag=-1; c=getchar(); }
	while(isdigit(c)) { x=((x+(x<<2))<<1)+(c^48); c=getchar(); }
	return x*flag;
}

const int N=200000;
int n;
int a[N+5];
int t[N+5];

set<int> s;
set<int>::iterator it1,it2;

signed main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read(),t[a[i]]=i;
    
    s.insert(0); s.insert(n+1);
    long long ans=0;
    
    for(int i=1;i<=n;i++){
	    it2=it1=s.lower_bound(t[i]);
	    it1--;
	    ans+=1ll*i*(t[i]-*it1)*(*it2-t[i]);
	    s.insert(t[i]);
	}
	printf("%lld\n",ans);
    return 0;
}

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

using namespace std;
int main(){
  int x;
  cin >> x;
  for(int i = 0; ; i++){
    bool ans = true;
    for(int j = 2; j < x + i; j++){
      if((x + i) % j == 0){
        ans = false;
        break;
      }
    }
    if(ans){
      cout << x + i << endl;
    break;
    }
  }
}

Measured memory_bytes: 256
#![allow(unused_macros)]

// cf. [Rustで競技プログラミングの入力をスッキリ記述するマクロ - Qiita](https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8)
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        c: chars,
    }
    let c = c[0];
    println!("{}", (c as u8 + 1) as char);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

typedef long long ll;

ll encode(int* state)
{
	ll res = 0;
	for (int i = 0; i < 13; ++i)
		res = res << 4 | state[i];
	return res;
}
void decode(int* d, ll e)
{
	for (int i = 12; i >= 0; --i, e >>= 4)
		d[i] = e & 15;
}

map<ll, int> minSteps;
int dir[] = { -1, 1, -2, 2, -4, 4 };
map<int, bool> ok[3];

map<ll, int> problemSteps;

int start_from_initial(ll current, ll next)
{
	bool newState = minSteps.count(next) == 0;
	if (newState)
		minSteps[next] = minSteps[current] + 1;

	return newState && minSteps[next] < 10 ? 0 : -1;
}
int start_from_problem(ll current, ll next)
{
	bool newState = problemSteps.count(next) == 0;
	if (newState)
		problemSteps[next] = problemSteps[current] + 1;

	if (minSteps.count(next))
		return problemSteps[next] + 10;

	return newState && problemSteps[next] < 10 ? 0 : -1;
}
int bfs(ll initial, int (*f)(ll, ll))
{
	queue<ll> q;
	q.push(initial);

	while (!q.empty())
	{
		ll e = q.front();
		q.pop();
		int d[13];
		decode(d, e);

		int zero_pos[2];
		for (int i = 0, j = 0; j < 2; ++i)
			if (!d[i])
				zero_pos[j++] = i;

		for (int i = 0; i < 2; ++i)
		{
			for (int j = 0; j < 6; ++j)
			{
				int a = zero_pos[i];
				int b = a + dir[j];
				if (a > b)
					swap(a, b);
				if (a < 0 || b > 12 || !d[a] && !d[b] || !ok[j/2][a])
					continue;

				int copy[13];
				memcpy(copy, d, sizeof(copy));
				swap(copy[a], copy[b]);
				ll next = encode(copy);

				int r = f(e, next);
				if (r == 0)
					q.push(next);
				else if (r > 0)
					return r;
			}
		}
	}

	return -1;
}

int main()
{
	int o[][9] = {
		{ 1, 2, 4, 5, 6, 7, 9, 10, -1 },
		{ 0, 10, -1 },
		{ 1, 2, 3, 5, 6, 7, -1 }
	};
	for (int i = 0; i < 3; ++i)
		for (int j = 0; o[i][j] != -1; ++j)
			ok[i][o[i][j]] = true;

	int initial[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 };
	ll t = encode(initial);
	minSteps[t] = 0;

	bfs(t, start_from_initial);

	while (true)
	{
		int d[13];
		for (int i = 0; i < 13; ++i)
			scanf("%d", d + i);
		if (d[0] == -1)
			break;

		int ans = -1;
		ll s = encode(d);
		if (minSteps.count(s))
			ans = minSteps[s];
		else
		{
			problemSteps.clear();
			ans = bfs(s, start_from_problem);
		}

		if (ans != -1)
			printf("%d\n", ans);
		else
			puts("NA");
	}

	return 0;
}

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

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

    if (b <= a)
        cout << "delicious" << endl;
    else if (b <= a + x)
        cout << "safe" << endl;
    else
        cout << "dangerous" << endl;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
int main()
{
  	int n;
  	cin >> n;
  
  	ll suma = 0LL;
  
  	for(int i = 1; i <= n; ++i)
    {
     	if(i%3==0 || i%5==0)continue;
      	suma += (ll)i;
    }
  
  	cout << suma << '\n';
  
 	return 0; 
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define mod 1000000007
#define inf 1e17
using namespace std;

int main() 
{ 
   int n;
   cin>>n;
   double x;
   double dp[n+1][n+1];
   dp[0][0] = 1;
   for(int i=1;i<=n;i++)
   {
      dp[0][i] = 0;
   }
   vector<double>v;
   // for(int i=0;i<n;i++)
   // {
   //    cin>>x;
   //    v.pb(x);
   // }
   for(int i=1;i<=n;i++)
   {
      cin>>x;
      for(int j=0;j<=n;j++)
      {

         if(j==0)
         {
            dp[i][j] = dp[i-1][j] * (1-x);
         }
         else
         {
            dp[i][j] = (dp[i-1][j-1] * x) + (dp[i-1][j]*(1-x));
         }
      }
   }
   // 
   double sum=0;
   for(int i=n/2+1;i<=n;i++)
   {
      sum = sum + dp[n][i];
   }
   printf("%.10lf", sum);
} 

Measured memory_bytes: 70528
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
class UnionFind {
public:
    vector<int> d;
    UnionFind(int n = 0) : d(n, -1) {}
    int find(int x) {
        if(d[x] < 0){
            return x;
        }
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); 
        y = find(y);
        if(x == y){
            return false;
        }
        if(size(x) < size(y)){
            swap(x,y);
        } 
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { 
        return find(x) == find(y);
    }
    int size(int x) { 
        return -d[find(x)];
    }
};

int main() {

    int n, m;
    cin >> n >> m;
    UnionFind uf(100000);
    rep(i, m){
        int x, y, z;
        cin >> x >> y >> z;
        --x; --y;
        uf.unite(x, y);
    }

    set<int> st;
    rep(i, n){
        st.insert(uf.find(i));
    }
    cout << st.size() << endl;

    return 0;
}


Measured memory_bytes: 5376
# cf16-exhibition-final-openC - Cheating Nim
import sys
input = sys.stdin.readline

from functools import reduce
from operator import xor


def main():
    # player is second move -> make xor 0
    N = int(input())
    A = sorted(map(int, [input() for _ in range(N)]), reverse=1)
    ans, x = 0, reduce(xor, A)
    # cand := rightmost bits of i^i-1
    cand = set(bin(i ^ i - 1)[::-1].rfind("1") for i in A)
    for i in range(29, -1, -1):
        p = 2 ** i
        if x & p:  # i-th bit is on
            if i in cand:  # possible to erase i-th bit of x
                x ^= (p - 1)
                ans += 1
            else:
                print(-1)
                return
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 14768
#include <bits/stdc++.h>
    using namespace std;
     
    int main()
    {
    long long n,a,i,x;
      float sum=0.0;
      
      cin>>n;
      
      for(i=0;i<n;i++)
      {
        cin>>x;
        sum+=(float)1/x;
        //cout<<"intermediate sum :: "<<sum<<"\n";
      }
      
      sum=1/sum;
      
      printf("%lf\n",sum);
      
     return 0; 
    }

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

int main() {
  int N, M;
  cin >> N;
  int ans = 0;
  int A[N+1];
  for(int i=1;i<=N;i++) {
    cin >> A[i];
    ans += A[i];
  }
  cin >> M;
  int B[M+1], C[M+1];
  for(int i=1;i<=M;i++){
    cin >> B[i] >> C[i];
  }
  for(int i=1; i<=M;i++){
    cout << ans - (A[B[i]] - C[i]) << endl;
  }
}

Measured memory_bytes: 256