akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ull unsigned long long
# define lli long long int
# define ulli unsigned long long int
#define ll long long
#define db double
#define ldb long double
#define vi vector<int>
#define vull vector<ull>
#define vll vector<ll>
#define pb push_back
#define si set<int>
#define sll set<ll>
#define ins insert
#define rep(i,n) for(int i=0;i<n;i++)
#define vpp vector<pair<int,int>>
#define mp make_pair
#define ft first
#define sc second
#define MOD 1000000007
using namespace std;
// ll prime[10000000];
// //Modular Exponentiation
//     ll fastExpo(ll x,ll n){
//         if(n==0) return 1;
//         if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
//         return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
//     }
//   //Euclidean Algorithm
//      ll gcd(ll a,ll b){
//       return (b==0)?a:gcd(b,a%b);
//     } 
//  // Extended Euclidean Algorithm
//   ll exgcd(ll a,ll b,ll &x, ll &y){
//   if(b==0){
//     x=1,y=0;
//     return a;
//   }
//    ll x1,y1;
//     ll d=exgcd(b,a%b,x1,y1);
//    x=y1;
//    y=x1-y1*(a/b);
//    return d;    
//  }    
  //sieve
//   void sieve(){
//   prime[0]=0;
//   prime[1]=0;
//   for(int i=2;i<10000000;i++){
//     prime[i]=1;
//   }
//   for(int i=2;i*i<10000000;i++){
//     if(prime[i]==1){
//       for(int j=i*i;j<10000000;j+=i){
//         prime[j]=0;
//       }
//     }
//   }
// }  
    bool compare(const pair<int,double>&p1,const pair<int,double>&p2)
    {
       if(p1.second>p2.second)
        return true;
       else if(p1.second==p2.second)
        return p1.first<p2.first;
       return false;

    }
     int main(){
      ios_base::sync_with_stdio(false);
      cin.tie(0);
      cout.tie(0);
      //cout << fixed;
      //cout.precision(2);
          
             ll n,k=0;
             cin>>n;
             ll a[n];
            
             ll ans=0;
             for(int i=0;i<n;i++)cin>>a[i];
              if(n==1)
              {
                cout<<0 <<"\n";
                return 0;
              }
             sort(a,a+n,greater<ll>());
             ans+=a[0];k+=2;
             for(int i=1;i<n;i++)
             {
                 if(k==n)break;
                 ans+=a[i];
                 k++;
                 if(k==n)break;
                 ans+=a[i];
                 k++;

             } 
             cout<<ans<<"\n";
             return 0;
            }

Measured memory_bytes: 5156
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Numerics;
using System.Diagnostics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Runtime.CompilerServices;
using static System.Math;


class P
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] l = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
        Console.WriteLine(l.Last() < l.Take(n - 1).Sum() ? "Yes" : "No");
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
 
const int MAXN = 2e5+3;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int N;
vector<int> V[MAXN];

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> N;
    fori(i,N) {
        int a; cin >> a;
        V[a].pb(i);
    }

    if(!V[1].size()) RETURN(-1);

    int ans = 0;
    int lst = -1;
    fore(i,1,N) {
        int idx = upper_bound(V[i].begin(), V[i].end(), lst) 
            - V[i].begin();
        if(idx == V[i].size()) break;
        ans++;
        lst = V[i][idx];
    }

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


Measured memory_bytes: 11264
#include <stdio.h>

int main(void)
{
     /* left, right, up, down */
     double al, ar, au, ad, bl, br, bu, bd;

     while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
                  &al, &ad, &ar, &au, &bl, &bd, &br, &bu)){

          if(br < al || bu < ad || bl > ar || bd > au)
               puts("NO");
          else
               puts("YES");
     }

     return 0;
}

Measured memory_bytes: 612
#include <iostream>
using namespace std;
 
int main() {
	int n,min=1000000000,max=1;
	cin >> n;
        int a[100];
	for(int i=0; i<n; i++){
		cin >> a[i];
		if(a[i]<min)min=a[i];
		if(a[i]>max)max=a[i];
	}
	cout << max-min << endl;
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 8;
bool e[N][N];
int n, m, f, t, ans;
int a[N];

int main() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        cin >> f >> t;
        e[f - 1][t - 1] = true;
        e[t - 1][f - 1] = true;
    }
    iota(a, a + n, 0);
    do {
        bool ok = true;
        for (int i = 0; i < n - 1; ++i) {
            if (!e[a[i]][a[i + 1]]) {
                ok = false;
                break;
            }
        }
        if (ok)
            ++ans;
    } while (next_permutation(a + 1, a + n));

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


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
using namespace std;
// 多倍長テンプレ
/* ---------------------- ここから ---------------------- */
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
// 任意長整数型
using Bint = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
/* ---------------------- ここまで ---------------------- */
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
int main() {
  int N,K;
  cin >> N >> K;
  int hito[N];
  for(int i=0;i<N;i++){
    hito[i]=0;
  }
  int d;
  for(int i=0;i<K;i++){
    cin >> d;
    int A;
    for(int j=0;j<d;j++){
      cin >> A;
      hito[A-1]+=1;
    }
  }
  int count=0;
  for(int i=0;i<N;i++){
    if(hito[i]==0){
      count++;
    }
  }
  cout << count;
  cout << endl;
  return 0;
}


