akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
#include <string.h>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

ll X, Y, Z, K;
const int MAX_N = 1000;
const int MAX_K = 3000;
ll A[MAX_N], B[MAX_N], C[MAX_N];
ll D[MAX_N * MAX_N], E[MAX_N * MAX_K];

int main(){
  cin >> X >> Y >> Z >> K;
  REP(i, X) cin >> A[i];
  REP(i, Y) cin >> B[i];
  REP(i, Z) cin >> C[i];
  
  REP(i, X) REP(j, Y) D[i * Y+ j] = A[i] + B[j];
  
  sort(D, D + X * Y, greater<ll>());

  if(X * Y > 3000) {
    REP(i, 3000) REP(j, Z) E[i * Z + j] = D[i] + C[j];
    sort(E, E + 3000 * Z, greater<ll>());
  } else {
    REP(i, X * Y) REP(j, Z) E[i * Z + j] = D[i] + C[j];
    sort(E, E + X * Y * Z, greater<ll>());
  }

  REP(i, K) cout << E[i] << endl;

  return 0;
}


Measured memory_bytes: 31488
use std::io;

fn main() {
    let (a, b, c) = input();

    let mut ans = 0;
    for n in a..(b+1) {
        if c % n == 0 {
            ans += 1;
        }
    }

    println!("{}", ans);
}

fn input() -> (i32, i32, i32) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");

    let mut iter = s.trim().split_whitespace();

    let a: i32 = iter.next().unwrap().parse().unwrap();
    let b: i32 = iter.next().unwrap().parse().unwrap();
    let c: i32 = iter.next().unwrap().parse().unwrap();

    (a, b, c)
}



Measured memory_bytes: 5020
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] in = s.nextLine().split(" ");
        int a = Integer.parseInt(in[0]);
        int p = Integer.parseInt(in[1]);
        System.out.println((a*3+p)/2);
    }
}

Measured memory_bytes: 21460
N = int(input())
A = [int(input()) for _ in range(N)]

if N == 2:
    print("\n".join(map(str, A[::-1])))
else:
    a = sorted(A)
    maxv1 = a[-1]
    maxi1 = A.index(maxv1)
    maxv2 = a[-2]

    for i in range(N):
        if i == maxi1:
            print(maxv2)        
        else:
            print(maxv1)


Measured memory_bytes: 14152
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,m;
	cin >> n >> m;
	int u,v;
	vector<vector<int>> to(n);
	REP(i,m){
		cin >> u >> v;
		u--;
		v--;
		to[u].push_back(v);
	}
	int s,t;
	cin >> s >> t;
	s--;
	t--;
	int dist[n][3];
	REP(i,n) REP(j,3) dist[i][j] = INF;
	queue<P> que;
	que.push(P(s,0));
	dist[s][0] = 0;
	while(que.size()){
		P p = que.front();
		que.pop();
		for(int i : to[p.first]){
			if(dist[i][(p.second + 1) % 3] == INF){
				dist[i][(p.second + 1) % 3] = dist[p.first][p.second] + 1;
				que.push(P(i, (p.second + 1) % 3));
			}
		}
	}
	if(dist[t][0] == INF) cout << -1 << endl;
	else cout << dist[t][0] / 3 << endl;
}

Measured memory_bytes: 6912
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int d = scan.nextInt();
        int t = scan.nextInt();
        int s = scan.nextInt();
        if (t * s >= d) System.out.println("Yes");
        else System.out.println("No");
    }
}


Measured memory_bytes: 35600
#include <stdio.h>
#include <stdlib.h>
using namespace std;
#define k 10000
int n, C[k];

int main(){
	scanf("%d", &n);
	int *A = (int *)malloc(sizeof(int)*n);
	int *B = (int *)malloc(sizeof(int)*n);
	
	for(int i = 0;i < n;i++)scanf("%d", &A[i]);
	
	for(int i = 0;i < k;i++)C[i] = 0;
	for(int i = 0;i < n;i++)C[A[i]]++;
	for(int i = 1;i < k;i++)C[i] += C[i - 1];
	for(int i = n - 1;i >= 0;i--){
		B[C[A[i]] - 1] = A[i];
		C[A[i]]--;
	}
	
	for(int i = 0;i < n - 1;i++)printf("%d ", B[i]);
	printf("%d\n", B[n - 1]);
	return 0;
}

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

