akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
	int n; cin >> n;
	int a[n] = {};
	for (int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n, greater<int>());
	ll ans = 0;
	int half = (n + 1) / 2;
	ans += accumulate(a, a + half - 1, 0LL);
	ans += accumulate(a + 1, a + 1 + n - half, 0LL);
	if (n % 2 == 0) 
		ans -= a[half], ans += a[half - 1];
	cout << ans << "\n";
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;
typedef vector<string> vs;
typedef vector<bool> vb;

const ll mod=998244353;
const ll inf=1e16;

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m-1;i>=n;i--)
#define fi first
#define se second
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
#define eb(x) emplace_back(x)
#define all(x) x.begin(),x.end()
#define gll greater<ll>()

const ll mx=1e18;

void add(ll &x, ll y){
  y%=mod;
  x+=y;
  x%=mod;
}

void solve(){
 ll n,s;
 cin >> n >> s;
 vll a(n);
  rep(i,0,n) cin >> a[i];
  
 vvll dp(n+1,vll(s+1,0));
  dp[0][0]=1;
 
  rep(i,0,n){
    rep(j,0,s+1){
    add(dp[i+1][j],2*dp[i][j]);
    if(j+a[i]<=s) add(dp[i+1][j+a[i]],dp[i][j]);
    }
  }
  
  cout << dp[n][s] << endl;
}
int main(){
   cin.tie(nullptr);
  ios::sync_with_stdio(false);
  solve();
}  

Measured memory_bytes: 73648
#include <iostream>
#include <sstream>
#include <iomanip>
#include <utility>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>

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

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; }

using namespace std;

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

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

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

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

class UnionFind {
private:
    vector<int> parents;

    int root(int A) {
        if (parents[A] < 0) return A;
        return parents[A] = root(parents[A]);
    }

public:
    UnionFind(int N)
    : parents(N, -1)  // -なら親
    {
    }

    bool merge(int A, int B) {
        int rA = root(A);
        int rB = root(B);
        if (rA == rB) return false;
        if (parents[rA] < parents[rB]) swap(rA, rB);
        parents[rA] += parents[rB];
        parents[rB] = rA;
        return true;
    }

    ll size(int A) {
        return -parents[root(A)];
    }
};

#define Max 110000
ll N, M;
int A[Max], B[Max];
ll ans[Max];

int main(int argc, const char * argv[]) {
    N = inputValue();
    M = inputValue();
    rep(i, M) {
        A[i] = inputValue() - 1;
        B[i] = inputValue() - 1;
    }

    UnionFind uf(N);
    ll count = N * (N-1)/2;
    for (auto i = M-1; i >= 0; --i) {
        ans[i] = count;
        ll diff = uf.size(A[i]) * uf.size(B[i]);
        bool res = uf.merge(A[i], B[i]);
        if (res) {
            count -= diff;
        }
    }

    rep(i, M) {
        output(ans[i]);
    }

    return 0;
}