Measured memory_bytes: 3640
# coding: utf-8
# Your code here!
s = input()
x = [s[i:i+1] for i in range(len(s))]

new_str_list = sorted(s)
li_uniq = list(set(new_str_list))
if len(li_uniq) == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
/*Author : Hrishi*/

/*When I wrote this, only God and I understood what I was doing.
Now, only God knows.*/

#include <bits/stdc++.h>

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int,int>
#define pl pair<ll,ll> 
#define ff first
#define ss second
#define PB push_back
#define F(i,L,R) for(auto i=L; i<R ;i++)
#define FR(i,R,L) for(auto i=R;i>L;i--)
#define all(x) (x).begin(),(x).end()
#define show(x) cout<<(#x)<<" = "<<(x)<<"\n";
#define show2(x,y) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<"\n";
#define show3(x,y,z) cout<<(#x)<<" = "<<(x)<<" & "<<(#y)<<" = "<<(y)<<" & "<<(#z)<<" = "<<(z)<<"\n";
#define endln "\n"
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define M 1000000007

using namespace std;

ll arr[100005][3];
ll dp[100005][3];

int main() 
{
	fastio;
	int n;
	cin>>n;
	F(i,0,n)
	    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
	    
    F(i,0,3)
        dp[0][i] = arr[0][i];
        
    F(i,1,n)
    {
        dp[i][0] = max(dp[i-1][1],dp[i-1][2]) + arr[i][0];
        dp[i][1] = max(dp[i-1][0],dp[i-1][2]) + arr[i][1];
        dp[i][2] = max(dp[i-1][0],dp[i-1][1]) + arr[i][2];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));

}




Measured memory_bytes: 4992
N,K = map(int,input().split())
a = list(map(int,input().split()))
town = [-1]*N
i=1
n=0
while True:
    if town[i-1] == -1:
        town[i-1] = n
        i = a[i-1]
    else:
        roop = i
        break
    n += 1

amari = (K-town[roop-1])%(n-town[roop-1])
if K-town[roop-1]>0:
    print(town.index(town[roop-1]+amari)+1)
else:
    print(town.index(K)+1)

