akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
int fi(int t, int f)
{
  if(t % f == 0) return t;
  else return ((t / f) + 1) * f;
}
int main(void)
{
  int n, c[500] = {}, s[500] = {}, f[500] = {};
  int t[500] = {};
  std::cin >> n;
  for(int i = 0; i != n; i++) std::cin >> c[i] >> s[i] >> f[i];
  for(int i = 0; i != n - 1; i++){
    for(int j = 0; j <= i; j++){
      t[j] = std::max(s[i], fi(t[j], f[i])) + c[i];
    }
  }
  for(int i = 0; i != n; i++) std::cout << t[i] << std::endl;
  return 0;
}

Measured memory_bytes: 256
#! /usr/bin/env python3

def f(a, b):
    if a < b : b, a = a, b
    c = a // b
    r = b * 3 * c
    if a % b > 0 : r += f(b, a-c*b)
    return r
N, X = map(int, input().split())
print(f(X, N-X))

Measured memory_bytes: 3064
#include <cstdio>
#include <algorithm>
using namespace std;
const int INF=10000000;
int dp[10][10];
int main(){
  while(true){
    int n;
    scanf("%d",&n);
    if(n==0) break;

    for(int i=0;i<10;i++)
      for(int j=0;j<10;j++) dp[i][j]=INF;

    int a,b,c;
    for(int i=0;i<n;i++){
      scanf("%d %d %d",&a,&b,&c);
      dp[a][b]=dp[b][a]=c;
    }
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        for(int j=0;j<10;j++){
          dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
        }
      }
    }
    int sum[10]={0};
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
        if(i!=j && dp[i][j]!=INF){
          sum[i]+=dp[i][j];
        }
      }
    }
    int ans=INF,ans_i=0;
    for(int i=0;i<10;i++){
      if(ans>sum[i] && sum[i]!=0){
        ans=sum[i];
        ans_i=i;
      }
    }
    printf("%d %d\n",ans_i,ans);
  }
  return 0;
}

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

using namespace std;

bool stat[10005] = {0};
int h, n, a[1005], b[1005], ans[10005];

long long atk(int x) {
  if(x <= 0) return 0;
  else if(stat[x]) return ans[x];
  else {
    long long mana = pow(10, 9) + 5;
    for(int axa = 0; axa < n; axa++) {
      mana = min(mana, atk(x - a[axa]) + b[axa]);
    }
    ans[x] = mana;
    stat[x] = 1;
    return mana;
  }
}

int main() {
  cin >> h >> n;
  for(int ana = 0; ana < n; ana++) {
    cin >> a[ana] >> b[ana];
  }
  cout << atk(h) << "\n";
}

Measured memory_bytes: 768
#include <stdio.h>
 
int main(void){
  int i;
  char st,al[53] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
   
  do{
    scanf("%c", &st);
 
    for(i=0;i<52;i++)
      if(al[i] == st){
        st = al[ (i+26)%52 ];
        break;
      }
 
    printf("%c", st);
 
  }while(st != '\n');
 
  return 0;
}


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

int rem[200005];

int main()
{
	int n;
	scanf("%d",&n);
	char s[50];
	int ac = 0 , wa = 0 , re = 0 , tle = 0;
	char acc[] = "AC";
	char waa[] = "WA";
	char tlee[] = "TLE";
	char ree[] = "RE";
	for(int i = 0 ; i < n ; i++){
		scanf("%s",s);
		int k  = strcmp(s , acc);
		int l  = strcmp(s , waa);
		int m = strcmp(s , tlee);
		int p = strcmp(s , ree);
		if(k == 0) ac++;
		else if(l == 0) wa++;
		else if(m == 0) tle++;
		else if(p == 0) re++;
	}
	printf("%s x %d\n%s x %d\n%s x %d\n%s x %d\n",acc , ac , waa , wa , tlee , tle , ree , re);
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(*array)
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; }

const ll INF = 1e13;

int main() {
    ll A, B, M;
    cin >> A >> B >> M;

    vector<ll> a(A), b(B), x(M), y(M), c(M);
    REP(i, A) cin >> a[i];
    REP(i, B) cin >> b[i];
    REP(i, M) {
        cin >> x[i] >> y[i] >> c[i];
        --x[i];
        --y[i];
    }

    ll ans = *min_element(a.begin(), a.end()) + *min_element(b.begin(), b.end());
    REP(i, M) {
        ll tmp = a[x[i]] + b[y[i]] - c[i];
        if(tmp < ans) {
            ans = tmp;
        }
    }

    cout << ans << endl;

    return 0;
}

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

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

