akhauriyash/Code-Regression huggingface dataset:
//#define NDEBUG
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <array>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <type_traits>
#include <utility>
#include <vector>
static constexpr double PI = 3.1415926535897932;

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
using intl32 = std::int_least32_t;
using intl64 = std::int_least64_t;
using uintl32 = std::uint_least32_t;
using uintl64 = std::uint_least64_t;

void yes(bool c) { puts(c ? "yes" : "no"); }
void Yes(bool c) { puts(c ? "Yes" : "No"); }
void YES(bool c) { puts(c ? "YES" : "NO"); }
void pos(bool c) { puts(c ? "possible" : "impossible"); }
void Pos(bool c) { puts(c ? "Possible" : "Impossible"); }
void POS(bool c) { puts(c ? "POSSIBLE" : "IMPOSSIBLE"); }
template<class T>bool bmaxi(T&a, const T&b) { if (b<a)return 0;a = b;return 1; }
template<class T>bool bmini(T&a, const T&b) { if (a<b)return 0;a = b;return 1; }
template<class T>bool nmaxi(T&a, const T&b) { if (a<b) { a = b;return 1; }return 0; }
template<class T>bool nmini(T&a, const T&b) { if (b<a) { a = b;return 1; }return 0; }
template<typename T>auto scan(T&d)->typename std::enable_if<std::is_same<T, std::string
>::value>::type {
	d.clear();int c = fgetc(stdin);while (c<'a' || 'z'<c)c = fgetc(stdin);
	while ('a' <= c&&c <= 'z') { d.push_back(c);c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->
typename std::enable_if<std::is_same<T, double>::value>::type {
	scanf("%lf", &d);
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	== std::is_same<T, std::string>::value>::type {
	d = 0;int c = fgetc(stdin);
	while (c<'0' || '9'<c)c = fgetc(stdin);while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }
}
template <typename T>auto scan(T&d)->typename std::enable_if<std::is_signed<T>::value
	!= std::is_same<T, double>::value>::type {
	d = 0;int c = fgetc(stdin);bool f = 0;while (c<'0' || '9'<c)
	{
		if (c == '-')f = 1;c = fgetc(stdin);
	}while ('0' <= c&&c <= '9') { d = d * 10 + c - '0';c = fgetc(stdin); }if (f)d = -d;
}
template<typename F, typename...R>void scan(F&f, R&...r) { scan(f);scan(r...); }



int main(void) {
	uint32 a, b;
	scan(a, b);
	uint32 x = 1;
	while (x <= b)x *= 10;
	x = a*x + b;
	for (uint32 i = 0;i < 100000;++i) {
		if (i*i == x) {
			Yes(1);return 0;
		}
	}
	Yes(0);
	return 0;
}

Measured memory_bytes: 128
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::ops::Bound::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout]
fn main() {
    input! {
        n: usize, q: usize,
        tuv: [(usize, usize, usize); q]
    }

    let mut uft = UFT::new(n);
    
    for (t, u, v) in tuv {
        match t {
            0 => uft.merge(u, v),
            1 => {
                let res = (uft.root(u) == uft.root(v)) as u32;
                println!("{}", res);
            }
            _ => unreachable!()
        }
    }
}

#[allow(dead_code)]
/// Union Find Tree
pub struct UFT {
    pub par: Vec<usize>,
    pub rank: Vec<usize>,
}
impl UFT {
    #[allow(dead_code)]
    pub fn new(n: usize) -> Self {
        UFT {
            par: (0..n).collect(),
            rank: vec![0; n],
        }
    }
    #[allow(dead_code)]
    pub fn root(&mut self, x: usize) -> usize {
        if self.par[x] == x {
            x
        } else {
            let p = self.par[x];
            let pp = self.root(p);
            self.par[x] = pp;
            pp
        }
    }
    #[allow(dead_code)]
    pub fn merge(&mut self, x: usize, y: usize) {
        let x = self.root(x);
        let y = self.root(y);
        if x == y {
            return;
        }
        if self.rank[x] < self.rank[y] {
            self.par[x] = y;
        } else {
            self.par[y] = x;
            if self.rank[x] == self.rank[y] {
                self.rank[x] += 1;
            }
        }
    }
}

Measured memory_bytes: 10920
#include<stdio.h>

int n,A[21];

int solve(int i, int m){
	int res;
	if(m == 0) return 1;
	if(i >= n) return 0;
	res = solve(i+1, m) || solve(i+1, m-A[i]);
	return res;
}

int main(){
	int i,q,m,ans;
	scanf("%d",&n);
	for(i = 0; i < n; i++) scanf("%d",&A[i]);
	scanf("%d",&q);
	for(i = 0; i < q; i++){
		scanf("%d",&m);
		if(solve(0, m)) printf("yes\n");
		else printf("no\n");
		
	}
	
	return 0;
}

Measured memory_bytes: 1800
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt[3];
int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int a;
		scanf("%d",&a);
		if(a%4==0)cnt[0]++;
		else if(a%2==0)cnt[1]++;
		else cnt[2]++;
	}
	if(cnt[1]==0){
		printf("%s\n",(cnt[0]>=cnt[2]-1)?"Yes":"No");
	}else{
		printf("%s\n",(cnt[0]>=cnt[2])?"Yes":"No");
	}
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

