akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3

import heapq
import collections
import sys
input=sys.stdin.readline

n=int(input())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
cnt1=collections.Counter(arr1)
cnt2=collections.Counter(arr2)
tmp=[[key,cnt1[key]] for key in cnt1.keys()]
tmp=sorted(tmp,reverse=True,key=lambda x:x[1])
arr3=[]
for key,cnt in tmp:
  for _ in range(cnt):
    arr3.append(key)
cnt3=collections.Counter(arr3)
ans=[0]*n
acum=0
pos=0
head=[]
tail=[]
for key in cnt3.keys():
    tcnt1=cnt3[key]
    tcnt2=cnt2[key]
    if tcnt1+tcnt2>n:
        print('No')
        exit()
    acum+=tcnt1
    tpos=max(acum,pos)
    remain=tcnt2
    #print(key,blank,remain)
    for i in range(tpos,n):
        if remain==0:
            break
        ans[i]=key
        remain-=1
        cnt2[key]-=1
    for _ in range(remain):
      if tpos!=pos:
        head.append(key)
      else:
        tail.append(key)
      cnt2[key]-=1
    pos=min(tpos+tcnt2,n)
    #print(ans,head,pos)
for key in cnt2.keys():
    if cnt2[key]==0:
        continue
    for _ in range(cnt2[key]):
        tail.append(key)
pos=0
head+=tail
for i in range(n):
    if ans[i]==0:
        ans[i]=head[pos]
        pos+=1
q=[]
for i in range(n):
  heapq.heappush(q,(arr3[i],ans[i]))
for i in range(n):
  _,val=heapq.heappop(q)
  ans[i]=val
print('Yes')
print(*ans)

Measured memory_bytes: 97900
def main():
    n = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    back_lim = []
    lim = []
    for i in range(n):
        for _ in range(t[i]):
            back_lim.append(v[i])
            lim.append(v[i])
    back_lim.append(0)
    for i in reversed(range(len(back_lim)-1)):
        back_lim[i] = min(back_lim[i], back_lim[i+1]+1)
    ans = 0.0
    p = 0
    for i in range(len(back_lim)-1):
        if p < back_lim[i+1]:
            if p < lim[i]:
                ans += p + 0.5
                p += 1
            else:
                ans += p
        elif p == back_lim[i+1]:
            if p < lim[i]:
                ans += p + 0.25
            else:
                ans += p
        else:
            ans += p - 0.5
            p -= 1
    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9420
// http://agc014.contest.atcoder.jp/submissions/1263665
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i, n) for (in i = 0; i < (n); ++i)
#define forv(i, v) forn(i, sz(v))
#define fors(i, s) for (auto i = (s).begin(); i != (s).end(); ++i)
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
in n;
VVI egs;
void first() {
  cout << "First" << endl;
  exit(0);
}
void second() {
  cout << "Second" << endl;
  exit(0);
}
in dfs0(in u, in pr) {
  in avc = 0;
  forv(i, egs[u]) {
    if (egs[u][i] == pr) continue;
    avc += dfs0(egs[u][i], u);
  }
  if (avc >= 2) first();
  if (avc == 0) return 1;
  return 0;
}

int dfs(int u, int pr) {
  int avc = 0;
  for(auto c: egs[u]) {
    if (c == pr) continue;
    avc += dfs(c, u);
  }

  if (avc >= 2) first();
  if (avc == 0) return 1;
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  egs.resize(n);
  in ta, tb;
  forn(z, n - 1) {
    cin >> ta >> tb;
    --ta;
    --tb;
    egs[ta].PB(tb);
    egs[tb].PB(ta);
  }
  if (dfs(0, 0)) {
    first();
  }
  second();
  return 0;
}

Measured memory_bytes: 6400
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007

