akhauriyash/Code-Regression huggingface dataset:
import java.util.Random;
import java.util.Scanner;

public class Main {
	private static final int K = 26;
	private static final int CHECK = 1000000;
	private static final int TIME = 1000;
	private static Random rand = new Random(System.currentTimeMillis());

	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var d = sc.nextInt();
		var c = new int[K];
		var s = new int[d][K];
		for (var i = 0; i < K; i++) {
			c[i] = sc.nextInt();
		}
		for (var i = 0; i < d; i++) {
			for (var j = 0; j < K; j++) {
				s[i][j] = sc.nextInt();
			}
		}
		sc.close();

		var t = search(c, s, d);
		for (var i = 0; i < d; i++) {
			System.out.println(t[i]);
		}
	}

	private static int[] search(int[] c, int[][] s, int d) {
		var time = System.currentTimeMillis();
		var count = 0;
		var countBk = 0;
		var t = create(c, s, d);
		for (var i = 0; count < CHECK; i++) {
			if (System.currentTimeMillis() - time > TIME) {
				break;
			}
			if (count - countBk > d * (K -1)) {
				break;
			}
			for (var j = 1; j < K; j++) {
				count++;
				var mdi = i % d;
				var mti = (t[mdi] + j - 1) % K;
				var check = check(c, s, t, d, mdi, mti);
				if (check > 0) {
					countBk = count;
					t[mdi] = mti + 1;
					//System.out.printf("%d %d %d %d\r\n", count, mdi + 1, t[mdi], score(c, s, t, d));
					break;
				}
			}
		}

		return t;
	}

	private static int check(int[] c, int[][] s, int[] t, int d, int mdi, int mti) {
		var sum = 0;
		var ti = t[mdi] - 1;
		sum += s[mdi][mti] - s[mdi][ti];

		var last1 = 0;
		var last2 = 0;
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == ti + 1) {
				last1 = i + 1;
				break;
			}
		}
		for (var i = mdi - 1; i >= 0; i--) {
			if (t[i] == mti + 1) {
				last2 = i + 1;
				break;
			}
		}

		var count1 = 1;
		var count2 = 1;
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == ti + 1) {
				break;
			}
			count1++;
		}
		for (var i = mdi + 1; i < d; i++) {
			if (t[i] == mti + 1) {
				break;
			}
			count2++;
		}
		sum += (mdi - last2 + 1) * c[mti] * count2 - (mdi - last1 + 1) * c[ti] * count1;

		return sum;
	}

	private static int score(int[] c, int[][] s, int[] t, int d) {
		var sum = 0;
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var ti = t[i] - 1;
			sum += s[i][ti];
			last[ti] = i + 1;
			for (var j = 0; j < K; j++) {
				sum -= ((i + 1) - last[j]) * c[j];
			}
		}

		return sum;
	}

	private static int[] create(int[] c, int[][] s, int d) {
		var t = new int[d];
		var last = new int[K];
		for (var i = 0; i < d; i++) {
			var v = new int[K];
			for (var j = 0; j < K; j++) {
				v[j] = s[i][j] + (((i + 1) - last[j]) * c[j]);
			}
			t[i] = rand(v) + 1;
			last[t[i] - 1] = i + 1;
		}
		return t;
	}

	private static int rand(int[] v) {
		var sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
		}
		var value = rand.nextInt(sum);
		var index = 0;
		sum = 0;
		for (var i = 0; i < v.length; i++) {
			sum += v[i];
			if (value < sum) {
				break;
			}
			index++;
		}
		return index;
	}
}

Measured memory_bytes: 46948
#include <bits/stdc++.h> 
using namespace std; 
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define flash ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ll long long
#define INF 1000000000
#define MOD 1000000007
#define pb push_back
#define ve vector<ll>
#define dos pair<ll,ll>
#define vedos vector<dos>
#define rand mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
struct greateri
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};
int main()
{
  //flash;
  ll a,b,c;
  cin>>a>>b>>c;
  ll ans1=0,ans2=0;
  ll dol = a;
  a-=min(c,a);
  c-=min(c,dol);
  b-=min(b,c);
  cout<<a<<" "<<b;
  return 0;
}
//code the AC sol !
// BS/queue/map


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;

#define N 1000007
ll s[N], t[N];

int main() {

    for(ll i=0; i<N; ++i) s[i] = t[i] = 10000000;
    s[0] = t[0] = 0;
    for(ll i=0; i<N; ++i) {
        ll j = 1;
        while(i + j*(j+1)*(j+2)/6 < N) {
            ll p = j*(j+1)*(j+2)/6;
            s[i+p] = min(s[i]+1, s[i+p]);
            if(p % 2 == 1) {
                t[i+p] = min(t[i]+1, t[i+p]);
            }
            ++j;
        }
    }

    int n;
    while(cin >> n && n) {
        cout << s[n] << " " << t[n] << endl;
    }

    return 0;
}

Measured memory_bytes: 18612
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

typedef long long ll;

