akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
int b[4][4]; 
void solve(){
    for(int i = 1; i <= 3; ++i) {
        for(int j = 1; j <= 3; ++j) {
            cin >> b[i][j]; 
        } 
    }
    int n;
    cin >> n;
    for(int q = 1; q <= n; ++q) {
        int x;
        cin >> x;
        for(int i = 1; i <= 3; ++i) {
            for(int j = 1; j <= 3; ++j) {
                b[i][j] = (b[i][j] == x) ? -1 : b[i][j];
            } 
        }
    }
    for(int i = 1; i <= 3; ++i) {
        if(b[i][1] == -1 && b[i][2] == -1 && b[i][3] == -1){
            cout << "Yes"; 
            return;
        }
    }
    for(int i = 1; i <= 3; ++i) {
        if(b[1][i] == -1 && b[2][i] == -1 && b[3][i] == -1){
            cout << "Yes"; 
            return;
        }
    }   
    if(b[1][1] == -1 && b[2][2] == -1 && b[3][3] == -1){
        cout << "Yes";
        return;
    } 
    if(b[3][1] == -1 && b[2][2] == -1 && b[1][3] == -1){
        cout << "Yes";
        return;
    } 
    cout << "No";
}

 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
flag = 'ap'
for i in range(N):
  if A[i]%2 == 0:
    if A[i]%3 == 0 or A[i]%5 == 0:
      continue
    else:
      flag = 'den'

if flag == 'ap':
  print('APPROVED')
else:
  print('DENIED')

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

int main(){
int X,N;
int big,small;

cin>>X>>N;
if(N==0){
    cout<<X<<endl;
    return 0;
}

int p[N];

for(int i=0;i<N;i++){
    cin>>p[i];
}
sort(p,p+N);

big=X,small=X;
int flag=0,flag2=0;
while(1){
for(int i=0;i<N;i++){

if(flag2==0){
    if(small==p[i]){
        flag=1;
    }
}else{
 if(big==p[i]){
        flag=1;
    }
}

}
if(flag2==0){
 if(flag==0){
        cout<<small<<endl;
        break;
    }else if(flag==1){
        flag=0;
        small--;
    }
}else{
if(flag==0){
        cout<<big<<endl;
        break;
    }else if(flag==1){
        flag=0;
        big++;
    }


}
if(flag2==1){
    flag2=0;
    }else{
        flag2=1;
    }
}


    return 0;
    
}

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

