akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<sstream>
#include<stack>
#include<string>
#include<unordered_set>
#include<vector>

#define ll long long
#define P pair<int,int>
#define FOR(i,N) for(int i=0;i<(int)N;i++)
#define FORIN(i,a,b) for(int i=a;i<(int)b;i++)
#define ALL(x) (x).begin(),(x).end()
#define LAST(x) (x)[(x).size()-1]

using namespace std;

string to_hex(int x){
    stringstream ss;
    ss<<hex<<x;
    return ss.str();
}

inline int get_int(){
    int ret;
    scanf("%d",&ret);
    return ret;
}

inline vector<int> get_ints(int n){
    vector<int> ret(n);
    FOR(i,n){
        scanf("%d",&ret[i]);
    }
    return ret;
}

inline string get_str(){
    string ret;
    cin>>ret;
    return ret;
}

bool is_prime(int n){
    int s=sqrt(n)+1;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            return 0;
        }
    }
    return 1;
}

vector<P> prime_division(int n){
    vector<P> ret;
    int s=sqrt(n)+1;
    int c=0;
    for(int i=2;i<=s;++i){
        if(n%i==0){
            c=0;
            do{
                ++c;
                n/=i;
            }while(n%i==0);
            ret.push_back(P(i,c));
        }
    }
    return ret;
}

string to_string(string s){
    return s;
}

template<class T>
string to_string(vector<T> v){
    string ret="{";
    FOR(i,v.size()-1){
        ret+=to_string(v[i])+",";
    }
    if(v.size()>0){
        ret+=to_string(LAST(v));
    }
    ret+="}";
    return ret;
}

void debug(){
    cerr<<endl;
}

template<class Head,class... Tail>
void debug(Head head,Tail... tail){
    cerr<<" "<<to_string(head);
    debug(tail...);
}