int main() {
  int t, r = 10;
  int ans = 0;
  while(cin >> t) {
    ans += (t / 10) * 10;
    if (t % 10 != 0) {
      ans += 10;
      r = min(r, t % 10);
    }
  }
  if (r < 10) ans -= (10-r);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>
 
int main(void){
	
	char x,y;
	
	scanf("%c %c",&x,&y);
	
	if(x<y){
	printf("<\n");
	} else if(x>y){
	printf(">\n");
	} else {
	printf("=\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
const int MOD = 1e9 + 7;
long long dfs(vector<long long> &dp, int N){
    if(dp[N] != -1) return dp[N];
    if(N < 3) return 0;
    long long res = 0;
    for(int i = 3; i <= N; i++){
        res = res + dfs(dp, N - i);
        res %= MOD;
    }
    return dp[N] = res;
}
int main(){
    int S;
    cin >> S;
    vector<long long> dp(S + 1, -1);
    dp[0] = 1;
    long long ans = dfs(dp, S);
    cout << ans << endl;
}

Measured memory_bytes: 3612
n = gets.to_i
a = []

n.times do |i|
  a[i] = gets.to_i
end

a_max = a.max

if(a.count(a_max) > 1)
  n.times do
    puts a_max
  end
else
  a_dup = a.dup
  a_dup.delete(a.max)
  a_max_sub = a_dup.max
  n.times do |i|
    if(a[i] == a_max)
      puts a_max_sub
    else
      puts a_max
    end
  end
end


Measured memory_bytes: 7292
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#define LL long long
using namespace std;
int n,a[1000001],max1=1e9,ans; 
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int m=a[n];
	for(int i=1;i<=n;i++)
	{
		if(abs(a[i]*2-m)<max1) max1=abs(a[i]*2-m),ans=a[i];
	}
	printf("%d %d",a[n],ans);
	return 0;
} 

Measured memory_bytes: 640
n = int(input())
s = []

for i in range(n):
    s.append(input())

a = 0
b = 0
ab = 0
ba = 0
for i in range(n):
    if (s[i][-1].count("A") and s[i][0].count("B")):
        ba += 1
    else:
        a += s[i][-1].count("A")
        b += s[i][0].count("B")
    ab += s[i].count("AB")

if ba != 0:
    ab += ba - 1
    if a > b:
        b += 1
    elif b > a:
        a += 1
    elif a == b and a >= 1:
        a += 1
        b += 1

print(ab + min(a,b))

Measured memory_bytes: 3700
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
const int maxn=1e9;
int x[110],y[110],h[110],n;

void solve(){
    int cx,cy,hh;
    for(cx=0;cx<=100;cx++){
        for(cy=0;cy<=100;cy++){
            hh=0;
            rep(i,0,n){if(h[i]){hh=h[i]+abs(cx-x[i])+abs(cy-y[i]);break;}}
            bool ok=1;
            rep(i,0,n){if(max(hh-abs(cx-x[i])-abs(cy-y[i]),0)!=h[i]){ok=0;break;}}
            if(ok){printf("%d %d %d\n",cx,cy,hh);return;}
        }
    }
}

int main()
{
    cin>>n;
    rep(i,0,n) scanf("%d%d%d",&x[i],&y[i],&h[i]);
    solve();
    return 0;
}


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

const int divisor = 1000000007;

int main(){
	// 100000!までの数をdivisorで割った余りを格納しておく
	long long* factmodary = new long long[100001];
	long long fact = 1;
	for (int i = 1; i <= 100000; i++){
		fact *= i;
		fact %= divisor;
		factmodary[i] = fact;
	}

	int* word = new int[100000] {0};

	for (;;){
		int N, R;
		cin >> N;
		if (N == 0) break;
		cin >> R;
		
		//まず0番目の単語を入れておく
		for (int i = 0; i < N; i++) word[i] = i + 1;

		for (int i = 0; i < R; i++){
			int s, t;
			cin >> s >> t;
			/* swap */
			int tmp = word[s - 1]; word[s - 1] = word[t - 1]; word[t - 1] = tmp;
		}

		//word[i]をkey, word[i]より小さい数がそれ以前にいくつ使われていたかをvalueとして格納するmap
		map<int, int> bubblehist;
		bubblehist[word[0]] = 0;

		long long ans = factmodary[N-1] * (word[0] - 1);

		for (int i = 1; i < N; i++){
			int facttime = word[i] - 1;
			int bubblenum;
			map<int, int>::iterator it = bubblehist.lower_bound(word[i]);

			if (it != bubblehist.end()){
				bubblenum = it->second;
				it--;
			}
			else {
				it--;
				bubblenum = it->second + 1;
			}
			pair<int, int> p;
			p.first = word[i];
			p.second = bubblenum;
			map<int, int>::iterator it2 = bubblehist.insert(it, p);
			//word[i]より大きい数はすべてvalueが1増える
			for (++it2; it2 != bubblehist.end(); it2++) (it2->second)++;

			facttime -= bubblenum;
			ans += factmodary[N - (i + 1)] * facttime;
			ans %= divisor;
		}
		cout << (int)ans << endl;
	}

	delete[] word;
	delete[] factmodary;
	return 0;
}

Measured memory_bytes: 6816
#include <cstdio>

long long S;
long long dfs(long long x, long long ex)
{
	long long t = x % 10, ans = x + ex, p = 10; x /= 10;
	for (; x; t += (x % 10) * p, x /= 10, p *= 10)
		ans += dfs(x, ex + t);
	return ans;
}

int main()
{
	scanf("%lld", &S), printf("%lld\n", dfs(S, 0));
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  int n,m;
  cin >> n >> m;
  vector<string> a(n),b(m);
  
  rep(i,n) cin >> a[i];
  rep(i,m) cin >> b[i];
  
  bool ans = false;
  for(int i = 0;i <= n-m;i++){
    for(int j = 0;j <= n-m;j++){
      for(int k = 0; k < m;k++){
        if(a[i+k].substr(j,m) != b[k]) break;
        if(k == m-1) ans = true;
      }
    }
  }
  
  if(ans){
    cout << "Yes";
  }else{
    cout << "No";
  }
  return 0;
}

Measured memory_bytes: 256
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main()
{
    ll i,j,n;
    cin>>i>>j>>n;
    if(i%j==0){
        cout<<(i/j)*n;
    }
    else{
        cout<<((i/j)+1)*n;
    }
    
    //cout<<"YES"<<endl;
    //cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll  = long long;
using vl  = vector<ll>;
using vvl = vector<vl>;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define per(i,n) for(int i = (n)-1; i >= 0; --i)
#define rng(i,a,b) for(int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

const int MOD = 1e9+7;

int main() {
    ll N, B = 60;
    cin >> N;
    vl A(N), cnts(B);
    rep(i,N) {
        cin >> A[i];
        rep(j,B) cnts[j] += (A[i]>>j) & 1;
    }
    ll ans = 0;
    rep(j,B) (ans += (cnts[j]*(N-cnts[j]))%MOD * ((ll)pow(2,j)%MOD)) %= MOD;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
int main(){

    string input;

    cin >> input;

    string pd = input;
    string capital,preCapital,ans;

    for(int i = 0; i < (int)pd.size(); ++i){
        if(pd[i] == '?'){
          ans += 'D';
        }else{
          ans += pd[i];
        }
    }
    
    printf("%s\n",ans.c_str());


	return 0;
}

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

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

const int INF = 1e+9;
typedef pair<int, int> P;
typedef pair<int, P> pp;
const int MAX_N = 105000;

int d[] = {0, 1, -1};

int N, M;
int t[16][16][16];

// ???: 0, ???: 1
bool check(int x, int y, int z, int c){
	REP(i, 3)REP(j, 3)REP(k, 3){
		if(i + j + k == 0)
			continue;
		int dx = d[i], dy = d[j], dz = d[k];
		int cnt = 0;
		int nx = x, ny = y, nz = z;
		while(nx >= 0 && nx < N && ny >= 0 && ny < N && nz >= 0 && nz < N && t[nx][ny][nz] == c){
			nx -= dx;
			ny -= dy;
			nz -= dz;
		}
		nx += dx;
		ny += dy;
		nz += dz;
		while(nx >= 0 && nx < N && ny >= 0 && ny < N && nz >= 0 && nz < N && t[nx][ny][nz] == c){
			cnt++;
			nx += dx;
			ny += dy;
			nz += dz;
		}
		if(cnt >= M)
			return true;
	}
	return false;
}

int main() {
	int p, x, y;
	while(cin >> N >> M >> p && (N || M || p)){
		memset(t, -1, sizeof(t));
		int cnt[16][16] = {0};
		bool ok = false;
		for(int i = 0; i < p; ++i){
			cin >> x >> y;
			x--; y--;
			t[x][y][cnt[x][y]] = i % 2;
			cnt[x][y]++;
			if(!ok && check(x, y, cnt[x][y] - 1, i % 2)){
				cout << ((i % 2 == 0) ? "Black " : "White ") << i + 1 << endl;
				ok = true;
			}
		}
		if(!ok)
			cout << "Draw" << endl;
	}
	return 0;
}

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

int main()
{
  int n,*a,count=0;
  int i,j,t,k;

  
  scanf("%d",&n);

  a = (int *)malloc(n * sizeof(int));

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

  for(i=0;i<n;i++)
    {
      for(j=0;j<n;j++)
	{
	  if(a[j] < a[j-1])
	    {
	      t = a[j-1];
	      k = a[j];
	      a[j] = t;
	      a[j-1] = k;
	      count++;
	    }
	 
	 
	}
      
    }
   for(j=0;j<n;j++)
     {
       if (j != 0) printf(" ");
       printf("%d",a[j]);
     }
     printf("\n");
 
  printf("%d\n",count);
  
  return 0;
}



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

int dfs(int v, vector<vector<int>> const& es, vector<bool>& visited) {
    int res = 1;
    visited[v] = true;
    for(int i=0; i<es[v].size(); ++i) {
        if(!visited[es[v][i]]) {
            res += dfs(es[v][i], es, visited);
        }
    }
    return res;
}

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> first(26), last(26);
        vector<vector<int>> edge(26);
        vector<bool> visited(26);
        set<char> appear;
        for(int i=0; i<n; ++i) {
            string s;
            cin >> s;
            first[s[0] - 'a']++;
            last[s.back() - 'a']++;
            edge[s[0]-'a'].push_back(s.back() - 'a');
            appear.insert(s[0]-'a');
            appear.insert(s.back()-'a');
        }
        bool ok = dfs(*appear.begin(), edge, visited) == appear.size();
        for(int i=0; i<26; ++i) {
            ok &= first[i] == last[i];
        }
        if(ok) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }
}


Measured memory_bytes: 3068
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,z;
    char ca,cb,cc;
    cin>>n;
    vector<ll> v(n);
    rep(i,n)cin>>v[i];
    rep(i,n){
        if(v[i]%2==0){
            if(v[i]%3==0||v[i]%5==0) a=0;
            else f=1;
        }
    }
    if(f) cout<<"DENIED";
    else cout<<"APPROVED";
    return 0;
}


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

#define ios ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define eb emplace_back
#define endl '\n'

typedef long long int ll ;

void dfs(int node , int vis[], vector<vector<int>> &ab , int mark) {
     vis[node] = mark;
 	 for (auto i: ab[node]) {
     	 if (vis[i] > mark ) {
         	 dfs(i , vis , ab , mark);
     }
  }
}

void solve() {
	 int n , m ;
	 cin >> n >> m ;
	 vector<vector<int>> ab(n + 1) ;
	 int a , b ;
	 for ( int i = 0 ; i < m ; i++ ) {
	 	 cin >> a >> b ;
	 	 ab[a].eb(b) ;
	 	 ab[b].eb(a) ;
	 }
	 int vis[n + 1] ;
	 memset(vis , 1e6 + 1 , sizeof(vis)) ;
	 vis[0] = 0 ;
	 int mark = 1 ;
	 dfs(1 , vis , ab , mark) ;;
	 for (int i = 1 ; i <= n ; i++) {
	 	 if (vis[i] > mark) { mark++ ; dfs(i , vis , ab , mark) ; }
	 }
	 cout << --mark << endl ;
}

int main() {
	 ios ;

	 int T = 1 ;
	 //cin >> T ;
	 for (int i = 1 ; i <= T ; i++)
	 {	solve();	}
}


Measured memory_bytes: 10004
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <limits>


using namespace std;


int main() {
	int n = 0, max = 0, e = 0, value = 0;
	cin >> n;
	int tab[n];
	for(int i = 0; i < n; i++) {
		cin >> tab[i];
		if(max < tab[i]) {
			max = tab[i];
			e = i;
		}
		else if(max == tab[i]) {
			max = 0;
		}
	}
	if(max != 0) {
		value = tab[e] / 2;
		tab[e] = value;
	}
	else if(max == 0) {
		value = tab[0] / 2;
		tab[0] = value;
	}
	int sum = 0;
	for(int j = 0; j < n; j++) {
		sum+=tab[j];
	}
	cout << sum << endl;

	return 0;
}

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

int sumWithoutI(int* arr, int n, int x) {
	int sum = 0;
	for(int i = 0; i < n; i++) {
		if(i != x) {
			sum += arr[i];
		}
	}
	return sum;
}
void printArr(int* arr, int n) {
	for(int i = 0; i < n; i++){ 
		cout << arr[i] << " ";
	}
	cout << endl;
}

int main() {
	int n, l;
	cin >> n >> l;
	int* flavors = new int[n];

	for(int i = 0; i < n; i++) {
		flavors[i] = l + i;

	}
	int lowestI;
	int lowestAbs = 9999;
	for(int i = 0; i < n; i++) {
		if(abs(flavors[i]) < lowestAbs) {
			lowestAbs = abs(flavors[i]);
			lowestI = i;
		}
	}
	cout << sumWithoutI(flavors, n, lowestI) << endl;
}	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string Change(int);
int main(){
  int h,m,s,ans,ans2,h1,m1,s1,h2,m2,s2;
  string str1,str2;
  while(1){
    cin >> h >> m >> s;
    if(h==-1&&m==-1&&s==-1) break;
    ans=7200-(h*3600+m*60+s);
    ans2=ans*3;
    h1=ans/3600;
    ans%=3600;
    m1=ans/60;
    ans%=60;
    s1=ans;
    str1=Change(h1)+':'+Change(m1)+':'+Change(s1);
    h2=ans2/3600;
    ans2%=3600;
    m2=ans2/60;
    ans2%=60;
    s2=ans2;
    str2=Change(h2)+':'+Change(m2)+':'+Change(s2);
    cout << str1 << endl;
    cout << str2 << endl;
  }
  return 0;
}
string Change(int x){
  int flag=0;
  string ret;
  if(x/10==0) flag=1;
  if(x==0) flag=2;
  while(x){
    ret+=(x%10+'0');
    x/=10;
  }
  reverse(ret.begin(),ret.end());
  if(flag==1) ret='0'+ret;
  if(flag==2) ret="00";
  return ret;
}

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

using namespace std;
const int N = 1e5 + 5;
long long dp[3][N], ans;

int main()
{
	int n;
	cin >> n;
	int A[n], B[n], C[n];
	for (int i = 0; i < n; i++)
		cin >> A[i] >> B[i] >> C[i];
	dp[0][0] = A[0];
	dp[1][0] = B[0];
	dp[2][0] = C[0];
	for (int i = 1; i < n; i++)
	{
		dp[0][i] = A[i] + max(dp[1][i - 1], dp[2][i - 1]);
		dp[1][i] = B[i] + max(dp[0][i - 1], dp[2][i - 1]);
		dp[2][i] = C[i] + max(dp[0][i - 1], dp[1][i - 1]);
	}
	ans = max(dp[0][n - 1], dp[1][n - 1]);
	ans = max(ans, dp[2][n - 1]);
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3712
n = int(input())

right = n
left = 0

print(0)
first = input()
state = first

cnt = 0
while True:
    cnt += 1
    if state == "Vacant":
        __import__("sys").exit()

    target = left + (right - left) // 2
    target = max(target, 1)

    print(target)
    state = input()

    if (target & 1 and state != first) or (not target & 1 and state == first):
        left = target
    else:
        right = target

    if left == right:break


Measured memory_bytes: 3660
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var ans=0;
  var l = String(N).length;
  num=["3","5","7"];
  X=[3,5,7];
  var n=0;
  for(i=0;i<l-1;i++){
    var Xl=X.length;
    for(j=0;j<3;j++){
      for(k=n;k<Xl;k++){
        X.push(parseInt(num[j]+X[k]));
      }
    }
    n=Xl;
  }
  for(i=0;i<X.length;i++){
    if(X[i]>N) break;
    Xsub=String(X[i]).split("");
    if(Xsub.indexOf("3")!=-1&&Xsub.indexOf("5")!=-1&&Xsub.indexOf("7")!=-1){
      ans++;
    }
  }



  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

map<int, int> res;

void prime_factor(int n){
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) res[n]++;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 2; i <= n; i++){
        prime_factor(i);
    }
    vector<int> cnt(1010);
    for(auto i : res) cnt[i.second + 1]++;
    for(int i = 999; i >= 0; i--) cnt[i] += cnt[i + 1];
    // for(int ii = 0; ii < 25; ii++){
    //     if(ii) cout << ' ';
    //     cout << cnt[ii];
    // }
    // cout << endl;
    int ans = 0;
    ans += cnt[5] * (cnt[5] - 1) / 2 * (cnt[3] - 2);
    ans += cnt[25] * (cnt[3] - 1);
    ans += cnt[15] * (cnt[5] - 1); 
    ans += cnt[75];
    cout << ans << endl;
}
// 5 5 3
// 25 3
// 15 5

Measured memory_bytes: 256
import bisect

def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))
    a.append(0)
    ans = solve(a, n)
    print(ans)

