akhauriyash/Code-Regression huggingface dataset:
import std;

int calc(long k, int[] a) {
    a = [0] ~ a;
    auto used = new long[a.length];
    used[] = -1;
    int p = 1;
    long step = 0;
    while (true) {
        if (step == k) {
            return p;
        }

        if (used[p] != -1) {
            // writeln("loop ", step - used[p]);
            auto m = (k - used[p]) % (step - used[p]);
            // writeln("m ", m);
            m += used[p];

            for (int i = 0; i < a.length; i++) {
                if (used[i] == m) return i;
            }
        }

        used[p] = step++;
        // writeln(p, " -> ", a[p]);
        p = a[p];
    }
    return 0;
}

// ダブリングによる解法
int calc2(long k, int[] a) {
    auto N = a.length;
    const C = 100;

    auto dub = new int[][](C, N);
    // k = 0 のとき(2^k = 0)
    for (int i = 0; i < N; i++)
        dub[0][i] = a[i] - 1;

    // k > 0 のとき
    for (int i = 0; i < C-1; i++) {
        for (int j = 0; j < N; j++) {
            dub[i+1][j] = dub[i][dub[i][j]];
        }
    }

    // k ステップで到達するノード
    auto step = k;
    int now = 0;
    for (int i = 0; ; i++) {
        if (step % 2 == 1) now = dub[i][now];
        step /= 2;
        if (step == 0) break;
    }
    return now + 1;
}

void main() {
    long n, k; scan(n, k);
    auto a = readints;
    writeln(calc2(k, a));
}

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T=string)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readints = reads!int;


