akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

string _dream = "dream";
string _erase = "erase";

int main() {

    string s,ans;

    cin >> s;

    int i=0;

    bool use_er = true;

    while(1){
        if(s[i] == 'd'){
            for(int j=0; j<5; j++){
                if(i>=s.size() || s[i] != _dream[j]){
                    cout << "NO" << endl;
                    return 0;
                }
                i++;
            }
            use_er = false;
            if(i == s.size()){
                break;
            }
        }
        else if(s[i] == 'e'){
            if(s[i+1] == 'r' && (s.size() == i+1 || s[i+2] != 'a')){
                if(!use_er){
                    use_er = true;
                    i += 2;
                }
                else{
                    cout << "NO" << endl;
                    return 0;
                }
            }
            else if(s[i+1] == 'r' && s[i+2] == 'a'){
                for(int j=0; j<5; j++){
                    if(i>=s.size() || s[i] != _erase[j]){
                        cout << "NO" << endl;
                        return 0;
                    }
                    i++;
                }
                use_er = false;
                if(s.size() != i && s[i] == 'r'){
                    i++;
                }
            }
            else{
                cout << "NO" << endl;
                return 0;
            }
            if(i == s.size()){
                break;
            }
        }
        else{
            cout << "NO" << endl;
            return 0;
        }
        if(i == s.size()){
            break;
        }
    }

    cout << "YES" << endl;

    return 0;
}

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

void fastInputOutput(){ios_base::sync_with_stdio(false);cin.tie(NULL);}

ll GCD(ll a, ll b){ll gcd, g;g = __gcd(a, b);return g;}
ll LCM(ll a, ll b){ll gcd, g;g = __gcd(a, b);return (a/g)*b;}
ll PowFun(ll base, ll power){ll ans = 1;for(int i = 1; i <= power; i++){ans *= base;}return ans;}



const ll INF_LONG = 1LL<<61;
const unsigned int inf_int = 1<<31;
const ll mod = 1e9+7;
double phi = acos(-1);

int main()
{
    fastInputOutput();
    int n, k;
    cin >> n >> k;
    int mark[n+4] = {};
    for(int i = 1; i <= k; i++)
    {
        int d;
        cin >> d;
        for(int j = 1; j <= d; j++)
        {
            int tem;
            cin >> tem;
            mark[tem]++;
        }
    }
    int Count = 0;
    for(int i = 1; i <= n; i++)
    {
        if(mark[i] == 0)
        {
            Count++;
        }
    }
    cout << Count << endl;
    return 0;
}


Measured memory_bytes: 3660
S = gets.chomp.chars
T = gets.chomp.chars
N = S.size
M = T.size

dp = Array.new(N+1){Array.new(M+1, 0)}
N.times do |i|
  dp_cur = dp[i]
  dp_next = dp[i+1]
  M.times do |j|
    if S[i] == T[j]
      dp_next[j+1] = dp_cur[j] + 1
    else
      a = dp_cur[j+1]
      b = dp_next[j]
      dp_next[j+1] = a > b ? a : b
    end
  end
end

i, j = N, M
ans = ''
while i > 0 && j > 0 do
  if dp[i][j] == dp[i-1][j]
    i -= 1
  elsif dp[i][j] == dp[i][j-1]
    j -= 1
  else
    ans << S[i-1]
    i -= 1
    j -= 1
  end
end

puts ans.reverse


Measured memory_bytes: 72444
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const int mod = (int)1e9 + 7;

int main() {
    //ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    string s,t;
    cin >> s >> t;
    bool a[26]={};
    rep(i,s.length()){
        a[s[i]-'a']=true;
    }
    bool ans=true;
    rep(i,t.length()){
        if(!a[t[i]-'a'])ans=false;
    }
    if(!ans)cout << -1;
    else{
        int p[26]={-1};
        map<ll,vector<ll>> mp;  
        rep(i,s.length()){
            mp[s[i]-'a'].push_back(i);
        }
        rep(i,26){
            mp[i].push_back(mod);
        }
        ll now;
        ll sum=0;
        rep(i,t.length()){
            if(i==0){
                sum+=mp[t[i]-'a'][0]+1;
                now=mp[t[i]-'a'][0];
            }
            if(i>0){
                auto ite=upper_bound(all(mp[t[i]-'a']),now);
                if(mp[t[i]-'a'][ite-mp[t[i]-'a'].begin()]==mod){ //|| ite-mp[t[i]-'a'].begin()>now){
                  	//cerr << 'a';
                    sum+=s.length()+mp[t[i]-'a'][0]-now;
                    now=mp[t[i]-'a'][0];
                }
                else{
                    sum+=mp[t[i]-'a'][ite-mp[t[i]-'a'].begin()];
                  	//cerr << mp[t[i]-'a'][ite-mp[t[i]-'a'].begin()] << endl;
                  	sum-=now;
                    now=mp[t[i]-'a'][ite-mp[t[i]-'a'].begin()];
                }
            }
          	cerr << s[now];
        }
      	//sum-=s.length();
        cout << sum;
    }
}

/*

if(i!=s.length()-1)

 */




Measured memory_bytes: 1728
#include <stdio.h>

