akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "math.h"
#include "utility"
#include "string"
#include "map"
#include "unordered_map"
#include "iomanip"
#include "random"

using namespace std;
const long long int MOD = 1000000007;

int H, W;
int fst;
int add;
bool exist[1002][1002];
char mod[3] = { 'J','O','I' };
int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> H >> W;
	vector<string>field(H + 2);
	vector<string>joi(2);
	for (int i = 1; i <= H; i++) {
		cin >> field[i];
		field[i] = '0' + field[i] + '0';
	}
	for (int i = 0; i < W + 2;i++) {
		field[0] += '0';
		field[H + 1] += '0';
	}
	for (int i = 0; i <= 1; i++)cin >> joi[i];
	for (int i = 1; i < H; i++) 
		for (int j = 1; j < W; j++) {
			bool flag = true;
			for (int k = 0; k < 2; k++)
				for (int l = 0; l < 2; l++)
					if (field[i + k][j + l] != joi[k][l])flag = false;
			if (flag) {
				fst++;
				exist[i][j] = true;
			}
		}

	for (int i = 1; i <= H; i++)
		for (int j = 1; j <= W; j++) {
			int box = 0;
			for (int k = -1; k <= 0; k++)
				for (int l = -1; l <= 0; l++)if (exist[i + k][j + l])box--;
			for (int k = 0; k < 3; k++) {
				int bag=0;
				for(int l=-1;l<=0;l++)
					for (int m = -1; m <= 0; m++) {
						bool flag = true;
						for (int n = 0; n <= 1; n++)
							for (int o = 0; o <= 1; o++) {
								if (!(l+n) && !(m+o)) {
									if (mod[k] != joi[n][o])flag = false;
								}
								else if (field[i + l + n][j + m + o] != joi[n][o])flag = false;
							}
						if (flag)bag++;
					}
				//cout << mod[k] << " " << box << " " << bag << endl;
				ans = max(ans, fst + box + bag);
			}
		}
//	cout << fst << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5832
#include <stdio.h>

int main(void){
 char num[1010];
 int a;
 while(1){
     scanf("%s", &num);
     if(num[0]=='0')
     break;
     else{
     int sum = 0;
     for(int i=0; i<strlen(num); i++){
         sum+=num[i]-'0';    
         }
     printf("%d\n", sum);
     }
 }
 return 0;

}


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