Measured memory_bytes: 87732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n;
    cin >> n;
    if (n <= 2) cout << 0 << endl;
    else cout << (n - 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int n;
	while (cin>>n)
	{
		if (n <= 2)
			cout << n << endl;
		else if(2<=n && n<4)
			cout << 2 << endl;
		else if (4 <= n && n<8)
			cout << 4 << endl;
		else if (8 <= n && n<16)
			cout << 8 << endl;
		else if (16 <= n && n<32)
			cout << 16 << endl;
		else if (32 <= n && n<64)
			cout << 32 << endl;
		else
			cout << 64 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
using vl = vector<ll>;
using Map = map<ll,ll>;
using Tup = tuple<ll,ll,ll>;
using vvl = vector<vector<ll>>;
#define all(v) v.begin(), v.end()
#define prt(v) cout<<(v)<<"\n";
#define fl cout<<flush;
#define fi(v) get<0>(v)
#define se(v) get<1>(v)
#define th(v) get<2>(v)
#define endl "\n"
template <typename T> bool chmax(T &a, const T &b){if (a<b){a=b;return 1;}return 0;}
template <typename T> bool chmin(T &a, const T &b){if (a>b){a=b;return 1;}return 0;}
const ll INF=1LL<<60;
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld pi=3.141592653589793238;


signed main(void){
    cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    ll H;
    cin >> H;
    ll W;
    cin >> W;
    vector<vector<char>> A(H, vector<char>(W));
    for(ll i=0;i<H;++i)
        for(ll j=0;j<W;++j)cin>>A[i][j];
    vector<vector<ll>> dp(H, vector<ll>(W,0));
    dp[0][0]=1;
    for(ll i=0;i<H;++i)
        for(ll j=0;j<W;++j){
            if(i>0&&A[i-1][j]=='.'){
                dp[i][j]+=dp[i-1][j];
            }
            if(j>0&&A[i][j-1]=='.'){
                dp[i][j]+=dp[i][j-1];
            }
            dp[i][j]%=MOD;
        }
    prt(dp[H-1][W-1])

    return 0;
}


Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
using namespace std;
typedef long long ll;
#define mp make_pair;
#define pb push_back;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


#include <bits/stdc++.h>

#define MAX 200010

using namespace std;
typedef long long int lli;

int n;

int v[MAX];
int L[MAX];
int R[MAX];

lli ans;

int main()
{
  scanf("%d",&n);

  v[0] = v[n + 1] = -MAX;

  rep1(g,n){
    scanf("%d",&v[g]);
  }
  rep1(g,n){
    
    int cur = g - 1;
    while(v[cur] > v[g]) cur = L[cur];
    L[g] = cur;
  }
  
  for(int g = n ; g >= 1 ; g--)
    {
      int cur = g + 1;

      while(v[cur] > v[g]) cur = R[cur];

      R[g] = cur;
    }

  for(lli g = 1 ; g <= n ; g++)
    {
      lli qtd = (R[g] - g)*(g - L[g]);
      ans += qtd*v[g];
    }

  printf("%lld\n",ans);
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
long long n,a[3500],dp[3050][3050][3],sum;
long long f(int l,int r,int ran)
{
    if(l>r)return 0;
    if(dp[l][r][ran]!=-1)return dp[l][r][ran];
    long long mx;
    if(ran==0)
    {
        mx=0;
        mx=max(f(l,r-1,1)+a[r],f(l+1,r,1)+a[l]);
    }
    else
    {
        mx=1e18;
        mx=min(f(l,r-1,0),f(l+1,r,0));
    }
    return dp[l][r][ran]=mx;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    memset(dp,-1,sizeof dp);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    cout<<f(0,n-1,0)-(sum-f(0,n-1,0));
}


Measured memory_bytes: 218496
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr<<#x<<": "<<x<<endl

int main(){
    ll n, k;
    cin >> k >> n;

    vector<ll> a(2*n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[n+i] = a[i]+k;
    }

    ll ans = 1000000000;
    for(int i = 0; i < n; i++){
        ans = min(ans,a[n-1+i]-a[0+i]);
    }
    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 3328
#include <stdio.h>

void insertion(int *,int ,int );
int cnt;

  int main (){
    int i,j,m=0,a[1000000],G[1000000],n;


  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);

  cnt=0;
  G[0]=1;
  m=m+1;
  for(i=0;n>3*G[i]+1;i++){
    G[i+1]=3*G[i]+1;
    m++;
  }

  for(i=0;i<m;i++){
    insertion (a,n,G[m-i-1]);
  }


  printf("%d\n",m);

  for(i=0;i<m;i++){
    printf("%d",G[m-i-1]);
    if(i<m-1)
      printf(" ");
  }

  printf("\n%d\n",cnt);
  for(i=0;i<n;i++)
    printf("%d\n",a[i]);
}
void insertion(int a[],int n,int g)
{
  int v,j,i;
  for(i=g;n>i;i++){
    v=a[i];
    j = i - g;
    while (j >= 0 && a[j] > v){
      a[j+g]=a[j];
      j =j-g;
      cnt++;
      a[j+g]=v;
    }
  }
  
}



Measured memory_bytes: 5608
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial,sqrt
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n=I()
    lis=LI()
    ans=0
    for i in range(1,n):
        if lis[i-1]>lis[i]:
            ans+=lis[i-1]-lis[i]
            lis[i]=lis[i-1]
    print(ans)
        
    
if __name__=="__main__":
    main()



Measured memory_bytes: 103904
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

ll a[200010], ans;

int main() {
    ios_base::sync_with_stdio(0);
    int n; cin >> n;
    for (int i=0;i<n;i++) cin >> a[i];
    sort(a, a+n, greater<ll>());
    for (int i=0;i<n-1;i++) ans += a[(i+1)/2];
    cout << ans << endl;
}


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

int calc(int x);
bool binary_search(const int *first, const int *last, int val);

vector<long long> a;

int n, m;

int main() {
    int ans = 0;

    cin >> n >> m;

    //a[0] = 0;
    if (m == 0) {
        a.push_back(0);
    } else {
    for (int i=0; i<m; i++) {
        int aa;
        cin >> aa;
        a.push_back(aa);
    }
    }

    ans = calc (n);
    cout << ans << endl;
}

bool binary_search(const int *first, const int *last, int val)
{
    if( first >= last )     // 範囲が空
        return false;     // 発見できなかった場合
    const int *ptr = first + (last - first) / 2;       // 中央位置へのポインタ、last = first + 1 の場合は、ptr = first となる
    if( *ptr == val )
        return true;        // 発見
    if( val < *ptr )     // 検索している要素は ptr よりも前にある場合
        return binary_search(first, ptr, val);
    else     // 検索している要素は ptr よりも後ろにある場合
        return binary_search(ptr + 1, last, val);
}

int calc(int x){
	long long dp[100001] = {0};
	dp[0] = 1;
	if (a[0] == 1) dp[1] = 1; else dp[1] = 2;
	for(int i = 2; i < x; i++){

        if (m == 0) {
            dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
        } else {
            if (binary_search(a.begin(), a.end(), i-1) == true && binary_search(a.begin(), a.end(), i) == true) {
                dp[i] = 0;
            } else if (binary_search(a.begin(), a.end(), i-1)) {
                dp[i] = dp[i-1] % 1000000007;
            } else if (binary_search(a.begin(), a.end(), i)) {
                dp[i] = dp[i-2] % 1000000007;
            } else {
		        dp[i] = (dp[i-1] + dp[i-2]) % 1000000007;
            }
        }
        // cout << dp[i] << endl;
	}
	return dp[x-1];
}

Measured memory_bytes: 1908
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long int


int main()
{
    ll i,j,n,sum=0,k;
    cin>>n;
    ll till_max=INT_MIN;
    cin>>k;
    n--;
    till_max=k;
    while(n--){
        cin>>k;
        if(k<till_max){
            sum+=till_max-k;
        }
        else{
            till_max=k;
        }
    }
    cout<<sum;
    
    
    //cout<<"YES"<<endl;
    //cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();
		if(p>q){
			if(p>r) System.out.println(q+r);
			else System.out.println(p+q);
		}else{
			if(q>r) System.out.println(p+r);
			else System.out.println(p+q);
		}
	}
}
				


Measured memory_bytes: 21972
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

const double pi = 4*atan(1);

int main(){
    int A,B, H, M;
    cin >> A >> B >> H >> M;
    double a = (H+M/60.0)/12.0*2*pi;
    double b = 2*pi*(M/60.0);
    double d = sqrt(A*A + B*B - 2*A*B*cos(a - b));    
    cout << setprecision(10) << d << endl;
}

Measured memory_bytes: 4160
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll a, b, c;
  cin >> a >> b >> c;
  if (a + b == c || a + c == b || b + c == a) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    int n;
    int[] as;

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

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        as = new int [n];
        for (int i = 0; i < n; i++) {
            as[i] = sc.nextInt();
        }
        solve();
    }

    void solve() {
        Arrays.sort(as);
        int turn = 0;
        int score = 0;
        for (int i = as.length - 1; i >= 0; i--) {
            if (turn++ % 2 == 0) {
                score += as[i];
            } else {
                score -= as[i];
            }
        }
        System.out.println(score);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  ll n, x;
  cin >> n >> x;
  V<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i - 1] + a[i] <= x) continue;
    ll diff = a[i - 1] + a[i] - x;
    ll eat = min(a[i], diff);
    ans += eat;
    a[i] -= eat;
  }
  if (a[0] > x) ans += a[0] - x;
  cout << ans << endl;
}


