akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

bool passNum[666];
bool writed[666];
ll dp[666][333][333];
void mod_add(ll &a, ll b){
	a += b;
	a %= MOD;
}

int main(){
	
	int n;cin >> n;
	int cou = 0;
	vector<int> v(2*n);
	REP(i,2*n){
		cin >> v[i];
		if(v[i] != -1)writed[v[i]] = true;
	}
	
	REP(i,n){
		if(v[2*i] != -1 && v[2*i+1] != -1){
			passNum[v[2*i]] = passNum[v[2*i+1]] = true;
		}
		if(v[2*i] == -1 && v[2*i+1] == -1)cou++;
	}
	
	dp[2*n][0][0] = 1;
	for(int i = 2*n;i > 0;i--){
		REP(j,n+1){
			REP(k,n+1){
				if(passNum[i]){
					mod_add(dp[i-1][j][k],dp[i][j][k]);
					continue;
				}
				if(writed[i]){
					if(j > 0)mod_add(dp[i-1][j-1][k], dp[i][j][k]);
					mod_add(dp[i-1][j][k+1], dp[i][j][k]);
				}
				else{
					if(j > 0)mod_add(dp[i-1][j-1][k], dp[i][j][k]);
					if(k > 0)mod_add(dp[i-1][j][k-1], k * dp[i][j][k] % MOD);
					mod_add(dp[i-1][j+1][k], dp[i][j][k]);
				}
			}
		}
	}
		
	REP(i,cou){
		dp[0][0][0] *= (i + 1);
		dp[0][0][0] %= MOD;
	}
	
	cout << dp[0][0][0] << endl;
				
	
	return 0;
}


Measured memory_bytes: 520320
def sol():
    h,w=map(int,input().split())
    c=[]
    for i in range(10):
        l=[int(i) for i in input().split()]
        c.append(l)
    a=[]
    for i in range(h):
        l=[int(i) for i in input().split()]
        a.append(l)
    p=[0]*10
    for i in range(10):
        if i==1: continue
        d=[1003]*10
        d[i]=0
        q=set([i])
        while 1:
            if len(q)==0: break
            x=q.pop()
            for j in range(10):
                if i==j: continue
                if (d[j]>d[x]+c[x][j]):
                    d[j]=d[x]+c[x][j]
                    q.add(j)
        p[i]=d[1]
    ans=0
    for i in range(h):
        for j in range(w):
            if a[i][j]==-1: pass
            else: ans+=p[a[i][j]]
    print(ans)

if __name__=="__main__":
    sol()


Measured memory_bytes: 3444
// clang-format off
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979;
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return ~n & 1; }
template<typename T> int len(const T &v) { return v.size(); }
template<typename T = int> T in() { T x; cin >> x; return x; }
template<typename T = int> T in(T &&x) { T z(forward<T>(x)); cin >> z; return z; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &x : v) is >> x; return is; }
template<typename A, typename B> istream &operator>>(istream &is, pair<A, B> &p) { return is >> p.first >> p.second; }
template<typename T> ostream &operator<<(ostream &os, const vector<vector<T>> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : "\n"); return os; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "" : " "); return os; }
template<typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << p.first << ' ' << p.second; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
// clang-format on

main() {
  int n = in();
  vector<pair<int, int>> v(n);
  cin >> v;
  sort(all(v));
  for (auto &p : v) cout << p << endl;
}



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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1

bool check(string s){
	int l = s.length();
	int i=0;
	while(i <= l/2){
		if(s[i] != s[l-i-1])
			return false;
		i++;
	}
	return true;
}


int32_t main(){	
	//file();
	string s;
	cin >> s;
	string s1 = "";
	string s2 = "";
	int l= s.length();
	for(int i=0 ; i<(l-1)/2 ; i++)
		s1+=s[i];
	for(int i=(l+3)/2-1 ; i<l ; i++)
		s2+=s[i];

	if(check(s) && check(s1) && check(s2))
		cout << "Yes" << endl;
	else cout << "No" << endl;


}

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

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

using ll = long long;
using lb = long double;
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  int N;
  cin>>N;
  vector<ll> ans(N);
  rep(i,N-1){
    int a;
    cin>>a;
    ans[a-1]++;
  }
  for(auto x:ans) cout<<x<<endl;
}

Measured memory_bytes: 4824
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
 
using namespace std;
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
	if(a>b)
		return a;
	return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 
 
 
 
int main()
{
	
	int h,a;
    cin>>h>>a;
    int test=h/a;
    if(h%a!=0)
        test++;
    cout<<test<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
from collections import deque

n = int(input())
a = [int(item) for item in input().split()]
a.sort()

first = a.pop() 
second = a.pop()
score = first
places = deque((second, second))

while a:
    v = a.pop()
    score += places.pop()
    places.appendleft(v)
    places.appendleft(v)
print(score)

Measured memory_bytes: 92048
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/#define lli long long int
#define uli unsigned long long int
#define INF 999999999999
#define rep(i,m,n) for(lli i = m;i < n;i++)
#define rrep(i,m,n) for(lli i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli A,B,C,D,E,H,W,M,K,L,R,N,num=0,sum=0,flag=0;string S,T;
  cin >> K;
  Vec(dist,lli,K,INF);
  dist[1]=1;
  deque<lli>que;
  que.pb(1);
  while(!que.empty()){
    auto x=que.front();
    que.pop_front();
    if(dist[(x+1)%K]>dist[x]+1){
      dist[(x+1)%K]=dist[x]+1;
      que.push_back((x+1)%K);
    }
    if(dist[x*10%K]>dist[x]){
      dist[x*10%K]=dist[x];
      que.push_front(x*10%K);
    }
  }
  Out(dist[0]);
}


