akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

using namespace std;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,x;
	cin >> N >> x;
	vector<int> a(N);
	rep(i,N)cin >> a[i];
	a.push_back(0);
	ll ans = 0;
	for(int i=0;i<N;i++){
		int y = a[i]+a[i+1];
		if(y>x){
			if(y-a[i+1]<=x){
				ans += y-x;
				a[i+1] -= y - x;
			}else{
				ans += y-x;
				a[i+1] = 0;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
long long int gcd(long long int a,long long int b){
    if(!b)return a;
    return gcd(b,a%b);
}
int main(){
    int K;
    cin>>K;
    long long int ans=0;
    for(int i=1;i<=K;i++){
        for(int j=1;j<=K;j++){
            for(int k=1;k<=K;k++){
                ans+=gcd(gcd(i,j),k);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
#include<cstdio>
#define A(a) ((a)>0?(a):-(a))
int n,m,k;
signed main()
{
	scanf("%d%d%d",&n,&m,&k);int t1,t2(0);
	while(n--)
	{
		t1=t2,scanf("%d",&t2);
	}
	return printf("%d\n",t1?(A(t2-t1)>A(t2-k)?A(t2-t1):A(t2-k)):A(t2-k)),0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>

using namespace std;

#define fi(a,b) for(int i=a;i<b;++i)
#define fj(a,b) for(int j=a;j<b;++j)
typedef long long ll;
///////////////////

int const N = 1e5 + 41;

ll a[3][N];
ll d[3][N];
int n;

int getless(int v, ll a[N]){
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(a[m] < v) l = m;
		else r = m;
	}
	return l;
}

void solve(){
	fi(0, 3) sort(a[i], a[i]+n);
	fj(0, 3){
		fi(0, n){
			if(!j) d[j][i] = 1;
			if(i) d[j][i] += d[j][i-1];
			if(j){
				int p = getless(a[j][i], a[j-1]);
				if(p >= 0) d[j][i] += d[j-1][p];
			}
		}
	}
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	scanf("%d",&n);
	fj(0, 3) fi(0, n) scanf("%lld",&a[j][i]);

	solve();

	printf("%lld\n",d[2][n-1]);

	return 0;
}

Measured memory_bytes: 4992
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$B = explode(" ",trim(fgets(STDIN)));

$A[0]=$B[0];
for($i=1;$i<$N-1;$i++) {
  $A[$i]=min($B[$i],$B[$i-1]);
}
$A[]=$B[$i-1];
for($i=0;$i<$N;$i++) {
  $res+=$A[$i];
}
printf("%d\n",$res);


Measured memory_bytes: 4728
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(br.readLine());
		}

		int now = 1;
		Set<Integer> set = new HashSet<>();
		set.add(1);

		for (int i = 0;; i++) {
			now = a[now - 1];
			if (set.contains(now)) {
				System.out.println("-1");
				return;
			}
			if (now == 2) {
				System.out.println(i + 1);
				return;
			}
			set.add(now);
		}
	}
}

Measured memory_bytes: 49596
#include<stdio.h>
#define NIL 0
#define FIRST 1
#define SECOND 2
#define MAX 101
//NILで未訪問（houmon[データの上限最大]に０を代入）と、矢印が伸びていないところを示す（M[][]に０を代入）
//FIRST SECOND はそれぞれ訪問回数。
int datanum,M[MAX][MAX];//Mは１、０のマトリックスであり、１がそこに矢印が伸びている、０は伸びていない
int houmon[MAX],check[MAX],end[MAX],timestamp;//houmonに訪問した回数。checkに１度目に訪れた時間、endに２度目に訪れた時間。

void dfs_visit(int point){
  int i;
  houmon[point] = FIRST;
  check[point]  = ++timestamp; 
  for(i = 1;i<=datanum;i++){
    if(M[point][i] == 0)continue; //そこには矢印が伸びていないのでたどり着けないので、飛ばす。
    if(houmon[i] == NIL){//訪問回数が０回の時、dfs_visitを再帰関数で呼び出す。
      dfs_visit(i);
    }
  }
  houmon[i] = SECOND;
  end[point] = ++timestamp;
}

void dfs(){
  int i;
  for(i=1;i<=datanum;i++)houmon[i] = NIL;//houmonに訪問回数NIL=0を代入している。
  timestamp =0;//timestampに現在時刻を代入し、その値を格納。
  for(i=1;i<=datanum;i++){//絶対にスタートが１からであるので
    if(houmon[i] == NIL)dfs_visit(i);
  }
}


int main(){
  int u,k,i,j,temp;//uは頂点の番号、kはuの出字数（その点から矢印で伸びている値の数）
  scanf("%d",&datanum);
  //1から頂点番号がスタートして、そこから１ずつ続いていくので、datanum以下のデータ数正方行列（0は未使用）
  for(i=1;j<=datanum;i++)
    for(j=1;j<=datanum;j++){
      M[i][j] = NIL;//NIL = 0
    }
  for(i=0;i<datanum;i++){
    scanf(" %d %d",&u,&k);//uは頂点数、kはuの出字数
    for(j=0;j<k;j++){
      scanf("%d",&temp);//頂点から伸びている値(->の先の値)がtemp
      M[u][temp] = 1;//Mという正方行列に1,0の表を作り、１が矢印が伸びている、０は矢印が伸びていないことを示す。
    }
  }
  dfs();
  //データの出力
  for(i=1;i<=datanum;i++){
    printf("%d %d %d\n",i,check[i],end[i]);
  }
  return 0;
}



Measured memory_bytes: 2048
#include <cstdio>
#include <iostream>

using namespace std;

const int maxn=1005;

long long a[maxn];

inline bool check(long long num)
{
	long long last=num%10;
	num /= 10;
	while(num){
		if(num%10 != last-1)
			return false;
		last = num%10;
		num /= 10;
	}
	return true;
}

int main()
{
	long long ma=-1;
	int n;
	scanf("%lld", &n);
	for(int i=0; i<n; i++)
		scanf("%d", &a[i]);
	for(int i=0; i<n; i++)
		for(int j=i+1; j<n; j++)
			if(check(a[i]*a[j]) && ma<a[i]*a[j])
				ma = a[i]*a[j];
	printf("%lld\n", ma);
	return 0;
}

Measured memory_bytes: 3216
# -*- coding: utf-8 -*-
import sys
a=10000
b=5000
c=1000

def check(y, i,j,k):
    if(y == i * a + j * b + k * c):
        print(i,j,k)
        sys.exit(0)

n, y = map(int, input().split())

for i in range(n,-1,-1):
    for j in range(n-i,-1,-1):
        k = n-i-j
        check(y,i,j,k)

print(-1,-1,-1)
    


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FR first
#define SE second

using namespace std;

map <int,int> f[2];
int num[200005];

inline void update(map<int,int> &f,int x,int y) {
  if (!f.count(y)) f[y]=x;
  else f[y]=min(f[y],x);
}

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<=n;i++) scanf("%d",&num[i]);
  int cur=0;
  f[cur][0]=num[1];f[cur][1]=0;
  for(int i=2;i<=n;i++) {
  	cur^=1;
  	f[cur].clear();
  	int v1=0,v2=num[i]-num[i-1];
  	if (v1>v2) swap(v1,v2);
  	for(map<int,int>::iterator it=f[cur^1].begin();it!=f[cur^1].end();it++)
  	  if (it->FR<=f[cur^1].begin()->FR+1) {
  	  	  int u=it->SE,v=it->FR;
  	  	  if (u+v1>0) update(f[cur],0,v+2);
  	  	  if (u+v1<=num[i]) update(f[cur],max(u+v1,0),v+1);
  	  	  if (u+v2<=num[i]) update(f[cur],max(u+v2,0),v);
		}
  }
  int ans=n;
  for(map<int,int>::iterator it=f[cur].begin();it!=f[cur].end();it++)
    ans=min(ans,it->FR+(it->SE>0));
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<int,int> ii;
typedef pair<ii,int> iii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define eb emplace_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"LINE %d: (%s) = ",__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll fpow(ll a,ll b){
    ll ret = 1;
    while (b) {
        if (b&1) ret = ret * a % MOD;
        a = a * a % MOD;
        b >>= 1;
    }
    return ret;
}
ll add(ll a,ll b){
    ll ret = a + b;
    if (ret >= MOD) ret -= MOD;
    return ret;
 }
ll sub(ll a,ll b){
    ll ret = a-b;
    if (ret < 0) ret += MOD;
    return ret;
}
int main(){
    IOS();
    ll n;
    cin >> n;
    ll ans = fpow(10,n);
    ans = sub(ans,2*fpow(9,n)%MOD);
    ans = add(ans,fpow(8,n));
    cout << ans << endl;
}


Measured memory_bytes: 3660
def check(s):
    if len(s) % 2 == 0:
        L = len(s)//2
        head=s[:L]
        tale=s[L:]
    else:
        L = (len(s)-1)//2
        head = s[:L]
        tale = s[L+1:]
    if head == tale[::-1]:
        return True
    return False
s = input()
if not check(s):
    print("No")
elif not check(s[:(len(s)-1)//2]):
    print("No")
elif not check(s[(len(s)+3)//2-1:]):
    print("No")
else:
    print("Yes")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define in(x, a, b) (a <= x && x < b)

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
const ll inf = 1000000001, INF = (ll)1e18 + 1;

int n, k;
vi a;

bool check(int val) {
	int total = 0;
	for(int i = 0; i < n; i++) {
		if(a[i] <= val) continue;
		total += a[i] / val;
		if(a[i] % val == 0) total--;
	}
	
	return (total <= k);
}

void solve() {
	cin >> n >> k;
	a.resize(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	ll ans = INF;
	int l = 1, r = 1e9 + 10;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(check(mid)) {
			ans = min(ans, (ll)mid);
			r = mid - 1;
		} else l = mid + 1;
	}
	
	cout << ans << endl;
}

int main(){
	ios_base::sync_with_stdio(false);
	solve();
    return 0;
}

Measured memory_bytes: 4008
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::*;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
  input! {
  s: i64,
  }

  let MOD: i64 = 1000000007;

  let mut vec = vec![0; 2005];
  vec[3] = 1;
  vec[4] = 1;
  vec[5] = 1;
  vec[6] = 2;
  for i in 0..2005 {
    if i > 6 {
      for j in 3..=i - 3 {
        if vec[j] != 0 {
          vec[i] += vec[j];
          vec[i] = vec[i] % MOD;
        } else {
          vec[i] += 1;
          vec[i] = vec[i] % MOD;
        }
      }
      vec[i] += 1;
    }
  }

  println!("{}", vec[s as usize]);
}


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

int main(){
    ll x;
    cin >> x;
    ll y = x % 11;
    if(y > 0 && y < 7){
        cout << (x / 11) * 2 + 1 << endl;
    }else if(y == 0){
        cout << x / 11 * 2 << endl;
    }else{
        cout << (x / 11) * 2 + 2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
_n = gets.chomp.to_i
ary = gets.chomp.split.map(&:to_i)
ary = ary.map.with_index do |attr, idx|
  attr - (idx + 1)
end.sort

mid = ary[ary.size/2]
ans = ary.inject(0) do |sum, i|
  sum + (i - mid).abs
end

puts ans




Measured memory_bytes: 34608
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let S: String = read();
    let T: String = read();
    let s: Vec<_> = S.chars().collect();
    let t: Vec<_> = T.chars().collect();
    for i in 0..s.len() {
        if s[i] != t[i] {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

const int MAXN = 1e5 + 5;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define OF {cout << "OVERFLOW!!!\n"; return 0;}

int N,M;
int A[MAXN];

LL modpow(LL r,LL n,LL m=MOD){
  LL re=1,d=r%m;
  if(n<0)(n%=m-1)+=m-1;
  for(;n;n/=2){
    if(n&1)(re*=d)%=m;
    (d*=d)%=m;
  }
  return re;
}

template <int mod=MOD> struct modInt{
  int v;
  modInt(int v=0):v(v){}
  modInt operator+(const modInt &n)const{return v+n.v<mod ? v+n.v : v+n.v-mod;}
  modInt operator-(const modInt &n)const{return v-n.v<0 ? v-n.v+mod : v-n.v;}
  modInt operator*(const modInt &n)const{return LL(v)*n.v%mod;}
  modInt operator/(const modInt &n)const{return LL(v)*modpow(n.v%mod,-1,mod)%mod;}
  modInt operator+(const LL &n)const{return v+n<mod ? v+n : v+n-mod;}
  modInt operator-(const LL &n)const{return v-n<0 ? v-n+mod : v-n;}
  modInt operator*(const LL &n)const{return LL(v)*(n%mod)%mod;}
  modInt operator/(const LL &n)const{return LL(v)*modpow(n%mod,-1,mod)%mod;}
  modInt& operator+=(const modInt &n){v+=n.v; if(v>=mod) v-=mod; return *this;}
  modInt& operator-=(const modInt &n){v-=n.v; if(v<0) v+=mod; return *this;}
  modInt& operator*=(const modInt &n){v=LL(v)*n.v%mod; return *this;}
  modInt& operator/=(const modInt &n){v=LL(v)*modpow(n.v,-1,mod)%mod; return *this;}
  modInt& operator+=(const LL &n){v+=n; if(v>=mod) v-=mod; return *this;}
  modInt& operator-=(const LL &n){v-=n; if(v<0) v+=mod; return *this;}
  modInt& operator*=(const LL &n){v=LL(v)*n%mod; return *this;}
  modInt& operator/=(const LL &n){v=LL(v)*modpow(n,-1,mod)%mod; return *this;}
};
template<int mod> ostream& operator<<(ostream &os,const modInt<mod> &n){return os<<n.v;};
template<int mod> modInt<mod> operator+(const LL &n,const modInt<mod> &m){return m.v+n<mod ? m.v+n : m.v+n-mod;}
template<int mod> modInt<mod> operator-(const LL &n,const modInt<mod> &m){return n-m.v<0 ? n-m.v+mod : n-m.v;}
template<int mod> modInt<mod> operator*(const LL &n,const modInt<mod> &m){return LL(m.v)*(n%mod)%mod;}
template<int mod> modInt<mod> operator/(const LL &n,const modInt<mod> &m){return LL(m.v)*modpow(n%mod,-1,mod)%mod;}
typedef modInt<MOD> mint;

mint dp[MAXN];
int B[MAXN];

mint f(int i) {
    if (i == N) return 1;
    if (B[i]) return dp[i];
    B[i] = 1;
    if (A[i]) return 0;

    if (i+1 <= N) dp[i] += f(i+1);
    if (i+2 <= N) dp[i] += f(i+2);

    return dp[i];
}

int main(int argc, char **argv) {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        A[a] = 1;
    }

    cout << f(0) << endl;
    return 0;
}


Measured memory_bytes: 4480
h,w=map(int,input().split())
m=[]
grid=[]
nextdfsstart=set()
nextdfsstart.add(0)
def dfs(x,y,colour):
  global grid
  global nextdfsstartcopy
  global visited
  grid[y][x]=depth
  visited.add(x+w*y)
  if x<w-1 and not x+1+y*w in visited:
    if m[y][x+1]==colour :
      dfs(x+1,y,colour)
    else:
      nextdfsstartcopy.add(x+1+y*w)
  if y<h-1 and not x+(y+1)*w in visited:
    if m[y+1][x]==colour :
      dfs(x,y+1,colour)
    else:
      nextdfsstartcopy.add(x+(y+1)*w)
for i in range(h):
  m.append(input())
  grid.append([])
  for j in range(w):
      grid[i].append(-1)
visited=set()
depth=0
while grid[h-1][w-1]==-1:
  nextdfsstartcopy=set()
  for i in nextdfsstart:
    if i in visited:
      continue
    k=i//w
    if (k+1)*w<=i:
      k+=1
    dfs(i%w,k,m[k][i%w])
  depth+=1
  nextdfsstart=nextdfsstartcopy.copy()
ans=grid[h-1][w-1]//2
if m[0][0]=='#' or m[h-1][w-1]=='#':
  ans+=1
print(ans)

Measured memory_bytes: 4076
#include <iostream>
#include<math.h>
#include <climits>

using namespace std;

int main() {
    int n,ans[100005] = {INT_MAX},a[100005], k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    cin>>a[i];
    ans[0] = 0;
    for(int i=1;i<n;i++){
        if(i==1)
        ans[i] = abs(a[1]-a[0]);
        else {
            int x = INT_MAX;
            for(int j = 1; j<=k;j++){
                if(j<=i){
                	x = min(x , (ans[i-j] + abs(a[i-j]-a[i])));
                }
                else {
                    ans[i] = x;
                    break;
                }
                ans[i] = x;
            }
        }
    }
    
    cout<<ans[n-1];
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
	
	int W,H,x,y,r;
	
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	
	if(x+r<=W && x-r>=0 && y+r<=H && y-r>=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1016
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <utility>
#include <vector>

using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> LR(M, pair<int, int>(0, 0));
    int From = 0, To = N;
    for (int i = 0; i < M; i++)
    {
        cin >> LR[i].first >> LR[i].second;
        if (LR[i].second < From)
        {
            cout << 0;
            return 0;
        }
        if (LR[i].first > To)
        {
            cout << 0;
            return 0;
        }

        if (From < LR[i].first)
            From = LR[i].first;
        if (To > LR[i].second)
            To = LR[i].second;
    }

    cout << (To - From + 1);

    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <unordered_set>

int main()
{
  int n;
  std::unordered_set<std::string> stringSet;
  int result;
  
  std::cin>>n;
  
  std::string s;
  for(int i=0;i!=n;i++)
  {
    std::cin>>s;
    stringSet.emplace(std::move(s));
    s.clear();
  }
  
  result=stringSet.size();
  
  std::cout<<result<<std::endl;
  
  return 0;
}

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

void MAIN() {
    int n, x;
    scanf("%d%d", &n, &x);
    std::vector<int> arr(n);
    for(int &now: arr) {
        scanf("%d", &now);
    }
    long long ans = LLONG_MAX;
    std::vector<int> minEle(n, INT_MAX);
    for(int k = 0; k < n; ++ k) {
        long long curAns = 0;
        for(int i = 0; i < n; ++ i) {
            minEle[i] = std::min(minEle[i], arr[(i - k + n) %n]);
            curAns += minEle[i];
        }
        curAns += k * 1ll * x;
        ans = std::min(ans, curAns);
    }
    printf("%lld\n", ans);
}

int main() {
    MAIN();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 1000000000
#define mod 1000000007
#define pb push_back
#define sz(v) (v).size()
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define fi first
#define se second
using namespace std;
template <class T> void chmax(T &x,T y){x=x>y?x:y;return;}
template <class T> void chmin(T &x,T y){x=x<y?x:y;return;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pi;

int k,n;
int a[200005],dist[200005];

int main()
{
	scanf("%d%d",&k,&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=2;i<=n;i++)
		dist[i]=a[i]-a[i-1];
	dist[1]=k-a[n]+a[1];
	int maxn=-1,sum=0;
	for(int i=1;i<=n;i++)
	{
		chmax(maxn,dist[i]);
		sum+=dist[i];
	}
	printf("%d\n",sum-maxn);
	return 0;
}

Measured memory_bytes: 5340
#include <bits/stdc++.h>
using namespace std;
int main () {
	int N;
	cin >> N;
	int x[N], y[N];
	for (int i=0; i<N; i++) {
		cin >> x[i] >> y[i];
	}
	double sum=0.0;
	for (int i=0; i<N; i++) {
		for (int j=0; j<N; j++) {
			sum+=sqrtl((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
		}
	}
	sum/=N;
	cout << fixed << setprecision(10)<< sum << endl;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	while(cin>>n,n){
		int s=0;
		rep(i,n/4){
			int t;
			cin>>t;
			s+=t;
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1160
#include<stdio.h>
int main(void)
{
  int a,b,x=0;
  
  scanf("%d %d",&a,&b);
  

    if(a>b){
      x+=a;
      a--;
    }else{
      x+=b;
      b--;
    }
  
      if(a>b){
      x+=a;
      a--;
    }else{
      x+=b;
      b--;
    }
  printf("%d\n",x);
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	char string[2048];
	int i=0;
	int qty=0;
	
	fgets(string,2000,stdin);
	
	while(string[i]!='\0')
	{
		qty++;
		i++;
	}
	
	for(i=0;i<=qty;i++)
	{
		if('A' <= string[i] && string[i] <= 'Z')
		{
			string[i] += ((int)('a') - ('A'));
		}
		else if('a' <= string[i] && string[i] <= 'z')
		{
			string[i] -= ((int)('a') - ('A'));
		}
	}
	
	printf("%s",string);
	
	return 0;
}


Measured memory_bytes: 2704
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  int n; cin >> n;
  if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8) cout << "pon" << endl;
  else if(n % 10 == 3) cout << "bon" << endl;
  else cout << "hon" << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
右端を更新できなければやる必要ないのでは？
*/

struct d{ll l,r,c;};
bool operator<(const d &l, const d &r){
	if(l.l<r.l)return true;
	if(l.l==r.l){
		if(l.c<r.c)return true;
		if(l.c==r.c){
			return l.r>r.r;
		}
	}
	return false;
}

ll n,m,l[100010],r[100010],c[100010];
d p[100010];
ll dp[100010];

int main(void){
	cin>>n>>m;
	rep(i,m)cin>>p[i].l>>p[i].r>>p[i].c;
	reg(i,1,n)dp[i]=1e18;
	dp[1]=0;
	sort(p,p+m);
	rep(i,m){
		ireg(j,p[i].l+1,p[i].r){
			if(dp[j]<=dp[p[i].l]+p[i].c)break;
			dp[j] = dp[p[i].l]+p[i].c;
		}
		// printf("%lld,%lld,%lld\n",p[i].l,p[i].r,p[i].c);
	}
	cout<<(dp[n]==1e18?-1:dp[n])<<endl;
	return 0;
}

Measured memory_bytes: 4352
import numpy as np


class FastFourierTransform:
	"""FFT
	"""

	def multiplySameArr(self,A):
		""" multiply by FFT(A*A)
		"""
		N=1
		# 1. N > deg(g) + deg(h)となる2の冪乗を選ぶ
		while N < 2*len(A): N *= 2

		# 2. 離散フーリエ変換の計算
		nf = np.zeros(N,int)
		nf[:len(A)]=A
		# nf=np.fft.fft(nf)
		nf=np.fft.rfft(nf)
		nf = nf * nf

		# 3. 離散フーリエ逆変換
		# nf=np.fft.ifft(nf)
		nf=np.fft.irfft(nf)

		# コピー
		ans = np.rint( nf )
		# ans = np.zeros(N,int)
		# for n in range(N):
		# 	# 係数を1/N倍 => np.fftの場合、すでに実行済
		# 	#ans.append( round(nf[n].real / N) )
		# 	if nf[n].real != 0:
		# 		ans[n] = int(nf[n].real + 0.5)

		return ans

if __name__ == "__main__":
	N=int(input())
	A=list(map(int,input().split()))

	P=200_003
	rootP=2

	# order of 1 to P-1 after fft
	order=[1]
	x=rootP
	while x!=1:
		order.append(x)
		x *= rootP
		x %= P

	ORDER_SIZE=len(order)	# 200_002

	# create order index
	where=np.zeros(P,int)
	for i in range(ORDER_SIZE):
		where[ order[i] ] = i

	# count non zero items
	prevCnt = np.zeros(P,int)
	resCnt = np.zeros(P,int)
	for n in range(N):
		if A[n] != 0:
			prevCnt[ where[A[n]] ] += 1
			# remove Ax * Ax pattern count
			resCnt[ (A[n] * A[n]) % P ] -= 1

	# fft to cnt (calc nC2 and all Ax * Ay)
	clsFFT = FastFourierTransform()
	fftRes = clsFFT.multiplySameArr(prevCnt)

	for r in range(len(fftRes)):
		if fftRes[r] != 0:
			# get result(Ax*Ay==resCnt.index) Cnt by summary fftRes
			resCnt[ order[ r % ORDER_SIZE ] ] += fftRes[r]

	ans = 0
	for p in range(P):
		if resCnt[p] != 0:
			# remove j <= i pattern count 
			# and
			# calc summary value((Ax * Ay cnt) * (Ax * Ay)))
			ans += (resCnt[p] // 2) * p

	print(ans)




Measured memory_bytes: 68948
#include<bits/stdc++.h>
#include<vector>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#define rep(i,N) for(int i=0;i<N;i++)

using namespace std;

int main(void){
    int H,R;
    cin>>H>>R;
    if(H+R<0)cout<<-1<<endl;
    else if(H+R==0)cout<<0<<endl;
    else cout<<1<<endl;

}




Measured memory_bytes: 3116
from collections import Counter

N, *A = map(int, open(0).read().split())

A.sort()
lim = A[-1] + 1

dp = Counter()
for a in A:
    dp[a] += 1
    if dp[a] == 1:
        dp.update({k : 2 for k in range(2 * a, lim, a)})

print(len([0 for k, v in dp.items() if v == 1]))

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

int main()
{
  int64_t K, S, ans = 0;
  cin >> K >> S;
  for (int i = 0; i <= K; i++)
  {
    for (int j = 0; j <= K; j++)
    {
      if (i + j <= S && S - i - j <= K)
        ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    const int n = 9;
    const int time = 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2;
    int t;
    int a[n], b[n];

    cin >> t;
    while (t--) {
        for (int i = 0; i < n; ++i)
            cin >> a[i];
        for (int i = 0; i < n; ++i)
            cin >> b[i];

        sort(b, b + n);
        int win = 0;
        do {
            int a_s = 0, b_s = 0;
            for (int i = 0; i < n; ++i) {
                if (a[i] > b[i])
                    a_s += a[i] + b[i];
                else
                    b_s += a[i] + b[i];
            }
            if (a_s > b_s)
                ++win;
        } while (next_permutation(b, b + n));

        printf("%.5lf %.5lf\n", (double)win / time, (double)(time - win) / time);
    }

    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    
    int N, M;
    cin >> N >> M;
    
    vector<vector<char>> a(N, vector<char>(M));
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < M; j++){
            cin >> a[i][j];
        }
    }
    
    for(int i = 0; i < N; i++){
        
        bool b = false;
        
        for(int j = 0; j < M; j++){
            
            if(a[i][j] != '.'){
                b = false;
                break;
            }
 
            else
                b = true;
        }
        
        if(b){
            for(int j = 0; j < M; j++){
                a[i][j] = 'X';
            }
        }
    }
    
    
    for(int j = 0; j < M; j++){
        
        bool b = false;
        
        for(int i = 0; i < N; i++){
            
            if(a[i][j] == 'X' || a[i][j] == '.')
                b = true;
                
            else{
                b = false;
                break;
            }
        }
        
        if(b){
            for(int i = 0; i < N; i++){
                a[i][j] = 'X';
            }
        }
    }
    
    
    for(int i = 0; i < N; i++){
        bool b = false;
        for(int j = 0; j < M; j++){
            if(a[i][j] != 'X'){
                cout << a[i][j];
                b = true;
            }
        }
        if(b)
            cout << endl;
    }
    
}


Measured memory_bytes: 256
main(a,b,c,n,r){
  for(;scanf("%d%d%d%d",&a,&b,&c,&n),a;){
    if(a>c)r=a,a=c,c=r;
    if(b>c)r=b,b=c,c=r;
    for(;n--;puts(r*2>hypot(a,b)?"OK":"NA"))scanf("%d",&r);
  }
  return 0;
}

Measured memory_bytes: 0
a, b, c, d = map(int, input().split())
import math
ao = math.ceil(a / d)
taka = math.ceil(c / b)
#print(taka, ao)
if taka == ao:
    print('Yes')
else:
    if taka > ao:
        print('No')
    else:
        print('Yes')

Measured memory_bytes: 9176
#include <cstdio>
#include <cmath>
#include <string>

using namespace std;

int main() {
	
	int H, W, a, b;
	int ans;
	
	scanf("%d", &H);
	scanf("%d", &W);
	scanf("%d", &a);
	scanf("%d", &b);
	
	ans = (H * W) - ((H*b) + (W*a) - a*b);
	
	printf("%d", ans);
	
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int x, y;
  cin >> x >> y;
  rep(i, x + 1){
    if(i * 2 <= y){
      if(i * 2 + (x - i) * 4 == y){
	cout << "Yes\n";
	return 0;
      }
    }
  }
  cout << "No\n";
		
  return 0;
}


Measured memory_bytes: 3636
import java.io.*;
import java.util.*;

class Main {

    public static void main(String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long N;
        N = sc.nextLong();
        long K;
        K = sc.nextLong();
        long[] h = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                h[i] = sc.nextLong();
        }
        solve(N, K, h);
    }

    static void solve(long N, long K, long[] h){
        long ans = 0;
        for (long hi : h) {
            if(hi >= K) ans++;
        }
        System.out.println(ans);
    }
}


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

const int MAX = 1000050;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  ll x, y;
  cin >> x >> y;
  COMinit();
  if((x+y)%3 != 0){
  	cout << '0' << endl;
  }else{
    ll n = (x+y)/3;
    ll k = (x-y+n)/2;
	cout << COM(n,k)%MOD << endl;    
  }
}

Measured memory_bytes: 23808
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
//int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
//int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
//const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
    fio();
    
    int n;
    cin >> n;
    vi a = {2,4,5,7,9};
    vi b = {0, 1, 6, 8};
    vi c = {3};
    for (int x: a) {
        if (x == n % 10) {
            cout << "hon" << endl;
        }
    }
    for (int x: b) {
        if (x == n % 10) {
            cout << "pon" << endl;
        }
    }
    for (int x: c) {
        if (x == n % 10) {
            cout << "bon" << endl;
        }
    }
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
/* S.size() s.substr(l,r=s.size()-l) -> l文字目からr文字分
__gcd()　lower_bound(a+l,a+r,x)-a でindex
// 配列  -> min/max({}) 
// vector-> *min_element(a+l,a+r)  *忘れず lとrで[l,r) 
//reverse(a+l,a+r)   配列aの[l,r)を逆順に strはreverse(all(s))
//sort(a+l,a+r,greater <int>()) 配列aの[l,r)昇順sort,大きい順はgreater<type>()
//vectorならall(v)
clock()/CLOCKS_PER_SEC で秒数
vector v.push_back(x),v.pop_back()
q.push(x),front()で先頭を返す,pop()で削除, size(),empty()
<deque>(push/pop)_(front/back)/fornt/back/insert/
priority_queue 宣言は priority_queue< Type, vector<Type>, greater<Type>> Q1; 
// pq.push(x),top()で参照 pop()で削除   greaterで最小 lessで最大がtopに*/
using namespace std;
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n)-1;(i)!=-1;(i)--)
#define vep(i,v) for(auto (i)=v.begin();(i)<(v.end());(i)++)
#define print(i) std::cout << (i) << '\n'
inline long long ceildiv(long long a, long long  b) { return (a+b-1)/b; }
typedef pair<long long,long long> P;
const long long inf = 10e7;
const long long mod = 1000000007;
//int |x|<=2*10**9     long |x|<= 9*10**18
//printf(".(小数点以下の桁数)lf(double時、float ならf)")
#define ll long long

int gen,yama;
int main(){
    cin>>gen>>yama;
    vector<bool> dp(yama+1,false);
    vector<int> move(gen);rep(i,gen)cin>>move[i];
    rep(i,yama+1){bool rec=false;rrep(m,gen)
    {
      if (i>=move[m]){rec|=!dp[i-move[m]];}
      }dp[i]=rec;
                 }

    bool ans=dp[yama];
  print(ans?"First":"Second");

}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int n,q,Q[200],i,j,k;
  int a[2000+1]={0};
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&q);
    for(j=2000-q;j>0;j--){
      if(a[j]){
        a[j+q] = 1;
      }
    }
    a[q] = 1;
  }
  scanf("%d",&k);
  for(i = 0; i < k; i++){
    scanf("%d", &q);
    if(a[q]){
      printf("yes\n");
    }
    else printf("no\n");
  }
  
  return 0;
}

Measured memory_bytes: 588
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n=int(input())

mod=10**9+7

MAX_N = n+5
fac = [1,1] + [0]*MAX_N
finv = [1,1] + [0]*MAX_N
inv = [0,1] + [0]*MAX_N
for i in range(2, MAX_N):
    fac[i] = fac[i-1] * i % mod
    inv[i] = mod - inv[mod % i] * (mod // i) % mod
    finv[i] = finv[i-1] * inv[i] % mod

def nCk(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ans=0
lim=n//3
for i in range(1,lim+1):
  q=n-3*i
  ans+=nCk(q+i-1,i-1)
  ans%=mod

print(ans)

Measured memory_bytes: 9360
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>

using namespace std;

int main(){
  int n; cin >> n;
  string s; cin >> s;
  vector<vector< vector<int> > > used(10, vector<vector<int> >(10, vector<int>(10, 0)));
  vector<int> f(10, 30000);
  vector<vector<int> > p(10);
  for(int i = 0; i < s.length(); i++){
    if(f[s[i]-'0'] == 30000) f[s[i]-'0'] = i;
    p[s[i]-'0'].push_back(i);
  }
  for(int i = 0; i < 10; i++){
    if(f[i] == 30000) continue;
    for(int j = 0; j < 10; j++){
      auto m = upper_bound(p[j].begin(), p[j].end(), f[i]);
      if(m == p[j].end()) continue;
      for(int k = 0; k < 10; k++){
        auto l = upper_bound(p[k].begin(), p[k].end(), *m);
        if(l == p[k].end()) continue;
        used[i][j][k] = 1;
      }
    }
  }
  int ans = 0;
  for(int i = 0; i < 10; i++){
    for(int j = 0; j < 10; j++){
      for(int k = 0; k < 10; k++){
        if(used[i][j][k]) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(){
  ll n,m,k,l;
  cin >>n>>m;
  vector<pair<ll,ll>> a;
  for(ll i=0;i<n;i++) {
    cin >>k>>l;
    a.push_back(make_pair(k,l));
  }
  sort(a.begin(),a.end());
  ll ans=0,cnt=m;
  for(ll i=0;i<n;i++){
    if(cnt-a[i].second<=0){
      ans+=(cnt*a[i].first);
      cout <<ans<<endl;
      return 0;
    }
    ans+=(a[i].second*a[i].first);
    cnt-=a[i].second;
  }
}


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

int A, B, C, D;

int max_overlap(int a, int b, int c, int d) {
  int max_lap = 0;

  if (a > c) {
    swap(a, c);
    swap(b, d);
  }

  if (b < c) {
    return 0;
  }

  if (d > b) {
    return b - c;
  } else {
    return d - c;
  }
}

int main() {
  while(cin >> A >> B >> C >> D) {
    cout << max_overlap(A, B, C, D) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int a[6],i,an=0,c,d,e;
    for(i=0;i<6;i++){
    scanf("%d\n",&a[i]);
    an+=a[i];
    }

if(a[4]>a[5])c=a[5];
else c=a[4];

if(a[1]>a[0])d=a[0];
else d=a[1];
if(a[3]>a[2])e=a[2];

else e=a[3];

if(e<d)d=e;





printf("%d\n",an-c-d);
return 0;
}

Measured memory_bytes: 1788
A,B = map(int,input().split())

ans_array = [ [1] * 100 if i < 50 else [0] * 100 for i in range(100)]

# print(ans_array)
A -= 1
B -= 1
i = 1
j = 1
# print(ans_array[i])
while A != 0:
    ans_array[i][j] = 0
    A -= 1
    j += 2
    if j >= 100:
        i += 2
        j = 1

i = 51
j = 1
while B != 0:
    ans_array[i][j] = 1
    B -= 1
    j += 2
    if j >= 100:
        i += 2
        j = 1

print(100,100)
for ans in ans_array:
    ans_str = "".join(map(str,ans)).replace("0",".").replace("1","#")
    print(ans_str)

Measured memory_bytes: 38768
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

class Edge {
public:
    int next;
    int dist;
    Edge() {}
    Edge(int n, int d) {
	next = n;
	dist = d;
    }
};

class Info {
public:
    int node;
    int left;
    double dist;
    Info() {}
    Info(int n, int l, double d) {
	node = n;
	left = l;
	dist = d;
    }
    bool operator< (const Info &a) const {
	return dist > a.dist;
    }
};

double mindist[30][300];

signed main() {
    int n, m, p, a, b;
    while (cin >> n >> m >> p >> a >> b) {
	if (n == 0) break;
	a--; b--;

	vector<int> t;
	inputVector(t, n);

	vector<vector<Edge>> edges;
	edges.resize(m);

	rep(i, p) {
	    int x, y, z;
	    cin >> x >> y >> z;
	    x--; y--;
	    edges[x].push_back(Edge(y, z));
	    edges[y].push_back(Edge(x, z));
	}

	rep(i, m) rep(j, 300) mindist[i][j] = 1000000000;
	mindist[a][(1 << n) - 1] = 0;

	bool pr = false;
	priority_queue<Info> q;
	q.push(Info(a, (1 << n) - 1, 0));
	while (!q.empty()) {
	    Info info = q.top(); q.pop();
	    if (info.dist > mindist[info.node][info.left] + 0.001) continue;
	    if (info.node == b) {
		printf("%.4f\n", info.dist);
		pr = true;
		break;
	    }
	    rep(i, n) {
		int j = 1 << i;
		if ((info.left & j) == 0) continue;
		int nleft = info.left ^ j;
		rep(k, edges[info.node].size()) {
		    int nnode = edges[info.node][k].next;
		    double ndist = info.dist + (double) edges[info.node][k].dist / t[i];
		    if (mindist[nnode][nleft] <= ndist) continue;
		    mindist[nnode][nleft] = ndist;
		    q.push(Info(nnode, nleft, ndist));
		}
	    }
	}

	if (!pr) {
	    cout << "Impossible" << endl;
	}
    }

    return 0;
}

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

int main(){
	char s[5];
	for (int i = 0; i<4; i++) cin >> s[i];
	sort(s,s+4);
	cout << ((s[0]==s[1] && s[0]!=s[2] && s[2]==s[3])? "Yes" : "No") << endl;
	
	return 0;
}

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

int main() {
  int a, c, ans;
  int b;
  cin >> a;
  b = ceil(a / 1.08);
  // cout << b << endl;
  c = b * 1.08;
  // cout << c << endl;
  if (a == c) {
    ans = b;
    cout << ans;
  } else {
    cout << ":(";
  }
  return 0;
}

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

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

using namespace std;

void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	long long int n, k, nw=1, sen=0;
	vector<int> v, seen, p(1);

	cin>> n >> k;
	v.resize(n+1);
	seen.resize(n+1, 0);

	rep(i, n) cin >> v[i+1];

	seen[1]=1;
	p[0]=1;
	while(1){
		if(k==sen) break;

		nw=v[nw];
		sen++;
		if(seen[nw]){
			int po;
			rep(i, p.size()){
				if(p[i]==nw){
					po=i;
					break;
				}
			}

			nw=p[(k-sen)%(sen-po)+po];
			break;
		}else{
			seen[nw]=1;
			p.push_back(nw);
		}
	}

	//PV(p);
	cout<< nw << endl;
 
	return 0;
}

Measured memory_bytes: 5712
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

int main(){
    ll a,v;
    ll b,w;
    cin >> a >> v;
    cin >> b >> w;
    ll t;
    cin >> t;
    ll d = abs(b-a);
    ll oni = v * t;
    ll nige = w * t;
    if(nige+d<=oni){
        cout << "YES" << endl;
    }
    else{
        cout << "NO"  << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
//Replacing Integer
//xとxをKの差の絶対値で置き換える
//最小かどうかの判断が難しい
//どのタイミングで止めればいい？

//自力で解くのに失敗
//得たもの->答えを絞り込めたら、どうにかして数式化できないか
//考察する
#include<iostream>
using namespace std;

int main(){
  long long x,k;
  cin>>x;
  cin>>k;
  long long ans=0;
  ans=min(x%k,k-(x%k));
  cout<<ans;
}


Measured memory_bytes: 256
#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(){
    int n, m;
    cin >> n >> m;
    vector<vector<int> > graph(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<int> ans(n, -1);
    vector<int> dist(n, -1);
    queue<int> q;
    dist[0] = 0;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();

        for(int nv : graph[v]){
            if(dist[nv] != -1)  continue;
            dist[nv] = dist[v] + 1;
            ans[nv] = v+1;
            q.push(nv);
        }
    }
    for(int i = 1; i<n; ++i){
        if(ans[i]==-1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    for(int v = 1; v<n; ++v) cout << ans[v] << endl;
    return 0;
}

Measured memory_bytes: 10580
n = int(input())
values = [int(i) for i in input().split()]
costs = [int(i) for i in input().split()]
differences = []
count = 0
for value in values:
  count += 1
  if value-costs[count-1] > 0:
      differences.append(value-costs[count-1])
print(sum(differences))

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

int main(){
  int n;
  cin>>n;
  long long int a[n];
  int max=0,mid;

  for(int i=0;i<n;i++){
    cin>>a[i];
    if(max<a[i])max=a[i];
  }
  mid=max;
  for(int i=0;i<n;i++){
    if(abs(max/2+max%2-mid)>=abs(max/2+max%2-a[i]))mid=a[i];
  }
  cout<<max<<" "<<mid<<endl;
}


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

#define MAX 12
#define MAX_ORDER 16777216

char dec[MAX_ORDER][MAX];

int getChar_ID(char c){
  if(c == 'A'){
    return 1;
  }else if(c == 'C'){
    return 2;
  }else if(c == 'G'){
    return 3;
  }else if(c == 'T'){
    return 4;
  }else return -1;
}

long analysis(char *str){
  int len = strlen(str);
  int i;
  int id=0;
  int k=1;
  //printf("in to analysis\n" );
  for(i=0; i<len; i++){
    id += k * getChar_ID(str[len-i-1]);
    k *= 4;
    //printf("len-i=%d\n",len-i );
    //printf("Now ID: %d\n", id);
  }
  return id;
}

void insert(int id, char *str){
  strcpy(dec[id],str);
}

void find(int id,char *str){
  if(0==strcmp(dec[id],str)){
    printf("yes\n" );
  }else printf("no\n" );
}

int main() {
  int n;
  char str[MAX];
  char com[7];
  int i;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%s %s",com,str);
    if(com[0]=='i'){
      insert(analysis(str),str);
    }else if(com[0]=='f'){
      find(analysis(str),str);
    }else printf("Command is illegal\n");
  }
  return 0;
}



Measured memory_bytes: 18100
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,k;
    cin>>n>>k;
    std::vector<int> v(n),answer(n);
    fr(i,n) cin>>v[i];
    answer[0]=0;
    for(int i=1;i<min(k,n);i++)
    {
        answer[i]=abs(v[i]-v[0]);
    }
    for(int i=k;i<n;i++)
    {
        int mini=INT_MAX;
        for(int j=1;j<=k;j++)
        {
            if(answer[i-j]+abs(v[i]-v[i-j])<mini)
                mini=answer[i-j]+abs(v[i]-v[i-j]);
        }
        answer[i]=mini;
    }
    cout<<answer[n-1];
    return 0;
}

Measured memory_bytes: 1792