akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=1e4;
int N;
string S[MAX_N],T;
int C(int x){
	int f=0;
	REP(i,(int)S[x].size()){
		if(i>=(int)T.size()){
			if(f==-1){
				return 0;
			}else{
				return 1;
			}
		}
		if(S[x][i]=='?'){
			if(T[i]>'a' && T[i]<'z'){
				return 0;
			}else if(T[i]=='a'){
				if(f!=-1){
					f=1;
				}else{
					return 0;
				}
			}else{
				if(f!=1){
					f=-1;
				}else{
					return 0;
				}
			}
		}
		if(S[x][i]<T[i]){
			if(f==1){
				return 0;
			}else{
				return -1;
			}
		}else if (S[x][i]>T[i]){
			if(f==-1){
				return 0;
			}else{
				return 1;
			}
		}
	}
	if(S[x].size()==T.size()){
		return 0;
	}
	if(f==1){
		return 0;
	}else{
		return -1;
	}
}
int main(){
	cin>>N;
	REP(i,N)cin>>S[i];
	cin>>T;
	int d=0,c=0;
	REP(i,N){
		int t=C(i);
		if(t<0){
			d++;
		}else if(t==0){
			c++;
		}
	}
	REP(i,c+1){
		if(i)cout<<" ";
		cout<<d+i+1;
	}
	cout<<endl;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int H,W;
int t[250000];
int u[250001];
bool rh[250001];
bool rw[250001];

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

bool solve(){
  int sy=t[0]/W;
  int sx=t[0]%W;
  for(int i=1;i<H*W;i++){
    int y=t[i]/W;
    int x=t[i]%W;
    if( abs(y-sy)%2 == 1 )rh[ t[i] ]=true;
    if( abs(x-sx)%2 == 1 )rw[ t[i] ]=true;
  }
  
  int last=-1;
  stack<int> total;
  stack<int> st[4];
  
  for(int i=0;i<H*W;i++){
    int n=t[i];
    vector<P> v;
    for(int dir=0;dir<4;dir++){
      int y=n/W+dy[dir];
      int x=n%W+dx[dir];
      if(y<0||H<=y)continue;
      if(x<0||W<=x)continue;
      int m=y*W+x;
      v.push_back(P(u[m],dir));
    }
    
    sort(v.begin(),v.end());
    reverse(v.begin(),v.end());
    
    for(int j=0;j<(int)v.size();j++){
      int dir=v[j].second;
      int y=n/W+dy[dir];
      int x=n%W+dx[dir];
      int m=y*W+x;
      int ndir=dir;
      if(rh[n]&&ndir%2==0)ndir=(ndir+2)%4;
      if(rw[n]&&ndir%2==1)ndir=(ndir+2)%4;
      stack<int> &w=st[ndir];
      if(u[m]<i){
        //        cout<<"pop  "<<n<<' '<<m<<' '<<ndir<<endl;
        if(w.empty()||w.top()!=n)return false;
        w.pop();
        //        if(total.top()<last)return false;
        total.pop();
        last=i;
      }
    }
    
    for(int j=0;j<(int)v.size();j++){
      int dir=v[j].second;
      int y=n/W+dy[dir];
      int x=n%W+dx[dir];
      int m=y*W+x;
      int ndir=dir;
      if(rh[n]&&ndir%2==0)ndir=(ndir+2)%4;
      if(rw[n]&&ndir%2==1)ndir=(ndir+2)%4;
      stack<int> &w=st[ndir];
      if(u[m]>=i){
        //        cout<<"push "<<n<<' '<<m<<' '<<ndir<<endl;
        w.push(m);
        total.push(i);
      }
    }
  }
  return true;
}

int main(){
  cin>>H>>W;
  for(int i=0;i<H*W;i++){
    cin>>t[i];
    u[t[i]]=i;
  }
  cout<<(solve()?"YES":"NO")<<endl;
  return 0;
}

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

long long a_min[2000][2000];

int main(){
    //input
    long long N;
    cin >> N;
    long long x;
    cin >> x;
    long long a[2*N], a_sub;
    long long i,j;
    for(i=0; i<N; i++){
        cin >> a_sub;
        a[i]=a_sub;
        a[i+N]=a_sub;
    }

    //calc
    for(i=0; i<N; i++){
        a_min[i][0]=a[i+N];
    }
    for(i=0; i<N; i++){
        for(j=1; j<N; j++){
            a_min[i][j]=min(a_min[i][j-1],a[i+N-j]);
        }
    }
    long long ans=10000000000000000;
    long long val;
    for(j=0; j<N; j++){
        val=j*x;
        for(i=0; i<N; i++){
            val+=a_min[i][j];
        }
        ans=min(ans,val);
    }

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

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

typedef long long ll;

int main(){
	static int n,k;
	static int a[200010];
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	
	static int b[200010];
	for(;k>0;k--){
		for(int i=0;i<200010;i++)b[i]=0;
		for(int i=1;i<=n;i++){
			b[max(1,i-a[i])]++;
			b[min(n,i+a[i])+1]--;
		}
		for(int i=2;i<=n;i++){
			b[i]+=b[i-1];
		}
		bool e=true;
		for(int i=1;i<=n;i++){
			a[i]=b[i];
			e&=a[i]==n;
		}
		if(e)break;
	}
	for(int i=1;i<=n;i++){
		printf("%d%c",a[i],(i==n)?'\n':' ');
	}
}


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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

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

    vector<string> ans;

    while(1){
        ll n, q; cin >> n >> q;
        if(n == 0 && q == 0) break;
        // start, end, name
        vector<pair<pair<ll, ll>, string> > era; 

        for(int i=0;i<n;i++){
            string name;
            ll eyear, wyear;
            cin >> name >> eyear >> wyear;
            ll st = wyear - eyear;
            ll ed = wyear;
            era.push_back(make_pair(make_pair(st, ed), name));
        }

        for(int i=0;i<q;i++){
            ll y; cin >> y;
            bool known = false;
            for(auto e: era){
                if(y > e.first.first && y <= e.first.second){
                    string name = e.second;
                    ll num = y - e.first.first;
                    known = true;
                    ans.push_back(name + " " + to_string(num));
                    break;
                }
            }
            if(!known) ans.push_back("Unknown");
        }
    }
    for(string a: ans) cout << a << endl;
}


Measured memory_bytes: 4372
#include <bits/stdc++.h>
#define PREP(i, s, x) for(ll (i) = (s); (i) < (x); (i) ++)
#define REP(i, x) PREP(i, 0, x)
#define MREP(i, s, x) for(ll (i) = (s); (i) >= (x); (i) --)
#define MOD7 (1000000007LL)
#define MOD9 998244353LL
#define INF (1LL<<60)
typedef long long ll;
using namespace std;
using P = pair<ll, ll>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

ll dfs(vector<string> &field, vector<vector<bool>> &seen, ll x, ll y, ll gx, ll gy, ll kai, ll h, ll w){
    seen[x][y] = true;
    cout << x << " " << y;
    cout << " " << kai << endl;

    ll res = INF;
    if(x == gx && y == gy) return kai;
    REP(dd, 4){
        ll next_x = x+dx[dd], next_y = y+dy[dd];
        cout << " " << next_x << " " << next_y << endl;

        if(next_x < 0 || next_x >= h) continue;
        if(next_y < 0 || next_y >= w) continue;
        if(seen[x+dx[dd]][y+dy[dd]] == true) continue;
        if(field[next_x][next_y] == '#') continue;
        cout << " " << "yap" << endl;
        ll hoge = dfs(field, seen, next_x, next_y, gx, gy, kai+1, h, w);
        chmin(res, hoge);
    }
    return res;
}

int main(){
    ll h, w;
    cin >> h >> w;
    vector<string> field(h);
    REP(i, h){
        cin >> field[i];
    }

    ll ans = 0;

    PREP(sy, 0, h){ // O(h)
        PREP(sx, 0, w){ // O(w)
            if(field[sy][sx] == '#') continue;
            vector<vector<ll>> seen(h, vector<ll>(w, -1));
            ll this_ans  = 0;
            queue<pair<pair<ll, ll>, ll>> que;
            que.push(make_pair(make_pair(sx, sy), 0));
            
            while(!que.empty()){ // O(HW)
                ll x = que.front().first.first;
                ll y = que.front().first.second;
                ll kai = que.front().second;
                que.pop();
                
                chmax(ans, kai);
                if(seen[y][x]!=-1)continue;
                seen[y][x] = kai;

                REP(d, 4){
                    ll next_x = x + dx[d], next_y = y + dy[d];
                    
                    if(next_x < 0 || next_x >= w) continue;
                    if(next_y < 0 || next_y >= h) continue;
                    if(seen[next_y][next_x] != -1) continue;
                    if(field[next_y][next_x] == '#') continue;

                    que.push(make_pair(make_pair(next_x, next_y), kai+1));
                }
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        int K = Integer.parseInt(sc.next());
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(sc.next());
        }

        int res = (N - 1) / (K - 1);
        if ((N - 1) % (K - 1) != 0) {
            res++;
        }

        System.out.println(res);
    }
}


Measured memory_bytes: 49060
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
  
  
signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);
  
  int a; string s;
  cin >> a >> s;

  cout << (a >= 3200 ? s : "red") << endl;

  return 0;
}

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