int main(){
    int N;
    cin>>N;
    int last_h;
    cin>>last_h;
    int c=0;
    FOR(i,N-1){
        int h;
        cin>>h;
        if(h<last_h){
            c+=(last_h-h);
        }
        last_h=h;
    }
    c+=last_h;
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<b;i++)
#define f(i,n) for(int i=0;i<n;i++)
typedef unsigned long long ull;
typedef long long ll;
#define vint vector<int>
#define pb(a) push_back(a);
#define bug(x) cout<<#x<<" = "<<x<<endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0)
// using namespace std;
int main(){
	fastio;
	int n; cin>>n;
	double p[n];
	f(i,n){
		cin>>p[i];	
	}
	double dp[n+1][n+1];
	int thres = (n/2) +1;
	f(i,n+1){
		f(j,n+1){
			if(i==0){
				dp[i][j]=0;
				// if(i==0 && j==0){
				// 	cout<<dp[i][j]<<"\n";
				// }
			}
			else if(j>i){
				dp[i][j]=0;
			}
			else{
				if(i==1){
					if(j==0){
						dp[i][j]=(1-p[i-1]);
					}
					else if(j==1){
						dp[i][j]=p[i-1];
					}
					else{
						dp[i][j]=0;
					}
				}
				else{
					if(j==0){
						dp[i][j]= dp[i-1][j]*(1-p[i-1]);
					}
					else{
						dp[i][j]= dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*(p[i-1]);
					}
				}
			}
			// cout<<dp[i][j]<<" ";
		}
		// cout<<endl;
	}
	// bug(thres);
	double ans=0;
	for(int i=thres;i<n+1;++i){
		// bug(n); bug(i); bug(dp[n][i]);
		ans = ans + dp[n][i];
		// ans = ans + dp[n][i];
		// ans+=1;
		// cout<<ans<<" "<<dp[n][i]<<"\n";
	}
	// cout<<fixed<<precision<<ans<<endl;
	printf("%.10f",ans);
	return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=1e9+7;

ll add(ll a,ll b){ return (a+b)%mod; }

void Add(int &a,ll b){
  ll tmp=(a+b)%mod;
  a=tmp;
}

ll mul(ll a,ll b){ return (a*b)%mod; }


ll mpow(ll a,ll b){
  ll res=1;
  while(b){
    if(b%2==1)res=mul(res,a);
    a=mul(a,a);
    b/=2;
  }
  return res;
}

ll divi( ll a,ll b){
  return mul(a, mpow(b,mod-2) );
}



int n;
int a[200];

ll Z=0;
ll cnt[10];
ll cntinv[10];

ll sum[10];

//ll dp[50][50][50][50][2];
//ll DP[50][50][50][50][2];
vector< vector< vector< vector< vector< int > > > >  > dp,DP;

void update(int a,int b,int c,int d,int z){

  int na=a%2;
  int ma=1-na;
  
  /*  cout<<a<<' '<<b<<' '<<c<<' '<<d<<' '<<z<<endl;
  cout<<dp[a][b][c][d][z]<<endl;
  cout<<DP[a][b][c][d][z]<<endl;
  cout<<endl;    */
  if(a<cnt[1]){
    int cc=cnt[1]-a;
    ll pp=mul(dp[na][b][c][d][z], cc);
    Add( dp[ma][b][c][d][z], pp );
    Add( DP[ma][b][c][d][z], mul(DP[na][b][c][d][z], 10*cc )    );
    Add( DP[ma][b][c][d][z], mul( mul(pp,cntinv[1]),sum[1]) );
  }
  
  if(b<cnt[2]){
    int cc=cnt[2]-b;
    ll pp=mul(dp[na][b][c][d][z], cc);
    Add( dp[na][b+1][c][d][z], pp );
    Add( DP[na][b+1][c][d][z], mul(DP[na][b][c][d][z], 100*cc )    );
    Add( DP[na][b+1][c][d][z], mul(mul(pp,cntinv[2]),sum[2]) );
  }
  if(c<cnt[3]){
    int cc=cnt[3]-c;
    ll pp=mul(dp[na][b][c][d][z], cc);
    Add( dp[na][b][c+1][d][z], mul(dp[na][b][c][d][z], cc) );
    Add( DP[na][b][c+1][d][z], mul(DP[na][b][c][d][z], 1000*cc )    );
    Add( DP[na][b][c+1][d][z], mul(mul(pp,cntinv[3]),sum[3]) );
  }
  if(d<cnt[4]){
    int cc=cnt[4]-d;
    ll pp=mul(dp[na][b][c][d][z], cc);
    Add( dp[na][b][c][d+1][z], mul(dp[na][b][c][d][z], cc) );
    Add( DP[na][b][c][d+1][z], mul(DP[na][b][c][d][z], 10000*cc )    );
    Add( DP[na][b][c][d+1][z], mul(mul(pp,cntinv[4]),sum[4]) );
  }
  
  if(z<Z && a+b+c+d>0){
    Add( dp[na][b][c][d][z+1], dp[na][b][c][d][z] );
    Add( DP[na][b][c][d][z+1], mul(DP[na][b][c][d][z], 10 )    );
  }
}

ll solve(){
  dp.resize(2);
  for(int i=0;i<(int)dp.size();i++){
    dp[i].resize(cnt[2]+1);
    for(int j=0;j<(int)dp[i].size();j++){
      dp[i][j].resize(cnt[3]+1);
      for(int k=0;k<(int)dp[i][j].size();k++){
        dp[i][j][k].resize(cnt[4]+1);
        for(int l=0;l<(int)dp[i][j][k].size();l++){
          dp[i][j][k][l].resize(2);
        }
      }
    }
  }
  DP=dp;

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

  int ans=0;
  
  for(int a=0;a<=cnt[1];a++){
    for(int b=0;b<=cnt[2];b++)
      for(int c=0;c<=cnt[3];c++)
        for(int d=0;d<=cnt[4];d++)
          for(int z=0;z<=Z;z++){
            update(a,b,c,d,z);
            Add( ans, DP[a%2][b][c][d][z] );

            dp[a%2][b][c][d][z]=0;
            DP[a%2][b][c][d][z]=0;
          }
  }

  return ans;
}

int countDisit(int x){
  int res=0;
  while(x){
    res++;
    x/=10;
  }
  return res;
}

int main(){
  cin>>n;
  
  for(int i=0;i<n;i++){
    cin>>a[i];
    int D=countDisit(a[i]);
    if(a[i]==0){
      Z++;
      continue;
    }
    cnt[D]++;
    sum[D]+=a[i];
  }

  for(int i=1;i<=4;i++)
    if(cnt[i]>0)
      cntinv[i]=divi(1,cnt[i]);
  cout<< solve() <<endl;

  return 0;
}

Measured memory_bytes: 59476
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,x=0,max=0;
  cin>>n;
  char word[n];
  for(int i=0;i<n;i++)
  {
  cin>>word[i];
  }
  for(int i=0;i<n;i++)
  {
  	if(word[i]=='I'||word[i]=='i')
		{
		x++;
  	   if(x>max)
  	   	max=x;
		}
  	else
  	 x--;
	 
  }
  cout<<max;
		return 0;	
}

Measured memory_bytes: 256
h,w = map(int,input().split())

d = {}
for _ in range(h):
    a = input()
    for i in range(w):
        a1 = a[i]
        if a1 in d:
            d[a1] += 1
        else:
            d[a1] = 1

if h % 2 == 0 and w % 2 == 0:
    for v in d.values():
        if v % 4 != 0:
            print('No')
            exit()
    print('Yes')

elif h % 2 == 0 or w % 2 == 0:
    cnt_4 = (h // 2) * (w // 2)
    if h % 2 == 0:
        cnt_2 = h // 2
    else:
        cnt_2 = w // 2
    tmp_2 = 0
    tmp_4 = 0
    for v in d.values():
        if v % 4 == 0:
            tmp_4 += v // 4
        elif v % 2 == 0:
            tmp_4 += v // 4
            tmp_2 += 1
        else:
            print('No')
            exit()
    if tmp_4 >= cnt_4 and cnt_2 == tmp_2 + (tmp_4 - cnt_4) * 2:
        print('Yes')
    else:
        print('No')

else:
    cnt_4 = (h // 2) * (w // 2)
    cnt_2 = h // 2 + w // 2
    cnt_1 = 1
    tmp_1 = 0
    tmp_2 = 0
    tmp_4 = 0

    for v in d.values():
        if v % 4 == 0:
            tmp_4 += v // 4
        elif v % 2 == 0:
            tmp_4 += v // 4
            tmp_2 += 1
        else:
            tmp_4 += v // 4
            tmp_2 += (v % 4) // 2
            tmp_1 += 1
    if tmp_4 >= cnt_4 and cnt_2 <= tmp_2 + (tmp_4 - cnt_4) * 2 and cnt_1 == tmp_1 + tmp_2 + (tmp_4 - cnt_4) * 2 - cnt_2:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 9184
import random

n = int(input())
dice_list = [list(map(int, input().split())) for i in range(n)]


class Dice():
    def __init__(self, dice, directions):
        self.dice = dice
        self.directions = directions

    def roll(self):
        for direction in self.directions:
            NS = [0, 1, 5, 4]
            WE = [0, 2, 5, 3]
            copy_dice = self.dice[:]

            if direction == 'N':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-3]]
            elif direction == 'S':
                for j in range(4):
                    self.dice[NS[j]] = copy_dice[NS[j-1]]
            elif direction == 'W':
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-3]]
            else:
                for j in range(4):
                    self.dice[WE[j]] = copy_dice[WE[j-1]]

        return self.dice


