akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
#define F first 
#define S second 
#define MAX 10000003 
using namespace std; 
  
typedef long long ll; 
const int mod = 1000000007; 
  
int prime[MAX]; 
unordered_map<int, int> max_map; 
  
// Function to return a^n 
ll power(int a, int n) 
{ 
    if (n == 0) 
        return 1; 
  ll p = power(a, n / 2) % mod; 
    p = (p * p) % mod; 
    if (n & 1) 
        p = (p * a) % mod; 
    return p; 
} 
  
// Function to find the smallest prime factors 
// of numbers upto MAX 
void sieve() 
{ 
    prime[0] = prime[1] = 1; 
    for (int i = 2; i < MAX; i++) { 
        if (prime[i] == 0) { 
            for (int j = i * 2; j < MAX; j += i) { 
                if (prime[j] == 0) { 
                    prime[j] = i; 
                } 
            } 
            prime[i] = i; 
        } 
    } 
} 
  
// Function to return the LCM modulo M 
ll lcmModuloM(const int* ar, int n) 
{ 
  
    for (int i = 0; i < n; i++) { 
        int num = ar[i]; 
        unordered_map<int, int> temp; 
  
        // Temp stores mapping of prime factor to 
        // its power for the current element 
        while (num > 1) { 
  
            // Factor is the smallest prime factor of num 
            int factor = prime[num]; 
  
            // Increase count of factor in temp 
            temp[factor]++; 
  
            // Reduce num by its prime factor 
            num /= factor; 
        } 
            
        for (auto it : temp) { 
  
            // Store the highest power of every prime 
            // found till now in a new map max_map 
            max_map[it.first] = max(max_map[it.first], it.second); 
        } 

    } 
    
    ll ans = 1; 
  
    for (auto it : max_map) { 
  
        // LCM is product of primes to their highest powers modulo M 
        ans = (ans * power(it.F, it.S)) % mod; 
    } 
  
    return ans; 
} 
ll modi(ll x){
    return power(x, mod - 2);
}
// Driver code 
int main() 
{ 
    sieve(); 
    ll n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    ll x = lcmModuloM(a, n);
    //cout << x << endl;
    ll o  = 0;
    for(int i = 0; i < n; i++){
        o += modi(a[i]);
        o %= mod;
    } 
    //cout << o << endl;
    while(o < 0){o += mod;}
    cout << (x * o) % mod << endl;
    return 0; 
} 

Measured memory_bytes: 39808
L,R = map(int,input().split())
sa = R - L
ans = 2020
if sa > 673:
	print("0")
else:
	for i in range (L,R):
		for j in range (i+1,R+1):
			tmp = (i * j) % 2019
			if ans > tmp:
				ans = tmp
	print(ans)

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

int sum_of_digits(int N) {
  int sum = 0;
  while (N > 0) {
    sum += N % 10;
    N /= 10;
  }
  return sum;
}