#define TRACE
#ifdef TRACE
template<class T, class U>
ostream& operator<<(ostream& out, const pair<T,U>& a){out<<"["<<a.first<<" "<<a.second<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const vector<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T>
ostream& operator<<(ostream& out, const set<T>& a){out<<"[ ";for(auto &it:a)out<<it<<" ";out<<"]";return out;}
template<class T,class U>
ostream& operator<<(ostream& out, const map<T,U>& a){for(auto &it:a)out<<it.first<<" -> "<<it.second<<" | ";return out;}
#define pra(a,n) cerr<<#a<<" : ";for(int i=0;i<n;++i)cerr<<a[i]<<" ";cerr<<endl;
#define pr(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
} 
#else
#define pr(...)
#define pra(a,n)
#endif
#define fill(a,x) memset(a,x,sizeof(a)) 
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size()) 
#define pb push_back 
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define NOFLUSH ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const ll INF = 1e18;
const int mod = 1e9+7;
const int N = 1e5+10; 
const double eps = 1e-9;

ll expo(ll a,ll b,ll c = mod){
    if(!b)return 1;
    ll temp = expo(a,b/2,c);
    temp = (temp*temp)%c;
    if(b&1)temp = (temp*a)%c;
    return temp; 
}
int a[300];
int main(){
  
  clock_t tm = clock();
  NOFLUSH;
  int __t = 1;
  //cin >> __t;
  FOR(_t,1,__t){

      int n;cin >> n;
      FOR(i,0,2*n-1)cin >> a[i];
      sort(a,a+2*n);
      int ans = 0;
      FOR(i,0,2*n-2){
        ans += min(a[i],a[i+1]);
        i++;
      }
      cout << ans << "\n";
  }
  tm = clock()-tm ;
  cerr << (float)(tm)/CLOCKS_PER_SEC << "\n";
  return 0;
}

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

const int MAX_K = 1000;
//initialized by 0
int desire_black[MAX_K][MAX_K];
int desire_white[MAX_K][MAX_K];
int black_sum_x[MAX_K][MAX_K];
int white_sum_x[MAX_K][MAX_K];

int main() {
	int n, k;
	cin >> n >> k;
	for(int i=0;i<k;i++) for(int j=0;j<k;j++) {
		desire_black[i][j] = 0;
		desire_white[i][j] = 0;
		black_sum_x[i][j] = 0;
		white_sum_x[i][j] = 0;
	}
	for(int i=0;i<n;i++) {
		int x, y;
		char c;
		cin >> x >> y >> c;
		bool black = c == 'B';
		if((x / k + y / k) % 2 == 1) black = !black;
		if(black) {
			desire_black[x%k][y%k] += 1;
		} else {
			desire_white[x%k][y%k] += 1;
		}
	}
	for(int y=0;y<k;y++) {
		int black_sum = 0;
		int white_sum = 0;
		for(int i=0;i<k;i++) {
			black_sum += desire_black[i][y];
			white_sum += desire_white[i][y];
		}
		for(int x=0;x<k;x++) {
			black_sum_x[x][y] = black_sum;
			white_sum_x[x][y] = white_sum;
			black_sum += desire_white[x][y] - desire_black[x][y];
			white_sum += desire_black[x][y] - desire_white[x][y];
		}
	}
	int max = 0;
	for(int x=0;x<k;x++) {
		int count = 0;
		for(int i=0;i<k;i++) count += black_sum_x[x][i];
		for(int y=0;y<k;y++) {
			if(max < count) max = count;
			if(max < n - count) max = n - count;
			count += white_sum_x[x][y] - black_sum_x[x][y];
		}
	}
	cout << max << endl;
	return 0;
}


Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#define MOD 1000000007
#define INF 1 << 30

using namespace std;
typedef long long ll;

int Pow(int n, int k) {
	int i, ans = 1;
	for (i = 0; i < k; i++) {
		ans *= n;
	}
	return ans;
}

