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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

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

int main(){
    int n;cin>>n;
    vll x(n);
    if(n==1){
        cout<<1<<endl;
        return 0;
    }
    rep(i,n){
        cin>>x[i].F>>x[i].S;
    }
    sort(all(x));
    vll d;
    rep(i,n-1){
        for(int j=i+1;j<n;++j){
            d.PB(MP((x[i].F-x[j].F),(x[i].S-x[j].S)));
        }
    }
    sort(all(d));
    ll a=d[0].F,b=d[0].S,cnt=1,ans=0;
    int z=d.size();
    for(int i=1;i<z;++i){
        if(a==d[i].F&&b==d[i].S){
            cnt++;
        }
        else{
            ans=max(ans,cnt);
            a=d[i].F;b=d[i].S;
            cnt=1;
        }
    }
    ans=max(ans,cnt);
    cout<<n-ans<<endl;
}

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

ll f(ll a, ll b)
{
	if (a == 0) {
		return -b;
	}
	if (a == 1) {
		return 2 * b * a + f(0, 1);
	}
	return 2 * (b / a) * a + f(b % a, a);
}

int main()
{
	ll n, x;
	cin >> n >> x;
	ll a = x, b = n - x;
	if (a > b) {
		swap(a, b);
	}
	cout << n + f(a, b) << endl;
	return 0;
}



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

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

  bool yes = false;

  for(int i=1;i<=b;i++) {
    int mul = a * i;
    if(mul % b == c) {
      yes = true;
      break;
    }
  }

  if(yes) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}

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

int main(){
  ll n, sum=0;
  cin >> n;
  vector<ll> v(n,0);
  r(i,n)cin >> v.at(i);
  r(i,n-1){
    for(int j=i+1;j<n;j++){
      sum+=v.at(i)*v.at(j);
    }
  }
  cout << sum << endl;
}


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

using namespace std;
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
const int N=2e5 + 5;
const ll mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    cin >> n;
    map<int, int> mp;
    ll res = 0;
    for(int i=1;i<=n;i++) {
        ll x;
        cin >> x;
        res += mp[i-x];
        mp[i+x]++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 20492
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<ull> vul;
#define For(i, n) for(ll i = 0; i < n; i++)
#define len(n) (ll)(n).size()
#define FAST_IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Sort(a) sort(a.begin(), a.end())

vector<vl> g;
vector<bool> used;
vl ts;
ll dp[(ll)1e5];

void dfs(ll v) {
    used[v] = true;
    for (ll to : g[v]) if (!used[to]) dfs(to);
    ts.push_back(v);
}

int main() {
    FAST_IO;
    ll n, m;
    cin >> n >> m;
    g.resize(n);
    For(i, m) {
        ll v, to_v;
        cin >> v >> to_v;
        v--; to_v--;
        g[v].push_back(to_v);
    }
    used.resize(n);
    For(i, n) if (!used[i]) dfs(i);
    reverse(ts.begin(), ts.end());
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll to_v : g[ts[i]]) {
            dp[to_v] = max(dp[to_v], dp[ts[i]] + 1);
            ans = max(ans, dp[to_v]);
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12316
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(in.readLine());
		
		int[] a = new int[n];
		for (int i = 0; i < a.length; i++) a[i] = Integer.parseInt(in.readLine());
		
		long c = 0;
		for (int i = 0; i < a.length - 1; i++) {
			if(a[i] % 2 == 0) {
				c += a[i] / 2;
				a[i] = 0;
			}
			else {
				if(a[i + 1] > 0) {
					c += (a[i] + 1) / 2;
					a[i] = 0;
					a[i+1]--;
				}
				else {
					c += (a[i] - 1) / 2;
					a[i] = 1;
				}
			}
		}
		
		c += a[a.length -1]/2;
		
		System.out.println(c);
	}
}


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

using namespace std;

const int N = 1e5 + 5;
int n, k, arr[N], dp[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        cin >> arr[i];
    }

    dp[1] = 0;

    for(int i = 2; i <= n; i++){
        int fmin = 2e9;
        for(int j = 1; j <= k; j++){
            if(i - j >= 1){
                fmin = min(fmin, dp[i - j] + abs(arr[i] - arr[i - j]));
            }
        }
        dp[i] = fmin;
    }
    cout << dp[n] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    string s;
    cin>>s;
    long long n;
    n=s.size();
    long long wk=0;
    long long iniw;
    long long aft=0;
    for(long long i=0;i<n;i++){
        if(s[i]=='W'){
            wk=wk+1;
            aft=aft+i+1;
        }
    }
    iniw=wk*(wk+1)/2;
    cout<<aft-iniw;
    return 0;
}

Measured memory_bytes: 640
#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 ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

ll n, q;
string s;
vector<char> t(200010), d(200010);

ll check(ll x) {
  REP(i, q) {
    if (t[i] != s[x]) continue;
    if (d[i] == 'L')
      --x;
    else
      ++x;

    if (x == -1 || x == n) return x;
  }
  return 0;
}

int main() {
  cin >> n >> q;

  cin >> s;

  REP(i, q) { cin >> t[i] >> d[i]; }
  t.resize(q);
  d.resize(q);

  ll sum = 0;
  ll lb = -1, ub = n;
  while (ub - lb > 1) {
    ll mid = (ub + lb) / 2;
    if (check(mid) == -1)
      lb = mid;
    else
      ub = mid;
  }
  sum += ub;

  lb = -1, ub = n;
  while (ub - lb > 1) {
    ll mid = (ub + lb) / 2;
    if (check(mid) == n)
      ub = mid;
    else
      lb = mid;
  }
  sum += n - ub;

  cout << n - sum << endl;
  return 0;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())

