akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define dep(i,b,a) for(register int i=(b);i>=(a);--i)
inline char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
	int x=0,fl=1;char ch=gc();
	for(;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
	for(;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
	return x*fl;
}
const int N=200002,M=1e9+7;
int n,X,Y,sum,ans,jl[N],mn[N],val[N],fac[N],ny[N],col[N];
int pw(int x,int y){
	int z=1;
	for (;y;y>>=1,x=1ll*x*x%M)
		if (y&1) z=1ll*z*x%M;
	return z;
}
int C(int aa,int bb){return 1ll*fac[bb]*ny[aa]%M*ny[bb-aa]%M;}
int main(){
	n=rd(),X=rd(),Y=rd();
	fac[0]=1;
	rep(i,1,n){
		col[i]=rd(),val[i]=rd();
		jl[col[i]]++;
		mn[i]=1e9;
		fac[i]=(1ll*fac[i-1]*i)%M;
	}
	ny[n]=pw(fac[n],M-2);
	dep(i,n,1) ny[i-1]=(1ll*ny[i]*i)%M;
	rep(i,1,n) mn[col[i]]=min(mn[col[i]],val[i]);
	int mx=0,mxx=0;
	rep(i,1,n)
		if (mn[i]!=1e9)
			if (!mx || mn[i]<mn[mx]) mxx=mx,mx=i;
			else if(!mxx || mn[i]<mn[mxx]) mxx=i;
	rep(i,1,n)
		if (!(mn[col[i]]!=val[i] && mn[col[i]]+val[i]<=X || col[i]==mx && val[i]+mn[mxx]<=Y || col[i]!=mx && val[i]+mn[mx]<=Y)) jl[col[i]]--;
	ans=1,sum=jl[mx];
	rep(i,1,n)
		if (i!=mx && mn[i]+mn[mx]<=Y) sum+=jl[i],ans=1ll*ans*C(jl[i],sum)%M;
	printf("%d",ans);
} 

Measured memory_bytes: 4992
#include<iostream>
#include<queue>
#include<algorithm>
#include<functional>

#define N 16

#define NORTH 0
#define EAST 1
#define SOUTH 2
#define WEST 3
#define DIRMAX 4

using namespace std;

const int di[] = {-1,0,1,0};
const int dj[] = {0,1,0,-1};
const int infty = (1LL<<31)-1;
const int dc[] = {120,24,6,2,1};

struct Dice{
  int D[6];
  Dice(){D[5]=1;D[1]=2;D[2]=3;decide();}
  void decide(){D[0]=7-D[5];D[3]=7-D[1];D[4]=7-D[2];}
  void roll(int dir){
    switch(dir){
    case NORTH:D[5]=D[1];D[1]=D[0];break;
    case EAST: D[2]=D[5];D[5]=D[4];break;
    case SOUTH:D[1]=D[5];D[5]=D[3];break;
    case WEST: D[5]=D[2];D[2]=D[0];break;
    }
    decide();
  }
  int index()const{
    int ret = 0;
    for(int i = 0; i < 5; ++i){
      if(D[i]>D[i+1])ret+=dc[i]*(D[i]-D[i+1]);
    }
    return ret;
  }
};

struct State{
  Dice c;
  int i,j;
  int cost;
  bool operator>(const State &t)const{
    return cost > t.cost; 
  }
};

inline bool isinside(int i, int j, int h, int w){
  return 0<=i&&i<h&&0<=j&&j<w;
}

int dijkstra(int h, int w, int M[][N],
	     int si, int sj, int gi, int gj){
  int ret = infty;
  State init;
  int A[720][N][N];
  bool vis[720][N][N];
  priority_queue<State,vector<State>,greater<State> > qs;
  
  init.cost=0;
  init.i=si;
  init.j=sj;
  for(int i = 0; i < 720; ++i){
    for(int j = 0; j < N; ++j){
      for(int k = 0; k < N; ++k){
	vis[i][j][k] = false;
	A[i][j][k] = infty;
      }
    }
  }
  
  qs.push( init );
  while(!qs.empty()){
    int cstate;
    State now = qs.top();
    qs.pop();

    cstate = now.c.index();
    if( vis[cstate][now.i][now.j] ) continue;
    vis[cstate][now.i][now.j] = true;

    for(int k = 0; k < sizeof(di)/sizeof(*di); ++k){
      int ncstate;
      State next = now;
      next.i = now.i + di[k];
      next.j = now.j + dj[k];
      next.c.roll( k );
      if( !isinside(next.i, next.j, h, w ) ) continue;
      next.cost += next.c.D[0] * M[next.i][next.j];
      ncstate = next.c.index();
      if( next.cost < A[ncstate][next.i][next.j] ){
	A[ncstate][next.i][next.j] = next.cost;
	if( !vis[ncstate][next.i][next.j] ){
	  qs.push( next );
	}
      }
    }
  }
  for(int i = 0; i < 720; ++i){
    ret = min( ret, A[i][gi][gj] );
  }
  return ret;
}

int main()
{
  while(true){
    int h,w;
    int M[N][N];
    cin >> h >> w;
    if( h == 0 && w == 0 ) break;
    
    for(int i = 0; i < h; ++i){
      for(int j = 0; j < w; ++j){
	cin >> M[i][j];
      }
    }
    int si,sj,gi,gj;cin >> si >> sj >> gi >> gj;
    cout << dijkstra(h,w,M,si,sj,gi,gj) << endl;
    
  }
  return 0;
}

Measured memory_bytes: 1844
def examA():
    N = I()
    ans = N//2 + N%2
    print(ans)
    return

def examB():
    A = [LI()for _ in range(3)]
    N = I()
    B = [I()for _ in range(N)]
    grid = [[False]*3 for _ in range(3)]
    ans = "No"
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    grid[i][j] = True
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[i][j]:
                flag = False
        if flag:
            ans = "Yes"
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[j][i]:
                flag = False
        if flag:
            ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][i]:
            flag = False
    if flag:
        ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][2-i]:
            flag = False
    if flag:
        ans = "Yes"
    print(ans)
    return