int main(void) {
	int num, i, j, ans = 0, a, b, ok;
	cin >> num;
	vector<int> l(num);
	vector<list<pair<int, int>>> d(num);
	for (i = 0; i < num; i++) {
		cin >> l[i];
		for (j = 0; j < l[i]; j++) {
			cin >> a >> b;
			d[i].push_back(make_pair(a, b));
		}
	}
	for (i = 1; i < Pow(2, num); i++) {
		ok = true;
		for (j = 0; j < num && ok; j++) {
			if (i & (1 << j)) {
				for (auto itr = d[j].begin(); itr != d[j].end(); itr++) {
					a = (*itr).first - 1;
					if ((*itr).second) {
						if (!(i & (1 << a))) {
							ok = false;
							break;
						}
					}
					else {
						if (i & (1 << a)) {
							ok = false;
							break;
						}
					}
				}
			}
		}
		if (ok) {
			a = 0;
			for (j = 1; j <= i; j <<= 1) {
				if (i & j)
					a++;
			}
			ans = max(ans, a);
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (a); i < n; i++)
#define print(x) cout << x << endl;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;

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

    cout << (N + 1) / 2 << endl;


    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
// 連続してるやつ-1 * グループ数
int main()
{
  int N; cin >> N;
  int ans = 0;
  int cnt = 0;
  FOR(i,1,N+1) {
    int in; cin >> in;
    if(in == i) cnt++;
    else {
      if(cnt == 1) ans++;
      else if(cnt % 2 == 0) ans += cnt / 2;
      else if(cnt % 2 == 1) ans += cnt / 2 + 1;
      cnt = 0;
    }
  }
  if(cnt == 1) ans++;
  else if(cnt % 2 == 0) ans += cnt / 2;
  else if(cnt % 2 == 1) ans += cnt / 2 + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a, b, c, d, N, ans=0, L, X;
    vector<int> v(3);
    int tmp=0, tmp2;
    string s, t;
    bool flag=true;
    
    cin >> s;
    cin >> t;

    if(s[0]==t[0])
	ans++;
    if(s[1]==t[1])
	ans++;

    if(s[2]==t[2])
	ans++;
    cout << ans << endl;



    // if(S[1]==S[2] &&(S[0]==S[1] | S[2]==S[3]))
    // 	cout << "Yes" <<endl;
    // else
    // 	cout << "No" <<endl;

    // string S;
    // cin >>S;
    // // cout << S + "pp"<<endl;
    // if(flag)
    // 	puts("Yes");
    // else
    // 	puts("No");
}



Measured memory_bytes: 764
using System;
using System.Linq;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NMK = Console.ReadLine().Split(' ');
            int N = int.Parse(NMK[0]);
            int M = int.Parse(NMK[1]);
            int K = int.Parse(NMK[2]);

            string[] strAs = Console.ReadLine().Split(' ');
            List<int> As = new List<int>();
            As.Add(0);
            foreach(string strA in strAs) As.Add(As.Last() + int.Parse(strA));

            string[] strBs = Console.ReadLine().Split(' ');
            List<long> Bs = new List<long>();
            Bs.Add(0);
            foreach(string strB in strBs) Bs.Add(Bs.Last() + long.Parse(strB));

            int j = M;
            int ans = 0;
            for(int i = 0; i <= N; i++) {
                if(As[i] > K) break;

                while(Bs[j] > (long)(K - As[i])) j--;
                
                ans = Math.Max(ans, i + j);
            }
            
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}


Measured memory_bytes: 72184
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=10000010, N=5010;

ll n, m, k, u, v, x, y, t, a, b, ans;
ll F[MAXN], I[MAXN];
ll dp[N];

ll powmod(ll a, ll b){
	ll res=1;
	for (; b; b>>=1, a=a*a%mod) if (b&1) res=res*a%mod;
	return res;
}

ll nCr(ll n, ll r){
	if (r<0 || r>n) return 0;
	return F[n]*I[r]%mod*I[n-r]%mod;
}

ll Count(ll n, ll m, ll k){
	return F[n+m-1]*I[n-1]%mod*F[n]%mod*F[n+m+k]%mod*I[n+m]%mod;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	F[0]=1;
	for (int i=1; i<MAXN; i++) F[i]=F[i-1]*i%mod;
	I[MAXN-1]=powmod(F[MAXN-1], mod-2);
	for (int i=MAXN-1; i; i--) I[i-1]=I[i]*i%mod;
	dp[0]=1;
	for (int n=2; n<N; n++) dp[n]=(dp[n-1] + dp[n-2])*(n-1ll)%mod;
	
	cin>>m>>n;
	for (int i=2; i<=n; i++){
		for (int t=0; t<i-1; t++){
			ll tmp=nCr(i-1, t)*Count(i-1-t, m-n, n-i)%mod;
			if (t&1) tmp*=-1;
			ans=(ans + tmp)%mod;
		}
	}
	for (int t=0; t<n; t++){
		ll tmp=nCr(n, t)*Count(n-t, m-n, 0)%mod;
		if (t&1) tmp*=-1;
		ans=(ans + tmp)%mod;
	}
	
	//debug(ans)
	if (ans<0) ans+=mod;
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 159936
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())

def binary_search(n):
    ok = n
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if (mid * 1.08) >= n:
            ok = mid
        else:
            ng = mid
    return ok

ans = binary_search(n)
if int(ans * 1.08) == n:
    print(ans)
else:
    print(':(')


Measured memory_bytes: 38588
#include<iostream>

using namespace std;

struct Cup{
  char cupname;
  int ball;
};

void init(Cup&, char, int);
void ChangeCup(char, char);
char SearchBall(void);

Cup data[3];

int main(){
  char change1, change2, z;

  init(data[0], 'A', 1);
  init(data[1], 'B', 0);
  init(data[2], 'C', 0);

  while(cin >> change1 >> z >> change2){
    ChangeCup(change1, change2);
  }
  cout << SearchBall() << endl;
  return 0;
}

void init(Cup& x, char name, int _ball){
  x.cupname = name;
  x.ball = _ball;
}

void ChangeCup(char x, char y){
  int i, n, m, copy;

  for(i=0; i<3; ++i){
    if(data[i].cupname == x)
      n = i;
    if(data[i].cupname == y)
      m = i;
  }

  copy = data[n].ball;
  data[n].ball = data[m].ball;
  data[m].ball = copy;
}

char SearchBall(void){
  for(int i=0; i<3; ++i){
    if(data[i].ball == 1)
      return data[i].cupname;
  }
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;

int main() {

    string s;
    cin >> s;
  REP(i,s.size()){
    if(s[i] == ',')s[i] = ' ';
    }



    
    cout << s << endl;
    
    



    return 0;

}


Measured memory_bytes: 256
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.IntMap as IM
import Data.List
import Control.Monad

readInput :: IO [Int]
readInput = map (either error fst . T.decimal) . T.words <$> T.getLine

main = do
  [n, m] <- readInput
  items <- readInput
  let total = foldl' (+) 0 items
  if null $ drop (m - 1) $ filter (\x -> x * m * 4 >= total) items
    then putStrLn "No"
    else putStrLn "Yes"

Measured memory_bytes: 508
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        if(a%2==0 ||b%2==0){
            System.out.println("No");
        }
        else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <utility>
#include <stdlib.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<long long> v(n);
    long long mn = (long long)(1e18);
    for(int i=0; i<n; i++) {
        cin >> v[i];
    }
    for(int i=1; i<=100; i++) {
        long long cur = 0;
        for(auto j : v) {
            cur = (cur) + ((j - i) * (j - i));
        }
        mn = min(mn, cur);
    }
    cout << mn << "\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    string s;
    cin >> s;
    int n = s.size(), cnt = 0, ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') {
            cnt++;
        } else cnt = 0;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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

int main() {
	int D, N;
	cin >> D >> N;
	if (N == 100) N ++;
	cout << N;
	for (int i = 0;i < D * 2;i ++) cout << '0';
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

100でD回割り切れるN番目の数は、N*100^D=N*10^(2D)である
よってNの後に0を必要な数だけ付ければ良い
なおN=100の時には注意が必要よ
*/

Measured memory_bytes: 256
#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;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if(a >= 13) cout << b << endl;
    else if(a >= 6) cout << b / 2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int n,m,c,s,g,p[22],q[22][55],r[22][55],cost[22][20011];
int d[22][111][111],D[111][111];

int main(){
	while(cin>>n>>m>>c>>s>>g && n){
		s--;g--;
		rep(i,c)rep(j,n)rep(k,n)d[i][j][k]=(j==k?0:INF);
		rep(i,m){
			int x,y,dd,cc;
			cin>>x>>y>>dd>>cc;
			x--;y--;cc--;
			d[cc][x][y]=min(d[cc][x][y],dd);
			d[cc][y][x]=min(d[cc][y][x],dd);
		}
		rep(i,c)cin>>p[i];
		rep(i,c){
			rep(j,p[i]-1)cin>>q[i][j];
			rep(j,p[i])cin>>r[i][j];
			q[i][p[i]-1]=INF;
		}
		rep(h,c)rep(k,n)rep(i,n)rep(j,n){
			d[h][i][j]=min(d[h][i][j],d[h][i][k]+d[h][k][j]);
		}
		rep(h,c){
			int cur=0;
			rep2(i,1,20001){
				cost[h][i]=cost[h][i-1]+r[h][cur];
				if(i==q[h][cur])cur++;
			}
		}
		rep(i,n)rep(j,n)D[i][j]=(i==j?0:INF);
		rep(h,c)rep(i,n)rep(j,n)if(d[h][i][j]<INF){
			D[i][j]=min(D[i][j],cost[h][d[h][i][j]]);
		}
		rep(k,n)rep(i,n)rep(j,n){
			D[i][j]=min(D[i][j],D[i][k]+D[k][j]);
		}
		cout<<(D[s][g]<INF?D[s][g]:-1)<<endl;
	}
}

Measured memory_bytes: 3428
#include <stdio.h>
int main(void){
    int a1,b1,c1,d1;
    int a2,b2,c2,d2;
    int S,T;
    
    scanf("%d %d %d %d",&a1,&b1,&c1,&d1);
    scanf("%d %d %d %d",&a2,&b2,&c2,&d2);

    S=a1+b1+c1+d1;
    T=a2+b2+c2+d2;
    
    if(S>T)printf("%d\n",S);
    else if(T>S)printf("%d\n",T);
    else if(S=T)printf("%d\n",S);
    
    return(0);
    
}


Measured memory_bytes: 2104
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
  int n;
  cin >> n;
  ll sum = 0;
  for (ll i = 1; i <= n; i++)
  {
    for (ll j = 1; j <= n; j++)
    {
      for (ll k = 1; k <= n; k++)
      {
        sum += gcd(gcd(i, j), k);
      }
    }
  }
  cout << sum << endl;
  return 0;
}


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

int main(){
	char str[3][3],s[9];
	int i,j,flag=0;
	
	
	while(scanf("%s",s)!=EOF){
	for(i=0;i<3;i++){
		for(j=0;j<3;j++)str[i][j]=s[j+i*3];
	}
	
	for(i=0;i<3;i++){
		if(str[0][i]=='o' && str[1][i]=='o' && str[2][i]=='o')flag=1;
		else if(str[0][i]=='x' && str[1][i]=='x' && str[2][i]=='x')flag=2;
		else if(str[i][0]=='o' && str[i][1]=='o' && str[i][2]=='o')flag=1;
		else if(str[i][0]=='x' && str[i][1]=='x' && str[i][2]=='x')flag=2;
	}
	if(str[0][0]=='o' && str[1][1]=='o' && str[2][2]=='o')flag=1;
	else if(str[0][0]=='x' && str[1][1]=='x' && str[2][2]=='x')flag=2;
	else if(str[2][0]=='o' && str[1][1]=='o' && str[0][2]=='o')flag=1;
	else if(str[2][0]=='x' && str[1][1]=='x' && str[0][2]=='x')flag=2;
	else if(flag!=1 && flag!=2)flag=0;
	
	if(flag==1)printf("o\n");
	else if(flag==2)printf("x\n");
	else if(flag==0)printf("d\n");
	flag=0;
	}
	return 0;
	
}

Measured memory_bytes: 524
#include <algorithm>
#include <bits/stdc++.h>
#include <limits>

#define ll long long
#define pi (acos(-1))
#define rep(i, n) for (unsigned long long i = 0; i < (unsigned long long)(n); ++i)
using namespace std;
std::vector<unsigned ll> genprimevec(const unsigned ll N);
int main()
{
    int n;
    cin >> n;
vector<unsigned ll> v(n);
rep(i,n){
	cin>>v[i];
}
unsigned ll ans=0;
rep(i,n){
	while(v[i]%2==0){
		v[i]/=2; ans++;
	}	
}

cout<<ans<<endl;

return 0;
}

/*author  https://qiita.com/drken/items/0c88a37eec520f82b788*/
ll extgcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0)
    {
        x = 1, y = 0;
        return a;
    }
    ll d = extgcd(b, a % b, y, x);
    y -= a / b * x;
    return d;
}