Measured memory_bytes: 4460
#include <iostream>
#include <vector>

int main(){
    std::vector<int> x(5);

    for (int i = 0; i < 5; i++)
    {
        std::cin >> x[i];
        if (x[i] == 0)
        {
            std::cout << i + 1 << std::endl;
            break;
        }
    }
    return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

int H, W;
int G[10][10];
int D[10];
int cnt[10];

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

	cin >> H >> W;
	int c;
	rep(i, 0, 10)rep(j, 0, 10)
	{
		cin >> c;
		G[i][j] = c;
	}

	rep(i, 0, H)rep(j, 0, W)
	{
		cin >> c;
		if (c != -1)
		{
			cnt[c]++;
		}
	}

	vector<int> vvec;
	rep(i, 0, 10)
	{
		if (i == 1)continue;
		vvec.push_back(i);
	}

	fill(D, D + 10, INF);
	D[1] = 0;

	int counter = 0;
	do
	{
		int res = 0;
		rep(i, 0, SZ(vvec))
		{
			if (i == 0)
			{
				res += G[vvec[i]][1];
			}
			else
			{
				res += G[vvec[i]][vvec[i - 1]];
			}
			chmin(D[vvec[i]], res);
		}
		counter++;
	} while (next_permutation(all(vvec)));

	int ans = 0;
	rep(i, 0, 10)
	{
		ans += cnt[i] * D[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
"""

部分文字列にSを含む長さ|S|+Kの文字列の数
dp[i][j] = i文字目まで見てj文字目まで含んでる文字列の数
dp[i][j] = dp[i-1][j] * 25 + dp[i-1][j-1]

dp[0][0] = 1
dp[|S|+K][|S|]が欲しい

1に
1かける/25を掛ける
をそれぞれ |S|回、K回やった組み合わせの総和


"""
def modfac(n, MOD):
 
    f = 1
    factorials = [1]
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    inv = pow(f, MOD - 2, MOD)
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
    return factorials, invs


def modnCr(n,r,mod,fac,inv): #上で求めたfacとinvsを引数に入れるべし(上の関数で与えたnが計算できる最大のnになる)

    return fac[n] * inv[n-r] * inv[r] % mod

K = int(input())

S = input()
ls = len(S)

mod = 10**9+7

fac,inv = modfac(3*(10**6),mod)

ans = 0

for i in range(ls,ls+K+1):
    down = i-ls
    rem = K-down
    #print (down,rem)
    now = pow(26,rem,mod) * pow(25,down,mod) * modnCr(i-1,ls-1,mod,fac,inv) % mod
    #print (i,now)
    ans += now
    ans %= mod
#print ( * modnCr(ls+K,K,mod,fac,inv) % mod)
print (ans % mod)


Measured memory_bytes: 165788
#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)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////
int h,w,a[82][82],b[82][82];bool dp[82][82][15000];
signed main(){
  cin>>h>>w;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h)rep(j,w){
    cin>>b[i][j];
    int ab = abs(a[i][j]-b[i][j]);
    a[i][j] = ab;b[i][j] = -ab;
  }
  dp[0][0][a[0][0]] = true;
  rep(i,h){
    rep(j,w){
      if(i == 0 && j == 0)continue;
      rep(k,15000){
        if(k-a[i][j] >= 0){
          dp[i][j][k] = (dp[i][j][k] || (i-1 >= 0 ? dp[i-1][j][k-a[i][j]] : false) || (j-1 >= 0 ? dp[i][j-1][k-a[i][j]] : false));
        }else{
          dp[i][j][k] = (dp[i][j][k] || (i-1 >= 0 ? dp[i-1][j][-k+a[i][j]] : false) || (j-1 >= 0 ? dp[i][j-1][-k+a[i][j]] : false));
        }
        if(k-b[i][j] >= 0){
          dp[i][j][k] = (dp[i][j][k] || (i-1 >= 0 ? dp[i-1][j][k-b[i][j]] : false) || (j-1 >= 0 ? dp[i][j-1][k-b[i][j]] : false));
        }else{
          dp[i][j][k] = (dp[i][j][k] || (i-1 >= 0 ? dp[i-1][j][-k+b[i][j]] : false) || (j-1 >= 0 ? dp[i][j-1][-k+b[i][j]] : false));
        }
      }
    }
  }

  rep(i,15000){
    if(dp[h-1][w-1][i]){
      cout << i << endl;return 0;
    }
  }
}


Measured memory_bytes: 96512
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	while(cin>>n,n){
		bool dia[41][41]={};
		for(int i=0,x,y;i<n;i++){
			cin>>x>>y;
			dia[y][x]=1;
		}
		int mo;
		cin>>mo;
		string di="NESW";
		int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
		for(int i=0,num,x=10,y=10;i<mo;i++){
			char direction;
			cin>>direction>>num;
			for(int j=0;j<4;j++){
				if(direction==di[j]){
					for(int k=0;k<num;k++){
						x+=dx[j];
						y+=dy[j];
						if(dia[y][x]==1){
							dia[y][x]=0;
							n--;
						}
					}
					break;
				}
			}
		}
		if(n==0)cout<<"Yes\n";
		else cout<<"No\n";
	}
}

Measured memory_bytes: 1176
#include <stdio.h>
int main(void){
  int n,a,i,min=1000,max=0;
  scanf("%d",&n);
  for (i=0;i<n;i++){
    scanf("%d",&a);
    if (min>a) min=a;
    if (max<a) max=a;
  }
  printf("%d\n",max-min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("h.txt", "r", stdin);
    // freopen("main.out", "w", stdout);
#else
    fastIO;
#endif

    int n;
    cin >> n;
    cout << (int)pow(n, 3) << endl;

#ifdef LOCAL
    cerr << "Total Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int n=s.size();
  int count=0;
  for(int i=0;i<n;i++){
    if(s[i]==s[n-1-i]){
      count++;
    }
  }
  if(count==n){
    int x=(n-1)/2;
    for(int i=0;i<x;i++){
      if(s[i]==s[x-1-i]){
        count++;
      }
    }
    int y=(n+3)/2;
    for(int i=0;i<n-y+1;i++){
      if(s[y-1+i]==s[n-1-i]){
        count++;
      }
    }
    if(count==n+n+1+x-y){
      cout<<"Yes";
    }
    else{
      cout<<"No";
    }
  }
  else{
    cout<<"No";
  }
  
}


Measured memory_bytes: 3596
n,x = gets.split(" ").map(&:to_i)
l = gets.split(" ").map(&:to_i)

d = [0]
last = 0
n.times do |b|
    dot = l[b].to_i + last
    d.push(dot)
    last = dot
end

count = 0
d.each do |i|
    count = count + 1 if x >= i
end
puts count

Measured memory_bytes: 1788
n, k = map(int, input().split())
a = list(map(int, input().split()))

cost = 10 ** 18
for i in range(2 ** (n - 1)):
    num = 0
    c = 0
    prev = a[0]
    for j in range(n - 1):
        if i >> j & 1:
            num += 1
            if a[j + 1] <= prev:
                c += prev - a[j + 1] + 1
                prev += 1
        prev = max(prev, a[j + 1])
    if num >= k - 1:
        cost = min(c, cost)
print(cost)

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
  int N;
  char S[222222];
  int i;
  scanf("%d %s",&N,S);
  int count[222222];
  count[0] = 0;
  for(i=0;i<=N-1;i++)
    if(S[i] != '#') count[0]++;
  for(i=1;i<=N;i++){
    if(S[i-1] != '#') count[i] = count[i-1] - 1;
    else count[i] = count[i-1] + 1;
    };
  int min = count[0];
  for(i=0;i<=N;i++)
    if(count[i] < min) min = count[i];
  printf("%d",min);
}

Measured memory_bytes: 1152
import math
import collections
import fractions
import itertools
import functools
import operator

def solve():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    ans = 0
    mid = n // 2
    if n % 2 == 1:
        for i in range(mid, n-1):
            ans += a[i+1]
        for i in range(mid):
            ans += a[i+mid]
    else:
        for i in range(mid, n-1):
            ans += a[i+1]
        ans += a[mid]
        for i in range(1, mid):
            ans += a[i+mid-1]
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 32880
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> a(q), b(q), c(q), d(q);
	REP(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];
	
	vector<int> now;
	queue< vector<int> > qu;
	vector<int> fi;
	fi.push_back(1);
	qu.push(fi);
	while(!qu.empty()){
		now = qu.front();
		qu.pop();
		if(now.size() == n+1){
			int sco = 0;
			REP(i, q){
				int x = a[i], y = b[i];
				if(now[y] - now[x] == c[i]) sco += d[i];
			}
			ans = max(ans, sco);
		}
		else{
			now.push_back(0);
			for(int i = 0; now[now.size()-2] + i <= m; i++){
				now[now.size()-1] = now[now.size()-2] + i;
				qu.push(now);
			}
		}
	}
	cout << ans << endl;
}

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