int main() {
    int n;
    cin >> n;
    string s[100];
    for (int i = 0; i < n; i++) {
        cin >> s[i];
    }
    
    int cnt[n][26];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 26; j++) {
            cnt[i][j] = 0;
        }
    }
    
    string ans = "";
    for (int i = 0; i < n; i++) {
        for(int j = 0; j < s[i].size(); j++) {
            cnt[i][s[i][j] - 'a']++;
        }
    }
    int used[26];
    
    for (int i = 0; i < 26; i++) {
        used[i] = 0;
        int mi = 1e9;
        for (int j = 0; j < n; j++) {
            if (cnt[j][i] ==0) {
                break;
            }
            mi = min(mi, cnt[j][i]);
            if (j == n - 1) {
                used[i] = mi;
            }
        }
    }
    
    for (int i = 0; i < 26; i++) {
        for (int j = 0; j < used[i]; j++) {
            ans += 'a'+ i;
        }
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
fun main(args : Array<String>) {
    val n = readLine()!!.toLong()
    val max = Math.sqrt(n.toDouble()).toLong()

    var min = Long.MAX_VALUE
    for (i in 1..max) {
        if (n % i == 0L) {
            val ans = n / i
            min = Math.min(min, Math.max(i.toString().length, ans.toString().length).toLong())
        }
    }

    println(min)
}

Measured memory_bytes: 33520
from sys import stdin,stdout,setrecursionlimit
from collections import Counter as C
setrecursionlimit(10**6)
M = 1000000007
input = stdin.readline
def write(n,sep="\n"):
	stdout.write(str(n))
	stdout.write(sep)
def gil():
	return list(map(int, input().split()))
	
n = int(input())
a, b, c = [], [], []
for i in range(n):
    x,y,z = gil()
    a.append(x)
    b.append(y)
    c.append(z)
    
mem = [[-1 for _ in range(3)] for _ in range(n+1)]
def rp(i, p):
    global a,b,c,n
    if i >= n:
        return 0
    if mem[i][p] != -1:
        return mem[i][p]
    av = [a[i] + rp(i+1, 0), b[i] + rp(i+1, 1), c[i] + rp(i+1, 2)]
    if p != -1:
        av[p] = 0
    ans = max(av)
    mem[i][p] = ans
    return ans
ans = rp(0, -1)
print(ans)
        
    
# on recursive mem sols, build the solution from the base case,
# ie, return 0 on basecase, and build up the solution.
# because state-cases below will not carry values from above, they only take values from below




Measured memory_bytes: 189320
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

 
const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }

int main(){
  int n; cin>>n;
  double ans=(double)(n-(n/2))/n;
  coutd(ans);
}

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