int main() {
  int N;
  cin >> N;
  int sum = sum_of_digits(N);
  if (N % sum == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
def find(x):
  if P[x] < 0:
    return x
  else:
    P[x] = find(P[x])
    return P[x]

N, M, *X = map(int,open(0).read().split())
P = [-1] * (N + 1)
S = N * (N - 1) // 2
r = [S]

while X:
  b, a = find(X.pop()), find(X.pop())
  if a != b:
    S -= P[a] * P[b]
    if P[a] > P[b]:
      a, b = b, a
    P[a] += P[b]
    P[b] = a
  r.append(S)

r.pop()
print(*reversed(r), sep='\n')

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

using namespace std;

int main() {
	string C1, C2;	cin >> C1 >> C2;
	bool b = true;

	for (int i = 0; i < 3; ++i) {
		if (C1[i] != C2[2 - i]) {
			cout << "NO" << endl;
			return 0;
		}
	}

	cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	float a, b, c, d, e, f;
	float x, y;
	
	while (scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF){
		y = (c * d - a * f) / ( b * d - a * e);
		x = (c - b * y) / a;
		
		printf("%.3f %.3f\n", x, y);
	}
	
	return (0);
}

Measured memory_bytes: 644
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = 1; i <= (int)(n); i++) 
#define dunk(n) cout << n << endl
#define all(a) (a).begin(),(a).end()
typedef pair<int,int> P;
typedef long long ll;

int main() {
    string s,t;
    cin >> s >> t;
    dunk(t+s);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <sstream>
#include <string>
#include <vector>

#define endl '\n'
#define ull unsigned long long
#define ll long long
#define ul unsigned long
#define ld long double
#define PI 3.14159265359

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t = 1;
	// cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<int> v(n), c(n);
		for (auto &i : v) {
			cin >> i;
		}
		for (auto &i : c) {
			cin >> i;
		}
		int m = INT_MIN;
		int s = 0;
		for (int i = 0; i < n; i++) {
			if (v[i] > c[i])
				s += v[i] - c[i];
			m = max(m, s);
		}
		cout << m;
	}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=998244353,MAX=1005,INF=1<<30;

ll rui(ll a,ll b){
    ll ans=1;
    while(b>0){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b/=2;
    }
    return ans;
}

int main(){
    
    int N;cin>>N;
    vector<int> X(N),Y(N);
    for(int i=0;i<N;i++){
        cin>>X[i]>>Y[i];
    }
    
    ll ans=rui(2,N);
    ans+=mod-(N+1);
    ans%=mod;
    
    for(int a=0;a<N;a++){
        for(int b=a+1;b<N;b++){
            ll cnt=0;
            int left=a,right=b;
            for(int k=0;k<N;k++){
                //if(k==a||k==b) continue;
                if((X[k]-X[a])*(Y[b]-Y[a])-(X[b]-X[a])*(Y[k]-Y[a])==0){
                    left=min(left,k);
                    right=max(right,k);
                    cnt++;
                }
            }
            if(left==a&&right==b) ans+=mod-(rui(2,cnt)-cnt-1)%mod;
            ans%=mod;
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Rep(i, k, n) for (int i = k; i < (int)(n); i++)
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; }
const long long INF = 1LL << 60;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int h, w;
vector<string> s;
int d[1001][1001];
queue<P> q;

void bfs()
{
    while(!q.empty())
    {
        P p = q.front(); q.pop();
        rep(i, 4)
        {
            int x = p.first + dx[i], y = p.second + dy[i];
            if (x >= 0 && x < w && y >= 0 && y < h && s[y][x] != '#'
            && d[x][y] == -1)
            {
                q.push(P(x, y));
                d[x][y] = d[p.first][p.second] + 1;
            }
        }
    }
}
int main()
{
    cin >> h >> w;
    s.resize(h);
    rep(i, h) cin >> s[i];

    rep(i, w)
        rep(j, h) d[i][j] = -1;

    rep(i, h)
    {
        rep(j, w)
            if(s[i][j] == '#')
            {
                d[j][i] = 0;
                q.push(P(j, i));
            }
    }
    bfs();
    int ans = 0;
    rep(i, w)
        rep(j, h) ans = max(ans, d[i][j]);
    cout << ans << endl;
}

Measured memory_bytes: 13456
N, X = map(int, input().split())

a = [1] * (N + 1)
p = [1] * (N + 1)
for i in range(N):
    a[i + 1] = a[i] * 2 + 3
    p[i + 1] = p[i] * 2 + 1

def f(n, x):
    if n == 0:
        return 0 if x <= 0 else 1
    elif x <= 1 + a[n - 1]:
        return f(n - 1, x - 1)
    else:
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1])
    
print(f(N, X))


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647

int main(){
  int N;cin>>N;
  vector<int> P(1,1);
  int s=6;
  while(s<=N){
    P.push_back(s);
    s*=6;
  }
  s=9;
  while(s<=N){
    P.push_back(s);
    s*=9;
  }
  int ps=P.size();
  vector<int> ANS(N+1);
  ANS[0]=0;
  int c;
  for(int i=1;i<=N;i++){
    c=INF;
    for(int j=0;j<ps;j++){
      if(i>=P[j]){
        c=min(c,ANS[i-P[j]]+1);
      }
    }
    ANS[i]=c;
  }
  cout<<ANS[N]<<endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, m, n) for(int i = (int)(m); i < (int)(n); ++i)


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

    vector<int> p(A), q(B), r(C);
    REP(i, A) cin >> p[i];
    REP(i, B) cin >> q[i];
    REP(i, C) cin >> r[i];

    sort(p.begin(), p.end(), greater<int>());
    sort(q.begin(), q.end(), greater<int>());
    sort(r.begin(), r.end(), greater<int>());

    priority_queue<int> cand;
    REP(i, X) cand.push(p[i]);
    REP(i, Y) cand.push(q[i]);
    REP(i, C) cand.push(r[i]);

    long long ans = 0;
    REP(i, X+Y){
        ans += cand.top();
        cand.pop();
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3572
N = int(input())
XLlist = [tuple(map(int, input().split())) for _ in range(N)]
XLlist.sort(key=lambda x: x[0])
ans = 1
x, l = XLlist[0]
rl = x + (l - 1)
for x, l in XLlist:
    ll = x - l
    if ll <= rl:
        rl = min(rl, x + l - 1)
    else:
        ans += 1
        rl = x + l - 1

print(ans)


Measured memory_bytes: 18192
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b;

ll powll(ll d){
	ll r = 1;
	for(ll i = 1; i <= d; i++){r *= 2;}
	return r;
}

ll func(ll n){
	if(n == -1){return 0;}
	ll r = 0;
	for(int d = 0; d < 50; d++){
		ll one = 0;
		one += ((n+1)/powll(d+1))*powll(d);
		one += max((n+1)%powll(d+1)-powll(d), 0LL);
		if(one%2){r += powll(d);}
	}
	return r;
}

int main(){
	cin >> a >> b;
	
	ll ans = 0;
	ans = (func(b)^func(a-1));
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		long A = long.Parse(str[0]);
		long B = long.Parse(str[1]);
		long ans = 999999;
		for(var i=0;i<A;i++){
			string[] str2 = Console.ReadLine().Split();
			long C = long.Parse(str2[0]);
			long D = long.Parse(str2[1]);
			if(D<=B){
				ans = Math.Min(ans,C);
			}
		}
		if(ans == 999999){
			Console.WriteLine("TLE");
		} else {
			Console.WriteLine(ans);
		}
	}
}

Measured memory_bytes: 11092
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;

#define   M             100005
#define   ll            long long
#define   PI            atan(1.0)*4
#define   mst(x,v)      memset(x,v,sizeof(x))
#define   inf           1e9
#define   rush()        int T;scanf("%d",&T);while(T--)
#define   debug         puts("debug")

typedef   pair<int,int> P;

int a[M];

int main() {
/*
	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
*/
	ll n;
	scanf("%lld",&n);
	for(int i=0;i<n;i++) scanf("%lld",&a[i]);
	
	sort(a,a+n);
	
	ll sum = 0,ans = 0;
	
	
	sum = a[0];
	for(int i=1;i<n;i++) {
		if(sum*2>=a[i]) {
			sum+=a[i];
		}
		else {
			sum = a[i]+sum;
			ans = i;
		}
	}
	
	printf("%lld\n",n-ans);
}




Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, k; cin >> n >> k;
  vll a(n); REP(i, n) cin >> a[i];
  //  dp[i][j]: i番目までの子供達にj個の飴を配る場合の数
  vvll dp(n+1, vll(k+1, 0));
  vll cum(k+2, 0);
  dp[0][0] = 1;
  rep(i, 1, n+1) {
    cum[0] = 0;
    rep(j, 1, k+2) cum[j] = (cum[j-1] + dp[i-1][j-1]) % MOD;
    rep(j, 0, k+1) dp[i][j] = (cum[j+1] - cum[max(0LL, j-a[i-1])] + MOD) % MOD;
  }
  cout << dp[n][k] << endl;
  return 0;
}


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

