akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define PI 3.1415926535898

//------------------------------------------------------

int main() {
    double a, b;
    cin >> a >> b;
    cout << ceil((a + b) / 2) << endl;

    return 0;
}



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

string s[2];
void init(){
  s[0]=s[1]="";
}

bool input(){
  cin>>s[0]>>s[1];
  return true;
}
//i1 x10 c100 m1000

int add(int tmp,int tmp_c){
  if(tmp==0)tmp++;
  int res=0;
  switch(tmp_c){
    case 'i':
      res+=tmp;
      break;
    case 'x':
      res+=tmp*10;
      break;
    case 'c':
      res+=tmp*100;
      break;
    case 'm':
      res+=tmp*1000;
      break;
  }
  return res;
}


int toINT(string str){
  int res=0;
  char tmp_c=str[str.size()-1];
  int count=0;
  int tmp=0;
  for(int i=str.size()-2;i>=0;i--){
    if(!(str[i]<'0'||'9'<str[i])){
      tmp+=(str[i]-'0')*pow(10,count);
      count++;
    }else{
      res+=add(tmp,tmp_c);
      tmp_c=str[i];
      tmp=0;
      count=0;
    }
  }
  res+=add(tmp,tmp_c);
  return res;
}

string toStr(int n){
  //1 is empty
  if(n==1)return "";
  string res="";
  while(n>0){
    res=char(n%10+'0')+res;
    n/=10;
  }
  return res;
}

string toMCXI(int n){
  string res="";
  if(n>=1000){
    res+=toStr(n/1000);
    res+="m";
  }
  n%=1000;
  if(n>=100){
    res+=toStr(n/100);
    res+="c";
  }
  n%=100;
  if(n>=10){
    res+=toStr(n/10);
    res+="x";
  }
  n%=10;
  if(n>0){
    res+=toStr(n);
    res+="i";
  }
  if(n==0 && res.size()==0){
    res="0";
  }
  return res;
}

string solve(){
  //cout<<s[0]<<" "<<toINT(s[0])<<" "<<s[1]<<" "<<toINT(s[1])<<endl;;
  return toMCXI(toINT(s[0])+toINT(s[1]));
}


int main(){
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    init(),input();
    cout<<solve()<<endl;
  }
}

Measured memory_bytes: 1228
#include <iostream>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
 
using namespace std;

string s;
 
