akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	string s;
	cin>>s;
	ll n=s.length();
	
	ll st=-1,en=-1;
	for(ll i=0;i<n;i++){
		if(s[i]=='<'){
			st=i;break;
		}
	}
	
	for(ll i=n-1;i>=0;i--){
		if(s[i]=='>'){
			en=i;break;
		}
	}
	
	if(st==-1){
		cout<<(n*(n+1))/2<<endl;
		return 0;
	}
	
//	cout<<"fgh"<<endl;
//	cout<<st<<" "<<en<<endl;
//	if(st==-1||en==-1){
//		cout<<(n*(n-1))/2<<endl;
//	}
//	else{
		ll ans=0;
		for(ll i=st;i<=en;){
			ll c1=0;
			while(i<=en&&s[i]=='<'){
				c1++;i++;
			}
			ll c2=0;
			while(i<=en&&s[i]=='>'){
				c2++;i++;
			}
//			cout<<c1<<" "<<c2<<endl;
			if(c1>c2) swap(c1,c2);
			ans+=((c1)*(c1-1)/2);
			ans+=((c2)*(c2+1)/2);
//			cout<<"ans: "<<ans<<endl;
		}
		ll c1=st;
		ans+=((c1)*(c1+1)/2);
		ll c2=n-en-1;
		ans+=((c2)*(c2+1)/2);
		cout<<ans<<endl;
//	}
	
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (abs(a - c) <= d || (abs(a - b) <= d) && abs(b - c) <= d) {
		cout << "Yes"<< endl;
	}
	else {
		cout << "No" << endl;
	}
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**2) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,a,b,c = li()
l = [ni() for _ in range(n)]

ans = 10**18

for i in range(4**n):
    cur = i
    cnt = {i: [] for i in range(4)}
    
    for bi in l:
        cnt[cur%4].append(bi)
        cur //= 4
    
    
    if len(cnt[1]) * len(cnt[2]) * len(cnt[3]) == 0:
        continue
    
    ans = min(ans, abs(a-sum(cnt[1]))\
                  + abs(b-sum(cnt[2]))\
                  + abs(c-sum(cnt[3]))\
                  + 10*(n - len(cnt[0]) -3))
    
print(ans)

Measured memory_bytes: 3188
import copy
s=input()
check="keyence"
tmp=6
sNow=0
cNow=0
#一度目のチェック
for i in s:
  sNow+=1
  if i == check[cNow]:
    cNow+=1
  else:
    break
#最初に見つかれば終了
if cNow == 7:
  print("YES")
  exit()

#print(check[cNow:], s[-1*(7-cNow):])
"""
sの最後が"keyence"の残りの文字と一致すればOK
例：keyaence
最初の"key"は合っているので，残りは"aence"の内"a"を除いたもの
cNow=3, 7-cNow=4
後ろの４文字が"ence"ならばYESとなる
"""
if check[cNow:] == s[-1*(7-cNow):]:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9272
n =int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

sum = 0
for i in A:
    sum += B[i - 1] 

for a,b in zip(A,A[1:]):
    if b == a + 1:
        sum += C[a - 1]
    
print(sum)

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

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

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d %d", $a,$b);
$c = abs($a-$b) / 2;

if(preg_match('/^([1-9]\d*|0)\.(\d+)?$/', $c)){
    echo "IMPOSSIBLE";
}else{
    echo min($a,$b)+$c;
}
?>

Measured memory_bytes: 3700
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc= new Scanner(System.in);
		
		int x= sc.nextInt();
		
		sc.close();
		
		if(x== 1)System.out.println(0);
		else if(x== 0)System.out.println(1);
		
	}

}


Measured memory_bytes: 35608
import java.util.Scanner;


public class Main {

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

		String s = sc.next();

		String front = s.substring(0, (s.length()-1)/2);
		String back = s.substring((s.length()+2)/2, s.length());

		if(front.equals(back)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 22740
aa = input()
l = aa.split()
a = l[0]
b = l[1]


x =""
y= ""
for i in range(1,int(b)+1):
    x = x+a
for i in range(1,int(a)+1):
    y = y+b
if x>y:
    print(y)
else:
    print(x)    


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

int main(void){
    
    int a, b, c, d, isok = 0;
    scanf("%d %d %d %d", &a, &b, &c, &d);
    
    
    
    if (abs(a-c) <= d || (abs(a-b)<=d && abs(b-c)<= d)) {
        isok = 1;
    }
    
    if (isok == 1) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
    
    return 0;
}

Measured memory_bytes: 128
//
//AtCoder Beginner Contest 173
//A
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    int a = 1000;
    while(true){
        if (n<=a) break;
        a+=1000;
    }
    cout << a-n << endl;

    return 0;
}


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

