akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <queue>
#include <sstream>
using namespace std;
int main(void){
	int n;
	while(cin >> n){
		if(n == 0)break;
		string L, S;
		for(int i = 0; i < n; i++){
			char a, b;
			cin >> a;
			cin >> b;
			L.push_back(a);
			S.push_back(b);
		}
		int m;
		cin >> m;
		int j;
		for(int i = 0; i < m; i++){
			int cnt = 0;
			char c;
			cin >> c;
			for(j = 0; j < n; j++){
				if(c == L[j]){
					cout << S[j];
					cnt++;
					break;
				}
			}
			if(cnt == 0)cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 1196
n=int(input())

no_tax=[[i,int(i*1.08)] for i in range(1,50001)]

ans=False
for g in range(len(no_tax)):
    if n==no_tax[g][1]:
        ans=True
        break

if ans:
    print(no_tax[g][0])
else:
    print(":(")

Measured memory_bytes: 11252
#include<bits/stdc++.h>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }


int main() {
	
	int n,wt;
	cin >> n >> wt;
	vector<int>v(n+1),w(n+1);
	vector<vector<int>> dp(n+1,vector<int>(wt+1));
	for(int i=1; i<=n; i++) cin >> v.at(i) >> w.at(i);
	for(int i=1; i<=n; i++){
		dp.at(i) = dp.at(i-1); 
		for(int j=0; j<=wt; j++){
			int cnt{1};
			while(1){
				if(j+w.at(i)*cnt>wt) break;
				if(!chmax( dp.at(i).at(j+w.at(i)*cnt), dp.at(i).at(j) + v.at(i)*cnt ))break; 
				cnt++;
			}
		}
	}
	cout << dp.at(n).at(wt) << endl;
}


Measured memory_bytes: 6848
#include <cstring>
#include <cstdio>
int lst[400005], to[800005], pre[800005], tot;
int seq[400005], cnta[400005], cntb[400005], ans[400005], cnt;
bool del[400005];
inline void add_edge(int u, int v)
{
	to[tot] = v;
	pre[tot] = lst[u];
	lst[u] = tot++;
}
void work(int u)
{
	while (true)
	{
		int i = lst[u];
		if (i == -1)
			break;
		lst[u] = pre[i];
		if (!del[i >> 1])
		{
			del[i >> 1] = true;
			work(to[i]);
			seq[cnt++] = i;
		}
	}
}
int main()
{
	// freopen("AGC018-F.in", "r", stdin);
	memset(lst, -1, sizeof(lst));
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		if (x == -1)
		{
			add_edge(n << 1, i);
			add_edge(i, n << 1);
		}
		else
		{
			cnta[--x] ^= 1;
			add_edge(x, i);
			add_edge(i, x);
		}
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		if (x == -1)
		{
			add_edge(n << 1, i + n);
			add_edge(i + n, n << 1);
		}
		else
		{
			cntb[--x] ^= 1;
			add_edge(x + n, i + n);
			add_edge(i + n, x + n);
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (cnta[i] ^ cntb[i])
		{
			puts("IMPOSSIBLE");
			return 0;
		}
	}
	for (int i = 0; i < n; i++)
	{
		if (cnta[i] ^ 1)
		{
			add_edge(i, i + n);
			add_edge(i + n, i);
		}
	}
	work(0);
	for (int i = 0; i < cnt; i++)
	{
		int u = to[seq[i] ^ 1], v = to[seq[i]];
		if (u < n && n <= v && v < n << 1)
			ans[u] = 1;
		if (v < n && n <= u && u < n << 1)
			ans[v] = -1;
	}
	puts("POSSIBLE");
	for (int i = 0; i < n; i++)
		printf("%d%c", ans[i], " \n"[i + 1 == n]);
	return 0;
}


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

int num[4];

int main(){
    int cnt=0;
    for(int i=1;i<=3;i++) cin>>num[i];
    sort(num+1,num+1+3);
    if((num[3]-num[2])%2==0){
        cnt=cnt+(num[3]-num[2])/2;
        num[2]=num[3];
    }
    else{
        cnt=cnt+(num[3]-num[2])/2;
        num[2]=num[3]-1;
    }

    if((num[3]-num[1])%2==0){
        cnt=cnt+(num[3]-num[1])/2;
        num[1]=num[3];
    }
    else{
        cnt=cnt+(num[3]-num[1])/2;
        num[1]=num[3]-1;
    }
    //cout<<num[1]<<" "<<num[2]<<" "<<num[3]<<endl;
    if((num[2]==num[3]-1)&&(num[1]==num[3]-1)) cout<<cnt+1<<endl;
    else if(num[2]==num[3]&&num[1]==num[3]) cout<<cnt<<endl;
    else cout<<cnt+2<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

fn main() {
    let s = parse_line::<String>();

    let passed_days = s.len();
    let wins = s.chars().into_iter().fold(0, |acc, c| if c =='o' { acc + 1 } else { acc });

    println!("{}", if (8 - wins) <= (15 - passed_days) { "YES" } else { "NO"} );
}


Measured memory_bytes: 4352
#include <iostream>
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
 
int main() {
    int n;
    int a[100100];
    int m4,m2;
    int ck4;
    m4 = 0;
    m2 = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) {
      cin >> a[i];
    }
    
    for (int i = 0; i < n ; ++i){
      if (a[i] % 4 == 0) {
          m4 = m4 + 1;
        }
      else if(a[i] % 2 == 0){
          m2 = m2 + 1;
        }
    }
  
    ck4 = n / 2;
    bool p,q;
    p = m4 >= ck4;
    q = n - 2 * m4 <= m2; 
  
    if(p){
      cout << "Yes" << endl;
      return 0;
      }
    else if(q){
      cout << "Yes" << endl;
      return 0;
    }
      
    cout << "No" << endl;
  
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		char []s = sc.next().toCharArray();
		String t = sc.next();
		
		int n = s.length;
		int m = t.length();
		boolean jdg = false;
		
		if(n < m) {
			System.out.println("UNRESTORABLE");
			return;
		}
		
		int num = -1;
		
		for(int i = n-1 ;i >= m-1 ;i--) {
			if(t.charAt(m-1) == s[i] || s[i] == '?') {
				int j = 0;
				while(j <= m-1) {
					if(s[i-j] != t.charAt(m-j-1) && s[i-j] != '?') {
						break;
					}
					j++;
				}
				if(j == m) {
					num = i - j + 1;
					jdg = true;
					break;
				}
				num = -1;
			}
	}
		int cnt = 0;
		
		for(int i = 0 ;i < n ;i++) {
			if(num > i || cnt == m) {
				if(s[i] == '?') {
					s[i] = 'a';
				}
			}
			else {
				s[i] = t.charAt(cnt);
				cnt++;
			}
		}
		
		String ans = String.valueOf(s);
		
		if(!jdg) {
			System.out.println("UNRESTORABLE");
			return;
		}
			System.out.println(ans);
		}
	}



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

int main()
{
	int n;
	cin>>n;
	int a[n],b[n],c[n],A[n],B[n],C[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		cin>>b[i];
		cin>>c[i];
	}
	A[0]=a[0];B[0]=b[0];C[0]=c[0];
	for(int i=1;i<n;i++)
	{
		A[i]=max(B[i-1],C[i-1])+a[i];
		B[i]=max(A[i-1],C[i-1])+b[i];
		C[i]=max(A[i-1],B[i-1])+c[i];
	}
	cout<<max(max(A[n-1],B[n-1]),C[n-1]);
	return 0;
}


Measured memory_bytes: 2560
import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))

