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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

// 約数を求める
vi divisor(int n){
	vi res;
	for(int i=1; i*i<=n; ++i){
		if(n%i==0){
			res.push_back(i);
			if(i!=n/i){
				res.push_back(n/i);
			}
		}
	}
	return res;
}

int cnt[252525];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, a[252525];
	cin>>n;
	FOR(i, 1, n+1){
		cin>>a[i];
	}
	vi ans;
	FORR(i, 1, n+1){
		if((cnt[i]&1)==a[i]){
			continue;
		}
		ans.push_back(i);
		vi v=divisor(i);
		for(auto &x : v){
			++cnt[x];
		}
	}
	int sz=ans.size();
	cout<<sz<<'\n';
	for(auto &x : ans){
		cout<<x<<'\n';
	}
	return 0;
}


Measured memory_bytes: 3192
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll ceil(ll a, ll b) {  // a÷b以上の最小の整数
    if(b == 0) {
        return 0;
    }
    return (a+b-1)/b;
}
 
int main() {
    ll k;
    cin >> k;

    vl a(k);
    rep(i, k) {
        cin >> a[i];
    }

    if(a[k-1] != 2) {
        out(-1);
        re0;
    }

    vl y(k+1), z(k+1);
    y[k] = z[k] = 2;
    for(ll i = k-1; i >= 1; i--) {
        y[i] = a[i-1]*ceil(y[i+1], a[i-1]);
        ll m = (z[i+1]+a[i])/a[i-1];
        if((z[i+1]+a[i])%a[i-1] == 0) {
            m--;
        }
        z[i] = a[i-1]*m;
        if(y[i] > z[i]) {
            out(-1);
            re0;
        }
    }

    y[0] = y[1];
    z[0] = z[1] + (a[0] - 1);
    
    cout << y[0] << " " << z[0] << endl;
    re0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
  vector<mint> fact, ifact;
  int N;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    N = n;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    if(n <= N) return fact[n]*ifact[k]*ifact[n-k];
    else if(k <= N) {
        mint ans = 1;
        rep(i,k) ans *= n-i;
        ans*=ifact[k];
        return ans;
    } else cout << "Err" << endl;
    return 0;
  }
};
int main(){
    ios::sync_with_stdio(false);
    int n,a,b;
    cin >> n >> a >> b;
    combination c(max(a,b));
    mint ans = 1;
    vector<mint> x2(32,2); //2^(2^i)
    rep(i,31) x2[i+1] = x2[i]*x2[i];
    rep(i,32) {
        if(n>>i&1) ans *= x2[i];
    }
    ans = ans - 1 - c(n,a) - c(n,b);
    cout << ans << endl;
}


Measured memory_bytes: 3328
# Problem A - ringing

from itertools import combinations

# input
a, b, c = map(int, input().split())

# initialization
combi_list = list(combinations(['A', 'B', 'C'], 2))
min_cost = 30000

# count
for combi in combi_list:
    tmp = 0
    if combi[0]=='A':
        tmp += a
    elif combi[0]=='B':
        tmp += b
    else:
        tmp += c

    if combi[1]=='A':
        tmp += a
    elif combi[1]=='B':
        tmp += b
    else:
        tmp += c

    min_cost = min(min_cost, tmp)

# output
print(min_cost)


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  1000LL
#define tmod            998244353
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<ll> &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n);

int main()
{
fast;
ll q=1,t;
//cin >> q;
t= q;
while(q--)
{
    ll n,m,k,i,j,l,r,c=0,g,counter=0,u,v,d,e,w,p,x,y,flag=1;
    //n=m=i=j=l=r=a=t=b=c=u=v=w=p=x=y=0;
    cin >> n ;
    vector<ll> A(n),B(n),C(n-1);
    CIN(A,0,n);
    CIN(B,0,n);
    CIN(C,0,n-1);
    ll sum = 0;
    for(i=0;i<n;i++)
    {
        sum += B[A[i]-1];
        if(i!=0 and A[i]==A[i-1]+1)
        {
                sum += C[A[i-1]-1];
        }
    }

    cout << sum << endl;



}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2);
    if(n%2==0){return (temp*temp)%mod;}
    else{return (b*((temp*temp)%mod))%mod;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<ll> &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid]==ser)
    {
        return mid;
    }
    else if(PS[mid] > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}

void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}


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

using namespace std;