std::vector<unsigned ll> genprimevec(const unsigned ll N)
{
    std::vector<bool> is_prime(N + 1);
    for (unsigned ll i = 0; i <= N; i++) { is_prime[i] = true; }
    std::vector<unsigned ll> P;
    for (unsigned ll i = 2; i <= N; i++)
    {
        if (is_prime[i])
        {
            for (unsigned ll j = 2 * i; j <= N; j += i) { is_prime[j] = false; }
            P.emplace_back(i);
        }
    }
    return P;
}


Measured memory_bytes: 3688
#include <cstdio> 
#include <ctime> 
#include <cmath>   
#include <cstring>
#include <cstdlib>               //a = clock(); b = clock(); time = a - b;
#include <iostream>                                      
#include <map>                   //map<Type, Type>::iterator it;
#include <queue>                 //priority_queue< Type >Name
#include <stack>                 
#include <vector>                //.push_back()
#include <string>  
#include <algorithm>  
#define e 2.718281828459045      //底数
#define pi 3.141592653589793239  //high precision Π
#define swap(a, b) {int temp = a; a = b; b =temp;}
using namespace std;
typedef long long ll;            //>10^18
typedef long double ld;          //3.3621e-4932 ~ 1.18937e4932
typedef unsigned long long ull;  //>10^20
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 5;
const int INF = 0x3f3f3f3f;      
const double eps = 1e-8;         //sometimes 1e-10
inline int read(){
    int sgn = 1, cnt = 0;        //sgn表示正负号 cnt表示读取的数字
    char ch = getchar();
    while(ch < '0' || ch > '9'){ //读取非数字的字符，保留负号，忽略其余无关符号
        if(ch == '-')
            sgn = -sgn;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        cnt = cnt * 10 + (ch - '0');
        ch = getchar();
    }
    return sgn * cnt;
}
int main(int argc, char *argv[]){
	//ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);//使用后无法用scanf, printf
	int d, t, s; cin >> d >> t >> s;
	if(t * s >= d) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3628
def main():
    N=int(input())
    X=[]
    U=[]
    for i in range(N):
        x,u=input().split()
        x=float(x)
        X.append(x)
        U.append(u)

    count=0
    for i in range(N):
        if U[i]=="JPY":
            count+=X[i]
        else:
            count+=380000*X[i]
    print(count)
if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
#pragma warning (disable: 4996)

long long mod = 1000000007;
long long N, A[1 << 20], power[1 << 20];
long long dp[1 << 20];

int main() {
	scanf("%lld", &N);
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
		dp[A[i]]++;
	}
	for (int i = 0; i < 20; i++) {
		for (int j = 0; j < (1 << 20); j++) {
			if ((j & (1 << i)) != 0) dp[j - (1 << i)] += dp[j];
		}
	}
	power[0] = 1; for (int i = 1; i < (1 << 20); i++) power[i] = (2LL * power[i - 1]) % mod;

	long long sum = 0;
	for (int i = 0; i < (1 << 20); i++) {
		int cnt = 0;
		for (int j = 0; j < 20; j++) { if ((i / (1 << j)) % 2 == 1) cnt++; }
		if (cnt % 2 == 0) sum += power[dp[i]];
		else sum -= power[dp[i]];
	}
	sum += mod * mod; sum %= mod;
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 20320
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void) {
    int a, b;
    scanf("%d%d",&a,&b);
    if (1 <= a && a <= 100 && 1 <= b && b <= 100)
    printf("%d %d\n", a * b, (a + b)*2);
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
typedef long long int lli;
using namespace std;
#pragma region DEBUG
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#pragma endregion DEBUG
#define MOD 1000000007
#define MAX 500005
#define endl "\n"
lli arr[MAX];
long long binpow(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
   // freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    lli t;
    t =1 ;
    while(t--){
        int n;
        cin>>n;
        lli s1 = 0;
        lli s2 = 0;
        for(int i = 0; i<n; i++)
            cin>>arr[i];
        for(int i = 0; i<n; i++){
            s1 += arr[i]*arr[i];
            s1 %= MOD;
            s2 += arr[i];
            s2 %= MOD;
        }
        s2 *=s2;
        s2 %= MOD;
       // cout<<s2<<" "<<s1<<endl;
        lli fin = (s2-s1)*binpow(2,MOD-2,MOD);
       fin %= MOD;
        fin += MOD;
        fin %= MOD;
        cout<<fin<<endl;
        

    
    }
}

Measured memory_bytes: 5204
// ------------------------------------
// Date:2018/ 4/ 1
// Problem:A- Diverse Word a.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

string S;

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

  cin >> S;

  string ans;
  if (S.size() < 26) {
    // (S + Sで使われていない最小の文字)が辞書式配列で次にくる
    ans += S;
    map< int, int > mp;
    EACH(si, S) {
      mp[si - 97]++;
    }
    REP(i, 26) {
      if (mp[i] == 0) {
	// 使われていない文字を最後にくっつける
	ans += i + 97;
	break;
      }
    }
  } else {
    // 後ろから昇順に並んでいるものをカウントしていく
    // もし、その値が0のときは全ての文字が前から降順に並んでいることになるため,-1を出力する
    int point = 25;
    RREP(i, S.size() - 1) {
      if (S[i] < S[i + 1]) break;
      point = i;
    }

    if (point == 0) {
      // point == 0の時は全ての数字が前から降順に並んでいることになるため,
      // その文字列が辞書式最大の文字列である
      ans = "-1";
    } else {
      // 前からpoint - 1番目までの文字列に,
      // 前からpoint + 1番目の文字列のうち,最小の文字を出力すればよい
      ans = S.substr(0, point - 1);
      map< int, int > mp;
      FOR(i, point - 1, 26) {
	mp[S[i] - 97]++;
      }
      REP(i, 26) {
	if (mp[i] == 1 && i + 97 > S[point - 1]) {
	  // S[point - 1]より大きいもののうち,最小の文字をくっつける
	  ans += i + 97;
	  break;
	}
      }
    }
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
N,M=map(int,input().split())
X=[tuple(map(int,input().split())) for i in range(N)]
X.sort()
ans=0
tmp=0
for i in range(N):
    if tmp+X[i][1]>M:
        ans+=(M-tmp)*X[i][0]
        break
    ans+=X[i][0]*X[i][1]
    tmp+=X[i][1]
print(ans)

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

int main(void){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b+c >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
  return 0;
}

Measured memory_bytes: 3632
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0075
public class Main {
	static Scanner sc = new Scanner(System.in);
	static final double EPS = 1e-8;
	public static void main(String[] args) {
		while (sc.hasNext()) {
			String[] ss = sc.next().split(",");
			double a = Double.valueOf(ss[1]), b = Double.valueOf(ss[2]);
			double bmi = a / (b * b);
			if (bmi - 25.0 >= 0) 
				System.out.println(ss[0]);
		}
	}	
}

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

using namespace std;

using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    ll n, m, i, j, k;
    cin >> n;
    vector<pair<ll, ll>> vp(n);
    for(auto &x : vp) {
        cin >> x.first >> x.second;
    }
    ll T = vp[0].first, A = vp[0].second;
    for(i = 1; i < vp.size(); i++) {
        ll ok = INF/max(vp[i].first,vp[i].second), ng = 0;
        while(abs(ok - ng) > 1) {
            ll mid = (ok + ng) / 2;
            if(mid * vp[i].first >= T && mid * vp[i].second >= A) {
                ok = mid;
            } else {
                ng = mid;
            }
        }
        T = ok * vp[i].first, A = ok * vp[i].second;
        //cout << T << " " << A << endl;
    }
    cout << T + A << endl;
    return 0;
}

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

#define N_MAX 100000
#define MOD (1000000007)

using namespace std;

typedef long long int Int;

int dp[N_MAX+5];
vector<int> G[N_MAX+10];
int N,M;
int dfs(int node) {
    if(dp[node] != -1)
        return dp[node];

    int ans = 0;
    for(auto x: G[node]) {
        ans = max(ans,dfs(x)+1);
    }

    return dp[node] = ans;
}

int main(void) {
    cin>>N>>M;

    for(int i = 0;i < M;i++) {
        int from,to;
        cin>>from>>to;
        G[from].push_back(to);
    }
    memset(dp,-1,sizeof(dp));

    int ans = 0;
    for(int i = 1;i <= N;i++) {
        ans = max(ans,dfs(i));
    }

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



Measured memory_bytes: 8192
#include <vector>
#include <iostream>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
typedef long long ll;
int N, Q, x, d[100009]; ll T, a[100009];
int main() {
	scanf("%d%lld%d", &N, &T, &Q);
	for (int i = 0; i < N; i++) scanf("%lld%d", &a[i], &d[i]);
	vector<ll> v;
	for (int i = 0; i < N - 1; i++) {
		if (d[i] == 1 && d[i + 1] == 2) v.push_back((a[i] + a[i + 1]) >> 1);
	}
	for (int i = 0; i < Q; i++) {
		scanf("%d", &x); x--;
		int ptr = lower_bound(v.begin(), v.end(), a[x]) - v.begin();
		if (d[x] == 2) ptr--;
		ll e = a[x] + T * (d[x] == 1 ? 1 : -1), ret;
		if (0 <= ptr && ptr < v.size()) {
			if (d[x] == 1) ret = min(e, v[ptr]);
			else ret = max(e, v[ptr]);
		}
		else ret = e;
		printf("%lld\n", ret);
	}
	return 0;
}

Measured memory_bytes: 4392
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N;
    io.read(N);
    cout << N + (111 - N % 111) % 111;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define int long long
using namespace std;

signed main() {
	int a, b;
	cin >> a >> b;
	vector<int>c(b);
	vector<int>f(a-1);
	for (int d = 0; d < b; d++) { int g; cin >> g; g--; c[d] = g; }
	for (int e = 0; e < b - 1; e++) {
		vector<int>h(2); h[0] = c[e]; h[1] = c[e + 1];
		sort(h.begin(), h.end());
		for (int i = 0; i < a - 1; i++) {
			if (i >= h[0] && i < h[1])f[i]++;
		}
	}
	int s = 0;
	for (int i = 0; i < a - 1; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		s += min(x*f[i],z+y*f[i]);
	}
	cout << s << endl;
}

Measured memory_bytes: 4384
#include<cstdio>
#include<queue> 
#include<algorithm>
#define ll long long
using namespace std;
const int N=1e5+5;
int n,nx,ny,nz,i,v[N];
ll sum,fx[N],fy[N],ans;
struct arr{int k,x,y;}a[N];
bool operator < (arr A,arr B){return A.k>B.k;}
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
int l[N],r[N];
struct drr{int x,k;}d[N];
bool operator < (drr A,drr B){return A.k>B.k;}
void solve(ll *f,int m){
	for (i=1;i<=n;i++) d[i]=(drr){i,v[i]};
	sort(d+1,d+n+1);ll res=0;int x=d[m].x;
	for (i=1;i<=n;i++)
		l[d[i].x]=d[i-1].x,r[d[i].x]=d[i+1].x;
	for (i=1;i<=m;i++) res+=d[i].k;
	for (f[n]=res,i=n;i>m;i--){
		if (v[i]>=v[x])
			x=r[x],res+=v[x]-v[i];
		r[l[i]]=r[i];l[r[i]]=l[i];
		f[i-1]=res;
	}
}
int main(){
	nx=read();ny=read();nz=read();n=nx+ny+nz;
	for (i=1;i<=n;i++){
		int x=read(),y=read(),z=read();
		a[i]=(arr){x-y,x-z,y-z};sum+=z;
	}
	sort(a+1,a+n+1);
	for (i=1;i<=n;i++) v[i]=a[i].x;
	solve(fx,nx);
	for (i=1;i<=n;i++) v[n-i+1]=a[i].y;
	solve(fy,ny);
	for (i=nx;i<=nx+nz;i++)
		ans=max(ans,sum+fx[i]+fy[n-i]);
	printf("%lld",ans);
}

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

int main(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = 0;
    while(k--){
        if(a){
            ans++;
            a--;
        }
        else if(b) b--;
        else if(c){
            ans--;
            c--;
        }
    }
    cout << ans << endl;
}

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

ll dp[101010];

int main() {
    int N;
    cin >> N;
    vector<int> h(N);
    rep(i, N) cin >> h[i];

    dp[0] = 0;
    for (int i = 1; i < N; ++i) {
        if (i == 1) {
            dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        }
        else {
            dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
        }
    }

    cout << dp[N-1] << endl;
}


Measured memory_bytes: 1408
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007LL
#define all(x) x.begin() , x.end()

void solve()
{
	ll n, k; cin >> n >> k;
	ll arr[n]; for (auto &x : arr) cin >> x;
	vector<string>res;
	for (int i = n - 1; i - k >= 0; i--) {
		if (arr[i] > arr[i - k]) res.push_back("Yes");
		else res.push_back("No");
	}
	reverse(all(res));
	for (auto &x : res) cout << x << "\n";
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; //cin >> t;
	while (t--)
		solve();
	return 0;
}

Measured memory_bytes: 13068
import itertools as it
N = int(input())
Q = []
P = []
Q = list(map(int, input().split()))
P = list(map(int, input().split()))
Jun = []
box = [i+1 for i in range(N)]

for num in it.permutations(Q):
    num = list(num)
    Jun.append(num)
Jun = sorted(Jun)
for i, num in enumerate(Jun):
    if Q == num:
        a = i
    if P == num:
        b = i
print(abs(a-b))



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

using namespace std;

vector<vector<int>> adjacent;
vector<pair<int, int>> ans;
vector<bool>checked;

//?????????is????????????
int dfs(int now,int time) {
	ans[now].first = time;
	checked[now] = true;
	for (int i = 0; i < adjacent[now].size(); i++) 
		if (!checked[adjacent[now][i]]) time = dfs(adjacent[now][i], time + 1);
	ans[now].second = time+1;
	return time + 1;
}

int main() {
	int n,u,k,v;
	cin >> n;
	adjacent = vector<vector<int>>(n);
	checked = vector<bool>(n, false);
	ans.resize(n);

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) cin >> v,adjacent[u - 1].push_back(v-1);
	}
	int time = 1;
	for (int i = 0; i < n; i++) if (!checked[i])time = dfs(i, time)+1;
	for (int i = 0; i < n; i++) 
		cout << i + 1 << " " << ans[i].first << " " << ans[i].second << endl;
}

