akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
#define MAX 20000000000LL
#define FOR(i,m,n) for(int i = (m); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define all(v) v.begin(),v.end()
 
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
 
int main(){
	
	ll n,k,x,dp[1000000];
	vi v;
	cin>>n>>k;
 
	REP(i,n){
		cin>>x;
		v.pb(x);
	}
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	FOR(i,2,n){
		dp[i]=MAX;
		for(int j=i-1; j>=max(i-k,0LL); j--){
			if(dp[i]>dp[j]+abs(v[i]-v[j])){
				dp[i]=dp[j]+abs(v[i]-v[j]);
			}
		}
	}
	//cout<<dp[n-1]<<endl;
 
	
	cout<<dp[n-1]<<endl;
 
	return 0;
	
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main (){
  int n,k;   cin >> n >> k;
  double a,b=0;
  cout << fixed << setprecision(12);
  vector<double>p(n+10);
  vector<double>v(n+10);
  for(int i=1;i<=n;i++){
      cin >> p.at(i);
      p.at(i)=(1+p.at(i))/2;
     // cout << p.at(i) << endl;
  }

  v.at(1)=p.at(1);
  for (int i=2;i<=n;i++){
      v.at(i)=p.at(i)+v.at(i-1);
     // cout << v.at(i) << endl;    //期待値の累積和
  }

  for(int i=0;i<=n-k;i++){
      a=0;
      a=v.at(i+k)-v.at(i);
      if(a>=b){
          b=a;
      }
  }
  

  cout << b << endl;
}


Measured memory_bytes: 3328
# coding: utf-8
alp=["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

S=input()
lS=list(S)
flg=False

for i in range(len(alp)):
    if alp[i] in lS:
        continue
    else:
        print(alp[i])
        flg=True
        break

if not(flg):
    print("None")

Measured memory_bytes: 45936
#include <cstdio>
#include <vector>
#include <set>

using namespace std;

void dfs(vector<set<int>>& adj, vector<bool>& visited, int here) {
    visited[here] = true;
    for(int there : adj[here]) {
        if(!visited[there]) dfs(adj, visited, there);
    }
}

int main() {
    int n, m; scanf("%d %d", &n, &m);
    vector<set<int>> adj(n, set<int>()); // adj[x]: x와 연결된 정점들
    for(int i = 0; i < m; i++) {
        int x, y, z;
        scanf("%d %d %d", &x, &y, &z);
        adj[x-1].insert(y-1);
        adj[y-1].insert(x-1);
    }
    vector<bool> visited(n);

    int cnt = 0;
    for(int i = 0; i < n; i++) {
        if(!visited[i]) {
            cnt++;
            dfs(adj, visited, i);
        }
    }
    printf("%d",cnt);

    return 0;
}


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

int main()
{
  int n;
  scanf("%d", &n);
  vector<int> a(n);
  for(int& i : a)
  {
    scanf("%d", &i);
  }
  long long dp[n + 1][n + 1];
  for(int i = n - 1; i >= 0; i--)
  {
    for(int j = i; j < n; j++)
    {
      if(i == j)
      {
        dp[i][j] = a[i];
      }
      else
      {
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1]);
      }
    }
  }
  printf("%lld", dp[0][n - 1]);
  return 0;
}


Measured memory_bytes: 46336
import java.util.Scanner;
import java.util.Set;
import java.util.HashSet;
 
public class Main {
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
         
        int m = stdIn.nextInt();
        for(int i=0;i<m;i++){
            Set<String> set = new HashSet<String>();
            String input = stdIn.next();
            set.add(input);
            for(int j=1;j<input.length();j++){
                String catBefore = input.substring(0, j);
                String catAfter = input.substring(j);
                String beforeBufferBuffer = new StringBuffer(catBefore).reverse().toString();
                String afterBuffer = new StringBuffer(catAfter).reverse().toString();
                set.add(catBefore.concat(catAfter));
                set.add(catBefore.concat(afterBuffer));
                set.add(catAfter.concat(catBefore));
                set.add(catAfter.concat(beforeBufferBuffer));
                set.add(beforeBufferBuffer.concat(afterBuffer));
                set.add(afterBuffer.concat(catBefore));
                set.add(beforeBufferBuffer.concat(catAfter));
            }
            System.out.println(set.size());
        }
    }
}

Measured memory_bytes: 37768
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cctype>
#include<utility>
 
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    if(n%2==0)
        printf("%d\n",n);
    else
        printf("%d\n",2*n);
    return 0;
}

