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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cout<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');
    cout.write(names,comma-names)<<" : "<<arg1<<" | ";
    __f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    int x;
    cin>>x;
    cout<<!x;
    return 0;
}



Measured memory_bytes: 3644
#include <stdio.h>

int gcd(long long a, long long b) {
	long long r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
int lcm(long long a, long long b) {
	return a * b / gcd(a,b);
}

int main(void) {
	long long i, n, a[3000], ans = 1, max = 0, sum = 0;
	
	scanf("%lld", &n);
	for (i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
		ans = lcm(ans, a[i]);
		sum += a[i];
	}
	
	for (i = 0; i < n; i++) {
		max += (ans - 1) % a[i];
	}
	
	printf("%lld", (max > sum-n ? max : sum-n));
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String a = sc.next();
		String b = sc.next();
		int length = a.length();
		// スペース区切りの整数の入力
		// 文字列の入力
		String afterA = a;

		for(int i=0;i<length;i++){
			char charA = afterA.charAt(length-1);
			afterA = charA+ afterA.substring(0, length-1);
			if(afterA.equals(b)){
			System.out.println("Yes");
			return;
			}
		}
			
System.out.println("No");
		
	}
}

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

int main(void){
 long long a, b, x;
  cin >> a >> b >> x;
  long long count = 0;
  long long div_a = a / x;
  long long div_b = b / x;
  int s = 0;
  if(a % x == 0) s++;
cout << div_b - div_a + s;
    
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string str="";
    int c=0;
    for(int i=0;i<k;i++)
    {
        str+='7';
        c=c*10+(str[i]-'0');
        c%=k;
        if(c==0)
        {
            cout<<str.size()<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 5232
#include <stdio.h>
#define M 1000000007

int main(){
	long a, b, x, n;
	scanf("%ld %ld %ld", &a, &b, &x);
	if(x - b >=0){
    	printf("%ld\n", (x + ( ( (x - b)/(a - b) )%M) * (b%M) ) %M );
	}else{
	    printf("%ld\n", x % M);
    }
}


Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n, k;
int r, s, p;
string t;

signed main() {
	int i;
	
	cin >> n >> k;
	cin >> r >> s >> p;
	cin >> t;
	
	string S;
	for (i = 0; i < n; i++) {
		char w;
		if (t[i] == 'r') { w = 'p'; }
		if (t[i] == 's') { w = 'r'; }
		if (t[i] == 'p') { w = 's'; }
		
		if (i >= k && S[i - k] == w) {
			w = '-';
		}
		S += w;
	}
	
	int ans = 0;
	rep(i, n) {
		if (S[i] == 'r') ans += r;
		if (S[i] == 's') ans += s;
		if (S[i] == 'p') ans += p;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int n, m;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n >> m;
    UnionFind<int> uf(n);
    vii lang[m];
    rep(i, 0, n) {
      int k; 
      cin >> k;
      rep(j, 0, k) {
        int x; cin >> x;
        lang[x-1].pb(i);
      }
    }
    rep(i, 0, m) {
      if (lang[i].size() == 0) continue; 
      int t = lang[i][0];
      rep(j, 1, lang[i].size()) {
        uf.merge(t, lang[i][j], 1);
      }
    }
    rep(i, 0, n-1) {
      if (!uf.issame(i, i+1)) {
        cout << "NO" << endl;
        return 0;
      }
    }
    cout << "YES" << endl;
    return 0;
}



Measured memory_bytes: 4608
n, m , c = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = 0
for i in range(n):
    a = list(map(int, input().split()))
    sum = 0
    for j in range(m):
        sum += a[j] * b[j]

    if sum + c > 0:
        ans += 1

print(ans)

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N,M=map(int,input().split())
B=[tuple(map(int,input().split())) for i in range(M)]
B.sort()


#Starry sky tree(一点取得、範囲min更新の1-indexed Segment tree. Aは0-indexedなことに注意.



seg_el=1<<((N+1).bit_length())# Segment treeの台の要素数
SEG=[1<<60]*(2*seg_el)# 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
SEG[1+seg_el]=0

def getvalue(n,seg_el):# 一点の値を取得
    i=n+seg_el
    ANS=1<<60
    
    ANS=min(SEG[i],ANS)
    i>>=1# 子ノードへ
    
    while i!=0:
        ANS=min(SEG[i],ANS)
        i>>=1

    return ANS

def updates(l,r,x):# 区間[l,r)のminを更新.
    L=l+seg_el
    R=r+seg_el

    while L<R:
        if L & 1:
            SEG[L]=min(x,SEG[L])
            L+=1

        if R & 1:
            R-=1
            SEG[R]=min(x,SEG[R])
        L>>=1
        R>>=1

for l,r,c in B:
    x=getvalue(l,seg_el)
    updates(l,r+1,x+c)

if getvalue(N,seg_el)==1<<60:
    print(-1)
else:
    print(getvalue(N,seg_el))


Measured memory_bytes: 69852
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();

		Shop[] shops = new Shop[n];

		for(int i = 0; i < n; i++){
			shops[i] = new Shop(sc.nextInt(), sc.nextInt());
		}

		Arrays.sort(shops);
		long total = 0;
		for(int i = 0; i < n; i++){
			if(shops[i].stock < m){
				total += (long)shops[i].stock*shops[i].price;
				m -= shops[i].stock;
			}
			else {
				total += (long)m*shops[i].price;
				break;
			}

//			System.out.println("total "+total+" m "+m);
		}

		System.out.println(total);
	}
}

class Shop implements Comparable<Shop>{
	int price;
	int stock;

	Shop(int price, int stock){
		this.price = price;
		this.stock = stock;
	}

	@Override
	public int compareTo(Shop s) {
		// TODO 自動生成されたメソッド・スタブ
		return this.price - s.price;
	}


}

Measured memory_bytes: 88480
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>

using namespace std;

typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef map<int, int> M;
typedef pair<int, int> P;
typedef stack<int> S;
typedef queue<int> Q;

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

    int a, b;
    cin >> a >> b;
    if ((!(a%2)) || (!(b%2))) cout << "No" << endl;
    else cout << "Yes" << endl;
    
    return 0;
}

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

const int MO=1e9+7;
const int M=2e5+5;

inline int add(int x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
	return x;
}
inline int sub(int x,int y)
{
	x-=y;
	if(x<0) x+=MO;
	return x;
}
inline int mul(int x,int y)
{
	return 1LL*x*y%MO;
}
inline void addv(int &x,int y)
{
	x+=y;
	if(x>=MO) x-=MO;
}
inline void subv(int &x,int y)
{
	x-=y;
	if(x<0) x+=MO;
}
inline void mulv(int &x,int y)
{
	x=1LL*x*y%MO;
}

int qp(int a,int n)
{
	int ans=1;
	while(n)
	{
		if(n&1) mulv(ans,a);
		mulv(a,a);
		n>>=1;
	}
	return ans;
}

int isp[M],pri[M],npri=0;
int mu[M];
void get_mu()
{
	mu[1]=1;
	for(int i=2;i<M;i++)
	{
		if(!isp[i])
		{
			pri[npri++]=i;
			mu[i]=-1;
		}
		for(int j=0;j<npri&&pri[j]*i<M;j++)
		{
			isp[i*pri[j]]=1;
			if(i%pri[j]==0)
			{
				mu[i*pri[j]]=0;
				break;
			}
			else
				mu[i*pri[j]]=-mu[i];
		}
	}
}

int f[M];

int main()
{
	get_mu();
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++)
		f[i]=qp(k/i,n);
	int ans=0;
	for(int i=1;i<=k;i++)
	{
		int g=0;
		for(int j=1;j*i<=k;j++)
		{
			addv(g,mul(add(mu[j],MO),f[i*j]));
		}
		//cout<<i<<" "<<g<<endl;
		addv(ans,mul(g,i));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5848
//Name: Count the Regions
//Level: 3
//Category: 塗りつぶし,座標圧縮
//Note:

/**
 * x座標をひとつ固定して、縦に連なったピクセルを縦ベクトルとして考えると、y軸に平行な辺が存在しない箇所ではずっと同じベクトルが続く。
 * したがって、この区間は1ピクセルにまとめてしまってよい。
 * y座標に関しても同じことが言える。
 *
 * この前処理を行うと、全体が O(N^2) ピクセルの画像として表されるので、塗りつぶしで領域の個数を求めることができる。
 * 辺は1ピクセルを専有し、かつ偶数座標にしか存在しないものとして扱うと楽に実装できる。
 * （元の状態におけるピクセルと辺を両方ともピクセルとして扱う）
 *
 * オーダーは O(N^2)。
 */
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>

using namespace std;

struct Dict {
    vector<int> elem;
    unordered_map<int,int> dict;

    void put(int i) {
        elem.push_back(i);
    }

    void gen() {
        sort(begin(elem), end(elem));
        elem.erase(unique(begin(elem), end(elem)), end(elem));
        for(auto i : elem) {
            const int idx = dict.size();
            dict[i] = idx;
        }
    }

    int get(int i) {
        return dict[i];
    }

    int rev(int i) {
        return elem[i];
    }

    int size() const {
        return elem.size();
    }
};

struct Rect {
    int l, t, r, b;
};

void put(Dict &d, int v) {
    d.put(v-1);
    d.put(v);
    d.put(v+1);
}

const int DR[] = {0, -1, 0, 1};
const int DC[] = {1, 0, -1, 0};
void paint(vector<vector<int>> &field, int r, int c) {
    static vector<pair<int,int>> q;
    q.clear();
    q.emplace_back(r, c);
    field[r][c] = 1;
    while(!q.empty()) {
        const auto cur = q.back();
        q.pop_back();
        for(int d = 0; d < 4; ++d) {
            const int nr = cur.first + DR[d];
            const int nc = cur.second + DC[d];
            if(nr < 0 || field.size() <= nr || nc < 0 || field[0].size() <= nc) continue;
            if(field[nr][nc]) continue;
            field[nr][nc] = 1;
            q.emplace_back(nr, nc);
        }
    }
}

bool solve() {
    int N;
    if(!(cin >> N)) return false;
    if(!N) return false;

    Dict xdict, ydict;
    vector<Rect> rects(N);
    for(int i = 0; i < N; ++i) {
        Rect &r = rects[i];
        cin >> r.l >> r.t >> r.r >> r.b;
        r.l *= 2;
        r.t *= 2;
        r.r *= 2;
        r.b *= 2;
        put(xdict, r.l);
        put(xdict, r.r);
        put(ydict, r.t);
        put(ydict, r.b);
    }
    xdict.gen();
    ydict.gen();

    vector<vector<int>> field(ydict.size(), vector<int>(xdict.size(), 0));
    for(const auto &re : rects) {
        const int l = xdict.get(re.l);
        const int r = xdict.get(re.r);
        const int t = ydict.get(re.t);
        const int b = ydict.get(re.b);
        for(int i = l; i <= r; ++i) {
            field[t][i] = field[b][i] = 1;
        }
        for(int i = b; i <= t; ++i) {
            field[i][l] = field[i][r] = 1;
        }
    }

    int ans = 0;
    for(int r = 0; r < field.size(); ++r) {
        for(int c = 0; c < field[0].size(); ++c) {
            if(field[r][c] == 0) {
                paint(field, r, c);
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return true;
}

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

    while(solve()) ;
    return 0;
}

Measured memory_bytes: 1752
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

#define rep(i,n) for(ll i=0;i<(n);i++)
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}

int main() {
	int n;
	cin >> n;
	vector<int> p(n);
	rep(i, n) cin >> p[i];

	int cnt = 0;
	for (int i = 1; i < n - 1; i++) {
		if (p[i - 1] <= p[i] && p[i] <= p[i + 1]) {
			cnt++;
		}
		else if (p[i + 1] <= p[i] && p[i] <= p[i - 1]) {
			cnt++;
		}
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cstdlib>  
#include<cmath>   
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include<map>
#include<algorithm>
#include<functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include<deque>
#include<climits>
#include<typeinfo>
#include<utility>
#define LEN 100005
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;
double pi() { return 3.14; }
int sum(int a, int b) { return a + b; }
int mul(int a, int b) { return a * b; }
ll LGCD(ll x, ll y) { if (x % y == 0) return y;else return LGCD(y, x % y); }
ll LLCM(ll x, ll y) { return x * y / LGCD(x, y); }

int GCD(int x, int y) { if (x % y == 0) return y;else return GCD(y, x % y); }
int LCM(int x, int y) { return x * y / GCD(x, y); }
ll dpc[10000][10000];

//void nCr(ll n, ll r) {
//	ll ans = 1;
//	for (int i = n; i > n - r; --i) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1; ++i) {
//		ans = ans / i;
//	}
//	printf("%d",ans);
//}

ll combination(ll n, ll r) {
	if (n == r) { return dpc[n][n] = 1; }
	else if (r == 0) { return dpc[n][0] = 1; }
	else if (r == 1) { return dpc[n][1] = n; }
	else if (dpc[n][r]) { return dpc[n][r]; }
	else { return dpc[n][r] = combination(n - 1, r - 1) + combination(n - 1, r); }
}

//cout << fixed << setprecision(10);


int main() {

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


	

	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const ll MOD = 1000000007;
ll modpow (ll radix,ll index){
    if(index == 0)return 1;
    if(index == 1)return radix%MOD;
    ll c;
    c = modpow(radix,index/2);
    c = c * c % MOD;
    if(index % 2){
        return c * radix % MOD;
    }else{
        return c;
    }
}
int main(){
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll N,ans=0;
    cin >> N;
    vector<ll>A(N);
    REP(i,N){
        cin>>A[i];
        (ans+=modpow(A[i],MOD-2))%=MOD;
    }
    for(int i = 2; i*i <= 1e6;i++){
        int cnt = 0;
        for(int j=0;j<N;j++){
            int now=0;
            while(A[j]%i==0){
                now++;
                A[j]/=i;
            }
            if(cnt < now)cnt = now;
        }
        (ans*=modpow(i,cnt))%=MOD;
    }
    REP(i,N){
        if(A[i]>1){
            REP2(j,i+1,N){
                if(A[i]==A[j])A[j]=1;
            }
            (ans*=A[i])%=MOD;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
string s;
bool two;
ll ans;
vector<string> he;
//ll a[200005];

//ll const BAD = 1e9+7;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> s;
	n = s.length();
	string z = to_string(s[0]);
	he.push_back(z);
	for (ll i = 1; i < n; i++){
		string x = to_string(s[i]);
		if(x == he[he.size()-1]){
			if (i == n-1){
				cout << he.size();
				return 0;
				}
			string a = to_string(s[i]);
			string b = to_string(s[i+1]);
			string c = a+b;
			he.push_back(c);
			i += 1;			}
		else{
			he.push_back(x);
			
			}
		}
		
			cout << he.size();
}

Measured memory_bytes: 11016
my ($n, $m) = split(/\s+/, <>);
my (@h) = (0, split(/\s+/, <>));
my (@op);
for (1..$n) { $op[$_] = []; }

for (1..$m) {
    my ($a, $b) = split(/\s+/, <>);
    push @{$op[$a]}, $b;
    push @{$op[$b]}, $a;
}

sub is_top {
    my ($i) = @_;
    my $is_top = 1;
    #print "i=$i, ", @{$op[$i]}, "\n";
    for (@{$op[$i]}) {
	#print "$_,";
	$is_top = 0 if ($h[$i] <= $h[$_]);
    }
    #print "\n";
    return $is_top;
}

my $num = 0;
for my $i (1..$n) {
    $num++ if is_top($i);
}
print $num, "\n";


Measured memory_bytes: 47392
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

// サイズ可変mod
class mod{
    public:
    ll N, M;
    vector<ll>fact;
    vector<ll>inv;
    vector<ll>finv;

    ll m_plus(ll a, ll b){return (a + b) % M;}
    ll m_minus(ll a, ll b){return (a + M - b) % M;}
    ll m_times(ll a, ll b){return (a * b) % M;}
    ll m_pow(ll a, ll b){
        ll ret = 1;
        while(b > 0){
            if(b & 1)(ret *= a) %= MOD;
            (a *= a) %= MOD;
            b >>= 1;
        }
        return ret;
    }

    void update(ll n){
        if(N > n)return;
        for(ll i = N; i <= n; i++){
            fact.push_back(m_times(fact[i - 1], i));
            inv.push_back(m_pow(i, M - 2));
            finv.push_back(m_times(finv[i - 1], inv[i]));
        }
        N = n + 1;
    }

    // 除算
    ll m_divs(ll a, ll b){
        if(N <= b)update(b);
        return m_times(a, inv[b]);
    }

    // N種の要素を並び替えてできる通りの数
    ll m_fact(ll a){
        if(N <= a)update(a);
        return fact[a];
    }

    // 階乗で割る
    ll m_finv(ll a){
        if(N <= a)update(a);
        return finv[a];
    }

    // N種の要素からk個取り出して並べる通りの数
    ll m_nPk(ll n, ll k){
        return m_times(m_fact(n), m_finv(n - k));
    }
    // N種の要素からk個を選ぶ通りの数
    // a個の赤い玉とb個の青い球を並び替える通りは(a+b)C(a)
    ll m_nCk(ll n, ll k){
        return m_times(m_nPk(n, k), m_finv(k));
    }
    // N種の要素からk個を選ぶ通りの数(重複して良い)
    ll m_nHk(ll n, ll k){
        return m_nCk(n + k - 1, k);
    }
    
    mod(ll m = MOD){
        M = m;
        N = 1;
        fact = vector<ll>(1, 1);
        inv = vector<ll>(1, 1);
        finv = vector<ll>(1, 1);
    }
};
mod m;

int main(){

    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    ll pa = m.m_divs(A, A + B);
    ll pb = m.m_divs(B, A + B);
    ll ans = 0;
    rep(i, N){
        ll a = (m.m_nCk(N + i - 1, i) * m.m_times(m.m_pow(pa, N), m.m_pow(pb, i))) % MOD;
        ll b = (m.m_nCk(N + i - 1, i) * m.m_times(m.m_pow(pa, i), m.m_pow(pb, N))) % MOD;
        ans = (ans + ((m.m_plus(a, b) * (N + i)) % MOD)) % MOD;
    }
    ans = (ans * 100) % MOD;
    ans = m.m_divs(ans, A + B);
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 5204
S = input()
T = input()
q = int(input())
L = [[int(l) for l in input().split()] for _ in range(q)]

sumS = [0]*(len(S)+1)
sumT = [0]*(len(T)+1)

for i in range(len(S)):
    if S[i] == "A":
        sumS[i+1] += 1
    sumS[i+1] += sumS[i]

for i in range(len(T)):
    if T[i] == "A":
        sumT[i+1] += 1
    sumT[i+1] += sumT[i]

for i in range(q):
    a = (sumT[L[i][3]]-sumT[L[i][2]-1]) - (sumS[L[i][1]]-sumS[L[i][0]-1])
    b = (L[i][3]-L[i][2]+1) - (L[i][1]-L[i][0]+1) - a
    if (a-b)%3 == 0:
        print("YES")
    else:
        print("NO")

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N+2,0),L(N+2,0),R(N+2,0);
    for(int i=1;i<=N;i++) cin >> A[i];
    for(int i=1;i<=N;i++) L[i] = max(A[i],L[i-1]);
    for(int i=N;i>=1;i--) R[i] = max(A[i],R[i+1]);
    for(int i=1;i<=N;i++) cout << max(L[i-1],R[i+1]) << endl;   
}

Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(ll i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;

const long long TIME_LIMIT=10000;

ll scorecalc(vector<vector<ll>> a, vector<ll> los, ll d, vector<ll> an)
{
    ll ans = 0;
    
    vector<ll> last(los.size(), 0);
    for (int i = 0; i < an.size(); i++)
    {
        ll loss = 0;
        for (int j = 0; j < 26; j++)
        {
            if (j == an[i] - 1)
                continue;

            loss += los[j] * (i+1LL - last[j]);
        }
        ans += a[i][an[i] - 1] - loss;
        last[an[i] - 1] = i + 1LL;
    }

    return ans;
}

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

    ll d;
    cin >> d;
    vector<ll> c(26);
    rep(i, 26)
    {
        cin >> c[i];
    }
    vector<vector<ll>> s(d, vector<ll>(26));
    rep(i, d)
    {
        rep(j, 26)
            cin >> s[i][j];
    }

    vector<ll> ans(d);

    vector<ll> last(26, 0);

    for (ll i = 0; i < d; i++)
    {
        ll lost = 0;
        for (int j = 0; j < 26; j++)
        {
            lost += c[j] * (i + 1 - last[j]);
        }
        ll man = s[i][0] - lost + c[0] * (i + 1 - last[0]);
        ll manu = 1;
        for (int j = 0; j < 26; j++)
        {
            if (man <= s[i][j] - lost + c[j] * (i + 1 - last[j]))
            {
                man = s[i][j] - lost + c[j] * (i + 1 - last[j]);
                manu = j + 1LL;
                last[j] = i + 1;
            }
        }
        ans[i] = manu;
    }
    ll score = scorecalc(s, c, d, ans);
    ll times = 0;
    while (times < 70000)
    {
        ll tmpD = (ll)rand() % d;
        ll tmpN = ans[tmpD];
        ans[tmpD] = (ll)rand() % 26 + 1;

        if (score >= scorecalc(s, c, d, ans))
            ans[tmpD] = tmpN;
        else
            score = scorecalc(s, c, d, ans);

        times++;
    }

    rep(i, d)
    {
        cout << ans[i] << endl;
    }

	return 0;

}

Measured memory_bytes: 3860
# 1行目の入力を空白で分割された数値として扱う
K, N = map(int, input().split())
# 2行目の入力を数値のリストとして扱う
A = list(map(int, input().split()))

# 答えの準備
ans = 0
max = 0

# 距離の取得
for i in range(0, N -1):
    d = A[i+1] - A[i]
    ans += d
    if d > max:
        max = d

# 一周した最後
dl = K - A[N - 1]
if dl + A[0] < max:
    ans = ans - max + dl + A[0]

# 出力
print(ans)


Measured memory_bytes: 26420
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
	static final Pattern pt = Pattern.compile("0?(\\d+):0?(\\d+):0?(\\d+)");
	static final Matcher mc = pt.matcher("");
	private static Comparator<Train> insort = new Comparator<Train>() {
		@Override
		public int compare(Train o1, Train o2) {
			return o1.t2 - o2.t2;
		}
	};
	private static final Comparator<Train> outsort = new Comparator<Train>() {
		@Override
		public int compare(Train o1, Train o2) {
			return o1.t1 - o2.t1;
		}
	};

	public static void main(String[] arg) {
		final Scanner in = new Scanner(System.in);
		int n;
		while ((n = in.nextInt()) != 0) {
			Train[] trains = new Train[n];
			for (int i = 0; i < n; i++) {
				trains[i] = new Train(getTime(in), getTime(in));
			}
			Arrays.sort(trains, outsort);
			int time = 0;
			int stock = 0;
			int count = 0;
			LinkedList<Train> moveset = new LinkedList<Train>();
			for (Train t : trains) {
				time = t.t1;
				while (!moveset.isEmpty() && moveset.getFirst().t2 <= time) {
					stock++;
					moveset.removeFirst();
				}
				if (stock == 0) {
					stock++;
					count++;
				}
				moveset.add(t);
				Collections.sort(moveset, insort);
				stock--;
			}
			System.out.println(count);

		}
		in.close();
	}

	private static int getTime(Scanner in) {
		int time;
		mc.reset(in.next());
		mc.matches();
		time = Integer.parseInt(mc.group(3));
		time += Integer.parseInt(mc.group(2)) * 60;
		time += Integer.parseInt(mc.group(1)) * 3600;
		return time;
	}
}

class Train {
	final int t1, t2;

	Train(int t1, int t2) {
		this.t1 = t1;
		this.t2 = t2;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + t1;
		result = prime * result + t2;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		Train other = (Train) obj;
		return (t1 != other.t1) && (t2 != other.t2);
	}
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

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

    int N, M;
    cin >> N >> M;
    vector<string> A, B;
    rep(i, N) {
        string S; cin >> S;
        A.push_back(S);
    }
    rep(i, M) {
        string S; cin >> S;
        B.push_back(S);
    }

    rep(ay, N-M+1) rep(ax, N-M+1) {
        bool ok = true;
        rep(by, M) rep(bx, M) {
            ok &= (A[ay+by][ax+bx] == B[by][bx]);
        }
        if (ok) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}



Measured memory_bytes: 256
#逆転させなきゃ
n,m = map(int, input().split())
cond = []
for i in range(m):
  temp = input().split()
  cond.append([int(i) for i in temp])
p = [int(i) for i in input().split()]

ans = 0
for i in range(2**n): #全状態を調べる
  flag = True
  temp = bin(i)
  sw = [str(l) for l in temp]
  sw.reverse()
  flag = True
  for j in range(m): #電球を１つずつ調べる
    if flag:
      c = 0 #スイッチのonの数
      for k in range(1,len(temp)-1): #指定のスイッチか
        if cond[j][1:].count(k)==1:
          c += int(sw[k-1])
      if c%2 != p[j]: #もし条件を満たさない電球があったら」
        flag = False
      elif c%2 == p[j] and j==m-1: #最後まで条件を満たしたら
        ans += 1
        
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;
const ll LINF=1e12;

int main(){
    int n,m,p;
    cin>>n>>m>>p;
    pair<pair<int,int>,ll> e[m];
    for(int i=0;i<m;i++){
        int a,b,c;
        cin>>a>>b>>c;
        e[i]={{a-1,b-1},p-c};
    }
    ll d[n];
    fill(d,d+n,LINF);
    d[0]=0;
    bool ng=false;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            int from=e[j].first.first;
            int to=e[j].first.second;
            ll cost=e[j].second;
            if(d[from]!=LINF&&d[to]>d[from]+cost){
                if(i==n-1){
                    ng=true;
                    d[to]=-LINF;
                    break;
                }
                d[to]=d[from]+cost;
            }
        }
    }
    if(ng){
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int from=e[j].first.first;
                int to=e[j].first.second;
                int cost=e[j].second;
                if(d[from]!=LINF&&d[to]>d[from]+cost){
                    d[to]=d[from]+cost;
                }
            }
        }
    }
    ll ans;
    if(-d[n-1]>1e10)ans=-1;
    else ans=max(0LL,-d[n-1]);
    cout<<ans<<endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for(int i=1; i<=a*b; i++) {
            if(a*i%b == c) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}

Measured memory_bytes: 21972
use text_io::*;
use std::collections::*;
use std::process::exit;

fn main() {
    let mut n:usize = read!();
    let mut k:usize = read!();
    let mut v:Vec<usize> = Vec::new();
    for i in 0..n {
        let a:usize = read!();
        v.push(a);
    }
    v.sort();
    // v.reverse();
    let mut g:usize = 0;
    if n<=k {
        println!("0");
        exit(0);
    }
    for i in 0..n-k {
        g += v[i];
    }
    println!("{}",g);
}

Measured memory_bytes: 4236
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007LL
#define INF (1LL<<60LL)
typedef long long ll;

using namespace std;


int main() {
	string s1, s2, s3; cin >> s1 >> s2 >> s3;
	cout << s1[0] << s2[0] << s3[0] << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# 入力を各変数に格納
n, m = map(int, input().split())

ans = 0

# 行列ともに1
if n == 1 and m == 1:
    ans = 1
# 行が1
elif n == 1:
    ans = m - 2
# 列が1
elif m == 1:
    ans = n - 2
# 行列とも1ではない
else:
    ans = (n - 2) * (m - 2)

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <list>
using namespace std;
using ll=long long;
const ll MAX=3e2+5,mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
#define X first
#define Y second
#define pb push_back

typedef pair < int , int > ii;
int n;
ll a[30];
ll solve(int l,int r,int p1,int p2){
    if(l+1==r) return 0;
    ll temp=inf;
    for(int i=l+1;i<r;i++) {
        temp=min(temp,solve(l,i,p1,p1+p2)+solve(i,r,p1+p2,p2)+a[i]*(p1+p2));
    }
    return temp;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("agc046.inp","r",stdin);
    //freopen("agc046.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<solve(1,n,1,1)+a[1]+a[n];
}


Measured memory_bytes: 3624
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_Node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#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 {
#ifdef LOCAL
~debug() { cerr << endl; }
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
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define maxn 100001
ll mark[maxn];
void init()
{
    for(int i=0;i<maxn;i++)
    {
        mark[i]=i;
    }
}
ll find(ll x)
{
    if(x!=mark[x])
    {
        return mark[x]=find(mark[x]);
    }
    return x;
}
void Union(ll x,ll y)
{
    ll val=find(x),val1=find(y);
    mark[val]=val1;
}
int main()
{
    fastIO;
    init();
    ll n,m;
    cin>>n>>m;
    pair<ll,ll>p[m];
    for(int i=0;i<m;i++)
    {
        cin>>p[i].fi>>p[i].se;
        Union(p[i].fi,p[i].se);
    }
    map<ll,ll>mp;
    for(int i=1;i<=n;i++)
    {
        mp[find(i)]++;
    }
    cout<<mp.size()-1<<endl;
}

Measured memory_bytes: 9680
#include<iostream>
#include<cstdio>
#define N 2010
using namespace std;

int n,m,Q,qz[N][N],ha[N][N],lie[N][N];
bool mm[N][N];
char str[N];

int main()
{
	int i,j,a,b,c,d;
	cin>>m>>n>>Q;
	for(i=1;i<=m;i++)
	{
		scanf("%s",str+1);
		for(j=1;j<=n;j++)
		{
			mm[i][j]=(str[j]=='1');
		}
		for(j=1;j<n;j++) if(mm[i][j]==mm[i][j+1]&&mm[i][j]) ha[i][j]=1;
		if(i>=2)
			for(j=1;j<=n;j++) if(mm[i][j]==mm[i-1][j]&&mm[i][j]) lie[i-1][j]=1;
	}
//	for(i=1;i<=m;i++){for(j=1;j<=n;j++) cout<<lie[i][j]<<" ";puts("");}return 0;
	for(i=1;i<=m;i++)
	{
		for(j=1;j<=n;j++)
		{
			qz[i][j]=qz[i-1][j]+qz[i][j-1]-qz[i-1][j-1]+mm[i][j];
			ha[i][j]+=ha[i-1][j]+ha[i][j-1]-ha[i-1][j-1];
			lie[i][j]+=lie[i-1][j]+lie[i][j-1]-lie[i-1][j-1];
		}
	}
	for(i=1;i<=Q;i++)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		printf("%d\n",
		qz[c][d]-qz[c][b-1]-qz[a-1][d]+qz[a-1][b-1]-
		(ha[c][d-1]-ha[c][b-1]-ha[a-1][d-1]+ha[a-1][b-1])-
		(lie[c-1][d]-lie[c-1][b-1]-lie[a-1][d]+lie[a-1][b-1])
		);
	}
}

Measured memory_bytes: 52992
using System;
using System.Linq;

namespace Ex160424_1{
    public class Program{
        public static void Main(string[] args){
            Console.ReadLine();
            var seq = Console.ReadLine().Split().Reverse().ToArray();

            Console.Write(seq[0]);
            for(var i = 1; i < seq.Length; i++){
                Console.Write(" " + seq[i]);
            }
            Console.WriteLine();
        }
    }
}

Measured memory_bytes: 9076
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << ", ";
#define ll long long
#define pb push_back
using namespace std;
#define FAST_IO                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
const int INF = 1e9 + 7;

int main()
{
    FAST_IO
    int n;
    cin >> n;
    vector<int> v(n);
    for (int &a : v)
    {
        cin >> a;
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    dp[1] = abs(v[1] - v[0]);
    for (int i = 2; i < n; i++)
    {
        dp[i] = min(dp[i], min (dp[i-2]+ abs(v[i]-v[i-2]) ,(dp[i-1] + abs(v[i]- v[i-1]))));
    }
    cout << dp[n-1] << endl;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

map<string,int> M;
int N;
int i;
string s;

int atm(){
  string name;
  if(i+1<N&&islower(s[i+1])){
    name=s.substr(i,2);
    i+=2;
  }else{
    name=s.substr(i,1);
    i++;
  }
  if(M.count(name))return M[name];
  else return -1;
}

int mol(){
  int res=0;
  while(i<N&&s[i]!=')'){
    if(s[i]=='('){
      i++;
      int add=mol();
      if(add==-1)return -1;
      int num=0;
      while(i<N&&isdigit(s[i])){
        num*=10; num+=s[i]-'0';
        i++;
      }
      res+=add*num;
    }else if(isupper(s[i])){
      int add=atm();
      if(add==-1)return -1;
      if(i<N&&isdigit(s[i])){
        int num=0;
        while(i<N&&isdigit(s[i])){
          num*=10; num+=s[i]-'0';
          i++;
        }
        res+=add*num;
      }else{
        res+=add;
      }
    }else{
      assert(0);
    }
  }
  if(i<N&&s[i]==')')i++;
  return res;
}

int main(){
  while(1){
    cin>>s;
    if(s=="END_OF_FIRST_PART")break;
    int m;
    cin>>m;
    M[s]=m;
  }
  while(1){
    cin>>s;
    if(s=="0")break;
    N=s.size();
    i=0;
    int res=mol();
    if(res==-1)cout<<"UNKNOWN"<<endl;
    else cout<<res<<endl;
  }
  return 0;
}



Measured memory_bytes: 3168
#include<iostream>
using namespace std;
int main() {
	int p[5];
	int a = 0, b = 0;
	for (int i = 0; i < 5; ++i) {
		cin >> p[i];
		if (p[i] < 40) {
			p[i] = 40;
		}
		a = a + p[i];
	}
	b = a / 5;
	cout << b << endl;
	return 0;
}

Measured memory_bytes: 1160
n = int(input())
a = list(map(int,input().split()))
a.sort()
largest = a[-1]
aim = largest // 2
index = 0
for i in range(n):
    if a[i] >= aim:
        index = i
        break
if a[index] - aim <= aim - a[index-1] and index < n-1 :
    ans = a[index]
else:
    ans = a[index-1]
print(str(largest) + " " + str(ans))

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

using namespace std;
#define NIL -1
#define ll long long
#define MAX 100
#define pb push_back

int main()
{
	int n, k;
	cin >> n >> k;
	ll ans = 0;
	int arr[n];
	for(int i=0; i<n; i++) cin >> arr[i];
	for(int i=0; i<n; i++) {
		int temp = min(arr[i], k-arr[i]);
		ans += temp;
	}
	cout << ans *2 << endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  vector<pl> v;
  ll x,y;
  rep(i,n){
    cin>>x>>y;
    v.pb(mp(x,y));
  }
  v.pb(mp(INF,0));
  sort(all(v));
  ll ans=0;
  rep(i,n+1){
    // 間にいるはずのやつ　と 入れる数．
    if(i==0){
      ans+=v[i].fi;
    }else{
      ans++;
      ans+=min((v[i].fi-v[i-1].fi-1),(v[i-1].se-v[i].se));
    }
  }
  ans--;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2420
#include<stdio.h>
#define N 45
void makeFibonacci(int);

int main(){
  int n;
  scanf("%d",&n);
  makeFibonacci(n);
  return 0;
}

void makeFibonacci(n){
  int i,F[N];
  F[0] = 1;
  F[1] = 1;
  for(i = 2; i < N; i++)
    F[i] = F[i-2] + F[i-1];
  printf("%d\n",F[n]);
}

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

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define LL long long
#define MAXN 2000
int L[MAXN+5];

int main(){
    int N=read();
    for(int i=1;i<=N;i++)
        L[i]=read();
    sort(L+1,L+N+1);
    int Ans=0;
    for(int i=1;i<=N;i++){
        for(int j=i+1;j<=N;j++){
            int Max=L[i]+L[j],Min=L[j]-L[i];
            int Begin=upper_bound(L+1,L+i+1,Min)-L;
            int End=lower_bound(L+1,L+i+1,Max)-L-1;
            Begin=max(Begin,1),End=min(End,i-1);
            Ans+=max(End-Begin+1,0);
        }
    }
    printf("%d",Ans);
}


Measured memory_bytes: 256
s = STDIN.gets.split
stack = Array.new(100)
sp=0
for x in s do
  if x == "+" then
    stack[sp-2]=stack[sp-1]+stack[sp-2]
    sp -= 1
  elsif x == "-" then
    stack[sp-2]=stack[sp-2]-stack[sp-1]
    sp -= 1
  elsif x == "*" then
    stack[sp-2]=stack[sp-1]*stack[sp-2]
    sp -= 1
  else
    stack[sp]=x.to_i
    sp += 1
  end

  #0.upto(sp-1) {|i| printf("%d|", stack[i])}
  #printf("\n")

end
puts stack[0]

Measured memory_bytes: 8712
///
// File:  2619.cpp
// Author: ymiyamoto
//
// Created on Sat Dec  2 21:02:56 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

struct tree_t {
  string str;
  vector<uint32_t> children;
};

void preorder(vector<tree_t> tree, uint32_t i, uint32_t depth)
{
  cout << string(depth, '.') << tree[i].str << endl;
  for (uint32_t j = 0; j < tree[i].children.size(); j++) {
    preorder(tree, tree[i].children[j], depth + 1);
  }
}

int32_t main()
{
  uint32_t N;
  cin >> N;

  vector<tree_t> tree(N + 1);

  for (uint32_t i = 1; i <= N; i++) {
    uint32_t n;
    string str;
    cin >> n >> str;
    tree[i].str = str;
    tree[n].children.push_back(i);
  }

  preorder(tree, 1, 0);

  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<string> words(N);
    for (int i = 0; i < N; i++) {
        cin >> words.at(i);
    }
    // 語尾と語頭の確認
    string ans = "Yes";
    for (int i = 0; i < N-1; i++) {
        int end = words.at(i).size() - 1;
        char ending = words.at(i).at(end);
        char bignning = words.at(i+1).at(0);
        if (ending != bignning) {
             ans = "No";
        }
    }
    // 同じワードが含まれるか確認
    for (int i = 0; i < N; i++) {
        string judge = words.at(i);
        for (int j = i+1; j < N; j++) {
            if (judge == words.at(j)) {
                ans = "No";
            }
        }
    }
    cout << ans << endl;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define Rep(i,n) for(int i = 1; i <= n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
template<class T> using V = vector<T>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }


struct UnionFind { // UnionFindTree
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int find(int x) {
    if(d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return false;
    if(-d[x] < -d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y); }
  int size(int x) { return -d[find(x)]; }
};


int main(){
    
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n) {
        chmax(ans, uf.size(i));
    }
    cout << ans << endl;
}

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

using namespace std;

const int MAXN=100005;
long long a[MAXN];

int main()
{
    int n;
    cin >> n;
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    long long m=0,k=0;
    for(int i=0;i<n-1;i++)
    {
        if(a[i]==a[i+1])
        {
            if(m<=a[i]) {k=m; m=a[i];i=i+1;}
        }
    }
    printf("%lld\n",m*k);
}


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

int main(){
	int n;
	cin>>n;
	vector<int> v(n);
	rep(i,n)cin>>v[i];
	
	bool dp[850][850]={};
	dp[0][0]=true;
	
	rep(i,n){
		for(int j=849;j>=0;j--){
			for(int k=849;k>=0;k--){
				if(j+v[i]<850) dp[j+v[i]][k] |= dp[j][k];
				if(k+v[i]<850) dp[j][k+v[i]] |= dp[j][k];
			}
		}
	}
	
	
	int sum=0;
	rep(i,n)sum+=v[i];
	
	int ans = 10000;
	rep(i,850){
		rep(j,850){
			if(dp[i][j]) ans = min( ans,max( i,max(j,sum-(i+j)) ) );
		}
	}
	cout<<ans<<endl;
}

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

string s[100];
int main(){
	int h,w;scanf("%d%d",&h,&w);
	rep(i,h)cin>>s[i];
	rep(i,h)rep(j,w){
		if(s[i][j]=='#')continue;
		s[i][j]='0';
		for(int dx=-1;dx<=1;dx++){
			for(int dy=-1;dy<=1;dy++){
				int nx=i+dx,ny=j+dy;
				if(0<=nx&&nx<h&&0<=ny&&ny<w){
					if(s[nx][ny]=='#')s[i][j]++;
				}
			}
		}
	}
	rep(i,h)cout<<s[i]<<endl;
}

Measured memory_bytes: 256
iN = int(input())
aS = [int(x) for x in input().rstrip().split()]

#はぁ こんなのを一発で通れるようなものも書けないのか.. つらい

#つけたしつけたしで条件追加しててやっててつらい



iCounter = 0
if iN == 2:
    if aS[0] == aS[1]:
        iCounter += 1
else:
    for i in range(1,iN-1):
        if aS[i] == aS[i-1]:
            if aS[i] == aS[i+1]:
                if aS[i] < 10000:
                    aS[i] += 1
                else:
                    aS[i] -= 1
                iCounter += 1
            else:
                iU = max(aS[i],aS[i+1])
                if iU < 10000:
                    iU += 1
                else:
                    iU -= 1
                    if iU == min(aS[1],aS[i+1]):
                        iU -= 1
                aS[i] = iU
                iCounter += 1
    if aS[iN-2] == aS[iN-1] :
        iCounter += 1
print(iCounter)


Measured memory_bytes: 3188
import math
from functools import reduce
import fractions
#import math
#import itertools
#import statistics
#import numpy as np
#import collections
#n = int(input())
n, k  = list(map(int, input().split()))
x = list(map(int, input().split()))
x.append(k)
x.sort()

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

dif = []
for i in range(n):
    dif.append(x[i+1]-x[i])

ans = gcd_list(dif)
print(ans)

Measured memory_bytes: 16312