akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;
int main()
{
  int x,y;
  cin>>x>>y;
  int ta=0,aa=0;
  if(x==2)ta=1;
  else if(x==4||x==6||x==9||x==11)ta=2;
  else ta=3;
  if(y==2)aa=1;
  else if(y==4||y==6||y==9||y==11)aa=2;
  else aa=3;
  if(ta==aa)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    int a[n];
    for(int i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    int c = 1;
    int count = 0;
    for(int i = 0;i < n;i++)
    {
        if(a[i] == c)
        {
            c++;
            count++;
        }
    }
    if(count == 0)
    {
        cout << "-1\n";
    }
    else
    {
        cout << n - count << "\n";
    }

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,t,a;
  long long tnow,anow;
  cin >> n >> tnow >> anow;
  for (int i=0;i < n-1;i++) {
    cin >> t >> a;
    if ((tnow-1)/t > (anow-1)/a){
      tnow = ((tnow+t-1)/t)*t;
      anow = ((tnow+t-1)/t)*a;
    }
    else {
      tnow = ((anow+a-1)/a)*t;
      anow = ((anow+a-1)/a)*a;
    }
  }
  cout << tnow + anow <<endl;
}

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

typedef long long ll;
using namespace std;

ll Mod = 1e9 + 7;
int MAX = -1;
int main()
{
    int N, K, sum = 0;
    cin >> N >> K;
    vector <int> l(N, 0);
 
    for (int i = 0; i < N; i++) cin >> l[i];

    sort(l.begin(), l.end(), greater<int>());
    for (int i = 0; i < K; i++) {
        sum += l[i];
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int n;
    while(cin>>n){
        n %= 10;
        if(n==2||n==4||n==5||n==7||n==9){
            cout << "hon" << endl;
        }
        else if(n==0||n==1||n==6||n==8){
            cout << "pon" << endl;
        }
        else if(n==3){
            cout << "bon" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2980
#include<bits/stdc++.h>
using namespace std;
char T;int l,a,b,x[999],d[999],M,N,y[999],z[999],i,j;
main(){
while(1){
M=0;
memset(y,0,999);
cin>>b>>l;if(!l){break;}
for(i=1;i<=b;i++){
cin>>T>>x[i];
if(T=='L'){d[i]=0;M=max(M,x[i]);}
else{d[i]=1;M=max(M,l-x[i]);}
}
N=0;
for(i=1;i<M+2;i++){
memset(z,0,sizeof(z));
for(j=b;j>0;j--) {
if(!y[j]) {
if(!d[j]){
x[j]--;
}
else{
x[j]++;
}
if(x[j]<0||x[j]>l){
y[j]=1;
}
z[x[j]]++;
if(M<i){
if(N){
if(x[j]<0){N=j;}
}
else{
N=j;
}
}
}
}
for(j=b;j>0;j--){
if(z[x[j]]>1){
if(d[j]){d[j]=0;}
else{d[j]=1;}
}
}
}
printf("%d %d\n",M,N);
}
}

Measured memory_bytes: 1160
li = [int(n) for n in list(input())]
Ops = []

def func(i, x, li, ops):
  if i==0:
    if x+li[0]==7:
      return True
    if x-li[0]==7:
      return True
  else:
    if func(i-1, x-li[i], li, ops):
      ops.append('-')
      return True
    if func(i-1, x+li[i], li, ops):
      ops.append('+')
      return True
    
func(3, 0, li, Ops)
Ops.append('=7')
for i in range(4):
  print(li[i], Ops[i], sep='', end='')

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

ll dp[101];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    dp[4]=1,dp[7]=1;
    for(int i=8;i<=100;i++)dp[i]=max(dp[i-4],dp[i-7]);
    ll n;
    cin>>n;
    if(dp[n])cout<<"Yes";
    else cout<<"No";
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
ll mod=1e9+7;
struct unionfind{
  vector<int> par;
  vector<int> size;
  unionfind(int n):par(n),size(n,1){
    rep(i,n)par.at(i)=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return root(par[x]);
  }
  void unit(int x,int y){
    x=root(x);
    y=root(y);
    if(x==y)return;
    if(size[par[x]]<size[par[y]])swap(x,y);
    par[y]=x;
    size[x]+=size[y];
  }
  bool find(int x,int y){
    x=root(x);
    y=root(y);
    return x==y;
  }
};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    vector<int> p(n+1);
    for(int i=1;i<=n;i++)cin>>p[i];
    unionfind uf(n);
    int ans=0;
    rep(i,m){
        int s,t;cin>>s>>t;
        uf.unit(s,t);
    }
    for(int i=1;i<=n;i++){
        if(uf.find(i,p[i]))ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

class program
{
    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int a = int.Parse(str[0]);
        int b = int.Parse(str[1]);
        int c = int.Parse(str[2]);

        int[] num = { a, b, c };
        int Max = num.Max();
        int Min = num.Min();

        if ((a == Min) && (c == Max))
        {
            if ((a != b) && (c != b))
                {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}

Measured memory_bytes: 9148
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <utility>
#include <string>
#include <cmath>
#include <set>
#include <functional>
#include <map>
#include <queue>
#include <cstring>
#include <stack>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cassert>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define show(x) cout << #x << " = " << x << endl;
typedef long long ll;
typedef pair<int,int> pii;
int main(){
    int a,b,c,d;
    cin >> a>> b >> c >> d;
    int t[105]={};
    int s[105]={};
    for(int i = a; i <= b; i++){
        t[i] = 1;
    }
    for(int i = c; i <= d; i++){
        s[i] = 1;
    }
    int ans = 0;
    rep(i,101){
        if(t[i] == s[i] && t[i]){
            ans++;
        }
    }
    cout << max(ans-1,0) << endl;
}

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

int main() {

    int a, b;
    char op;

    scanf("%d %c %d", &a, &op, &b);

    if (op == '+')
        printf("%d\n", a + b);
    else
        printf("%d\n", a - b);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 998244353
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

ll ppow(ll a,ll b){
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}
int a[500];
ll dp[500][100000],dp2[500][100000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%d",&a[i]);
	}
	dp[0][0]=1;
	dp2[0][0]=1;
	ll all=ppow(3,n);
	int cnt=0;
	rep(i,n){
		rep(j,cnt+1){
			if(dp[i][j]==0)continue;
			(dp[i+1][j]+=dp[i][j]*2)%=MOD;
			(dp[i+1][j+a[i]]+=dp[i][j])%=MOD;
			(dp2[i+1][j]+=dp2[i][j])%=MOD;
			(dp2[i+1][j+a[i]]+=dp2[i][j])%=MOD;
		}
		cnt+=a[i];
	}
	rep(i,cnt+1){
		if(cnt-i<i){
			if(dp[n][i]==0)continue;
			all=(all+MOD-dp[n][i]*3%MOD)%MOD;
		}
		else if(cnt-i==i){
			if(dp[n][i]==0)continue;
			all=(all+MOD-(dp[n][i])%MOD*3%MOD)%MOD;
			all=(all+dp2[n][i]*3%MOD)%MOD;
		}
	}
	cout<<all<<endl;
}

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

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	int i;
	
	if(a >= b){
		for(i = 0; i < a; i++){
			printf("%d", b);
		}
	}
	
	else{
		for(i = 0; i < b; i++){
			printf("%d", a);
		}
	}
		
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  ll n,m;
  cin >> n >> m;
  int p = m/n;
  priority_queue<int> a;
  for(int i = 1;i*i<=m;i++){
    if(m%i==0){
      a.push(i);
      a.push(m/i);
    }
  }
  while(!a.empty()){
    ll s = a.top();
    a.pop();
    
    if(s*n<=m){
      cout << s << endl;
      return 0;
    }
  }
  
}




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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;
constexpr int MOD = 998244353;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

constexpr int MAX_N = 100005;

int n, c[MAX_N], k;
vector<pii> G[MAX_N];

void visit(int x, int preC)
{
    int curC = preC;
    for (int i = 0; i < G[x].size(); i++)
    {
        const int to = G[x][i].first, idx = G[x][i].second;
        if (c[idx]) continue;

        if (curC == preC)
        {
            curC++;
            curC %= k;
        }

        c[idx] = curC + 1;
        visit(to, curC);

        curC++;
        curC %= k;
    }
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);
    cout << fixed;

    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b;
        cin >> a >> b;
        G[a].emplace_back(b, i);
        G[b].emplace_back(a, i);
    }

    for (int i = 0; i < n; i++)
    {
        k = max(k, (long long) G[i + 1].size());
    }

    visit(1, -1);

    cout << k << endl;
    for (int i = 0; i < n - 1; i++)
    {
        cout << c[i] << endl;
    }
}


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

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

int main(){

int a,b;
cin>>a>>b;
cout<<a+b/2<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define N 110000
int n,cnt,ans;
int a[N],b[N<<2];
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[++cnt]=a[i];
		b[++cnt]=a[i]-1;
		b[++cnt]=a[i]+1;
	}
	sort(b+1,b+1+cnt);
	for(int i=1,now=0;i<=cnt;i++)
	{
		if(b[i]!=b[i-1])now=0;
		now++;
		ans=max(ans,now);
	}
	printf("%d\n",ans);
	return 0;
}


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

int main()
{
	char s[100001];
	scanf("%s", s);
	
	int i, j, k = 0, flag = 1, count[100001] = {};
	for (i = -1, j = 0; s[j] != 0; j++);
	while (i < j) {
		for (i++; i < j && s[i] == 'x'; i++) count[k]++;
		if (i == j) {
			count[k] = 0;
			break;
		} else {
			for (j--; s[j] == 'x'; j--) count[k]--;
			if (j == i) break;
			else if (s[j] == s[i]) k++;
			else {
				flag = 0;
				break;
			}
		}
	}
	
	int sum = 0;
	for (i = 0; i <= k; i++) sum += abs(count[i]);
	
	if (flag == 0) printf("-1\n");
	else printf("%d\n", sum);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 640
sub f{my($u,$p)=@_;push@{--$|?b:c},$u;$_-$p&&f($_,$u)for@$u;--$|}<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;@a=($,=$",(f 1)x$.);--$x;@b>$./3&@c>$./3?(map$a[$_]=$x+=3,@b)+map$a[$_]=++$y*3-2,@c:map$a[$_]=$x+=$x%3,@b>@c?@b:@c;print map$_<=$.&&$_||3*++$z,@a

Measured memory_bytes: 269440
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,f[1000005];
int sum;

int main(){
	cin>>n;
	f[0]=f[1]=1;
	sum=2;
	for(int i=2;i<=n;i++){
		f[i]=(sum-f[i-2]+mod)%mod;
		sum=(sum+f[i])%mod;
	}
	f[n]=(f[n]+1ll*f[n-1]*(n-1)%mod)%mod;
	for(int i=2;i<=n;i++) f[n]=(f[n]+1ll*(n-i+1)*f[n-i]%mod)%mod;
	int ans=f[n];
	for(int i=0;i<n-1;i++) ans=(ans+1ll*(n-1)*(n-1)%mod*f[i]%mod)%mod;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 4096
from copy import deepcopy

WHITE = 0
GRAY = 1
BLACK = 2


def dfs(s, n, m):
    color = [WHITE] * n

    stack = [s]
    color[s] = GRAY
    while stack:
        u = stack[-1]
        for v, flg in enumerate(m[u]):
            if flg:
                if color[v] == WHITE:
                    color[v] = GRAY
                    stack.append(v)
                    break
        else:
            stack.pop()
            color[u] = BLACK

    cnt = color.count(BLACK)

    return cnt


def main():
    n, m = map(int, input().split())
    ab = [list(map(int, input().split())) for _ in range(m)]

    g = [[0] * n for _ in range(n)]
    for a, b in ab:
        a -= 1
        b -= 1
        g[a][b] = 1
        g[b][a] = 1

    ans = 0
    for a, b in ab:
        a -= 1
        b -= 1
        cp = deepcopy(g)
        cp[a][b] = 0
        cp[b][a] = 0

        cnt = dfs(0, n, cp)

        if cnt != n:
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

ll modpow(ll a, ll n, ll p){
  if(n == 0){
    return 1;
  }
  if(n%2 == 0){
    ll root = modpow(a,n/2,p);
    return root * root %p;
  }
  else{
    return a*modpow(a,n-1,p)%p;
  }
}


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

  int work[2019][2];
  for(int i=0;i<2019;i++){
    work[i][0] = 0;
    work[i][1] = 0;
  }

  ll ans = 0;
  for(int i=0;i<s.length();i++){
    int num = s[i]-'0';
    
    for(int j=0;j<2019;j++){
      work[j][i%2] = 0;
    }
    
    work[num][i%2] = 1;
    for(int j=0;j<2019;j++){
      int idx = (j*10+num)%2019;
      work[idx][i%2] += work[j][(i+1)%2];
    }

    ans += work[0][i%2];
  }

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


Measured memory_bytes: 3736
s=[0,0,0]
s[0]=list(input())
s[1]=list(input())
s[2]=list(input())
n=0
for i in range(100000):
    if len(s[n])==0:
        break
    tmp=s[n].pop(0)
    if tmp=="a":
        n=0
    elif tmp=="b":
        n=1
    else:
        n=2

if n==0:
    print("A")
elif n==1:
    print("B")
else:
    print("C")

Measured memory_bytes: 9000
#include<bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
//#define sz(x) int((x).size())

int gcd(int a, int b) {
  if(a < b) gcd(b, a);
  int r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
  }


int main() {
  int N,M;
  cin >>N >> M;
  string S,T;
  cin >> S >> T;
  //  long long int GCD = __gcd(M,N);
  long long int GCD = gcd(M,N);
  int n = N/GCD;
  int m = M/GCD;
  bool out=false;
  for (int i=0; i<GCD; i++){
    if(S[i*n] != T[i*m]){
      //    if(S[i*(N/GCD)] != T[i*(M/GCD)]){  
      cout <<  -1 << endl;
      return 0;
      //      out = true;
      }
      
  }
  /*  if(out)
    cout<<-1<<endl;
  else
  cout<<M*(N/GCD)<<endl;*/
  cout << M*(N/GCD) << endl;
  return 0;
}


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

int main() {
  int n, k;
  cin >> n >> k;
  int num = 1;
  for (int i = 0; i < n; i++) {
    if (num * 2 - num < k){
      num *= 2;
    }
    else {
      num += k;
    }
  } 
  cout << num << endl;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        s: chars,
    }
    let mut dict_ = HashMap::new();
    dict_.insert('a', 0i64);
    dict_.insert('b', 0i64);
    dict_.insert('c', 0i64);
    for &c in &s {
        *dict_.entry(c).or_insert(0) += 1;
    }

    if (dict_[&'a'] - dict_[&'b']).abs() <= 1
        && (dict_[&'b'] - dict_[&'c']).abs() <= 1
        && (dict_[&'c'] - dict_[&'a']).abs() <= 1
    {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int n; cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = n-1; i >= 0; i--) {
    cout << a[i];
    if (i != 0) cout << " ";
  } 
  cout << endl;
  return 0;
}

Measured memory_bytes: 1196
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

const n = 26

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	d := io.NextInt()
	c := io.NextInts(n)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = io.NextInts(n)
	}
	t := io.NextInts(d)
	ans := solve(c, s, t)
	for i := range ans {
		io.Println(ans[i])
	}
}

func solve(c []int, s [][]int, t []int) []int {
	d := len(s)
	lasts := make([]int, n)
	scores := make([]int, d+1)
	for i := 0; i < d; i++ {
		lasts[t[i]-1] = i + 1
		up := s[i][t[i]-1]
		down := calcDown(c, lasts, i+1)
		scores[i+1] = scores[i] + up - down
	}
	return scores[1:]
}

func calcDown(c []int, lasts []int, day int) int {
	down := 0
	for i := 0; i < n; i++ {
		down += c[i] * (day - lasts[i])
	}
	return down
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// NextInts returns n integers from stdin
func (io *Io) NextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = io.NextInt()
	}
	return ret
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 2156
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())
  
a,b,c=i2()
if a>=b+c:
	print(0)
elif a<b+c and a>=b:
	print(c-a+b)
elif a<b:
	print(c)

Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007

int main() {
    string L;
    cin >> L;
    int s = L.size();
    ll dp[100002][2] = {{1}};


    REP(i, s) {
        if (L[i] == '0') {
            dp[i + 1][0] = dp[i][0];    // (0, 0)
            dp[i + 1][1] = dp[i][1] * 3 % MOD;  // (0, 0), (0, 1), (1, 0)
        } else {
            dp[i + 1][0] = dp[i][0] * 2 % MOD;  // (1, 0), (0, 1)
            dp[i + 1][1] = (dp[i][0] + dp[i][1] * 3) % MOD; // (0, 0) | (0, 0), (0, 1), (1, 0)
        }
    }
    cout << (dp[s][0] + dp[s][1]) % MOD << endl;
    return 0;
}

Measured memory_bytes: 2048
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLong()
    val b = sc.nextLong()
    val c = sc.nextLong()
    println(problem058a(a, b, c))
}

fun problem058a(a: Long, b: Long, c: Long): String {
    return if (b - a == c - b) "YES" else "NO"
}

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

using namespace std;
typedef long long ll;
const ll mx = 10000007;
const ll mod = 1e9 + 7;
const double pi = acos(-1);
#define    ss   second
#define    ff   first
#define    pb   push_back
#define gcd(a, b) __gcd((a), (b))
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
#define FIO ios_base::sync_with_stdio(false);  cin.tie(NULL);


int main() {
    FIO;
    ll a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout << a << " " << b<< " " << c << endl;
    
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n, ans;
	cin >> n;
	ans=n%1000;
	if (ans<=0){
		cout << ans << endl;
		return 0;
	} else if (ans>=0){
		cout << 1000-ans << endl;
	return 0;
	}
}

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;
/* c++11
#include <tuple>
using std::tuple; 
using std::make_tuple;
using std::get; // tuple std::get<NUM>(t); (0 <= NUM <= 2)
 */

typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

VC make_alphabet_list() {
    VC ret(52);
    for (int i = 0; i < 26; i++) {
        ret[i] = (char)('a' + i);
        ret[i + 26] = (char)('A' + i);
    }
    return ret;
}

VI recreate(VI k, int length) {
    VI use(length);
    int base = (int)(k.size());
    for (int i = 0; i < length; i++) {
        use[i] = k[i % base];
    }
    return use;
}

int main(void) {
    VC alphabet = make_alphabet_list();
    while (1) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        VI k(n);
        for (int i = 0; i < n; i++) {
            cin >> k[i];
        }
        string s;
        cin >> s;
        int length = s.length(); 
        VI s_temp(length);
        VI use_v = recreate(k, length);

        for (int i = 0; i < length; i++) {
            if (s[i] >= 'a' && s[i] <= 'z') {
                s_temp[i] = (int)(s[i] - 'a') + 52;
            } else if (s[i] >= 'A' && s[i] <= 'Z') {
                s_temp[i] = (int)(s[i] - 'A') + 26 + 52;
            }
        }
        s = "";
        for (int i = 0; i < length; i++) {
            s_temp[i] = (s_temp[i]- use_v[i]) % 52;
            s += alphabet[s_temp[i]];
        }
        cout << s << endl;
    }
    return 0;
}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

struct P {
  int y, m, d;
  P(int y = 0, int m = 0, int d = 0) : y(y), m(m), d(d) {}
};

bool operator < (const P& a, const P& b) {
  return a.y != b.y ? a.y < b.y : a.m != b.m ? a.m < b.m : a.d < b.d;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  P a;
  while (cin >> a.y >> a.m >> a.d) {
    if (a < P(1868, 9, 8)) cout << "pre-meiji" << endl;
    else if (a < P(1912, 7, 30)) cout << "meiji " << a.y - 1868 + 1 << " " << a.m << " " << a.d << endl;
    else if (a < P(1926, 12, 25)) cout << "taisho " << a.y - 1912 + 1 << " " << a.m << " " << a.d << endl;
    else if (a < P(1989, 1, 8)) cout << "showa " << a.y - 1926 + 1 << " " << a.m << " " << a.d << endl;
    else cout << "heisei " << a.y - 1989 + 1 << " " << a.m << " " << a.d << endl;
  }

  return 0;
}


Measured memory_bytes: 3152
#include <cstdio> 
#include <cstring>
char a[10];
int main(){
	scanf("%s",a + 1);
	for (int i = 1 ; i <= strlen(a + 1) ; i++){
		if (a[i] == '1') printf("9");
		else printf("1");
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define gridif(a,x,b) if((a)<=(x)&&(x)<(b))

using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
const int mod=1000000007;

int digitsum(int n,int b){
	if(b<2) return -1;
	if(n<b) return n;
	return digitsum(n/b,b)+n%b;
}
int mpow(int a,int x);
int m_inv(int n);
vector<int> split(int n,int a);
string xal_number(int n,int x);
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
class Factorial{
private:
	vector<int> fac;
public:
	Factorial(int N){
		fac.push_back(1);
		rep(i,N) fac.push_back(fac[i]*(i+1)%mod);
	}
	int fact(int a){return fac[a];}
	int ifac(int a){return m_inv(fac[a]);}
	int cmb(int n,int r);
};
struct UnionFind {
    vector<int> par; // 親ノード
    UnionFind(int n = 1) { init(n);}
    void init(int n = 1) {
        par.resize(n);
        rep(i,n) par[i] = -1;
    }
    int root(int x) {
        if (par[x] <0) return x;
        else return par[x] = root(par[x]);      
    }
    int size(int x){ return -par[root(x)];}
    bool issame(int x, int y) {return root(x)==root(y);}
    bool connect(int x, int y);
};

signed main(){
	int H,W;
	cin>>H>>W;
	vector<string> s(H);
	rep(i,H) cin>>s[i];
	rep(i,H+2){ rep(j,W+2){
		if(i==0||i==H+1) cout<<"#";
		else if(j==0||j==W+1) cout<<"#";
		else cout<<s[i-1][j-1];
	}
	cout<<endl;
}
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<bits/stdc++.h>
#include<iostream>
#include<math.h>
#include<fstream>
#define sc(x) scanf("%d",&x)
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORd(i,a,b) for(int i=a;i>b;i--)
#define ff first
#define ss second
#define reset(x) memset(x,0,sizeof x)
#define sz(x) x.size()
#define pb push_back
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);


using namespace std;

typedef pair<int,int> pii;
typedef vector<pii> vii;
const int con = 1e5+7;
static const int INF = 0x3f3f3f3f;
static const int MOD = 1e9+7;


















int main() {

    int T;cin >> T;
    ll sum = 0,x=0,ma = 0;
    FOR(i,0,T){
        cin >> x;
        sum += x;
        ma = max(ma,x);
    }
    sum -= ma;
    if(ma < sum)
        cout <<"Yes";
    else
        cout << "No";
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

typedef pair<int,int> P;
typedef long long ll;

const int INF = 1e9;


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

	int n;
	cin >> n;
	
	map<int,int> a;
	int tmp;
	for(int i=0;i<n;i++){
		cin >> tmp;
		if(a.find(tmp) != a.end())	a[tmp]++;
		else						a[tmp]=1;
	}
	int cnt=0;
	long long e[2];
	for(auto i=a.rbegin();i!=a.rend();i++){
		if(i->second >= 2) {
			if(cnt==0 && i->second >= 4){
				e[0] = e[1] = i->first;
				cnt=2;
			}
			else e[cnt++] = i->first;
			
			if(cnt==2) break;
		}
	}
	if(cnt < 2) cout << "0\n";
	else		cout << e[0]*e[1] << "\n";
			
	return 0;
}

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

#define ll long long 
#define pii pair<int, int>
#define ull unsigned ll
#define f first
#define s second
#define FOR(i,a,b) for (int i=(a); i<(b); i++)
#define REP(i,n) for (int i=0; i<(n); i++)
#define RREP(i,n) for (int i=(n-1); i>=0; i--)
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define MNTO(a,b) a = min(a,(__typeof__(a))(b))
#define MXTO(a,b) a = max(a,(__typeof__(a))(b))
#define pb push_back
#define debug(x) cerr<<#x<<" is "<<x<<endl

using namespace std;

const int maxn = 2e3+5;
const int intinf = 1<<29;
const ll inf = 1ll<<60;


void GG(){cout<<"No\n"; exit(0);}


vector<int> tree[maxn];
int nx = 0;
int k;
bool seen[maxn];

int dfs(int at, int left){
	if (left<0) return 0;
	seen[at]=1;
	int re = 1;
	for (int &v: tree[at]){
		if (!seen[v]) re+=dfs(v,left-1);
	}
	seen[at]=0;
	return re;
}

int solve(int x){
	int ex = 0, aa = 1;
	seen[x]=1;
	for (int &v: tree[x]){
		int a = dfs(v, k/2-1), b = dfs(v,k/2);
		aa += a; MXTO(ex, b-a);
		//debug(v); debug(a); debug(b);
	}
	seen[x]=0;
	return aa + ex;
}

int main(){
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
   	ll n, x; cin>>n>>x;
   	ll gg = __gcd(n,x);
   	cout<<gg * (-1+n/gg) * 3;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, D, A;
  cin >> N >> D >> A;
  vector<pair<ll, ll>> XH(N);
  for (int i = 0; i < N; i++)
    cin >> XH[i].first >> XH[i].second;
  sort(XH.begin(), XH.end());
  vector<ll> X(N);
  for (int i = 0; i < N; i++)
    X[i] = XH[i].first;
  ll cnt = 0;
  vector<ll> S(N + 1, 0);
  for (int i = 0; i < N; i++)
  {
    if (S[i] < XH[i].second)
    {
      ll H_now = XH[i].second;
      ll need = (H_now - S[i] + A - 1) / A;
      int idx = upper_bound(X.begin(), X.end(), X[i] + 2 * D) - X.begin();

      // imosしながら爆発させる
      S[i] += need * A;
      S[idx] -= need * A;
      cnt += need;
    }
    S[i + 1] += S[i];
  }
  cout << cnt << endl;
  return 0;
}

// 貪欲？出来るだけ離れたところで爆弾を使う 尺取り的な動き
// 更に累積和などを用いて既に減らした体力を保持しておくことが重要　imosしながら処理する 区間に値を加算するといえばimos法．imos法といえば区間加算処理が全て終わってから最後に累積和を取って結果を見るというイメージが強いが今回は値を取得する，と区間に加算するが交互に現れるので一見imos出来ないように見えるがimosすることが出来る．毎回のステップで途中まで累積和を取るみたいな感じにすればおけ


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b=0,d=0;
  string c[3];
  cin>>a;
  for(int i=0;i<3;i++) cin>>c[i];
  for(int i=0;i<a;i++){
    b=0;
    if(c[0][i]==c[1][i]);
    else b++;
    if(c[0][i]==c[2][i]);
    else b++;
    if(c[1][i]==c[2][i]);
    else b++;
    d=(b+1)/2+d;
    }
  cout<<d<<"\n";
  }


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int count=0;
		if(s.charAt(0)=='1') {
			count++;
		}
		if(s.charAt(1)=='1') {
			count++;
		}
		if(s.charAt(2)=='1') {
			count++;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 21844
#include<iostream>
#include <algorithm>

using namespace std;

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

int main(){
	int n, m;
	cin >> n >> m;
	long int a[n];
	
	rep(i, n) cin >> a[i];
	pair<long int, int> b[m];
	rep(i, m) {
		cin >> b[i].second >> b[i].first;
	}
	sort(a, a + n);
	sort(b, b + m, greater<pair<long int,int>>());
	long int c[n];
	fill(c, c + n, 0);
	int idx = 0;
	rep(i, m)rep(j, b[i].second){
		if(idx >= n) break;
		c[idx] = b[i].first;
		idx++;
	}
	rep(i, n){
		if(a[i] >= c[i]) break;
		else a[i] = c[i];
	}
	long int ans = 0;
	rep(i, n) ans += a[i];
	cout << ans << endl;
			
}


Measured memory_bytes: 3328
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
//template<class T>void max(T a,T b){if(a<b)return b;else return a;}
//template<class T>void min(T a,T b){if(a>b)return b;else return a;}
//template<class T>bool Max(T&a, T b){if(a < b){a = b;return 1;}return 0;}
//template<class T>bool Min(T&a, T b){if(a > b){a = b;return 1;}return 0;}

//////////////////////////


int main(){fastio
    string s;cin>>s;
    rep(i,0,2){
        if(s[i]=='7'){
            cout<<"Yes";return 0;
        }
    }
    cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,m,v,p;
    cin >> n >> m >> v >> p;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    ll l=-1,r=n;
    ll o=a[p-1],u=0;
    while(r-l>1){
        ll mid=(l+r)/2;
        ll k=max(0ll,v-(p-1)-(n-mid));
        ll y=k*m;
        for (int i=p-1;i<mid;i++){
            y-=(o-a[i]);
        }
        ll yy=0;
        // cout << y << endl;
        if (y>0) yy=(y-1)/(mid-p+1)+1;
        // cout << mid << " " << yy << " " << k << endl;
        if (a[mid]+m>=a[p-1]+yy) l=mid;
        else r=mid;
    }
    cout << l+1 << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define N 2*10e5
#define precise cout<<fixed<<setprecision(10)
#pragma GCC optimize("O0")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("-ffloat-store")
#define rep(i,a,b) for(int i=a;i<b;i++)
#define min3(a,b,c) min(a,min(b,c))
#define nl cout<<"\n";
#define all(v) v.begin(),v.end()
#define F first
#define S second
typedef long long ll;
typedef vector<long long> vl;
typedef vector<pair<long,long>> vp;
void get(ll arr[],ll n){for(ll i=0;i<n;i++) cin>>arr[i];}
ll gcd(ll a,ll b);
ll binpow(ll a,ll b);
void solve()
{
    string s,x;
    cin>>s>>x;
    ll n=s.length(),n1=x.length();
    ll mini=n1;
    rep(i,0,n-n1+1)
    {
        ll temp=0;
        string t1= s.substr(i,n1);
        rep(i,0,n1)
        {
            if(t1[i]!=x[i]) temp++;
        }
        mini=min(mini,temp);
    }
    cout<<mini;   
}
int main()
{
 	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
	 	solve();
	}
	//cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}
ll binpow(ll a, ll b) {
   ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

Measured memory_bytes: 3624
#include <iostream>
#include <set>
using namespace std;
int main()
{
  set<int> S;
  int n;
  cin>>n;
  for (int i=0;i<n;i++)
  {
    int x;
    cin>>x;
    S.insert(x);
  }
  cout<<S.size()<<endl; 
  //system("pause");
  return 0;
}

Measured memory_bytes: 256
import sys
from heapq import heappush, heappop


I = sys.stdin.readlines()
N, Q = map(int, I[0].split())
P = []
for i in range(1, N + 1):
    s, t, x = map(int, I[i].split())
    P.append((s - x, t - 1 - x, x))
P.sort()


q = []
cur = 0
cnt = 0
for i in range(N + 1, N + Q + 1):
    d = int(I[i])
    while cur < N and P[cur][0] <= d:
        s, t, x = P[cur]
        heappush(q, (x, t))
        cnt += 1
        cur += 1
    ans = -1
    while cnt:
        if d <= q[0][1]:
            ans = q[0][0]
            break
        else:
            heappop(q)
            cnt -= 1
    print(ans)



Measured memory_bytes: 137692
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void solve(long long A, long long B, long long N){
    chmin(N, B-1);
    cout<<(A*N)/B<<endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long N;
    scanf("%lld",&N);
    solve(A, B, N);
    return 0;
}


Measured memory_bytes: 3256
#include <stdio.h>

int main(void)
{
  char n[5];
  int number, i;

  fgets(n, sizeof(n), stdin);
  sscanf(n, "%d", &number);

  for (i=1; i <= number; i <<= 1)
      ;

  if (i > number) {
    i >>= 1;
  }

  printf("%d\n", i);
  
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>                    
                                     
signed main()                        
{                                    
  int a,b,c,d;                       
  scanf("%d %d %d %d",&a,&b,&c,&d);  
                                     
  if( a + b > c + d ){               
    puts("Left");                    
  }                                  
  else if( a + b == c + d ){         
    puts("Balanced");                
  }                                  
  else{                              
    puts("Right");                   
  }                                  
                                     
  return 0;                          
}                                    

Measured memory_bytes: 128
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  auto x = readln.chomp.to!int;
  if (x == 7 || x == 5 || x == 3) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cctype>
#include <queue>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <climits>
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
#define fi first
#define se second
#define ping(x,y) ((x-y)*(x-y))
#define mst(x,y) memset(x,y,sizeof(x))
#define mcp(x,y) memcpy(x,y,sizeof(y))
using namespace std;
#define gamma 0.5772156649015328606065120
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define N 200005
#define maxn 30010
typedef pair<int,int> PII;
typedef long long LL;
LL read(){
    LL x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
    return x*f;
}

int n,m;
int a[N];
int l[N],r[N];

int main(){
    //freopen("in.txt","r",stdin);
    int i,j,group,x,y,v,Case=0;
    n=read();
    for(i=1;i<=n;++i)a[i]=read(),l[i]=i-1,r[i]=i+1;
    l[1]=0;r[n]=n+1;
    for(i=2;i<=n;++i){
        while(l[i]>=1&&a[i]<=a[l[i]]){
            l[i]=l[l[i]];
        }
    }
    for(i=n-1;i>=1;--i){
        while(r[i]<=n&&a[i]<=a[r[i]]){
            r[i]=r[r[i]];
        }
    }
    LL res=0,ll,rr,t1,t2;
    for(i=1;i<=n;++i){
        ll=(l[i]>=1?l[i]:1);
        rr=(r[i]<=n?r[i]:n);
        if(a[i]>a[ll])++ll;
        if(a[i]>a[rr])--rr;
        t1=i-ll+1;
        t2=rr-i+1;
        res+=t1*t2*a[i];
    }
    printf("%lld\n",res);
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main(void)
{
    int f, m, r;

	while (1){
		scanf("%d%d%d", &f, &m, &r);
		
		if (f == -1 && m == -1 && r == -1){
			break;
		}

		if (f == -1 || m == -1){
			printf("F\n");
		}
		else if (f + m >= 80){
			printf("A\n");
		}
		else if (f + m >= 80){
			printf("F\n");
		}
		else if (f + m >= 65){
			printf("B\n");
		}
		else if (f + m >= 50){
			printf("C\n");
		}
		else if (f + m >= 30){
			if (r >= 50){
				printf("C\n");
			}
			else {
				printf("D\n");
			}
		}
		else {
			printf("F\n");
		}
		
	}
	return (0);
}




Measured memory_bytes: 2048
from itertools import combinations
n = int(input())
p = []
for _ in range(n):
    p.append(list(map(int, input().split())))
dis = 0
for i, j in combinations([i for i in range(n)], 2):
    dis += ((p[i][0]-p[j][0])**2 + (p[i][1]-p[j][1])**2)**(1/2)
print(dis/n*2)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define fix(n) cout<<fixed<<setprecision(n);
#define rep(i,n)   for (int i = 0; i < (n); ++i)
#define sort(a)    sort((a).begin(), (a).end());
#define uniq(a)    SORT(a);(a).erase(unique((a).begin(), (a).end()), (a).end());
#define find(a,x)  find((a).begin(), (a).end(), (x)) != (a).end()
#define reverse(a) reverse((a).begin(), (a).end());
#define out(d) cout << (d);
#define outl(d) std::cout<<(d)<<"\n";
#define Yes() printf("Yes\n");
#define No() printf("No\n");
#define YES() printf("YES\n");
#define NO() printf("NO\n");
#define ceil(x, y) ((x + y - 1) / (y))

using namespace std;
using ll = long long;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12)

  ll h, w; cin >> h >> w;

  rep(i, h) {
    rep(j, w) {
      string s; cin >> s;
      if (s == "snuke") {
        cout << char('A' + j) << i + 1 << endl;
      }
    }
  }
}


Measured memory_bytes: 888
n = gets.chomp.to_i
s = gets.chomp.to_s.split(//)

both_have = 0
max = 0

(n-1).times do |i|
  both_have = (s[0..i] & s[i+1..-1]).size
  if both_have > max
    max = both_have
  end
end

puts max

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

int main(){
  long long N;
  cin>>N;
  long long temp;
  queue<long long>Q;
  for(int i=1;i<=9;i++){
    Q.emplace(i);
  }
  for(long long i=1;i<=N;i++){
    temp=Q.front();
    //cout<<temp<<endl;
    if(temp%10 !=0){
      Q.emplace(temp*10+temp%10-1);
    }
    Q.emplace(temp*10+temp%10);
    if(temp%10 !=9){
      Q.emplace(temp*10+temp%10+1);
    }
    Q.pop();
  }
  cout<<setprecision(20)<<temp<<endl;
  return 0;
}


Measured memory_bytes: 5116
#!/usr/bin/python3

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

A = []
for k in range(N):
    Ai = [i for i in map(int, input().split())]
    _M = Ai.pop(0)
    A.append(Ai)

res = A[0]
for k in range(N - 1):
    res = list(set(res) & set(A[k + 1]))


print(len(res))


Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>

using namespace std;

struct Point {
  double x;
  double y;
  
  Point(double xx = 0, double yy = 0) {
    x = xx;
    y = yy;
  }
  Point operator + (Point p) { return Point(x + p.x, y + p.y); } //演算子のオーバーロード
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double k) { return Point(x * k, y * k); }
  Point operator / (double k) { return Point(x / k, y / k ); }
  bool operator == (Point p1) {
    if(p1.x == x && p1.y == y)
      return true;
    else 
      return false;
  }

};

double norm(Point p0, Point p1) {
  return sqrt(pow(p1.x - p0.x, 2) + pow(p1.y - p0.y, 2));
}

double dot(Point p0, Point p1, Point p2) {
  return (p1.x - p0.x) * (p2.x - p0.x) + (p1.y - p0.y) * (p2.y - p0.y);
}

double cross(Point p0, Point p1, Point p2) {
  return ( p1.x - p0.x ) * ( p2.y - p0.y ) - ( p2.x - p0.x) * (p1.y - p0.y);
}


double area_ratio(Point p0, Point p1, Point p2, Point p3) {
  double s1 = fabs( cross(p2, p0, p3) );
  double s2 = fabs( cross(p2, p3, p1) );
  return s1 / (s1 + s2);
}


/*
int positional_relationship(Point p0, Point p1, Point p2) {
  if(cross(p0, p1, p2) > 0) //反時計回り
    return 1;
  else if(cross(p0, p1, p2) < 0) //時計回り
    return -1;
  else if(dot(p0, p1, p2) < 0) //一直線上で反転向き
    return 2;
  else if(norm(p0, p1) < norm(p0, p2)) // 一直線上で同じ向き
    return -2;
  else //線分上に存在
    return 0;  
}

bool isIntersected(Point p0, Point p1, Point p2, Point p3) {
  if(positional_relationship(p0, p1, p2) * positional_relationship(p0, p1, p3) <= 0 && positional_relationship(p2, p3 ,p0) * positional_relationship(p2, p3, p1) <= 0)
    return true;
  return false;
};
*/

int main(void) {
  int q;
  cin >> q;
  Point p0, p1, p2, p3;

  for(int i = 0; i < q; i++) {
    cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
    double k = area_ratio(p0, p1, p2, p3);
    printf("%.10f %.10f\n", p0.x + k * (p1.x - p0.x), p0.y + k * (p1.y - p0.y));
  }

}


Measured memory_bytes: 3292
#include<iostream>
using namespace std;
int main()
{
int x[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int y;
cin>>y;
cout<<x[y-1];
}

Measured memory_bytes: 256