akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 998244353;
const int N = 1e5 + 5;
int cnt[N], a[N];


ll ksm(ll x, ll n, ll mod)
{
    ll ret = mod != 1;
    for (x %= mod; n; n >>= 1, x = x * x % mod)
        if (n & 1)
            ret = ret * x % mod;
    return ret;
}

int main()
{
    int n;
    cin >> n;
    int maxa = -1;
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
        cnt[a[i]]++;
        maxa = max(maxa, a[i]);
    }
    if (!(cnt[0] == 1 && a[0] == 0))
    {
        cout << 0;
        return 0;
    }
    ll ans = 1ll;
    for (int i = 0; i <= n - 1 - 1; i++)
    {
        if (cnt[i + 1] == 0)
        {
            if (i < maxa)
            {
                cout << 0;
                return 0;
            }
            else
            {
                break;
            }
        }
        ans = ans * ksm(cnt[i], cnt[i + 1], mod) % mod;
    }
    cout << ans % mod;
    // cout<<endl;
    // cout<<ksm(100000, 100000, mod);
}


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

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		 int x = sc.nextInt(); 
		 long num = 0, cnt = 0;
		 while(num < x){
			 cnt++;
			 num += cnt;
		 }	
		out.println(cnt);
		
		out.close();
	}

	static boolean prime(int n) {
		boolean flag = true;
		int max = (int)Math.sqrt(n);
		for (int i = 2; i <= max; i++) {
			if (n % i == 0) {
				flag = false;
				break;
			}
		}
		if (n == 1) flag = false;
		return flag;
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



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

int main() {
  string s;
  cin >> s;
  for(int i=0;i<3;i++){
   if(s.at(i) =='9') s.at(i)='1';
   else s.at(i)='9';
  }
  cout << s.at(0) << s.at(1) << s.at(2) <<endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,a[5000],b[5000],i,j,l,h,w,k,p;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<m;i++){
		scanf("%d",&b[i]);
	}
	w=0;
	for(i=m-1;i>=0;i--){
		h=0;p=n-1;
		for(j=i;j>=0;j--){
			k=0;
			for(l=p;l>=0;l--){
				if(a[l]==b[j]){
//					printf("%d %d %d %d\n",l,a[l],j,b[j]);
					h++;
					p=l-1;
					k=1;
					break;
				}
			}
			if(k==0) break;
		}
		if(w<h) w=h;
	}
	printf("%d\n",w);
	return 0;
}

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

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

    vector<int> data(n);
    for (int i = 0; i < n; i++){
        cin >> data.at(i);
    }

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

    cout << data.at(n / 2) - data.at(n / 2 - 1) << endl;
}


Measured memory_bytes: 768
s=input()
t=input()
S=[]
T=[]
for i in range(len(s)):
	S.append(ord(s[i]))
for i in range(len(t)):
	T.append(ord(t[i]))
if min(S)<max(T):
	print("Yes")
elif min(S)>max(T):
	print("No")
else:
	S.sort()
	T.sort()
	for i in range(1,min(len(s),len(t))):
		if S[i]<T[-i-1]:
			print("Yes")
			exit()
		elif S[i]>T[-i-1]:
			print("No")
			exit()
	if len(s)<len(t):
		print("Yes")
	else:
		print("No")
		


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