	int main(){

		double a,b,c,d,e,f;
		while(cin>>a>>b>>c>>d>>e>>f)
		{
			double tx,ty;

			tx = (1.0*(c*e - b*f) / (e*a - b*d));
			ty = (1.0*(d*c - a*f) / (b*d - a*e));

			if(tx>=0){
			tx+=0.0004;
		}
		else{
			tx-=0.0004;
		}
		if(ty>=0){
		   ty+=0.0004;
		}
		else{
			ty-=0.0004;
		}

			cout<<setprecision(3) << setiosflags(ios::fixed)<< tx<<" "<<ty<<endl;
		}
	

		
		return 0;
	}

Measured memory_bytes: 1284
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
ll n, x[55], y[55], ans;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll div(ll x)
{
	return pow(x, mod - 2);
}

int main(void)
{
	cin >> n;
	if (n == 1)
	{
		cout << 1 << endl;
		return 0;
	}
	ans = 100000000000000000;
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			if (i == j) continue;
			ll a = x[i] - x[j], b = y[i] - y[j], zan = 0;
			for (int k = 0; k < n; k++)
			{
				if (k == i)
				{
					zan++;
				}
				else
				{
					bool jud = false;
					for (int l = 0; l < n; l++)
					{
						if (l == k) continue;
						if (x[l] - a == x[k] && y[l] - b == y[k])
						{
							jud = true;
						}
					}
					if (!jud)
					{
						zan++;
					}
				}
			}
			ans = min(zan, ans);
		}
	}
	cout << ans << endl;
	int www;
	cin >> www;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

d = {
    'SUN': 7, 'MON': 6, 'TUE': 5 ,'WED': 4, 'THU': 3, 'FRI': 2, 'SAT': 1, 
}

S = input()

print(d[S])


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define rs(v,n)     v.resize(n)
#define hell        1000000007
#define peak        9123372036854775807
#define pii         acos(-1)
#define clr(a,x)    memset(a,x,sizeof(a))
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class x,class y> x sum(x a,y b){return a+b;}
template<class x,class y> x mul(x a,y b){return a*b;}
template<class x,class y> x sub(x a,y b){return a-b;}
template<class x,class y> x divi(x a,y b){return a/b;}

template<class x,class y>
istream &operator>>(istream &in,pair<x,y> &p) 
{ 
    in>>p.F>>p.S;
    return in;
}
template<class x>
istream &operator>>(istream &in,vector<x> &v) 
{
    for(auto& i:v)
        in>>i;
    return in;
}
template<class x,class y>
ostream &operator<<(ostream &out,pair<x,y> &p) 
{ 
    out<<"("<<p.F<<","<<p.S<<") ";
    return out; 
}
template<class x>
ostream &operator<<(ostream &out,vector<x> &v) 
{ 
    out<<v.size()<<endl;
    for(auto i:v)
        out<<i<<" ";
    out<<endl;
    return out; 
}
#define N  200005

ll n;
vi v;

vector<map<ll,ll>> ma(N);

ll solve(ll ind,ll x)
{
	if(ma[ind].find(x)!=ma[ind].end()) return ma[ind][x];
	ll y=n-ind;
	if(x<=0) 
	{
		ma[ind][x]=0;
		return 0;
	}
	if(ind>=n) 
	{
		ma[ind][x]=-peak;
		return -peak;
	}
	if((y+1)/2<x) 
	{
		ma[ind][x]=-peak;
		return -peak;
	}
	ll ans=v[ind]+solve(ind+2,x-1);
	y=solve(ind+1,x);
	ma[ind][x]=max(y,ans);
	return max(y,ans);
}

int main()
{
    ios;
    ll tt=1;
    // cin>>tt;
    while(tt--)
    {
    	ll i,j,k,l,m;
    	cin>>n;
    	for(i=0;i<n;i++)
    	{
    		cin>>l;
    		v.pb(l);
    	}
    	ll ans=solve(0,n/2);
    	cout<<ans;
    }
    return 0;
}

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

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

using namespace std;


#define INF 1000000000

const long long DIMN = 1007;
const long long DIMW = 20007;

long long d[DIMN][DIMW];
long long n,res,MAXW;

typedef struct box{
    long long w,s,v;
};

bool cmp(box &a, box &b ) {
    return a.w+a.s < b.w+b.s;
}

box a[DIMN];

int main() {
    //freopen("input.txt", "r", stdin);

    cin >> n;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].w >> a[i].s >> a[i].v;
    }
    sort(a+1,a+1+n,cmp);
    MAXW = 20000;
    //MAXW = 5;

    d[0][0] = 0;
    for(int i = 1; i <= n; i++)
        for(int j = 0; j <= MAXW; j++) {
            d[i][j] = d[i-1][j];
            if(a[i].w <= j && a[i].s >= j-a[i].w) d[i][j] = max(d[i][j], d[i-1][j-a[i].w] + a[i].v);
        }

    res = 0;
    for(int i = 1; i <= MAXW; i++) res = max(res, d[n][i]);

    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 156544
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}


fn main() {
   input!{
     s : String,
   }
   if( s == "ani" ) {
     println!("square1001")
   } else {
     println!("e869120")
   }
}


