akhauriyash/Code-Regression huggingface dataset:
import static java.lang.System.*;
import java.util.*;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Scanner sc = new Scanner(in);
		
		for(int seti=1; ; seti++) {
			int n = sc.nextInt();
			if(n==0) break;
			
			boolean[][][] map = new boolean[5][5][5];
			for(int i=0; i<5; i++) {
				for(int j=0; j<5; j++) {
					char[] tmp = sc.next().toCharArray();
					for(int k=0; k<5; k++) {
						map[i][j][k] = tmp[k] == '1';
					}
				}
			}

			ArrayList<Integer> birth = new ArrayList<Integer>();
			ArrayList<Integer> die = new ArrayList<Integer>();

			int b = sc.nextInt();
			for(int i=0; i<b; i++) birth.add(sc.nextInt());
			int d = sc.nextInt();
			for(int i=0; i<d; i++) die.add(sc.nextInt());

			while(n-->0) {
				boolean[][][] next = new boolean[5][5][5];
				
				for(int i=0; i<5; i++) {
					for(int j=0; j<5; j++) {
						for(int k=0; k<5; k++) {
							int count = 0;
							for(int x=-1; x<=1; x++) {
								for(int y=-1; y<=1; y++) {
									for(int z=-1; z<=1; z++) {
										if(x==0 && y==0 && z==0) continue;
										
										int nz = i + z;
										int ny = j + y;
										int nx = k + x;
										
										if(!(0<=nx && nx<5 && 0<=ny && ny<5 && 0<=nz && nz<5)) continue;
										if(map[nz][ny][nx]) count++;
										
//										out.println(" " + nz + " " + ny + " " + nx + "  " + (map[nz][ny][nx] ? "T":"F"));
									}
								}
							}
//							out.println(i + " " + j + " " + k + " " + count);
							
							next[i][j][k] = false;
							if(!map[i][j][k]) {
								for(int c: birth) {
									if(count == c) {
										next[i][j][k] = true;
										break;
									}
								}
							}
							else {
								for(int c: die) {
									if(count == c) {
										next[i][j][k] = true;
										break;
									}
								}
							}
						}
					}
				}
				
				map = next;
			}
			
			if(seti != 1) out.println();
			out.println("Case " + seti + ":");

			for(int i=0; i<5; i++) {
				for(int j=0; j<5; j++) {
					for(int k=0; k<5; k++) {
						out.print(map[i][j][k] ? "1": "0");
					}
					out.println();
				}
				if(i!=4) out.println();
			}
		}
	}

}

Measured memory_bytes: 33836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int n;
    cin>>n;
    int a[n+1];
    fo(i,1,n) cin>>a[i];
    int ans = 0;
    fo(i,1,n){
    	if(i%2 and a[i]%2) ans++;
    }
    show(ans);
    return 0;
}

Measured memory_bytes: 3608
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();

        if(s.equals("Sunny")){
            System.out.println("Cloudy");
        }else if(s.equals("Cloudy")){
            System.out.println("Rainy");
        }else{
            System.out.println("Sunny");
        }
        sc.close();
    }
}

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

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

    if (N == 10 or N == 100 or N == 1000 or N == 10000 or N == 100000) {
        cout << 10 << endl;
    } else {
        int ans = 0;
        while (N>0) {
            ans += N%10;
            N /= 10;
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll x;
    cin >> x;
    ll a = 100;
    ll count = 0;
    while(a < x){
        double b = (double)a*1.01;
        a = (ll)b;
        count++;
       // cout << a << endl;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
int main() {
  while (1) {
    int x, y;
    scanf("%d %d", &x, &y);
    if (x == 0 && y == 0) break;
    if (x > y) {
      int t=x;
      x=y;
      y=t;
    }
    printf("%d %d\n", x, y);
  }
  return 0;
}

Measured memory_bytes: 596
#include <iostream>

using namespace std;

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

    if(S=="A"){cout<<"T"<<endl; return 0;}
    if(S=="T"){cout<<"A"<<endl; return 0;}
    if(S=="C"){cout<<"G"<<endl; return 0;}
    if(S=="G"){cout<<"C"<<endl; return 0;}

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int room[5][4][11]={{{}}};
  int n,i,i2,i3,v,f,r,b;
 


  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d%d%d%d",&b,&f,&r,&v);  
    room[b][f][r]+=v;
  }


  for(i3=1;i3<=4;i3++){
    for(i2=1;i2<=3;i2++){
      for(i=1;i<=10;i++){
	printf(" %d",room[i3][i2][i]);
	if (i==10) {printf("\n");}
      }
    }
    if(i3!=4) {printf("####################\n");}
  }

  return 0;
}
     

Measured memory_bytes: 612
from heapq import heappush, heappop
N, M = map(int, input().split())

Data = [list(map(int, input().split())) for _ in range(N)]
Data.sort(reverse = True)

heap = [0] * M
ans = 0
for i in range(1, M+1):
    N = len(Data)
    for j in range(N-1, -1, -1):
        if Data[j][0] > i:
            break
        if (Data[j][0] <= i):
            heappush(heap, -(Data.pop(j)[1]))

    ans += -(heappop(heap))

print(ans)


Measured memory_bytes: 29484
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}