def examC():
    N, M = LI()
    S = [LI()for _ in range(M)]
    ans = [-1]*N
    for s,c in S:
        s -= 1
        if ans[s]!=-1:
            if ans[s]!=c:
                print(-1)
                return
        ans[s] = c
    A = ""
    if ans[0]==0 and N>=2:
        print(-1)
        return
    elif ans[0]==-1 and N>=2:
        ans[0] = 1
    for i in ans:
        if i==-1:
            A += str(0)
        else:
            A += str(i)
    print(A)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

"""

"""

Measured memory_bytes: 4716
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma comment(linker,"/STACK:36777216")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW cout << "meowwwww" << '\n'; system("pause");
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 123456, maxkk = 2345;
int n, k, x[maxn], y[maxn], c[maxn], diff[maxkk][maxkk], a[maxkk][maxkk];
void input()
{
	cin >> n >> k;
	F1 (i, n)
	{
		char C;
		cin >> x[i] >> y[i] >> C;
		c[i] = C == 'B'; 
	} 
}

void pre(int x, int y, int e)
{
	diff[1][1] += e;
	diff[1][y + 1] -= e;
	diff[x + 1][1] -= e;
	diff[x + 1][y + 1] += e;
} 

void add(int a, int b, int c, int d)
{
	++a, ++b, ++c, ++d;
	if (b < a || d < c) return;
	pre(a - 1, d, -1);
	pre(b, c - 1, -1);
	pre(a - 1, c - 1, 1);
	pre(b, d, 1);
}

void solve()
{
	int ans = 0;
	F1 (i, n)
	{
		int v[2];
		vector<pii> v0[2], v1[2];
		v[0] = x[i] % (k + k), v[1] = y[i] % (k + k); 
		F (t, 2)
		{
			if (v[t] < k)
			{
				v0[t].pb(mp(0, k - v[t] - 1));
				v0[t].pb(mp(k + k - v[t], k + k - 1));
				v1[t].pb(mp(k - v[t], k + k - v[t] - 1));
			} else
			{
				v0[t].pb(mp(k + k - v[t], k + k + k - v[t] - 1));
				v1[t].pb(mp(0, k + k - v[t] - 1));
				v1[t].pb(mp(k + k + k - v[t], k + k - 1));
			}
		}
		if (c[i])
		{
			for (auto xx : v0[0]) for (auto yy : v0[1])
				add(xx.fi, xx.se, yy.fi, yy.se);
			for (auto xx : v1[0]) for (auto yy : v1[1])
				add(xx.fi, xx.se, yy.fi, yy.se);
		} else
		{
			for (auto xx : v0[0]) for (auto yy : v1[1])
				add(xx.fi, xx.se, yy.fi, yy.se);
			for (auto xx : v1[0]) for (auto yy : v0[1])
				add(xx.fi, xx.se, yy.fi, yy.se);
		}
	}
	F1 (i, k + k) F1 (j, k + k)
		ans = max(ans, diff[i][j] += 
			diff[i - 1][j] + diff[i][j - 1] - diff[i - 1][j - 1]);
	cout << ans << '\n';
}

main()
{
	input();
	solve();
}


Measured memory_bytes: 23936
s = str(input())
m = len(s)
c = 0
r = 0
prevr = -1
s += "a"
if s[0] == "<":
  state = 1
else:
  state = -1
for i in range(1,m+1):
  if s[i] == s[i-1]:
    r += 1
  else:
    if state == 1:
      prevr = r
      c += ((r+2)*(r+1))//2
      state = -1
      r = 0
    else:
      c += ((r+2)*(r+1))//2
      if prevr >= r:
        c -= (r+1)
      else:
        c -= (prevr+1)
      state = 1
      r = 0
print(c)

Measured memory_bytes: 4120
#include <iostream>
#include <cstdio>
using namespace std;
int main(){
    int n;
    int a[100];
    scanf("%d",&n);
    for(int i = 1; i <= n; i++) {
        scanf("%d",&a[i]);
    }
    int sum = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = i + 1; j <= n; j++){
            sum += a[i] * a[j];
        } 
    }
    printf("%d\n",sum);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll ans =0;
  ll n,a,b; cin >> n >> a >> b;
  ll aa = a*(n-1) + b;
  ll bb = b*(n-1) + a;

  if(n==1&&a!=b){
    ans =0;
  }else{
    ans = bb-aa;
    if(ans<0) ans =0;
    else ans++;
  }

  cout << ans <<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <cstdint>