Measured memory_bytes: 5016
import java.util.*;

public class Main {

  public static void main (String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int N = sc.nextInt();
    int K = sc.nextInt();
    String[] D = new String[K];

    for (int i = 0; i < K; i++) {
      D[i] = sc.next();
    }

    sc.close();

    boolean flg = true;

    while (flg) {

      String n = String.valueOf(N);

      boolean hasD = false;

      for (int i = 0; i < K; i++) {
        if (n.indexOf(D[i]) != -1) {
          hasD = true;
          break;
        }
      }

      if (hasD){
        N++;
      } else {
        flg = false;
      }

    }

    System.out.println(N);
    
  }

}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    ll n,l;cin >>n>>l;
    vector<ll>a(n);
    for (int i = 0; i < n; ++i) {
        cin >>a[i];
    }
    ll mx=0;ll k;
    for (int i = 0; i < n-1; ++i) {
        if(a[i]+a[i+1]>mx){
            mx=a[i]+a[i+1];
            k=i;
        }
    }
    if(mx<l){
        puts("Impossible");
        return 0;
    }
    vector<ll>ans;
    for (int i = k; i <n-1; ++i) {
        ans.push_back(i);
    }
    for (int i = k-1; i >=0; --i) {
        ans.push_back(i);
    }
    reverse(all(ans));
    puts("Possible");
    for (int i = 0; i < ans.size(); ++i) {
        cout <<ans[i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 5100
#include <iostream>
#include <cstring>

using namespace std;

int main(){
	int N, T, L, B;
	while(cin >> N >> T >> L >> B, N){
		bool lose[101], back[101];
		memset(lose, false, sizeof(lose));
		memset(back, false, sizeof(back));
		for(int i=0;i<L;i++){
			int idx; cin >> idx; lose[idx] = true;
		}
		for(int i=0;i<B;i++){
			int idx; cin >> idx; back[idx] = true;
		}
		double dp[102][101];
		for(int i=0;i<=T;i++)
			for(int j=0;j<=N;j++) dp[i][j] = 0.0;
		dp[0][0] = 1.0;
		for(int i=0;i<T;i++){
			for(int j=0;j<N;j++){
				for(int k=1;k<=6;k++){
					int pos = j+k<=N ? j+k : N-(j+k-N);
					if(back[pos]) pos = 0;
					dp[i+1+lose[pos]][pos] += dp[i][j]/6;
				}
			}
		}
		double res = 0.0;
		for(int i=1;i<=T;i++) res += dp[i][N];
		printf("%.8lf\n", res);
	}
}

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

#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define rep(i, n) repi(i, 0, n)
#define all(x) (x).begin(), (x).end()

inline void Main() {
  // code
  int p,q,r;
  cin>>p>>q>>r;
  cout<<min(p+q,min(q+r,r+p)) << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(20);
  Main();
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int t1 = sc.nextInt();
		int[] t = new int[n];
		int sum = t1;
		
		t[0] = sc.nextInt();
		
		for(int i=1; i<n; i++){
		    t[i] = sc.nextInt();
		    if(t[i]-t[i-1]<=t1){
            	sum = t[i]-t[i-1] + sum;
            }else{
              	sum = t1+sum;
            }
		}
		
		
      	System.out.println(sum);
    }
}

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

int main() {
  string n,ans="No";
  cin >> n;
  if(n[0]=='7') ans="Yes";
  if(n[1]=='7') ans="Yes";
  if(n[2]=='7') ans="Yes";
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  return gcd(b, a % b);
}


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  long long N, M, d, L, di;

  std::string S, T;

  std::cin >> N >> M >> S >> T;

  L = N * M / (d = gcd(N, M));

  di = N / d * M / d;

  for (long long i = 0; i < L; i += di)
    if (S[i * N / L] != T[i * M / L]) {
      std::cout << -1 << std::endl;

      return 0;
    }

  std::cout << L << std::endl;
  
  return 0;
}


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