ll used[100000];
int main(){
    ll N,K,R,S,P;cin>>N>>K>>R>>S>>P;
    string T;cin>>T;
    ll ans=0;
    rep(i,N){
        if(i+1<=K){
            if(T[i]=='r')ans+=P;
            else if(T[i]=='s')ans+=R;
            else ans+=S;
            used[i]=1;
        }
        else if(T[i]==T[i-K] and used[i-K])continue;
        else{
            if(T[i]=='r')ans+=P;
            else if(T[i]=='s')ans+=R;
            else ans+=S;
            used[i]=1;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1280
"""
combination
右が固定 : 左は大きければ大きいほうが良い
左が固定 : 右は1/2に近ければ近いほうが良い
これを左から順に探していくので良い
"""

N = int(input())
As = list(map(int,input().split()))
As = sorted(As, reverse=True)
l = As[0]
r = As[1]

for a in As[2:]:
    if abs(l/2-a) < abs(l/2-r):
        r = a
print(l,r)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 k;
  cin >> k;
  string s;
  cin >> s;
  int32 n = s.size();
  if(n <= k){
    ANS(s);
  }else{
    REP(i,k){
      cout << s[i];
    }
    cout << "...\n";
  }
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const long long MOD=10000007;
const int INF=1e9+5;
// bool isPowerOfTwo(int n)
// {
// 	return (n && !(n & (n-1)));

// } 



int32_t main() {
	// your code goes here
	long n;cin>>n;
		 //long long k;cin>>k;
		// vector<vector<int > >h(n,vector<int>(3));
		// for(int i=0;i<n;i++)
		//   for(int j=0;j<3;j++)
		//       cin>>h[i][j];
		
		vector<int>dp(3);
		for(int day=0;day<n;day++)
		{ 	vector<int>new_dp(3,0);
		    vector<int>c(3);
			for(int j=0;j<3;j++)
			  	cin>>c[j];
			 for(int i=0;i<3;i++)
			   {
			   	for(int j=0;j<3;j++)
			   	    if(i!=j)
			   	       new_dp[j]=max(new_dp[j],dp[i]+c[i]);
			   }
			  dp=new_dp;
			  
	      }
	      int result=max(dp[0],max(dp[1],dp[2]));
		cout<< result<<endl;
	


		 
	
	return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
constexpr int MOD = 1000000007;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

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

struct rule {
  int l, x;
};

int f(vector<int> &c, int l) {
  if (l > c[1]) return 1;
  if (l > c[0]) return 2;
  return 3;
}

void solve() {
  int N, M;
  cin >> N >> M;
  vector<vector<rule>> R(N + 1);
  for (int i = 0; i < M; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    R[r].push_back({l, x});
  }
  
  const int mod = 1e9 + 7;
  vector<vector<vector<ll>>> dp(N + 1, vector<vector<ll>>(N + 1, vector<ll>(N + 1, 0)));
  dp[0][0][0] = 1;
  for(int i = 0; i <= N; i++) {
    for(int j = 0; j <= N; j++) {
      for(int k = 0; k <= N; k++) {
        int m = max({i, j, k});
        vector<int> c{i, j, k};
        sort(all(c));
        bool flag = true;
        for(int p = 0; p < R[m].size(); p++) {
          int l = R[m][p].l;
          int x = R[m][p].x;
          if (f(c, l) != x) {
            flag = false;
            break;
          }
        }
        if (!flag) {
          dp[i][j][k] = 0;
          continue;
        }

        int m_ = m + 1;
        if (m_ > N) continue;
        dp[m_][j][k] += dp[i][j][k]; dp[m_][j][k] %= mod;
        dp[i][m_][k] += dp[i][j][k]; dp[i][m_][k] %= mod;
        dp[i][j][m_] += dp[i][j][k]; dp[i][j][m_] %= mod;
      }
    }
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      ans += dp[N][i][j]; ans %= mod;
      ans += dp[i][N][j]; ans %= mod;
      ans += dp[i][j][N]; ans %= mod;
    }
  }
  cout << ans << endl;

}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}

Measured memory_bytes: 218880
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N],b[N],x[N],y[N],ans[N],m,k;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
		a[x[i]]=y[i];
	}
	m=n+1;
	for(int i=1;i<=n;i++)
	{
		m=min(m,a[i]);
		if(m==n-i+1)
			b[++k]=i;
	}
	for(int i=1;i<=n;i++)
		for(int j=b[i];j>b[i-1];j--)
			ans[j]=b[i]-b[i-1];
	for(int i=1;i<=n;i++)
		printf("%d\n",ans[x[i]]);
	return 0;
}


Measured memory_bytes: 6916
#include<bits/stdc++.h>
using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int N,M;
  cin >> N >> M;
  int A[M];
  REP(i,M) cin >> A[i];

  int ans = N;
  REP(i,M) ans -= A[i];
  cout << (ans < 0 ? -1 : ans) << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n;
  cin >> n;
  vector<int> v(n), c(n);
  rep(i, n) cin >> v[i];
  rep(i, n) cin >> c[i];

  int ans = 0;
  rep(i, n) {
    if (v[i] - c[i] > 0) {
      ans += v[i]-c[i];
    }
  }
  cout << ans << endl;
}


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

int main(int argc, char const *argv[])
{
	std::vector<int> a;
	std::vector<int> b;
	std::vector<char> op;
	std::vector<int> res;
	int x, y;
	char shisoku = '+';
	while (shisoku != '?')
	{
		std::cin >> x >> shisoku >> y;
		switch (shisoku)
		{
			case '+':
				a.push_back(x);
				b.push_back(y);
				op.push_back(shisoku);
				res.push_back(x+y);
				break;
			case '-':
				a.push_back(x);
				b.push_back(y);
				op.push_back(shisoku);
				res.push_back(x-y);
				break;
			case '*':
				a.push_back(x);
				b.push_back(y);
				op.push_back(shisoku);
				res.push_back(x*y);
				break;
			case '/':
				a.push_back(x);
				b.push_back(y);
				op.push_back(shisoku);
				res.push_back(x/y);
				break;
			case '?':
				a.push_back(x);
				b.push_back(y);
				op.push_back(shisoku);
				break;
		}
	}
	for (int i = 0; i < res.size(); ++i)
	{
		std::cout << res[i] << std::endl;
	}
}


Measured memory_bytes: 3140
n = int(input())
d, x = map(int, input().split())
a = [int(input()) for _ in range(n)]
res = x
for i in range(n):
    count = 0
    for j in range(1, d+1):
        if a[i] * count + 1 == j:
            count += 1
    res += count
print(res)


Measured memory_bytes: 3060
def prod(l):
    r = 1
    mod = 10 ** 9 + 7
    for a in l:
        r = (r * a) % mod
    return r

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    P = [a for a in A if a >=0]
    M = [a for a in A if a < 0]
    PP, MM = len(P), len(M)
    P.sort(reverse=True)
    M.sort()
    k = 0
    p, m = 0, 0
    if PP == 0:
        if K % 2 == 0:
            return prod(M[:K])
        return prod(M[-K:])
    if P[0] == 0 and K % 2 == 1:
        return 0
    if K == N:
        return prod(A)
    while p + m < K:
        if m == MM:
            p += 1
        elif p == PP:
            m += 1
        elif P[p] > -M[m]:
            p += 1
        else:
            m += 1
    if m % 2 != 0:
        if m == MM or p == 0:
            m -= 1
            p += 1
        elif p == PP or m == 0:
            m += 1
            p -= 1
        elif M[m - 1] * M[m] >= P[p - 1] * P[p]:
            m += 1
            p -= 1
        else:
            m -= 1
            p += 1
    if p < 0 or p > PP:
        return prod(M[-K:])
    return prod(P[:p] + M[:m]) 