#include <algorithm>
#include <utility>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}
int main(){
  string N; cin >> N;
  int sum = 0;
  bool flag = true;
  if(N.size() == 1){
    cout << ctoi(N[0]) << endl;;
  }
  else{
    for(int i=1; i < N.size();i++){
      if(N[i] != '9'){
        flag = false;
      }
    }
    if(flag){
      rep(j,N.size()){
        sum += ctoi(N[j]);
    }
    }
    else{
      sum = (N.size()-1)*9;
      sum += ctoi(N[0])-1;
  }
  cout << sum << endl;
  
  }
}

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

int main() {
  int A,B; char op; cin >>A >>op >>B;
  if (op=='+') cout <<A+B <<endl;
  else cout <<A-B <<endl;
  return 0;
}


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


int h, w;
bool done[100][100];
const int dx[4] = {0, 0, -1, 1};
const int dy[4] = {-1, 1, 0, 0};
string field[100];

void dfs(int y, int x) {
	if(done[y][x])
		return;

	done[y][x] = true;

	for(int i = 0; i < 4; ++i) {
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(nx < 0 || ny < 0 || nx >= w || ny >= h)
			continue;

		if(field[y][x] == field[ny][nx])
			dfs(ny, nx);
	}
}


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

	for(; cin >> h >> w, h | w;) {
		for(int i = 0; i < h; ++i)
			cin >> field[i];

		memset(done, false, sizeof(done));
		int ans = 0;
		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(!done[i][j]) {
					++ans;
					dfs(i, j);
				}
			}
		}

		cout << ans << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2176
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
  int n, i, j, e, sum,u,min;
  int A[MAX][MAX],vis[MAX],cost[MAX],pi[MAX];

  scanf("%d", &n);

  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      A[i][j] = (e==-1)?INFTY:e;
    }
  }

  for (i = 0; i < n; i++ ){
    cost[i] = INFTY;
    vis[i] = 0; 
    pi[i] = -1;
  }
  cost[0] = 0;
  while (1){
    u = -1;
    min = INFTY;
    for (i = 0; i < n; i++ ){
      if (cost[i] < min && !vis[i]){
    u = i;
    min = cost[i];
      }
    }
    if (u  == -1 ) break;
    vis[u] = 1;   
    for (i = 0; i < n; i++ ){         
      if ( A[u][i] < cost[i] && !vis[i]){
    cost[i] = A[u][i];
    pi[i] = u;
      }
    }
  }

  sum = 0;
  for ( i = 0; i < n; i++ ){
    if ( pi[i] != -1 ) sum += A[i][pi[i]];
  }
  printf("%d\n", sum);

  return 0;
}

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

long long calc(long long A) {
	long long cnt = (A+1)/2;
	long long ans = cnt%2;
	if (A%2 == 0) {
		ans ^= A; 
	}
	return ans;
}