Measured memory_bytes: 256
n=int(input())
ta=[list(map(int,input().split())) for i in range(n)]
a,b=1,1
for i in range(n):
  l=-min(-a//ta[i][0],-b//ta[i][1])
  a=ta[i][0]*l
  b=ta[i][1]*l
print(a+b)

Measured memory_bytes: 3188
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long ll;

int f(int a) {
	int s = 0;
	while(a) {
		s += a % 10;
		a /= 10;
	}
	return s;
}

int main() {
	int n;
	cin >> n;
	int best = INT_MAX;
	for(int a = 1; a < n; ++a) {
		int b = n - a;
		best = min(best, f(a) + f(b));
	}
	printf("%d\n", best);
}


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

using namespace std;

int main(){
  int N;
  string s;
  cin >> N;
  cin >> s;
  int nr = 0, nb = 0;
  for (int i=0; i<s.size(); i++){
    if (s[i] == 'B') nb++;
    else nr++;
  }
  if (nr > nb) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

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

long long n;
long long a[(1<<20)], f[(1<<20)];

vector < long long > prs;

pair < long long, long long > vals[(1<<20)];
map < long long, long long > cnt;
map < long long, pair < long long , long long > > mem;

pair< long long, long long > gg ( long long x ) {

    if ( mem[x].first ) { return mem[x]; }

    long long a = 1, b = 1;

    for ( int i = 0 ; i < prs.size() && prs[i]*prs[i] <= x ; i ++ ) {

        if ( x%prs[i] == 0 ) {
            int cnt = 0;
            for ( ; x%prs[i] == 0 ; cnt ++ ) {
                x /= prs[i];
            }
            cnt %= 3;
            for ( int c = 0 ; c < cnt ; c ++ ) { a *= prs[i]; }
            cnt = (3-cnt)%3;

            for ( int c = 0 ; c < cnt ; c ++ ) {
                if ( b != -1 ) {
                    b *= prs[i];
                    if ( b >  (10000000000LL) ) { b = -1; }
                }
            }

        }
    }

    if ( x != 1 ) {
        a *= x;
        if ( x > 1000000 ) { b = -1; }
        if ( b != -1 ) {
            b *= x;
            if ( b > (10000000000LL) ) { b = -1; }
        }
        if ( b != -1 ) {
            b *= x;
            if ( b > (10000000000LL) ) { b = -1; }
        }
    }

    mem[x] = make_pair( a, b );
    return make_pair( a, b );
}

int main () {

    for( long long i = 2 ; i*i < (10000000000LL) ; i ++ ) {
        if ( f[i] == 0 ) {
            prs.push_back( i );
            for ( long long j = 1;  i*i*j*j < (10000000000LL) ; j ++ ) {
                f[i*j] = 1;
            }
        }
    }


    cin >> n;
    for ( long long i = 0 ; i < n ; i ++ ) {
        cin >> a[i];
    }
    sort( a, a+n );
    for ( int i = 0 ; i < n ; i ++ ) {
        if ( i == 0 || a[i] != a[i-1] ) { vals[i] = gg( a[i] ); }
        else {
            vals[i] = vals[i-1];
        }
     //   cout << vals[i].first << " " << vals[i].second << "\n";
        cnt[ vals[i].first ] ++;
    }
    sort ( vals, vals+n );

    long long ans = 0;
    for ( long long i = 0 ; i < n ; ) {
        long long j = i;
        for ( ; j < n && vals[i].first == vals[j].first ; j ++ ) {}

        long long ccnt = j-i, revcnt = cnt[ vals[i].second ];

        if ( vals[i].first == 1 ) { ans ++; }
        else {
            if ( ccnt > revcnt ) {
                ans += ccnt;
            }else if ( ccnt < revcnt ) {
                //ans += revcnt;
            }else {
                if ( vals[i].first < vals[i].second ) {
                    ans += ccnt;
                }
            }

        }

        i = j;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 22708
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    s=input()
    n=len(s)
    A=[0]*(n+1)
    for i in range(n):
        if s[i]=="<":
            A[i+1]=A[i]+1
    for i in range(n):
        if s[n-i-1]==">":
            A[n-i-1]=max(A[n-i-1],A[n-i]+1)
    print(sum(A))

if __name__=='__main__':
    main()

Measured memory_bytes: 46320
n = int(input())
from bisect import bisect 
ab = [list(map(int,input().split())) for i in range(n)]

ab.sort(key = lambda x: x[1])
ok = True
last = 0
for a,b in ab:
    if b-a>=last:
        last += a
    else:
        ok = not ok
        break
print('Yes' if ok else 'No')

Measured memory_bytes: 112688
#include<iostream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<map>

using namespace std;

#define rep(i,N) for(int i=0;i<N;i++) //0から


typedef long long ll;




ll binary_search(vector<ll> a, ll n, ll key){
    ll right = n, left = -1;
    ll md = (right + left) / 2;

    while(right - left > 1){
        if(a[md] <= key){
            right = md;
        }else{
            left = md;
        }
        md = (right + left) / 2;
    }
    if(left == -1) return -1; //無い場合
    return right;
}

vector<ll> prime;
void Prime(ll n){ //線形篩,素数列挙
    vector<ll> p(n,0);
    p[0]=1;
    p[1]=1;
    for(ll i=2;i<n;i++){
        if(p[i]==0){
            prime.push_back(i);
            p[i]=i;
        }
        ll k=prime.size();
        for(ll j=0;j<k && i*prime[j]<n && prime[j]<=p[i];j++){
            p[i*prime[j]]=prime[j];
        }
    }
}

#define MOD ((ll)1e+9 + 7)




//cout<<fixed<<setprecision(10);
int main(){
    int n;
    cin>>n;
    vector<int> w(n);
    int sum=0;
    rep(i,n){
        cin>>w[i];
        sum+=w[i];
    }
    int ans=sum,sum2;
    rep(i,n){
        sum2=0;
        for(int j=i;j<n;j++){
            sum2+=w[j];
        }
        ans=min(ans,abs(sum-2*sum2));
    }
    cout<<ans<<endl;


    return 0;
}



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

using namespace std;
using ll =long long;
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
#define leftunique(a) {sort((a).begin(),(a).end());(a).erase(unique((a).begin(),(a).end()),(a).end());}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
static const ll INF = 1LL << 60;
//Write From this Line

int main()
{
	ll x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vector<ll> p(a), q(b), r(c);
	rep(i,a) cin >> p[i];
	rep(i,b) cin >> q[i];
	rep(i,c) cin >> r[i];
	sort(p.rbegin(),p.rend());
	sort(q.rbegin(),q.rend());
	sort(r.rbegin(),r.rend());
	// p(つまり赤)を大きい方からx個食べる
	// q(つまり緑)を大きい方からy個食べる
	ll ans = 0;
	vector<ll> look(x+y);
	rep(i,x){
		ans += p[i];
		look[i] = p[i];
	}
	rep(i,y){
		look[x+i] = q[i];
		ans += q[i];
	}
	sort(look.begin(),look.end());
	int count = 0;
	rep(i,x+y){
		int x = r[count];
		if(look[i] < r[count]){
			ans -= look[i];
			ans += r[count];
			count ++ ;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    void solve(){
        vector<LL> a(3);
        for(int i=0; i<3; ++i){
            cin >> a[i];
        }
        sort(a.begin(),a.end());
        if(a[0]==a[2] && a[0]%2==0){
            cout << -1 <<"\n";
            return;
        }
        LL ans=0;
        while(1){
            if(a[0]%2 || a[1]%2 || a[2]%2){
                cout << ans <<"\n";
                break;
            }
            vector<LL> b(a);
            a[0]=(b[1]+b[2])/2;
            a[1]=(b[0]+b[2])/2;
            a[2]=(b[1]+b[0])/2;
            ++ans;
        }
    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    Problem p;
    p.solve();
    return 0;
}



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

int main(){
    long long int X; cin>>X;
    long long int ans=0;
    if (X>=500){
        ans=(X/500)*1000;
        X=X%500;
        ans=ans+(X/5)*5;
    }
    else{
        ans=(X/5)*5;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	if (K == 1) {
		vector<bitset<50000>>bs(150000);
		vector<vector<int>>v(N, vector<int>(1));
		vector<pair<int, int>>w;
		for (int i = 0; i < N; i++) {
			bs[i].flip(i);
			v[i].back() = i;
		}
		for (int i = N; i < N + M; i++) {
			cin >> L >> R;
			L--, R--;
			w.emplace_back(L, R);
			bs[i] = bs[v[L].back()] | bs[v[R].back()];
			v[L].push_back(i);
			v[R].push_back(i);
		}
		bool flag = false;
		int st = 0;
		for (int i = N; i < N + M; i++) {
			if (bs[i].count() == N) {
				st = i - N;
				flag = true;
				break;
			}
		}
		if (!flag) {
			cout << -1 << endl;
			return 0;
		}
		string ans(M, '^');
		vector<int>use(N);
		use[w[st].first] = 1;
		use[w[st].second] = 1;
		for (int i = st - 1; i >= 0; i--) {
			if (!use[w[i].first])ans[i] = 'v';
			if (use[w[i].first] || use[w[i].second]) {
				use[w[i].first] = use[w[i].second] = 1;
			}
		}
		cout << ans << endl;
	}
	else {
		vector<int>v(N, 1);
		if (N == 2) {
			cout << -1 << endl;
			return 0;
		}
		int num = N;
		vector<pair<int, int>>w(M);
		for (auto &i : w) {
			cin >> i.first >> i.second;
			i.first--, i.second--;
		}
		string ans(M, '^');
		for (int i = 0; i < M; i++) {
			if (num == 3) {
				vector<int>p;
				for (int j = 0; j < N; j++) {
					if (v[j])p.push_back(j);
				}
				vector<int>x;
				for (int j = i; j < M; j++) {
					if (v[w[j].first] && v[w[j].second]) {
						x.push_back(j);
					}
				}
				int cnt = 0;
				for (int j = i; j < M; j++) {
					if (cnt < x.size() && x[cnt] == j) {
						if (cnt+1!=x.size()) {
							if (w[x[cnt]] != w[x[cnt + 1]]) {
								if (w[x[cnt]].second != w[x[cnt + 1]].first&&w[x[cnt]].second != w[x[cnt + 1]].second)ans[j] = 'v';
							}
						}
						cnt++;
					}
					else {
						if (v[w[j].second])ans[j] = 'v';
					}
				}
				break;
			}
			num -= v[w[i].first];
			num -= v[w[i].second];
			v[w[i].first] |= v[w[i].second];
			v[w[i].second] = 0;
			num += v[w[i].first];
			num += v[w[i].second];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 921588
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scanner = new Scanner(System.in);
        double a = scanner.nextInt();
        double b = scanner.nextInt();
        
        System.out.println((int)(a/b) + " " + (int)(a%b) + " " + String.format("%.5f",a/b));
        
    }
}



Measured memory_bytes: 26536
// time-limit: 2000
// 23
#include <bits/stdc++.h>
using namespace std;
#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define endl '\n'
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)
#define fi first
#define se second
#define pb push_back
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define len(x) int(x.size())
#define lli __int128_t
#define li long long int
#define ld long double
#ifdef DEBUG
// 3
ostream &operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 4
ostream &operator<<(ostream &o, vector<auto> v) {
  rep(i, len(v)) o << setw(7) << right << v[i];
  return o << endc << endl << coutc;
}
// 4
ostream &operator<<(ostream &o, map<auto, auto> m) {
  for (auto &kv : m) o << kv;
  return o;
}
// 7
void debug(const auto &e, const auto &... r) {
  cout << coutc << e;
  ((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif

int sign(li x) { return x < 0 ? -1 : x > 0; }

//         a / b
li ceil(li a, li b) {
  if (sign(a) == sign(b) && a % b) return a / b + 1;
  else return a / b;
}

void _main(int tc) {
    int a, b;
    cin >> a >> b;

    if (b == 1) {
        cout << 0 << endl;
        return;
    }

    // b = a + (a - 1) * X
    // X = (b - a) / (a - 1)
    // is ceiling because we need to assure that with X pipes we complete "b - a" lines.
    // we add one because after fullfilling "b - a" we still need to complete with "a" lines.
    cout << ceil(b - a, a - 1) + 1 << endl;
}
// 7
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}


Measured memory_bytes: 3592
/*
题意：给定n个数，每次可以使得ai和ai+1变成相反数，求能使得n个数的和最大，并求出最大值。

思路：记录负数的个数，如果是偶数，则可以全部化为正数，如果为奇数，这选择绝对值最小的一个，最后sum-=2*minn;
*/

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

int main(){
	long long n,tmp,summ=0,k=0,minn=1000000009;
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>tmp;
		if(tmp<0){
			k++;
			tmp=-tmp;
		}
		summ+=tmp;
		if(minn>tmp)	minn=tmp;
	}
	if(k%2==0)	cout<<summ;
	else		cout<<summ-2*minn;
}

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

int N, a[200000], ans, K;

int main() {
    cin >> N;
    rep(i, N) cin >> a[i];
    
    rep(i, N) {
        if (a[i] == K + 1) K++;
        else ans++;
    }
    
    cout << (K ? ans : -1) << endl;
}

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

namespace abc161_c
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] NK = Console.ReadLine().Split(' ');
            long N = long.Parse(NK[0]);
            long K = long.Parse(NK[1]);

            if (N % K == 0)
            {
                Console.WriteLine(0);
            }
            else
            {
                N = N % K;

                if (Math.Abs(N - K) < N)
                {
                    N = Math.Abs(N - K);
                }

                Console.WriteLine(N);
            }

            Console.Read();
        }
    }
}


Measured memory_bytes: 27524
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x,d[100],e=0,z=0;
    cin>>n>>m>>x;
    for(int i=0;i<m;i++){
        cin>>d[i];
    }
    for(int i=x;i<=n;i++) {
            for(int j=0;j<m;j++) if(i==d[j]) e++;
    }
    for(int i=x;i>=0;i--){
            for(int j=0;j<m;j++) if(i==d[j]) z++;
    }
    if(e<z)cout<<e<<endl;
    else cout<<z<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
from numpy import*
def main(h,w,k,t):
    c=zeros((3001,3001),int_)
    dp=zeros((4,3001,3001),int_)
    for i in range(k):
        y,x,v=t[i]
        c[y,x]=v
    for i in range(1,h+1):
        for j in range(1,w+1):
            x=max(dp[:,i-1,j])
            for k in range(4):
                if k:dp[k,i,j]=max(dp[k,i,j-1],dp[k-1,i,j-1]+c[i,j])
                else:dp[k,i,j]=max(dp[k,i,j-1],x)
            dp[1,i,j]=max(dp[1,i,j],x+c[i,j])
    return max(dp[:,h,w])
if sys.argv[-1]=='ONLINE_JUDGE':
  from numba.pycc import CC
  cc=CC('my_module')
  cc.export('main','i8(i8,i8,i8,i8[:,:])')(main)
  cc.compile()
  exit()
from my_module import main
(h,w,k),*t=[int_(t.split())for t in open(0)]
print(main(h,w,k,int_(t)))

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

using namespace std;

const long long INF = 1e18;
const int N = 3e5;
const int MOD = 998244353;
const double EPS = 1e-9;

const double PI = acos(-1);


int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int k;
    cin >> k;
    long long ans = 0;
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int h = 1; h <= k; h++)
                ans += __gcd(i, __gcd(j, h));
    cout << ans;
}

Measured memory_bytes: 3640
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()

int main() {
	int n, k;
	cin >> n >> k;
	vector<bool> sunuke(n, false);
	rep(i, k) {
		int d;
		cin >> d;
		rep(j, d) {
			int a;
			cin >> a;
			a--;
			sunuke[a] = true;
		}
	}
	ll ans = 0;
	rep(i, n) {
		if (!sunuke[i])ans++;
	}
	cout << ans << endl;
}


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

using lnt = long long;
using Real = long double;

#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(lnt i=0;i<(n);++i)
#define RANGE(i, a, b) for(lnt i=(a);i<(b);++i)
#define RREP(i, n) for(lnt i=(n)-1;i>= 0;--i)

#define ln '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define dcout cout<<fixed<<setprecision(20)
#define summon_tourist cin.tie(0);ios::sync_with_stdio(false)

constexpr int dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
constexpr Real eps = 1e-9; const Real pi = acosl(-1);
constexpr lnt BIG = INT_MAX/10, BBIG = LLONG_MAX/10;

template<class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<class T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<class T> inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template<class T> inline T nHr(T a,T b){return nCr(a+b-1,b);}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

using pint = pair<int, int>; using plnt = pair<lnt, lnt>;
using vint = vector<int>; using vlnt = vector<lnt>;
constexpr lnt MOD = 1e9+7;

int main(){
	summon_tourist;

	int H, W; cin >> H >> W;
	vector<string> S(H);
	REP(i, H) cin >> S[i];

	int dp[100][100];
	REP(i, H) REP(j, W) dp[i][j] = BIG;
	if(S[0][0] == '#') dp[0][0] = 1;
	else dp[0][0] = 0;

	REP(i, H) REP(j, W){
		REP(k, 2){
			int nxi = i+k, nxj = j+1-k;
			if(nxi < H and nxj < W){
				if(S[i][j] == '.' and S[nxi][nxj] == '#'){
					chmin(dp[nxi][nxj], dp[i][j] + 1);
				} else {
					chmin(dp[nxi][nxj], dp[i][j]);
				}
			}
		}
	}

	cout << dp[H-1][W-1] << ln;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#define INF 10000005

typedef long long ll;

using namespace std;

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

    if (abs(a - b) <= w) cout << '0' << endl;
    else cout << abs(a - b) - w << endl;
}

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

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int k, a, b;
	cin >> k >> a >> b;

	for (int i = k; i <= b; i += k) {
		if (i >= a ) {
			cout << "OK\n";
			return 0;
		}
	}

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

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=1e5+5;


int main(){
	int n,k,s;
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>k>>s;
	for(int i=1;i<=k;i++){
		cout<<s;
		if(i!=n)cout<<' ';
	}
	for(int i=k+1;i<=n;i++){
		
		if(s==1e9)cout<<s-1;
		else cout<<s+1;
		if(i!=n)cout<<' ';
	}

	return 0;
	
}

Measured memory_bytes: 1280
import math
#入力二つ
# n, k = map(int,input().split())

n = int(input())
n_list = list(map(int,input().split(" ")))

min_num = 100000000000000

for p in range(min(n_list), max(n_list)+1):
    sum = 0
    for j in n_list:
        sum += (j-p)**2

    if sum<min_num:
        min_num = sum

print(min_num)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[100005],p[100005],hell=pow(10,9)+7;
ll exp(ll x,ll y){
    ll res=1;
    while(y>0){
        if(y&1)
        res=(res*x)%hell;
        y>>=1;
        x=(x*x)%hell;
    }
    return res;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    p[0]=1;
    for(ll i=1;i<100005;i++)
    p[i]=(i*p[i-1])%hell;
    ll n,k,res=0;
    cin>>n>>k;
    for(ll i=0;i<n;i++)
    cin>>arr[i];
    sort(arr,arr+n);
    for(ll i=k-1;i<n;i++){
        ll sum=p[i];
        sum*=exp(p[i-k+1],hell-2);
        sum%=hell;
        res+=(sum*arr[i])%hell;
        res%=hell;
    }
    for(ll i=n-k;i>=0;i--){
        ll sum=p[n-i-1];
        sum*=exp(p[n-i-k],hell-2);
        sum%=hell;
        res-=(sum*arr[i])%hell;
        res%=hell;
    }
    res*=exp(p[k-1],hell-2);
    res%=hell;
    if(res<0)
    res+=hell;
    cout<<res;
}


Measured memory_bytes: 1792
from itertools import *
n,x,y=map(int,input().split())
a=[0]*n
for i,j in combinations(range(1,n+1),2):
    b=min(abs(i-j),abs(x-i)+1+abs(y-j),abs(x-j)+1+abs(y-i))
    a[b]+=1
print(*a[1:],sep="\n")   

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf=0x7fffffff;
#define mp(a,b) make_pair(a,b)
const int N=1e5+5;
int n,m;
vector<int> g[N];
int col[N];
int cnt;
void dfs(int x){
	col[x]=cnt;
	for(int i=0;i<g[x].size();i++){
		int nx=g[x][i];
		if(col[nx]!=-1)continue;
		dfs(nx);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int s,t;
		scanf("%d%d",&s,&t);
		s--;
		t--;
		g[s].push_back(t);
		g[t].push_back(s);
	}
	memset(col,-1,sizeof(col));
	cnt=0;
	for(int i=0;i<n;i++){
		if(col[i]==-1){
			cnt++;
			dfs(i);
		}
	}
	printf("%d\n",cnt-1); 
	return 0;
}


Measured memory_bytes: 10068
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <queue>

using namespace std;
using ll = long long;

const int MN = 220;
const int MR = 1100;
const ll INF = 1e9;

ll dp[MR][MN];
ll dist[MN][MN];
ll distS[MN][MN];

bool solve() {
    for (int i = 0; i < MN; i++) {
        for (int j = 0; j < MN; j++) {
            dist[i][j] = INF;
            distS[i][j] = INF;
            if (i == j) {
                dist[i][j] = 0;
                distS[i][j] = 0;
            }
        }
    }
    int n, m;
    cin >> n >> m;
    if (!n) return false;
    for (int i = 0; i < m; i++) {
        int x, y; ll t; char s;
        cin >> x >> y >> t >> s; x--; y--;
        if (s == 'L') {
            dist[x][y] = dist[y][x] = min(dist[x][y], t);
        } else {
            distS[x][y] = distS[y][x] = min(distS[x][y], t);
        }
    }
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
                distS[i][j] = min(distS[i][j], distS[i][k]+distS[k][j]);
            }
        }
    }

    int r;
    cin >> r;
    int z0; cin >> z0; z0--;
    fill_n(dp[0], n, INF);
    dp[0][z0] = 0;
    int b = z0;
    r--;
    for (int i = 0; i < r; i++) {
        int p;
        cin >> p; p--;
        for (int j = 0; j < n; j++) {
            dp[i+1][j] = dp[i][j] + dist[b][p];
            for (int k = 0; k < n; k++) {
                dp[i+1][j] = min(dp[i+1][j], dp[i][k]+dist[b][k]+distS[k][j]+dist[j][p]);
            }
        }
        b = p;
    }
    ll ans = INF;
    for (int i = 0; i < n; i++) {
        ans = min(ans, dp[r][i]);
    }
    cout << ans << endl;
    return true;
}

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

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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

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