int main() {
    long long k,n,mi;
    cin >> k >> n;
    long long a[n],tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    tmp = k + a[0] - a[n-1];
    for (int i = 0; i < n-1; i++)
    {
        mi = a[1 + i] - a[i];
        if(mi > tmp){
            tmp = mi;
        }
    }
    cout << k-tmp << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
const int maxn=2e5+10;
const int maxt=(1<<20)+10;
ll posdat[maxt],negdat[maxt],minedge[maxt],addpos[maxt],addneg[maxt];
int pospos[maxt],negpos[maxt],mnpos[maxt];
ll D,A[maxn];
int n;
void update(int x)
{
	posdat[x]=min(posdat[x*2],posdat[x*2+1]);
	pospos[x]=(posdat[x*2]==posdat[x]?pospos[x*2]:pospos[x*2+1]);
	
	negdat[x]=min(negdat[x*2],negdat[x*2+1]);
	negpos[x]=(negdat[x*2]==negdat[x]?negpos[x*2]:negpos[x*2+1]);
	
	minedge[x]=min(minedge[x*2],minedge[x*2+1]);
	mnpos[x]=(minedge[x*2]==minedge[x]?mnpos[x*2]:mnpos[x*2+1]);
	
	if(addpos[x]+posdat[x]<minedge[x])
	{
		minedge[x]=addpos[x]+posdat[x];
		mnpos[x]=pospos[x];
	}
	if(addneg[x]+negdat[x]<minedge[x])
	{
		minedge[x]=addneg[x]+negdat[x];
		mnpos[x]=negpos[x];
	}
}
void build(int x,int l,int r)
{
	addpos[x]=addneg[x]=linf;
	if(l==r)
	{
		posdat[x]=A[l]+D*(l+1);
		pospos[x]=l;
		negdat[x]=A[l]-D*(l+1);
		negpos[x]=l;
		minedge[x]=linf;
		mnpos[x]=l;
		return;
	}
	int mid=(l+r)>>1;
	build(x*2,l,mid);
	build(x*2+1,mid+1,r);
	update(x);
}
void del(int x,int l,int r,int p)
{
	if(l==r)
	{
		posdat[x]=negdat[x]=linf;
		minedge[x]=linf;
		addpos[x]=addneg[x]=linf;
		return;
	}
	int mid=(l+r)>>1;
	if(p<=mid)del(x*2,l,mid,p);
	else del(x*2+1,mid+1,r,p);
	update(x);
}
void modify_pos(int x,int l,int r,int tl,int tr,ll v)
{
	if(l>tr||r<tl)return;
	if(tl<=l&&r<=tr)
	{
		addpos[x]=min(addpos[x],v);
		if(posdat[x]+addpos[x]<minedge[x])
		{
			minedge[x]=posdat[x]+addpos[x];
			mnpos[x]=pospos[x];
		}
		return;
	}
	int mid=(l+r)>>1;
	modify_pos(x*2,l,mid,tl,tr,v);
	modify_pos(x*2+1,mid+1,r,tl,tr,v);
	update(x);
}
void modify_neg(int x,int l,int r,int tl,int tr,ll v)
{
	if(l>tr||r<tl)return;
	if(tl<=l&&r<=tr)
	{
		addneg[x]=min(addneg[x],v);
		if(negdat[x]+addneg[x]<minedge[x])
		{
			minedge[x]=negdat[x]+addneg[x];
			mnpos[x]=negpos[x];
		}
		return;
	}
	int mid=(l+r)>>1;
	modify_neg(x*2,l,mid,tl,tr,v);
	modify_neg(x*2+1,mid+1,r,tl,tr,v);
	update(x);
}
int main()
{
	scanf("%d%lld",&n,&D);
	for(int i=0;i<n;i++)scanf("%lld",&A[i]);
	build(1,0,n-1);
	ll ret=0;
	del(1,0,n-1,0);
	modify_pos(1,0,n-1,1,n-1,-D+A[0]);
	for(int i=1;i<n;i++)
	{
		ret+=minedge[1];
		int cur=mnpos[1];
	//	cout<<cur<<" "<<minedge[1]<<endl;
		del(1,0,n-1,cur);
		modify_pos(1,0,n-1,cur+1,n-1,-(cur+1)*D+A[cur]);
		modify_neg(1,0,n-1,0,cur-1,(cur+1)*D+A[cur]);
	}
	printf("%lld\n",ret);
	return 0;
}

Measured memory_bytes: 43264
#include<iostream>
#include<sstream>
#include<iomanip>
#include<bitset>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<limits.h>
using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e3+10;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a,b;
    cin>>a>>b;
    if(a==b)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cmath>
 
using namespace std;
 
const int MAX = 200;
const int BASE = 70;
int map[MAX][MAX];
bool wall[MAX][MAX];
int dx[] = {0,0,1,-1,1,-1};
int dy[] = {1,-1,0,0,1,-1};
int T,n,ans;
 
void init(){
  memset(map,-1,sizeof(map));
  memset(wall,false,sizeof(wall));
  ans = 0;
}
 
void dfs(int x, int y, int t){
 
  // cout << x << " "  << y << endl;
  if(map[x][y] >= t) return;
  map[x][y] = t;
  if(t <= 0) return;
 
  for(int i = 0; i < 6; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    if(!wall[nx][ny]) dfs(nx,ny,t-1);
  }
}
 
void solve(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      if(map[i][j] >= 0) ans++;
  cout << ans << endl;
}
 
int main(){
 
  while(cin >> T >> n && T+n){
    init();
    while(n--){
      int x,y;
      cin >> x >> y;
      wall[x+BASE][y+BASE] = true;
    }
    int sx,sy;
    cin >> sx >> sy;
    dfs(BASE+sx,BASE+sy,T);
    solve();
  }
  return 0;
}

Measured memory_bytes: 1364
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

struct edge{
  int to, rev;
  int64_t cap;
  edge(int t=0, int64_t c=0, int r=0):to(t), cap(c), rev(r) {}
};

struct max_flow {
  vector<vector<edge> > G;
  vector<int> level, iter;
  int n;
  max_flow(int n=0):n(n), G(n), level(n), iter(n) {}
  inline void add(int from, int to, int64_t cap) {
    G[from].emplace_back(to, cap, G[to].size());
    G[to].emplace_back(from, 0, G[from].size()-1);
  }
  void bfs(int s) {
    for(int i = 0; i < n; i++) level[i] = -1;
    queue<int> que;
    level[s] = 0;
    que.emplace(s);
    while(!que.empty()) {
      int now = que.front();
      que.pop();
      for(edge &e:G[now]) {
        if(e.cap > 0 and level[e.to] < 0) {
          level[e.to] = level[now] + 1;
          que.emplace(e.to);
        }
      }
    }
  }
  int64_t dfs(int v, int t, int64_t f) {
    if(v == t) return f;
    for(int &i = iter[v]; i < G[v].size(); i++) {
      edge &e = G[v][i];
      if(e.cap > 0 and level[v] < level[e.to]) {
        int64_t d = dfs(e.to, t, min(f, e.cap));
        if(d > 0) {
          e.cap -= d;
          G[e.to][e.rev].cap += d;
          return d;
        }
      }
    }
    return 0;
  }
  int64_t Dinic(int s, int t) {
    int64_t flow = 0;
    while(true) {
      bfs(s);
      if(level[t] < 0) return flow;
      for(int i = 0; i < n; i++) iter[i] = 0;
      int64_t f;
      while((f = dfs(s, t, INT64_MAX)) > 0) flow += f;
    }
  }
};

//head

int v, e;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> v >> e;
  max_flow M(v);
  rep(i, e) {
    int a, b, c;
    cin >> a >> b >> c;
    M.add(a, b, c);
  }
  cout << M.Dinic(0, v-1) << endl;
}


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