#define rep(i,n) for(int i=0,i##_cond=(n);i<i##_cond;++i)
#define all(a) (a).begin(),(a).end()
using vi  = vector<int>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}

int n; // ノード数
vector<vector<pii>> g;
vi d;

pii bfs(int s){ // sを根としてbfs
  d.clear();
  d.resize(n,-1);
  queue<int> q;
  d[s] = 0;
  int maxd = 0;
  int pos = s;
  q.push(s);
  
  while(!q.empty()){
    int next = q.front();
    q.pop();
    
    rep(i, g[next].size()){
      int c = g[next][i].first;
      
      if(d[c] == -1){
	d[c] = d[next] + g[next][i].second;;
	if(chmax(maxd,d[c])) pos = c;
	q.push(c);
      }
    }
  }
  // sから最も遠いノードとその距離を返す
  return pii(pos,maxd);
}

int diameter(){
  int s = -1;
  rep(i,n) if(g[i].size() != 0) s = i;
  if(s == -1) return 0;
  pii a = bfs(s);
  return bfs(a.first).second;
}

int main(){
  while(cin >> n, n){
    g.clear();
    g.resize(n);
    vi p(n-1), dis(n-1);
    rep(i,n-1){
      cin >> p[i];
      p[i]--;
    }
    rep(i,n-1) cin >> dis[i];
    rep(i,n-1){
      g[i+1].emplace_back(p[i],dis[i]);
      g[p[i]].emplace_back(i+1,dis[i]);
    }
    vi leaf;
    rep(i,n)
      if(g[i].size() == 1) leaf.push_back(i);
    rep(k,leaf.size()){
      int to = g[leaf[k]][0].first;
      g[leaf[k]].clear();
      rep(i,g[to].size())
	if(g[to][i].first == leaf[k]){
	  g[to].erase(g[to].begin()+i);
	  break;
	}
    }
    int sumv = 0;
    rep(i,n) rep(j,g[i].size()) sumv += g[i][j].second; // 既に2倍されている
    cout << accumulate(all(dis),0) + sumv - diameter() << endl;
  }
}