int main()
{

    int a, b, c, d, e, f;
    vector<int> x, y;

    cin >> a >> b >> c >> d >> e >> f;

    REP(i, f + 1)
    {
        REP(j, f + 1)
        {
            if (100 * i * a + 100 * j * b <= f && 100 * i * a + 100 * j * b != 0)
            {
                x.push_back(100 * i * a + 100 * j * b);
                //cout << x.back() << endl;
            }
        }
    }

    REP(i, f + 1)
    {
        REP(j, f + 1)
        {
            if (i * c + j * d <= f)
            {
                y.push_back(i * c + j * d);
            }
        }
    }

    double maxRate = -1.0;
    int maxX = 0, maxY = 0;

    REP(i, x.size())
    {
        REP(j, y.size())
        {
            if (x[i] + y[j] <= f && 100.0 * (double)y[j] / (double)x[i] <= (double)e)
            {
                if (maxRate < (double)y[j] * 100.0 / ((double)x[i] + (double)y[j]))
                {
                    maxRate = (double)y[j] * 100.0 / ((double)x[i] + (double)y[j]);
                    maxX = x[i];
                    maxY = y[j];
                    //cout << maxY + maxX << endl;
                    //cout << maxRate << endl;
                }
            }
        }
    }

    cout << maxX + maxY << " " << maxY << endl;

    return 0;
}

Measured memory_bytes: 1400
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    L=I()
    power = 1
    N = 1
    while power<<1 <= L:
        power<<=1
        N+=1
    
    ans = []
    for i in range(N-1):
        ans.append((i+1,i+2,0))
        ans.append((i+1,i+2,1<<i))
    for i in range(N-1)[::-1]:
        X=L-(1<<i)
        if(X>=power): #X<(1<<N)ならダブる
            ans.append((i+1,N,X))
            L-=1<<i
    M=len(ans)
    print(N,M)
    for a in ans:
        print(*a)
if __name__ == '__main__':
    main()

Measured memory_bytes: 5460
from collections import defaultdict

n = int(input())
mod = 10**9 + 7
DP = [defaultdict(int) for _ in range(n+1)]
DP[0]['TTT'] = 1

for length in range(n):
    for seq, count in DP[length].items():

        if seq[1:] in ['AG', 'GA'] or seq[:2] == 'AG' or seq[0]+seq[2] == 'AG':
            for ns in 'AGT':
                new_seq = seq[1:] + ns
                DP[length+1][new_seq] += count
                DP[length + 1][new_seq] %= mod

        elif seq[1:] == 'AC':
            for ns in 'ACT':
                new_seq = seq[1:] + ns
                DP[length + 1][new_seq] += count
                DP[length + 1][new_seq] %= mod

        else:
            for ns in 'ACGT':
                new_seq = seq[1:] + ns
                DP[length + 1][new_seq] += count
                DP[length + 1][new_seq] %= mod

ans = sum(DP[n].values()) % mod
print(ans)

Measured memory_bytes: 4084
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

template <typename T>
struct Edge {
    int from, to;
    T cost;
    Edge(int s, T d) : to(s), cost(d) {}
    Edge(int f, int s, T d) : from(f), to(s), cost(d) {}

    bool operator<(const Edge &e) const {
        return cost < e.cost;
    }
    bool operator>(const Edge &e) const {
        return cost > e.cost;
    }
};
#define Graph(type) vector< vector< Edge<type> > >

// ????°???¨?????¨(??????)
// Verified: AOJ GRL_2_A: Minimum Spanning Tree
template <typename T>
T prim(vector< vector< Edge<T> > > &G) {
    int V = G.size(); T ans = 0;
    vector<bool> used(V, false);
    priority_queue< Edge<T>, vector< Edge<T> >, greater< Edge<T> > > q;
    q.push(Edge<T>(0, 0, 0));
    while(!q.empty()) {
        Edge<T> temp = q.top(); q.pop();
        if(used[temp.to]) continue;
        used[temp.to] = true;
        ans += temp.cost;

        rep(i,0,G[temp.to].size()) q.push(G[temp.to][i]);
    }
    return ans;
}

int main() {
    int n, m;
    while(cin >> n) {
      if(n == 0) break;
      cin >> m;
      Graph(int) g(n);
      int a,b,d;
      rep(i,0,m) {
        scanf("%d,%d,%d", &a, &b, &d);
        d = d / 100 - 1;
        g[a].pb(Edge<int>(a,b,d));
        g[b].pb(Edge<int>(b,a,d));
      }
      int ret = prim(g);
      cout << ret << endl;
    }
    return 0;
}

Measured memory_bytes: 3408
//======================================================================
// Contents    : AOJ ITP1_6_D
//               行列 A と 列ベクトル c の積を出力
// Input       : 行 n、列 m
//               行列 A の要素 a
//               ベクトル b の要素 b
// Output      : ベクトル c の要素 c
// Constraints : 1 ≤ n,m ≤ 100
//               0 ≤ b,a ≤ 1000
// Author      : 廣部智也
// LastUpdate  : 2020/06/28
// Since       : 2020/06/28
//======================================================================