def solve(a, n):
    if not check(a, n):
        return -1

    base = 0
    s = 0
    for i in range(n):
        if a[i] > base + i:
            return -1
        
        if a[i + 1] <= a[i]:
            s += a[i]
        
        base = i - a[i]
    
    return s

def check(a, n):
    if a[0] != 0:
        return False
    
    for i in range(1, n):
        if a[i] - a[i - 1] > 1:
            return False

    return True

main()

Measured memory_bytes: 11056
s = str(input())
k = int(input())
s = list(s)

n = len(s)

import copy
l = copy.copy(s)
l = set(l)
l = list(l)
l.sort()
#print(l)

ans = set()
for i in range(len(l)):
    for j in range(n):
        if s[j] == l[i]:
            p = j
            temp = []
            while p < n and p-j+1 <= k:
                temp.append(s[p])
                ans.add(''.join(temp))
                p += 1
    if len(ans) >= k:
        break
#print(ans)
ans = list(ans)
ans.sort()
print(ans[k-1])


Measured memory_bytes: 39408
n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

v = [0] * 41
for x in a:
  for i in range(41):
    v[i] += x & 1
    x >>= 1

max_acc = 0
max_bit = 0
for i in range(41):
  if (k >> i) & 1:
    max_acc = max( (1 << i)*(n-v[i]) + max_acc,
                   (1 << i)*   v[i]  + max_bit )
  else:
    max_acc += (1 << i)*v[i]
  max_bit += (1 << i)*max(v[i], n-v[i])

