akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VS ss(n);
    cin >> ss[0];
    REP(i,1,n) {
        cin >> ss[i];
        REP(j,0,i) if (ss[j] == ss[i]) {
            cout << "No" << endl;
            return;            
        }
        if (ss[i-1][ss[i-1].size()-1] != ss[i][0]) {
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   long long  int a,b=0,c=1;
    scanf("%lld",&a);
    if(a==1)
    {
        printf("1");
    }
    else
    {
       for(;a>1;)
       {
           a=a/2;
           c=c*2;
       }
       printf("%lld",c+c-1);
    }
    }


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

int main() {
	std::string S;
	std::cin >> S;
	std::vector<bool> check(26, false);
	for (char p : S) {
		check[p - 'a'] = true;
	}

	for (int i = 0; i < 26; i++) {
		if (!check[i]) {
			std::cout << char('a' + i) << std::endl;
			return 0;
		}
	}
	std::cout << "None" << std::endl;
	return 0;
}

Measured memory_bytes: 512
import Control.Applicative
import Control.Monad
import Data.Array
import Data.Array.ST
import Data.Char
import Data.List
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Printf

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
  s <- getLine
  when (s /= "-") $ do
    m <- readLn
    hs <- replicateM m readLn
    putStrLn $ solve s hs
    main

solve :: String -> [Int] -> String
solve s hs = s1 ++ s0
 where
  h = sum hs `rem` length s
  (s0, s1) = splitAt h s



Measured memory_bytes: 4088
#include <iostream>
#include <iomanip>
/*cout<<setprecision(5)<<ret<<endl;で、数字部分を計5桁表示かつゼロ埋め無*/
/*cout<<fixed<<setprecision(5)<<ret<<endlで、小数部のみ5桁表示かつゼロ埋め有*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;

typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }

/* [Shift+Command+b]（コンパイル）ー＞[Ctrl+Shift+^]（ターミナル起動）ー＞[./a.out] */


//////////////////
//  A
int main(void){
    int n,a,b;cin>>n>>a>>b;
    int ret=(b>n*a)? n*a : b;
    cout<<ret<<endl;
    return 0;
}
//////////////////
//  B
/*int main(void){

    return 0;
}*/
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
int main(void){
    string s;
    cin>>s;
    int n=s.size();
    bool ok=false;
    int L=-1,R=-1;
    if(n==2&&s[0]==s[1]){
        L=1,R=2;
    }
    for(int i=0;i<n-2;i++){
        if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i+2]==s[i]){
            L=i+1,R=i+3;
        }
    }
    cout<<L<<" "<<R<<endl;
}

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

using namespace std;

typedef long long ll;

ll mod;

ll powimod(ll x,ll n,ll mod){
    ll res=1;
    while(n){
        if(n&1) res=(res*x)%mod;
        x=(x*x)%mod;
        n>>=1;
    }
    return res;
}

ll powi(ll x,ll n){
    ll res=1;
    while(n){
        if(n&1) res*=x;
        x*=x;
        n>>=1;
    }
    return res;
}

vector<int> z_function(string s) {
    int n = (int) s.length();
    vector<int> z(n);
    for (int i = 1, l = 0, r = 0; i < n; ++i) {
        if (i <= r)
            z[i] = min (r - i + 1, z[i - l]);
        while (i + z[i] < n && s[z[i]] == s[i + z[i]])
            ++z[i];
        if (i + z[i] - 1 > r)
            l = i, r = i + z[i] - 1;
    }
    return z;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
    {
    cin>>a[i];
    }
    ll ans=1000;
    ll temp;
    for(ll i=1;i<n;i++)
    {
    if(a[i+1]>=a[i])
    {
    temp=ans/a[i];
    ans+=temp*(a[i+1]-a[i]);
    }
    }
    cout<<ans;
}


Measured memory_bytes: 3648
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
using namespace std;

int main(){
    int a,b ;
    cin >> a >> b ;
    int ans = 0 ;
    while (1)
    {
        double p = ans * 0.08 ;
        int pp = p/1 ;
        if (pp < a)
        {
            ans ++ ;
            continue;
        }else if (pp > a)
        {
            ans = -1 ;
            break ;
        }
        p = ans * 0.1 ;
        pp = p/1 ;
        if (pp == b)
        {
            break ;
        }
        
        ans ++ ;
    }
    cout << ans << endl ;
}    

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

int main() {
vector<int> v(32);
  v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int K;
  cin>>K;
  cout<<v.at(K-1)<<endl;
}


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

bool isInv(string s){
    string inv;
    inv = s;
    reverse(inv.begin(), inv.end());
    bool t = (s == inv);
    return t;
}

int main(){
    string s;
    cin >> s;
    int n;
    n = s.size();
    string left_s = s.substr(0, (n-1)/2);
    string right_s = s.substr((n+1)/2, n);

    bool all, left, right;
    all = isInv(s);
    left = isInv(left_s);
    right = isInv(right_s);
    if(all * left * right) cout << "Yes" << endl;
    else cout << "No" << endl;

}

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