#include <stdio.h>
#include <stdlib.h>                                                       // exit 関数を使用するため

#define LOWER_LIMIT_n_m    1
#define UPPER_LIMIT_n_m  100
#define LOWER_LIMIT_a_b    0
#define UPPER_LIMIT_a_b 1000

// 入力エラーを判断する関数
int Input_error( int number, int lower_limit, int upper_limit );



int main(){

    int n = 0, m = 0, a[100][100] = {}, b[100] = {};
    int c[100] = {};

    int i = 0, j = 0;

    // データの入力：カードの所持数
    scanf("%d %d", &n, &m );
    
    Input_error( n , LOWER_LIMIT_n_m, UPPER_LIMIT_n_m );
    Input_error( m , LOWER_LIMIT_n_m, UPPER_LIMIT_n_m );

    for ( i = 0; i < n; ++i ) {
        for ( j = 0; j < m; ++j ) {
            scanf("%d", &a[i][j] );
            Input_error( a[i][j] , LOWER_LIMIT_a_b, UPPER_LIMIT_a_b );
        }
    }
    
    for ( j = 0; j < m; ++j ) {
        scanf("%d", &b[j] );
        Input_error( b[j] , LOWER_LIMIT_a_b, UPPER_LIMIT_a_b );
    }

    // データの処理と出力
    for ( i = 0; i < n; ++i ) {
        for ( j = 0; j < m; ++j ) {
            c[i] = c[i] + a[i][j] * b[j];
        }

        printf("%d\n", c[i] );
    }

    return 0;
}



//============================================================
// Contents    : 入力エラーを判断
// Input       : 調べる変数, 下限, 上限
// Output      : エラーなら強制終了
// Author      : 廣部智也
// LastUpdate  : 2020/06/05
// Since       : 2020/06/05
//============================================================