int main() {
  fast_io;

  cin >> s;

  string ans = (s[2] == s[3] && s[4] == s[5]) ? "Yes" : "No";

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

Measured memory_bytes: 256
def main():
    import sys
    input=sys.stdin.readline   
    M=10**6

    dp=[0]+[M]*M
    dpo=[0]+[M]*M

    for i in range(1,200):
        t=i*(i+1)*(i+2)//6

        for j in range(t,min(5*t,M)):
            if j<t:
                dp[j]=dp[j]
            else:
                dp[j]=min(dp[j],dp[j-t]+1)
        
        if t%2==1:
            for j in range(t,M):
                if j<t:
                    dpo[j]=dpo[j]
                else:
                    dpo[j]=min(dpo[j],dpo[j-t]+1)
    
    while True:
        n=int(input())
        if n==0:
            break
        else:
            print(dp[n],dpo[n])

if __name__=='__main__':
    main()


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

typedef double Real;
typedef complex<Real> P;

const Real INF = 1e18;
Real g[252][252];

int n;
Real px[252], py[252], pz[252], vx[252], vy[252], vz[252], r[252], vr[252];

Real dist(Real ax, Real ay, Real az, Real bx, Real by, Real bz){
  Real ret = 0.0;
  ret += (ax-bx)*(ax-bx);
  ret += (ay-by)*(ay-by);
  ret += (az-bz)*(az-bz);
  return sqrt(ret);
}

Real calc(int a, int b){
  // calc time of first collision between a and b
  
  // relative values
  const Real X = px[b] - px[a];
  const Real Y = py[b] - py[a];
  const Real Z = pz[b] - pz[a];
  const Real VX = vx[b] - vx[a];
  const Real VY = vy[b] - vy[a];
  const Real VZ = vz[b] - vz[a];
  const Real R = r[b] + r[a];
  const Real VR = vr[b] + vr[a];
  
  // mendoi
  const Real LOW = 0;
  const Real HIGH = R / VR;
  const Real TRI_X = 101;
  const Real TRI_Y = 100;
  const Real TRI_Z = TRI_X + TRI_Y;
  Real low = LOW;
  Real high = HIGH;
  Real dist_low = INF;
  Real dist_high = INF;
  REP(_,50){
    Real ml = (low*TRI_X+high*TRI_Y)/TRI_Z;
    Real mr = (low*TRI_Y+high*TRI_X)/TRI_Z;
    Real dist_ml = dist(0,0,0,X+VX*ml,Y+VY*ml,Z+VZ*ml) - (R-VR*ml);
    Real dist_mr = dist(0,0,0,X+VX*mr,Y+VY*mr,Z+VZ*mr) - (R-VR*mr);
    if(dist_ml < dist_mr){
      high = mr;
      dist_high = dist_mr;
    }else{
      low = ml;
      dist_low = dist_ml;
    }
  }
  if(dist_low > 0.0)return INF;
  low = LOW;
  REP(_,50){
    Real m = (low + high) / 2.0;
    Real dist_m = dist(0,0,0,X+VX*m,Y+VY*m,Z+VZ*m) - (R-VR*m);
    if(dist_m <= 0.0){
      high = m;
    }else{
      low = m;
    }
  }
  return high;
}

Real ans[252];

int main(){
  while(true){
    scanf("%d", &n);
    if(n==0)break;
    REP(i,n)scanf("%lf%lf%lf%lf%lf%lf%lf%lf",px+i,py+i,pz+i,vx+i,vy+i,vz+i,r+i,vr+i);
    REP(i,n)REP(j,n)g[i][j] = INF;
    REP(i,n)g[i][i] = r[i] / vr[i];
    REP(i,n)REP(j,i)g[i][j] = g[j][i] = calc(i,j);
    // REP(i,n){
    //   REP(j,n)printf("%02.2f ",g[i][j]==INF ? 99.99 : g[i][j]);
    //   puts("");
    // }
    REP(_,n){
      Real mn = INF;
      int ii = 0, jj = 0;
      REP(i,n)REP(j,n)if(g[i][j] < mn){
        mn = g[i][j];
        ii = i;
        jj = j;
      }
      if(mn == INF)break;
      ans[ii] = mn;
      ans[jj] = mn;
      REP(j,n)g[ii][j] = INF;
      REP(i,n)g[i][jj] = INF;
    }
    REP(i,n)printf("%.9f\n",ans[i]);
  }
  return 0;
}


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

int main() {
  int a, b;

  cin >> a >> b;

  //a * b がoddになるのは a = odd && b = odd

  if(((a % 2) != 0) && ((b % 2) != 0)){
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    while (1) {
        int n,m,x=0,i;
        scanf("%d %d",&n,&m);
        if (n==0&&m==0) return 0;
        int masu[n],dise[m];
        for (i=0; i<n; i++) {
            scanf("%d",&masu[i]);
        }
        for (i=0; i<m; i++) {
            scanf("%d",&dise[i]);
        }
        i=0;
        while (x<n-1) {
            x+=dise[i];
            i++;
            if (x>=n-1) {
                break;
            }
            x+=masu[x];
        }
        printf("%d\n",i);
    }
}

Measured memory_bytes: 604
function Main(input) {
	input = input.split("\n");
	tmp = input[0].split(" ");
    for( let i = 0 ; i < 5 ; i++ ){
		var a = parseInt(tmp[i], 10)
		if( a == 0 ) {
             console.log( '%d',i+1 );
        }
    }  
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29624
max = 1_000_000

is_prime = [false, false] + [true]*(max -1)

loop_max = Math.sqrt(max).to_i + 1

2.upto(loop_max) do |i|
  next unless is_prime[i]
  (i*i).step(max, i) do |j|
    is_prime[j] = false
  end
end

count = 0
prime_num_list = (0..max).map do |i|
  count += 1 if is_prime[i]
  count
end

while n = gets.to_i
  break if n == 0
  puts prime_num_list[n]
end

Measured memory_bytes: 32172
#include <iostream>

using namespace std;

int main(){
  int N, X;
  int min = 10000;
  int tot = 0;
  cin >> N >> X;
  for (int i=0;i<N;i++) {
    int m;
    cin >> m;
    if (m < min) {
      min = m;
    }
    tot += m;
  }
  cout << N + (X - tot)/min << endl;
  return(0);
}


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

int x[510][510];
bool ok = true;

void solve(int h, int w, int H, int W) {
    for (int i = 0; i < H; i++) {
        int cnt = 0; int sum = 0;
        for (int j = 0; j < W; j++) {
            cnt++;
            if (cnt == w) {
                x[i][j] = -(500 * (w-1) + 1);
                cnt = 0;
            } else {
                x[i][j] = 500;
            }
            sum += x[i][j];
        }
        if (sum <= 0) ok = false;
    }
}

void transpose() {
    for (int i = 0; i <= 500; i++) {
        for (int j = i+1; j <= 500; j++) {
            swap(x[i][j], x[j][i]);
        }
    }
}

int main() {
    int H, W; cin >> H >> W;
    int h, w; cin >> h >> w;
    if (H % h == 0 && W % w == 0) {
        cout << "No" << endl;
        return 0;
    }
    if (W % w == 0) {
        solve(w, h, W, H);
        transpose();
    } else {
        solve(h, w, H, W);
    }

    if (!ok) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (j) cout << " ";
            cout << x[i][j];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int main(){

	deque<int> DEQ;

	int num_query;
	scanf("%d",&num_query);

	int command,A,B;

	for(int loop = 0; loop < num_query; loop++){
		scanf("%d",&command);

		switch(command){
		case 0:

			scanf("%d %d",&A,&B);
			if(A == 0){
				DEQ.push_front(B);
			}else{
				DEQ.push_back(B);
			}
			break;
		case 1:

			scanf("%d",&A);
			printf("%d\n",DEQ[A]);

			break;
		case 2:
			scanf("%d",&A);
			if(A == 0){
				DEQ.pop_front();
			}else{
				DEQ.pop_back();
			}
			break;
		}
	}

	return 0;
}



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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  int64_t ans = 0;
  for(int j=0; j<N; j++){
    ans += vec.at(j) -1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll n,ans=0,toubatu=0;
    cin>>n;
    vector<ll> a(n+1),b(n);
    rep(i,n+1) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n){
        toubatu=min(a[i],b[i]);
        b[i]-=toubatu;
        ans+=toubatu;
        toubatu=min(a[i+1],b[i]);
        a[i+1]-=toubatu;
        ans+=toubatu;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 4828
use std::cmp;
use std::fmt::Debug;
use std::str::FromStr;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where
    T: FromStr,
    <T as FromStr>::Err: Debug,
{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim()
        .split_whitespace()
        .map(|c| T::from_str(c).unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_as_string() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main() {
    let line = read_as_vec::<usize>();
    let n: usize = line[0];

    let mut a: Vec<i64> = read_as_vec::<i64>();

    let mut cost: i64 = 0;

    for i in 1..n {
        if a[i - 1] > a[i] {
            cost += (a[i - 1] - a[i]).abs();
            a[i] = a[i - 1];
        }
    }
    println!("{}", cost);
}


Measured memory_bytes: 5856
'use strict';

// PROCESS
function caesar(cipherText) {
    var plainText = '';

    // buf is ASCII code
    var buf;

    for(var i = 0; i < cipherText.length; i++)
    {
        buf = cipherText.charCodeAt(i) - 3;
        if (buf < 65) {
            buf += 26;
        }
        plainText += String.fromCharCode(buf);
    }
    
    return plainText;
}

// IO (RAW)

require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
}).on('line', function (line) {
    console.log(caesar(line.trim()));
});

Measured memory_bytes: 15716
#include <iostream>

using namespace std;

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  int range_sum[N][N];
  for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) range_sum[i][j] = 0;

  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    l--, r--;
    range_sum[l][r] += 1;
  }

  for (int i = 0; i < N; i++) {
    int sum = 0;
    for (int j = 0; j < N; j++) {
      sum += range_sum[i][j];
      range_sum[i][j] = sum;
    }
  }

  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    p--, q--;
    int sum = 0;
    for (int j = p; j <= q; j++) {
      sum += range_sum[j][q];
    }
    cout << sum << endl;
  }
}


Measured memory_bytes: 1920
package main

import (
	"fmt"
	"math"
)

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

	ans := 1
	for b := 2; b < x; b++ {
		for q := 2; q < x; q++ {
			num := int(math.Pow(float64(b), float64(q)))
			if num > x {
				break
			} else if num > ans {
				ans = num
			}
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int add = A + B;
        int sub = A - B;
        int mul = A * B;
        
        int ans = Math.max(add, sub);
        ans = Math.max(ans, mul);
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    long long m,n,t,x,y;
    m=a+b;
    n=a-b;
    t=(m>n)?m:n;
    x=a*b;
    y=(t>x)?t:x;
    cout<<y<<endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    # ヒープキューをインポート
    from heapq import heappush, heappop
 
    n, m = map(int, input().split())
    jobs = [[] for _ in range(m)]  # 締め切り別に，報酬を管理
 
    # See:
    # https://www.youtube.com/watch?v=1Z6ofKN03_Y
    for i in range(n):
        ai, bi = map(int, input().split())
 
        # 報酬が振り込まれる日がM日よりも後になる場合は除外
        if ai > m:
            continue
 
        # i件目のアルバイトを遅くてもいつまでに始める必要があるかを計算
        # heappopは最小値を返す．biを-1倍することで，最大値が取り出せる
        deadline = m - ai
        jobs[deadline].append(-bi)
 
    ans = 0
    reward = []
 
    # M-1日に始める必要があるアルバイトのうち，最も報酬の高いものを選択
    # 以降，今日始める必要があるアルバイトまで，順番に調べる
    # ある時点で得られる報酬の大小に着目
    for i in range(m - 1, -1, -1):
        for job in jobs[i]:
            # ヒープキューに，報酬の候補を追加
            heappush(reward, job)
 
        # 条件を満たすもののうち，最大の報酬を選択
        if reward:
            ans += heappop(reward)
 
    # ヒープキューに追加するときに，-1倍した分を元に戻す
    print(-ans)
 
 
if __name__ == '__main__':
    main()

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

int main() {
  int s,s1,s2,s3;
  cin >> s;
  s1 = s / 100;
  s2 = (s - 100 * s1) / 10;
  s3 = s - 100 * s1 - 10 * s2;
  cout << s1 + s2 + s3 << endl; 
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    char s[101];
    int i=0;
    
    
    scanf("%s",s);
    
    while(s[i]!='\0'){
        s[i]='x';
        i++;
    }
    i=0;
    while(s[i]!='\0'){
        printf("%c",s[i]);
        i++;
    }
    return 0;
}


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

typedef long long int llint;

int main()
{
  int s[1000] = {};
  int n;
  cin>> n;

  for(int i = 0; i < n; i++) cin>> s[i];

  int cnt = 0;

  for(int i = 1; i < n; i++) {
    if(s[i - 1] == s[i]) {
      cnt++;
      s[i] += s[i - 1] + s[i + 1];
    }
  }

  cout<< cnt <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define INFTY 1000000
#define M -1
#define WHITE 0
#define GRAY  1
#define BLACK 2
#define N 100


int n;
int A[N][N];

void dijkstra(void)
{
  int d[N],p[N],color[N];
  int i,v,u,mincost;

  for(i = 0;i < n;i ++)
    {
      d[i] = INFTY;
      p[i] = M;
      color[i] = WHITE;
    }
  
  d[0] = 0;
  color[0] = GRAY;
  while(1)
    {
      mincost=INFTY;
      //u=M;
      for(i = 0;i< n;i ++)
	{
	  if(mincost > d[i] && color[i] != BLACK)
	    {
	      u = i;
	      mincost = d[i];
	    }
	}
      if(mincost == INFTY) break;
       
      color[u] = BLACK;
      for(v = 0;v < n;v ++)
	{
	  if(color[v] != BLACK && d[u] + A[u][v] < d[v])
	    {
	      d[v] = d[u] + A[u][v];
	      p[v] = u;
	      color[v] = GRAY;
	    }
	}
    }
  for(i = 0;i < n;i ++)
    {
      printf("%d %d\n",i,d[i]);
    }
}


 
int main()
{
  int i,j,u,k,v,c;

  scanf("%d",&n);

  for(i = 0;i < n;i ++)
    {
      for(j = 0;j < n;j ++)
	{
	  A[i][j] = INFTY;
	}
    }
  
  for(i = 0;i < n;i ++)
    {
      scanf("%d%d",&u,&k);
      for(j = 0;j < k;j ++)
	{
	  scanf("%d%d",&v,&c);
	  A[u][v] = c;
	}
    }
 
  dijkstra();
  return 0;
}
 

Measured memory_bytes: 636
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll = long long;


int main() {
	
	int n, num=2,ans=0;
	cin >> n;
	
	for (int i = 1; i <= n; i += 2 )
	{
		for (int j = 2; j < i; j++)
		{
			if (i%j == 0)
			{
				num++;
			}
			
		}
		if (num == 8)
			ans++;

		num = 2;
	}
	cout << ans << endl;
}



Measured memory_bytes: 256
def main():
    N = int(input())
    S = input()
    # [0, i)
    L = [0]
    for i in range(N):
        L.append(L[i] | (1 << int(S[i])))
    R = [0]
    for i in range(N):
        R.append(R[i] | (1 << int(S[N - i - 1])))
    R.reverse()
    L = L[:-1]
    R = R[1:]
    ans = set()
    for m in range(N):
        for l in range(10):
            for r in range(10):
                if ((L[m] >> l) & 1) > 0 and ((R[m] >> r) & 1) > 0:
                    ans.add('%d%s%d' % (l, S[m], r))
    print(len(ans))

if __name__ == '__main__':
    main()


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

int main(void){
  int h,w;cin>>h>>w;
  vector<vector<char>> field(h, vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin>>field.at(i).at(j);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout << field.at(i).at(j);
    }
    cout << endl;
    for(int j=0;j<w;j++){
      cout << field.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
s = raw_input()
a, b = -1, -1
if s[0] == s[1]:
  a, b = 1, 2
for i in range(len(s) - 2):
  if s[i] == s[i + 2]:
    a, b = i + 1, i + 3
  if s[i + 1] == s[i + 2]:
    a, b = i + 2, i + 3
print a, b

Measured memory_bytes: 5892
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
ll dp[100010][2][2];
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    vector<char> c(n - 1);
    int t = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i] *= t;
        if (i < n - 1) {
            cin >> c[i];
            if (c[i] == '-') {
                t = -1;
            } else {
                t = 1;
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                dp[i][j][k] = -LINF;
            }
        }
    }
    dp[0][0][0] = 0;
    for (int i = 0; i < n; i++) {
        chmax(dp[i + 1][0][0], dp[i][0][0] + a[i]);
        chmax(dp[i + 1][0][1], dp[i][0][1] + a[i]);
        chmax(dp[i + 1][1][1], dp[i][1][1] - a[i]);
        if (i > 0 && c[i - 1] == '-') {
            chmax(dp[i + 1][1][1], dp[i][0][0] + a[i]);
            chmax(dp[i + 1][1][1], dp[i][0][1] + a[i]);
            chmax(dp[i + 1][0][1], dp[i][1][1] - a[i]);
        } else if (i > 0) {
            chmax(dp[i + 1][1][1], dp[i][0][1] + a[i]);
        }
    }
    cout << max(dp[n][0][1], dp[n][0][0]) << endl;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;

  
ll g[102][102];
ll matchU[102];
ll ans;
bool vis[102];
ll X, Y, E;
  
bool dfs(ll v){
    for (int i = 0; i < Y; i++){
        if (g[v][i] && !vis[i]){
            vis[i] = true;
            if(matchU[i] < 0 || dfs(matchU[i])){
                matchU[i] = v;
                return true;
            }
        }
    }
    return false;
}
  
int main() {
 
    // 1. 入力.
    scanf("%d %d %d", &X, &Y, &E);
     
    // 2. 始点, 終点.
    for(int i = 0; i < E; i++) {
        int fr, to;
        scanf("%d %d", &fr, &to);
        g[fr][to] = 1;  
    }
     
    // 3. マッチング.
    for(int i = 0; i < 102; i++) matchU[i] = -1;
    for(int i = 0; i < X; i++){
        for (int j = 0; j < 102; j++) vis[j] = 0;
        if(dfs(i)) ans++; 
    }
     
    // 4. 出力.
    printf("%d\n", ans);
 
}



Measured memory_bytes: 3300
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        S: u64,
        C: u64,
    }
    let mut ans = min(S,C/2);
    if S*2 <= C{
        let C = C - S*2;
        ans += C/4;
    }
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
  int a,b,c,i;
  i=0;
  scanf("%d%d%d",&a,&b,&c);
  if(a>b){
    i=a;
    a=b;
    b=i;
  }
  if(a>c){
    i=a;
    a=c;
    c=i;
  }
  if(b<c) printf("%d %d %d\n",a,b,c);
    else{
      printf("%d %d %d\n",a,c,b);
    }
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int dp[3005][3005];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    for(int i=0;i<3005;i++)for(int j=0;j<3005;j++)dp[i][j]=0;
    string ss,tt;
    cin>>ss>>tt;
    for(int i=0;i<ss.size();i++){
        for(int j=0;j<tt.size();j++){
            if(ss[i]==tt[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i+1][j]);
            dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j+1]);
        }
    }
    
    string res="";
    int i=ss.size();
    int j=tt.size();
    while(i>0&&j>0){
        if(dp[i][j]==dp[i-1][j])--i;
        else if(dp[i][j]==dp[i][j-1])--j;
        else{
            res=ss[i-1]+res;
            --i;--j;
        }
    }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 35584
/*
このコード、と～おれ!
Be accepted!
  ∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>

using namespace std;

int main() {
	
	char c;
	scanf("%c", &c);
	if( c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')printf("vowel\n");
	else printf("consonant\n");
	return 0;
}
	    

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Threading;

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}

	Scanner cin;

	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-8;
	const double PI = 3.1415926536;
	int[,] dir8;
	int[,] dir4;



	void prog()
	{
		cin = new Scanner();
		dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int N = cin.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		int[] num = new int[N];
		for (int i = 0; i < N; i++)
		{
			A[i] = cin.nextInt();
			num[A[i]]++;
		}
		if (N % 2 == 0)
		{
			for (int i = 1; i < N; i+=2)
			{
				if (num[i] != 2)
				{
					Console.WriteLine(0);
					return;
				}
			}
			for (int i = 0; i < N; i+=2)
			{
				if (num[i] != 0)
				{
					Console.WriteLine(0);
					return;
				}
			}
			int ans = 1;
			for (int i = 0; i < N / 2; i++)
			{
				ans *= 2;
				ans %= MOD;
			}
			Console.WriteLine(ans);
		}
		else
		{
			for (int i = 1; i < N; i += 2)
			{
				if (num[i] != 0)
				{
					Console.WriteLine(0);
					return;
				}
			}
			if (num[0] != 1)
			{
				Console.WriteLine(0);
				return;
			}
			for (int i = 2; i < N; i += 2)
			{
				if (num[i] != 2)
				{
					Console.WriteLine(0);
					return;
				}
			}
			int ans = 1;
			for (int i = 0; i < N/2; i++)
			{
				ans *= 2;
				ans %= MOD;
			}
			Console.WriteLine(ans);
		}
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

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

const int cnMaxArray = 1000033;

long long fnStrToInt(string sKey)
{
  int iElement;
  int iBase = 1;
  int llKey  = 0;
  for (int i = sKey.size() - 1; i >= 0; i--)
  {
    switch (sKey[i])
    {
      case  'A': iElement = 1;
                 break;
      case  'C': iElement = 2;
                 break;
      case  'G': iElement = 3;
                 break;
      case  'T': iElement = 4;
                 break;
      default:   iElement = 0;
    }
    llKey += iBase * iElement;
    iBase *= 5;
  }
  return llKey;
}

int fnHash1(long long a_llKey) { return (a_llKey % cnMaxArray); }
int fnHash2(long long a_llKey) { return (1 + (a_llKey % (cnMaxArray - 1))); }

void fnDictionary(string a_rsDictionary[])
{
  int iCommandCnt;
  cin >> iCommandCnt;

  for (int i = 0; i < iCommandCnt; i++)
  {
    string sCommand;
    string sKey;
    cin >> sCommand >> sKey;

    long long llKey = fnStrToInt(sKey);
    int iCnt = 0;
    for (iCnt = 0; ;iCnt++)
    {
      int ix = (fnHash1(llKey) + iCnt * fnHash2(llKey)) % cnMaxArray;
      if (a_rsDictionary[ix] == sKey)
      {
        if (sCommand[0] == 'f')
        {
          cout << "yes" << endl;
          break;
        }
      }
      else if (a_rsDictionary[ix].size() == 0)
      {
        if (sCommand[0] == 'i')
        {
          a_rsDictionary[ix] = sKey;
          break;
        }
        else if (sCommand[0] == 'f')
        {
          cout << "no" << endl;
          break;
        }
      }
    }
  }
}

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

  static string sDictionary[cnMaxArray];
  fnDictionary(sDictionary);
  
  return 0;
}

Measured memory_bytes: 35780
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan=new Scanner(System.in);
		int n=scan.nextInt();
		String str=Integer.toString(n);
		int len=str.length();
		String s="";
		for(int i=0;i<=len-1;i++) {
			if(str.charAt(i)=='1') {
				s+='9';
			}
			else if(str.charAt(i)=='9') {
				s+='1';
			}
	}
		System.out.println(s);
	}
}

Measured memory_bytes: 38552
#include<bits/stdc++.h>
using namespace std;
int n,ct[1010101],nw[1010101],sum,al;
string s;
vector<pair<int,int> >v;
bool cmp(pair<int,int>a,pair<int,int>b)
{
	return min(a.second,a.first+b.second)>min(b.second,b.first+a.second);
}
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		int a=0;
		for(int j=0;j<s.size();j++)
		{
			if(s[j]=='(')
			{
				a++;
			}
			else
			{
				a--;
			}
			nw[i]=min(nw[i],a);
		}
		ct[i]=a;
		sum+=a;
		v.push_back(make_pair(ct[i],nw[i]));
	}
	if(sum!=0)
	{
		cout<<"No"<<endl;
		return 0;
	}
	sort(v.begin(),v.end(),cmp);
	int nn=0;
	for(int i=0;i<n;i++)
	{
		if(nn<-v[i].second)
		{
			cout<<"No"<<endl;
			return 0;
		}
		nn+=v[i].first;
	}
	cout<<"Yes"<<endl;
	return 0;
}


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




/*
int main() {
	int n; cin >> n;
	string s; cin >> s;

	int l[5000] = {};
	int ans = 0;

	for (int i = n - 1; i >= 0; i--) {
		for (int j = n - 1; j > i; j--) {
			if (s[i] == s[j - l[j]]) {
				l[j]++;
			}
			else l[j] = 0;
			ans = max(ans, min((j - i + 1) / 2, l[j]));
		}
	}

	cout << ans << endl;

	return 0;
}*/

using ULL = unsigned long long;

int main() {
	ULL Z = 0;
	ULL s[100000];

	int n; cin >> n;
	for (int i = 0; i < n; i++) {
		ULL a; cin >> a;
		s[i] = a; Z ^= a;
	}
	for (int i = 0; i < n; i++) {
		s[i] &= ~Z;
	}

	for (int i = 59; i >= 0; i--) {
		ULL m = 1ull << i;
		int p = 0;
		for (; p < n; p++) {
			if ((s[p] & m) && s[p] < (m << 1))
				break;
		}if (p == n) continue;
		for (int j = 0; j < n; j++) {
			if (j == p) continue;
			if (s[j] & m)s[j] ^= s[p];
		}
	}

	ULL Y = 0; for (int i = 0; i < n; i++)Y ^= s[i];

	cout << (Z^Y) + Y << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 300001
#define PI 3.14159265358979323846264338327950
 
#define ll   long long int
#define mod  1000000007


int main()
{
	FAST;
	ll t;
	cin >> t;
	ll o = t% 1000;
	ll ans;
	ans = 1000 - o;
	ans %= 1000;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,a[100010],b[100010],d[100010],sa[100010]={0},sb[100010]={0},m=0,sd=0;
  cin>>n;
  fr(i,n) cin>>a[i];
  fr(i,n) cin>>b[i];
  fr(i,n){
    sa[i+1]=sa[i]+a[i];
    sb[i+1]=sb[i]+b[i];
    d[i]=a[i]-b[i];
  }
  sort(d,d+n);
  if(sa[n]<sb[n]) cout<<-1<<endl;
  else{
    fr(i,n){
      if(d[i]<0){
        sd-=d[i];
        m+=1;
      }
    }
    if(sd>0){
    fr(i,n){
      sd-=d[n-1-i];
      if(sd<=0){
        m+=i+1;
        break;
      }
    }
    }
    cout<<m<<endl;;
  }
}

Measured memory_bytes: 4096
#include <stdio.h>


int main()
{
    int n;
    int result = 0, conq = 0;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) {
        int x;
        scanf("%d", &x);
        if (x == i) {
            ++ conq;
        }

        if (x != i || i == n) {
            result += conq + 1 >> 1;
            conq = 0;
        }
    }
    printf("%d\n", result);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if ((a % 2 == 0 && b % 2 == 0) || (a % 2 != 0 && b % 2 != 0)) {
          System.out.println(Math.abs(a+b)/2);
        } else {
          System.out.println("IMPOSSIBLE");
        }

    }
}


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