Measured memory_bytes: 3180
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int calc_left[20][3],calc_right[20][3];

bool check(ll a,ll b, ll c){
	return a+b > c;
}

void divideGroup(){

	int index = 0,left_index,right_index;
	int left_table[6],right_table[6];

	for(int i = 0; i < 64; i++){
		left_index = right_index = 0;
		for(int loop = 0; loop < 6; loop++){
			if(i & (1 << loop)){
				left_table[left_index++] = loop;
			}else{
				right_table[right_index++] = loop;
			}
		}
		if(left_index != 3 || right_index != 3)continue;

		for(int k = 0; k < 3; k++){
			calc_left[index][k] = left_table[k];
			calc_right[index][k] = right_table[k];
		}
		index++;
	}

}

int main(){

	divideGroup();

	int N;
	scanf("%d",&N);

	ll* table = new ll[N];
	for(int i = 0; i < N; i++)scanf("%lld",&table[i]);

	sort(table,table+N);

	ll* max_3seq = new ll[N];
	for(int i = 0; i < N; i++)max_3seq[i] = 0;

	for(int i = 0; i <= N-3; i++){
		if(check(table[i],table[i+1],table[i+2])){
			max_3seq[i] = table[i]+table[i+1]+table[i+2];
		}else{
			if(i > 0){
				max_3seq[i] = max_3seq[i-1];
			}
		}
	}

	ll ans = 0;
	int debug;
	for(int i = 0; i+5 <= N-1; i++){
		if(check(table[i+3],table[i+4],table[i+5])){
			ans = max(ans,max_3seq[i]+table[i+3]+table[i+4]+table[i+5]);
		}
		bool FLG = false;

		for(int k = 0; k < 20; k++){
			if(check(table[i+calc_left[k][0]],table[i+calc_left[k][1]],table[i+calc_left[k][2]]) == true &&
					check(table[i+calc_right[k][0]],table[i+calc_right[k][1]],table[i+calc_right[k][2]]) == true){
				FLG = true;
				debug = k;
				break;
			}
		}

		if(FLG){
			ans = max(ans,table[i]+table[i+1]+table[i+2]+table[i+3]+table[i+4]+table[i+5]);
		}
	}


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

	return 0;
}

Measured memory_bytes: 4852
import java.util.*;
public class Main{
    public static void main(String[] args) {
  Scanner sc=new Scanner(System.in);
  ArrayList<String> array = new ArrayList<String>();
double N=sc.nextDouble();
double n=Math.floor(Math.sqrt(2*N))+1;
System.out.println(n*(n-1)==2*N?"Yes":"No");
if(n*(n-1)==2*N){
int s[][]=new int[(int)n][(int)n-1];
  int now=0;
int num=1;
  while(num<=N){  
  for(int i =now;i<(int)n-1;i++){
        s[now][i]=num;
           s[i+1][now]=num;
           
           num++;
     }
  now++;
  }
System.out.println((int)n);
 for (int k=0;k<(int)n;k++){
   System.out.println((int)n-1);
     for (int l=0;l<(int)n-1;l++){
     System.out.println(s[k][l]); 
    }
   }
     }
    }
}

Measured memory_bytes: 49328
//
// Created by bytedance on 2020/5/6.
//
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 5;
char shit[maxn][5];

int main() {
    int n, a, b, c;
    scanf("%d%d%d%d", &n, &a, &b, &c);
    vector<char> ans;
    for (int i = 0; i < n; i++) {
        scanf("%s", shit[i]);
    }
    for (int i = 0; i < n; i++) {
        int *t1, *t2;
        if (strcmp(shit[i], "AB") == 0) {
            t1 = &a;
            t2 = &b;
        } else if (strcmp(shit[i], "AC") == 0) {
            t1 = &a;
            t2 = &c;
        } else if (strcmp(shit[i], "BC") == 0) {
            t1 = &b;
            t2 = &c;
        } else {
            while (1);
        }
        if (*t1 != *t2) {
            if (*t1 > *t2) {
                (*t1)--;
                (*t2)++;
                ans.push_back(shit[i][1]);
            } else {
                (*t2)--;
                (*t1)++;
                ans.push_back(shit[i][0]);

            }
        } else {
            if (*t1 == 0) {
                printf("No\n");
                return 0;
            } else if (*t1 == 1) {
                if (i == n - 1 || (shit[i][0] == shit[i + 1][0] || shit[i][0] == shit[i + 1][1])) {
                    (*t1)++;
                    (*t2)--;
                    ans.push_back(shit[i][0]);
                } else {
                    (*t1)--;
                    (*t2)++;
                    ans.push_back(shit[i][1]);
                }
            } else {
                (*t1)++;
                (*t2)--;
                ans.push_back(shit[i][0]);
            }
        }
    }
    printf("Yes\n");
    for (int i = 0; i < n; i++) {
        printf("%c\n", ans[i]);
    }
    return 0;
}


Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define ll long long
#define x first
#define y second
#define pb push_back
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(a>b)
		cout<<a-1;
	else
		cout<<a;
	return 0;
}

