akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<set>
#include<queue>
#include<stack>
#include<vector>
#define rep(i,l,r) for(int i=l;i<r;i++)
const int MOD=1e9+7;
using namespace std;
int main()
{
	char a[53],b[53];
	int n,it,f;
	cin>>n;
	cin>>a>>b;
	long long sum;
	if(a[0]==b[0])
	{
		sum=3;
		it=1;
		f=1;
	}
	else
	{
		sum=6;
		it=2;
		f=2;
	}
	while(it<n)
	{
		if(a[it]==b[it])
		{
			it++;
			if(f==1)
			sum=(sum*2)%MOD;
			f=1;
		}
		else
		{
			it+=2;
			if(f==1)
			{
				sum=(sum*2)%MOD;
			}
			else
			{
				sum=(sum*3)%MOD;
			}
			f=2;
		}
	}
	cout<<sum<<endl;
	return 0;
} 

Measured memory_bytes: 256
n, m = map(int, input().split())
if m%2 == 1:
  # for i in range(m):
  #   print(str(i+1) + ' ' + str(2*m-i))
  for i in range(int((m-1)/2)):
    print(str(i+1) + ' ' + str(m-i))
  for i in range(int((m+1)/2)):
    print(str(m+i+1) + ' ' + str(2*m-i+1))
else:
  for i in range(int(m/2)):
    print(str(i+1) + ' ' + str(m-i+1))
  for i in range(int(m/2)):
    print(str(i+m+2) + ' ' + str(2*m-i+1))

Measured memory_bytes: 9224
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
	  String s=sc.next();
	  int r=0,b=0;
	  for(int i=0;i<s.length();i++) {
		  if(s.substring(i, i+1).equals("0"))r++;
		  else b++;
	  }
	  System.out.println(Math.min(r, b)*2);
  }
}



Measured memory_bytes: 30360
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e6+2;
const int mod=1e9+7;
const int inf=(int)(1e19+10LL);
void solve(){
	string str;
	sl(str);
	int cnt[2];

	cnt[0]=0,cnt[1]=0;
	int n=str.size();
		int ans[n+1];
	ms(ans,0);
	char curr='R';
	int lastpair=-1;
	for(int i=0;i<n;i++){
		if(str[i]==curr){
			cnt[i%2]++;
		}
		else{
			if(str[i]=='L'){
				lastpair=i-1;
				ans[lastpair]+=cnt[lastpair%2];
				ans[lastpair+1]+=cnt[(lastpair+1)%2];
			}
			else{
				ans[lastpair]+=cnt[lastpair%2];
				ans[lastpair+1]+=cnt[(lastpair+1)%2];
			}
			cnt[0]=0;
			cnt[1]=0;
			cnt[i%2]++;
			curr=str[i];
		}
	}
	ans[lastpair]+=cnt[lastpair%2];
	ans[lastpair+1]+=cnt[(lastpair+1)%2];
	for(int i=0;i<n;i++)cout<<ans[i]<<" ";
	
	
 
}

signed main(){
  int test=1;
  //sl(test);
 while(test--){
 	solve();
 }
 
}

Measured memory_bytes: 1408
#include <iostream>

#include <boost/lexical_cast.hpp>

bool is_heisei(const int y, const int m, const int d) {
  if (y < 2019) {
    return true;
  }
  if (y == 2019 && m < 4) {
    return true;
  }
  if (y == 2019 && m == 4 && d < 31) {
    return true;
  }
  return false;
}