Measured memory_bytes: 3144
### main

loop do
  n, r = gets.split.map(&:to_i)
  break if (n | r) == 0

  cards = (1..n).to_a.reverse

  r.times do
    pn, cn = gets.split.map(&:to_i)
    pn -= 1
    cards0 = cards[pn, cn] + cards[0, pn] + cards[(pn + cn)...n]
    cards = cards0
  end

  puts cards.first
end

Measured memory_bytes: 6144
#include <iostream>
#include <utility>
#include <vector>

enum {
	Hanako = 0,
	Taro = 1
};

int main() {
	int n;
	while (std::cin >> n, n) {
		std::vector<std::pair<bool, bool>> hand(n * 2);

		for (int i = 0; i < n; ++i) {
			int c;
			std::cin >> c;
			hand[c - 1].first = Taro;
		}

		int remain[2] = { n, n };
		bool turn = Taro;
		int field = -1;

		while (remain[Taro] > 0 && remain[Hanako] > 0) {
			for (int i = field + 1; i < n * 2; ++i) {
				if (hand[i].first == turn && hand[i].second == false) {
					field = i;
					hand[i].second = true;
					--remain[turn];

					goto found;
				}
			}
			field = -1;

		found:;

			turn = !turn;
		}

		std::cout << remain[Hanako] << "\n" << remain[Taro] << std::endl;
	}
}

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


