akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
import java.util.Random;

public class Main {
    private static FastScanner sc = new FastScanner();
    private static boolean DEBUG_FLG = false;

    public static void main(String[] args) {
    	char[] S = sc.next().toCharArray();
    	if(S[0] == S[1] || S[1] == S[2] || S[2] == S[3] ) {
    		System.out.println("Bad");
    	} else {
    		System.out.println("Good");
    	}
    }

    static void debug(long... args) {
    	if(!DEBUG_FLG) return;
    	boolean flg = false;
    	for(long s : args) {
    		if(flg) System.out.print(" ");
    		flg = true;
    		System.out.print(s);
    	}
    	System.out.println();
    }

    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;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); 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() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }

    static void shuffleArray(long[] arr){
        int n = arr.length;
        Random rnd = new Random();
        for(int i=0; i<n; ++i){
            long tmp = arr[i];
            int randomPos = i + rnd.nextInt(n-i);
            arr[i] = arr[randomPos];
            arr[randomPos] = tmp;
        }
    }
}


Measured memory_bytes: 23252
s=input().strip()
K=int(input())
sorteds=sorted(set(s))
ct=0
subsset=set()
for c in sorteds:
    ct+=1
    ixs=[]
    ss=s
    ix=0
    while len(ss):
        ii=ss.find(c)
        if ii==-1:break
        ixs.append(ix+ii)
        ix=ix+ii
        ss=ss[ii:]
        for i in range(min(len(ss),K)):
            subsset.add(ss[:1+i])
        ss=ss[1:]
    if len(subsset)>=K:
        break
print(sorted(list(subsset))[K-1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<int, int>
#define debug(x) cout << #x << ": " << x << ", "
#define debugln(x) cout << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const int mod = 1e9+7;

long long gcd(long long a, long long b) {
  long long r = 1;
  while (r != 0) {
    r = a%b;
    a = b;
    b = r;
  }
  return a;
}

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

  int n; cin >> n;
  int X; cin >> X;

  vector<int> vec;
  rep(i, n) {
    int x; cin >> x;
    x -= X;
    if (x < 0) {
      x = -x;
    }
    if (x != 0) {
      vec.push_back(x);
    }
  }

  int ans = vec.at(0);
  for (int x: vec) {
    ans = gcd(ans, x);
  }

  cout << ans << endl;
}


Measured memory_bytes: 892
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    for (int i = n; i <= 1000000; i++) {
      int amari_count = 0;
      boolean isFound = true;
      for (int j = 1; j <= i; j++) {
        if (i % j == 0) {
          amari_count++;
        }
        if (amari_count > 2) {
          isFound = false;
          break;
        }
      }
      if (isFound) {
        System.out.println(i);
        break;
      }
    }
  }
}


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

int main() {
	double a,b;
	int c;
	cin >> a >> b;
	c = (a + b) / 2;
	a = (a + b) / 2;
	if (a != c) {
		c = c + 1;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define iof freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define BiEdge(v,a,b) (v)[(a)].pb((b)),(v)[(b)].pb((a))
#define ll long long
#define ld long double
#define pb push_back
#define Pb pop_back
#define F first
#define S second
#define pi acos(-1)
#define eps 1e-7
#define bpc __builtin_popcount
#define all(f) (f).begin(),(f).end()
#define allr(f) (f).rbegin(),(f).rend()
#define cross(a,b) (conj(a)*(b)).real()
#define dot(a,b) (conj(a)*(b)).imag()
typedef complex <ld> point ;
typedef vector <point> polygon ;
typedef tuple <ll,ll,ll> line ;
const int mod = 1e9+7 , A = 1e5+5 ;

ll rep[100005] , sz[100005] ;
ll find(ll u)
{
	return rep[u] == u ? u : rep[u] = find(rep[u]) ;
}
bool join(ll a , ll b)
{
	a = find(rep[a]) , b = find(rep[b]) ;
	if (a == b)
		return false ;
	if (sz[a] < sz[b])
		swap (a , b) ;
	sz[a] += sz[b] , sz[b] = 0 ;
	rep[b] = a ;
	return true ;
}
int main()
{
	ios
	ll n;
	cin >> n;
	for(int i = 0;i<n;i++)
		rep[i] = i,sz[i] = 1;
	pair<ll,ll>arr[n+1];
	vector<pair<ll,pair<ll,ll>>>byX,byY;
	for(int i = 0;i<n;i++)
		cin >> arr[i].F >> arr[i].S,byX.pb({arr[i].F,{arr[i].S,i}}),byY.pb({arr[i].S,{arr[i].F,i}});
	sort(all(byX)),sort(all(byY));
	map<ll,vector<pair<ll,ll>>>mp;
	for(int i = 1;i<n;i++)
	{
		mp[byX[i].F - byX[i-1].F].pb({byX[i].S.S,byX[i-1].S.S});
		mp[byY[i].F - byY[i-1].F].pb({byY[i].S.S,byY[i-1].S.S});
	}
	ll ans = 0;
	for(auto i:mp)
		for(auto j:i.S)
			if(join(j.F,j.S))
				ans+=i.F;
	cout << ans;
	return 0 ;
}


Measured memory_bytes: 16800
from math import inf
class solution(object):
    def __init__(self, S: str, T:str) -> None:
        self.S = S
        self.T = T
    
    def solve(self)->int:
        ans = inf
        for i in range(0, len(self.S)-len(self.T)+1):
            temp = 0
            for j in range(0, len(self.T)):
                if(self.S[i+j]!=self.T[j]): temp+=1;
            ans = min(ans,temp)
        return ans

if __name__=='__main__':
    S = input()
    T = input()
    problem = solution(S,T)
    ans = problem.solve()
    print(ans)



Measured memory_bytes: 9012
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define vc vector<int>
#define F first
#define S second
#define eb emplace_back

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1; 
        x = (x * x) % p;
    }
    return res;
}