print(max_acc)


Measured memory_bytes: 14620
#include<iostream>
#include<cstdio>
using namespace std;
const int N=1005;
int h,w,A,B;
int a[N][N];
int main()
{
	scanf("%d%d%d%d",&h,&w,&A,&B);
	for(int i=1;i<=B;i++)
		for(int j=1;j<=A;j++)
			a[i][j]=1;
	for(int i=B+1;i<=h;i++)
		for(int j=A+1;j<=w;j++)
			a[i][j]=1;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
			printf("%d",a[i][j]);
		printf("\n");
	}
	return 0;
}

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

char t[22][22];
char tt[22][22];
int d[22][22];
int w, h;

void init_d(){
    rep(i, 22){
        rep(j, 22){
            d[i][j] = -1;
        }
    }
}

void copy_t(){
    rep(i, h){
        rep(j, w){
            tt[i][j] = t[i][j];
        }
    }
}

int main(){
    
    cin >> h >> w;
    
    rep(i, h){
        rep(j, w){
            cin >> t[i][j];
        }
    }
    int ans = 0;
    int ansans;
    int dx[4] = {1, -1, 0, 0};
    int dy[4] = {0, 0, -1, 1};
    rep(sy, h){
        rep(sx, w){
            init_d();
            copy_t();
            if(tt[sy][sx] == '#'){
                continue;
            }  
            queue<P> q;
            d[sy][sx] = 0;
            q.push(P(sy, sx));
            while(q.size()){
                P p = q.front(); q.pop();
                int nx = p.second;
                int ny = p.first;
                tt[ny][nx] = '#';
                rep(i, 4){
                    int tx = dx[i] + nx;
                    int ty = dy[i] + ny;
                    if(ty >= 0 && ty < h && tx >= 0 && tx < w && tt[ty][tx] == '.' && d[ty][tx] == -1){
                        q.push(P(ty, tx));
                        d[ty][tx] = d[ny][nx] + 1;
                    }
                }
            }
            ansans = 0;
            rep(i, h){
                rep(j, w){
                    ansans = max(ansans, d[i][j]);
                }
            }
            ans = max(ans, ansans);
        }
    }
    cout << ans << endl;
}

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