print(main())


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

#define int long long 

int n;

main(){
	cin>>n;
	int a[222222];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	int ia[222222];
	for(int i=0;i<n;i++){
		ia[i+1]=a[i]+ia[i];
	}
	int x=0,y=2,ans=LLONG_MAX;
	for(int i=2;i<n-1;i++){
		while(ia[x+1]<ia[i]-ia[x+1])x++;
		while(ia[y+1]-ia[i]<ia[n]-ia[y+1])y++;
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				ans=min({ans,abs(max({ia[x+j],ia[i]-ia[x+j],ia[y+k]-ia[i],ia[n]-ia[y+k]})-min({ia[x+j],ia[i]-ia[x+j],ia[y+k]-ia[i],ia[n]-ia[y+k]}))});
			}
		}
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 3584
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <bitset>
#include <queue>
#include <deque>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAXN=256;

char st[100],mas[MAXN][5];
int n,number,nnew[MAXN],flag[MAXN],p[MAXN];
vector<int> e[MAXN],v;

int dfs(int v) {
	if (flag[v]==number) return 0;
	flag[v]=number;
	for (int i=0; i<(int) e[v].size(); i++)
		if (p[e[v][i]]==-1 || dfs(p[e[v][i]])) {
			p[e[v][i]]=v;
			return 1;
		}
	return 0;
}

struct ptt {int x,y;} bl[MAXN],rd[MAXN];

int compat(ptt A, ptt B) {
    return A.x<B.x && A.y < B.y;
}

int main() {
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
    
    int n;
    cin>>n;
    for (int i=0; i<n; i++) cin>>bl[i].x>>bl[i].y;
    for (int i=0; i<n; i++) cin>>rd[i].x>>rd[i].y;

	for (int i=0; i<n; i++) {
		e[i].clear();
		nnew[i]=0;
		flag[i]=0;
		p[i]=-1;
	}
	number=0;
	int ans=0;

	for (int i=0; i<n; i++)
		for (int j=0; j<n; j++)
			if (compat(bl[i],rd[j]))
				e[i].push_back(j);
	for (int i=0; i<n; i++)
		if (!nnew[i])
			for (int j=0; j<(int) e[i].size(); i++)
				if (p[e[i][j]]==-1) {
					p[e[i][j]]=i;
					nnew[i]=1;
					ans++;
					break;
				}
	for (int i=0; i<n; i++)
		if (!nnew[i]) {
			number++;
			ans+=dfs(i);
		}

	cout<<ans;
   	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,K,m[5555],v[2][11111],x=1;
int main(){
    cin>>N>>K;
    v[0][0]=1;
    for(int i=0;i<N;i++)cin>>m[i];
    sort(m,m+N);
    int a=0,b=N,d=N;
    while(a<b){
        int c=(a+b)/2,pass=0;
        if(m[c]>=K){
            pass = 1;
            goto z;
        }
        v[0][0]=x;
        for(int i=0;i<N;i++){
            if(m[i]>=K)break;
            if(i==c)continue;
            for(int j=0;j<K;j++){
                if(v[0][j]==x){
                    v[1][j]=x;
                    v[1][j+m[i]]=x;
                    if(j+m[i]<K&&m[c]+j+m[i]>=K){
                        pass=1;
                        goto z;
                    }
                }
            }
            swap(v[0],v[1]);
        }
        z:
        if(pass){
            b=c;
            d=min(c,d);
        }
        else{
            a=c+1;
        }
        x++;
    }
    cout<<d<<endl;
}


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

int main(){
	int N,sum=0,a=0;
	cin>>N;
	int d[N];
	for(int i=0;i<N;i++){
		cin>>d[i];
	}
	for(int i=0;i<N-1;i++){
		a=0;
		for(int j=i+1;j<N;j++){
			a+=d[j];
		}
		sum+=d[i]*a;
	}
	cout<<sum;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  if (S == "Sunny") {
    cout << "Cloudy" <<endl;
  }
  if (S == "Cloudy") {
    cout << "Rainy" <<endl;
  }
  if (S == "Rainy") {
    cout << "Sunny" <<endl;
  }
}

Measured memory_bytes: 256
def insertion_sort(l, g):
    cnt = 0
    for i in range(g, len(l)):
        tmp = l[i]
        j = i - g
        while j >= 0 and l[j] > tmp:
            l[j+g] = l[j]
            cnt += 1
            j -= g
        l[j+g] = tmp

    return l, cnt


def shell_sort(l, lg):
    tot = 0
    for g in lg:
        sl, cnt = insertion_sort(l, g)
        tot += cnt
    return sl, tot


if __name__ == '__main__':
    N = int(input())
    l = []
    for _ in range(N):
        l.append(int(input()))

    lg = [1]
    while True:
        gc = 3 * lg[-1] + 1
        if gc > N:
            break
        lg.append(gc)

    lg = lg[::-1]

    print(len(lg))
    print(' '.join(map(str, lg)))
    sl, tot = shell_sort(l, lg)
    print(tot)
    for e in sl:
        print(e)



Measured memory_bytes: 45516
#include <stdio.h>

int main () {

    int i, j, a, b, x;
    char op;

    for (; ; ) {
        scanf("%d %c %d", &a, &op, &b);

        if (op == '+') {
            x = a + b;
        } else if (op == '-') {
            x = a - b;
        } else if (op == '*') {
            x = a * b;
        } else if (op == '/') {
            x = a / b;
        } else if (op == '?') {
            break;
        }

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

    }

    return 0;

}


Measured memory_bytes: 2140
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int n,ans,a[N],b[N];
int calc(int v)
{
	int res=0;
	for(int l=1,r=n;l<=n;l++)
	{
		while(r&&a[l]+b[r]>=v)r--;
		res^=(n-r)&1;
	}
	return res;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)scanf("%d",&b[i]);
	for(int i=28;i>=0;i--)
	{
		for(int j=1;j<=n;j++)a[j]&=((1<<i+1)-1),b[j]&=((1<<i+1)-1);
		sort(a+1,a+n+1);sort(b+1,b+n+1);
		int x=calc(1<<i)^calc(2<<i)^calc(3<<i);
		ans|=x*(1<<i);
	}
	printf("%d\n",ans);
	return 0;
} 

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <numeric>