const int INF = 100000002;

int main(){
	int a, b; cin >> a >> b;
	for(int i = 1; i < 1500; i++){
		int t8 = i*0.08;
		int t10 = i*0.1;
		if(t8 == a && t10 == b){
			cout << i << endl;
			return 0;	
		} 

	}
	cout << -1 << endl;

}

Measured memory_bytes: 256
import std.stdio;
import std.conv;
import std.string;
import std.algorithm;

int table[1 << 10];
int ans;

// n 残りの残数
// s 合計
// bit mask
void solve(int mask, int n, int s) {
  if (table[mask] != 0) return;
  if (s == 0 && n == 0) {
    table[mask] = 1;
    ans++;
    return;
  }
  if (s < 0 || n <= 0) return;
  int sum = 0;
  for (int i = 0; i <= 9; i++) {
    if (((mask >> i) & 1) == 0) {
      solve(mask | 1 << i, n - 1, s - i);
    }
  }
  return;
}

void main() {
  while(true) {
    (cast(ubyte*)&table)[0..table.sizeof] = 0;
    auto line = readln.chomp.split(" ").map!(to!(int));
    int n = line[0];
    int s = line[1];
    if (n == 0 && s == 0) break;
    ans = 0;
    solve(0, n, s);
    writeln(ans);
  }
}