int main(){
    int N; cin >> N;
    vector<long long> A(N); vector<long long> B(N); vector<long long> C(N);
    for (auto &a : A) { cin >> a; } for (auto &b : B) { cin >> b; } for (auto &c : C) { cin >> c; }
    sort(A.begin(), A.end()); sort(B.begin(), B.end()); sort(C.begin(), C.end());
    
    long long ans = 0;
    vector<long long> cnt(N, 0);
    for (int i = 0; i < N; i++) {
        int j = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
        cnt[i] = j;
    }
    
    vector<long long> sum(N + 1, 0);
    for (int i = 0; i < N; i++) sum[i + 1] = sum[i] + cnt[i];
    
    for (int i = 0; i < N; i++) {
        int j = lower_bound(B.begin(), B.end(), C[i]) - B.begin();
        ans += sum[j];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

ll n, P = 1000000007;
bitset<64> N;
vvv dp = vvvl(64, 2, 2, -1);
ll calc(ll b, bool f, bool g){
  if(b==-1) return 1;
  if(dp[b][f][g]!=-1) return dp[b][f][g];
  if(g) return dp[b][f][g] = (3*calc(b-1, f, g))%P;
  if(f){
    if(N[b]){
      ll zero_zero = calc(b-1, f, 1);
      ll one_zero = calc(b-1, f, 1);
      ll one_one = calc(b-1, f, 0);
      return dp[b][f][g] = (zero_zero+one_one+one_zero)%P;
    }else{
      ll zero_zero = calc(b-1, f, 1);
      ll one_zero = calc(b-1, f, 0);
      ll one_one = calc(b-1, 0, 0);
      return dp[b][f][g] = (zero_zero+one_one+one_zero)%P;
    }
  }
  if(N[b]) return dp[b][0][0]=(calc(b-1,0,0)+calc(b-1,1,0))%P;
  return dp[b][0][0] = calc(b-1, 0, 0);
}
int main(int argc, char const *argv[]) {
  std::cin >> n;
  N = bitset<64> (n);
  //std::cout << N << '\n';
  cout << calc(63, 0, 0) << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double a,b,c,d;
int main()
{
    cin>>a>>b>>c>>d;
    int ans1=ceil(c/b);
    int ans2=ceil(a/d);
    if(ans2>=ans1) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define vec vector
#define rep(i,n) for (int i=0; i<(n); i++)
#define reps(i,s,n) for (int i=(s); i<(n); i++)
#define rep1(i,n) for (int i=1; i<=(n); i++)
#define repr(i,s,n) for (int i=(s)-1; i>=(n); i--)
#define print(a) cout << a << endl
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()


const ll mod = 1e9+7;
struct mint {
  ll x;
  mint(ll x=0) : x((x%mod+mod)%mod) {}
  mint &operator+=(const mint &p) { if((x += p.x) >= mod) x -= mod; return *this; }
  mint &operator-=(const mint &p) { if((x += mod - p.x) >= mod) x -= mod; return *this; }
  mint &operator*=(const mint &p) { x = x * p.x % mod; return *this; }
  mint &operator/=(const mint &p) { *this *= p.inverse(); return *this; }
  mint operator-() const { return mint(-x); }
  mint operator+(const mint &p) const { return mint(*this) += p; }
  mint operator-(const mint &p) const { return mint(*this) -= p; }
  mint operator*(const mint &p) const { return mint(*this) *= p; }
  mint operator/(const mint &p) const { return mint(*this) /= p; }
  bool operator==(const mint &p) const { return x == p.x; }
  bool operator!=(const mint &p) const { return x != p.x; }
  mint inverse() const {
    ll a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return mint(u);
  }
  mint pow(ll n) const {
    mint ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  friend ostream &operator<<(ostream &os, const mint &p) { return os << p.x; }
  friend istream &operator>>(istream &is, mint &a) {
    ll t;
    is >> t;
    a = mint(t);
    return (is);
  }
};
string alpha = "ABC";

int main() {
  string S;
  cin >> S;
  int N = S.size();
  vec<vec<mint>> dp(4,vec<mint>(N+1,0));
  dp[3][N] = 1;
  repr(i,N,0) {
    if (S[i] == '?')
      dp[3][i] = dp[3][i+1]*3;
    else
      dp[3][i] = dp[3][i+1];
  }
  repr(j,3,0) {
    repr(i,N,0) {
      if (S[i] == alpha[j]) {
        dp[j][i] = dp[j][i+1] + dp[j+1][i+1];
      } else if (S[i] == '?') {
        dp[j][i] = dp[j][i+1]*3 + dp[j+1][i+1];
      } else {
        dp[j][i] = dp[j][i+1];
      }
    }
  }
  print(dp[0][0]);
  return 0;
}

Measured memory_bytes: 7460
S = input()
dic = {}
ok = 0
for i in S:
    if not i in dic:
        dic[i] = 1
    else:
        dic[i]+= 1

if len(dic)==2:
    for i in dic:
        if dic[i]!=2:
            ok = 0
            break
        else:
            ok = 1
if ok:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String a = in.nextLine();
        long[] count = new long[28];
        for (char ch : a.toCharArray()) {
            count[ch - 'a']++;
        }
        long ans = 1;
        for (long i = 1; i < a.length(); i++) {
            ans += i;
        }
        for (long val : count) {
            if (val > 1) {
                long d = 0;
                for (long i = 1; i < val; i++) {
                    d += i;
                }
                ans -= d;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26572
import heapq
import math
n = int(input())

element = int(math.sqrt(n))
nk = n
i = 2
p = []
while nk>1 and i <= element:
    if nk % i == 0:
        p.append(i)
        while nk % i == 0:
            nk //= i
    i += 1
if nk > 1:
    p.append(nk)
ans = 0
option = [[k, k] for k in p]
heapq.heapify(option)
while n>1 and option:
    val, p = heapq.heappop(option)
    #print(n, ans, val, option)
    if val*p <= n:
        heapq.heappush(option, [val*p, p])
    if n % val == 0:
        ans += 1
        n //= val
print(ans)

Measured memory_bytes: 9224
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    int c = Integer.parseInt(str[2]);
    int max = Math.max(a,Math.max(b,c));
    System.out.println((a+b+c-max)==max?"Yes":"No");
  }
}

Measured memory_bytes: 32756
#include<stdio.h>
int main()
{
	int w,h,n,x,y,a,x0=0,y0=0;

	scanf("%d%d%d",&w,&h,&n);
	while(n--){
		scanf("%d%d%d",&x,&y,&a);
		if(a==1&&x0<x)
			x0=x;
		else if(a==2&&w>x)
			w=x;
		else if(a==3&&y0<y)
			y0=y;
		else if(a==4&&h>y)
			h=y;
		if(w<x0||h<y0){
			puts("0");
			return 0;
		}
	}
	printf("%d",(w-x0)*(h-y0));
	return 0;
}

Measured memory_bytes: 128
s=list(input())
j=len(s)-2
for i in range(j):
    if s[i]==s[i+1]:
        print("{} {}".format(i+1,i+2))
        break
    elif s[i]==s[i+2]:
        print("{} {}".format(i+1,i+3))
        break
else:
    if s[j]==s[j+1]:
        print("{} {}".format(j+1,j+2))
    else:
        print("-1 -1")

Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int minutes = 60*(h2-h1)+m2-m1;
    if(minutes>k){
        cout << minutes-k << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3624
Q = int(input())
for i in range(Q):
    a,b = (map(int, input().split()))
    if(a == b):
        print(2*a -2)
    elif(abs(a-b) == 1):
        print(2 * min(a,b) -2)
    else:
        c = int((a*b) ** 0.5)
        if c == (a*b) ** 0.5:
            c -= 1
        if(c*(c+1) >= a*b):
            print(2*c-2)
        else:
            print(2*c-1)

Measured memory_bytes: 3188
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct node{int p,l,r;};
struct node t[MAX];
int n;

void preparse(int u){
  if(u==NIL) return;
  printf(" %d",u);
  preparse(t[u].l);
  preparse(t[u].r);
}

void inparse(int u){
  if(u==NIL) return;
  inparse(t[u].l);
  printf(" %d",u);
  inparse(t[u].r);
}

void postparse(int u){
  if(u==NIL) return;
  postparse(t[u].l);
  postparse(t[u].r);
  printf(" %d",u);
}

int main(){
  int i,v,l,r,root;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    t[i].p=NIL;
  }

  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    t[v].l=l;
    t[v].r=r;
    if(l!=NIL) t[l].p=v;
    if(r!=NIL) t[r].p=v;
  }

  for(i=0;i<n;i++) if(t[i].p==NIL) root=i;

  printf("Preorder\n");

  preparse(root);
  printf("\n");
  printf("Inorder\n");
  inparse(root);
  printf("\n");
  printf("Postorder\n");
  postparse(root);
  printf("\n");
  return 0;
}



Measured memory_bytes: 2048
import java.util.*;
import java.lang.*;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long mod = 1000000007;
		long power = 1;
		for (int i = 1; i <= n; i++) {
			power = power * i % mod;
		}
		System.out.println(power);
	}
}

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

int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    if(a == 0){
        cout << 0 << endl;
        return 0;
    }
    if(b == 0){
        cout << n << endl;
        return 0;
    }
    ans += n/(a+b)*a;
    n %= a+b;
    ans += min(n, a);
    cout << ans << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

vector<int> fri[100005];
vector<int> blo[100005];
int grp[100005];
bool used[100005];
int grpnum[100005];

void dfs(int v, int id)
{
    if (used[v]) return;
    else {
        grp[v] = id;
        used[v] = true;
        for(int e:fri[v]) {
            dfs(e, id);
        }
    }
    return;
    
}

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        fri[a].push_back(b);
        fri[b].push_back(a);
    }
    rep(i, n) {
        dfs(i, i);
    }
    rep(i, n) {
        int v = grp[i];
        grpnum[v]++;
    }
    
    rep(i, k) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        if (grp[a]==grp[b]) {
            blo[a].push_back(b);
            blo[b].push_back(a);
        }
    }
    
    rep(i, n) {
        int v = grp[i];
        int ans = grpnum[v]-1;
        //cout << "aaa " << grpnum[v] << endl;
        ans -= fri[i].size();
        ans -= blo[i].size();
        cout << ans << " ";
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 12408
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int n;
    cin >> n;
    switch (n % 10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon" << endl;
        break;
    case 0:
    case 1:
    case 6:
    case 8:
    cout << "pon" << endl;
        break;
    case 3:
    cout << "bon" << endl;
        break;
    default:
        break;
    }
    return 0;
}

