akhauriyash/Code-Regression huggingface dataset:
#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;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int SZ = 5e5 + 100;
vector<int> p[SZ];
int pos[SZ];

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        p[c[i]].push_back(i);
    }
    
    ordered_set s;
    for (int i = 0; i < SZ; ++i) {
        if (p[i].size()) {
            s.insert(p[i][0]);
        }
    }
    
    vector<tuple<int, int, int>> qs;
    vector<int> res(q);
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        --l; --r;
        qs.push_back(make_tuple(l, r, i));
    }
    sort(qs.begin(), qs.end());
    int cur = 0;
    
    for (int i = 0; i < q; ++i) {
        int l = get<0>(qs[i]), r = get<1>(qs[i]), j = get<2>(qs[i]);
        while (cur < l) {
            int val = c[cur];
            s.erase(cur);
            pos[val]++;
            if (pos[val] < p[val].size()) {
                s.insert(p[val][pos[val]]);
            }
            ++cur;
        }
        auto it = s.upper_bound(r);
        --it;
        res[j] = s.order_of_key(*it);
    }
    
    for (int i = 0; i < q; ++i) {
        cout << res[i] + 1 << '\n';
    }
    return 0;
}

Measured memory_bytes: 66388
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
  int M[2],D[2];
  cin >> M[0] >> D[0];
  cin >> M[1] >> D[1];
  if(M[0]==M[1]){cout << 0 << endl;}
  else{cout << 1 << endl;}
  return 0;
}

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

using namespace std;

bool dp[100100];
int n, k;
int a[110];

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 0; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i >= a[j] && !dp[i - a[j]]) dp[i] = true;
		}
	}
	cout << (dp[k] ? "First" : "Second") << '\n';
}


Measured memory_bytes: 384
use whiteread::parse_line;

fn main() {
    let k: i32 = parse_line().unwrap();
    let mut a = 0;
    for i in 0..k {
        a = (10 * a + 7) % k;
        if a == 0 {
            println!("{}", i + 1);
            return;
        }
    }
    println!("-1");
}


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