Measured memory_bytes: 3328
#include <stdio.h>
int main(){
  int n,i,I;
  scanf("%d",&n);
  int a[n];
  int tmp,count =0 ;
  for(i = 0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int j;
  for(i = 0;i<n-1;i++){
    for(j = n-1;j >= i+1;j--){
      if(a[j] < a[j-1]){
	count ++;
	tmp = a[j];
	a[j] = a[j-1];
	a[j-1]= tmp;
      }
    }
  }
  for(i=0;i<n-1;i++){
    printf("%d ",a[i]);
  }
  printf("%d\n",a[i]);
  printf("%d\n",count);
  return 0;
}
  
	

Measured memory_bytes: 2728
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int h[n];
  rep(i,n) cin >> h[i];
  int ma = h[0];
  int ans=1;
  repi(i,1,n){
    if(ma<=h[i]){
      ans++;
      ma = max(ma,h[i]);
    }
  }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

ll H,W,N;
bool IsInField(int x, int y){
	if(0<x&&x<H-1&&0<y&&y<W-1){
		return true;
	}
	else{
		return false;
	}
}
int main() {
	cin>>H>>W>>N;
	vector<P> ab;
	rep(i,N){
		int a,b;
		cin>>a>>b;
		ab.push_back({a,b});
	}
	sort(all(ab));
	printpair(ab);
	map<P, ll> map;
	for (int i = 0; i < N; ++i){
		int x = ab[i].first;
		int y = ab[i].second;
		for (int j = 0; j <= 2; ++j){
			for (int k = 0; k <= 2; ++k){
				if(IsInField(x - j,y - k)){
					map[{x - j, y - k}]++;
				}
			}
		}
	}
	vector<ll> ans(10);
	ans[0] = (H-2)*(W-2);
	for(auto x: map){
		ans[x.second]++;
		ans[0]--;
	}
	for (int i = 0; i < 10; ++i){
		cout<<ans[i]<<endl;
	}
}

Measured memory_bytes: 57332
#include <iostream>
#include <string>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short SHORT;
typedef unsigned short USHORT;
typedef int INT;
typedef unsigned int UINT;
typedef long long LLONG;
typedef unsigned long long ULLONG;

#define LengthOf(x)    (sizeof(x) / sizeof(x[0]))


#if 0
//No.2
int main()
{

	return 0;
}
#endif

#if 1
//No.1
int main()
{
	INT K, A, B;
	cin >> K >> A >> B;

	int i;
	for (i = A; i <= B; ++i) {
		if (i % K == 0) { cout << "OK"; break; }
	}
	if (i > B) {
		cout << "NG";
	}

	return 0;
}
#endif


Measured memory_bytes: 3648
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n, c = ns()
    l = 10 ** 5
    table = [[0 for _ in range(l + 10)] for __ in range(c)]

    for _ in range(n):
        s, t, ci = ns()
        ci -= 1
        table[ci][s] += 1
        table[ci][t] -= 1

    ans = 0
    tmp = 0
    for i in range(l + 10):
        fin = 0
        for j in range(c):
            if table[j][i] > 0:
                tmp += table[j][i]
            else:
                fin += table[j][i]
        ans = max(ans, tmp)
        tmp += fin
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 181964
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;


 
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    ll h,w,m;
    cin>>h>>w>>m;
    map<ll,ll> x,y;
    ll u,v;
    set<pair<ll,ll>> s;
    for(ll i=0;i<m;i++){
        cin>>u>>v;
        x[u]++;
        y[v]++;
        s.insert({u,v});
    }
    ll xm=0,ym=0;
    for(auto p:x)
        xm=max(xm,p.second);
    for(auto p:y)
        ym=max(ym,p.second);
    set<ll> xs,ys;
    for(auto p:x)
        if(p.second==xm)
            xs.insert(p.first);
    for(auto p:y)
        if(p.second==ym)
            ys.insert(p.first);
    ll xt=xs.size(), yt=ys.size();
    ll tot=0;
    for(pair<ll,ll> v:s){
        ll x1=v.first, x2=v.second;
        bool ok1=xs.find(x1)!=xs.end();
        bool ok2=ys.find(x2)!=ys.end();
        if(ok1 && ok2)
            tot++;
    }
    if(tot<xt*yt)
        cout<<xm+ym;
    else
        cout<<xm+ym-1;

    cerr<<"\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}


Measured memory_bytes: 88168
#include<iostream>
using namespace std;
unsigned int a,n;
int IsPrime(int n)
{
    int i;
 
    if (n < 2)
        return 0;
    else if (n == 2)
        return 1;
 
    if (n % 2 == 0)
        return 0;
 
    for (i = 3; i <= n / i; i += 2)
        if (n % i == 0)
            return 0;
    return 1;
}
int main() {
    int temp=0,flag=0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (IsPrime(a) == 1)temp++;
    }
    cout << temp << endl;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define lli   long long int
#define pb push_back
#define rep(i,s,n) for(lli i=s;i<n;i++)
#define irep(i,n,s) for(lli i=n-1;i>=s;i--)
#define mp make_pair
#define mod 1000000007
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio;
    cin.tie(NULL);
    int i, j, k, m, n, t;
    // cin >> t;
    t = 1;
    while (t--)
    {
        float d, tm, s;
        cin >> d >> tm >> s;
        float req = d / s;
        if (req <= tm)
        {
            cout << "Yes";
        }
        else
        {
            cout << "No";
        }





    }



}




Measured memory_bytes: 3720
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

string s;
map<int,int>mp;
map<int,bool>used;
signed main(){
	cin>>s;
	int now=0;
	used[0]=true;
	rep(i,len(s)){
		now^=1<<(s[i]-'a');
		if(i==len(s)-1){
			if(used[now])mp[now]++;
		}
		rep(j,26){
			if(used[now^(1<<j)]){
				if(!used[now]){
					used[now]=true;
					mp[now]=mp[now^(1<<j)]+1;
				}else {
					chmin(mp[now],mp[now^(1<<j)]+1);
				}
			}
		}
	}
	cout<<mp[now]<<endl;
}


Measured memory_bytes: 284036
#include <iostream>

using namespace std;
int main(){
    string s;
    cin>>s;
    string Code="CODEFESTIVAL2016";
    int temp=0;
        for(int i=0;i<16;i++){
        if(s[i]!=Code[i]){
                    temp++;
                }
            }


    cout<<temp<<endl;
    return 0;
}



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

int D, G;
//vector<int> p(D), c(D);
vector<int> p(20), c(20);

int ans = 1e9;

void rec(int sum, int counter, int i, vector<bool> D_bool) {
  if (i == D) {
    if (sum >= G) {
      ans = min(ans, counter);
    }
    else {
      rrep(j,D-1) {
        if (D_bool.at(j)) 
          continue;
        else {
          for (int l = 0; l < p.at(j)-1 && sum < G; l++) {
            sum += 100*(j+1);
            counter++;
          }
          if (sum >= G) {
            ans = min(ans,counter);
            break;
          }
        }
      }
    }
  }
  else {
    D_bool.at(i) = false;
    rec(sum, counter, i+1, D_bool);
    
    D_bool.at(i) = true;
    rep(j,p.at(i)) {
      sum += 100*(i+1);
      counter++;
    }
    sum += c.at(i);
    rec(sum, counter, i+1, D_bool);
  }
}