Measured memory_bytes: 4024
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

struct node {
  int v;
  int supply;
  int amari;
};

class MyComparison {
public:
  bool operator()(node n1, node n2) {
    return (n1.supply!=n2.supply)?(n1.supply>n2.supply):(n1.amari<n2.amari);
  }
};

int main() {
  long long X, K, D;
  std::cin >> X >> K >> D;
  long long ans;
  if (K<=-X/D) {
    ans = abs(X+K*D);
  } else if (K<=X/D) {
    ans = abs(X-K*D);
  } else if (X>=0){
    long long amari = X%D;
    long long sho = X/D;
    if (K%2==sho%2) {
      ans = abs(amari);
    } else {
      ans = abs(amari-D);
    }
  } else {
    long long amari = (-X)%D;
    long long sho = (-X)/D;
    if (K%2==sho%2) {
      ans = abs(amari);
    } else {
      ans = abs(amari-D);
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

ll ar[100005];
int main()
{
    _fastio
    ll n,cn=0;
    double x,y,d;
    cin>>n>>d;
    for1(i,n)
    {
        cin>>x>>y;
        double dis=sqrt((x*x)+(y*y));
        if(dis<=d)
            cn+=1;
    }
    cout<<cn<<en;
}


Measured memory_bytes: 3820
#include <stdio.h>
#include <inttypes.h>

int64_t koenai_saidai(int64_t start, int64_t limit, int64_t delta) {
	if (delta > 0) {
		return start + ((limit - start) / delta) * delta;
	} else {
		int64_t d = -delta;
		return start - ((start - limit) / d) * d;
	}
}

int main(void) {
	int T;
	int nakagawasyouko;
	if (scanf("%d", &T) != 1) return 1;
	for (nakagawasyouko = 0; nakagawasyouko < T; nakagawasyouko++) {
		int64_t A, B, C, D;
		if (scanf("%" SCNd64 "%" SCNd64 "%" SCNd64 "%" SCNd64, &A, &B, &C, &D) != 4) return 1;
		if (C < B - D || A < B || D < B) {
			puts("No");
		} else {
			int64_t right = B >= C ? B : C;
			int64_t ng_left = B - D - 1, ng_right = C + 1;
			/* 最初にBまたはCを切った時 */
			int64_t start = koenai_saidai(A, right, -B) - B;
			int64_t D_mod_B = D % B;
			if (ng_right <= start) {
				puts("No");
			} else if (D_mod_B == 0) {
				/* 着地位置が変わらない */
				puts(D_mod_B <= ng_left || ng_right <= D_mod_B ? "No" : "Yes");
			} else {
				int64_t zure = B % D_mod_B;
				int64_t diff, saidai;
				if (zure == 0) {
					diff = D_mod_B;
				} else {
					int64_t asumi = D_mod_B, iguti = zure;
					while (iguti > 0) {
						int64_t ogura = asumi % iguti;
						asumi = iguti;
						iguti = ogura;
					}
					diff = asumi;
				}
				saidai = koenai_saidai(start, right - 1, diff);
				if (ng_right <= saidai) {
					puts("No");
				} else {
					int64_t next = saidai + diff;
					int64_t next_next = next - B;
					puts(next_next <= ng_left ? "No" : "Yes");
				}
			}
		}
	}
	return 0;
}

/*

NGになる場合とは？

昼の時点でジュースがB本未満
・最初から足りない A<B
・補充判定に引っかからず足りない 在庫<B && 在庫>C
・補充しても足りない 在庫<=C && 在庫+D<B

パターン1 (右にNGエリアあり : C < B - 1)
     B-D    C     B
     |      |     |
xxxxxooooooooxxxxxoooooo

パターン2 (右にNGエリアなし : C <= B - 1)
     B-D    B     C
     |      |     |
xxxxxooooooooooooooooooo

パターン3 (絶望 : C < B - D (C + D < B))
     C      B-D   B
     |      |     |
xxxxxxxxxxxxxxxxxxoooooo

B本ずつ買っていく → Bの倍数を引く
最初にBまたはCを切った時注目！
この時、max(B,C)-B <= 在庫 < max(B,C) になっている
在庫がD増える → またBの倍数を引く → D mod B だけ足せばよい
パターン3のとき、死亡確定
パターン1のとき、max(B,C) = B
  D mod B を足していって、B以上になる直前に注目！
    Cを超えていたら、失格
    Cを超えていなかったら…？
パターン2のとき、max(B,C) = C
  D mod B を足していって、C以上になったらBを引く

パターン1・2共通
  Bを引くと、B mod (D mod B)だけ位相がずれる
  結局、gcd(D mod B, B mod (D mod B)) 個おきの列になる
  最初の着地位置から考えて、この列に引っかからなければ右のNGエリアはセーフ
  左のNGエリアは、この列で行けるmax(B,C)以上の最小の位置からB引いてチェック

*/


Measured memory_bytes: 1652
#include <stdio.h>
int main(void){
    // Your code here!
    int a,n,i,min=1000000,max=-1000000;
    long int sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        if(min>a){
            min=a;
        }
        if(max<a){
            max=a;
        }
        sum+=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
    
}


Measured memory_bytes: 2100
#include<bits/stdc++.h>
using namespace std;
int main(){
	char w[101];
	int num[26];
	for(int i = 0; i < 26; i++) num[i] = 0;
	scanf("%s", w);
	for(int i = 0; i < strlen(w); i++){
		num[w[i] - 'a']++;
	}
	for(int i = 0; i < 26; i++){
		if(num[i] % 2 != 0){
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int h[10],l[10],x1[15],x2[15];
int s[10][10];
void print()
{
    for(int i=0;i<8;i++)
        for(int j=0;j<8;j++)
    {
        if(s[i][j]&&h[i]!=j)
            return ;
    }
    for(int i=0;i<8;i++)
    {
        for(int j=0;j<8;j++)
        {
            printf("%c",h[i]==j?'Q':'.');
        }
        printf("\n");
    }
}
void dfs(int i)
{
    if(i==8)
    {
        print();
        return ;
    }
    for(int j=0;j<8;j++)
    {
        if(l[j]||x1[i+j]||x2[i-j+8])
            continue;
        h[i]=j;
        l[j]=x1[i+j]=x2[i-j+8]=1;
        dfs(i+1);
        h[i]=l[j]=x1[i+j]=x2[i-j+8]=0;
    }
}
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        memset(s,0,sizeof(s));
        memset(h,0,sizeof(h));
        memset(l,0,sizeof(l));
        memset(x1,0,sizeof(x1));
        memset(x2,0,sizeof(x2));
        int x,y;
        for(int i=1;i<=t;i++)
        {
            scanf("%d%d",&x,&y);
            s[x][y]=1;
        }
        dfs(0);
    }
}



Measured memory_bytes: 2128
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	string s;
	cin >> s;
	string ss = { s[0],s[1],s[2],s[3],s[4] };
	string tt = { s[6],s[7],s[8],s[9],s[10],s[11],s[12] };
	string rr = { s[14],s[15],s[16],s[17],s[18] };
	cout << ss << " " << tt << " " << rr << endl;
}



Measured memory_bytes: 256
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          string s = ReadLine();
          if(s[2] == s[3] && s[4] == s[5]){
             WriteLine("Yes");
             return;
          }
          WriteLine("No");
      }
   }
}