int main() {
	int w, a, b;
	cin >> w >> a >> b;
	cout << max(max(b - a - w, 0),max(a-b-w,0)) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
#include <string>
#include <utility>

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

using namespace std;

int inputValue(){
	int a;
	cin >> a;
	return a;
}

void inputArray(int *p,int a){
	rep(i,a){
		cin >> p[i];
	}
}

void inputVector(vector<int> *p,int a){
	rep(i,a){
		int input;
		cin >> input;
		p -> push_back(input);
	}
}

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

int main(){
	//source
	int n,m;
	cin >> n >> m;
	vector<int> a;
	inputVector(&a,m);
	int num[10]={0,2,5,5,4,5,6,3,7,6};
	sort(a.rbegin(),a.rend());
	int inf=pow(10,8);

	int dp[n+1];
	dp[0]=0;
	repd(i,1,n+1){
		int max_value=-inf;
		rep(j,m){
			int new_index=i-num[a[j]];
			if(new_index>=0){
				max_value=max(dp[new_index]+1,max_value);
			}
		}
		dp[i]=max_value;
	}

	int remain=n;
	string result="";
	rep(i,dp[n]){
		rep(j,m){
			int new_index=remain-num[a[j]];
			if(new_index<0){
				continue;
			}
			if(dp[remain]-dp[new_index]==1){
				remain=new_index;
				result=result+to_string(a[j]);
				break;
			}
		}
	}

	cout << result << endl;
	return 0;
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    for( int i = 0; i < n; i++ ) cin >> a[i];
    sort( a.begin(), a.end() );
    ll s, t;
    s = t = 0;
    for( int i = 0; i < n/2; i++ ) s += a[i]*2;
    for( int i = n/2; i < n; i++ ) t += a[i]*2;
    ll res;
    if( n%2 == 0 ) {
        res = (t-a[n/2])-(s-a[n/2-1]);
    }
    else {
        ll sum1, sum2;
        sum1 = sum2 = 0;
        sum1 = (t-a[n/2]-a[n/2+1]) - s;
        sum2 = (t-a[n/2]*2) - (s+a[n/2]-a[n/2-1]);
        res = max( sum1, sum2 );
    }
    dump( res );
    return 0;  
}

Measured memory_bytes: 1024
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

long long max(long long a, long long b) {
    if(a >= b) {
        return a;
    } else {
        return b;
    }
}
long long min(long long a, long long b) {
    if(a >= b) {
        return b;
    } else {
        return a;
    }
}
// 互除法で最大公約数
long long gcd(long long a, long long b) {
    long long x = max(a, b);
    long long y = min(a, b);
    long long temp = x % y;
    while(temp != 0) {
        x = y;
        y = temp;
        temp = x % y;
    }
    return y;
}

int main() {
    long long a, b;
    cin >> a >> b;
    //最大公約数求める
    long long x = gcd(a, b);

    long long ans = x * (a / x) * (b / x);

    cout << ans << endl;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
           bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        b: String,
    };
    let ret = match &*b {
        "A" => "T",
        "T" => "A",
        "C" => "G",
        "G" => "C",
        _ => "",
    };

    println!("{}", ret);

}



Measured memory_bytes: 4352
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const int INF= 1e9+5;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
int main(){
  ll n;cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  vl sum(n);
  sum[0]=a[0];
  rep(i,n-1)sum[i+1]=sum[i]+a[i+1];
  ll ans=0,count=0;
  rep(i,n){
    if(i%2==0){
      if(sum[i]+count<=0){
        ll p=1-(sum[i]+count);
        count+=p;
        ans+=p;
      }
    }
    else{
      if(sum[i]+count>=0){
        ll d=sum[i]+count+1;
        count-=d;
        ans+=d;
      }
    }
  }
  ll anss=0,countt=0;
  rep(i,n){
    if(i%2==1){
      if(sum[i]+countt<=0){
        ll q=1-(sum[i]+countt);
        countt+=q;
        anss+=q;
      }
    }
    else{
      if(sum[i]+countt>=0){
        ll t=sum[i]+countt+1;
        countt-=t;
        anss+=t;
      }
    }
  }
  cout<<min(anss,ans)<<endl;
}
      

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>