int main() {
    string s;
    cin>>s;
    s[2]='1';
    s[3]='8';
    cout<<s<<endl;
    return 0;
    }
    

Measured memory_bytes: 3560
package main

import "fmt"

func main() {

	var n, a, b int
	fmt.Scanf("%d %d %d\n", &n, &a, &b)

	var max, min int
	if a+b <= n {
		if a > b {
			max = b
			min = 0
		} else {
			max = a
			min = 0
		}
	} else {
		if a > b {
			max = b
			min = a - n + b
		} else {
			max = a
			min = a - n + b
		}
	}
	fmt.Println(max, min)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007
#define ll long long
using namespace std;
signed main(){
	ll n; cin>>n;
	vector< pair<ll,ll> > v;
	for(ll i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		v.pb(mp(min(x,y),max(x,y)));
	}
	sort(v.begin(),v.end());
	ll ans1 = 0, ans2 = 0;
	vector<ll> r,b;
	for(ll i=0;i<n;i++){
		r.pb( v[i].first );
		b.pb( v[i].second );
	}
	sort( r.begin(),r.end() );
	sort( b.begin(),b.end() );
	ans1 = (r[n-1]-r[0])*(b[n-1]-b[0]);
	ll msa = b[n-1]-r[0];
	multiset<ll> s;
	for(ll i=0;i<n;i++){
		s.insert(r[i]);
	}
	ll lit = *s.upper_bound(-1);
	multiset<ll>::iterator it = s.end(); it--;
	ll big = *it;
	ans2 = big - lit;
	for(ll i=0;i<n;i++){
		it = s.lower_bound(v[i].first);
		s.erase(it);
		s.insert(v[i].second);
		lit = *s.upper_bound(-1);
		it = s.end();it--;
		big = *it;
		if(big-lit<ans2){ans2=big-lit;}
	}
	ans2 *= msa;
	cout<<min(ans1,ans2)<<endl;
	return 0;
}

Measured memory_bytes: 17260
# include <cstdio>
# include <algorithm>
# include <cstring>
# include <cmath>
# include <climits>
# include <iostream>
# include <string>
# include <queue>
# include <vector>
# include <set>
# include <map>
# include <cstdlib>
# include <stack>
# include <ctime>
using namespace std;

# define Rep(i,a,b) for(int i=a;i<=b;i++)
# define _Rep(i,a,b) for(int i=a;i>=b;i--)
# define mct(a,b) memset(a,b,sizeof(a))
# define gc getchar()
typedef long long ll;
const int N=1e6+5;
const int inf=0x7fffffff;
const double eps=1e-7;
template <typename T> void read(T &x){
	x=0;int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')f=-1;
	for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+c-'0';
	x*=f;
}
int n,a[N],f[N],ans;

int main()
{
	read(n);
	Rep(i,1,n)read(a[i]);
	Rep(i,1,n)
		if(a[i]<=a[i-1])f[i]=f[i-1]+1;
		else f[i]=0;
	Rep(i,1,n)ans=max(ans,f[i]);
	printf("%d\n",ans);
	return 0;	
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
using namespace std;
const int N=100005;
int Head[N],Next[N<<1],Adj[N<<1],tot=0;
void addedge(int u,int v){
	Next[++tot]=Head[u],Head[u]=tot,Adj[tot]=v;
	Next[++tot]=Head[v],Head[v]=tot,Adj[tot]=u;
}
int dep[N];bool ban[N];
int fa[N];
void dfs(int x,int f){
	fa[x]=f;
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f) dep[Adj[e]]=dep[x]+1,dfs(Adj[e],x);
}
int dis[N];
void getd(int x,int f){
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f) dis[Adj[e]]=dis[x]+1,getd(Adj[e],x);
}
int ans=0;
void solve(int x,int f){
	ans=max(ans,dis[x]);
	for (int e=Head[x];e;e=Next[e])
		if (Adj[e]!=f&&(!ban[Adj[e]])) solve(Adj[e],x);
}
int main (){
	int n;scanf ("%d",&n);
	int x,y;scanf ("%d%d",&x,&y);
	for (int i=1;i<n;i++){
		int u,v;scanf ("%d%d",&u,&v);
		addedge(u,v);
	}
	dfs(x,0);getd(y,0);
	int c=dep[y]/2;int add=(dep[y]%2==0);
	while (c--) y=fa[y];ban[y]=true;
	solve(x,0);
	printf ("%d",ans-1);
	return 0;
}