int main() {
	long long A, B;
	cin >> A >> B;
	long long ans = calc(B) ^ calc(A - 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N;
  cin >> N;
  // const int64_t L = static_cast<int64_t>(T.length());
  vector<Pair> due_and_time(N);
  for (int64_t i = 0; i < N; ++i) {
    cin >> due_and_time[i].second >> due_and_time[i].first;
  }
  sort(due_and_time.begin(), due_and_time.end());
  int64_t ctime = 0LL;
  bool is_okay = true;
  for (int64_t i = 0; i < N; ++i) {
    ctime += due_and_time[i].second;
    if (ctime > due_and_time[i].first) {
      is_okay = false;
      break;
    }
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

using namespace std;
int a[5][5];
int b[5], c[5];
bool ok;
int main()
{
    for(int i = 1; i <= 3; ++i)
        for(int j = 1; j <= 3; ++j)
            cin >> a[i][j];
    for(int i = 0; i <= 100; ++i)
    {
        ok = 1;
        b[1] = i;
        for(int j = 1; j <= 3; ++j)
            c[j] = a[1][j] - b[1];
        for(int j = 1, nb; j <= 3; ++j)
        {
            nb = a[2][j] - c[j];
            if(nb != b[2] && j >= 2)
            {
                ok = 0;
                break;
            }
            b[2] = a[2][j] - c[j];
        }
        for(int j = 1, nb; j <= 3; ++j)
        {
            nb = a[3][j] - c[j];
            if(nb != b[3] && j >= 2)
            {
                ok = 0;
                break;
            }
            b[3] = a[3][j] - c[j];
        }
        if(ok)
        {
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
t=[list(input())for i in range(h)]
ans=True
dx=[1,-1,0,0]
dy=[0,0,1,-1]
for i in range(h):
    for j in range(w):
        if t[i][j]=="#":
            found=False#隣あう黒マスが見つかったか判定する
            for k in range(4):
                i2=i+dx[k]
                j2=j+dy[k]
                if 0<=i2 and i2<h and 0<=j2 and j2<w and t[i2][j2]=="#":
                    found=True
            if found==False:
                ans=False
if ans:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};



int main() {
int a,b;
cin>>a>>b;
string s;
cin>>s;
int c=s.length();
bool number_a =true;
REP(i,a) if(s[i]=='-') number_a=false;

bool number_b =true;
    for(int i=a+1; i<=a+b; i++) if(s[i]=='-') number_b=false;

if(c==a+b+1&&s[a]=='-'&&number_a==true&&number_b==true) cout<<"Yes"<<endl;
else cout<<"No"<<endl;

}


Measured memory_bytes: 256
S = list(raw_input())
T = list(raw_input())

S.sort()
T.sort()
Sdata = []
Tdata = []

counter = 0
p = S[0]
for i in S:
    if i == p:
        counter += 1
    else:
        Sdata.append(counter)
        counter = 1
        p = i
Sdata.append(counter)

counter = 0
p = T[0]
for i in T:
    if i == p:
        counter += 1
    else:
        Tdata.append(counter)
        counter = 1
        p = i
Tdata.append(counter)

Sdata.sort()
Tdata.sort()

if Sdata == Tdata:
    print 'Yes'
else:
    print 'No'

Measured memory_bytes: 6748
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

string num = "0123456789";

int main()
{
	int n; cin>>n;
	while (n--) {
		string ord; cin>>ord;
		string s; cin>>s;
		reverse(all(ord));
		rep(i,0,len(ord)) {
			string t = s;
			if (ord[i]=='J') {
				s = t.back();
				s += t.substr(0,len(t)-1);
			}
			if (ord[i]=='C') {
				s = t.substr(1,len(t)-1);
				s += t.front();
			}
			if (ord[i]=='E') {
				if (len(s)%2) {
					int c = len(s)/2;
					s = t.substr(c+1, len(s)-(c+1));
					s += t[c];
					s += t.substr(0, c);
				}
				else {
					int c = len(s)/2;
					s = t.substr(c, len(s)-c);
					s += t.substr(0, c);
				}
			}
			if (ord[i]=='A') {
				reverse(all(s));
			}
			if (ord[i]=='P') {
				rep(j,0,len(s)) {
					int idx = num.find(s[j]);
					if (idx != std::string::npos) {
						s[j] = num[(len(num)+idx-1)%len(num)];
					}
				}
			}
			if (ord[i]=='M') {
				rep(j,0,len(s)) {
					int idx = num.find(s[j]);
					if (idx != std::string::npos) {
						s[j] = num[(len(num)+idx+1)%len(num)];
					}
				}
			}
		}
		cout << s << endl;
	}

	return 0;
}

Measured memory_bytes: 3204
MOD = 10 ** 9 + 7

S = input().strip()
#S = '?' * (10 ** 5)
N = 13

dp = [0] * N
dp[0] = 1

for i in range(len(S)):
  next_dp = [0] * N
  c = S[i]
  if c == '?':
    for k in range(10):
      for j in range(N):
        next_dp[(j * 10 + k) % N] += dp[j]
        next_dp[(j * 10 + k) % N] %= MOD
  else:
    k = int(c)
    for j in range(N):
      next_dp[(j * 10 + k) % N] += dp[j]
      next_dp[(j * 10 + k) % N] %= MOD

  dp = next_dp

print(dp[5])

Measured memory_bytes: 43116
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=0,o,aa[220000],cntl=0,ab[220000];
pair<int,int> p[220000];
string s,ss[220000];
char c,cc[5000][5000]={};
queue<int> que;
signed main(){
    cin>>s;
    rep(i,s.size()){
        rep(j,i){
            if(s[i]==s[j]){
                cout<<"no"<<endl;
                return 0;
            }
        }
    }
    cout<<"yes"<<endl;
}

Measured memory_bytes: 4352
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []
part_start = -1

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        part_start = i

if part_start != -1:
    # 部分文字列は最後にあったほうがいい?はaで最小化できる可能性があり、文字列の先頭に近い部分にそれらがあったほうがよい
    ans = sp[:part_start] + t + sp[part_start + len_t:]
    ans = ans.replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
import math
import sys

input = sys.stdin.readline

def main():
    N = int(input())
    t = []
    for _ in range(5):
        t.append(int(input()))
    wait = [math.ceil(N/x) for x in t]
    maxwait = max(wait)
    ans = 5 + maxwait - 1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<stdio.h>
int main(){
	int n[5],i,j,k,m;
	for(i=0;i<5;i++)scanf("%d",&n[i]);
	if(n[0]<0){
		n[0]-=(n[0]+n[0]);
		m=n[2]*n[0]+n[3]+n[4]*n[1];
	}
	else m=n[4]*(n[1]-n[0]);
	printf("%d\n",m);
	return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		char str[16];
		sprintf(str, "%o", n);
		rep(i, strlen(str)){
			printf("%c", str[i] + (str[i]>='4') + (str[i]>='5'));
		}
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1000000007;
string alp="abcdefghijklmnopqrstuvwxyz";

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> P(N);
    rep(i,N){
        cin >> P[i];
    }
    set<int> s;
    int ans=1;
    rep(i,K){
        s.insert(P[i]);
    }
    vector<int> A(N);
    A[0]=1;
    rep(i,N-1){
        if (P[i+1]>P[i]){
            A[i+1]=A[i]+1;
        }
        else {
            A[i+1]=1;
        }
    }
    bool b=true;
    if (A[K-1]==K){
        b=false;
    }
    rep(i,N-K){
        int n=*begin(s);
        int m=*rbegin(s);
        if (!(P[i]==n&&P[i+K]>m)&&A[i+K]<K){
            ans++;
        }
        else if (!(P[i]==n&&P[i+K]>m)&&b){
            ans++;
        }
        if (A[i+K]==K){
            b=false;
        }
        s.erase(P[i]);
        s.insert(P[i+K]);
    }
    cout << ans << endl;
}

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

int main(){
  std::string str;
  std::cin >> str;
  int ans=0, tmp=0;
  bool r=false;
  for(auto &&e : str){
    if(!r && e == 'R'){
      	r = true;
      	tmp=0;
    }
    if(r && e == 'R'){
      	tmp++;
    }
    if(r && e != 'R'){
      	if(tmp > ans) ans = tmp;
      	r = false;
    }
  }
  if(r){
    if(tmp > ans) ans = tmp;
  }
  std::cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3192
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int Z = scanner.nextInt();
    int W = scanner.nextInt();

    int[] a = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();

    int b1 = Math.abs(W - a[N - 1]);
    int b2 = N > 1 ? Math.abs(a[N - 1] - a[N - 2]) : 0;
    System.out.println(Math.max(b1, b2));
  }
}


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

int main()
{
    string str;cin>>str;
    
    sort(str.begin(),str.end());
    int n = str.size();
    int ans=0;
    
    if(n%2==1)ans=-1;
    
    
    for(int i=0;i<n-1;i+=2){
        if(str[i]!=str[i+1])ans=-1;
    }
    
    if(ans==-1) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
//    cout<<str<<endl;
}

Measured memory_bytes: 256
lists = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(lists[k-1])

Measured memory_bytes: 3060
import sys

INF = 10 ** 18
sys.setrecursionlimit(10 ** 6)
from collections import defaultdict


def li():
    return [int(x) for x in input().split()]


from collections import deque

H, W = li()
Ch, Cw = li()
Dh, Dw = li()
S = [list(input()) for x in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def bfs():
    costmap = [[-1] * W for i in range(H)]
    costmap[Ch - 1][Cw - 1] = 0
    que = deque([])
    que.append((Cw, Ch))

    while que:
        # print(que)
        # 左から取り出す
        x, y = que.popleft()
        # 通常移動パターン
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            # バリデーション
            if nx <= 0 or nx > W or ny <= 0 or ny > H:
                continue
            if S[ny - 1][nx - 1] != '.':
                continue
            # 初探索 or コストが下がる場合
            if costmap[ny - 1][nx - 1] == -1 or costmap[y - 1][x - 1] < costmap[ny - 1][nx - 1]:
                # コストゼロは左から
                que.appendleft((nx, ny))
                costmap[ny - 1][nx - 1] = costmap[y - 1][x - 1]
        # 特殊移動パターン
        for i in range(x - 2, x + 3):
            for j in range(y - 2, y + 3):
                nx, ny = i, j
                # バリデーション
                if nx <= 0 or nx > W or ny <= 0 or ny > H:
                    continue
                if S[ny - 1][nx - 1] != '.':
                    continue
                # 初探索 or コストが下がる場合
                if costmap[ny - 1][nx - 1] == -1 or costmap[y - 1][x - 1] + 1 < costmap[ny - 1][nx - 1]:
                    # コスト1は右から
                    que.append((nx, ny))
                    costmap[ny - 1][nx - 1] = costmap[y - 1][x - 1] + 1
    return costmap


costmap = bfs()
# print(costmap)
print(costmap[Dh - 1][Dw - 1])

Measured memory_bytes: 130232
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define cY cout << "Yes" << endl;
#define cN cout << "No" << endl;

ll saiki(ll x){
  if(x == 1) return 1;
  return 2*saiki(x/2) + 1;
}

int main() {
  ll h;
  cin >> h;
  cout << saiki(h) << endl;
  return 0;
}


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


void solve(long long N, std::vector<long long> A){
  vector<ll> v(N+1, 0);
  map<ll,ll> m;
  ll ans = 0;
  m[0] = 0;
  rep(i, N) v[i+1] += v[i]+A[i];
  for(int i=1; i<=N; i++) {
    if(m.find(v[i])!=m.end()) {
      m[v[i]]++;
      ans += m[v[i]];
    } else {
      m[v[i]] = 0;
    }
  }

  std::cout << ans << std::endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 18696
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)

using namespace std;

int main(){
	int N,v[101]={},w[101]={},W,i,j,dp[101][10001]={};
	cin >> N >> W;
	myforFL(i,1,N+1)cin >> v[i] >> w[i];
	myforFL(i,1,N+1){
		myforFL(j,1,W+1){
			if(j >= w[i])dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
			else dp[i][j] = dp[i-1][j];
		}
	}
	cout << dp[N][W] << endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define INF  numeric_limits<int>::max()
#define NINF numeric_limits<int>::min()

using namespace std;
using ll = long long;

const int N_MAX = 8;
int N, M;
bool edge[N_MAX][N_MAX];
bool reached_vertex[N_MAX];

int dfs(int vertex) {
    if(std::accumulate(reached_vertex, reached_vertex + N, 0) == N) {
        return 1;
    }

    int ret = 0;
    REP(i, N) {
        if(!edge[vertex][i] || reached_vertex[i]) continue;

        reached_vertex[i] = true;
        ret += dfs(i);
        reached_vertex[i] = false;
    }

    return ret;
}

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

    std::cin >> N >> M;
    REP(i, N) {
        reached_vertex[i] = 0;
    }

    REP(i, M) {
        int a, b;
        std::cin >> a >> b;
        edge[a - 1][b - 1] = edge[b - 1][a - 1] = true;
    }

    reached_vertex[0] = true;
    std::cout << dfs(0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
int i,max=0;
int n,a[100000],b[100000];

scanf("%d",&n);
for(i=0;i<n;i++){
    scanf("%d%d",&a[i],&b[i]);
    if(a[i]>=a[max])max=i;
}

printf("%d",a[max]+b[max]);
    return(0);
}

Measured memory_bytes: 896
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a=3,b=3;
    cin >> a >> b;
    if( a > b ){
        if( a * 2 - 1 >= a + b  ){
            cout << a * 2 - 1;
        }
        else {
            a + b;
        }
    }
    else  {
        if( b * 2 - 1 >= a + b ){
            cout << b * 2 - 1;;
        }
        else {
            cout << a + b;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
ll dig_sum(ll n){
  ll ans=0;
  while(n){
    ans+=n%10;
    n/=10;
  }
  return ans;
}
int main(void){
  ll k;
  cin>>k;
  ll a=0,d=1;
  while(k--){
    if(d*dig_sum(a+d) < a+d){
      d*=10;
    }
    a+=d;
    cout<<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
const long long INF = 1e15;

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

    int n;
    cin >> n;
    int cnt = 0;
    int ans = -1;
    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        if(a == b){
            cnt++;
        }
        else{
            ans = max(ans,cnt);
            cnt = 0;
        }
    }
    ans = max(ans,cnt);
    //cout << ans << endl;
    if(ans >= 3) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll MX = 1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
 
int main() {
  int h,n;
  cin>>h>>n;
  vi a(n);
  int sum=0;
  rep(i,n){ 
    cin>>a[i];
    sum+=a[i];
  }
  if(h>sum){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
}

Measured memory_bytes: 3652
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))

d = defaultdict(int)
for i in range(n):
    for border in reversed(range(0, 3201, 400)):
        if a[i] >= border:
            d[border] += 1
            break

ans_min = ans_max = 0
if 3200 in d:
    if len(d) > 1:
        ans_min, ans_max = len(d)-1, len(d)-1+d[3200]
    else:
        ans_min, ans_max = 1, d[3200]
else:
    ans_min, ans_max = len(d), len(d)

print(ans_min, ans_max)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
string jz(int n)
{
	string s="1";
	for(;n;)
	{
		s+=(char)(n%2+'0');
		n/=2;
	}
	return s;
}
int main()
{
	string s;
	cin>>s;
	long long ans=0;
	int x=1;
	for(int i=0;i<s.size()-1;i++)
	{
	  x*=2;	
	}
	for(int i=0;i<x;i++)
	{
		string z=jz(i);
	    for(int j=z.size()-1;j<s.size()-1;j++)
	    {
		  z+='0';
	    }
		reverse(z.begin(),z.end());
		int last=0;
		for(int j=0;j<s.size();j++)
		{
			if(z[j]=='1')
			{
				long long m=0;
				for(int k=last;k<=j;k++)
				{
					m=m*10+(int)(s[k]-'0');
				}
				ans+=m;
				last=j+1;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	int a, b, c, d, e, k;
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a <= k) {
		cout << "Yay!" << endl;
	}

	else {
		cout << ":(" << endl;
	}

}

Measured memory_bytes: 256
h, w = [int(x) for x in input().split()]
m = []
m.append(list("." * (w + 2)))
for _ in range(h):
    m.append(["."] + list(input()) + ["."])
m.append(list("." * (w + 2)))
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if m[i][j] == ".":
            c = 0
            if m[i-1][j-1] == "#": c += 1
            if m[i-1][j]   == "#": c += 1
            if m[i-1][j+1] == "#": c += 1
            if m[i][j-1]   == "#": c += 1
            if m[i][j]     == "#": c += 1
            if m[i][j+1]   == "#": c += 1
            if m[i+1][j-1] == "#": c += 1
            if m[i+1][j]   == "#": c += 1
            if m[i+1][j+1] == "#": c += 1
            print(str(c), end="")
        else:
            print("#", end="")
    print()

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

#define         pb         push_back
#define         sf(x)      scanf("%d",&x)
#define         sfl(x)     scanf("%lld",&x)
#define         pf(x)      printf("%d\n",x)
#define         pfl(x)     printf("%lld\n",x)
#define         endl       '\n'
#define         pii        pair<int,int>
#define         mapii      map<int,int>
#define         mapll      map<ll,ll>
#define         mapci      map<char,int>
#define         mapcl      map<char,ll>
#define         mapsi      map<string,int>
#define         mapsl      map<string,ll>
#define         pll        pair<ll,ll>
#define         vi         vector<int>
#define         vl         vector<ll>
#define         vd         vector<double,double>
#define         all(c)     c.begin(),c.end()
#define         F          first
#define         S          second
#define         mp         make_pair
#define        ftc(x)      cerr << #x << ": " << x << " " << endl;
#define         PI         acos(-1)
#define         lcm(a,b)   ((a*b)/__gcd(a,b))
#define        optimize    ios_base::sync_with_stdio(false);cin.tie(NULL);
#define  mod 1000000007

int cnt[200000];


int main()
{


    int i,j,k,l,m,n,r;

    cin >> n;

    int ar[n+10];
    int br[n+10];

    for(i=0; i<n; i++)cin >> ar[i];
    for(i=0; i<n; i++)cin >> br[i],cnt[br[i]]++;

    reverse(br,br+n);

    l = 0;
    r = n-1;

    for(i=0; i<n; i++)
    {
        if(ar[i] == br[i])
        {
            if(br[i]!=br[r] && ar[r]!=br[i])
            {
                swap(br[i],br[r]);
                r--;
            }
            else if(br[i]!=br[l] && ar[l]!=br[i])
            {
                swap(br[i],br[l]);
                l++;
            }

        }
    }


    for(i=0; i<n; i++)
    {
        if(ar[i] == br[i])return cout << "No" << endl,0;
    }

    // if(l<r)return cout << "No" << endl,0;

    cout << "Yes" << endl;

    for(i = 0 ; i<n; i++)cout<<br[i]<<" ";

    cout<<endl;


}


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

int main(){
    
    //中間試験の点数 m、期末試験の点数 f、再試験の点数 r 
    int m,f,r;

    while(1){
      cin >> m >> f >> r;

      if((m == -1)&&(f == -1)&&(r == -1)){
          break;
      }
      if((m == -1)||(f == -1)){
        cout << 'F' << endl;
        continue;
      }
      if(m+f >= 80){
        cout << 'A' << endl;
      }else if(m+f >= 65){
        cout << 'B' << endl;
      }else if(m+f >= 50){
        cout << 'C' << endl;
      }else if(m+f >= 30){
        if(r >= 50){
            cout << 'C' << endl;
        }else{
          cout << 'D' << endl;
        }
      }else{
        cout << 'F' << endl;
      }
    }
    return(0);
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 +7;
const ll MAXN = 1e6 + 5;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n,r;
	cin>>n>>r;
	if(n>=10) cout<<r;
	else{
		cout<<r+100*(10-n);
	} 
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

cost = [0]*N
for n in range(1, N):
    if n == 1:
        cost[n] = cost[n-1]+abs(H[n-1]-H[n])
    else:
        cost[n] = min(cost[n-1]+abs(H[n-1]-H[n]), cost[n-2]+abs(H[n-2]-H[n]))
print(cost[N-1])


Measured memory_bytes: 52208
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
    ll h,w;int n;
    cin>>h>>w>>n;
    ll ans[10]={};
    map< pair<int,int>, int > mp;
    map< pair<int,int>, bool > check;
    rep(i,n){
        int a,b;
        cin>>a>>b;
        mp[make_pair(a,b)]++;
    }

    //黒点の周りだけ調べれば十分
    for(const auto x : mp){
        for(int i=-1;i<=1;i++){
            for(int j=-1;j<=1;j++){
                int sx=(x.first).first+i,sy=(x.first).second+j;
                if(check[make_pair(sx,sy)]||sx<2||sx>h-1||sy<2||sy>w-1) continue;
                check[make_pair(sx,sy)]=true;
                int cnt=0;
                for(int k=-1;k<=1;k++){
                    for(int l=-1;l<=1;l++){
                        if(mp.count(make_pair(sx+k,sy+l))) cnt++;
                    }
                }
                ans[cnt]++;
            }
        }
    }
    ll sum=(h-2)*(w-2);
    for(int i=1;i<10;i++){
        sum-=ans[i];
    }
    ans[0]=sum;
    rep(i,10){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 62720
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static readonly StreamScanner Scanner = new StreamScanner(Console.OpenStandardInput());
        
        static void Main(string[] args)
        {
            var str1 = Scanner.Scan();
            var str2 = Scanner.Scan();

            int num = 0;
            for (int i = 0; i < str1.Length; i++)
            {
                if (str1[i] != str2[i])
                {
                    num++;
                }
            }
            Console.WriteLine(num);
        }

        private static IEnumerable<long> ScanLong(int count = 0)
        {
            var scan = new List<long>();
            for (int i = 0; i < count; i++)
            {
                scan.Add(Scanner.Long());
            }

            return scan;
        }
        
        private static void OutAllLine(IEnumerable<dynamic> items)
        {
            var sb = new StringBuilder();
            foreach (var result in items)
            {
                sb.Append(result + "\n");
            }
            sb = sb.Remove(sb.Length - 1, 1);
            Console.WriteLine(sb);
        }
    }
    
    public class StreamScanner
    {
        public StreamScanner(Stream stream) { str = stream; }
        private readonly Stream str;
        private readonly byte[] buf = new byte[1024];
        private int len, ptr;
        public bool isEof = false;
        public bool IsEndOfStream { get { return isEof; } }
        private byte read()
        {
            if (isEof) throw new EndOfStreamException();
            if (ptr >= len) {
                ptr = 0;
                if ((len = str.Read(buf, 0, 1024)) <= 0)
                {
                    isEof = true;
                    return 0;
                }
            }
            return buf[ptr++];
        }
        public char Char() 
        {
            byte b = 0;
            do b = read();
            while (b < 33 || 126 < b);
            return (char)b; 
        }
        public string Scan()
        {
            var sb = new StringBuilder();
            for (var b = Char(); b >= 33 && b <= 126; b = (char)read())
                sb.Append(b);
            return sb.ToString();
        }
        public long Long()
        {
            long ret = 0; byte b = 0; var ng = false;
            do b = read();
            while (b != '-' && (b < '0' || '9' < b));
            if (b == '-') { ng = true; b = read(); }
            for (; true; b = read())
            {
                if (b < '0' || '9' < b)
                    return ng ? -ret : ret;
                else ret = ret * 10 + b - '0';
            }
        }
        public int Integer() { return (int)Long(); }
        public double Double() { return double.Parse(Scan(), CultureInfo.InvariantCulture); }
    }
}

Measured memory_bytes: 27164
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if (A >= B && A >= C && C >= B) cout<<"Yes"<<endl;
  else if (B >= A && B >= C && C >= A) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    string s;
    cin>>s;
    int ans=0;
    for (int i = s.size()-1; i >= 0; i--)
    {
        for (int j = 0; j <=i ;j++)
        {
            string t=s.substr(j,i-j+1);
            bool flag=false;
            for(char c:t)
            {
                if(c=='A' || c=='T' || c== 'C' || c=='G')flag=true;
                else
                {
                    flag=false;
                    break;
                }
            }
            if(flag)
            {
                int size=t.size();
                ans=max(ans,size);
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
def main():
    N = int(input())
    S = input().rstrip("\r\n")
    R = []
    G = []
    B = []
    for i, s in enumerate(S):
        if s == "R":
            R.append(i)
        elif s == "G":
            G.append(i)
        else:
            B.append(i)
    ans = len(R) * len(G) * len(B)
    for i in range(N):
        for j in range(i+1, N):
            k = 2 * j - i
            if k >= N:continue
            if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
                ans -= 1
    print(ans)
if __name__ == "__main__":
    main()

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

#define F first
#define S second
#define PB push_back
#define PF push_front
#define MP make_pair

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 3e5 + 4;
const int mod = 998244353;

int main () {
	ios::sync_with_stdio(false);
	ll h, w;
	cin >> h >> w;
	if (h % 3 == 0 or w % 3 == 0)
		return cout << 0 << endl, 0;
	ll ans = min (h, w);
	for (ll i = 1; i < h; i++) {
		ll s1 = i * w;
		ll s2 = (h - i) * (w / 2);
		ll s3 = (h - i) * ((w + 1) / 2);
		ans = min (ans, max (max (abs (s3 - s2), abs (s3 - s1)), abs (s2 - s1)));
	}
	for (ll i = 1; i < w; i++) {
		ll s1 = i * h;
		ll s2 = (w - i) * (h / 2);
		ll s3 = (w - i) * ((h + 1) / 2);
		ans = min (ans, max (max (abs (s3 - s2), abs (s3 - s1)), abs (s2 - s1)));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a[N];
    int ct;
    ct = 0;
    int pv;
    pv = 1;
    int flag;
    flag = 0;
    for( int i=0; i<N; i++){
        cin >> a[i];
        if( pv == a[i]){
            pv++;
            flag = 1;
        }else{
            ct++;
        }
    }
    if(flag == 1){
        cout << ct << endl;
    }else {
        cout << -1 << endl;
    }
}




Measured memory_bytes: 1024
"""abc129_b"""
N = int(input())
W = list(map(int, input().split()))

W_SUM = sum(W)

W_TOTAL = 0
W_ABS = []
for w in W :
    W_TOTAL += w
    W_ABS.append(abs(W_SUM - W_TOTAL * 2))

    if W_TOTAL > W_SUM/2:
        break

print(min(W_ABS))


Measured memory_bytes: 9040
def main():
    n = int(input())
    lst_a = [int(v) for v in input().split(' ')]
    s = 0
    c = int(1000)
    max_c = int(1000)

    prev_tlt = '-'
    for i in range(len(lst_a) - 1):
        if lst_a[i] < lst_a[i + 1]:
            tlt = '+'
        elif lst_a[i] > lst_a[i + 1]:
            tlt = '-'
        else:
            continue

        if tlt != prev_tlt:
            if tlt == '-':
                c += s * lst_a[i]
                s = 0
            else:
                s = int(c // lst_a[i])
                c -= lst_a[i] * s
            max_c = max(c, max_c)
        prev_tlt = tlt
    c += s * lst_a[-1]
    max_c = max(c, max_c)
    print(max_c)


if __name__ == '__main__':
    main()


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

  ll sum = 0;
  for (int i = 1; i <= N; i++)
  if (i % 3 != 0 && i % 5 != 0){
    sum += i;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3604
use std::io;


fn main() {
    let (a, b) = {
        let i = read::<isize>();
        (i[0], i[1])
    };
    println!("{}", xor(b) ^ xor(a - 1));
}

fn xor(x: isize) -> isize {
    if x % 2 != 0 { return odd_xor(x); }
    odd_xor(x + 1) ^ (x + 1)
}

fn odd_xor(x: isize) -> isize {
    (x + 1) / 2 % 2
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main() {
    int d, g, ans = 0, eachsum, numpro;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) {
        cin >> p.at(i) >> c.at(i);
        ans += p.at(i);
    }
    for (int bit = 0; bit < (1 << d); bit++) {
        vector<bool> solved(d, false);
        eachsum = 0;
        numpro = 0;
        for (int i = 0; i < d; i++) {
            if(bit & (1 << i)) {
                eachsum += 100 * (i + 1) * p.at(i) + c.at(i);
                numpro += p.at(i);
                solved.at(i) = true;
            }
        }
        if (eachsum >= g) ans = min(ans, numpro);
        else {
            for (int i = d - 1; i >= 0; i--) {
                if (solved.at(i)) continue;
                for (int j = 1; j <= p.at(i); j++){
                    eachsum += 100 * (i + 1);
                    if (j == p.at(i)) eachsum += c.at(i);
                    numpro++;
                    if (eachsum >= g) break;
                }
                if (eachsum >= g) break;
            }
        }
        ans = min(ans, numpro);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596