for i in range(n):
    a[i]*=-1
    
heapq.heapify(a)
#print(a)

for i in range(m):  
    t=heapq.heappop(a)
    t*=-1
    t//=2
    t*=-1
    heapq.heappush(a,t)
    
ans=0
for i in range(n):
    ans-=a[i]
print(ans)

Measured memory_bytes: 14180
#include<iostream>
using namespace std;
int main(){
	int i=0,count=0,number[100];
	cin>>i;
	for(;count<i;count++){
		cin>>number[count];
	}
	for(;count>0;count--){
		cout<<number[count-1];
		if(count==1){break;}
		cout<<' ';
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1160
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var S = Console.ReadLine();
        var first = int.Parse(S.Substring(0, 2));
        var second = int.Parse(S.Substring(2, 2));

        bool isYymm = false;
        if (0 <= first && 1 <= second && second <= 12)
        {
            isYymm = true;
        }

        bool isMmyy = false;
        if (0 <= second && 1 <= first && first <= 12)
        {
            isMmyy = true;
        }

        string ans;
        if (isYymm && isMmyy)
        {
            ans = "AMBIGUOUS";
        }
        else if (isYymm)
        {
            ans = "YYMM";
        }
        else if (isMmyy)
        {
            ans = "MMYY";
        }
        else
        {
            ans = "NA";
        }

        Console.WriteLine(ans);
    }


}



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

int main() {
    string s;
    cin>>s;
    bool flag = false;
    int l=s.length();
    int i=0;
    while(i!=(l-1))
    {
        if(s[i]==s[i+1])
            flag=true;
        i++;
    }
    if(flag)
        cout<<"Bad";
    else
        cout<<"Good";
    	return 0;
}

Measured memory_bytes: 256
MX = 10**18
def fun(a,n):
	if max(a) > MX:
		return -1
	if 0 in a:
		return 0
	res = a[0]
	for i in range(1,n):
		res = res * a[i]
		if res > MX:
			return -1
	return res

n = int(input())
a = list(map(int,input().split()))
print(fun(a,n))

Measured memory_bytes: 21784
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int MOD = 1000000007;
int INF = numeric_limits<int>::max() / 2;


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

  int N;
  cin >> N;
  int ans = N/11*2;
  if(N%11 == 0) cout << ans << endl;
  else if(N%11 < 7){
    cout << ans+1 << endl;
  }
  else{
    cout << ans+2 << endl;
  }

}

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

