akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main() {
    int N;
    cin >> N;
    int L[2*N];
    rep(i, 2*N) {
        cin >> L[i];
    } 
    sort(L, L+2*N);
    int ans = 0;

    for(int i = 0; i < 2*N; i += 2) {
        ans += L[i];
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
def check(lis,k,mid):
	for i in lis:
		if(i%mid==0):
			k+=1
		k-=(i//mid)
	return k>=0
n,k=map(int,input().split())
lis=list(map(int,input().split()))
a,b=1,max(lis)
ans=b
while(a<=b):
	mid=(a+b)//2
	if(check(lis,k,mid)):
		ans=mid
		b=mid-1
	else:
		a=mid+1
print(ans)


Measured memory_bytes: 30828
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

string s;
int n;

void check(){
    bool f=1;
    if(s[1]=='0'||s[n]=='1') f=0;
    if(f){
        rep1(i,n-1){
            if(s[i]!=s[n-i]){
                f=0;
                break;
            }
        }
    }
    if(!f){
        cout1(-1)
        exit(0);
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>s;
    n=s.size();
    s='0'+s;
    check();
    
    s[n]='1';
    int nxt=0;
    rep1(i,n-1){
        while(i>=nxt||s[nxt]=='0') nxt++;
        cout2(i,nxt)
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <numeric>
#include <cctype>
#include <tuple>
#include <iterator>
#include <bitset>
#include <random>
#include <assert.h>
#include <unordered_map>
#include <array>
#include <ctime>

#ifdef _MSC_VER
#include <agents.h>
#endif

#define FOR(i, a, b) for(int i = (a); i < (int)(b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define REV(v) v.rbegin(), v.rend()
#define MEMSET(v, s) memset(v, s, sizeof(v))
#define X first
#define Y second
#define MP make_pair
#define umap unordered_map

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> P;
typedef unsigned int uint;

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

vector<vector<int>> field;

int w, h;
void bfs(int r, int c){

	queue<P> q;
	q.push(MP(r, c));
	field[r][c] = 1;
	while (!q.empty()){
		int y = q.front().first;
		int x = q.front().second;
		q.pop();

		for (int i = 0; i < 4; ++i){
			int nx = x + dx[i], ny = y + dy[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (field[ny][nx]) continue;
			field[ny][nx] = 1;
			q.push(MP(ny, nx));
		}
	}
}

int main(){
	while (cin >> w >> h, w|h){
		int n;
		cin >> n;
		vector<int> x(n * 2), y(n * 2);
		rep(i, n * 2){
			cin >> x[i] >> y[i];
		}
		vector<int> vx = x, vy = y;
		vx.emplace_back(0), vx.emplace_back(w);
		vy.emplace_back(0), vy.emplace_back(h);
		sort(ALL(vx));
		vx.erase(unique(ALL(vx)), vx.end());
		sort(ALL(vy));
		vy.erase(unique(ALL(vy)), vy.end());

		for (auto &e : x) e = lower_bound(ALL(vx), e) - vx.begin();
		for (auto &e : y) e = lower_bound(ALL(vy), e) - vy.begin();

		w = vx.size() - 1, h = vy.size() - 1;

		field = vector<vector<int>>(h + 1, vector<int>(w + 1, 0));

		rep(i, n){
			++field[y[i * 2]][x[i * 2]];
			--field[y[i * 2 + 1]][x[i * 2]];
			--field[y[i * 2]][x[i * 2 + 1]];
			++field[y[i * 2 + 1]][x[i * 2 + 1]];
		}

		rep(i, h) rep(j, w){
			field[i + 1][j] += field[i][j];
			field[i][j + 1] += field[i][j];
			field[i + 1][j + 1] -= field[i][j];
		}

		//rep(i, h){
		//	rep(j, w) cout << field[i][j];
		//	cout << '\n';
		//} cout << '\n';
		int ans = 0;
		rep(i, h) rep(j, w){
			if (field[i][j]) continue;
			bfs(i, j);
			++ans;
		}
		cout << ans << endl;
	}


	return 0;
}

Measured memory_bytes: 3372
//package atcoder;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String [] args)  {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		if(X>=30) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		
		
		
	}
}

Measured memory_bytes: 35632
N = int(input())
a = [int(_) for _ in input().split()]

numfour = 0
numtwo = 0

for i in a:
    if i % 4 == 0:
        numfour += 1
    elif i % 2 == 0:
        numtwo += 1

if (numfour*2+1) + (numtwo//2*2) >= N:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define pi 3.1415  
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 200009
#define MOD 1000000007
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
using namespace std;
const ll INF = 1e15 + 9;
ll n,m;
vector<pii> adj[maxn];
ll dis[maxn];
ll pai[maxn];
void addedge(ll a,ll b,ll c){
    adj[a].push_back({b,c});
    adj[b].push_back({a,c});
}
void INFINITAR(){
    for(ll i=0;i<=n;i++){
        dis[i]=INF;
    }
}
void dijkstra(int x){
    INFINITAR();
    dis[x]=0;
    priority_queue<pii, vector<pii>, greater<pii> > pq;
    pq.push({0,x});
    while(!pq.empty()){
        auto f=pq.top();
        pq.pop();
        if(dis[f.second]<f.first)continue;
        for(auto e: adj[f.second]){
            if(f.first+e.second<dis[e.first]){
                pai[e.first]=f.second;
                dis[e.first]=f.first+e.second;
                pq.push({dis[e.first],e.first});
            }
        }
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin>>n>>m;
    memset(pai,-1,sizeof pai);
    while(m--){
        ll a,b;
        cin>>a>>b;
        addedge(a,b,1);
    }
    dijkstra(1);
    bool can=true;
    rep(i,2,n+1){
        if(pai[i]==-1)can=false;
    }
    if(!can){
        cout<<"No\n";
    }
    else{
        cout<<"Yes\n";
        rep(i,2,n+1)cout<<pai[i]<<'\n';
    }
    return 0;
}   

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

int main(){
  int n, a,now;
  priority_queue<int> nums;
  vector<int> nums_v;
  vector<int> nums_count(200000,0);
  long long sum=0,ans=0,b=0,count=0;
  cin >> n;
  rep(i,n){
    cin >> a;
    nums_v.push_back(a);
    nums.push(a);
  }
  now = nums.top();
  rep(i,n){
    if(nums.top() == now){
      count++;
    }else{
      nums_count.at(now) = count;
      sum += count*(count-1)/2;
      now = nums.top();
      count = 1;
    }
    nums.pop();
  }
  
  nums_count.at(now) = count;
  sum += count*(count-1)/2;
  
  
  rep(i,n){
    b = nums_count.at(nums_v.at(i));
    if(b != 0){
      ans = sum - b + 1;
    }else{
      ans = sum;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 5100
a, b= map(int, input().split())
if a > 0:
    print('Positive')
elif (a < 0 and b > 0) or a==0 or b==0:
    print('Zero')
else:
    if (abs(a) - abs(b)+1) % 2 ==0:
        print('Positive')
    else:
        print('Negative')

Measured memory_bytes: 9184
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct S{
  int number;
  int AC[10]={},WA[10]={},time=0;
  int sumAC=0;
};
bool cmp(S a,S b){
  if(a.sumAC==b.sumAC){
      if(a.time==b.time)return a.number>b.number;
      return a.time<b.time;
  }
  return a.sumAC>b.sumAC;
 
}
signed main (){
  int M,T,P,R;
  while(cin>>M>>T>>P>>R&&M){
    vector<S> v(T);
    for(int i=0;i<T;i++)v[i].number=i+1; //まずは番号を入れる
    for(int i=0;i<R;i++){
      int m,t,p,j;
      cin>>m>>t>>p>>j;
      t--;p--; //0-indexに
      if(j==0){ //正解なら
          v[t].AC[p]++;
          v[t].time+=v[t].WA[p]*20;
          v[t].time+=m;
      }
      else v[t].WA[p]++; //誤答なら
    }
    for(int i=0;i<T;i++){
      for(int j=0;j<P;j++){
        v[i].sumAC+=v[i].AC[j]; //各チームの正解数を求める
      }
    }
    sort(v.begin(),v.end(),cmp); //上で書いた比較関数cmpを使ってソート。配列の中身が強い順になる
 
    for(int i=0;i<T;i++){
      cout<<v[i].number;
      while(i+1<T&&v[i].sumAC==v[i+1].sumAC&&v[i].time==v[i+1].time){ //順位が同じ時の処理
          i++;
          cout<<'='<<v[i].number;
      }
      if(i!=T-1)cout<<','; //最後はカンマ打ちません
    }
    cout<<endl;
  }
}


Measured memory_bytes: 3076
N,M = map(int, input().split())
AB = [list(map(int, input().split())) for i in range(N)]
AB = sorted(AB)
def ans(x, y, List):
  ans = 0
  for i in range(x):
    if y > List[i][1]:
      ans = ans + List[i][0] * List[i][1]
      y = y - List[i][1]
    else:
      ans = ans + List[i][0] * y
      return(ans)
  return(ans)
print(ans(N, M, AB))

Measured memory_bytes: 28648
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e5 + 5;

int n, val = 0;
int a[N];

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		val ^= a[i];
	}
	for(int i = 1; i <= n; i++)
		cout << (val ^ a[i]) << " ";
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<char> S(10);
    string r ="YAKI";
    int i;
    int y=0;
    for(i=0;i<s.size();i++){
        S.at(i)=s.at(i);
    }
    for(i=0;i<4;i++){
        if(S.at(i)!=r.at(i)){
            y++;
        }
    }
    if(y==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>//小数点以下表示
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int k,n;
    cin>>k>>n;
    vector<int> a(n);
    rep(i,n){
        cin>>a.at(i);
    }
    int64_t distancemax=0;
    rep(i,n-1){
        int64_t dist=a.at(i+1)-a.at(i);
        distancemax=max(distancemax,dist);
    }
    int64_t b=a.at(0)+k-a.at(n-1);
    distancemax=max(distancemax,b);
    cout<<k-distancemax<<endl;
}

Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: i32,
    a: i32,
    b: i32,
  }

  puts!("{}\n", cmp::min(n * a, b));
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
int p[N],cnt;
int find(int x){
	if (x==p[x]) return x;
	return find(p[x]);
}
void Union(int x,int y){
	x=find(x);
	y=find(y);
	if (x==y) return;
	p[x]=p[y];
	cnt--;
}
int ans;
bool pa[N];
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	cnt=n;
	for (int i=1;i<=n;i++) p[i]=i;
	for (int i=1;i<=m;i++){
		int a,b;
		scanf("%d %d",&a,&b);
		Union(a,b);
	}
	printf("%d\n",cnt-1);
	return 0;
}

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

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

    if (abs(a - c) <= d || (abs(a - b) <= d && abs(b - c) <= d)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,k;
	cin>>n>>k;
		long long sum=0;

	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}

	sort(arr,arr+n,greater<int>());

	if(k>=n){
		cout<<0;
		return 0;
	}

	else {
		for(int i=k;i<n;i++){
			sum+=arr[i];
		}
	}
	cout<<sum;
	return 0;
	
	

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};


int main(){
    int n;cin >> n;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    LL ans = 0;
    for (int i = 1; i < n; i++) {
        if(a[i] < a[i-1]){
            ans += a[i-1] - a[i];
            a[i] = a[i-1];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4716
#import<iostream>
#import<atcoder/all>
using namespace std;long N,Q,i,a;main(){cin>>N>>Q;atcoder::fenwick_tree<long>b(N);for(;i<N;i++)cin>>a,b.add(i,a);while(Q--){cin>>i>>a>>N;if(i)cout<<b.sum(a,N)<<endl;else b.add(a,N);}}

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

int main(){
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    if(A+B==C+D)cout<<"Balanced"<<endl;
    else if(A+B>C+D)cout<<"Left"<<endl;
    else cout<<"Right"<<endl;
    return 0;
}


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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    string a;

    cin >> a;

    if(a.find("RRR")!=string::npos) {

        cout << 3 << '\n';

    } else if(a.find("RR")!=string::npos) {

        cout << 2 << '\n';

    } else if(a.find("R")!=string::npos) {

        cout << 1 << '\n';

    } else {

        cout << 0 << '\n';

    }

    return 0;

}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, b, e) for(auto i = (b); i != (e); i++)

int main(){
    bitset<20> x;
    int n, k;
    cin >> n >> k;
    ll e = pow(2, n);
    rep(i, 0LL, e){
        x = bitset<20>(i);
        if(x.count() == k){
            cout << i << ":";
            rep(j, 0, 20){
                if(x.test(j)){
                    cout << " " << j;
                }
            }
        cout << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3268
//
//  main.cpp
//  sum of divisor
//
//  Created by Bryan on 27/06/20.
//  Copyright © 2020 mac. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main()
{
    vector <long long> prima (10000007);
    prima[1] = 1;
    for (long long f = 1; f<=10000007;f++)
        prima[f] = f;
    for (long long f = 2; f<=10000007;f+=2)
        prima[f] = 2;
    for (long long f = 3; f*f<=10000007;f++)
    {
        if (prima[f] == f)
        {
            for (long long g = f*f;g<=10000007;g+=f)
            {
                if (prima[g] == g)
                    prima[g] = f;
            }
        }
    }
    long long sum = 0;
    long long N;
    scanf ("%lld", &N);
    for (long long f = 1; f<=N;f++)
    {
        long long faktor = 1;
        if (f == 1 )
            faktor = 1;
        else
        {
            long long small = prima[f];
            long long c = 1;
            long long j = f/small;
            while (j!=1)
            {
                if (prima[j]==small)
                    c++;
                else
                {
                    small = prima[j];
                    faktor = faktor*(c+1);
                    c = 1;
                }
                j = j/prima[j];
            }
            faktor = faktor*(c+1);
        }
        long long temp = f*faktor;
        sum +=temp;
    }
    printf ("%lld\n", sum);
}


Measured memory_bytes: 81212
-- | Main entry point to the application.
module Main where

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace
import Text.Printf

rInt :: String -> Int
rInt str = read str :: Int

-- | The main entry point.
main :: IO ()
main = do
    [s] <- (map rInt . words) <$> getLine
    printf "%d:%d:%d\n" (s `div` 3600) ((s `mod` 3600) `div` 60) (s `mod` 60)

Measured memory_bytes: 3652
D = int(input())
C = list(map(int, input().split()))
S = [list(map(int, input().split())) for _ in range(D)]
E = [-1] * 26
score = 0
for i in range(D):
    t = int(input())
    score += S[i][t-1]
    E[t-1] = i
    for j in range(26):
        score -= C[j] * (i - E[j])
    print(score)


Measured memory_bytes: 9316
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args){
        PrintWriter out = new PrintWriter(System.out);
        FastScanner sc = new FastScanner();

        int N = sc.nextInt();
        int X = sc.nextInt();
        int L[] = sc.nextIntArray(N);

        int D = 0;
        int ans = 1;
        for (int i=0;i<N;i++) {
            D += L[i];
            if (D <= X) {
                ans++;
            }
        }

        out.println(ans);
        out.flush();
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }

        int[] nextIntArray(int N) {
            int a[] = new int[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextInt();
            }

            return a;
        }

        long[] nextLongArray(int N) {
            long a[] = new long[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextLong();
            }

            return a;
        }

        double[] nextDoubleArray(int N) {
            double a[] = new double[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextDouble();
            }

            return a;
        }

        String[] nextTokenArray(int N) {
            String a[] = new String[N];
            for (int i=0;i<N;i++) {
                a[i] = this.nextToken();
            }

            return a;
        }
    }
}

Measured memory_bytes: 22868
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

prev_a = -1
ans = 0
for i_a in a:
    ans += b[i_a-1]
    if i_a - prev_a == 1:
        ans += c[prev_a-1]
    prev_a = i_a

print(ans)


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

const ll INF = 1000000000;
const int MAX_N = 1000;

int N;

void solve(){
    cin >> N;

    int ans = 1;
    while(1){
        if(ans * 2 > N) break;
        ans *= 2;
    }

    cout << ans << endl;

    return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll N;
    string S;
    cin >> N >> S;
    ll r = 0, g = 0, b = 0;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        if(S[i] == 'R') r++;
        else if(S[i] == 'G') g++;
        else b++;
    }
    ans = r*g*b;
    for(ll distance = 1; distance < N; distance++){
        for(ll i = 0; i + distance * 2 < N; i++){
            if(S[i] != S[i + distance] && S[i + distance] != S[i + 2 * distance] && S[i] != S[i + 2 * distance])
             ans--;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main(){
  int n;
  string a,b,c;cin>>n>>a>>b>>c;
  int cnt=0;
  int i=0;
  rep(i,n){
    if(b[i]!=a[i]&&b[i]!=c[i]&&a[i]!=c[i])cnt+=2;
    else if(b[i]==a[i]&&b[i]==c[i]&&a[i]==c[i])cnt+=0;
    else cnt++;
  }
  cout<<cnt<<endl;
}


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

double A,B;


signed main(){
    scanf("%lf %lf",&A,&B);
    double mini=max(A/0.08,B/0.1);
    double maxi=min((A+1.0)/0.08,(B+1.0)/0.1);
    for(int i=(int)mini;i<(int)(maxi+1);i++){
        if((int)((double)i*0.08)==A&&(int)((double)i*0.1)==B){
            printf("%lld\n",i);
            return 0;
        }
    }
    printf("%lld\n",(int)-1);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vr vector
#define pb push_back
#define watch(x) cout << (#x) << " is " << (x) << endl
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define loop(i,n) for(i=0;i<n;i++)

int main()
{
   ll k=1;
   string a,b;
   cin>>a>>b;
   for(ll i=0;i<a.size();i++)
   {
       if(a[i]!=b[i])
       {
           k=0;break;
       }

   }
   if(k==0)
    cout<<"No";
   else
    cout<<"Yes";


    cout<<endl;




    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int N=4e5+5;
struct node
{
    int k,l,r;
    node(int k=0,int l=0,int r=0):k(k),l(l),r(r){}
};
struct haha
{
    int id,v,k;
    haha(int id=0,int v=0,int k=0):id(id),v(v),k(k){}
    bool operator<(const haha&o)const
    {
        if(v==o.v) return k<o.k;
        return v<o.v;
    }
};
vector<node>vl,vr;
int n,t[N<<2],lz[N<<2],ss[N];
ll ans=0;
ll s[2][N];
void update(int l,int r,int k)
{
    t[k]-=lz[k];
    assert(t[k]>=0);
    if(l!=r)
        lz[k<<1]+=lz[k],lz[k<<1|1]+=lz[k];
    lz[k]=0;
}
int query(int l,int r,int k,int x)
{
    if(lz[k]) update(l,r,k);
    if(r<x) return 1;
    if(l>=x) return t[k];
    int m=l+r>>1;
    int ans=min(query(l,m,k<<1,x),query(m+1,r,k<<1|1,x));
    t[k]=min(t[k<<1],t[k<<1|1]);
    return ans;
}
void fix(int l,int r,int k,int x)
{
    if(lz[k]) update(l,r,k);
    if(r<x) return;
    if(l>=x)
    {
        lz[k]++;
        update(l,r,k);
        return;
    }
    int m=l+r>>1;
    fix(l,m,k<<1,x);fix(m+1,r,k<<1|1,x);
    t[k]=min(t[k<<1],t[k<<1|1]);
}
void build(int l,int r,int k)
{
    t[k]=l;lz[k]=0;
    if(l==r) return;
    int m=l+r>>1;
    build(l,m,k<<1);build(m+1,r,k<<1|1);
}
void solve(vector<node>v,int p)
{
    build(1,n,1);
    for(int i=1;i<=n;i++) ss[i]=i;
    priority_queue<haha>q;
    ll sum=0;
    for(int i=0;i<v.size();i++) sum+=v[i].r,q.push(haha(i,v[i].l-v[i].r,v[i].k));
    s[p][0]=sum;
    for(int i=1;i<=n;i++)
    {
        int l=1,r=n,pos=0;
        while(l<=r)
        {
            int m=l+r>>1;
            if(query(1,n,1,m)==0) pos=m,l=m+1;
            else r=m-1;
        }
        while(!q.empty())
        {
            int id=q.top().id;q.pop();
            if(v[id].k==0) continue;
            if(v[id].k>pos)
            {
                //cout<<pos<<' '<<v[id].l<<' '<<v[id].r<<' '<<v[id].k<<endl;
                sum=sum-v[id].r+v[id].l;
                fix(1,n,1,v[id].k);
                break;
            }
        }
        s[p][i]=max(sum,s[p][i-1]);
    }
}
fstream in,out;
void getts()
{
    int t=50;
    in.open("1.txt");
    in<<t<<endl;
    while(t--)
    {
        int n=1000;
        in<<n<<endl;
        for(int i=1;i<=n;i++)
        {
            int k=rand()%n+1,l=rand()%100+1,r=rand()%100+1;
            in<<k<<' '<<l<<' '<<r<<endl;
        }
    }
    in.close();
}
bool de=false;
int main()
{
    srand(time(0));
    //getts();freopen("1.txt","r",stdin);out.open("out.txt");de=true;
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        vl.clear();vr.clear();ans=0;
        for(int i=1;i<=n;i++)
        {
            int k,l,r;
            scanf("%d%d%d",&k,&l,&r);
            if(l==r) ans+=l;
            else if(l>r) vl.push_back({k,l,r});
            else vr.push_back({n-k,r,l});
        }
        for(int i=0;i<=n;i++) s[0][i]=s[1][i]=0;
        solve(vl,0);
        solve(vr,1);
        ll res=0;
        for(int i=0;i<=n;i++)
            res=max(res,s[0][i]+s[1][n-i]);
        if(!de) printf("%lld\n",ans+res);
        if(de) out<<ans+res<<endl;
    }
}
/*
1
5
4 65 49
4 59 67
3 66 67
4 98 68
3 32 91
*/


Measured memory_bytes: 17584
import numpy as np
[A,B,H,M] =list(map(int,input().split()))
t = H*60+M
oma = np.pi/360. #[rad/min]
omb = np.pi/30. #[rad/min]
tha  = oma * t
thb  = omb * t
tha, thb = tha%(2*np.pi),thb%(2*np.pi)
# print(tha/np.pi*180)
# print(thb/np.pi*180)
L = A**2 + B**2 - 2*A*B*np.cos(tha-thb)
L = np.sqrt(L)
print(L)

Measured memory_bytes: 27196
import java.util.*;
public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long ans =0;
        long[] nums = new long[N+1];
        for (int i = 1; i <= N; i++) {
            long  ni =N/i;
            long l = i * ni*(ni+1)/2;
            ans += l;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 116260
c,d,s="%d %d\n";
main(n,a,b){
for(;scanf("%d ",&n),n;
printf(s,c,d))
for(c=d=0;n--;){
scanf(s,&a,&b);
*(a>=b?&c:&d)+=a;
*(b>=a?&d:&c)+=b;
}
}

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

void Main() {
    // input
    int A, B, C;
    int K;
    cin >> A >> B >> C >> K;


    // translate
    int ans = 0;

    // A, B, C の順番で取れるだけ取る
    int numA = min(A, K);
    ans += 1 * numA;
    K -= numA;

    int numB = min(B, K);
    ans += 0 * numB;
    K -= numB;

    int numC = min(C, K);
    ans += -1 * numC;
    K -= numC;

    // assertion
    if (K != 0) {
        cout << "Error" << endl;
    }

    // output
    cout << ans << endl;

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int a,b,c,k;
  cin >> a >> b >> c >> k;
  int x=max({a,b,c});
  int s=1;
  for(int i=0;i<k;i++){
    s=s*2;
  }
  cout << (s-1)*x+a+b+c << endl;
}

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

using namespace std;
#define inf 1e16
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL);
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

struct person{
	int h,p;
	void read() {
		scanf("%d %d",&h,&p);
	}
};

bool cmp(person a, person b){
	return a.h + a.p < b.h + b.p;
}

const int maxn = 5e3 + 3;

ll dp[maxn][maxn]; //dp[i][j] menyatakan banyaknya minimal sum of p sampe idx i dengan banyaknya peserta yg ikut adalah j

void minim(ll &a, ll b){
	a = min(a, b);
}

int main(){
	int n,i,j;
	scanf("%d",&n);
	vector<person> a(n+1);
	for(i=1;i<=n;i++){
		a[i].read();
	}
	sort(a.begin(), a.end(), cmp);
	for(i=1;i<=n;i++){
		if(i > 1){
			for(j=1;j<i;j++){
				dp[i][j] = dp[i-1][j];
			}	
			dp[i][j] = inf;
		}else{
			for(j=1;j<=i;j++){
				dp[i][j] = inf;
			}
		}
		
		int h = a[i].h, p = a[i].p;
		// printf("h: %d p: %d\n",h,p);
		for(j=i-1;j>=0;j--){
			if(h >= dp[i][j]){
				minim(dp[i][j+1], dp[i-1][j] + p);
				// printf("masuk sini dp[%d][%d]: %lld\n",i,j+1, dp[i][j+1]);
			}
		}
	}
	int ans = 0;
	for(i=1;i<=n;i++){
		for(j=0;j<=i;j++){
			// printf("dp[%d][%d]: %lld\n",i,j,dp[i][j]);
			if(dp[i][j] != inf){
				ans = max(ans, j);
			}
		}
	}
	printf("%d\n",ans);
	return 0;
};

Measured memory_bytes: 193920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

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

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        ll b;
        cin >> b;
        if(b == 0) break;
        ll ans0, ans1;
        for(ll num = 1; num * (num+1) <= 2 * b; num++) {
            ll ok = 1;
            ll ng = 1e9 + 1;
            while(ng - ok > 1) {
                //cerr << num << " " << ok << " " << ng << endl;
                ll mid = (ok + ng) / 2;
                ll end = mid + num - 1;
                ll val = (mid + end) * num / 2;
                if(val <= b) ok = mid;
                else ng = mid;
            }
            ll end = ok + num - 1;
            ll val = (ok + end) * num / 2;
            if(val == b) {
                ans0 = ok;
                ans1 = ok + num - 1;
            }
        }
        cout << ans0 << " " << ans1 - ans0 + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <stdio.h>

int main(){
	int a, b; scanf("%d%d",&a,&b);
	if(a==1 && b==1) printf("1");
	else if(a==1 || b==1) printf("%d",a*b-2);
	else printf("%lld",((long long)a-2)*(b-2));
	return 0;
}

Measured memory_bytes: 128
import bisect
N,M = map(int,input().split())
A = []
for _ in range(N):
    a,b = map(int,input().split())
    if a<=M: A.append([a,b])
A.sort(reverse=True)
import heapq
h = []
ans = 0
for m in range(1,M+1):
    while A and A[-1][0] == m:
        heapq.heappush(h, A.pop()[1]*(-1))
    if h:
        ans -= heapq.heappop(h)
print(ans)

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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	string s, t;
	int ans = 0;
	cin >> s >> t;
	for (int i = 0; i < s.length(); ++i)
		ans += (s[i] == t[i]);
	cout << ans << '\n';
}


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

int main(){
	
	int n, W; cin >> n >> W;
	vector<int> v(n);
	vector<int> w(n);
	vector<int> m(n);
	for(int i = 0; i < n; i++) cin >> v[i] >> w[i] >> m[i];

	vector<int> dp(W + 1, 0);
	for(int i = 0; i < n; i++){

		//take key goods each
		for(int k = 0; m[i] > 0; k++){
			int key = min(m[i], (int)(1<<k));
			m[i] -= key;
			for(int j = W; j >= 0; j--){
				if(j + key * w[i] <= W) dp[j + key * w[i]] = max(dp[j + key * w[i]], dp[j] + key * v[i]);
			}
		}
	}

	int ans = 0;
	for(int j = 0; j <= W; j++) ans = max(ans, dp[j]);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <vector>
using namespace std;
//---------------------------------------
string henkan(string inp); //??§??????????°???????
//---------------------------------------

int main(void)
{
	string w, t;  //????????°??¶_s, ??????????????????p
	int answer = 0;
	
	cin >> w;  //???????????????
	w = henkan(w);
	
	while(t != "END_OF_TEXT"){ 
		cin >> t; //t??????????????????
		string t_copy;
		t_copy = henkan(t);
		if(w == t_copy){
			answer++;
		}
	}
	cout << answer << endl;
	
	return 0;
}

//----------------------------------
string henkan(string inp)
{	
	int len = inp.size(); //= inp.length();
	
	for(int i = 0; i < len; i++){
		if(inp[i] >= 'A' && inp[i] <= 'Z'){
			inp[i] += 32;
		}
	}
	return inp;
}

Measured memory_bytes: 3152
#include <stdio.h>

int n, A[20];

int solve(int, int);

int main(){
  int q, i;
  int m[200];

  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[i]);
    if(solve(0, m[i])){
      printf("yes\n");
    }else{
      printf("no\n");
    }
  }

  return 0;
}


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;
}

Measured memory_bytes: 580
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define mod 1000000007
int main() 
{
   map<string,int>mp;
   ll n;
   cin>>n;
   for(ll i=0;i<n;i++)
   {
    string s;
    cin>>s;
    mp[s]++;

   }
   cout<<mp.size();
}


Measured memory_bytes: 19228
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;
typedef pair<int,int> P;
int a[200000],b[200000],flg[200001],f;
P pp[400000];
int main(void)
{
	int n,m,i,j;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)	scanf("%d %d",&a[i],&b[i]);
	for(i=0;i<m;i++)	{
		pp[i].first=a[i];	pp[i].second=b[i];
		pp[i+m].first=b[i];	pp[i+m].second=a[i];
	}
	for(i=1;i<=n;i++)	flg[i]=0;
	for(i=0;i<m;i++)	{
		if(a[i]==1)	flg[b[i]]=1;
	}
	sort(pp,pp+m+2);
	f=0;
	for(i=0;i<m*2;i++)	{
		if(flg[pp[i].first]==1 && pp[i].second==n)	{
			f=1;	break;
		}
	}
	if(f==1)	printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 5632
import sys, fractions

readline = sys.stdin.readline

N = int(readline())
AB = [list(map(int, readline().split())) for i in range(N)]

AB.sort(key=lambda x:x[1])

t = 0
for a, b in AB:
    t += a
    if t > b:
        print('No')
        exit(0)

print('Yes')

Measured memory_bytes: 56972
#include <stdio.h>

int main()
{
	int i, H, W, K;
	char S[12][1002];
	scanf("%d %d %d", &H, &W, &K);
	for (i = 1; i <= H; i++) scanf("%s", &(S[i][1]));
	
	int j, k, t[12], b[12], flag[12] = {}, count[12], ans = 1 << 30, tmp;
	flag[H] = 1;
	while (flag[H+1] == 0) {
		t[0] = 1;
		for (i = 0; t[i] <= H; i++) {
			count[i] = 0;
			for (b[i] = t[i]; flag[b[i]] == 0; b[i]++);
			t[i+1] = b[i] + 1;
		}
		for (j = 1, tmp = i - 1; j <= W; j++) {
			for (i = 0; t[i] <= H; i++) {
				for (k = t[i]; k <= b[i]; k++) if (S[k][j] == '1') count[i]++;
				if (count[i] > K) break;
			}
			if (t[i] <= H) {
				for (i = 0; t[i] <= H; i++) {
					count[i] = 0;
					for (k = t[i]; k <= b[i]; k++) if (S[k][j] == '1') count[i]++;
					if (count[i] > K) break;
				}
				if (t[i] <= H) break;
				else tmp++;
			}
		}
		if (j > W && tmp < ans) ans = tmp; 
		
		for (i = 1; i <= H && flag[i] == 1; i++);
		for (flag[i--] = 1; i >= 1; flag[i--] = 0);
	}
	
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1736
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <algorithm>

#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()

#define X first
#define Y second

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const int INF = 0x3fffffff;


vector<pii> edge[2][100005];
int memo[2][100005];

bool dfs(int k, int n, int v, int m[2]){
	if( memo[k%2][n] == INF ){
		memo[k%2][n] = v;
	}else{
		return ( memo[k%2][n] == v );
	}

	chmin( m[k%2], v );
	if( m[0] + m[1] < 0 ) return false;

	bool ret = true;
	for(auto t: edge[k%2][n]){
		ret &= dfs(k+1, t.X, t.Y-v, m);
	}
	return ret;
}

int main(){
	int R, C, N;
	cin >> R >> C >> N;
	rep(i,N){
		int r, c, a;
		cin >> r >> c >> a;
		r--; c--;
		edge[0][r].emplace_back(c, a);
		edge[1][c].emplace_back(r, a);
	}

	bool ans=true;
	Fill(memo, INF);
	rep(i,R) if( memo[0][i] == INF ){
		int m[2] = {INF, INF};
		ans &= dfs(0, i, 0, m);
	}

	cout << (ans?"Yes":"No") << endl;

	return 0;
}


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

typedef long long LL;
const int N = 55;
LL n, ans, a[N];

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

inline void work() {
	LL p, sum; in(n);
	for (int i = 1; i <= n; ++i) in(a[i]);
	for (;;) {
		sum = 0;
		for (int i = 1; i <= n; ++i) sum += a[i] / n;
		if (!sum) break;
		ans += sum;
		for (int i = 1; i <= n; ++i) {
			p = a[i] / n;
			a[i] += sum - p;
			a[i] -= p * n;
		}
	}
	printf("%lld\n", ans);
}

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

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

int main(){
	char c;
	int a[4][13],n,x;
	cin>>n;
	for(int i;i<4;i++) for(int j=0;j<13;j++) a[i][j]=1;
	for(int i;i<n;i++){
		cin>>c>>x;
		switch(c){
			case 'S':
				a[0][x-1]=0;
				break;
			case 'H':
				a[1][x-1]=0;
				break;
			case 'C':
				a[2][x-1]=0;
				break;
			case 'D':
				a[3][x-1]=0;
				break;
			default:
				break;
		}
	}
	for(int i=0;i<4;i++){
		for(int j=0;j<13;j++){
			if(a[i][j]){
				switch(i){
					case 0:
						cout<<"S "<<j+1<<endl;
						break;
					case 1:
						cout<<"H "<<j+1<<endl;
						break;
					case 2:
						cout<<"C "<<j+1<<endl;
						break;
					case 3:
						cout<<"D "<<j+1<<endl;
						break;
					default:
						break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3104
package main

import "fmt"

func main() {
	var s string
	fmt.Scanf("%s", &s)

	if solve(s) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func solve(s string) bool {
	sum := 0

	for _, c := range s {
		sum += int(c - '0')
	}

	return sum%9 == 0
}


Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q;
  cin >> n >> q;
  vector<int> c(n),p(q),x(q);
  vector<pair<int,int>> m(n-1);
  for(int i=0;i<n-1;i++){
    int a,b;
    cin >> a >> b;
    m[i]=make_pair(a,b);
  }
  for(int i=0;i<q;i++){
    cin >> p[i] >> x[i];
    c[p[i]-1]+=x[i];
  }
  sort(m.begin(),m.end());
  for(int i=0;i<n-1;i++){
    c[m[i].second-1]+=c[m[i].first-1];
  }
  for(int i=0;i<n;i++){
    cout << c[i] << " ";
  }
  cout << endl;
}

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

using namespace std;

void solve(void)
{
	int n, q;
	cin >> q >> n;
	vector<tuple<int, int, int>> qs;
	multiset<int> xs;
	for (int i = 0; i < q; i++)
	{
		int s, t, x;
		cin >> s >> t >> x;
		qs.push_back(make_tuple(s-x, 0, x));
		qs.push_back(make_tuple(t-x, 1, x));
	}
	sort(qs.begin(), qs.end());
	auto it = qs.begin();

	while (n--)
	{
		int d;
		cin >> d;
		while(get<0>(*it) <= d && it != qs.end())
		{
			int x = get<2>(*it);
			if (get<1>(*it))
			{
				xs.erase(xs.find(x));
			}
			else
			{
				xs.insert(x);
			}
			it++;
		}
		if (xs.empty())
		{
			cout << -1 << endl;
		}
		else
		{
			cout << *xs.begin() << endl;
		}
	}
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 16108
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}


int32_t main(){
		int a,b,k;
		cin>>a>>b>>k;
		int r = min(a,k);
		k-=r;
		a-=r;
		r = min(b,k);
		b-=r;
		cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORP(i, m, n) for(int i = m; i < n+1; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
using UnweightedGraph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const int INF = 2000000000ll;
const long double PI = acosl(-1);
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; }



int power(int a, int b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
int perm(int N, int K){
    int x=1;
    for(int i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
int factorial(int N) {return perm(N,N);}
int comb(int N,int K) {return factorial(N)/factorial(K)/factorial(N-K);}
int hcomb(int N, int K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

int isprime(int n) {
    if (n < 2) return 0;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return 0;
    }
    return 1;
}

int mystoll(string S){
    int num = 0;
    for (int i = (int) S.length()-1; i >= 0; i--){
        num += (S[i]-'0') * power(10,S.length()-1-i);
    }
    return num;
}

template<class T>
int SUM(T a) {
    int sum = 0;
    for(auto iter : a) sum += iter;
    return sum;
}

void solve(int X);

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int X;
    cin >> X;
    solve(X);
    return 0;
}

void solve(int X) {
    FOR(i,-200,200) FOR(j,-200,200) if (power(i,5)-power(j,5) == X) {
        cout << i << " " << j << endl; 
        return;
    }
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_d && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_d && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc166/abc166_d && sh submit.sh
*/


Measured memory_bytes: 3656
// AOJ 1604 Deadlock Detection
// 2018.4.18 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char str[10005];
char dp[1024][10];
int  a[10005][2], sz;

int calc(int n)
{
	int i, s, k, l, w, sw;
	char *p;

	memset(dp, 0, sizeof(dp));
	s = 0, sz = 0;
	for (p = str; *p > ' '; p++) {
		if (*p == 'u') s = 0;
		else {
			k = *p & 0xf;
			if (s) {
				if (s & (1<<k)) return 0;
				dp[s][k] = 1;
				a[sz][0] = s, a[sz++][1] = k;
			}
			s |= 1<<k;
		}
	}
 	for (l = 1; l < 1024; l++) for (w = 0; w < 10; w++) {
		if (!dp[l][w]) continue;
		sw = 1<<w;
		if (l & sw) return 0;
 
		for (i = 0; i < sz; i++) {
			if ((l & a[i][0]) == 0 && (sw & a[i][0])) {
				dp[l|a[i][0]][a[i][1]] = 1;
			}
		}
	}
	return 1;
}
 
int main()
 {
	int n;
	
	while (fgets(str, 10, stdin) && *str != '0') {
		n = atoi(str);
		fgets(str, sizeof(str), stdin);
		puts(calc(n)? "SAFE": "UNSAFE");
	}
	return 0;
}


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

#define N 500000

int count=0;

void merge(int A[], int left, int mid,int right){
  int n1=mid-left;
  int n2=right-mid;
  int i,j,k,L[N/2+2],R[N/2+2];

  for(i=0;i<n1;i++) L[i]=A[left+i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=1000000001;
  R[n2]=1000000001;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i]<= R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
  }
}

void mergesort(int A[], int left, int right){
  int mid;
  if(left+1<right){
    mid =(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}

int main(){
  int i,n,A[500000];

  scanf("%d",&n);

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

  mergesort(A,0,n);
  for(i=0;i<n;i++){
    if(i>0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 5612
#%%
n = int(input())
s = []
t = []
for i in range(n):
    a ,b = input().split()
    b = int(b)
    s.append(a)
    t.append(b)
x = input()
ind = s.index(x)

ans = 0
for i in range(ind+1, n):
    ans += t[i]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<string.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 2005;
const int Mod=1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first

int main()
{
    int a,b,c,x;
     ll sum=0;
    cin>>a>>b>>c>>x;
    for(int i=0;i<=a;i++)
    {
        for(int j=0;j<=b;j++)
        {
            for(int k=0;k<=c;k++)
            {
                if(i*500+j*100+k*50==x)
                    sum++;
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256