int modInverse(int n, int p)
{
    return power(n, p - 2, p);
}

int nCrModPFermat(int n, int r, int p)
{

    if (r == 0)
        return 1;

    int fac[n + 1];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
        fac[i] = fac[i - 1] * i % p;

    return (fac[n] * modInverse(fac[r], p) % p *
            modInverse(fac[n - r], p) % p) %
           p;
}
/*
// dsu started 
int a[1000000],b[1000000];
    int find(int x){
        if(b[x]==x) return x;
        b[x]= find(b[x]);
      return b[x];
    }
    void uniona(int x,int y){
        x=find(x);
        y=find(y);
        if (x!=y) {
            a[y]<a[x] ? b[x]=b[y]:b[y]=b[x];
        }
    }
//cut from here
int n,k;
    cin>>n>>k;
     
   
     for(int i=1;i<=n;i++){
    cin>>a[i];
    b[i]=i;
    }
     for(int i=1;i<=k;i++){
    int t1,t2;
    cin>>t1>>t2;// basic code for dsu
    uniona(t1,t2);
//dsu ends
*/

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,mm;
    cin>>n>>mm;
    int q;
    cin>>q;
    map<int,map<int,int>> p;
    map<int,int> sumr,sumc;
    vector<pair<int,int>> v;
    while(q--){
            int t1,t2;
            cin>>t1>>t2;
        p[t1][t2]=1;
            v.eb(make_pair(t1,t2));
            sumr[t1]++;
            sumc[t2]++;
    }
    int x=0,y=0;
    int m=-1;
   for(auto i:sumr){
      if(m<i.S){
          m=i.S;
        //   x=i.first;

      }

 }   vc ur;
  for(auto i:sumr){
      if(m==i.S){
         ur.eb(i.F);

      }
    }    
//  cout<<x<<endl;
vc u;
m=-1;

      for(auto i:sumc){
      if(m<i.S){
          m=i.S;
        //   x=i.first;
      }

 }    
//  cout<<m<<" ";
  for(auto i:sumc){
      if(m==i.S){
         u.eb(i.F);

      }
    }    
 
 int f=1;


for(int i:ur)    
{ 
    x=i;
 for(int j:u){
     y=j;
     if(p[x][y]==0){
        //  cout<<x<<" "<<y;
         f=0;break;
         
     }

 }
 if(f==0) break;
}
// cout<<x<<" "<<y;
if(f)
    cout<<sumr[x]+sumc[y]-1;

else cout<<sumr[x]+sumc[y];
     
}

Measured memory_bytes: 100928
#include <stdio.h>