using namespace std;


void weather_predicition()
{
  string s;
  cin >> s;

  if (s == "Sunny") cout << "Cloudy\n";
  else if (s == "Cloudy") cout << "Rainy\n";
  else if (s == "Rainy") cout << "Sunny\n";
}


void odds_of_oddness()
{
  int n;
  cin >> n;

  int cnt = 0;
  for (int i = 1; i <= n; ++i)
  {
    if (i % 2 != 0) ++cnt;
  }

  cout << (float)cnt / (float)n << "\n";
}


void curtain()
{
  int a, b;
  cin >> a >> b;

  if (a - 2 * b > 0) cout << a - 2 * b << "\n";
  else cout << 0 << "\n";
}


void cant_wait_for_holiday()
{
  string s;
  cin >> s;

  vector<string> S{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};

  int cnt = 7;
  for (int i = 0; i < 7; ++i)
  {
    if (s == S[i]) cout << cnt << "\n"; 
    --cnt;
  }

}


void blackjack()
{
  vector<int> a(3);
  for (int i = 0; i < 3; ++i) cin >> a[i];

  if (accumulate(a.begin(), a.end(), 0) >= 22) cout << "bust\n";
  else cout << "win\n";
}


void round_one()
{
  int a, b;
  cin >> a >> b;

  cout << 6 - a - b;
}


void strings()
{
  string s, t;
  cin >> s >> t;

  cout << t + s << "\n";
}


void yen_conins()
{
  int k, x;
  cin >> k >> x;

  if (k * 500 - x >= 0) cout << "Yes\n";
  else cout << "No\n";
}


void tap_dance() 
{
  string s;
  cin >> s;

  int flag = 1;
  for (int i = 1; i <= s.size(); ++i)
  {
    if (i % 2 == 0)
    {
      if (s[i] == 'L') flag = 0;
    }
    else
    {
      if (s[i] == 'R' ) flag = 0;
    }
  }
  if (flag) cout << "Yes\n";
  else cout << "No\n";
}


void roller_coaster()
{
  int n, k;
  cin >> n >> k;

  int cnt = 0;
  for (int i = 0; i < n; ++i)
  {
    int h;
    cin >> h;
    if (h >= k) ++cnt;
  }
  cout << cnt << "\n";
}


void takoyaki_festival2019()
{
  int n;
  cin >> n;
  vector<int> d(n);
  for (int i = 0; i < n; ++i) cin >> d[i];

  int v_sum = 0;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      v_sum += d[i] * d[j];
    }
  }
  cout << v_sum << "\n";
}


void echo()
{
  int n;
  string s;
  cin >> n >> s;

  if (n % 2 != 0)
  {
    cout << "No\n";
    return;
  }

  for (int i = 0; i < n / 2; ++i)
  {
    if (s[i] != s[i + n / 2])
    {
      cout << "No\n";
      return;
    }
  }
  cout << "Yes\n";
}



int main()
{
  //weather_predicition();
  //odds_of_oddness();
  //curtain();
  //cant_wait_for_holiday();
  //blackjack();
  //round_one();
  //strings();
  //yen_conins();

  //tap_dance();
  //roller_coaster();
  //takoyaki_festival2019();
  echo();
}

Measured memory_bytes: 256
import math
def good_distance(n, d, xli):

    ans = 0

    for i in range(n):
        for q in range(i+1, n):
            count = 0
            for w in range(d):
                count += (xli[i][w]-xli[q][w])**2

            if math.sqrt(count).is_integer():
                ans += 1

    return ans

def main():
    n, d = map(int, input().split())
    xli = [list(map(int, input().split()))for i in range(n)]
    print(good_distance(n, d, xli))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

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



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