int Input_error( int number, int lower_limit, int upper_limit ){
    
    if( number < lower_limit || number > upper_limit ){
        printf("Input error\n");
        exit(1);
    }

    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdint>
using namespace std;

int main() {
    uint32_t n; cin >> n;
    vector<uint32_t> a(n);
    for (auto &e : a) cin >> e;
    sort(a.begin(), a.end());

    if ((n & 1) && a[0] != 0) {
        cout << 0 << endl;
        return 0;
    }

    uint64_t ans = 1;
    for (auto i = a.begin() + (n & 1); i != a.end(); i += 2, ans = (ans * 2) % 1000000007) {
        if ((*i == 0 || *(i + 1) == 0) || *i != *(i + 1)) {
            cout << 0 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3760
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    private static Scanner in;

    private static int n;
    private static int[] a;
    private static int[] b;
    private static int[] c;
    private static int[][] mem;
    
	public static void main(String[] args) {
        in = new Scanner(System.in);
        n = in.nextInt();
        a = new int[n];
        b = new int[n];
        c = new int[n];

        for(int i=0; i<n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
            c[i] = in.nextInt();
        }

        mem = new int[n][4];

        for(int i=0; i<n; i++) Arrays.fill(mem[i], -1);

        System.out.println(solve(0, -1));
	}

    public static int solve(int i, int prev) {
        if (i==n) return 0;

        if (mem[i][prev+1]!=-1) return mem[i][prev+1];

        int ans = 0;

        if (prev!=0) {
            ans = Math.max(ans, a[i]+solve(i+1, 0));
        }
        if (prev!=1) {
            ans = Math.max(ans, b[i]+solve(i+1, 1));
        }
        if (prev!=2) {
            ans = Math.max(ans, c[i]+solve(i+1, 2));
        }

        return mem[i][prev+1] = ans;
    }

}


Measured memory_bytes: 104288
#include <bits/stdc++.h>
#define ll long long
using namespace std;
constexpr int MOD = 1e9 + 7;
ll pow1(ll n, ll p){
    ll cur, res;
    cur = n;
    res = 1;
    while(p){
        if(p & 1){
            res *= cur;
            res %= MOD;
        }
        p /= 2;
        cur *= cur;
        cur %= MOD;
    }
    return res;
}
ll fact[1000001];
ll inv[1000001];
ll K[1000001];
ll cnk(int n, int k){
    if(n < k)return 0;
    return fact[n] * inv[k] % MOD * inv[n-k] % MOD;
}
int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    fact[0] = inv[0] = 1;
    for(int i = 1;i < 1000001;i++)
        fact[i] = fact[i-1] * i % MOD, inv[i] = pow1(fact[i], MOD - 2);
    int n;
    cin >> n;
//    cout << fact[10000] * inv[9999] % MOD << endl;
    for(int i = 1;i < n;i++){
        K[i] = cnk(i-1, n - i - 1) * fact[i] % MOD * fact[n-1-i] % MOD;
    }
    ll cum = 0;
    ll res = 0;
//    cout << K[5] - K[4] << endl;
    for(int i = 1;i < n;i++){
        res += (K[i] - K[i-1]) * i % MOD;
        cum += K[i];
        cum %= MOD;
        res %= MOD;
    }
    if(res < 0)res += MOD;
    cout << res;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
typedef complex<double> xy_t;

double dot(xy_t a, xy_t b){
    return (conj(a) * b).real();
}

int main(){
    int n;
    scanf("%d", &n);
    xy_t p[n];
    rep(i, n){
        double x, y;
        scanf("%lf%lf", &x, &y);
        p[i] = xy_t(x, y);
    }
    
    double ans = 0;
    rep(t, 100000){
        xy_t a = xy_t(cos(t), sin(t));
        xy_t z = xy_t(0, 0);
        rep(i, n)if(dot(a, p[i]) >= 0){
            z += p[i];
        }
        ans = max(ans, abs(z));
    }
    
    printf("%.12lf\n", ans);
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n;
  cin>>n;
  vll b(n),a(n);
  rep(i,n){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(all(a));
  map<ll,ll> p;
  rep(i,n){
    p[a[i]]=i%2;
  }
  ll ans=0;
  ll cu=0;
  rep(i,n){
    if(i%2==0&&p[b[i]]!=0){
      cu++;
    }
  }
  COUT(cu);
}

Measured memory_bytes: 8064
import sys


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, K = map(int, input().split())
    if K % 2 == 1:
        a = N // K
        print(a * a * a)
        exit()
    else:
        a = N // K
        count = a * a * a
        b = (N+K//2)//K
        count+=b*b*b
        print(count)



if __name__ == "__main__":
    main()


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

int asc(const void *a, const void *b){
    long *A = (long *)a;
    long *B = (long *)b;
    if(*A > *B)
        return 1;
    if(*A < *B)
        return -1;
    return 0;
}

int main(){
    int N, i, cnt=1, ans=0;
    long int a[100010];

    scanf("%d", &N);
    for(i=0; i<N; i++){
        scanf("%ld", &a[i]);
    }

    qsort(a, N, sizeof(long int), asc);
    a[N+1]=0;
    for(i=0; i<N; i++){
        if(a[i+1] == a[i]){
            cnt++;
        }else if(cnt%2==1){
            	ans++;
              cnt=1;
        }else{
          cnt=1;
        }
    }

    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
int N;
  cin>>N;
  vector<int>T(N);
  for(int i=0;i<N;i++)
    cin>>T.at(i);
  int sum=0;
  for(int i=0;i<N;i++)
    sum+=T.at(i);
  int M;
  cin>>M;
  vector<pair<int,int>>P(M);
  for(int i=0;i<M;i++){
    int p,x;
    cin>>p>>x;
    P.at(i)=make_pair(p-1,x);
  
  }for(int i=0;i<M;i++){
  int a=P.at(i).first;
    int b=P.at(i).second;
    int ans=sum+b-T.at(a);
    cout<<ans<<endl;
  
  
  }
   return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include<cstdlib>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int top,s[101];
int pop(){
  top--;
  return s[top+1];
}
void push(int a){
  s[++top] = a;
  //cout<<a<<endl;
}
int main(){
  char temp[100]={};
  int a,b;
  while(cin>>temp){
    if(temp[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(temp[0]=='-'){
      a=pop();
      b=pop();
      push(b-a);
      //cout<<a<<"-"<<b<<endl;
    }
    else if(temp[0]=='*')
      push(pop()*pop());
    else {
      push(atoi(temp));
      //cout<<temp<<endl;
    }
  }
  cout<<pop()<<endl;
  return 0;
}



Measured memory_bytes: 3100
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 256
#!usr/bin/env python3
import sys
import math
import string
import collections
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

sys.setrecursionlimit(10 ** 8)

A, B, C = map(int, input().split())
Sum = 0
for i in range(1, 10**9):
    Sum += A
    if i%7 == 0:
        Sum += B
    if Sum >= C:
        print(i)
        sys.exit()


Measured memory_bytes: 8928
/*Author SHUBH AGRAWAL  */

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
//a power n mod p

#define vl  vector<long long int >
#define vpl vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 

long long int modp(lld a,lld p,lld n)
{
    int d[100];
    int i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

long long int nCrModPFermat(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
    
    // Fill factorial array so that we 
    // can find all factorial of r, n 
    // and n-r 
    lld fac[n+1]; 
    fac[0] = 1; 
    for (lld i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}


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


lld l,r,mid,ans;
lld n,m,i,j,k,x;


char c;
void solve()
{
    cin>>n;
    ans=(n/500)*1000;
    n-=(n/500)*500;
    ans+=(n/5)*5;
    cout<<ans;
 //   cout<<"\n";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;


int main(){
    int t=1;
    //cin>>t;
    while(t--){
        ll n;
        cin>>n;
        vector<ll> a(n+1,0);
        ll x;
        for(int i=0;i<n-1;i++){
            cin>>x;
            a[x]++;
        }
        for(int i=1;i<=n;i++){
            cout<<a[i]<<endl;
        }
    }
    return 0;
}
    

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

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}

signed main() {
	int a, p;
	cin >> a >> p;
	int x = a * 3 + p;
	cout << x / 2 << endl;

	return 0;
}


Measured memory_bytes: 256
n, m = gets.split.map(&:to_i)
s = gets.chomp
t = gets.chomp

ans = n.lcm(m)
g = n.gcd(m)

g.times do |i|
  l = s[i * n / g]
  r = t[i * m / g]
  next if l == r

  ans = -1
  break
end

puts ans


Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) < (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n) - 1; (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;
#define all(x) (x).begin(),(x).end()

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

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

ll fac(ll n){
    ll t = 1;
    rep1(i, n + 1)t *= i;
    return t;
}

int main()
{
    ll n,ans  = 0,cnt = 1;
    cin >> n;
    vector<ll> a(n);
    rep0(i, n)cin >> a[i];
    sort(all(a));
    a.push_back(0);
    rep0(i, n){
        if (a[i] != a[i + 1]) {
            if (a[i] < cnt) {
                ans += (cnt - a[i]);
            }else if (a[i] > cnt){
                ans += cnt;
            }
            cnt = 1;
        }else{
            ++cnt;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

vector<vector<int> > to;
vector<int> ans;

void dfs(int v, int p = -1) {
  for (int u : to[v]) {
    if (u == p) continue;
    ans[u] += ans[v];
    dfs(u, v);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  to.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  ans.resize(n);
  for (int i = 0; i < q; i++) {
    int p, x;
    cin >> p >> x;
    --p;
    ans[p] += x;
  }
  dfs(0);
  for (int i = 0; i < n; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 23552
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
S=get_nsp
T=get_nsp
S.each_with_index do|c,i|
    if c==T[0]
      flag=true
      (i+1).upto(N-1) do|j|
          unless S[j]==T[j-i]
              flag=false
              break
          end
      end 
      if flag
        puts i*2+(N-i)
        exit
      end
    end
end
puts N*2

Measured memory_bytes: 14288
def main():
    X=int(input())
    if 400<=X<=599:
        print(8)
    elif 600<=X<=799:
        print(7)
    elif 800 <= X <= 999:
        print(6)
    elif 1000 <= X <= 1199:
        print(5)
    elif 1200 <= X <= 1399:
        print(4)
    elif 1400 <= X <= 1599:
        print(3)
    elif 1600 <= X <= 1799:
        print(2)
    elif 1800 <= X <= 1999:
        print(1)


if __name__=="__main__":
    main()

Measured memory_bytes: 61736
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define dunk(a) cout << (a) << endl
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main() {
	int n; cin >> n;
	string s; cin >> s;
	int t = s.size();

	rep(i, t) {
		s[i] = s[i] + n;
		if (s[i] > 90) s[i] -= 26;
	}

	dunk(s);
	return 0;
}


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

using namespace std;

#define int long long

#define rep(i,x) for(int i=0;i<x;++i)
#define all(x) begin(x),end(x)

int n, m, h, k;
int s[1010];
int root[1010][1010], rt;
bool f[1010][1010];
int res[1010][1010];

int rec(int cur, int H)
{
    if (H == h) return cur;

    root[cur][H] = rt;

    if (cur - 1 >= 0) if (f[cur - 1][H]) return res[cur][H] = rec(cur - 1, H + 1);
    if (cur + 1 < n) if (f[cur][H]) return res[cur][H] = rec(cur + 1, H + 1);

    return res[cur][H] = rec(cur, H + 1);
}

signed main()
{
    while (cin >> n >> m >> h >> k, n) {
        memset(f, 0, sizeof(f));

        rep(i, n) {
            cin >> s[i];
        }

        vector<pair<int,int>> vp;

        rep(i, m) {
            int a, b; cin >> a >> b;
            --a, b;
            f[a][b] = true;
            vp.push_back(make_pair(a, b));
        }

        rep(i, n) {
            rt = i;
            rec(i, 1);
        }

        int sum = 0;
        rep(i, k) sum += s[res[i][1]];
        int mi = sum;

        rep(i, m) {
            auto dat = vp[i];
            int num = dat.first, height = dat.second;

            int ans = sum;

            if (root[num][height] < k) {
                ans += s[res[num+1][height]];
                ans -= s[res[num][height]];
            }

            if (root[num+1][height] < k) {
                ans += s[res[num][height]];
                ans -= s[res[num+1][height]];
            }

            mi = min(mi, ans);

            //cout << "ans = " << ans << endl;
        }

        cout << mi << endl;
    }
}

Measured memory_bytes: 21184
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>

using namespace std;

typedef long long ll;

int main() {
	ll N;
	cin >> N;
	
	vector<int> soinsu;
	for (ll i = 2; i * i <= N; i++) {
		int cnt = 0;
		while (N % i == 0)N /= i, cnt++;
		if (cnt != 0)soinsu.push_back(cnt);
	}
	if (N != 1)soinsu.push_back(1);

	int ans = 0;
	for (int i = 0; i < soinsu.size(); i++) {
		ans += (int)((-1 + sqrt(1 + 8 * soinsu[i])) / 2);
	}
	cout << ans << endl;
 	return 0;
}

Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }     //最小公倍数
using Graph = vector<vector<ll>>;
ll inf=300000000000000000;
const double PI = 3.14159265358979323846;
int main(){
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i]=='?')s[i]='D';
  }
  cout << s << endl;
}  


Measured memory_bytes: 3752
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

X, K, D = MI()

if X < 0:
    X *= -1

if X - K * D <= 0:
    if (K - X // D) % 2 == 0:
        X = X % D
    else:
        X = min(abs(X % D - D), abs(X % D + D))
else:
    X -= K * D
        
print(X)

Measured memory_bytes: 61856
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  long long A,ans = 1;
  bool can = true;
  bool zero = false;
  for(int i=0;i<N;i++){    
    cin >> A;
    if(A==0){
      zero = true;
      break;
    }
//    cout << pow(10,18) << " / " << ans << " = " << pow(10,18)/ans << " vs " << A << endl;    
//    cout << 1000000000000000000 << " / " << ans << " = " << 1000000000000000000/ans << " vs " << A << endl;    
//    if(A <= pow(10,18)/ans){
    if(A <= 1000000000000000000/ans){
      ans *= A;
    }else{
      can = false;
//      break;
    }
  }
  
  if(zero) cout << 0 << endl;
  else if(can) cout << ans << endl;
  else cout << -1 << endl;
}

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

typedef long long i64;

const int NMAX = 1e5 + 5;
const char sp[] = {'W', 'S'};

int n;
char rel[NMAX], ant[NMAX];

inline int st(const int &x) {
    if (x == 1) return n;
    return x - 1; }

inline int dr(const int &x) {
    if (x == n) return 1;
    return x + 1; }

bool check() {
    char rem = ant[n];

    for (int i = 1; i < n; ++i)
        if (ant[i] == 'S') {
            if (ant[st(i)] == 'W') {
                if (rel[i] == 'o')
                    ant[dr(i)] = 'W';
                else
                    ant[dr(i)] = 'S'; }
            if (ant[st(i)] == 'S') {
                if (rel[i] == 'o')
                    ant[dr(i)] = 'S';
                else
                    ant[dr(i)] = 'W'; } }
        else {
            if (ant[st(i)] == 'W') {
                if (rel[i] == 'o')
                    ant[dr(i)] = 'S';
                else
                    ant[dr(i)] = 'W'; }
            if (ant[st(i)] == 'S') {
                if (rel[i] == 'o')
                    ant[dr(i)] = 'W';
                else
                    ant[dr(i)] = 'S'; } }

    if (ant[n] == 'W') {
        if (rel[n] == 'o') {
            if (ant[st(n)] == ant[dr(n)])
                return false; }
        else if (ant[st(n)] != ant[dr(n)])
            return false; }
    if (ant[n] == 'S') {
        if (rel[n] == 'o') {
            if (ant[st(n)] != ant[dr(n)])
                return false; }
        else if (ant[st(n)] == ant[dr(n)])
            return false; }

    return rem == ant[n]; }

int main() {
    //freopen("dat.in", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);


    cin >> n;
    cin >> (rel + 1);

    for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
        ant[1] = sp[i];
        ant[n] = sp[j];
        if (check()) {
            cout << (ant + 1) << '\n';
            exit(0); } } }

    cout << "-1\n";

    return 0; }


Measured memory_bytes: 512
from itertools import combinations_with_replacement


def main():
    N, M, Q = map(int, input().split())
    conds = [list(map(int, input().split())) for i in range(Q)]
    combs = combinations_with_replacement([i for i in range(1, M+1)], N)
    ans = 0
    for comb in combs:
        ans_ = 0
        for c in conds:
            if comb[c[1]-1] - comb[c[0]-1] == c[2]:
                ans_ += c[3]
        ans = max(ans, ans_)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9124
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var tempArray = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

        var N = tempArray[0];
        var K = tempArray[1];
        var Q = tempArray[2];

        var memberPoints = new List<int>();

        for(var i = 0; i < N; i++)
        {
            memberPoints.Add(K - Q);
        }

        for(var i = 0; i < Q; i++)
        {
            var A = int.Parse(Console.ReadLine());

            memberPoints[A - 1]++;
        }

        for (var i = 0; i < N; i++)
        {
            if (memberPoints[i] > 0)
            {
                Console.WriteLine("Yes");
            }
            else if (memberPoints[i] <= 0)
            {
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 18652
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    vector<int> a(7);
    rep(i, 7) cin >> a[i];
    ll ans = 0;
    ans += a[0] / 2 * 2;    
    ans += a[1];
    ans += a[3] / 2 * 2;
    ans += a[4] / 2 * 2;
    int cnt = 0;
    cnt += a[0]%2 + a[3]%2 + a[4]%2;
    if (cnt == 3) {
        ans += 3;
    } else if (cnt == 2) {
        if (a[0]%2 == 0 && a[0] != 0) ans++;
        else if (a[3]%2 == 0 && a[3] != 0) ans++;
        else if (a[4]%2 == 0 && a[4] != 0) ans++;
    }
    cout << ans << endl;
}


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

// Loops
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define _rrep(i, n) rrepi(i, n, 0)
#define rrepi(i, a, b) for (int i = int(a) - 1; i >= int(b); --i)

#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__, rrepi, _rrep, )(__VA_ARGS__)
#define each(xi, x) for (auto &&xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)

// typedef
template <class T> using vec = vector<T>;
using ll = long long;
using vi = vec<ll>;
using vvi = vec<vi>;
using vvvi = vec<vvi>;
using pii = pair<ll, ll>;

// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define mp make_pair

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase(unique(all(v)), v.end())
#define perm(c)                                                                \
  sort(all(c));                                                                \
  for (bool c##p = 1; c##p; c##p = next_permutation(all(c)))

template <class T> pair<T, size_t> max(vector<T> &x) {
  auto it = max_element(all(x));
  return mp(*it, it - x.begin());
}
template <class T> pair<T, size_t> min(vector<T> &x) {
  auto it = min_element(all(x));
  return mp(*it, it - x.begin());
}

template <class T> inline bool chmax(T &maxval, const T &newval) {
  if (maxval < newval) {
    maxval = newval;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &minval, const T &newval) {
  if (minval > newval) {
    minval = newval;
    return 1;
  }
  return 0;
}

// Utilities
// Grid world utilities
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
#define inside(H, W, y, x) 0 <= (x) && (x) < (W) && 0 <= (y) && (y) < (H)

// Debug
#ifdef LOCAL
#include "dump.hpp"
#define debug(x) cerr << #x << ": " << x << '\n'
#else
#define dump(...)
#define debug(x)
#endif

// Paste snippets here!!

//

void solve(std::string C) {
  cout << (char)(C[0]+1) << endl;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); // Magic for faster cin
  std::string C;
  std::cin >> C;
  solve(C);
  return 0;
}


Measured memory_bytes: 3652
import sys

input = sys.stdin.readline
n,m = map(int,input().split())
from collections import defaultdict
dic = defaultdict(list)

for _ in range(m):
    u,v = map(int,input().split())
    dic[u-1].append(v-1+n)
    dic[u - 1+n].append(v - 1 + 2*n)
    dic[u - 1+2*n].append(v - 1)

G = dic
s,t = map(int,input().split())

# G[v]: 頂点vに隣接する頂点list
# N: 頂点数

from collections import deque
dist = [-1]*(n*3)
que = deque([s-1])
dist[s-1] = 0
while que:
    v = que.popleft()
    d = dist[v]
    for w in G[v]:
        if dist[w] > -1:
            continue
        dist[w] = d + 1
        que.append(w)
print(dist[t-1]//3)



Measured memory_bytes: 79644
#include<bits/stdc++.h>
using namespace std;
int h,w,k;
string s[12];
int main(){
	//freopen("input.txt","r",stdin);
	int coun=0;
	cin>>h>>w>>k;
	for(int i=0;i<h;i++){
		cin>>s[i];
	}
	//特判
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) if(s[i][j]=='1') coun++;
	 if(coun<=k) cout<<0<<endl;
	else{
		int ans=1e9;
	for(int u=1;u<(1<<(h-1));u++){
		int x=__builtin_popcount(u);
		int cut_num=x;
		int block[x+1]={0};
		int p=0;
		int mx=0;
		bool flag=true;
		for(int j=0;j<w;j++){
			for(int i=0;i<h;i++){
				block[p]+=s[i][j]-'0';
				mx=max(mx,block[p]);
				if(u>>i&1) p++;
			}
			//mx=max(mx,block[p]);
			if(mx>k) {
				if(j==0) { flag=false;break;
				}
				cut_num++;
				mx=0;
				memset(block,0,sizeof(block));
				p=0;
				for(int i=0;i<h;i++){
				block[p]+=s[i][j]-'0';
				mx=max(mx,block[p]);
				if(u>>i&1) p++;
			}
			}
			p=0;
		}
		if(flag) ans=min(ans,cut_num);
	}
	cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define _GLIBCXX_DEBUG // ArrayOutofBounds
#define rep(i, N) for (int i = 0; i < N; i++) //制御変数iを用いてN回転
using namespace std;
using ll = long long;

int main() {
    int count = 0, ans = 0;
    string S;
    cin >> S;
    rep(i, 3) {
        if (count > 0 && S[i] == 'S') {
            ans = max(ans, count);
            count = 0;
        } else if (S[i] == 'R') count++;
    }
    ans = max(ans, count);
    cout << ans << endl;
    return 0;
}

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

const int L = 1e6 + 1;
vector<int> cnt(L);

void solve() {
    // INPUT
    int n; cin >> n;
    fill(cnt.begin(), cnt.end(), 0);
    int cp = 0;
    for (int i = 0; i < n; ++i) { 
        int a;
        cin >> a;
        cnt[a]++;
        cp = __gcd(cp, a);
    }

    bool pairwise = true;
    for (int i = L; i >= 2; --i) {
        int tmp = 0;
        for (int j = i; j <= L; j += i) {
            tmp += cnt[j];
        }
        if (tmp > 1) {
            pairwise = false;
            break;
        }
    }

    if (pairwise) cout << "pairwise coprime\n";
    else if (cp == 1) cout << "setwise coprime\n";
    else cout << "not coprime\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    while(t--) {
        solve();
    }
}


Measured memory_bytes: 7072
from math import sqrt,factorial
from itertools import permutations
N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]
perm = permutations(range(N),N)
tmp = 0
for p in perm:
    for i in range(1,N):
        tmp += sqrt((xy[p[i]][0] - xy[p[i-1]][0])**2 + (xy[p[i]][1] - xy[p[i-1]][1])**2)
print(tmp/factorial(N))

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

int main(){
  int r,c;
  cin>>r>>c;

  int num[101][101] = {};
  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) cin>>num[i][j];

  for(int i=0;i<r;i++)
    for(int j=0;j<c;j++) num[r][c] += num[i][j];

  for(int i=0;i<r;i++){
    int sum = 0;
    for (int j=0;j<c;j++) sum += num[i][j];
    num[i][c] = sum;
  }

  for(int j=0;j<c;j++){
    int sum = 0;
    for(int i=0;i<r;i++) sum += num[i][j];
    num[r][j] = sum;
  }

  for (int i=0;i<=r;i++){
    for(int j=0;j<=c;j++){
      if(j) cout<<" ";
      cout<<num[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3148
#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 A,B,K;
cin>>A>>B>>K;
ll dd =K-A;
A = A-K;
if(A<=0){
  A=0;
}


if(dd>0){
  B = B-dd;
  if(B<=0){
    B=0;
  }
}

cout<<A<<" "<<B<<endl;
  return 0;
}


Measured memory_bytes: 256
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        let _ = io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line()
            .split_whitespace()
            .map(|s| s.to_string())
            .collect()
    }

    #[allow(dead_code)]
    pub struct Reader {
        buf: VecDeque<String>,
    }

    #[allow(dead_code)]
    impl Reader {
        pub fn new() -> Reader {
            Reader { buf: VecDeque::new() }
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T
            where
                T: FromStr,
                T::Err: Debug,
        {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn next_n<T>(&mut self, n: usize) -> Vec<T>
            where
                T: FromStr,
                T::Err: Debug,
        {
            let mut vec: Vec<T> = Vec::with_capacity(n);

            for _ in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

#[allow(unused_macros)]
macro_rules! p {
    ([$($x:expr), *]) => {{
        let mut f = true;
        $(
            print!("{}{}", if f {""} else {" "}, $x);
            f = false;
        )*
        print!("\n");
    }};
    ($x:expr) => {{
        let mut f = true;
        for a in $x.iter() {
            print!("{}{}", if f {""} else {" "}, a);
            f = false;
        }
        print!("\n");
    }};
}

trait ToChars {
    fn to_chars(&self) -> Vec<char>;
}

impl ToChars for String {
    fn to_chars(&self) -> Vec<char> {
        self.chars().collect::<Vec<char>>()
    }
}

fn main() {
    let mut rd = reader::Reader::new();

    let n = rd.next();
    let a: i64 = rd.next();
    let b: i64 = rd.next();
    let c: i64 = rd.next();
    let d: i64 = rd.next();

    let mut ans = false;
    for x in 0..n {
        let y = n - 1 - x;

        let lb = a + x * c - y * d;
        let ub = lb + (d - c) * (n - 1);
//        p!(["x: ", x, "y: ", y, "lb: ", lb, "ub: ", ub]);

        ans |= lb <= b && b <= ub;
    }
    p!([if ans {"YES"} else {"NO"}]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int mod = 1e9+7, A = 4e4+5;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	string s, t;
  cin >> s >> t;
  cout << t << s;
    return 0;
}

Measured memory_bytes: 256
void main(){
	int a = _scan();
	string s = readln().chomp();
	if(a>=3200)s.writeln();
	else writeln("red");
}

import std.stdio, std.conv, std.algorithm, std.numeric, std.string, std.math;

// 1要素のみの入力
T _scan(T= int)(){
	return to!(T)( readln().chomp() );
}

// 1行に同一型の複数入力
T[] _scanln(T = int)(){
	T[] ln;
	foreach(string elm; readln().chomp().split()){
		ln ~= elm.to!T();
	}
	return ln;
}


Measured memory_bytes: 2580
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define repp(i,n,s) for (int i= (int)(n); i >= (int)(s); i--)
#define mp make_pair
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int n,x;cin>>n>>x;
    int ans = 1;
    int num = 0;
    rep(i,0,n){
        int y;cin>>y;
        num += y;
        if (num<=x) ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3608