Measured memory_bytes: 7296
#include<stdio.h>
#define N 100050
int a[N];
int main()
{
    int n,x;
    while(scanf("%d%d",&n,&x)!=EOF)
    {
        int i,j;
        for(i=0;i<n;i++)
            scanf("%d",&a[i]);
        long long sum=0;
        for(i=n-1;i>0;i--)
        {
            if(a[i]+a[i-1]>x)
            {
                long long t=a[i]+a[i-1]-x;
                if(a[i-1]>=t)
                    a[i-1]-=t;
                else
                {
                    a[i-1]=0;
                    t-=a[i-1];
                    a[i]-=t;
                }
                sum+=t;
            }
        }
        printf("%lld\n",sum);
    }
    return 0;
}


Measured memory_bytes: 512
n, m, x = map(int, input().split())
c = []
a = []
for i in range(n):
    b = list(map(int, input().split()))
    c.append(b[0])
    a.append(b[1:])

ans = float("inf")
for bit in range(1 << n):
    rikai = [0 for i in range(m)]
    count = 0

    for i in range(n):
        if bit & (1 << i):
            for j in range(m):
                rikai[j] += a[i][j]
            count += c[i]

    flag = True
    for i in rikai:
        if i < x:
            flag = False
            break

    if flag:
        ans = min(ans, count)