using namespace std;

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

    vector<int> h(N,0);
    for(int i=0; i<N; i++){
        cin >> h[i];
    }

    vector<int> dp(N,2000000000);
    dp[0]=0;
    for(int i=1; i<N; i++){
        for(int j=1; j<min(K+1,i+1); j++){
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
import math
K = int(input())
ans = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            gcd = math.gcd(i, math.gcd(j, k))
            if i == j == k:
                ans += gcd
            elif i != j and j != k:
                ans += 6 * gcd
            else:
                ans += 3 * gcd
print(ans)

Measured memory_bytes: 67944
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
#define pb push_back
#define f first
#define s second
#define fr(i, n) for(int i = 0; i < n; i++)
#define frr(i, n) for(int i = 1; i<= n; i++)
#define MOD 1000000007
const int MAX = 2123;
ll n, k;
map<ll, ll> m;
ll a, b;
ll cnt;
ll ans;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	cin >> k;
	for(ll i = 0; i < n; i++){
		cin >> a >> b;
		m[a] += b;
	}
	ans = 0;
	cnt = 0;
	for(auto x : m){
		cnt += x.s;
		if(cnt >= k){
			ans = x.f;
			break;
		}
	}
	cout << ans << endl;
}


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

using namespace std;
#define LL long long

const LL M = 10e9+7;

int main()
{
    int s[6],k;
    for(int i=0;  i<5; i++)
    {
        cin>>s[i];
    }
    cin>>k;
    sort(s,s+5);
    if(s[4]-s[0]>k) cout<<":("<<endl;
    else cout<<"Yay!"<<endl;
    return 0;
}


Measured memory_bytes: 256
import collections

N = int(input())

withdraw = []
withdraw.append(1)
i = 1
while 6 ** i < 100000:
    withdraw.append(6 ** i)
    i += 1
i = 1
while 9 ** i < 100000:
    withdraw.append(9 ** i)
    i += 1
withdraw = sorted(withdraw)

# 残り12ってときに、6, 6だと最小だが貪欲だと9, 1, 1, 1になっちゃう。
# 幅優先探索して最初に0になったものが最短。
# nodeは(残り金額, depth)
memo = set([N])
q = collections.deque([(N, 0)])
while len(q) > 0:
    n, depth = q.popleft()
    if n == 0:
        print(depth)
        break
    for w in withdraw:
        if n >= w and n-w not in memo:
            q.append((n-w, depth+1))
            memo.add(n-w)


Measured memory_bytes: 14124
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;

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

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}

long long int kaijo(long long int n){
    if(n==0) return 1;
    else return n*kaijo(n-1);
}

long long int product(long long int n, long long int k){
    long long int tmp=1;
    for(int i=k;i<=n;i++){
        if(k==0) continue;
        tmp*=i;
    }
    return tmp;
}


int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    vector<pair<int, int>> c(n);
    for(int i=0;i<n;i++){
        cin>>s[i];
        c[i].first=0;c[i].second=0;
    }
    sort(s.begin(),s.end());

    string k=s[0];
    int num=0;
    int m=0;
    for(int i=0;i<n;i++){
        if(s[i]==k){
            c[num].first++;
        }
        else{
            m=max(m,c[num].first);
            num++;
            c[num].first++;
            c[num].second=i;
            k=s[i];
        }
    }m=max(m,c[num].first);

    for(int i=0;i<n;i++){
        if(c[i].first==m){
            cout<<s[c[i].second]<<endl;
        }
    }


    return 0;
} //カモンAC


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG_OUTPUT
#define DEBUG_LOG(s) cout << s << endl;
#else
#define DEBUG_LOG(s) void();
#endif

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

    vector<vector<int>> a(3, vector<int>(n));
    priority_queue<int, vector<int>, greater<>> left;
    priority_queue<int> right;
    vector<int64_t> lsum(n + 1, 0), rsum(n + 1, 0);
    for (auto i = 0; i < 3; i++) {
        for (auto j = 0; j < n; j++) cin >> a[i][j];
    }

    for (auto i = 0; i < n; i++) {
        left.push(a[0][i]);
        right.push(a[2][i]);
        lsum[0] += a[0][i];
        rsum[0] += a[2][i];
    }

    for (auto i = 0; i < n; i++) {
        left.push(a[1][i]);
        auto p = left.top(); left.pop();
        lsum[i + 1] = lsum[i] + a[1][i] - p;

        right.push(a[1][n - i - 1]);
        p = right.top(); right.pop();
        rsum[i + 1] = rsum[i] + a[1][n - i - 1] - p;
    }

//    for (auto i = 0; i <= n; i++) cout << lsum[i] << " ";
//    cout << endl;
//    for (auto i = 0; i <= n; i++) cout << rsum[i] << " ";
//    cout << endl;

    int64_t ans = INT64_MIN;
    for (auto i = 0; i <= n; i++) {
        ans = max(ans, lsum[i] - rsum[n - i]);
    }

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

Measured memory_bytes: 7220
fun main() {
    val num = readLine()!!
    var pow = 1
    var rem = 0
    val rems = IntArray(2019)
    rems[0] = 1
    for (i in num.length - 1 downTo 0) {
        val d = num[i] - '0'
        rem = (rem + pow * d) % 2019
        pow = (pow * 10) % 2019
        rems[rem]++
    }
    var count = 0
    rems.forEach { i ->
        if (i > 0) {
            count += i * (i - 1) / 2
        }
    }
    println(count)
}