int main() {
  int n; cin>>n;
  double sum=0;
  for (int i=0; i<n; i++){
    int a; cin>>a;
    sum+=1.0/a;
  }
  cout<<fixed<<setprecision(10);
  cout<<1.0/sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize(1,2,3,"Ofast","Os","inline")
#define rnt register int
using namespace std;
int a[2000011];
int n;
inline bool small(int i,int j,int k){return a[i]<=k&&a[j]<=k;}
inline bool big(int i,int j,int k){return a[i]>k&&a[j]>k;}
inline bool check(int x)
{
	for(rnt i=0;i<n-1;++i)
	{
		if(big(n+i,n+i+1,x)||big(n-i,n-i-1,x))return false;
		if(small(n+i,n+i+1,x)||small(n-i,n-i-1,x))return true;
	}
	return small(1,1,x);
}
int main()
{
	scanf("%d",&n);
	for(rnt i=1;i<=2*n-1;++i)scanf("%d",&a[i]);
	int l=1,r=2*n-1,mid;
	while(l<r)
	{
		mid=l+r>>1;
		if(check(mid)==true)r=mid;
		else l=mid+1;
	}
	printf("%d\n",r);
	return 0;
}

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

int main() {

	string S;
	int N;
	int K;
	cin >> N >> K;
	cin >> S;


	if (S.at(K - 1) == 'A') {
		S.at(K - 1) = 'a';
	}
	if (S.at(K - 1) == 'B') {
		S.at(K - 1) = 'b';
	}
	if (S
		.at(K - 1) == 'C') {
		S.at(K - 1) = 'c';
	}

	cout << S << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	char arr[101][101];
	for(int i=1;i<=a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			cin>>arr[i][j];
		}
	}
	for(int i=1;i<=2*a;i++)
	{
		for(int j=1;j<=b;j++)
		{
			cout<<arr[(int)(i+1)/2][j];
		}
		cout<<endl;
	}
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[3];
int main(){
	char c;
	for(int i=0;i<3;i++){
		cin>>c;
		a[c-'a']++;
	}
	bool pd=true;
	for(int i=0;i<3;i++){
		if(a[i]==0){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E17;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
///////////////////////////////////////

ll c=0,d=0;
void yes(){
    cout<<"Yes"<<endl;
}
void no(){
    cout<<"No"<<endl;
}

int main(){fastio
    ll n,a,b;cin>>n>>a>>b;
    string s;cin>>s;
    rep(i,0,n-1){
        if(s[i]=='a'){
            if(c<a+b){
                c++;
                yes();
            }else{
                no();
            }
        }else if(s[i]=='b'){
            if(c<a+b&&d<b){
                c++;d++;
                yes();
            }else{
                no();
            }
        }else{
            no();
        }
    }
    return 0;
}



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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {set_intersection(ALL(a),ALL(b),inserter(c,c.end()));}
template<class T> void getor(const T &a,const T &b,T &c) {set_union(ALL(a),ALL(b),inserter(c,c.end()));}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;

int main() {
  // 現状存在するトップの数列で、ペアのものを全部選択
  // 全部なくなる前にペアが作れなくなったらアウト
  int N;cin>>N;
  // AS[x][N]は門番の-1を入れる
  vector<deque<int>> AS(N,deque<int>(N,-1));
  REP(i,N)REP(j,N-1) {
    cin>>AS[i][j];
    AS[i][j]--;
  }
 
  int total_buttle_cnt=0;
  int ans = 0;
  set<int> battled_idx;
  // 最初はどれかわからないから
  REP(i,N) battled_idx.insert(i);
  while (total_buttle_cnt<N*(N-1)/2) {
    set<int> next_battled_idx;
 
    for (int i:battled_idx) {
      // すでに試合が決まっているか、もうできる試合がない場合
      if (next_battled_idx.find(i)!=next_battled_idx.end() || AS[i].front()==-1) continue;
      int other = AS[i].front();
      // 試合ができるなら
      if (AS[other].front()==i) {
        next_battled_idx.insert(i);
        next_battled_idx.insert(other);
        total_buttle_cnt++;
      }
    }
 
    if (next_battled_idx.empty()) {
      OUT(-1);
      return 0;
    } else {
      for (int i:next_battled_idx) AS[i].pop_front();
    }
    ans++;
    swap(next_battled_idx, battled_idx);
  }
  OUT(ans);
 
  return 0;
}

Measured memory_bytes: 4608
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

a = ri_()
print(min((a[0] % 2) * (a[1] * a[2]), (a[1] % 2) * (a[0] * a[2]), (a[2] % 2) * (a[0] * a[1])))

Measured memory_bytes: 9204
import Data.List

g::Int->Int->Int->Int->Int->Bool
g _ _ _ (-1) _=False
g w h a b c=if w*b+(h-b)*a-b*a==c then True else g w h a (b-1) c

f::Int->Int->Int->Int->Int->Bool
f w h (-1) b c=False
f w h a b c=(g w h a b c)||(f w h (a-1) b c)

main = do
       x<-getLine
       let (h:w:c:[])=map read (words x)::[Int]
       putStrLn $ if f w h w h c then "Yes" else "No"

Measured memory_bytes: 508
#include <bits/stdc++.h>
using namespace std;
struct node
{
    int x,y;
};
stack<node> d;
#define mo 1500
int a[mo][mo];
int main()
{
    int n,m;
    while(cin>>n>>m)
    {
        int x;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cin>>x;
                if(!x)
                    a[i][j]+=a[i-1][j]+1;

            }
        }

        /*
        cout<<endl;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                cout<<a[i][j]<<' ';
            }
            cout<<endl;
        }
        */


        node t;
        int maxs=0;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
            {
                t.x=a[i][j];
                t.y=j;

                if(d.size()==0||t.x>d.top().x) d.push(t);
                else if(t.x<d.top().x)
                {
                    int l=j;
                    while(d.size()&&d.top().x>t.x)
                    {
                        maxs=max(maxs,(l-d.top().y)*d.top().x);
                        t.y=d.top().y;
                        d.pop();
                    }
                    d.push(t);
                }
                //cout<<setw(3)<<maxs<<' ';
            }
            int l=m;
            while(d.size()>0)
            {

                maxs=max(maxs,(l-d.top().y+1)*d.top().x);
               // cout<<d.top().x<<' '<<d.top().y<<' '<<l<<' '<<maxs<<endl;
                d.pop();
            }
            //cout<<endl;

        }
        cout<<maxs<<endl;


    }

}



Measured memory_bytes: 10128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modとる */
inline ll modu(ll a){
    return(a % mod + mod) % mod;
}

/* 逆元(法mod = 1e9+7) */
ll modinv(ll a){
    ll b = mod, u = 1, v = 0;
    while (b){
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
        }
    return modu(u);
}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    REP(i,N)cin >> A[i];
    REP(i,N)B[i] = A[i];
    vector<vector<int>> beki(N,vector<int>(0));
    vector<int> lcm(0);
    REP(l,N){
        REPS(i,1020){
            if(i == 1)continue;
            while(B[l]%i == 0){
                B[l]/= i;
                beki[l].pb(i);
            }
        }
        if(B[l] != 1)beki[l].pb(B[l]);
    }
    vector<int> tmp(0);
    REP(i,N){
        set_union(ALL(beki[i]),ALL(lcm),back_inserter(tmp));
        lcm = move(tmp);
        tmp.clear();
    }
    ll lcmv = 1;
    REP(i,lcm.size()){
        lcmv = modu(lcmv*lcm[i]);
    }
    ll sum = 0;
    REP(i,N){
        sum = modu(sum + lcmv * modinv(A[i]));
    }
    cout << sum << "\n";
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define REPRl(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < (int)n; i++)
#define FORl(i, m, n) for(ll i = m; i < (ll)n; i++)
#define ALL(v) v.begin(), v.end()
ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}