int main(){

    int X,Y;
    cin >> X >> Y;
    
    int A = (Y-X*2) / 2; int A2 = (Y-X*2) % 2;
    int B = (X*4-Y) / 2; int B2 = (X*4-Y) % 2;

    if( A2==0 && B2==0 && A>=0 && B >= 0 ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3636
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}
const int dm = 1 << 21;
char dn[dm], * di = dn;

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


	int N = getint();
	int A[500001];
	A[0] = getint();
	int d[500000];
	rep(i, N) {
		d[i] = getint();
		A[i + 1] = min(A[i], abs(d[i] - A[i]));
	}
	ll B = 1;
	for (int i = N - 1; i >= 0; i--) {
		A[i] = A[i] >= B;
		if (B << 1 > d[i]) B += d[i];
	}
	int Q = getint();
	rep(i, Q) {
		int q = getint() - 1;
		if (A[q]) {
			*di++ = 'Y';
			*di++ = 'E';
			*di++ = 'S';
			*di++ = '\n';
		}
		else {
			*di++ = 'N';
			*di++ = 'O';
			*di++ = '\n';
		}
	}

	fwrite_unlocked(dn, di - dn, 1, stdout);

	Would you please return 0;
}

Measured memory_bytes: 7552
from collections import defaultdict


def main():
    n = int(input())
    a = [int(an) for an in input().split()]
    cnt = defaultdict(int)
    for an in a:
        for val in {an - 1, an, an + 1}:
            cnt[val] += 1
    print(max(cnt.values()))