Measured memory_bytes: 38532
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), x(n, -1), origin(n, 0);
    priority_queue<int, vector<int>, greater<int>> smallest;
    bool ok = true;
    map<int, int> islast;
    rep(i, n)
    {
        cin >> a[i];
        if(a[i]>i or a[i]-a[i-1]>1){
            ok=false;
        }
    }
    ll cnt = 0;
    if(ok){
        FOR(i,1,n){
            if(a[i]==a[i-1]+1){
                cnt++;
            }else{
                cnt+=a[i];
            }
        }
        cout<<cnt<<endl;
    }else{
        cout<<-1<<endl;
    }

   
}

Measured memory_bytes: 2688
#pragma region Macros
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
#pragma endregion

void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    int cnt0 = 0, cnt1 = 0, cnt2 = 0;
    for (int i=0; i<n; i++) {
        int tmp;
        cin >> tmp;
        if (tmp <= a) cnt0++;
        else if (tmp > a && tmp <= b) cnt1++;
        else cnt2++;
    }
    cout << min(cnt0, min(cnt1, cnt2)) << "\n";
}

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

    solve();

    return 0;
}


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

using namespace std;
using ll=long long;
using ull=unsigned long long;

typedef pair<int,int>Pi;
typedef pair<long long,long long>P;
typedef pair<long long,P>PP;
typedef pair<P,P>PPP;

const long long MOD=1e9+7;
const long long INF=3e18;
const int di[4]={1,0,-1,0};
const int dj[4]={0,1,0,-1};

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()

int a,b,q;
ll s[100010],t[100010],x;
ll ne1[100010],ne2[100010];
ll n1[100010],n2[100010];

void input(){
	cin>>a>>b>>q;
    for(int i=0;i<a;i++)cin>>s[i];
    for(int i=0;i<b;i++)cin>>t[i];
	return;
}

void solve(){
    while(q--){
        cin>>x;
        int it1=lower_bound(s,s+a,x)-s;
        int it2=lower_bound(t,t+b,x)-t;
        ll sl,sr,tl,tr;
        if(it1==0)sl=-INF;else sl=s[it1-1];
        if(it1==a)sr=INF;else sr=s[it1];
        if(it2==b)tr=INF;else tr=t[it2];
        if(it2==0)tl=-INF;else tl=t[it2-1];
        ll ans=INF;
        ans=min(ans,x-sl+min(abs(sl-tl),abs(sl-tr)));
        ans=min(ans,x-tl+min(abs(tl-sl),abs(tl-sr)));
        ans=min(ans,sr-x+min(abs(sr-tl),abs(sr-tr)));
        ans=min(ans,tr-x+min(abs(tr-sl),abs(tr-sr)));
        cout<<ans<<endl;
    }
	return;
}

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

Measured memory_bytes: 3968
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N+1)
for _ in range(M):
    A, B = map(int, input().split())
    uf.union(A, B)

print(len(uf.roots()) - 2)


Measured memory_bytes: 12768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&a!=c)||(a==c&&a!=b)||(b==c)&&b!=a)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cstdio>
#include<cmath>
#include<map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
int MOD=1000000007;
int inf=1e9+7;
signed main(){
    int n;cin>>n;
    vector<int> p(n+1,0);
    vector<int> memo(n+1,0);
    rep1(i,n){
        int buf;cin>>buf;
        p[i]=buf;
        memo[buf]=i;
    }
    int res=0;
    map<int,int> array;
    array[0]=0;
    array[n+1]=n+1;
    for(int i=n;i>0;--i){
        array[memo[i]]=i;
        auto it=array.find(memo[i]);
        auto b=it;--b;
        auto f=it;++f;
        int buf=0;
        int sup=min(f->first,n+1);
        if(b->second!=0){
            auto bb=b;--bb;
            buf+=(b->first-bb->first)*(f->first-it->first)*it->second;
        }
        if(f->second!=n+1){
            auto ff=f;++ff;
            buf+=(ff->first-f->first)*(it->first-b->first)*it->second;
        }
        res+=buf;
    }
    cout<<res<<"\n";
    return 0;
}

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

using namespace std;

const int N = 1e5 + 5;

int a[N];