int main(void)
{
	int card[5];
	int i,j;
	int temp;
	while(scanf("%d,%d,%d,%d,%d",&card[0],&card[1],&card[2],&card[3],&card[4])!=EOF){
	
	for(i=0;i<4;i++){
		for(j=4;j>i;j--){
			if(card[j-1]>card[j]){
				temp=card[j];
				card[j]=card[j-1];
				card[j-1]=temp;
			}
		}
	}
	
	if(card[0]==card[3]||card[1]==card[4]){
		printf("four card\n");
	}
	else if((card[0]==card[1]&&card[2]==card[4])||(card[0]==card[2]&&card[3]==card[4])){
		printf("full house\n");
	}
	else if(card[0]==card[2]||card[1]==card[3]||card[2]==card[4]){
		printf("three card\n");
	}
	else if((card[0]==card[1]&&(card[2]==card[3]||card[3]==card[4]))||(card[1]==card[2]&&card[3]==card[4])){
		printf("two pair\n");
	}
	else if(card[0]==card[1]||card[1]==card[2]||card[2]==card[3]||card[3]==card[4]){
		printf("one pair\n");
	}
	else if((card[4]==(card[0]+4))||(card[0]==1&&card[4]==13&&card[3]==12&&card[2]==11&&card[1]==10)){
		printf("straight\n");
	}
	else{
		printf("null\n");
	}
	
	}
	
	return 0;
}

Measured memory_bytes: 580
import std.stdio;
import std.string;
import std.conv;

void main() {
	string[] cin;
	while((cin=split(readln())).length!=0) {
		int a=to!int(cin[0]),b=to!int(cin[1]);
		int c=a+b;
		string s=to!string(c);
		writeln(s.length);
	}
}


Measured memory_bytes: 1060
#include<bits/stdc++.h>
#define ROCK 0
#define SCISSORS 1
#define PAPER 2
using namespace std;
int n,k,r,s,p;
string arr;
int dp[100005][4];
int f(int curr,int shape){
	if(curr>=n) return 0;
	int&ret=dp[curr][shape];
	if(~ret) return ret; 
	for(int i=0; i<3; i++){
		if(i!=shape) ret = max(ret,f(curr+k,i));
	}
	if(arr[curr]=='p') ret+=(shape==SCISSORS?s:0);
	else if(arr[curr]=='s') ret+=(shape==ROCK?r:0);
	else ret+=(shape==PAPER?p:0);
	return ret;
}
int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>k>>r>>s>>p;
	cin>>arr;
	int ret = 0;
	for(int i=0; i<k; i++){
		int mx = 0;
		for(int j=0; j<3; j++){
			mx = max(mx,f(i,j));
		}
		ret+=mx;
	}
	cout<<ret; 
}


Measured memory_bytes: 13012
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll logx=30;
const ll N=1e5+5;
const ll INF=1e18+5;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%intd",&n)
#define longp(n) printf("%intd\n",n)

inline ll mul(ll a, ll b, ll p){ return (a * 1ll * b) % p; }
inline ll sub(ll a, ll b, ll p){ ll c = a - b; if(c < 0) c += p; return c; }
inline ll add(ll a, ll b, ll p){ ll c = a + b; if(c > p) c -= p; return c; }

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1ll;x=(x*x)%m;}return ans%m;}

#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl

vector<ll> g[N];
ll n,m,u,v,dp[N][2];

void DFS(ll cur,ll par)
{
	dp[cur][0]=1; // white
	dp[cur][1]=1; // black
	for(auto i:g[cur])
	{
		if(i==par){continue;}
		DFS(i,cur);
		dp[cur][1]=mul(dp[cur][1],dp[i][0],mod);
		dp[cur][0]=mul(dp[cur][0],dp[i][0]+dp[i][1],mod);
	}
}