int main(void){
	string c;
	string s,rslt;
	cin >> s;
	
	for(int i=0;i<s.size();++i){
		c = s.substr(i,1);

		if (c == "0"){
			rslt += "0";
		}else if(c == "1"){
			rslt += "1";
		}else if(c == "B"){
			if(rslt.size()!=0){
				rslt.erase(rslt.end()-1);
			}
		}else{
			//NOP
		}
	}

	cout << rslt << endl;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


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

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int main(){
	int N,botton[100001],next,result=1;
	cin>>N;
	FOR(i,1,N+1) cin>>botton[i];

	next=botton[1];
	while(1){
		if(result>N){
			puts("-1");
			break;
		}

		switch(next){
			case 2:
				printf("%d\n",result);
				goto exit;
			default:
				next=botton[next];
				result++;
				break;
		}
	}
exit:
	return 0;
}



Measured memory_bytes: 640
n, w = (int(x) for x in input().split())
wv = [[0, 0]]
for _ in range(n):
    wv.append([int(x) for x in input().split()])
vmax = max(wv, key=lambda x:x[1])[1]
dp = [[float('inf')] * (n * vmax + 1) for _ in range(n + 1)]
dp[0][0] = 0
for i in range(1, n + 1):
    for j in range(0, n * vmax + 1):
        if j - wv[i][1] >= 0:
            dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - wv[i][1]] + wv[i][0])
        else:
            dp[i][j] = dp[i - 1][j]
for i in range(n * vmax, -1, -1):
    if dp[n][i] <= w:
        ans = i
        break
print(ans)

Measured memory_bytes: 310680
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>

int main(void){
	int n;
	int i;
	int a[5];
	for(i = 0; i < 5; i++){
		scanf("%d",&n);
		if(n == 0) break;
			a[i] = n;
	}
	
	for(int j = 0; j < i; j++){
		int val = 1000 - a[j];
		int count = 0;
		count += val / 500;
		val -= 500 * (val / 500);
		count += val / 100;
		val -= 100 * (val / 100);
		count += val / 50;
		val -= 50 * (val / 50);
		count += val / 10;
		val -= 10 * (val / 10);
		count += val / 5;
		val -= 5 * (val / 5);
		count += val;
		
		printf("%d\n", count);
	}
	return 0;
}


Measured memory_bytes: 2600
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
typedef long long ll;
using namespace std;

int main(void){
    
    int n,i,odd=0;
    ll tmp,a[100000],sum=0,min=1000000001;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]<0){
            tmp=a[i]*-1;
            odd++;
        }
        else{
            tmp=a[i];
        }
        sum+=tmp;
        if(min>tmp){
            min=tmp;
        }
    }
    if(odd%2==1)cout<<sum-min-min<<endl;
    else cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 1024
use proconio::input;

#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::ops::*;

#[derive(Clone, Debug, Default)]
struct Struct;




//#[proconio::fastout]
fn main() {
    input! {
        a: u64,
        b: f32,
    }
    let bb = (b*100.0).round() as u64;

    println!("{}", (a*bb)/100);
}


Measured memory_bytes: 2616
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll x;
        cin >> x;
        if (x == 0) cout << 1 << endl;
        else cout << 0 << endl;
}


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

int main(){
    int A,B;
    cin >> A >> B;
    int a1,a2,a3,a4,a5;
    int sum=0;

    for(int i=A;i<=B;i++){
        a1 = i%10;
        a2 = (i%100-a1)/10;
        a3 = (i%1000-10*a2-a1)/100;
        a4 = (i%10000-100*a3-10*a2-a1)/1000;
        a5 = (i%100000-1000*a4-100*a3-10*a2-a1)/10000;

        if((a1 == a5)&&(a2==a4)) sum++;
    }
    cout << sum << endl;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	cin>>n;
	if(n==0)
		cout<<1<<endl;
	else if(n==1)
		cout<<2<<endl;
	else if(n==2)
		cout<<1<<endl;
	else
		cout<<0<<endl;
	return 0;
}


Measured memory_bytes: 3124
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    int a, b;
    cin >> a >> b;
    if( (a*b)%2 == 0 ) cout << "Even" << endl;
    else cout << "Odd" << endl;

    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    vector<bool>yon(n+1,false);
    vector<ll>ans;
    ll ansc=0;
    for(int i=n;i>=1;i--){
        int temp=0;
        for(int j=i;j<=n;j+=i){
            if(yon[j]==true)temp+=1;
    
        }
        if(temp%2==a[i])yon[i]=false;
        else {
            yon[i]=true;
            ansc+=1;
        }
    }
    cout<<ansc<<endl;
    for(int i=1;i<=n;i++){
        if(yon[i]==true)cout<<i<<endl;
    }
    
}

Measured memory_bytes: 4048
n = gets.to_i
t = h = 0
n.times {
    cards = gets.chomp.split
    if cards[0] < cards[1]
        h += 3
    elsif cards[0] > cards[1]
        t += 3
    else
        t += 1
        h += 1
    end
}
puts "#{t} #{h}"