Measured memory_bytes: 11092
n = int(input())
s = list(map(int, input().split()))
q = int(input())
t = list(map(int, input().split()))
count = 0
for a in t:
    left = 0
    right = n
    while left < right:
        mid = (right + left) // 2
        if a == s[mid]:
            count += 1
            break
        elif a < s[mid]:
            right = mid
        else :
            left = mid + 1

print(count)



Measured memory_bytes: 16712
using System;

class Program
{

    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int k = int.Parse(str[1]);
        ulong res = 0;
        //Console.WriteLine("{0}, {1}", n, k);
        if (k % 2 == 0)
        {
            int kk = k / 2;
            int knum = n / k;
            int kknum = n / kk - knum;
            res = powi(knum, 3) + powi(kknum, 3);
        }
        else
        {
            int knum = n / k;
            res = powi(knum, 3);
        }
        Console.WriteLine("{0}", res);
    }

    static ulong powi(int x, int n)
    {
        ulong res = 1;
        for (int i = 0; i < n; i++)
        {
            res *= (ulong)x;
        }
        return res;
    }
}

Measured memory_bytes: 13268
# AtCoder Beginner Contest 145
# C - Average Length
# https://atcoder.jp/contests/abc145/tasks/abc145_c
import sys
from itertools import permutations
input = sys.stdin.readline
N = int(input())