Measured memory_bytes: 3600
import java.util.Scanner;
import java.util.HashSet;
import java.util.*;

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

        HashSet<Integer> hs = new HashSet<Integer>();
        int n = sc.nextInt();
        for(int i=0;i<n;i++){
            Integer a = new Integer(sc.nextInt());
            if(hs.contains(a)){
                hs.remove(a);
            }else{
                hs.add(a);
            }
        }

        System.out.println(hs.size());
    }
}

Measured memory_bytes: 63604
import sys
#import numpy as np

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    A, B = i2nn()
    n = B
    if 6 <= A and A <= 12:
        n = B / 2
    elif A <= 5:
        n = 0
    n = int(n)
    print(n)

main()


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

int a[200000];
P h[200000];
vector<int>E[200000];
bool used[200000];

void dfs(int v){
	for(auto u:E[v]){
		h[u].first=h[v].first+1;
		dfs(u);
	}
}
void dfs2(int v){
	used[v]=true;
	for(auto u:E[v]){
		if(used[u])continue;
		dfs2(u);
	}
}
int main(){
	int n,k;scanf("%d%d",&n,&k);
	int ans=0;
	rep(i,n){
		scanf("%d",&a[i]);a[i]--;
		if(i==0){
			if(a[i]!=i)ans++;
			a[i]=0;
		}
		else E[a[i]].push_back(i);
		h[i].second=i;
	}
	dfs(0);
	sort(h,h+n,greater<>());
	rep(i,n){
		if(used[h[i].second])continue;
		int v=h[i].second;
		rep(j,k-1){
			v=a[v];
			if(a[v]==0)break;
		}
		if(a[v]==0)break;
		ans++;dfs2(v);
	}
	cout<<ans<<endl;
}

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