int N,M;
signed main(){
    scanf("%lld %lld",&N,&M);
    int ans=N*(N-1)/2+M*(M-1)/2;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                           \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
  cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  K = min(K, 100);
  int A[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int k = 0; k < K; k++) {
    int B[N];
    fill(B, B + N, 0);
    for (int i = 0; i < N; i++) {
      int l = max(0, i - A[i]);
      int r = min(N, i + A[i] + 1);
      B[l]++;
      if (r < N) B[r]--;
    }
    for (int i = 1; i < N; i++) {
      B[i] += B[i - 1];
    }
    for (int i = 0; i < N; i++) {
      A[i] = B[i];
    }
  }
  for (int i = 0; i < N; i++) {
    cout << (i ? " " : "") << A[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 5204
program j01;
uses math;
var a,b,ans,n,i:longint;
begin
  b:=maxlongint;ans:=0;
  readln(n);
  for i:=1 to n do
  begin
    read(a);inc(ans,a);
    if a mod 10<>0 then b:=min(a,b);
  end;
  if ans mod 10<>0 then begin writeln(ans);halt; end; 
  if b=maxlongint then writeln(0) else writeln(ans-b);
end.


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((int)(x).size())
#define inf          1<<25

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//typedef vector<int> vi;
//typedef vector<long long> vl;
//typedef vector<double> vd;
//typedef pair<int,int> pii;
//typedef pair<long,long> pll;
//typedef long long ll;

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

int main() {
    int m;
    cin >> m;
    
    cout << 24 + (24 - m) << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define print(obj) cout << obj << endl
#define scan(obj) cin >> obj

typedef long long ll;

using namespace std;

int main(void){
    int n, ans = 0;
    cin >> n;
    rep(i, n){
        int temp1, temp2;
        cin >> temp1 >> temp2;
        ans += temp2 - temp1 + 1;
    }
    print(ans);
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }

    int cnt = 0;
    for(int i=0; i<N; i++){
        while(i+1 < N && A.at(i+1) == A.at(i)){
            i++;
        }
        if(i+1 < N && A.at(i+1) > A.at(i)){
            while(i+1 < N && A.at(i+1) >= A.at(i)) i++;
        }
        else if(i+1 < N && A.at(i+1) < A.at(i)){
            while(i+1 < N && A.at(i+1) <= A.at(i)) i++;
        }
        cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3784
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 20 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int n;
int a[maxN][maxN];
int dp[1 << 21];

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	cin >> n;
	FOR(i, n) {
		FOR(j, n)
		cin >> a[i][j];
	}
	// set bit represents that the woman has been paired up
	dp[0] = 1;
	for (int mask = 0; mask < (1 << n); mask++)
	{
		int i = __builtin_popcount(mask);
		for (int j = 0; j < n; j++)
		{
			if (a[i][j] && !(mask & (1 << j)))
			{
				int new_mask = mask | (1 << j);
				dp[new_mask] += dp[mask];
				dp[new_mask] %= MOD;
			}
		}
	}
	cout << dp[(1 << n) - 1];
	return 0;
}

Measured memory_bytes: 11836
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define P pair<int,int>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define asort(x) sort(x.begin(),x.end())
 
int main() {
    string s;
    cin>>s;
    if(s.compare("ABC") == 0) cout << "ARC" << endl;
    else if(s.compare("ARC") == 0) cout << "ABC" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
const long long mod=1e9+7; //10^9+7

int main() {
    int m,d;
    cin>>m>>d;
    int ans = 0;
    for(int i=1; i<=m; i++){
        int x=2,y=2;
        while(1==1){
            if(10*x+y>d) break;
            if(y>=2 && x >= 2 && y*x == i){
                ans++;
                //cout << i << "月" << x<<y<<"日"<<endl;
            }
            if(y==9) x++;
            y++;
            y=y%10;
        }
    }

    cout << ans << endl;


    return 0;
}


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

const int MAX = 510000;
const int mod = 1000000007;

long long fac[MAX]; //i!%mod=fac[i]
long long finv[MAX]; //pow(i!,-1)%mod=finv[i]
long long inv[MAX]; //pow(i,-1)%mod=inv[i]

// テーブルを作る前処理
void cominit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
long long com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

int main(int argc, char const *argv[])
{
	cominit();
	int n,m,k;
	cin>>n>>m>>k;
	long long ans=0LL;
	for (int i = 1; i < n; ++i)
	{
		long long tmp=(long long)i*(n-i)%mod*m%mod*m%mod;
		tmp*=com(n*m-2,k-2);
		tmp%=mod;
		ans+=tmp;
		ans%=mod;
	}
	for (int i = 1; i < m; ++i)
	{
		long long tmp=(long long)i*(m-i)%mod*n%mod*n%mod;
		tmp*=com(n*m-2,k-2);
		tmp%=mod;
		ans+=tmp;
		ans%=mod;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 12160
#include <cstdio>

int n, m,t,ans;
int a[1000], cnt[1000];

int main(){
	scanf("%d%d", &n, &m);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	for(int i = 0; i < m; i++){
		int b; scanf("%d", &b);
		for(int i = 0; i< n; i++){
			if(a[i] <= b){
				cnt[i]++;
				break;
			}
		}
	}
	for(int i = 0; i < m; i++){
		if(t < cnt[i]){
			ans = i;
			t  = cnt[i];
		}
	}
	printf("%d\n", ans+1);
}

Measured memory_bytes: 1032
package main

import "fmt"

func main() {
	var k int
	fmt.Scan(&k)

	n := 50
	d := k / 50
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = i + d
	}

	for i := 0; i < k%n; i++ {
		key, val := -1, int(1e18)
		for j := 0; j < n; j++ {
			if as[j] < val {
				key = j
				val = as[j]
			}
		}

		for j := 0; j < n; j++ {
			if key == j {
				as[j] += n
			} else {
				as[j]--
			}
		}
	}

	pre := ""
	fmt.Println(n)
	for i := 0; i < n; i++ {
		fmt.Printf("%s%d", pre, as[i])
		pre = " "
	}
	fmt.Println()
}


Measured memory_bytes: 1840
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc. nextInt();
        int area = a * b;
        int length = ( a + b ) * 2;
        System.out.println(area+" "+length);
        sc.close();
    }
}


Measured memory_bytes: 26272
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

int main(void){
    char trump;
    while (cin>>trump && trump != '#') {
        vector<vector<char> > vc(4, vector<char>(13));
        vector<vector<int> >  vi(4, vector<int>(13));
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                string s;
                cin >> s;
                vc[i][j] = s[1];
                if (s[0] >= '0' && s[0] <= '9') vi[i][j] = s[0] - '0';
                else if (s[0] == 'T') vi[i][j] = 10;
                else if (s[0] == 'J') vi[i][j] = 11;
                else if (s[0] == 'Q') vi[i][j] = 12;
                else if (s[0] == 'K') vi[i][j] = 13;
                else if (s[0] == 'A') vi[i][j] = 14;
            }
        }
        
        int lead = 0;
        int ns_score = 0, ew_score = 0;
        for (int i = 0; i < 13; i++) {
            int w_player = lead;
            char w_suit = vc[lead][i];
            int w_num = vi[lead][i];
            
            for (int j = 1; j < 4; j++) {
                int p = (lead + j) % 4;
                char p_suit = vc[p][i];
                char p_num = vi[p][i];
                if (w_suit == trump) {
                    if (p_suit == trump && p_num > w_num) w_player = p, w_suit = p_suit , w_num = p_num;
                }
                else {
                    if (p_suit == trump) w_player = p, w_suit = p_suit , w_num = p_num;
                    else if (p_suit == w_suit && p_num > w_num) w_player = p, w_suit = p_suit , w_num = p_num;
                }
            }
            
            lead = w_player;
            if (lead % 2) ew_score++;
            else ns_score++;
        }
        //cout << endl;
        if (ns_score > ew_score) cout << "NS" << " " << ns_score - 6 << endl;
        else cout << "EW" << " " << ew_score - 6 << endl;
    }
}

Measured memory_bytes: 3160
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque
import math

def run():
    N = int(input())
    for n in range(1, N+1):
        ret = 0
        val = int(math.sqrt(2 * n))
        for X in range(2, val+1):
            for Y in range(2, val+1):
                tmp1 = 2 * n - X ** 2 - Y ** 2
                if tmp1 >= 0 and math.sqrt(tmp1) == int(math.sqrt(tmp1)):
                    Z_ = int(math.sqrt(tmp1))
                    if Z_ != 0:
                        for k in [-1, 1]:
                            Z = Z_ * k
                            if not (X + Y + Z) % 2:
                                xyz = (X + Y + Z) // 2
                                x = xyz - Y
                                y = xyz - Z
                                z = xyz - X
                                if x >= 1 and y >= 1 and z >= 1:
                                    ret += 1
                                    #print(x, y,z)


        print(ret)



if __name__ == "__main__":
    run()


Measured memory_bytes: 71168
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! chmax {
    ($x:expr, $y:expr) => {
        if $x < $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}


#[allow(unused_macros)]
macro_rules! chmin {
    ($x:expr, $y:expr) => {
        if $x > $y {
            $x = $y;
            true
        } else {
            false
        }
    };
}

fn main() {
    let cin = stdin();
    let mut scan = Scanner::new(cin.lock());
    let n = scan.read::<usize>();
    let mut g = vec![vec![];n];
    for i in 0..n-1 {
        let a = scan.read::<usize>()-1;
        let b = scan.read::<usize>()-1;
        g[a].push((b, i));
        g[b].push((a, i));
    }
    let mut t = 0;
    let mut k = 0usize;
    for i in 0..n {
        if chmax!(k, g[i].len()) {
            t = i;
        }
    }

    let mut env = Env {g: g, color: vec![0;n-1]};
    env.dfs(t, None, None);
    println!("{}", k);
    for i in 0..n-1 {
        println!("{}", env.color[i]);
    }
}

struct Env {
    g: Vec<Vec<(usize, usize)>>,
    color: Vec<usize>
}

impl Env {
    fn dfs(&mut self, cur: usize, pre: Option<usize>, pre_color: Option<usize>) {
        let mut p = 1;
        if pre_color == Some(p) {p = 2;}
        let vs = self.g[cur].clone();
        for &(v, i) in &vs {
            if Some(v) == pre {continue;}
            self.color[i] = p;
            self.dfs(v, Some(cur), Some(p));
            p += 1;
            if pre_color == Some(p) { p+=1;}
        }
    }
}

// region template
#[allow(dead_code)]
fn iu(i: i64) -> usize { i as usize }

#[allow(dead_code)]
fn ui(i: usize) -> i64 { i as i64 }

#[allow(dead_code, deprecated)]
fn join<T: std::fmt::Display>(slice: &[T], sep: &str) -> String {
    let strings = slice.iter().map(|t| format!("{}", t)).collect::<Vec<_>>();
    strings.connect(sep)
}

#[allow(dead_code)]
fn arr<'a, S, T>(n: usize, mut f: S) -> Vec<T> where S: FnMut(usize) -> T + 'a {
    (0..n).map(|i| f(i)).collect::<Vec<T>>()
}

struct Scanner<'a> {
    cin: StdinLock<'a>,
}

#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }

    fn readn<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read::<T>()).collect()
    }

    fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}