int main(void){
	int a,b,c,d;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b){
		d=b;
		b=a;
		a=d;
	}
	if(a>c){
		d=c;
		c=a;
		a=d;
	}
	if(b>c){
		d=c;
		c=b;
		b=d;
	}
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] sticks = new int[n];
    for (int i = 0; i < n; i++)
      sticks[i] = sc.nextInt();
    Arrays.sort(sticks);
    int count = 0;
    for (int i = 0; i < n; i++) {
      int k = i + 2;
      for (int j = i + 1; j < n; j++) {
        while (k < n && sticks[i] + sticks[j] > sticks[k])
          k++;
        count += k - 1 - j;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 27304
<?php
$searchQuery = fgets(STDIN);
$delimiters = array(' ', '.', ',');
$minlength = 3;
$maxlength = 6;

$searchQuery = str_replace($delimiters[1], $delimiters[0], $searchQuery);
$searchQuery = str_replace($delimiters[2], $delimiters[0], $searchQuery);
$allSearchWords = explode($delimiters[0], $searchQuery);

$searchWords = array();
foreach ($allSearchWords as $word) {
  if (strlen($word) >= $minlength && strlen($word) <= $maxlength)
    array_push($searchWords, $word);
}

echo trim(implode(' ', $searchWords)) . "\n";

Measured memory_bytes: 15376
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++) 
#define all(v) begin(v),end(v)
using ll = long long;

int main() {
  int n;string s;cin>>n>>s;
  int R=0,B=0;
  rep(i,s.size()){
    if(s[i]=='R')R++;
    else B++;
  }
  if(R>B)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3608
// Author : Mohamed Sameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define Flush fflush(stdout);
using namespace std ;
const int M =1e5 ;
int n ;
int a[M][3];
int dp[M][3];
int solve (int i = 0, int last = 0 )
{
    if (i == n )return 0 ;
    int &ret = dp[i][last];
    if (~ret)return ret ;
    for (int j =0 ; j < 3 ; j++)
    {
        if (j == last && i )continue ;
        ret = max ( ret, a[i][j] + solve(i + 1, j ) ) ;
    }
    return ret;
}
int main()
{
    scanf ("%d", &n );
    memset(dp , -1 ,sizeof dp );
    for (int i =0 ; i < n ; i++)
    {
        scanf ("%d%d%d", a[i], a[i]+1, a[i] + 2 );
    }
    for (int i =0 ; i < 3 ; i++)dp[0][i] = a[0][i];
    for (int i =1 ; i < n ;i++)
    {
        for (int j = 0 ; j < 3 ; j++)
        {
            for (int k =0 ; k < 3 ;k++){
            if (k != j )
            dp[i][j] = max ( dp[i-1][k] + a[i][j], dp[i][j] );
            }
        }
    }

    dp[n-1][0] = max (dp[n-1][1] , dp[n-1][0]);
    dp[n-1][0] = max (dp[n-1][0] , dp[n-1][2]);
    printf ("%d\n" , dp[n-1][0]);

}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    float m=n;
    if(n%2==0){
        n/=2;
    }
    else
     n=(n+1)/2;
    cout<<n/m;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
const int MOD = 1000000007;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

int N, K;
vector<int> A;

int main() {
  while (cin >> N >> K) {
    A.resize(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    int res = 0;
    int right = 0;
    while (true) {
      if (res == 0) right += K;
      else right += K-1;
      ++res;

      if (right >= N) break;
    }
    cout << res << endl;
  }
}

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

using namespace std;

int main(void) {
    string str;
    int flag = 1;
    int j = 0;
    cin >> str;
    //cout << str.size() << endl;
    for(int i = 0; i < ((str.size() - 1) / 2); i++){
        if(str.at(i) != str.at(str.size() - 1 -i)){
            flag = 0;
        }
    }
    //cout << "YES1" << endl;
    //cout << (str.size() / 4) - 1 << endl;
    //cout << str.at(str.size() - 1) << endl;
    //cout << str.at((str.size() - 1) ) << endl;

    if(str.size() > 3){
        for(int i = 0; i <= (str.size() / 4) - 1; i++){
            if(str.at(i) != str.at(((str.size() - 1) / 2) - 1 - i)){
                //cout << str.at(i) << " " << str.at((str.size() - 1) / 2) - 1 - i << endl;
                flag = 0;
            }
        }
    }
    else{
        if(str.at(0) != str.at(2)){
            //cout << str.at(i) << " " << str.at((str.size() - 1) / 2) - 1 - i << endl;
            flag = 0;
        }
    }
    //cout << "YES2" << endl;
    for(int i = ((str.size() + 1) / 2); i <= ((str.size() + 1) / 2) + ((str.size() / 4) - 1); i++){
        
        if(str.at(i) != str.at(str.size() - 1 - j)){
            //cout << i << endl;
            //cout << str.at(i) << " " << str.at(str.size() - 1 - j) << endl;
            flag = 0;
        }
        j = j + 1;
    }

    if (flag == 1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


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


int main()
{


        int A,B,C;
        cin >> A>>B>>C;

        if(A+B+C!=17){
                cout<<"NO"<<endl;
                return 0;
        }

        int cnt=0;

        if(A==5)cnt++;
        else if(A==7)cnt+=10;
        if(B==5)cnt++;
        else if(B==7)cnt+=10;
        if(C==5)cnt++;
        else if(C==7)cnt+=10;

        if(cnt==12)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
        return 0;



}


Measured memory_bytes: 256
//Love and Freedom.
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define ll long long
#define inf 20021225
#define int ll
using namespace std;

char ch[440][440];
int id[440][440],h,w,ans;
bool vis[440][440];
char mp[440][440];
int bl,wh;
int xx[4] = {0,0,-1,1};
int yy[4] = {1,-1,0,0};

void dfs(int x,int y)
{
	if(ch[x][y]=='#')	bl++;
	else	wh++;
	vis[x][y] = 1;
	for(int i=0;i<4;i++)
	{
		int tx = x+xx[i], ty=y+yy[i];
		if(tx<1||ty<1||tx>h||ty>w||vis[tx][ty])	continue;
		if(id[tx][ty] == id[x][y])	dfs(tx,ty);
	}
}

signed main()
{
	scanf("%lld%lld",&h,&w);
	for(int i=1;i<=h;i++)
		scanf("%s",ch[i]+1);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			mp[i][j] = ((i&1)^(j&1)?'#':'.');
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			id[i][j] = (ch[i][j] == mp[i][j]);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(!vis[i][j])
				bl=wh=0,dfs(i,j),ans+=bl*wh;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int N;
vvint graph;
vint seen;
bool bipartite(int p = 0, bool color = 0)
{
    seen[p] = color;
    for (size_t i = 0; i < N; i++)
    {
        if (graph[p][i] == 1)
        {
            if (seen[i] == -1)
            {
                seen[i] = !color;
                if(!bipartite(i, !color))
                return false;
            }
            else if (seen[i] == color)
            {
                return false;
            }
        }
    }
    return true;
}
vint dist;

int main()
{

    cin >> N;
    seen.resize(N);
    dist.resize(N);
    fill_v(dist, -1);
    fill_v(seen, -1);
    graph = make_v<int>(N, N);
    for (size_t i = 0; i < N; i++)
    {
        string s;
        cin >> s;
        for (size_t j = 0; j < N; j++)
        {
            if (s[j] == '1')
            {
                graph[i][j] = 1;
            }
        }
    }
    if (!bipartite())
    {
        cout << -1;
    }
    else
    {
        int ans = 0;
        for (size_t i = 0; i < N; i++)
        {
            fill_v(dist, -1);
            dist[i]=0;
            queue<pair<int,int>> q;
            q.emplace(i,0);
            while(!q.empty())
            {
                int p = q.front().first;
                int d = q.front().second;
                q.pop();
                for (size_t j = 0; j < N; j++)
                {
                    if(graph[p][j]==1 and dist[j] == -1)
                    {
                        dist[j]=d+1;
                        q.emplace(j,d+1);
                    }
                }
                
            }
            for (auto &&j : dist)
            {
                chmax(ans,j);
            }
            
        }

        cout << ans+1;
    }

    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;
}


Measured memory_bytes: 256
N = int(input())
data = []
for _ in range(N):
    x, y, h = map(int,input().split())
    data.append([h, x, y])
data.sort(reverse=True)
end = False
for x in range(101):
    if end:
        break
    for y in range(101):
        if end:
            break
        hi, xi, yi = data[0]
        H = hi + abs(x - xi) + abs(y - yi)
        for i in range(1, N):
            hi, xi, yi = data[i]
            if max(H - abs(x - xi) - abs(y - yi), 0) != hi:
                break
            if i == N - 1:
                print(x, y, H)
                end = True
                break

Measured memory_bytes: 41072
N, K = map(int, input().split())
MOD = 998244353

move = []
for _ in range(K):
  L, R = map(int, input().split())
  move.append((L, R))

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

for i in range(1, N+1):
  dp[i] += dp[i-1]
  for l, r in move:
    if i - l >= 0:
      dp[i] += dp[i-l]
    if i - r - 1 >= 0:
      dp[i] -= dp[i-r-1]
  dp[i] %= MOD

print(dp[N-1])

Measured memory_bytes: 16764
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a, a + 3);
    cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? "YES" : "NO") << endl; 
}

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

using namespace std;
int main() {
  set<int> s;
  int q, x;
  cin >> q; // skip n
  while (cin >> q >> x) {
    if (q == 0) {
      s.insert(x);
      cout << s.size() << endl;
    }
    if (q == 1)
      cout << s.count(x) << endl;
  }
}


Measured memory_bytes: 12488
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long LL;
const int maxn=1e6+2;
const int modn=1e6+3;
ll num[maxn+10];
LL pow(LL a, LL n, LL p)   
{
    LL ans = 1;
    while(n)
    {
        if(n & 1) ans = ans * a % p;          
        a = a * a % p;
        n >>= 1;
    }
    return ans;
}
int main()
{
	num[0]=1;
	for(int i=1;i<=maxn+5;i++){
		num[i]=i*1ll*num[i-1]%modn;
	}
	int q;
	ll x,d,n;
	scanf("%d",&q);
	while(q--){
		scanf("%lld%lld%lld",&x,&d,&n);
		if(d==0){
			printf("%lld\n",pow(x,n,modn));
			continue;
		}
		ll y=x*pow(d,modn-2,modn)%modn;
		if(y+n-1>maxn||y==0){
			printf("0\n");
			continue;
		}
		ll sum=pow(num[y-1],modn-2,modn);
		ll sum1=num[y+n-1]*sum%modn;
		sum1=sum1*pow(d,n,modn)%modn;
		printf("%lld\n",sum1);
	}
}

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

struct point{double x, y;};

void koch(int n, point a, point b){

  if(n == 0) return;
  point s, t, u;
  double th = M_PI * 60.0 / 180.0;

  s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
  s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
  t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
  t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
  u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
  u.y = (t.x - s.x) * sin(th) +(t.y - s.y) * cos(th) + s.y;

  koch(n-1, a, s);
  printf("%.8f %.8f\n", s.x, s.y);
  koch(n-1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);
  koch(n-1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);
  koch(n-1, t, b);
}

int main(){

  int n;
  point a, b;
  cin >> n;
  a.x = a.y = 0;
  b.x = 100; b.y = 0;
  printf("%.8f %.8f\n", a.x, a.y);
  koch(n, a, b);
  printf("%.8f %.8f\n", b.x, b.y);
  return 0;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
    cin.tie(NULL); cout.tie(NULL);
    ios_base:: sync_with_stdio(false);
    ll n;cin>>n;
    string s,t,u;cin>>s>>t>>u;
    ll ans = 0;
    for(ll i=0;i<n;i++){
        set<char> st={s[i],t[i],u[i]};
        ans+=st.size()-1;
    }
    cout<<ans;
}

Measured memory_bytes: 256
import itertools

N = int(input())
S = input()

counter = 0
for a,b,c in itertools.product(range(10), repeat=3):
  
  a_ind = S.find(str(a))
  if a_ind==-1:
    continue
  else:
    b_ind = S[a_ind+1:].find(str(b))
    if b_ind==-1:
      continue
    else:
      c_ind = S[a_ind+1+b_ind+1:].find(str(c))
      if c_ind==-1:
        continue
      else:
        counter += 1
        # print(a_ind,b_ind,c_ind)
        
print(counter)

Measured memory_bytes: 9240
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
using namespace std;
using pll = pair<long long, long long>;

int main() {
    int N, M; cin >> N >> M;
    vector<long long> A(N), B(M), C(M);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end());
    B.resize(M);
    C.resize(M);
    for (int i = 0; i < M; ++i) cin >> B[i] >> C[i];

    // C をソート (B をまとめて)
    vector<int> id(M);
    iota(id.begin(), id.end(), 0);
    sort(id.begin(), id.end(), [&](int i, int j) {
            return C[i] > C[j];});

    // A (小さい順) と C (大きい順) とを比べて大きい方を足していく
    long long sum = 0;
    long long K = 0;
    for (auto i : id) {
        for (int j = 0; j < B[i]; ++j) {
            if (K >= N) break;
            sum += max(A[K++], C[i]);  
        }
    }
    for (int i = K; i < N; ++i) sum += A[i];        
    cout << sum << endl;
}

Measured memory_bytes: 2944
N = int(input())
Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
help = 0
kill = 0
for i in range(N):
    monster = Alist[i] - help
    if monster >= 0:
        kill += help
    else:
        kill += Alist[i]
        monster = 0

    can_kill = Blist[i]
    if can_kill >= monster:
        kill += monster
        help = can_kill - monster
    else:
        kill += can_kill
        help = 0
monster = Alist[-1]
if help >= monster:
    kill += monster
else:
    kill += help
print(kill)


Measured memory_bytes: 18624
import java.io._
import scala.io.StdIn.{readInt, readLine}
 
object Main {
  val out:BufferedWriter =
    new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512)
  var count = 0
  class Node(var key:Int, var left:Node = null, var right:Node = null) { }
 
  def insert(tree:Node, keyNode:Node) = {

    def getNodeToInsert(node:Node):Node =
      if(node.key > keyNode.key) {
        if(node.left == null) node
        else getNodeToInsert(node.left)
      } else {
        if(node.right == null) node
        else getNodeToInsert(node.right)
      }
 
    val target = getNodeToInsert(tree)
 
    if(keyNode.key < target.key) target.left = keyNode
    else target.right = keyNode
  }
 
  def inOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      inOrder(tree.left)
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      inOrder(tree.right)
    }
 
  def preOrder(tree:Node):Unit =
    if(tree == null) return
    else {
      out.write(" ")
      out.write(tree.key.toString)
      if(count<1000) count += 1
      else {
        out.flush
        count = 0
      }
      preOrder(tree.left)
      preOrder(tree.right)
    }
 
  def main(args:Array[String]) = {
    val n = readInt
    val tree = new Node(-1)
 
    for(i<-0 until n) {
      val s = readLine.split(" ")
      s(0) match {
        case "insert" =>
          if(tree.key == -1) tree.key = s(1).toInt
          else insert(tree, new Node(s(1).toInt))
        case _ => {
          inOrder(tree)
          out.write("\n")
          out.flush()
          preOrder(tree)
          out.write("\n")
          out.flush()
        }
      }
    }
  }
}