int main() {
    string str;
    cin >> str;
    size_t p1 = str.find_first_of('C');
    size_t p2 = str.find_last_of('F');
    puts( p1!=string::npos&&p2!=string::npos&&p1<p2 ? "Yes" : "No" );
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) REP((i),0,(n))
#define RREP(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define rrep(i,n) RREP(i,n,0)
#define each(it,X) for(__typeof((X).begin())  it=(X).begin();it!=(X).end();it++)
#define all(v) ((v).begin(),(v).end())
#define fi first
#define se second
#define pb push_back
typedef pair<int,int>pr;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef set<int>si;
const int INF=1070000000ll;
const int mod=1000000007ll;
const double EPS=1e-9;
const double PI=3.14159265;
double getS(int x){
    int d=360;
    double S=0;
    rep(i,x-1){
        int z;cin>>z;
        d-=z;
        S+=fabs(sin(1.0*z/180*PI));
    }
    S+=fabs(sin(1.0*d/180*PI));
    return S;
}
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    double S[2];

    int x;
    while(cin>>x,x){
        S[0]=getS(x);
        cin>>x;
        S[1]=getS(x);
        if(fabs(S[0]-S[1])<EPS)cout<<0<<endl;
        else if(S[0]>S[1])cout<<1<<endl;
        else cout<<2<<endl;
    }
    return 0;
}

Measured memory_bytes: 1228
n, m = map(int, input().split())
city = []
for i in range(m):
    x, y = map(int, input().split())
    city.append(list([x, y, i]))

city.sort()
cnt = 1

tmppref = city[0][0]

for i in range(m):
    city[i][1] = cnt
    cnt += 1
    if i < m - 1 and tmppref != city[i + 1][0]:
        cnt = 1
        tmppref = city[i+1][0]
city = sorted(city, key=lambda x: x[2])
for i in range(m):
    pref = city[i][0]
    num = city[i][1]
    ans = str(pref).zfill(6) + str(num).zfill(6)
    print(ans)



Measured memory_bytes: 28640
n, k = STDIN.gets.split.map(&:to_i)
r, s, p = STDIN.gets.split.map(&:to_i)
t = STDIN.gets.strip.split('')

arrays = t.size.times.inject([]) {|array, index|
  array[index % k] = [] unless array[index % k]
  array[index % k] << t[index]
  array
}

scores = arrays.map {|array|

  before = ''

  array.map {|i|
    case i
    when before
      before = ''
      0
    when 'r'
      before = i
      p
    when 's'
      before = i
      r
    when 'p'
      before = i
      s
    end
  }
}

puts scores.flatten.inject(0) {|acc, i| i + acc }

Measured memory_bytes: 17404
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 1LL << 60;

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

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;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}