Measured memory_bytes: 6856
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws Exception {
    try (final var stdin = new InputStreamReader(System.in);
      final var br = new BufferedReader(stdin)) {
      final var s = br.readLine();
      final var t = br.readLine();

      var count = 0;
      for (int i = 0; i < s.length(); i++) {
        if (s.charAt(i) != t.charAt(i)) {
          count++;
        }
      }

      System.out.println(count);
    }
  }
}


Measured memory_bytes: 37436
// -*- coding:utf-8-unix -*-

#[macro_use]
extern crate lazy_static;
extern crate num_bigint; // 0.2.2
extern crate num_traits; // 0.2.8
use num_bigint::BigInt;
use num_traits::Pow;

// use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
// use std::convert::TryInto;
use itertools::concat;
use lazy_static::lazy_static;
// use libm::*;
use std::cmp::*;
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::*;
use std::ops::Range;
use std::str::FromStr;
use std::sync::Mutex;
use superslice::*;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

// lazy_static! {
//     static ref H: Mutex<Vec<i32>> = Mutex::default();
//     static ref W: Mutex<Vec<i32>> = Mutex::default();
// }

const MOD: usize = 1000_000_000 + 7;

//abc147-D
// #[fastout]
fn main() {
    input![n: usize, mut a: [usize; n]];

    let mut bit_counts = Vec::new();

    for i in 0..60 {
        // eprintln!("{:?}", a);
        let mut count = 0;
        for a in a.iter_mut() {
            if *a & 1 == 1 {
                count += 1;
            }

            *a = *a >> 1;
        }

        bit_counts.push(count);
    }

    // eprintln!("{:?}", bit_counts);

    let mut ans = 0;
    let mut fac = 1;
    for (i, c) in bit_counts.iter().enumerate() {
        ans += (((fac * c) % MOD) * (n - c)) % MOD;
        ans %= MOD;

        fac *= 2;
        fac %= MOD;
    }
    println!("{}", ans);
}

// let mut values = VALUES.lock().unwrap();
// values.extend_from_slice(&[1, 2, 3, 4]);
// assert_eq!(&*values, &[1, 2, 3, 4]);


Measured memory_bytes: 9840
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()
A=one_int()

temp= N % 500
if temp>A:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<utility>
#include<queue>
using namespace std;
#define LL long long
#define MOD 1000000007

int a, b, c, d, n, m, A[10], ans = 0;
string s;

int main() {
	cin >> a >> b;
	cout << max(max(a+b,a-b),a*b) << endl;
	return 0;
}

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

using namespace std;

int N,W,v[100],w[100],dp[100][100000];

int maxval(int _d,int _w)
{
	if((_w > 0 && _d < N))
	{
		if(dp[_d][_w] != 0)
		{
			return dp[_d][_w];
		}
		else
		{
			int res1 = 0;
			if(w[_d] <= _w)
			{
				res1 = maxval(_d + 1,_w - w[_d]) + v[_d];
			}
			int res2 = maxval(_d + 1,_w);
			dp[_d][_w] = max(res1,res2);
			return max(res1,res2);
		}
	}
	else
		return 0;
}

int main(void)
{
	cin >> N >> W;
	for(int i = 0;i < N;i++)
	{
		cin >> v[i] >> w[i];
	}
	int result = maxval(0,W);
	cout << result << endl;
	return 0;
}

Measured memory_bytes: 7144
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	cout << (b - a == c - b ? "YES" : "NO") << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//using namespace std;
#define rep(i,j,n) for(ll i=(ll)(j);i<(ll)(n);i++)
#define REP(i,j,n) for(ll i=(ll)(j);i<=(ll)(n);i++)
#define per(i,j,n) for(ll i=(ll)(j);(ll)(n)<=i;i--)
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(ll)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(ll)(key)))
#define pb push_back
#define mp make_pair
#define endl "\n"
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;
using std::upper_bound;
using std::lower_bound;
using vi=vector<ll>;
using vii=vector<vi>;
using pii=pair<ll,ll>;
//const ll MOD=1e9+7;
const ll MOD=998244353;
const ll MAX=1e7;
const ll INF=(1ll<<62)-1;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
struct Binary_indexed_tree{
    int N;
    vi bit;
    Binary_indexed_tree(int n):N(n){
        bit.resize(N+1,0);
    }
    void add(int x,int a){
        for(x;x<=N;x+=(x&-x)) bit[x]+=a;
    }
    ll sum(int x){
        ll ret=0;
        for(x;x>0;x-=(x&-x)) ret+=bit[x];
        return ret;
    }
};
signed main(){
    int Q; cin>>Q;
    vi type(Q),a,b;
    rep(i,0,Q){
        cin>>type[i];
        if(type[i]==1){
            int x,y; cin>>x>>y;
            a.pb(x);
            b.pb(y);
        }
    }
    int N=a.size();
    Binary_indexed_tree number(N),index(N);
    vector<pii> Data(N);
    rep(i,0,N) Data[i]=std::mp(a[i],i);
    sort(ALL(Data));
    vi ind(N);
    rep(i,0,N) ind[Data[i].second]=i+1;
    ll sum_=0,memo=0;
    rep(i,0,Q){
        if(type[i]==1){
            index.add(ind[memo],1);
            number.add(ind[memo],a[memo]);
            sum_+=b[memo++];
        }
        else{
            int left=1,right=N;
            while(left+1<right){
                int mid=(left+right)/2;
                int cnt=index.sum(mid);
                if(cnt>=(memo+1)/2) right=mid;
                else left=mid;
            }
            ll ans=right;
            if(index.sum(left)>=(memo+1)/2) ans=left;
            cout<<Data[ans-1].first<<" ";
            if(memo%2==0){
                ll sum__=number.sum(N)-number.sum(ans)*2;
                cout<<sum_+sum__<<endl;
            }
            else{
                ll sum__=number.sum(N)-number.sum(ans)-number.sum(ans-1);
                cout<<sum_+sum__<<endl;
            }
        }
    }
}
 
 



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