int main() {
  cin >> D >> G;
  rep(i,D) cin >> p.at(i) >> c.at(i);
  
  vector<bool> vec_bool(D, false);
  
  rec(0,0,0,vec_bool);
  
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 256
/*Writer : Md. Shafiur Rahman Dipu */

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

#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define pi acos(-1.0)
#define INF 2e12

#define ull unsigned long long
#define ll long long
#define ld long double

#define pb push_back

#define mx 5000005
#define mod 1000000007

long long poW(long long base, long long power) {
    long long result = 1;
    while(power > 0) {

        if(power & 1) {
            result = (result*base) ;
        }
        base = (base * base);
        power = power / 2;
    }
    return result;
}

int ar[100005];
ll dp[100005];
int n;
ll func(int pres){
    if(dp[pres]>0){
        return dp[pres];
    }
    if(pres >= n-1){
        return 0;
    }
    if(pres == n-2){
        return dp[pres] = abs(ar[pres]-ar[pres+1]);
    }

    ll a = abs(ar[pres]-ar[pres+1]) + func(pres+1);
    ll b = abs(ar[pres]-ar[pres+2]) + dp[pres+2];

    //cout << a <<  " " << b << endl;
    return dp[pres] = min(a,b);

}


int main()
{
    #ifdef dipu
    //freopen("inp.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    while(1){
    #endif
    FASTER
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> ar[i];
    }
    memset(dp,0,sizeof dp);
    ll res = func(0);

    cout << res << endl;

    #ifdef dipu
    }
    #endif // dipu


    return 0;
}