def check_equal(dice_1, dice_2):
    for i in range(n+100):
        dice_A = Dice(dice_1, random.choice(['N', 'S', 'W', 'E']))

        if dice_A.roll() == dice_2:
            return True
            break

    else:
        return False

check_dice = True

for i in range(n):
    for j in range(i+1, n):
        if check_equal(dice_list[i], dice_list[j]) == True:
            check_dice = False
            break


if check_dice == True:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 8208
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n, t, l, b;
    while (cin >> n >> t >> l >> b && n){
        VI a(n+1);
        while (l--){
            int x;
            cin >> x;
            a[x] = 1;
        }
        while (b--){
            int x;
            cin >> x;
            a[x] = 2;
        }
        vector<vector<double> > dp(t+2, vector<double>(n+1));
        dp[0][0] = 1.0;
        REP(i,t){
            REP(j,n){
                FOR(k,1,6){
                    int next = j + k;
                    if (next > n) next = 2*n - next;
                    if (a[next] == 2) next = 0;
                    if (a[next] != 1) dp[i+1][next] += 1.0/6.0 * dp[i][j];
                    else dp[i+2][next] += 1.0/6.0 * dp[i][j];
                }
            }
            dp[i+1][n] += dp[i][n];
        }
        printf("%.10f\n", dp[t][n]);
    }
    return 0;
}

Measured memory_bytes: 3148
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use grapth::*;
use input_scanner::*;
use math::*;
use string_algorithm::*;
use util::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let k: usize = scan.next();
    let mut p: Vec<i32> = scan.next_vec(n);
    p.sort();
    let mut ans = 0;
    for i in 0..k {
        ans += p[i];
    }
    println!("{}", ans);
}

mod datastructure {}
mod grapth {}
mod math {}
mod string_algorithm {}
mod util {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }

    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str =
                unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }
}


Measured memory_bytes: 2152
def resolve():
    N = int(input())

    P = []
    for _ in range(N):
        x, l = map(int, input().split())
        P.append((x - l, x + l))

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

    cnt = 0
    pre = -(1 << 60)
    for (l, r) in P:
        if pre > l:
            continue
        cnt += 1
        pre = r

    print(cnt)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 23988
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define REP(i,x,n) for(int i = (x); i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll h,w,k,ans=0;
    cin>>h>>w>>k;
    vector<string> c(h);
    rep(i,h) cin>>c[i];
    rep(biti,(1<<h))rep(bitj,(1<<w)){
        ll cnt=0;
        rep(i,h)rep(j,w){
            if(biti & (1<<i)) continue;
            if(bitj & (1<<j)) continue;
            if(c[i][j]=='#') cnt++;
        }
        if(cnt==k) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n,a,b;
	cin>>n>>a>>b;
	cout << ((b-a)%2==0?"Alice":"Borys");
	// your code goes here
	return 0;
}

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

const int INF = 1e8;

int n, m;
vector<int> L, R;

vector<vector<int> > stuff;

struct node {
	node* c[2];
	int lx, rx;
	int maxv;
	int lazy;

	void upd() {
		maxv = lazy + max(c[0]->maxv, c[1]->maxv);
	}
};

node* init(int lx, int rx) {
	node* v = new node();
	v->lx = lx; v->rx = rx;
	if (lx + 1 == rx) {
		v->maxv = -(m+1-lx);
	} else {
		v->c[0] = init(lx, (lx + rx) / 2);
		v->c[1] = init((lx + rx) / 2, rx);
		v->upd();
	}
	return v;
}

void upd(node* v, int ulx, int urx, int del) {
	if (urx <= v->lx || v->rx <= ulx) {
		return;
	} else if (ulx <= v->lx && v->rx <= urx) {
		v->maxv += del;
		v->lazy += del;
	} else {
		upd(v->c[0], ulx, urx, del);
		upd(v->c[1], ulx, urx, del);
		v->upd();
	}
}

int max_query(node* v, int qlx, int qrx) {
	if (qrx <= v->lx || v->rx <= qlx) {
		return -INF;
	} else if (qlx <= v->lx && v->rx <= qrx) {
		return v->maxv;
	} else {
		return v->lazy + max(max_query(v->c[0], qlx, qrx), 
							 max_query(v->c[1], qlx, qrx));
	}
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;
	L.resize(n);
	R.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> L[i] >> R[i];
	}
	stuff.resize(m+1);
	for (int i = 0; i < n; i++) {
		stuff[L[i]].push_back(R[i]);
	}

	node* segtree = init(0, m+2);
	int ans = max(0, n-m);
	for (int l = 0; l <= m; l++) {
		for (int i = 0; i < int(stuff[l].size()); i++) {
			int r = stuff[l][i];
			upd(segtree, 0, r+1, 1);
		}
		ans = max(ans, max_query(segtree, l+1, m+2) - l);
	}
	cout << ans << '\n';
}