using namespace std;

int t;

int fomula(string str, int p, int q, int r)
{
	int v = 1;
	if(str[t] == 'P'){
		t++;
		v = p;
	} else if(str[t] == 'Q'){
		t++;
		v = q;
	} else if(str[t] == 'R'){
		t++;
		v = r;
	} else if('0' <= str[t] && str[t] <= '2'){
		v = (int)(str[t]-'0');
		t++;
	} else if(str[t] == '-'){
		t++;
		v = 2-fomula(str, p, q, r);
	} else {
		t++;
		int v1 = fomula(str, p, q, r);
		char w = str[t++];
		int v2 = fomula(str, p, q, r);
		t++;
		if(w == '+'){
			if(v1 == 2 || v2 == 2){
				v = 2;
			} else if(v1 == 0 && v2 == 0){
				v = 0;
			}
		} else {
			if(v1 == 0 || v2 == 0){
				v = 0;
			} else if(v1 == 2 && v2 == 2){
				v = 2;
			}
		}
	}
	
	return v;
}

int main()
{
	int c;
	string str;
	
	while(cin>>str && str != "."){
		c = 0;
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 3; k++){
					t = 0;
					if(fomula(str, i, j, k) == 2){
						c++;
					}
				}
			}
		}
		
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

int main(){
  ll n,W; cin>>n>>W;
  ll weight[n];
  ll value[n];
  for(int i=0;i<n;i++){
    cin>>weight[i]>>value[i];
  }

  ll N = 1000*n+100;
  ll dp[n+1][N];
  ll inf=pow(10,13);
  for(int i=0;i<=n;i++){
    for(int j=0;j<N;j++){
      dp[i][j]=inf;
    }
  }

  dp[0][0]=0;

  for(int i=0;i<n;i++){
    for(int v=0;v<N;v++){
      if(v>=value[i]) dp[i+1][v]=min(dp[i+1][v],dp[i][v-value[i]]+weight[i]);
      dp[i+1][v]=min(dp[i+1][v],dp[i][v]);
    }
  }

  ll ans=0;

  for(int v=0;v<N;v++){
    if(dp[n][v]<=W){
      ans=v;
    }
  }
  
  cout<<ans<<endl;
  /*
  for(int i=0;i<n;i++){
    for(int w=0;w<=W;w++){
      if(w-weight[i]<0) dp[i+1][w]=dp[i][w];
      else dp[i+1][w]=max(dp[i][w],dp[i][w-weight[i]]+value[i]);
    }
  }

  cout<<dp[n][W]<<endl;*/
}