//cout<<""<<endl;
int main(){
  ll N,W;cin>>N>>W;
  vl w(N),v(N);
  rep(i,N){
    cin>>w[i]>>v[i];
  }
  vvl dp(101,vl(100001));
  rep(i,N){
    dp[i][0]=0;
  }
  rep(i,N){
    for(ll j=0;j<=W;j++){
      if(j>=w[i]){
        dp[i+1][j]=max(dp[i+1][j],dp[i][j-w[i]]+v[i]);
      }
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  cout<<dp[N][W]<<endl;
}





Measured memory_bytes: 83324
#include <iostream>
#include <cassert>
//#define NDEBUG
int main(void){
	using namespace std;
  
	static const int INPUT_NUM_MIN = 1;
	static const int INPUT_NUM_MAX =  10000;
	int input_num[3];
	int min_num = 10000;
	int midle_num = 0;
	int max_num = 1;
	int index_min = 0;
	int index_max = 0;
	cin >> input_num[0];
	cin >> input_num[1];
	cin >> input_num[2];
     
	assert(INPUT_NUM_MIN <= input_num[0] && input_num[0] <= INPUT_NUM_MAX); /* Precondition */
	assert(INPUT_NUM_MIN <= input_num[1] && input_num[1] <= INPUT_NUM_MAX); /* Precondition */
	assert(INPUT_NUM_MIN <= input_num[2] && input_num[2] <= INPUT_NUM_MAX); /* Precondition */
 
	/* Calculatoin */
	for (int i=0; i<3; i++){			/* Calculatoin Min */
		if(input_num[i] < min_num){
			min_num = input_num[i];
			index_min = i;
		}
	}
	for (int i=0; i<3; i++){			/* Calculatoin Max */
		if(input_num[i] > max_num){
			max_num = input_num[i];
			index_max = i;
		}
	}
	for (int i=0; i<3; i++){			/* Calculatoin Midle */
		if(i != index_min && i != index_max){
			midle_num = input_num[i];
		}
	}
	cout << min_num << " " << midle_num << " " << max_num << endl;
	return 0;
}

Measured memory_bytes: 3096
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String s = in.next();
        int ans = 0;
        for(int i = 0; i < 3; i++){
            if(s.charAt(i) == '1') ans++;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 20948
import math as ma

def bs(num, li):
    low, high = 0, len(li)
    if num >= li[low] and num <= li[high-1]:
        while(low <= high):
            center = ma.floor((low + high)/2 )
            if li[center] < num:
                low = center + 1
            elif li[center] > num:
                high = center -1
            else:
                return True
                break

flag = False
cnt = 0

n = int(input())
li1 = list(map(int, input().split()))
m = int(input())
li2 = list(map(int, input().split()))

for i in li2:
    flag = bs(i, li1)
    if flag:
        cnt += 1
print(cnt)

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(NAME, NUM) for (int NAME = 0; NAME < (NUM); ++NAME)
#define BREP(NAME, NUM) for (int NAME = (NUM)-1; NAME >= 0; --NAME)
#define ALL(NAME) (NAME).begin(), (NAME).end()

#define cMOD 1000000007ULL
#define cINF ((1ll<<62)-1)
#define cINFINT ((1<<30)-1)

ll n;
vector<ll> x;
vector<ll> y;
map<ll,vector<ll>> xx;
map<ll,vector<ll>> yy;
map<ll,ll> yetx;
map<ll,ll> yety;
vector<bool> b;

ll calc( ll curi, ll curx, ll cury, ll&xn, ll&yn )
{
	ll sum = 1;
	b[curi] = true;
	if( yetx[curx] == 0 )
	{
		++yn;
		yetx[curx] = 1;
		for( auto& i : xx[curx] ) if( !b[i] )
		{
			sum += calc( i, x[i], y[i], xn, yn );
		}
	}
	if( yety[cury] == 0 )
	{
		++xn;
		yety[cury] = 1;
		for( auto& i : yy[cury] ) if( !b[i] )
		{
			sum += calc( i, x[i], y[i], xn, yn );
		}
	}
	return sum;
}

int main()
{
	cin>>n;
	x.assign( n, 0 );
	y.assign( n, 0 );
	b.assign( n, false );
	REP(i,n)
	{
		cin>>x[i]>>y[i];
		xx[x[i]].push_back( i );
		yy[y[i]].push_back( i );
	}

	ll sum = 0;
	REP( i, n ) if( !b[i] )
	{
		yetx.clear();
		yety.clear();
		ll xn = 0, yn = 0;
		ll c = calc( i, x[i], y[i], xn, yn );
		//cout << i << ":" <<  xn << " " << yn << " " << c << endl;
		sum += xn * yn - c;
	}


	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 29824
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        mut a: [i64; n]
    }
    a.sort();
    a.reverse();

    let mut ans = a[0];
    let mut pos = 1;
    let mut count = 2;
    let mut to_next = false;
    while count < n {
        ans += a[pos];
        count += 1;
        if to_next {
            pos += 1;
            to_next = false;
        } else {
            to_next = true;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6244
#include<cstdio>

#include<algorithm>

using namespace std;

const int N=1e6+5;

int n,m,x,maxx=0;

int a[N];


int gcd(int p,int q)

{

while(p%q!=0)
{
	int t=p;
	p=q;
	q=t%q;
}
	return q;
}

bool check(int x)
{
	int k=a[n];
	if(x%k==0)return 1;
	else return 0;
}

int main()
{
	
//freopen("aa.txt","r",stdin);
//freopen("aaaa.txt","w",stdout);

int k;
scanf("%d%d",&n,&k);

for(int i=1;i<=n;++i)
{

	scanf("%d",&x);

	if(i==1)a[i]=x;
	else a[i]=gcd(a[i-1],x);
	if(x>maxx)	maxx=x;
}

if(check(k)&&k<=maxx)
	puts("POSSIBLE");
else
	puts("IMPOSSIBLE");


return 0;

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define rrdebug(i, j, x) rep(i, alength(x))rep(j, alength(x[i]))cout << #x << "[" << i << "][" << j << "]:" << x[i][j] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) {a = b; return true;} return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) {a = b; return true;} return false; }
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){ if(!b)return a; return gcd(b, a % b); }
intl lcm(intl a,intl b){ return a / gcd(a, b) * b; }
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    intl h[n];
    cin(i,h);
    intl a[m],b[m];
    rep(i,m){
        cin >> a[i] >> b[i];
    }
    bool f[n];
    rep(i,n)f[i] = true;
    rep(i,m){
        if(h[a[i]-1] > h[b[i]-1])f[b[i]-1] = false;
        else if(h[a[i]-1] < h[b[i]-1])f[a[i]-1] = false;
        else {
            f[a[i]-1] = false;
            f[b[i]-1] = false;
        }
    }
    intl cnt = 0;
    rep(i,n){
        cnt += f[i];
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6068
#include <bits/stdc++.h>
using namespace std;
const long MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    long dp[100001][4] = {{1}}, n = s.size();
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 4; j++) dp[i + 1][j] = dp[i][j];
        if(s[i] == 'A') dp[i + 1][1] = (dp[i][1] + dp[i][0]) % MOD;
        if(s[i] == 'B') dp[i + 1][2] = (dp[i][2] + dp[i][1]) % MOD;
        if(s[i] == 'C') dp[i + 1][3] = (dp[i][3] + dp[i][2]) % MOD;
        if(s[i] == '?'){
            dp[i + 1][0] = dp[i][0] * 3 % MOD;
            dp[i + 1][1] = (dp[i][1] * 3 + dp[i][0]) % MOD;
            dp[i + 1][2] = (dp[i][2] * 3 + dp[i][1]) % MOD;
            dp[i + 1][3] = (dp[i][3] * 3 + dp[i][2]) % MOD;
        }
    }
    cout << dp[n][3] << endl;
}


Measured memory_bytes: 3584
package main

import (
  "fmt"
  "sort"
)

func main(){
  var N, K int
  fmt.Scan(&N, &K)
  A := make([]int, N)
  for i:=0; i<N; i++{
    fmt.Scan(&A[i])
  }
  // fmt.Println(A)
  sort.Ints(A)
  // fmt.Println(A)

  // m = map[int]int{}
  m := make(map[int]int, N)
  for i:=0; i<N; i++{
    m[A[i]] += 1
  }
  // fmt.Println(m)

  l := []int{}
  for _, value := range m {
    l = append(l, value)
  }
  // fmt.Println(l)
  sort.Ints(l)
  // fmt.Println(l)
  kinds := len(l)
  ans := 0
  for i:=0; i<(kinds-K); i++{
    ans += l[i]
  }
  fmt.Println(ans)
}


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

struct vec{double x;double y;};
double naiseki(vec a,vec b)
{
	return a.x*b.x+a.y*b.y;
}

int main()
{
	double xp1,xp2,yp1,yp2;
	cin>>xp1>>yp1>>xp2>>yp2;
	int q;cin>>q;
	vec base;
	base.x=xp2-xp1;
	base.y=yp2-yp1;
	
	for(int i=0;i<q;i++)
	{
		double s,t;
		cin>>s>>t;
		vec hypo;
		hypo.x=s-xp1;
		hypo.y=t-yp1;
		cout<<fixed<<setprecision(10)<<xp1+base.x*naiseki(hypo,base)/naiseki(base,base)<<" ";
		cout<<(double)yp1+base.y*naiseki(hypo,base)/naiseki(base,base)<<endl;
	}
	return 0;
}

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

int main(){

  ll n,k;

  cin >> n >> k;
  
  n = n%k;
  
  if(n >= abs(n-k)){
    n = abs(n-k);
  }
  
  cout << n << endl;
 
  
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define STR 31
#define PAGE 100

typedef struct{
	char word[STR];
	int page[PAGE];
	int count;
}LIST;

void set_ward(char ward[PAGE][STR],LIST L[],int count){
	for(int i=0;i<count;i++){
		strcpy(ward[i],L[i].word);
	}
	char tmp[STR];
	for(int i=0;i<(count-1);i++){
		for(int j=(count-1);j>i;j--){
			if(strcmp(ward[j-1],ward[j])>0){
				strcpy(tmp,ward[j-1]);
				strcpy(ward[j-1],ward[j]);
				strcpy(ward[j],tmp);
			}
		}
	}
}

void sort_page(LIST L[],int count){
	int tmp;
	for(int i=0;i<count;i++){
		for(int j=0;j<(L[i].count-1);j++){
			for(int k=(L[i].count-1);k>j;k--){
				if(L[i].page[k-1]>L[i].page[k]){
					tmp=L[i].page[k-1];
					L[i].page[k-1]=L[i].page[k];
					L[i].page[k]=tmp;
				}
			}
		}
	}
}

int main(void){
	LIST L[PAGE];

	char w[STR];
	int page;
	int count=0;
	int flag=0;

	for(int i=0;i<PAGE;i++){
		L[i].count=0;
	}

	while(scanf("%s %d",w,&page)!=EOF){
		flag=0;
		for(int i=0;i<count;i++){
			if(strcmp(L[i].word,w)==0){
				L[i].page[L[i].count]=page;
				L[i].count++;
				flag=1;
				break;
			}
		}
		if(flag==0){
			L[count].page[0]=page;
			strcpy(L[count].word,w);
			L[count].count++;
			count++;
		}
	}

	sort_page(L,count);

	char ward[PAGE][STR];
	set_ward(ward,L,count);

	for(int i=0;i<count;i++){
		printf("%s\n",ward[i]);
		for(int j=0;j<count;j++){
			if(strcmp(ward[i],L[j].word)==0){
				for(int k=0;k<L[j].count;k++){
					printf("%d",L[j].page[k]);
					if(k==(L[j].count-1)){
						printf("\n");
					}else{
						printf(" ");
					}
				}
				break;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 2024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi acos(-1.0)

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    bool hash[256] = {};
    cin >> s;
    REP(i, s.size()){
        hash[(int)s[i]] = true;
    }

    FOR(i, 'a', 'z'){
        if(hash[i] == false){
            cout << (char)i << "\n";
            return 0;
        }
    }
    cout << "None" << "\n";
    return 0;
}


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

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,l; cin >> n >> l;
    vector<int> a(n);
    int acc = 0;
    for(int i = 1; i <= n; i++){
        a[i-1] = l + i - 1;
        acc += a[i-1];
    }
    int ans = 1e9;
    int val = 0;
    for(int i: a)
        if(ans > abs(acc - (acc - i))){
            ans = abs(acc - (acc - i));
            val = i;
        }
    cout << acc - val <<"\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef unsigned long long ull;
typedef long long ll;
#define __TRUE "Yes"
#define __FALSE "No"
#define cout(x) cout << (x) << endl
#define MAX 100001
using namespace std;

int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<string> T;
  for(int i=0;i<s.size();i++) {
    for(int j=1;j<=k;j++) {
      T.push_back(s.substr(i,j));
    }
  }
  sort(T.begin(), T.end());
  T.erase(unique(T.begin(), T.end()), T.end());
  cout << T[k-1] << endl;
}

Measured memory_bytes: 1660
#include<iostream>

using namespace std;

int main () {

    int W, H, x, y, r;

    cin >> W >> H >> x >> y >> r;

    if (x-r < 0 || x+r > W || y-r < 0 || y+r > H) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;

}

Measured memory_bytes: 3088
from collections import deque

N,q=map(int,input().split())
Q=deque()
#deque型はデータをキューやスタック、デックとして効率的に扱うことができる

for i in range(N):
    name,time=input().split()
    Q.append([name,int(time)])

sum=0

while Q:
    
    qt = Q.popleft()
    #print(qt)
    if qt[1] <= q:
        sum += qt[1]
        print(qt[0], sum)
    else:
        sum += q
        qt[1] -= q
        Q.append(qt)




Measured memory_bytes: 13280
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int a, b,c;
    cin >> a>> b >>c;
    if(c==a+b||a==b+c||b==a+c){
        cout << "Yes";
    }else{
        cout << "No";
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll h, w, ca, cb, ans;
bool v[405][405];
char a[405][405];

void f(ll p, ll q) {
	if(p<1 || q<1 || p>h || q>w || v[p][q]) return;
	v[p][q] = 1;
	if(a[p][q]=='#') ca++; else cb++;
	if(a[p][q] != a[p+1][q]) f(p+1, q);
	if(a[p][q] != a[p-1][q]) f(p-1, q);
	if(a[p][q] != a[p][q+1]) f(p, q+1);
	if(a[p][q] != a[p][q-1]) f(p, q-1);
}

int main() {
	ll i, j;
	cin>>h>>w;
	for(i=1; i<=h; i++) scanf("%s", &a[i][1]);
	for(i=1; i<=h; i++) for(j=1; j<=w; j++) {
		if(!v[i][j]) {
			ca = cb = 0;
			f(i, j);
			ans += ca * cb;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 13056
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    int n;cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
        b[a[i]-1]=i;
    }
    int res = 1,tmp=1;
    for(int i=1;i<n;++i){
        if(b[i]>b[i-1]){
            tmp++;
        }
        else{
            tmp=1;
        }
        res=max(res,tmp);
    }
    cout<<n-res<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long int
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll x;
int32_t main(){
CODE_START;
cin>>x;
ll a,b;
a=x*x;
b=a*x;
cout<<x+a+b<<endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> inline void chmin(T& a, T b) {if (a>b) a=b; }
template<class T> inline void chmax(T& a, T b) {if (a<b) a=b; }
inline void print() { cout << endl; }
template <class Head, class... Tail> inline void print(Head&& head, Tail&&... tail) {cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...);}
template <class T> inline void print(vector<T>& vec) { for (auto& a : vec) {cout << a; if (&a != &vec.back()) cout << " "; } cout << endl;}
template <class T> inline void print(vector<vector<T>>& df) { for (auto& vec : df) { print(vec); }}
typedef long long ll;
const ll LINF = 1e18;
const int INF = 1e9;


int main() { 
    int x; cin >> x;
    if(x==3 || x==5|| x==7) cout << "YES" << endl;
    else cout << "NO" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const char nl = '\n';
using namespace std;
typedef long long ll;
typedef double ld;
typedef complex<ld> pt;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int N = 3000;

int n;
ld p[N];
ld dp[N];

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j >= 0; j--) {
      dp[j] = p[i] * dp[j-1] + (1 - p[i]) * dp[j];
    }
  }
  cout << fixed << setprecision(10) << accumulate(dp + (n+1)/2, dp + n + 1, 0.L) << nl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int main()
{
int K;
int b=0;
cin >>K;
std::string S;
cin >>S;

for(int a=0;a<=100;a++){
if(S[a]=='\0'){
break;
}
b++;
}

if(b<=K){
std::cout <<S<<std::endl;
}

if(b>K){
std::cout<<S.substr(0,K)<<"..."<<std::endl;
}

return 0;
}

Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
 
    /**
     * @param args
     * @throws IOException 
     */
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int a = Integer.parseInt(s[0]);
        int b = Integer.parseInt(s[1]);
        int menseki = a*b;
        int syu = (a+b)*2;
        System.out.println(menseki+" "+syu);
    }
 
}


Measured memory_bytes: 24232
//#pragma comment(linker, "/STACK:102400000,102400000")
//#include <initializer_list>
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define slla(n) scanf("%lld", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define DE(val) cout<<#val<<": "<<val<<endl;
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); repp(i,1,___T)

const int dx44[5] = { 0,-1,-1,1,1 };
const int dy44[5] = { 0,-1,1,-1,1 };

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 5e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes");}// exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No");}// exit(0); }
void one() { puts("-1"); exit(0); }

int n;
char v[maxn];
int val[maxn];
int c[maxn];
int dp[maxn];
vector<int>pos[maxn];

void solve()
{
    sa(n);
    scanf("%s",v+1);
    n = strlen(v+1);
    repp(i,1,n)
    {
        val[i] = v[i] - '0';
    }

    repp(i,1,n)
    {
        c[i]=val[i];
    }
    int st = -1;
    int flag = 0;
    repp(i,3,n)
    {
        if(c[i]&&flag)
        {
            pos[i].push_back(st);
        }
        else if(c[i] == 1&&c[i-1]==0&&c[i-2]==1)
        {
            flag = 1;
            st = i-2;
            pos[i].push_back(st);
        }
        else
        {
            flag = 0;
            st = -1;
        }
    }
    flag = 0;
    repp(i,1,n)
    {
        c[i] = val[i];
    }
    st = -1;
    for(int i=n-2;i>=1;i--)
    {

        if(c[i]&&flag)
        {
            pos[st].push_back(i);
        }
        else if(c[i] == 1&&c[i+1]==0&&c[i+2]==1)
        {
            flag = 1;
            st = i+2;
            pos[st].push_back(i);
        }
        else
        {
            flag = 0;
            st = -1;
        }
    }
    repp(i,3,n)
    {
        dp[i] = dp[i-1];
        rep(k,0,pos[i].size())
        {
            dp[i] = max(dp[i], dp[pos[i][k] - 1] + i - pos[i][k] - 1);
        }
    }
    cout<<dp[n]<<endl;
}

int main()
{

    solve();
    // system("pause");
    return 0;
}

Measured memory_bytes: 36608
#include <limits.h>
#include <stdio.h>

int n, a[10000];

int main(void) {
    int i, min = INT_MAX, max = INT_MIN;
    long sum = 0;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
        if (a[i] < min) min = a[i];
        if (a[i] > max) max = a[i];
        sum += a[i];
    }
    
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}



int main(){
    int a,b;cin>>a>>b;
    cout<<(a%b==0 ? 0:1);
}



Measured memory_bytes: 256
n = int(input())
a = [0] * (n+1)
for i in range(n):
    a[i+1] = int(input())

ans = 0
idx = 1
for i in range(n-1):
    if a[idx] == 2:
        print(ans+1)
        exit()
    else:
        ans += 1
        idx = a[idx]
print(-1)

Measured memory_bytes: 6980
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int max = -1000000000;
		int min = 100000000;
		long sum = 0;

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a > max) {
				max = a;
			}
			if (a < min) {
				min = a;
			}
			sum = sum + a;
		}
		System.out.println(min + " " + max + " " + sum);
	}

}