int main()
{
	cin>>n;
	m=n-1;
	while(m--)
	{
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	DFS(1,0);
	cout<<add(dp[1][0],dp[1][1],mod)<<endl;
}


Measured memory_bytes: 14208
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>
#include <math.h>

using namespace std;

int main(void)
{
    long long A, B, C;
    cin >> A >> B >> C;

    if (A != 0)
    {
        cout << (B / C + 1) - ((A - 1) / C + 1) << endl;
    }
    else
    {
        cout << (B / C + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
    public class Main {
     
    	public static void main(String[] args) {
    		Scanner scan = new Scanner(System.in);
    		int a=Integer.parseInt(scan.next());
    		if (scan.next().contentEquals("+")) {
    			System.out.print(a+Integer.parseInt(scan.next()));
    		}else {
    			System.out.print(a-Integer.parseInt(scan.next()));
    		}
    		
    }
     
    }

Measured memory_bytes: 22868
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = (ll)(1e9+7);
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(int)(n); (i)++)
int dx[4]={ 1,0,-1,0 };
int dy[4]={ 0,1,0,-1 };

ll N;

signed main(){
    cin >> N;
    if(N%2 == 1) cout << 0 << endl;
    else{
        ll ans = 0;
        for(ll i=10; i<=1'000'000'000'000'000'000LL; i*=5) ans += N/i;
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
function main(input) {
  var nums = input[1].split(" ").map(v=>{
    return v-0;
  });
  nums.sort((a,b)=>a-b);
  var sum = 0;
  nums.forEach(v=>sum+=v);
  sum-=nums[nums.length-1];
  console.log(sum>nums[nums.length-1]?"Yes":"No");

}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

n = INT()
a = LIST()
arr = []
plus = 0
for i in range(n):
    flag = True
    for j in range(1, 9):
        if (j - 1) * 400 <= a[i] < j * 400:
            if not j in arr:
                arr.append(j)
            flag = False
    if flag:
        plus += 1
debug(len(arr), plus, arr)
ansmx = len(arr) + plus
ansmn = max(1, len(arr))
print(ansmn, ansmx)


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

int main(){
    int a,b;

    cin>>a>>b;

    // Se um dos números for par o produto será par. Logo só é possível se os três forem ímpares
    cout<<(a%2 and b%2 ? "Yes" : "No")<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
  int K;
  long long A,B;
  
  int number;
//  long long N[101]={};
  int i;
//    int k=0;
  scanf("%lld", &A);
  scanf("%lld", &B);
  scanf("%d", &K);

  for(i=0;i<K;i++){
//      if(B<=i+1) return 0;
    printf("%lld\n", A+i);
      if(B-A<=i) return 0;
    
  }

  for(i=0;i<K;i++){
    if((B+i+1)>=A+(2*K))  printf("%lld\n", B+i-K+1);
  }
//  if(ans[0]&&ans[1]&&ans[2])  printf("Yes\n");  
//  else printf("No\n"); 
return 0;
}


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

#define mod 1000000007

using namespace std;
 
int main(void){
	
	int N, L, count;
	
	cin >> N >> L;
	
	if(L + N - 1 <= 0){
		for(int i=1; i<N; i++){
			count += L + i -1;
			if(i == N-1){
				cout << count;
				return 0;
			}
		}
	}
	
	for(int i=2; i<=N; i++){
		count += L + i - 1;
		if(L + i - 1 == 0){
			count += L;
		}
	}
	
	cout << count;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int h, w;
void check(int data2[100][101], int a, int b, int kind) {

	if (data2[a][b] == kind) {
		data2[a][b] = 0;
		if (b + 1 < w) {
			check(data2, a, b + 1, kind);
		}
		if (b > 0) {
			check(data2, a, b - 1, kind); 
		}
		if (a + 1 < h) {
			check(data2, a + 1, b, kind); 
		}
		if (a > 0) {
			 check(data2, a - 1, b, kind); 
		}
	}
}
char data1[100][101] = { 0 };
int data2[100][101] = { 0 };
int main(void) {
	int ans;
	int i, j;

	while (1) {
		scanf("%d %d",&h,&w);
		if (h == 0 && w == 0)break;
	
		for(i = 0; i < h; i++) {
				scanf("%s",&data1[i]);
		}
		for (i = 0; i < h; ++i) {
			for (j = 0; j < w; j++) {
				data2[i][j] = data1[i][j];
			}
		}
		
		ans = 0;
		for (i = 0; i < h; i++) {
			for (j = 0; j < w; j++) {
				if (data2[i][j] != 0) {
					ans++;
					check(data2, i, j, data2[i][j]);
				}
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1428
#include<cstdio>

int main(){
	long long int n;
	scanf("%lld",&n);
	long long int x = n % 11;
	long long int y = n / 11;
	if(x==0) x = 0;
	else if(x<=6) x = 1;
	else x = 2;
	printf("%lld\n",2*y+x);
	return 0;
}


Measured memory_bytes: 128
a, b, k = map(int, input().split())

if b+1 - a <= 2*k:
    for i in range(a, b+1):
        print(i)
else:
    for i in range(a, a+k):
        print(i)

    for j in range(b-k+1, b+1):
        print(j)


Measured memory_bytes: 3060
//2020-08-30, Sun

#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int N;
    int a[110];  // 最大 100 個ですが余裕をもたせます
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];

    sort(a, a + N, greater<int>());  // a[0:N] を大きい順にソート
    int Alice = 0;
    int Bob = 0;
    for (int i = 0; i < N; ++i) {
        if (i % 2 == 0) { // Alice のターン
            Alice += a[i];
        }
        else { // Bob のターン
            Bob += a[i];
        }
    }
    cout << Alice - Bob << endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) true
#define dump(x) true
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	
	int A,B; cin >> A >> B;
	if(A<=9 && B<=9) cout << A*B << endl;
	else cout << -1 << endl;
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF 1e8

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    s = "0"+s;
    reverse(all(s));
    int sz = s.size();
    vector<vi> dp(sz+1, vi(2,INF));
    dp[0][0] = 0;
    rep(i,sz){
        int d = s[i]-'0';
        rep(j,2)rep(k,10){
            if (k-j<d){
                chmin(dp[i+1][1],dp[i][j]+2*k+10-j-d);
            }else{
                chmin(dp[i+1][0],dp[i][j]+2*k-j-d);
            }
        }
    }
    cout<<dp[sz][0]<<endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int N;
int x,y,z;

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		int a;
		scanf("%d" , &a);
		if(a % 4 == 0) ++z;
		else if(a % 2 == 0) ++y;
		else ++x;
	}
	if(y>0) ++x;
	printf("%s\n" , z >= x-1 ? "Yes" : "No");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
 
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
 
const int MAX = 1000001;
bool pri[MAX];
vector<int>v;
map<int,pair<int,int> >pos;
int field[1201][1201];
int N,M;
 
void make(){
  int cnt = 2;
  int c = 1;
  int x = 500,y=500;
  int cc = 0;
  field[500][500] = 1;
  pos[1] = make_pair(500,500);
 
  while(cnt < 1000000){
    for(int i=0; i<4; i++){
      if(cc == 2){cc = 0; c++;}
      int nx = x, ny = y;
      for(int j=0; j<c; j++){
    nx += dx[i];
    ny += dy[i];
    pos[cnt] = make_pair(ny,nx);
    field[ny][nx] = cnt++;
      }
 
      x = nx, y = ny;
      cc++;
    }
  }
}
 
void createPrime(){
  fill(pri,pri+MAX,1);
  pri[0] = pri[1] = 0;
  for(int i=2; i*i<MAX; i++){
    for(int j=2*i; j<MAX; j+=i){
      pri[j] = false;
    }
  }
 
  for(int i=2; i<MAX; i++) if(pri[i]) v.push_back(i);
}
 
bool compare(pair<int,int>p, pair<int,int>p2){
  if(p.first == p2.first){
    return p.second > p2.second;
  }
  return p.first > p2.first;
}
 
int main(){
  make();
  createPrime();
 
  while(cin >> M >> N,M|N){
    pair<int,int> p = pos[N];
    int sx = p.second, sy = p.first;
    bool F = false;
 
    static bool used[1200][1200];
    static pair<int,int> dp[1200][1200];
    memset(used,0,sizeof(used));
    memset(dp,0,sizeof(dp));
 
    if(binary_search(v.begin(),v.end(),field[sy][sx])){
      dp[sy][sx].first = 1;
      dp[sy][sx].second = field[sy][sx];
    }
    used[sy][sx] = true;
 
    for(int i=sy; i<=1000; i++){
      for(int j=0; j<=1000; j++){
    for(int k=-1; k<=1; k++){
      if(!used[i][j])continue;
      int nx = j + k;
      if(nx < 0 || nx > 1000)continue;
      if(field[i+1][nx] > M)continue;
 
      used[i+1][nx] = true;
      int value = binary_search(v.begin(),v.end(),field[i+1][nx]);
       
      if(value){
        if(dp[i+1][nx].first < dp[i][j].first + 1){
          dp[i+1][nx].first = dp[i][j].first + 1;
          dp[i+1][nx].second = field[i+1][nx];
        }
      } else {
        dp[i+1][nx] = max(dp[i+1][nx],dp[i][j]);
      }
    }
      }
    }
 
    vector<pair<int,int> >ans;
 
    for(int i=0; i<=1000; i++){
      for(int j=0; j<=1000; j++){
    if(field[i][j] > M)continue;
    if(dp[i][j].first == 0)continue;
    ans.push_back(dp[i][j]);
      }
    }
 
 
    if(ans.size() == 0){cout << "0 0" << endl;}
    else{
      sort(ans.begin(),ans.end(),compare);
      cout << ans[0].first << " " << ans[0].second << endl;
    }
 
  }
 
  return 0;
}

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

#define ll long long
#define vll vector<ll>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vvll vector< vll >
#define write(v) for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
#define read(v) for(int i=0;i<v.size();i++)cin>>v[i];
#define write1(v) for(int i=1;i<v.size();i++)cout<<v[i]<<" ";
#define read1(v) for(int i=1;i<v.size();i++)cin>>v[i];
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);

int main()
{
	ll n,w,i,j;
	cin>>n>>w;
	
	ll wt[n+1],val[n+1],ans=-1;
	ll dp[102][100009];
	
	for(i=0;i<n;i++)
	{
		for(j=0;j<=100000;j++)
		{
			if(j!=0)
			dp[i][j]=1000000001;
			else
			dp[i][j]=0;
		}
	}
	for(i=0;i<n;i++)
	{
		cin>>wt[i];
		cin>>val[i];
	}

	for(i=0;i<100000;i++)
	{
		if(i==val[0])
			dp[0][i]=wt[0];
	}
	for(i=1;i<n;i++)
	{
		for(j=0;j<=100000;j++)
		{
			if(val[i]<=j)
			{ 
						
						dp[i][j]=min(dp[i-1][j],wt[i]+dp[i-1][j-val[i]]);
			}
			else
			{
				dp[i][j]=dp[i-1][j];
			}
		}
	}
	for(i=0;i<=100000;i++)
	{
		if(dp[n-1][i]<=w)
		{
			ans=max(ans,i);
		}
		//cout<<i<<" "<<dp[n-1][i]<<"\n";
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 79872
import math
N, M = map(int, input().split())
if abs(N-M)>1:
    print(0)
elif N!=M:
    ans = (math.factorial(N)%1000000007)*(math.factorial(M)%1000000007)%1000000007
    print(ans)
else:
    ans = (math.factorial(N)%1000000007)*(math.factorial(M)%1000000007)*2%1000000007
    print(ans)

Measured memory_bytes: 4108
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm> 
#include<vector>
using namespace std;
int m, n, a, b, temp, head, tail = 1, c[100010], q[100010];
vector<int> ac[100010];
int main()
{
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= m; i++)
	{
		scanf("%d%d", &a, &b);
		ac[a].push_back(b);
		ac[b].push_back(a);
	}
	q[++head] = 1;
	while(head <= tail)
	{
		for(int i = 0; i < ac[q[head]].size(); i++)
		{
			if(c[ac[q[head]][i]] == 0) 
			{
				q[++tail] = ac[q[head]][i];
				c[ac[q[head]][i]] = q[head];
			}
		}
		head++;
	}
	for(int i = 2; i <= n; i++)
	{
		if(c[i] == 0)  
		{
			printf("No\n");
			return 0;
		} 
	}
	printf("Yes\n");
	for(int i = 2; i <= n; i++)
	{
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 10824
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int x[300005], y[300005];
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	for (int d = 0; d<a; d++) {
		int e, f, g; scanf("%d%d%d", &e, &f, &g);
		x[max(0,e - g)]++; x[e + g]--;
		y[max(0,f - g)]++; y[f + g]--;
	}
	int s = 0;
	bool N = false, M = false;
	for (int i = 0; i<b; i++) {
		s += x[i];
		if (s <= 0) { N = true; }
	}
	s = 0;
	for (int i = 0; i<c; i++) {
		s += y[i];
		if (s <= 0) { M = true; }
	}
	if (N&&M) { puts("No"); }
	else puts("Yes");
}

Measured memory_bytes: 4644
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (int i = (a); i < (n); i++)
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

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

	int N, D;
	int c = 0;
	cin >> N >> D;

	vector<vector<int> > A;

	REP(i, N)
	{
		A.emplace_back();
		REP(j, D)
		{
			int temp;
			cin >> temp;
			A[i].push_back(temp);
		}
	}

	REP(i, N - 1)
	{
		for (int k = i + 1; k < N; k++)
		{
			int temp = 0;
			REP(j, D)
			{
				temp += (A[k][j] - A[i][j]) * (A[k][j] - A[i][j]);
			}
			double x = sqrt(temp);

			if (ceil(x) == floor(x))
			{
				c++;
			}
		}
	}

	cout << c << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)


int log2ceil(int n) {
    --n;
    n |= n >> 16;
    n |= n >> 8;
    n |= n >> 4;
    n |= n >> 2;
    n |= n >> 1;
    return n + 1;
}

template<class Monoid>
class SegmentTree {
public:
    using value_type = typename Monoid::value_type;
    using update_type = typename Monoid::value_type;

private:
    const int size_, n;
    std::vector<value_type> data;

public:
    SegmentTree(const std::vector<value_type> &vec) :
            size_(vec.size()), n(log2ceil(size_)), data(n * 2, Monoid::id()) {
        std::copy(begin(vec), end(vec), begin(data) + n);
        for (int i = n - 1; i >= 0; --i) {
            data[i] = Monoid::op(data[i * 2 + 0], data[i * 2 + 1]);
        }
    }

    SegmentTree(const int count, const value_type &value = Monoid::id()) :
            SegmentTree(std::vector<value_type>(count, value)) {}

    int size() const { return size_; }

    void update(int pos, const value_type &value) {
        assert(0 <= pos && pos < size_);  // assertion
        data[pos += n] = value;
        while (pos /= 2) {
            data[pos] = Monoid::op(data[pos * 2], data[pos * 2 + 1]);
        }
    }

    // セグメント木の区間 [l, r) を演算 Monoid::op (⋅⋅) で畳み込んだ値を返す． すなわち，al⋅al+1⋅…⋅ar−1al⋅al+1⋅…⋅ar−1 を返す． l=rl=r の場合は Monoid::id() を返す．
    value_type query(int l, int r) const {
        assert(0 <= l && l <= r && r <= size_);  // assertion
        l += n;
        r += n;
        value_type res1 = Monoid::id(), res2 = Monoid::id();
        while (l < r) {
            if (l & 1) res1 = Monoid::op(res1, data[l++]);
            if (r & 1) res2 = Monoid::op(data[--r], res2);
            l >>= 1;
            r >>= 1;
        }
        return Monoid::op(res1, res2);
    }
};

// RMQ
struct RMQ {
    using value_type = int;

    static value_type id() { return -1000000000; }

    static value_type op(const value_type &l, const value_type &r) {
        return std::max(l, r);
    }
};


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

    vector<pair<int, int>> lisv;

    SegmentTree<RMQ> rmq(100010);
    vector<int> A(n);
    for(int i = 0 ; i < n ; i++) {
        scanf("%d", &A[i]);

    }
    rmq.update(0, 0);

    for (int i = 0; i < n; i++) {
        int dpv;
        if( A[i] == 0 ){
            dpv = 1;
        }else{
            dpv = rmq.query(0, A[i]) + 1;
        }


        rmq.update(A[i], dpv);
        lisv.push_back({dpv, i});
    }
    sort(lisv.begin(), lisv.end(), [&](pair<int,int> &a,pair<int,int> &b){
        if( a.first != b.first ) return a.first > b.first;
        return A[a.second] > A[b.second];
    });
    int lst = n;
    int val = 10000000;
    ll ans = 0;
    for (auto p : lisv) {
        if (p.second > lst) {
            continue;
        }
        if (p.first >= val) continue;
        if( lst != n && A[p.second] >= A[lst] ) continue;

        val = p.first;
        ans += A[p.second];
        lst = p.second;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5912
def main():
    n = int(input())
    w = [input() for _ in range(n)]

    if len(set(w)) == n:
        for i in range(n-1):
            if w[i][-1] != w[i+1][0]:
                print('No')
                break
        else:
            print('Yes')
    else:
        print('No')

if __name__=='__main__':
    main()


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>

int main()
{
	int n,i,taro=0,hanako=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		char t[101],h[101];
		scanf("%s %s",t,h);
		if(strcmp(t,h)>0)taro+=3;
		else if(strcmp(t,h)<0)hanako+=3;
		else {taro++;hanako++;}
	}
	printf("%d %d\n",taro,hanako);
	return 0;
}

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

typedef long long llt;

const int MaxN = 50 + 5;

int N; llt X;
llt P[MaxN], Size[MaxN];

llt solve(llt l, llt r, int n) {
    // printf("solve(%lld, %lld, %d)\n", l, r, n);
    if (n == 0) return 1;
    if (r <= n) return 0;
    llt m = (Size[n] >> 1) + 1ll;

    if (r < m) {
        return solve(1, r - 1, n - 1);
    } else if (r == m) {
        return solve(1, r - 2, n - 1) + 1ll;
    } else {
        return P[n - 1] + solve(1, r - m, n - 1) + 1ll;
    }
}

int main() {
    cin >> N >> X;
    P[0] = 1ll;
    for (int i = 1; i <= N; ++i) P[i] = P[i - 1] * 2ll + 1ll;
    Size[0] = 1ll;
    for (int i = 1; i <= N; ++i) Size[i] = Size[i - 1] * 2ll + 3ll;
    cout << solve(1ll, X, N) << endl;
    return 0;
}

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

void solve()
{
	ll n;
	cin>>n;
	vector<ll> v(20);
	v.push_back((ll)0);
	for(ll i=1;i<=15;i++)
	{
		v[i]=v[i-1]+pow(26,i);
	}
	
	ll idx,cur,pre;
	for(ll i=1;i<=15;i++)
	{
		if(v[i]>=n)
		{
			idx=i;
			cur=v[i];
			pre=v[i-1];
			break;
		}
	}
	n=n-pre-1;
	string final="";
	while(idx)
	{
		idx--;
		final+=('a'+(n%26));
		n/=26;
	}
	reverse(final.begin(),final.end());
	cout<<final;
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

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

const long long MOD = 1000000007;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	
	cin >> n;
	
	long long ans = 1;
	
	int t[3] = {-1, -1, -1};
	vector<int> v(n);
	for (int i = 0; i < n; ++i){
		cin >> v[i];
		
		int count = 0;
		bool f = false;
		for (int j = 0; j < 3; ++j){
			if (t[j] == v[i] - 1){
				if (!f){
					f = true;
					t[j]++;
				}
				count++;
			}
		}
		
		ans = ans * count % MOD;
	}
	cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
struct store
{
    int num;
    string s;
    int p;
};

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

    vector<store> stores(n);
    string s;
    int p;
    for (int i = 0; i < n; i++)
    {
        cin >> s >> p;
        struct store a = {i + 1, s, p};
        stores[i] = a;
    }

    stable_sort(stores.begin(), stores.end(), [](const store &x, const store &y) { return x.p > y.p; });
    stable_sort(stores.begin(), stores.end(), [](const store &x, const store &y) { return x.s < y.s; });

    for (int i = 0; i < n; i++)
    {
        cout << stores[i].num << endl;
    }
    return 0;
}

Measured memory_bytes: 256
y = [int(z) for z in input().split()]
l = [int(z) for z in input().split()]
d = [0]*(y[0]+1)
c = 1
for i in range(1,y[0]+1):
      d[i] = d[i-1]+l[i-1]
      if (d[i]<=y[1]):
            c+=1
print(c)


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

int main()
{
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++)
    cin >> a[i];
  int cnt = 0;
  int now = 1;
  for (int i = 0; i < N; i++)
  {
    if (a[i] != now)
      cnt++;
    else
      now++;
  }
  if (cnt == N)
    cout << -1 << endl;
  else
    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define all(vec) vec.begin(), vec.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = (1e9 + 7);
ll dp[100010];
ll gcd(ll x, ll y){
  return y == 0 ? x : gcd(y, x % y);
}
ll lcg(ll x, ll y){
  return x * y / gcd(x, y);
}
map<ll, ll> factor(ll n){
  map<ll, ll> ans;
  ll a = 2;
  while (n >= a * a){
    if (n % a == 0){
      ans[a]++;
      n /= a;
    }
    else a++;
  }
  ans[n]++;
  return ans;
}
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;
}

int main(){
  cout << fixed << setprecision(15);
  string s; cin >> s;
  int ans = 0;
  string a = s;
  rep(i, s.size()){
    if (i % 2 == 0) a[i] = '0';
    if (i % 2 == 1) a[i] = '1';
  }
  rep(i, s.size()) if (s[i] != a[i]) ans++;
  ans = min(ans, (int)s.size() - ans);
  cout << ans << endl;
}

Measured memory_bytes: 512
x, n = map(int, input().split())
p = list(map(int ,input().split()))
p.sort()
ans = []
for i in range(100):
    x_left = x-i
    x_right = x + i
    if x_left not in p:
        print(x_left)
        exit()
    elif x_right not in p:
        print(x_right)
        exit()


Measured memory_bytes: 9180
import sys

class SWAG:
    def __init__(self):
        self.fold_l = []
        self.r = []
        self.fold_r = ~(1 << 60)
    def push(self, a):
        if self.fold_r < a:
            self.fold_r = a
        self.r.append(a)
    def pop(self):
        if not self.fold_l:
            self.r.reverse()
            self.fold_l = self.r
            self.r = []
            self.fold_r = ~(1 << 60)
            fold_l = self.fold_l
            for i in range(len(fold_l) - 1):
                if fold_l[i + 1] < fold_l[i]:
                    fold_l[i + 1] = fold_l[i]
        self.fold_l.pop()
    def get(self):
        if not self.fold_l:
            return self.fold_r
        elif not self.r:
            return self.fold_l[-1]
        else:
            return max(self.fold_l[-1], self.fold_r)

n, k = map(int, input().split())
p = [*map(int, input().split())]
c = [*map(int, input().split())]
for i in range(n):
    p[i] -= 1

if max(c) < 0:
    print(max(c))
    sys.exit()

ans = 0
used = [False] * n
for i in range(n):
    if used[i]:
        continue

    # ループを取り出す
    loop = []
    at = i
    while not used[at]:
        loop.append(c[at])
        used[at] = True
        at = p[at]

    siz = len(loop)
    cusum = [0] + loop * 3
    for i in range(siz * 3):
        cusum[i + 1] += cusum[i]
    sum = max(0, cusum[siz])

    # k % siz 回以下での最大 -> 累積和にスライド最大値
    d = k % siz
    swag = SWAG()
    for i in range(d):
        swag.push(cusum[i])
    for i in range(siz):
        swag.push(cusum[d + i])
        ans = max(ans, swag.get() - cusum[i] + sum * (k // siz))
        swag.pop()

    if k < siz:
        continue

    # k % siz + siz 回以下での最大
    d = k % siz + siz
    swag = SWAG()
    for i in range(d):
        swag.push(cusum[i])
    for i in range(siz):
        swag.push(cusum[d + i])
        ans = max(ans, swag.get() - cusum[i] + sum * (k // siz - 1))
        swag.pop()

print(ans)


Measured memory_bytes: 10408
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}
int gyaku(int n){
    return modpow(n,MOD-2);
}
signed main() {
  string s;
  cin>>s;
  int n;
  n=s.size();
  int i=0;
  vector<string>v={"dreamer","dream","erase","eraser"};
  while(true){
    if(i==n){cout<<"YES";break;}
    if(i>n-5){cout<<"NO";break;}
    if(s.substr(n-i-5,5)==v[1]||s.substr(n-i-5,5)==v[2]){
      i+=5;
      continue;
    }
    if(i>n-6){cout<<"NO";break;}
    if(s.substr(n-i-6,6)==v[3]){
      i+=6;
      continue;
    }
    if(i>n-7){cout<<"NO";break;}
    if(s.substr(n-i-7,7)==v[0]){
      i+=7;
      continue;
    }
    cout<<"NO";
    break;
  }
}


Measured memory_bytes: 3788
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

#ifdef WAFDAYO
#define DBG_PRINT(s, t, u) { cerr << s << " \e[2m=\e[m \e[1m" << t << "\e[m" << u; }
#else
#define DBG_PRINT(s, t, u) {}
#endif
#define dbg(x) DBG_PRINT(#x, x, ", ")
#define dbgln(x) DBG_PRINT(#x, x, endl)
#define idbg(x, i) DBG_PRINT(#x "[" << i << "]", x[i], ", ")
#define idbgln(x, i) DBG_PRINT(#x "[" << i << "]", x[i], endl)

typedef long long i64;
const i64 inf = (i64)1.05e18;
// const int inf = (int)1.05e9;

int main() {

	int n;
	vector<i64> as;
	i64 sum = 0;

	scanf("%d", &n);
	as.resize(n);
	for(int i = 0; i < n; i++) {
		scanf("%lld", &as[i]);
		sum += as[i];
	}

	i64 ans = inf;

	i64 cur = 0;
	for(int i = 0; i < n; i++) {
		cur += as[i];
		i64 x = abs(cur - (sum - cur));
		ans = min(ans, x);
	}

	printf("%lld\n", ans);

	return 0;
}


// wafdayo~~~


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,k,a[10010];
char s[10010];
main()
{
	scanf("%d%d%d",&n,&m,&k);
	if (k==0)
	{
		puts("Yes");
		return 0;
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++)
		{
			if (k==i*j+(n-i)*(m-j))
			{
				puts("Yes");
				return 0;
			}
		}

	puts("No");
return 0;
}

Measured memory_bytes: 128
from collections import deque
N = int(input())
A = [list(map(lambda x:int(x)-1, input().split()))[::-1] for _ in range(N)]
q = deque([])

# 選手iが試合ができるかをチェックして、できるならばキューに入れる
def check(i, q):
  if len(A[i]) == 0:
    return
  j = A[i][-1]
  if len(A[j]) == 0:
    return
  if A[j][-1] == i:
    if i > j:
      i, j = j, i
    q.append((i, j))
  return 

for i in range(N):
  check(i, q)

day = 0
while q:
  day += 1
  q = set(sorted(q))
  prev = deque([])
  prev, q = q, prev
  for i, j in prev:
    A[i].pop(-1)
    A[j].pop(-1)
  for i, j in prev:
    check(i, q)
    check(j, q)
  
for i in range(N):
  if len(A[i]) != 0:
    print(-1)
    exit()

print(day)



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

using namespace std;

int main()
{
	string str[3];
	int i;
	
	for (i = 0; i < 3; i++){
		cin >> str[i];
	}
	
	cout << str[0][0] << str[1][1] << str[2][2] << "\n";
	
	return (0);
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define ll long long
#define str string
#define sonic ios_base::sync_with_stdio(0)
using namespace std;
ll a[1001];
int main(){
	sonic;
	ll n,cnt=0;
	str s;
	cin>>n;
	cin>>s;
	for(ll i=0;i<s.size();i++){
		if(s[i]==s[i+1]){
			continue;
		}
		else{
			cnt++;
		}
	}
	cout<<cnt;
}

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

using namespace std;
int main ()
{
    int N;
    cin >> N;
  int i;
    for(i=1;i<=9;i++){
        if(i+i*10+i*100>=N){
      	cout << i+i*10+i*100 <<endl;
        break;
        }
    }
    
    
}












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

int main()
{
  int N, K, Q;
  cin >> N >> K >> Q;
  if (Q < K)
  {
    for (int i = 0; i < N; ++i)
      cout << "Yes" << endl;
    return 0;
  }
  vector<int> _point(N + 1, K - Q);
  auto * const point = &_point[0];
  for (int i = 0; i < Q; ++i)
  {
    int A;
    cin >> A;
    ++point[A];
  }
  for (int i = 1; i <= N; ++i)
    cout << (0 < point[i] ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

int main(){
    int N;cin>>N;
    vector<int>P(N);
    for(int i = 0;i <N;i++){
        cin>>P[i];
    }


    int cnt = 0;
    for(int i = 1; i < N -1; i++){
        if(P[i-1] < P[i] && P[i] < P[i+1])cnt++;
        else if(P[i-1] > P[i] && P[i] > P[i+1])cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  ll a,b,x;
  cin >> a >> b >> x;
  ll ans = 0;
  if(a > 0) ans = (b/x) - ((a-1)/x);
  else ans = b/x + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin >> S;
  int head = 0;
  int tail = S.size() - 1;
  int count = 0;
  while(head < tail)
  {
    if(S[head] != S[tail]) {
      S[head] = S[tail];
      count++;
    }
    head++;
    tail--;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}


ll a[100009];


int main() {
	ll H, W, an = 1e11 + 7;
	cin >> H >> W;
	for (ll i = 1; i < H ; i++) {
		ll s1 = i * W;
		ll s2h = ((H - i) / 2)*W;
		ll s3h = H * W - s1 - s2h;
		an = min(an, Max(s1, s2h, s3h) - Min(s1, s2h, s3h));
		ll s2w = (H - i) * (W / 2);
		ll s3w= H * W - s1 - s2w;
		an = min(an, Max(s1, s2w, s3w) - Min(s1, s2w, s3w));
	}
	swap(H, W);
	for (ll i = 1; i < H; i++) {
		ll s1 = i * W;
		ll s2h = ((H - i) / 2) * W;
		ll s3h = H * W - s1 - s2h;
		an = min(an, Max(s1, s2h, s3h) - Min(s1, s2h, s3h));
		ll s2w = (H - i) * (W / 2);
		ll s3w = H * W - s1 - s2w;
		an = min(an, Max(s1, s2w, s3w) - Min(s1, s2w, s3w));
	}
	cout << an << endl;
}


Measured memory_bytes: 3636
// Aizu Vol-10 1072: Rearranging Seats
// 2017.8.18 bal4u@uu

#include <stdio.h>

int main()
{
	int r, c;
	while (scanf("%d%d", &r, &c) && r) puts(r*c & 1 ? "no" : "yes");
	return 0;
}

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

string copyStr(int a, int b) {
  string res = "";
  for (int i = 0; i < b; i++) {
    res += to_string(a);
  }
  return res;
}

int main() {
  int a, b;
  scanf("%d %d", &a, &b);

  string s = copyStr(a, b);
  string t = copyStr(b, a);
  if (s < t)
    cout << s << endl;
  else
    cout << t << endl;

  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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 mod = 1000000007;
struct mint{
	ll x;
	mint(ll x = 0):x((x%mod+mod)%mod){}
	mint operator-() const{return mint(-x);}
	mint& operator+=(const mint a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a){
		if((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a){
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const{
		mint res(*this);
		return res+=a;
	}
	mint operator-(const mint a) const{
		mint res(*this);
		return res-=a;
	}
	mint operator*(const mint a) const{
		mint res(*this);
		return res*=a;
	}
	mint pow(ll t) const{
		if(!t) return 1;
		mint a = pow(t>>1);
		a *= a;
		if(t&1) a *= *this;
		return a;
	}
	mint inv() const{
		return pow(mod-2);
	}
	mint& operator/=(const mint a){
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const{
		mint res(*this);
		return res/=a;
	}
	bool operator==(const mint a){
		return x == a.x;
	}
};

mint f(int n){
	if(n == 0) return 1;
	mint x = f(n/2);
	x *= x;
	if(n%2 == 1) x *= 2;
	return x;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    map<int, int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a]++;
    }
    if(n%2 == 0){
        for(int i = 1; i <= n-1; i+=2){
            if(mp[i] != 2){
                cout << 0 << endl;
                return 0;
            }
        }
        mint ans = f(n/2);
        cout << ans.x << endl;
    }
    else{
        if(mp[0] != 1){
            cout << 0 << endl;
            return 0;
        }
        for(int i = 2; i <= n-1; i+=2){
            if(mp[i] != 2){
                cout << 0 << endl;
                return 0;
            }
        }
        mint ans = f(n/2);
        cout << ans.x << endl;
    }
    return 0;
}


Measured memory_bytes: 6532
import java.util.*;
import static java.lang.System.*;
public class Main {
    public static void main(String[] $) {
        Scanner sc = new Scanner(in);
        int n = sc.nextInt(),m=sc.nextInt();
        int[] a=new int[200001];
        int[] b=new int[200001];
        HashSet<Integer>[] via=new HashSet[200001];
        if(n>=200001||m>=200001){
            while (true){
                
            }
        }
        for (int i = 1; i <= 200000; i++) {
            via[i]=new HashSet<>();
        }
        for (int i = 0; i < m; i++) {
            a[i]=sc.nextInt();
            b[i]=sc.nextInt();
            via[a[i]].add(b[i]);
            via[b[i]].add(a[i]);
        }
        for (Integer k:via[1]){
            for (Integer l:via[k]){
                if(l==n){
                    out.println("POSSIBLE");
                    exit(0);
                }
            }
        }
        out.println("IMPOSSIBLE");
    }
}

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	int d;
	cin>>d;
	int c[26];
	rep(i,26)cin>>c[i];
	int lastd[26]={};
	int s[d][26];
	rep(i,d){
		rep(j,26)cin>>s[i][j];
	}

	ll ans=0,maxi=0,maxid=0;
	ll ans2=0;
	int t[d]={};
	rep(i,d){
		maxi=0;
		rep(j,26){
			ans=s[i][j];
			rep(k,26){
				if(k==j)continue;
				ans-=c[k]*(i+1-lastd[k]);
			}
			if(ans>maxi){
				maxi=ans;
				maxid=j;
			}
		}
		ans2+=maxi;
		lastd[maxid]=i+1;
		t[i]=maxid;
	}

	rep(i,d){
      cout<<t[i]+1;
      if(i!=d-1)cout<<endl;
    }  

	return 0;
}


Measured memory_bytes: 3668