int main()
{
    string S1,S2;
    cin >> S1 >> S2;
    reverse(S2.begin(), S2.end());
    if( S1 == S2 ){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  long int a,b,k,i;
  scanf("%ld%ld%ld",&a,&b,&k);
  if(a>=k)
    a -= k;
  else if(a+b>=k){
    k -= a;
    a = 0;
    b -= k;
  }
  else
    a = b = 0;
  printf("%ld %ld\n",a,b);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

int main(){
  int n,f[100][10],i,j,a[10],c[100],cnt=0;
  long p[100][11],sum=0,max=-1000000000;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      scanf("%d",&f[i][j]);
    }
  }
  for(i=0;i<n;i++){
    for(j=0;j<11;j++){
      scanf("%ld",&p[i][j]);
    }
  }
  for(a[0]=0;a[0]<2;a[0]++){
    for(a[1]=0;a[1]<2;a[1]++){
      for(a[2]=0;a[2]<2;a[2]++){
        for(a[3]=0;a[3]<2;a[3]++){
          for(a[4]=0;a[4]<2;a[4]++){
            for(a[5]=0;a[5]<2;a[5]++){
              for(a[6]=0;a[6]<2;a[6]++){
                for(a[7]=0;a[7]<2;a[7]++){
                  for(a[8]=0;a[8]<2;a[8]++){
                    for(a[9]=0;a[9]<2;a[9]++){
                      sum=0;
                      cnt=0;
                      for(i=0;i<10;i++)
                        cnt+=a[i];
                      if(cnt){
                        for(i=0;i<n;i++){
                          c[i]=0;
                          for(j=0;j<10;j++){
                            if(a[j]&&f[i][j]) c[i]++;
                          }
                          sum+=p[i][c[i]];
                        }
                        if(max<sum) max=sum;
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  }
  printf("%ld\n",max);
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        double a=scanner.nextDouble();
        double b=scanner.nextDouble();
        double C=scanner.nextDouble();
        
        double cosC=Math.cos(C * (Math.PI / 180));
        double sinC=Math.sin(C * (Math.PI / 180));
        double menseki=a*b*sinC/2;
        
        double x2=b*cosC;
        double y2=b*sinC;
        
        double deltax=(x2-a)*(x2-a);
        double deltay=(y2)*(y2);
        
        System.out.println(menseki);
        double kyori=Math.sqrt(deltax+deltay);
        System.out.println(kyori+a+b);
        
        System.out.println(b*sinC);
    }
}

Measured memory_bytes: 27884
import math as ma
import sys
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

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

def nu():
	return int(input())

def find_gcd(x , y):
	while (y):
		x , y = y , x % y
	return x

n,k=num()
if(n%k==0):
	print(0)
else:
	print(1)

Measured memory_bytes: 5204
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rrep(i,n) for(ll i = 1; i <= (n); ++i)
#define drep(i,n) for(ll i = (n)-1; i >= 0; --i)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (ll)(x).size()
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const int INF=1e9;
const ll MX = 1e18;
const ll MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define YN {puts("YES");}else{puts("NO");}
const ll MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {fac[0] = fac[1] = 1;finv[0] = finv[1] = 1;inv[1] = 1;for (ll i = 2; i < MAX; i++){fac[i] = fac[i - 1] * i % MOD;inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;finv[i] = finv[i - 1] * inv[i] % MOD;}}
long long COM(ll n, ll k){if (n < k) return 0;if (n < 0 || k < 0) return 0;return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;}
ll llpow(ll n,ll i){ll cnt=n;  for(ll j=0;j<i-1;j++){n*=cnt;}return n;}

int main() {
  string s;
  cin>>s;
  string t=s;
  reverse(all(s));
  if(t==s)yn;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef long int li;
typedef vector<int> vi;
#define pb push_back
vi a;
vi b;
int n,m,x,y;
map<char,int> frq;
map<char,int> frq1;
int main() {
string x,y;
cin>>x>>y;
for(int i=0;i<x.size();i++)
{
    frq1[x[i]]++;
}
for(int i=0;i<y.size();i++)
{
    frq[y[i]]++;
}
if(frq.size()>frq1.size()){cout<<"No";exit(0);}
int temp=true;
for(map<char,int>::iterator it=frq.begin();it!=frq.end();it++)
{
    int t=0;
    for(map<char,int>::iterator it1=frq1.begin();it1!=frq1.end();it1++)
     if( it->second==it1->second)
    {
         t++;

    }
    else
    {
        t--;
    }

if(t==-frq1.size()){temp=false;break;}
}
if(temp==1)cout<<"Yes"<<endl;
else cout<<"No"<<endl;


    return 0;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << (abs(x-a) < abs(x-b) ? "A" : "B") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
typedef long long LL;
const int e[40]={0,1,1,2,2,2,3,3,3,3,4,4,4,4,4,5,5,5,5,5,
                 5,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,8,8,8,8};
LL IN(void)
{
  LL x=0;short f=0,c=getchar();
  while(c<48||c>57)f^=c==45,c=getchar();
  while(c>47&&c<58)x=x*10+c-48,c=getchar();
  return f?-x:x;
}
int main(void)
{
  int i,x=0;LL a=0,N=IN();
  while(N%2==0){x++;N/=2;}
  a+=e[x];
  for(i=3;(LL)i*i<=N;i+=2)
  {
    x=0;while(!(N%i))x++,N/=i;
    a+=e[x];
  }
  if(N>1)a++;
  return printf("%lld\n",a),0;
}

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

typedef long long ll;

string S;

int main() {
  cin >> S;
  sort(S.begin(), S.end());
  cout << (S[0] == S[1] && S[1] != S[2] && S[2] == S[3] ? "Yes" : "No") << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define F first
#define S second
#define PB push_back
#define MK make_pair
#define REP(i, a, b) for (int i=a; i < b; i++)


bool sort_by(pi c, pi d){
	return c.S < d.S;
}

int main() {
	ll n;
	cin >> n;
	ll o[n], c[n+1]={0};
	REP(i, 0, n){
		cin >> o[i];
		++c[o[i]];
	}
	ll pos = 0, val;
	REP(i, 0, n+1){
		val = c[i];
		pos += val* (val - 1)/2;
		c[i] = (val - 1)*(val - (val-2))/2;
	}
	REP(i, 0, n){
		cout <<  pos - c[o[i]] << endl;
	}
		

}


Measured memory_bytes: 5760
// Package main provides
//
// File:  b.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 15:41:00 2018
//
package main

import "fmt"

var n int

func allSame(a int) bool {
	for _, i := range []int{111, 222, 333, 444, 555, 666, 777, 888, 999} {
		if a == i {
			return true
		}
	}
	return false
}

func main() {
	fmt.Scan(&n)
	for i := n; i <= 999; i++ {
		if allSame(i) {
			fmt.Println(i)
			return
		}
	}
}


Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <functional>
using namespace std;
 
int main(void) {
	int A, B;
	cin >> A>>B;
	if (A > 8 || B > 8)
		cout << ":(" << endl;
	else
		cout << "Yay!" << endl;
	return 0;
}

Measured memory_bytes: 256
import sys,collections,math;sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod
mod = 998244353 #出力の制限
N = 3*10**5
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル
for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

N,A,B,K = Is()
ans = 0
for x in range(N+1):
    y = (K-A*x)/B
    if 0 <= y <= N and y.is_integer():
        ans += cmb(N,x,mod)*cmb(N,int(y),mod) % mod
print(ans % mod)


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define itrout(x) for(int i=0;i<x.size();i++) {cout << x[i] << (i==x.size()-1 ? "\n" : " ");}
#ifdef LOCAL
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define debugbit(x, n) cerr << #x << " = " << bitset<n>(x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define itrdebug(x) cerr << #x << " "; for (auto & el : (x)) {cerr << (el) << " ";} cerr << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define debug(x)
#define debugbit(x, n)
#define itrdebug(x)
#define dassert(...)
#endif
//#define int long long
//using mint = atcoder::modint;

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, long long M, std::vector<long long> A, std::vector<long long> B){
    atcoder::dsu d(N+1);
    rep(i,0,M) d.merge(A[i], B[i]);
    cout << d.groups().size() - 2 << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> A(M);
    std::vector<long long> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9080
#include<bits/stdc++.h>
using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
    char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
    vector<char*> v({token});
    while(token = strtok(NULL,", ")) v.push_back(token);
    return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
    debug() << " [" << args.back() << ": " << H << "] ";
    args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    cout<<max({a*c,b*d,a*d,b*c});
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>
#include <unordered_set>

using namespace std;
using ll = long long;
const int BIG = 1000000007;


int main() {
    string s;
    cin >> s;
    cout << (s[s.size() - 1] == 's' ? (s + "es") : (s + "s")) << endl;
}




Measured memory_bytes: 3040
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;
using ll = long long;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((int)(x).size())
#define MSG(a) cout << #a << " " << a << endl;

class Radix {
private:
    const char* s;
    int a[128];
public:
    Radix(const char* s = "0123456789ABCDEF") : s(s) {
        int i;
        for(i = 0; s[i]; ++i)
        a[(int)s[i]] = i;
    }
    std::string to(long long p, int q) {
        int i;
        if(!p)
        return "0";
        char t[64] = { };
        for(i = 62; p; --i) {
        t[i] = s[p % q];
        p /= q;
        }
        return std::string(t + i + 1);
    }
    std::string to(const std::string& t, int p, int q) {
        return to(to(t, p), q);
    }
    long long to(const std::string& t, int p) {
        int i;
        long long sm = a[(int)t[0]];
        for(i = 1; i < (int)t.length(); ++i)
        sm = sm * p + a[(int)t[i]];
        return sm;
    }
};

int main()
{
    ll n;
    int k;
    Radix r;
    cin >> n >> k;
    cout << r.to(n, k).length() << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
long long a[10000+5];
int Tot(long long x)
{
	int ret=0;
	while(x%2==0)
	{
		x/=2;
		ret++;
	}
	return ret;
}
int main()
{
	int n,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		sum+=Tot(a[i]);
	}
	printf("%d\n",sum);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <iostream>
#include <string.h>
#include <algorithm>
 size_t strlen(const char *s);
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const int N=100010;
const int P=1000000007;
int compare_int(const void *a, const void *b)
{
    return *(long long int*)b - *(long long int*)a;
}
//絶対値
int ze(int a, int b){
	if(a>b){
		return a-b;
	}else{
		return b-a;
	}
}
// 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);
}

//mod掛け算
long long mt(long long a, long long b, long long mod){
	return (a*b)%mod;
}

//メモ
//	cout<<(n-2)*180<<endl;
//	string s="hoge";
//	cout<<ans<<endl;
//	int  n  ,a  ,b  ,c  ,d  ,e  ,f  ;
//	cin  >>n  >>a  >>b  >>c  >>d  >>e  >>f  ;

/*
	memset(b, '\0', sizeof(b));
初期化*/
/*
	len = strlen(s);
文字列長さ*/
/*
	string s;
	s.size()
*/
/*
	char s[N];
	strlen(s)
/*
	if(  <  )puts("YES");
	else puts("NO");
*/

int main(){
	int n, b[30],ans=0;
	memset(b, '\0', sizeof(b));
	cin>>n;
	rep(i, n){
		cin>>b[i];
	}
	for(int i=1;i<n-1;i++){
		if((b[i]-b[i-1])*(b[i]-b[i+1])<0){
			ans++;
		}
	}
	cout<<ans<<endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int mod = (int) 1e9 + 7;
const int N = 200005;

int h, w, n;
int dp[3005];
int fact[N];
int inv[N];
vector < pair <int, int> > vec;

inline int add(int a, int b) {
  return (1ll * a + b) % mod;
}

inline int sub(int a, int b) {
  long long ans = (1ll * a - b) % mod;
  return (ans + mod) % mod;
}

inline int mul(long long a, long long b) {
  a %= mod; b %= mod;
  return (1ll * a * b) % mod;
}

inline int fp(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1) {
      ans = mul(ans, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return ans;
}

inline int invr(int x) {
  return fp(x, mod - 2);
}

int comb(int n, int k) {
  int ans = (1ll * fact[n] * inv[n - k]) % mod;
  return (1ll * ans * inv[k]) % mod;
}

int main() {
  fact[0] = 1;
  for (int i = 1; i < N; i++) {
    fact[i] = (1ll * fact[i - 1] * i) % mod;
  }
  inv[N - 1] = invr(fact[N - 1]);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = (1ll * inv[i + 1] * (i + 1)) % mod;
  }
  cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    vec.push_back({x, y});
  }
  vec.push_back({h, w});
  sort(vec.begin(), vec.end());
  n = vec.size();
  for (int i = 0; i < n; i++) {
    dp[i] = comb(vec[i].first + vec[i].second - 2, vec[i].first - 1);
  }
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (!(vec[j].first <= vec[i].first && vec[j].second <= vec[i].second)) continue;
      int aa = vec[i].first - vec[j].first;
      int bb = vec[i].second - vec[j].second;
      dp[i] = sub(dp[i], mul(dp[j], comb(aa + bb, aa)));
    }
  }
  cout << dp[n - 1] << endl;
  return 0;
}


Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int[] a = new int[N];
    int[] b = new int[N];
    for (int i = 0; i < N; i++) a[i] = scanner.nextInt();
    for (int i = 0; i < N; i++) b[i] = scanner.nextInt();
    if (possible(N, a, b)) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }

  private static boolean possible(int N, int[] a, int[] b) {
    long asum = 0;
    long bsum = 0;
    for (int i = 0; i < N; i++) asum += a[i];
    for (int i = 0; i < N; i++) bsum += b[i];
    if (asum > bsum) return false;
    long ca = bsum - asum;
    long cb = bsum - asum;
    for (int i = 0; i < N; i++) {
      if (a[i] < b[i]) {
        int d = b[i] - a[i];
        ca -= d / 2 + d % 2;
        cb -= d % 2;
      } else {
        cb -= a[i] - b[i];
      }
    }
    return ca >= 0 && cb >= 0 && ca * 2 == cb;
  }
}


Measured memory_bytes: 43804
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;

vector<ll> divisor(ll n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    vector<vector<ll> >div(n);
    rep(i,n)div[i]=divisor(a[i]);
    set<ll>st;
    set<ll>x;
    rep(i,n-1){
        if(a[i]==a[i+1]){
            x.insert(a[i]);
        }
    }
    ll ans = 0;
    rep(i,n){
        bool flag = true;
        if(!st.empty()){
            for(auto j:div[i]){
                if(st.count(j)!=0){
                    flag = false;
                }
            }
        }

        if(flag&&x.count(a[i])==0)ans++;
        st.insert(a[i]);
    }
    
    cout << ans << endl;
    return 0;
}


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


int main(){
    int n;
    int a[3005];
    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    ll ans=0;
    for(int i=0;i<n;i++){
        ans+=a[i];
    }
    ans-=n;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }



int main()
{
	int a; string s;
	cin >> a >> s;

	if (a >= 3200)
		cout << s << endl;
	else
		cout << "red" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int cnt = 0;
    for(int i = 0; i < N-1; i++) {
        if(a[i] == a[i+1]) {
            if(a[i] == a[i+1]) {
                cnt++;
                i++;
            }
            else {
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto a = readints;
    int ab = a[0], bc = a[1];

    int area = ab * bc / 2;
    writeln(area);
}


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

using namespace std;

int main()
{
    string s;
    int k;

    cin >> s >> k;

    int n = s.length();

    vector <int> c(n, 0);

    for (int i = 0; i < n; i++)
    {
        c[i] = ('z' - s[i] + 1) % 26;
    }

    for (int i = 0; i < n; i++)
    {
        if (c[i] <= k)
        {
            s[i] = 'a';
            k -= c[i];
        }
    }

    k = k % 26;
    s[n-1] = ((s[n-1] - 'a' + k) % 26) + 'a';

    cout << s << "\n";

    return 0;
}

Measured memory_bytes: 896
import java.util.*;
import static java.lang.System.*;
public class Main{
    public static void main(String[]$){
        Scanner sc = new Scanner(in);
        int mod=1000000007;
        int n=sc.nextInt();
        int[] a=new int[n];
        for (int i = 0; i < n; i++) {
            a[i]=sc.nextInt();
        }
        HashMap<Integer,Integer> map=new HashMap<>();
        for (int i = 0; i < n; i++) {
            map.put(a[i],map.getOrDefault(a[i], 0)+1);
        }
        if((n%2==0&&map.get(0)!=null)||(n%2==1&&map.get(0)!=1)){
            out.println(0);
            exit(0);
        }
        for(int k:map.keySet()){
            if(k!=0&&map.get(k)!=2){
                out.println(0);
                exit(0);
            }
        }
        out.println(power(2,n/2));
    }
    static long power(long x,int n){
        long mod=1000000007;
        long ans=1;
        while (n>0) {
            if((n&1)==1){
                ans=(ans*x)%mod;
            }
            x=(x*x)%mod;
            n>>=1;
        }
        return ans;
    }
}


Measured memory_bytes: 52596
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,j,n) for(int i=j;i<n;++i)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(), i.rend()
#define INF 1e9
#define LINF 1e18
const int mod = 1e9 + 7;
 
typedef long long i64;
typedef pair<int, int> pi;
 
template <class T> using vt = vector<T>;
template <class T> using vvt = vector<vector<T>>;
 
i64 gcd(i64 n, i64 m) {return (m == 0? n : gcd(m, n % m));}
i64 lcm(i64 n, i64 m) {return (n / gcd(n, m) * m);}
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

  int a, b, c;
  cin >> a >> b >> c;
  if(a + b + c >= 22) cout << "bust\n";
  else cout << "win\n";
}

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

int main()
{
	int ans = 0;
	string S;
	cin >> S;
	rep(i,4)
	{
		if (S[i] == '+')
		{
			ans++;
		}
		else
		{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
typedef long long ll;

const int MAXN = 1000*1000 + 7;
const int SS = 1<<20;
const int INF = 1000*1000*1000 + 7;


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

	int T;
	//cin >> T;
	T = 1;
	while(T--)
	{
		bool x;
		cin >> x;
		cout << (!x) << '\n';
	}
	return 0;
}


Measured memory_bytes: 3636
def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append((i-1)+(n//i-1))
        i += 1
    table = list(set(table))
    a = min(table)
    return a

print(divisor(int(input())))

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;

P p[200000];
signed main() {
	int n; scanf("%d", &n);
	ll Min = LLONG_MAX, Max = LLONG_MIN;
	rep(i, n) {
		scanf("%lld%lld", &p[i].first, &p[i].second);
		if (p[i].first > p[i].second)swap(p[i].first, p[i].second);
	}
	sort(p, p + n);
	//MaxとMinが同じところに入らない
	ll a = INT_MAX, b = 0, c = INT_MAX, d = 0;
	rep(i, n) {
		a = min(a, p[i].first); b = max(a, p[i].first);
		c = min(c, p[i].second); d = max(d, p[i].second);
	}
	ll ans = (b - a)*(d - c);
	//MaxとMinが同じところに入る
	multiset<ll>k, t;
	rep(i, n) {
		k.insert(p[i].first);
		t.insert(p[i].second);
	}
	rep(i, n) {
		ans = min(ans, (*k.rbegin() - *k.begin())*(*t.rbegin() - *t.begin()));
		k.erase(k.find(p[i].first)); t.erase(t.find(p[i].second));
		k.insert(p[i].second); t.insert(p[i].first);
	}
	ans = min(ans, (*k.rbegin() - *k.begin())*(*t.rbegin() - *t.begin()));
	printf("%lld\n", ans);
}

Measured memory_bytes: 24192
k , n = (int(x) for x in input().split())
a = [int(i) for i in input().split()]
b = []
 
for i in range(n-1):
    b.append(a[i+1] - a[i])
    
b.append(a[0] + k -a[n-1])

ans=0 
b.sort()
 
for i in range(len(b)-1):
    ans = b[i] + ans

print(ans)

Measured memory_bytes: 25452
#include <iostream>

int main(int argc, char const* argv[]) {
  using namespace std;

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

  if ((b - 1) % (a - 1) != 0)
    cout << (b - 1) / (a - 1) + 1 << endl;
  else
	  cout << (b-1)/(a-1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define sync ios_base::sync_with_stdio(false); cin.tie(NULL) 
#define input(arr,n) for(ll i1=0;i1<n;i1++ )cin>>arr[i1]
#define rep(n) for(ll i2=0;i2<n;i2++)
#define vmp(v,a,b) v.push_back(make_pair(a,b))
#define si(a) scanf("%lld",&a)
#define pi(a) printf("%lld",a)
#define aset(a,n,k) for(ll i3=0;i3<n;i3++)a[i3]=k; 	
#define mod 1000000007
#define mp(a,b) make_pair(a,b)
#define f first
#define s second 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,greater_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>//s.order_of_key(val) *s.find_by_orde(ind)
using namespace std;
int main()
{
	sync;
	ll a,b,t;
	cin>>a>>b>>t;
	cout<<(t/a)*b;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;

int main()
{
    int n, m, i;
    ll sum=0;
    cin>>n>>m;
    int a[m];
    for(i=0;i<m;i++) {
     cin>>a[i];
        sum=sum+a[i];
    }
    if(sum>n) cout<<"-1"<<endl;
        else cout<<n-sum<<endl;
    return 0;
}



Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
string s;
int main()
{
    int n;
    cin>>n;
    cin>>s;
    long long r=0;long long g=0;long long b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R')
            r++;
        else if(s[i]=='G')
            g++;
        else if(s[i]=='B')
            b++;
    }
    long long p = r*g*b;
    for(int i=0;i<n-2;i++)
        for(int j=i+1;j<n-1;j++)
    {
        long long k=j+(j-i);
        if(k>=n)
            continue;
        if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k])
            p--;
    }
    cout<<p<<endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <set>
#include <cmath>
#include <algorithm>

using namespace std;

#define PB push_back
#define MP make_pair

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vii;

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

int main() {
  int N;
  set<char> arares;
  cin >> N;
  for (int i = 0; i < N; i++) {
    char tmp;
    cin >> tmp;
    arares.insert(tmp);
  }
  string ans = (arares.size()==3)?"Three":"Four";
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}


// Z algorithm
// 前処理でO(N)で配列lcpを求める。
// S自身とS[i:]とが、先頭から最大で何文字一致しているかをO(1)で求めることができる。
vector<int> Zalgo(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (i+k < N && k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}

int main() {    
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        string sub = s.substr(i);
        auto lcps = Zalgo(sub);
        for (int j = 0; j < sub.size(); ++j) {
            // cout << lcps[j] << " " << endl;
            chmax(ans, min(lcps[j], j));
        }
        // END;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int result = k != 1 ? n - k : 0;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 22868
// abc136d.cpp : Gathering Children
#include <bits/stdc++.h>
using namespace std;
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define ot(x) cout<<(x)

int main(){
	string S; cin>>S; int n = S.length();

	bool sepOrCenter = false; // 切れ目 か 集合場所
	int is,il, even, odd;
	is = 0;
	il = -1;

	up(i,0,n,1){
		if(!sepOrCenter && S[i]=='R'){ // 切れ目
			sepOrCenter = true;
			if(il>=0){
				up(i,is,il-1,1) cout<<0<<"\n";
				cout<< (il%2? even:odd) <<"\n"<< (il%2? odd:even) <<"\n";
				is = il+1;
			}
			even = odd = 0;
			il = -1;
		}
		else if(sepOrCenter && S[i]=='L'){ // 集合場所（L側）
			sepOrCenter = false;
			il = i;
		}
		if(i%2) odd++; else even++;
	}

	up(i,is,il-1,1) cout<<0<<"\n";
	cout<< (il%2? even:odd) <<"\n"<< (il%2? odd:even) <<"\n";
	up(i,il+1,n,1) cout<<0<<"\n";
}

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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

string s;

vi pos[26];

int cnt(int c1, int c2){
    if(pos[c1].size() == 0 || pos[c2].size() == 0) return 0;
    int N = pos[c1].size() + pos[c2].size();
    if(pos[c1].size() % 2 == 1) swap(c1, c2);
    vi p;
    int i = 0, j = 0;
    while( i < pos[c1].size() and j < pos[c2].size()  ){
        if(pos[c1][i] < pos[c2][j]) p.pb( (i++) + j );
        else j++;
    }
    for(; i < pos[c1].size(); i++) p.pb(i + j);
    int res = 0;
    for(int i = 0; i < pos[c1].size()/2; i++) {
        res += abs( N-1 - p[i]  -  p[ p.size()-1  -i]   );
    }
    //cout << (char)(c1+'a') << " " << (char)(c2+'a') << ": " << res << endl;
    return res;
}

signed main(){
    fast_io();
    cin >> s;
    FOR(i, 0, s.size()) pos[s[i]-'a'].pb(i);
    int res = 0;
    bool possible = 1;
    FOR(c1, 0, 26) FOR(c2, c1+1, 26) {
        if(pos[c1].size() % 2 == 1 and pos[c2].size() % 2 == 1) possible = 0; 
        res += cnt(c1, c2);
    }
    if(!possible){
        cout << -1 << endl;
        return 0;
    }
    cout << res << endl;
}


Measured memory_bytes: 5512
/**********************************************
*
*  Author: wangyankai
*  Email: wangyk0517@gmail.com 
*  Filename: atcoder_training.cpp
*  Last modified: 2019-07-14 19:41:02
*
***********************************************/

#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <string>
using namespace std;
const int maxn = 1e5 + 5;
long long a[maxn];
int main(int argc,char **argv)
{
    int n;
    while(~scanf("%d", &n))
    {
        for(int i = 1; i <= n; i++) scanf("%lld", &a[i]);
        int ans = 0;
        for(int i = 1; i <= n; i++)
            ans ^= a[i];
        if(!ans) puts("Yes");
        else puts("No");
    }
    return 0;
}


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

namespace ConsoleApplication1
{
    struct Card
    {
        internal int num, vol;
    }

    class Problem
    {
        readonly int MAX = 1000;
        readonly int m;

        Card[] cards;
        int[,] dp;

        public Problem(int m)
        {
            this.m = m;
            cards = new Card[m];
            dp = new int[m + 1, MAX + 1];
        }

        public void SetCards()
        {
            for (int i = 0; i < m; i++)
            {
                string[] input = Console.ReadLine().Split(' ');
                cards[i].num = int.Parse(input[0]);
                cards[i].vol = int.Parse(input[1]);
            }
        }

        public void MakeDP()
        {
            dp[0, 0] = 1;

            for (int i = 0; i < m; i++)
            {
                for (int j = MAX; j >= 0; j--)
                {
                    for (int k = 0; k <= cards[i].vol; k++)
                    {
                        int sum = j + cards[i].num * k;

                        if (dp[i, j] == 0 || sum > MAX) continue;

                        dp[i + 1, sum] += dp[i, j];
                    }
                }
            }
        }

        public int GetConmination(int n)
        {
            return dp[m, n];
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int m = int.Parse(Console.ReadLine());

                if (m == 0) break;

                Problem p = new Problem(m);
                p.SetCards();
                p.MakeDP();

                int g = int.Parse(Console.ReadLine());

                while (g-- > 0)
                {
                    int n = int.Parse(Console.ReadLine());
                    sb.AppendLine(p.GetConmination(n).ToString());
                }
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9348
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(a) sort(a.begin(), a.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define Max(a, b) a = max(a, b)
#define Min(a, b) a = min(a, b)
#define Ans(f, y, n) if(f) cout << y << endl; else cout << n << endl;
#define int long long
#define INF 1000000000000000000
using namespace std;

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using PiP = pair<int, Pii>;
using PPi = pair<Pii, int>;
using bools = vector<bool>;

template<typename T>
void readv(vector<T> &a){ REP(i, a.size()) cin >> a[i]; }
void readi(vector<int> &a){ REP(i, a.size()){cin >> a[i]; a[i]--;} }
template<typename T>
void debug(vector<vector<T>> m){ REP(i, m.size()){ REP(j, m[i].size()){ cout << m[i][j] << ","; } cout << endl;} }



signed main(){

    int N, K; cin >> N >> K;
    vec A(N); readv(A);

    mat dp(42, vec(2, -INF));
    dp[41][0] = 0;
    IREP(i, 41){
        int n1 = 0;
        REP(j, N) if((A[j] >> i) & 1) n1++;
        if((K >> i) & 1){
            Max(dp[i][0], dp[i + 1][0] + ((N - n1) << i));
            Max(dp[i][1], dp[i + 1][1] + (max(n1, N - n1) << i));
            Max(dp[i][1], dp[i + 1][0] + (n1 << i));
        }else{
            Max(dp[i][0], dp[i + 1][0] + (n1 << i));
            Max(dp[i][1], dp[i + 1][1] + (max(n1, N - n1) << i));
        }
    }
    cout << max(dp[0][0], dp[0][1]) << endl;

    return 0;
}


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

using namespace std;

using ll = long long;

int main()
{
    string s;
    cin >> s;
    
    ll N = s.size();
    ll S = stol(s);
    ll P = pow(10LL, N);
    vector<ll> p;
    for (int i = 0; i <= 9; i++) {
        p.emplace_back(i);
    }
    
    ll diff = -1;
    string t;
    do {
        ll T = 0;
        string str;
        for (int i = 0; i < N; i++) {
            T *= 10LL;
            T += p[i];
            str += (p[i] + '0');
        }
        ll U = abs(S - T), V = min(U, P - U);
        if (diff < V) {
            diff = V;
            t = str;
        } else if (diff == V) {
            t = min(t, str);
        }
    } while (next_permutation(p.begin(), p.end()));
    
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 3352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		double w = in.nextInt();
		double h = in.nextInt();
		double x = in.nextInt();
		double y = in.nextInt();

		System.out.print(w*h/2 + " ");
		
		if( w/2.0 == x && h/2.0 == y ) {
			System.out.print(1);
		}else {
			System.out.print(0);
		}

		in.close();
	}
}

Measured memory_bytes: 21460
def solve():
    from sys import stdin
    f_i = stdin
    
    N = int(f_i.readline())
    P = list(map(int, f_i.readline().split()))
    left = P[0]
    
    ans = N * 6
    for i in range(left + 1):
        tP = P[:]
        tP[0] -= i
        t_ans = i
        for j in range(N - 1):
            tpj = tP[j]
            if tpj > 0:
                tP[j + 1] -= tpj
                t_ans += 2 * tpj
        if tP[-1] > 0:
            t_ans += tP[-1]
        if t_ans < ans:
            ans = t_ans
    
    print(ans)

solve()


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

namespace RBST{
	// root = insert(root,k,hoge) ???????????????????????????????????¨????????§??????
	struct T{
		T *l,*r;
		int size;
		char v;
		T(){ l = r = NULL; size=1; }
		T(T *a){ *this = *a; }
		T(char v) : v(v) { l = r = NULL; size=1;}
	};

	int stack_size;
	T *my_new(T *a){ return new T(a); }
	T *my_new(int v){ return new T(v); }

	class BST{
		public:
		static int size(T *c){
			if( !c ) return 0;
			else return c->size;
		}
		static T* update(T *c){
			if( !c ) return 0;
			c->size = size(c->l) + size(c->r) + 1;
			return c;
		}
		static T *merge(T *a,T *b,int perm=0){
			if(!a) return b;
			if(!b) return a;
			if( rand() % ( size(a) + size(b) ) < size(a) ){
				T *R = perm ? my_new(a) : a;
				R->r = merge(a->r,b,perm);
				return update(R);
			}else{
				T *R = perm ? my_new(b) : b;
				R->l = merge(a,b->l,perm);
				return update(R);
			}
		}
		// [0,k) [k,n)
		static pair<T*,T*> split(T *c,int k,int perm=0){
			if(!c) return {0,0};
			T *R = perm ? my_new(c) : c;
			if(k <= size(c->l)){
				pair<T*,T*> s = split(c->l,k,perm);
				R->l = s.second;
				return make_pair(s.first,update(R));
			}else{
				pair<T*,T*> s = split(c->r,k-size(c->l)-1,perm);
				R->r = s.first;
				return make_pair(update(R),s.second);
			}
		}
		static T* insert(T *c,int k,T *newnode,int perm=0){
			//cout << s.first << " " << s.second << endl;
			pair<T*,T*> s = split(c,k,perm);
			return merge(merge(s.first,newnode,perm),s.second,perm);		
		}
		static T* erase(T *c,int k,int perm=0){
			pair<T*,T*> s1 = split(c,k,perm);
			pair<T*,T*> s2 = split(s1.second,1,perm);
			return merge(s1.first,s2.second,perm);		
		}
		// ?????????NULL
		static T* newTree(){ return 0; }
		
		static void view(T *c){
			if(!c)return;
			view(c->l);
			printf("%c",c->v);
			view(c->r);
		}
	};
};

using namespace RBST;

char str[2000010];
T *root[100010];
int main(){
	int N,Q;
	cin >> N >> Q;
	
	for(int i = 0 ; i < N ; i++){
		scanf("%s",str);
		int j = 0;
		while( str[j] ){
			root[i] = BST::insert(root[i],j,new T(str[j]));
			j++;
		}
	}
	for(int i = 0 ; i < Q ; i++){
		int t;
		scanf("%d",&t);
		if( t == 1 ){
			int a,b,c,d;
			scanf("%d%d%d%d",&a,&b,&c,&d);
			--a;
			--b;
			--c;
			--d;
			auto s1 = BST::split(root[a],b);
			auto s2 = BST::split(root[c],d);
			root[c] = BST::merge(s2.first,s1.second);
			root[a] = BST::merge(s1.first,s2.second);
		}else{
			int a,b;
			char c[2];
			scanf("%d%d%s",&a,&b,c);
			--a;
			--b;
			
			root[a] = BST::erase(root[a],b);
			//BST::view(root[a]);puts("");
			//cout << "ins" << " " << b << " " << c << endl;
			
			root[a] = BST::insert(root[a],b,new T(c[0]));
			//BST::view(root[a]);puts("");
			
			
		}
	}
	for(int i = 0 ; i < N ; i++){
		BST::view(root[i]);
		puts("");
	}
}

Measured memory_bytes: 67816
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);



int main(){
    FIN;
    ll n,x;
    cin >> n >> x;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    ll ans = 0;

    if(a[0] > x){
        ans += a[0] - x;
        a[0] = x;
    }

    for(ll i=1;i<n;i++){
        if(a[i]+a[i-1] > x){
            ans += a[i] + a[i-1] - x;
            a[i] = x - a[i-1];
        }
    }

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


Measured memory_bytes: 3948
memorization_dict = dict()
max_number = 10 ** 13
i = 0
power_value = 0
while power_value <= max_number:
    power_value = i ** 5
    memorization_dict[power_value] = i
    i += 1

X = int(input())

solution_1 = 0
solution_2 = 0

for B in memorization_dict.keys():
    A = X + B
    if A in memorization_dict.keys():
        solution_1 = memorization_dict[A]
        solution_2 = memorization_dict[B]
        break
    A = X - B
    if A in memorization_dict.keys():
        solution_1 = memorization_dict[A]
        solution_2 = memorization_dict[B] * (-1)
        break

print(solution_1, solution_2)

Measured memory_bytes: 8948