Measured memory_bytes: 301776
#N=int(input())
N,K = map(int,input().split())
#N=int(input())
A = list(map(int,input().split()))
#S=str(input())

now=1
flag=[-1]*(N)

for i in range(K):
    if flag[now-1]==-1:
        flag[now-1]=i
        now = A[now-1]
    else:
        loop = i - flag[now-1]
        zan=(K-(i-loop))%loop
        ans = flag.index(i-loop+zan)+1
        print(ans)
        exit()

print(now)


Measured memory_bytes: 32376
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  string X;
  cin>>X;
  int count=0;
  for(auto c:X)if(c=='1')count++;
  int C[3]={count-1,count,count+1};
  lint pow2[3][N+1];
  pow2[0][0]=1;
  pow2[1][0]=1;
  pow2[2][0]=1;
  REP(i,N){
    REP(j,3)if(C[j]!=0){
      pow2[j][i+1]=pow2[j][i]*2;
      pow2[j][i+1]%=C[j];
    }
  }
  // REP(i,N)cerr<<pow2[2][i]<<" ";
  // cerr<<endl;
  lint A[3]={0};
  REP(i,N){
    if(X[i]=='1'){
      REP(j,3)if(C[j]!=0){
        A[j]+=pow2[j][N-i-1];
        A[j]%=C[j];
      }
    }
  }
  // cerr<<bitset<5>(A[0])<<" "<<bitset<5>(A[1])<<" "<<bitset<5>(A[2])<<endl;
  vector<int> ans(N,0);
  REP(i,N){
    int temp=1;
    lint Y,p;
    if(X[i]=='0'){
      p=C[2];
      Y=A[2];
      Y+=pow2[2][N-i-1];
      Y%=p;
    }else{
      p=C[0];
      if(p==0){
        ans[i]=0;
        continue;
      }
      Y=A[0];
      Y-=pow2[0][N-i-1];
      Y%=p;
      if(Y<0)Y+=p;
    }
    // cerr<<bitset<5>(Y)<<" "<<p<<endl;
    while(Y>0){
      lint YC=Y;
      p=0;
      while(YC>0){
        p+=YC%2;
        YC/=2;
      }
      Y%=p;
      temp++;
    }
    ans[i]=temp;
  }
  for(auto e:ans)cout<<e<<endl;
  return 0;
}