Measured memory_bytes: 256
from bisect import bisect,bisect_left
S = input()
s = []
d = 'R'

for i in range(len(S)):
    if S[i] != d:
        s.append(i)
    d = S[i]

ans = [0]*len(S)
for i in range(len(S)):
    j = s[min(bisect(s,i),len(s)-1)]
    if S[i] == 'R':
        if (i-j)%2==0:
            ans[j]+=1
        else:
            ans[j-1]+=1
    else:
        j = s[bisect(s,i)-1]
        if (i-j)%2==0:
            ans[j]+=1
        else:
            ans[j-1]+=1
        
ans = [str(i) for i in ans]
print(' '.join(ans))

Measured memory_bytes: 54492
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = list(map(int, input().split()))
INF = 10 ** 9 + 7

inner = 0
outer = 0
cnt = 0
ans = 0

for i in range(N - 1):
    # print(inner)
    for j in range(i, N - 1):
        if A[i] > A[j + 1]:
            inner += 1

for i in range(N):
    for j in range(N):
        if A[i] > A[j]:
            outer += 1

ans = (inner * K + ((K * (K - 1)) // 2) * outer) % INF
print(ans)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, mod = 1000003;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define HelloFile freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define ll long long
int main()
{
    Hello
    string s;
    cin >> s;
    if( s == "Sunny" )
        cout << "Cloudy";
    else if( s == "Cloudy" )
        cout << "Rainy";
    else if( s == "Rainy" )
        cout << "Sunny";
    return 0;
}


Measured memory_bytes: 256
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;
use std::collections::BTreeMap;
fn exec() {
    let mut sc = Scanner::new();
    let n: usize = sc.ne();
    let mut map = BTreeMap::new();
    for _ in 0..n {
        let a: usize = sc.ne();
        *map.entry(a).or_insert(0) += 1;
    }
    let mut cnt = 0i32;
    let mut even = 0;
    for x in &map {
        if x.1 & 1 == 1 {
            cnt += x.1 - 1;
        } else {
            cnt += x.1 - 1;
            even += 1;
        }
    }
    let mut ans = n - (cnt as usize);
    if even & 1 == 1 {
        ans -= 1;
    }
    println!("{}", ans);
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r]).ok().unwrap().parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 10620
<?php

    $N = intval(trim(fgets(STDIN)));
    
    $H = array_map('intval',explode(" ",trim(fgets(STDIN))));
    $i=0;
    //スタート地点が一番後ろに行くまで
    $max=0;
    $count=0;
    while($i<$N-1){
        // echo $i." ";
        if($H[$i]>=$H[$i+1]){
            $count++;
            // echo "a\n";
            if($max<$count){
                $max = $count;
            }
        }else{
            
            $count=0;
        }
        $i++;

    }
    echo $max;
?>

Measured memory_bytes: 27320
using System.Collections.Generic;
using System.Linq;
using System;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	int[] G() => ReadLine().Split().Select(int.Parse).ToArray();
	public const int MOD = 1000000007;
	public K() { Solve(); }
	int V, E, C;
	List<E> all;
	List<E>[] es;
	void Solve()
	{
		var I = G();
		V = I[0];
		E = I[1];
		all = new List<E>();
		es = new List<E>[V];
		for (var i = 0; i < V; i++) es[i] = new List<E>();
		for (var i = 0; i < E; i++)
		{
			I = G();
			AddEdge(I[0] - 1, I[1] - 1, I[2]);
		}
		var d = new int[V, V];
		for (var i = 0; i < V; i++)
		{
			var e = DijkstraFrom(i);
			for (var j = 0; j < V; j++) d[i, j] = e[j];
		}
		var c = E;
		foreach (var e in all)
		{
			var flag = false;
			for (var i = 0; i < V; i++)
				if (d[i, e.From] + e.Cost == d[i, e.To])
				{
					flag = true;
					break;
				}
			if (flag) c--;
		}
		WriteLine(c);
	}
	void AddEdge(int f, int t, int c)
	{
		var e = new E(f, t, c);
		es[f].Add(e);
		es[t].Add(new E(t, f, c));
		all.Add(e);
		C = Max(C, c);
	}
	int[] DijkstraFrom(int from)
	{
		var d = Enumerable.Repeat(MOD, V).ToArray();
		var queue = new DialQueue(C);
		d[from] = 0;
		queue.Add(from, 0);
		while (queue.Any)
		{
			var p = queue.Pop();
			var v = p.To;
			if (d[v] < p.Cost) continue;
			foreach (var e in es[v])
			{
				var tmp = d[v] + e.Cost;
				if (d[e.To] > tmp)
				{
					if (d[e.To] != MOD) queue.Move(e.To, d[e.To], tmp);
					else queue.Add(e.To, tmp);
					d[e.To] = tmp;
				}
			}
		}
		return d;
	}
}
struct E
{
	public int From, To, Cost;
	public E(int f, int t, int c)
	{
		From = f;
		To = t;
		Cost = c;
	}
}
class DialQueue
{
	public int Count { get; private set; }
	int C, offset;
	HashSet<int>[] buckets;
	HashSet<int> this[int n] { get { return buckets[(n - offset + offset % C) % C]; } }
	public DialQueue(int c)
	{
		C = c + 1;
		buckets = new HashSet<int>[C];
		for (var i = 0; i < C; i++) buckets[i] = new HashSet<int>();
	}
	public void Add(int v, int d)
	{
		Count++;
		this[d].Add(v);
	}
	public void Move(int v, int prev, int now)
	{
		this[prev].Remove(v);
		this[now].Add(v);
	}
	public bool Any { get { return Count > 0; } }
	public E Pop()
	{
		Count--;
		var t = offset;
		while (true)
		{
			var s = this[t];
			if (s.Count > 0)
			{
				var v = s.First();
				s.Remove(v);
				return new E(-1, v, offset = t);
			}
			t++;
		}
	}
}