using namespace std;
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;


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

    rep(i, n) rep(j , n) {

        int dollar = i * 4 + j * 7;
        if(dollar == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int main() {
    int N, M; cin >> N >> M;
    vector<int> H(N); for (auto &h : H) cin >> h;
    vector<bool> good(N, true);
    for (int i = 0; i < M; i++) {
        int a, b; cin >> a >> b; a--, b--;
        if (H[a] <= H[b]) good[a] = false;
        if (H[b] <= H[a]) good[b] = false;
    }
    cout << accumulate(begin(good), end(good), 0) << endl;
    return 0;
}

Measured memory_bytes: 3728
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    n,a,b,c,d = LI()
    t = n - 1
    s = abs(a-b)
    if s > d * t:
        return 'NO'
    if s >= c * t:
        return 'YES'

    for i in range(1,t):
        k = c * (t-i) - d * i
        if k <= s:
            if (d-c) * t >= s-k:
                return 'YES'
            break
    return 'NO'


print(main())





Measured memory_bytes: 7840
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;

void solve() {
    int n, m;
    lint k;
    std::cin >> n >> m >> k;

    std::vector<lint> asum(n + 1, 0), bsum(m + 1, 0);
    for (int i = 0; i < n; ++i) {
        int a;
        std::cin >> a;
        asum[i + 1] = asum[i] + a;
    }
    for (int i = 0; i < m; ++i) {
        int b;
        std::cin >> b;
        bsum[i + 1] = bsum[i] + b;
    }

    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        lint rem = k - asum[i];
        if (rem < 0) break;
        int j = std::upper_bound(bsum.begin(), bsum.end(), rem) -
                bsum.begin() - 1;
        ans = std::max(ans, i + j);
    }

    std::cout << ans << "\n";
}

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

    solve();

    return 0;
}


Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t;
  
  int ans=0;
  if(s.at(0) == t.at(0)){
    ans++;
  }
  if(s.at(1) == t.at(1)){
    ans++;
  }
  if(s.at(2) == t.at(2)){
    ans++;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
A, B, AB, X, Y = map(int, input().split())

if X > Y:
	print(min(A*X+B*Y, A*(X-Y)+AB*2*Y, AB*2*X))
else:
	print(min(A*X+B*Y, AB*2*X+B*(Y-X), AB*2*Y))

Measured memory_bytes: 3060
use std::io::*;
use std::str::*;
use std::collections::*;

fn main() {
    let A : isize = read();
    let B : isize = read();
    let C : isize = read();
    println!("{}", std::cmp::max(0,C-(A-B)));
}

fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= n; i--)
#define ll long long
#define pb push_back
#define popb pop_back
#define debug(i) cout << i << endl
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a,b;

    REP(i,n){
        int t;
        cin >> t;
        a.pb(t);
        b.pb(t);
    }

    sort(b.begin(),b.end(),greater<int>());

    REP(i,n){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
    return 0;
}