const unsigned long long int maxv = pow(10,9) + 7;
int main(void){
  
    int N;
    cin >> N;
    unsigned long long int ans = 1;
    
    for(int i=1;i<=N;i++){
        ans *= i;
        if(ans > maxv) ans%= maxv;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 3620
N = int(input())
A = list(map(int,input().split()))
B1, B2 = [], []

if N % 2 == 1:
  for idx in range(0,N,2):
    B1.append(A[N-idx-1])
  for idx in range(1,N,2):
    B2.append(A[idx])
else:
  for idx in range(0,N,2):
    B2.append(A[idx])
  for idx in range(1,N,2):
    B1.append(A[N-idx])
print(' '.join(map(str,B1+B2)))

Measured memory_bytes: 118740
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        self.rank = [0]*n
        self.size = [1]*n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.size[y] += self.size[x]
            self.parents[x] = y
        else:
            self.size[x] += self.size[y]
            self.parents[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def msize(self, x):
        return self.size[self.find(x)]

def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for i in range(M):
        A, B = map(int, input().split())
        uf.union(A-1, B-1)
    ans = 0
    for i in range(N):
        ans = max(ans, uf.msize(i))
    print(ans)


if __name__ == "__main__":
    main()



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

int main()
{
    int N;
    cin>>N;
    vector<long long>A(N),B(N),C(N);
    for(int i=0;i<N;i++)
    cin>>A[i]>>B[i]>>C[i];
    
    vector<vector<int>>dp(N,vector<int>(3,0));
    dp[0][0]=A[0];
    dp[0][1]=B[0];
    dp[0][2]=C[0];
    for(int i=1;i<N;i++)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+A[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+B[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+C[i];
    }
    cout<<max(dp[N-1][0],max(dp[N-1][1],dp[N-1][2]));
    
}

Measured memory_bytes: 8064
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

int a, b, c;
int flag[11];
int main()
{
	memset(flag, 0, sizeof(flag));
	scanf("%d %d %d", &a, &b, &c);
	flag[a]++;
	flag[b]++;
	flag[c]++;
	if(flag[5] == 2 && flag[7] == 1) printf("YES\n");
		else printf("NO\n");
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scanf("%d", &N)

	c := map[string]int{}

	for i := 0; i < N; i++ {
		var s string
		fmt.Scanf("%s", &s)
		a := count(s)
		key := key(a)
		_, ok := c[key]
		if ok {
			c[key] += 1
			continue
		}
		c[key] = 1
	}

	var total int64
	for _, count := range c {
		if count == 1 {
			continue
		}
		total += int64(count) * (int64(count)-1) / 2
	}

	fmt.Printf("%d", total)
}

func key(m map[rune]int) string {
	keys := []int{}
	for k := range m {
		keys = append(keys, int(k))
	}
	sort.Ints(keys)

	str := ""
	for _, k := range keys {
		str += fmt.Sprintf("%d:%d-", k, m[rune(k)])
	}
	return str
}


func count(s string) map[rune]int {
	c := map[rune]int{}
	for _, r := range s {
		_, ok := c[r]
		if ok {
			c[r] += 1
			continue
		}
		c[r] = 1
	}
	return c
}


Measured memory_bytes: 18304
//QWsin
#include<set>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,x,y) for(int i=x;i<=y;++i)
#define out(i,u) for(int i=first[u];i!=-1;i=nxt[i])
#define repvc(i,vc) for(int i=0,Sz=vc.size();i<Sz;++i)
using namespace std;
inline int read()
{
	char ch=getchar();int ret=0,f=1;
	while(ch<'0' || ch>'9') {if(ch=='-')f=-1;ch=getchar();}
	for(;ch>='0' && ch<='9';ch=getchar()) ret=ret*10+ch-'0';
	return ret*f;
}

inline void print(string name,int *arr,int len){
	rep(i,1,len) printf("%s[%d]=%d\n",name.c_str(),i,arr[i]);puts("");
}
inline void print(string name,int a){
	printf("%s=%d\n",name.c_str(),a);puts("");
}

typedef long long ll;
typedef unsigned long long ull;
const int INF=1<<30;

const int maxn=200000+10;
int cnt[maxn],ans[maxn],x[maxn*2],a[maxn],x2[maxn*2],b[maxn];
int n;

ull base=827;
ull basec[maxn*2],hashv[maxn*2],hashv2[maxn*2];
ull gethash(int l,int r,ull *hashv){
	return hashv[r]-hashv[l-1]*basec[r-l+1];	
}

void solve(int p)
{
	rep(i,1,n) x[i]=a[i]&p,x2[i]=x[i]^p;
	rep(i,n+1,n*2) x[i]=x[i-n],x2[i]=x2[i-n];
	rep(i,1,n*2) {
		hashv[i]=hashv[i-1]*base+x[i]+1;
		hashv2[i]=hashv2[i-1]*base+x2[i]+1;
	}
	ull val=0;
	rep(i,1,n){
		val=val*base+(b[i]&p)+1;	
	}
	rep(i,1,n) {
		ull cur=gethash(i,i+n-1,hashv);
		if(gethash(i,i+n-1,hashv)==val) ++cnt[i];
	}
	rep(i,1,n) if(gethash(i,i+n-1,hashv2)==val) ++cnt[i],ans[i]|=p;
	
}

int main()
{
	cin>>n;
	basec[0]=1;
	rep(i,1,n*2) basec[i]=basec[i-1]*base;
	rep(i,1,n) cin>>a[i];
	rep(i,1,n) cin>>b[i];
	rep(i,0,29) 
		solve(1<<i);
	rep(i,1,n) if(cnt[i]==30) printf("%d %d\n",i-1,ans[i]);
	return 0;
}


Measured memory_bytes: 19072
from collections import Counter
n=int(input())
a=list(Counter(list(map(int,input().split()))).items())
ans=0
for i in range(len(a)):
  if a[i][0]<a[i][1]:
    ans+=a[i][1]-a[i][0]
  elif a[i][0]>a[i][1]:
    ans+=a[i][1]
print(ans)



Measured memory_bytes: 102348
#include<stdio.h>
int main(){
  int a,b,c,d,e,f,g,h,suma,sumb;
 
  scanf("%d %d %d %d\n %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h);
   
  suma=a+b+c+d;
  sumb=e+f+g+h;
   
  if(suma >= sumb){
    printf("%d\n",suma);
  }
  else{
    printf("%d\n",sumb);
      }
   
  return 0;
   
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
        #define ll    long long
        #define lld long double
        #define hell  998244353 
         
        using namespace std;
         
         
         
        int main()
        {
        	ios::sync_with_stdio(0);
        	cin.tie(0);
        	cout.tie(0);
         ll a,b;
          cin>>a>>b;
          if(a==b)
            cout<<0;
          else if((a+b)%2==0)
            cout<<(a+b)/2;
          else
            cout<<"IMPOSSIBLE";
          cout<<endl;
          
        }

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


//int h[100001];


unsigned long long dp[100001] = {};
/*
int solve(int i){
	if(i == 0) return 0;
	if(i == 1) return 0;
	if(memo[i] != -1) return memo[i];
	int m = INT_MAX;
	for(int d = 1; d <= k; d++){
		if(i - d < 0) break;
		m = min(solve(i-d, k)+abs(h[i]-h[i-d]), m);
	}
	return memo[i] = m;
}
*/

int main(){

	int n;
	cin >> n;

	int w; cin >> w;

	pair<int, int> wv[100];
	for(int i = 0; i < n; i++){
		cin >> wv[i].first >> wv[i].second;
		dp[0] = 0;
		for(int j = 1; j < 100001; j++){
			dp[j] = ~0ull;
		}
	}

	int ans = 0;
	
	for(int j = 0; j <= n; j++){
		for(int i = 100000; i >= 0; i--){
			if(dp[i] == ~0ull)continue;
			
			dp[i + wv[j].second] = min(dp[i] + wv[j].first, dp[i + wv[j].second]);
			dp[i] = dp[i];
			if(dp[i] + wv[j].second <= w) ans = max(ans, i);
		}
	}


	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] sa = br.readLine().split(" ");
		BigInteger[] a = new BigInteger[n];
		for (int i = 0; i < n; i++) {
			a[i] = new BigInteger(sa[i]);
		}
		br.close();

		BigInteger m = BigInteger.valueOf(1000000007);
		BigInteger lcm = BigInteger.ONE;
		for (int i = 0; i < n; i++) {
			lcm = lcm.multiply(a[i]).divide(lcm.gcd(a[i]));
		}
		lcm = lcm.mod(m);

		BigInteger ans = BigInteger.ZERO;
		for (int i = 0; i < n; i++) {
			BigInteger val = lcm.multiply(a[i].modInverse(m));
			ans = ans.add(val);
			ans = ans.mod(m);
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 154416
function Main(input){
  //パラメータ受け取り
  input = input.split("\n");
  inputStr = input[0].split(" ");
  var N = Number.parseInt(inputStr[0]);
  var K = Number.parseInt(inputStr[1]);
  inputStr = input[1].split(" ");
  var H_arr = inputStr.map( inputStr => parseInt(inputStr));
  
  //解法としてDPを用いる
  var i = 0;	//今たっている場所
  var ans = []; //回答格納用配列
  //ansの配列要素Nの確定と初期化
  for(var i=0 ; i<N ; i++){
    ans.push(0);
  }
  
  //階段の0段目のコストをメモ。値は0
  ans[0] = 0;
  //階段の1段目に進んだ時のコストをメモ
  ans[1] = Math.abs(H_arr[1]-H_arr[0]); 
  //階段の3段目以降のコストをforループで処理
  for( var i=2 ; i<N ; i++){
    var last = 10000000000;
    for(var j=1 ; j<=K ; j++){
      if( i >= j){
        //自分のところ(i段目)にj段前から来た場合の値を格納
        var tmp = ans[i-j]+Math.abs(H_arr[i]-H_arr[i-j]);
        last = Math.min(tmp,last);
      }
    }
    //より小さい値(最小コスト)を回答配列の自分の段に格納
    ans[i] = last;
  }
  //結果表示
  console.log(ans[N-1]);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 27932
#include <stdio.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <string.h>
#define FOR(x, z, y) for(int x = (z); y; x++)
#define rep(x, y) for(int x = 0; x < (y); x++)
#define REP(x, z, y) for(int x = (z); x < (y); x++)
#define all(x) x.begin(), x.end()
#define len(x) (sizeof(x) / sizeof(x[0]))
#define split_str(str, sp_word) istringstream stream(str); string res; FOR(cnt, 0, getline(stream,res,sp_word))
#define scanln(x) fgets(x, sizeof x, stdin)
#define down_queue(x) priority_queue<x>
#define up_queue(x) priority_queue<x, vector<x>, greater<x>>
#define i_str(x) atoi(x.c_str())
typedef long long ll;
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  getchar();

  int INF = 51;
  int a[26],cnt_line[26] = {};
  fill(a,a + 26,INF);

  string line;
  rep(i,N){
    getline(cin,line);

    for(char c:line) 
      a[c - 'a'] = min(a[c - 'a'], (int)count(all(line), c)); 

    for(int i = 'a'; i <= 'z'; i++)
      if(count(all(line), i) > 0)
        cnt_line[i - 'a']++;
  }

  rep(i,26)
    if(cnt_line[i] >= N && a[i] != INF)
      rep(j,a[i]) 
        printf("%c",i + 'a');

  return 0;
}

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

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

    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
    {
        cout << "Yes" << "\n";
    } else 
    {
        cout << "No" << "\n";
    }
    return 0;
}

Measured memory_bytes: 3568
n,m = map(int,input().split())
ss = []
for mi in range(m):
  splus = [0]*n
  s = list(map(int,input().split()))[1:]
  for ni in range(n):
    if (ni+1) in s:
      splus[ni] = 1
  ss.append(splus)
p = list(map(int,input().split()))
score = 0
swi = [0]*n
while True:
  judge = 1
  for mi in range(m):
    count = 0
    for ni in range(n):
      count += ss[mi][ni] * swi[ni]
    judge *= bool(count%2==p[mi])
  if judge == 1:
    score += 1
  swi[0] +=1
  for ni in range(n-1):
    if swi[ni] == 2:
      swi[ni] = 0
      swi[ni+1] += 1
  if swi[-1] == 2:
    break
print(score)

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


int main(){
    int n;
    cin >> n;
    vector<ll> v(n);
    int neg = 0;
    int zero = 0;
    for(int i=0; i<n; i++){
        cin >> v[i];
        if(v[i] < 0) neg++;
        if(v[i] == 0) zero++;
    }
    ll mi = 1e9;
    for(int i=0; i<n; i++){
        mi = min(mi, abs(v[i]));
    }

    ll ans = 0;
    for(int i=0; i<n; i++) ans += abs(v[i]);
    bool flag = false;
    if(neg%2 == 0) flag = true;
    if(neg%2 != 0 && zero != 0) flag = true;
    if(flag == false) ans -= 2*abs(mi);
    cout << ans << endl;
}

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

using namespace std;

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

	string s,t;
	cin >> s >> t;
	int count = 0;
	for(int i=0; i<s.length(); i++){
		if(s[i] != t[i]) count++;
	}
	cout << count;
	return 0;
}

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

int main(){
    ll A, B;
    cin >> A >> B;
    if (A < B) swap(A, B);
    for (ll i=1; i<=B; i++) {
        if ((A*i)%B == 0) {
            A = A*i;
            break;
        }
    }
    cout << A << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef long li;
typedef int in;
typedef double dub;
#define fst first
#define scnd second
#define pub push_back
#define pob pop_back
#define mkp make_pair
#define lb lower_bound
#define ub upper_bound
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int a,b,i;
    while(cin>>a>>b)
    {
        if(a>b)
        {
            for(i=0;i<a;i++)
            {
                cout<<b;
            }
            cout<<endl;
        }
        else
        {
            for(i=0;i<b;i++)
            {
                cout<<a;
            }
            cout<<endl;
        }
    }
    return 0;
}



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

int main(){
	int n; cin >> n; 
	vector<pair<int, int>>a(n);
	for(int i = 0; i < n; i++){
		pair<int, int> a_in;
		int first; cin >> first;
		a_in.first = first;
		a_in.second = i;
		a[i] = a_in;
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	for(int i = 0; i < n; i++){
		if(i == a[0].second){
			cout << a[1].first << endl;
		}else{
			cout << a[0].first << endl;
		}
	}
}

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

int waru(int n) {
  int ans = 0;
  while(n%2==0) {
    n = n/2;
    ans++;
  }
  return ans;
}


int main() {
  int N;
  cin >> N;
  int cnt = 0;
  int ans = 1;
  for (int i = 1; i <= N;i++) {
    if (cnt < waru(i)) {
      cnt = waru(i);
      ans = i;
    }
  }
  cout << ans << endl;
    
    
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i=0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using M = map<int, int>;
ll INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(m);
  rep(i, m) cin >> a[i];

  ll sum = accumulate(a.begin(), a.end(), 0);
  if (n - sum < 0) cout << -1 << endl;
  else cout << n - sum << endl;


  return 0;
}


Measured memory_bytes: 3704
import java.util.Scanner

object Main extends App {
  def readALine(c:Int, ac:List[Int]):List[Int] =
    if (c > 0) readALine(c-1, sc.nextInt::ac) else ac.reverse
  def readLines(r:Int, c:Int, ac:List[List[Int]]):List[List[Int]] =
    if (r > 0) readLines(r-1, c, readALine(c, Nil)::ac) else ac.reverse
  val sc = new Scanner(System.in)
  val n = sc.nextInt

  println(n*n*n)

}


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

int main() {
   int N, X,T;
   cin >> N >> X >> T;
   int ans;
   if(N % X == 0){
       ans = (N / X) * T;
   }else{
       ans = (N / X + 1) * T;
   }
   cout << ans << endl;
}

Measured memory_bytes: 3588
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

//NまでのMOD逆元をコンパイル時計算する
template<long long N,long long MOD>
class ModInv_calc{
  public:
  long long inv[N+1];
  constexpr ModInv_calc():inv(){
    inv[1]=1;
    for(int i=2;i<=N;i++)inv[i]=inv[MOD%i]*(MOD-MOD/i)%MOD;
  }

  constexpr long long operator[](size_t i)const noexcept{return inv[i];}
};

constexpr ModInv_calc<1000100,1000000007> inv{ModInv_calc<1000100,1000000007>()};

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

  ll n;
  std::cin>>n;

  std::vector<ll> a(n);
  rep(i,0,n)std::cin>>a[i];

  std::map<ll,ll> prime;

  rep(i,0,n){
    ll temp=a[i];
    for(ll j=2;j*j<=a[i];j++){
      if(temp%j==0){
        ll cnt=0;
        while(temp%j==0){
          cnt++;
          temp/=j;
        }
        chmax(prime[j],cnt);
      }
    }
    if(temp!=1)chmax(prime[temp],1);
  }

  ll lcm=1;

  for(auto e:prime){
    lcm*=pow_mod(e.first,e.second,MOD);
    lcm%=MOD;
  }

  ll ans=0;

  rep(i,0,n){
    ans+=lcm*inv[a[i]];
    ans%=MOD;
  }

  std::cout<<ans<<"\n";

  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int n,k;
    cin >> n >> k;
    int tmp,cnt[n]={};
    for(int i=1; i<=n; i++){
        tmp=i;
        for(int j=1; j<=k; j++){
            if(tmp>=k){
                cnt[i-1]=j-1;
                break;
            }
            tmp*=2;
        }
    }
    double ans[n];
    double sum=0;
    for(int i=0; i<n; i++){
        ans[i]=1.0/(1ll<<cnt[i]);
        sum+=ans[i];
    }
    sum/=n;
    cout << fixed << setprecision(15) << sum <<endl;
}

Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E '\n'

using namespace std;
const long long MOD = 998244353;

int n, k;
vector<pair<int, int>> segs;
long long dp[200009], sum[200009];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for (int i = 0; i < k; i++) {
		int l, r;
		cin >> l >> r;
		segs.pb({ l, r });
	}
	dp[0] = 1;
	sum[0] = 1;
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < k; j++) {
			int l = segs[j].fi, r = segs[j].se;
			if (i - l < 0) continue;
			long long tmp = sum[i - l];
			if (i - r > 0) tmp -= sum[i - r - 1];
			if (tmp < 0) tmp += MOD;
			dp[i] += tmp;
			dp[i] %= MOD;
		}
		sum[i] = sum[i - 1] + dp[i];
		sum[i] %= MOD;
	}
	cout << dp[n - 1] << E;
	//system("pause");
	return 0;
}

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

ll N;
vector<ll> A;

ll gcd(ll a, ll b) {
  ll A = max(a, b);
  ll B = min(a, b);
  if (A < 1 || B < 1) {
    return A;
  }
  return gcd(B, A % B);
}

void solve() {
  ll init = A[0];
  for (int i = 1; i < N; i++) {
    init = gcd(init, A[i]);
  }

  for (int i = 0; i < N; i++) {
    A[i] /= init;
  }

  sort(A.rbegin(), A.rend());
  ll tmp = A[N - 1];
  int itr = 0;
  for (int i = N - 1; i >= 0; i--) {
    if (gcd(tmp, A[i]) == 1) {
      itr = i;
      break;
    }
  }

  ll init2 = A[N - 1];
  for (int i = N - 1; i >= 0; i--) {
    if (i == itr) {
      continue;
    }
    init2 = gcd(init2, A[i]);
  }

  ll res = init * init2;

  ll init3 = A[N - 2];
  for (int i = N - 2; i >= 0; i--) {
    init3 = gcd(init3, A[i]);
  }

  res = max(res, init * init3);

  cout << res << "\n";
  return;
}

int main() {
  cin >> N;
  A.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  solve();
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,M,K,T;
ll fast,slow,mid;
vector<ll> t;

ll search(ll x,ll v){
  if(x>T)return 0;
  return (T-x)/v+1;
}

void solve(){
  ll ans=0;
  vector<ll> v;
  if( (N-1)*fast <= T )ans++;
  
  for(int i=0;i+1<(int)t.size();i++){
    ll left=t[i],right=t[i+1];
    ll lx=(left-1)*fast;
    ll Fi=search(lx,slow);
    ans+=min(left+Fi,right)-left;
    for(int j=0;j<K-M;j++){
      ll Se=search(lx+Fi*mid,slow);
      ll first=min(left+Fi,right);
      ll second=min(left+Fi+Se,right);
      v.push_back(second-first);
      Fi+=Se;
    }
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  for(int i=0;i<K-M;i++)ans+=v[i];
  cout<<ans-1<<endl;
}
 
int main(){
  cin>>N>>M>>K>>slow>>fast>>mid>>T;
  t.resize(M);
  for(int i=0;i<M;i++)cin>>t[i];
  solve();
  return 0;
}

Measured memory_bytes: 19268
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define rep(i,N) for(long long i = 0; i < (long long)(N); i++)
#define repr(i,N) for(long long i = (long long)(N) - 1; i >= 0; i--)
#define rep1(i,N) for(long long i = 1; i <= (long long)(N) ; i++)
#define repr1(i,N) for(long long i = (N) ; (long long)(i) > 0 ; i--)
#define each(x,v) for(auto& x : v)
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
using namespace std; void solve();
using ll = long long; template<class T = ll> using V = vector<T>;
using vi = V<int>; using vl = V<>; using vvi = V< V<int> >;
constexpr int inf = 1001001001; constexpr ll infLL = (1LL << 61) - 1;
struct IoSetupNya {IoSetupNya() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(7);} } iosetupnya;
template<typename T, typename U> inline bool amin(T &x, U y) { return (y < x) ? (x = y, true) : false; }
template<typename T, typename U> inline bool amax(T &x, U y) { return (x < y) ? (x = y, true) : false; }
template<typename T, typename U> ostream& operator <<(ostream& os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<typename T, typename U> istream& operator >>(istream& is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator <<(ostream& os, const vector<T> &v) { int s = (int)v.size(); rep(i,s) os << (i ? " " : "") << v[i]; return os; }
template<typename T> istream& operator >>(istream& is, vector<T> &v) { for(auto &x : v) is >> x; return is; }
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
template<typename T>void die(T x){out(x); exit(0);}
#ifdef NyaanDebug
  #include "NyaanDebug.h"
  #define trc(...) do { cerr << #__VA_ARGS__ << " = "; dbg_out(__VA_ARGS__);} while(0)
  #define trca(v,N) do { cerr << #v << " = "; array_out(v , N);} while(0)
  #define trcc(v) do { cerr << "name : " << #v << "\n"; int cnt = 0; each(x , v){cerr << (cnt++) << " : "; trc(x); } } while(0)
#else
  #define trc(...)
  #define trca(...)
  #define trcc(...)
  int main(){solve();}
#endif

#define inc(...) char __VA_ARGS__; in(__VA_ARGS__)
#define in2(s,t)   rep(i,sz(s)){in(s[i] , t[i]);}
#define in3(s,t,u) rep(i,sz(s)){in(s[i] , t[i] , u[i]);}
using vd = V<double>; using vs = V<string>; using vvl = V< V<> >;
template<typename T,typename U>ll ceil(T a,U b){return (a + b - 1) / b;}

using P = pair<int,int>; using vp = V<P>;
constexpr int MOD = /**/ 1000000007; //*/ 998244353;
//////////////////

void solve(){
  ins(S);
  vi cnt(3);
  each(x , S) cnt[x - 'a']++;
  sort(all(cnt));
  out((cnt[2] - cnt[0]) <= 1 ? "YES" : "NO");
}

Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

#include <stdexcept>

using namespace std;

//conversion
//------------------------------------------
inline int toint(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class t> inline string tostring(t x) { ostringstream sout; sout << x; return sout.str(); }

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (l" << __line__ << ")" << " " << __file__ << endl

// type alias
using ll = long long;
using ull = unsigned long long;

inline ll floor(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return a / llb;
	}
	else
	{
		return - ( (-a + llb - 1) / llb);
	}
}

inline ll ceil(ll a, ull b)
{
	ll llb = b;
	if (a >= 0)
	{
		return (a + llb - 1) / llb;
	}
	else
	{
		return - (-a / llb);
	}
}

inline bool isPower2(ull a)
{
	if (a == 0)
	{
		return false;
	}
	return !(a & (a - 1));
}

inline ll getMaxEffectiveBit(ull a)
{
	ll index = -1;
	for (; a != 0; a >>= 1)
	{
		++index;
	}
	return index;
}

inline ll getSpecifiedBit(ull a, unsigned bit)
{
	return (a & (1LL << bit)) >> bit;
}

// computational complexity: o(log(max(a, b))) 
inline ull getGcd(ull a, ull b)
{
	if (b == 0)
	{
		return a;
	}
	return getGcd(b, a % b);
}

template<class Integer>
inline Integer getPower(Integer base, ull exponential)
{
	Integer result = 1;
	while (exponential >= 1)
	{
		if (exponential & 1)
		{
			result = result * base;
		}
		base = base * base;
		exponential >>= 1;
	}

	return result;
}

ll val(ll a, ll c, ll d)
{
	ll m = c / getGcd(c, d) * d;
	return a - a / c - a / d + a / m;
}

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

	ll N, K;
	cin >> N >> K;
	
	if (K > (N - 1) * (N - 2) / 2)
	{
		cout << -1 << endl;
		return 0;
	}

	ll M = 0;
	vector<pair<ll, ll>> edges;
	for (ll i = 2; i <= N; ++i, ++M)
	{
		edges.emplace_back(1LL, i);
	}

	ll u = 2;
	ll v = u + 1;
	for (ll res = (N - 1) * (N - 2) / 2; res > K; --res, ++M)
	{
		edges.emplace_back(u, v);
		if (v < N)
		{
			++v;
		}
		else
		{
			++u;
			v = u + 1;
		}
	}
	
	cout << M << endl;
	for (ll i = 0; i < edges.size(); ++i)
	{
		cout << edges[i].first << " " << edges[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 512
SA=input()
SB=input()
SC=input()

A_rest=len(SA)
B_rest=len(SB)
C_rest=len(SC)
next='a'

while(1):
    if next=='a':
       	if A_rest==0:
            print('A')
            exit()
        next=SA[len(SA)-A_rest]
        A_rest-=1
    elif next=='b':
       	if B_rest==0:
            print('B')
            exit()
        next=SB[len(SB)-B_rest]
        B_rest-=1
    else:
       	if C_rest==0:
            print('C')
            exit()
        next=SC[len(SC)-C_rest]
        C_rest-=1

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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define rALL(x) x.rbegin(),x.rend()

using namespace std;
using ll=long long;


int main(){
  string u;cin>>u;
  vector<string> s(16);
  s[0]="KIHBR";
  s[1]="KIHBRA";
  s[2]="KIHBAR";
  s[3]="KIHBARA";
  s[4]="KIHABR";
  s[5]="KIHABRA";
  s[6]="KIHABAR";
  s[7]="KIHABARA";

  s[8]="AKIHBR";
  s[9]="AKIHBRA";
  s[10]="AKIHBAR";
  s[11]="AKIHBARA";
  s[12]="AKIHABR";
  s[13]="AKIHABRA";
  s[14]="AKIHABAR";
  s[15]="AKIHABARA";

  for(auto t:s)if(t==u){cout<<"YES";return 0;}
  cout<<"NO";

}

Measured memory_bytes: 3584
/*
[agc029] D - Grid game
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_N = 2e5;
const int MAX_H = 2e5;

int H, W, N;
int X[MAX_N], Y[MAX_N];
set<int> obs[MAX_H];

ll solve() {
    for (int i = 0; i < N; i++) {
        obs[Y[i]].insert(X[i] - Y[i]);
    }

    int ans = H;
    int lx = 0;
    for (int y = 0; y < W; y++) {
        obs[y].insert(H - y);
        while (obs[y].find(lx) != obs[y].end()) {
            lx++;
        }
        auto iter = obs[y].upper_bound(lx);
        if (iter == obs[y].end()) {
            break;
        }
        int x = *iter;
        ans = min(ans, x + y);
    }

    return ans;
}

int main() {
    cin >> H >> W >> N;
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
        X[i]--;
        Y[i]--;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 27904
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll dep(ll a, ll b){
	if(b==0){
		return a;
	}
	return dep(b,a%b);
}
int main() {
	ll n;
	cin>>n;
	if(n%2!=0){
		cout << 0;
		return 0;
	}
	ll now=10;
	ll ans=0;
	while(now<=n){
		ans+=n/now;
		now*=5;
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 3604
import java.io.*;
import java.lang.Integer;
import static java.lang.Math.*;
public class Main {
	public static void main(String[] args) {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String in  = br.readLine() ;
			double r = Double.parseDouble(in);
			double area = r*r*PI;
			double enshu = 2*r*PI;
			System.out.printf("%5.5f %5.5f", area, enshu );
		} catch ( IOException e ) {
			System.out.println("??¨??????????????????????????????");
		}
	}
}

Measured memory_bytes: 24616
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 1e9+7;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll x[11000];
int main(){
  ll n,k,ans=0;
  cin>>n;
  rep(i,0,n)cin>>x[i];
  ll xxx=1e9;
  rep(i,1,101){
    ll tmp=0;
    rep(j,0,n){
      tmp+=(x[j]-i)*(x[j]-i);
    }
    xxx=min(xxx,tmp);
  }
  cout<<xxx;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
const int X = 3999;
 
int a[1234][1234];
 
int main() {
  int H, W, h, w;
  cin >> H >> W >> h >> w;
  if(H%h==0&&W%w==0)return puts("No"),0;
  puts("Yes");
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i % h == h - 1 && j % w == w - 1) {
        a[i][j] = -X * (h * w - 1) - 1;
      } else {
        a[i][j] = X;
      }
    }
  }
  // long long total = 0;
  // for (int i = 0; i < H; i++) {
  //   for (int j = 0; j < W; j++) {
  //     total += a[i][j];
  //   }
  // }
  // if (total <= 0) {
  //   puts("No");
  //   return 0;
  // }
  // puts("Yes");
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (j > 0) putchar(' ');
      printf("%d", a[i][j]);
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 5632
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.FilterInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Jenish
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        ScanReader in = new ScanReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        OMatching solver = new OMatching();
        solver.solve(1, in, out);
        out.close();
    }

    static class OMatching {
        private static final long mod = (long) (1e9 + 7);

        public void solve(int testNumber, ScanReader in, PrintWriter out) {
            int n = in.scanInt();
            boolean mat[][] = new boolean[n][n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                    mat[i][j] = (in.scanInt() == 1);


            long dp[] = new long[(1 << n)];

            for (int j = 0; j < n; ++j) if (mat[0][j]) dp[1 << j]++;

            for (int mask = 0; mask < (1 << n); mask++) {
                int i = Integer.bitCount(mask) - 1;
                if (i < 0) continue;
                for (int e = 0; e < n; e++) {
                    if (mat[i][e]) {
                        if ((mask & (1 << e)) != 0) {
                            if (i != 0) dp[mask] = (dp[mask] + dp[mask ^ (1 << e)]) % mod;
                        }
                    }
                }
            }
            out.println(dp[(1 << n) - 1]);
        }

    }

    static class ScanReader {
        private byte[] buf = new byte[4 * 1024];
        private int INDEX;
        private BufferedInputStream in;
        private int TOTAL;

        public ScanReader(InputStream inputStream) {
            in = new BufferedInputStream(inputStream);
        }

        private int scan() {
            if (INDEX >= TOTAL) {
                INDEX = 0;
                try {
                    TOTAL = in.read(buf);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (TOTAL <= 0) return -1;
            }
            return buf[INDEX++];
        }

        public int scanInt() {
            int I = 0;
            int n = scan();
            while (isWhiteSpace(n)) n = scan();
            int neg = 1;
            if (n == '-') {
                neg = -1;
                n = scan();
            }
            while (!isWhiteSpace(n)) {
                if (n >= '0' && n <= '9') {
                    I *= 10;
                    I += n - '0';
                    n = scan();
                }
            }
            return neg * I;
        }

        private boolean isWhiteSpace(int n) {
            if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1) return true;
            else return false;
        }

    }
}



Measured memory_bytes: 41428
import copy
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    h,w,k=INTM()
    c=[]
    ct=0
    for i in range(h):
        c.append(list(input()))
    for i in range(2**h):
        h2=str(format(i, 'b').zfill(h))
        for j in range(2**w):
            w2=str(format(j, 'b').zfill(w))
            #print(h2,w2)
            c_t=copy.deepcopy(c)
            
            for i2 in range(h):
                if h2[i2]=='1':
                    c_t[i2]=['.']*w
                    
            #print(c_t)
            for j2 in range(w):
                #print(j2)
                if w2[j2]=='1':
                    for i3 in range(h):
                        c_t[i3][j2]='.'
            
            temp=0
            for i2 in range(h):
                temp+=c_t[i2].count('#')
            
            if temp==k:
                ct+=1
                
    
    print(ct)
            
    
    
        
if __name__ == '__main__':
    do()

Measured memory_bytes: 9356
N = int(input())

W = []
for i in range(N):
    W.append(str(input()))

for i in range(N):
    if i != 0:
        tmp = list(W[i-1])
        last_end = tmp[-1]

        tmp = list(W[i])
        current_start = tmp[0]
        if (last_end != current_start) or (len(W) != len(list(set(W)))):
            print('No')
            exit()
print('Yes')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
char s[12], t[12];
int main(){
    scanf("%s%s", s, t);
    int len = strlen(s);
    int flag = 0;
    for(int i = 0; i < len; i++) {
        if(s[i] != t[i]) {
            flag = 1;
            break;
        }
    }
    if(flag) printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3764
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll dp[100005];
const ll MOD=1e9+7;

int main()
{jizz
	ll n,k,sum,x;
	cin >> n >> k,dp[0]=1;
	for(int i=1;i<=n;++i)
	{
		cin >> x,sum=0;
		for(int j=k;j>k-x;--j) 
			sum=(sum+dp[j])%MOD;
		for(int j=k;j>0;--j)
		{
			if(j>=x) sum=(sum+dp[j-x])%MOD;
			sum=(sum-dp[j]+MOD)%MOD,dp[j]=(sum+dp[j])%MOD;
		}
	}
	cout << dp[k] << "\n";
}

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

//--------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

//--------------------------------------------
const double EPS = 1e-14;
const double PI  = acos(-1.0);

//--------------------------------------------

int main(){
  string s;

  cin >> s;

  int c = s.find("C");
  int f = s.rfind("F");

  if (c != -1 && f != -1 && c < f) printf("Yes\n");
  else printf("No\n");
}


Measured memory_bytes: 256