#include <iostream>
using namespace std;
int main() {
  string s;
  cin >> s;
  uint64_t n = s.size();
  bool is_strong = true;
  for (size_t i = 0; i < (n - 1) / 2; i++) {
    if (s[i] != s[n - i - 1]) {
      is_strong = false;
      break;
    }
  }

  for (size_t i = 0; i < (n - 1) / 4; i++) {
    if (s[i] != s[(n - 1) / 2 - i - 1]) {
      is_strong = false;
      break;
    }
    if (s[(n - 1) / 2 + 1 + i] != s[n - i - 1]) {
      is_strong = false;
      break;
    }
  }

  if (is_strong) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


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

int main(){
  int n, p[20];
  int count=0;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> p[i];
  }
  for(int i=0;i<n-2;i++){
    if((p[i]<p[i+1]&&p[i+1]<p[i+2])||(p[i]>p[i+1]&&p[i+1]>p[i+2])){
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

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

int main() {
    string S;
    cin >> S;

    int mod = 1e9+7;

    int n = sz(S);
    
    //dp[i][j] = 先頭i文字として考えられるもののうち, 13で割ったあまりがjであるものの数
    vector< vector<int> > dp(n+1, vector<int>(13));

    rep(i, n) {
        int rec = 0;
        if (i == 0) {
            if (S[0] != '?') {
                rec = S[0]-'0';
                dp[1][rec] = 1;
            }
            else { //?のとき
                rep(j, 10) {
                    dp[1][j] = 1;
                }
            }
            continue;
        }

        if (S[i] != '?') {
            rep(j, 13) {
                rec = 10*j + S[i]-'0';
                rec %= 13;
                if (dp[i][j] != 0) {
                    dp[i+1][rec] += dp[i][j];
                    dp[i+1][rec] %= mod;
                }
            }
            
            
        }
        else { // ?のとき
            rep(j, 13) { //i文字目までの余りj
                rep(k, 10) { //?をkとする
                    rec = 10*j + k;
                    rec %= 13;
                    dp[i+1][rec] += dp[i][j];
                    dp[i+1][rec] %= mod;
                }
            }
        }

    }

    cout << dp[n][5] << endl;

}

Measured memory_bytes: 8960
#include<bits/stdc++.h>
#define R register int
#define G if(++ip==ie)if(fread(ip=buf,1,SZ,stdin))
using namespace std;
const int SZ=1<<19,N=1e5+9,M=2*N;
char buf[SZ],*ie=buf+SZ,*ip=ie-1;
inline int in(){
    G;while(*ip<'-')G;
    R x=*ip&15;G;
    while(*ip>'-'){x*=10;x+=*ip&15;G;}
    return x;
}
int he[N],ne[M],to[M],f[N],a[N],b[N];
int Getf(R x){
    return x==f[x]?x:f[x]=Getf(f[x]);
}
void Dfs(R x,R op){
    a[x]=op;
    for(R y,i=he[x];i;i=ne[i])
        if((y=to[i])!=f[x])
            f[y]=x,Dfs(y,-op),a[x]+=a[y];
}
int main(){
    R n=in(),m=in(),rt=1,re=1,p=0,ans=0;
    for(R i=1;i<=n;++i)f[i]=i;
    for(R p=0,i=1;i<=m;++i){
        R x=in(),y=in();
        if(Getf(x)!=Getf(y))f[f[x]]=f[y];
        else{rt=x,re=y;continue;}
        ne[++p]=he[x];to[he[x]=p]=y;
        ne[++p]=he[y];to[he[y]=p]=x;
    }
    f[rt]=0;Dfs(rt,1);
    if(n==m){
        for(R x=re;x;x=f[x])b[++p]=a[x];
        if(p&1){
            if(a[rt]&1)return puts("-1"),0;
            for(R x=re;x;x=f[x])a[x]-=a[rt]>>1;
        }
        else{
            if(a[rt])return puts("-1"),0;
            sort(b+1,b+p+1);
            for(R x=re;x;x=f[x])a[x]-=b[p>>1];
        }
    }
    else if(a[rt])return puts("-1"),0;
    for(R i=1;i<=n;++i)ans+=abs(a[i]);
    return cout<<ans<<endl,0;
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
  
#define rep(i,a,b) for(int i = a ; i <= b; i++)
#define dep(i,a,b) for(int i = a ; i >= b; i--)
#define F first
#define S second
#define pb push_back
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define dbg(a) cout<<#a<<" = "<<a<<endl
#define dbg2(a,b) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<endl
#define dbg3(a,b,c) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<endl
#define dbg4(a,b,c,d) cout<<#a<<" = "<<a<<", "<<#b<<" = "<<b<<", "<<#c<<" = "<<c<<", "<<#d<<" = "<<d<<endl
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
 
 
void solve()
{
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    vi ans(n+1,mod);
    ans[0]=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<=i+2;j++){
            if(j>=n) break;
            ans[j] = min(ans[j], abs(a[i]-a[j])+ans[i]);
            // dbg2(ans[j],j);
        }
    }
    cout<<ans[n-1];
}
 
int main()
{   
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cout << fixed << setprecision(11);
    clock_t beg=clock();
    int t=1, n;
    // cin>>t;
    // n = t;
    while(t--){
        // cout << "Case #" << n-t << ": ";
        solve();
    }
    //
    clock_t end=clock();
    fprintf(stderr, "%lf sec\n", (double)(end-beg)/(CLOCKS_PER_SEC));
    return 0;
}

Measured memory_bytes: 1024
def main():
    #1:初期化
    N,W = map(int,input().split())
    dp = [W+1]*(N*10**3+1)

    #2:初期値
    dp[0] = 0

    #3:dp実行部(貰うDP)
    for i in range(N):
        w, v = map(int,input().split())
        for i in range(N*10**3, v-1, -1):
            tmp = dp[i-v] + w
            if dp[i] > tmp:
                dp[i] = tmp
        #print(dp,sep="\n")

    #4:出力
    output = 0
    for i in range(N*10**3+1):
        if dp[i] <= W:
            output = i
    print(output)

if __name__ == '__main__':
    main()

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

#define REP(i,n) for(int (i)=0; i<(int)(n); i++)

int a[100010];
vector <int> v[100010];

int main(void) {
	int N;
	cin >> N;
	REP(i,N) cin >> a[i];
	REP(i,N) {
		v[a[i]].push_back(1);
		if(a[i] == 0) continue;
		v[a[i]+1].push_back(1);
		v[a[i]-1].push_back(1);
	}
	int ans = 0;
	REP(i,100000) ans = max(ans, (int)v[i].size());
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6400
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	p := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&p[i])
	}
	ans := 0
	for i := 0; i < n-2; i++ {
		if !(p[i+1] > p[i] && p[i+1] > p[i+2]) && !(p[i+1] < p[i] && p[i+1] < p[i+2]) {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstring>
#include <map>

#define ll long long
const ll MOD = 1e9 + 7;
const ll INF = 1 << 29;

int main()
{
    std::vector<int> durations(5);
    for (auto i=0; i<5; ++i)
        std::cin >> durations[i];

    std::sort(durations.begin(), durations.end(),
            [](int lhs, int rhs)
            {
                if (lhs % 10 == 0)
                    return true;

                if (rhs % 10 == 0)
                    return false;

                return (10 - lhs % 10) < (10 - rhs % 10);
            });

    int sum = 0;
    for (auto i=0; i<4; ++i)
    {
        auto a = durations[i];
        auto intervals = a % 10 == 0
                ? a
                : a - (a % 10) + 10;

        sum += intervals;
    }

    sum += durations[4];
    std::cout << sum << std::endl;
}

Measured memory_bytes: 256
N = int(input())
mul = N % 10
if(mul == 2 or mul == 4 or mul == 5 or mul == 7 or mul == 9):
    print("hon")
elif(mul == 0 or mul == 1 or mul == 6 or mul == 8):
    print("pon")
else:
    print("bon")


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

#define pb push_back
#define fi first
#define se second
#define ll long long
#define ld long double
#define pii pair < int , int >
#define pll pair < long long, long long >

const int N = 200005;


int main()
{
    #ifdef Estb_probitie
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n;
    cin >> n;
    int dp[n + 2][2][2][2] = {};

    for (int i = 0; i < n; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;
        if (!i)
        {
            dp[1][1][0][0] = a;
            dp[1][0][1][0] = b;
            dp[1][0][0][1] = c;
            continue;
        }

        dp[i + 1][1][0][0] = max(dp[i][0][1][0], dp[i][0][0][1]) + a;
        dp[i + 1][0][1][0] = max(dp[i][1][0][0], dp[i][0][0][1]) + b;
        dp[i + 1][0][0][1] = max(dp[i][1][0][0], dp[i][0][1][0]) + c;
    }

    cout << max(dp[n][0][0][1], max(dp[n][0][1][0], dp[n][1][0][0]));

}


Measured memory_bytes: 3328
a=list(input())
b=list(input())
flag_a=0
flag_b=0
for i in range(len(a)+len(b)):
  
  if(flag_a==flag_b):
    print(a[flag_a],end="")
    flag_a+=1
  else:
    print(b[flag_b],end="")
    flag_b+=1
print("")

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

using namespace std;

int main(void){
    string s;
    cin>>s;
    set<char> dict;
    for(int i=0;i<s.size();i++){
        dict.insert(s[i]);
    }
    if(dict.size()==2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

using namespace std;

class position {
public:
    int x;
    int y;
    int n;

    bool judge(position * next) {
        int distance = std::abs(x - next->x) + std::abs(y - next->y);
        int time = std::abs (next->n - n);
        // cout << distance << " " << time << endl;
        if (distance > time)
            return false;
        else if (distance == time)
            return true;
        else if (((time - distance) % 2) == 0)
            return true;
        else return false;
    }

    position(int x, int y, int n) : x(x), y(y), n(n) {}
};

int main() {
    unsigned num;
    cin >> num;

    auto vec = std::vector<position*>(num);

    for (unsigned i = 0; i < num; i++){
        int x, y, n;
        cin >> n >> x >> y;
        vec[i] = new position(x, y, n);
    }

    auto p = new position (0, 0, 0);
    bool flag = true;
    std::for_each(vec.begin(), vec.end(), [&](position * p2){
        if (! p->judge(p2)) {
            flag = false;
        }
        p = p2;
    });

    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 4096
def main():
  import itertools
  n,m,q=map(int,input().split())
  l=[tuple(map(int,input().split())) for _ in range(q)]
  a=[i+1 for i in range(m)]
  ans=0
  for i in itertools.combinations_with_replacement(a,n):
    cnt=0
    for j in range(q):
      ll=l[j]
      if i[ll[1]-1]-i[ll[0]-1]==ll[2]:
        cnt+=ll[3]
    ans=ans if ans>=cnt else cnt
    cnt=0
  print(ans)   
if __name__=='__main__':
  main()

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mp(a,b) make_pair(a,b)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int n;
    cin>>n;
    vector<pair<int64_t,int>> T_A(n),A_T(n);
    vector<int64_t> a(n),b(n);
    priority_queue<pair<int64_t,int>> taq,atq,dish;
    rep(i,n){
        cin>>a[i]>>b[i];
        T_A[i] = mp(a[i]-b[i],i);
        taq.push(mp(b[i]-a[i],i));
        A_T[i] = mp(b[i]-a[i],i);
        atq.push(mp(a[i]-b[i],i));
        dish.push(mp(a[i]+b[i],i));
    }
    vector<bool> eaten(n,false);
    all(T_A),all(A_T);
    int64_t tp=0,ap=0;
    int turn = 0;
    while(turn<n){
        //if(turn%2==0){//高橋のターン
            /*
            while(eaten[taq.top().second]){
                taq.pop();//もう食べたことあったら、削除して次
            }
            */
           while(eaten[dish.top().second]){
               dish.pop();
           }
           eaten[dish.top().second]=true;
           if(turn%2==0){
           tp += a[dish.top().second];
           }
           else{
               ap += b[dish.top().second];
           }
           dish.pop();
            //eaten[taq.top().second]=true;
            //tp += a[taq.top().second];
            //taq.pop();
        //}
        /*
        else{//青木のターン
            while(eaten[atq.top().second]){
                atq.pop();//もう食べたことあったら、削除して次
            }
            eaten[atq.top().second]=true;
            ap += b[atq.top().second];
            atq.pop();
        }
        */
        turn++;
    }
    cout<<tp-ap<<endl;
}

Measured memory_bytes: 12884
#include <bits/stdc++.h>
#define fi(i,a,b) for (int i=a; i<=b; ++i)
#define fid(i,a,b) for (int i=a; i>=b; --i)
#define pp pair<int,int>
#define f first
#define s second
#define DAVu "Vacation"
#define maxn 100005
using namespace std;
int n, l[maxn][3], a[maxn][3] ;
int main()
{
    ios_base::sync_with_stdio(0) ;
    cin.tie(NULL); cout.tie(NULL) ;
    //freopen(DAVu".inp", "r", stdin) ;
    //freopen(DAVu".out", "w", stdout) ;
    cin >> n ;
    fi(i,1,n)
    fi(j,1,3)
        cin >> a[i][j] ;
    fi(i,1,n){
        l[i][1] = max(l[i-1][2], l[i-1][3])+a[i][1] ;
        l[i][2] = max(l[i-1][1], l[i-1][3])+a[i][2] ;
        l[i][3] = max(l[i-1][1], l[i-1][2])+a[i][3] ;
    }
    cout << max(l[n][1], max(l[n][2], l[n][3])) ;
}


Measured memory_bytes: 5972
#include <iostream>
#include <vector>
using namespace std;
const int max_num=200001;
vector<int> G;

void swap(long long int v[],int i,int j){
	long long int temp=v[i];
	v[i]=v[j];
	v[j]=temp;
}

void qsort(long long int v[],int left,int right){
	int i,last;

	if(left>=right)
		return;
	swap(v,left,(left+right)/2);
	last=left;
	for(i=left+1;i<=right;i++)
		if(v[i]>v[left])
			swap(v,++last,i);
	swap(v,left,last);
	qsort(v,left,last-1);
	qsort(v,last+1,right);
}

void insSort(long long int *a,int n, int g){
	int v,j;
	for(int i=g;i<n;i++){
		v=a[i];
		j=i-g;
		while(j>=0 && a[j]<v){
			a[j+g]=a[j];
			j=j-g;
			a[j+g]=v;
		}
	}
}

void shellSort(long long int *a,int n){
	for(int h=1;;){
		if(h>n)
			break;
		G.push_back(h);
		h=3*h+1;
	}
	for(int i=G.size()-1;i>=0;i--)
		insSort(a,n,G[i]);

}



void inputnumbers(int *n,long long int *a){
	cin >> *n;
	for(int i=0;i<*n;i++)
		cin >> *(a+i);
}

void printnumbers(int n,long long int *a){
	for(int i=0;i<n;i++)
		cout << *(a+i) << ' ';
	cout << endl;
}



long long int solve(int n,long long int a[]){
	int q=n/2;
	int r=n%2;

	//qsort(a,0,n-1);
	shellSort(a,n);

	//printnumbers(n,a);

	long long int sum=a[0];
	for(int i=1;i<q;i++)
		sum+=2*a[i];
	if(r==1)
		sum+=a[q];

	return sum;
}

int main() {
	long long int a[max_num];
	int n;

	inputnumbers(&n,a);

	//printnumbers(n,a);
	//qsort(a,0,n-1);
	//printnumbers(n,a);


	cout << solve(n,a) << endl;

	return 0;
}


Measured memory_bytes: 5172
#define _USE_MATH_DEFINES

#include <iostream>
#include <iterator>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <unordered_set>
#include <ctime>

using namespace std;
using ll = long long;
const ll INF = 0x3f3f3f3f3f3f3f3fLL;

void solve() {
	vector<int> cnt(26, 0);
	int all_cnt = 0;
	ll ans = 0;
	string s;
	getline(cin, s);
	for (int i = 0; i < s.size(); i++) {
		int sym = s[i] - 'a';
		cnt[sym]++;
		all_cnt++;
		ans += all_cnt - cnt[sym];
	}
	cout << ans + 1;
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	solve();

#ifdef LOCAL
	cerr << double(clock()) / CLOCKS_PER_SEC << " sec" << endl;
#endif
	return 0;
}

Measured memory_bytes: 764
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from bisect import bisect_left as bl, bisect_right as br
n,q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()

def sub(x, i):
    # i番目を取れるかどうか
    v = a[i]
    target = x - (v-x)
    num = i - bl(a, target)
    return num+1 >= n - i

anss = [None] * q
cumsum1 = [0] * n
cumsum0 = [0] * n
cumsum = [0] * n
for i in range(n):
    if i%2:
        cumsum1[i] = cumsum1[i-1] + a[i]
        cumsum0[i] = cumsum0[i-1]
    else:
        cumsum0[i] = cumsum0[i-1] + a[i]
        cumsum1[i] = cumsum1[i-1]
    cumsum[i] = cumsum[i-1] + a[i]

for j in range(q):
    x = int(input())
    l = 0
    r = n-1
    while l<r-1:
        m = (r+l)//2
        if sub(x, m):
            r = m
        else:
            l = m
    # rまではxより大きくて取れる
#     ans = sum(a[r:])
    ans = cumsum[-1] - cumsum[r-1]
    ii = r-2 - (n-r-1)
    if ii>=0:
        if ii%2:
            ans += cumsum1[ii]
        else:
            ans += cumsum0[ii]
    anss[j] = ans
write("\n".join(map(str, anss)))

Measured memory_bytes: 108584
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>
using namespace std;
int main()
{
	string A;
	cin >> A;
	int flag = 0;
	for (size_t i = 0; i < A.length(); i+=2)
	{
		if (A.at(i)=='L') {
			flag++;
		}
	}
	for (size_t i = 1; i < A.length(); i += 2)
	{
		if (A.at(i) == 'R') {
			flag++;
		}
	}
	if (flag==0)
	{
		cout << "Yes";
	}
	else {
		cout << "No";

	}
}


Measured memory_bytes: 256
from fractions import gcd
# from datetime import date, timedelta
# from heapq import *
import heapq
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import fractions
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def lcm(a, b):
    return a * b / fractions.gcd(a, b)


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

    # divisors.sort()
    return divisors


def factorize(n):
    fct = []  # prime factor
    b, e = 2, 0  # base, exponent
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct


def is_prime(n):
    if n == 1:
        return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True


def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

def modpow(a, n, mod):
    res = 1
    while n > 0:
        if n & 1:
            res = res * a % mod
        a = a * a % mod
        n >>= 1
    return res


def modinv(a, mod):
    return modpow(a, mod - 2, mod)


def cnk(a, b):
    MOD = 10**9+7
    ret = 1
    for i in range(b):
        ret *= (a-i)
        ret %= MOD
        ret = ret * modinv(i+1, MOD) % MOD
    return ret


class UnionFind:
    def __init__(self, n):
        self.sz = [-1 for i in range(n)]

    # 検索
    def find(self, x):
        if self.sz[x] < 0:
            return x
        else:
            self.sz[x] = self.find(self.sz[x])
            return self.sz[x]

    # 併合
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return False
        if self.sz[x] > self.sz[y]:
            x, y = y, x
        self.sz[x] += self.sz[y]
        self.sz[y] = x

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # xが含まれている集合のサイズを求める
    def size(self, x):
        return -self.sz[self.find(x)]


def main():
    n,k = map(int, input().split())
    a = list(map(int, input().split()))
    ans = 0
    if n <= k:
        print(0)
        exit()
    a.sort()
    for i in range(k):
        a[-i - 1] = 0
    ans += sum(a)
    print(ans)




            


    




    


if __name__ == '__main__':
    main()


Measured memory_bytes: 27224
#include <iostream>


#include <string>


#include <algorithm>


#include <utility>


#include <iomanip>


#include <functional>


#include <queue>


#include <stack>


#include <map>


#include <set>


#include <vector>


#include <cmath>


#include <cctype>


#include <cstdio>


#include <bitset>


#define ll long long


#define INF 1000000000000000001


#define MOD 1000000007


using namespace std;





int main(){


    string s,t;


    cin >> s >> t;


    int ans=0;


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


        if(s[i]==t[i]){


            ans++;


        }


    }


    cout<<ans<<endl;


    return 0;


}

Measured memory_bytes: 256
#include<stdio.h>
#include<ctype.h>

int main(void){

    int N,K;
    char str[50];

    scanf("%d %d",&N,&K);
    scanf("%s",str);

    str[K - 1] = tolower(str[K - 1]);
    printf("%s",str);
    return 0;
}

Measured memory_bytes: 128
#define _DEBUG 1
#define _GLIBCXX_DEBUG

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

#ifdef _DEBUG
#define dump(x) cerr << #x << "=" << x << endl
#define dump2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define dump3(x, y, z)                                                     \
  cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z \
       << endl
#define check(s) cerr << s << endl
#else
#define dump(x)
#define dump2(x, y)
#define dump3(x, y, z)
#define check(s)
#endif

#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define unique(v) v.erase(unique(v.begin(), v.end()), v.end());

const ll LINF = 2e18;
const int INF = 1e9;

ll N, M, Q;
vector<int> a, b, c, d;
vector<int> A(10);
int mx = -1;

void dfs(int len, int last) {
  if (len == N) {
    int sum = 0;
    rep(i, Q) {
      if (A.at(b.at(i)) - A.at(a.at(i)) == c.at(i)) {
        sum += d.at(i);
      }
    }
    if (sum > mx) {
      mx = sum;
    }
  } else {
    for (int i = last; i <= M; i++) {
      A.at(len) = i;
      dfs(len + 1, i);
    }
  }
}

void solve() {
  dfs(0, 1);

  cout << mx << endl;
}

int main() {
  cin >> N >> M >> Q;
  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  rep(i, Q) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
    a.at(i)--;  // 0-indexed
    b.at(i)--;  // 0-indexed
  }
  solve();
  return 0;
}


Measured memory_bytes: 3596
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long

int gcd(int a,int b){
    return b ? gcd(b, a % b) : a;
}


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

    int n; cin >> n;
    vector<int> a(n);
    for(int i = 0;i < n;i ++ ) cin >> a.at(i);

    int ans = a.at(0);
    for(int i = 1;i < n;i ++){
        ans = gcd(ans,a.at(i));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
#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 ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	int R, C, K;
	cin >> R >> C >> K;
	
	vector<vector<int>> item(R + 1, vector<int>(C, 0));
	REP(i, K) {
		int r, c, v;
		scanf("%d %d %d", &r, &c, &v);
		--r; --c;
		item[r][c] = v;
	}
	
	vector<vector<ll>> dp(C, vector<ll>(4, 0)); // ([y])[i][j] := (y, i) にいて y の行で合計 j 個拾った
	dp[0][1] = item[0][0];
	
	REP(i, R) {
		vector<vector<ll>> nex(C, vector<ll>(4, 0));
		REP(j, C) REP(k, 4) {
			// 右に移動
			if (j + 1 < C) {
				chmax(dp[j + 1][k], dp[j][k]);
				if (k < 3) chmax(dp[j + 1][k + 1], dp[j][k] + item[i][j + 1]);
			}
			// 下に移動
			chmax(nex[j][0], dp[j][k]);
			chmax(nex[j][1], dp[j][k] + item[i + 1][j]);
		}
		dp = nex;
	}
	
	cout << dp[C - 1][0] << endl;
	return 0;
}


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

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;
ll  LINF = 1e18;


int main(){
	int n,x;cin >> n >> x;
	if(x == 1 || x == 2*n-1) {
		cout << "No" << endl;
		return 0;
	}else cout << "Yes" << endl;

	vector<int> ans(200006,0);
	vector<bool> num(200006,true);
	if(x == 2){
		ans[n-2] = x;
		ans[n-1] = 1;
		num[x] = false;
		num[1] = false;
	}else{
		ans[n-2] = x;
		ans[n-1] = 2*n-1;
		ans[n] = x-1;
		num[x] = false;
		num[2*n-1] = false;
		num[x-1] = false;
		if(n>2) {
			ans[n-3] = x-2;
			num[x-2] = false;
		}
	}
	int ind = 1;
	rep(i,2*n-1){
		if(ans[i]!=0) continue;
		while(!num[ind]) ind++;
		ans[i] = ind;
		num[ind] = false;
	}
	rep(i,2*n-1) cout << ans[i] << endl;


}


Measured memory_bytes: 4048
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;


int main(){
  string s; cin>>s;
  int size=s.size()-2;
  string ans;
  ans+=s[0];
  if(size<10){
    char c=size+'0';
    ans+=c;
    ans+=s[size+1];
  }else{
    ans+=size/10+'0';
    ans+=size%10+'0';
    ans+=s[size+1];
  }
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
        cout.tie(0);
		ll arr[5];
		ll ans=0;
		for(int i=0;i<5;i++)
		{
			cin>>arr[i];
		}
		for(int i=0;i<5;i++)
		{
			if(arr[i]==0)
			ans=i+1;
		}
		cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n; cin >> n;
  string a; cin >> a;
  int ans[n],total=0;
  for(int i=0;i<n;i++){
    if(a[i]=='I') total+=1;
    else total+=-1;
    ans[i]=total;
  }  
  sort(ans,ans+n);
  if(ans[n-1]<0) cout << 0 << endl;
  else cout << ans[n-1] << endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc146/tasks/abc146_f

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(i, n) REP(j, m) printf("%d%c", a[i][j], j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
#define LF(i)   (n - 1 + i)
#define PA(k)   ((k - 1) / 2)
#define LC(k)   (k * 2 + 1)
#define RC(k)   (k * 2 + 2)
#define M(l,r)  ((l + r) / 2)

template<typename T> class SegTree {
public:
  int n;
  int sz;
  T def;
  vector<T> dat;

  void init(int _n, T _def) {
    n = 1; while (n < _n) n <<= 1;
    sz = n * 2 - 1;
    def = _def;
    dat.resize(sz, def);
  }

  void update(int i, T x) {
    int k = LF(i);
    dat[k] = x;
    while (k > 0) {
      k = PA(k);
      dat[k] = min(dat[LC(k)], dat[RC(k)]);
    }
  }

  T query(int a, int b, int k, int l, int r) {
    if (r <= a || b <= l) return def;
    if (a <= l && r <= b) return dat[k];
    T vl = query(a, b, LC(k), l, M(l, r));
    T vr = query(a, b, RC(k), M(l, r), r);
    return min(vl, vr);
  }

  T query(int a, int b) {
    return query(a, b, 0, 0, n);
  }

  void dump() {
    REP(i, sz) printf("{%d,%d}%c", dat[i].first, dat[i].second, i + 1 == sz ? '\n' : ' ');
  }
};

//------------------------------------------------------------------------------
const int N_MAX = 1e5;
const int M_MAX = 1e5;

int N, M;
char S[N_MAX + 2];

//------------------------------------------------------------------------------
const int INF = 1e9+7;

typedef pair<int, int> pii;

SegTree<pii> dp;
int prv[N_MAX + 1];
vector<int> ans;

void solve() {
  dp.init(N + 1, { INF, -1 });
  dp.update(0, { 0, 0 });
  prv[0] = -1;
  FOR(i, 1, N) {
    if (S[i] == '1') continue;
    pii k = dp.query(i - M, i);
    dp.update(i, { k.first + 1, i });
    prv[i] = k.second;
  }
  if (prv[N] < 0) {
    puts("-1");
    return;
  }
  int v = N;
  int u = prv[v];
  while (u >= 0) {
    ans.push_back(v - u);
    v = u;
    u = prv[v];
  }
  for (int i = ans.size() - 1; i >= 0; i--) {
    printf("%d%c", ans[i], i == 0 ? '\n' : ' ');
  }
}

void input() {
  scanf("%d%d", &N, &M);
  scanf("%s", &S);
}

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


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

long long gcd(long long a, long long b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    else return gcd(b, a % b);
}

int main() {
    long long N, X;
    cin >> N >> X;
    long long x[N], y[N];
    for (long long i = 0; i < N; ++i) {
        cin >> x[i];
        y[i] = x[i] - X;
        if (y[i] < 0) y[i] *= -1;
    }
    long long maxy = 0;
    for (long long i = 0; i < N; ++i) {
        if (maxy < y[i]) maxy = y[i];
    }
    
    long long ans[N];
    ans[0] = y[0];
    for (int i = 1; i < N; ++i) {
        ans[i] = gcd(ans[i - 1], y[i]);
    }

    cout << ans[N - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mx 10000000000008
#define mod 1000000007
ll n,m,i,j,k,l,t,arr[sz],brr[sz],crr[sz];
vector<ll>v;
int main()
{
     t=1;
   // scanf("%lld",&t);
    while(t--)
    {
     scanf("%lld",&n);
     for(i=1;i<=n;i++)
     {
         scanf("%lld",&arr[i]);
         brr[i]=brr[i-1]+arr[i];
         brr[i]%=mod;
     }
     for(i=2;i<=n;i++)
     {
         crr[i]=(brr[i-1]*arr[i])%mod;
         l=(l+crr[i])%mod;
     }
     printf("%lld\n",l);
    }
    return 0;
}


Measured memory_bytes: 8436
<?php
// C
fscanf(STDIN, '%d %d %d', $a, $b, $c);
$a = [$a, $b, $c];
sort($a);
if (count(array_unique($a)) === 1) exit('0');
$ans = $a[2] - $a[1];
$ans += intdiv($a[1] - $a[0], 2);
if (($a[1] - $a[0]) % 2 === 1) $ans += 2;
echo $ans;

Measured memory_bytes: 4604
n, m = map(int, input().split())
ans = [1] + [0] * (n - 1)
flag1 = 0
flag2 = 0

if n == 1 and m == 0:
    print("0")
    exit()
for i in range(m):
    s, c = map(int, input().split())
    if s == 1:
        if c == 0 and n != 1:
            print("-1")
            exit()
        if (ans[s - 1] != 1 and ans[s - 1] != c) or (ans[s - 1] == 1 and flag1 == 1 and c != 1):
            print("-1")
            exit()
        if ans[s - 1] == 1 and c == 1:
            flag1 = 1
        ans[s - 1] = c
    else:
        if (ans[s - 1] != 0 and ans[s - 1] != c) or (ans[s - 1] == 0 and flag2 == 1 and c != 0):
            print("-1")
            exit()
        if ans[s - 1] == 0 and c == 0:
            flag2 = 1
    ans[s - 1] = c
print(*ans, sep = "")

Measured memory_bytes: 3188
N,K,Q=map(int,input().split())
cnt=[0 for i in range(0,N+1)]
for i in range(Q):
    A=int(input())
    cnt[A]+=1
for i in range(1,N+1):
    if cnt[i]+K-Q<=0:
        print("No")
    else:
        print("Yes")


Measured memory_bytes: 4672
#include<bits/stdc++.h>
using namespace std;
bool gu(string S){
  int N=S.size();
  bool flag=true;
  for(int i=0;i<N/2;i++){
    if(S.at(i)!=S.at(i+N/2)){
      flag=false;
    }
  }
  return flag;
}
      
int main(){
  string T;
  cin>>T;
  int K=T.size();
  for(int i=0;i<K/2;i++){
    T.pop_back();
    T.pop_back();
    if(gu(T)){
      cout<<T.size()<<endl;
      break;
    }
  }
}
  


Measured memory_bytes: 256
// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let s: String = read();
    let mut svec: Vec<char> = s.chars().collect();
    let mut change_count = 0_u32;

    for i in 1..svec.len()
    {
        if svec[i] == svec[i - 1]
        {
            svec[i] = if svec[i] == '0' { '1' } else { '0' };
            change_count += 1;
        }
    }

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


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

int main()
{
	string marble;
	cin >> marble;

	int count = 0;
	for(int loop = 0; loop < marble.size(); ++loop) {
		if ('1' == marble.at(loop)) {
			++count;
		}
	}

	cout << count << endl;

	return 0;
}


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

int main() {
  int N;
  int L;
  cin >> N >> L;
  string C;
  priority_queue <string, vector<string>, greater<string>> q;
  for(int i=0;i<N;i++){
    cin >> C;
    q.push(C);
  }
  for(int j=0;j<N;j++){
    cout << q.top();
    q.pop();
  }
  cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#define my_max zhi5968
typedef long long ll;
using namespace std;

int main()
{
	ll n,tmp_n;
	cin>>n;
	tmp_n=n;
	n=abs(n);
	ll ans[40]={0};
	int t=0;
	while(n)
	{
		ans[t++]=n%2;
		n/=2;
	}
	if(tmp_n==0)
	{
		cout<<"0"<<endl;
		return 0;
	}
//	for(int i=0;i<t;i++)
//		printf("%d",ans[i]);
//	cout<<endl;
	if(tmp_n>0)
		for(int i=0;i<t;i++)
		{
			int tat=0;
			if(i%2==1&&ans[i]==1)
			{
				while(ans[tat+1+i]==1)
				{
					ans[i+1+tat]=0;
					tat++;
				}
				ans[tat+1+i]=1;
				t=max(t,tat+2+i);
			}
		}
	else
		for(int i=0;i<t;i++)
		{
			int tat=0;
			if(i%2==0&&ans[i]==1)
			{
				while(ans[tat+1+i]==1)
				{
					ans[i+1+tat]=0;
					tat++;
				}
				ans[tat+1+i]=1;
				t=max(t,tat+2+i);
			}
		}
	for(int i=t-1;i>=0;i--)
		printf("%d",ans[i]);
	cout<<endl;
	return 0;
}


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

using namespace std;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    vector<int> result(n);
    for (int i = 0; i < n; i++) {
        result[a[i] - 1] = i + 1;
    }
    for (int i = 0; i < n; i++) {
        printf("%d ", result[i]);
    }
    return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define endl "\n"
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e2+4;

int fa[N];

int main()                  
{
	int x,n; scn(x); scn(n);

	rep(i,0,n)
	{
		int val; scn(val); fa[val]++;
	}

	int dis=inf,ans=-1;

	rep(i,x,N)
	if(fa[i]==0)
	{
		dis=i-x; ans=i; break;
	}

	int flag=0;

	for(int i=x-1;i>=0;i--)
	if(fa[i]==0)
	{
		if(x-i<=dis)
		dis=x-i,ans=i;

		flag=1; break;
	}

	if(flag==0)
	{
		if(x+1<=dis)
		ans=-1;
	}

	pri(ans);
} 

Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int M = scan.nextInt();
        double[] A = new double[N];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        double sum = Arrays.stream(A).sum();
        double p = 4 * M;
        double limit = sum / p;
        int count = 0;
        for (int i = 0; i < N; i++) {
            if (A[i] < limit) {
                continue;
            }
            count += 1;
        }
        System.out.println(M <= count ? "Yes" : "No");
    }
}


Measured memory_bytes: 29012
N, M = map(int, input().split())
P = [input().split() for i in range(M)]

ans = [None for _ in range(N)]

flag = True
for p in P:
  keta = int(p[0])-1
  val = int(p[1])
  if N!=1 and keta == 0 and val == 0:
    flag = False
  if not ans[keta]:
    ans[keta] = val
  else:
    if ans[keta] != val:
      flag = False
fin = ""
if flag:
  for i, a in enumerate(ans):
    if a:
      fin += str(a)
    else:
      if i == 0 and N != 1:
        fin += "1"
      else:
        fin += "0"
  print(int(fin))
else:
  print(-1)

Measured memory_bytes: 3064
n, l = map(int, input().split())
applepi = sum([l + i - 1 for i in range(1,n+1)])
minas = 100000000000
for j in range(1, n+1):
  a = l + j - 1
  if abs(a) <= abs(minas):
    minas = a
print(applepi - minas)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> P;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double PI=3.1415926535897932;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod


int main(){
    ll A,B; cin>>A>>B;
    cout<<A*B<<endl;
}


Measured memory_bytes: 3624