int main(){
	int n, x;
	cin >> n >> x;
	for (int i = 1; i <= n; i++) cin >> a[i];
	
	int ans = 0;
	for (int i = 1; i <= n; i++) ans = __gcd(ans, abs(x - a[i]));
	cout << ans;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#include <cstring>

using namespace std;

#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")

int dp[100001];
vector<int> adj[100001];
int v, e, x, y, res;

int dfs(int n) {
    if (dp[n] != -1) return dp[n];
    int out = 0;

    for (auto x: adj[n]) {
        out = max(out, dfs(x)+1);
    }

    dp[n] = out;
    return out;
}

int main() {
    scanf("%d %d", &v, &e);
    memset(dp, -1, sizeof(dp));

    for (int i = 0; i < e; i++) {
        scanf("%d %d", &x, &y);
        x--; y--;
        adj[x].push_back(y);
    }

    for (int i = 0; i < v; i++) {
        res = max(res, dfs(i));
    }

    printf("%d", res);
    
    return 0;
}

Measured memory_bytes: 8320
n = int(input())
v = list(map(int, input().split()))

array1 = v[::2]
array2 = v[1::2]

dict1 = {}
dict2 = {}
for i in array1:
  if i not in dict1:
    dict1[i] = 1
  else:
    dict1[i] = dict1[i] + 1

for i in array2:
  if i not in dict2:
    dict2[i] = 1
  else:
    dict2[i] = dict2[i] + 1

sort_array1 = []
sort_array2 = []
for k, v in sorted(dict1.items(), key=lambda x: -x[1]):
    sort_array1.append({k:v})
for k, v in sorted(dict2.items(), key=lambda x: -x[1]):
    sort_array2.append({k:v})

one_num1 = 0
one_num2 = 0

for k1,v1 in sort_array1[0].items():
  if len(sort_array1) != 1:
    one_num1 = len(array1) - v1
  for k2,v2 in sort_array2[0].items():
    if len(sort_array2) != 1:
      one_num2 = len(array2) - v2
    if k1 != k2:
      print(one_num1 + one_num2)
      break

    if len(sort_array1) == 1 and len(sort_array2) == 1:
      print(len(array1))
      break
    if len(sort_array1) == 1:
      for k,v in sort_array2[1].items():
        two_num2 = v
      print(1+two_num2)
      break
    if len(sort_array2) == 1:
      for k,v in sort_array1[1].items():
        two_num1 = v
      print(1+two_num1)
      break

    for k,v in sort_array1[1].items():
      two_num1 = len(array1) - v
    for k,v in sort_array2[1].items():
      two_num2 = len(array2) - v
    if two_num1 <= two_num2:
      print (one_num2 + two_num1)
    else:
      print (one_num1 + two_num2)

Measured memory_bytes: 47276
# include <stdio.h>

int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  int a_flg, b_flg;
  a_flg = (a/100) * 100
    + ((a/1000)%10) * 10
    + (a/10000) - a >= 0;
  b_flg = (b/100) * 100
    + ((b/1000)%10) * 10
    + (b/10000) - b <= 0;
  printf("%d\n",b/100-a/100-1+a_flg+b_flg);
 return 0; 
}

Measured memory_bytes: 128
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#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 <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#define endl "\n";
using namespace std;

const long long INF = 100100100100100100;
const int MOD = 1000000007;
const int inf = 1001001001;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

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

    int N;long long K;cin >> N >> K;
    string S;cin >> S;
    vector<int> alpha(26);
    for(int i = 0;i<N;i++){
        alpha.at(S.at(i)-97)++;
    }
    char miniC = 'a';
    for(int i = 0;i<26;i++){
        if(alpha.at(i) >= 1) {
            miniC = 'a'+i;
            break;
        }
    }
    if(K >= 13){
        for(int i = 0;i<N;i++){
            cout << miniC;
        }
        cout << endl;
        return 0;
    }
    //K <= 12なので、愚直にやりまぁす
    for(int i = 1;i<=K;i++){
        string U = S;
        reverse(S.begin(),S.end());
        U += S;
        string next = "";
        if(i == K){
            string ans = "";
            for(int j = 0;j<N;j++) ans += 'z';
            for(int j = 0;j<=U.size()-N;j++){
                string Compare = U.substr(j,N);
                if(ans > Compare){
                    ans = Compare;
                }
                //cout << Compare << endl;
            } 
            cout << ans << endl;
            return 0;
        }
        for(int j = 0;j<N;j++) next += 'z';
        for(int j = 0;j<=U.size()-N;j++){
            string Compare = U.substr(j,N);
            reverse(Compare.begin(),Compare.end());
            if(next > Compare){
                //cout << next << "->";
                next = Compare;
                //cout << next << endl;
            }
        }
        reverse(next.begin(),next.end());
        S = next;
    }
    
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

ll MOD;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 3001;

ll s[N_MAX][N_MAX], pow2[N_MAX*N_MAX], powpow2[N_MAX];

void init_stirling(int n, int m) {
    for(int i=0;i<=n;++i) s[i][0] = 1;
    for(int i=1;i<=n;++i) {
        for(int j=1;j<=m;++j) {
            s[i][j] = (s[i-1][j-1] + (s[i-1][j]*(j+1)) % MOD) % MOD;
        }
    }
}

ll fact[N_MAX], rfact[N_MAX];

ll perm(ll n, ll r){
    return (fact[n] * rfact[r]) % MOD;
}

ll comb(ll n, ll r){
    return (perm(n, r) * rfact[n-r]) % MOD;
}

void init(ll n){
    fact[0] = fact[1] = 1;
    rfact[0] = rfact[1] = 1;
    for(int i=2;i<=n;++i) {
        fact[i] = (fact[i-1] * (ll)i) % MOD;
        rfact[i] = 1;
        ll k = MOD-2;
        ll a = fact[i];
        while(k > 0){
            if(k & 1){
                rfact[i] *= a;
                rfact[i] %= MOD;
            }
            a *= a;
            a %= MOD;
            k  >>= 1;
        }
    }
}