int main(int argc, char *argv[]) {
  std::string s;
  std::cin >> s;

  if (is_heisei(boost::lexical_cast< int >(s.substr(0, 4)),
                boost::lexical_cast< int >(s.substr(5, 2)),
                boost::lexical_cast< int >(s.substr(8, 2)))) {
    std::cout << "Heisei" << std::endl;
  } else {
    std::cout << "TBD" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k,a,b;
    cin>>k>>a>>b;
    if(a%k==0||b%k==0||b/k-a/k>0)cout<<"OK";
    else cout<<"NG";
    return 0;
}


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

int main(){

  int n;
  int a[1000][1000],b;

  while(cin >> n, n){

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

    for(int i=0;i<n;i++){
      b = 0;

      for(int j=0;j<n;j++) b += a[i][j];

      a[i][n] = b;

    }

    for(int j=0;j<n;j++){
      b = 0;

      for(int i=0;i<n;i++) b += a[i][j];

      a[n][j] = b;

    }

    b = 0;
    for(int i=0;i<n;i++) b += a[i][n];
    a[n][n] = b;

    for(int i=0;i<=n;i++){
      for(int j=0;j<=n;j++) printf("%5d",a[i][j]);
      cout << endl;
    }

  }
}

Measured memory_bytes: 1236
p['   '];t['   '];n,x,k,j;main(i){for(;i++<1e6;)for(x=i;x<1e6;p[x+=i]=1);for(;scanf("%d%d",&n,&x)*n;memset(t,0,4e6)){for(*t=1;n--;)for(i=-scanf("%d",&k);++i<x;)t[i]&&++t[i+k];for(;p[x]|!t[x];x--);printf(x<2?"NA\n":"%d\n",x);}}

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if(a<b) swap(a,b);
	if(a<c) swap(a,c);
	if(b<c) swap(b,c);
	if(a==b&&a!=c&&b!=c||b==c&&b!=a&&c!=a)
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
function Main(input) {
    input = input.trim()
  input = input.split("");
  input.sort();
  if(input[0]==input[1]&&input[2]==input[3]&&input[1]!==input[2]) console.log("Yes")
  else console.log("No")
}Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7500
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = [-1] + list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

left_gcd = [0] + [0] * n + [-1]
right_gcd = [-1] + [0] * n + [0]

for i in range(n):
    left_gcd[i + 1] = gcd(left_gcd[i], a[i + 1])
    right_gcd[n - i] = gcd(right_gcd[n - i + 1], a[n - i])

ans = 1
for i in range(1, n+1):
    ans = max(ans, gcd(left_gcd[i-1], right_gcd[i+1]))
print(ans)


Measured memory_bytes: 20448
#ifndef CLion
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/numeric>

#define F first
#define S second
#define pb push_back
#define ll long long
#define all(x) x.begin() , x.end()
#define rep(i,s,e) for (int i = s; i < e; ++i)
#define rev(i,s,e) for (int i = s; i > e; --i)
#define mem(a,v) memset(a , v , sizeof a)
//#define mod(x,m) ((x%m + m)%m)
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;


void Main(int cse , bool last){
    int n; cin >> n;
    vector<ll> vec(n);
    for ( ll& i : vec ) cin >> i;
    vec.pb(-1);

    ll cnt = 1000 , buy = -1;
    rep(i,1,n+1){
        if ( vec[i] >= vec[i - 1] ){
            if (buy == -1) buy = vec[i - 1];
        }
        else if ( ~buy ){
            ll div = cnt / buy;
            cnt -= div * buy;
            cnt += div * vec[i - 1];
            buy = vec[i];
        }
    }
    cout << cnt;
}

int main(){
#ifndef CLion
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
#ifdef CLion
    freopen( "in.txt" , "r" , stdin  );
//    freopen( "out.txt", "w" , stdout );
    clock_t st = clock();
#endif

    int t = 1;
//    cin >> t;
    for ( int cse = 1; cse <= t; ++cse ) Main(cse, cse == t);

#ifdef CLion
    clock_t en = clock();
    cout << "\n\nTime: " << fixed << (en - st - 0.0) / CLOCKS_PER_SEC;
#endif
    return 0;
}


Measured memory_bytes: 3660
n = int(input())
p_t, p_x, p_y = 0, 0, 0

available = True

for i in range(n) :
	t, x, y = map(int, input().split())
	judge = (t - p_t) - ( abs(x - p_x) + abs(y - p_y) )
	if judge < 0 or judge % 2 != 0 :
		available = False
		break
	p_t, p_x, p_y = t, x, y

if available :
	print('Yes')
else :
	print('No')


Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
string s;
void Rev(int i,int j){
    while(i<j){
        swap(s[i],s[j]);
        i++,j--;
    }
}
int main()
{
    cin>>s;
    int len=s.length();
    if(len==2){
        cout<<s<<endl;
    }else{
        Rev(0,len-1);
        cout<<s<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		long[] cnt = new long[5]; // 'M','A','R','C','H'

		for (int i = 0; i < n; i++) {
			String name = sc.next();
			switch (name.charAt(0)) {
			case 'M':
				cnt[0]++;
				break;
			case 'A':
				cnt[1]++;
				break;
			case 'R':
				cnt[2]++;
				break;
			case 'C':
				cnt[3]++;
				break;
			case 'H':
				cnt[4]++;
				break;
			default:
				break;
			}
		}

		long ans = 0;
		for (int i = 0; i < cnt.length - 2; i++) {
			for (int j = i + 1; j < cnt.length - 1; j++) {
				for (int k = j + 1; k < cnt.length; k++) {
					ans += cnt[i] * cnt[j] * cnt[k];
				}
			}
		}

		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 44992
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

int main(){
	int n,a[2],b[2];
	int r=0,x,y,t;
	scanf("%d",&n);
	rep(i,2)scanf("%d%d",a+i,b+i);
	rep(i,2){a[i]--;b[i]--;}
	reps(i,1,n){
		t=0;
		rep(j,2)t+=abs(a[j]%i-b[j]%i) + abs(a[j]/i-b[j]/i);
		if(r)r=min(r,t);
		else r=t;
	}
	printf("%d\n",r);
	return 0;
}

Measured memory_bytes: 1188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
int main()
{
    int x,y;
    cin>>x>>y;
    cout<<x + y/2<<endl;
}












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

int main() {
  string S;
  vector<int> vec(26);
  bool answer =true;
  cin >> S;
  
  for(int i=0;i<S.size();i++){
    int num;
    num = S.at(i)-'a';
    vec.at(num) +=1;
  }
  
  for(int i=0;i<26;i++){
    if(vec.at(i)%2==1)
      answer = false;
  }
  
  if(answer == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}



Measured memory_bytes: 256
from math import cos, sin, pi

def show(p):
    print(f'{p.real:.08} {p.imag:.08}')

def rotate(p, theta):
    return p*complex(cos(theta), sin(theta))

def go(n, p1, p2):
    if n == 0:
        return
    s = (p2 - p1)/3 + p1
    t = 2*s - p1
    u = rotate(t - s, pi/3) + s
    go(n - 1, p1, s)
    show(s)
    go(n - 1, s, u)
    show(u)
    go(n - 1, u, t)
    show(t)
    go(n - 1, t, p2)


p1 = complex(0, 0)
p2 = complex(100, 0)
show(p1)
go(int(input()), p1, p2)
show(p2)


Measured memory_bytes: 5776
#include <stdio.h>
 
int rot[5][7] = {
{0,1,2,3,4,5,6},{0,2,6,3,4,1,5},{0,4,2,1,6,5,3},{0,3,2,6,1,5,4},{0,5,1,3,4,6,2}};
int assign[7];      // サイコロの1～6の各面に割り当てる数字
int tr['Z'];
 
void dice_init(int *a)
{
    int i;
    int t[5] = {0,'N','E','W','S'};
    for (i = 1; i <= 6; i++) assign[i] = a[i];
    for (i = 1; i <= 4; i++) tr[t[i]] = i;
}
 
char s[102];
int main()
{
    int i, k1, k2;
    int a[7], dice[2][7];
    char *p;
 
    for (i = 1; i <= 6; i++) scanf("%d", a+i);
    dice_init(a);
    scanf("%s", p=s);
    for (i = 1; i <= 6; i++) dice[0][i] = rot[0][i];
    for (k1 = 0, k2 = 1; *p; k1 = k2, k2 = !k2) {
        for (i = 1; i <= 6; i++) dice[k2][i] = dice[k1][rot[tr[*p]][i]];
        p++;
    }
    printf("%d\n", assign[dice[k1][1]]);
    return 0;
}


Measured memory_bytes: 2056
N,K=map(int,input().split())
x=list(map(int,input().split()))

ans=float('inf')
for i in range(N-K+1):
  ans=min(ans,abs(x[i])+abs(x[i+K-1]-x[i]),abs(x[i+K-1])+abs(x[i+K-1]-x[i]))
print(ans)

Measured memory_bytes: 14252
#include <stdio.h>

int main (void)
{
  int a , b , flag = 0;
  scanf("%d %d",&a,&b);
  
  char s[11];
  scanf("%s",s);
  
  for(int i = 0;s[i]!='\0';i++){
    if(i==a){
      if(s[i]!='-'){
        flag++;
        break;
      }}
    else{
      if(s[i]=='-'){
        flag++;
        break;
      }}
  }
  if(flag==0){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>

using namespace std;
int main() {
	int n, m, A[1010101], a = 0;
	cin >> n >> m;

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

	m -= a;
	sort(A, A + n);
	cout << (m / A[0]) + n << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()

map<int, int> mapA, mapB;
int n;
vector<int> a, b;
vector<bool> p;
int x;

void dfs(int now, int cnt)
{
	if (p[now])
	{
		x = cnt;
		return;
	}

	p[now] = true;
	dfs(mapB[mapA[a[now]]], cnt + 1);
}


int main()
{
	cin >> n;
	a.resize(n), b.resize(n), p.resize(n);
	vector<int> sa(n), sb(n);
	rep(i, 0, n - 1)
	{
		cin >> a[i];
		sa[i] = a[i];
	}
	rep(i, 0, n - 1)
	{
		cin >> b[i];
		sb[i] = b[i];
		mapB[b[i]] = i;
	}
	sort(all(sa));
	sort(all(sb));
	bool ok = false;
	rep(i, 0, n - 1)
	{
		mapA[sa[i]] = sb[i];
		if (sa[i] > sb[i])
		{
			cout << "No" << endl;
			return 0;
		}
		if (0 < i&&sa[i] <= sb[i - 1])ok = true;
	}

	rep(i, 0, n - 1)
	{
		if (mapB[mapA[a[i]]] == i)ok = true;
	}

	dfs(0, 0);
	if (x != n)ok = true;

	if (ok)cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#define lol long long
#define mp(x,y) make_pair(x,y)
using namespace std;

// const int mod=1e9+7;

/*  author: H3XoRuSH  */

signed main() {
    ios_base::sync_with_stdio(false);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    lol N,a;
    cin >> N;
    lol x[N],dp[N];
    for(lol i=0; i<N; i++) cin >> x[i];
    for(lol i=0; i<N; i++){
        if(i==0) dp[i]=0;
        else if(i==1) dp[i]=abs(x[i]-x[i-1]);
        else dp[i]=min(dp[i-2]+abs(x[i]-x[i-2]),dp[i-1]+abs(x[i]-x[i-1]));
    }
    cout << dp[N-1];
    return 0;
}


Measured memory_bytes: 1792
#import<atcoder/all>
int N,Q,i,a;main(){std::cin>>N>>Q;atcoder::fenwick_tree<long>b(N);for(;i++<N;b.add(i-1,a))std::cin>>a;for(;std::cin>>i>>a>>N;Q--){i&&std::cout<<b.sum(a,N)<<'\n';if(!i)b.add(a,N);}}

Measured memory_bytes: 8204
package main

import "fmt"

func main() {
	var N int
	fmt.Scan(&N)

	var s []string

	for i := 0; i < N; i++ {
		var tmp string
		fmt.Scan(&tmp)
		s = append(s, tmp)
	}

	m := make(map[string]struct{})

	delDup := make([]string, 0)

	for _, e := range s {
		_, ok := m[e]
		if !ok {
			m[e] = struct{}{}
			delDup = append(delDup, e)
		}
	}

	fmt.Println(len(delDup))
}


Measured memory_bytes: 32452
'''
V, E : Vは頂点数、Eは辺数
nodes : e = [from, to, cost] を要素とする辺のリスト（有向辺）
☆負のループがあっても、それがゴールと非連結な場所にあった場合関係ない。
つまり「0→負のループ→N-1」という経路が存在するときのみ問題になる。
0→負のループ、という経路があるかどうかは0からの距離がfloat('inf')でないことで調べられる
負のループのある点→N-1という経路があるかどうかは、更新の際にnegative[i]から辺が伸びている頂点も更新することで調べられる。
'''
V, E = map(int, input().split())
nodes = []
for _ in range(E):
    e_from, e_to, e_cost = map(int, input().split())
    e_from -= 1
    e_to -= 1 #頂点を0-indexedに
    e_cost *= -1
    nodes.append([e_from, e_to, e_cost])

d = [float('inf')] * V
negative = [False] * V
d[0] = 0
for _ in range(V):
    for e in nodes:
        if d[e[0]] != float('inf') and d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
for _ in range(V):
    for e in nodes:
        if d[e[0]] != float('inf') and d[e[1]] > d[e[0]] + e[2]:
            d[e[1]] = d[e[0]] + e[2]
            negative[e[1]] = True
        if negative[e[0]]:
            negative[e[1]] = True

if negative[V - 1]:
    print('inf')
else:
    print(- d[V - 1])

Measured memory_bytes: 47832
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 400010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<int> cnt(3,0);
    bool ok = 1;
    rep(i,s.length()){
        cnt[s[i]-'a']++;
    }
    rep(i,3){
        if (abs(cnt[i%3]-cnt[(i+1)%3]) > 1) ok = 0;
    }
    if (ok) PRINT("YES");
    else PRINT("NO");
}


Measured memory_bytes: 512
def myAnswer(N:int,W:list) -> str:
   lis =[W[0]]
   pre = W.pop(0)[-1]
   for word in W:
      if(pre == word[0] and (word in lis)==False):
         lis.append(word)
         pre = word[-1]
      else:
         return "No"
   return "Yes"

def modelAnswer():
   tmp=1
def main():
   N = int(input())
   W=[]
   for _ in range(N):
      W.append(input())
   print(myAnswer(N,W[:]))

if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
ll dot_read(string s){
  ll c = 0;
  for(auto i:s){
    if(i!='.') break;
    c++;
  }
  return c;
}
void solve(){
  ll n;
  bool sign[1500]={};
  cin >> n;
  if(n==0) return;
  vector<string> s(n);
  for(int i=0;i<n;i++){
    cin >> s[i];
  }
  for(int i=0;i<n;i++){
    ll dots = dot_read(s[i]),len;
    len = s[i].size();
    if(sign[dots]){
      sign[dots] = false;
    }
    for(int j=i+1;j<n;j++){
      ll nl = dot_read(s[j]);
      if(nl==dots){
        sign[dots] = true;
        break;
      }else if(nl<dots){
        break;
      }
    }
    for(int j=0;j<dots;j++){
      if(j==dots-1){
        cout <<"+";
      }else if(sign[j+1]){
        cout << "|";
      }else{
        cout <<" ";
      }
    }
    for(int j=dots;j<len;j++){
      cout << s[i][j];
    }
    cout << endl;
  }
  solve();
}
signed main(){
  init_io();
  solve();
}



Measured memory_bytes: 9160
program beki
  implicit none

  integer :: x, n, p, b

  read(*,*) x

  n = 1
  if (x < 4 ) then
     n = 1
  else
     do b = 2, x-1
        p = 2
        do while ( b**p <= x )
         
           if ( n < b**p ) then
              n = b**P
           end if
           p = p + 1
        end do
     end do
  end if
  write(*,*) n
     
  stop
end program beki
  

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

long long combi(int n, int r);

int main()
{
	int n, a, b;
	long long v[50]{};
	scanf("%d%d%d", &n, &a, &b);
	for (int i = 0; i < n; i++)
		scanf("%lld", v + i);
	std::sort(v, v + n, std::greater<long long>());

	double ave{};
	for (int i = 0; i < a; i++)
		ave += v[i];
	ave /= a;
	printf("%lf\n", ave);

	int max_count{}, min_count{}, need_min{};
	for (int i = 0; i < n; i++)
	{
		if (v[i] == v[0])
			max_count++;

		if (v[i] > v[a - 1])
			continue;
		if (v[i] < v[a - 1])
			break;

		if (i < a)
			need_min++;
		min_count++;
	}

	if (min_count == 1)
		printf("1\n");
	else if (max_count > a)
	{
		long long sum{};
		int r_limit{std::min(max_count, b)};
		for (int r = a; r <= r_limit; r++)
			sum += combi(max_count, r);
		
		printf("%lld\n", sum);
		return 0;
	}
	else
		printf("%lld\n", combi(min_count, need_min));

	return 0;
}

long long combi(int n, int r)
{
	long long ret{1};
	for (int i = 1; i <= r; i++)
	{
		ret *= (n + 1 - i);
		ret /= i;
	}
	return ret;
}

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

    const int MOD = 1000000007;
    const double PI = acos(-1); 

    //long long
    using ll = long long;

    //出力系
    #define print(x) cout << x << endl
    #define yes cout << "Yes" << endl
    #define YES cout << "YES" << endl
    #define no cout << "No" << endl
    #define NO cout << "NO" << endl
    
    // begin() end()
    #define all(x) (x).begin(),(x).end()

    //for
    #define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

    //最大公約数（ll）
    ll gcd(ll x, ll y) { return y ? gcd(y,x%y) : x;}

    //素因数分解
    vector<pair<ll, int>>factorize(ll n){
      vector<pair<ll, int>> res;
      for(ll i = 2; i * i <= n; ++i){
        if(n % i) continue;
        res.emplace_back(i, 0);
        while(n % i == 0){
          n /= i;
          res.back().second++;
        }
      }
    if(n != 1) res.emplace_back(n, 1);
    return res;
    }



  // // 二分探索(最小値を出す問題は疑う)
  // bool C(ll x){
  //     ll res = 0;
  //     for(int i = 0; i < N; ++i){
  // 		res += max(0ll, A[i]-x/F[i]);
  //     }
  //     return res <= K;
  // }

  //   ll binary_search(ll ok, ll ng){
  //     while(abs(ok - ng) > 1){
  //       ll mid = (ok + ng) / 2;
  //       if(C(mid)) ok = mid;
  //       else ng = mid;
  //     }
  //     return ok;
  //   }


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

    if(A + B + C <= 21) print("win");
    else print("bust");
  }

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

using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int> v1(n);
    for (int i = 0; i < n;i++)
    {
        cin >> v1[i];
    }
    sort(v1.begin(), v1.end());
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n;j++)
        {
            for (int z = j + 1; z < n;z++)
            {
                if(v1[i] != v1[j] && v1[i] != v1[z] && v1[j] != v1[z] && v1[i] + v1[j] > v1[z])
                    ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3528
#include<iostream>
#include<fstream>
#include<cstdio>
using namespace std;
int N,ans=0;
long long x,y,d;
int main()
{
	scanf("%d%lld",&N,&d);
	d=d*d;
	for(int i=1;i<=N;i++){
		scanf("%lld%lld",&x,&y);
		if(x*x+y*y<=d)ans++;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
 
#define A_MAX 1000000
#define A_MAX_HALF 500000
 
using namespace std;
 
int scanint() { 
	char c = getchar_unlocked();
    int x = 0;
    for(; (c<48)||(c>57);c = getchar_unlocked());
    for(; (c>47)&&(c<58);c = getchar_unlocked())
        x = 10 * x + c - 48;
    return x;
} 
 
int min_factor[A_MAX + 1];
int q[A_MAX + 1];
int a[A_MAX + 1];
 
int main() {
 
    vector<int> primes;
    for (int i = 2; i <= A_MAX_HALF; ++i) {
        if (!min_factor[i]) {
            min_factor[i] = i;
            primes.push_back(i);
        }
        for (int p : primes) {
            int n = i * p;
            if (n > A_MAX) {
                break;
            }
            min_factor[n] = p;
            if (p == min_factor[i]) {
                q[n] = q[i];
                break;
            } else {
                q[n] = i;
            }
        }
    }
 
    int N = scanint();
    for (int i = 0; i < N; ++i) {
        ++a[scanint()];
    }
 
    bool is_pairwise_coprime = true;
    for (int n = A_MAX; n > 1; --n) {
        int an = a[n];
        if (an) {
            if (an > 1) {
                if (an == N) {
                    printf("not coprime\n");
                    return 0;
                }
                is_pairwise_coprime = false;
            }
            a[min_factor[n]] += an;
            a[q[n]] += an;
        }
    }
    if (is_pairwise_coprime) {
        printf("pairwise coprime\n");
    } else {
        printf("setwise coprime\n");
    }
 
    return 0;
}

Measured memory_bytes: 15468
n=int(input())
l=[0]*n
for x in range(1,100):
    for y in range(1,100):
        for z in range(1,100):
            ans=x**2 + y**2 + z**2 + x*y + x*z + y*z
            if ans<=n:
                l[ans-1]+=1
for i in l:
    print(i)

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

int a[6], st[2], ans, q;

int main(){
    for (int i=0; i<6; i++) cin >> a[i];
    cin >> q;
    for (int i=0; i<q; i++){
        cin >> st[0] >> st[1];
        if (st[0]==a[0]) st[0] = 1;
        else if (st[0]==a[1]) st[0] = 2;
        else if (st[0]==a[2]) st[0] = 3;
        else if (st[0]==a[3]) st[0] = 4;
        else if (st[0]==a[4]) st[0] = 5;
        else if (st[0]==a[5]) st[0] = 6;
        if (st[1]==a[0]) st[1] = 1;
        else if (st[1]==a[1]) st[1] = 2;
        else if (st[1]==a[2]) st[1] = 3;
        else if (st[1]==a[3]) st[1] = 4;
        else if (st[1]==a[4]) st[1] = 5;
        else if (st[1]==a[5]) st[1] = 6;
            if (st[1] == 6) {
                if (st[0] == 5) st[0] = 4;
                else if (st[0] == 4) st[0] = 2;
                else if (st[0] == 2) st[0] = 3;
                else st[0] = 5;
            }
            if (st[1] == 5) {
                if (st[0] == 1) st[0] = 4;
                else if (st[0] == 4) st[0] = 6;
                else if (st[0] == 6) st[0] = 3;
                else st[0] = 1;
            }
            if (st[1] == 4) {
                if (st[0] == 1) st[0] = 2;
                else if (st[0] == 2) st[0] = 6;
                else if (st[0] == 6) st[0] = 5;
                else st[0] = 1;
            }
            if (st[1] == 3) {
                if (st[0] == 1) st[0] = 5;
                else if (st[0] == 5) st[0] = 6;
                else if (st[0] == 6) st[0] = 2;
                else st[0] = 1;
            }
            if (st[1] == 2) {
                if (st[0] == 1) st[0] = 3;
                else if (st[0] == 3) st[0] = 6;
                else if (st[0] == 6) st[0] = 4;
                else st[0] = 1;
            }
            if (st[1] == 1) {
                if (st[0] == 2) st[0] = 4;
                else if (st[0] == 4) st[0] = 5;
                else if (st[0] == 5) st[0] = 3;
                else st[0] = 2;
            }
        
    cout << a[st[0]-1] << endl;}
}


Measured memory_bytes: 3104
import sys
sys.setrecursionlimit(10**7)

n,u,v=map(int, input().split())
u-=1
v-=1
 
graph = [[] for _ in range(n+1)]
for i in range(n-1):
    a, b=map(int, input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)
 

dist=[[-1, -1] for _ in range(n)]
dist[v][0]=0
dist[u][1]=0
 
def dfs(graph,v,k):
    ver=graph[v]
    for vers in ver:
        if dist[vers][k]==-1:
            dist[vers][k]=dist[v][k]+1
            dfs(graph,vers,k)
 
 
dfs(graph,v,0)
dfs(graph,u,1)
dist.sort(reverse=True)
 
for i in range(10**6):
    if dist[i][0]-dist[i][1]>=1:
        print(dist[i][0]-1)
        break

Measured memory_bytes: 110936
#include <bits/stdc++.h>
using namespace std;
//T+N
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl

const ll MAX_N = 100;
ll n, m, q;
ll a[MAX_N], b[MAX_N], c[MAX_N], d[MAX_N];
vector<ll> curr;

ll ans = 0;

void make() {
    if(curr.size() == n + 1) {
        ll now = 0;
        for(ll i = 0; i < q; i ++) {
            if(curr[b[i]] - curr[a[i]] == c[i]) {
                now += d[i];
            }
        }
        chkmax(ans, now);
        return;
    }
    for(ll i = curr.back(); i <= m; i ++) {
        curr.push_back(i);
        make();
        curr.pop_back();
    }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    curr.push_back(1);
    cin >> n >> m >> q;
    for(ll i = 0; i < q; i ++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    make();
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3660
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		for(int i=0;i<N;i++) {
			a.add(sc.nextInt());
		}
		int min = Collections.min(a);
		int max = Collections.max(a);

		long ans = Long.MAX_VALUE;
		for(int i=min;i<=max;i++) {
			int sum = 0;
			for(int j=0;j<N;j++) {
				sum += (a.get(j) - i)*(a.get(j) - i);
			}

			if(ans > sum) {
				ans = sum;
			}
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 23636
import sys
sys.setrecursionlimit(200000)
input = sys.stdin.readline

S = input().strip()

f = True

c = 0
for i in range(len(S)):
    if i == 0:
        if S[i] != "A":
            f = False
            break
        continue

    if i >= 2 and i <= len(S) - 2:
        if S[i] == "C":
            c += 1
        continue

    if S[i].lower() != S[i]:
        f = False
        break

if f and c == 1:
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3064
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS

#include <bits/stdc++.h>

//LIFE IS NOT A PROBLEM TO BE SOLVED

using namespace std;

#define rep(i,a,b) for(int i = int(a); i < int(b) ; i++)
#define pb push_back
#define mp make_pair
#define F first
#define S second

typedef long long int ll;
typedef pair < int, int > ii;
typedef pair < ii, ii > iii;

int main(){
	
	//fflush(stdout);
	//cout.flush();
	
	ll n; cin >> n;
	ll a[n]; rep(i, 0, n) cin >> a[i];
	
	if(a[n-1]!=2){
		puts("-1");
		return 0;
	}
	
	/*
	11 
	4 55 2 3 33 27 14 8 5 3 2
	*/
	ll m = 2, M = 2;
	for(int i=n-1; i>=0; i--){
		ll last = M;
		ll ini = 1, fim = (M+a[i]-1)/a[i], mid, ans;
		while(ini<=fim){
			mid = (ini+fim)/2;
			if(a[i]*mid>=m){
				ans = mid;
				fim = mid-1;
			}else{
				ini = mid+1;
			}
		}
		m = ans*a[i];
		ini = 1, fim = (M+a[i]-1)/a[i], mid, ans;
		while(ini<=fim){
			mid = (ini+fim)/2;
			if(a[i]*mid<=M){
				ans = mid;
				ini = mid+1;
			}else{
				fim = mid-1;
			}
		}
		M = max(M, ans*a[i]+a[i]-1);
		//cout << m << " " << M << " " << a[i] << "\n";
		if(m>last){
			puts("-1");
			return 0;
		}
	}
	
	cout << m << " " << M << "\n";
	
	return 0;
}

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

#define ll long long
#define INF 99999999
#define rep(i,n) for(int i=0,temp=(int)(n);i<temp;++i) //vec.size()がnの時等の高速化
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define vint vector<int>
#define vvint vector<vector<int>>

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 gcd(int a,int b){return b?gcd(b,a%b):a;}

string s;
ll cnt=0;
vector<char> after;
int main(){
  cin >> s;
  rep(i,s.length()){
    if(s[i]=='W'){
      after.push_back('W');
      cnt += i+1-(int)after.size();
    }
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 772
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <cmath>
#include <cstring>

#define fi first
#define se second
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = 1; i < (n); ++i)
#define drep(i,n) for (int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(), (x).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define pb push_back
#define sz(x) (int)(x).size()
#define PQ(T) priority_queue<T, v(T), greater<T> >

using namespace std;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;

const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

const int mod = 1000000007;

int main() {
    string s, t;
    cin >> s >> t;
    cout << (t+s) << endl;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
C - HonestOrUnkind2
https://atcoder.jp/contests/abc147/tasks/abc147_c

"""
import sys


from itertools import product

def solve(N, data):
    ans = 0
    for prd in product([0, 1], repeat=N):
        res = [0] + list(prd)
        is_valid = True
        for i, p in enumerate(prd, start=1):
            if p == 0:
                continue
            for x, y in data[i]:
                if y != res[x]:
                    is_valid = False
                    break
        if is_valid:
            ans = max(ans, sum(res))
    return ans


def main(args):
    N = int(input())
    data = [[] for _ in range(N+1)]
    for a in range(1, N+1):
        for _ in range(int(input())):
            x, y = map(int, input().split())
            data[a].append([x, y])
    ans = solve(N, data)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, min,max, tmp;
    cin >> n;
    cin >> min;
    max = min;
    for(int i=1;i<n;i++){
        cin >> tmp;
        if(tmp > max) max = tmp;
        if(tmp < min) min = tmp;
    }
    cout << max - min << "\n";
    return 0;
}


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

int a[200005];
vector<int> v[200005];
int l[200005];
int re[200005];
int cnt[200005];
int c[200005];

int main()
{
    ll n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        cnt[a[i]]++;
        re[i] = cnt[a[i]];
        v[a[i]].push_back(i);
    }
    for(int i = 0; i < n; i++){
        l[a[i]] = v[a[i]].size();
    }
    int now = 0;
    int i;
    for(i = 0; ; i++){
        while(l[a[now]] != re[now]){
            now = v[a[now]][re[now]] + 1;
            if(now == n){
                break;
            }
        }
        c[i] = now;
//        cout << i << " " << c[i] << endl;
        if(l[a[now]] == 1 && now == n - 1){
            i++;
            c[i] = n;
            break;
        }
        if(now == n) break;
        now = (v[a[now]][0] + 1) % n;
    }
    int cir = i + 1;
//    cout << cir << endl;
    int p = (k + cir - 1) % cir;
    for(int i = c[p]; i < n; i++){
        while(l[a[i]] != re[i]){
            i = v[a[i]][re[i]] + 1;
            if(i == n){
                break;
            }
        }
        if(i >= n) break;
        cout << a[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 16384
#include<stdio.h>

int main(){
    int n, m;
    scanf("%d%d", &n, &m);
    int l, r;
    scanf("%d%d", &l, &r);
    for(int i=1; i<m; i++){
        int p, q;
        scanf("%d%d", &p, &q);
        if(l < p){
            l = p;
        }
        if(q < r){
            r = q;
        }
    }
    printf("%d", l<=r?r-l+1:0);

    return 0;
}

Measured memory_bytes: 128
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N, L = map(int, input().split())

tmp = float('inf')
for v in range(N):
    if tmp > abs(v+L):
        tmp = abs(v+L)
        eat = v
sumALL = sum([v+L for v in range(N)])

print(sumALL-eat-L)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
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; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
ll n,a,b;
cin>>n>>a>>b;
ll ans=a*(n/(a+b));
ll ans2=n%(a+b);
if(ans2>a){
    ans+=a;
}
else{
    ans+=ans2;
}

cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int (i)=0; (i)<(a); (i)++)
#define rep2(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define MOD 1000000007
#define all(v) v.begin(), v.end()
#define m0(x) memset(x,0,sizeof(x))
#define chmax(a,b) if(b>a) a = b
#define chmin(a,b) if(b<a) a = b
typedef long long ll;
using namespace std;

using namespace std;

int main(){
        ios_base::sync_with_stdio(false); 
        cin.tie(NULL);
        ll n; cin >> n;
        ll ac = 0, wa = 0, tle = 0, re = 0;
        string s;
        rep(i,n){
                cin >> s;
                if(s[0] == 'A' && s[1] == 'C') ac++;
                if(s[0] == 'W' && s[1] == 'A') wa++;
                if(s[0] == 'T' && s[1] == 'L' && s[2] == 'E') tle++;
                if(s[0] == 'R' && s[1] == 'E') re++;
        }
        cout << "AC x " << ac << endl;
        cout << "WA x " << wa << endl;
        cout << "TLE x " << tle << endl;
        cout << "RE x " << re << endl;
        return 0;
}


Measured memory_bytes: 3656
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();

        List<Integer> digits = new ArrayList<>();
        List<Integer> numbers = new ArrayList<>();
        for(int i = 0;i < m;i++){
            digits.add(sc.nextInt());
            numbers.add(sc.nextInt());
        }
        System.out.println(solve(n, m, digits, numbers));
    }

    public static String solve(int n, int m, List<Integer> digits, List<Integer> numbers){
        for(int i = 0;i < 1000;i++){
            String str = String.valueOf(i);
            if(isOK(str, n, m, digits, numbers)) return str;
        }
        return "-1";
    }

    public static boolean isOK(String str, int n, int m, List<Integer> digits, List<Integer> numbers) {
        if(str.length() != n) return false;
        for (int i = 0; i < m; i++) {
            if(str.charAt(digits.get(i) - 1) != (char)((int)numbers.get(i) + '0')) return false;
        }
        return true;
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
typedef long long int ll;
using namespace std;
const int MAX=5000+10;
const double eps=1e-9;
const double PI=acos(-1.0);

int sgn(double x)
{
    if (fabs(x)<eps) {
        return 0;
    }
    if (x<0) {
        return -1;
    }
    else return 1;
}
struct point
{
    double x,y;
    point(){}
    point(double _x,double _y)
    {
        x=_x;y=_y;
    }
    point operator +(const point &b)const
    {
        return point(x+b.x,y+b.y);
    }
    point operator -(const point &b)const
    {
        return point(x-b.x,y-b.y);
    }
    double operator ^(const point &b)const
    {
        return x*b.y-y*b.x;
    }
    double operator *(const point &b)const
    {
        return x*b.x+y*b.y;
    }
    point operator *(const double k)const
    {
        point kk;kk.x=k*x;kk.y=k*y;return kk;
    }
    double len(void)
    {
        return sqrt(x*x+y*y);
    }
};

struct line
{
    point s,e;
    line(){}
    line(point _s,point _e)
    {
        s=_s;e=_e;
    }
    pair<int, point> operator &(const line &b)const
    {
        point res=s;
        if(sgn((s-e)^(b.s-b.e))==0){
            if(sgn((s-b.e)^(b.s-b.e))==0){
                return make_pair(0, res);
            }
            else{
                return make_pair(1,res);
            }
        }
        double t=((s-b.s)^(b.s-b.e))/((s-e)^(b.s-b.e));
        res.x+=(e.x-s.x)*t;
        res.y+=(e.y-s.y)*t;
        return make_pair(2, res);
    }
};

bool inter(line l1,line l2)
{
    return max(l1.s.x,l1.e.x) >= min(l2.s.x,l2.e.x) &&
    max(l2.s.x,l2.e.x) >= min(l1.s.x,l1.e.x) &&
    max(l1.s.y,l1.e.y) >= min(l2.s.y,l2.e.y) &&
    max(l2.s.y,l2.e.y) >= min(l1.s.y,l1.e.y) &&
    sgn((l2.s-l1.e)^(l1.s-l1.e))*sgn((l2.e-l1.e)^(l1.s-l1.e)) <= 0 &&
    sgn((l1.s-l2.e)^(l2.s-l2.e))*sgn((l1.e-l2.e)^(l2.s-l2.e)) <= 0;
}

int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    int q;
    scanf("%d",&q);
    while(q--){
        line l1,l2;
        scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&l1.s.x,&l1.s.y,&l1.e.x,&l1.e.y,&l2.s.x,&l2.s.y,&l2.e.x,&l2.e.y);
        point crosspoint=(l1&l2).second;
        printf("%.8lf %.8lf\n",crosspoint.x,crosspoint.y);
    }
    return 0;
}

Measured memory_bytes: 3248
#include <stdio.h>
                                                                                                                        int main(void)                                                                                                          {                                                                                                                         int x, y;                                                                                                               scanf("%d %d", &x, &y);                                                                                                 printf("%d %d\n", x*y, 2*(x+y));                                                                                        return 0;                                                                                                             }
  


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

int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    /////////////////////
    // Write code below /
    /////////////////////
    int H,N,a,sum=0;

    cin>>H>>N;
    rep(i,N){
        cin>>a;
        sum+=a;
    }

    if(sum<H){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }


    return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	int a,b;
	cin>>a>>b;
    string s,t="0123456789",q="Yes";
    cin>>s;
    //vector<long long int>a(10000000);
    //vector<long long int>b(10000000);
    if(s[a]!='-'){
    	q="No";
    }
    for(int i=0;i<a+b+1;i++){
    	if(i!=a){
    		for(int j=0;j<=10;j++){
    			if(s[i]==t[j]){
    				break;
    			}
    			else if(j==10){
    				q="No";
    			}
    		}
    	}
    }
    cout<<q<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>
#include<experimental/any>
#include<cstring>
#include<cctype>
#include<ctime>
#include<cstdbool>
#include<cstdint>
#include<cstddef>
#include<set>
#include<unordered_set>
#include<bitset>
 
using namespace std;
using experimental::any;
 
#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);
 
#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)
#define BitFOR(N) REP(Bit,1<<(N))
 
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define TFDEB(f) (f)? cout<<"true ":cout<<"false ";
#define FORDEB(n,X) for(int i=0;i<(n);i++)ARDEB(i,X)
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define ARDEB(i,X) {}
#define TFDEB(f) {}
#define FORDEB(n,X) {}
#define END {}
#endif
 
typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
//struct edge{int from,cost,to;};
struct P2{int x,y;};
#define BIT(Bit,n) bitset<n>(Bit)
#define Endl endl
#define YN(f) cout<<((f)?"Yes":"No")<<endl
 
const int MOD7=1000000007;
const int INF=100000000;
const int SET=1000; 
 
 
int main(){
	string s;
	int ans=0;
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
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; }
using namespace std;

signed main(){
    int h,w,d; cin>>h>>w>>d;
    vector<vector<int>> grid(h,vector<int>(w));
    map<int,P> mp;
    rep(i,h)rep(j,w){
        cin>>grid.at(i).at(j);
        mp[grid.at(i).at(j)]=P(i,j);
    }
    vector<vector<int>> sum(d,vector<int>(1,0));
    rep(i,d){
        if(i==0){
            rep(j,h*w/d-1){
                int cur=(j+1)*d;
                int next=cur+d;
                sum.at(i).push_back(abs(mp[next].F-mp[cur].F)+abs(mp[next].S-mp[cur].S)+sum.at(i).back());
            }
        }else{
            rep(j,(h*w-i)/d){
                int cur=i+j*d;
                int next=cur+d;
                sum.at(i).push_back(abs(mp[next].F-mp[cur].F)+abs(mp[next].S-mp[cur].S)+sum.at(i).back());
            }
        }
    }
    int q; cin>>q;
    rep(i,q){
        int l,r; cin>>l>>r;
        int re=l%d;
        cout<<sum.at(re).at((r-1)/d)-sum.at(re).at((l-1)/d)<<endl;
    }
}

Measured memory_bytes: 11648
from math import gcd

a, b, c, d = map(int, input().split())
a -= 1
lcm = c * d // gcd(c, d)
cnt_b = b - b // c - b // d + b // lcm
cnt_a = a - a // c - a // d + a // lcm
print(cnt_b - cnt_a)

Measured memory_bytes: 9180