Measured memory_bytes: 79232
import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)
def multiple(a, b):
    return a*b // euclid(a, b)
def lcm(nums):
        return functools.reduce(multiple, nums)

n = int(input())
num = list(map(int, input().split()))
a = lcm(num)-1
ans = 0
for i in num:
    ans += a%i
print(ans)

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

#define ll long long

int main(){
    ll N, ans = pow(10,9);
    cin >> N;
    vector<ll> A(N+1);
    for(int i = 1; i <= N; ++i) cin >> A[i];
    for(int i = 1; i <= N; ++i){
        ll buf = 0;
        while(true){
            if(A[i]%2 == 0){
                ++buf;
                A[i] /= 2;
            }
            else break;
        }
        ans = min(ans, buf);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int cnt=0;
    string  str;
    cin>>str;
        if(str[0]=='R')
        {
            cnt++;
            if(str[1]=='R')
            {
                cnt++;
                if(str[2]=='R')
                    cnt++;
            }
        }
        else  if(str[1]=='R')
        {
            cnt++;
            if(str[2]=='R')
                cnt++;
        }
        else  if(str[2]=='R')
                cnt++;
                cout<<cnt<<endl;
                return 0;

    }


Measured memory_bytes: 3616
# /usr/bin/python3
# -*- coding: utf-8 -*-
from queue import Queue
from queue import LifoQueue as Stack
from math import sqrt, floor, ceil, log2
from fractions import gcd
from itertools import permutations, combinations
from operator import itemgetter
from functools import cmp_to_key


yn = 'YNeos'
ynflg = False
cnt = 0
ans = None

def lcm(a, b):
    return (a*b) // gcd(a,b)

def intinput():
    return int(input())

def mulinputs():
    return map(int,input().split())

def lineinputs(func=intinput):
    datas = []
    while True:
        try:
            datas.append(func())
        except EOFError:
            break
    return datas


A1n = list(map(lambda n: [n, 0], mulinputs()))
A2n = list(map(lambda n: [n, 0], mulinputs()))
A3n = list(map(lambda n: [n, 0], mulinputs()))
N = intinput()

As = [A1n, A2n, A3n]
# for a in A1n + A2n + A3n:
#     aa[a] = 0

bs = []
for i in range(N):
    # bs.append(int(input()))
    b = int(input())
    for row in As:
        for col in row:
            if b == col[0]:
                col[1] = 1

is_bingo = True
is_bingo &= (As[0][0][1] == 1)
is_bingo &= (As[1][1][1] == 1)
is_bingo &= (As[2][2][1] == 1)

if is_bingo:
    print('Yes')
    exit()

is_bingo = True
is_bingo &= (As[2][0][1] == 1)
is_bingo &= (As[1][1][1] == 1)
is_bingo &= (As[0][2][1] == 1)

if is_bingo:
    print('Yes')
    exit()

for row in As:
    if len(list(filter(lambda x: x[1]==1, row))) == 3:
        print('Yes')
        exit()

is_bingo = True
is_bingo &= (As[2][0][1] == 1)
is_bingo &= (As[1][0][1] == 1)
is_bingo &= (As[0][0][1] == 1)

if is_bingo:
    print('Yes')
    exit()

is_bingo = True
is_bingo &= (As[2][1][1] == 1)
is_bingo &= (As[1][1][1] == 1)
is_bingo &= (As[0][1][1] == 1)

if is_bingo:
    print('Yes')
    exit()

is_bingo = True
is_bingo &= (As[2][2][1] == 1)
is_bingo &= (As[1][2][1] == 1)
is_bingo &= (As[0][2][1] == 1)

if is_bingo:
    print('Yes')
    exit()

print('No')




Measured memory_bytes: 5688
import sys

sys.setrecursionlimit(10**6)

stdin = sys.stdin
na = lambda: map(int, stdin.readline().split())

g = []
counter = []
ans = []

def dfs(cur, par, val):
  global counter, ans, g
  val += counter[cur]
  ans[cur] = val
  for e in g[cur]:
    if e == par:
      continue
    dfs(e, cur, val)

def main():
  global g, ans, counter
  N, Q = na()
  
  g = [[] for _ in range(N)]
  for _ in range(N - 1):
    a, b = na()
    g[a-1] += [b-1]
    g[b-1] += [a-1]

  counter = [0] * N
  for _ in range(Q):
    p, x = na()
    counter[p-1] += x

  ans = [0] * N
  dfs(0, -1, 0)
  print(*ans)

if __name__ == "__main__":
  main()

Measured memory_bytes: 236936
use strict;
use warnings;
use utf8;

use POSIX qw/ ceil floor/; 

my $n = <STDIN>;
my $ceil = ceil($n/1.08);
my $floor = floor($n/1.08);

if (floor($ceil*1.08) == $n) {
    print $ceil;
}
elsif (floor($floor*1.08) == $n) {
    print $floor;
}
else {
    print ':(';
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 100005
#define ll signed long long int
using namespace std;

ll ans = 0, a[MAXX] = {0}, n , t, k;
signed main()
{
    FAST;
    string s1, s2;
     cin>> s1 >> s2;
     for(ll i = 0; i < s1.size(); i++){
     	if(s1[i] != s2[i]){
     		cout << "No";
     		return 0;
		 }
	 }
    cout << "Yes";
}

Measured memory_bytes: 3564
#include<stdio.h>
#include<math.h>
 
int main(void){
    double x1=0.0, y1=0.0;
    double x2=0.0, y2=0.0;
    double ans=0.0;
 
    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
 
    ans = sqrt(pow(x1-x2, 2) + pow(y1-y2, 2));
    printf("%lf\n", ans);
 
    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int WEEKTIME = 60*24*7;

int main() {
    int s, n, t, p, m;
    bool table[WEEKTIME];
    string weekday, time;
    cout.setf(ios::fixed);
    cout.precision(10);
    while (true) {
        cin >> s >> n >> t >> weekday >> time >> p >> m;
        if (s == 0) {
            break;
        }
        for (int i=0; i<WEEKTIME; i++) {
            table[i] = false;
        }
        for (int i=0; i<(weekday=="All"? 7: 1); i++) {
            if (time == "All" || time == "Day") {
                int stop = time=="All"? 24*60: 12*60;
                for (int j=0; j<stop; j++) {
                    table[i*60*24+j] = true;
                }
            }
            else {
                for (int j=0; j<6*60; j++) {
                    table[i*60*24+j] = true;
                    table[i*60*24+18*60+j] = true;
                }
            }
        }
        int hatched_stage_max = 0;
        for (int i=0; i<WEEKTIME; i++) {
            int hatched_stage = 0;
            int start = i;
            for (int j=0; j<m; j++) {
                if (table[start] && table[(start+s)%WEEKTIME]) {
                    hatched_stage++;
                }
                start = (start+t)%WEEKTIME;
            }
            hatched_stage_max = max(hatched_stage, hatched_stage_max);
        }
        cout << 1-pow(1-1.0/p, n*hatched_stage_max) << endl;
    }

    return 0;
}

Measured memory_bytes: 1292
#include <stdio.h>

int main(void)
{
	int a, b;

	if (scanf("%d %d", &a, &b) == EOF)
	{
		return 0;
	}

	if (b % a == 0)
	{
		printf("%d\n", a+b);
	}
	else
	{
		printf("%d\n", b-a);
	}

	return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int n, k, S, valmax, W[105], P[105], sol;
long long dp[100100];

int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> W[i] >> P[i], S+=P[i];

    dp[P[1]] = W[1];
    valmax = P[1];
    if(dp[P[1]] <= k) sol = P[1];

    for(int i=2; i<=n; i++)
    {   for(int j=valmax; j>=1; j--)
            if(dp[j])
            {   if(!dp[j + P[i]]) dp[j + P[i]] = dp[j] + W[i];
                else dp[j + P[i]] = min(dp[j + P[i]], dp[j] + W[i]);
                if(dp[j + P[i]] <= k) sol = max(sol, j+P[i]);
                valmax = max(valmax, j + P[i]);
            }
        if(!dp[P[i]]) dp[P[i]] = W[i];
        else if(W[i] < dp[P[i]]) dp[P[i]] = W[i];
    }
    cout << sol << '\n';
    return 0;
}

Measured memory_bytes: 1024
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include<bits/stdc++.h>
/*#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>*/

#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define rep(a, b, c) for(int a = b; a <= c; ++a)
#define per(a, b, c) for(int a = b; a >= c; --a)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
//using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
/*typedef tree<pair<int, int>, 
null_type, less<pair<int, int>>, 
rb_tree_tag, tree_order_statistics_node_update>
ordered_set;*/
//find_by_order() order_of_key()

const double eps = 1e-7;
const int mod = 1e9+7, MXN = 1e3+17;
const int dx[] = {0,0,1,-1}, dy[] = {1,-1,0,0};

template<typename T>inline bool updmin(T &a, const T &b) {return a > b ? a = b,1 : 0;}
template<typename T>inline bool updmax(T &a, const T &b) {return a < b ? a = b,1 : 0;}

int n, k;
int d[15];

inline bool is_good(int x) {
	while(x) {
		rep(i,1,k)
			if(x%10 == d[i])
				return 0;
		x /= 10;
	}
	return 1;
}

int32_t main() { _
#ifdef DanQQQQQ
	freopen(".in","r",stdin);
	freopen(".out","w",stdout);
#endif
	cin >> n >> k;
	rep(i,1,k) cin >> d[i];
	while(!is_good(n)) ++n;
	cout << n;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
long long int N;
long long int ans =0;
long long int count3=0,count5=0,count7=0;
string str;
long long int dfs(long long int x) {
    if(x>N)return 0;
   
    ans++;
     str=to_string(x);
     rep(i,str.size()){
         if(str[i]=='3')count3++;
         if(str[i]=='5')count5++;
         if(str[i]=='7')count7++;
     }
     if(count3==0||count5==0||count7==0)ans--;
     count3=0;
     count5=0;
     count7=0;
    dfs(10*x+3);
    dfs(10*x+5);
    dfs(10*x+7);
    return ans;
}

int main(){
cin>>N;


cout <<dfs(0);

}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
    int n,m=0; cin >> n;
    int A[n];
    for (int i=0; i<n; i++) cin >> A[i];

    for (int i=0; i<n-1; i++){
        for (int j=i+1; j<n; j++){
            m = max(m, abs(A[j]-A[i]));
        }
    }
    cout << m << endl;
}


Measured memory_bytes: 256
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[]
for i in range(n):
  a_=list(map(int,input().split()))
  a.append(a_)
  
cnt=0
for i in range(n):
  sum_ab=c
  for j in range(m):
    sum_ab+=a[i][j]*b[j]
    
  if sum_ab>0:
    cnt+=1
    
  else:
    continue
    
print(cnt)
    
  

Measured memory_bytes: 9108
//This is getting accepted!
// I HATE BUG
// God Of The Bugs
// 12/11/2016
#include<bits/stdc++.h>

using namespace std;

#define ms(s, n) memset(s, n, sizeof(s))
#define FI first
#define SE second
#define pb push_back
#define mp make_pair
#define ll long long
#define sz(a) ((int)(a).size())
#define __builtin_popcount __builtin_popcounll
#define ld long double

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<int, pii> ppi;

const double PI = acos(0) * 2;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 5;
const int oo = 1e9;
const double foo = 1e30;

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcounll(s);}
template<class T> T sqr(T x) { return x * x; }

inline void addmod(int& a, int val, int p = MOD) {if ((a = (a + val)) >= p) a -= p;}
inline void submod(int& a, int val, int p = MOD) {if ((a = (a - val)) < 0) a += p;}
inline int mult(int a, int b, int p = MOD) {return (ll) a * b % p;}

string s;

int main() {
//#ifndef ONLINE_JUDGE
//    freopen("inp.txt", "r", stdin);
////    freopen("out.txt", "w", stdout);
//#endif

	cin >> s;
	
	int tot = sz(s);
	for (int i=0; i<26; i++) {
		int cnt = 0, res = 0;
		for (int j=0; j<sz(s); j++) {
			if (s[j] - 'a' == i) {
				res = max(res, cnt);
				cnt = 0;
			}
			else {
				cnt++;
			}
		}
		res = max(res, cnt);
		tot = min(tot, res);
	}

	cout << tot;
}


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

#define int long long


signed main() {
    
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i=0; i<N; i++) cin >> p[i];
    
    int ans = 0;
    for(int i=1; i<N-1; i++){
        if(p[i-1]<p[i] && p[i]<p[i+1]) ans++;
        if(p[i-1]>p[i] && p[i]>p[i+1]) ans++;
        
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <utility>

std::pair<double, bool> solve(long w, long h, long x, long y)
{
  return std::make_pair(w * h / 2.0, w == x * 2 && h == y * 2);
}

int main()
{
  long w, h, x, y;
  std::cin >> w >> h >> x >> y;

  const auto p = solve(w, h, x, y);
  std::cout << std::setprecision(15) << p.first << ' ' << p.second << std::endl;
}


Measured memory_bytes: 256
n = int(input())
c = input().strip()
c = list(c)

ans = 0
low = 0
high = n-1

while low<high:
    if c[low] == 'W':
        
        while low<high and c[high]=='W':
            high -= 1
        
        if c[high] == 'R':
            ans+=1
            c[high], c[low] = c[low], c[high]
            
    low += 1    

print(ans)

Measured memory_bytes: 10756
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int n, a, cnt = 0, tmp, point=1;
  cin >> n;
  vector<int> light(n,0);

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

  while(cnt<n){
      tmp = light[point-1];
      cnt++;
      if(tmp == 2){
          break;
      } 
      point = tmp;

  }
  if(cnt>=n){
      cout << -1 << endl;
  }
  else{
      cout << cnt << endl;
  }

}


Measured memory_bytes: 640
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int k;
  cin >> k;
  string s;
  cin >> s;
  if(s.size()<=k)cout<<s<<endl;
  else{
    for(int i=0;i<k;i++){
      cout<<s.at(i);
    }
    cout<<"..."<<endl;
  }
}



Measured memory_bytes: 3628
#include <iostream>
#include <cstdlib>
#include <time.h>
#include <algorithm>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <array>
#include <string>
using namespace std;

typedef long long int ll;

int main(){
	cin.sync_with_stdio(false);
	cin.tie(0);
	ll n, m, k;
	cin >> n >> m >> k;
	for(ll i=min(n, m), j=0; i >= 0; i--){
		if(n%i == 0 and m%i == 0){
			j++;
			if(k == j){
				cout << i;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <set>
// #include <numeric>
// #include <algorithm>
// #include <cmath>
// #include <string>
// #include <map>
// #include <iomanip>

// #define MOD 1000000007

using namespace std;
// typedef unsigned long long ull;
typedef long long ll;

void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}

template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& s) {
    os << "{";
    for (const auto& i : s) {
        os << i << " ";
    }
    os << "}";
    return os;
}


int main(int argc, char const *argv[]) {
    string S;
    cin >> S;

    set<char> C;
    for (int i = 0; i < S.length(); i++) {
        C.insert(S[i]);
    }
    if (C.size() == S.length()) {
        cout << "yes" << endl;
    } else {
        cout << "no" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
  static int n;
  static int[] p;

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

    n = sc.nextInt();
    p = new int[n];
    for(int i = 0; i < n; i++){
      p[i] = sc.nextInt();
    }

    int count = 0;
    for(int i = 0; i < n; i++){
      if(p[i] != i + 1){
        continue;
      }
      if(i + 1 < n && p[i + 1] == (i + 1) + 1){
        ++i;
      }
      ++count;
    }

    System.out.println(count);
  }
}


Measured memory_bytes: 50652
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, x;
    cin >> n >> x;
    if(x == 1 || x == 2 * n - 1) cout << "No" << endl;
    else{
        cout << "Yes" << endl;
        int now = x - n;
        rep(i, 0, 2 * n - 1){
            cout << (now + 2 * n - 1) % (2 * n - 1) + 1 << endl;
            now++;
        }
    }
}

Measured memory_bytes: 1536
b="abcdefghijklmnopqrstuvwxyz"
c=[0]*26
while True :
    try: 
        a=input()
        for i in range(len(a)):
            if a[i] in b or a[i].lower() in b : c[b.index(a[i].lower())]+=1
    except:break
for j in range(26):
    print(b[j], ":", c[j])


Measured memory_bytes: 5564
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long 
using namespace std;
const int N=500005;
int n;
ll a,b,c,d,del;
int main(){
	scanf("%d%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	del=b-a; 
	for (int i=0;i<=n-1;i++) 
	 if (c*i-d*(n-1-i)<=del && del<=d*i-c*(n-1-i)) {
	 	puts("YES");
	 	return 0;
	 }
	puts("NO");
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;
const int N=3005;
const int mod=1e9+7;
char str[N];
int r[N];
int d[N][N];
int s[N];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    scanf("%s",str+1);
    for(int i=1;i<=n;i++){
        s[i]=str[i]-'0';
    }
    for(int i=1;i<=n+1;i++)
        s[i]+=s[i-1];
    for(int i=1;i<=n+1;i++)
        r[i]=i;
    for(int i=1;i<=m;i++){
        int a,b;
        scanf("%d%d",&a,&b);
        r[a]=max(r[a],b);
    }
    for(int i=1;i<=n;i++)
        r[i]=max(r[i],r[i-1]);
    d[1][s[r[1]]]=1;
    for(int i=1;i<=n;i++)
        for(int j=0;j<=n;j++)
            if(d[i][j]){
                int a=r[i],b=r[i+1];
                int f=s[b]-s[a];
                if(j){
                    d[i+1][j+f-1]+=d[i][j];
                    d[i+1][j+f-1]%=mod;
                }
                if(r[i]!=i+j-1){
                    d[i+1][j+f]+=d[i][j];
                    d[i+1][j+f]%=mod;
                }
            }
    int ans=d[n+1][0];
    printf("%d\n",ans);
}


Measured memory_bytes: 33792
fun main() {
    val n = readLine()?.toInt() ?: return
    val s = readLine() ?: return
    val r = hashMapOf<Int, Long>()
    val g = hashMapOf<Int, Long>()
    val b = hashMapOf<Int, Long>()
    repeat(n) {
        val i = n - it - 1
        r[i] = r.getOrDefault(i + 1, 0L)
        g[i] = g.getOrDefault(i + 1, 0L)
        b[i] = b.getOrDefault(i + 1, 0L)
        when (s[i]) {
            'R' -> {
                r[i] = r.getOrDefault(i, 0L) + 1
            }
            'G' -> {
                g[i] = g.getOrDefault(i, 0L) + 1
            }
            'B' -> {
                b[i] = b.getOrDefault(i, 0L) + 1
            }
        }
    }

    fun counter(s: String, i: Int, j: Int, diff: Int, a: Char, b: Char, c: Char, cMap: Map<Int, Long>): Long {
        return if (s[i] == a && s[j] == b || s[i] == b && s[j] == a) {
            (cMap[j] ?: 0L) - if (s.getOrNull(j + diff) == c) {
                1L
            } else {
                0L
            }
        } else {
            0L
        }
    }
    var count = 0L
    0.until(n - 2).forEach { i ->
        (i + 1).until(n - 1).forEach { j ->
            if (s[i] != s[j] && i < j) {
                val diff = j - i
                count += counter(s, i, j, diff, 'B', 'G', 'R', r) +
                        counter(s, i, j, diff, 'R', 'B', 'G', g) +
                        counter(s, i, j, diff, 'R', 'G', 'B', b)
            }
        }
    }
    println(count)
}


Measured memory_bytes: 58544
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int a,b,c;
	cin >> a>>b>>c;
	int max;
	max = a > b ? a : b;
	max = max > c ? max : c;
	while ((3 * max - a - b - c) % 2) {
		max++;
	}
	cout << (3 * max - a - b - c) / 2;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
// #define DEBUG 10
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const int oo = 1e9 + 7;
const ll mod = 998244353, maxn = 2 * 1e5 + 10, maxm = 15;
const double PI = acos(-1);
ll fat[maxn], inv[maxn];

ll mul(ll a, ll b){
    ll ans = 0;
    while (b){
        if (b&1) ans = (ans + a)%mod;
        a = (a + a)%mod;
        b = (b >> 1);
    }
    return ans;
}

ll sum(ll a, ll b){
    return (a % mod + b % mod) % mod;
}

ll sub(ll a, ll b){
    return (a - b + mod + mod)%mod;
}

ll fexp(ll a, ll b){
    ll ans = 1;

    while (b){
        if (b&1){
            ans = mul(ans, a);
        }
        a = mul(a, a);
        b = (b >> 1);
    }
    return ans;
}

void init(){
    fat[0] = fat[1] = inv[0] = inv[1] = 1;
    for (ll i=2; i<maxn; i++){
        fat[i] = mul(fat[i-1], i);
        inv[i] = fexp(fat[i], mod-2);
    }
}

ll C(ll a, ll b){
    if (a < b) return 0;
    if (a == b || b == 0) return 1;
    return mul(mul(fat[a], inv[b]), inv[a-b]);
}

int main (){
    ios_base::sync_with_stdio(false);
    ll n, k, m, ans = 0;
    init();
    cin >> n >> m >> k;
    for (ll i=0; i<=k; i++){
        ll x = n - i - 1;
        ans = sum(ans, mul(mul(m, C(n-1, x)), fexp(m-1, x)));
    }

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

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

int main(){
int ans=0;
int a,b,c;
cin>>a>>b>>c;
for (int i = 0; i < 9; i++)
{
    if((i==a)+(i==b)+(i==c)==2){
        ans=1;
    }

}

if (ans==1){
    cout<<"Yes";
}
else
{
    cout<<"No";
}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cctype>
#include <stack>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <math.h>
#include <iomanip>

using namespace std;

const long long MOD = 1e9 + 7;

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

    string s;
    cin >> s;
    auto n = s.size();
    if(s.at(n-1) == 's'){
        s = s + "es";
    }else{
        s = s + "s";
    }
    cout << s << '\n';
}


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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep(i,n) cin >> v[i];
  sort(v.begin(),v.end());
  int now=(v[0]+v[n-1]+1)/2;
  cout << now-v[0] << endl;
}


Measured memory_bytes: 3152
N,M=map(int,input().split())
d={} #正解の辞書
e={} #誤答の辞書
f={} #ペナの辞書
for _ in range(M):
    p,s=input().split()
    d.setdefault(p,0)
    e.setdefault(p,0)
    #f.setdefault(p,0)
    if s=="WA" and d[p]==0:
        e[p]+=1
    elif s=="AC":
        d[p]=1
        f[p]=e[p]

print(sum(d.values()),sum(f.values()))



Measured memory_bytes: 29420
use std::collections::VecDeque;

use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

type Weight = i32;
#[allow(dead_code)]
#[derive(Clone, Debug, Eq, PartialEq)]
struct Edge {
    index: usize,
    src: usize,
    dest: usize,
    weight: Weight,
}
#[allow(dead_code)]
impl Edge {
    fn new(index: usize, src: usize, dest: usize, weight: Weight) -> Edge {
        Edge {
            index: index,
            src: src,
            dest: dest,
            weight: weight,
        }
    }
}
impl std::cmp::Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        (self.weight, self.src, self.dest).cmp(&(other.weight, other.src, other.dest))
    }
}
impl std::cmp::PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}
type Edges = Vec<Edge>;
type Graph = Vec<Edges>;
#[allow(dead_code)]
fn graph_new(n: usize) -> Graph {
    vec![vec![]; n]
}
#[allow(dead_code)]
fn add_bi_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    graph[dest].push(Edge::new(*index, dest, src, weight));
    *index += 1;
}
#[allow(dead_code)]
fn add_uni_edge(graph: &mut Graph, index: &mut usize, src: usize, dest: usize, weight: Weight) {
    graph[src].push(Edge::new(*index, src, dest, weight));
    *index += 1;
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut g = graph_new(n);
    let mut index = 0;
    for _i in 0..m {
        let f = read::<usize>() - 1;
        let t = read::<usize>() - 1;
        add_uni_edge(&mut g, &mut index, f, t, 1);
    }
    let s = read::<usize>() - 1;
    let t = read::<usize>() - 1;
    let mut que = VecDeque::new();
    que.push_back((0, 0, s));
    let mut visited = vec![vec![false; 3]; n];
    visited[s][0] = true;
    while let Some((cost, cnt, from)) = que.pop_front() {
        if cnt == 0 && from == t {
            println!("{}", cost);
            return;
        }
        for e in g[from].iter() {
            let mut ncost = cost;
            let mut ncnt = cnt + 1;
            if ncnt == 3 {
                ncost += 1;
                ncnt = 0;
            }
            let to = e.dest;
            if visited[to][ncnt] {
                continue;
            }
            visited[to][ncnt] = true;
            que.push_back((ncost, ncnt, to));
        }
    }
    println!("{}", -1);
}