if ans < float("inf"):
    print(ans)
else:
    print(-1)

Measured memory_bytes: 9164
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,ai,bi;
    cin>>n;
    int r=0,ri;
    rep(i,n){
        cin>>ai>>bi;
        if(r<ai) r=ai,ri=bi;
    }
    cout<<r+ri<<endl;
    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	int sum = 0;
	int num = n;
	while (1) {
		sum += (num % 10);
		num = num / 10;
		if (num < 10) {
			sum += num; break;
		}
	}
	if (n%sum == 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



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

int main(){
    int N,Z,W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    for (int i=0;i<N;i++){
        cin>>a[i];
    }

    int cand1=abs(a[N-1]-W);
    int cand2=abs(a[N-2]-a[N-1]);
    if (N==1){
        cout<<cand1<<endl;
    }else{
        cout<<max(cand1, cand2)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int main()
{
 char str[512];
 int count[256];

 memset(count, 0, sizeof(count));

 scanf("%s", str);

 for (int i = 0; str[i] != '\0'; i++) count[str[i]]++;
 printf("%d\n", min(min(count['K'], count['U']), min(count['P'], count['C'])));

 return (0);
}

Measured memory_bytes: 968
#include<bits/stdc++.h>
using namespace std;
#define sz 100100
int ar[sz];
int dp[sz];
int main()
{
    int n, k;
    scanf("%d", &n); scanf("%d", &k);
    for (int i = 0; i < n; ++i)
    {
        scanf("%d", &ar[i]);
    }
    for (int i = 0; i < n; ++i)
    {
        if (i == 0)
            continue;
        dp[i] = INT_MAX;
        for (int j = i - 1; j > -1 && i - j <= k; --j)
        {
            dp[i] = min(dp[i], dp[j] + abs(ar[j] - ar[i]));
        }
    }
    cout << dp[n - 1];
}

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

#define rep(i,n) for (int i = 0; i < (n); ++i)
using Graph = vector<vector<int>>;
typedef pair<int,int> P;

int main() {
    int N,a,b,mc=0;
    cin >> N;
    Graph g(N);
    vector<bool> seen(N,0);
    vector<P> ns(N-1);
    vector<int> rc(N,1),p(N);
    map<P,int> c;
    queue<int> q;

    rep(i,N-1) {
        cin >> a >> b;
        a--, b--;
        g.at(a).push_back(b);
        g.at(b).push_back(a);
        ns.at(i) = P(a,b);
    }

    p.at(0) = -1;
    q.push(0);

    while(!q.empty()) {
        int x = q.front();
        q.pop();
        seen.at(x) = 1;

        for(int nx : g.at(x)) {
            if(seen.at(nx))
                continue;

            if(rc.at(x) == p.at(x))
                rc.at(x)++;
            c[P(x,nx)] = rc.at(x);
            p.at(nx) = rc.at(x);
            mc = max(mc,p.at(nx));
            rc.at(x)++;
            q.push(nx);
        }
    }

    cout << mc << endl;
    rep(i,N-1)
        cout << c.at(ns.at(i)) << endl;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll A, B, C, K; cin >> A >> B >> C >> K;
    
    if (K % 2 == 0) cout << A - B << endl;
    else cout << B - A << endl;
    
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int cnt[26] = {}, n = S.length();
  bool chk = true;
  for (int i=0; i<n; i++)
    cnt[S[i]-'a']++;
  for (int i=0; i<26; i++)
    if (cnt[i]>1)
      chk = false;
  if (chk)
    cout << "yes\n";
  else
    cout << "no\n";
  return 0;
}

Measured memory_bytes: 256
S = input()
K = int(input())

S = S + S + S
i = 1
count = 0
while i < len(S):
  if S[i] == S[i-1]:
    count += 1
    i += 2
    continue
  i += 1

if count % 3 == 0:
  print(count // 3 * K)
elif count % 3 == 1:
  print(count // 3 * K + K // 2)
elif count % 3 == 2:
  print((count+1) // 3 * K - 1)

Measured memory_bytes: 3064
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define scan(n,v) v.resize(n); rep(i,n){ cin>>v[i];}
#define lim 1000000007ll
#define Yes(flag) cout<<((flag)? "Yes":"No");
#define YES(flag) cout<<((flag)? "YES":"NO");
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T>T 
chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T>T 
chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template <class T> T 
gcd(T a, T b){if (a < b) {a ^= b;b ^= a;a ^= b;} return b ? gcd(b, a % b) : a;}
template <class T> T 
lcm(T a, T b){return a * b / gcd(a, b);}
//  二項係数 nCk
long long binomial(long long N, long long K) {
    if(K < 0 || N < K) return 0;
    long long ret = 1;
    for(long long i = 1; i <= K; ++i) {
        ret *= N--;
        ret /= i;
    }
    return ret;
}
// header
ll n,k;
vector<ll> a;
void input(){
    cin>>n>>k;
    scan(n,a);
}
void src(){
    ll odd=0,even=0;
    rep(i,n){
        if(a[i]%2==0){
            even++;
        }else{
            odd++;
        }
    }
    ll cnt_e = pow(2,even);
    ll cnt_o = 0;
    repi(i,0,odd+1){
        if((i)%2==0){
            cnt_o += binomial(odd,i);
        }
    }
    if(k==0){
        cout<<cnt_e*cnt_o;
    }else{
        cout<<(ll)(pow(2,n)-cnt_e*cnt_o);
    }
}   
int main(int argc,char* argv[]){
    ios::sync_with_stdio(false);
 //   ifstream in( argv[1] ); cin.rdbuf(in.rdbuf());
    input();
    src();    
    return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s[ohara];
ll n, cnt, a, b, c, d, tmp, m, h, w, x, y, sum, k, q, ma;
map<string, ll> mp;
map<string, ll> look;
vector<string> ans;

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

  cin >> n;
  rep(i, n) {
    cin >> s[i];
    mp[s[i]]++;
    ma = max(ma, mp[s[i]]);
  }
  rep(i, n) {
    if (ma != mp[s[i]]) continue;
    if (look[s[i]]) continue;
    look[s[i]] = 1;
    ans.p_b(s[i]);
  }
  sort(all(ans));
  rep(i, Size(ans)) Cout(ans[i]);
  return 0;
}

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

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

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

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	vi w(n);
	rep(i, n) cin >> w[i];

	ll dif = INFLL;
	rep(t, n)
	{
		ll s1 = 0;
		rep(i, t) s1 += w[i];
		ll s2 = 0;
		for(int i = t; i < n; i++) s2 += w[i];
		chmin(dif, abs(s1-s2));
	}
	cout << dif << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct s_data
{
	char *str;
	int i;
	int index;
}	t_data;

int data_sort(const void *a, const void *b)
{
	int r = strcmp((*(t_data * )a).str,(*(t_data  *)b).str);
	//printf("%d\n",r);
	if (r == 0)
		return ((*(t_data *)b).i - (*(t_data *)a).i);
	else
		return (r);
}


int main(void)
{
	int n;
	scanf("%d",&n);
	int i =0;
	char **str;
	int *p;
	str = (char **)malloc(sizeof(char*)*(n+2));
	p = (int *)malloc(sizeof(int)*(n+2));
	t_data *data;
	data = (t_data *)malloc(sizeof(t_data)*(n));
	while (i < n)
	{
		str[i] = (char *)malloc(sizeof(char)*(15));
		scanf("%s %d",str[i],&p[i]);
		data[i].str = str[i];
		data[i].i = p[i];
		data[i].index = i+1;
		i++;
	}
	qsort((void *)data, n, sizeof(data[0]),data_sort);
	i = 0;
	while (i < n)
	{
		printf("%d\n",data[i].index);
		i++;
	}
	return (0);
}


Measured memory_bytes: 128