int main(){
    ll A, B, M; std::cin >> A >> B >> M;
    std::vector<ll> a, b;
    ll min_a=1145141919, min_b=1145141919;
    for(int i=0; i<A; i++){
        ll buf; std::cin >> buf;
        a.push_back(buf); min_a=std::min(min_a, buf);
    }
    for(int i=0; i<B; i++){
        ll buf; std::cin >> buf;
        b.push_back(buf); min_b=std::min(min_b, buf);
    }

    ll ans = min_a + min_b;

    for(int i=0; i<M; i++){
        ll x, y, c; std::cin >> x >> y >> c;
        ans = std::min(ans, a[x-1] + b[y-1] - c);
    }

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


Measured memory_bytes: 2548
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> A(N),B(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        B[A[i]-1] = i + 1;
    }
    for(int i = 0; i < N; i++){
         cout << B[i] << " ";
    }
    cout << endl;
}


Measured memory_bytes: 1664
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

X, Y, Z = map(int,input().split())

print(Z, X, Y)

Measured memory_bytes: 8220
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const int N=1<<17;
const ll mod=1e9+7;
ll n,x,y,z,dp[45][N];
int read(){
    int ans=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
    while (ch>='0'&&ch<='9'){ans=ans*10+ch-'0';ch=getchar();}
    return ans*f;
}
int main(){
	n=read();x=read();y=read();z=read();
	ll res=1;
	for (int i=1;i<=n;i++)	res=(res*10ll)%mod;
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	int forbid=(1<<z-1)|(1<<y+z-1)|(1<<x+y+z-1);
	int state=(1<<x+y+z)-1;
	for (int i=1;i<=n;i++){
		for (int s=0;s<=state;s++){
				if (dp[i-1][s]==0)	continue;
				for (int k=1;k<=10;k++){
					int now=(s<<k)|(1<<k-1);
					now&=state;
					if ((now&forbid)!=forbid)
						dp[i][now]=(dp[i][now]+dp[i-1][s])%mod;
				}
		}
	}
	for (int i=0;i<=state;i++)	res=(res-dp[n][i]+mod)%mod;
	cout<<res;
	return 0;
}

Measured memory_bytes: 46464
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;

    if(A < C && C < B){
        cout << "Yes" << endl;
    }else if(B < C && C < A){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n, m = LI()
    span = [None for _ in range(m)]
    for i in range(m):
        a, b = LI()
        span[i] = [a,b]
    span.sort(key=lambda x: x[1])
    choice = [0, 0]
    ans = 0
    for each_span in span:
        if choice[1]<=each_span[0]:
            choice = each_span
            ans += 1
    print(ans)
main()


Measured memory_bytes: 88496
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using T = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll T1;
    cin >> T1;
    ll T2;
    cin >> T2;
    ll A1;
    cin >> A1;
    ll A2;
    cin >> A2;
    ll B1;
    cin >> B1;
    ll B2;
    cin >> B2;
    ll S=T1*(A1-B1);
    ll T=T2*(A2-B2);
    if(S+T==0){
        prt("infinity")return 0;
    }
    if(S<0){
        S*=-1;T*=-1;
    }
    if(S+T>0){
        prt(0)return 0;
    }
    ll k=-T-S;
    if(S%k!=0){
        prt(2*(S/k)+1)return 0;
    }
    else prt(2*(S/k))

    return 0;
}


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


using namespace std;


#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()


ll sum(int n);

void go(){
	int n;cin>>n;
	string s;cin>>s;
	int mid = n/2;
	string f1=s.substr(0,mid);
	string f2=s.substr(mid, n);
	string ans=f1==f2?"Yes":"No";
	cout << ans;
}
int main(){
   
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cout.tie(0);

   go();

   return 0;
}

ll sum(int n){                
   if(n == 0){
      return n;
   }else{
      return sum(n/10) + n%10;
   }
}


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

using namespace std;

namespace mylib {
template<int mod>
struct ModInt {
	using ll = long long;
	int x;
	const static int M = mod;
	ModInt(ll x_) {
		x = x_ % mod;
		if (x < 0) x += mod;
	}
	ModInt() : ModInt(0) {}
	inline ModInt& operator+=(const ModInt rhs) {
		x += rhs.x;
		x %= mod;
		return (*this);
	}
	inline ModInt& operator-=(const ModInt rhs) {
		x += -rhs;
		return *this;
	}
	inline ModInt& operator*=(const ModInt rhs) {
		x = ((ll) x * rhs.x) % mod;
		return *this;
	}
	inline ModInt& operator/=(ModInt rhs) {
		return *this *= rhs.power(mod - 2);
	}
	inline ModInt power(ll p) {
		ModInt res = 1;
		ModInt a = x;
		for (; p; res = p & 1 ? res * a : res, a *= a, p >>= 1);
		return res;
	}
	inline ModInt& operator=(const ModInt& rhs) {
		this->x = rhs.x;
		return *this;
	}
	inline int operator==(const ModInt& rhs) const {
		return this->x == rhs.x;
	}
	inline int operator!=(const ModInt& rhs) const {
		return !(*this != rhs);
	}
	inline ModInt operator++(signed unused) {
		ModInt res(*this);
		++(*this);
		return res;
	}
	inline ModInt& operator++() {
		(*this) += 1;
		return (*this);
	}
	inline ModInt operator--(signed unused) {
		ModInt res(*this);
		--(*this);
		return res;
	}
	inline ModInt& operator--() {
		(*this) -= 1;
		return (*this);
	}
	inline ModInt operator+() const {
		return (*this);
	}
	inline ModInt operator-() const {
		return (*this).x ? ModInt(mod - (*this).x) : ModInt(0);
	}
	friend const ModInt operator+(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) += rhs;}
	friend const ModInt operator-(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) -= rhs;}
	friend const ModInt operator*(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) *= rhs;}
	friend const ModInt operator/(const ModInt& lhs, const ModInt& rhs) {return ModInt(lhs) /= rhs;}
	explicit operator int() const {return x;}
	friend ostream& operator<<(ostream& lhs, const ModInt& rhs) {
		lhs << rhs.x;
		return lhs;
	}
	friend istream& operator>>(istream& lhs, ModInt& rhs) {
		long long t;
		lhs >> t;
		rhs = ModInt(t);
		return lhs;
	}
};
using modint = ModInt<1000000007>;
//using modint = ModInt<998244353>;
modint operator"" _mi(unsigned long long lit) {
	return modint(lit % modint::M);
}
}; // mylib
using namespace mylib;