if __name__ == "__main__":
    main()


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

using namespace std;
const int MOD=1e9+7;
long long dp[1005][1005];
int n,m,a[1005][1005];
int main()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=m;j++)
    {
        char ch;
        cin>>ch;
        a[i][j]=(ch=='.'?1:0);
    }
    dp[1][1]=1;
    for(int j=2;j<=m;j++)
    {
        if (!a[1][j]) break;
        dp[1][j]=1;
    }
    for(int j=2;j<=n;j++)
    {
        if (!a[j][1]) break;
        dp[j][1]=1;
    }
    for(int i=2;i<=n;i++)
        for(int j=2;j<=m;j++)
            if (a[i][j])
                dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD;
    cout<<dp[n][m];

    return 0;
}


Measured memory_bytes: 12032
#include <stdio.h>

int N, M;
int a[271828], b[271828];

char hitotume[271828];

int main(void) {
	int i;
	int asumisu = 0; /* イエス！アスミス！ */
	if (scanf("%d%d", &N, &M) != 2) return 1;
	for (i = 0; i < M; i++) {
		if (scanf("%d%d", &a[i], &b[i]) != 2) return 1;
	}
	for (i = 0; i < M; i++) {
		if (a[i] == 1) hitotume[b[i]] = 1;
		if (b[i] == 1) hitotume[a[i]] = 1;
	}
	for (i = 0; i < M; i++) {
		if (hitotume[a[i]] && b[i] == N) asumisu = 1;
		if (hitotume[b[i]] && a[i] == N) asumisu = 1;
	}
	puts(asumisu ? "POSSIBLE" : "IMPOSSIBLE");
	return 0;
}


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