Measured memory_bytes: 9092
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define DEBUG(x) cout<<#x<<"="<<x<<endl
#define DEBUG2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
typedef long long ll;
class Solver{
public:
    static const int MAXN=1e5+10;
    int N,M;
    int A[MAXN];
    int B[MAXN];
    int fa[MAXN];
    ll cnt[MAXN];
    ll ans[MAXN];
    void initFa(){
        for(int u=0;u<MAXN;u++){
            fa[u]=u;
            cnt[u]=1;
        }
    }
    int sfind(int root){
        if(fa[root]==root)return fa[root];
        int x=sfind(fa[root]);
        fa[root]=x;
        return x;
    }
    void solve(){
        ios::sync_with_stdio(false);
        initFa();
        cin.tie(0);
        cin>>N>>M;
        for(int u=1;u<=M;u++){
            cin>>A[u]>>B[u];
        }
        ll tot=(ll)N*(N-1)/2,acc=0;
        for(int u=M;u>=1;u--){
            ans[u]=tot-acc;
            int ra=sfind(A[u]),rb=sfind(B[u]);
            if(ra==rb)continue;
            acc+=cnt[ra]*cnt[rb];
            fa[rb]=ra;
            cnt[ra]+=cnt[rb];
        }
        for(int u=1;u<=M;u++)cout<<ans[u]<<"\n";
    }
};
int main()
{
    // freopen("in.txt","r",stdin);
    (new Solver())->solve();
}

Measured memory_bytes: 4096
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.List ((\\))