Measured memory_bytes: 24956
#include<bits/stdc++.h>
#include<algorithm>
#include<string>
#include<vector>
#include<tuple>
using namespace std;

int main(){
  int x,y;
  cin >> x >> y;
  if(x>8 || y>8) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
	  #define endl "\n"
	  #define ll long long int
	  #define mod 1000000007
	  #define inf 1000000000000000001;
	  using namespace std;
	  int main()
	  {
	    //  #ifndef ONLINE_JUDGE
	    //  // for getting input from input.txt
	    //  freopen("input.txt", "r", stdin);
	    //  // for writing output to output.txt
	    //  freopen("output.txt", "w", stdout);
	    // #endif
	    std::ios::sync_with_stdio(false);
	    cin.tie(NULL);
	    ll n,x,t,r=0,f=0;
	    cin>>n>>x>>t;
	    while(n > r){
	    	r =r + x;
	    	f = f+t;
	    }
	    cout<<f;
	    return 0;
	  }


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

int main(){
    int N,K;
    string S;
    cin >> N >> K >> S;
    int ans =0;
    rep(i,N-1){
        if(S[i] == S[i+1])ans++;
        
    }
    ans +=(2*K);
    if(N-1<ans) cout << N-1;
    else cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

vector<pair<long long,long long>> edge[100010];
long long place[100010];
bool dfs(long long from,long long cost){
    // cout<<from<<" "<<cost<<" "<<place[from]<<endl;
    if(place[from]!=cost){
        if(place[from]!=LINF) return false;
    }
    if(place[from]==cost) return true;
    place[from]=cost;
    for(auto e:edge[from]){
        long long to=e.first,dd=e.second;
        if(!dfs(to,cost+dd)) return false;
    }
    return true;
}
int main(){
    rep(i,100010) place[i]=LINF;
    int n,m; cin>>n>>m;
    rep(i,m){
        int l,r,d; cin>>l>>r>>d;
        edge[l].push_back({r,d});
        edge[r].push_back({l,-d});
    }
    string ans="Yes";
    for(int i=1;i<=n;i++){
        if(!dfs(i,(place[i]!=LINF?place[i]:0))) ans="No";
    }
    // rep(i,4) cout<<place[i]<<endl;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 15488
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
#include<set>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define Pr pair<int,int>
#define X first
#define Y second
#define MAXN 500000
#define INF 1000000000
#define mem(x,p) memset(x,p,sizeof(x))

int read(){
  int x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}

struct Seg_tree{
	#define pl (x<<1)
	#define pr (x<<1|1)
	#define mid (l+r>>1)
	int mn[(MAXN<<2)+5];
	void Build(int x,int l,int r){
		mn[x]=INF;
		if(l==r)return ;
		Build(pl,l,mid),Build(pr,mid+1,r);
	}
	void Insert(int x,int l,int r,int pos,int v){
		if(l==r){mn[x]=v;return ;}
		if(pos<=mid)Insert(pl,l,mid,pos,v);
		else Insert(pr,mid+1,r,pos,v);
		mn[x]=min(mn[pl],mn[pr]);
	}
	int Query(int x,int l,int r,int L,int R){
		if(L>r||l>R)return INF;
		if(L<=l&&r<=R)return mn[x];
		return min(Query(pl,l,mid,L,R),Query(pr,mid+1,r,L,R));
	}
}T;

vector<int> G[MAXN+5];
int n,K,a[MAXN+5],ct;
int rnk[MAXN+5],du[MAXN+5],ans[MAXN+5];
priority_queue<int> Q;
void topsort(){
	for(int i=1;i<=n;i++)
		for(int j=0;j<G[i].size();j++)
		du[G[i][j]]++;
	for(int i=1;i<=n;i++)
	if(!du[i])Q.push(i);
	while(!Q.empty()){
		int x=Q.top();Q.pop();
		rnk[++ct]=x;
		for(int i=0;i<G[x].size();i++){
			int v=G[x][i];
			if(!(--du[v]))Q.push(v);
		}
	}
}

int main(){
	n=read(),K=read();
	for(int i=1;i<=n;i++){
		int x=read();a[x]=i;
	}
	reverse(a+1,a+n+1);
	T.Build(1,1,n);
	for(int i=n;i>=1;i--){
		int p=T.Query(1,1,n,max(1,a[i]-K+1),a[i]);
		if(p!=INF)G[a[i]].push_back(a[p]);
		p=T.Query(1,1,n,a[i],min(n,a[i]+K-1));
		if(p!=INF)G[a[i]].push_back(a[p]);
		T.Insert(1,1,n,a[i],i);
	}
	topsort();
	reverse(rnk+1,rnk+n+1);
	for(int i=1;i<=n;i++)ans[rnk[i]]=i;
	for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
}

Measured memory_bytes: 43184
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int leng = s.length();
    // cout << t.substr(0, leng) << endl;
    if (s == t.substr(0, leng))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    cout << (a+b)%24 << endl;
    return 0;
}


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

typedef long long ll;
ll MOD = 1000000007;

struct bit {
	vector<ll> v;
	bit(int n) : v(n + 1) {}
	ll sum(int i) {
		ll res = 0;
		for (; i > 0; i -= i & -i) res += v[i];
		return res;
	}
	void add(int i, ll x) {
		for (i++; i < v.size(); i += i & -i) v[i] += x;
	}
};

int B = 500;

int main() {
	int N; cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		scanf("%d", &p[i]);
		p[i]--;
	}
	int Q; cin >> Q;
	vector<vector<int> > query(N);
	vector<int> l(Q), r(Q);
	for (int q = 0; q < Q; q++) {
		scanf("%d%d", &l[q], &r[q]);
		l[q]--; r[q]--;
		query[r[q]].push_back(q);
	}
	vector<int> index(N, -1);
	bit bt(N);
	vector<int> A(N / B + 1);
	vector<vector<int> > v(N / B + 1);
	vector<vector<ll> > sum(N / B + 1, vector<ll>(1));
	ll cur = 0;
	vector<ll> ans(Q);
	for (int i = 0; i < N; i++) {
		for (int x = N - 1; x > p[i];) {
			if (x % B == B - 1 && x - B >= p[i]) {
				A[x / B]++;
				cur += v[x / B].size();
				x -= B;
			}
			else {
				if (index[x] != -1) {
					bt.add(index[x], 1);
					cur++;
				}
				x--;
			}
		}
		int x = p[i];
		index[x] = i;
		ll prev = sum[x / B].back();
		v[x / B].push_back(i);
		sum[x / B].push_back(prev + A[x / B]);
		for (int k = 0; k < query[i].size(); k++) {
			int q = query[i][k];
			ans[q] = cur - bt.sum(l[q]);
			for (int i = 0; i <= N / B; i++) {
				int j = lower_bound(v[i].begin(), v[i].end(), l[q]) - v[i].begin();
				ans[q] -= (ll)j * A[i] - sum[i][j];
			}
		}
	}
	for (int q = 0; q < Q; q++)
		printf("%lld\n", ans[q]);
}

Measured memory_bytes: 13732
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
    while(true){
        int n,x,ans=0;
        cin>>n>>x;
        if(n==0 && x==0)return 0;
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x){
                        ans++;
                    }
                }
            }
        }
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 3056
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
using namespace std;
using ll = long long;