Measured memory_bytes: 42812
// Last Change: 05/11/2019 21:15:58.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  int N, K;
  cin >> N >> K;
  cout << N - K + 1;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };

const int D = 80*160+10;
const int D2 = D * 2;
typedef bitset<D2> bs;
bs dp[85][85];

int main(){
  int H,W;cin>>H>>W;
  vector<vector<int>> num(H,vector<int>(W));
  rep(i,H) {
    rep(j,W) {
      cin>>num[i][j];
    }
  }
  rep(i,H) {
    rep(j,W) {
      int b;cin>>b;
      num[i][j] = abs(num[i][j] - b);
    }
  }
  dp[0][0][D-num[0][0]] = dp[0][0][D+num[0][0]] = 1;
  rep(i,H){
    rep(j,W){
      if(i) {
	dp[i][j] |= dp[i-1][j]<<num[i][j];
	dp[i][j] |= dp[i-1][j]>>num[i][j];
      }
      if(j) {
	dp[i][j] |= dp[i][j-1]<<num[i][j];
	dp[i][j] |= dp[i][j-1]>>num[i][j];
      }
    }
  }
  int ans = D2;
  rep(i,D2) {
    if(dp[H-1][W-1][i]) {
      ans = min(ans,abs(D-i));
    }
  }
  cout<<ans<<endl;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int Q=in();
	map<string,int> M;
	REP(i,Q){
		int q=in();
		if(q==1){
			out(M[in<string>()]);
		}
		else{
			string key=in<string>();
			M[key] = in();
		}
	}
	return 0;
}