Measured memory_bytes: 24416
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll inf = 1e9 + 7;
ll n, m, s[2020], t[2020];
ll dp[2020][2020] = {};
vector<ll> s_list[100010], t_list[100010];

/*
ll solve(int k, int l) {
    if (dp[k][l]) return dp[k][l];
    
    if (k * l == 0) dp[k][l] = 1;
    else {
        
    }
    
    dp[k][l] %= inf;
    return dp[k][l];
}*/


int main(void){
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> s[i];
        s_list[s[i]].push_back(i);
    }
    for (int i = 0; i < m; i++) {
        cin >> t[i];
    }
    
    dp[0][0] = 1;
    for (int i = 0; i < n; i++) dp[i + 1][0] = 1;
    for (int j = 0; j < m; j++) dp[0][j + 1] = 1;
    
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
            else dp[i + 1][j + 1] = inf + dp[i + 1][j] + dp[i][j + 1] - dp[i][j];
            dp[i + 1][j + 1] %= inf;
        }
    }
    
    cout << dp[n][m] << endl;
    
    /*
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            if (j != 0) cout << " ";
            cout << dp[i][j];
        }
        cout << endl;
    }*/
    
    
    //cout << solve(n, m) << endl;
}


Measured memory_bytes: 36608
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(size_t i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using ti3 = tuple<int,int,int>;

int main(){
  ll n; cin>>n;
  vi d(n); REP(i,n) cin>>d[i];
  sort(d.begin(),d.end());
  cout<<d[n/2]-d[n/2-1]<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i=0;i<(n);++i)
#define RANGE(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(n)-1;i>= 0;--i)

#define endl '\n'
#define pb push_back
#define eb emplace_back
#define pque priority_queue
#define umap unordered_map
#define uset unordered_set
#define BIG 2000000000
#define VERYBIG 1000000000000000ll
#define dcout cout<<fixed<<setprecision(20)
#define Accepted_MAGIC cin.tie(0);ios::sync_with_stdio(false);cerr << "compiled" << endl

// typedef long long ll;
using Real = long double;
#define int long long

const long long dx[]={1,0,-1,0,1,1,-1,-1}, dy[]={0,-1,0,1,1,-1,1,-1};
const long long MOD = 1e9+7;
constexpr Real eps = 1e-9, pi = acos(-1);

template<typename T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template<typename T> inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template<typename 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<typename 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;}

typedef pair<int, int> INTP;
typedef vector<int> INTV;
struct edge2 {int to, cost;};
struct edge3 {int from, to, cost;};

signed main(void){
  Accepted_MAGIC;
  
  string S; int Q; cin >> S >> Q;
  string front = "", back = "";
  bool rev = 0;
  REP(_, Q){
    int q; cin >> q;
    if(q == 1) rev ^= 1;
    else {
      int f; char c; cin >> f >> c;
      if(rev ^ (f==1)) front += c;
      else back += c;
    }
  }
  reverse(ALL(front));
  S = front + S + back;
  if(rev) reverse(ALL(S));
  cout << S << endl;
}

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

// struct Node {
//     int h;
// } nodes[233];

// struct Edge {
//     int to, nex;
// } edges[2333];

// int n, m, ans, cnt;

// void addedge(int u, int v) {
//     edges[++cnt] = {v, nodes[u].h};
//     nodes[u].h = cnt;
// }

// int main() {
//     cin >> n >> m;
//     for(int i = 1; i <= m; ++i) {
//         int u, v;
//         cin >> u >> v;
//         addedge(u, v);
//         addedge(v, u);
//     }
//     for(int i = 1; i <= )
// }

#include <iostream>
#include <cstring>
using namespace std;

int n, m, e[51][51], ans, u[51 << 1], v[51 << 1];
bool vis[51];

void dfs(int node) {
    vis[node] = 1;
    for(int i = 1; i <= n; ++i) {
        if(i == node) continue;
        if(!vis[i] && e[node][i]) dfs(i);
    }
}