// endregion

Measured memory_bytes: 18812
#include <iostream>
#include<stdio.h>
using namespace std;




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


	int result;

	result= N-K;
	if(K==1){
			cout <<0 <<endl;
	}else{
		cout <<result <<endl;
	}
	

  return 0;
}

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

int main() {
  int N,M;
  cin>>N>>M;
  
  vector<int> p(M);
  vector<string> S(M);
  rep(i,M){
    cin>>p[i]>>S[i];
  }
  
  int ans=0;
  int penalty=0;
  
  vector<int> count_p(N+1);
  vector<bool> flag(N+1);
  
  rep(i,M){
    if(S[i]=="AC")
      flag[p[i]]=true;
    else{
      if(!flag[p[i]])
        ++count_p[p[i]];
    }
  }
  
  for(int i=1;i<=N;++i){
    if(flag[i]){
      ++ans;
      penalty+=count_p[i];
    }
  }
  
  cout<<ans<<" "<<penalty<<endl;
}


Measured memory_bytes: 6528
#include<stdio.h>
int main(){
	int a, b, hasil;
	char op;
	for(int i=0; ; i++){
		scanf("%d %c %d", &a, &op, &b);
		if(op=='+'){
			hasil = a + b;
			printf("%d\n", hasil);
		}
		else if(op=='-'){
			hasil = a - b;
			printf("%d\n", hasil);
		}
		else if(op=='*'){
			hasil = a * b;
			printf("%d\n", hasil);
		}
		else if(op=='/'&&b!=0){
			hasil = a/b;
			printf("%d\n", hasil);
		}
		else if(op=='?'){
			break;
		}
	}
	
}