int main() {
  string s;cin>>s;
  set<char> st;
  REP(i,4){
    st.insert(s[i]);
  }
  int ans=st.size();
  cout << (ans==2?"Yes":"No") << endl;
}

Measured memory_bytes: 256
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//素数判定　O(√A) 
bool is_prime(int x){
 if(x<=1) return false;
 for(int i=2;i*i<=x;i++)
 if(x%i==0) return false;
 return true;
 }
//グローバル変数宣言
 ll p=0,q=0,r=0;


int main(){
   ll A,B,M;
   cin>>A>>B>>M;
   vl a(A),b(B),x(M),y(M),c(M);
   rep(i,A)cin>>a[i];
   rep(i,B)cin>>b[i];
   rep(i,M){cin>>x[i]>>y[i]>>c[i];x[i]-=1;y[i]-=1;}
   rep(i,M){p=a[x[i]]+b[y[i]]-c[i];if(i==0)q=p;q=min(p,q);}
   sortp(a);sortp(b);
   print(min(a[0]+b[0],q))
}

Measured memory_bytes: 7228
inf = 1 << 60
n,m = map(int, input().split())
c = list(map(int, input().split()))
dp = [inf] * (n + 1)
dp[0] = 0
for ci in c:
    for i in range(0, n + 1 - ci):
        dp[i + ci] = min(dp[i + ci], dp[i] + 1)
print(dp[n])



Measured memory_bytes: 7516
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
//const int inf = 0x3f3f3f3f;
const ll inf = 1ll << 62;
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define pi 3.14159265358979323846
#define pc putchar
#define gc getchar
#define fi first
#define se second
#define debug(x) cout << #x" = " << x << endl;
//char __wzp[1<<15|1],*__S=__wzp+32768;
//#define gc() (__S>=__wzp+32768?(__wzp[fread(__wzp,sizeof(char),1<<15,stdin)]=EOF),*((__S=__wzp)++):*(__S++))
#define rd read
#define mem(x,v) memset(x,v,sizeof(x))
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-(x)))
inline ll read(){
    register ll x=0,f=1;register char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
void writeln(ll x){write(x);puts("");}
const int mod = 1e9+7;
int n,k,top,q[233333],sum[233333];
inline int qpow(int a,int b){
	int ans = 1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1) ans=1ll*ans*a%mod;
	return ans;
}
int main(){
	n = rd(),k = rd();
	for(int i=1;i*i<=n;++i){
		if(!(n%i)){
			q[++top] = i;
			if(n != i*i) q[++top] = n / i;
		}
	}sort(q+1,q+1+top);
	Rep(i,1,top) sum[i] = qpow(k,(q[i]+1)>>1);
	int ans = 0;
	Rep(i,1,top){
		rep(j,1,i)if(!(q[i]%q[j])) sum[i]=(sum[i]-sum[j]+mod)%mod;
		ans = (ans + 1ll * sum[i]*((q[i]&1)?q[i]:(q[i]>>1)) % mod) %mod;
	}writeln((ans+mod)%mod);
	return 0;
}

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

using i64 = int64_t;

int main(){
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3])cout << "Bad";
    else cout << "Good";
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for((i)=1;(i)<=(n);(i)++)
using namespace std;
int n,m,i,j,a[3005],b[3005],c1,c2,id[6005],nxt[6005];
string st,f[3005];
int main(){
	cin>>n>>st;
	st=" "+st;
	rep(i,n+n){
		if(st[i]=='a'){
			a[++c1]=i;
			id[i]=c1;
		}
		else{
			b[++c2]=i;
			id[i]=c2;
		}
	}
	j=0;
	a[n+1]=b[n+1]=n+n+1;
	id[n+n+1]=n+1;
	rep(i,n+1){
		while(j<min(a[i],b[i])){
			nxt[++j]=i;
		}
	}
	for(i=n;i;i--){
		if(a[i]<b[i]){
			f[i]="ab"+f[nxt[b[i]+1]];
		}
		else{
			int j=b[i];
			f[i]="";
			while(b[id[j]]<a[id[j]]&&(id[j]<=i||b[id[j]]<a[id[j]-1])){
				if(id[j]>=i) f[i]+=st[j];
				j++;
			}
			f[i]+=f[id[j]];
		}
		f[i]=max(f[i],f[i+1]);
//		cerr<<f[i]<<endl;
	}
	cout<<f[1]<<endl;
	return 0;
}

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