Measured memory_bytes: 25872
n = int(input())
a = list(map(int, input().split()))
m = int(input())
q = list(map(int, input().split()))

ans = []
for i in range(2**n):
    cnt = 0
    for j in range(n):
        if ((i>>j)&1): cnt += a[j]
    ans.append(cnt)
for x in q:
    print('yes' if (x in ans) else 'no')


Measured memory_bytes: 43080
def main():
    even, odd = map(int, input().split())
    cases = 0
    if even >= 2:
        cases += 1
        for i in range(3, even + 1):
            cases = cases - 1 + i
    if odd >= 2:
        cases += 1
        for i in range(3, odd + 1):
            cases = cases - 1 + i

    print(cases)


if __name__ == '__main__':
    main()

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

int n, a, b;
int main()
{
  scanf("%d %d %d", &n, &a, &b);
  
  if (n*a > b)
    printf("%d\n", b);
  else
    printf("%d\n", n*a);

  return 0;
}




Measured memory_bytes: 256
import math

a, b, h, m = map(int, input().split())

min = h * 60 + m
short = 0.5 * min
long = 6 * m

if abs(short - long) >= 180:
    deg = 360 - abs(short - long)

else:
    deg = abs(short - long)

coss = math.cos(math.radians(deg))
c = (a ** 2 + b ** 2 - 2 * a * b * coss) ** 0.5
#print(c)
print('{:.20f}'.format(c))


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