vector<long long> enum_divisor(long long n) {
    vector<long long> res;
    for (long long i = 1LL; i*i <= n; ++i) {
        if (n % i == 0) {
            res.push_back(i);
            long long j = n / i;
            if (j != i) res.push_back(j);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<long long> divisors;
    divisors = enum_divisor(M);
    sort(divisors.rbegin(), divisors.rend());
    for (int i = 0; i < divisors.size(); ++i) {
        long long x = M / divisors[i];
        if (x >= N) {
            cout << divisors[i] << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
import fractions


n,X= map(int,input().split())
x = list(map(int, input().split()))
x.append(X)
x = sorted(x)

#print(x)

difflis = [0] * (n)

for i in range(n):
    difflis[i] = x[i+1] - x[i]

ans = difflis[0]
for i in range(1,len(difflis)):
    ans = fractions.gcd(ans,difflis[i])
print(ans)

Measured memory_bytes: 16240
#include <bits/stdc++.h>
using namespace std;
 
#define SKILLER ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N=1e4, MOD = 1e9 + 7;
string s, t;
int n, m, totW;
//int w[105], v[105];
int cache[N][N];
char a[N][N];
int dp(int i, int j)
{
  if(i == n && j == m)return 1;
  if(a[i][j] != '.') return 0;
  if(cache[i][j] != -1)return cache[i][j];
  cache[i][j] = 0;
  cache[i][j] = dp(i + 1,j) + dp(i, j + 1);
  return cache[i][j]%MOD;
}

int32_t main()
{
    SKILLER
      
    memset(cache, -1, sizeof(cache));
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    int ans = dp(1,1);
   // cout<<ans<<"\n";
    cout<< ans;
    return 0;
}

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

int main()
{
	string a, b;
	cin >> a >> b;
	a += b;
	int num = stoi(a), calc;
	calc = sqrt(num);
	if(calc * calc == num)
	{
		cout << "Yes\n";
	}else
	{
		cout << "No\n";
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

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

  for(int i = 0;i < s.size();i += w){
    cout << s.substr(i,min((int)s.size() - i , w))[0];
  }

  cout << endl;
}


Measured memory_bytes: 256