modint solve() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	sort(A.begin(), A.end());
	if (N % 2) {
		for (int i = 0; i < N; i++) {
			if (A[i] != (i + 1) / 2 * 2) return 0;
		}
	} else {
		for (int i = 0; i < N; i++) {
			if (A[i] != i / 2 * 2 + 1) return 0;
		}
	}
	modint res = 1;
	for (int i = 0; i < N / 2; i++) {
		res *= 2;
	}
	return res;
}

int main() {
	cout << solve() << endl;
}



Measured memory_bytes: 640
/*
author: shah_entrance
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,i,j,x,k,res;
    cin>>n>>x;
    k=min(n,x);
    ll arr[n],dp[n+5][k+1]={},a[k]={};
    for(i=0;i<n;i++)
        cin>>arr[i];
    for(i=0;i<k;i++)
        dp[1][i]=abs(arr[1]-arr[0]);
    for(i=2;i<n;i++)
    {
        for(j=0;j<k;j++)
            dp[i][j]=INT_MAX;
    }
    a[1]=dp[1][0];
    for(i=2;i<n;i++)
    {
        ll low=INT_MAX;
        for(j=0;j<min(i,k);j++)
        {
            dp[i][j]=a[i-j-1]+abs(arr[i]-arr[i-j-1]);
            if(dp[i][j]<low)
                low=dp[i][j];
        }
        a[i]=low;
    }
    cout<<a[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 80000
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n) for(i = 0; i < (n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;
typedef pair<int, int> pp;

ll Pow(ll n, ll k) {
	ll ans = 1, a = n % MOD;
	while (k > 0) {
		if (k & 1) {
			ans *= a;
			ans %= MOD;
		}
		a *= a;
		a %= MOD;
		k >>= 1;
	}
	return ans;
}

ll Inverse(ll a) {
	return Pow(a, MOD - 2);
}

ll Combi(ll n, ll a) {
	chmin(a, n - a);
	ll i, ans = 1;
	for (i = 1; i <= a; i++) {
		ans *= n--;
		ans %= MOD;
		ans *= Inverse(i);
		ans %= MOD;
	}
	return ans;
}

int main(void) {
	ll num, i, all, a, b, ans;
	cin >> num >> a >> b;
	all = (Pow(2, num) - 1) % MOD;
	if (all < 0)
		all += MOD;
	a = Combi(num, a);
	b = Combi(num, b);
	all -= a;
	all %= MOD;
	if (all < 0)
		all += MOD;
	all -= b;
	ans = all % MOD;
	if (ans < 0)
		ans += MOD;
	cout << ans << "\n";
	return 0;
}

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

typedef long long LL;
typedef pair <int,int> pii;

#define pb push_back
#define fi first
#define sc second
#define mp make_pair

int main()
{
	#ifdef local
		freopen("read.txt","r",stdin);
	#endif
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if (a==b&&b==c)
		printf("Yes");
	else
		printf("No");
	return 0;
}

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

using namespace std;

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  int n_a = 0;
  int n_b = 0;
  int n_c = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (s[i] == 'a')
      ++n_a;
    else if (s[i] == 'b')
      ++n_b;
    else if (s[i] == 'c')
      ++n_c;
  }

  int diff = abs(n_a - n_b);
  diff = max(diff, abs(n_b - n_c));
  diff = max(diff, abs(n_c - n_a));

  if (diff >= 2)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;

  return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
char a1,b1,c1,d1;
int a,b,c,d;
int main()
{
	ios::sync_with_stdio(false);
	cin>>a1>>b1>>c1>>d1;
	a=a1-'0';
	b=b1-'0';
	c=c1-'0';
	d=d1-'0';
	if (a+b+c+d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a+b+c-d==7)
	{
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a+b-c+d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a-b+c+d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a+b-c-d==7)
	{
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a-b-c+d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a-b+c-d==7)
	{
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
		return 0; 
	}
	if (a-b-c-d==7)
	{
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
		return 0; 
	}
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ull B = 100000007;
int mod = 1000000007;

class Solution {
public:
    int b(string a, string b) {
       int n = a.length();
       int res = 0;
       for(int i = 0; i < n; ++i) {
           if(a[i] != b[i]) {
               res++;
           }
       }
       return res;
    }
};

int main() {
    string a, b;
    cin >> a >> b;
    Solution zhy;
    cout << zhy.b(a, b) << endl;
    return 0;
}

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

int main()
{
	int d;

	while(std::cin >> d)
	{
		int vol=0;

		for(int i=1; i*d<600; ++i)
		{
			vol += d*(d*i)*(d*i);
		}

		std::cout << vol << '\n';
	}

}

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

int main( )
{
    int n, i, j, k = 1;
    cin >> n;
    for (i = 1; i <= n; i++) {
        cin >> j;
        if (j == k) {
            k++;
        }
    }
    k--;
    if (k == 0) {
        cout << "-1\n";
    }
    else {
        cout << (n - k) << '\n';
    }
    return 0;
}

Measured memory_bytes: 256
S=input()

n1=0
istr=1
for i,s in enumerate(S):
    if i%2==0:
        if int(s)!= istr:
            n1+=1
    else:
        if int(s) == istr:
            n1+=1


n2=0
istr=0
for i,s in enumerate(S):
    if i%2==0:
        if int(s)!= istr:
            n2+=1
    else:
        if int(s) == istr:
            n2+=1

print(min(n1,n2))


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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N;
double xs, ys, xt, yt;
vector<vector<double>> d;
vector<double> Xs, Ys, Rs;


void warshall_floyd() { // nは頂点数
  for (int i = 0; i < N; i++)      // 経由する頂点
    for (int j = 0; j < N; j++)    // 開始頂点
      for (int k = 0; k < N; k++)  // 終端
        d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
}

signed main(){
    cin >> xs >> ys >> xt >> yt >> N;
    d.resize(N);
    for(int i=0;i<N;i++) {
        d[i].resize(N, INF);
        double x, y, r;
        cin >> x >> y >> r;
        Xs.push_back(x);
        Ys.push_back(y);
        Rs.push_back(r);
    }
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            d[i][j] = max(0.0, sqrt(pow(Xs[i]-Xs[j], 2.0)+pow(Ys[i]-Ys[j], 2.0))-Rs[i]-Rs[j]);
        }
    }
    warshall_floyd();
    double ans = sqrt(pow(xs-xt, 2.0)+pow(ys-yt, 2.0));
    for(int i=0;i<N;i++) {
        for(int j=0;j<N;j++) {
            ans = min(ans, max(0.0, max(0.0, sqrt(pow(xs-Xs[i], 2.0)+pow(ys-Ys[i], 2.0))-Rs[i])+max(0.0, sqrt(pow(xt-Xs[j], 2.0)+pow(yt-Ys[j], 2.0))-Rs[j])+d[i][j]));
        }
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> a(26,INF);

    REP(i,N){
        string s; cin >> s;
        vector<int> b(26,0);
        
        REP(j,s.size()){
            b[s[j]-'a'] ++;
        }
        REP(j,26){
            a[j] = min(a[j], b[j]); 
        }
    }
    for(char c = 'a'; c<='z'; c++){
        REP(i,a[c-'a']) cout << c;
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
using namespace std;
int mp[505][505];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	char s[505];
	for (int i=1;i<=n;++i)
	{
		scanf("%s",s+1);
		for (int j=1;j<=m;++j)
			if (s[j]=='#')
			mp[i][j]=1;	
	}
	for (int i=1;i<=m;++i)
		printf("#");
	printf("\n");
	for (int i=2;i<=n;++i)
	{
		for (int j=1;j<=m;++j)
		{
			if ((j%2==0 || mp[i][j]==1) && i!=n)
				printf("#");
			else printf(".");
		}
		printf("\n");
	}
	printf("\n");	
	for (int i=1;i<n;++i)
	{
		for (int j=1;j<=m;++j)
		{
			if ((j%2==1 || mp[i][j]==1) && i!=1)
				printf("#");
			else printf(".");
		}
		printf("\n");
	}
	for (int i=1;i<=m;++i)
		printf("#");
	printf("\n");
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	string S;
	cin >> S;

	int gu = 0;
	rep(i, S.size()) {
		if (S[i] == 'g') gu++;
	}

	int gumin = (S.size() + 1) / 2;

	co(gu - gumin);

	Would you please return 0;
}

Measured memory_bytes: 512
import math
from functools import reduce
import itertools
#入力:N(int:整数)
def input1():
	return int(input())

#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))





N=input1()
S=[]
for _ in range(N):
	S.append(str(input()))

dic={}
results=[]
for s in S:
	if s not in dic:
		dic[s]=1
	else:
		dic[s]+=1
ans=10000010010


score_sorted = sorted(dic.items(), key=lambda x:x[1])

max_count=max(dic.values())
for x in score_sorted:
	if x[1]==max_count:
		results.append(x[0])
results.sort()
for i in results:
	print(i)








Measured memory_bytes: 47904
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N;
	cin >> N;
	vector<int>A(N);
	for (long long i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	int M;
	cin >> M;
	vector<int>T(M);
	long long C = 0;
	for (long long i = 0; i < M; i++) {
		cin >> T.at(i);
		bool check = binary_search(A.begin(), A.end(), T.at(i));
		if (check) C++;
	}
	cout << C << endl;
}



Measured memory_bytes: 3276
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    int l, n;
    cin >> l >> n;
    vector<int> x(n);
    rep(i, n) cin >> x[i];

    vector<int> left(n + 1), right(n + 1);
    rep(i, n){
        right[i+1] = right[i] + x[i] * 2;
    }
    for(int i = n; i > 0; i--){
        left[i-1] = left[i] + (l - x[i-1]) * 2;
    }

    int ans = 0;
    //right
    rep(i, n){
        int tmp = 0;
        if((n - i) % 2 == 0){
            int cnt = (n - i) / 2;
            tmp += right[i+cnt] - right[i];
            tmp += left[n-cnt+1];
            tmp += l - x[n-cnt];
        }else{
            int cnt = (n - i) / 2;
            tmp += right[i+cnt] - right[i];
            tmp += left[n-cnt];
            tmp += x[i+cnt];
        }
        ans = max(ans, tmp);
    }

    //left
    rep(i, n){
        int tmp = 0;
        if((n - i) % 2 == 0){
            int cnt = (n - i) / 2;
            tmp += left[n-i-cnt] - left[n-i];
            tmp += right[cnt-1];
            tmp += x[cnt-1];
        }else{
            int cnt = (n - i) / 2;
            tmp += left[n-i-cnt] - left[n-i];
            tmp += right[cnt];
            tmp += l - x[n-i-cnt-1];
        }
        ans = max(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

enum class status {
  head,
  middle,
  tail
};

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

  std::string reference = "keyence";

  i64 head_match = 0;
  for (auto it = S.begin(), ref_it = reference.begin(); it != S.end() && ref_it != reference.end() && *it == *ref_it; ++it, ++ref_it) {
    ++head_match;
  }

  i64 tail_match = 0;
  for (auto it = S.rbegin(), ref_it = reference.rbegin(); it != S.rend() && ref_it != reference.rend() && *it == *ref_it; ++it, ++ref_it) {
    ++tail_match;
  }

  std::cout << (head_match + tail_match >= static_cast<i64>(reference.size()) ? "YES" : "NO") << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>

using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>v;
	for (int i = 0; i < m; i++) {
		int l, r;
		cin >> l >> r;
		v.emplace_back(l, r);
	}
	int mn = v[0].first;
	int mx = v[0].second;
	for (int i = 0; i < m; i++) {
		if (v[i].first > mn) {
			mn = v[i].first;
		}
		if (v[i].second < mx) {
			mx = v[i].second;
		}
	}
	int ans = mx - mn + 1;
	if (ans > 0) {
		cout << ans << endl;
	}
	else {
		cout << 0 << endl;
	}
}

Measured memory_bytes: 1400
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  1000000007
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int bigmod(int a,int p,int m){
    if (p==0) return 1;
    if (p&1){
        int p1=a%mod;
        int p2 = bigmod(a,p-1,m);
        return (p1*p2)%mod;
    }
    int p1=bigmod(a,p/2,m);
    return (p1*p1)%m;
}

int ncr(int n,int r){
    int a=1,b=1;
    for (int i=1;i<=r;i++){
        a = (a*(n-i+1))%mod;
        b = (b*i)%mod;
    }
    return (a*bigmod(b,mod-2,mod))%mod;
}

inline void solve(){
    int  n, k; cin >> n >> k ; 
    int spot = n-k+1 ; 
    int  ans = 0 ; 
    for (int i=1;i<=k;i++){
        cout << ((ncr(spot,i)*ncr(k-1,i-1))%mod) << endl;
    }
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>

using namespace std;

const int N = 100000;

int main() {
    int n, q, t;
    bool a[N];
    for (int i = 0; i < N; ++i) a[i] = false;
    a[0] = true;
    cin >> n;
    // for (int i = 0; i < 10; ++i) {
    //     cout << i << ": " << a[i] << endl;
    // }
    for (int i = 0; i < n; ++i) {
        cin >> t;
        for (int j = N - 1; j >= 0; --j) {
            if (j - t >= 0 && a[j - t]) a[j] = true;
        }
    }
    // for (int i = 0; i < 10; ++i) {
    //     cout << i << ": " << a[i] << endl;
    // }
    cin >> q;
    for (int i = 0; i < q; ++i) {
        cin >> t;
        cout << (a[t] ? "yes" : "no") << endl;
    }

    return 0;
}



Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 502;
int n,C,D[N][N],c[N][N],f[3][32];

int main(){
    read2i(n,C);
    lp(i,1,C) lp(j,1,C) readi(D[i][j]);
    lp(i,1,n) lp(j,1,n) readi(c[i][j]), ++f[(i+j)%3][c[i][j]];

    ll ans = infll;
    lp(i,1,C) lp(j,1,C) if(i != j) lp(k,1,C) if(i != k and j != k){
        ll cur = 0;
        lp(x,1,C){
            cur += 1ll * D[x][i] * f[0][x];
            cur += 1ll * D[x][j] * f[1][x];
            cur += 1ll * D[x][k] * f[2][x];
        }
        ans = min(ans, cur);
    }
    cout <<ans;
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 1280