int main() {
    ll N, P;
    string S;
    cin >> N >> P >> S;
    vector<ll> vec(N); // 文字列の各桁を配列に起こす
    for (ll i = 0; i < N; i++) {
        vec[i] = S[i]-'0';
    }

    ll ans = 0;

    if (P == 2) {
        vector<bool> two(N, false);
        for (ll i = 0; i < N; i++) {
            if (vec[i] % 2 == 0) {
                two[i] = true;
            }
            if (two[i]) ans += i+1;
        }
        cout << ans << endl;
    }
    else if (P == 5) {
        vector<bool> five(N, false);
        for (ll i = 0; i < N; i++) {
            if (vec[i] % 5 == 0) {
                five[i] = true;
            }
            if (five[i]) ans += i+1;
        }
        cout << ans << endl;
    }

    else {
        vector<ll> modten(N); // modten[i]は10^(i)乗のmod pの値
        for (ll i = 0; i < N; i++) {
            if (i == 0) modten[i] = 1;
            else {
                modten[i] = modten[i-1]*10;
                modten[i] %= P;
                if (modten[i] < 0) modten[i] += P;
            }
        }
        vector<ll> sub(N+1); // sub[i]は左からi番目の数以右で作られる部分文字列のmod pの値
        for (ll i = 0; i <= N; i++) {
            if (i == 0) sub[i] = 0;
            else {
                sub[i] = sub[i-1] + vec[N-i]*modten[i-1];
                sub[i] %= P;
                if (sub[i] < 0) sub[i] += P;
            }
        }

        map<ll, ll> MAP;
        for (ll i = 0; i <= N; i++) {
            MAP[sub[i]] ++;
        }
        for (pair<ll, ll> t : MAP) {
            ll count = t.second*(t.second-1);
            count /= 2;
            ans += count;
        }

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

Measured memory_bytes: 5764
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
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; }
const ll INF = 1LL << 60;
int main(){
    ll n,k,r,s,p; cin >> n >> k >> r >> s >> p;
    string t; cin >> t;

    ll dp[100005][3];
    rep(i,100005)rep(j,3) dp[i][j] = 0;
    map<char,ll> po;
    po['r']=p; po['s']=r; po['p']=s;
    map<char,int> c2i;
    c2i['r']=0; c2i['s']=1; c2i['p']=2;
    rep(i,k)rep(j,3){
        if(c2i[t[i]]==j) dp[i][j]=po[t[i]];
    }

    rep(i,n-k)rep(j,3){
        ll ni=i+k;
        rep(nj,3){
            if (j==nj) continue;
            if (c2i[t[ni]]==nj) chmax(dp[ni][nj], dp[i][j]+po[t[ni]]);
            else chmax(dp[ni][nj], dp[i][j]);
        }
    }
    ll ans=0;
    rep(i,k){
        ans+=max({dp[n-1-i][0],dp[n-1-i][1],dp[n-1-i][2]});
    }
    // rep(i,n){
    //     rep(j,3) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2816
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int ans;
string st, gl;
void dfs(int turn, string cur, vector< vector<string> > &words) {
    int len = cur.length();
    if(len > gl.length()) return;
    if(cur == gl) {
        chmin(ans, turn);
        return;
    }

    rep(i,0,words.size()) {
        string nxt = cur;
        int pos = nxt.find(words[i][0]);
        while(pos != string::npos) {
            nxt.replace(pos, words[i][0].size(), words[i][1]);
            pos = nxt.find(words[i][0], pos + words[i][1].size());
        }
        // cout << "nxt = " << nxt << endl;
        if(cur != nxt) dfs(turn+1, nxt, words);
    }
}

signed main() {
    int N;
    while(cin >> N, N) {
        ans = INF;
        vector< vector<string> > vs(N, vector<string>(2));
        rep(i,0,N) rep(j,0,2) {
            cin >> vs[i][j];
        }
        cin >> st >> gl;
        dfs(0, st, vs);
        if(ans == INF) cout << -1 << endl;
        else cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3148
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#include <cstdio>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>

#define MOD 1000000007
#define INF 1012345678
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;

int main() {
    int A, B, T;
    cin >> A >> B >> T;
    cout << T / A * B << endl;
    getchar(); getchar();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI 3.141592653589793
int mod = 1e9 + 7;
int INF = 2e18;

signed main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> food(N);
    for (int i = 0; i < N; i++) cin >> food[i].first >> food[i].second;
    sort(food.begin(),food.end(),[](pair<int,int> x, pair<int,int> y){
        return x.first < y.first;
    });
    vector<vector<int>> dp(N + 5, vector<int>(T + 30, 0));
    int ans = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < T; j++) {
            if (dp[i][j] == -1) continue;
            int before = food[i].first;
            int value = food[i].second;
            dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
            if (j + before < T) {
                dp[i + 1][j + before] = max(dp[i + 1][j + before], dp[i][j] + value);
            } else {
                ans = max(ans, dp[i][j] + value);
            }
        }
    }
    for (int i = 0; i < T; i++) ans = max(ans, dp[N][i]);
    cout << ans << endl;
}


Measured memory_bytes: 71680
N = int(input())
L = [i for i in map(int,input().split())]
t = 0
res = 0
for i in range(len(L)):
    for j in range(i):
        if L[j] > L[i]:
            t = 1
            break
    if t==0:
        res += 1
    t = 0
print(res)

Measured memory_bytes: 3064