Measured memory_bytes: 1072
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
#include <cassert>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define PP(p) cout<<(p)<<" ";
#define INF 1e18

typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pi;
//int dy[8]={1,1,1,0,-1,-1,-1,0};
//int dx[8]={-1,0,1,1,1,0,-1,-1};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int n,m;
vi h;
vi M;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>n>>m;
    h.resize(n+1);
    M.resize(n+1,-1);
    rep(i,n)cin>>h.at(i);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--;b--;
        M[a] = max(M[a],h[b]);
        M[b] = max(M[b],h[a]);
    }
    int ans = 0;
    rep(i,n){
        if(M[i] < h[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4756
N = int(input())
Hs = list(map(int, input().split()))

for i in range(1, N):
    if Hs[N-i] >= Hs[N-i-1]:
        continue
    elif Hs[N-i-1] - Hs[N-i] >= 2:
        print("No")
        exit()
    else:
        Hs[N-i-1] -= 1
print("Yes")


Measured memory_bytes: 15020
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N,K;cin>>N>>K;
    vector<int>a(N);
    REP(i,N)cin>>a[i];
    // dp[i] 石がi個残っているとき手番を持っている方が勝ちならばtrue
    vector<bool> dp(K+1,false);
    REP(i,K+1)
    {
        if(dp[i])continue;
        else{
            REP(j,N){
                if(i+a[j]<=K)dp[i+a[j]]=true;
            }
        }
    }
    if(dp[K])cout<<"First"<<endl;
    else cout<<"Second"<<endl;
    return 0;
}

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

using namespace std;

int main()
{
	string s;

	int n;
	int ans = 0;
	cin >> n >> s;
	for (int offset = 1; offset < n; offset++) {
		int m = 0;
		for (int i = 0; i + offset < n; i++)
		{
			if (s[i] == s[i + offset]) {
				m++;
				ans = max(ans, min(offset, m));
			}
			else {
				m = 0;
			}			
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<array>
#include<algorithm>
using namespace std;

int main() 
{
	int a, b;
	cin >> a >> b;
	if (a*b % 2 == 0 ) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;
//using namespace atcoder;

template< typename OperatorMonoid >
struct DuelSegmentTree {
  using H = function< OperatorMonoid(OperatorMonoid, OperatorMonoid) >;

  int sz, height;
  vector< OperatorMonoid > lazy;
  const H h;
  const OperatorMonoid OM0;


  DuelSegmentTree(int n, const H h, const OperatorMonoid OM0)
      : h(h), OM0(OM0) {
    sz = 1;
    height = 0;
    while(sz < n) sz <<= 1, height++;
    lazy.assign(2 * sz, OM0);
  }

  inline void propagate(int k) {
    if(lazy[k] != OM0) {
      lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
      lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
      lazy[k] = OM0;
    }
  }

  inline void thrust(int k) {
    for(int i = height; i > 0; i--) propagate(k >> i);
  }

  void update(int a, int b, const OperatorMonoid &x) {
    thrust(a += sz);
    thrust(b += sz - 1);
    for(int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
      if(l & 1) lazy[l] = h(lazy[l], x), ++l;
      if(r & 1) --r, lazy[r] = h(lazy[r], x);
    }
  }

  OperatorMonoid operator[](int k) {
    thrust(k += sz);
    return lazy[k];
  }
};



void solve(){
	ll n,t;
	cin>>n>>t;
	DuelSegmentTree<ll>row(n-2,[](ll a,ll b){return min(a,b);},n-2),
										 clm(n-2,[](ll a,ll b){return min(a,b);},n-2);
	ll ans=(n-2)*(n-2);
	while(t--){
		ll q,x;
		cin>>q>>x;
		x-=2;
		if(q==1){
			ll val=clm.operator[](x);
			ans-=val;
			row.update(0,val,x);
			clm.update(x,x+1,0);
		}
		else{
			ll val=row.operator[](x);
			ans-=val;
			clm.update(0,val,x);
			row.update(x,x+1,0);
		}
	}
	cout<<ans;
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 11344
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, S: str):
    print(''.join([chr((ord(i)+N-ord('A'))%26 + ord('A')) for i in S]))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
import math
def per_count(n, r):
    result = 0
    if n >= r:
        result = math.factorial(n) // math.factorial(n - r)
    return result

N, M = map(int, input().split())
result = (per_count(N, 2) + per_count(M, 2)) // 2
print(result)

Measured memory_bytes: 3060
#include<iostream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include <iterator>
#include<cassert>
#include<functional>
#include<random>
#include<complex>
#include<bitset>
#include<cstdint>
#include<chrono>
#define int int64_t
#define uint uint64_t
#define REP(i, a, b) for (int64_t i = (int64_t)(a); i < (int64_t)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define Min(x) *min_element(ALL(x))
#define Max(x) *max_element(ALL(x))
#define Unique(L) (L.erase(unique(ALL(L)), L.end()))
#define veccat(v1, v2) std::copy((v2).begin(),(v2).end(),std::back_inserter(v1)/*v1の後ろにv2を入れる*/)
#define intmax (std::numeric_limits<int64_t>::max() / 4)
using namespace std;
//typedef boost::multiprecision::cpp_int bigint;
const double EPS = 1e-9;
const double PI = acos(-1.0);

using namespace std;



signed main() {

	int N;
	cin >> N;
	vector<vector<int>>A(N, vector<int>(N - 1));
	rep(i, N)rep(j, N - 1) {
		cin >> A[i][j];
		A[i][j]--;
	}

	vector<int>indegree(N*N, 0);
	vector<set<int>>graph(N*N);

	rep(i, N)rep(j, N - 2) {
		int s1 = min(i, A[i][j]);
		int s2 = max(i, A[i][j]);
		int t1 = min(i, A[i][j + 1]);
		int t2 = max(i, A[i][j + 1]);
		int x = s1 * N + s2;
		int y = t1 * N + t2;
		if (graph[x].find(y) == graph[x].end()) {
			indegree[y]++;
			graph[x].insert(y);
		}
	}

	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>D;
	rep(i, N)REP(j, i + 1, N) {
		if (indegree[i * N + j] == 0)D.push(make_pair(1, i * N + j));
	}

	vector<int>day(N * N, -1);

	int searched_num = 0, max_day = 0;
	while (!D.empty()) {
		auto x = D.top();
		D.pop();
		if (day[x.second] != -1)continue;
		searched_num++;
		day[x.second] = x.first;
		max_day = max(max_day, x.first);
		for (int y : graph[x.second]) {
			indegree[y]--;
			if (indegree[y] != 0)continue;
			D.push(make_pair(x.first + 1, y));
		}
	}

	if (searched_num != N * (N - 1) / 2) {
		cout << -1 << endl;
		return 0;
	}

	cout << max_day << endl;



	return 0;
}

Measured memory_bytes: 117376
N = int(input())
A = list(map(int, input().split()))

#print(A)

A.sort()
#print(A)

mul = 1
for i in range(N):
    if mul == 0:
        break
    elif mul > 10**18:
        mul = -1
        break
    else:
        mul *= A[i]
 
if mul > 10**18:
    print("-1")
else:
    print(mul)


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

int main(){
  int r,D,X,i;
  cin>>r>>D>>X;
  int x[11];
  x[0]=X;
  for(i=1;i<11;i++){
    x[i]=r*x[i-1]-D;
  }
  for(i=1;i<11;i++){
    cout<<x[i]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector <int> v(100001);
  vector <int> ans;
  for(int i=1;i<=100000;i++){
    for(int j=2;j*j<=i;j++){
      if(i%j==0)
        v[i]=1;
    }
  }
  for(int i=1;i<=100000;i++){
    if(v[i]==0)
      ans.push_back(i);
  }
  ans.push_back(100003);
  int n;
  cin>>n;
  vector <int> ::iterator it=lower_bound(ans.begin(),ans.end(),n);
  cout<<*it;
}
  

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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1000000007ll;
const i64 smod = 998244353ll;
const i64 inf = 10000000000000007ll;

const double eps = 1e-10;

const i64 MAXN = 300005;
const i64 MAXM = 60;

i64 n;
i64 a[MAXN];
i64 ps[2][MAXM][MAXN];

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    cin >> n;

    for (i64 i = 1; i <= n; i++) {
        cin >> a[i];
    }

    for (i64 k = 0; k < 2; k++) {
        for (i64 j = 0; j < MAXM; j++) {
            for (i64 i = n; i >= 1; i--) {
                //cerr << "kji: " << k << " " << j << " " << i << endl;
                ps[k][j][i] = ps[k][j][i + 1] + ((k == 0 ? ~a[i] : a[i]) & (1ll << j));
                ps[k][j][i] %= mod;
            }
        }
    }

    i64 R = 0;
    for (i64 i = 1; i < n; i++) {
        for (i64 j = 0; j < MAXM; j++) {
            i64 k = (a[i] & (1ll << j)) != 0 ? 0 : 1;
            R += ps[k][j][i + 1];
            R %= mod;
        }
    }
    cout << R << endl;

    return 0;
}

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

int main(){
    int a, b;
    cin >> a >> b;
    if((a < 0 && b < 0) && (a - b) % 2 == 0) cout << "Negative" << endl;
    else if (a <= 0 && b >= 0) cout << "Zero" << endl;
    else cout << "Positive" << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split())) # N + 1
B = list(map(int, input().split())) # N
 
# 重みがないのですべて小さい方から倒せると仮定する
cnt = 0
for i in range(N):
    cnt += min(B[i], A[i])
    diff = B[i] - A[i]
    if diff > 0:
        if A[i+1] < diff:
            cnt += A[i+1]
            A[i+1] = 0
        else:
            cnt += diff
            A[i+1] -= diff
        #A[i] = 0
    #else:
    #    A[i] -= B[i]
#print("A",A)
#print("B",B)
print(cnt)

Measured memory_bytes: 18624
x = [int(input()) for i in range(5)]
y=0
for i in x:
  if i%10==0:
    y+=i
  else:
    y+=(i+(10-(i%10)))
a=[]
for i in x:
  a.append(i%10)
if a.count(0)!=5:
  while 0 in a:
    a.remove(0)
  b=sorted(a)
  print(y-(10-b[0]))
else:
  print(y)


Measured memory_bytes: 61972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int N,S;
    cin >> N >> S;
  
    if(N < 10){
        S = S + 100*(10 - N);
    }
  
    cout << S << endl;

}

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

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

  if(K > (N - 1) * (N - 2) / 2){
    cout << -1 << endl;
    return 0;
  }

  int M = N - 1 + (N - 1) * (N - 2) / 2 - K;
  cout << M << endl;

  for(int i = 2; i <= N; i++){
    cout << 1 << " " << i << endl;
  }

  int cnt = 0;
  for(int i = 2; i <= N; i++){
    for(int j = i + 1; j <= N; j++){
      if(cnt == (N - 1) * (N - 2) / 2 - K){
        return 0;
      }
      cout << i << " " << j << endl;
      cnt++;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll H, W;
	cin >> H >> W;
	char s[52][52];
	rep(i, H) {
		string S;
		cin >> S;
		rep(j, W) {
			s[i][j] = S.at(j);
		}

	}
	rep(i, H) {
		rep(j, W) {
			if (s[i][j] == '.')continue;
			if (i > 0 && s[i - 1][j] == '#') {
				continue;
			}
			else if (i <H-1 && s[i + 1][j] == '#') {
				continue;
			}
			else if (j < W - 1 && s[i][j+1] == '#') {
				continue;
			}
			else if (j >0 && s[i][j - 1] == '#') {
				continue;
			}
			else {
				cout <<"No" << endl; return 0;
			}

		}
	}
	cout << "Yes" << endl;
}


Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
 
  vector<int>A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  
  for (int i = 0; i < N-K; i++) {
    if (A.at(i) >= A.at(i+K)){
      cout << "No" << endl;
    }
    else {
      cout << "Yes" << endl;
    }
  }
}
    
      



Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    string s;
    cin>>s;
    bool win=(int)s.size()%2;
    win^=(s[0]==s.back());
    cout<<(win?"First":"Second")<<endl;
}


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

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

using namespace std;

template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    string s;
    cin >> s;
    int ans=0;
    int g=0,p=0;
    char self;

    rep(i,s.size()){
        if(i%2==0){
            self='g';
        }else{
            self='p';
        }

        if(s[i]==self){
            ans+=0;
        }else if(s[i]=='g' && self=='p'){
            ans+=1;
        }else{
            ans-=1;
        }
    }

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

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

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

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

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


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


int main() {
  int n,x,y;
  cin>>n>>x>>y;
  int g[n][n],h[n][n],ans[n]={0};
  rep(i,n) rep(j,n){
    g[i][j]=0;
    h[i][j]=0;
  }
  for(int i=0;i<n-1;i++){
    for(int j=1;j<n;j++){
      g[i][j]=j-i;
      h[i][j]=abs(x-1-i)+abs(y-1-j)+1;
    }
  }
  
  for(int i=0;i<n-1;i++){
    for(int j=1;j<n;j++){
      ans[min(g[i][j],h[i][j])]++;
    }
  }
  
 for(int i=1;i<n;i++) cout<<ans[i]<<endl;
  
}

Measured memory_bytes: 31488
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <bitset>

using namespace std;
using llong = long long;
using P = pair<llong,int>;

P items[100000];

int main(){
  int N;
  llong K;
  cin >> N >> K;
  int max_bit = 32;
  for(int i=0;i<N;++i){
    cin >> items[i].first >> items[i].second;
  }
  llong pow2max = 1LL << max_bit;

  llong max_val = 0;
  llong val = 0;
  for(int j=0;j<N;++j){
    if((items[j].first | K) == K ) val += items[j].second;
  }
  if(val > max_val) max_val = val;

  for(int i=0;i<max_bit;++i){
    llong pow2 = 1LL << i;
    if((K&pow2)==0) continue;
    llong X = (pow2-1 | K) ^ pow2;
    val = 0;
    for(int j=0;j<N;++j){
      if((items[j].first | X) == X ) val += items[j].second;
    }
    if(val > max_val) max_val = val;
  }
  cout << max_val << endl;
  
  return 0;
}

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

int main() {
	int A1, A2, A3;

	cin >> A1 >> A2 >> A3;
	if (A1 + A2 + A3 <= 21) {
		cout << "win" << endl;
	}
	else {
		cout << "bust" << endl;
	}

	return 0;
}

Measured memory_bytes: 256