Measured memory_bytes: 3436
#include<iostream>

using namespace std;

int main() {
	int n,a[11];

	cin >> n;

	int f = n;

	int w = 1000000000;
	int p = 0;
	for (int i = 0; i < 10; i++) {
		a[i] = 0;
		if (n / w >= 1) {
			a[i] = n / w;
		}
		n -= a[i] * w;
		w /= 10;
		p += a[i];
	}

	if (f % p == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
long lucas(int n);
int main(void){
    int n;
    scanf("%d",&n);
    
    long ans = lucas(n);
    printf("%ld\n",ans);
    return 0;
}

long lucas(int n){
    long l[100];
    l[0] = 2;
    l[1] = 1;
    int i = 2;
    while(i<=n)
    {
        l[i] = l[i-1]+l[i-2];
        i++;
    }
    return l[i-1];
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>


using namespace std;


int main(){
    int N;
    cin >> N;
    map<string, int> kinds;
    for(int i=0; i<N; i++){
        string key;
        cin >> key;
        kinds[key] = 1;
    }
    cout << kinds.size() << endl;
}

Measured memory_bytes: 19204
#include <iostream>
#include <vector>
#include <map>

using namespace std;


struct UnionFind
{
	vector<int> par;
	vector<int> height;

	UnionFind(int n)
	{
		for (int i = 0; i < n; i++)
		{
			par.push_back(i);
			height.push_back(0);
		}
	}

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

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
			return;

		if (height[x] < height[y])
			par[x] = y;
		else
		{
			par[y] = x;
			if (height[x] == height[y])
				height[x]++;
		}
	}

	bool same(int x, int y)
	{
		return find(x) == find(y);
	}
};

int main()
{
	int N, K, L;
	int tmp_i, tmp_j;
	
	cin >> N >> K >> L;

	UnionFind road(N+5);
	UnionFind rail(N+5);

	for (int i = 1; i <= K; i++)
	{
		cin >> tmp_i >> tmp_j;
		road.unite(tmp_i, tmp_j);
	}
	for (int i = 1; i <= L; i++)
	{
		cin >> tmp_i >> tmp_j;
		rail.unite(tmp_i, tmp_j);
	}

	map<pair<int, int>, int> link;

	for (int i = 1; i <= N; i++)
	{
		link[make_pair(road.find(i), rail.find(i))]++;
	}

	for (int i = 1; i <= N; i++)
		cout << link[make_pair(road.find(i), rail.find(i))] << " ";

	cout << endl;


	return 0;
}

Measured memory_bytes: 15124
T1,T2=map(int,input().split())
A1,A2=map(int,input().split())
B1,B2=map(int,input().split())
a,b,c,d=T1*A1,T1*B1,T2*A2,T2*B2
if a+c==b+d:
    print('infinity')
else:
    if (a-b)*(a+c-b-d)>0:
        print(0)
    else:
        x,y=abs(a-b),abs(a+c-b-d)
        if x%y==0:
            print(x//y*2)
        else:
            print(x//y*2+1)

Measured memory_bytes: 3064
#include<stdio.h>

int main (void)
{
	int H;
	int W;
	int i,j;
		
	while(1 ){
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0) break;
		for(i=1; i<= H; i++){
			for(j=1; j<=W; j++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

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

int main() {
  int x;
  cin >> x;
  int array[x];
  for (int i = 0; i < x; ++i) {
    cin >> array[i];
  }

  for (int j = x; j > 0; --j) {
    if(j == 1) {
      cout << array[j - 1] << endl;
    } else {
      cout << array[j - 1] << " " << flush;
    }
  } 
}

Measured memory_bytes: 3076