int main(){
  int a, b, k;
  cin >> a >> b >> k;
  int cnt = 0;
  for(int i = min(a, b); i > 0; i--){
    if(a % i == 0 && b % i == 0){cnt++;}
    if(cnt == k){cout << i << endl; break;}
  }


}

Measured memory_bytes: 256
N,X=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
answer=0
for b in range(N):
  if X>=a[b]:
    if b!=N-1:
      X-=a[b]
      answer+=1
    elif X==a[b]:
      answer+=1
  else:
    break
print(answer)

Measured memory_bytes: 3060
object Main extends App {
  import scala.io.StdIn._

  val n = readInt
  val (lower, upper) = Array.tabulate(n){_ ⇒
    val Array(a, b) = readLine.trim.split(' ').map(_.toLong)
    (a, b)
  }.let{a ⇒ (a.map(_._1).sorted, a.map(_._2).sorted)}

  println(
    lower.map(v ⇒
      upperBound(lower, v) - lowerBound(upper, v)
    ).max
  )

  def upperBound(array: Array[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) <= target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  def lowerBound(array: Array[Long], target: Long): Int = {
    var left = 0
    var right = array.length
    while(left < right){
      val mid = (left + right) / 2
      if (array(mid) < target){
        left = mid + 1
      }else {
        right = mid
      }
    }
    right
  }
  implicit class Scope[T](val value: T) extends AnyVal {
    @inline
    def let[A](func: T ⇒ A): A = func(value)
  }
}


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

int main() {
  string S;
  cin >> S;
  
  if (S == "Sunny") {
  	cout << "Cloudy" << endl;
  }
  
  else if (S == "Cloudy") {
    cout << "Rainy" << endl;
  }
  
  else {
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <queue>
#include <bits/stdc++.h>
#include <stack>
#include <vector>
#include <list>

using namespace std;

int main()
{
  char str[15];
  scanf("%s", str);

  for(int i = 0; i < 12; i++){
    cout << str[i];
    if(i == 3)
      cout << " ";
  }
  cout << endl;


  return 0;
}

Measured memory_bytes: 256