Measured memory_bytes: 2760
#include <cstdio>
#include <algorithm>
using namespace std;

int N, M, p[1001], s[1001 * 1001];

int main(){
    while(scanf("%d%d", &N, &M) != EOF && (N|M)){
        for(int x = 0; x < N; x++){
            scanf("%d", p+x);
        }
        p[N++] = 0;
        for(int x = 0; x < N; x++){
            for(int y = 0; y < N; y++){
                s[N*x + y] = p[x] + p[y];
            }
        }
        sort(s, s+N*N);
        int ans = 0;
        for(int x = 0; x < N*N; x++){
            int* lb = lower_bound(s, s + N * N, M - s[x]);
            if(lb != s) --lb;
            if(s[x] + *lb > M) continue;
            ans = max(ans, s[x] + *lb);
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 4960
n = int(input())
txys = [[0, 0, 0]] + [[int(x) for x in input().split()] for _ in range(n)]

def check(txy1, txy2):
    dt = txy2[0] - txy1[0]
    dx = abs(txy2[1] - txy1[1])
    dy = abs(txy2[2] - txy1[2])
    return (dt >= dx + dy) and (dt % 2 == (dx + dy) % 2)

print('Yes' if all(check(*rows) for rows in zip(txys, txys[1:])) else 'No')

Measured memory_bytes: 21948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int a, b, c; cin >> a >> b >> c;
    if (a + b >= c) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;
// << fixed << setprecision
// --------------------------------------
string s;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> s;

  if(s[s.length() - 1] == 's') {
    cout << s << "es" << endl;
  } else {
    cout << s << "s" << endl;
  }
}


Measured memory_bytes: 3644
#include<cstdio>
#include<cstring>
#include<cmath>
#include<utility>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 233;
ll ans =0;
int a[maxn];
int main()
{
	int n;cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	ll x=0,y=0,j=0;
	for(int i=1;i<=n;i++)
	{
		while(j<n&&((x+a[j+1])==(y^a[j+1])))
		{
			j++;
			x += a[j];
			y ^= a[j];
		}
		ans += (j-i+1);
//		cout<<"!"<<i<<" "<<j<<endl;
		x -= a[i];
		y ^= a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,A=ilint()
C=counter()
for a in A:
    C.add(a)
ans=powmod(2,N//2,MOD)
for k in range((N-1)%2,N,2):
    if k not in C or C[k]!=2-(k==0):
        ans=0
        break
print(ans)

Measured memory_bytes: 100168
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));


signed main() {
	int x;
	cin >> x;
	cout << 1 - x;
}

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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MOD 1000000007
#define INF 100100100

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


int main(){
  int n, c, k;
  cin >> n >> c >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  ll res = 0;
  sort(all(v));

  bool new_bus = true;
  int bus_num = 0;
  int wait_time = 0;
  int now = 0;
  int first_num = 0;
  for (int i = 0; i < n; i++) {
    now = v[i];
    if(new_bus){
      bus_num = 0;
      wait_time = 0;
      first_num = i;
      new_bus = false;
    }
    bus_num++;
    wait_time = now - v[first_num];
    // cout << wait_time << endl;
    // cout << bus_num << endl;
    if(bus_num > c || wait_time > k){
      res++;
      // cout << "go" << endl;
      new_bus = true;
      i--;
    }
    // cout << "======" << endl;
  }
  res++;
  cout << res << endl;
}


Measured memory_bytes: 640
//Bagher The Gang Boy
#include <bits/stdc++.h>
using namespace std;

#define int long long

const int LG = 60;
int A, B;
vector <int> a, b;

int32_t main() {
	cin >> A >> B;
	if (A == B)
		return cout << 1, 0;
	for (int i = 0; i < LG; i++) {
		if (A & (1ll << i))
			a.push_back(i);
		if (B & (1ll << i))
			b.push_back(i);
	}
	while (a.size() && b.size() && a.back() == b.back()) {
		A -= (1ll << a.back());
		B -= (1ll << b.back());
		b.pop_back();
		a.pop_back();
	}
	int NUM = b.back();
	b.pop_back();
	int val = 0;
	if (b.size() > 0)  {
		int now = b.back();
		while (now > -1) {
			val += (1ll << now);
			now--;
		}
	}
	return cout << ((val < A) ? ((1ll << (NUM + 1)) - (A << 1) + val + 1) : ((1ll << (NUM + 1)) - A)), 0;
}

Measured memory_bytes: 3604
from heapq import heappush, heappop
import re
from collections import deque
import sys
import math
input = sys.stdin.readline


def int_raw():
    return int(input())


def ss_raw():
    return input().split()


def ints_raw():
    return tuple(map(int, ss_raw()))


DIV = 10**9+7


def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def ncr(n, r, mod=DIV):
	r = min(r, n-r)
	ret = 1
	for i in range(1, r+1):
		ret = ret * (n-i+1) % mod
		ret = ret * mod_inv(i, mod) % mod
	return ret


def main():
    N = int_raw()
    As = ints_raw()
    Bs = ints_raw()
    ans = 0
    resB = 0
    for i in range(N):
        Bi = Bs[i]
        Ai = As[i] 
        ans += min(Bi+resB,Ai)

        resB = max(Bi-max(Ai-resB,0),0)

    return ans+min(resB,As[-1])
print(main())


Measured memory_bytes: 77540
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define REP(i, N) for (int i = 0; i < (int)N; i++)
#define FOR(i, a, b) for (int i = a; i < (int)b; i++)
using ll = long long;

constexpr int SZ = 100000, prs = 10;
ll pre[1 << prs][SZ + 1];

int main() {
  int N;
  cin >> N;
  vector<int> V(N + 1), W(N + 1);
  REP(i, N) cin >> V[i + 1] >> W[i + 1];
  FOR(i, 1, min(N + 1, 1 << prs)) {
    if (i != 1) copy(pre[i / 2], pre[i / 2] + SZ + 1, pre[i]);
    for (int j = SZ; j >= W[i]; --j)
      pre[i][j] = max(pre[i][j], pre[i][j - W[i]] + V[i]);
    REP(j, SZ) pre[i][j + 1] = max(pre[i][j + 1], pre[i][j]);
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int v, L;
    cin >> v >> L;
    if (v < (1 << prs)) {
      cout << pre[v][L] << "\n";
    } else {
      int lvl = 32 - __builtin_clz(v) - prs;
      ll ans = 0;
      REP(b, 1 << lvl) {
        int w = 0;
        ll va = 0;
        REP(i, lvl) {
          if ((b >> i) & 1) {
            w += W[v >> i];
            va += V[v >> i];
          }
          if (w > L) break;
        }
        if (w <= L) ans = max(ans, pre[v >> lvl][L - w] + va);
      }
      cout << ans << "\n";
    }
  }
  return 0;
}


Measured memory_bytes: 804476
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    // TODO 自動生成されたメソッド・スタブ
    Scanner scanner = new Scanner(System.in);
    int inNumber = scanner.nextInt();
    List iList = new ArrayList<Integer>();
    for (int i = 0; i < inNumber; i++) {
      int num = scanner.nextInt();
      iList.add(num);
    }

    boolean isTrue = true;
    int count = 0;

    while (isTrue) {
      for (int i = 0; i < iList.size(); i++) {
        if ((int) iList.get(i) % 2 == 0) {
          iList.set(i, (int) iList.get(i) / 2);
        } else {
          isTrue = false;
          break;
        }
      }
      if (isTrue) {
        count++;
      }
    }

    System.out.println(count);

  }

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
 
#define int long long
 
#define pii pair<int, int>
 
#define x1 x1228
#define y1 y1228
 
#define left left228
#define right right228
 
#define pb push_back
#define eb emplace_back
 
#define mp make_pair                                                                
                                                                                                                                        
#define ff first                                                                  
#define ss second   
 
#define matr vector<vector<int> > 
 
#define all(x) x.begin(), x.end()
 
 
using namespace std;
typedef long long ll; 
typedef long double ld; 
                                                                                                   
const int maxn = 1000 + 7, mod = 998244353, inf = 1e18, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n, m, a, b; 
int ans[maxn][maxn]; 

void solve() { 
    cin >> n >> m >> a >> b; 
    for (int i = 0; i < b; ++i) {
        for (int j = 0; j < a; ++j) {
            ans[i][j] = 1; 
        }
    }
    for (int i = n - 1; i >= b; --i) {
        for (int j = m - 1; j >= a; --j) {
            ans[i][j] = 1; 
        }
    }
    for (int i = 0; i < n; ++i) {
        int a1 = 0;
        int b1 = 0; 
        for (int j = 0; j < m; ++j) {
            a1 += ans[i][j]; 
            b1 += !ans[i][j]; 
        }
        if (min(a1, b1) != a) {
            cout << "-1\n";
            return; 
        }
    }
    for (int j = 0; j < m; ++j) {
        int a1 = 0;
        int b1 = 0; 
        for (int i = 0; i < n; ++i) {
            a1 += ans[i][j]; 
            b1 += !ans[i][j];
        }
        if (min(a1, b1) != b) {
            cout << "-1\n"; 
            return; 
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) cout << ans[i][j]; 
        cout << '\n'; 
    }
}                                   
   
signed main() {
#ifdef LOCAL
    freopen("TASK.in", "r", stdin);
    freopen("TASK.out", "w", stdout);
#else 
    
#endif // LOCAL
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20); 
    cout << fixed; 
    int t = 1; 
    for (int i = 0; i < t; ++i) {              
        solve();
    }
    return 0;
}  

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

int main(){
  int a,b,c,d; cin>>a>>b>>c>>d;
  if(abs(c-a) <= d) cout<<"Yes"<<endl;
  else if(abs(b-a)<=d && abs(c-b)<=d) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

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

int main() {

    int n, a, b; cin >> n >> a >> b;

    int  ans = 0;
    for (int i = 1; i <= n; i++) {
        int sum = 0;
        int tmp = i;
        while (0 < tmp) {
            sum += tmp % 10;
            tmp /= 10;
        }
        if (a <= sum && sum <= b) ans += i;
    }

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

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

int m, f, r;

int main() {
    while (1) {
        cin >> m >> f >> r;
        if (m == -1 && f == -1 && r == -1) {
            return 0;
        } else if (m == -1||f == -1) {
            cout << "F" << endl;
        } else if (m + f >= 80) {
            cout << "A" << endl;
        } else if (m + f >= 65 && m + f < 80) {
            cout << "B" << endl;
        } else if (m + f >= 50 && m + f < 65) {
            cout << "C" << endl;
        } else if (m + f >= 30 && m + f < 50) {
            if (r >= 50) {
                cout << "C" << endl;
            } else {
                cout << "D" << endl;
            }
        } else {
            cout << "F" << endl;
        }
    }
}



Measured memory_bytes: 3108
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int N,a[100005];

int solve(){
    int res=0,sum=0;
    REP(i,N){
        sum+=a[i];
        if(i%2==0 and sum<=0){
            res+=1-sum;
            sum=1;
        }
        if(i%2==1 and sum>=0){
            res+=sum+1;
            sum=-1;
        }
    }
    return res;
}

signed main()
{
    cin>>N;
    REP(i,N) cin>>a[i];
 
    int ans=solve();
    REP(i,N) a[i]*=-1;
    ans=min(ans,solve());
    cout<<ans<<endl;
}


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

signed main(){
	int N , K , G = 0; cin >> N >> K; bool flg = 1;
	for(int i = 1 , x ; i <= N ; ++i){cin >> x; G = __gcd(G , x); flg &= K > x;}
	puts(!(K % G) && !flg ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = sorted(list(map(int, input().split(' '))), reverse=True)

ans = 0

t = N - 1

for i in range(N):
    lim = 1 if i == 0 else 2
    for j in range(lim):
        if (t > 0):
            ans += A[i]
            t -= 1

print(ans)

Measured memory_bytes: 31612
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    ll N;
    cin >> N;

    int ans = 0;
    rep(i,0,N) {
        int tmp;
        cin >> tmp;
        ans += tmp-1;
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(std::vector<std::string> c){
    for (int i = 0; i < 3; i++)
    {
        cout << c[i][i];
    }
    cout << endl;
    
}

int main(){
    std::vector<std::string> c(3);
    for(int i = 0 ; i < 3 ; i++){
        std::cin >> c[i];
    }
    solve(std::move(c));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void chmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void chmin(T& a, U b) { if (a>b) a = b; }

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

  string k = "keyence";
  string s;
  cin >> s;
  if (s == k) {
    cout << "YES" << endl;
    return 0;
  }

  bool ans = 0;

  int cnt = 0;
  int scnt = 0;
  for (auto&& i : s) {
    if (i == k[cnt]) {
      cnt++;
      rep(i, s.size()-scnt) {
        cerr << s.substr(i+scnt, 100) << " " <<  k.substr(cnt+1, 100) << endl;
        if (s.substr(i+scnt, 100) == k.substr(cnt+1, 100)) {
          cout << "YES" << endl;
          return 0;
        }
      }
    } else {
      break;
    }
    scnt++;
  }
  
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll          long long int
#define uu          first
#define vv          second
#define pii         pair<int,int>
#define pll         pair<ll,ll>
#define INF         1e9
#define fastRead    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;

const int MAX = 1e6 + 6;
int main()
{
    fastRead;
    ll n, m, k;
    cin>>n>>m>>k;
    vector<ll>sum1(n+1);
    vector<ll>sum2(m+1);
    
    for(int i = 1; i <=n ; i++ ) cin>>sum1[i], sum1[i] += sum1[i-1];
    for(int i = 1; i <=m ; i++ ) cin>>sum2[i], sum2[i] += sum2[i-1];
    
    int ans = 0;
    
    for(int i = 0 ; i <=n ; i++ ) {
        
        if(sum1[i] > k) break;
        
        ll baki = k - sum1[i];
        
        int id = upper_bound(sum2.begin()+1, sum2.end(), baki) - sum2.begin()-1;
        ans = max(ans, i + id);
    }
    cout<<ans<<'\n';
    return 0;
}

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

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


		for (int i = 0; i < n; i++) {
			char s;
			cin >> s;
			if (s == 'Y') {
				cout << "Four" << endl;
				return 0;
			}
		}
		cout << "Three" << endl;
		return 0;
		}

Measured memory_bytes: 3592
N, X = map(int, input().split())

def burger(N,X):
  #print(N,X)
  if N == 0 and X == 1:
    return 1
  if X == 0:
    return 0
  twopow = pow(2,N)
  if X == 4*twopow-3:
    return 2*twopow-1
  if X > 2*twopow-2:
    return twopow + burger(N-1,X-2*twopow+1)
  elif X <= 2*twopow-2:
    return burger(N-1,X-1)

print(burger(N,X))

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

int gcd(int a,int b)
{
	int r=max(abs(a),abs(b));
	int l=min(abs(a),abs(b));
	if (l==0LL)
	{
		return r;
	}
	return gcd(l,r%l);
}

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int l[n+5],r[n+5];
	l[0]=0;
	for (int i = 1; i < n; ++i)
	{
		l[i]=gcd(l[i-1],a[i-1]);
	}
	r[n]=0;
	for (int i = n-1; i >= 0; --i)
	{
		r[i]=gcd(r[i+1],a[i]);
	}
	int ans=1;
	for (int i = 0; i < n; ++i)
	{
		ans=max(ans,gcd(l[i],r[i+1]));
	}
	cout<<ans<<endl;
	return 0;
}


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

bool comp(pair<int, int>& a, pair<int, int>& b){
  return a.second < b.second;
}

int main() {
  int n,q;
  cin >> n >> q;
  vector<pair<int, int>> ab(n-1),px(q);
  for(int i=0; i<n-1; i++){
    cin >> ab.at(i).first >> ab.at(i).second;
  }
  for(int i=0; i<q; i++){
    cin >> px.at(i).first >> px.at(i).second;
  }

  vector<int> c(n);
  for(int i=0; i<q; i++){
    c.at(px.at(i).first - 1) += px.at(i).second;
  }

  sort(ab.begin(),ab.end(),comp);

  for(int i=0; i<n-1; i++){
    c.at(ab.at(i).second - 1) += c.at(ab.at(i).first - 1);
  }

  for(int i=0; i<n; i++){
    cout << c.at(i) << " ";
  }

  cout << endl;

}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

  int a, b;
  cin >> a >> b;
  int count = a, ans = 1;

  if (b == 1)
    ans = 0;
  else {
    while (count < b) {
      count += a - 1;
      ans++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
n,t = map(int,readline().split())
f = []
m = 0
for i in range(n):
  p,q = map(int,readline().split())
  m = max(m,p)
  f.append((p,q))
  
f.sort()
dp = [[0]*(t+m) for i in range(n+1)]

for i,c in enumerate(f):
  a,b = c
  for j in range(t+m):
    if j-a >= t:
      break
    if j < a :
      dp[i+1][j] = dp[i][j]
    else:
      dp[i+1][j] = max(dp[i][j],dp[i][j-a]+b)
      
print(max(dp[n]))


Measured memory_bytes: 181212
lines = $stdin.read
array = lines.split("\n")

class Dfs
  attr_accessor :mat,:inc

  def initialize(mat)
    @mat = mat.dup
    @inc = 1
  end

  def dfs(x,y)

    @mat[x][y] = @inc if @mat[x][y] == 1

    #@mat.each{|r| p r}

    #dxy = [[-1,-1],[-1,0],[-1,1],[0,-1],[0,1],[1,-1],[1,0],[1,1]]
    dxy = [[-1,0],[0,-1],[0,1],[1,0]]
    for i in 0...dxy.length
      dx,dy = dxy[i].first,dxy[i].last
      nx,ny = x+dx,y+dy
      if 0<=nx and nx<@mat.length and 0<=ny and ny<@mat.first.length
        dfs(nx,ny) if @mat[nx][ny]==1
      end
    end

  end
end

# 0=sea,1=island

i = 0
until array[i].nil?

  if array[i]==''
    i+=1
    next
  end

  m = Array.new(12).map{Array.new(12,0)}
  array[i...i+12].each_with_index do |line,idx|
    m[idx] = line.split("").map(&:to_i)
  end

  dfs,ans = Dfs.new(m),0

  for y in 0...12
    for x in 0...12
      # puts "x=#{x},y=#{y}"
      if dfs.mat[x][y]==1
        dfs.inc = dfs.inc + 1
        dfs.dfs(x,y)
      end
    end
  end

  #dfs.mat.each{|r| p r}
  #puts ""

  ans = dfs.mat.map(&:max).max-1
  ans = if ans<0
          0
        else
          ans
        end
  puts ans

  i+=(12+1)
end


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

int main() {
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0; i < s.size(); i++) {
        int now = s[i] - '0';
        sum += now;
    }
    cout << (sum % 9 == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3684
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main (){
    int a[4];
    int b[4];
    for(int i = 0 ;i < 4;i++){
        cin >> a[i];
        cin >> b[i];

    }
    for(int i = 0 ;i < 4;i++){
        switch (a[i]){
            case 1:
            cout << 6000*b[i]<< endl;
            break;
            case 2:
            cout << 4000*b[i]<< endl;
            break;
            case 3:
            cout << 3000*b[i]<< endl;
            break;
            case 4:
            cout << 2000*b[i]<< endl;
            break;
        }

    }
    return 0;
}


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

using namespace std;

int main()
{
    long long int N,A,B;
    cin >> N >> A >> B;

    long long int count = 0;

    long long int k = N / (A+B);
    long long int amari = N % (A+B);
    count = k*A;
    count += (amari < A) ? amari : A;

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef vector<string> VS;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N, X; cin >> N >> X;
	VI A(N);
	vector<VI> ans(N + 1, VI(N, LLINF));
	REP(i, N)cin >> A[i];
	REP(i, N) {
		int x = 0;
		eREP(j, N) {
			chmin(ans[x][(i + j) % N], A[i]);
			x++;
		}
	}
	eFOR(i, 1, N) {
		REP(j, N)chmin(ans[i][j], ans[i - 1][j]);
	}
	int res = LLINF;
	eREP(j, N) {
		int cnt = 0;
		REP(i, N)cnt += ans[j][i];
		chmin(res, j*X + cnt);
	}
	cout << res << endl;
	return 0;
}



Measured memory_bytes: 31616