int main() {
    long long h, w;
    cin >> h >> w;

    if ((h * w) % 3 == 0) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 10'000'000'000ll;
    for (int i = 1; i < h; i++) {
        long long a = i * w;
        long long b = (h - i) * (w / 2);
        long long c = (h - i) * (w - w / 2);
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
        
        b = w * ((h - i) / 2);
        c = w * ((h - i) - (h - i) / 2);
        if (b == 0 || c == 0) continue;
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }
    
    for (int i = 1; i < w; i++) {
        long long a = i * h;
        long long b = (w - i) * (h / 2);
        long long c = (w - i) * (h - h / 2);
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
        
        b = h * ((w - i) / 2);
        c = h * ((w - i) - (w - i) / 2);
        if (b == 0 || c == 0) continue;
        ans = min(ans, max(a, max(b, c)) - min(a, min(b, c)));
    }
    cout << ans << endl;
}   

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

int main(void) {
  string s; cin >> s;
  int n = s.length();
  
  int t, m = 1000;
  for (int i=0; i<(n-2); i++) {
    t = stoi(s.substr(i, 3));
    if (abs(753 - t) < m) m = abs(753 - t);
  }
  cout << m << endl;
  return 0;
}

Measured memory_bytes: 3536
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <iomanip>
#include <cassert>
using namespace std;

struct wrect{
    int h;
    int w;
    int diag;
    wrect(){}
    ~wrect(){}
    wrect(int a, int b): h(a), w(b){
        diag = h * h + w * w;
    }
    bool operator < (const wrect& r) const {
        return diag == r.diag ? h < r.h : diag < r.diag;
    }
};

int main(){
    vector<wrect> rv;
    for(int w = 1; w <= 150; w++){
        for(int h = 1; h < w; h++){
            rv.push_back(wrect(h, w));
        }
    }
    sort(rv.begin(), rv.end());
    while(true){
        int h, w;
        scanf("%d%d", &h, &w);
        if(h == 0 && w == 0) break;
        vector<wrect>::iterator it = lower_bound(rv.begin(), rv.end(), wrect(h, w));
        ++it;
        printf("%d %d\n", it->h, it->w);
    }
    return 0;
}

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

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

  vector<int> a(N);
  rep(i, N) cin >> a[i];

  sort(a.rbegin(), a.rend());

  int alice = 0, bob = 0;
  rep(i, N) {
    if (i % 2 == 0)
      alice += a[i];
    else
      bob += a[i];
  }

  cout << alice - bob << endl;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H=list(map(int,input().split()))
s=set()
for i in range(M):
  a,b=map(int,input().split())
  a,b=a-1,b-1
  if H[a]>H[b]:
    s.add(b)
  elif H[a]<H[b]:
    s.add(a)
  else:
    s.add(a)
    s.add(b)
print(N-len(s))


Measured memory_bytes: 19932
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  long mini = 1e9;
  rep(i,n) cin >> a.at(i);
  rep(i,600){
    int tmp = i-300;
    long ans = 0;
    rep(j,n){
      ans += pow(tmp-a.at(j),2);
    }
    mini = min(mini,ans);
  }
  cout << mini << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge {
    ll from;
    ll to;
    ll cost;
};

ll V, E, d[1010];
edge es[2010];


bool find_negative_loop() {
    for (ll i = 0; i < V; i++) {
        for (ll j = 0; j < E; j++) {
            edge e = es[j];
            if (d[e.from]!=INF&&d[e.to] > d[e.from] + e.cost) {
                d[e.to] = d[e.from] + e.cost;
                if (e.to== V - 1) {
                    return true;
                }
            }
        }
    }
    return false;
}
void shortest_path(ll s){
  rep(i,V)d[i]=INF;
  d[s]=0;
  rep(j,V){
    bool update=false;
    rep(i,E){
      edge e=es[i];
      if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
        d[e.to]=d[e.from]+e.cost;
        update=true;
      }
    }
    if(!update)break;
    return;
  }
}
int main(){
  cin>>V>>E;
  rep(i,E){
    ll f,t,c;
    cin>>f>>t>>c;
    es[i].from=f-1;
    es[i].to=t-1;
    es[i].cost=-c;
  }
  shortest_path(0);
  if(find_negative_loop()){
    cout<<"inf"<<endl;
    return 0;
  }
  rep(j,V){
        rep(i,E){
            edge e=es[i];
            if(d[e.from]!=INF&&d[e.to]>d[e.from]+e.cost){
                d[e.to]=d[e.from]+e.cost;
                if(e.to==V-1){
                    cout<<"inf"<<endl;
                    return 0;
                }
            }
        }
    }
  //shortest_path(0);
  cout<<-d[V-1]<<endl;
  
}
  


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