int main(void) {
  int N, K, Q;
  cin >> N >> K >> Q;
  vector<long long> A(N, 0);
  for (int i = 0; i < Q; i++) {
    int a;
    cin >> a;
    A[a - 1]++;
  }

  for (int i = 0; i < N; i++) {
    if (K - (Q - A[i]) > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1408
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

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

void Main()
{
	int n;
	cin >> n;
	int t = 10;
	vvi f(n, vi(t)), p(n, vi(t+1));
	rep(i,n){
		rep(j,t){
			cin >> f[i][j];
		}
	}
	rep(i,n){
		rep(j,t+1){
  			cin >> p[i][j];
		}
	}
	
	// bit全探索
	ll mx = -INT_MAX;
	for(int bit = 1; bit < (1<<t); bit++){
		ll temp = 0;
		vi c(n, 0);
		rep(i,n){
			rep(j,t){
				if(bit&(1<<j)){ // j 番目のビットが 1
					if(f[i][j]) c[i]++;
				}
			}
			temp += p[i][c[i]];
		}
		mx = max(mx, temp);
	}
	cout << mx << endl;
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

int a[200500];

int main()
{
    int n,k;
    while(cin>>n>>k)
    {
        int i;
        int t,f;
        scanf("%d",&t);
        f=t;
        int x;
        for(i=1;i<k;i++)
        {
            scanf("%d",&x);
            a[i-1]=x-t;
            t=x;
        }
        a[i-1]=n+f-x;
        sort(a,a+i);
        int num=0;
        for(i=0;i<k-1;i++)
            num+=a[i];
        printf("%d\n",num);
    }
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int n,ans,a,b;
int digsum(int x){
    stack<int> s;
    while(x>0){
        s.push(x%10);
        x/=10;
    }
    int res = 0;
    while(!s.empty()){
        res += s.top();
        s.pop();
    }
    return res;
}
bool inrange(int l,int r, int x){
    if(l<=x && x<=r)return true;
    else return false;
}
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++){
        if(inrange(a,b,digsum(i)))ans+=i;
    }
    cout<<ans<<newl;

}


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

ans = 0
for i in range(N):
    for j in range(N):
        x = d[i] * d[j]
        ans += x

dans = 0
for i in range(N):
    y = d[i] ** 2
    dans += y

fans = (ans - dans) // 2

print(fans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
char in[110];
int main(){
	scanf("%s",in);
	if(in[0]=='Y'&&in[1]=='A'&&in[2]=='K'&&in[3]=='I')printf("Yes\n");else printf("No\n");
}

Measured memory_bytes: 128
import numpy as np
q = int(input())
b = [True] * (10**5+1)
for i in range(2, 10**5):
    if not b[i]:
        continue
    x = 2 * i
    while x <= 10**5:
        b[x] = False
        x += i
b[0] = b[1] = False
a = [False] *  (10**5+1)
for i in range(1, 10**5):
    if b[i] and b[int((i+1)/2)]:
        a[i] = True
cumsum = np.array(a).cumsum()
for _ in range(q):
    l, r = map(int, input().split())
    print(cumsum[r] - cumsum[l-1])

Measured memory_bytes: 17220
import java.util.*;
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        
        int temp,case_num = 1;
        
        while((temp=sc.nextInt())!=0) {
            System.out.printf("Case %d: %d\n",case_num, temp);
            case_num++;
        } 

    }
}



Measured memory_bytes: 63048
#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int, int> > a(2010);
long dp[2010][2010];
template<class T> inline bool chmax(T& a, const T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
int main() {
	int n, x;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		a.push_back(make_pair(x, i));
	}
	sort(a.begin(), a.end(), greater<pair<int, int> >());
	long ans = 0;
	for (int l = 0; l < n; l++) {
		for (int r = 0; r < n; r++) {
			if (l + r == n) {
				chmax(ans, dp[l][r]);   break;
			}
			else {
				chmax(dp[l + 1][r], dp[l][r] + (long)a[l + r].first * abs(l - a[l + r].second));
				chmax(dp[l][r + 1], dp[l][r] + (long)a[l + r].first * abs((n - 1 - r) - a[l + r].second));
			}
		}
	}
	cout << ans;
}

Measured memory_bytes: 26308
#include<bits/stdc++.h>
using namespace std;
int h[100010],f[100010];
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)  cin>>h[i];
	f[1]=0,f[2]=abs(h[2]-h[1]);
	for(int i=3;i<=n;i++)
	   f[i]=min(f[i-1]+abs(h[i]-h[i-1]),f[i-2]+abs(h[i]-h[i-2]));
	cout<<f[n]<<endl;
	return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys


def solve(N: int):
    print(N**3)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include<vector>
#include <queue>
using namespace std;
int h[11] = {0};
int main()
{
	while(1){
		int n;
		cin >> n;
		if (n == 0)break;
		int a;
		for (int i = 1; i <= n; i++) {
			cin >> a;
			h[a]++;
		}
		for (int i = 0; i <= 9; i++) {
			if (h[i] == 0)cout << "-";
			for (int j = 1; j <= h[i]; j++) {
				cout << "*";
			}
			h[i] = 0;
			cout << endl;
		}
		
	}
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define li long long
#define itn int
 
using namespace std;
 
inline int nxt(){
	int n;
	scanf("%d", &n);
	return n;
}

template <typename T>
ostream& operator <<(ostream& ostr, const vector<T>& a) {
	ostr << "(";
	for (size_t i = 0; i < a.size(); ++i) {
		if (i) {
			ostr << ", ";
		}
		ostr << a[i];
	}
	ostr << ")";
	return ostr;
}

const int mod = 1000000007;

long long pw(long long a, long long b) {
	long long res = 1;
	while (b) {
		if (b & 1ll) {
			res = res * a % mod;
		}
		b >>= 1;
		a = a * a % mod;
	}
	return res;
}

int main(){
	// int n = nxt();
	// vector<int> a(n);
	// for (int i = 0; i < n; ++i) {
	// 	a[i] = nxt();
	// }

	int n = nxt(), a = nxt(), b = nxt();
	if (n == 1) {
		if (a == b) {
			puts("1");
		} else {
			puts("0");
		}
	} else {
		if (a <= b) {
			cout << 1ll * (n - 2) * b - 1ll * (n - 2) * a + 1 << "\n";
		} else {
			puts("0");
		}
	}

	return 0;
}

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

#define mod 1000000007 

int main(void) {
    //code goes 
	int c11,c12,c13,c21,c22,c23,c31,c32,c33; 
	scanf("%d %d %d %d %d %d %d %d %d",&c11,&c12,&c13,&c21,&c22,&c23,&c31,&c32,&c33); 
	if(c11+c22==c21+c12 && c21+c32==c22+c31 && c12+c23==c22+c13 && c33+c22==c23+c32) 
	    printf("Yes"); 
	else      
	    printf("No");
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000

//aのb乗
int beki(int a,int b){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=mod(x*a);
		}
		a=mod(a*a);
		b>>=1;
	}
	return x;
}

//aの逆元
int gyakugen(int a){
	return beki(a,modulo-2);
}

struct combi{
	deque<int> kaijou;
	deque<int> kaijou_;
	
	combi(int n){
		kaijou.push_back(1);
		for(int i=1;i<=n;i++){
			kaijou.push_back(mod(kaijou[i-1]*i));
		}
		
		int b=gyakugen(kaijou[n]);
		
		kaijou_.push_front(b);
		for(int i=1;i<=n;i++){
			int k=n+1-i;
			kaijou_.push_front(mod(kaijou_[0]*k));
		}
	}
	
	int combination(int n,int r){
		if(r>n)return 0;
		int a = mod(kaijou[n]*kaijou_[r]);
		a=mod(a*kaijou_[n-r]);
		return a;
	}
	
	int junretsu(int a,int b){
		int x = mod(kaijou_[a]*kaijou_[b]);
		x=mod(x*kaijou[a+b]);
		return x;
	}
	
};

int main(){
	
	int N,K;
	cin>>N>>K;
	
	vector<int> a(K);
	for(int i=0;i<K;i++)cin>>a[i];
	
	vector<vector<int>> dp(K+1,vector<int>(N+1,0));
	
	dp[0][0] = 1;
	
	combi C(2000);
	
	for(int i=0;i<K;i++){
		for(int j=0;j<=N;j++){
			for(int k=0;k<=a[i];k++){
				int x = k;
				int y = a[i] - k;
				int new_i = i+1;
				int new_j = j+x;
				if(new_j>N)continue;
				int r = 1;
				r = mod(r * C.combination(N-j,x));
				r = mod(r * C.combination(N-x,y));
				r = mod(r * dp[i][j]);
				dp[new_i][new_j] = mod(dp[new_i][new_j] + r);
			}
		}
	}
	
	int ans = dp[K][N];

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


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cstring>
#include <functional>
#include <cmath>
#include <complex>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define rep1(i,n) for(int i=1;i<=(n);++i)
#define all(c) (c).begin(),(c).end()
#define fs first
#define sc second
#define pb push_back
#define show(x) cout << #x << " " << x << endl
typedef double D;
int H,W;
string s[601];
bool dx[601][601],dy[601][601];
int gcd(int x,int y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	cin>>H>>W;
	rep(i,H) cin>>s[H-1-i];
	s[H].assign(W,'.');
	rep(i,H+1) s[i]+='.';
	rep(i,H) rep(j,W+1) dx[i][j]=(s[i][j]==s[i+1][j]);
	rep(i,H+1) rep(j,W) dy[i][j]=(s[i][j]==s[i][j+1]);
	int mx=0;
	rep1(a,W) rep1(b,H){
		if(gcd(a,b)!=1) continue;
		int cnt=0;
		rep1(x,W){
			int y=(b*x-1)/a;
			if(y<H&&!dy[y][x-1]) cnt++;
		}
		rep1(y,H){
			int x=(a*y)/b;
			if(x<W&&!dx[y-1][x]) cnt++;
		}
		mx=max(mx,cnt);
		cnt=0;
		rep1(x,W){
			int y=(b*x)/a;
			if(y<H&&!dy[y][x-1]) cnt++;
		}
		rep1(y,H){
			int x=(a*y-1)/b;
			if(x<W&&!dx[y-1][x]) cnt++;
		}
		mx=max(mx,cnt);
	}
	cout<<(mx+3)/2<<endl;
}

Measured memory_bytes: 2316
class UnionFind():
  def __init__(self, n):
    self.n=n
    self.parents=[-1]*n

  def find(self,x):
    if self.parents[x]<0:
      return x
    else:
      self.parents[x]=self.find(self.parents[x])
      return self.parents[x]

  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if x == y:
      return
    if self.parents[x]>self.parents[y]:
      x,y=y,x
    self.parents[x]+=self.parents[y]
    self.parents[y]=x

  def size(self, x):
    return -self.parents[self.find(x)]

  def same(self, x, y):
    return self.find(x) == self.find(y)

  def members(self, x):
    root = self.find(x)
    return [i for i in range(self.n) if self.find(i)==root]

  def roots(self):
    return [i for i,x in enumerate(self.parents) if x<0]

N,M=map(int,input().split())
uf=UnionFind(N)
for _ in range(M):
  a,b=map(int,input().split())
  a-=1
  b-=1
  uf.unite(a,b)
print(len(set(uf.roots()))-1)

Measured memory_bytes: 19100
#include<stdio.h>

int main(void) {
  long a, b, c, d;
  scanf("%ld %ld %ld %ld", &a, &b, &c, &d);
  long n[4] = {a*c, a*d, b*c, b*d};
  long max = n[0];
  int i;
  for(i=1; i<4; i++) {
    if(max < n[i]) {
      max = n[i];
    }
  }
  printf("%ld\n", max);
  return 0;
}


Measured memory_bytes: 1732
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]

# print(x,n)
# print(p)
flag = 0
temp = x
while(flag == 0):
    if x in p:
        x +=1        
    else:
        ans_p = x
        flag =1

x = temp
flag = 0

while(flag == 0):
    if x in p:
        x -=1        
    else:
        ans_n = x
        flag =1
# print(ans_p, ans_n)
abso_p = abs(ans_p-temp)
abso_n = abs(ans_n-temp)
if abso_p >= abso_n:
    print(ans_n)
elif abso_p < abso_n:
    print(ans_p)

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

int main(){
	while(true){
		int N;
		cin>>N;
		if(N==0){
			break;
		}
		int cnt0=0;
		int cnt1=0;
		for(int i=0;i<N;i++){
			int k;
			cin>>k;
			if(k==0){
				cnt0++;
			}else if(k==1){
				cnt1++;
			}
		}
		if(cnt0+cnt1==N){
			cout<<"NA"<<endl;
		}else{
			cout<<N-cnt0+1<<endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
typedef long long int ll;
using namespace std;
using Graph = vector<vector<int> >;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int A,B,C;
cin>>A>>B>>C;
vector<int> ABC{A,B,C};
sort(ABC.begin(),ABC.end());
int ans=10*ABC[2]+ABC[1]+ABC[0];
cout<<ans<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {
	public static void main(String ards[])
	{
		Scanner cin = new Scanner(System.in);
		String a = cin.next();
		String b = cin.next();
		String c = cin.next();
		
		boolean[]ab = check(a,b);
		boolean[]ac = check(a,c);
		boolean[]ba = check(b,a);
		boolean[]bc = check(b,c);
		boolean[]ca = check(c,a);
		boolean[]cb = check(c,b);
		
		int ans = a.length()+b.length()+c.length();
		int mlen = Math.max(a.length(), Math.max(b.length(), c.length()));
		
		for(int i = 0; i <= mlen; i++){
			for(int j = 0; j <= mlen; j++){
				ans = Math.min(ans, solve(a,b,c,ab,bc,ac,i,j));
				ans = Math.min(ans, solve(a,c,b,ac,cb,ab,i,j));
				ans = Math.min(ans, solve(b,a,c,ba,ac,bc,i,j));
				ans = Math.min(ans, solve(b,c,a,bc,ca,ba,i,j));
				ans = Math.min(ans, solve(c,a,b,ca,ab,cb,i,j));
				ans = Math.min(ans, solve(c,b,a,cb,ba,ca,i,j));
			}
		}
		System.out.println(ans);
	}
	
	public static boolean[] check (String s, String t){
		boolean[] ans = new boolean[s.length()];
		for(int i = 0; i < s.length(); i++){
			boolean tmp = true;
			for(int j = 0; j < Math.min(t.length(), s.length()-i); j++){
				tmp &= (s.charAt(i+j) == t.charAt(j) || s.charAt(i+j) == '?' || t.charAt(j) == '?');
			}
			ans[i] = tmp;
		}
		return ans;
	}
	
	public static int solve(String a, String b, String c, boolean[] ab, boolean[] bc, boolean[] ac, int i, int j){
		if((i >= a.length() || ab[i]) && (j >= b.length() || bc[j]) && (i+j >= a.length() || ac[i+j])){
			return Math.max(a.length(), Math.max(i+b.length(), i+j+c.length()));
		}else{
			return Integer.MAX_VALUE;
		}
	}
}

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

using namespace std;

int n;
bool taken[51];
vector<int> a, b;

bool explore(int current_vertex, int goal_vertex){
	if(current_vertex < goal_vertex)
		return false;
	if(current_vertex == goal_vertex)
		return true;
	for(int i = 1; i <= 50; i++)
		if(taken[i] == true && i <= current_vertex)
			if(explore(current_vertex % i, goal_vertex))
				return true;
	return false;
}

bool works(){
	for(int i = 0; i < n; i++)
		if(explore(a[i], b[i]) == false)
			return false;
	return true;
}
int main(){
	cin >> n;
	memset(taken, true, sizeof taken);
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		a.push_back(x);
	}
	for(int i = 0; i < n; i++) {
		int x;
		cin >> x;
		b.push_back(x);
	}
	int current_edge = 50;
	while(current_edge > 0){
		taken[current_edge] = false;
		if(!works())
			taken[current_edge] = true;
		current_edge--;
	}
	long long answer = 0;
	for(int i = 1; i <= 50; i++)
		if(taken[i] == true) {
			answer += pow(2,i);
		}
	cout << (works() ? answer : -1) << endl;
	return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int>> g(n);
	vector<int> h(n);
	for (int i = 0; i < n + m - 1; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		g[x].push_back(y);
		h[y]++;
	}
	vector<int> ans(n);
	queue<int> que;
	for (int i = 0; i < n; i++) {
		if (h[i] == 0) que.push(i);
	}
	ans[que.front()] = -1;
	while ((int) que.size()) {
		int from = que.front();
		que.pop();
		for (auto &to : g[from]) {
			h[to]--;
			if (h[to] == 0) {
				que.push(to);
				ans[to] = from;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << ans[i] + 1 << '\n';
	} 
	return 0;
}

Measured memory_bytes: 7040
#include "bits/stdc++.h"

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i, x, n) for(int i = x; i >= n; i--)
#define rrep(i, n) RREP(i,n,0)
#define pb push_back
#define show_table(n, k, table) rep(i,n){ rep(j,k) cout << table[i][j] << " "; cout << endl;}

using namespace std;

template<class T> inline void chmax(T& a,T const& b){a=max(a,b);}
template<class T> inline void chmin(T& a,T const& b){a=min(a,b);}

using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll lmod = 1e9+7,LINF=1LL<<60;
const int MAX_N = 100005;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s[3],ans;
  rep(i,3){
    cin >> s[i];
    ans += s[i][i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N=int(input().strip())
S=input().strip()
maxnum=0
for i in range(1,N):
    if min(i, N-i) < maxnum:
        continue
    s1=set(i for i in S[:i])
    s2=set(i for i in S[i:])
    num=0
    for c in s1:
        if c in s2:
            num+=1
    if num > maxnum:
        maxnum=num
print(maxnum)

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 24;

int main(void){
    for(int n; cin >> n, n;){
        vi s(n); for(auto && ss : s) cin >> ss;

        sort(all(s));

        int res = 0;
        range(i, 1, n - 1) res += s[i];

        cout << res / (n - 2) << endl;
    }

	return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007;//998244353;

template<class _T> static void get(_T& a) {
	std::cin >> a;
}
template<class _T> static void get(_T& a, _T& b) {
	std::cin >> a >> b;
}
template<class _T> static void get(_T& a, _T& b, _T& c) {
	std::cin >> a >> b >> c;
}
template<class _T> static void getint(_T& a) {
	if (sizeof(_T) > sizeof(int)) {
		scanf("%lld", &a);
	}
	else {
		scanf("%d", &a);
	}
}
template <class _T> static _T tp_abs(_T a) {
	if (a < (_T)0) {
		a *= (_T)-1;
	}
	return a;
}

static void exec();

int main()
{
	exec();
	fflush(stdout);
	return 0;
}

static void dfs(std::string s, char mx, int len)
{
	if (s.length() == len) {
		printf("%s\n", s.c_str());
	}
	else {
		for (char c = 'a'; c <= mx; c++) {
			dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx), len);
		}
	}
}
static void exec()
{
	int N;
	get(N);
	dfs("", 'a', N);
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S;
  cin >> S;
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == '1') {
      S.at(i) = '9';
    }
    else if (S.at(i) == '9') {
      S.at(i) = '1';
    }
  }
  cout << S << endl;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int a, b;
    cin >> a >> b;
    cout << (a+b+1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

const int QMAX = 200000;
char T[QMAX], D[QMAX];

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, Q;
  cin >> N >> Q;
  cin.ignore();
  string board;
  getline(cin, board);
  REP(i, Q) { cin >> T[i] >> D[i]; }
  int head = -1, tail = N;
  for (int i = Q - 1; i >= 0; --i) {
    char t = T[i];
    if (D[i] == 'L') {
      if (head + 1 < N && t == board[head + 1]) ++head;
      if (tail < N && t == board[tail]) ++tail;
    } else {
      if (tail - 1 >= 0 && t == board[tail - 1]) --tail;
      if (head >= 0 && t == board[head]) --head;
    }
  }
  cout << (tail - head - 1) << endl;
}


Measured memory_bytes: 1020
#include <iostream>

using namespace std;

int main()
{
  int x,a,b,d1,d2;
  cin >> x >> a >> b;

  d1 = a-x; d2 = b-x;

  if(d1<0)d1 = -d1;
  if(d2<0)d2 = -d2;

  if(d2 > d1)cout << "A" << endl;
  else cout << "B" << endl;

  return 0;
}

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

#define db(x) cerr << #x << " == " << x << endl
#define all(container) container.begin(), container.end()
#define mp(i,j) make_pair(i,j)
#define pb push_back

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<pii> vii;

template<typename T>
void print_vector_debug(const T& t) {
	cout << "[DEBUG] VECTOR:";
	for (auto i = t.cbegin(); i != t.cend(); ++i) {
		if ((i + 1) != t.cend()) {
			cout << *i << " ";
		} else {
			cout << *i << endl;
		}
	}
}

#define MAXN 1005
#define MOD 1000000007

char grid[MAXN][MAXN];
int N, M;
int vis[MAXN][MAXN], dp[MAXN][MAXN];

int solve(int n, int m)
{
	if (n == N - 1 && m == M - 1)
	{
		return 1;
	}
	
	if (vis[n][m])
	{
		return dp[n][m];
	}
	vis[n][m] = 1;
	
	int down = 0, right = 0;
	
	if (n + 1 < N && grid[n + 1][m] == '.')
	{
		down = solve(n + 1, m);
	}
	if (m + 1 < M && grid[n][m + 1] == '.')
	{
		right = solve(n, m + 1);
	}
	
	dp[n][m] = (right + down) % MOD;
	return dp[n][m];
}

int main() 
{
	scanf("%d%d\n", &N, &M);
	
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < M; j++)
		{
			scanf("%c", &grid[i][j]);
		}
		scanf("\n");
	}
	
	printf("%d\n", solve(0, 0));
	return 0;
}


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

using namespace std;

/*  テンプレここから */
typedef long long ll;

#define rep(i, n) for(int i = 0; i < n; ++i)
#define repi(i, start, end) for(int i = start; i < end; ++i)
#define all(x) (x).begin(), (x).end()
#define INF (1e9)
#define INFL (1e18)
#define add_mod(a, b, x) ( (ll)(a) + (ll)(b) ) % (ll)(x)
#define mul_mod(a, b, x) ( ((ll)(a) % (ll)(x)) * ((ll)(b) % (ll)(x)) ) % (ll)(x)
#define out(x) cout << (x) << endl;
#define outyes(bool_val) cout << (bool_val ? "yes" : "no") << endl;
#define outYes(bool_val) cout << (bool_val ? "Yes" : "No") << endl;
#define outYES(bool_val) cout << (bool_val ? "YES" : "NO") << endl;
#define outPossible(bool_val) cout << (bool_val ? "Possible" : "Impossible") << endl;
#define outPOSSIBLE(bool_val) cout << (bool_val ? "POSSIBLE" : "IMPOSSIBLE") << endl;

template<typename A, size_t N, typename T>
void array_fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll sub_mod(ll a, ll b, ll x){
    ll tmp = (a - b) % x;
    if(tmp < 0) tmp += x;
    return tmp;
}
ll gcd(ll a, ll b){
    if(b == 0) return a;
    else return gcd(b, a % b);
}

int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
/*  テンプレここまで */

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

    int a, b, c;
    cin >> a >> b >> c;

    outYes(a == b && b == c);
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
d = {'8':0}
for i in a:
  if 1 <= i <= 399:
    if '0' in d:
      d['0'] += 1
    else:
      d['0'] = 1
  elif 400 <= i <= 799:
    if '1' in d:
      d['1'] += 1
    else:
      d['1'] = 1
  elif 800 <= i <= 1199:
    if '2' in d:
      d['2'] += 1
    else:
      d['2'] = 1
  elif 1200 <= i <= 1599:
    if '3' in d:
      d['3'] += 1
    else:
      d['3'] = 1
  elif 1600 <= i <= 1999:
    if '4' in d:
      d['4'] += 1
    else:
      d['4'] = 1
  elif 2000 <= i <= 2399:
    if '5' in d:
      d['5'] += 1
    else:
      d['5'] = 1
  elif 2400 <= i <= 2799:
    if '6' in d:
      d['6'] += 1
    else:
      d['6'] = 1
  elif 2800 <= i <= 3199:
    if '7' in d:
      d['7'] += 1
    else:
      d['7'] = 1
  else:
    d['8'] += 1

if d['8'] == 0 :
  print(len(d)-1,len(d)-1)
else:
  if len(d)-1 == 0:
    print(1,len(d)+d['8'] -1)
  else:
    print(len(d)-1,len(d)+d['8'] -1)

Measured memory_bytes: 3064
s = input()

mae = int( s[0]+s[1] )
ato = int( s[2]+s[3] )

if mae>=1 and mae<=12:
    if ato>=1 and ato<=12:
        print("AMBIGUOUS")
    else:
        print("MMYY")
else:
    if ato>=1 and ato<=12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define N 1000005
using namespace std;

int n, a, b;

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d",&n ,&a ,&b);
	if(abs(a - b)%2 == 0)
		puts("Alice");
	else
		puts("Borys");
	return 0;
}

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

int n,k;
char s[10005];
LL dp[10005][105];
int mod = 1e9+7;

int main() {
	scanf("%s",&s);
	scanf("%d",&k);
	n = strlen(s);
	memset(dp,0,sizeof(dp));
	dp[0][0] = 1;
    for (int i=1; i<=n; i++) {
		for (int j=0; j<k; j++) {
			dp[i][j] = 0;
			for (int d=0; d<10; d++) {
				dp[i][j] += dp[i-1][((j-d)%k+k)%k];
			}
			dp[i][j] %= mod;
			//printf("  %d,%d = %lld\n",i,j,dp[i][j]);
		}
    }
    LL ret = 0;
    int rem = 0;
    for (int i=0; i<n; i++) {
		int dig = s[i]-'0';
		for (int j=0; j<dig; j++) {
			ret += dp[n-i-1][((rem-j)%k+k)%k];
			//printf("%d,%d + %lld = %lld\n",i,j,dp[n-i-1][((rem-j)%k+k)%k],ret);
		}
		ret %= mod;
		rem = ((rem-dig)%k+k)%k;
    }
    if (rem == 0) ret++;
    printf("%lld\n",(ret-1+mod)%mod);
	return 0;
}


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

int main(){
    int h, w, n, sx, sy;
    string s,t;
    cin >> h >> w >> n 
        >> sx >> sy 
        >> s >> t;
    
    sx -= 1;
    sy -= 1;
    reverse(s.begin(), s.end());
    reverse(t.begin(), t.end());

    int left = 0, right = w-1;// survival border
    for(int i=0; i<n; i++){
        if(i != 0){
            if(t[i] == 'L') right = min(right + 1, w-1);
            if(t[i] == 'R') left  = max(left  - 1, 0);
        }
        if(s[i] == 'L') left  += 1;
        if(s[i] == 'R') right -= 1;
        if(left > right){
            cout << "NO" << endl;
            return 0;
        }
    }
    int above = 0, below = h-1;// survival border
    for(int i=0; i<n; i++){
        if(i != 0){
            if(t[i] == 'U') below = min(below + 1, h-1);
            if(t[i] == 'D') above = max(above - 1, 0);
        }
        if(s[i] == 'U') above += 1;
        if(s[i] == 'D') below -= 1;
        if(above > below){
            cout << "NO" << endl;
            return 0;
        }
    }

    if(left  <= sy && sy <= right
    && above <= sx && sx <= below){
        cout << "YES" << endl;
    }
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 3832
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val d = readLine()!!.split(" ").map(String::toInt)
    var result = 0
    for (i in 0 until d.size) {
        for (j in 0 until d.size) {
            if (i < j) {
                result += d[i] * d[j]
            }
        }
    }
    println(result)
}

Measured memory_bytes: 37832
from fractions import gcd

def lcm(x, y):
    return (x * y) // gcd(x, y)

a, b, c, d = map(int, input().split())

koubai = lcm(c, d)

a -= 1
x1 = a // c
x2 = a // d
x3 = a // koubai

y1 = b // c
y2 = b // d
y3 = b // koubai

ans = b - a - ((y1+y2-y3) - (x1+x2-x3))

print(ans)

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

int main(){
    ll a, b, k;
    cin >> a >> b >> k;

    if(a >= k){
        cout << a-k << " " << b << endl;
    }

    else{
        if(a+b-k>=0){
            cout << 0 << " " << a+b-k << endl;
        }

        else{
            cout << 0 << " "  << 0 << endl;
        }
    }
}

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

int  main()
{
	int w, h, n; cin >> w >> h >> n;
	int Xs = 0; int Xe = w;
	int Ys = 0; int Ye = h;
	rep(i, n)
	{
		int x,y,a;
		cin >> x >> y >> a;
		if (a == 1)
		{
			if (Xs < x)
				Xs = x;
		}
		if (a == 2)
		{
			if (Xe > x)
				Xe = x;
		}
		if (a == 3)
		{
			if (Ys < y)
				Ys = y;
		}
		if (a == 4)
		{
			if (Ye > y)
				Ye = y;
		}
	}
	int X = Xe - Xs;
	int Y = Ye - Ys;
	if (X < 0)
		X = 0;
	if (Y < 0)
		Y = 0;
	cout << X * Y << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>; // グラフ型

/* // 深さ優先探索
vector<bool> seen;
int dfs(const Graph &G, int v) {
    seen[v] = true; // v を訪問済にする
    int score = 0; 

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー

        // 負荷さ優先探索中の処理



        dfs(G, next_v); // 再帰的に探索, 毎回mat渡してええの？
    }
    return score;
} */


int main() {
    int N, K;
    cin >> N >> K;
    vector<int> d(K);
    //vector<vector<int>> mat(K, vector<int>);
    vector<vector<int>> data(K, vector<int>(N, -1));
    vector<bool> sunuke(N, false);

    for (int i = 0; i < K ; i++){
        cin >> d.at(i);
        for(int j = 0 ; j < d.at(i); j++){
            cin >> data.at(i).at(j);
            sunuke.at(data.at(i).at(j) - 1) = true;
        }
    }
    int count = 0;

    for (int i =0; i < N; i++){
        if (sunuke.at(i) == false) count++;
    }

    cout << count << endl;

}


Measured memory_bytes: 3632
n,a,b = [int(i) for i in input().split()]
mod = 10**9+7

def mpow(a,n):
  if n == 1:
    return a
  x = mpow(a,n//2)
  ans = x*x%mod
  if n%2==1:
    ans *= a
  return ans

def comb(n,a,b):
  if a < b:
    s, l = a, b
  else:
    s, l = b, a
  rs = 1
  for i in range(s):
    rs = rs*(n-i)%mod
  rl = rs
  for i in range(s,l):
    rl = rl*(n-i)%mod
  L = 1
  for i in range(1,s+1):
    L = L*mpow(i,mod-2)%mod
  rs = rs*L%mod
  rl = rl*L%mod
  for i in range(s+1,l+1):
    rl = rl*mpow(i,mod-2)%mod
  if a < b:
    nCa, nCb = rs, rl
  else:
    nCa, nCb = rl, rs
  return nCa, nCb
nCa,nCb = comb(n,a,b)
print((mpow(2,n)-1-nCa-nCb)%mod)
# print(nCa,nCb)


Measured memory_bytes: 47452
#include <stdio.h>

int main(void){

	int i, j;
	int q;
	int t, f;
	int x, y;
	int dice[6];

	for (i=0; i<6; i++){
		scanf("%d", &dice[i]);
	}	/* ??????????????????????????????????????????????????¢?????°????????\??? */

		/* ???????????????????????°q?????\??? */
	scanf("%d", &q);
		for (j=0; j<q; j++) {
			t=0;
			f=0;

		/* ?????¢??¨?????¢?????°????????¨??????????????´??°?????\??? */
	scanf("%d %d", &x, &y);
		for(i=0; i<6; i++){
			if(x==dice[i]){
				t=i;
		}

		else if(y==dice[i]){
			f=i;
		}
	}

	/* ?????????????????????????????¨?????¢????????£???????????¢????????? */
	/* ?????????????????????????????¨?????¢????????£???????????¢????????? */
	/* ???????????¢???????????????????????????????????§?????¢???????????????????????¢?????????????????? */
	if (t==0) {
		if(f==1){
			printf("%d\n", dice[2]);
	}
		else if(f==2){
			printf("%d\n", dice[4]);
		}
		else if(f==3){
			printf("%d\n", dice[1]);
		}
		else if(f==4){
			printf("%d\n", dice[3]);
		}
	}

	else if(t==1){
		if(f==0){
			printf("%d\n", dice[3]);
		}
		else if(f==2){
			printf("%d\n", dice[0]);
		}
		else if(f==3){
			printf("%d\n", dice[5]);
		}
		else if(f==5){
			printf("%d\n", dice[2]);
		}
	}

	else if(t==2){
		if(f==0){
			printf("%d\n", dice[1]);
	}
		else if(f==1){
			printf("%d\n", dice[5]);
		}
		else if(f==4){
			printf("%d\n", dice[0]);
		}
		else if(f==5){
			printf("%d\n", dice[4]);
		}
	}

	else if(t==3){
		if(f==0){
			printf("%d\n", dice[4]);
	}
		else if(f==1){
			printf("%d\n", dice[0]);
		}
		else if(f==4){
			printf("%d\n", dice[5]);
		}
		else if(f==5){
			printf("%d\n", dice[1]);
		}
	}

	else if(t==4){
		if(f==0){
			printf("%d\n", dice[2]);
	}
		else if(f==2){
			printf("%d\n", dice[5]);
		}
		else if(f==3){
			printf("%d\n", dice[0]);
		}
		else if(f==5){
			printf("%d\n", dice[3]);
		}
	}

	else if(t==5){
		if(f==1){
			printf("%d\n", dice[3]);
	}
		else if(f==2){
			printf("%d\n", dice[1]);
		}
		else if(f==3){
			printf("%d\n", dice[4]);
		}
		else if(f==4){
			printf("%d\n", dice[2]);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 596
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int first = N%10;
        int tenth = N/10;
        sc.close();
            
        if(first == 9 || tenth == 9){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21716
#include <iostream>
#include <set>

int main(void){
    std::multiset<int> vs1, vs2;
    int Q;
    std::cin >> Q;
    int qi = 0;
    int med = -1;
    long sum_abs = 0;
    long bias = 0;
    for(int ii = 0; ii < Q; ++ii){
        int q;
        std::cin >> q;
        if(q == 1){
            int v, b;
            std::cin >> v >> b;
            qi++;
            bias += b;
            if(qi == 1){
                vs1.insert(v);
                med = v;
            } else if(qi == 2){
                int w = *vs1.begin();
                if(w <= v){
                    vs2.insert(v);
                } else {
                    vs1.clear();
                    vs1.insert(v);
                    vs2.insert(w);
                }
                med = *vs1.begin();
                sum_abs = *vs2.begin() - med;
            } else {
                auto vs1_size = vs1.size(), vs2_size = vs2.size();
                if(*vs1.rbegin() >= v){
                    vs1.insert(v);
                    if(vs1.size()-2 >= vs2.size()){
                        int w = *vs1.rbegin();
                        vs1.erase(--vs1.end());
                        vs2.insert(w);
                    }
                } else {
                    vs2.insert(v);
                    if(vs2.size() > vs1.size()){
                        int w = *vs2.begin();
                        vs2.erase(vs2.begin());
                        vs1.insert(w);
                    }
                }
                int new_med = *vs1.rbegin();
                sum_abs += std::abs(new_med - v);
                sum_abs += std::abs((static_cast<long>(new_med - med) * static_cast<long>(vs1_size - vs2_size)));
                med = new_med;
            } // end of insertion
        } else {
            std::cout << med << " " << sum_abs + bias << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9600
from functools import reduce
def gcd(a,b):
  if a<b:a,b=b,a
  if a%b==0:return b
  return gcd(b,a%b)
 
read=lambda :map(int,input().split())
n,k=read()
*a,=read()
 
m=max(a)
o=reduce(gcd,a)
print("POSSIBLE" if k<=m and k%o==0 else "IMPOSSIBLE")


Measured memory_bytes: 14596
import math
import cmath
def dot(a:complex,b:complex):
  return (a.conjugate()*b).real
def cross(a:complex,b:complex):
  return (a.conjugate()*b).imag
eps=10**(-11)
n=int(input())
for i in range(n):
  l=list(map(float,input().split()))
  p=[complex(l[2*j],l[2*j+1]) for j in range(4)]
  print('YES' if abs(cross(p[1]-p[0],p[3]-p[2]))<eps else 'NO')


Measured memory_bytes: 5748
def main():
    N, M = (int(i) for i in input().split())
    S = input()
    from itertools import groupby
    for k, v in groupby(S):
        if k == "1" and M <= len(list(v)):
            return print(-1)
    ans = []
    posi = 0
    S = S[::-1]
    while posi < N:
        pre = posi
        posi = min(posi+M, N)
        while S[posi] == "1":
            posi -= 1
        ans.append(posi - pre)
    print(*(ans[::-1]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 50288
n,m = gets.split.map(&:to_i)
b = Array.new(n+2,true)
m.times do
    a = gets.to_i
    b[a] = false
end
dp = Array.new(n+2,0)
mod = 10**9+7
dp[0] = 1
(1..n).each do |i|
    dp[i] = (dp[i-1]+dp[i-2])%mod if b[i]
end
# p dp
puts dp[n]

Measured memory_bytes: 3708
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
delta = [a[i] - b[i] for i in range(n)]
delta.sort()

count = 0
minus = 0
for i in range(n):
    if delta[i] < 0 :
        count += 1
        minus += delta[i]


if sum(a) < sum(b):
    print(-1)
    
else:
    for i in range(n):
        if minus >= 0:
            break
            
        count += 1
        minus += delta[n-i-1]

    
    print(count)    
  
  

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

int main(){
  bool cards[4][14];
  int n, number;
  char kind;
  cin >> n;

  for( int i=0; i<=3; i++){
    for( int j=0; j<=14; j++){
      cards[i][j] = false;
    }
  }

  for( int i=0; i<n ; i++){
    cin >> kind >> number;
    if( kind == 'S') cards[0][number] = true;
    else if( kind == 'H') cards[1][number] = true;
    else if( kind == 'C') cards[2][number] = true;
    else if( kind == 'D') cards[3][number] = true;  
  }
  for( int i=0; i<4 ; i++){
    for( int j=1; j<=13; j++){
      if( cards[i][j] == true) continue;

      else if( i==0 ) cout << 'S' << ' ' << j << endl;
      else if( i==1 ) cout << 'H' << ' ' << j << endl;
      else if( i==2 ) cout << 'C' << ' ' << j << endl;
      else if( i==3 ) cout << 'D' << ' ' << j << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3084
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		new Main().run();
	}

	void run() throws FileNotFoundException {
		solver();
	}

	@SuppressWarnings("unchecked")
	void solver() throws FileNotFoundException {
		Scanner sc = new Scanner(System.in);
		int na = sc.nextInt();
		int nb = sc.nextInt();
		int w = sc.nextInt();
		int[][] p = new int[na + nb][3];
		for (int i = 0; i < na; ++i) {
			p[i][0] = 0;
			p[i][1] = sc.nextInt();// m
			p[i][2] = sc.nextInt();// c
		}
		for (int i = na; i < na + nb; ++i) {
			p[i][0] = 1;
			p[i][1] = sc.nextInt();// m
			p[i][2] = sc.nextInt();// c
		}

		Arrays.sort(p, new Comparator<int[]>() {
			@Override
			public int compare(int[] o1, int[] o2) {
				return Integer.compare(o1[2], o2[2]);
			}
		});

		long[][] f = new long[2][w + 1];
		for (int i = 0; i < f.length; ++i) {
			for (int j = 0; j < f[i].length; ++j) {
				f[i][j] = -1;
			}
		}
		long ans = Long.MAX_VALUE / 16;
		int t = 0;
		for (int i = 0; i < na + nb; ++i) {
			if (p[i][1] > w)
				continue;
			for (int j = w - p[i][1]; j >= 1; --j) {
				f[p[i][0]][j + p[i][1]] = Math.max(f[p[i][0]][j + p[i][1]], f[p[i][0]][j]);
			}
			f[p[i][0]][p[i][1]] = p[i][2];
			ans = Math.min(ans, Math.max(g(f, p[t][2]), p[i][2] - p[t][2]));
			while (t + 1 <= i && g(f, p[t][2]) < p[i][2] - p[t][2]) {
				++t;
				ans = Math.min(ans, Math.max(g(f, p[t][2]), p[i][2] - p[t][2]));
			}
		}
		System.out.println(ans);
	}

	long g(long[][] f, long lower) {
		long ret = Long.MAX_VALUE / 16;
		long las = Long.MAX_VALUE / 16;
		for (int i = 1; i < f[0].length; ++i) {
			if (f[1][i] >= lower)
				las = i;
			if (f[0][i] < lower)
				continue;
			ret = Math.min(ret, Math.abs(i - las));
		}
		las = -Long.MAX_VALUE / 16;
		for (int i = 1; i < f[1].length; ++i) {
			if (f[0][i] >= lower)
				las = i;
			if (f[1][i] < lower)
				continue;
			ret = Math.min(ret, Math.abs(i - las));
		}
		return ret;
	}

	private static void tr(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
}

Measured memory_bytes: 35784
#include<stdio.h>
#include<math.h>
#define N 4
#define SUM 7
int main(){
    int num[N],keep,bit;
    scanf("%d",&keep);
    for(int i=0;i<N;i++){
        num[i] = keep/(int)pow(10,N-1-i);
        keep -= num[i]*(int)pow(10,N-1-i);
    }
    for(bit=0;bit<(1<<N-1);bit++){  //+は0-は1
        int ans = num[0];
        for(int i=1;i<=N-1;i++){
            if(bit & 1<<(N-1-i))
                ans -= num[i];
            else
                ans += num[i];
        }
        if(ans==SUM) break;
    }
    printf("%d",num[0]);
    for(int i=0;i<N-1;i++){
        if(bit & 1<<(N-2-i)) printf("-");
        else printf("+");
        printf("%d",num[i+1]);
    }
    printf("=%d",SUM);
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; 
int main()
{
	int n;int a[110];
	scanf("%d",&n);
	int mmax=-1;
	int mmin=105;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		mmin=min(mmin,a[i]);
		mmax=max(mmax,a[i]);
	}
	int ans=9000000000;
	int sum;
	for(int i=mmin;i<=mmax;i++)
	{
		sum=0;
		for(int j=0;j<n;j++)
		{
			sum+=(i-a[j])*(i-a[j]);
		}
		ans=min(ans,sum);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

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

    int ans = 0;
    string t = "";
    string now = "";

    rep(i, s.size()) {

        now += s[i];

        if(now != t) {
            t = now;
            now = "";
            ans++;
        }
    }

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

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    ll n;
    cin >> n;

    vector<ll> arr(n);

    for (ll &x : arr)
        cin >> x;

    map<ll, ll> look;
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
        ans += look[i - arr[i]];
        look[arr[i] + i]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 27392