cost = [0] * m
keys = [0] * m

for i in range(m):
    a, b = map(int, input().split())
    cost[i] = a
    k = list(map(int, input().split()))
    for j in range(b):
        keys[i] |=  (1 << (k[j]-1))

INF = 10 ** 9 + 1
dp = [INF] * (2**n)
dp[0] = 0

for i in range(1 << n):
    if dp[i] == INF:
        continue
    for next_cost, next_key in zip(cost, keys):
        m = next_key | i
        dp[m] = min(dp[m], dp[i] + next_cost)

if dp[-1] == INF:
    print(-1)
else:
    print(dp[-1])

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

int main() {
	int n, d, x;
	vector<int> a;
	cin >> n >> d >> x;
	a.resize(n);

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

	for (int j = 0; j < n; j++) {
		for (int k = 0; k <= d; k++) {
			if ((a[j] * k) + 1 <= d) {
				x++;
			}
		}
	}

	cout << x << endl;

	return 0;
}

Measured memory_bytes: 256
//C skill Up
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) //これでiやjを定義しなくていいらしい
using namespace std;

const int INF = 100100100; //ansを高い値段で初期化しておく

int main(){
  int n,m,x;//参考書冊数、アルゴリズム数、理解度の目標値
  int c[12],a[12][12];//参考書価格、能力値
  int ans=INF,cost;

  cin >> n >> m >> x;
  //入力
  rep(i,n){
    cin >> c[i];
    //cout << c[i] << "\t";
    rep(j,m){
      cin >> a[i][j];
      //cout << a[i][j] << " ";
    }
    //cout << "\n";
  }

  //処理
  //ビット全探索
  rep(i,1<<n){
    cost = 0;
    vector<int> d(m);//能力値の合計値を仮置き

    rep(j,n){//何冊目の本を買うパターン？
      if(i>>j&1){//1ビットずつシフト、買う場合は
        cost+=c[j];//書籍代を足し、
        rep(k,m){
          d[k]+=a[j][k];//能力値を増やす
        }
      }
    }//価格と能力値合計が出たら

    bool flag = true;
    rep(j,m){//能力値確認
      if(d[j]<x){//ひとつでもxに達していないアルゴリズムがあったら
        flag = false;
      }
    }//能力値の条件をクリアしたら
    if(flag){//答えを更新
      ans = min(ans,cost);
    }
  }
  //cout << "Main part end\n";
  //出力
  if(ans == INF){
    cout << -1 << endl;
  }else{
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 3548
n500 = int(input())
n100 = int(input())
n50 = int(input())
total = int(input())
count = 0
for i1 in range(n500+1):
    for i2 in range(n100+1):
        for i3 in range(n50+1):
            val100 = i2*100
            val500 = i1*500
            val50 = i3*50
            if val500+val100+val50 == total:
                count+=1
print(count)

Measured memory_bytes: 3064
from sys import stdin
from operator import itemgetter
##stdin = open("sample.txt")

N, K = [int(x) for x in stdin.readline().rstrip().split()]
d = stdin.readline().rstrip()
D = d.replace(' ','')
D_list = [D[i] for i in range(0, len(D), 1)]
price = N
buy = False

while buy == False:
    price_str = str(price)
    price_list = [price_str[i] for i in range(0, len(price_str), 1)]
    price_kaburi = list(set(price_list)) 
    check = D_list + price_kaburi
    check_list = list(set(check))
    if len(check) == len(check_list):
        print(price)
        break
    else:
        price += 1

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

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


  while(true){
    char d;
    int n, l ,p, con = 0;
    vector<int> L, R;

    cin>>n>>l;

    if(!n &&!l) break;
    
    con = n;
    L.resize(l*2+2, 0);
    R.resize(l*2+2, 0);

    
    for(int i = 0; i < n; i++){
      cin>>d>>p;

      if(d == 'L') L[p*2] = i+1;
      else if(d == 'R') R[p*2] = i+1;
    }

    for(int time = 1; ; time++){// cout<<time<<" "<<con<<endl;
      L[0] = R[l*2] = 0;
      
      //for(int i = 1; i < l*2; i++){
      //cout<<(L[i]?L[i]:R[i])<<" ";
      // }cout<<endl;

       
      for(int i = 1; i < l*2; i++){
	L[i-1] = L[i];
	R[l*2-i+1] = R[l*2-i];
      }
      
      for(int i = 1; i < l*2; i++){
        if(i%2 == 0 && L[i] && R[i]){
	  swap(L[i],R[i]);
	} 
      }
      for(int i = 1; i < l*2; i++){
	L[i-1] = L[i];
	R[l*2-i+1] = R[l*2-i];
      }
      // for(int i = 1; i < l*2; i++){
      // cout<<(L[i]?L[i]:R[i])<<" ";
      // }cout<<endl;

       for(int i = 1; i < l*2; i++){
	 if(i%2 == 0 && L[i] && R[i]){
	   swap(L[i],R[i]);
	 } 
       }
       
      if(L[0])con--;
      if(R[l*2])con--;

      if(!con){
	if(L[0]) cout<<time<<" "<<L[0]<<endl;
	else cout<<time<<" "<<R[l*2]<<endl;

        break;
      }
    }
  }
}



Measured memory_bytes: 3096
A,B,H,M = map(int,input().split())

import math

H_tmp = 2*math.pi*(H/12) + (2*math.pi/12)*(M/60)
M_tmp = 2*math.pi*(M/60)

kakudo = min(abs(H_tmp-M_tmp),2*math.pi - abs(H_tmp-M_tmp))

ans = (A**2 + B**2 - 2*A*B*math.cos(kakudo))**0.5

print(ans)

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

int main(){
  int n;
  cin >> n;
  if(n%10 == n/10%10 && n/10%10 == n/100%10 || n/10%10 == n/100%10 && n/100%10 == n/1000){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
#include <cstdio>
#define k 1024
#define r(a) for(int i=0;i<a;i++)
#define s(a) scanf("%d",&a);
#define m(a,b) a<b?a:b
int w,n,m,c[k],d[k],p[k];main(){s(n)s(m)r(n)s(d[i])r(m)s(c[i])r(n+1)p[i]=1e9;p[0]=0;r(m*n)w=n-i%n,p[w]=m(p[w],p[w-1]+c[i/n]*d[w-1]);printf("%d\n",p[n]);}

Measured memory_bytes: 1036
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar  1 19:29:34 2019

@author: nakamuratakayuki
"""

H, W = tuple(map(int, input().split()))
h, w = tuple(map(int, input().split()))
print(H*W-h*W-H*w+h*w)

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

int main() {
  int n;

  cin >> n;

  long luca1 = 2, luca2 = 1;

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

  for (int i = 1; i < n; i++) {
    long temp = luca2;
    luca2 = luca1 + luca2;
    luca1 = temp;
  }

  cout << luca2;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using vi = vector<int>;

int num[10] = {0,2,5,5,4,5,6,3,7,6};

int main(){
    int n,m;
    cin >>n >>m;
    vi a(m);
    rep(i,m) cin >>a[i];

    sort(all(a), greater<int>());

    vi NG(m+1,-1);
    vector<vector<vi>> dp(n+1,vector<vi>(m,NG));
    dp[n][0] = vi(m+1,0);

    for(int i=n; i>0; --i)rep(j,m)if(dp[i][j] != NG){
        if(j<m-1) dp[i][j+1] = max(dp[i][j+1], dp[i][j]);

        int ni = i-num[a[j]];
        if(ni>=0){
            vi nx = dp[i][j];
            ++nx[0];
            ++nx[j+1];
            dp[ni][j] = max(dp[ni][j], nx);
        }
    }

    vi ans = NG;
    rep(i,m) ans = max(ans, dp[0][i]);

    rep(i,m)rep(j,ans[i+1]) cout << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 6912
N, A, B, C = map(int, input().split())
take_list = [int(input()) for i in range(N)]
INF = 10 **9


def dfs(a, b, c, n):

    if n == N:
        return abs(A-a) + abs(B-b) + abs(C-c) - 30 if min(a,b,c) > 0 else INF

    ret1 = dfs(a, b, c, n + 1)
    ret2 = dfs(a + take_list[n], b, c, n + 1) + 10
    ret3 = dfs(a, b + take_list[n], c, n + 1) + 10
    ret4 = dfs(a, b, c + take_list[n], n + 1) + 10
    return min(ret1, ret2, ret3, ret4)

print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
char s[100001];
int n,m;
int main() {
	cin>>n>>m;
	for(int i=1; i<=n; i++) {
		memset(s,' ',sizeof(s));
		scanf("%s",s);
		printf("%s\n",s);
		printf("%s\n",s);
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int I,O,T,J,L,S,Z;
int main() {
    cin>>I>>O>>T>>J>>L>>S>>Z;
    if(I&&J&&L) printf("%lld\n",O+max(2ll*(I/2+J/2+L/2),3ll+2ll*((I-1)/2+(J-1)/2+(L-1)/2)));
    else printf("%lld\n",O+2ll*(I/2+J/2+L/2));
    return 0;
}


Measured memory_bytes: 256
import itertools

def find(table, x):
    stack = [x]
    while table[stack[-1]] != stack[-1]:
        stack.append(table[stack[-1]])
    
    for i in stack:
        table[i] = stack[-1]
    return table[x]


def union(table, x1, x2):
    p1 = find(table, x1)
    p2 = find(table, x2)
    table[p2] = p1

n = int(input())
points = [tuple(map(int, input().split())) for _ in range(n)]

edges = []
cities = list(range(n))
for j in (0, 1):
    cities.sort(key=lambda city: points[city][j])
    for i in range(n - 1):
        city1, city2 = cities[i], cities[i + 1]
        (x1, y1), (x2, y2) = points[city1], points[city2]
        cost = min(abs(x1 - x2), abs(y1 - y2))
        edges.append((cost, city1, city2))
edges.sort() # key=lambda cost, city1, city2: cost

table = list(range(n))
answer = 0
for cost, city1, city2 in edges:
    parent1, parent2 = find(table, city1), find(table, city2)
    if parent1 != parent2:
        answer += cost
        union(table, city1, city2)

print(answer)

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

int main () {
	int a, b, d, r;
	double f;
	cin >> a >> b;
	d = a/b;
	r = a%b;
	f = (double)a/b;
	
	cout << fixed << setprecision(5);
	cout << d << " " << r << " " << f << endl;
	return 0;
}


Measured memory_bytes: 3240
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int MOD = 1000000007;

LL N,M,S,L;
LL a,b,c,d;
string s;
P ba[200010];
int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>ba[i].second>>ba[i].first;
    }
    sort(ba,ba+N);
    LL now=0;
    for(int i=0;i<N;i++){
        now+=ba[i].second;
        if(now>ba[i].first){
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define ll long long
#define pi pair<int,int>
#define endl "\n"
#define MAXN 100005
using namespace std;

double n;

void solve()
{
    cin>>n;
    double ans=(double)2*((double)22.0/(double)7.0)*n;
    cout<<fixed<<setprecision(10)<<ans<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	cout.tie(NULL);
    solve();
}


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

using namespace std;

const int N=18,M=1<<16,mo=1e9+7;

typedef long long LL;

int n,m,ans,a[N],f[N][M],Fac[M],Inv[M],T;

int C(int n,int m)
{
	if (n<m) return 0;
	return (LL)Fac[n]*Inv[m]%mo*Inv[n-m]%mo;
}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++) scanf("%d",&a[i]);
	Fac[0]=Inv[0]=Fac[1]=Inv[1]=1;
	for (int i=2;i<M;i++) Inv[i]=(LL)Inv[mo%i]*(mo-mo/i)%mo;
	for (int i=2;i<M;i++)
	{
		Fac[i]=(LL)Fac[i-1]*i%mo; Inv[i]=(LL)Inv[i-1]*Inv[i]%mo;
	}
	T=1<<n;
	sort(a+1,a+m+1);
	f[m+1][T-1]=1;
	for (int i=m;i;i--)
	{
		for (int j=0;j<T;j++) if (f[i+1][j])
		{
			f[i][j]=(f[i+1][j]+f[i][j])%mo;
			for (int k=0;k<n;k++) if (((1<<k)&j)>0)
			{
				f[i][j^(1<<k)]=(f[i][j^(1<<k)]-(LL)C(j+1-a[i],(1<<k)-1)*Fac[1<<k]%mo*f[i+1][j])%mo;
			}
		}
	}
	for (int i=0;i<T;i++) ans=(ans+(1ll<<n)*f[1][i]%mo*Fac[i])%mo;
	if (ans<0) ans+=mo;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <numeric>

int gcd3(int, int, int);

int gcd3(int a, int b, int c) {
	return std::gcd(a, std::gcd(b, c));
}

int main() {
	std::ios::sync_with_stdio(false);

	int k;
	std::cin >> k;

	int sum = 0;
	for (int i = 1; i <= k; i++) {
		for (int j = 1; j <= k; j++) {
			for (int p = 1; p <= k; p++) {
				sum += gcd3(i, j, p);
			}
		}
	}

	std::cout << sum;

	return 0;
}

Measured memory_bytes: 3652
N=int(input())
s=[]
for i in range(N):
    s+=[input()]
M=int(input())
t=[]
for i in range(M):
    t+=[input()]
ans1=0
ss=list(set(s))
for i in range(len(set(s))):
    ans=s.count(ss[i])-t.count(ss[i])
    ans1=max(ans1,ans)
if ans1<0:
    print(0)
    exit()
print(ans1)

Measured memory_bytes: 3064
#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 sz(x) (int)x.size()
#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 PI 3.14159265
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
    IOS;
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    h1=h1*60+m1;
    h2=h2*60+m2;
    h2-=h1;
    cout<<h2-k;
    return 0; 
}


Measured memory_bytes: 3656
#C
N = int(input())
XY = []
for i in range(N):
    a = int(input())
    kari = []
    for j in range(a):
        kari.append(list(map(int,input().split())))
    XY.append(kari)
    
N2 = 2**N
ans = 0
for i in range(N2):
    b = bin(i)
    b = b.lstrip("0b")
    while len(b) < N:
        b = "0"+b
        
    flag = 0
    boo = [-1]*N
    for j in range(N):
        if b[j] == "1":
            if boo[j] == 0:
                flag = 1
                break
            else:
                boo[j] = 1
                for xy in XY[j]:
                    x,y = xy
                    if boo[x-1] == -1:
                        boo[x-1] = y
                    else:
                        if boo[x-1] != y:
                            flag = 1
                            break
        else:
            if boo[j] == 1:
                flag = 1
                break
            else:
                boo[j] = 0
    if flag == 0:
        kari = 0
        for bo in boo:
            if bo == 1:
                kari+=1
        ans = max(ans,kari)
    
print(ans)

Measured memory_bytes: 45660
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=500000;
const int INF=2e9;
int L[maxn/2+2],R[maxn/2+2];
int cnt;
void merge_sort(int a[],int n,int l,int mid,int r)
{
    int n1=mid-l;
    int n2=r-mid;
    for(int i=0;i<n1;i++)
    {
        L[i]=a[l+i];
    }
    for(int i=0;i<n2;i++)
    {
        R[i]=a[mid+i];
    }
    L[n1]=R[n2]=INF;
    int p=0,q=0;
    for(int i=l;i<r;i++)
    {
        cnt++;
        if(L[p]<=R[q])
            a[i]=L[p++];
        else
            a[i]=R[q++];
    }
}
void get_merge(int a[],int n,int l,int r)
{
    if(l+1<r)
    {
        int mid=(l+r)/2;
        get_merge(a,n,l,mid);
        get_merge(a,n,mid,r);
        merge_sort(a,n,l,mid,r);
    }
}
int main()
{
    int a[maxn],n;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    get_merge(a,n,0,n);
    for(int i=0;i<n;i++)
    {
        if(i)
            printf(" ");
        printf("%d",a[i]);
    }
    printf("\n%d\n",cnt);
    return 0;
}



Measured memory_bytes: 7116
#include "bits/stdc++.h"
#define MOD 1000000007
#define INF 11234567890
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N, M, a[112345], b[112345];
std::vector<LL>G[112345];

int main()
{
	in >> N >> M;
	rep(i, M)
	{
		in >> a[i] >> b[i];
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}

	rep(i, N)
	{
		if (G[i + 1].size() % 2 == 1)
		{
			out << "NO" << std::endl;
			return 0;
		}
	}
	out << "YES" << std::endl;
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int main(){
  int n ,cnt=0 ,cont=0;
  char s[10000];
  while( cin >> s ){
  n = strlen(s);

  for( int i=0 ; i<n ; i++ ){
    if( s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I' ){
      cnt++;
    }

    if( s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I' ){
      cont++;
    }
  }

  cout << cnt << endl << cont << endl;
  cnt = 0;
  cont = 0;
  }
}

Measured memory_bytes: 1148
N=int(input())
S = [list(map(int, input().split())) for _ in range(2)]
a=0
for i in range(N):
    for j in range(i,N):
        x=sum(S[0][:i+1])+sum(S[1][i:])
        if a<x:
            a=x
print(a)


Measured memory_bytes: 3060
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

const int MNN = 333;

int a[MAXN];
int b[MAXN];
//int ans[MNN][MNN];
/*
int get(int a, int b, int c) {
	int sum = a + b + c;
	return sum - min({a, b, c}) - max({a, b, c});
}
*/
int tot;
int n;
bool f(int x) {
	for (int i = 0; i < tot; i++) {
		b[i] = (a[i] <= x ? 1 : 0);
	}
	int kek = n - 1;
	int l = kek;
	int r = kek;
	int dl = 0;
	int dr = 0;
	while(l > 0 && b[l] != b[l - 1]) {
		l--;
		dl++;
	}	
	while(r + 1 < tot && b[r] != b[r + 1]) {
		r ++;
		dr++;
	}
	if (l == 0 && r == tot - 1) {
		return ((n - 1) % 2) ^ b[kek];
	}
	if (dl < dr) {
		return b[l];
	} else {
		return b[r];
	}
}

int main() {
	#ifdef IZI_KATKA
	freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    n = readInt();
    tot = 2 * n - 1;
    for (int i = 0; i < tot; i++) {
    	a[i] = readInt() - 1;
    }
    int l = 0;
    int r = tot - 1;
	while(l < r) {
		int m = (l + r) / 2;
		if (f(m)) {
			r = m;
		} else {
			l = m + 1;
		}
	}
	cout << l + 1;
    return 0;
}

Measured memory_bytes: 5120
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const int N=1e5+10;
const int INF=0x3f3f3f3f;
int a[N];
int sum1[N],sum2[N];
int main()
{
	int n;scanf("%d",&n);
	int maxx=0,t1=0,t2=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]); maxx=max(maxx,a[i]);
		if(i%2==1){sum1[a[i]]++;}
		if(i%2==0){sum2[a[i]]++;}
	}
	int mn1[2]={0,0},mx1[2]={0,0},mn2[2]={0,0},mx2[2]={0,0};
	
	for(int i=1;i<=n;i++)
	{
		if(i%2==1)
		{
			if(mx1[0]<sum1[a[i]])
			{
				mn1[0]=mx1[0];
				mn1[1]=mx1[1];
				
				mx1[0]=sum1[a[i]];
				mx1[1]=a[i];
			}
			else if(mn1[0]<sum1[a[i]] && a[i]!=mx1[1])
			{
				mn1[0]=sum1[a[i]];
				mn1[1]=a[i];
			}
		}
		else if(i%2==0)
		{
			if(mx2[0]<sum2[a[i]])
			{
				mn2[0]=mx2[0];
				mn2[1]=mx2[1];
				
				mx2[0]=sum2[a[i]];
				mx2[1]=a[i];
			}
			else if(mn2[0]<sum2[a[i]] && a[i]!=mx2[1] )
			{
				mn2[0]=sum2[a[i]];
				mn2[1]=a[i];
			}
		}
	}
	int ans;
	if(mx1[1]!=mx2[1])
		ans=n-mx1[0]-mx2[0];
	else
	{
		ans=min(n-mx2[0]-mn1[0],n-mx1[0]-mn2[0]);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>

int main()
{
	int n, m;
	int time[100001] ={};

	scanf( "%d", &n );

	for (int i=0; i < n; i++)
	{
		scanf( "%d", &time[i] );
	}

	scanf( "%d", &m );

	for (int i=0, total, p, x; i < m; i++)
	{
		total = 0;

		scanf( "%d%d", &p, &x );

		for (int j=0; j < n; j++)
		{
			total += ( j == (p-1) )? x: time[j];
		}

		printf( "%d\n", total );
	}

	return 0;
}

Measured memory_bytes: 512
//
// Created by sark2 on 17-07-2019.
//

#include "bits/stdc++.h"

using namespace std;
#define IOS cin.sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cases int t;cin>>t;while(t--)
typedef long double ld;
ld solve(ld p[], int n){

    ld dp[n+1][n+1];
    memset(dp,0.0,sizeof dp);
    dp[0][0] = 1.0;
    for(int i = 1; i <=n; i++) {
        for (int j = 0; j <= i; j++) {

            if (j == 0) {
                dp[i][j] = dp[i - 1][j] * (1 - p[i]);
            } else {
                dp[i][j] = (1 - p[i]) * dp[i - 1][j] + p[i] * dp[i - 1][j - 1];
            }

        }
    }

    ld ans = 0.0;
        for(int i = (n+1)/2 ; i <= n; i++){
            ans += dp[n][i];
        }

    return ans;
    }



int main() {
    IOS

    int n;
    cin>>n;
    ld p[n+5];
    for(int i = 1; i <= n; i++) cin>>p[i];

    cout<<fixed<<setprecision(10)<<solve(p,n);

}


Measured memory_bytes: 140928
#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

int getChar(char ch){

	if (ch == 'A')return 1;
	else if (ch == 'C')return 2;
	else if (ch == 'G')return 3;
	else if (ch == 'T')return 4;
	else return 0;
}

//?????????????????°??????????????????key?????????????????¢??°
long long getKey(char str[]){

	long long sum = 0, p = 1, i;
	for (i = 0; i < strlen(str); i++){
		sum += p*(getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key){ return key% M; }
int h2(int key){ return 1 + (key % (M - 1)); }

int find(char str[]){

	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++){

		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0)return 0;
		}
	return 0;
}

int insert(char str[]){
	long long key, i, h;
	key = getKey(str);
	for (i = 0;; i++){
		h = (h1(key) + i*h2(key)) % M;
		if (strcmp(H[h], str) == 0)return 1;
		else if (strlen(H[h]) == 0){
			strcpy(H[h], str);
			return 0;		
		}
	}
	return 0;
}


int main(){

	int i,n,h;
	char str[L], com[9];
	for (i = 0; i < n; i++)H[i][0] = '\0';
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%s %s", com, str);
		if (com[0] == 'i'){
			insert(str);	
		}
		else{
			if (find(str)){
				printf("yes\n");
			}
			else{
				printf("no\n");
			}
		}	
	}
	return 0;
}

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

//入力を受け取る
//順列全探索を行う
//{1, 2, ...N}という配列を準備しておく

double distance(double x, double y, double z, double w){
    double delta_x = z - x;
    double delta_y = w - y;
    double squared_distance = (delta_x)*(delta_x) + (delta_y)*(delta_y);
    return pow(squared_distance, 0.5);
}

int main(){
    int n;
    cin >> n;
    
    //n=3
    
    vector<double> x(n+1), y(n+1), v(n);
    for (int i = 0; i < n; i++){
        cin >> x[i+1] >> y[i+1];
        v[i] = i+1;
    }
    
    //x = {0, 1, 0, 0}, y = {0, 0, 1, 0}, v = {1, 2, 3}
    
    //移動距離の総和を求める
    double sum_of_distance = 0;
    do{
        for (int i = 0; i < n-1; i++){
            sum_of_distance += distance(x[v[i]], y[v[i]], x[v[i+1]], y[v[i+1]]);
        }
    } while (next_permutation(v.begin(), v.end()));
    
    //N!を求める
    double factorial = 1.0;
    for (int i = 2; i <= n; i++) factorial *= i;
  
    double ans = (sum_of_distance) / factorial;
    
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

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 int MAX_D=365;
const int MAX_type=26;
const int BeamWidth=200;

int D;
int c[MAX_D+5];
int s[MAX_D+5][MAX_type+5];

struct State{
    vector<int> contest;
    vector<int> last;
    int day;
    int score;

    State(){
        day=1;
        score=0;
        last.assign(MAX_type+5,0);
    }

    void update(int type){
        contest.push_back(type);
        last[type]=day;
        score+=s[day][type];
        for(int i=1;i<=MAX_type;++i){
            score-=c[i]*(day-last[i]);
        }
        day++;
    }

    State nextState(int type){
        State next;
        next=*this;
        next.update(type);
        return next;
    }
};

bool operator< (const State &state1, const State &state2){
    return state1.score < state2.score;
};

bool operator> (const State &state1, const State &state2){
    return state1.score > state2.score;
};

State beamsearch(){
    int D_=D;
    priority_queue<State, vector<State>, greater<State> > nowpq;
    for(int type=1;type<=MAX_type;++type){
        State s;
        nowpq.push(s.nextState(type));
    }
    while(nowpq.size()>BeamWidth)nowpq.pop();
    D_--;
    while(D_--){
        priority_queue<State, vector<State>, greater<State> > nextpq;
        while(nowpq.size()){
            State now=nowpq.top();
            nowpq.pop();
            for(int type=1;type<=MAX_type;++type){
                nextpq.push(now.nextState(type));
            }
        }
        while(nextpq.size()>BeamWidth)nextpq.pop();
        nowpq=nextpq;
    }
    while(nowpq.size()>1)nowpq.pop();
    State ret=nowpq.top();
    return ret;
}

void input(){
    cin>>D;
    for(int i=1;i<=MAX_type;++i)cin>>c[i];
    for(int i=1;i<=D;++i){
        for(int j=1;j<=MAX_type;++j){
            cin>>s[i][j];
        }
    }
}

signed main(){
    input();
    auto res=beamsearch();
    for(auto u:res.contest){
        cout<<u<<endl;
    }
}

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

#define LL long long
int a[20005], b[20005], k;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n; cin >> n;
	for(int i=1;i<=n;i++) {
		cin >> k;
		a[k] = i, b[k] = i;
	}

	for(int i=1;i<=n;i++) {
		a[i] += i * n;
		b[i] += n * (n - i);
	}

	for(int i=1;i<=n;i++) cout << a[i] << " ";
	cout << '\n';
	for(int i=1;i<=n;i++) cout << b[i] << " ";
}

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

using namespace std;
typedef long long ll;

int main() {
    char s;
    cin >> s;
    if (s >= 'A' && s <= 'Z') {
        cout << "A" << endl;
    } else {
        cout << "a" << endl;
    }
    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    int ans = 1000;
    for (int i = 0; i <= s.size() - t.size(); i++) {
        int cnt = 0;
        for (int j = i; j < i + t.size(); j++) {
            if (s[j] != t[j - i]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
using namespace std;
const int INF = 1e+9;

int main(void){
	int n;
	while(cin>>n,n){
		int g[11][11],v=0;
		for(int i=0;i<11;++i)for(int j=0;j<11;++j) g[i][j]=INF;
		for(int i=0,a,b,c;i<n;++i){
			cin>>a>>b>>c;
			g[a][b]=c;
			g[b][a]=c;
			v = (((a>b)?a:b)>v)?((a>b)?a:b):v;
		}
		int sum_min=INF,d_sum[11]={0};
		for(int i=0;i<=v;++i){
			int d[11];
			for(int j=0;j<=v;++j) d[j]=INF;
			d[i]=0;
			bool f=false;
			for(;;){
				f=false;
				for(int j=0;j<=v;++j){//from
					for(int k=0;k<=v;++k){//to
						if(d[j] != INF && d[k] > d[j] + g[j][k]){
							f = true;
							d[k] = d[j] + g[j][k];
						}
					}
				}
				if(!f) break;
			}
			for(int j=0;j<=v;++j) d_sum[i]+=d[j];
			if(sum_min>d_sum[i]) sum_min = d_sum[i];
		}
		for(int i=0;i<=v;++i){
			if(sum_min==d_sum[i]){
				cout<<i<<" "<<sum_min<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 1164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#include <set>
#include <math.h>
#include <array>
#include <list>
#include <set>
const int MOD=1000000007;
const int INF=1000000000;
using namespace std;
typedef long long ll;
typedef tuple<ll,int,int> p;
typedef vector<int> vi;
set <int> st;
int n,a,b,ans=0;
vector<string> c(3);

int main(int argc,char const* argv[])
{
  cin >> n >> a >> b;
  for(int i=1;i<=n;i++)
    {
      int calc=i,save=i;
      int tmp=0;
      while(calc>0)
	{
	  tmp+=(calc%10);
	  calc/=10;
	}
      if(tmp>=a && b>=tmp) ans+=save;
    } 
  cout << ans <<  endl;
  return 0;
}


Measured memory_bytes: 256
path1 = list(map(int, input().split()))
path2 = list(map(int, input().split()))
path3 = list(map(int, input().split()))

path = path1 + path2 + path3
path.sort()

S = []
for i in range(5):
    if path[i] == path[i+1]:
            S += [path[i]]

if len(S) != 2:
    print('NO')
elif S[0] == S[1]:
    print('NO')
else:
    path.pop(S[0])
    path.pop(S[1])
    if path != [1,2,3,4]:
        print('NO')
    else:
        print('YES')

Measured memory_bytes: 3064
<?php

fscanf(STDIN, "%d", $n);
$a_input = explode(' ', fgets(STDIN));
$a = [];
for ($i = 0; $i < $n; $i++) {
	$a[] = (int)$a_input[$i];
}

//var_dump($a);

$pair = [];
$one = max($a);
$max = 0;
$key = 0;
foreach ($a as $other) {
	$r = ($other > $one / 2) ? $one - $other : $other;
	if ($r > $max) {
		$key = $other;
		$max = $r;
	}
}
echo $one, " ", $key, "\n";


Measured memory_bytes: 19188
#include<bits/stdc++.h>
using namespace std;
#define all(a)  (a).begin(),(a).end()
typedef long long ll;
const ll mod=1000000007;
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)

int main() {
  int h,w,n;cin>>h>>w;
  cin >> n;
  vector<int> a(n);
  repi(i,0,n) cin >> a[i];
  int out[h][w];
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      out[i][j] = 0;
    }
  }
  int cnt = 0;
  int clr_id = 0;
  int paint_h = 0;
  int paint_w = 0;
  repi(i,0,n){
    int cnt_clr = a[i];
    for(int j=0;j<cnt_clr;++j){
      out[paint_h][paint_w] = i+1;
      if(paint_w+1<w)if(out[paint_h][paint_w+1] == 0){++paint_w;continue;}
      if(paint_w-1>=0)if(out[paint_h][paint_w-1] == 0){--paint_w;continue;}
      ++paint_h;
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      cout << out[i][j] << " ";
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())





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

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	cout << min({ abs((a + b) - (c + d)),abs((a + c) - (b + d)),abs((a + d) - (b + c)) }) << endl;




	return 0;
}


Measured memory_bytes: 3204
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std;
#define Sort(s) sort(s.begin(),s.end())
#define f0(i,n) for(int i=0;i<n;i++)
#define fs(i,s) for(int i=0;i<s.size();i++)
#define ll long long int
#define nl endl
int main()
{
	int c=0;
	string s,s1;
	cin>>s>>s1;
	for(int i=0;i<s.size();)
	{
		for(int j=0;j<s1.size();)
		{
			if(s[i]!=s1[i]){
				c++;i++;j++;
		}
		else{
			i++;j++;
	}
}
}cout<<c;
}
	

Measured memory_bytes: 3840
N, M = map(int, input().split())
ans = 1
K = M//N
for i in range(1, int(M**0.5)+1):
    if M%i == 0:
        if i <= K:
            ans = max(ans, i)
        if M//i <= K:
            ans = max(ans, M//i)

print(ans)

Measured memory_bytes: 63464
use std::cmp::min;
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let k:usize = read();
    let v:Vec<i64> = (0..n).map(|_| read()).collect();
    let mut ans = 1<<60;

    for i in 0..n-k+1 {
        let left = v[i];
        let right = v[i + k- 1];
        ans = min(ans, min(left.abs(), right.abs()) + right - left);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2800
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input()) - 1

print(a[k])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)); //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;

int main(void){
    int K, X;
    cin >> K >> X;

    int left = max(-1000000, X - (K - 1));
    int right = min(1000000, X + (K - 1));

    for (int i = left; i <= right; i++)
    {
        cout << i;
        if(i != right) cout << " ";
        else cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.InputMismatchException;
import java.util.Scanner;

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

			int n = scanner.nextInt();
			scanner.nextLine(); //次の行へ

			int[] p = new int[n+1];
			int i = 1;
			while (scanner.hasNext()) {
				p[i] = scanner.nextInt();
				i++;
			}

			Main swap = new Main();
			if(swap.swap(p)) {
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}

			scanner.close();

		} catch (InputMismatchException e) {
			// TODO: handle exception
			System.out.println("整数を入力してください");
		}
	}


	public Boolean swap(int[] p) {
		int count = 0;

		for(int i = 1; i < p.length; i++) {
			//i番目の数字がiでは無い
			if(p[i] != i) {
				//iと（i番目の数字）番目の数字が一致
				if(i == p[p[i]]) {
					if(count < 2) {		//2回目まで
						 count++;
					}else{				//2回目以降
						return false;
					}
				}else{
					return false;
				}
			}
		}

		return true;
	}

}



Measured memory_bytes: 21844
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()
#define pl pair<ll,ll>
#define fi first
#define se second
#define inf 1000000007

ll N,K;
vector<ll> P[200010];

int main() {
    scanf("%lld%lld",&N,&K);
    ll ans = 0;
    rep(i,K){
        if (i*2 % K == 0){
            ll temp = 0;
            while(K*temp + i <= N){
                if (K*temp+i != 0){
                    P[i].push_back(K*temp + i);
                    temp++;
                }
                else temp++;
            }
            ans += pow(P[i].size(),3);
        }
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7284
def check_at(i,ans,s):
  if ans[i] == "S":
    if (s[i] == "o" and ans[i-1] != ans[i+1]) or (s[i] == "x" and ans[i-1] == ans[i+1]):
      return True
  else:
    if (s[i] == "o" and ans[i-1] == ans[i+1]) or (s[i] == "x" and ans[i-1] != ans[i+1]):
      return True

N = int(input())
S = input()

opposite = {"S": "W",
            "W": "S"}

for ans in ["SS","SW","WS","WW"]:
  for i in range(1,N-1):
    if ans[i] == "S" and S[i] == "o":
      ans += ans[i-1]
    elif ans[i] == "S" and S[i] == "x":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "o":
      ans += opposite[ans[i-1]]
    elif ans[i] == "W" and S[i] == "x":
      ans += ans[i-1]
  
  if (not check_at(-1,ans,S)) and (not check_at(0,ans,S)):
    print(ans)
    break
else:
  print(-1)

Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main()
{
	int n,ans=0,a[2][100];
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[0][i];
	for(int i=0;i<n;i++)cin>>a[1][i];
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		for(int j=0;j<n;j++)
		{
			if(j<i)cnt+=a[0][j];
			else if(i<j)cnt+=a[1][j];
			else cnt+=a[0][j]+a[1][j];
		}
		ans=max(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


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

// 1
// 12
// 312
// 3124

vector<int> ans;
signed main() {
  int n;cin>>n;
  deque<int> q;
  for(int i=0;i<n;++i) {
    int a;cin>>a;
    if(i%2) {
      q.push_front(a);
    }else{
      q.push_back(a);
    }
  }

  for_each(q.begin(), q.end(), [](int x){
                                 ans.push_back(x);
                               });
  
  if(n%2==1) reverse(ans.begin(),ans.end());
  bool isFirst = true;
  for(int i=0;i<n;++i){
    if(isFirst) isFirst = false;
    else cout<<" ";
    cout<<ans[i];
  }
  cout<<endl;
  
  return 0;
}


Measured memory_bytes: 5488