A = [tuple(map(int, input().split())) for _ in [0]*N]

suml = 0
cnt = 0
for i in permutations(range(N)):
    length = 0
    x0, y0 = A[i[0]]
    for j in i[1:]:
        x1, y1 = A[j]
        length += ((x1-x0)**2+(y1-y0)**2)**0.5
        x0, y0 = x1, y1
    suml += length
    cnt += 1

print(suml/cnt)


Measured memory_bytes: 3064
import sys
from collections import deque

readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda: readline().rstrip() # input string
ni = lambda: int(readline().rstrip()) # input int
nm = lambda: map(int, readline().split()) # input multiple int 
nl = lambda: list(map(int, readline().split())) # input multiple int to list

s = ns()
counter = deque()
index = deque()
tmp = 'R'
cnt = 0
for i, c in enumerate(s):
    if c == tmp:
        cnt += 1
    else:
        counter.append(cnt)
        tmp = c
        cnt = 1
        if c == 'L':
            index.append(i-1)
counter.append(cnt)
index.append(10**6)

ans = []
sign = index.popleft()
done = False
for i in range(len(s)):
    if i == sign:
        sign = index.popleft()
        done = True
        r = counter.popleft()
        l = counter.popleft()
        ans.append(str((r+1)//2 + l//2))
        ans.append(str(r//2 + (l+1)//2))
    elif done:
        done = False
        continue
    else:
        ans.append('0')
print(' '.join(ans))


Measured memory_bytes: 10452
#include<stdio.h>

int main(void) {
  
  int N;
  scanf("%d", &N);
  int A[2][N];
  for (int i = 0; i < N; i++){
   scanf("%d", &A[0][i]);
  }
  for (int i = 0; i < N; i++){
    scanf("%d", &A[1][i]);
  }
  
  int candy = 0;
  
  for (int i = 0; i < N; i++){
    int rest1 = 0;
    int rest2 = 0;
    for(int j = 0; j <= i; j++){
      rest1 += A[0][j];
    }
    for(int j = i; j < N; j++){
      rest2 += A[1][j];
    }
    if (candy < rest1 + rest2){
      candy = rest1 +rest2;
    }
  }
  
  printf("%d", candy);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	ll n; cin >> n;
	ll mini = INF;
	for( ll i = 1; i*i <= n; ++i ){
		if( n%i == 0 ){
			ll candy = max(to_string(i).l_ength(), to_string(n/i).l_ength()); 
			mini = min(candy, mini);
		}
	}
	cout << mini << endl;
	return 0;
}

Measured memory_bytes: 256
int main()
{
    int num;
    int temp;
    int sum = 0;
    scanf("%d",&num);
    temp = num;
    while(num)
    {
        sum = sum*10 + num%10;
        num/=10;
    }
    if(temp == sum)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

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

using namespace std;

int main()
{
    vector<int> v;
    int a,b,c;
    cin >> a>>b>>c;
    for(int i = 1 ; i <=max(a,b); i++ )
    {
        if(a%i==0&&b%i==0)
        {
            v.push_back(i);
        }
    }
    sort(v.begin(), v.end() );
    reverse(v.begin(),v.end());
    cout << v[c-1];
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

struct edge{
	int to;
	ll cost;
};

vector<vector<edge>> graph(100100);
ll dist[100100];
bool visited[100100];

void dfs( int node, ll score ){
	visited[node] = true;
	dist[node] = score;
	for( auto e : graph[node] ){
		if( !visited[ e.to ] ){
			dfs( e.to, score+e.cost );
		}
	} 
}

int main(){
	int n; cin >> n;
	for( int i = 0; i < n-1; ++i ){
		int a, b; ll c; cin >> a >> b >> c;
		--a; --b;
		edge temp;
		temp.to = b; temp.cost = c; 
		graph[a].push_back(temp);
		temp.to = a;
		graph[b].push_back(temp);
	}
	int q, k; cin >> q >> k;
	--k;
	dfs( k, 0 );
	while( q-- ){
		int x, y; cin >> x >> y;
		--x; --y;
		// cout << dist[x] << " + " << dist[y] << " = " << dist[x]+dist[y] << endl;
		cout << dist[x]+dist[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 12800
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for( int i=a; i<b; i++)
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef vector<pii>vpi;

vvll A(1e5,vll (3));
vvll dp(1e5+1, vll(4));

ll rec(ll n,int ch){
    ll mx = -1;
    dp[0][0] = dp[0][1] = dp[0][2] = dp[0][3] = 0 ;
    for(ll i = 1;i<=n;i++){
        dp[i][0] = max(A[i-1][1]+dp[i-1][1],A[i-1][2]+dp[i-1][2]);
        dp[i][1] = max(A[i-1][0]+dp[i-1][0],A[i-1][2]+dp[i-1][2]);
        dp[i][2] = max(A[i-1][0]+dp[i-1][0],A[i-1][1]+dp[i-1][1]);
        dp[i][3] = max( max(A[i-1][0]+dp[i-1][0],A[i-1][1]+dp[i-1][1]), A[i-1][2]+dp[i-1][2]);
    }
    return dp[n][3];
}
void solve(){
    ll n;
    cin>>n;
    for(ll i =0;i<n;i++){
        cin>>A[i][0]>>A[i][1]>>A[i][2];
    }
    ll ans = rec(n,-1);
    cout<<ans<<"\n";
}
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    solve();
}

Measured memory_bytes: 15848
/* SmartCoder Apr 7, 2019 */
#include <bits/stdc++.h>
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end();i++)
#define present(c,x)  ( (c).find(x) !=(c).end())
#define cpresent(c,x) (find(all(c),x)!= (c).end() )
#define minei(x)  min_element(x.begin(),x.end())-(x).begin()
#define maxei(x)  max_element(x.begin(),x.end())-(x).begin()

#define uns(v)     sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define acusum(x)  accumulate(x.begin(),x.end(),0)
#define acumul(x)  accumulate(x.begin(),x.end(),1, multiplies<int>());
#define bits(x)     __builtin_popcount( x )
#define oo INT_MAX
#define inf 1000000000

const double pi = acos(-1.0);
const double eps = 1e-11;
#define MAXN 100007
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
void fastIO() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
ll W[MAXN], V[MAXN];
ll dp[2][MAXN];
void copyOver(int r) {
	for (int i = 0; i < MAXN; i++) {
		dp[r % 2][i] = dp[1 - (r % 2)][i];
	}
}
int main() {
	fastIO();
	int n, w;
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		cin >> W[i] >> V[i];
	}
	for (int i = 0; i <= w; i++) {
		dp[0][i] = dp[1][i] = -1;
	}
	dp[1][0] = 0;
	for (int i = 0; i < n; i++) {
		copyOver(i);
		for (int j = w; j >= 0; j--) {
			if (dp[i % 2][j] == -1 || W[i] + j > w)
				continue;
			if (dp[i % 2][j + W[i]] == -1)
				dp[i % 2][j + W[i]] = V[i] + dp[i % 2][j];
			else
				dp[i % 2][j + W[i]] = max(dp[i % 2][j + W[i]], V[i] + dp[i % 2][j]);
		}
	}
	ll res = -1;
	for (int i = 0; i <= w; i++) {
		res = max(res, dp[1 - (n % 2)][i]);
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N;
	string S;
	cin >>N >>S;
	string ansS;
	for (int n = 0; n < S.size(); ++n) {
		int num = S[n] - 'A';
		num += N;
		num %= 26; 
		ansS += 'A' + num;
	}
	cout << ansS <<endl;
	return 0;
}

Measured memory_bytes: 3672
<?php
    while(true){
        $num = explode(" ",trim(fgets(STDIN)));
        $a = $num[0];
        $op = $num[1];
        $b = $num[2];
        if($op == '+'){
    	    $ans = $a + $b;
        } elseif($op == '-' ){
    	    $ans = $a - $b;
        } elseif($op == '*'){
    	    $ans = $a * $b;
        } elseif($op == '/'){
    	    $ans = floor($a/$b);
        } else{
    	    break;
        }
        echo $ans .PHP_EOL;
    }

Measured memory_bytes: 15332
#include <iostream>
#include <queue>
using namespace std;
typedef pair<string,int> psi;
int main(void){
    int n,q,t=0;
    cin>>n>>q;
    queue<psi> p;
    for(int i=0;i<n;i++){
        string s;
        int j;
        cin>>s>>j;
        p.push(psi(s,j));
    }
    while(!p.empty()){
        psi pp=p.front();
        p.pop();
        if(pp.second<=q){
            t+=pp.second;
            cout<<pp.first<<' '<<t<<endl;
        }else {
            t+=q;
            p.push(psi(pp.first,pp.second-q));
        }
    }
    return 0;
}

Measured memory_bytes: 6292
#include <algorithm>
#include <climits>
#include <complex>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <vector>

// using
using namespace std;

// typedef
typedef long long ll;

// define
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REVERSE(c) reverse(ALL(c))
#define UNIQ(c) unique(ALL(c))
#define FOR(i, a, b, c) for (int i = (int)(a); i < (int)(b); i += (int)(c))
#define REP(i, n) FOR(i, 0, n, 1)
#define RFOR(i, a, b, c) for (int i = (int)(a); i >= (int)(b); i -= (int)(c))
#define RREP(i, n) RFOR(i, n, 0, 1)

// functions
int ceil(int a, int b) {
    return (a + b - 1) / b;
}
int round(int a, int b) {
    return (a + b / 2) / b;
}
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
template <class T> bool amax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> bool amin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}

// main
int main() {
    string s;
    cin >> s;
    int n = s.size();
    FOR(i, 0, n, 2) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pf(n) printf("%d\n",n)
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1001001001;
const double PI = acos(-1);

int main() {
	ll a, b;
	cin >> a >> b;

	if ((a + b) % 2 != 0) {
		cout << "IMPOSSIBLE\n";
	}
	else {
		cout << (a + b) / 2 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3596
package main

import "fmt"

func scanNums(nums_len int) []int {
	nums := make([]int, nums_len)
	var num int
	for i := 0; i < nums_len; i++ {
		fmt.Scan(&num)
		nums[i] = num
	}
	return nums
}

func main() {
	var n int
	fmt.Scan(&n)
	nums := scanNums(n)

	count := 0
	pos := 1
	for i := 0; i < n; i++ {
		pos = nums[pos-1]
		count++

		if pos == 2 {
			break
		}
	}

	if count == n {
		fmt.Println(-1)
	} else {
		fmt.Println(count)
	}
}


Measured memory_bytes: 5504
fun main() {
    val n = readLine()!!.toInt()
    var sum = 0
    for (i in (0 until n)) {
        val d = readLine()!!.split(" ")
        if (d[0] == d[1]) {
            sum++
            if (sum == 3) {
                println("Yes")
                return
            }
        } else {
            sum = 0
        }
    }
    println("No")
}

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

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,m,Q;
	cin >> n >> m >> Q;
	vector<int> l(m),r(m);
	vector<vector<int> > t(n+1);
	for(int i = 0; i < n+1; i++){
		t[i].resize(n+1);
		t[i].assign(t[i].size(),0);
	}
	for(int i = 0; i < m; i++){
		cin >> l[i] >> r[i];
		t[l[i]][r[i]]++;
	}

	for(int i = 0; i < n+1; i++){
		for(int j = 1; j < n+1; j++){
			t[i][j] += t[i][j-1];
		}
	}
	for(int i = 1; i < n+1; i++){
		for(int j = 0; j < n+1; j++){
			t[i][j] += t[i-1][j];
		}
	}

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

	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin >> N;
  unordered_map<long long, long long>mp;
  mp[0]++;
  long long pre = 0;
  for(int i = 0 ; i < N; ++i){
    int x; cin >> x;
    pre += x;
    mp[pre]++;
  }
  long long cnt = 0;
  for(auto&&e:mp)
    cnt += e.second*(e.second-1)/2;
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 8520
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
void solve(){
    int n, m;
    cin >> n >> m;
    set <int> s[15];
    
    for(int i = 1; i <= m; ++i) {
        int j, c;
        cin >> j >> c;
        s[j].ins(c);  
    }    
    for(int i = 1; i <= n; ++i) {
        if(s[i].size() > 1){
            cout << "-1";
            return;
        }
    }
    if(n > 1 && s[1].find(0) != s[1].end()){
        cout << "-1";
        return;
    }
    
    cout << ((s[1].size() == 0) ? ((n == 1) ? 0 : 1) : *s[1].begin());
    
    for(int i = 2; i <= n; ++i) {
        cout << ((s[i].size() == 0) ? 0 : *s[i].begin());
    }
}


 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 256
import sys



def check_number(p,numbers):
  for plis in p:
    if plis == numbers:
      return 1
  return 0


X,N = map(int,input().split())
p = list(map(int,input().split()))

if N == 0:
  print( X )
  sys.exit()


after_ans = X
i = 100


for i in range(X,X+100,1):#前半
  if check_number(p,i) == 0:
    after_ans = i
    after_abs = abs(X-i)
    break

for i in range(X,X-100,-1):#後半
  if check_number(p,i) == 0:
    before_ans = i
    before_abs = abs(X-i)
    break

if abs(after_abs) == abs(before_abs):
  answer = before_ans
elif abs(after_abs) > abs(before_abs):
  answer = before_ans
else:
  answer = after_ans

print( answer )


Measured memory_bytes: 62924
import numpy as np

S = input()
N = len(S)
ans = np.zeros(N, dtype=np.int)

j = 0
for i in range(0,N-1):
  if j != 0:
    j -= 1
  if j == 0:
    while S[i+j] == 'R':
      j += 1
  if j != 0:
    if j % 2 == 0:
      ans[i+j] += 1
    else:
      ans[i+j-1] += 1

j = 0
for i in range(N-1, 0, -1):
  if j != 0:
    j -= 1
  if j == 0:
    while S[i-j] == 'L':
      j += 1
  if j != 0:
    if j % 2 == 0:
      ans[i-j] += 1
    else:
      ans[i-j+1] += 1
print(*ans)

Measured memory_bytes: 31756
#include <iostream>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#define int long long
using namespace std;
signed main() {
	int a,b,c;
    cin>>a>>b>>c;

    cout<<a+b+c-max(a,max(b,c))<<endl;
}

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

#define int long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ff first
#define ss second
#define pb push_back

const int N = 1e5 + 5;
int n;
int a[5][N], cache[5][N];

int dp(int idx, int prev)
{
	if (idx == n + 1)
		return 0;
	int &ans = cache[prev][idx];
	if (ans != -1)
		return ans;
	for (int i = 1; i <= 3; i++)
	{
		if (i == prev)
			continue;
		ans = max(ans, a[i][idx] + dp(idx + 1, i));
	}
	return ans;
}

int32_t main()
{
	IOS;
	cin >> n;
	memset(cache, -1, sizeof(cache));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= 3; j++)
			cin >> a[j][i];
	}
	int ans = dp(1, 0);
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 15104
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln = '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    vector<ll> A(N+1);
    rep(i,N) cin >> A[i];

    ll val = 1000;
    ll cnt = 0;
    rep(i,N) {
        val += cnt*A[i];
        cnt = 0;
        if (i < N-1) {
            if (A[i] < A[i+1]) {
                cnt += val/A[i];
                val -= cnt*A[i];
            }
        }
    }

    cout << val << ln;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  int e;
  while(cin >> e && e){
    int m=1000000;
    for(int z=0; z*z*z<=e; ++z){
      for(int y=0; z*z*z+y*y<=e; ++y){
	int x = e-(z*z*z+y*y);
	m = min(m, x+y+z);
      }
    }
    cout << m << endl;
  }
  return 0;
}

Measured memory_bytes: 1156
import numpy as np
n,m,q = map(int,raw_input().split())

imos = [[0 for i in xrange(n)] for j in xrange(n)]

for i in xrange(m):
	f,t = map(int,raw_input().split())
	f -= 1
	t -= 1
	imos[f][t] += 1

for i in range(n-1,0,-1):
	for j in range(n):
		imos[i-1][j] = imos[i][j] + imos[i-1][j]

for i in xrange(n):
	imos[i] = np.cumsum(imos[i])

for i in xrange(q):
	a,b = map(int,raw_input().split())
	print imos[a-1][b-1]

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

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N, K; cin >> N >> K;
    int ans = 0;
    // vector<int> h(N);
    int h;
    rep(i, N) {
        cin >> h;
        if (h >= K) {
            ans += 1;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<29;
const ll LLINF = 1LL<<61;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string a,b,c;
  cin >> a >> b >> c;
  cout << (char)toupper(a[0]) << (char)toupper(b[0]) << (char)toupper(c[0]) << endl;
  
}

Measured memory_bytes: 256
mod=10**9+7
N=int(input())
M=1
y=[1 for k in range(N)]
for k in range(2,N+1):
    for j in range(2,k+1):
        if k%j ==0:
            count=0
            while k%j==0:
                k=k//j
                count+=1
            y[j-1]+=count
ans=1
for k in range(len(y)):
    ans=ans*y[k]%mod
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


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

	int n;
	cin >> n;
	int cnt = 0;
	rep(i, n) {
		int a;
		cin >> a;
		if (a & 1) cnt ^= 1;
	}
	cout << (cnt ? "NO":"YES") << endl;
}

Measured memory_bytes: 256