Measured memory_bytes: 28800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
using namespace std;

typedef long long ll;



class segment_tree {
private:
	int num;
	vector<int> dat;

	// TODO: change operator and its identity
	static const int INI = 0;
	int op(int a, int b) {
		return a + b;
		//return min(a, b);
	}

public:
	segment_tree(int n_) {
		num = 1;
		while (num < n_) num *= 2;
		dat = vector<int>(2 * num, INI);
	}

	// update the k-th value (0-indexed) to a
	void update(int k, int a) {
		k += num - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}

	// get the value of the range [a, b)
	// k: the index of the node  
	// [left, right): the range corresponds to the k-th node
	// called like getval(a, b) or getval(a, b, 0, 0, num)
	int getval(int a, int b, int k = 0, int left = 0, int right = -1) {
		if (right < 0) right = num;
		if (right <= a || b <= left) return INI;
		if (a <= left && right <= b) return dat[k];
		int vleft = getval(a, b, 2 * k + 1, left, left + (right - left) / 2);
		int vright = getval(a, b, 2 * k + 2, left + (right - left) / 2, right);
		return op(vleft, vright);
	}
};

class segment_tree_r {
private:
	int num;
	vector<int> dat;

	// TODO: change operator and its identity
	static const int INI = 0;
	int op(int a, int b) {
		return a^b;
	}

public:
	segment_tree_r(int n_) {
		num = 1;
		while (num < n_) num *= 2;
		dat = vector<int>(2 * num, INI);
	}

	// update the k-th value (0-indexed) to a
	void update(int k, int a) {
		k += num - 1;
		dat[k] = a;
		while (k > 0) {
			k = (k - 1) / 2;
			dat[k] = op(dat[2 * k + 1], dat[2 * k + 2]);
		}
	}

	// get the value of the range [a, b)
	// k: the index of the node  
	// [left, right): the range corresponds to the k-th node
	// called like getval(a, b) or getval(a, b, 0, 0, num)
	int getval(int a, int b, int k = 0, int left = 0, int right = -1) {
		if (right < 0) right = num;
		if (right <= a || b <= left) return INI;
		if (a <= left && right <= b) return dat[k];
		int vleft = getval(a, b, 2 * k + 1, left, left + (right - left) / 2);
		int vright = getval(a, b, 2 * k + 2, left + (right - left) / 2, right);
		return op(vleft, vright);
	}
};