Measured memory_bytes: 4608
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>  
#include <stdlib.h> 
#include <stdio.h>  
#include <string>
#include <string.h>
#include <math.h>  
#include <time.h>
#include <list>
#include <map>  
#include <queue>  
#include <set>
#include <stack>
#include <vector>  
#include <algorithm>
#define ms(a) memset(a,0,sizeof(a)) 
#define inf 0x3f3f3f3f
#define MAX 100010
#define MX 10010
#define ll long long
using namespace std;
struct node
{
	int data;
	node *lch,*rch,*par;
}*root,*null;
void insert(int k)
{
	node *cur=root,*res=null,*ins=(node*)malloc(sizeof(node));
	ins->data=k;
	ins->lch=null;
	ins->rch=null;
	while (cur!=null)
	{
		res=cur;
		if(ins->data<cur->data)cur=cur->lch;
		else cur=cur->rch;
	}
	ins->par=res;//定?父?点
	if(res==null)root=ins;//第一次插入
	else{//定?左右子
		if(ins->data<res->data)res->lch=ins;
		else res->rch=ins;
	}
}
void inorder(node *cur)
{
	if(cur==null)return;
	inorder(cur->lch);
	printf(" %d",cur->data);
	inorder(cur->rch);
}
void preorder(node *cur)
{
	if(cur==null)return;
	printf(" %d",cur->data);
	preorder(cur->lch);
	preorder(cur->rch);
}
int main()
{
	int n,m;
	char oper[10];
	scanf("%d",&n);
	for (int i = 0; i < n; i++)
	{
		scanf("%s",&oper);
		if(oper[0]=='i'){
			scanf("%d",&m);
			insert(m);
		}
		else if(oper[0]=='p'){
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26668
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>

#define FOR(i, f, n) for(int (i) = (f); (i) < (n); (i)++)
#define RFOR(i, f, n) for(int (i) = (f); (i) >= (n); (i)--)
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for(int (i) = (n); (i) >= 0; (i)--)
#define step(i, f, n, a) for(int (i) = (f); (i) < (n); (i)+=a)
#define rstep(i, f, n, a) for(int (i) = (f); (i) >= (n); (i)-=a)
#define p(...) printf(__VA_ARGS__); cout << endl;
#define gets(x) x; cin >> x;
#define puts(x) x; cout << x << endl;
#define list_input(x, n) x[(n)]; for(int (i) = 0; (i) < (n); (i)++) cin >> x[i];
#define lambda(a, b, c) [](const a, const b){ return c ;}
#define key(t, x, compare) [](const t& a, const t& b){ return a x compare b x ;}

using namespace std;

using pii = pair<int, int>;

int main(){
  int aindex, zindex, result;
  string s;
  gets(s)
  aindex = s.find('A');
  zindex = s.rfind('Z');
  result = zindex - aindex +1;
  puts(result)
}


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

class Calc_Mod{//mod演算用クラス
    public:
        unsigned int mod=1000000007;
        ll plus_mod(ll a,ll b){
            return (a+b)%mod;
        }
        ll minus_mod(ll a,ll b){
            return (a-b)%mod;
        }
        ll multi_mod(ll a,ll b){
            return a*b%mod;
        }
        ll LSM(ll a,int b){//a^b%mod
            queue<int> q;
            while(b>=1){
                q.push(b%2);
                b/=2;
            }
            ll ans=1;
            while(!q.empty()){
                if(q.front()==1){
                    ans=multi_mod(ans,a);
                }
                a=multi_mod(a,a);
                q.pop();
            }
            return ans;
        }
        ll div_mod(ll a,ll b){// a/b
            return multi_mod(a,LSM(b,mod-2));
        }
};

int main()
{
    Calc_Mod mod;

    int X,Y;
    cin >> X >> Y;
    int val;
    if((X+Y)%3!=0){
        cout << 0 << endl;
        return 0;
    }else{
        int range=(X+Y)/3;
        int ans=0;
        queue<int> q;
        rep(n,range+1){
            if(n+2*(range-n)==X&&2*n+(range-n)==Y){
                q.push(n);
            }
        }
        while(!q.empty()){
            val=q.front();
            ll up_kaijo=1;
            ll kaijo=1;
            val=min(range-val,val);
            rep(i,val){
                up_kaijo=mod.multi_mod(up_kaijo,range-i);
                kaijo=mod.multi_mod(kaijo,val-i);
            }
            ans=mod.plus_mod(ans,mod.div_mod(up_kaijo,kaijo));
            q.pop();
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
from itertools import product

d, g = map(int, input().split())
q = [list(map(int, input().split())) for _ in range(d)]

bits = product((0, 1), repeat=d)

least_cnt = float('inf')

for bit in bits:
    sum_of_points = 0
    cnt = 0
    cnt_increment = 0
    
    for i in range(d):
        if bit[i]:
            sum_of_points += 100*(i+1)*q[i][0] + q[i][1]
            cnt += q[i][0]
    
    if sum_of_points < g:
        for i in reversed(range(d)):    # 大きい方から探す
            if not bit[i]:
                if sum_of_points + 100*(i+1)*q[i][0] < g:   # ほぼ全問解いても点数が足りない
                    continue
                while sum_of_points < g:
                    sum_of_points += 100*(i+1)
                    cnt += 1
                break
    if sum_of_points >= g:
        least_cnt = min(least_cnt, cnt)

print(least_cnt)

Measured memory_bytes: 41072
n = gets.to_i
t = gets.chomp.split.map &:to_i


h = Hash.new(0)
t.each do |d|
  h[d] += 1
end
t = t.uniq.sort{|a,b|b<=>a}
f = true


if(h[t[0]] != 1)
  f = false
end


tree  = Array.new(n, 0)
max   = Array.new(n, 0)
n.times{|i|max[i] = 2**i}
t.shift


t.each do |d|
  able  = 1
  stock = h[d]
  n.times do |i|
    plable = tree[i]
    if(tree[i]<max[i])
      note    = [[max[i]-tree[i], able-tree[i], stock].min, 0].max
      tree[i] += note
      stock   -= note
    end
    able  += plable
  end
  f = false if(stock != 0)
end


puts (f)? "Yes" : "No"

Measured memory_bytes: 58380
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

// a^{-1} mod を計算する
long long modinv(long long a, long long mod) {
  return modpow(a, mod - 2, mod);
}

//                123456789
const int kMod = 1000000007;
ll F[200005];
ll IF[200005];

ll comb(ll N, ll a) {
  // return F[N] / (F[N - a] * F[a]);
  return F[N] * IF[N - a] % kMod * IF[a] % kMod;
}

ll Count(ll N, ll z) {
  return comb(N - 1, N - z - 1);
}

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

  // fill F[] and IF[]
  F[0] = 1;
  for (int i = 1; i <= N; ++i) {
    F[i] = i * F[i - 1] % kMod;
  }
  for (int i = 0; i <= N; ++i) {
    IF[i] = modinv(F[i], kMod);
  }

  ll ans = 0;
  for (int z = 0; z <= min(K, N - 1); ++z) {
    ll tmp = Count(N, z) * comb(N, z) % kMod;
    ans = (ans + tmp) % kMod;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

ll x[100001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; ll a, b;
	cin>>n>>a>>b;
	for(int i = 0; i < n; i++)
	{
		cin>>x[i];
	}
	ll ans = 0;
	for(int i = 1; i < n; i++)
	{
		ll d = x[i]-x[i-1];
		if(a*d<=b)
		{
			ans+=a*d;
		}
		else
		{
			ans+=b;
		}
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
//vector<int> is passed by &
#define maxholidays 100000

int dp[maxholidays][3];
vector<vector<int>> joy;

int getMostJoyToDay(int D, int A)
{
	if(dp[D][A]!=-1)
		return dp[D][A];

	if(D==0)
		return joy[D][A];

	if(A==0)
		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,1) , getMostJoyToDay(D-1,2) );
	else if(A==1)
		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,0) , getMostJoyToDay(D-1,2) );
	else //(A==2)
		return dp[D][A] = joy[D][A] + max( getMostJoyToDay(D-1,0) , getMostJoyToDay(D-1,1) );
}


int main()
{
	for(int i=0;i<maxholidays;i++)
		for(int j=0;j<3;j++)
			dp[i][j]=-1;

	int n;	
	cin >> n ;
	int t;
	for(int i=0;i<n;i++)
	{
		vector<int> x;
		for(int j=0;j<3;j++)
		{
			cin >> t;
			x.push_back(t);
		}
		joy.push_back(x);
	}
	int a = getMostJoyToDay(n-1,0);
	int b = getMostJoyToDay(n-1,1);
	int c = getMostJoyToDay(n-1,2);
	cout << max(max(a,b),c) <<endl;

	return 0;
}

Measured memory_bytes: 14512
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
 
const int N = int(2e5) + 2;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e18; 
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int n, a[N];
int main (){
    scanf ("%d", &n);
    map < int, int > cnt;
    for (int i = 1; i <= n; ++i) scanf ("%d", a + i), cnt[a[i]]++;
    if (cnt[0] == n) return !printf ("Yes\n");
    if (n % 3 != 0) return !printf ("No\n");
    vector < int > cur;
    for (auto to : cnt){
        for (int i = 0; i < to.se / (n / 3); ++i) cur.pb(to.fi);
    }
    if (sz(cur) == 3 && (cur[0] ^ cur[1] ^ cur[2]) == 0) return !printf ("Yes\n");
    else return !printf ("No\n");
}

Measured memory_bytes: 4224
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
#define CONTAINS_SET(m, a) (m).find((a)) != m.end()
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
//void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


signed main()
{
	int a, b;
	cin >> a >> b;
	
	int ans = (a + b) / 2;
	if ((a + b) % 2 != 0) ans++;

	cout << ans << endl;
}




Measured memory_bytes: 3548
#include<bits/stdc++.h>
#include<iostream>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>=n;--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define here(s)      cout<<s<<endl;
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


typedef long long ll;


int main()
{
    run;
   ll n,k;
   cin>>n>>k;
   ll h[n];
   fr(i,0,n)
   {
       cin>>h[i];
   }
   sort(h,h+n);
   reverse(h,h+n);
   ll s=0;
   fr(i,k,n)
   {
       s+=h[i];
   }
   cout<<s;




    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

int ctoi(const char c)
{
    if ('0' <= c && c <= '9')
        return (c - '0');
    return -1;
}

int main(){
    vector<char> n(4);
    REP(i,4){
        cin >> n[i];
    }

    sort(n.begin(), n.end());

    if(n[0]=='1' and n[1]=='4' and n[2]=='7' and n[3]=='9'){
        cout << "YES"<< endl;
        return 0;
    }
    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = a; i < (n); i++)
#define rrep(i, n, k) for (int i = (n); i >= (k); i--);
#define all(x) (x).begin(), (x).end()
#define vi vector<int>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>vector<T> make_vector(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto make_vector(size_t a, Ts... ts){return vector<decltype(make_vector<T>(ts...))>(a, make_vector<T>(ts...));}
const int MOD = 1e9 + 7;
const int INF = 9e18;

signed main() {
    int N;
    string S;
    cin >> N >> S;
    int Q;
    cin >> Q;
    vector<int> k(Q);
    cin >> k;
    for (int range : k) {
        int ans = 0;
        int D = 0, M = 0, sum = 0;
        for (int i = 0; i < range; i++) {
            if (S[i] == 'D') D++;
            if (S[i] == 'M') {
                M++;
                sum += D;
            }
            if (S[i] == 'C') ans += sum;
        }
        for (int i = 0; i + range < N; i++) {
            if (S[i] == 'D') {
                sum -= M;
                D--;
            }
            if (S[i] == 'M') M--;
            if (S[i + range] == 'D') D++;
            if (S[i + range] == 'M') {
                M++;
                sum += D;
            }
            if (S[i + range] == 'C') ans += sum;
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 1412
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iomanip>
using namespace std;

int main() {
  while(true){
    int n;
    cin >>n;
    
    if(n==0) break;
    
    vector<int> score(n);
    double m=0,a=0;
    for(int i =0;i<n;i++){
      cin >> score.at(i);
      m+=score.at(i);
    }
    m/=n;
    for(int i =0;i<n;i++){
      a+=(pow(score.at(i)-m,2));
    }
    a=sqrt(a/n);
    
    cout << std::fixed << std::setprecision(8) << a << endl;
  }
}


Measured memory_bytes: 3244
#include<iostream>

using namespace std;

main(){
  int a,b,c;
  cin>>a>>b;
  c = a+b;
  if(c%3 == 0 || a%3 == 0 || b%3 == 0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
  return 0;
}

Measured memory_bytes: 256
def gcd(x, y):
    if x < y:
        a, b = x, y
    else:
        a, b = y, x

    while True:
        r = a % b
        if r == 0:
            break
        a, b = b, r

    return b


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

ans = abs(X - x[0])

for i in range(1, N):
    ans = gcd(ans, abs(X - x[i]))

print(ans)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    string s, t;
    cin >> N >> s >> t;

    rep(i, N) {
        bool flag = true;
        rep(j, N - i) {
            if (t[j] != s[i + j]) {
                flag = false;
                break;
            }
        }
        if (flag) {
            cout << N + i << endl;
            return 0;
        }
    }

    cout << N * 2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int H,M,h,m,k;
    cin>>H>>M>>h>>m>>k;
    int A,B,ans;
    A=60*H+M;
    B=60*h+m;
    ans=B-A-k;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <queue>

int main()
{
    int n, m;
    std::cin >> n >> m;

    std::priority_queue<int> queue;

    for (int i = 0; i < n; i++) {
        int temp;
        std::cin >> temp;

        queue.push(temp);
    }

    for (int i = 0; i < m; i++) {
        int temp = queue.top() / 2;
        queue.pop();
        queue.push(temp);
    }

    long long ans = 0;
    while (queue.size()) {
        ans += queue.top();
        queue.pop();
    }

    std::cout << ans << std::endl;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N,M;cin>>N>>M;
  vector<long long>DP(N,-1);
  DP[0]=1;DP[1]=2;
  for(int X=0;X<M;X++){
    int G;cin>>G;DP[G-1]=0;
  }
  if(DP[0]==0&&DP[1]!=0)DP[1]=1;
  for(int X=2;X<N;X++){
    if(DP[X]!=0){
      DP[X]=DP[X-1]+DP[X-2];
      DP[X]%=1000000007;
    }
  }
  cout<<DP[N-1]<<endl;
}

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

int sumofdigits(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int main() {
  int n;
  std::cin >> n;
  int min = 1000;
  for (int a = 1; a < n; a++) {
    int b = n - a;
    int sum = sumofdigits(a) + sumofdigits(b);
    if (sum < min) {
      min = sum;
    }   
  }
  std::cout << min << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define WHITE 0 // ????¨??????????????????????????????°
#define GRAY 1 // ??¢?´¢?????????????????????????????°
#define BLACK 2 // ??¢?´¢????????????????????????????????°

int n,/* ????????° */ M[N][N]; /* ??£??\?????? */
int color[N],/* ??????i????¨??????¶??? */ d[N],/* ??????i?????????????¨?????????????????????? */ f[N],/* ??????i?????£??\??????????????????????????????????????? */ tt /* ?????? */;

// ?????°??¢??°???????????±???????????¢?´¢
void dfs_visit(int u){
	int v; // ??¢?´¢?????????????????????
	color[u] = GRAY;
	d[u] = ++tt; // ??????????¨????
	for(v=0;v<n;v++){
		if(M[u][v] == 0) continue; // ??????u????????????v????????????????????¨?????????
		if(color[v] == WHITE){
			dfs_visit(v); // ??????v????¨???????????????¨??????????????°???v??????????????¢?´¢???????§???????
		}
	}
	color[u] = BLACK; // ??¢?´¢??????????????????BLACK?????°????????????
	f[u] = ++tt; // ????????????
}

void dfs(){
	int u;
	// ?????????
	for(u=0;u<n;u++) color[u] = WHITE;
	tt = 0;

	for(u=0;u<n;u++){
		// ????¨???????u????§??????¨????????±???????????¢?´¢
		if(color[u] == WHITE) dfs_visit(u);
	}
	for(u=0;u<n;u++){
		printf("%d %d %d\n",u+1,d[u],f[u]);
	}
}


int main(){
	int u,v,k,i,j; // u:??????????????? k:u???????¬???° v:??£??\?????????????????????

	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(j=0;j<n;j++) M[i][j] = 0; // ??£??\??????????????????
	}

	for(i=0;i<n;i++){
		scanf("%d %d",&u,&k);
		u--;
		for(j=0;j<k;j++){
			scanf("%d",&v);
			v--;
			M[u][v] = 1;
		}
	}

	dfs();

	return 0;
}

Measured memory_bytes: 2688
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

ll mod_pow(int a, int n){
    ll ret = 1;
    FOR(i, 0, n){
        ret *= a;
        ret %= mod;
    }
    return ret;
}

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

    // input
    ll N;
    cin >> N;

    vector<int> A(N);
    map<int, int> mp;
    FOR(i, 0, N){
        int a;
        cin >> a;
        A[i] = a;

        mp[a]++;
    }

    sort(ALL(A));

    if(N%2==0){
        for(int i=1; i<N; i+=2){
            if(mp[i]!=2){
                p(0);
                return 0;
            }
        }
    }
    // 奇数
    else{
        if(mp[0] != 1){
            p(0);
            return 0;
        }

        for(int i=2; i<N; i+=2){
            if(mp[i]!=2){
                p(0);
                return 0;
            }
        }
    }

    // チェックが通った状態
    
    int n = N / 2;
    p(mod_pow(2, n));

    return 0;
}

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

using namespace std;

int n,x;
long long sum = 0;
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    int mn = 1e9 + 233;
    int minus = 0;
    for (int i = 1 ; i <= n ; i++)
        {
            cin >> x;
            sum += (long long )abs(x);
            if (x < 0 ) minus++;
             if ( abs(x) < mn ) mn = abs(x);
        }

    if (minus & 1)
        cout << sum - 2 * mn << endl;
    else 
        cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>){
    val N = nextInt()
    val P = listOfInt()
    var count = 0
    for (n in 0 until N) {
        if (P[n] != n + 1) count++
    }
    println(if (count <= 2) "YES" else "NO")
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }


Measured memory_bytes: 37904
/** Author : Parth Prajapati
 * 	Institute : Pandit Deendayal Petroleum University
**/
#include<bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k,i,j;
    cin>>n;
    k=2;
    long long int h[n],dp[n];
    for(i=0;i<n;++i)    cin>>h[i];
    dp[0] = 0;
    //cout<<"0 ";
    for(i=1;i<n;++i)    dp[i] = pow(10,10);
    for(i=1;i<n;++i)
    {
        for(j=i-1;j>=(i-k) && j>=0;--j)
        {
            dp[i] = min(dp[i] , dp[j]+abs(h[i]-h[j]));
        }
        //cout<<dp[i]<<" ";
    }
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end();
int main() {
  int a,b,ans=1;
  cin >> a >> b;
  rep(i,a){
    ans += min(ans,b);
  }
  cout << ans;
}

Measured memory_bytes: 3540
def main():
    def b_search(a, b, value, delta):
        while True:
            med = (a+b)/2
            if abs(b-a) < delta:
                if value(b):
                    return b
                else:
                    return a
            elif value(med):
                a = med
            else:
                b = med

    x1, y1 = map(int, input().split())
    x2, y2 = map(int, input().split())
    x3, y3 = map(int, input().split())

    a = ((x1-x2)**2+(y1-y2)**2)**0.5
    b = ((x2-x3)**2+(y2-y3)**2)**0.5
    c = ((x3-x1)**2+(y3-y1)**2)**0.5

    m = max(a, b, c)
    if a == m:
        l = a
    elif b == m:
        x1, x2, x3 = x2, x3, x1
        y1, y2, y3 = y2, y3, y1
        l = b
    else:
        x1, x2, x3 = x3, x1, x2
        y1, y2, y3 = y3, y1, y2
        l = c

    x2 -= x1
    x3 -= x1
    y2 -= y1
    y3 -= y1
    x1, y1 = 0, 0

    if x2 < 0:
        x2 = -x2
        x3 = -x3
    if y2 < 0:
        y2 = -y2
        y3 = -y3

    cos = x2/l
    sin = -(1-cos**2)**0.5

    x2, y2 = l, 0
    x3, y3 = abs(cos*x3-sin*y3), abs(sin*x3+cos*y3)

    a = l
    b = (x3**2+y3**2)**0.5
    c = ((x2-x3)**2+(y2-y3)**2)**0.5

    def value(x):
        t1 = x*y3/x3
        t2 = (x2-x)*y3/(x2-x3)
        s1 = t1*x/2
        s2 = t2*(a-x)/2
        r1 = (2*s1)/(x+t1+(x**2+t1**2)**0.5)
        r2 = (2*s2)/((a-x)+t2+((a-x)**2+t2**2)**0.5)
        if r1 < r2:
            return True
        else:
            return False

    def value2(x):
        t1 = x*y3/x3
        s1 = t1*x/2
        r1 = (2*s1)/(x+t1+(x**2+t1**2)**0.5)
        return r1

    v = b_search(0, l, value, 10**(-12))
    print(value2(v))


main()


Measured memory_bytes: 3316
import java.util.Scanner;

public class Main {

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

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		System.out.println(c(n)+c(m));
		sc.close();
	}

	private long c(int n) {
		if(n==0) return 0;
		return(n*(n-1))/2;
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i,n) for (int i = 1; i < (int)(n+1); i++)
#define N_MAX 110
#define K_MAX 100010

const int INF = 1001001001;

int main() {
  int N;
  cin >> N;
  
  vector<int> W(N);
  rep(i,N){
    cin >> W.at(i);
  }

  int res = INF;
  for(int t = 0; t < N; t++){
    int S1 = 0;
    int S2 = 0;
    for(int i = 0; i <= t; i++){
      S1 += W.at(i);
    }
    for(int i = t+1; i <N ; i++){
      S2 += W.at(i);
    }
    res = min(res,abs(S1-S2));
  }

  cout << res << endl;
}

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





int main(void){
    // 自分の得意な言語で
    // Let's チャレンジ！！
    int A,B;
    cin>>A>>B;


    int x,y,z;
    int max;
    max= A+B;
    if(max<(A-B)){
        max=A-B; 
    }

    if(max<(A*B)){
        max=A*B;
    }
    
    cout<<max<<endl;



    return 0;
}


//3 人は同時に、他の 2 人の持っている整数の和を求める。
//その後、自分の持っている整数を求めた整数で置き換える。

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
H, W, K = map(int, input().split())
B = {}
for _ in range(K):
    r, c, v = map(int, input().split())
    B[(r, c)] = v

dp = [[0]*4 for _ in range(W+1)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if (i, j) in B:
            v = B[(i, j)]
            dp[j][0] = max(dp[j-1][0], dp[j][0], dp[j][1], dp[j][2], dp[j][3])
            dp[j][1] = max(dp[j-1][1], dp[j][0]+v)
            dp[j][2] = max(dp[j-1][2], dp[j-1][1]+v)
            dp[j][3] = max(dp[j-1][3], dp[j-1][2]+v)
        else:
            dp[j][0] = max(dp[j-1][0], dp[j][0], dp[j][1], dp[j][2], dp[j][3])
            dp[j][1] = dp[j-1][1]
            dp[j][2] = dp[j-1][2]
            dp[j][3] = dp[j-1][3]

print(max(dp[-1]))


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int ISPRIME_SIZE=11111111;
bool isprime[ISPRIME_SIZE];
struct isprime_exec{
    isprime_exec(){
        for(int i=0;i<ISPRIME_SIZE;i++)isprime[i]=true;
        isprime[0]=isprime[1]=false;
        for(int i=2;i<ISPRIME_SIZE;i++){
            if(!isprime[i])continue;
            for(int j=i+i;j<ISPRIME_SIZE;j+=i)isprime[j]=false;
        }
    }
}isprimeexec;

int a[111111];

signed main(){
    for(int i=1;i<111111;i++){
        if(isprime[i]&&isprime[(i+1)/2])a[i]++;
        a[i]+=a[i-1];
    }
    int Q;cin>>Q;
    while(Q--){
            int l,r;cin>>l>>r;
            cout<<a[r]-a[l-1]<<endl;
        
    }
}

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

int main(void){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int k,a,b;
    cin >> k >> a >> b;

    bool flag = false;

    for(int i = a;i<=b;i++){
        if(i%k==0){
            flag = true;
            break;

        }
    }
    if(flag){
        cout << "OK" << endl;
    }else{
        cout << "NG" << endl;
    }


    return 0;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define N 100001
using namespace std;
#define LL long long 

int main()
{
	LL n,k,x,y,ans=0;
	cin>>n>>k>>x>>y;
	if(k<n)
	{
		ans+=x*k;
		ans+=(n-k)*y;
	}
	else 
	{
		ans+=x*n;
	}
	
	cout<<ans<<endl;
	
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100
 
void Preorder(int);
void Inorder(int);
void Postorder(int);
 
struct Node{
  int parent, left, right;
};
  
struct Node Tree[MAX];
int n;
 
void Preorder(int i){
  printf(" %d",i);
  if ( Tree[i].left != -1 ) Preorder( Tree[i].left );
  if ( Tree[i].right != -1 ) Preorder( Tree[i].right );
}
 
void Inorder(int i){
  if( Tree[i].left != -1 ) Inorder( Tree[i].left );
  printf(" %d",i);
  if( Tree[i].right != -1 ) Inorder( Tree[i].right);
}
   
void Postorder(int i){ 
  if( Tree[i].left != -1 ) Postorder( Tree[i].left );
  if( Tree[i].right != -1 ) Postorder( Tree[i].right );
  printf(" %d",i);
   
}
 
int main(){
  int root = 0,i,j,a;
  scanf("%d",&n);
  
  for( i = 0 ; i < n ; i++ ){
    Tree[i].parent = -1;
    Tree[i].left = -1;
    Tree[i].right = -1;
  }
 
  for( i = 0; i < n ; i++ ){
    scanf("%d", &a);
    scanf("%d %d", &Tree[a].left, &Tree[a].right);
    if(Tree[a].left != -1) Tree[Tree[a].left].parent = a;
    if(Tree[a].right != -1) Tree[Tree[a].right].parent = a;
  }
 
  for( i = 0 ; i < n ; i++ ){
    if( Tree[i].parent == -1 ) root = i;
  }
 
  printf("Preorder\n");
  Preorder(root);
 
  printf("\nInorder\n");
  Inorder(root);
 
  printf("\nPostorder\n");
  Postorder(root);
  printf("\n");
 
  return 0;
}
 

Measured memory_bytes: 616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define se second
int main(){
	ll h1,m1,h2,m2,k; cin>>h1>>m1>>h2>>m2>>k;
	ll s=h1*60+m1;
	ll e=h2*60+m2;
	e-=k;
	cout<<e-s<<endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <cstring>


using namespace std;

int main(){
  string S;
  cin >> S;
  int N = strlen(S.c_str());
  int out[N];
  int max_length_of_same_direction = 1;
  for(int i=0;i<N;i++){
    out[i]=0;
  }
  int cnt = 1;
  for(int i=1;i<N;i++){
    if(S[i] != S[i-1] && S[i-1] == 'R'){
      out[i-1] += cnt/2 + cnt%2;
      out[i] += cnt/2;
      //cout << "diff of R" << endl;
      cnt = 1;
    }else if(S[i] != S[i-1] ){
      cnt = 1;
    }else{
      cnt++;
    }
  }

  cnt =1;
  for(int i=N-1;i>0;i--){
    if(S[i] != S[i-1] && S[i] == 'L'){
      out[i] += cnt/2 + cnt%2;
      out[i-1] += cnt/2;
      //cout << "diff of L" << endl;
      cnt = 1;
    }else if(S[i] != S[i-1] ){
      cnt = 1;
    }else{
      cnt++;
    }
  }
  for(int i=0;i<N-1;i++){
    cout << out[i] << " ";
  }
  cout << out[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    string s;
    while (cin >> s) {
        int cnt = 0, cnt2 = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s[i] == 'J' && s[i + 1] == 'O' && s[i + 2] == 'I') {
                cnt++;
            } else if (s[i] == 'I' && s[i + 1] == 'O' && s[i + 2] == 'I') {
                cnt2++;
            }
        }
        cout << cnt << endl;
        cout << cnt2 << endl;
        cnt = 0;
        cnt2 = 0;
    }
}



Measured memory_bytes: 3064
import itertools

def main():
    S = list(input())
    ans = 0
    for syms in itertools.product(("+", ""), repeat=len(S)-1):
        v = S[0]
        for i, sym in enumerate(syms, start=1):
            if sym == "":
                v += S[i]
            else:
                ans += int(v)
                v = S[i]
        ans += int(v)
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 39536
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;
int n, m;
int ans = -1;

int main()
{
	scanf("%d%d",&n,&m);
	int ccsaldklajsdlaksjdlaksjdlkjaslkdj = m/n;
	int ccsaldklajsdlaksjdlaasasjkdlajsdlkajsksjdlkjaslkdj = sqrt(m);
	ccsaldklajsdlaksjdlaksjdlkjaslkdj = min(ccsaldklajsdlaksjdlaksjdlkjaslkdj, ccsaldklajsdlaksjdlaasasjkdlajsdlkajsksjdlkjaslkdj);
	for (int i = 1; i * i <= m; ++i)
	{
		if (m % i == 0) 
		{
			int i1 = i;
			int i2 = m / i;
			if (i1 <= m / n) ans = max(ans, i1); 
			if (i2 <= m / n) ans = max(ans, i2);
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 256
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 100000, INF = 1e9+1;
int N;
int a[MAX_N];

int main(){
  rep(i, MAX_N) a[i] = INF;

  cin >> N;
  rep(i,N) cin >> a[i];

  sort(a, a+N);


  vector<pii> v;
  int i = 0;
  while (i < N) {
    int t = a[i];
    int c = upper_bound(a,a+N,t) - lower_bound(a,a+N,t);
    v.push_back(pii(t,c));
    i += c;
  }

  int ans = 0;
  for (int k = 0; k < (int)v.size(); ++k) {
    pii p = v[k];
    if (p.fi > p.sc) ans += p.sc;
    if (p.fi < p.sc) ans += p.sc - p.fi;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1784