akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>
#include <bitset>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return; std::cout << e <<" ";}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){std::cout<< e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class... Ts> void DEBUG(T d, Ts... e){if(DEBUG_OUT == false)return;DEBUG(d);DEBUG(e...);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//FUNCTION

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec (N,0);
  int SUM = 0;
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
    SUM += vec[i];
  }
  if(SUM % 10 != 0)
  {
    cout<<SUM<<endl;
    return;
  }
  sort(ALL(vec));
  for (int i = 0; i < N; i++)
  {
    if(vec[i]%10 == 0)continue;
    cout<<SUM - vec[i]<<endl;
    return;
  }
  cout<<0<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 256
N,M,K=map(int,input().split())
fdic={}
for i in range(1,N+1):
  fdic[i]=set()  
for i in range(M):
  a,b=map(int,input().split())
  fdic[a].add(b)
  fdic[b].add(a)

blist=[]
for i in range(K):
  c,d=map(int,input().split())
  blist.append((c,d))
  
#print(fdic)
#print(blist)

dic_cluster={}
cluster_num=0
cluster_list=[0]*(N+1)

for i in range(1,N+1):
  if cluster_list[i]>0:
    continue
  else:
    cluster_num+=1
    dic_cluster[cluster_num]=set()
    visited=set()
    queue=[i]
    while(len(queue)>0):
      new_queue=set()
      for q in queue:
        cluster_list[q]=cluster_num
        dic_cluster[cluster_num].add(q)
        visited.add(q)
        nx=fdic[q]
        for n in nx:
          if not n in visited:
            new_queue.add(n)

      queue=new_queue
      #print(new_queue)
      
#print(cluster_list)
#print(dic_cluster)

candlist=[0]*(N+1)
for i in range(1,N+1):
  candlist[i]=len(dic_cluster[cluster_list[i]])-len(fdic[i])-1
for c,d in blist:
  if d in dic_cluster[cluster_list[c]]:
    candlist[c]-=1
    candlist[d]-=1
  
print(" ".join(map(str,candlist[1:])))

Measured memory_bytes: 103192
#include<iostream>

typedef long long ll;

int N;
int a[100];
ll dp[100][21];

int main()
{
	std::cin >> N;
	for( int i = 0; i != N; ++i )
		std::cin >> a[i];

	dp[0][a[0]] = 1;

	for( int i = 0; i != N - 2; ++i )
	{
		for( int j = 0; j <= 20; ++j )
		{
			if( j + a[i+1] <= 20 )
				dp[i+1][j+a[i+1]] += dp[i][j];
			if( j - a[i+1] >= 0 )
				dp[i+1][j-a[i+1]] += dp[i][j];
		}
	}

	std::cout << dp[N - 2][a[N - 1]] << std::endl;

	return 0;
}

Measured memory_bytes: 1172
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors
  
n = int(input())
count = 0
nlis = make_divisors(n)
n1lis = make_divisors(n-1)
for i in nlis:
  if i == 1:
    continue
  num = n
  while num % i == 0:
    num //= i
  num %= i
  if num == 1:
    count += 1
    
count += len(n1lis) - 1
print(count)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int ct[100005];
int n,q;
ll sum = 0;
int main(){
    scanf("%d",&n);
    for (int i = 0,x; i < n;i ++){
        scanf("%d",&x);
        ct[x]++;
        sum += x;
    }
    scanf("%d",&q);
    for (int i =0 ;i  <q;i++){
        int b,c;
        scanf("%d%d",&b,&c);
        sum += (ll)(c-b)*ct[b];
        ct[c] += ct[b];
        ct[b] = 0;
        printf("%lld\n",sum);
    }
    
}


Measured memory_bytes: 4120
#include<stdio.h>
#include<math.h>
/*
外接円の中心座標の求め方
→http://www.h6.dion.ne.jp/~jpe02_tn/ki-5.html

半径の求め方
→中心座標と、三角形のいずれかの点との距離

注意点
・全部実数
・答えは第三位まで出力、第四位は四捨五入

履歴
・rounddoubleが、与えた値が負の時におかしかったので、修正
・投下 → WA
*/

//中心座標を求める
void GetCenterPos(double x1, double y1, double x2, double y2, double x3, double y3, double *xp, double *yp){
  double a1,a2,b1,b2,c1,c2;
  a1 = 2*(x2-x1);
  b1 = 2*(y2-y1);
  c1 = x1*x1 - x2*x2 + y1*y1 - y2*y2;
  a2 = 2*(x3-x1);
  b2 = 2*(y3-y1);
  c2 = x1*x1 - x3*x3 + y1*y1 - y3*y3;
  
  *xp = (b1*c2 - b2*c1) / (a1*b2 - a2*b1);
  *yp = (c1*a2 - c2*a1) / (a1*b2 - a2*b1);
}

//入力したdouble値を小数点第n位で四捨五入する
//細かいエラーチェックは書いてない
double rounddouble(double a, int n){
  double dup = a; //計算で使う一時変数
  double adjuster = 5; //四捨五入で使う一時変数
  int i; //カウンタ変数
  
  //弟n位に5を入れた小数点をつくる
  for(i=0 ; i<n ; i++)
    adjuster /= 10;
  
  //つくった値を足して
  //→dupが負の時は引いてやらないと！
  /*dup += adjuster;*/
  if(dup<0){
    dup -= adjuster;
  }else{
    dup += adjuster;
  }
  
  //10^n倍して
  dup *= pow(10, n-1);
  
  //小数点以下を切り捨てて, 10^nで割る
  dup = (int)dup / (double)pow(10, n-1);
  
  return dup;
}