int main() {
	int n; cin >> n;
	vector<int> a(n + 2);
	segment_tree l(n);
	segment_tree_r r(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i < n; i++) {
		l.update(i, a[i]);
		r.update(i, a[i]);
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		int lo = i, hi = n + 1;
		while (hi - lo > 1) {
			int mid = lo + (hi - lo) / 2;
			if (l.getval(i, mid) == r.getval(i, mid)) lo = mid;
			else hi = mid;
		}
		ans += lo - i;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<pair<long, long>> data(M);
  for(int i = 0; i < M; i++){
    cin >> data.at(i).first >> data.at(i).second;
  }
  string S;
  int flag;
  for(int i = 0; i < 1000; i++){
    S = to_string(i);
    flag = 1;
    if(S.size() != N)continue;
    for(int j = 0; j < M; j++){
      if((S.at(data.at(j).first - 1) - '0') != data.at(j).second){
        flag = 0;
        break;
      }
    }
    if(flag == 1){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


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

void swap(int *xs, int front, int back)
{
    int temp = xs[front];
    xs[front] = xs[back];
    xs[back] = temp;
}

bool isSwap(int nowBibs, int nextBibs, int baton)
{
    return (nowBibs % baton) > (nextBibs % baton);
}

void printIntArray(int *arr, int num)
{
    for (int i = 0; i < num; i++)
    {
        printf("%d\n", arr[i]);
    }
}

void batonRelay(int *arr, int num, int baton)
{
    for (int i = 0; i < num - 1; i++)
    {
        if (isSwap(arr[i], arr[i + 1], baton))
        {
            swap(arr, i, i + 1);
        }
    }
}

int main()
{
    int nm[2];
    scanf("%d"
          "%d",
          &nm[0], &nm[1]);

    int studentNum = nm[0];
    int batonNum = nm[1];

    int students[studentNum];

    for (int i = 0; i < studentNum; i++)
    {
        scanf("%d", &students[i]);
    }

    for (int bi = 0; bi < batonNum; bi++)
    {
        batonRelay(students, studentNum, bi + 1);
    }

    printIntArray(students, studentNum);

    return 0;
}



Measured memory_bytes: 2108
N=int(input())
list1 = list(map(int, input().split()))

list2=[]
for i in list1:
    if i%2==0:
        list2.append(i)
    else:
        continue

list3=[]
for j in list2:
    if j%3==0 or j%5==0:
        list3.append(j)
    else:
        continue

x=len(list2)
y=len(list3)

if x==y:
    print('APPROVED')
else:
    print('DENIED')


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

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<vector<int>> state(N, vector<int>(N, -1));
	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		int a;
		cin >> a;
		for (int j = 0; j < a; j++)
		{
			int x, y;
			cin >> x >> y;
			state[i][x-1] = y;
		}	
	}
	for (int bit = 0; bit < (1<<N); bit++)
	{
		bool F = true;
		int tmp = 0;
		for (int i = 0; i < N; i++)
		{
          	if(!(bit&1<<i))continue;
          	tmp++;
			for (int j = 0; j < N; j++)
			{
				if(state[i][j] == -1) continue;
				else if(state[i][j] == 0){
					if(bit&1<<j)F = false;
				}else{
					if(!(bit&1<<j))F = false;
				}
			}
		}
		if(F)ans = max(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
ans = [''] * len(s)

for i in range(len(s)):
  rot = ord(s[i]) + n
  if rot > ord('Z'):
    rot -= (ord('Z') - ord('A') + 1)
    
  ans[i] = chr(rot)
  
print(''.join(ans))


Measured memory_bytes: 3060
n,m=map(int,input().split())
a=list(map(int,input().split()))
from collections import Counter
c=Counter()
sm=0
c[sm]+=1
for i in range(n):
  sm+=a[i]
  c[sm%m]+=1
ans=0
for v in c.values():
  ans+=v*(v-1)//2
print(ans)


Measured memory_bytes: 14252
#include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

// 入力
int N;
long long a[100010][3]; // a[i], b[i], c[i] をそれぞれまとめて a[i][0], a[i][1], a[i][2] にしてしまう

// DP テーブル
long long dp[100010][3];

int main() {
    int N; cin >> N;
    for (int i = 0; i < N; ++i) for (int j = 0; j < 3; ++j) cin >> a[i][j];
  
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
    if(k==j){continue;}
    else{ chmax( dp[i+1][k],dp[i][j]+a[i][k]);}}}}
    long long i=0;
    for (int k = 0; k < 3; ++k) i=max(dp[N][k],i);
    cout<<i<<endl;}
    


Measured memory_bytes: 4992
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0; i<n; i++) cin >> a[i];

    int min_cost = 1e9;
    for (int i=-100; i<=100; i++)
    {
        int cost = 0;
        for (int j=0; j<n; j++)
        {
            cost += (a[j] - i) * (a[j] - i);
        }
        min_cost = min(min_cost, cost);
    }
    cout << min_cost << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A, B;
  cin >> A >> B;
  int sum = A+B;
  int sub = A-B;
  int mul = A*B;
  if (sum<sub){
    if(sub<mul){
      cout << mul;
    }
    else {
      cout << sub;
    }
  }
  else{
    if(sum<mul){
      cout << mul;
    }
    else{
      cout << sum;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
template <typename T> using lim = numeric_limits<T>;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll w, h, x, y;
    cin >> w >> h >> x >> y;
    cout << fixed << setprecision(9) << (long double)(w * h) / 2 << " " << (y == h - y and x == w - x) << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ld> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<ll>> vvll;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define TS to_string
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


ll INF = 1e9;
ll MOD = 1000000007;
ll LINF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "yes" << endl;}
void no(){ cout << "no" << endl;}

//-----------------------------------------
template<class T>
class BT{
  private:
    struct Node{
      T key;
      Node *par, *lef, *rig;
    };
    Node *NIL, *root;
  public:
    BT(){
      NIL = NULL;
    }
    void insert(T k){
      Node *y = NIL;
      Node *x = root;
      Node *z;

      z = (Node*)malloc(sizeof(Node));
      z->key = k;
      z->lef = NIL;
      z->rig = NIL;

      while(x != NIL){
        y = x;
        if(k < x->key) x = x->lef;
        else x = x->rig;
      }
      z->par = y;
      if(y == NIL) root = z;
      else if(z->key < y->key) y->lef = z;
      else y->rig = z;
    }

    void pmid(Node *t){
      if(t == NIL) return;
      pmid(t->lef);
      cout << " " << t->key;
      pmid(t->rig);
    }

    void ppre(Node *t){
      if(t == NIL) return;
      cout << " " << t->key;
      ppre(t->lef);
      ppre(t->rig);
    }

    void pr(){
      pmid(root);
      cout <<endl;
      ppre(root);
      cout <<endl;
    }
};
//-----------------------------------------

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

  int n;
  cin >> n;
  BT<int> tree;
  REP(i,n){
    string s;
    cin >> s;
    if(s == "insert"){
      int a;
      cin >> a;
      tree.insert(a);
    }
    else{
      tree.pr();
    }
  }



  return 0;
}





Measured memory_bytes: 26668
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[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 n = read_as_vec::<usize>()[0];
    let a = read_as_vec::<i64>();

    let sum: i64 = a.iter().sum();

    let mut ans = std::i64::MAX;

    let mut x = 0;

    for i in 0..n-1{
        x += a[i];
        let y = sum - x;

        ans = cmp::min(ans, (x-y).abs());
    }

    println!("{}", ans);
}


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

int main(){
  long long int N;
  cin >> N;
  vector<string> S(N);
  long long int a[5];
  for(long long int i = 0; i < N; i++){
    cin >> S[i];
  }
  for(int i = 0; i < 5; i++){
    a[i] = 0;
  }

  for(long long int i = 0; i < N; i++){
    if(S[i].front() == 'M'){ a[0] += 1; }
    else if(S[i].front() == 'A'){ a[1] += 1; }
    else if(S[i].front() == 'R'){ a[2] += 1; }
    else if(S[i].front() == 'C'){ a[3] += 1; }
    else if(S[i].front() == 'H'){ a[4] += 1; }
  }

  long long int sum = 0;

  sum += a[0] * a[1] * a[2];
  sum += a[0] * a[1] * a[3];
  sum += a[0] * a[1] * a[4];
  sum += a[0] * a[2] * a[3];
  sum += a[0] * a[2] * a[4];
  sum += a[0] * a[3] * a[4];
  sum += a[1] * a[2] * a[3];
  sum += a[1] * a[2] * a[4];
  sum += a[1] * a[3] * a[4];
  sum += a[2] * a[3] * a[4];

  cout << sum;

return 0;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    long long int n, w;
    cin >> n >> w;
 
    vector<pair<long long int, long long int>> wt;
 
    long long int x, y;
    for(long long int i=1; i<=n; i++){
        cin >> x >> y;
        wt.push_back({x,y});
    }
 
    sort(wt.begin(),wt.end());    
 
    vector<ll> dp(w+1);
    for(int i=0; i<=w; i++){
        if(wt[0].first<=i) dp[i]=wt[0].second;
        else dp[i]=0;
    }
 
    for(int i=1; i<n; i++){
        vector<ll> new_dp(w+1);
        for(int cap=0; cap<=w; cap++){
            if(wt[i].first>cap) new_dp[cap]=dp[cap];
            else new_dp[cap]=max(wt[i].second+dp[cap-wt[i].first],dp[cap]);
        }
        dp=new_dp;
    }
    cout<<dp[w]<<'\n';
 
    return 0;
}

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

struct Gard{
  char a;
  int b;
};

bool compare_as_ints(Gard i,Gard j){
  return (i.b<j.b);
}

int partition(Gard A[],int p,int r){
  Gard x=A[r];
  int i=p-1;

  for(int j=p; j<=r-1; j++){
    if(A[j].b<=x.b){
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

void quickSort(Gard A[],int p,int r){
  if(p<r){
    int q=partition(A,p,r);
    quickSort(A,p,q-1);
    quickSort(A,q+1,r);
  }
}

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

  Gard A[100000],B[100000];
  for(int i=0; i<n; i++){
    cin >> A[i].a >> A[i].b;
    B[i]=A[i];
  }

  quickSort(A,0,n-1);
  stable_sort(B,B+n,compare_as_ints);

  for(int i=0; i<n; i++){
    if(A[i].a!=B[i].a){
      cout << "Not stable" << endl;
      break;
    }
    if((A[i].a==B[i].a)&(i==n-1)){
      cout << "Stable" << endl;
    }
  }

  for(int i=0; i<n; i++){
    cout << A[i].a << ' ' << A[i].b << endl;
  }

  return 0;
}


Measured memory_bytes: 4632
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<string.h>
#include <iomanip>
#include <sstream>
using namespace std;

int main() {
  int N, K;
  int ans = 0;
  int ttl = 0 ;
  string s;

  cin >> K >> N;

  vector<int> a(N);
  vector<int> b(N);
  b[0] = 0;
  for(int i = 0; i < N; i++){
    cin >> a[i];
    if(i > 0){
      b[i] = a[i] - a[i-1];
    }
    ans = max(ans, b[i]);
//    ttl += b[i];
  }
  ans = max(ans, (a[0]+(K-a[N-1])));
  // cout << a[0] << endl;
  // cout << (K-a[N-1]) << endl;
  // cout << ans << endl;
  cout << K-ans << endl;


}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int sum = 0;
  
  // ここにプログラムを追記
  for(int i = 0; i < N; i++){
    int start;
    int end;
    cin >> start >> end;
    sum += end - start + 1;
  }  
  
  cout << sum << endl;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    S.append(int(input()))

su = sum(S)
if su % 10 != 0:
    print(su)
else:
    S.sort()
    for i in range(len(S)):
        if S[i] % 10 != 0:
            su -= S[i]
            break
    if su % 10 != 0:
        print(su)
    else:
        print(0)

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

// Sieve of Eratosthenes
// https://youtu.be/UTVg7wzMWQc?t=2774
struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
  vector<pair<ll,int>> factor(ll x) {
    vector<pair<ll,int>> res;
    for (int p : primes) {
      int y = 0;
      while (x%p == 0) x /= p, ++y;
      if (y != 0) res.emplace_back(p,y);
    }
    if (x != 1) res.emplace_back(x,1);
    return res;
  }
};

int main() {
    int n;
    cin >> n;
    Sieve sieve(n+5);
    ll ans = 0;
    for (int c = 1; c < n; ++c) {
        int x = n - c;
        vector<P> factors = sieve.factor(x);
        ll count = 1;
        for (auto f : factors) {
            count *= f.second + 1;
        }
        ans += count;
    }
    cout << ans << endl;
    return 0;
}

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


int main() 
{ 
    long long int n,temp,j=1,i,ans = -1;
    cin>>n;
    for(i = 0;i<n;i++)
    {
        cin>>temp;
        if (temp == j)
        {
            ans++;
            j++;
        }
    //    cout<<i<<" "<<temp<<" "<<j<<" "<<ans<<endl;
    }
    
    
    if (ans > -1)
    {
        cout<<(n-ans-1);
    }
    else
    {
        cout<<ans;
    }

	return 0; 
} 


Measured memory_bytes: 256
use std::io::Read;
use std::cmp::min;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m: usize = it.next().unwrap().parse().unwrap();
    let inf = 1_000_000;
    let mut dp = vec![inf; 1 << n];
    dp[0] = 0;
    for _ in 0..m {
        let a: u32 = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        let mut bit = 0;
        for _ in 0..b {
            let c = it.next().unwrap().parse::<usize>().unwrap() - 1;
            bit |= 1 << c;
        }
        for j in 0..(1 << n) {
            let k = j | bit;
            dp[k] = min(dp[k], dp[j] + a);
        }
    }
    if dp[(1 << n) - 1] >= inf {
        println!("-1");
    } else {
        println!("{}", dp[(1 << n) - 1]);
    }
}

fn main() {
    run();
}


Measured memory_bytes: 4352
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
prv = -1

for i in A:
  ans += B[i-1]
  if prv == i - 1:
    ans += C[prv-1]
  
  prv = i

print(ans)

Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

/// [..)
struct SegTree(alias _fun, alias def, T)
if (is(typeof(def) : T))
{
    import std.functional : binaryFun;
    alias fun = binaryFun!_fun;

    ///
    this(size_t n, T[] ts) {
        this.n = 1;
        while (this.n < n) this.n *= 2;
        this.tree.length = this.n * 2 - 1;
        foreach (ref e; this.tree) e = def;
        foreach (i, e; ts) this.put(i, e);
    }

    ///
    void put(size_t i, T e) {
        i += this.n - 1;
        this.tree[i] = e;
        while (i > 0) {
            i = (i-1) / 2;
            this.tree[i] = fun(this.tree[i*2+1], this.tree[i*2+2]);
        }
    }

    ///
    T query(size_t a, size_t b) {
        T impl(size_t i, size_t l, size_t r) {
            if (r <= a || b <= l) return def;
            if (a <= l && r <= b) return this.tree[i];
            return fun(
                impl(i*2+1, l, (l+r)/2),
                impl(i*2+2, (l+r)/2, r)
            );
        }
        return impl(0, 0, this.n);
    }

private:
    size_t n;
    T[] tree;
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(size_t n, T[] arr = [])
{
    return SegTree!(f, def, T)(n, arr);
}

///
SegTree!(f, def, T) seg_tree(alias f, alias def, T)(T[] arr)
{
    return SegTree!(f, def, T)(arr.length, arr);
}

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp.to!(char[]);
    SegTree!("a + b", 0, int)[] ss;
    ss.length = 26;
    foreach (ref s; ss) s = SegTree!("a + b", 0, int)(N+1, []);
    foreach (i, c; S) {
        ss[c-'a'].put(i, 1);
    }

    auto Q = readln.chomp.to!int;
    foreach (_; 0..Q) {
        auto q = readln.split;
        if (q[0] == "1") {
            auto i = q[1].to!int-1;
            auto c = q[2][0];
            ss[S[i]-'a'].put(i, 0);
            S[i] = c;
            ss[c-'a'].put(i, 1);
        } else {
            auto l = q[1].to!int-1;
            auto r = q[2].to!int;
            int ret;
            foreach (i, ref s; ss) {
                ret += min(s.query(l, r), 1);
            }
            writeln(ret);
        }
    }
}

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



int main()
{
    int a, b, c ,k;
    cin >> a >> b >> c >> k;
    if (k <= a)
    {
        cout << k << endl;
        return(0);
    }
    else if(k > a && k <= a + b)
    {
        cout << a << endl;
        return (0);
    }
    else if(k > a && k > a + b)
    {
        cout << a + (-1 * (k - (a + b))) << endl;
        return(0);
    }


}

Measured memory_bytes: 3160
/*input
codefestival
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a[3];
	REP(i,3) cin>>a[i];
	sort(a,a+3);
	if(a[2]==a[1]+a[0]) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdint>

using i16 = std::int16_t;
using i32 = std::int32_t;
using i64 = std::int64_t;
template<class T>
using Vector = std::vector<T>;
using String = std::string;
using std::to_string;
using std::cin;
using std::cout;
using std::getline;
using std::stoi;
using std::endl;

void program();

int main()
{
    std::ios::sync_with_stdio(false);
    program();
}

void program() {
    auto line = String();
    getline(cin, line);

    int sum = 0;
    for (i32 i = 0; i < (i32)line.size(); ++i) {
        sum += (i32)(line[i] - '0');
        sum %= 9;
    }
    if (sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

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

  ll n;
  cin >> n;

  map<string, ll> m;
  rep(i, n) {
    string s;
    cin >> s;
    m[s]++;
  }

  ll max_val = 0;
  FORm(it, m) {
    chmax(max_val, it->second);
  }

  FORm(it, m) {
    if (it->second == max_val) {
      cout << it->first << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 25676
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	if(s.size()%2){
		cout<<"No\n";
		return 0;
	}
	for(int i=0;i<s.size();i+=2){
		if(s[i]!='h'||s[i+1]!='i'){
			cout<<"No\n";
			return 0;
		}
	}
	cout<<"Yes\n";
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>

int gen_price(int x, int y, int z) {
    return x * 10 + y + z;
}

int main() {
    int A, B, C;
    std::cin >> A >> B >> C;
    
    int ans = 0;
    if (A >= B && A >= C) {
        if (B >= C)
            ans = gen_price(A, B, C);
        else
            ans = gen_price(A, C, B);       
    } else if (B >= A && B >= C) {
        if (A >= C)
            ans = gen_price(B, A, C);
        else
            ans = gen_price(B, C, A);
    } else {
        if (B >= A)
            ans = gen_price(C, B, A);
        else
            ans = gen_price(C, A, B);
    }
        std::cout << ans << std::endl;
}

Measured memory_bytes: 256
N = int(input())
F = [[] for _ in range(N)]
P = [[] for _ in range(N)]
for i in range(N):
    F[i] = list(map(int,(input().split())))
for i in range(N):
    P[i] = list(map(int,(input().split())))

ans = []

# 全探査
K = 2 # 選択肢の数
M = 10 # 問題の個数
for i in range(K**M):
    TF=[0]*M

    for j in range(M):
        TF[M-j-1] = i % K
        i //= K
    
    benefit = 0
    if sum(TF) != 0:
        for j in range(N):
            c = 0
            for k in range(10):
                if TF[k] == 1 and F[j][k] == 1:
                    c += 1
            benefit += P[j][c]
        ans.append(benefit)

print(max(ans))


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

#define INF 1000000000
#define MOD 1000000007

typedef  long long ll;

using namespace std;

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

double euclid_distance(double a,double b){
    return sqrt(a*a+b*b);
}

ll gcd(ll  a,ll b){
    ll r;
    if(a < b){
        ll tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r = a % b){
        a = b;
        b = r;
    }
    return b;
}
/*
ll Integer_factorization(ll n){
    ll num = 0;
    ll ndash = n;
    if(n == 1) return 1;
    ll a = 2;
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    return num;
}
*/

ll r_fuct[2000];
ll fuct[2000];

//MOD逆元
void conb(ll n,ll k){
    fuct[0] = 1;
    for(int i = 1;i < k+1;i++){
        fuct[i] *= fuct[i-1]%MOD;
        
        ll b = MOD, u = 1, v = 0;
        ll value = fuct[i];
        while (b) {
            ll t = value / b;
            value -= t * b;
            swap(value, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) u += MOD;
        r_fuct[i] = u;
    }
}

ll factrial(ll n){
    if(n == 0) return 1;
    ll p = factrial(n-1)*n%MOD;
    return p;
}

//MOD逆元
ll farmat(ll n,ll p){    
    if(p == 0) return 1;
    else if(p == 1) return n%MOD;
    ll d = farmat(n,p/2);
    if(p%2 == 0){
        return (d*d)%MOD;
    }else{
        return ((n*d)%MOD*d)%MOD;
    }
}

ll conbination(ll n,ll k){
    ll a = factrial(n);
    ll b = factrial(k);
    ll c = factrial(n-k);
    return (a*farmat(b,MOD-2)%MOD*farmat(c,MOD-2))%MOD;
}

int memo[10000000];

int fib(int i){
    if(i <= 1) return i;
    if(memo[i] != 0) return memo[i];
    return memo[i] = fib(i-1)+fib(i-2);
}

ll dig(ll n){
    ll d = 0;
    while(n != 0){
        n/=10;
        d++;
    }
    return d;
}

void solve() {
  vector<string> s(3);
  for(int i = 0;i < 3;i++){
      cin >> s[i];
  }
  cout << s[0][0] << s[1][1] << s[2][2] << endl;
}




int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	solve();
	return 0;
}



Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	k := nextInt()
	n := nextInt()
	alist := make([]int, n)
	kukanlist := make([]int, n)

	for i := 0; i < n; i++ {
		alist[i] = nextInt()
	}

	// 区間リストの作成
	for i := 0; i < n-1; i++ {
		kukanlist[i] = alist[i+1] - alist[i]
	}
	kukanlist[n-1] = k - alist[n-1] + alist[0]

	// 通るべきではない最長区間の長さを探す
	maxkukan := -1
	for i := 0; i < n; i++ {
		if kukanlist[i] > maxkukan {
			maxkukan = kukanlist[i]
		}
	}

	//fmt.Println(kukanlist, maxkukan)
	fmt.Println(k - maxkukan)
}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 6120
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	int k;cin>>k;
	while(k>0){
		if(c<=b||c<=a){
			c*=2;k--;
		}
		if(k>0){
			if(b<=a){
				b*=2;k--;
			}
		}
		if((c>b&&c>a)&&b>a)
			break;
	}
	if((c>b&&c>a)&&b>a)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 3648