main :: IO ()
main = do
  (a : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  (b : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  print . head . (\\ [a, b]) $ [1, 2, 3]

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


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

#define f first
#define s second
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;

const int N = (int)2e5 + 123, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18;

int main()
{
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < m; j++){
			cout << ((i < b) ^ (j < a));	
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    long m,n,sum;
    while(~scanf("%ld %ld",&m,&n)){
        sum=0;
        if(m==1||n==1){
            sum=1;
        }
        else{
            if(m%2==0){
            sum=m/2*n;
        }
        else{
            if(n%2==0){
                sum=((m/2)*2+1)*n/2;
            }
            else
                sum=((m/2)*2+1)*(n-1)/2+m/2+1;
        }
        }
        printf("%ld\n",sum);
    }
    return 0;
}


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

const long long MOD = 1e9 + 7;
long long dp[10001][100][2][2];
vector<int> dig;
long long d;

long long rec(int pos, int rem, int st, int f) {
    if (pos == -1) {
        if (rem == 0 && st)
            return 1;
        else
            return 0;
    }
    long long &res = dp[pos][rem][st][f];
    if (res != -1)
        return res;
    int lmt = f ? 9 : dig[pos];
    long long ans = 0;
    for (int i = 0; i <= lmt; i++) {
        int nf = f | (i < lmt);
        int nst = st | (i > 0);
        ans += rec(pos - 1, (rem + i) % d, nst, nf);
        if (ans > MOD)
            ans -= MOD;
    }
    return res = ans;
}

void solve() {
    memset(dp, -1, sizeof(dp));
    string s;
    cin >> s >> d;
    int n = s.size();
    dig = vector<int> (n);
    for (int i = 0; i < n; i++) {
        dig[n - 1 - i] = s[i] - '0';
    }
    cout << rec(n - 1, 0, 0, 0);
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;

typedef long long ll;
const ll INF = 1LL << 60;

ll N;
vector<ll> X;

int main() {
    cin >> N;
    X.resize(N);
    rep(i, N) {
        cin >> X[i];
    }

    ll ans = INF;
    for (int i = 1; i <= 100; i++) {
        ll tmp = 0;
        rep(j, N) {
            tmp += (X[j] - i) * (X[j] - i); 
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>prime_factorize(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  deque<int>k;
  for(int i=0;i<n;i++){
    if(i%2==0){k.push_back(a[i]);}
    else{k.push_front(a[i]);}
  }
  if(n%2!=0){reverse(k.begin(),k.end());}
  for(int i=0;i<n;i++){
    cout<<k[i];
    if(i<n-1){cout<<" ";}
  }
  cout<<endl;

  return 0;
}

Measured memory_bytes: 4716
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mode        998244353
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define mset(x)     memset(x,0,sizeof x)
#define pi          3.14159265358979323

ll dp[404][404], a[404], sum[404];

ll f(ll l, ll r)
{
       if(l==r) return 0;
       ll &ans = dp[l][r];
       if(ans!=-1) return ans;
       ans = inf;
       ll s = sum[r] - sum[l-1];
       rep(i, l, r)
              ans = min(ans, f(l, i)+f(i+1, r)+ s);
       return ans;
}

void solve()
{
       ll n;
       cin>>n;
       rep(i,1,n+1) cin>>a[i];
       sum[0]=0;
       rep(i,1,n+1) sum[i] = sum[i-1]+a[i];
       memset(dp, -1, sizeof dp);
       cout<<f(1, n);
}

int main() {
	ll T = 1;
	speed_up
	//cin>>T;
	while(T--)
	    solve();
	return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
bool comp(const pair<string,ll> &a,const pair<string, ll> &b)
{
   return a.second>b.second;
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n;
    cin>>n;
    map <string, int> m;
    for(ll i=0; i<n;i++)
    {
        string s;
        cin>>s;
        m[s]++;
    }
    vector<pair<string, int>> v;
   for(auto it= m.begin();it!=m.end();it++)
       v.push_back(make_pair(it->first, it->second));
   sort(v.begin(),v.end(),comp);
   set<string> p;
   for(ll i=0;i<v.size();i++)
   {
       if(v[i].second==v[0].second)
        p.insert(v[i].first);
       //cout<<v[i].first<<" "<<v[i].second<<endl;
   }
   for(auto it=p.begin();it!=p.end();it++)
    cout<<*it<<endl;
    return 0;
}

Measured memory_bytes: 37484
#include<stdio.h>
#define MAX 500000
int sort_num=0;
void Marge(int * ,int,int,int);
void MargeSort(int * ,int,int);
int main()
{
  int n,S[MAX],N[MAX];
  int i;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&S[i]);
      //printf("%d\n",S[i]);
    }
  MargeSort(S,0,n);
  for(i=0;i<n;i++)
    {
      if(i!=n-1) printf("%d ",S[i]);
      else printf("%d\n",S[i]);
    }
  printf("%d\n",sort_num);
  return 0;
}

void Marge(int *S,int left,int mid ,int right)
{
  int i,j,k;
  int  n1 = mid-left;
  int  n2 = right-mid;
  int L[n1+1],R[n2+1];
  for(i=0;i<n1;i++)
    {
      L[i]=S[left+i];
    }
  for(i=0;i<n2;i++)
    {
      R[i]=S[mid+i];
    }
  i=0;
  j=0;
  L[n1]=-1;
  R[n2]=-1;
  for(k=left;k<right;k++)
    {
      sort_num++;
      if(R[j]==-1)
	{
	  S[k]=L[i];
	  i++;
	  continue;
	}
      if(L[i]==-1)
	{
	  S[k]=R[j];
	  j++;
	  continue;
	}
      if(L[i]<=R[j])
	{
	  S[k]=L[i];
	  i++;
	}
      else
	{
	  S[k]=R[j];
	  j++;
	}
    }
}

void MargeSort(int *S,int left,int right)
{
  int mid;
  if(left+1<right)
    {
      mid=(left+right)/2;
      MargeSort(S,left,mid);
      MargeSort(S,mid,right);
      Marge(S,left,mid,right);
    }
}

Measured memory_bytes: 4504
#include <iostream>
#define N 100
using namespace std;

int main()
{
    int n,a[N],key,i,k;
    cin >> n;
    for( i=0; i<n ; i++)
    {
        cin >> a[i];
    }
    for(i=0; i<n ; i++)
    {
        key = a[i];
        int j = i-1;
        while(a[j]>key && j>=0)
        {
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = key;
        for( k=0; k<n-1 ; k++)
            cout << a[k] << " ";
        cout << a[k] << endl;
    }
    return 0;
}



Measured memory_bytes: 3084
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {
	n := nextInt()

	m := make(map[int]bool)
	for i := 0; i < n; i++ {
		a := nextInt()
		if m[a] {
			m[a] = false
		} else {
			m[a] = true
		}
	}

	var cnt int
	for _, a := range m {
		if a {
			cnt++
		}
	}

	fmt.Println(cnt)
}


Measured memory_bytes: 5504
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int n;
    scanf("%d",&n);
    double ans = 0;
    for (int i = 0; i < n; i++) {
        int tmp;
        scanf("%d",&tmp);
        ans += (double)1 / tmp;
    }
    ans = (double)1/ ans;
    printf("%lf",ans);
}

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

typedef pair<int, int> PII;

int main(void){
  int N, T;
  cin >>N>>T;
  vector<PII> ct(N);
  int i, tmpc, tmpt;
  for (i=0;i<N;i++){
    cin >>tmpc>>tmpt;
    ct[i]=make_pair(tmpc, tmpt);
  }

  sort(
    ct.begin(),
    ct.end(),
    [](const PII& x, const PII& y){return x.second < y.second;} // ラムダ式
  );

  int ans=1001;
  for (i=0; i<N; i++){
    if (ct[i].second<=T && ans>=ct[i].first)
      ans=ct[i].first;
  }
  if (ans==1001){
    cout<<"TLE";
    exit(0);
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(void)
{
  int N;
  int A[20], B[20], C[20];
  int sat, prev;

  scanf("%d",&N);
  rep(i,N) scanf("%d",&A[i]);
  rep(i,N) scanf("%d",&B[i]);
  rep(i,N) scanf("%d",&C[i]);
  
  sat = 0;
  prev = -1;
  rep(i,N){
    sat += B[A[i]-1];
    if(A[i]-prev==1) sat += C[prev-1];
    prev = A[i];
  }
  
  printf("%d\n",sat);
  return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <sstream>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cmath>
 
using namespace std;

int main()
{
	string S;
	cin>>S;
	int year;
	int month;
	int day;
	bool heisei = true;
	year = stoi(S.substr(0,4));
	month = stoi(S.substr(5,2));
	day = stoi(S.substr(8,2));
	if(year < 2019){
		heisei = true;
	}else if(year > 2019){
		heisei = false;
	}else if(year == 2019){
		if(month < 4){
			heisei = true;
		}else if(month > 4){
			heisei = false;
		}else if(month == 4){
			heisei = true;
		}
	}
	cout<<(heisei ? "Heisei" : "TBD")<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<set<string>> v(100010);
    for (int i = 0; i < n; ++i) {
        string c; int d;
        cin >> c >> d;
        v[d-1].insert(c);
    }
    int cur = 0;
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
        string s;
        cin >> s;
        while(cur < 100005 && !v[cur].count(s)) cur++;
        if(cur == 100005) {
            puts("No");
            return 0;
        }
        cur++;
    }
    puts("Yes");
    return 0;
}


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

int main() {
  string o,e;
  cin >> o >> e;
  for(int i=0; i<o.length()+e.length(); i++) {
    if(i%2==0) {
      cout << o[i/2];
    }
    else {
      cout << e[i/2];
    }
  }
}


Measured memory_bytes: 256
c = []
c.append([int(i) for i in input().split()])
c.append([int(i) for i in input().split()])
c.append([int(i) for i in input().split()])

for i in range(2):
  c0 = c[0][i] - c[0][i + 1]
  c1 = c[1][i] - c[1][i + 1]
  c2 = c[2][i] - c[2][i + 1]
  if not (c0 == c1 == c2):
    print("No")
    exit(0)


for i in range(2):
  r0 = c[i][0] - c[i + 1][0]
  r1 = c[i][1] - c[i + 1][1]
  r2 = c[i][2] - c[i + 1][2]
  if not (c0 == c1 == c2):
    print("No")
    exit(0)

print("Yes")



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

#define int long long
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

signed main(){
	int a, b, c;
	cin >> a >> b >> c;
	int k;
	cin >> k;

	int cnt = 0;
	while(a >= b){
		cnt++;
		b *= 2; 
	}

	while(b >= c){
		cnt++;
		c *= 2;
	}
	cout << (cnt <= k ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
int main(){
  
 string s; cin >> s;
	if (s == "SSS") cout << 0 << endl;
	if (s == "SSR") cout << 1 << endl;
	if (s == "SRS") cout << 1 << endl;
	if (s == "SRR") cout << 2 << endl;
	if (s == "RSS") cout << 1 << endl;
	if (s == "RSR") cout << 1 << endl;
	if (s == "RRS") cout << 2 << endl;
	if (s == "RRR") cout << 3 << endl;
  
  return 0;
  
}
  

Measured memory_bytes: 3636
#include<iostream>
#include<vector>
using namespace std;
const long long M=998244353;
	vector<int> fakt(1000000);
int pomnozi(int a,int b){
	return ((long long) a*b) %M;
}
int zbroji(int a,int b){
	a+=b;
	if(a>=M) a-=M;
	return a;
}
int potenciraj(int a,int b){
	int r=1;
	while(b){
		if(b%2==1){
			r=pomnozi(r,a);
		}
		b/=2;
		a=pomnozi(a,a);
	}
	return r;
	
}
int povrh(int n,int k){
	int sol;
	sol=pomnozi(fakt[n], potenciraj(pomnozi(fakt[k], fakt[n - k]), M-2));
	return sol;
}
int main(){
	int n;
	long long k,a,b;
	cin>>n>>a>>b>>k;

	fakt[0]=1;
	for(int i=1;i<n+1;i++){
		fakt[i]=pomnozi(fakt[i-1],i);
	}
	int nacini=0;
	for(int i=0;i<=n;i++){
		long long temp= a*i;
		if((temp>k)) break;
		if((k-temp)%b)continue;
		long long j=(k-temp)/b;
		if (j>n) continue;
		nacini=zbroji(nacini,(pomnozi(povrh(n,i),povrh(n,j))));
	}
	cout<<nacini;
}

Measured memory_bytes: 4096
N = int(input())
a = list(map(int,input().split()))
b = [0]*N
if N % 2 == 0:
  for i in range(N):
    if (i+1) %2 == 1:
      b[N//2+(i+1)//2] = a[i]
    else:
      b[N//2-(i+1)//2] = a[i]
else:
  for i in range(N):
    if (i+1) %2 == 1:
      b[(N-1)//2-(i+1)//2] = a[i]
    else:
      b[(N-1)//2+(i+1)//2] = a[i]
print(' '.join(map(str,b)))

Measured memory_bytes: 29892
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x, y) (lower_bound(vec.begin(), vec.end(), make_pair(x, y)) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>

const int N = 2e5 + 7;

map <int, int> mp;
vector <int> ad[N];
int dif[N], m;
int n, a[N], b[N];
int com;
bool mrk[N];

void dfs(int v) {
	mrk[v] = 1;
	for (auto u: ad[v])
		if (!mrk[u])
			dfs(u);
}
int cnt[N];
int main() {
	makefast;
	cin >> n;
	int x = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		x ^= a[i];
	}
	int res = 0;
	for (int i = 1; i <= n; i++) {
		cin >> b[i];
		if (!mp[b[i]]) {
			m++;
			mp[b[i]] = m;
		}
		if (!mp[a[i]]) {
			m++;
			mp[a[i]] = m;
		}
		a[i] = mp[a[i]];
		b[i] = mp[b[i]];
		cnt[a[i]]++;
		cnt[b[i]]--;
		if (a[i] != b[i]) {
			res++;
			dif[b[i]]++;
			dif[a[i]]--;
			ad[b[i]].push_back(a[i]);
			ad[a[i]].push_back(b[i]);
		}
	}
	if (res == 0) {
		cout << 0;
		return 0;
	}
	if (!mp[x]) {
		m++;
		mp[x] = m;
	}
	x = mp[x];
	cnt[x]++;
	int d = 0;
	for (int i = 1; i <= m; i++) {
		if (dif[i] > 0)
			d = 1;
		if (cnt[i] < 0) {
			cout << -1;
			return 0;	
		}
		if (!mrk[i] && (ad[i].size() || x == i)) {
			dfs(i);
			com++;
		}
	}
	if (!d) {
		cout << res + com - 1;
	}
	else {
		if (dif[x] > 0) {
			cout << res + com - 1;
		}
	}
}


Measured memory_bytes: 20780
def resolve():
    '''
    code here
    '''

    N, M = [int(item) for item in input().split()]
    res_dict = {0:0, 1:0, 2:0, 3:0, 5:0, 8:0}

    if N > M:
        N, M = M, N
    
    if N == 1:
        if M >= 2:
            res_dict[1] = 2
            res_dict[2] = M -2
        else:
            res_dict[0] = 1
    else:
        res_dict[3] = 4
        res_dict[5] = 2* (N - 2 + M - 2)
        res_dict[8] = M*N - (2*(N+M) -4)
    
    # print(res_dict)
    cnt = 0
    for i, v in res_dict.items():
        if i % 2 == 0:
            cnt += v

    print(cnt)            


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
#define rep(i,a,b) for (int i=(a);i<(b);i++)
#define rev(i,a,b) for (int i=(a)-1;i>=b;i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef queue<int> qi;
typedef vector<int> vi;
typedef vector<string> vs;
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };

int main() {

	while(true) {
		int h, w;
		cin >> w >> h;
		if(!(h||w)) break;

		char m[51][51];
		rep(i,0,h) rep(j,0,w) cin >> m[i][j];

		bool B[50][50], W[50][50];
		rep(i,0,h) rep(j,0,w) B[i][j] = W[i][j] = false;

		rep(y,0,h) {
			rep(x,0,w) {
				if(m[y][x] == '.') continue;

				bool m2[h][w];
				rep(i,0,h) rep(j,0,w) m2[i][j] = false;

				queue<pii> que;
				que.push(pii(y,x));
				m2[y][x] = true;
				while(!que.empty()) {
					pii tmp = que.front();
					que.pop();
					int ny = tmp.first;
					int nx = tmp.second;
					rep(i,0,4) {
						int my = ny + dy[i];
						int mx = nx + dx[i];
						if(0 <= my && my < h && 0 <= mx && mx < w && !m2[my][mx] &&
							 m[my][mx] == '.') {
							que.push(pii(my, mx));
							m2[my][mx] = true;
							if(m[y][x] == 'B') B[my][mx] = true;
							else if(m[y][x] == 'W') W[my][mx] = true;
						}
					}
				}

			}
		}

		int ans1 = 0, ans2 = 0;
		rep(i,0,h) rep(j,0,w) {
			if(B[i][j] && !W[i][j]) ans1++;
			else if(!B[i][j] && W[i][j]) ans2++;
		}

		cout << ans1 << " " << ans2 << endl;
	}
	return 0;
}

Measured memory_bytes: 1228