int main() {
    cin >> n >> m;
    for(int i = 1; i <= m; ++i) {
        cin >> u[i] >> v[i];
        e[u[i]][v[i]] = e[v[i]][u[i]] = 1;
    }
    for(int i = 1; i <= m; ++i) {
        e[u[i]][v[i]] = e[v[i]][u[i]] = 0;
        memset(vis, 0, sizeof(vis));
        dfs(1);
        for(int i = 1; i <= n; ++i)
            if(!vis[i]) {
                ++ans;
                break;
            }
        e[u[i]][v[i]] = e[v[i]][u[i]] = 1;
    }
    cout << ans;
    return 0;
}

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

using namespace std;
using ll = long long;

void init();
void solve();

#define rep(i, a) for (int i = 0; i < (int) (a); i++)
#define reps(i, a, b) for (int i = (int) (a); i < (int) (b); i++)
#define rrep(i, a) for (int i = (int) a-1; i >= 0; i--)
#define rreps(i, a, b) for (int i = (int) (a)-1; i >= (int) (b); i--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "H"
#define FALSE__ "D"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
#define lcout(a) cout << a;
#define lcoutln(a) cout << a << endl;
#define lcerr(a) cerr << a;
#define lcerrln(a) cerr << a << endl;
#else
#define lcout(a) 
#define lcoutln(a) 
#define lcerr(a) 
#define lcerrln(a) 
#endif
#define MOD 1000000007

int a, b;

signed main()
{
	init();
	solve();
}

void init()
{
	cin >> a >> b;
	if (a == 1) a = 14;
	if (b == 1) b = 14;
}

void solve()
{
	if (a == b) cout << "Draw" << endl;
	else if (a < b) cout << "Bob" << endl;
	else cout << "Alice" << endl;
}


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

int main() {
  int n;
  cin >> n ;
  vector<int> p(n);

  for (int i=0; i<n; ++i) cin >> p.at(i);
  
  sort(p.begin(), p.end());
  
  int result=0;
  
  for(int i=0; i<n-1; ++i) result += p.at(i);
  
  cout << result + (p.at(n-1)/2);
}

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

int main() {
  int n,m,c1=0,c2=0;
  cin>>n>>m;
  
  if(n>1){c1=(n*(n-1))/2;}
  if(m>1){c2=(m*(m-1))/2;}

  cout<<c1+c2<<endl;;

}


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

typedef long long ll;
typedef pair<ll, ll> pii;

ll dp[10][10];
ll pows10[13];

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

	pows10[0] = 1;

	for (int i = 1; i < 13; i++) {
		pows10[i] = pows10[i - 1] * 10;
	}

	int k;
	cin >> k;

	priority_queue<pii, vector<pii>, greater<>> pq;

	for (int i = 0; i <= 9; i++) {
		pq.push({1, i});
	}

	while (k > 0) {
		pii cur = pq.top();
		pq.pop();

		if (cur.second >= pows10[cur.first - 1]) {
			k--;

			if (k == 0) {
				cout << cur.second;
				return 0;
			}
		}

		ll ldig = cur.second / pows10[max(0LL, cur.first - 1)];

		for (int x = max(0LL, ldig - 1); x <= min(9LL, ldig + 1); x++) {
			pq.push({cur.first + 1, cur.second + x * pows10[cur.first]});
		}
	}

	/*for (int i = 0; i <= 9; i++) {
		dp[0][i] = 1;
	}

	for (int i = 1; i < 10; i++) {
		for (int j = 0; j <= 9; j++) {
			for (int k = max(0, j - 1); k <= min(9, j + 1); k++) {
				dp[i][j] += dp[i - 1][k];
			}
		}
	}

	vector<int> num;

	for (int ldig = 9; ldig >= 0; ldig--) {
		if (dp[9][ldig] > k) {
			num.push_back(ldig);

			for (int len = 9; )

			break;
		} else {
			k -= dp[9][ldig];
		}
	}*/

	return 0;
}

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