signed main(){
  ios::sync_with_stdio( 0 );
  int N; cin >> N; N *= 3;
  vector< int > A( N );
  for( int i = 0; i < N; ++i ){
    cin >> A[ i ];
  }
  sort( A.begin(), A.end() );
  long long ans = 0LL;
  for( int i = N - 2, c = 0; c < N / 3; i -= 2, ++c ){
    ans += A[ i ];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=998244353;
signed main(){
    ll a,b,c,d,e;cin>>a>>b>>c>>d>>e;
    if(a==0)cout<<1<<endl;
    if(b==0)cout<<2<<endl;
    if(c==0)cout<<3<<endl;
    if(d==0)cout<<4<<endl;
    if(e==0)cout<<5<<endl;
}

Measured memory_bytes: 3560
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 99999.
       01 B PIC 99999.
       01 temp1 PIC 9999.
       01 temp2 PIC 9999.
       01 N PIC 9999.
       PROCEDURE DIVISION.
       MAIN.
       	ACCEPT INP.
      	PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM temp1.
      	MOVE INP(1:temp1) TO A.
      	ADD 2 TO temp1.
      	PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp2 - temp1.
      	MOVE INP(temp1:N) TO B.
      	COMPUTE A = A * B.
      	COMPUTE B = A / 2.
      	COMPUTE A = A - B * 2.
      	IF A = 0 THEN
      		DISPLAY "Even"
      	ELSE
      		DISPLAY "Odd"
      	END-IF.
        STOP RUN.



Measured memory_bytes: 636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

const int INF = 1 << 29;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
//
template <typename T> class ModUtil {
public:
  ModUtil(int N, T mod) : N(N), mod(mod), fact(N + 1) { calc(); }

  T get_inv(int x) { return modpow(x, mod - 2); }
  T get_fact(int n) { return fact[n]; }
  T get_inv_fact(int n) { return get_inv(fact[n]); }
  T get_P(int n, int k) {
    if (n < k)
      return 0;
    return fact[n] % mod * get_inv_fact(n - k) % mod;
  }
  T get_C(int n, int k) {
    if (n < k)
      return 0;
    return fact[n] * get_inv_fact(k) % mod * get_inv_fact(n - k) % mod;
  }
  T modpow(int a, int n) {
    if (n == 0)
      return 1;
    T res = modpow(a, n / 2);
    res *= res;
    res %= mod;
    if (n % 2)
      res *= a;
    return res % mod;
  }

private:
  vector<T> fact;
  int N;
  T mod;
  // O(N)
  void calc() {
    fact[0] = 1;
    for (int i = 1; i <= N; i++) {
      fact[i] = i * fact[i - 1] % mod;
    }
  }
};
int N;
map<int, int> deg;
int node, s, t;

int main() {
  cin >> N;
  vector<int> A(N + 1);
  ModUtil<ll> util(N + 10, MOD);
  for (int i = 0; i < N + 1; i++) {
    cin >> A[i];
    deg[A[i]]++;
    if (deg[A[i]] >= 2) {
      node = A[i];
      t = i + 1;
    }
  }
  for (int i = 0; i < N + 1; i++) {
    if (A[i] == node) {
      s = i + 1;
      break;
    }
  }
  // cerr << s << " " << t << endl;
  vector<ll> ans;
  ans.resize(N + 100);
  for (int i = 1; i <= N+1; i++) {
    ans[i] = util.get_C(N+1, i);
  }
  ans[1] = N;
  ans[N+1] = 1;

  int a = (s - 1);
  int b = (N + 1 - t);
  cerr << s << " " << t << endl;
  cerr << a << " " << b << endl;
  //a >= 1
  for (int i = 1; i <= a + b; i++){
      ans[i+1] -= util.get_C(a + b, i);
  }

  for (int i = 1; i <= N+1; i++){
      while (ans[i] < 0){
          ans[i] += MOD;
          ans[i] %= MOD;
      }
  }
  //b >= 1
  for (int i = 1; i <= N+1; i++){
      cout << ans[i] % MOD << endl;
  }

  return 0;
}


Measured memory_bytes: 7808
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n = ni()
s = ns().strip()
h = 0
minh = 0
for c in s:
    if c == "(":
        h += 1
    else:
        h -= 1
    minh = min(minh, h)
print("("*(-minh) + s + ")"*(h-minh))


Measured memory_bytes: 3060
import fractions

N = int(input())
*A, = map(int, input().split())
L = [0]*N
R = [0]*N

for i in range(0, N, 1):
    if i==0:
        L[i] = fractions.gcd(0, A[i])
        continue
    L[i] = fractions.gcd(L[i-1], A[i])

for i in range(N-1, -1, -1):
    if i==(N-1):
        R[i] = fractions.gcd(0, A[i])
        continue
    R[i] = fractions.gcd(R[i+1], A[i])

ans = 0
for i in range(0, N):
    if i==0:
        ans = max(ans, fractions.gcd(0, R[i+1]))
        continue
    if (N-1)==i:
        ans = max(ans, fractions.gcd(L[i-1], 0))
        continue
    ans = max(ans, fractions.gcd(L[i-1], R[i+1]))

print(ans)

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

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


Measured memory_bytes: 256
N,L = map(int,input().split(' '))

taste = [L+i-1 for i in range(1,N+1)]

if 0 in taste:
	print(sum(taste))
else:
	if taste[0] > 0:
		print(sum(taste[1:]))
	else:
		print(sum(taste[:-1]))


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  vector<bool> sel(4, false);
  int a, b; cin >> a >> b;
  sel[a] = true;
  sel[b] = true;
  if(!sel[1]) {
    cout << 1 << endl;
  } else if(!sel[2]) {
    cout << 2 << endl;
  } else if(!sel[3]) {
    cout << 3 << endl;
  }
  

}


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

int main() {
  int n,m,x;
  cin>>n>>m>>x;
  vector<int>a(m);
  for(int i=0;i<m;i++) cin>>a[i];
  int left=0;
  int right=0;
  for(int i=0;i<m;i++){
    if(a[i]<x) left++;
    else right++;
  }
  cout<<min(left,right)<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    int N, M, X, Y, x, y;
    cin >> N >> M >> X >> Y;
    while (N--){
        cin >> x, X = max(X, x);
    }
    while (cin >> y){
        Y = min(Y, y);
    }
    cout << (X < Y ? "No War" : "War") << endl;
}

Measured memory_bytes: 3620
import itertools
n,m,q=map(int,input().split())
l=[]
for i in range(q):
  a=list(map(int,input().split()))
  l.append(a)
#print(l)
ans=0
aa=0
for now in itertools.combinations_with_replacement(range(1,m+1), n):
  aa+=1
  ansn=0
  #print(now)
  for i in l:
    if now[i[1]-1]-now[i[0]-1]==i[2]:
      ansn+=i[3]
  #print(ansn)
  if ansn>ans:
    ans=ansn
#print(aa)
print(ans)

Measured memory_bytes: 9112
package main

import "fmt"

func main() {
	var m, d int
	fmt.Scan(&m, &d)

	ans := 0
	for i := 11; i <= d; i++ {
		d1, d2 := i%10, i/10
		if d1 == 1 || d2 == 1 {
			continue
		}
		for j := 2; j <= m; j++ {
			if j == d1*d2 {
				ans++
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x, s, y, i, j, ix, jx, iy, jy, max;
		while(true) {
			max = 0;
			x = sc.nextInt();
			y = sc.nextInt();
			s = sc.nextInt();
			if(x == 0 && y == 0 && s ==0) break;
			for(i = 1; i < s; i++) {
				for(j = 1; j < s; j++) {
					ix = ((i * 100) + (i * x)) / 100;
					jx = ((j * 100) + (j * x)) / 100;
					if(s == ix + jx) {
						iy = ((i * 100) + (i * y)) / 100;
						jy = ((j * 100) + (j * y)) / 100;
						if(max <= iy + jy) {
							max = iy + jy;
						}
					}
				}
			}
			System.out.println(max);
		}
		sc.close();
	}
}

/*
5 8 105
8 5 105
1 2 24
99 98 24
12 13 26
1 22 23
1 13 201
13 16 112
2 24 50
1 82 61
1 84 125
1 99 999
99 1 999
98 99 999
1 99 11
99 1 12
0 0 0
*/


Measured memory_bytes: 29228
n = int(input())
 
ans = []
for i in range(1, 99): # 99は適当
    if n <= 26**i:
        n -= 1
        for j in range(i):
            ans.append(chr(ord('a') + n % 26))
            n //= 26
        break
    else:
        n -= 26**i
 
print(''.join(ans[::-1]))

Measured memory_bytes: 9128
open Num

let prk ss ps f =
  let ssl = String.length ss in
  let psl = String.length ps in
  let m = (num_of_int 2) **/ (num_of_int 64) in
  let b = num_of_int 1000000007 in
  let rec pow a n =
    if n = 0 then a
    else  pow (mod_num (a */ b) m) (n-1) in
  let bb = pow (num_of_int 1) psl in
  let rh s =
    let h = ref (num_of_int 0) in
    String.iter (fun c -> h := mod_num (!h */ b +/ (num_of_int (Char.code c))) m) s; !h
  in
  let ih = rh (String.sub ss 0 psl) in
  let psh = rh ps in
  let rec loop h x =
    if h =/ psh then f x;
    if x = ssl - psl then ()
    else
      let nh = mod_num (h */ b +/ (num_of_int (Char.code ss.[x+psl])) -/ (num_of_int (Char.code ss.[x]) */ bb)) m in
      loop nh (x+1)
  in
  loop ih 0
      
let () =
  let t = read_line () in
  let p = read_line () in
  let f x = string_of_int x |> print_endline in
  try prk t p f with _ -> ()

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

int main() {
    ios::sync_with_stdio(false);
    int N, W;
    cin >> N >> W;
    int w[N + 1], v[N + 1];
    map<int, vector<int> > dict;
    for (int i = 1; i <= N; i++) {
        cin >> w[i] >> v[i];
        dict[w[i]].push_back(v[i]);
    }
    for (int i = 0; i <= 3; i++) {
        vector<int>& vect = dict[w[1] + i];
        sort(vect.begin(), vect.end(), greater<int>());                     // descending order (greedy)
    }
    int max_value = 0;
    for (int a = 0; (size_t)a <= dict[w[1]].size(); a++) {                  // 'a': qty of w1
        if (a * w[1] > W)
            break;
        int value_a = 0;
        for (int i = 0; i < a; i++)
            value_a += dict[w[1]][i];
        for (int b = 0; (size_t)b <= dict[w[1] + 1].size(); b++) {          // 'b': qty of w1+1
            if (a * w[1] + b * (w[1] + 1) > W)
                break;
            int value_b = 0;
            for (int i = 0; i < b; i++)
                value_b += dict[w[1] + 1][i];
            for (int c = 0; (size_t)c <= dict[w[1] + 2].size(); c++) {      // 'c': qty of w1+2
                if (a * w[1] + b * (w[1] + 1) + c * (w[1] + 2) > W)
                    break;
                int value_c = 0;
                for (int i = 0; i < c; i++)
                    value_c += dict[w[1] + 2][i];
                for (int d = 0; (size_t)d <= dict[w[1] + 3].size(); d++) {  // 'd': qty of w1+3
                    if (a * w[1] + b * (w[1] + 1) + c * (w[1] + 2) + d * (w[1] + 3) > W)
                        break;
                    int value_d = 0;
                    for (int i = 0; i < d; i++)
                        value_d += dict[w[1] + 3][i];
                    max_value = max(max_value, value_a + value_b + value_c + value_d);
                }
            }
        }
    }
    cout << max_value << "\n";

    return 0;
}

Measured memory_bytes: 256
import sys, math, itertools, collections, bisect 
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a, b, c = map(int, input().split())
k = int(input())
for i in range(k):
    if a >= b:
        b *= 2
    elif b >= c:
        c *= 2
if a < b and b < c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9524
#include <cstdio>
#include <vector>

using namespace std;

void Get_Val(int &Ret)
{
	Ret = 0;
	char ch;
	while (ch = getchar(), ch > '9' || ch < '0')
		;
	do
	{
		(Ret *= 10) += ch - '0';
	}
	while (ch = getchar(), ch >= '0' && ch <= '9');
}

const int Max_N(3050);
const int MOD(1000000007);
const int Add(3010);
typedef long long int LL;

inline int Mult(const int &a, const int &b)
{
	return static_cast<int>(static_cast<LL>(a) * static_cast<LL>(b) % static_cast<LL>(MOD));
}

inline void update(int &a, const int &b)
{
	((a += b) >= MOD) ? (a -= MOD) : 0;
}

struct node
{
	int l, r;
	void give(const int &_l, const int &_r)
	{
		l = _l, r = _r;
	}
};
int N, M, S0[Max_N][Max_N], S1[Max_N][Max_N], C[Max_N][Max_N], R[Max_N], Pre[Max_N];
char S[Max_N];
node V[Max_N];

void init()
{
	Get_Val(N), Get_Val(M);
	C[0][0] = 1;
	for (int i = 1;i <= N;++i)
	{
		C[i][0] = C[i][i] = 1;
		for (int j = 1;j < i;++j)
			C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	}
	scanf("%s", S + 1);
	for (int i = 0;i <= N;++i)
	{
		S0[i][i] = (S[i] == '0');
		S1[i][i] = (S[i] == '1');
		for (int j = i + 1;j <= N;++j)
		{
			S0[i][j] = S0[i][j - 1] + (S[j] == '0');
			S1[i][j] = S1[i][j - 1] + (S[j] == '1');
		}
	}
	for (int i = 1, l, r;i <= M;++i)
	{
		Get_Val(l), Get_Val(r);
		R[l] = max(R[l], r);
	}
	M = 0;
	for (int i = 1, Max = 0;i <= N;++i)
		if (R[i] > Max)
			V[++M].give(i, Max = R[i]);
}

int F[Max_N][Max_N << 1];
void dp()
{
	//首先去除所有被包含的区间
	//考虑两个相交的区间[l1, r1]和[l2, r2]，满足l1 < l2 <= r1 < r2
	//等价于可以把[l1, l2 - 1]乱排，并将[l1, l2 - 1]中的1/0与[l2, r1]中的0/1交换
	//根据此dp，F[i][j]表示dp到第i个区间，多了j个1
	F[0][0 + Add] = 1;
	for (int i = 0;i <= M - 1;++i)
		if (V[i].r < V[i + 1].l)//不相交 
		{
			for (int j = -S1[V[i].l][V[i].r];j <= S0[V[i].l][V[i].r];++j)
				update(F[i + 1][0 + Add], Mult(F[i][j + Add], C[V[i].r - V[i].l + 1][S1[V[i].l][V[i].r] + j]));
		}
		else
		{
			for (int j = -S1[V[i].l][V[i].r], s1, s0;j <= S0[V[i].l][V[i].r];++j)
			{
		 		s1 = S1[V[i].l][V[i].r] + j;
		 		s0 = (V[i].r - V[i].l + 1) - s1;
		 		for (int k = max(-s0, -S1[V[i + 1].l][V[i].r]);k <= min(s1, S0[V[i + 1].l][V[i].r]);++k)
		 			update(F[i + 1][k + Add], Mult(F[i][j + Add], C[V[i + 1].l - V[i].l][s1 - (S1[V[i + 1].l][V[i].r] + k)]));
			}
		}
	int Ans(0);
	for (int j = -S1[V[M].l][V[M].r];j <= S0[V[M].l][V[M].r];++j)
		update(Ans, Mult(F[M][j + Add], C[V[M].r - V[M].l + 1][S1[V[M].l][V[M].r] + j]));
	printf("%d", Ans);
}

int main()
{
	init();
	dp();
	return 0;
}

Measured memory_bytes: 138112
import java.util.*;

public class Main {
    private static final int MOD = 1_000_000_007;
    private static final String YES = "Yes";
    private static final String NO = "No";

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

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i=0; i<N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println(solve2(N, A));
    }

    private static int solve2(int N, int[] A) {
        int[] count = new int[1_000_001];

        for(int i = 0; i < N; i++){
            count[A[i]]++;
        }

        if (count[1] > 1) {
            return 0;
        } else if (count[1] == 1) {
            return 1;
        }

        int ans = 0;
        Arrays.sort(A);
        boolean[] visited = new boolean[1_000_001];
        for (int i=0; i<N; i++){
            if (count[A[i]] == 1 && !visited[A[i]]) ans++;
            for (int j = A[i]*2; j < visited.length; j += A[i]) {
                visited[j] = true;
            }
        }

        return ans;
    }

    private static int solve(int N, int[] A) {
        Arrays.sort(A);
        List<Integer> ans = new ArrayList();
        int dup = 0;

        check: for (int i=0; i<N; i++) {
            if (i > 0 && A[i] == A[i-1]) continue;
            if (i < N-1 && A[i] == A[i+1]) {
                dup++;
                ans.add(A[i]);
                continue;
            }

            for (int j=0; j<ans.size(); j++) {
                int val = ans.get(j);

                if (A[i]%val == 0) {
                    continue check;
                } else if (val > A[i]/2) {
                    break;
                }
            }

            ans.add(A[i]);
        }

        return ans.size() - dup;
    }

}


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

	int
main (void)
{
	auto div = [](int m, int n, int p, int q)
	{
		int mpnq = m * p + n * q;
		int mqnp = m * q - n * p;
		int mn   = m * m + n * n;
		return (mpnq % mn == 0) && (mqnp % mn == 0);
	};
	int line; cin >>line;
	while (0 < line--)
	{
		int m, n; cin >> m >> n;
		int count = 0;
		for (int p = -150; p < 150; p++)
			for (int q = -150; q < 150; q++)
			{
				if (p == 0 && q == 0)
					continue;
				if (div(p, q, m, n))
					count++;
			}
		cout << ((count == 8)? "P":"C") << endl;
	}
	return 0;
}



Measured memory_bytes: 3068
#!/usr/bin/env pytho3
n = int(input())
a = list(map(int,input().split()))
# ３種類の値をもち、自分より前に同じ色の人がa[i]となる組み合わせ
# コーナーケースとして、全部同じ色なら3通り、あとは*6したらいい
# n<=10**5
# 先頭を色１、次にa[i] == 0になった点を色2,3にしてしていい。前から埋める
# 前から見ていって、それぞれの色の今の人数をcolorとして
# color.count(a[i]) == 2　ならans *= 2, ==3 ans *= 3
# 2ケースのみRE
mod = 10**9 + 7
if a == list(range(n)): print(3)
else:
  k = 0
  ans = 6
  color = [0,0,0]
  for person in range(n):
    #print(color,person)
    bit = 0#すでにcolor == a[i]が出てきているか?
    if a[person] == 0:
      if k == 3:#REになるケース
        print(0)
        exit()
      color[k] = 1
      k += 1
      continue
    for num in range(3):
      if color[num] == a[person]:
        bit += 1
        if bit == 1:
          color[num] += 1
      if num == 2: 
        ans *= bit
        ans = ans % mod
  print(ans)


Measured memory_bytes: 53740
def resolve():
    '''
    code here
    '''
    x1, y1, x2, y2 = [int(item) for item in input().split()]

    del_x = x2 - x1
    del_y = y2 - y1

    print(x2 - del_y, y2 + del_x, x2 - del_y - del_x, y2 + del_x - del_y)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9156
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>

using namespace std;


int main()
{
	int a, b, c, x;

	cin >> a >> b >> c >> x;

	int ans = 0;


	for (int i = 0; i <= a; i++) {

		for (int j = 0; j <= b; j++) {

			for (int k = 0; k <= c; k++) {

				int total = 500 * i + 100 * j + 50 * k;

				if (total == x) {
					++ans;
				}

			}

		}

	}

	cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
signed  main()
{
  int a[5],d;
  for(int i=0;i<3;i++){
    cin>>a[i];
  }
  sort(a,a+3);
  d=abs(a[0]-a[1]);
  cout<<d+abs(a[1]-a[2])<<"\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll n;
vll a = {7, 5, 3};
ll count(ll n, ll d){
	ll res = 0, state = 1;
	REP(i, d) state *= 3;
	REP(i, state){
		ll tmp = i, num = 0, dig = 1, id;
		vll used(3);
		REP(j, d){
			id = tmp % 3;
			num += dig * (a[id]);
			used[id] = 1;
			tmp /= 3;
			dig *= 10;
		}
		if(num <= n) res += used[0] * used[1] * used[2];
	}
	return res;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> n;
	ll ans = 0;
	for(int i = 3; i <= 9; i++) ans += count(n, i);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[5];
int main(){
    int p,d=0,mx=0,i,sum=0;
    cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4];
    for(i=0;i<5;i++){
        if (a[i]%10!=0){
            d=(a[i]/10+1)*10-a[i];
            if(d>mx){
                mx=d;
                p=i;
            }
        }
    }
    for(i=0;i<5;i++){
        if(p!=i){
            if(a[i]%10!=0){
                sum+=
				(a[i]/10+1)*10;
            }
            else sum+=a[i];
        }
    }
    cout<<(sum+a[p])<<endl;
    return 0;

}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import itertools

import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

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

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

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

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

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

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

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

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = ns()
    uf = UnionFind(n + m)

    for _ in range(n):
        a = na()
        for i in range(1, a[0] + 1):
            uf.union(_, n + a[i] - 1)

    flg = True
    for i in range(1, n):
        if not uf.same(i, i - 1):
            flg = False
            break

    print("YES" if flg else "NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 33688
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>

using namespace std;

int main() {
    int N;
    int H[30];
    int counter = 1;
    cin >> N;
    for(int i = 0; i < N; i++) cin >> H[i];

    int min = H[0];
    for(int i = 1; i < N; i++) {
        if(min <= H[i]) {
            min = H[i];
            counter++;
        }
    }
    cout << counter << endl;


    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define d double
using namespace std;
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin>>n;
  int i;
  for(i=1;i<10;i++){
    if(n%i==0){
      int r=n/i;
      if(r<10&&r>=1){
        cout<<"Yes"<<endl;
        return 0;
      }
     
    }
     
  }
  cout<<"No"<<endl;
  
  return 0;
}  

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

int main(){
    string s;
    int k, i;
    cin >> k;
    cin >> s;
    if(s.length() <= k){
        cout << s << endl;
    }else{
        for(i=0; i<k; i++){
            cout << s[i];
        }
        cout << "..." << endl;
    }
    
}

Measured memory_bytes: 3628
/* Author: Dhruv Rastogi */
#include<iostream>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<ctime>
#include<string>
#include<random>
#include<ctime>
using namespace std;
#define ll long long
#define int long long
#define all(sdk) sdk.begin(),sdk.end()
#define mll map<int, int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;++i)
#define repd(i,a,b) for(int i=a;i>=b;--i)
#define mp make_pair
#define hell 1000000007
#define endl '\n'
#define vvll vector<vector<int> >
#define vll vector<int>
#define mint map<int,int> 
#define sz(x) (int)x.size()
#define sll set<int>
#define pll pair<int,int>
#define F first
#define S second
const long double PI = acos(-1.0);

void solve(){
	int p,q,r;
	cin>>p>>q>>r;
	cout<<p+q+r-max(p,max(q,r))<<endl;  
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256