int main(){
	int a, b;
  cin>>a>>b;
  if(a%3==0||b%3==0||(a+b)%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.PriorityQueue;
import java.util.Collections;
import java.util.Comparator;

data class position(val x: Int, val y: Int, val z: Int)
data class score(val score: Long, val pos: position) : Comparable<score> {
     override operator fun compareTo(other: score): Int{ return if(score < other.score){1}else if(score == other.score){0}else{-1} }
}

fun main(args : Array<String>) {
    val (xc,yc,zc,k) = readLine()!!.split(" ").map{n->n.toInt()};
    val a = readLine()!!.split(" ").map({n->n.toLong()}).sortedDescending()
    val b = readLine()!!.split(" ").map({n->n.toLong()}).sortedDescending()
    val c = readLine()!!.split(" ").map({n->n.toLong()}).sortedDescending()
    
    
    var pq = PriorityQueue<score>( );
    val hash = hashSetOf<position>()
    
    val push = {x:Int,y:Int,z:Int -> 
        val t = position(x,y,z);
    	if(!hash.contains(t) && a.size > x && b.size > y && c.size > z){
            hash.add(t)
            pq.add(score(a[x] + b[y] + c[z],position(x,y,z)))
        }
    }
    push(0,0,0)
    
    for(i in 0..k-1){
        val r = pq.poll();
        println(r.score);
        push(r.pos.x+1,r.pos.y,r.pos.z);
        push(r.pos.x,r.pos.y+1,r.pos.z);
        push(r.pos.x,r.pos.y,r.pos.z+1);
    }
}

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

g = [[] for _ in range(N)]
for i in range(N - 1):
    u = i
    v = i + 1
    g[u].append(v)
    g[v].append(u)
g[X - 1].append(Y - 1)
g[Y - 1].append(X - 1)

from collections import deque
dis = [[0] * N for _ in range(N)]
def bfs(i):
    visited = [False] * N
    que = deque([i])
    dis[i][i] = 0
    visited[i] = True
    
    while que:
        p = que.popleft()
        for new in g[p]:
            if visited[new]:
                continue
            else:
                visited[new] = True
                que.append(new)
                dis[i][new] = dis[i][p] + 1
                count[dis[i][new] - 1] += 1

count = [0] * (N - 1)
for i in range(N):
    bfs(i)

for i in range(N - 1):
    print(count[i] // 2)

Measured memory_bytes: 78172
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
using namespace std;
int mx4[] = {0,1,0,-1};
int my4[] = {1,0,-1,0};
int INF = 2e6;
 

int main(){
    int n, k, ans = 0;
    cin >> n >> k;
    set<int> d;
    rep(i,k){
        int a; cin >> a;
        d.insert(a);
    }

    for (int ans = n; ans <= 99999; ans++) {
        int x = ans;
        bool ok = true;
        while(x) {
            if(d.count(x % 10)) {
                ok = false;
                break;
            }
            x /= 10;
        }
        if(ok) {
            cout << ans << endl;
            return 0;
        }
    }
}



Measured memory_bytes: 256
n = int(input())
 
nopass = False
for i in range(n) :
    t, x, y = map(int, input().split())
    if (x+y > t) or ((x+y+t)%2 == 1) :
        nopass = True
        break

if nopass :
    print("No")
else :
    print("Yes")

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

int h[100000];
int mem[100000];
long long solve( int i,int n)
{
    if(i == n - 1 )
        return mem[i] = 0;
    else if(i >= n)
        return -1;
    if(mem[i] != -1)
        return mem[i];

    long long p1 = solve(i+1,n), p2 = solve(i+2,n);
    if(p2 == -1)
        return abs(h[i+1] - h[i]) + p1;
    return mem[i] = min(abs(h[i+1]-h[i]) + p1, abs(h[i+2]-h[i]) + p2); 

}
int main()
{
    int n;
    cin >> n;
    memset(mem, -1, sizeof mem);
    for(int i = 0; i < n; i++)
        cin >> h[i];
    cout << solve(0,n);
    return 0;
}

Measured memory_bytes: 5760
program prob2
    implicit none
    character(110) :: a, b
    integer :: i, la, lb
    logical :: ans, decide
    read(*,*) a, b
    la = len_trim(a)
    lb = len_trim(b)
    decide = .false.
    if(la > lb) then
        ans = .true.
        decide = .true.
    else if(la < lb) then
        decide = .true.
        ans = .false.
    else
        do i = 1, la
            if(a(i:i) > b(i:i))then
                decide = .true.
                ans = .true.
                exit
            else if(a(i:i) < b(i:i)) then
                decide = .true.
                ans = .false.
                exit
            else
                cycle
            end if
        end do
    end if

    if(decide .eqv. .false.) then
        write(*,*) 'EQUAL'
    else
        if(ans .eqv. .true.) then
            write(*,*) 'GREATER'
        else
            write(*,*) 'LESS'
        end if
    end if

    stop
contains
end program prob2

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



int main(){
    int N,x;
    cin >> N >> x;
    vector<int> a(N); 
    for(int i=0;i<N;i++) cin >> a.at(i);
    sort(a.begin(),a.end());
 

    int ans = 0;

    //基本的にはあめの要求個数が少ない子供から与える
    for(int i=0;i<N;i++){
        if(x >= a[i]){
            ans++;
            x = x - a[i];
        }
    }

    //あめがあまったとき
    if(ans==N && x>0 ) ans--;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main(){
    int N,i,p,sum=0,mean,ans=0,tmp=0;
    cin >> N;
    vector<int> a(N);
    for(i=0;i<N;i++){
        cin >> p;
        a.at(i) = p;
        sum += p;
    }
    mean = sum / N;
    for(i=0;i<N;i++){
        ans += (a.at(i)-mean)*(a.at(i)-mean);
        tmp += (a.at(i)-mean-1)*(a.at(i)-mean-1);
    }
    if(tmp < ans) ans = tmp;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

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

var N int

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func readKey() [2]int {
	a := readInt()
	b := readInt()
	m := 0
	for i := 0; i < b; i++ {
		m |= 1 << uint(readInt()-1)
	}
	return [2]int{a, m}
}

func readKeys(M int) (result [][2]int) {
	for i := 0; i < M; i++ {
		result = append(result, readKey())
	}
	return
}

func solve(keys [][2]int, amount int, cm int, dp []int) int {
	if cm == (1<<uint(N))-1 {
		return amount
	}
	if len(keys) == 0 {
		return math.MaxInt64
	}
	a := keys[0][0]
	m := keys[0][1]
	if dp[cm|m] < amount+a {
		return solve(keys[1:], amount, cm, dp)
	} else {
		dp[cm|m] = amount + a
		return min(solve(keys[1:], amount+a, cm|m, dp), solve(keys[1:], amount, cm, dp))
	}
}

func main() {
	N = readInt()
	M := readInt()
	keys := readKeys(M)

	dp := make([]int, 1<<uint(N))
	for i := 0; i < 1<<uint(N); i++ {
		dp[i] = math.MaxInt64
	}

	t := solve(keys, 0, 0, dp)
	if t == math.MaxInt64 {
		fmt.Println(-1)
	} else {
		fmt.Println(t)
	}
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


Measured memory_bytes: 1152
import java.util.Scanner;
class Main{
  public static void main (String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    
    if(N==M){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}


Measured memory_bytes: 23636
#include <iostream>
#include <stack>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <cstring>
#include <map> 
#include<set>
#include<queue>
#include <iomanip>

typedef long long ll;

#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1000000000000000;
const ll inf = -1e18;
typedef pair<ll, ll> P;
ll ma = 1000000000 + 7;
ll mx = 1000003;
ll h,n, w,m,t; string s;
ll R, C;
ll sy, sx, gy, gx;
char maze[20][20];
ll dis[20][20];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
ll gcd(ll x, ll y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);
}
ll lcm(ll a,ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
void comb(vector<vector <ll> >& v) {
	for (ll i = 0; i < v.size(); i++) {
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (ll k = 1; k < v.size(); k++) {
		for (int j = 1; j < k; j++) {
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j])%ma;
		}
	}
}

ll GetDigit(ll num) {
	return log10(num) + 1;
}
ll Combination(int n, int r)
{
	if (n - r < r) r = n - r;
	if (r == 0) return 1;
	if (r == 1) return n;

	vector<ll> numerator(r);
	vector<ll> denominator(r);

	for (int k = 0; k < r; k++)
	{
		numerator[k] = n - r + k + 1;
		denominator[k] = k + 1;
	}

	for (int p = 2; p <= r; p++)
	{
		int pivot = denominator[p - 1];
		if (pivot > 1)
		{
			int offset = (n - r) % p;
			for (int k = p - 1; k < r; k += p)
			{
				numerator[k - offset] /= pivot;
				denominator[k] /= pivot;
			}
		}
	}

	ll result = 1;
	for (int k = 0; k < r; k++)
	{
		if (numerator[k] > 1) result *= numerator[k];
		result %= ma;
	}

	return result;
}

ll bfs() {
	queue<P> que;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) dis[i][j] = INF;
	}
	que.push(P(sy - 1, sx - 1));
	dis[sy - 1][sx - 1] = 0;

	while (que.size() > 0) {
		P p = que.front();
		que.pop();
		if (p.first == gy - 1 && p.second == gx - 1) break;
		for (ll i = 0; i < 4; i++) {
			ll ny = p.first + dy[i];
			ll nx = p.second + dx[i];
			if (0 <= ny && ny < R && 0 <= nx && nx < C && maze[ny][nx] == '.' && dis[ny][nx] == INF) {
				que.push(P(ny, nx));
				dis[ny][nx] = dis[p.first][p.second] + 1;
			}
		}
	}
	return dis[gy - 1][gx - 1];
}

int main() {
	ll k;
	cin >> n >> k;
	vector<ll> H(n);
	rep(i, n) {
		cin >> H[i];
	}
	if (n <= k) {
		cout << 0 << endl;
		return 0;
	}
	sort(H.begin(), H.end(), greater<ll>());
	rep(i, k) {
		H[i] = 0;
	}
	ll res = 0;
	rep(i, n) {
		res += H[i];
	}
	cout << res << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

#define MAX_T 30000+1

bool is_prime[MAX_T];
vector<int> prime;
void init() {
    is_prime[0] = is_prime[1] = false;
    memset(is_prime, 1, sizeof(is_prime));
    for (int i = 2; i < MAX_T; i++) {
        if (is_prime[i]) {
            prime.push_back(i);
            for (int j = i+i; j < MAX_T; j+=i) {
                is_prime[j] = false;
            }
        }
    }
}

bool possible_triangle(int a, int b, int c) {
    vector<int> v(3);
    v[0] = a, v[1] = b, v[2] = c;
    sort(v.begin(), v.end());
    return v[0] + v[1] > v[2];
}

int T;

int cnt() {
    int c = 0;
    for (int i = 0; i < prime.size() && prime[i] < T; i++) {
        for (int j = i; j < prime.size() && prime[j] < T; j++) {
            int k = T - prime[i] - prime[j];
            if (prime[j] <= k && is_prime[k] && possible_triangle(prime[i], prime[j], k)) {
                //cout << prime[i] << ' ' << prime[j] << ' ' << T-i-j << endl;
                c++;
            }
        }
    }
    return c;
}

int main() {
    init();
    while (cin >> T, T != 0) {
        cout << cnt() << endl;
    }
    return 0;
}

Measured memory_bytes: 1284
A, B = map(int, input().split())
S = input()

for i in range(len(S)):
    if i+1 <= A and S[i]=='-':
        print('No')
        break
    elif i+1 == A+1 and S[i]!='-':
        print('No')
        break
    elif A+1 < i+1 and i+1 <= A+B+1:
        if S[i]=='-':
            print('No')
            break

else:
    print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
using namespace std;
 
int main() 
{ 
    string S, T; 
    cin >> S >> T; 
    int count=0;
    int len = S.size();
    for (int i = 0; i < len; i++)
    {
        if(S[i]!=T[i]) count++ ;
    }
    
    cout << count << endl;

} 

Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int L[5000];

/*================================================
	Z - algorithm
================================================*/
void Z_algorithm(const string & S, int* A)
{
	A[0] = S.size();
	int i = 1, j = 0;
	while (i < S.size()) {
		while (i + j < S.size() && S[j] == S[i + j]) ++j;
		A[i] = j;
		if (j == 0) { ++i; continue; }
		int k = 1;
		while (i + k < S.size() && k + A[k] < j) A[i + k] = A[k], ++k;
		i += k; j -= k;
	}
}

int main()
{
	int N, len, ans = 0;
	string S;

	cin >> N >> S;
	len = S.length();

	rep(i, N) {
		string sub = S.substr(i, len - i);
		Z_algorithm(sub, L);
		repc(j, 1, len - i - 1) {
			if (L[j] < j + 1) ans = max(ans, L[j]);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Miscalculation - Accepted
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		String exp = br.readLine();
		int ans = parseInt(br.readLine());

		int M, L;
		M = M(exp);
		L = L(exp);

		if (ans == M && ans == L) System.out.println('U');
		else if (ans == M) System.out.println('M');
		else if (ans == L) System.out.println('L');
		else System.out.println('I');
	}

	static int M(String exp) {
		char[] pri = new char[127];
		Arrays.fill(pri, (char) 3);
		pri['*'] = 2;
		pri['+'] = 1;
		pri[0] = 0;
		return eval(exp, pri);
	}

	static int L(String exp) {
		char[] pri = new char[127];
		Arrays.fill(pri, (char) 3);
		pri['*'] = 1;   //change pri
		pri['+'] = 1;
		pri[0] = 0;
		return eval(exp, pri);
	}

	static int eval(String exp, char[] pri) {

		Deque<Character> stack = new ArrayDeque<>();
		String rpn = "";

		stack.push('\0');
		for (char c : exp.toCharArray()) {
			if (pri[c] > pri[stack.peek()]) {
				stack.push(c);
			} else {
				while (pri[c] <= pri[stack.peek()]) {
					rpn += String.valueOf(stack.pop());
				}
				stack.push(c);
			}
		}
		while (stack.peek() != '\0') {
			rpn += String.valueOf(stack.pop());
		}

		//
		Deque<Integer> ans = new ArrayDeque<>();

		for (char c : rpn.toCharArray()) {
			int a, b;
			switch (c) {
				case '*':
					b = ans.pop();
					a = ans.pop();
					ans.push(a * b);
					break;
				case '+':
					b = ans.pop();
					a = ans.pop();
					ans.push(a + b);
					break;
				default:
					ans.push(c - '0');
			}
		}
		return ans.peek();
	}
}

Measured memory_bytes: 24504
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

const ll INF = 1LL << 60;

int main() {
    int N,M; cin >> N >> M;
    vecl A(N),B(N),C(M),D(M),a(N),b(N);
    REP(i,N) cin >> A[i] >> B[i];
    REP(i,M) cin >> C[i] >> D[i];
    REP(i,N) {
        ll x = A[i];
        ll y = B[i];
        ll ans  = INF;
        for(int j = M-1; j>= 0; --j) {
            ll d = abs(x-C[j]) + abs(y-D[j]);
            if(d <= ans) {
                ans = d;
                a[i] = j+1;
            }
        }
    }
    REP(i,N) cout << a[i] << endl;
}

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

int main(){
  int N; cin >> N;
  vector<ll> v(N);
  rep(i,N){
    cin >> v[i];
  }
  ll ans=0;
  ll pow=1;
  for(int j=0;j<60;j++){
    ll cnt=0;
    for(int i=0;i<N;i++){
      if(v[i]&(1LL<<j)) cnt++;
    }
    if(j>0) pow=pow*2%MOD;
    ans=(ans+pow*cnt%MOD*(N-cnt)%MOD)%MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}



int a[6];
int M = 10;
int mod;
int main(){
  rep(i,5){
    cin >> a[i];
    if(a[i]%10 == 0) continue;
    else{
      mod = a[i] % 10 ;
      a[i] = a[i] + 10 - mod;
      M = min(mod,M);
    }
  }
  int time = 0;
  if(M == 10){
    rep(i,5){
      time += a[i];
    }
  }
  else{
    rep(i,5){
      time += a[i];
    }
    time = time + M - 10;
  }
  cout << time << endl;
  return 0;
}


Measured memory_bytes: 256