akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

int  mod;
struct mint{
    ll x;
    mint (ll x=0) : x((x%mod+mod)%mod){}//カッコの中で初期化している
    mint& operator+=(const mint a){//operatorは構造体同士の比較に用いられる
        if((x +=a.x)>=mod) x-=mod;
        return *this;//thisとは現在のオブジェクトのこと
    }
    mint& operator-=(const mint a){
        if((x +=mod-a.x)>=mod) x-=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x*=a.x)%=mod;
        return *this;
    }
    mint operator+(const mint a){
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a){
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a){
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const{
        if(!t) return 1;
        mint a=pow(t>>1);
        a*=a;
        if(t&1) a*=*this;
        return a;
    }
    mint inv() const{
        return pow(mod-2);//逆元
    }
    mint&operator/=(const mint a) {
        return (*this)*=a.inv();
    }
    mint&operator/(const mint a) const{
    mint res(*this);
    return res/=a;
    }
};
 
int main(void){
    int n;
    int m;
    cin>>n>>m;
    mod = m;
    vector<mint> v(n);
    rep(i, n){
        ll a;
        cin>>a;
        v[i] = a;
    }
    map<ll, ll> mp;
    mint now = v[0];
    mp[now.x]++;
    rep(i, n-1){
        now += v[i+1];
        mp[now.x]++;
    }
    ll ans = 0;
    for(auto p : mp){
        if(p.first == 0) ans += p.second + p.second*(p.second-1)/2;
        else ans += p.second*(p.second-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {
    static long[] fac = new long[1000003];
    static long[] finv = new long[1000003];
    static long[] inv = new long[1000003];
    static final int MOD = 1000000007;
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a  = sc.nextInt();
        int b = sc.nextInt();

        long aa = 1;
        long bb = 1;
        //前処理
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < 1000003; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
        for (int i = 0 ; i < a ; i++) {
            aa *= (long) (n - i) % MOD;
            aa %= MOD;
        }
        for (int i = 0 ; i < b ; i++) {
            bb *= (long) (n - i) % MOD;
            bb %= MOD;
        }

        aa *= finv[a] % MOD;
        bb *= finv[b] % MOD;
        aa %= MOD;
        bb %= MOD;
        long ans = (pow (2, n) - 1 - aa - bb) % MOD;
        if (n == 2) {
            System.out.println(0);
            return;
        }
        System.out.println((ans + MOD) % MOD);
    }

    static int pow (long b, int e) {
        long ans = 1;
        while (e > 0) {
            if (e % 2 == 1) {
                ans = ans * b % MOD;
            }
            e >>= 1;
            b = b * b % MOD;
        }
        return (int) ans;
    }

}

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

int main(){

  int n;
  int a,b,ans2=0;

  cin>>n>>a>>b;

  for(int i=a;i<=n;i++){
    int cnt=i;
    int ans=0;
    while(cnt!=0){
      ans+=cnt%10;
      cnt=cnt/10;
    }

    if(a<=ans&&ans<=b){
      ans2+=i;
    }
  }

  cout<<ans2<<endl;

  return 0;

}


Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
    int a,b,c,d,s=0,i,j;
    scanf("%d%d",&a,&b);
    for(i=a;i<=b;i++){
        d=i;
        c=0;
        while(d/10!=0){
            c+=d%10;
            c=c*10;
            d=d/10;
        }
        c+=d;
        if(i-c==0)
            s++;
    }
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<map>
#include<string>
#include<numeric>
#include<set>
using namespace std;

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

  int ans = 0;

  if(n < 10) cout << n << endl;
  else if(n < 1000) cout << 9 + max(0, n-99) << endl;
  else if(n < 100000) cout << 9 + 900 + max(0, n - 9999) << endl;
  else cout << 90909 << endl;
  
  return 0;
}


Measured memory_bytes: 256
def dfs(s, m):
    if len(s) == N:
        print (s)
        return
    for i in range(0, m+1):
        if i < m:
            dfs(s+chr(ord("a")+i), m)
        else:
            dfs(s+chr(ord("a")+i), m+1)

N = int(input())
dfs("", 0)

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

using ll = long long;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int n;
ll p[20005];
ll r[20005];
int main()
{
	std::cin >> n;
	for (int i = 0; i < n; ++i)
		std::cin >> p[i];

	for (int i = 0; i < n; ++i)
		r[p[i]] = i + 1;

	for (int i = 1; i <= n; ++i)
		std::cout << 30000 * i << ' ';

	std::cout << std::endl;

	for (int i = 1; i <= n; ++i)
		std::cout << 30000 * (n - i) + r[i] << ' ';

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


Measured memory_bytes: 896
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

int main() {
	int W, H, x, y, r;
	cin >> W >> H >> x >> y >> r;
	if (x - r<0 || x + r>W) {
		cout << "No" << endl;
	}
	else if (y - r<0 || y + r>H) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstring>

using namespace std;

int main()
{
    string w;
    int len;
    int num_1 = 0,num_2 = 0,num_3 = 0,num_4 = 0,num_5 = 0,num_6 = 0,num_7 = 0,num_8 = 0,num_9 = 0,num_10 = 0,num_11 = 0,num_12 = 0,num_25 = 0,num_26 = 0;
    int num_13 = 0,num_14 = 0,num_15 = 0,num_16 = 0,num_17 = 0,num_18 = 0,num_19 = 0,num_20 = 0,num_21 = 0,num_22 = 0,num_23 = 0,num_24 = 0;
    cin >> w;
    len = w.length();
    for(int i = 0; i <= len; i++){
        if(w[i] == 'a'){
            num_1++;
        }else if(w[i] == 'b'){
            num_2++;
        }else if(w[i] == 'c'){
            num_3++;
        }else if(w[i] == 'd'){
            num_4++;
        }else if(w[i] == 'e'){
            num_5++;
        }else if(w[i] == 'f'){
            num_6++;
        }else if(w[i] == 'g'){
            num_7++;
        }else if(w[i] == 'h'){
            num_8++;
        }else if(w[i] == 'i'){
            num_9++;
        }else if(w[i] == 'j'){
            num_10++;
        }else if(w[i] == 'k'){
            num_11++;
        }else if(w[i] == 'l'){
            num_12++;
        }else if(w[i] == 'm'){
            num_13++;
        }else if(w[i] == 'n'){
            num_14++;
        }else if(w[i] == 'o'){
            num_15++;
        }else if(w[i] == 'p'){
            num_16++;
        }else if(w[i] == 'q'){
            num_17++;
        }else if(w[i] == 'r'){
            num_18++;
        }else if(w[i] == 's'){
            num_19++;
        }else if(w[i] == 't'){
            num_20++;
        }else if(w[i] == 'u'){
            num_21++;
        }else if(w[i] == 'v'){
            num_22++;
        }else if(w[i] == 'w'){
            num_23++;
        }else if(w[i] == 'x'){
            num_24++;
        }else if(w[i] == 'y'){
            num_25++;
        }else if(w[i] == 'z'){
            num_26++;
        }
    }
    if(num_1 % 2 == 0 && num_2% 2 == 0 && num_3 % 2 == 0 &&
       num_4 % 2 == 0 && num_5 % 2 == 0 && num_6 % 2 == 0 &&
       num_7 % 2 == 0 && num_8 % 2 == 0 && num_9 % 2 == 0 &&
       num_10 % 2 == 0 && num_11 % 2 == 0 && num_12 % 2 == 0 &&
       num_13 % 2 == 0 && num_14 % 2 == 0 && num_15 % 2 == 0 &&
       num_16 % 2 == 0 && num_17 % 2 == 0 && num_18 % 2 == 0 &&
       num_19 % 2 == 0 && num_20 % 2 == 0 && num_21 % 2 == 0 &&
       num_22 % 2 == 0 && num_23 % 2 == 0 && num_24 % 2 == 0 &&
       num_25 % 2 == 0 && num_26 % 2 == 0){
        cout << "Yes" << endl;
       }else{
        cout << "No" << endl;
       }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

struct Point { double x, y; };

void koch(int n, Point a, Point b) {
	if (n == 0) return;
	Point s, t, u;
	double th = M_PI * 60.0 / 180.0;	/* π/3 = 60° */

	s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
	s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
	t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
	t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
	u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
	u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

	koch(n - 1, a, s);
	printf("%.8f %.8f\n", s.x, s.y);
	koch(n - 1, s, u);
	printf("%.8f %.8f\n", u.x, u.y);
	koch(n - 1, u, t);
	printf("%.8f %.8f\n", t.x, t.y);
	koch(n - 1, t, b);
}

int main() {
	Point a, b;
	int n;

	scanf("%d", &n);

	a.x = 0;
	a.y = 0;
	b.x = 100;
	b.y = 0;

	printf("%.8f %.8f\n", a.x, a.y);
	koch(n, a, b);
	printf("%.8f %.8f\n", b.x, b.y);

	return 0;
}


Measured memory_bytes: 2756
#inport
import sys
import numpy as np
from collections import deque


#input
N,M = [int(x) for x in sys.stdin.readline().split()]
g = [int(x) for x in sys.stdin.readline().split()]

g = np.array(g)
#print(g)
#print(1/4/M*np.sum(g))
#print(g >= 1/4/M*np.sum(g))

if np.count_nonzero(g >= 1/4/M*np.sum(g)) >= M:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 27268
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
string a;

int main(){
	IOS
	cin >> a;
	int b=a.length();
	while(b--){
		cout << 'x';
	}
	cout << endl;
}

Measured memory_bytes: 3656
#include<stdio.h>
int main(void)
{
	long long a,b,c,d,e,f,g;
	scanf("%lld %lld %lld",&a,&b,&c);//a位置,b回数,c距離//
	if(a<0) a=-a;
	d=a/c;/*移動回数*/
	e=a%c;/*位置*/
	if(d<=b){
		f=d-b;
		if(f%2==0){
			printf("%lld\n",e);
		}
		else {
			printf("%lld\n",c-e);
		}
	}
	else {
		printf("%lld\n",a-(b*c));
	}
	return 0;
}

Measured memory_bytes: 1704
#include<stdio.h>
int main()
{
    int A1,A2,A3;
    scanf("%d%d%d",&A1,&A2,&A3);
    if(A1+A2+A3>=22)
    {
      printf("bust");
    }
    else
      {
          printf("win");
      }
      return 0;
}


Measured memory_bytes: 1720
import Data.IORef
import Control.Monad
  
main :: IO()
main = getLine >> getContents >>= solve.map read.lines >>= print
  
solve :: [Int] -> IO Int
solve (x : y : xs) = do
                a <- newIORef (y - x)
                b <- newIORef (if x < y then x else y)
                forM_ xs $ \z -> do
                    a' <- readIORef a
                    b' <- readIORef b
                    when (z - b' > a') $ writeIORef a (z - b')
                    when (z < b')      $ writeIORef b z
                readIORef a

Measured memory_bytes: 5584
#include <stdio.h>
long long int lcm(long long int c, long long int d);
long long int gcd(long long int c, long long int d);
int main()
{
    long long int a,b,c,d,res;
    
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    
long long int     p=b/c;
long long int     q=(a-1)/c;
long long int     r=b/d;
long long int     s=(a-1)/d;
long long int     t=b/lcm(c,d);
long long int     u=(a-1)/lcm(c,d);
    
    res=(b-(a-1))-(p-q+r-s-(t-u));
    
    printf("%lld",res);
    
}
long long int gcd(long long int c, long long int d)
{
    if(c==0)
    return d;
    else 
    return gcd(d%c,c);
}
long long int lcm(long long int c,long long int d)
{   
   long long  int p=(c*d)/gcd(c,d);
    return p;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	string s; cin >> s;
	int ans;
	for(char i:s){
		if(i=='+') ans++;
		else ans--;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#from collections import deque,defaultdict
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7
#R = 998244353

def ddprint(x):
  if DBG:
    print(x)

n = inn()
c = ins()
l = 0
r = n-1
cnt = 0
while l<r:
    while l<r and c[l]=='R':
        l += 1
    while l<r and c[r]=='W':
        r -= 1
    if l>=r:
        break
    cnt += 1
    l += 1
    r -= 1
print(cnt)


Measured memory_bytes: 67832
#include <iostream>
#include <cstdio>

int a,b,sum[1000];

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin>>a>>b;
    for(int i=1;i<=999;i++){
        sum[i]=sum[i-1]+i;
    }
    cout<<sum[b-a]-b<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};


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

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

    sort(L.begin(), L.end());
    int total = 0;
    for(int i = 0; i < N; i++){
      for(int j = i+1; j < N; j++){
        int a = L[i];
        int b = L[j];
        int c_min = b-a;
        int c_max = a+b;
        int cnt = lower_bound(L.begin()+j,L.end(),c_max)-1
        -upper_bound(L.begin()+j,L.end(),c_min);
        total += cnt;
      }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
using namespace std;
const int N=205;
struct edge{int to,nxt,w;}a[N*N];
int n,m,S,T,head[N],cnt,dep[N],q[N],hd,tl,cur[N],ans[N][N];
vector<int>vec[N][N];
void link(int u,int v){
	a[++cnt]=(edge){v,head[u],1};head[u]=cnt;
	a[++cnt]=(edge){u,head[v],0};head[v]=cnt;
}
bool bfs(){
	memset(dep,0,sizeof(dep));
	dep[q[hd=tl=1]=S]=1;
	while(hd<=tl)
		for(int u=q[hd++],e=head[u];e;e=a[e].nxt)
			if(a[e].w&&!dep[a[e].to]){
				dep[q[++tl]=a[e].to]=dep[u]+1;
				if(a[e].to==T)return true;
			}
	return false;
}
int dfs(int u,int f){
	if(u==T)return f;int res=0;
	for(int &e=cur[u];e;e=a[e].nxt)
		if(a[e].w&&dep[a[e].to]==dep[u]+1){
			int d=dfs(a[e].to,min(a[e].w,f));
			a[e].w-=d;a[e^1].w+=d;f-=d;res+=d;
			if(!f)break;
		}
	if(!res)dep[u]=0;return res;
}
void dinic(){
	while(bfs())memcpy(cur,head,sizeof(cur)),dfs(S,1<<30);
}
int main(){
	scanf("%d%d",&n,&m);S=n+n;T=n+n+1;
	for(int i=0,x;i<n;++i)
		for(int j=0;j<m;++j){
			scanf("%d",&x);--x;
			vec[i][x/m].push_back(x);
		}
	for(int i=0;i<m;++i){
		memset(head,0,sizeof(head));cnt=1;
		for(int j=0;j<n;++j){
			for(int k=0;k<n;++k)
				if(vec[j][k].size())
					link(j,k+n);
			link(S,j);link(j+n,T);
		}
		dinic();
		for(int j=0;j<n;++j){
			for(int e=head[j];e;e=a[e].nxt)
				if(!a[e].w){
					int k=a[e].to-n;
					ans[i][j]=vec[j][k].back();
					vec[j][k].pop_back();
				}
		}
	}
	for(int i=0;i<n;++i,puts(""))
		for(int j=0;j<m;++j)
			printf("%d ",ans[j][i]+1);
	for(int i=0;i<m;++i)
		sort(ans[i],ans[i]+n);
	for(int i=0;i<n;++i,puts(""))
		for(int j=0;j<m;++j)
			printf("%d ",ans[j][i]+1);
	return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
int main() {
	int num;
	scanf("%d",&num);
	int sum=0;
	int t=num;
	while(t>0) {
		sum+=t%10;
		t/=10;
	}
	if(num%sum==0) {
		printf("Yes\n");
	}
	else {
		printf("No\n");
	}
	return 0;
}


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

class Graph{
    int V;
    list<int> *adj;
    void topologicalSortUtil(int v, bool visited[], stack<int> &Stack);
public:
    Graph(int V);
    void addEdge(int v, int w);
    void longestPath();
};

Graph::Graph(int V){
    this->V = V;
    adj = new list<int>[V];
}
void Graph::addEdge(int v, int w){
    adj[v].push_back(w);
}
void Graph::topologicalSortUtil(int v, bool visited[], stack<int> &Stack){
    visited[v] = true;
    list<int>::iterator i;
    for(i = adj[v].begin();i != adj[v].end(); i++){
        if(!visited[*i])
            topologicalSortUtil(*i,visited,Stack);
    }
    Stack.push(v);
}
void Graph::longestPath(){
    bool *visited = new bool[V];
    for(int i=0;i<V;i++)
        visited[i] = false;
    stack<int> Stack;
    for(int i=0;i<V;i++)
        if(visited[i] == false)
            topologicalSortUtil(i,visited,Stack);
    int dist[V];
    for(int i=0;i<V;i++)
        dist[i] = INT_MIN;
    dist[0] = 0;
    while(!Stack.empty()){
        int u = Stack.top();
        Stack.pop();
        list<int>::iterator i;
        if(dist[u]!=INT_MIN)
            for(i = adj[u].begin(); i != adj[u].end(); i++)
                if(dist[*i]<dist[u]+1)
                    dist[*i] = dist[u] + 1;
    }
    int result = INT_MIN;
    for(auto i: dist)
        result = max(result,i);
    cout<<result-1;
}

int main(){
    int n_nodes,n_edges;
    cin>>n_nodes>>n_edges;
    Graph g(n_nodes+1);
    for(int i=0;i<n_edges;i++){
        int from , to;
        cin>>from>>to;
        g.addEdge(from, to);
    }
    for(int i=1;i<=n_nodes;i++){
        g.addEdge(0,i);
    }
    g.longestPath();
}

Measured memory_bytes: 11264
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
template<class T>inline bool CHMIN(T&a,T b){if(a > b){a = b;return true;}return false;}
template<class T>inline bool CHMAX(T&a,T b){if(a < b){a = b;return true;}return false;}
constexpr int INF = 1e18;

vector<vector<int> > calcNext(const vector<int> &S) {
	int n = (int)S.size();
	vector<vector<int> > res(n+1, vector<int>(26, 0));
	for (int i = 1; i < n + 1; ++i) {
		for (int j = 0; j < 26; ++j) res[i][j] = res[i-1][j];
		res[i][S[i - 1]] = i;
	}
	return res;
}

signed main(){
	int D;
	cin >> D;
	vector<int>c(26);
	REP(i,26){
		cin >> c[i];
	}
	vector<vector<int>>s(D,vector<int>(26));
	REP(i,D){
		REP(j,26){
			cin >> s[i][j];
		}
	}
	vector<int>ans(D,-1);
	REP(i,D){
		cin >> ans[i];
		--ans[i];
	}
	auto last = calcNext(ans);
	auto getScore = [&](int day) -> int {
		int ret = 0;
		ret += s[day][ans[day]];
		REP(i,26){
			ret -= (day + 1 - last[day + 1][i]) * c[i];
		}
		return ret;
	};
	int sum = 0;
	REP(i,D){
		sum += getScore(i);
		out(sum);
	}
}

Measured memory_bytes: 3772
import sys
import copy

def print_data(data):
    last_index = len(data) - 1
    
    for idx, item in enumerate(data):
        print(item, end='')
        if idx != last_index:
            print(' ', end='')

    print('')

def bubbleSort(data, N):
    for i in range(N):
        j = N -1
        while j >= i+1:
            if data[j][1] < data[j-1][1]:
                hoge = data[j]
                data[j] = data[j-1]
                data[j-1] = hoge
            j -= 1
    return data

def selectSort(data, N):
    for i in range(N):
        mini = i
        for j in range(i, N):
            if data[j][1] < data[mini][1]:
                mini = j
        if i == mini:
            pass
        else:
            hoge = data[mini]
            data[mini] = data[i]
            data[i] = hoge
    
    return data

def isStable(inData, outData, N):
    for i in range(N):
        for j in range(i+1, N):
            if inData[i][1] == inData[j][1]:
                a = outData.index(inData[i])
                b = outData.index(inData[j])
                if a > b :
                    return False
    return True




def main():
    N = int(input())
    data0 = list(input().split())
    data1 = copy.deepcopy(data0)
    data2 = copy.deepcopy(data0)
    
    bubbleData = bubbleSort(data1, N)
    selectData = selectSort(data2, N)
    
    
                  
        
    print_data(bubbleData)
    if isStable(data0, bubbleData, N):
        print('Stable')
    else:
        print('Not stable')
    
        
    print_data(selectData)
    if isStable(data0, selectData, N):
        print('Stable')
    else:
        print('Not stable')

            
if __name__ == '__main__':
    main()


Measured memory_bytes: 6344
/*
t.me/ivanesipovvpered
*/
#pragma ARCENIY_KIRILLOV_POVELITEL_KROKODILOV
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("no-stack-protector")
//#pragma GCC push_options
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC pop_options
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define rng(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define rep(i, n) for (int i = 0; i < n; i++)
#define per(i, n) for (int i = n - 1; i > -1; i--)
#define rer(i, x, n) for (int i = x; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef long double ld;

const double EPS = 1e-5;
const int mod = 1e9 + 7;
const ll INFLL = 1e18;
const int INF = 1e9;
const int maxn = 1e5 + 3;

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

ll lcm(ll a, ll b){
    return (a / gcd(a, b) )* b;
}

bool is_prime(ll a){
    if (a == 2 || a == 3 || a == 5 || a == 7) return true;
    if (a % 2 == 0 || a%3 == 0 || a%5 == 0 || a%7 == 0)
        return false;
    for (ll i = 11; i * i <= a; i += 2){
        if (a % i == 0)
            return false;
    }
    return true;
}

ll binpow(ll a, int n){
    if (a == 0)
        return 1;
    if (a % 2 == 0){
        ll q = binpow(a, n / 2);
        return (q * q)  ;
    }else return (a * binpow(a, n - 1) ) ;
}

istream& operator>>(istream &in, vector<ll> &p) {
    int n = p.size();
    for (int i = 0; i < n; i++)
        in >> p[i];
    return in;
}

istream& operator>>(istream &in, vector<int> &p) {
    int n = p.size();
    for (int i = 0; i < n; i++)
        in >> p[i];
    return in;
}

ostream& operator<<(ostream &out, vector<int> &p) {
    int n = p.size();
    for (int i = 0; i < n; i++)
        out << p[i] << ' ';
    out << endl;
    return out;
}

ostream& operator<<(ostream &out, vector<ll> &p) {
    int n = p.size();
    for (int i = 0; i < n; i++)
        out << p[i] << ' ';
    out << endl;
    return out;
}

istream& operator>>(istream &in, pair<int, int> &p) {
    in >> p.fi >> p.se;
    return in;
}

ostream& operator<<(ostream &out, pair<int, int> &p) {
    out << p.fi << " " << p.se << endl;
    return out;
}



















main(){
    int m, d;
    cin >> m >> d;
    int ans = 0;
    for (int i = 1; i <= m; i++){
        for (int j = 10; j <= d; j++){
            int d1 = j / 10;
            int d2 = j % 10;
            if (d1 >= 2 && d2 >= 2 && d1 * d2 == i){
                    ans++;

            }
        }
    }
    cout << ans;


}


Measured memory_bytes: 256
from collections import deque
n=int(input())
tree=[[] for _ in range(n+1)]
for i in range(1,n):
  a,b=map(int,input().split())
  tree[a].append([b,i])
  tree[b].append([a,i])
queue=deque([[1,0]])
ans=[0]*(n+1)
ans[1]=1
visited=[0]*(n+1)

while queue:
  v,c=queue.popleft()
  color=1
  for nv,i in tree[v]:
    if c==color:
      color+=1
    if visited[i]==1:
      continue
    visited[i]=1
    queue.append([nv,color])
    ans[i]=color
    color+=1
print(max(ans))
for i in range(1,n):
  print(ans[i])

Measured memory_bytes: 47676
#include<bits/stdc++.h>
using namespace std;
 
int pow(int a, int b){
  int aa = 1;
  for(int i=0; i<b; i++) aa *= a;
  return aa;
}
 
int main(){
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for(int i=0; i<M; i++) cin >> s.at(i) >> c.at(i);
  int number = 0;
  if(N != 1) number += pow(10, N-1);
  int digit;
  int dignum;
  for(int i=0; i<M; i++){
    digit = pow(10, (N - s.at(i)));
    dignum = (number % (digit * 10)) / digit;
    number -= (digit * dignum);
    number += (digit * c.at(i));
  }
  
  
  
  for(int i=0; i<(M-1);i++){
    for(int j=i+1; j<M; j++){
      if(s.at(i) == s.at(j)){
        if(c.at(i) != c.at(j)) number = -1;
      }
    }
  }
  
  for(int i=0; i<M; i++){
    if(s.at(i) == 1){
      if(N != 1 && c.at(i) == 0) number = -1;
    }
  }
  
  cout << number << endl;
}

Measured memory_bytes: 256
import collections
N, M, K = map(int, input().split())
friend = [[] for i in range(N)]
block = [[] for i in range(N)]
graph = [-1] * N
for i in range(M):
  a, b = map(int, input().split())
  friend[a-1].append(b-1)
  friend[b-1].append(a-1)
  
for i in range(K):
  c, d = map(int, input().split())
  block[c-1].append(d-1)
  block[d-1].append(c-1)
  
#print(friend, block)

used = [True] * N
for i in range(N):
  if used[i]:
    q = [i]
    used[i] = False
    graph[i] = i
    while q:
      now = q.pop()
      for j in friend[now]:
        if used[j]:
          graph[j] = graph[now]
          q.append(j)
          used[j] = False
          
          
#print(graph)          
gg = dict(collections.Counter(graph))  
#print(gg)

for i in range(N):
  nn = graph[i]
  size = gg[nn]
  ans = size - 1
  for j in friend[i]:
    if nn == graph[j]:
      ans -= 1
  for j in block[i]:
    if nn == graph[j]:
      ans -= 1
  print(ans, end = " ")




Measured memory_bytes: 135904
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false); cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	deque<char> d;
	for (int i = 0; i < n; i++) {
		if (d.empty()) {
			d.push_back(s[i]);
			continue;
		}
		if (d.back() == '(' && s[i] == ')') d.pop_back();
		else d.push_back(s[i]);
	}
	int open = 0, close = 0;
	for (int i = 0; i < (int) d.size(); i++) {
		open += d[i] == ')';
		close += d[i] == '(';
	}
	for (int i = 0; i < open; i++) {
		cout << '(' ;
	}
	cout << s;
	for (int i = 0; i < close; i++) {
		cout << ')';
	}
	cout << endl;
	return 0;	
}

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

string A, B, C;

int main() {
	cin >> A >> B >> C;
	bool b1 = A[A.length() - 1] == *B.begin();
	bool b2 = B[B.length() - 1] == *C.begin();
	cout << (b1 && b2 ? "YES" : "NO") << '\n';
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w,n;
cin>>h>>w>>n;
int y=h;
int j=w;
int e=1,ee=1;
int count=1,con=1;
while(h<n){
        h+=y;
    count++;
}
while(w<n){
    w+=j;
    con++;
}
cout<<min(con,count);
}


Measured memory_bytes: 256
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cstring>
#include <functional>
#include <iostream>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <cmath>
#include <array>
#include <complex>

#define endl '\n'

using namespace std;

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

    string s;
    cin >> s;

    vector<int> pre(s.length());

    int x = 0, m = 0;

    for (int i = 0; i < s.length(); ++i)
    {
        x += s[i] == '0' ? +1 : -1;
        m = max(x, m);
        pre[i] = x;
    }

    vector<int> pre_rev = pre;

    for (int i = (int)s.length() - 2; i >= 0; --i)
        pre_rev[i] = max(pre_rev[i], pre_rev[i + 1]);
    pre_rev.push_back(-1000000000);

    int res = s.length();

    for (int j = 0; j < 2; ++j)
    {
        int z = m + j, l = 0, x = 0, k = 0;

        for (int i = 0; i < s.length(); ++i)
        {
            if (s[i] == '?')
            {
                if (max(x + 1, pre_rev[i + 1] + 2 * (k + 1)) <= z)
                {
                    x += 1;
                    k += 1;
                }
                else
                {
                    x--;
                }
            }
            else if (s[i] == '0')
            {
                x++;
            }
            else
            {
                x--;
            }

            l = min(l, x);
        }

        res = min(res, z - l);
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 15752
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){
    int n,k,t=0;
    cin>>n>>k;
    vector<int> v(k+1);
    for(int i=0;i<k;i++) cin>>v[i];
    v[k]=n+v[0];
    for(int i=1;i<k+1;i++) t=max(t,v[i]-v[i-1]);
    cout<<n-t;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

struct Node{
  int parent, left, right;
};

int n;
Node T[30];
int D[30], H[30];

void depth(int u, int d){
  if(u == -1) return;
  D[u] = d;
  depth(T[u].left, d+1);
  depth(T[u].right, d+1);
}

int height(int u){
  int ret1 = 0, ret2 = 0;
  if(T[u].left != -1) ret1 = height(T[u].left) + 1;
  if(T[u].right != -1) ret2 = height(T[u].right) + 1;
  return (H[u] = max(ret1, ret2));
}

signed main(){
  cin >> n;
  int u, l, r;

  for(int i = 0 ; i < 30 ; i++){
    T[i].parent = T[i].left = T[i].right = -1;
  }

  for(int i = 0 ; i < n ; i++){
    cin >> u >> l >> r;
    T[u].left = l;
    T[u].right = r;
    if(l != -1) T[l].parent = u;
    if(r != -1) T[r].parent = u;
  }

  int root;
  for(int i = 0 ; i < n ; i++){
    if(T[i].parent == -1) root = i;
  }
  
  depth(root, 0);
  height(root);
  
  for(int i = 0 ; i < n ; i++){
    cout << "node " << i << ": ";
    cout << "parent = " << T[i].parent << ", ";
    cout << "sibling = ";
    if(T[i].parent == -1){
      cout << -1 << ", ";
    }else if(T[T[i].parent].left != -1 && T[T[i].parent].left != i){
      cout << T[T[i].parent].left << ", ";
    }else if(T[T[i].parent].right != -1 && T[T[i].parent].right != i){
      cout << T[T[i].parent].right << ", ";
    }else{
      cout << -1 << ", ";
    }
    cout << "degree = " << (T[i].left!=-1?1:0)+(T[i].right!=-1?1:0) << ", ";
    cout << "depth = " << D[i] << ", ";
    cout << "height = " << H[i] << ", ";
    if(root == i) cout << "root" << endl;
    else if(T[i].left != -1 || T[i].right != -1) cout << "internal node" << endl;
    else cout << "leaf" << endl;
  }

}



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

int less(void const* pa, void const* pb) {
  int a = *(int const*)pa;
  int b = *(int const*)pb;
  if (a < b) return +1;
  if (a > b) return -1;
  return 0;
}

int main(void) {
  size_t n;
  scanf("%zu", &n);

  int a[n];
  for (size_t i = 0; i < n; ++i)
    scanf("%d", &a[i]);

  qsort(a, n, sizeof(int), less);
  for (size_t i = 1; i < n; ++i)
    if (a[i-1] == a[i]) return puts("NO"), 0;

  puts("YES");
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,ans=0;
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		if (1<=i&&i<=9)
		{
			ans++;
			continue;
		}
		if (100<=i&&i<=999)
		{
			ans++;
			continue;
		}
		if (10000<=i&&i<=99999)
		{
			ans++;
			continue;
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n,x,a[111111];
  cin>>n>>x;
  for(int i=0;i<n;i++)cin>>a[i];
  int ans=0;
  if(a[0]>x)ans=a[0]-x,a[0]=x;
  for(int i=1;i<n;i++){
    int t=a[i-1]+a[i];
    if(t>x){ans+=t-x;
      a[i]-=t-x;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

int dp_max[300][300];
int dp_min[300][300];
int val[300];
int rest[300];
void solve() {
    string s;
    cin >> s;
    int now = 0;
    REP(i, s.length()) {
        if (s[i] == '(') {
            rest[now] |= 1;
        }
        else if (s[i] == ')') {
            rest[now - 1] |= 2;
        }
        else if (s[i] == '+') {
            val[now] = -1;
            now++;
        }
        else if (s[i] == '-') {
            val[now] = -2;
            now++;
        }
        else {
            val[now] = s[i] - '0';
            now++;
        }
    }
    REP(i, now + 1) {
        REP(q, now + 1) {
            dp_min[i][q] = 1e18;
            dp_max[i][q] = -1e18;
        }
    }
    REP(i, now) {
        if (val[i] >= 0) {
            dp_max[i][i] = val[i];
            dp_min[i][i] = val[i];
        }
    }
    for (int len = 3; len <= now; len += 2) {
        for (int q = 0; q < now - len + 1; ++q) {
            if (rest[q] == 2) continue;
            if (rest[q + len - 1] == 1) continue;
            for (int j = 1; j < len - 1; ++j) {
                if (val[q + j] == -1) {
                    dp_max[q][q + len - 1] = max(dp_max[q][q + len - 1], dp_max[q][q + j - 1] + dp_max[q + j + 1][q + len - 1]);
                    dp_min[q][q + len - 1] = min(dp_min[q][q + len - 1], dp_min[q][q + j - 1] + dp_min[q + j + 1][q + len - 1]);
                }
                if (val[q + j] == -2) {
                    dp_max[q][q + len - 1] = max(dp_max[q][q + len - 1], dp_max[q][q + j - 1] - dp_min[q + j + 1][q + len - 1]);
                    dp_min[q][q + len - 1] = min(dp_min[q][q + len - 1], dp_min[q][q + j - 1] - dp_max[q + j + 1][q + len - 1]);
                }
            }
        }
    }
    cout << dp_max[0][now - 1] << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 4176
s=list(raw_input().split("T"))
#print s
x,y=map(int,raw_input().split())
cx,cy=len(s[0]),0
lx=[len(_) for _ in s[2::2]]
ly=[len(_) for _ in s[1::2]]
#print lx
#print ly

memo_x=[set((cx,))]
for ind_i,i in enumerate(lx):
	next_memo_x = set()
	for j in memo_x[ind_i]:
		next_memo_x.add(j+i)		
		next_memo_x.add(j-i)
	memo_x.append(next_memo_x)
#print memo_x


memo_y=[set((cy,))]
for ind_i,i in enumerate(ly):
	next_memo_y = set()
	for j in memo_y[ind_i]:
		next_memo_y.add(j+i)		
		next_memo_y.add(j-i)
	memo_y.append(next_memo_y)
#print memo_y

if x in memo_x[-1] and y in memo_y[-1]:
	print "Yes"
else:
	print "No"




Measured memory_bytes: 330244
#define _USE_MATH_DEFINES
#include <math.h>
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int a,b,h;
    cin >> a >> b >> h;
    cout << (a + b) * (h / 2) << "\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(){
   int A, B, K;
   std::cin >> A >> B >> K;
   int min = A < B ? A : B;
   int count = 0;
   for(int i=min+1; i>0; --i){
      if(A%i==0 && B%i==0){
	 ++count;
	 //std::cout << i << ' ' << count << std::endl;
      }
      if(count==K){
	 std::cout << i << std::endl;
	 return 0;
      }
   }
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**7)
MOD=10**9+7

n=int(input())
edge=[[] for _ in range(n)]
for _ in range(n-1):
    p,q = [int(i)-1 for i in input().split()]
    edge[p].append(q)
    edge[q].append(p)

    
used = [0]*n
ansb = [0]*n
answ = [0]*n

def dfs(x):
    if used[x]: return (ansb[x], answ[x])
    used[x] = 1
    cb=1; cw=1;
    for e in edge[x]:
        if used[e]: continue
        eb,ew = dfs(e)
        cb*=ew
        cb%=MOD
        cw*=(eb+ew)
        cw%=MOD        
    ansb[x]=cb
    answ[x]=cw
    return (cb,cw)

print(sum(dfs(0))%MOD)

#print(used)
#print(ansb)
#print(answ)

Measured memory_bytes: 102064
#include <bits/stdc++.h>
using namespace std;
int my_gcd(int a, int b)
{
	int c;

	while (true)
	{
		if (a == 0)
		{
			return b;
		}
		else if (a == b)
		{
			return a;
		}
		else if (a < b)
		{
			c = a;
			a = b;
			b = c;
		}
		a = a - (a / b) * b;
	}
}
int main()
{
	//cin.tie(0);
	//ios::sync_with_stdio(false);

	int N;
	scanf("%d", &N);

	vector<int> A(N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}

	vector<int> head_gcd(N);
	head_gcd[0] = A[0];
	for (int i = 1; i < N; i++)
	{
		head_gcd[i] = my_gcd(head_gcd[i - 1], A[i]);
	}

	vector<int> tail_gcd(N);
	tail_gcd[N - 1] = A[N - 1];
	for (int i = N - 2; i >= 0; i--)
	{
		tail_gcd[i] = my_gcd(tail_gcd[i + 1], A[i]);
	}

	int result = max(head_gcd[N - 2], tail_gcd[1]);

	for (int i = 1; i < N - 1; i++)
	{
		result = max(result, my_gcd(head_gcd[i - 1], tail_gcd[i + 1]));
	}
	cout << result;
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define N 100010
int n,k,l,r;
int a[N],ans;
int main(){
    while (scanf("%d %d",&n,&k)!=EOF){
        int mn = 1e9;
        for (int i=0;i<n;i++){
            scanf("%d",&a[i]);
            if (i>=k-1){
                l = i-k+1;
                r = i;
                ans = abs(a[r] - a[l]) + min(abs(a[l]),abs(a[r]));
                //printf("[%d,%d] = %d\n",l,r,ans);
                mn = min(mn,ans);
            }
        }
        printf("%d\n",mn);
    }
    return 0;
}



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

using namespace std;

typedef long long ll;

const ll LongINF=1e13+7;
const int INF=1e9+7;
const int dx[]={0,1,0,-1};
const int dy[]={1,0,-1,0};

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template <class T, class Y>T GCD(T a, Y b){if(a<b){int c=a;a=b;b=c;}if (a % b == 0){return b;}return GCD(b, a % b);}
void clear(queue<pair<int, int>> &q){queue<pair<int, int>> empty;swap(q, empty);} //queueの中身の型は適時変更を忘れない

#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define rv reverse

//総和を出す。そこから、10で割れない数を引く

int main(){
    ll N,A,B;
    cin>>N>>A>>B;
    if(N<3){
        if(A!=B&&N==2)cout<<N<<endl;
        else if(A==B&&N==1)cout<<N<<endl;
        else cout<<0<<endl;
    }
    else if(A>B)cout<<0<<endl;
    else{
        ll ANS=(N-2)*(B-A)+1;
        cout<<ANS<<endl;
    }

    return 0;
}

//a=97,z=122

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

using namespace std;

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

//===

//const ll mod = static_cast<int>(1e9 + 7);



int main() {
	int K, X;
	cin >> K >> X;

	int left, right;

	left = max(X - K + 1, -1000000);
	right = min(X + K - 1, 1000000);

	for (int i = left; i <= right - 1; ++i) {
		cout << i << " ";
	}
	cout << right << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <math.h>
#include <sstream>
#include <map>
#include <vector>
#include <queue>
#include <iomanip>
#include <unordered_map>
using namespace std;
typedef long long ll;
ll ans, mx, sum,temp, mn = 1e14, flag,cnt;

string s[100],s2[100];
string t;
int main(){
	ll n,m;
	cin>>n>>m;
	for(ll i=0; i<n; i++){
		cin>>s[i];
	}
	for(ll i=0; i<m; i++){
		cin>>s2[i];
	}
	for(ll i=0; i<n; i++){
		for(ll j=0; j<n; j++){
			t+=s[i][j];
		}	
	}
	for(ll i=0; i<t.size(); i++){
		ll g=0,cnt=0;
		for(ll k=i; k<t.size(); k+=n){
			
			string r=t.substr(k,m);
			if(r==s2[g]){
				cnt++;
				g++;			
			}	
			if(cnt==m){
				cout<<"Yes";
				return 0;
			}
		}
	
		
	}
	cout<<"No";
} 


Measured memory_bytes: 3600
//by rng_59
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <memory.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;

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

bool col[1000010];
bool row[1000010];
const int mod = 1e9+7;
int main(){
	int N,M;
	long long ans = 1;
	cin >> N >> M;
	REP(i,N) {
		int a;
		cin >> a;
		if(row[a]) {
			cout << 0;
			return 0;
		}
		row[a] = 1;
	}
	REP(i,M) {
		int b;
		cin >> b;	
		if(col[b]) {
			cout << 0;
			return 0;
		}
		col[b] = 1;
	}
	int c=0,r=0;
	for(int i=N*M; i>0; i--) {
        int tc = c,tr = r;
        if(col[i]) {
			tc = 1;
			c++;
		}
        if(row[i])  {
			tr = 1;
			r++;
		}
        if(col[i] || row[i]) ans *= (tc*tr)%mod;
        else ans *= (tc*tr-(N*M-i))%mod;
		ans %= mod;
    }
	cout << ans%mod << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <deque>

using namespace std;
using ll = long long;

#define rep(countName, left, right, up) for (ll countName = left; countName < right; countName += up)
#define rev(countName, right, left, down) for (ll countName = right - 1; countName >= left; countName -= down)

int solve1()
{
    int n, m, ans = 0;
    bool exist = true;

    cin >> n >> m;
    vector<int> number(n, -1);

    rep(i, 0, m, 1)
    {
        int s, c;
        cin >> s >> c;
        --s;

        if (number[s] != -1 && number[s] != c)
        {
            //条件の矛盾が存在する場合
            exist = false;
        }
        else if (n > 1 && s == 0 && c == 0)
        {
            //2桁以上の条件下で最大桁を0にしようとしたとき
            exist = false;
        }
        else
        {
            number[s] = c;
        }
    }

    if (exist)
    {
        if (n > 1 && number[0] == -1)
        {
            //2桁以上の数であり、条件が入力で無かった場合
            number[0] = 1;
        }

        rep(i, 0, n, 1)
        {
            if (number[i] == -1)
            {
                number[i] = 0;
            }
            ans += number[i] * pow(10, n - 1 - i);
        }
    }
    else
    {
        ans = -1;
    }

    /*
    rep(i, 0, n, 1)
    {
        cout << number[i];
    }
    cout << endl;
    */

    return ans;
}

int solve2(void)
{
    int n, m;

    cin >> n >> m;
    vector<int> s(m);
    vector<char> c(m);

    rep(i, 0, m, 1)
    {
        cin >> s[i] >> c[i];
        --s[i];
    }

    rep(i, 0, 1000, 1)
    {
        bool ok = true;
        string match = to_string(i);

        if ((int)match.length() != n)
        {
            continue;
        }

        rep(k, 0, m, 1)
        {
            if (match[s[k]] != c[k])
            {
                ok = false;
                break;
            }
        }

        if (ok)
        {
            return i;
        }
    }

    return -1;
}

int main(void)
{
    //cout << solve1() << endl;
    cout << solve2() << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
#include<math.h>
using namespace std;
int main()
{
    long long int a,b,c,d,e,f,i;
    cin>>a>>b>>c;
    d=a/(b+c)*b;

     e=a%(b+c);
     d+=min(e,b);
     cout<<d<<endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

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

    vector<pair<int,int>> red(n);
    for (int i = 0; i < n; i++)
        cin >> red[i].first >> red[i].second;
    vector<pair<int,int>> blue(n);
    for (int i = 0; i < n; i++)
        cin >> blue[i].first >> blue[i].second;

    sort(red.begin(), red.end(), [](auto a, auto b) {
            return a.second > b.second;
        });
    sort(blue.begin(), blue.end(), [](auto a, auto b) {
            return a.first < b.first;
        });
    long count = 0;
    vector<bool> married(n);
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (!married[j] &&
                red[j].first < blue[i].first &&
                red[j].second < blue[i].second) {
                married[j] = true;
                count += 1;
                break;
            }
        }
    }
    cout << count << endl;

    return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (A > 0 and C > 0) {
        C -= B;
        if (C <= 0) break;
        A -= D;
        if (A <= 0) break;
    }
    cout << (C <= 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3640