int main(){

  int i; //カウンタ変数
  int n; //データセット数
  double x1,y1,x2,y2,x3,y3; //入力中の値
  double xp,yp,r; //入力値に対する答えの値
  char line[80]; //入力行
   
  //データセット数を受け付ける
  fgets(line, sizeof(line), stdin);
  sscanf(line, "%d", &n);
  
  //データセット数だけ入力を受け付けて, 処理する
  for(i=0 ; i<n ; i++){
    fgets(line, sizeof(line), stdin);
    sscanf(line, "%lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3);
    //中心座標を求める
    GetCenterPos(x1,y1,x2,y2,x3,y3,&xp,&yp);
    //二点間の距離を求める
    r = sqrt((x1-xp)*(x1-xp) + (y1-yp)*(y1-yp));
    //表示する
    printf("%.3lf %.3lf %.3lf\n",rounddouble(xp,4), rounddouble(yp,4), rounddouble(r,4));
  }

  return 0;
}
/*
四捨五入はどうやるの？
弟n位に5を入れて、
 → 0.00...5 
5が第一位になるように乗算して、
小数点以下切り捨てて、乗算を元に戻す。

  printf("## %lf\n",dup);

  printf("##%lf %lf %lf\n",xp, yp, r);

  printf("##2 %.3lf\n",rounddouble(-100.4142,4));
  printf("##5 %.3lf\n",rounddouble(-100.4145,4));
  printf("##7 %.3lf\n",rounddouble(-100.4147,4));
  printf("##9 %.3lf\n",rounddouble(-100.4149,4));
  printf("##1 %.3lf\n",rounddouble(-100.4141,4));
  printf("##4 %.3lf\n",rounddouble(-100.4144,4));

  printf("##2 %.3lf\n",rounddouble(1.4142,4));
  printf("##5 %.3lf\n",rounddouble(1.4145,4));
  printf("##7 %.3lf\n",rounddouble(1.4147,4));
  printf("##0 %.3lf\n",rounddouble(1.4140,4));
  return;


*/

Measured memory_bytes: 708
N,K = map(int,input().split())

ans = 0

c = 0

for i in range(K+1,N+1) :
    c += 1
    d = min(N,N-(K-1))

    while d > 0 :
        ans += min(d,c)
        d -= c
        d -= K

print(ans)
    

Measured memory_bytes: 2940
while True:
	n = int(raw_input())
	if n == 0:
		break
	else:
		data = map(int, raw_input().split())

		all_sum = 0
		for i in range(n):
			all_sum += data[i]
		ave = all_sum * 1.0 / n

		bunsan_sum = 0
		for i in range(n):
			bunsan_sum += (data[i] - ave)**2
		bunsan = bunsan_sum / n

		alpha = bunsan ** 0.5

		print("{:.8f}".format(alpha))

Measured memory_bytes: 6536
use std::io::*;
use std::str::FromStr;


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


fn main() {


    let mut x = Vec::new();

    for _i in 0..3 {
        let a: i32 = read();
        x.push(a);
    }
    x.sort();


    let sum: String = x.pop().unwrap().to_string() + &x.pop().unwrap().to_string();
    let mut result: i32 = sum.parse().unwrap();
    result += x.pop().unwrap();

    println!("{}",  result);

}


Measured memory_bytes: 4352
n=input()
lst=list(map(int,input().split()))
m=sum(lst)%(10**9+7)
s=0
for i in lst:
    s=(s+i*i)%(10**9+7)
a=(m*m-s)%(10**9+7)
if a%2:print(a//2+5*10**8+4)
else:print(a//2)

Measured memory_bytes: 94184
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string r;
  r="Yes";
  string S;
  cin >> S;
  for (int i=1;i<S.size()+1;i++) {
    if (r=="No") continue;
	if (i%2==0 && S[i-1]=='R') {r="No";}
	if (i%2==1 && S[i-1]=='L') {r="No";}
  }
  cout << r << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main(){
    ll n,m; cin>>n>>m;
    vector<vector<ll>> ord(m,vector<ll>(3));
    rep(i,m){cin>>ord[i][1]>>ord[i][0]; ord[i][2]=i;}
    vector<string> res(m);
    sort(ord.begin(), ord.end());
    map<ll,ll> cnt;
    rep(i,m){
        cnt[ord[i][1]]++;
        string ans1=to_string(ord[i][1]);
        while(ans1.size()<6) ans1='0'+ans1;
        string ans2=to_string(cnt[ord[i][1]]);
        while(ans2.size()<6) ans2='0'+ans2;
        res[ord[i][2]]=ans1+ans2;
    }
    rep(i,m){
        cout<<res[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 18688
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

int n,W,H;
bool solve(vector<int> vy,vector<int> vx){
    bool a=true,b=true;
    rep(i,H) if(vy[i]<=0) a=false;
    rep(i,W) if(vx[i]<=0) b=false;
    
    if(a || b)return true;
    return false;
}

int main(){
    vector<int> vx(100001,0),vy(100001,0);

    cin>>n>>W>>H;
    rep(i,n){
        int x,y,w;
        cin>>x>>y>>w;
        vx[ max(0,x-w) ]++;
        vx[ min(W,x+w) ]--;

        vy[ max(0,y-w) ]++;
        vy[ min(H,y+w) ]--;
    }
    
    rep(i,H)vy[i+1] += vy[i];
    rep(i,W)vx[i+1] += vx[i];
    
    if( solve(vy,vx) )  cout<<"Yes"<<endl;
    else                cout<<"No"<<endl;
}

Measured memory_bytes: 2596
import io.Source.stdin

object Main {
  
  def main(args: Array[String]) {
    for ((list) <- stdin.getLines().toList.takeWhile(_ != "0 0").map(_.split(" "))) {
      val x = list(0).toInt
      val y = list(1).toInt
      if (x < y) println(s"$x $y")
      else println(s"$y $x")
    }
  }
}



Measured memory_bytes: 48732
use std::cmp::*;
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let s: Vec<char> = itr.next().unwrap().chars().collect();
    let t: Vec<char> = itr.next().unwrap().chars().collect();

    let mut dp: Vec<Vec<usize>> = vec![vec![0; t.len() + 1]; s.len() + 1];

    for i in 0..s.len() {
        for j in 0..t.len() {
            if s[i] == t[j] {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            } else {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], max(dp[i][j + 1], dp[i + 1][j]));
            }
        }
    }

    let mut si = s.len();
    let mut ti = t.len();
    let mut ans = Vec::new();
    while si != 0 && ti != 0 {
        if dp[si][ti] == dp[si][ti - 1] {
            ti -= 1;
        } else if dp[si][ti] == dp[si - 1][ti] {
            si -= 1;
        } else {
            ans.push(s[si - 1]);
            si -= 1;
            ti -= 1;
        }
    }
    let ans: String = ans.into_iter().rev().collect();
    println!("{}", ans);
}


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

using namespace std;

int A[200000];

int main(void)
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);

    int N, K;  cin >> N >> K;
    for(int i=0; i<N; i++)
        cin >> A[i];
    int lo = 0, hi = K;
    while(hi < N)
    {
        if(A[lo] < A[hi])
            cout << "Yes\n";
        else
            cout << "No\n";
        lo++;   hi++;
    }
}

Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	char rem[n][m+1];
	for (int i=0;i<n;i++){
		scanf("%s",rem[i]);
	}
	int dc[m];
	int dr[n];
	for (int i=0;i<n;i++){
		int good=0;
		for (int j=0;j<m;j++){
			if (rem[i][j]!='.'){
				good=1;
				break;
			}
		}
		dr[i]=good;
	}
	for (int i=0;i<m;i++){
		int good=0;
		for (int j=0;j<n;j++){
			if (rem[j][i]!='.'){
				good=1;
				break;
			}
		}
		dc[i]=good;
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<m&&dr[i];j++){
			if (dc[j])printf ("%c",rem[i][j]);
		}
		if (dr[i])printf ("\n");
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1ll<<60;

int main(int argc, char **argv)
{
	ll N; cin >> N;
	vector<ll> X(N), XX(N);
	for (ll i = 0; i < N; ++i) cin >> X[i], XX[i] = X[i];

	sort(XX.begin(), XX.end());
	ll left = XX[N/2-1];
	ll right = XX[N/2];

	// std::cout << "left : " << left << std::endl;
	// std::cout << "right : " << right << std::endl;

	for (ll i = 0; i < N; ++i)
	{
		if (X[i] <= left)
			std::cout << right << std::endl;
		else if (right <= X[i])
			std::cout << left << std::endl;
	}
}

Measured memory_bytes: 5376
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  REP(i,h) cin >> s[i];
  REP(i,h){
    cout << s[i] << '\n';
    cout << s[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
INF = 1e10

n = int(input())
a = list(map(int, input().split()))
flag = True
a_min = INF
ans = abs(a[-1])
for i in range(n-1):
    ans += abs(a[i])
    if a[i]<0:
        a[i] = -1*a[i]
        a[i+1] = -1*a[i+1]
    a_min = min(a_min, abs(a[i]))
a_min = min(a_min, abs(a[-1]))
if a[-1]<0:
    ans = ans - 2*a_min
print(ans)

Measured memory_bytes: 14412
n=int(input())
a=list(map(int,input().split()))
k=1
for i in range(n):
    if a[i]==0:
        print(0)
        exit()
for i in range(n):
    k*=a[i]
    if k>10**18:
        print(-1)
        exit()
print(k)

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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> michi(n);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        michi[a]++; michi[b]++;
    }

    for(int i=0; i<n; i++){
        cout << michi[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int Q = sc.nextInt();
        
        String S = sc.next();
        
        int[] dp = new int[N];
        dp[0] = 0;
        for(int i = 1; i < N; i++){
            if( S.charAt(i-1) == 'A' && S.charAt(i) == 'C' ){
                dp[i]++;
            }
            if(i != N-1) dp[i+1] = dp[i];
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < Q; i++){
            int l = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            sb.append(dp[r] - dp[l]).append("\r\n");
        }
        
        System.out.println(sb.toString());
    }
}


Measured memory_bytes: 68092
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	vector<int> v(N);
	for (int i = 0; i < N; i++) cin >> v[i];

	int ans = 0;
	for (int a = 0; a <= min(K, N); a++) {
		for (int b = 0; a + b <= min(N, K); b++) {
			vector<int> vec;
			int sum = 0;
			for (int i = 0; i < a; i++) {
				vec.push_back(v[i]);
				sum += v[i];
			}
			for (int i = 0; i < b; i++) {
				vec.push_back(v[N - 1 - i]);
				sum += v[N - 1 - i];
			}
			sort(vec.begin(), vec.end());
			int len = vec.size();
			for (int i = 0; i < min(K - a - b, len); i++) {
				if (vec[i] < 0) sum += abs(vec[i]);
			}
			ans = max(ans, sum);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 3612
import copy
import fractions

inp = input()
# inp = "314159265358979323 846264338327950288 419716939 937510582"
inp = inp.split(" ")
a = int(inp[0])
b = int(inp[1])
c = int(inp[2])
d = int(inp[3])

h = c * d // fractions.gcd(c, d)
e = int(b // c) - int((a-1) // c)
f = int(b // d) - int((a-1) // d)
g = int(b // h) - int((a-1) // h)

print((b-a+1)-(e+f-g))

Measured memory_bytes: 5120
#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<int,int> 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,r;cin >> n >> r;
    if(n <= 10) cout << r + 100 * (10 - n) << endl;
    else cout << r << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;


int main() {
	string s;
	cin >> s;
	int k;
	cin >> k;
	
	char ans = '1';
	for (int i = 0; i < k; i++) {
		if (s[i] != '1') {
			ans = s[i];
			break;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef long double db;
ll n,q;
struct ppp{ll l,r,tag,v;}tree[800005][2];
void push(ll i,ll p){
    tree[i*2][p].tag=tree[i*2+1][p].tag=tree[i][p].tag;
	tree[i*2][p].v=(tree[i*2][p].r-tree[i*2][p].l+1)*tree[i*2][p].tag;
	tree[i*2+1][p].v=(tree[i*2+1][p].r-tree[i*2+1][p].l+1)*tree[i*2+1][p].tag;
	tree[i][p].tag=0;
}
void buildtree(ll i,ll l,ll r,ll p){
	tree[i][p].l=l;tree[i][p].r=r;tree[i][p].tag=0;
	if(l==r){tree[i][p].v=n;return;}
	buildtree(i*2,l,(l+r)/2,p);
	buildtree(i*2+1,(r+l)/2+1,r,p);
	tree[i][p].v=tree[i*2][p].v+tree[i*2+1][p].v;
}
void update(ll i,ll l,ll r,ll k,ll p){
    if(tree[i][p].l>=l&&tree[i][p].r<=r){
        tree[i][p].tag=k;
		tree[i][p].v=(tree[i][p].r-tree[i][p].l+1)*k;
        return;
    }
    if(tree[i][p].tag) push(i,p);
    ll m=(tree[i][p].l+tree[i][p].r)/2;
    if(l<=m) update(i*2,l,r,k,p);
    if(r>m) update(i*2+1,l,r,k,p);
    tree[i][p].v=tree[i*2][p].v+tree[i*2+1][p].v;
}
ll query(ll i,ll l,ll r,ll p){
    if(tree[i][p].l>=l&&tree[i][p].r<=r){
        return tree[i][p].v;
    }
    if(tree[i][p].tag) push(i,p);
    ll m=(tree[i][p].r+tree[i][p].l)/2,ans=0;
    if(l<=m) ans+=query(i*2,l,r,p);
    if(r>m) ans+=query(i*2+1,l,r,p);
    return ans;
}
int main(){
    cin>>n>>q;ll ans=(n-2)*(n-2);
    buildtree(1,1,n,0);buildtree(1,1,n,1);
    update(1,n,n,1,0);update(1,n,n,1,1);
    while(q--){
        ll op,x;cin>>op>>x;
        if(op==1){
            ll v=query(1,x,x,0);
            ans-=max((ll)0,v-2);
            update(1,x,x,1,0);
            if(query(1,1,1,1)>x){
                update(1,1,v-1,x,1);
            }
        }
        else{
            ll v=query(1,x,x,1);
            ans-=max((ll)0,v-2);
            update(1,x,x,1,1);
            if(query(1,1,1,0)>x){
                update(1,1,v-1,x,0);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 36404
#include <bits/stdc++.h>
using namespace std;
#define el '\n'

int gcd(int a, int b) {
  if (!b) return a;
  return gcd(b, a%b);
}
int main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  int gle[n], gri[n];
  gle[0] = ar[0];
  gri[n-1] = ar[n-1];
  for (int i = 1; i < n; i++) {
    gle[i] = gcd(gle[i-1], ar[i]);
  }
  for (int i = n-2; i >= 0; i--) {
    gri [i] = gcd(gri[i+1], ar[i]);
  }
  int ans = 1;
  for (int i = 0; i < n; i++) {
    if (i == 0) ans = max(ans, gri[i+1]);
    else if (i == n-1) ans = max(ans, gle[i-1]);
    else ans = max(ans, gcd(gle[i-1], gri[i+1]));
  }
  cout << ans << el;
  return 0;
}

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())
#define put(a) ((cout) << (a) << (endl))
#define putf(a, n) ((cout) << (fixed) << (setprecision(n)) << (a) << (endl))
#define deg2rad(x) (((x)*PI) / (180.0))
#define rad2deg(x) (((x) * (180.0)) / PI)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;
template <class T> using vec = vector<T>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class T> static inline T gcd(T a, T b);
template <class T> static inline T lcm(T a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);
template <class T> T mod(T a, T m);

int main(int argc, char* argv[]) {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }

  set<ll> s;

  for (ll l : A) {
    if (s.count(l)) {
      s.erase(l);
      continue;
    }

    s.insert(l);
  }

  put(s.size());
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[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;
}

template <class T> inline T gcd(T a, T b) { return __gcd(a, b); }

template <class T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); }

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}

template <class T> T mod(T a, T m) { return (a % m + m) % m; }


Measured memory_bytes: 5760
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N;
    cin>>N;
    int sum=0;
    int a=0;
    for(int i=0;i<N;i++){
        int price;
        cin>>price;
        sum+=price;
        if(a<price){
            a=price;
        }
    }
    sum-=a/2;
    cout<<sum<<endl;
}


Measured memory_bytes: 256
N = int(input())
ans = []
for p in range(7, 55555, 10):
    pr, j = True, 3
    while j * j <= p:
        if p % j == 0:
            pr = False
            break
        j += 2
    if pr:
        ans.append(p)
        if len(ans) == N:
            break
print(*ans)


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

int main(){
    int n, num[100];
    cin >> n;
    
    for (int i = 0; i < n; i++) cin >> num[i];
    for (int i = n - 1; i >= 0; i--){
        if (i != n - 1) cout << " ";
        cout << num[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)

using namespace std;

int main() {
    string s;
    cin >> s;
    int l = (int)s.size();

    int h[l+1];
    h[0] = 0;
    rep (i, l) {
        if (s[i] == '/')
            h[i+1] = h[i] + 1;
        else if (s[i] == '\\')
            h[i+1] = h[i] - 1;
        else 
            h[i+1] = h[i];
    }
    /*
    rep (i,l+1) cout << h[i] << ' ';
    cout << endl;
    */
    
    vector<vector<int>> a;
    int m = -100000;
    int n = 0;
    rep (i,l+1) {
        if (m == h[i] && i != 0) {
            a.push_back({n,i,m});
            m = -100000;
        }
        if (m < h[i] || i == 0) {
            m = h[i];
            n = i;
        }
        bool flag = false;
        for (int j=i+1;j<l+1;j++) {
            if (h[j] == m) {
                flag = true;
                break;
            }
        }
        if (flag == false) m = -100000;
    }
    /*
    rep (i,(int)a.size()) {
        rep (j,3) cout << a[i][j] << ' ';
        cout << endl;
    }
    */

    vector<int> b;
    float tmp = 0;
    rep (i, (int)a.size()) {
        for (int j=a[i][0];j<a[i][1];j++) {
            tmp += a[i][2] - h[j];
            if (s[j] == '/') tmp += 1 / 2;
            else if (s[j] == '\\') tmp -= 1 / 2;
        }
        b.push_back(int(tmp));
        tmp = 0;
    }
    //rep(i,(int)b.size()) cout << b[i] << ' ';

    if ((int)b.size() != 0) {
        int i = 0;
        while (true) {
            if (b[i] == 0) {
                b.erase(b.begin() + i);
                i--;
            }
            i++;
            if (i == (int)b.size()) break;
        }
    }

    int A = 0;
    rep (i,(int)b.size()) A += b[i];
    int k = (int)b.size();

    cout << A << endl;
    cout << k;
    if (k != 0) {
        cout << ' ';
        rep (i,k - 1) {
            cout << b[i] << ' ';
        }
        cout << b[k-1] << endl;
    } else cout << endl;


}


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

int s[1000], d[1000], t[1000][1000], y[1000];
P p[100000];
int main() {
	int n, m, h, k;
	while (scanf("%d%d%d%d", &n, &m, &h, &k), n) {
		rep(i, n) {
			scanf("%d", &s[i]);
			d[i] = t[0][i] = i;
		}
		rep(i, m) {
			int a, b; scanf("%d%d", &a, &b);
			p[i] = P(b, a);
		}
		sort(p, p + m);
		int u = 0;
		for (int i = 1; i < h; i++) {
			while (p[u].first == i) {
				swap(d[p[u].second - 1], d[p[u].second]); u++;
				if (u >= m)break;
			}
			rep(j, n)t[i][j] = d[j];
		}
		rep(i, n)y[d[i]] = i;
		int Min = 0;
		rep(i, n) {
			if (d[i] < k)Min += s[i];
		}
		rep(i, m) {
			swap(d[y[t[p[i].first - 1][p[i].second - 1]]], d[y[t[p[i].first - 1][p[i].second]]]);
			int sum = 0;
			rep(i, n) {
				if (d[i] < k)sum += s[i];
			}
			Min = min(Min, sum);
			swap(d[y[t[p[i].first - 1][p[i].second - 1]]], d[y[t[p[i].first - 1][p[i].second]]]);
		}
		printf("%d\n", Min);
	}
}

Measured memory_bytes: 7848
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int n;
vector<int> a;
int rec(int ai, int cnt){
    if(cnt==n){
        return -1;
    }
    if(a[ai]==2){
        //cnt += 1;
        return cnt;
    }
    int res = rec(a[ai]-1,cnt+=1);
    return res;
}
int main() {
    cin >> n;
    a.resize(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    cout << rec(0,1) << endl;

}

Measured memory_bytes: 640
"use strict"
function main(arg) {
    var data = arg.trim().split("\n")
    var table = []
    table.push(data.shift())
    table.push(data.shift())
    table.push(data.shift())
    table = table.map(e => e.split(" ").map(Number))
    data.shift()
    data = data.map(Number)
    for (var i = 0; i <  data.length; i++) {
        for (var y = 0; y < table.length; y++) for (var x = 0; x < table[0].length; x++) {
            if (table[y][x] === data[i]) {
                table[y][x] = 0
            }
        }
    }
    if (solve(table)) {
        console.log('Yes')
    } else {
        console.log('No')
    }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

function solve(table) {
    // 横
    for (var y = 0; y < table.length; y++) {
        var sum = 0
        for (var x = 0; x < table[0].length; x++) {
            sum += table[y][x]
        }
        if (sum === 0) {
            return true
        }
    }
    // 縦
    for (var x = 0; x < table[0].length; x++) {
        var sum = 0
        for (var y = 0; y < table.length; y++) {
            sum += table[y][x]
        }
        if (sum === 0) {
            return true
        }
    }
    if ((table[0][0] + table[1][1] + table[2][2]) === 0) {
        return true
    }
    if ((table[0][2] + table[1][1] + table[2][0]) === 0) {
        return true
    }
    return false
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n;
  cin >> n;
  
  if (n >= 24) {
    cout << "0\n";
    return 0;
  }
  
  vector<int> d(n);
  for (int i = 0; i < n; i++) cin >> d.at(i);
  sort(d.begin(), d.end());
  
  vector<int> a = {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12};
  if (d == a) {
    cout << "1\n";
    return 0;
  }
  else if (n == 23) {
    cout << "0\n";
    return 0;
  }
  
  vector<int> e(n);
  for (int i = 0; i < n; i++) e.at(i) = 24 - d.at(i);
  
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> x(n);
    for (int i = 0; i < n; i++) {
      if (bit & (1 << i)) x.at(i) = d.at(i);
      else x.at(i) = e.at(i);
    }
    sort(x.begin(), x.end());
    int keep = 12;
    for (int i = 1; i < n; i++) {
      keep = min(keep, x.at(i) - x.at(i - 1));
    }
    keep = min({keep, x.front(), 24 - x.back()});
    ans = max(ans, keep);
  }
  
  cout << ans << '\n';
}

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

int main() {
	long long N;
	cin >> N;
	cout << N << ":";
	for (long long i = 2; i * i <= N; i++) {
		if (N % i == 0) cout << " " << i, N /= i, i--;
	}
	if (N != 1) cout << " " << N << endl;
}


Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#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 FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	ll n, ans = 1;
	cin >> n;
	REPO(i, n) {
		ans *= i;
		ans %= 1000000007;
	}
	cout << ans << endl;
}

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

bool is_ok(ll key, ll val) {
    if (val >= key) return true;
    
    return false;
}

int binary_search(ll key, vector<ll> &tgt) {
    int ng = -1, ok = (int)tgt.size();
    int tmp;
    do {
        tmp = (ng + ok) / 2;
        if (is_ok(key, tgt.at(tmp))) ok = tmp;
        else ng = tmp;
    } while (abs(ok - ng) != 1);
    
    return ok; 
}

int main (void) {
    int N;
    cin >> N;
    vector<vector<ll>> abc(3, vector<ll>(N));
    rep(i, 3) rep(j, N) cin >> abc.at(i).at(j);
    rep(i, 3) sort(abc.at(i).begin(), abc.at(i).end());
    
    ll ans = 0;
    rep(i, N)  {
        ll key = abc.at(1).at(i);
        ll x = binary_search(key, abc.at(0));
        ll y = binary_search(key+1, abc.at(2));
        if (x > N || y > N) continue;
        ans += (x) * (N - y);

    }
    cout << ans << endl;
}


Measured memory_bytes: 3328
#include <algorithm>
#include <cctype>
#include <complex>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::to_string;
using std::vector;
using std::set;
using std::queue;
using std::priority_queue;

using std::min;
using std::max;
using std::sort;
using std::abs;

typedef long long int ll;

const ll MOD = 1000000007;

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

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        int m = i;
        for(int j = 2; j <= m; j++){
            while(m % j == 0){
                a[j]++;
                m /= j;
            }
        }
    }

    ll ans = 1;
    for(int i = 2; i <= n; i++){
        ans *= a[i] + 1;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
using namespace std;
typedef long long LL;
#define M(a,b) memset(a,b,sizesof(a))
#define pb push_back
int a[100005];
int Min(const int &a,const int &b)
{
    return a<b?a:b;
}
int main()
{
    int n,t;
    scanf("%d%d",&n,&t);
    for (int i=1;i<=n;++i)
        scanf("%d",a+i);
    int ma=0,mi=a[1];
    int cnt=0;
    for (int i=2;i<=n;++i)
    {
        if (ma==a[i]-mi)
            ++cnt;
        if (a[i]-mi>ma)
        {
            ma=a[i]-mi;
            cnt=1;
        }
        mi=min(mi,a[i]);
    }
    printf("%d\n",cnt);
    return 0;
}


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

typedef long long ll;

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

    int n; cin >> n;
    vector<int> L(n);
    for(int i=0;i<n;i++) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int left = j + 1;
            int right = lower_bound(L.begin(),L.end(),L[i]+L[j]) - L.begin();
            ans += max(right-left,0);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
 * http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C&lang=jp
 */
import java.util.*;

class Node {
	char c;
	List<Node> childs = new LinkedList<Node>();
	boolean isRoot = false;
	boolean isTerminator = false;
	Node() {
		this.isRoot = true;
	}
	Node(char c, boolean isTerminator) {
		this.c = c;
		this.isTerminator = isTerminator;
	}
	Node get(char childChar) {
		for (Node node : childs) {
			if (node.c == childChar) return node;
		}
		return null;
	}
	Node dig(char c, boolean isTerminator) {
		Node node = get(c);
		if (node == null) {
			node = new Node(c, isTerminator);
			childs.add(node);
		}
		if (isTerminator && !node.isTerminator) node.isTerminator = true; 
		return node;
	}
	public String toString() {
		String ret = "\'" + String.valueOf(c) + "\'";
		for (Node node : childs) {
			ret += " " + node.c;
		}
		return ret;
	}
}

public class Main {
	void insert(Node root, String str) {
		char[] ca = str.toCharArray();
		Node node = root;
		for (int i = 0; i < ca.length; i++) {
			node = node.dig(ca[i], i==(ca.length-1));
		}
	}
	boolean find(Node root, String str) {
		//System.out.println("### " + str);
		char[] ca = str.toCharArray();
		//System.out.println("root: " + root.toString());
		Node node = root;
		for (int i = 0; i < ca.length; i++) {
			node = node.get(ca[i]);
			//System.out.println(ca[i] + " : " + (node != null));
			if (node == null) return false;
		}
		return node.isTerminator;
	}
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node root = new Node();
		for (int i = 0; i < n; i++) {
			String cmd = sc.next();
			String str = sc.next();
			if (cmd.equals("insert")) {
				insert(root, str);
			} else if (cmd.equals("find")) {
				if (find(root, str)) {
					System.out.println("yes");
				} else {
					System.out.println("no");
				}
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 308068
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <climits>
#include <iomanip>
#define endl "\n"
#define debug(x) cout << #x << " : " << x << endl;
#define debug2(x, y) cout << #x << " : " << x  << ", " << #y << " : " << y << endl;
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0);
typedef long long ll;
using namespace std;

const ll maxSize = 2e6;
ll parent[maxSize];
ll size_set[maxSize];
ll cnt[maxSize];

void make_set(ll v)
{
	parent[v] = v;
	size_set[v] = 1;
}

ll find(ll v)
{
	if(v == parent[v])
		return v;
	return parent[v] = find(parent[v]);	
}

void union_set(ll a, ll b)
{
	a = find(a);
	b = find(b);

	if(a != b)
	{
		if(size_set[a] > size_set[b])
			swap(a, b);
		parent[a] = b;
		size_set[b] += size_set[a];
	}
}

int main()
{
	FASTIO

	ll n, m;
	cin >> n >> m;

	for(ll i = 1; i <= n; i ++)
		make_set(i);

	for(ll i = 0; i < m; i ++)
	{
		ll a, b;
		cin >> a >> b;
		union_set(a, b);
	}

	ll maxm = 0;
	for(ll i = 1; i <= n; i ++)	
	{
		maxm = max(maxm, size_set[i]);
	}

	cout << maxm << endl;
}

Measured memory_bytes: 6792
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    
    int n = Integer.parseInt(data[0]);
    int k = Integer.parseInt(data[1]);
    
    int result = 1;
    
    for(int i=0; n/(Math.pow(k, i))>=1; i++){
      result = i+1;
    }
    System.out.println(result);
  }
}


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

int main() {
  vector<vector<int>>B(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin>>B.at(i).at(j);
    }
  }
  vector<int>I(3);
  vector<int>J(3);
  for(int i=0;i<3;i++){
    J.at(i)=B.at(0).at(i)-I.at(0);
  }
  for(int i=0;i<3;i++){
    I.at(i)=B.at(i).at(0)-J.at(0);
  }
  
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      if(I.at(i)+J.at(j)!=B.at(i).at(j)){
        cout<<"No"<< endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<< endl;
}


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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1000000001
#define INF 1410065408
#define EPS 1e-9
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);

    if(n % 2 == 0){
        rep(n){
            int tmp;
            cin >> tmp;
            if(i % 2 == 0){
                a[n/2 + i/2] = tmp;
            }else{
                a[n/2 - (i+1)/2] = tmp;
            }
        }
    }else{
        int tmp;
        cin >> tmp;
        a[(n-1)/2] = tmp;
        reppp(i, 1, n-1){
            int tmp;
            cin >> tmp;
            if(i % 2 == 0){
                a[(n-1)/2 - i/2] = tmp;
            }else{
                a[(n-1)/2 + (i+1)/2] = tmp;
            }
        }
    }
    rep(n-1){
        cout << a[i] << " ";
    }
    cout << a.back();
}

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

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

    int A[N];
    int ans = 0;

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

    for (int i = 0; i < M; i++){
        int s, c;
        cin >> s >> c;

        if (s-1 == 0 && c == 0 && N != 1){
            ans = -1;
        }
        else if (A[s-1] == 0){
            A[s-1] = c;
        }
        else if (A[s-1] == c){
            A[s-1] = c;
        }
        else {
            ans = -1;
        }
    }

    if (N == 3 && A[0] != 0 && ans == 0){
        ans = A[0] * 100 + A[1] * 10 + A[2];
    }
    else if (N == 3 && A[0] == 0 && ans == 0){
        ans = 100 + A[1] * 10 + A[2];
    }
    else if (N == 2 && A[0] != 0 && ans == 0){
        ans = A[0] * 10 + A[1];
    }
    else if (N == 2 && A[0] == 0 && ans == 0){
        ans = 10 + A[1];
    }
    else if (N == 1 && ans == 0){
        ans = A[0];
    }
    else {
        ans = -1;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var list = new Dictionary<string, int[]>();
            //var list2= new Dictionary<string, List<int>>();
            var s_rog = new List<string>();

            for(int i = 0; i < n; i++)
            {
                var data = new int[n];
                //var data2 = new int[n];
                string[] sp = Console.ReadLine().Split();
                if (list.ContainsKey(sp[0]))
                {
                    list[sp[0]][i]=int.Parse(sp[1]+1);
                    //list2[sp[0]].Add(i);
                }
                else
                {
                    s_rog.Add(sp[0]);
                    data[i]=int.Parse(sp[1]+1);
                    //data2.Add(i);
                    list.Add(sp[0],data );
                    //list2.Add(sp[0],data2);
                }
                
            }

            var s_rog2 = s_rog.ToArray();
            Array.Sort(s_rog2, StringComparer.Ordinal);

            for (int j = 0; j < s_rog2.Length; j++)
            {
                var data2 = new int[n];
                list[s_rog2[j]].CopyTo(data2, 0);
                int cnt = 0;
                Array.Sort(data2);
                while (data2[n - 1 - cnt] > 0)
                {
                    Console.WriteLine(Array.IndexOf(list[s_rog2[j]], data2[n - 1 - cnt]) + 1);
                    //Console.WriteLine(string.Join(" ", s_rog2));
                    if (cnt < n - 1) cnt++;
                    else break;
                }
            }
        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 13276
def test():
    A, B, C, K = map(int, input().split())
    A_K_MIN = min(A, K)
    ans = A_K_MIN
    K -= A_K_MIN

    B_K_MIN = min(B, K)
    K -= B_K_MIN

    ans -= K
    print(ans)


if __name__ == "__main__":
    test()


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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

const int N = 1e5 + 7;

LL n, A[N], B[N], C[N], dp[N][3];

int main()
{
    _upgrade
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> A[i]; sort(A + 1, A + n + 1);
    for(int i = 1; i <= n; i++) cin >> B[i]; sort(B + 1, B + n + 1);
    for(int i = 1; i <= n; i++) cin >> C[i]; sort(C + 1, C + n + 1);
    for(int i = 1; i <= n; i++) dp[i][0] = i;
    for(int i = 1; i <= n; i++)
    {
        dp[i][1] = dp[i - 1][1];
        auto it = lower_bound(A + 1, A + n + 1, B[i]);
        dp[i][1] += dp[it - A - 1][0];
    }
    for(int i = 1; i <= n; i++)
    {
        dp[i][2] = dp[i - 1][2];
        auto it = lower_bound(B + 1, B + n + 1, C[i]);
        dp[i][2] += dp[it - B - 1][1];
    }
    cout << dp[n][2] << "\n";
    return 0;
}


Measured memory_bytes: 4992
#include<iostream>

void Show(int* n){
	for (int i = 0; i < 17; i++){
		std::cout << n[i] << " ";
	}
	std::cout << std::endl;

}

int main(){
	long long N;
	std::cin >> N;
	int n[17];
	for (int i = 0; i < 17; i++){
		n[i] = -1;
	}

	int i = 16;
	int first;
	do{
		first = i;
		n[i] = N % 10;
		N /= 10; i--;
	} while (N > 0);

	//Show(n);
	for (int i = 0; i < 17; i++){
		if (n[i] != 9 && n[i] != -1){
			if (i == first){
				bool b = true;
				for (int j = i + 1; j < 17; j++){
					if (n[j] != 9){
						b = false;
						n[j] = 9;
					}
				}
				if (!b)	n[i]--;

			}
			else{
				n[i - 1]--;
				for (int j = i; j < 17; j++){
					n[j] = 9;
				}
			}
		}
		//Show(n);
	}

	int sum = 0;
	for (int i = 0; i < 17; i++){
		if (n[i] > 0){
			sum += n[i];
		}
	}

	std::cout << sum << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int W , H , x , y ,r;
cin >> W >> H >> x >> y >> r;
if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H){
  cout << "Yes" << endl;
} else {
  cout << "No" << endl;
}

  return 0;
}


Measured memory_bytes: 3120
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
using namespace std;

int main(int argc,char** argv)
{
	int a, b;
	string s;
	cin >> a >> b >> s;
	for(int i = 0; i < a+b+1; i++){
		if(i < a){
			if(s[i]!='1' && s[i]!='2' && s[i]!='3' && s[i]!='4' && s[i]!='5'
				&&s[i]!='6' && s[i]!='7' && s[i]!='8' && s[i]!='9' && s[i]!='0'){
				cout << "No" <<endl;
				return 0;
			}
		}
		else if(i == a){
			if(s[i] != '-'){
				cout << "No" <<endl;
				return 0;
			}
		}
		else{
			if(s[i]!='1' && s[i]!='2' && s[i]!='3' && s[i]!='4' && s[i]!='5'
				&&s[i]!='6' && s[i]!='7' && s[i]!='8' && s[i]!='9' && s[i]!='0'){
				cout << "No" <<endl;
				return 0;
			}
		}
	}
	cout << "Yes" <<endl;


	return 0;

}

Measured memory_bytes: 256