using namespace std;

int check(char in){
	string left = "qwertasdfgzxcvb";
	for(int i = 0; i < left.size(); i++){
		if(in == left[i]) return 1;
	}
	return 0;
}

int main(){

	string in;
	while(cin >> in && in != "#"){
		int sum = 0;
		int status = 0;
		if(check(in[0])) status = 1;

		for(int i = 1; i < in.size(); i++){
			if(check(in[i])){
				if(!status){
					sum++;
					status = 1;
				}
			}else{
				if(status){
					sum++;
					status = 0;
				}
			}
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
double x[10],y[10];
int main()
{
	int n; double res=0;
	cin>>n;
	for(int i=0;i<n;i++) cin>>x[i]>>y[i];
	for(int i=0;i<n;i++) for(int j=i+1;j<n;j++) res+=sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
	res=res/((double)(n)*0.5);
	cout<<fixed<<res;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;

#define ft first
#define sd second
#define flag bool fl=true

#define mod 1000000007
#define N 10000001
#define MX 1000000001
#define MXX 1000000000000000001

#define pb push_back
#define fa(n) for(int i=0;i<n;i++)
#define fa1(n) for(int i=1;i<=n;i++)
#define fab(i, a, b) for(int i=a;i<=b;i++)
#define cs cout<<"Case "<<qq<<": "
#define csl cout<<"Case "<<qq<<":"<<endl;
#define T int tt, qq=0; cin>>tt; while(qq++<tt)
#define fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ina(array, size) for(int i=0;i<size;i++) cin>>array[i];
#define outa(array, size) for(int i=0;i<size;i++) cout<<array[i]<<" ";
#define outla(array, size) for(int i=0;i<size;i++) cout<<array[i]<<endl;

#define deg(rad) (rad*180.0)/pi
#define pi acos(-1)
#define log(n) (int)log2(n)
#define logg(a)(b) log(b)/log(a)

int main()
{
    string s, t;
    cin>>s>>t;

    int len=MX;
    for(int i=0;i<=s.size()-t.size();i++)
    {
        int l=0;
        for(int j=0;j<t.size();j++)
            if(t[j]!=s[i+j]) l++;

        len=min(len, l);
    }
    cout<<len;
}


/*

//----------useful_functions----------

long long extended_euclid(ll a, ll b, ll &x, ll &y) //ax+by=c
{
    if(b==0)
    {
        x=1, y=0;
        return a;
    }

    ll x1, y1;
    ll d=extended_euclid(b, a%b, x1, y1);
    x=y1;
    y=x1-y1*(a/b);
    return d;
}

long long bigMod(ll a, ll b) //(a^b)%mod
{
    ll ans=1;
    while(b)
    {
        if(b%2==1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return ans%mod;
}

long long modInverse(ll a, ll b) //a*x=1 mod b
{
    ll x, y;
    ll gcd=extended_euclid(a, b, x, y);

    if(gcd==1) return ((x%b)+b)%b;
    else return 1;
}

long long nCr(ll n, ll r) //n<=1e6
{
    //declare globally-> ll fact[1000001];
    fact[1]=1;
    for(ll i=2; i<1000001; i++)
        fact[i]=(i*fact[i-1])%mod;

    return (fact[n]*modInverse(fact[r], mod)*modInverse(fact[n-r], mod))%mod;
}

long long josephus(ll n, ll k) //k'th person is killed out of n in the circle
{
    if(n==1) return 1;
    else return (josephus(n-1, k)+k-1)%n+1;
}

bool fl[N+1];
vector<ll> sieve(ll n)
{
    vector<ll> primes;
    for(ll i=3; i*i<=n; i+=2)
        for(ll j=i*i; j<=n; j+=i+i)
            fl[j]=true;

    primes.pb(2);
    for(ll i=3; i<=n; i+=2) if(!fl[i]) primes.pb(i);
    return primes;
}
vector<ll> p=(sieve(N));

ll eulerTotient(ll x)
{
    db ans=x;
    for(int i=0; i<p.size() && p[i]*p[i]<=x; i++)
    {
        if(x%p[i]==0)
        {
            ans*=(1.0-(1/(db)p[i]));
            while(x%p[i]==0) x/=p[i];
        }
    }
    if(x>1) ans*=(1.0-(1/(db)x));

    return ans;
}

*/


Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,sum=0;
  	int a[m];
  	cin>>n>>m;
  	for(int i=0;i<m;i++)
    {cin>>a[i];
     sum=sum+a[i];
    }
  	if(sum>n)
      cout<<-1;
  	if(sum<=n)
      cout<<n-sum;
}

Measured memory_bytes: 3668
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
int main()
{
    int n,m,i,j;
    cin>>n>>m;
    string str;
    vector<string>s;
    for(i=1;i<=n;i++){
        cin>>str;
        s.push_back(str);
    }
    sort(s.begin(),s.end());
    for(auto x:s) cout<<x;
    cout<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long  
#define mod 1000000007
#define am 998244353
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){ 
  int c=max(a,b)-min(a,b);
  return c;
}
int gcd(int a,int b){//最大公約数
  int c=a%b;
  while(true){
    if(c==0) break;
    a=b;
    b=c;
    c=a%b;
  }
  return b;
}
bool IsPrime(int num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for(int i=3;i<=sqrtNum;i+=2){
    if(num%i==0){
      return false;
    }
  }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	    
string w[1000];
queue<pair<int,int> > q;
signed main(){
// __builtin_ctz(N);      Nを２で何回割り切れるかを返す
//(n+1)*n/2;              １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,c=0;
    string b;
    cin>>a>>b;
    for(int i=0;i<(a+1)/2;i++){
    if(b[i]!=b[i+(a+1)/2]) c=1;
    }
    if(c||a==1) cout<<"No";
    else cout<<"Yes";
    cout<<"\n";
    
}


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

using namespace std;

int main() {
  int n = 0;
  cin >> n;
  string s = "";
  cin >> s;
  for (char &c : s) {
    c += n;
    if (c > 'Z') {
      c = 'A' + (c - 'Z' - 1);
    }
  }
  cout << s << endl;
  return 0;
}


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

int main(){
    string ca;
    cin >> ca;
    int h1,h2;
    while(1){
        if (ca == "-") break;
        
        cin >> h1;
        for (int i=0;i<h1;i++){
            cin >> h2;
            ca = ca.substr(h2,ca.size()-h2) + ca.substr(0,h2);
            
        } 
        cout << ca << endl;
        cin >> ca;

    
    }

    return 0;
}


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

int main(){
	int n,t,s=0,t_old=0,t_now,t_tmp,t_s=0;
	cin>>n>>t;
	for(int i=0;i<n;i++){
		cin>>t_now;
		t_tmp=t_now-t_old;
		if(t_tmp>t){
			s+=(t_old-t_s+t);
			t_s=t_now;
		}
		t_old=t_now;
	}
	
	if(t_tmp>t)	cout<<s+t<<endl;
	else cout<<s+(t_now-t_s+t)<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int, int>
#define pb(a) push_back(a)
#define all(v) v.begin(), v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

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

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

	int no1, no2;

	int N;
	cin >> N;

	vint A(N);
	vint B(N);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
		B[i] = A[i];
	}

	sort(all(A), greater<int>());
	no1 = A[0];
	no2 = A[1];

	for (int i = 0; i < N; i++) {
		if (B[i] == no1) {
			cout << no2 << endl;
		} else {
			cout << no1 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 4736
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    string S;
    in >> S;

    // solution here
    auto len = S.size();
    ll count = 0;
    REP(i, len/2) {
        if (S[i] != S[len-1-i]) {
            ++count;
        }
    }
    out << count << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


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

ll triple(ll a) {
    return a * a * a;
}

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans = triple(N / K);
    if (K % 2 == 0) {
        ans += triple((N + K / 2) / K);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 1987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const int MOD = 123456789;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1 }, dy[] = { 1,0,-1,0 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

int main() {
	int ans=0;
	int n;
	scanf("%d",&n);
	while(n--)
	{
		int x;
		scanf("%d",&x);
		while(x%2==0)ans++,x/=2;
	}
	printf("%d",ans);
}

Measured memory_bytes: 256
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int a,b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
    ll n, cnt=1;
    cin >> n;
    vector<ll> a(n), ans;
    rep(i, n)cin >> a.at(i);
    sort(a.rbegin(), a.rend());
    REP(i, n-1){
        if(ans.size() == 4)break;
        if(a.at(i) == a.at(i-1)){
            cnt++;
            if(cnt == 2){
                ans.push_back(a.at(i));
                ans.push_back(a.at(i));
                cnt=0;
            }
        }
        else cnt=1;
    }
    if(ans.size() == 4)cout << ans.at(0)*ans.at(2);
    else cout << 0;
}

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

inline int read() {
	int ret, cc;
	while (!isdigit(cc = getchar()));
	ret = cc - 48;
	while ( isdigit(cc = getchar()))
		ret = cc - 48 + ret * 10;
	return ret;
}

const int MOD = 1000000007;
inline int add(int a, int b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, int b) { return (a -= b) <    0 ? a + MOD : a; }
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
inline int qpow(int a, int p) {
	int ret = 1;
	for (; p; p >>= 1, a = mul(a, a))
		if (p & 1) ret = mul(ret, a);
	return ret;
}


const int MAXN = 200010;

int fac[MAXN];
int inv[MAXN];

int col[MAXN];
int val[MAXN];
std::vector<int> node[MAXN];
int ans[MAXN];
int root[MAXN];
int n, X, Y;

int main() {
#ifdef ARK
	freopen("test.in", "r", stdin);
#endif
	n = read(), X = read(), Y = read();
	val[0] = 0x3f3f3f3f;
	for (int i = 1; i <= n; ++i) {
		col[i] = read(), val[i] = read();
		if (val[i] < val[root[col[i]]]) 
			root[col[i]] = i;
		if (val[i] < val[root[0]])
			root[0] = i;
		node[col[i]].push_back(i);
	}
	int rt2 = 0;
	for (int i = 1; i <= n; ++i) 
		if (root[i] != root[0] && val[root[i]] < val[rt2])
			rt2 = root[i];
	if (val[rt2] + val[root[0]] > Y) rt2 = 0;
	for (int i = 1; i <= n; ++i) {
		if (root[i] != root[0]) {
			int cnt = 1;
			for (auto x : node[i]) if (x != root[i]) {
				if (val[x] + val[root[i]] <= X) cnt++;
				else if (val[x] + val[root[0]] <= Y) ans[i]++;
			}
			if (val[root[i]] + val[root[0]] <= Y) ans[i] += cnt;
		} else {
			ans[i] = 1;
			for (auto x : node[i]) if (x != root[i]) {
				if (val[x] + val[root[i]] <= X) ans[i]++;
				else if (val[x] + val[rt2] <= Y) ans[i]++;
			}
		}
	}
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = mul(fac[i - 1], i);
	inv[n] = qpow(fac[n], MOD - 2);
	for (int i = n; i >= 1; --i) inv[i - 1] = mul(inv[i], i);
	int res1 = 1, res2 = 0;
	for (int i = 1; i <= n; ++i) 
		res1 = mul(res1, inv[ans[i]]), res2 += ans[i];
	printf("%d\n", mul(fac[res2], res1));
}


Measured memory_bytes: 13952
#include<iostream>
using namespace std;
int main()
{
	int n;
  	cin>>n;
  	int x = n%10;
  	if(x==2 || x==4 || x==5 ||x==7 || x==9)
      	cout<<"hon";
  	else if(x==0 || x==1 ||x==6 || x==8)
      	cout<<"pon";
  	else
      	cout<<"bon";
  	return 0;
}

Measured memory_bytes: 3576
using System;
using System.Collections.Generic;
using System.Text;

class TEST{
	static void Main(){
		while(true){
			var s=Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
			if(s[0]==0 && s[1]==0 && s[2]==0)break;
			Sol mySol=new Sol(s[0],s[1],s[2]);
			Console.WriteLine(mySol.Ans);
		}
	}
}

class Sol{
	int ans;
	public int Ans{
		get{return ans;}
	}
	
	int An;
	int Bn;
	int R;
	public Sol(int an,int bn,int r){
		An=an;Bn=bn;R=r;
		Point[] A=new Point[An];
		Point[] B=new Point[Bn];
		
		for(int i=0;i<An;i++){
			var d =Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
			A[i]=new Point(d[0],d[1]);
		}
		for(int i=0;i<Bn;i++){
			var d =Array.ConvertAll(Console.ReadLine().Split(' '),elem=>int.Parse(elem));
			B[i]=new Point(d[0],d[1]);
		}
	
		//Array.Sort(B,(x,y)=>(int)(x.R-y.R));
		Array.Sort(B,(x,y)=>(x.R>y.R?1:(x.R<y.R?-1:0)));

//for(int i=0;i<Bn;i++){Console.WriteLine("B[{0}]:{1},{2},{3:f4}",i,B[i].X,B[i].Y,B[i].R);}
	
		int cnt=0;
		for(int i=0;i<An;i++){
			int L=LowerBoundSearch(A[i].R-4*R,B);
			int U=UpperBoundSearch(A[i].R+4*R,B);
//Console.WriteLine("A[{0}]:,{1},{2},{3:f4},Ltrgt,{4},L,{5},Utrgt,{6},U,{7}",i,A[i].X,A[i].Y,A[i].R,A[i].R-4*R,L,A[i].R+4*R,U);
			for(int j=L;j<=U;j++){
				if((A[i].X-B[j].X)*(A[i].X-B[j].X)+(A[i].Y-B[j].Y)*(A[i].Y-B[j].Y)<=16*R*R){cnt++;/*dump(i,j,A,B);*/}
			}
		}
		ans=cnt;
	}
	
	void dump(int i,int j,Point[] A,Point[] B){Console.WriteLine("A[{0}]:{1},{2}-B[{3}]:{4},{5}\tD2={6}\tR2={7}",i,A[i].X,A[i].Y,j,B[j].X,B[j].Y,(A[i].X-B[j].X)*(A[i].X-B[j].X)+(A[i].Y-B[j].Y)*(A[i].Y-B[j].Y),16*R*R);}
	
	
	int LowerBoundSearch(double trgt,Point[] X){
		int len=X.Length;
		if(len==0)return 0;
		
		int idx=0;
		int max=len-1;
		int min=0;
		
		while(len!=0){
			idx=(max+min)/2;
			if(X[idx].R>=trgt){
				max=idx;
			}
			if(X[idx].R<trgt){
				min=idx;
			}
			len/=2;
		}
		
		//バックして調整
		while(X[idx].R>trgt && idx>0)idx--;
		while((idx+1)!=X.Length && X[idx+1].R<=trgt)idx++;
		return idx;
	}
	
	int UpperBoundSearch(double trgt,Point[] X){
		int len=X.Length;
		if(len==0)return 0;
		
		int idx=0;
		int max=len-1;
		int min=0;
		
		while(len!=0){
			idx=(max+min)/2;
			if(X[idx].R>=trgt){
				max=idx;
			}
			if(X[idx].R<trgt){
				min=idx;
			}
			len/=2;
		}
		
		//前進して調整
		while(X[idx].R<trgt && idx<X.Length-1)idx++;
		while(idx!=0 && X[idx-1].R>=trgt)idx--;
		return idx;
	}
	
	
	
}



class Point{
	
	int x;
	int y;
	double r;
	
	public int X{
		get{return x;}
	}
	public int Y{
		get{return y;}
	}
	public double R{
		get{return r;}
	}
	public Point(int a,int b){
		x=a;y=b;r=Math.Sqrt((double)(x*x+y*y));
	}
}

Measured memory_bytes: 16856
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-9;

int main() {
	int N; cin >> N;
	vector<int> r(N);
	for (int i = 0; i < N; i++)
		cin >> r[i];
	sort(r.begin(), r.end());
	double ma = 0;
	for (int n = 3; n <= N; n++) {
		vector<int> a(r.end() - n, r.end());
		do {
			vector<double> x(n), y(n);
			for (int i = 0; i < n; i++) {
				x[i] = a[i] * cos(M_PI*2 / n * i);
				y[i] = a[i] * sin(M_PI*2 / n * i);
			}
			for (int t = 0; t < 10000; t++) {
				int i = rand() % n;
				int j = (i + n - 1) % n, k = (i + 1) % n;
				double dx = x[k] - x[j], dy = y[k] - y[j];
				double _dx = dy, _dy = -dx;
				double r = sqrt(_dx * _dx + _dy * _dy);
				x[i] = _dx / r * a[i];
				y[i] = _dy / r * a[i];
			}
			double sum = 0;
			for (int i = 0; i < n; i++) {
				int j = (i + 1) % n;
				sum += x[i] * y[j] - y[i] * x[j];
			}
			ma = max(ma, sum);
		} while (next_permutation(a.begin() + 1, a.end()));
	}
	printf("%.15f\n", ma / 2);
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
    int n,a[105]={};
    int ans=0;
    string s1,s2,s3;
    cin>>s1>>s2>>s3;
    cout<<s1[0]<<s2[1]<<s3[2]<<endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<vector>
#define ll long long
#define MOD(x) ((x)>=mod?(x)-mod:(x))
using namespace std;
const int maxn=500010, mod=1e9+7;
struct tjm{int too, pre;}e[maxn<<1];
struct poi{int f[3];};
int n, x, ans, tot, tott;
int last[maxn], root[maxn];
vector<poi>q[maxn];
inline void read(int &k)
{
    int f=1; k=0; char c=getchar();
    while(c<'0' || c>'9') c=='-' && (f=-1), c=getchar();
    while(c<='9' && c>='0') k=k*10+c-'0', c=getchar();
    k*=f;
}
inline void add(int x, int y){e[++tot]=(tjm){y, last[x]}; last[x]=tot;}
inline int merge(int x, int y)
{
    if(q[x].size()<q[y].size()) swap(x, y);
    int nx=q[x].size()-1, ny=q[y].size()-1;
    for(int i=0;i<=ny;i++) 
    {
        int sum0=0, sum1=0, sum2=0;
        sum0=1ll*q[x][nx-i].f[0]*q[y][ny-i].f[0]%mod;
        sum1=(1ll*q[x][nx-i].f[1]*q[y][ny-i].f[0]+1ll*q[x][nx-i].f[0]*q[y][ny-i].f[1])%mod;
        for(int j=0;j<3;j++)
            for(int k=2;j+k>=2;k--)
                sum2=(1ll*sum2+1ll*q[x][nx-i].f[j]*q[y][ny-i].f[k])%mod;
        q[x][nx-i].f[0]=sum0; q[x][nx-i].f[1]=sum1; q[x][nx-i].f[2]=sum2;
    }
    q[y].clear(); return x;
}
void dfs(int x, int fa)
{
    if(!last[x]) root[x]=++tott; int dep=0;
    for(int i=last[x], too;i;i=e[i].pre)
    if((too=e[i].too)!=fa)
    {
        dfs(too, x);
        if(!root[x]) root[x]=root[too];
        else dep=max(dep, (int)min(q[root[x]].size(), q[root[too]].size())), root[x]=merge(root[x], root[too]);
    }
    int nx=q[root[x]].size()-1; 
    for(int i=0;i<dep;i++) 
        q[root[x]][nx-i].f[0]=MOD(q[root[x]][nx-i].f[0]+q[root[x]][nx-i].f[2]), q[root[x]][nx-i].f[2]=0;
    poi tmp; tmp.f[1]=tmp.f[0]=(mod+1)>>1; tmp.f[2]=0; q[root[x]].push_back(tmp);
}
inline int power(int a, int b)
{
    int ans=1;
    for(;b;b>>=1, a=1ll*a*a%mod)
    if(b&1) ans=1ll*ans*a%mod;
    return ans;
}
int main()
{
    read(n);
    for(int i=1;i<=n;i++) read(x), add(x, i);
    dfs(0, -1); 
    for(int i=0;i<q[root[0]].size();i++) ans=MOD(ans+q[root[0]][i].f[1]);
    printf("%lld\n", 1ll*ans*power(2, n+1)%mod);
}

Measured memory_bytes: 46836
import java.util.Scanner;

public class Main{
	public Main(){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			int n = sc.nextInt();
			if(n == -1){
				break;
			} else if(n == 0){
				System.out.println(n);
				continue;
			}
			
			String str = "";
			while(n > 0){
				str = n%4 + str;
				n /= 4;
			}
			System.out.println(str);
		}
	}
	
	public static void main(String[] args){
		new Main();
	}
}

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

import static java.lang.System.in;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
        long ans = 0;
        ans += 2*Math.min(b,c);
        b -= ans/2;
        c -= ans/2;
        if(b>0){
            ans += b;
        }else{
            if(a>c-1) ans += c;
            else ans += a+1;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
 
int main(void) {
    int n, first, second, third, out, point;
    char in[16];
 
    scanf("%d ", &n);
 
    while (n--) {
        first = second = third = out = point = 0;
 
        while (out < 3) {
            fgets(in, 15, stdin);
 
            if (in[1] == 'I') {
                point += third;
                third = second;
                second = first;
                first = 1;
            } else if (in[1] == 'U') {
                out++;
            } else {
                point += first + second + third + 1;
                first = second = third = 0;
            }
        }
        printf("%d\n", point);
    }
    return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int swap(int ,int );

int main()
{
    int x,y,r;
    scanf("%d%d",&x,&y);
    if(x < y){
        r = x;
        x = y;
        y = r;
    }
    printf("%d\n",swap(x,y));
    return 0;
}
    int swap(int x, int y) 
    {
        int r;
        while(y > 0){
        r = x % y;
        x = y;
        y = r;
        }
        return x;
    }   


Measured memory_bytes: 2104
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
const int N = 100000 + 10;
using namespace std;
int n, a[N], ans;
int main()
{
  scanf("%d",&n);
  for(int i=1; i<=n; ++i) scanf("%d",&a[i]);
  int tim = 0;
  for(int i=1; i<=n+1; ++i)
  {
    if(i==a[i]) tim++;
    else
    {
      ans += (tim+1)/2;
	  tim = 0;
	}
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 640
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

struct PMA{
	PMA *next[0x100];
	vector<int> accept;
};
int sz;
PMA pma[1000];
PMA *mynew(){
	rep(i, 256) pma[sz].next[i] = 0;
	pma[sz].accept.clear();
	return pma + sz++;
}
PMA *buildPMA(const vector<string> &p) {
	PMA *root = mynew();
	rep(i, p.size()){
		PMA *t = root;
		rep(j, p[i].size()){
			char c = p[i][j];
			if(t->next[c] == NULL) t->next[c] = mynew();
			t = t->next[c];
		}
		t->accept.pb(i);
	}
	queue<PMA*> Q;
	for(char c = 'A'; c <= 'z'; c++){
		if (root->next[c]) {
			root->next[c]->next[0] = root;
			Q.push(root->next[c]);
		}
		else root->next[c] = root;
	}
	while(!Q.empty()){
		PMA *t = Q.front();
		Q.pop();
		for(char c = 'A'; c <= 'z'; c++){
			if(t->next[c]){
				Q.push(t->next[c]);
				PMA *r = t->next[0];
				while(!r->next[c]) r = r->next[0];
				t->next[c]->next[0] = r->next[c];
				each(i, r->next[c]->accept) t->next[c]->accept.pb(*i);
			}
		}
	}
	return root;
}

const int mod = (int)1e9 + 7;
int n, m, k, N, dp[22][500][610][2]; //文字数, prev, state, match
vector<vi> e;
string a[300], b[300];
vector<string> c, v;
pi memo[610][500];
pi next(PMA *p, int s) {
	pi &res = memo[p - pma][s];
	if(res.second >= 0) return res;
	int count = 0;
	rep(i, v[s].size()){
		char c = v[s][i];
		while (!p->next[c]) p = p->next[0];
		p = p->next[c];
		rep(j, p->accept.size()) count++;
	}
	return res = mp(p - pma, count);
}

int main(){
	while(cin >> n >> m >> k, n){
		v.clear();
		memset(dp, 0, sizeof(dp));
		
		rep(i, n) cin >> a[i] >> b[i], v.pb(a[i]), v.pb(b[i]);
		sort(all(v));
		v.erase(unique(all(v)), v.end());
		
		e.clear(); e.resize(v.size());
		rep(i, n){
			int p = lower_bound(all(v), a[i]) - v.begin();
			int q = lower_bound(all(v), b[i]) - v.begin();
			e[p].pb(q);
		}
		c.clear(); c.resize(k);
		rep(i, k) cin >> c[i];
		sz = 0;
		PMA* r = buildPMA(c);
		
		assert(sz < 610);
		rep(i, sz) rep(j, v.size()) memo[i][j].second = -1;
		
		rep(i, v.size()){
			pi x = next(r, i);
			if(v[i].size() <= m && x.second < 2) dp[v[i].size() % 22][i][x.first][x.second] = 1;
		}
		rep(i, m){
			memset(dp[(i + 21) % 22], 0, sizeof(dp[0]));
			rep(j, v.size()) rep(k, sz) rep(l, 2) if(dp[i % 22][j][k][l]){
				rep(h, e[j].size()){
					pi x = next(pma + k, e[j][h]);
					int ni = v[e[j][h]].size() + i;
					if(ni <= m && x.second + l < 2)
					(dp[ni % 22][e[j][h]][x.first][x.second + l] += dp[i % 22][j][k][l]) %= mod;
				}
			}
		}
		int res = 0;
		rep(i, v.size()) rep(j, sz) (res += dp[m % 22][i][j][1]) %= mod;
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 58196
program answer
  implicit none

  integer :: a, b, c, d, e, k

  read(*,*) a
  read(*,*) b
  read(*,*) c
  read(*,*) d
  read(*,*) e
  read(*,*) k
  if(abs(a-b)<=k .and. abs(a-c)<=k .and. abs(a-d)<=k .and. abs(a-e)<=k) then
     if(abs(b-c)<=k .and. abs(b-d)<=k .and. abs(b-e)<=k .and.abs(c-d)<=k) then
        if( abs(c-e)<=k .and. abs(d-e)<=k) then
           write(*,*) 'Yay!'
        else
           write(*,*) ':('
        end if
     else
        write(*,*) ':('
     end if
  else
     write(*,*) ':('
  end if

  stop
 end program answer


Measured memory_bytes: 2852
n,T = map(int,input().split())
a = []
b = []

for i in range(n):
    c,t = map(int,input().split())
    
    if t <= T:
        a.append(c)
        b.append(t)
if b == []:
    print('TLE')
else:
    print(min(a))

Measured memory_bytes: 3060
def solve():
    from itertools import accumulate

    N, W = map(int, input().split())

    e = tuple([] for _ in range(4))
    w1, v1 = map(int, input().split())
    e[0].append(v1)

    for _ in range(N - 1):
        _w, _v = map(int, input().split())
        e[_w - w1].append(_v)

    g = [None for _ in range(4)]
    for j in range(4):
        e[j].sort(reverse=True)
        g[j] = (0,) + tuple(accumulate(e[j]))

    ret = 0
    for a in range(min(len(e[0]), N) + 1):
        for b in range(min(len(e[1]), N - a) + 1):
            for c in range(min(len(e[2]), N - a - b) + 1):
                for d in range(min(len(e[3]), N - a - b - c) + 1):
                    if w1 * a + (w1 + 1) * b + (w1 + 2) * c + (w1 + 3) * d > W:
                        break
                    ret = max(ret, g[0][a] + g[1][b] + g[2][c] + g[3][d])
    return ret


print(solve())


Measured memory_bytes: 40688
#include <bits/stdc++.h>
#define ll long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

ll mod_abs(ll x)
{
    if (x < 0)
        return x * -1;
    return x;
}

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

    ll h, w, tmp, ans = LONG_LONG_MAX, x, y, z, mn, mx;
    cin >> h >> w;
    for (ll i = 1; i <= w; i++)
    {
        x = i * h;
        y = ((w - i) / 2) * h;
        z = ((w - i + 1) / 2) * h;
        mn = min(x, min(y, z));
        mx = max(x, max(y, z));
        ans = min(ans, mx - mn);
    }
    for (ll i = 1; i <= h; i++)
    {
        x = i * w;
        y = ((h - i) / 2) * w;
        z = ((h - i + 1) / 2) * w;
        mn = min(x, min(y, z));
        mx = max(x, max(y, z));
        ans = min(ans, mx - mn);
    }
    tmp = h / 2;
    for (ll i = 1; i <= w; i++)
    {
        x = i * h;
        y = (w - i) * tmp;
        z = (w - i) * (h - tmp);
        mn = min(x, min(y, z));
        mx = max(x, max(y, z));
        ans = min(ans, mx - mn);
    }
    tmp = w / 2;
    for (ll i = 1; i <= h; i++)
    {
        x = i * w;
        y = (h - i) * tmp;
        z = (h - i) * (w - tmp);
        mn = min(x, min(y, z));
        mx = max(x, max(y, z));
        ans = min(ans, mx - mn);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3624
import sys

def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M = map(int, input().split())
    A = [int(input()) for _ in range(M)]
    is_safe = [True] * (N+2)
    for a in A:
        is_safe[a+1] = False

    dp = [0] * (N+2)
    dp[1] = 1
    for i in range(2, N+2):
        if is_safe[i]:
            dp[i] = dp[i-1] + dp[i-2]
            dp[i] %= MOD
        else:
            dp[i] = 0

    return dp[N+1]


if __name__ == '__main__':
    print(main())

Measured memory_bytes: 44892
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int n = sc.nextInt();
        Set<String> sSet = new HashSet<>(4);
        for (int i = 0; i < n; i++) {
            sSet.add(sc.next());
        }
        System.out.println(sSet.size() == 3 ? "Three" : "Four");
    }
}

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

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

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

int main(void) {
	int A, B;
	cin >> A >> B;
	cout << lcm(A, B) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define int long long
const int INF = 1e18, MOD = 998244353;
signed main() {
    int h, w;
    cin>>h>>w;
    if (w == 1 || h == 1) cout<<1<<endl;
    else cout<<(h + 1) / 2 * ((w + 1) / 2) + h / 2 * (w / 2)<<endl;
}

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

#define in cin
#define out cout

#define REP(i,n) for(int i=0; i<n; i++)
#define REP2(i,s,e) for(int i=s; i<e; i++)
#define REPE(i,s,e) for(int i=s; i<=e; i++)
#define REPR(i,s,e) for(int i=s; i>=e; i--)

#define all(v) v.begin(), v.end()
#define pb push_back

#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define rd(n) scanf("%d", &n)

#define x first
#define y second
#define intINF 2147483647
#define llINF 9223372036854775807LL
#define MOD 1000000007

int main()
{
    string s; in >> s; s += 'S';
    int cnt = 0;
    int res = s.size()-1;
    for(int i=0; i<s.size()-1; i++)
    {
        char w = s[i];
        if(w == 'S') cnt++;
        else
        {
            if(cnt > 0)
            {
                res -= 2;
                cnt--;
            }
        }
    }

    out << res << "\n";

    return 0;
}


Measured memory_bytes: 640
#include<algorithm>//sort(all(変数),greater<型名>())　で降順に
#include<bits/stdc++.h>
#include<cmath>//切り上げceil(値)
#include<deque>
#include<iomanip>//setprecision(数字)
#include<iostream>
#include<list>
#include<map>
#include<numeric> //xとyの最大公約数は__gcd(x,y),xとyの最小公倍数は(x*y)/__gcd
#include<queue>//priority_queue<型名> 変数：優先度付きキュー　最大値の探索が早い
#include<set>
#include<stack>
#include<string>
#include<vector>
#define rep0(i,n)  for(ll i=0; i<n; i++)
#define rrep0(i,n) for(ll i=n-1; 0<=i; i--)
#define rep1(i,n)  for(ll i=1; i<=n; i++)
#define rrep1(i,n) for(ll i=n; 1<=i; i--)
#define vll vector<ll>
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e18
using ll = long long;
using namespace std;
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; }

int main(){
  int n;  cin >> n;
  vll a(n);
  rep0(i,n)  cin >> a[i];
  set<ll> st;
  rep0(i,n){
    if(st.count(a[i]) == 0){
      st.insert(a[i]);
    }else{
      st.erase(a[i]);
    }
  }
  cout << st.size();
}


Measured memory_bytes: 5760
function main()
  
  N = split(chomp(readline()),"")
  
  check = true
  
  for i in 1:div(length(N),2)
    
    if N[i] != N[end+1-i]
      check = false
    end
    
  end
  
  if check
    println("Yes")
  else
    println("No")
  end
  
end

main()

Measured memory_bytes: 109788