int main(){
    int i,j;
    int n;
    cin>>n;
    double ans=0;
    for(i=0;i<n;i++){
        string x;
        double y;
        cin>>y>>x;
        if(x[0]=='J') ans+=y;
        else ans+=380000.0*y;

    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n;
int a[100010],b[100010];

void solve(){
    cin >> n;
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    vector<P> v(n);
    rep(i,n){
        v[i]=P(b[i],a[i]);
    }
    sort(v.begin(),v.end());
    rep(i,n){
        b[i]=v[i].first;
        a[i]=v[i].second;
    }
    // rep(i,n){
    //     cout << a[i] << " ";
    // }
    // cout << "" << endl;
    // rep(i,n){
    //     cout << b[i] << " ";
    // }
    //cout << "" << endl;
    vector<int> s(n);rep(i,n) s[i]=i;
    sort(s.begin(),s.end(),[](int p,int q){return a[p]<a[q];});
    // rep(i,n){
    //     cout << s[i] << " ";
    // }
    // cout << "" << endl;
    rep(i,n){
        if(a[s[i]]>b[i]){
            cout << "No" << endl;
            return;
        }
    }
    rep(i,n-1){
        if(a[s[i+1]]<=b[i]){
            cout << "Yes" << endl;
            return;
        }
    }
    int num=0,pos=0;
    while(num==0 || pos!=0){
        pos=s[pos];
        num+=1;
    }
    if(num==n) cout << "No" << endl;
    else cout << "Yes" << endl;
}

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

Measured memory_bytes: 2304
use std::io;

fn main() {
  let n = read_values::<usize>()[0];
  let mut cur = (0, 0);
  let mut time = 0;

  for _ in 0..n {
    let (t, x, y) = {
      let v = read_values::<i64>();
      (v[0], v[1], v[2])
    };

    let duration = t - time;
    let (cx, cy) = cur;
    let length = (cx - x).abs() + (cy - y).abs();

    if length > duration {
      println!("No");
      return;
    }
    if (duration - length) % 2 != 0 {
      println!("No");
      return;
    }

    time = t;
    cur = (x, y);
  }
  println!("Yes");
}

fn read_line() -> String {
  let stdin = io::stdin();
  let mut buf = String::new();
  stdin.read_line(&mut buf).unwrap();
  buf
}

fn read_values<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug {
  read_line()
    .split(' ')
    .map(|a| a.trim().parse().unwrap())
    .collect()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
#define MOD 1000000007

vector<pair<int, int>> X[1003];
ll perm[1002][1002], dp[1002][1002], jk[1002][1002];
ll fact[1002];

//mod冪乗
ll modpow(ll a, ll b) {
	ll ans = 1;
	while (b) {
		if (b % 2)
			ans *= a;
		a *= a;
		a %= MOD;
		ans %= MOD;
		b /= 2;
	}
	return ans;
}

//mod割り算
ll moddiv(ll a, ll b) {
	a %= MOD;
	return (a * modpow(b, MOD - 2)) % MOD;
}

ll A, B, C, D;

int main() {
	ll N, E;
	int n;
	cin >> N >> A >> B >> C >> D;
	for (int i = 1;i <= N;i++) {
		E = 1;
		for (int j = i;j > 0;j--) {
			E *= j;
			E %= MOD;
			perm[i][i - j + 1] = E;
		}
	}

	E = 1;
	for (int i = 1;i <= N;i++) {
		E *= i;
		E %= MOD;
		fact[i] = E;
	}

	E = 1;
	for (int j = A;j <= B;j++) {
		for (int k = C;k <= D;k++) {
			E = (modpow(fact[j], k) * fact[k]) % MOD;
			jk[j][k] = E;
		}
	}

	int a, b, cnt = 0;
	dp[N][A - 1] = 1;
	for (int j = A;j <= B;j++) {
		for (int i = N;i >= 0;i--) {
			dp[i][j] += dp[i][j - 1];
			dp[i][j] %= MOD;
			if (i < j * C)continue;
			for (int k = C;k <= D;k++) {
				if (i < j * k) {
					break;
				}
				cnt++;
				dp[i - j * k][j] += dp[i][j - 1] * moddiv(perm[i][j * k], jk[j][k]);
				dp[i - j * k][j] %= MOD;
			}
		}
	}
	cout << dp[0][B] << endl;
}

Measured memory_bytes: 23808
# Problem B - RGB Boxes

# input
r, g, b, n = map(int, input().split())

# initialization
count = 0

# count
for i in range(n+1):
    for j in range(n+1):
        if n-r*i-g*j<0:
            continue
        k = 0
        if (n-r*i-g*j)%b==0:
            k = (n-r*i-g*j)//b
        if (r*i + g*j + b*k)==n:
            count += 1

# output
print(count)


Measured memory_bytes: 68648
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<queue>
#include<stack>
#include<cmath>
#define LL long long
using namespace std;
inline void read(int &x){
	x=0;int f=1;char c=getchar();
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();	}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
	x*=f;
}
int n;
struct node{
	int v,pos;
}a[52];
inline int cmp(node a,node b)
{
	return a.v<b.v;
}
int main()
{
	read(n);
	for(int i=1;i<=n;i++) read(a[i].v),a[i].pos=i;
	sort(a+1,a+1+n,cmp);
	int sum=0;
	for(int i=1;i<=n;i++) 
	    if(a[i].pos!=i)
	        sum++;
	if(sum==0||sum==2)
	{
		puts("YES");
	}
	else
	{
		puts("NO");
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner scanner = new Scanner(System.in);
		
		int A = scanner.nextInt();
		
		scanner.close();
		
		if (A < 30) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}

}


Measured memory_bytes: 27024
N, M = map(int, input().split())
if M:
    sc = [map(int, input().split()) for _ in range(M)]
    s, c = [list(i) for i in zip(*sc)]

    def isOK(num):
        str_num = str(num)
        l = len(str_num)
        if l != N:
            return False
        for i in range(M):
            if str_num[s[i]-1] != str(c[i]):
                return False

        return True

    ans = -1

    for i in range(10**N):
        if isOK(i):
            ans = i
            break

    print(ans)
else:
    print(10**(N-1) if N != 1 else 0)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,w;
    cin>>h>>w;
    string ba(w+2,'#');
    cout<<ba<<endl;
    for(int i = 0; i < h; i++){
        cout<<'#';
        string s;
        cin>>s;
        cout<<s;
        cout<<"#\n";
    }
    cout<<ba;
}

Measured memory_bytes: 256
#include<cstdio>//g-石头,p-纸
#include<cstring>//出纸的次数<=出石头的次数
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
char a[1000000+5];
int n,ans;
int gn,pn,gt,pt;
int main()
{
	scanf("%s",a);
	n=strlen(a);
	for(int i=0;i<n;i++)
	{
		if(a[i]=='g')
			gn++;
		else
			pn++;
	}
	printf("%d\n",n/2-pn);
	return 0;
}



Measured memory_bytes: 384