ll modpow(ll a, ll t) {
    ll ret = 1LL;
    while(t){
        if(t & 1LL){
            ret *= a;
            ret %= MOD;
        }
        a *= a;
        a %= MOD;
        t >>= 1;
    }
    return ret;
}

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin >> n >> MOD;
    init(n);
    init_stirling(n, n);

    pow2[0] = 1LL;
    for(int i=0;i<n*n;++i) {
        pow2[i+1] = (2LL * pow2[i]) % MOD;
    }
    powpow2[0] = 2LL;
    for(int i=0;i<n;++i) {
        powpow2[i+1] = (powpow2[i] * powpow2[i]) % MOD; // 2^(2^n) = 2^(2^(n-1)) * 2^(2^(n-1))
    }

    ll ans = powpow2[n];
    for(ll i=1;i<=n;++i) {
        ll tmp = 0LL;
        for(ll j=0;j<=i;++j) {
            if(pow2[(n-i)*j] == 0) {
                pow2[(n-i)*j] = modpow(2LL, (n-i)*j);
            }
            tmp += pow2[(n-i)*j] * s[i][j];
            tmp %= MOD;
        }
        tmp *= comb(n, i);
        tmp %= MOD;
        tmp *= powpow2[n-i];
        tmp %= MOD;
        if(i % 2) {
            ans += MOD - tmp;
        } else {
            ans += tmp;
        }
        ans %= MOD;
    }

    cout << ans << endl;

}


Measured memory_bytes: 141056
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)


def main(): # C163
    N = int(input())
    sum = 0
    for i in range(1, N+1):
        for j in range(1, N+1):
            for h in range(1, N+1):
                sum += gcd(i,j,h)
    print(sum)


main()

Measured memory_bytes: 74716
/*
Author: Hossam Eissa
Idea:
*/
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define FI freopen("input.txt", "r", stdin);
#define FO freopen("o.txt", "w", stdout);
#define start ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 2000000000;
const int N = 5e5+5;
const double PI=acos(-1);
int n,m,k;
vector<int> kmparr(string s)
{
    vector<int>ret(s.size());
    int j=0;
    for(int i=1;i<s.size();i++){
        while(j&&s[i]!=s[j])j=ret[j-1];
        if(s[i]==s[j])j++;
        ret[i]=j;
    }
    return ret;

}

int main()
{
    cin>>n;
    string s1,s2;
    cin>>s1>>s2;
    vector<int>Z=kmparr(s2+'$'+s1);
    string ans=s1+s2.substr(Z[2*n]);
    cout<<ans.size()<<endl;;
}


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