Measured memory_bytes: 32384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 10;
const ll MOD = 1e9 + 7;
const int B = 12711;
const int B1 = 1007;
int n;
string s;
ll h1[N], f1[N];
ll h0[N], f0[N];
int geth(int l, int r, ll* h, ll* f) {
    ll res = ((h[r] - h[l-1] * f[r-l+1]) % MOD + MOD) % MOD;
    return res;
}
int main() {
    cin >> n >> s;
    f0[0] = 1;
    f1[0] = 1;
    for(int i = 0; i < n; i++) {
        h0[i+1] = (h0[i] * B + s[i] - 'a') % MOD;
        f0[i+1] = f0[i] * B % MOD;
        h1[i+1] = (h1[i] * B1 + s[i] - 'a') % MOD;
        f1[i+1] = f1[i] * B1 % MOD;
    }
    int l = 1, r = n, ans = 0;
    while(l <= r) {
        int mid = (l + r) / 2;
        int f = 0;
        for(int i = 1; i+mid-1 <= n && !f; i++) {
            for(int j = i+mid; j+mid-1 <= n; j++) {
                if(geth(i,i+mid-1, h0, f0) == geth(j,j+mid-1, h0, f0) && geth(i,i+mid-1, h1, f1) == geth(j,j+mid-1, h1, f1)) {
                    f = 1;
                    break;
                }
            }
        }
        if(f) {
            ans = mid;
            l = mid + 1;
        } else {
            r = mid - 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 6400
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
#define dcml(n) fixed<<setprecision(n)
//CONST
//------------------------------------------
const ll INF=1010000000000000017LL;
const ll MOD=1000000007LL;
const ld EPS=1e-12;
const ld PI=3.14159265358979323846;
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define  FORS(i,m,n) for(ll (i)=(m);   (i)<=(n); (i)++)
#define  RFOR(i,m,n) for(ll (i)=(n)-1; (i)>=(n); (i)--)
#define RFORS(i,m,n) for(ll (i)=(n);   (i)>(n);  (i)--)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
#define WREPS(i,in,j,jn) REPS(i,in)REPS(j,jn)
//-----------------------------------------
//namespace
using namespace std;
//ライブラリはここに
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

//-----------------------------------------
ll f(ll n,ll x){
    if(n==-1)return 0;
    return n/x+1;
}
int main(void){
    ll a,b,x;cin>>a>>b>>x;
    cout<<f(b,x)-f(a-1,x)<<"\n";
}

Measured memory_bytes: 256
def tt(o,t):
    om=o%100
    oh=o/100
    tm=t%100
    th=t/100
    return tm-om+(th-oh)*60
    

while(1):
    [c,s,e]=[int(x) for x in raw_input().split()]
    if c==0:
        break
    else:
        cmlist=[]
        timelist=[s]
        state=2**c-1
        oldtime=s
        oldstate=0
        ans=0
        temptv=0
        for i in range(c):
            numofcom=int(raw_input())
            aa=[int(x) for x in raw_input().split()]
            cmlist.append(aa)
            timelist=timelist+aa
        timelist.append(e)
        timelist=sorted(list(set(timelist)))
        for time in timelist:
            for i in range(c):
                if len(cmlist[i])>0:
                    if cmlist[i][0]==time:
                        state=state^(2**i)
                        cmlist[i].pop(0)
            if oldstate!=0:
                temptv=temptv+tt(oldtime,time)
            else:
                ans=max(ans,temptv)
                temptv=0
            oldtime=time
            oldstate=state
            #print time,bin(state),temptv
        ans=max(ans,temptv)
        print ans

Measured memory_bytes: 4288
import sys
input = sys.stdin.readline
def main():
    D = int(input())
    c = list(map(int, input().split()))
    s = []
    for _ in range(D):
        si = list(map(int, input().split()))
        s.append(si)
    for i in range(D):
        max_type = [-1, 0]
        for j in range(26):
            if s[i][j] > max_type[1]:
                max_type[0], max_type[1] = j, s[i][j]
        print(max_type[0]+1)
if __name__ == "__main__":
    main()

Measured memory_bytes: 74292
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <queue>
using namespace std;
int main(void){
    int n,w,h;
    cin>>n>>w>>h;
    int x[100010]={},y[100010]={};
    for(int i=0;i<n;i++){
        int a,b,c;
        cin>>a>>b>>c;
        int l=max(0,a-c),r=min(100000,a+c);
        x[l]+=1;
        x[r]-=1;
        l=max(0,b-c);r=min(100000,b+c);
        y[l]+=1;
        y[r]-=1;
    }
    for(int i=1;i<=100000;i++){
        x[i]+=x[i-1];
        y[i]+=y[i-1];
    }
    for(int i=0;i<w;i++){
        if(x[i]==0)break;
        if(i==w-1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    for(int i=0;i<h;i++){
        if(y[i]==0)break;
        if(i==h-1){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}



Measured memory_bytes: 3864
#include <stdio.h>
#include <string.h>

/*
MAXTURNはバトルの最大ターン数
MAXLENGTHは入力される最大の文字数
*/
#define MAXTURN 1000
#define MAXLENGTH 100

//ゲームで必要になるデータ
typedef struct{
	//cardは所持カード、pointは勝敗に応じた得点を格納
	char card[MAXTURN][MAXLENGTH];
	int point;
}Game;

int main(void)
{
	//resultは1ターン毎の勝敗を、turnはターン数を格納
	int i, result, turn;
	//太郎さんと花子さんを準備する
	Game taro;
	Game hanako;

	//ターン数を入力
	scanf("%d", &turn);
	for(i = 0; i < turn; i++){
		//所持カードを入力
		scanf("%s %s", taro.card[i], hanako.card[i]);
	}

	taro.point = 0;
	hanako.point = 0;
	for(i = 0; i < turn; i++){
		//resultに結果を格納
		result = strcmp(taro.card[i], hanako.card[i]);
		//結果に応じた得点を加算する
		if(result >= 1){
			taro.point += 3;
		}
		else if(result == 0){
			taro.point += 1;
			hanako.point += 1;
		}
		else{
			hanako.point += 3;
		}
	}

	//結果を出力
	printf("%d %d\n", taro.point, hanako.point);

	return 0;
}


Measured memory_bytes: 2044
/*input
2 11 4
*/
#include <bits/stdc++.h>

using namespace std;

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	printf("%d\n", min(b / a, c));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
// #include <numeric>
#include <complex>

#define FAST ios_base::sync_with_stdio(false); cin.tie(0)
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define repr(i, a, b) for(int i=int(a); i>=int(b); i--)
#define reps(i,n) for(int i=1;i<=int(n);++i)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define iceil(x,y) (x+y-1)/y
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef pair<int, PII> PP;

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

int main() {
	ll n,k,p,q=0;
	cin >> n >> k;
	p = n/k;
	if (k%2==0) q=n/(k/2)-p;
	cout << p*p*p+q*q*q << "\n";

	return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Class1
    {
        static void Main(string[] args)
        {
            sbyte N, K;

            string[] input = Console.ReadLine().Split(' ');

            N = sbyte.Parse(input[0]);
            K = sbyte.Parse(input[1]);

            Console.WriteLine(N - (K - 1));
        }

    }
}


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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    bool x;
    cin >> x;
    COUT(!x);
}


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

using namespace std;

typedef long long ll;

#define MOD 1000000007

int cnt[3][3];

int main() {
  int a[3][3];
  for (int i = 0; i < 3; ++i) {
    for (int j = 0; j < 3; ++j) {
      cin >> a[i][j];
    }
  }
  int n;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 3; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (a[j][k] == b[i]) {
          cnt[j][k]++;
        }
      }
    }
  }
  bool ok = false;
  for (int i = 0; i < 3; ++i) {
    if (cnt[i][0] && cnt[i][1] && cnt[i][2]) ok = true;
    if (cnt[0][i] && cnt[1][i] && cnt[2][i]) ok = true;
  }
  if (cnt[0][0] && cnt[1][1] && cnt[2][2]) ok = true;
  if (cnt[0][2] && cnt[1][1] && cnt[2][0]) ok = true;
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 256
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input.trim().to_string());
    println!("{}", output);
}

fn run(input: String) -> String {
    let list = input.split("\n").skip(1).map(|line| {
        let ll = line.split_whitespace()
            .map(|x| x.parse::<usize>().unwrap())
            .collect::<Vec<_>>();
        //l,r
        (ll[0], ll[1])
    });

    let primes = generate_prime(100000);
    let mut is_prime = Vec::with_capacity(100001);
    for prime in primes {
        for _ in 0..prime - is_prime.len() {
            is_prime.push(false);
        }
        is_prime.push(true);
    }

    for _ in 0..100 {
        is_prime.push(false);
    }

    //似た数の個数の累積和
    let count = (0..100001)
        .map(|n| {
            if is_prime[n] && is_prime[(n + 1) / 2] {
                1
            } else {
                0
            }
        })
        .scan(0, |state, x| {
            *state = *state + x;
            Some(*state)
        })
        .collect::<Vec<i32>>();

    list.map(|(l, r)| (count[r] - count[l - 1]).to_string())
        .collect::<Vec<_>>()
        .join("\n")
}

fn generate_prime(max: usize) -> Vec<usize> {
    let sqrt_max = (max as f64).sqrt();
    let mut prime_list = Vec::new();

    let mut search_list = (2..max + 1).collect::<Vec<_>>();

    while {
        let prime = search_list[0];
        prime_list.push(prime);
        search_list = search_list.into_iter().filter(|n| n % prime != 0).collect();

        (prime as f64) < sqrt_max
    } {}

    prime_list.append(&mut search_list);

    prime_list
}

#[test]
fn test() {
    let tests = vec![
        ("1\n3 7", "2"),
        ("4\n13 13\n7 11\n7 11\n2017 2017", "1\n0\n0\n1"),
        (
            "6\n1 53\n13 91\n37 55\n19 51\n73 91\n13 49",
            "4\n4\n1\n1\n1\n2",
        ),
    ];
    for (i, (input, output)) in tests.into_iter().enumerate() {
        println!("test:{}", i);
        assert_eq!(run(input.to_string()), output.to_string());
    }
}


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

int main(){
	int p,q,r;
	cin >> p >> q >> r;
	
	int temp = max(p,q);
	temp = max(temp,r);
	
	cout << p+q+r - temp << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const double EPS = 1e-10;
string tile[1000];
int N, M, A, B;
int a, b;
void fill() {
	for (int i = 0; i + 1 < N; i += 2) {
		for (int j = 0; j + 1 < M; j += 2) {
			if (tile[i][j] != '.') continue;
			if (a < A) {
				tile[i][j] = tile[i + 1][j] = '<';
				tile[i][j + 1] = tile[i + 1][j + 1] = '>';
				a += 2;
			}
			else {
				tile[i][j] = tile[i][j + 1] = '^';
				tile[i + 1][j] = tile[i + 1][j + 1] = 'v';
				b += 2;
			}
		}
	}
}
void clear() {
	for (int i = 0; i + 1 < N; i += 2) {
		for (int j = 0; j + 1 < M; j += 2) {
			if (tile[i][j] == '.') continue;
			if (tile[i][j] == '<') a -= 2;
			else b -= 2;
			tile[i][j] = tile[i][j + 1] = tile[i + 1][j] = tile[i + 1][j + 1] = '.';
		}
	}
}
int main() {
	cin >> N >> M >> A >> B;
	if (A + B > ((N*M) / 2) || A > N*(M / 2) || B > M*(N / 2)) {
		cout << "NO" << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		tile[i].resize(M);
		for (int j = 0; j < M; j++) {
			tile[i][j] = '.';
		}
	}
	a = b = 0;
	if (N % 2 == 1) {
		for (int i = 0; i + 1 < M; i += 2) {
			tile[N - 1][i] = '<';
			tile[N - 1][i + 1] = '>';
			a++;
		}
	}
	if (M % 2 == 1) {
		for (int i = 0; i + 1 < N; i+=2) {
			tile[i][M - 1] = '^';
			tile[i + 1][M - 1] = 'v';
			b++;
		}
	}
	fill();
	if (b < B) {
		if (N >= 3 && M >= 3 && N % 2 == 1 && M % 2 == 1) {
			clear();
			tile[N - 3][M - 3] = '^';
			tile[N - 2][M - 3] = 'v';
			tile[N - 1][M - 3] = '<';
			tile[N - 1][M - 2] = '>';
			tile[N - 2][M - 1] = '^';
			tile[N - 1][M - 1] = 'v';
			tile[N - 3][M - 2] = '<';
			tile[N - 3][M - 1] = '>';
			tile[N - 2][M - 2] = '.';
			a++;
			b++;
			fill();
		}
		if (b < B) {
			cout << "NO" << endl;
			return 0;
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (tile[i][j] == '<') {
				if (a > A) {
					a--;
					tile[i][j] = tile[i][j + 1] = '.';
				}
			}
			else if (tile[i][j] == '^') {
				if (b > B) {
					b--;
					tile[i][j] = tile[i + 1][j] = '.';
				}
			}
		}
	}
	cout << "YES" << endl;
	for (int i = 0; i < N; i++) {
		cout << tile[i] << endl;
	}
}

Measured memory_bytes: 2304
#include<iostream>
#include<vector>
#include<cstdlib>

using namespace std;

int main(){
  int i,j,k=0;
  cin >> i>>j;

  if(i>j){
    k+=i;
    i--;
  }
  else {
    k+=j;
    j--;
  }

  if(i>j){k+=i;}
  else k+=j;

  cout << k<<endl;
  return 0;
}

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

int n,i,x,y,d[15],j;
char s[15];

int comp1(const void *a,const void *b){return *(int *)a-*(int *)b;}
int comp2(const void *a,const void *b){return *(int *)b-*(int *)a;}

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%s",s);
		for(i=0;i<8;i++)d[i]=s[i]-'0';
		qsort(d,8,sizeof(int),comp1);
		x=y=0;j=1;
		for(i=0;i<8;i++)x+=d[i]*j,j*=10;
		qsort(d,8,sizeof(int),comp2);j=1;
		for(i=0;i<8;i++)y+=d[i]*j,j*=10;
		printf("%d\n",x-y);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
#define dump(a) cout << (a) << endl;
typedef long long ll;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    while ( true ) {
        if( a%2 == 1 ) a--;
        b += a/2;
        a /= 2;
        k--;
        if( k == 0 ) break;

        if( b%2 == 1 ) b--;
        a += b/2;
        b /= 2;
        k--;
        if( k == 0 ) break;
    }
    cout << a << " " << b << endl;
    return 0;  
}

Measured memory_bytes: 384
X, Y = map( str, input().split() )
li = [ "A", "B", "C", "D", "E", "F" ]
if li.index(X) == li.index(Y) : 
   print( "=" )
elif li.index(X) < li.index(Y) : 
   print( "<" )
else : 
   print( ">" )

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)

using namespace std;

namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;

using ll = long long;
ll mod = pow(10, 9) + 7;

template <typename T> void output(T, ll);
ll gcd(ll, ll);
ll lcm(ll, ll);
Bint comb(Bint, Bint);
void prime_map(map<ll, ll> &, ll);
ll solve(string, int);

int main() {
    // source
    string s;
    ll k;
    cin >> s;
    cin >> k;

    string s1 = s, s2 = s + s, s3 = s + s + s;

    ll count1 = solve(s1, k);
    ll count2 = solve(s2, k);
    ll count3 = solve(s3, k);

    ll ans;
    if (k == 1) {
        cout << count1 << endl;
        return 0;
    }

    if (k % 2 == 0) {
        ans = count1 + (count2 - count1) * (k - 1);
    } else {
        ans = count1 + (count3 - count1) * (k - 1) / 2;
    }

    cout << ans << endl;
}

ll solve(string s, int k) {
    ll ans0 = 0, ans1 = 0;
    string s0 = s, s1 = s;
    repd(i, 1, s0.length()) {
        if (s0[i] == s0[i - 1]) {
            s0[i] = 'A';
            ans0++;
        }
    }

    repd(i, 0, s1.length() - 1) {
        if (s1[i] == s1[i + 1]) {
            s1[i] = 'A';
            ans1++;
        }
    }
    ll ans = min(ans0, ans1);
    return ans;
}

Bint comb(Bint a, Bint b) {
    Bint ans = 1;

    if (a < b) {
        return 0;
    }

    rep(i, b) {
        ans *= a - i;
        ans /= i + 1;
    }

    return ans;
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

template <typename T> T min(T a, T b) {

    if (a < b) {
        return a;
    } else {
        return b;
    }
}

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

void prime_map(map<ll, ll> &m, ll num) {
    ll cache = num;
    repd(i, 2, sqrt(num) + 2) {
        if (num % i == 0) {
            if (m[i] == 0) {
                m[i] = 1;
            } else {
                m[i]++;
            }

            num /= i;
            break;
        }
    }

    if (cache == num) {
        if (m[num] == 0) {
            m[num] = 1;
        } else {
            m[num]++;
        }
        return;
    } else {
        prime_map(m, num);
    }
}


Measured memory_bytes: 256
#include<math.h>
#include<map>
#include<iostream>
#include <algorithm>
#include <string>
#include<vector>
#include<array>
#include<tuple>
#include<queue>
#include<stack>
#include<iomanip>
#include<bitset>
#include <list>
#include<numeric>
//AtCoderC++.cpp

using namespace std;

inline int ceiling(int n, int d) {
	return n % d == 0 ? n / d : n / d + 1;
}

int main() {
	int N; cin >> N;
	auto ts = vector<int>(N);
	long long sum = 0;
	for (size_t i = 0; i < N; i++) { cin >> ts[i]; sum += ts[i]; }
	int M; cin >> M;
	auto drink = vector<pair<int, int>>(M);
	for (size_t i = 0; i < M; i++) cin >> drink[i].first >> drink[i].second;
	for (size_t i = 0; i < M; i++) {
		auto sub = (ts[drink[i].first - 1] - drink[i].second);
		sum -= sub;
		cout << sum << endl;
		sum += sub;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
/*ll divr[maxn];
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}
void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}
 
*/















int ct[100005][2];
int main()
{
     int n;
     cin>>n;
     int a[n];
     map<int,int> mp;
     for(int i=0;i<n;i++)
     {
          cin>>a[i];mp[a[i]]++;
     }
     int ans=0;
     for(auto it:mp)
     {
          int x=it.first,ct=it.second;
          if(ct>=x)ans+=ct-x;
          else ans+=ct;
     }
     cout<<ans;
     
}
























 

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

#define DIV 1000000007
#define BLACK 0
#define WHITE 1

long long N;
long long ban[100005];
string S;

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

	long long left = 0;
	long long ans = 1;
	for(long long i = 0; i < 2*N; i++){
		if(i%2 == 0){
			if(S[i] == 'B'){
				left++;
			}else{
				ans *= left;
				ans %= DIV;
				left--;
			}
		}else{
			if(S[i] == 'B'){
				ans *= left;
				ans %= DIV;
				left--;
			}else{
				left++;
			}
		}
	}
	
	if(left!=0){
		cout << 0 << endl;
		return 0;
	}

	for(long long i = 1; i <= N; i++){
		ans *= (i);
		ans %= DIV;
	}
	cout << ans << endl;
}


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

struct UnionFind{
  vector<int> par;
  
  UnionFind(int n) : par(n,-1) {}
  
  int root(int x){
    if(par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  
  void unite(int x, int y){
    x = root(x); y = root(y);
    if(x == y) return;
    if(-par[y] > -par[x]) swap(x,y);
    par[x] += par[y]; 
    par[y] = x;
  }
  
  bool same(int x, int y){
    return root(x) == root(y);
  } 
  
  int size(int x){
    return -par[root(x)];
  }
};

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<int> fri(n);
  vector<set<int>> blo(n);
  UnionFind tree(n);
  
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--, b--;
    fri[a]++, fri[b]++;
    tree.unite(a,b);
  }
    
  rep(i,k){
    int c, d;
    cin >> c >> d;
    c--, d--;
    blo[c].insert(d);
    blo[d].insert(c);
  }
  
  rep(i,n){
    int c = tree.size(i) - 1 - fri[i];
    for(int j : blo[i]){      
      if(tree.same(i,j)) c--;
    }
    cout << c << ' ';
  }
  cout << endl;
}



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

namespace ABC_Training
{

    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var result = 0;
            for(int i = 1; i <= n; i++)
            {
                if (i.ToString().Length % 2 == 1)
                {
                    result++;
                }
            }
            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 13140
//#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int n;
	int cnt[100];
	int mead = 0;

	for (int i = 0; i < 100; i++){
		cnt[i] = 0;
	}

	while (cin >> n){
		cnt[n - 1]++;
		if (cnt[n - 1] > mead) mead = cnt[n - 1];
	}

	for (int i = 0; i < 100; i++){
		if (cnt[i] == mead) cout << i + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    val (a, b, c) = readLine()!!.split(" ").map(String::toInt)
    if ((a == 7 && b == 5 && c == 5)
        || (a == 5 && b == 7 && c == 5)
        || (a == 5 && b == 5 && c == 7)) {
        println("YES")
    } else {
        println("NO")
    }
}


Measured memory_bytes: 38000
#include <cstdio>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;

int main(void)
{
    int n, m;
    
    while (1){
        cin >> n;
        if (n == 0) break;
        
        map <char, char> change;
        char a, b;
        for (int i = 0; i < n; i++){
            cin >> a >> b;
            change[a] = b;
        }
        
        cin >> m;
        
        char ans;
        for (int i = 0; i < m; i++){
            cin >> ans;
            map<char, char>::iterator it;
            it = change.find(ans);
            if (it != change.end()){
                char a = it->second;
                ans = a;
            }
            printf("%c", ans);
        }
        printf("\n");
        
    }
    
    return (0);
}

Measured memory_bytes: 880
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n,x;
    cin>>n>>x;
    vi l(n);
    rep(i,n)cin>>l[i];
    vi d(n+1);
    REP(i,1,n){
        d[i]=d[i-1]+l[i-1];
    }
    int ans=0;
    rep(i,n+1)ans+=d[i]<=x;
    cout<<ans<<endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    a88(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}


fun a88(args: Array<String>) {
    if (args.size != 2) {
        throw IllegalArgumentException()
    }
    val (price, oneyen) = args.map { it.toInt() }
    println(if (price % 500 <= oneyen) "Yes" else "No")
}

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

using static Input;
using static Util;
class Program
{
    static int N;
    static int K;
    static void INPUT()
    {
        N = NextInt();
        K = NextInt();
    }
    static void OUT()
    {
        var ans = 0L;
        for(var k = K; k <= N + 1; k++)
        {
            var min = ArithmeticProgression(0, k - 1, k);
            var max = ArithmeticProgression(N, N - k + 1, k);
            ans += max - min + 1;
            ans %= MOD;
        }

        Console.WriteLine(ans);
    }
    static void Main(string[] args)
    {
#if DEBUG  
        //TESTINPUT();
        INPUT();

#else
        INPUT();
#endif
        OUT();
    }

    static void TESTINPUT()
    {
    }

}

public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}

class Util
{
    /// <summary>
    /// 等差数列和
    /// </summary>
    /// <param name="a">初項</param>
    /// <param name="l">末項</param>
    /// <param name="n">項数</param>
    /// <returns></returns>
    public static long ArithmeticProgression(long a, long l, long n)
    {
        return (a + l) * n / 2;
    }

}




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

vector<int> v[100010],g[100010];

ll sum[100010],f[100010];
int A[100010],B[100010],h[100010],from[100010],id[100010],n,m;

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline bool cmp(const int &x,const int &y) { return A[x]<A[y]; }

inline int find(int x) { return (x==from[x])?x:from[x]=find(from[x]); }

int main()
{
	n=rd();m=rd();
	for (int i=1;i<=n;i++) A[i]=rd(),B[i]=rd(),A[i]=max(0,A[i]-B[i]);
	for (int i=1;i<=m;i++)
	{
		int x=rd(),y=rd();
		v[x].push_back(y);
		v[y].push_back(x);
	}
	for (int i=1;i<=n;i++) h[i]=i;
	sort(h+1,h+n+1,cmp);
	for (int i=1;i<=n;i++) from[i]=i,id[h[i]]=i;
	for (int i=1;i<=n;i++)
	{
		int x=h[i];
		for (int t:v[x]) if (id[t]<i&&find(t)!=x) g[x].push_back(find(t)),from[find(t)]=x;
	}
	for (int i=1;i<=n;i++)
	{
		int x=h[i];
		sum[x]=B[x];
		for (int t:g[x]) sum[x]+=sum[t];
		f[x]=sum[x]+A[x];
		for (int t:g[x]) f[x]=min(f[x],max(f[t],(ll)A[x])+sum[x]-sum[t]);
	}
	printf("%lld\n",f[h[n]]);
	return 0;
}

Measured memory_bytes: 14204
#include <iostream>
#include <string>

using namespace std;

int main(void){
  string str;
  int ret = 0;
  while(cin >> str){
    bool isParin = true;
    for(int i=0;i<str.size()/2;i++){
      if(str[i] != str[str.size()-1-i]) isParin = false;
    }
    if(isParin) ret++;
  }
  cout << ret << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
	boost;
	int n;
	cin>>n;
	int a[n];
	rep(i,0,n){
		cin>>a[i];
	}
	int mx=1e18;
	int ans=-1;
	for(int pos=1;pos<=100;pos++){
		int res=0;
		for(int i=0;i<n;i++){
			res+=(pos-a[i])*(pos-a[i]);
		}
		if(res<mx){
			mx=res;
			ans=res;
		}
	}
	cout<<ans;
	return 0;
}

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


int main()
{
    long long N, C;
    cin >> N >> C;
    vector<long long> x(N), v(N);
    for( int i = 0; i < N; i++ ) cin >> x[i] >> v[i];


    vector<long long> vSumCW(N), vSumCCW(N);
    vSumCW = vSumCCW = v;
    for( int i = 0; i < N-1; ++i ) vSumCW[i+1] += vSumCW[i];
    for( int i = N-1; i > 0; --i ) vSumCCW[i-1] += vSumCCW[i];

    // maxEneCW[i]: v[0] + ... + v[j] - x[j] ( i <= j ) のうちの最大値
    vector<long long> maxEneCW(N), maxEneCCW(N);
    maxEneCW[0] = max( 0LL, vSumCW[0] - x[0] );
    maxEneCCW[N-1] = max( 0LL, vSumCCW[N-1] - (C-x[N-1]) );
    for( int i = 1; i < N; ++i )
        maxEneCW[i] = max( maxEneCW[i-1], vSumCW[i]-x[i] );
    for( int i = N-2; i > 0; --i )
        maxEneCCW[i] = max( maxEneCCW[i+1], vSumCCW[i]-(C-x[i]) );

    long long ansCW = 0, ansCCW = 0;
    // 始め時計回りに回る場合
    for( int i = 0; i < N; ++i ){
        if( maxEneCCW[i+1] < x[i] or i == N-1 ) ansCW = max( ansCW, vSumCW[i] - x[i] );
        else ansCW = max( ansCW, vSumCW[i] - 2*x[i] + maxEneCCW[i+1] );
    }
    // 始め反時計回りに回る場合
    for( int i = N-1; i >= 0; --i ){
        if( maxEneCW[i-1] < C-x[i] or i == 0 ) ansCCW = max( ansCCW, vSumCCW[i] - (C-x[i]) );
        else ansCCW = max( ansCCW, vSumCCW[i] - 2*(C-x[i]) + maxEneCW[i-1] );
    }
    cout << max( ansCW, ansCCW ) << endl;

    return 0;

}

Measured memory_bytes: 4992
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    a = [0] * N
    for i in range(N):
        a[i] = int(input()) - 1

    visited = [False] * N
    visited[0] = True
    i = 0
    ans = 0
    while True:
        i = a[i]
        if visited[i]:
            ans = -1
            break
        visited[i] = True
        ans += 1
        if i == 1:
            break

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 7668
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

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

    map<string, int> cnt;
    for(int i=0; i<n; ++i){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        ++ cnt[s];
    }

    long long ans = 0;
    for(const auto& p : cnt)
        ans += p.second * (p.second - 1LL) / 2;
    cout << ans << endl;

    return 0;
}


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

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

Measured memory_bytes: 256
n = int(input())
def reversed_bit(N):
    if N == 1:
        return [1]
    elif N == 0:
        return [0]
    elif N % 2 == 0:
        return reversed_bit(N / (-2)) + [0]
    else:
        return reversed_bit((N-1) / (-2)) + [1]
m = ""
for i in range(len(reversed_bit(n))):
    m += str(reversed_bit(n)[i])
print(str(m))


Measured memory_bytes: 3060
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
v = lr()
v2 = [0]
for i in range(n):
    v2.append(v2[-1]+v[i])
def sumArea(l,r):
    return v2[r]-v2[l]
ans = -inf
for tmp in range(min(k,n)+1):
    for r in range(tmp+1):
        minus = []
        for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
        for num in v[n-r:]:
            if num < 0:
                minus.append(num)
        pre = sumArea(0,tmp-r) + sumArea(n-r,n)
        l = min(tmp,k-tmp,len(minus))
        if minus:
            minus.sort()
            pre -= sum(minus[:l])
        ans = max(ans,pre)
print(ans)

Measured memory_bytes: 78932
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MP make_pair
#define MOD 1000000007LL
#define endl "\n"
#define fst first
#define snd second
const ll UNDEF = -1;
const int INF=1e9;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
const int mn=6004;
bool a[mn],b[mn];
int vleft[mn],vright[mn];

ll fcost(ll left, ll right, ll k) {
	if (k>=0) {
		return left*2+k+max(0ll,right-k)*2;
	}
	return right*2+abs(k)+max(0ll,left-abs(k))*2;
}

int main(){	
	ios_base::sync_with_stdio(false); cin.tie(0);
	string A,B; cin>>A>>B;
	int n=A.length();
	for (int i=0;i<3*n;i++) a[i]=A[i%n]-'0';
	for (int i=0;i<3*n;i++) b[i]=B[i%n]-'0';
	{
		int lastone=-1;
		for (int x=0;x<n+n;x++) {
			if (b[x]==1) lastone=x;
			if (lastone!=-1) {
				vleft[x]=x-lastone;
			}
			else {
				vleft[x]=INF;
			}
		}
	}
	{
		int lastone=-1;
		for (int x=3*n-1;x>=n;x--) {
			if (b[x]==1) lastone=x;
			if (lastone!=-1) {
				vright[x]=lastone-x;
			}
			else {
				vright[x]=INF;
			}
		}
	}
	ll final=INF;
	for (ll k=-n;k<=n;k++) {
		vector<pll> vl;
		ll add=0;
		for (ll x=n;x<n+n;x++) {
			if (a[x]==1&&b[x+k]==0) {
				vl.PB(MP(vleft[x],vright[x]));
				//printf("x:%lld vleft:%lld vright:%lld\n",x,vleft[x],vright[x]);
			}
			if (a[x]!=b[x+k]) add++;
		}
		sort(vl.begin(),vl.end(),greater<pll>());
		ll right=0;
		for (auto &w:vl) {
			ll left=w.fst;
			//printf("left:%lld right:%lld\n",left,right);
			ll cand=fcost(left,right,k)+add;
			chkmin(final,cand);
			chkmax(right,w.snd);
		}
		{
			ll left=0;
			//printf("left:%lld right:%lld\n",left,right);
			ll cand=fcost(left,right,k)+add;
			chkmin(final,cand);
		}
	}
	if (final>=INF-1) final=-1;
	printf("%lld\n",final);
}



Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define POWER9 1000000000
#define MOD POWER9+7
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << setprecision(9);

	int N;
	cin >> N;
	int A[200000];
	for(int i=0; i<N; i++){
		cin >> A[i];
		A[i] -= i+1;
	}
	sort(A,A+N);
	int tmp = A[N/2];
	LL ans = 0;
	for(int i=0; i<N; i++){
		ans += abs(A[i]-tmp);
	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 1024