int main()
{
	int N, K, X, Y, res = 0;
	cin >> N >> K >> X >> Y;
	for (int i = 1; i <= N; i++) {
		res += i <= K ? X : Y;
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();

            if (x[0] < x[1] && x[1] < x[2])
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}



Measured memory_bytes: 18220
n = input()
a,b = map(int, raw_input().split())
l = map(int, raw_input().split())
cnt1 = 0
cnt2 = 0
cnt3 = 0
for x in l:
	if x <= a:
		cnt1 += 1
	elif x >= b+1:
		cnt3 += 1
	else:
		cnt2 += 1
print min(cnt1, cnt2, cnt3)

Measured memory_bytes: 27884
n,m = map(int, input().split())
like = {i:0 for i in range(1,m+1)}
for i in range(n):
    k,*a = map(int, input().split())
    for j in a:
        like[j]+=1
ans = 0
for i in range(1,m+1):
    if like[i]==n:ans+=1
print(ans)

Measured memory_bytes: 3060
N, K, Q = map(int, input().split())

A = [0] * N
B = []

for i in range(Q):
    a_temp = int(input())
    B.append(a_temp)

for i in B:
    A[i-1] += 1

for i in A:
    if i > Q - K:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 13728
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <string>
 
int main()
{
    int ans, max = 0, min = 1000, n;

    std::cin >> n;
    for(int i = 0;i < n;i++){
        std::cin >> ans;
        if(ans < min){
            min = ans;
        }
        if(ans > max){
            max = ans;
        }
    }

    ans = max - min;

    std::cout << ans;

    return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	vector<int> s(m), c(m);
	for(int i = 0; i < m; i++){
		cin>>s[i]>>c[i]; s[i]--;
	}
	for(int i = 0; i < 1000; i++){
		string str = "";
		int v = i;
		while(v){
			str += char('0' + v%10);
			v /= 10;
		}
		reverse(str.begin(), str.end());
		if(str == "")str = "0";
		if(str.size() != n)continue;
		bool flg = true;
		for(int j = 0; j < m; j++){
			if(str[s[j]] - '0' != c[j])flg = false;
		}
		if(flg){
			cout<<i<<endl;
			exit(0);
		}
	}
	cout<<-1<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

int n,k,ad[1<<21][21];

int distinct(string S) {
    vi tot(2);
    int ans = 1;
    for (char c: S) {
        int t = (ans-tot[c-'0']+MOD)%MOD;
        tot[c-'0'] = (tot[c-'0']+t)%MOD;
        ans = (ans+t)%MOD;
    }
    return ans;
}

bool getBit(int i, int j, int y) {
    return (j>>(i-1-y))&1;
}

int hsh(int i, int j) {
    return (1<<i)^j;
}

void process(int i, int j, int k) {
    if (!k) return;
    int fre = j>>(i-k), fix = j-(fre<<(i-k));
    
    ad[hsh(i-1,((fre>>1)<<(i-k))+fix)][k-1] += ad[hsh(i,j)][k]; // no char
    ad[hsh(i,j)][k-1] += ad[hsh(i,j)][k]; // yes char 
    
    int y = k-2;
    while (y >= 0 && getBit(i,j,y) != getBit(i,j,k-1)) y--;
    if (y >= 0) {
        int ne = fix^(getBit(i,j,y)<<(i-k));
        ne ^= ((j>>(i-y))<< (i-k+1));
        ad[hsh(i-k+1+y,ne)][y] -= ad[hsh(i,j)][k];
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> k;
    F0R(i,n+1) {
        string s; cin >> s;
        F0R(j,1<<i) if (s[j] == '1') ad[hsh(i,j)][i] = 1;
    }
    F0Rd(i,n+1) F0R(j,1<<i) F0Rd(k,i+1) process(i,j,k);
    F0Rd(i,n+1) F0R(j,1<<i) if (ad[j^(1<<i)][0] >= k) {
        string z;
        F0Rd(Z,i) if (j&(1<<Z)) z += "1";
        else z += "0";
        cout << z;
        exit(0);
    }
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)

Measured memory_bytes: 174524
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

vector<ll> enum_div(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i != 1 && i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret;
}

int main(){
    ll N;
    cin>>N;
    vector<ll> K1=enum_div(N);;
    vector<ll> K2=enum_div(N-1);;
    K2.push_back(N-1);
    K2.push_back(N);
    set<ll> st;

    REP(i,K1.size()){
        if(K1[i]==1) continue;
        if(K1[i]==2){
            st.insert(2);
            continue;
        }
        ll k=K1[i];
        ll tmp=N;

        while(tmp>=k){
            if(tmp%k==0){
                tmp/=k;
            }else if(tmp%k==1){
                tmp=1;
                break;
            }else{
                break;
            }
        }
        if(tmp==1) st.insert(k);
    }


    REP(i,K2.size()){
        st.insert(K2[i]);
    }

    cout<<st.size()-1<<endl;
    

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define repr(i, a, b) for (int i = a; i < b; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
#define mod 1000000007

ll gcd(ll x,ll y) {return y ? gcd(y,x%y) : x;} 
ll lcm(ll x,ll y) {return x/gcd(x,y)*y;}

int main(){
    ll n,kabu=0,yen=1000;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    
    for(ll i=0;i<n;i++){
        if(i){
            yen+=kabu*a[i];
            kabu=0;
        }
        if(i==n-1) break;
        if(a[i+1]<=a[i]) continue;
        kabu=yen/a[i];
        yen=yen-kabu*a[i];
    }
    
    cout << yen << endl;

    return 0;
}











Measured memory_bytes: 3628
#include <iostream>
#include <functional>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);++(i))

int n,m,q;

vector<int> edges[101010];

int v[101010];
int d[101010];
int c[101010];

vector<int> dist(101010,-1);
vector<int> color(101010,0);

void dfs(int s,int d,int C){
    if(color[s] == 0) color[s] = C;
    if(d == 0) return;
    for(int to : edges[s]){
        if(dist[to] < d - 1){
            dist[to] = d - 1;
            dfs(to,d - 1,C);
        }
    }
}


int main(){
    cin >> n >> m;
    for(int i = 0;i < m;i++)
    {
        int a,b;
        cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    cin >> q;
    for(int i = q - 1;i >= 0;i--){
        cin >> v[i] >> d[i] >> c[i];
    }

    for(int i= 0;i < q;i++){
        if(dist[v[i]] < d[i]){
            dist[v[i]] = d[i];
            dfs(v[i],d[i],c[i]);
        }
    }

    for(int i = 1;i <= n;i++){
        cout << color[i] << endl;
    }
}



Measured memory_bytes: 8440
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}

struct Time{
    int h,m,s;
    Time(int _h,int _m,int _s) : h(_h),m(_m),s(_s) {}
    Time() {}
};

ostream& operator<<(ostream& os,Time t){
    os << t.h << " " << t.m << " " << t.s;
    return os;
}

long to_long(Time t){
    return t.h*3600 + t.m * 60 + t.s;
}

Time to_time(long t){
    int h = t / 3600;
    t -= 3600*h;
    int m = t / 60;
    t -= 60*m;
    int s = t;
    return Time(h,m,s);
}

Time diff(Time a,Time b){
    return to_time(to_long(b) - to_long(a));
}

int main(){
    for(int i=0;i<3;i++){
        Time f,t;
        cin >> f.h >> f.m >> f.s >> t.h >> t.m >> t.s;
        cout << diff(f,t) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int w,h;
int is(int x,int y){
	return (x>=0 && x < w && y>=0 && y< h)?1:0;
}
int main(void){
	const int dx[4]={0,-1,0,1};
	const int dy[4]={-1,0,1,0};
	int qx[100000];
	int qy[100000];
	int p,mx;
    int n,m[101][101]={0};
    int xs,ys,xg,yg,a,c,d,x,y,cnt,f;
	for(;;){
		scanf("%d %d",&w,&h);
		//printf("%d %d\n",w,h);
		if(w==0)break;
		for(int i=0;i<w;i++){
			for(int j=0;j<h;j++){
				m[i][j]=0;
			}
		}
		scanf("%d %d %d %d",&xs,&ys,&xg,&yg);
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			for(int j=0;j<(d==0?2:4);j++){
				for(int k=0;k<(d==0?4:2);k++){
					m[x-1+k][y-1+j]=c;
				}
			}
		}
		c = m[xs-1][ys-1];
/**		if(c==0){
			puts("NG");
			continue;
		}//**/
		p=0;
		mx=1;
		qx[0]=xs-1;
		qy[0]=ys-1;
		m[xs-1][ys-1]=-1;
		f=1;
/**
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("%3d",m[j][i]);
			}
			puts("");
		}
				printf("%d\n",c);
				/**/
		while(f==1 && p<mx){
			cnt = 0;
			for(int i=0;i<4;i++){
				x = qx[p] + dx[i];
				y = qy[p] + dy[i];
				if(is(x,y)==1 && m[x][y] == c){
					m[x][y]=-1;
					qx[mx+cnt] = x;
					qy[mx+cnt] = y;
					cnt++;
					if(x == xg-1 && y == yg-1)f=0;
					//printf("%d %d にいるよ,%d\n",x+1,y+1,i);
				}
			}
			mx += cnt;
			p++;
		}/**
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				printf("%3d",m[j][i]);
			}
			puts("");
		}
				printf("%d\n",c);
				/**/

		puts(f?"NG":"OK");
	}
    return 0;
}

Measured memory_bytes: 1072
#include <iostream> // cout, endl, cin
#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

#define lint long long

using namespace std;

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

  for(int i=0;i<s.size();i++){
    cout << 'x';
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <bitset>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007; //998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}


static LLONG dfs(std::string& str, int nowd, int digit, int N)
{
	LLONG ans = 0;
	char num[] = { '0', '3', '5', '7' };
	if (nowd == digit) {
		for (int i = 0; i < 4; i++) {
			str[nowd - 1] = num[i];
			bool search = false;
			bool b3, b5, b7;
			b3 = b5 = b7 = false;
			for (int i = 0; i < digit; i++) {
				if (str[i] != '0') {
					search = true;
				}
				else if (search) {
					b3 = b5 = b7 = false;
					break;
				}

				switch (str[i]) {
				case '3':
					b3 = true;
					break;
				case '5':
					b5 = true;
					break;
				case '7':
					b7 = true;
					break;
				}
			}
			if (b3 && b5 && b7) {
				if (strtol(str.c_str(), 0, 10) <= N) {
					ans++;
				}
			}
		}
	}
	else {
		for (int i = 0; i < 4; i++) {
			str[nowd - 1] = num[i];
			ans += dfs(str, nowd + 1, digit, N);
		}
	}
	return ans;
}

static void exec()
{
	LLONG N;
	get(N);

	std::string num;
	LLONG tmp = N;
	int digit = 0;
	while (tmp) {
		digit++;
		tmp /= 10;
		num += '0';
	}
	printf("%lld\n", dfs(num, 1, digit, N));
}


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
ll ans = 0;
vector< int > z_algorithm(const string &s) {
  vector< int > prefix(s.size());
  for(int i = 1, j = 0; i < s.size(); i++) {
    if(i + prefix[i - j] < j + prefix[j]) {
      prefix[i] = prefix[i - j];
    } else {
      int k = max(0, j + prefix[j] - i);
      while(i + k < s.size() && s[k] == s[i + k]) ++k;
      prefix[i] = k;
      j = i;
    }
  }
  prefix[0] = (int) s.size();
  return prefix;
}
int main()
{
ll n ;
cin >> n ;
string s ;
cin >> s ;

rep(i,n){
  auto v=z_algorithm(s);
  rep(j,v.size()-1){
    if(j>=v[j+1]-1)
    ans=max((int)ans,v[j+1]);
  }
  s.erase(0,1);
}
cout << ans << endl;
return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef  long long LL;
typedef  unsigned long long ULL;
typedef  double db;
typedef  long double ld;
#pragma comment(linker, "/STACK:102400000,102400000")
#define fuck(x) cout<<x<<endl
#define fuck1(x,y) cout<<x<<" "<<y<<endl
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
#define MP(a,b) make_pair(a,b)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
const int INF = 0x3f3f3f3f3f,mod = 1e9+7;
const double eps  =1e-6,PI = acos(-1);
template<typename T> inline void read(T &x){
    x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
LL A,B,C,D;
LL get_ans(LL A){
    LL num1,num2,num3,num4;
    num1 = A/C;
    num2 = A/D;
    num3 = A/(C*D/__gcd(C,D));
    num1 = num1+num2-num3;
    return num1;
}
int main(){
    cin>>A>>B>>C>>D;
    cout<<B-A+1-(get_ans(B) - get_ans(A-1))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(100000,0);
  rep(i,n){
    cin >> a.at(i);
  }
  rep(i,n){
    b.at(a.at(i))++;
  }
  int ans=0;
  for(int i=1;i<100000-1;i++){
    int maxi=b.at(i-1)+b.at(i)+b.at(i+1);
    ans=max(maxi,ans);
  }
  cout << ans;
}

Measured memory_bytes: 1024
n,m = gets.split.map(&:to_i)
a,b,c = 3.times.map{Array.new(m)}
m.times do |i|
    a[i],b[i],c[i] = gets.split.map(&:to_i)
end
$score = Array.new(n+1,-10**15)
$score[1] = 0

def bellmanford(a,b,c,n,m)
    n.times do
        m.times do |i|
            $score[b[i]] = $score[a[i]]+c[i] if $score[b[i]] < $score[a[i]]+c[i]
        end
    end
end

bellmanford(a,b,c,n,m)
ans = $score[n]
bellmanford(a,b,c,n,m)
if ans == $score[n]
    puts ans
else
    puts "inf"
end

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

int main(void)
{
	int n;
	scanf("%d",&n);
	int i,temp=n,f=0;
	for(i=100000000;i >= 1;i /= 10)
		{
		f += temp/i;
		temp %= i;
		//printf("i=%d f=%d temp=%d\n",i,f,temp);
		}

	if(n % f == 0)
		{printf("Yes\n");}
	else
		{printf("No\n");}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
int N ;
cin >>N;
N= N%10;
if(N==2 ||N==4 ||N==5 ||N==7 ||N==9) cout << "hon" << endl;
if(N==0 ||N==1 ||N==6 ||N==8) cout << "pon" << endl;
if(N==3) cout << "bon" << endl;

    return 0;
}

Measured memory_bytes: 3624
/*
Author :: Shahadat Hossain Nirob
............SUST_MATH14..........
*/
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <vector>

#define Long long long
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define II() ( { int a ; read(a) ; a; } )
#define LL() ( { Long a ; read(a) ; a; } )
#define DD() ({double a; scanf("%lf", &a); a;})
#define DB if(0) 
#define D(x) cout << #x " is " << x << endl
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef vector<PII> VII;
typedef vector<string> VS;

const int INF = 2000000009;
const int MX = 200005;
const double EPS = 1e-9;
const int MOD = 1000000007;

template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }

template<class T>inline bool read(T &x){
    int c=getchar();int sgn=1;
    while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}
    for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; 
    x*=sgn; return ~c;
}

#define nl puts ("")
#define sp printf ( " " )
#define phl printf ( "hello\n" )
#define ff first
#define ss second
#define POPCOUNT __builtin_popcountll
#define RIGHTMOST __builtin_ctzll
#define LEFTMOST(x) (63-__builtin_clzll((x)))
#define MP make_pair
#define FOR(i,x,y) for(vlong i = (x) ; i <= (y) ; ++i)
#define ROF(i,x,y) for(vlong i = (y) ; i >= (x) ; --i)
#define CLR(x,y) memset(x,y,sizeof(x))
#define UNIQUE(V) (V).erase(unique((V).begin(),(V).end()),(V).end())
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define NUMDIGIT(x,y) (((vlong)(log10((x))/log10((y))))+1)
#define SQ(x) ((x)*(x))
#define ABS(x) ((x)<0?-(x):(x))
#define FABS(x) ((x)+eps<0?-(x):(x))
#define ALL(x) (x).begin(),(x).end()
#define LCM(x,y) (((x)/gcd((x),(y)))*(y))
#define SZ(x) ((vlong)(x).size())
#define NORM(x) if(x>=mod)x-=mod;
#define MOD(x,y) (((x)*(y))%mod)
#define ODD(x) (((x)&1)==0?(0):(1))

typedef string st;
typedef vector<st> vs;
#define rep(i, n) for(int i = 0; i < n; i++)
#define fogg(i,a,b) for(int i = (a); i <= (b); i++)
#define ford(i,a,b) for(int i = (a); i >= (b); i--)
#define test int t; cin >> t; while(t--)

#define endl '\n'
#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main()
{
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif*/
    
    string s;
    cin >> s;
    int init=0;
    rep(i,4)
    {
    	if(s[i]=='+') init++;
    	else init--;
    }
    cout << init << endl;
	
	return 0;
}



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

using ll = long long;

int main()
{
    int A,  B;
    vector<bool> ch(4, false);
    cin >>A >> B;
    ch.at(A) = true;
    ch.at(B) = true;
    for(int i = 1; i<4; i++){
        if(ch.at(i)==false){
            cout << i << endl;
            return 0;
        }
    }
}

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

int main(){

int N,C,m = 0;

cin>>N>>C;

for (int i = 0; i < C; i++) {
        int p;
        cin >> p;
        m += p;
    }
 
    cout << (m + N) / (N + 1) << endl;
 
    return 0;
}


Measured memory_bytes: 3136
#include <cstdio>
#include <cstring>
#include <cstdlib>
using namespace std;

const int x[] = {0, 1, 2, 0, 1, 2, 0, 1, 2};
const int y[] = {0, 0, 0, 1, 1, 1, 2, 2, 2};

int main()
{
	char str[128];
	while (scanf("%s", str) != EOF){
		int len = strlen(str);
		
		bool f = true;
		for (int i = 1; i < len; i++){
			if (
			abs(x[str[i - 1] - 'A'] - x[str[i] - 'A']) + 
			abs(y[str[i - 1] - 'A'] - y[str[i] - 'A']) != 1
			){
				f = false;
				break;
			}
		}
		
		if (f){
			printf("%s\n", str);
		}
	}
	
	return 0;
}

Measured memory_bytes: 952
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <sstream>
#include <cmath>
#include <functional>
#include <fstream>
#include <cstdlib>
typedef long long ll;
const int MOD = 1e9+7;


#define REP(i, N) for (int i = 0; i < (N); i++)
#define REPP(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define VSORT(c) sort((c).begin(),(c).end())
#define SZ(x) ((int)(x).size())
//vvintを作る　マクロで　 #define vvint(N,M) vector<vector<int>>

using namespace std;


int main(){
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<string> v;
    for(int i = 0; i < n;i++){
        string tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    sort(ALL(v));
    ll cnt=0;
    string s = v[0];
    int ma=0;
    vector<string> ans;
    for(int i = 0; i < v.size();i++){
        if(s == v[i]){
            cnt++;
        }else{
            cnt = 1;
            s = v[i];
        }
        if(ma < cnt){
            ma = cnt;
            ans.clear();
            ans.push_back(s);
        }else if(ma == cnt){
            ans.push_back(v[i]);
        }
    }
    for(int i = 0; i < ans.size();i++){
        cout << ans[i] << endl;
    }
    

    return 0;
}

Measured memory_bytes: 14832
#include<cstdio>
char s[105][105];

int main(){
    int a,b;
    scanf("%d%d",&a,&b);
    for(int i = 1; i <= 100; i++){
        for(int j = 1; j <= 100; j++){
            if(j<=50) s[i][j] = '#';
            else s[i][j] = '.';
        }
    }
    a--, b--;
    for(int i = 2; i <= 99; i += 2){
        for(int j = 2; j <= 49; j += 2){
            if(a!=0) s[i][j] = '.', a--;
        }
    }
    for(int i = 2; i <= 99; i+=2){
        for(int j = 52; j <= 99; j+=2){
            if(b!=0) s[i][j] = '#', b--;
        }
    }
    printf("%d %d\n",100,100);
    for(int i = 1; i <= 100; i++){
        for(int j = 1; j <= 100; j++) printf("%c",s[i][j]);
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 1744
import           Data.Maybe
import qualified Data.ByteString.Char8         as C8

getInts :: IO [Int]
getInts = fmap (map (fst . fromJust . C8.readInt) . C8.words) C8.getLine

main :: IO ()
main = do
    [n, k] <- getInts
    print
        $ ((n `div` k) ^ 3)
        + ((if even k then (n + k `div` 2) `div` k else 0) ^ 3)


Measured memory_bytes: 380
#include <iostream>
#include <vector>
#include <functional>

using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;
    vector<vector<int>> E(N);
    for (int i=0; i<M; i++)
    {
        int A, B;
        cin>>A>>B;
        E[A-1].push_back(B-1);
        E[B-1].push_back(A-1);
    }
    vector<int> X(N);

    function<bool(int, int, int)> f = [&](int c, int p, int x)
    {
        if (X[c]==x)
            return true;
        if (X[c]==-x)
            return false;
        X[c] = x;
        for (int e: E[c])
        if (e != p)
            if (!f(e, c, -x))
                return false;
        return true;
    };

    if (f(0, -1, 1))
    {
        int c1 = 0;
        int c2 = 0;
        for (int x: X)
            (x == 1 ? c1 : c2)++;
        cout<<(long long)c1*c2 - M<<endl;
    }
    else
    {
        cout<<(long long)N*(N-1)/2 - M<<endl;
    }
}


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

int main(){
    long long n, t[100010], x[100010], y[100010];

    cin >> n;
    t[0] = x[0] = y[0] = 0;

    for(int i = 0;i < n;i++){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    for(int i = 0;i < n;i++){
        long long move = abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        if(!(move <= t[i+1]-t[i] && ((t[i+1]-t[i])-move) % 2 == 0)){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

int main(){

  int n, m;
  cin >> n >> m;

  int a[n], b[n], c[m], d[m];

  for (int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }

  for (int i = 0; i < m; i++){
    cin >> c[i] >> d[i];
  }

  int x, y;
  int px, py;

  int checkpoint;
  int min_mandis;
  int mandis;

  for (int i = 0; i < n; i++){
    min_mandis = 400000000;
    x = a[i];
    y = b[i];
    for (int j = 0; j < m; j++){
      px = c[j];
      py = d[j];
      mandis = abs(x - px) + abs(y - py);
      if (mandis < min_mandis){
        min_mandis = mandis;
        checkpoint = j;
      }
    }
    cout << checkpoint + 1 << endl;
  }

  return 0;
}


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

#define rep(i,n) for(ll (i)=0;(i)<(ll)(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
typedef long long ll;

using namespace std;


signed main() {
	vector<ll> v('z'+1, 0);
	char a;
	while (1) {
		cin >> a;
		if (cin.eof()) break;
		if ('a' <= a && a <= 'z') {
			v[a]++;
		}
		if ('A' <= a && a <= 'Z') {
			v[a-('A'-'a')]++;
		}
	}

	for (int i = 'a'; i <= 'z'; i++) {
		char str = i;
		cout << str << " : " << v[i] << endl;
	}
}


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
int main(){
    string o,e;
    cin>>o;
    cin>>e;
    string ans="";
    int ln=o.size()+e.size();
    ans.resize(ln);
    for(int i=0;i<ln;i++){
        if(i%2==0) ans.at(i)=o.at(i/2);
        if(i%2==1) ans.at(i)=e.at(i/2);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
data class Tuple(val a: Long, val b: Int): Comparable<Tuple> {
    override fun compareTo(other: Tuple): Int =
        a.compareTo(other.a).let {
            if (it == 0) b.compareTo(other.b) else it
        }
}

fun main(args: Array<String>) = IO().println {
    val n = int()
    val a = Array(n){Pair(long(), it)}
    val sum = a.map { it.first }.sum()
    val b = Array(n){ Tuple(Math.abs(a[it].first * n - sum), a[it].second) }
    b.sort()
    b[0].b
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }

    inline fun println(block: IO.() -> Any) {
        println(block())
        out.flush()
    }
}
// endregion

Measured memory_bytes: 33744
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i;
    cin>>n;
    int s[n],sum=0,cnt=0;
    for (i=0;i<n;i++)
    {
        cin>>s[i];
        sum+=s[i];
        if (s[i]%10==0)
            cnt++;
    }
    if (cnt==n)
        cout<<"0\n";
    else if (sum%10!=0)
        cout<<sum<<endl;
    else
    {
        sort(s,s+n);
        for (i=0;i<n;i++)
        {
            if (s[i]%10!=0)
            {
                cout<<sum-s[i]<<endl;
                break;
            }
        }
    }
}

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

 int main(){
     int A,B,C,X,Y,Z,L;
    cin >> X >> Y >>Z;
    A = X;
    B = Y;
    C = Z;
    
    L = A; // 1
    A = B; // 2
    B = L; // 1
    L = A;
    A = C; // 3
    C = L;
    cout << A << ' ' << B << ' ' << C << endl;
 }

Measured memory_bytes: 256