int main() {
  char c;
  cin >> c;
  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o') {
    cout << "vowel" << endl;
  }
  else {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
n = int(input())
prime5 = []
for i in range(1,5600):
  a = i * 10 + 1
  # flag = True
  for j in range(3,int(a**0.5) + 1):
    if a % j == 0:
      break
      # flag = False
  else: prime5.append(a)
print(*prime5[:n])


Measured memory_bytes: 3188
N,K=map(int,input().split())
p=list(map(int,input().split()))
for i in range(N-1):
    p[i+1]=p[i+1]+p[i]
max=p[K-1]
if N>K:
    for i in range(1,N-K+1):
        tmp=p[i+K-1]-p[i-1]
        if max < tmp:
            max=tmp
print((max+K)/2.)

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

bool C(ll t, vector<ll>b, vector<ll>l, vector<ll>u, ll N, ll X){
    // 重要度はl_iかu_iの2択
    // 点数は端数が1個で他は満点か0点
    // 満点を取るのに必要な時間は一定
    vector<pair<ll,int>> effect(N);
    for (int i = 0; i < N; ++i) {
        ll temp = ((X - b[i]) * u[i]) + (b[i] * l[i]);
        effect[i] = make_pair(temp, i);
    }
    sort(effect.begin(), effect.end(), greater<pair<ll,int>>());

    vector<int> flag(N,0); // 満点を取ったら1にする
    ll score = 0;
    for (int i = 0; i < N; ++i) {
        score -= b[i] * l[i];
    }

    // 上から満点の個数だけ満点と仮定
    int perfect = t / X;
    for (int i = 0; i < perfect; ++i) {
        score += effect[i].first;
        flag[effect[i].second] = 1;
    }
    t %= X;
    if(score >= 0) return true;
    if(t == 0) return false;

    // まずは今0点と仮定した中から端数を選んで探索
    for (int i = 0; i < N; ++i) {
        if(flag[i] == 0){
            ll temp; // 増える効果
            if(t <= b[i]) {
                temp = t * l[i];
            } else {
                temp = ((t - b[i]) * u[i]) + (b[i] * l[i]);
            }
            if(score + temp >= 0) return true;
        }
    }

    // 無理なら effect[perfect].second を満点にして満点→端数をどれにするかで探索
    score += effect[perfect].first;
    for (int i = 0; i < N; ++i) {
        if(flag[i] == 1){
            ll temp; // 減る効果
            if(t <= b[i]) {
                temp = ((X - b[i]) * u[i]) + ((b[i] - t) * l[i]);
            } else {
                temp = (X - t) * u[i];
            }
            if(score - temp >= 0) return true;
        }
    }

    return false;
}

int main() {
    ll N, X;
    cin >> N >> X;
    vector<ll>b(N);
    vector<ll>l(N);
    vector<ll>u(N);
    for (int i = 0; i < N; ++i) {
      cin >> b[i] >> l[i] >> u[i];
    }
    
    // llで二分探索して最小値
    ll lb=-1, ub = N * X + 1;
    while( ub-lb > 1 ){
        ll mid = (lb+ub)/2;
        if(C(mid, b, l, u, N, X)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    cout << ub;
    return 0;
}

Measured memory_bytes: 6948
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int n;
int field[6][6];
char memo[1 << 25];

void printField() {
  REP(y, n) {
    REP(x, n) {
      cout << field[y][x] << " ";
    }
    cout << endl;
  }
}

int encode() {
  int ret = 0;
  REP(y, n) REP(x, n) {
    if (y == 0 && x == 0) { continue; }
    ret |= field[y][x] << ((y * 5) + x);
  }
  return ret;
}

void inv(int y, int x, int ey, int ex) {
  FOREQ(ny, y, ey) FOREQ(nx, x, ex) {
    field[ny][nx] ^= 1;
  }
}

int calc(int y, int x) {
  int state = encode();
  if (memo[state] != -1 && y != 0 && x != 0) { return memo[state]; }
  int ret = 100;
  if (x == n) { ret = calc(y + 1, 0); }
  else if (y == n) { ret = 0; }
  else if (field[y][x] == 0) { ret = calc(y, x + 1); }
  else {
    FOR(ny, y, n) {
      FOR(nx, x, n) {
        inv(y, x, ny, nx);
        ret = min(ret, calc(y, x + 1) + 1);
        inv(y, x, ny, nx);
      }
    }
  }
  if (y == 0 && x == 0) { return ret; }
  return memo[state] = ret;
}

int main() {
  MEMSET(memo, -1);
  while (scanf("%d", &n), n) {
    MEMSET(field, 0);
    REP(y, n) REP(x, n) {
      scanf("%d", &field[y][x]);
    }
    int ans = calc(0, 0);
    while (ans--) { printf("myon"); }
    puts("");
  }
}

Measured memory_bytes: 32000
while True:
  n,x = map(int, input().split())
  if n==0 and x==0:
    break
  ans=0
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      for k in range(j+1,n+1):
        if i+j+k==x:
          ans=ans+1
  print(ans)    


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define ll long long
#define ALL(x) x.begin(),x.end()
#define MOD (1000000000+7)
using namespace std;
#define PI 3.14159265359
#define tMOD 998244353
#define mkpr(x,y) make_pair(x,y)



int main(){
  ll X,ans,Y;
  ans =0;
  cin>>X>>Y;

  if(X==1){
ans +=300000;
  }
   if(X==2){
ans +=200000;
  }
   if(X==3){
ans +=100000;
  }
   if(Y==1){
ans +=300000;
  }
   if(Y==2){
ans +=200000;
  }
   if(Y==3){
ans +=100000;
  }

  if(X==1&&Y==1){
    ans+=400000;
  }
  cout<<ans<<endl;
}

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

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

  int k, s;
  cin >> k >> s;

  int cnt = 0;
  int r;
  for (int i = 0; i <= k; i++) {
    r = s - i;
    if (0 <= r && r <= k) {
      cnt += r + 1;
    } else if (k < r && r <= 2*k) {
      cnt += k - (r - k) + 1;
    }
  }
  cout << cnt << '\n';
  return 0;
}

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

using namespace std;


int gcd2(int a, int b) 
{ 
    if (a == 0) 
        return b; 
    return gcd2(b % a, a); 
} 

int gcd(int a,int b,int c)
{
	return gcd2(a,gcd2(b,c));
}
int main()
{
	int k;
	long long sum=0;
	cin>>k;
	for(int i=1;i<=k;i++){
		for(int j=1;j<=k;j++){
			for(int l=1;l<=k;l++){
				sum+=gcd(i,j,l);
			}
		}
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3636
def slove():
    import sys
    input = sys.stdin.readline
    pl = {}
    p = [True] * (10 ** 5 + 1)
    p[0] = False
    p[1] = False
    cnt = 0
    pll = [0] * (10 ** 5 + 1)
    for i in range(2, len(p)):
        if p[i]:
            pl[i] = 1
            for j in range(i, len(p), i):
                p[j] = False
        if i % 2 != 0:
            if (i + 1) // 2 in pl and i in pl:
                cnt += 1
        pll[i] = cnt
    q = int(input().rstrip('\n'))
    lr = [list(map(int, input().rstrip('\n').split())) for _ in range(q)]
    for l, r in lr:
        print(pll[r] - pll[l-1])


if __name__ == '__main__':
    slove()


Measured memory_bytes: 65500
using System;
using System.Collections.Generic;

class Program
{
	static void Main(string[] args)
	{
        int n;
        n = int.Parse(Console.ReadLine());
        int[] list = new int[n];
        int sum = 0;



        for (int i = 0;i < n;i++)
        {
            int a = int.Parse(Console.ReadLine());
            list[i] = a; 
        }

        Array.Sort(list);
        int j = 0;
        while(j < n)
        {
            int cc = list[j];
            int f = 0;
            while(j < n && list[j] == cc)
            {
                f++;
                j++;
            }
            sum += f % 2;

        }


        Console.WriteLine(sum);

	}
}

Measured memory_bytes: 15328
#include<cstdio>
#include<iostream>
using namespace std;
int n,m=42;
bool vis[100010];
int main()
{
	scanf("%d",&n);
	
	if (n<=8)
	{
		if (n==3) printf("2 5 63");
		if (n==4) printf("2 4 3 9");
		if (n==5) printf("2 4 3 6 9");
		if (n==6) printf("2 4 3 9 6 12");
		if (n==7) printf("2 4 3 9 6 8 10");
		if (n==8) printf("2 4 3 9 6 12 8 10");
		return 0;
	}
	for (int i=2;i<=30000;i+=2) vis[i]+=1;
	for (int i=3;i<=30000;i+=3) vis[i]+=2;
	int tim=n/8;
	n=n%8;
	for (int i=1;i<=12*tim;i++)
		if (vis[i]) printf("%d ",i);
	int nw=6*tim*2;
	if (n==1) printf("%d",nw+6);
	if (n==2) printf("%d %d",nw+6,nw+12);
	if (n==3) printf("%d %d %d",nw+6,nw+3,nw+9);
	if (n==4) printf("%d %d %d %d",nw+2,nw+4,nw+3,nw+9);
	if (n==5) printf("%d %d %d %d %d",nw+2,nw+4,nw+3,nw+6,nw+9);
	if (n==6) printf("%d %d %d %d %d %d",nw+2,nw+4,nw+3,nw+6,nw+9,nw+12);
	if (n==7) printf("%d %d %d %d %d %d %d",nw+2,nw+4,nw+3,nw+6,nw+9,nw+8,nw+10);
//	if (n==8) printf("%d %d %d %d %d %d %d %d",nw+2,nw+4,nw+3,nw+6,nw+9,nw+8,nw+10,nw+12);
}

Measured memory_bytes: 384
/*Lucky_Glass*/
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		ll a,b;scanf("%lld%lld",&a,&b);
		if(a>b) swap(a,b);
		if(a==b || a+1==b) printf("%lld\n",2*(a-1));
		else
		{
			ll c=(ll)floor(sqrt(a*b));
			if(c*c==b*a) c--;
			if(c*(c+1)>=a*b) printf("%lld\n",2*c-2);
			else printf("%lld\n",2*c-1);
		}
	}
	return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

lli cnt[100100];

void func(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){


    lli sum = 0;

    REP(i,0,N){
        cnt[A[i]]++;
        sum += A[i];
    }

    REP(i,0,Q){
        lli fromC = cnt[B[i]];
        sum -= B[i]*fromC;
        sum += C[i]*fromC;
        cnt[B[i]] = 0;
        cnt[C[i]] += fromC;
        cout<<sum<<endl;
    }

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    func(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 6364
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <numeric>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

// Split
namespace util {

std::vector< std::string > split(std::string s, char delimiter)
{
  std::vector< std::string > vs;
  std::string sub;
  for (auto c : s) {
    if (c == delimiter) vs.push_back(sub), sub.clear();
    else sub += c;
  }
  vs.push_back(sub);
  return vs;
}

} // namespace util

// Minimum, Maximum
template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }
template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

// Output
template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  for (ll i = 0; i < (ll)v.size(); i++){ os << " [" << i << "]" << v[i]; if (i % 10 == 9) os << std::endl; }
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp){os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

  ll N;
  std::cin >> N;
  std::vector< ll > va(N, 0LL);
  for (ll i = 0; i < N; i++) {
    std::cin >> va[i];
  }

  std::vector< std::vector<ll> > dp(N+1, std::vector<ll>(2, 0LL));
  dp[0][0] = 0LL;
  dp[0][1] = -INF;
  for (ll i = 0; i < N; i++) {
    dp[i+1][0] = std::max(dp[i][0] + va[i], dp[i][1] - va[i]);
    dp[i+1][1] = std::max(dp[i][0] - va[i], dp[i][1] + va[i]);
  }

  print(dp[N][0]);
  return 0;
}


Measured memory_bytes: 6528
def main():
    from collections import Counter
    import sys
    input = sys.stdin.readline
    n=int(input())
    s=[]
    ap = s.append
    for _ in [0]*n:
        ap(input().rstrip())
    c = Counter(s)
    ans=[]
    max_vote = max(c.values())
    for i,j in c.items():
        if j == max_vote:
            ans.append(i)
    print("\n".join(sorted(ans)))
main()

Measured memory_bytes: 35932