akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    int n;
    cin >> n;
    bool ok = 0;
    for (int i = 1; i < 10; ++i)
    {
        for (int j = 1; j < 10; ++j)
        {
            if (i * j == n)
            {
                ok = 1;
                break;
            }
        }
    }
    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3628
list = input().split()
N = int(list[0])
M = int(list[1])
X = int(list[2])
A = input().split()
A = [int(i) for i in A]

cnt_left,cnt_right = 0,0
for i in range(X,N+1):
    for j in A:
        if j == i:
            cnt_right += 1
for i in range(0,X):
    for j in A:
        if j == i:
            cnt_left += 1
print(min(cnt_left,cnt_right))

Measured memory_bytes: 3064
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
signed main(){
  init_io();
  ll n,ans=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      for(int k=0;k<10;k++){
        ll idx = 0,a[]={i,j,k};
        for(int l=0;l<n;l++){
          if(idx!=3 && a[idx] == (s[l]-'0')){
            idx++;
          }
        }
        if(idx == 3) ans++;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>

using namespace std;
typedef long long int ll;


bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}
// use case
//sort(V.begin(), V.end(), compare_function);

void solve(string s, string t) {
int n=s.length();
if (t.length()!=n+1) {cout<<"No"<<endl; return;}
for (int i=0;i<n;i++) {
if (s[i]!=t[i]) {cout<<"No"<<endl; return;}
}
cout<<"Yes"<<endl; return;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s,t;
    cin>>s;
    cin>>t;
    solve(s,t);
    return 0;
}


Measured memory_bytes: 3616
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		double[] ar = new double[10];
		
		while (sc.hasNext()) {
			ar[0] = sc.nextDouble();
			double total = ar[0];
			for (int i=1; i<=9; i++) {
				if (i%2==1) {
					ar[i] = ar[i-1]*2;
				}
				else {
					ar[i] = ar[i-1]/3;
				}
				total += ar[i];
			}
			out.println(total);
		}
	}
}


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

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい]
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

int main() {
	int N, M;
	cin >> N >> M;
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++)
	{
		cin >> A[i] >> B[i];
		A[i]--;
		B[i]--;
	}

	vector<long long> ans(M);
	ans[M - 1] = (long long)N * (N - 1) / 2;

	UnionFind Uni(N);

	for (int i = M - 1; i >= 1; i--)
	{
		ans[i - 1] = ans[i];

		//繋がってなかったのが繋がった時
		if (Uni.root(A[i]) != Uni.root(B[i])) {
			ans[i - 1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
			Uni.connect(A[i], B[i]);
		}
	}

	for (int i = 0; i < M; i++)
	{
		cout << ans[i] << endl;
	}
}


Measured memory_bytes: 3328
#include <cstdio>


int n,d;
int num[10]={0x3F,0x6,0x5B,0x4F,0x66,0x6D,0x7D,0x27,0x7F,0x6F};

void p(int st){
	for(int i = 6; i >= 0; i--){
		if((st&(1 << i)) !=0){
			printf("1");
		}
		else{
			printf("0");
		}
	}
	printf("\n");
}

int main(){
	while(scanf("%d",&n),n != -1){
		int st = 0;
		for(int i = 0; i < n; i++){
			scanf("%d",&d);
			st ^= num[d];
			p(st);
			st = num[d];
		}

	}

	return 0;
}

Measured memory_bytes: 2496
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int N,ans=0,cnt=0;
  string S;
  cin>>S;
  N=S.length();
  for(int i=0;i<N;i++){
    if(S[i]=='0'){
      cnt++;
    }
  }
  cout<<min(cnt,N-cnt)*2<<endl;
}


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

const int N = 1e5 + 5;
int n;

int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    ll a,b;
    cin >> a >> b;
    if(abs(a-b)&1){
        cout << "IMPOSSIBLE" << "\n";
    }else{
        cout<< (a+b)/2 << endl;
    }
    
    
    
    return 0;
} 


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> vs(n);
    for (auto& v : vs)
    {
        cin >> v;
    }
    sort(vs.begin(), vs.end(), greater<>());
    vs[0] /= 2;

    int sum = 0;
    for (auto v : vs)
    {
        sum += v;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
// Problem : F - Tree and Constraints
// Contest : AtCoder - AtCoder Beginner Contest 152
// URL : https://atcoder.jp/contests/abc152/tasks/abc152_f
// Memory Limit : 1024 MB
// Time Limit : 4000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 52

int n, tin[N], tout[N], up[N][25], timer, l, m, a[N];
vi g[N];
vii p;
//call dfs(root,root)

void dfs(int u, int par){
    tin[u] = ++timer;
    up[u][0] = par;
    for(int i=1;i<=l;i++) up[u][i] = up[up[u][i-1]][i-1];
    for(auto i : g[u]){
        int v = i;
        if(v != par) dfs(v,u);
    }
    tout[u] = ++timer;
}

bool ancestor(int u, int v){
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int lca(int u, int v){
    if(ancestor(u,v)) return u;
    if(ancestor(v,u)) return v;
    for(int i=l;i>=0;i--){
        if(!ancestor(up[u][i],v)) u = up[u][i];
    }
    return up[u][0];
}

int dfs2(int u, int par){
    int ret = 0;
    for(int i : g[u]){
        if(i == par) continue;
        ret += dfs2(i,u);
        a[u] += a[i];
    }
    ret += (a[u] > 0 ? 1 : 0);
    return ret;
}

//Solution

void solve(){
    cin>>n;
    l = ceil(log2(n));
    for(int i=0;i<n-1;i++){
        int u,v; cin>>u>>v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1,1);
    cin>>m;
    p.resize(m);
    for(int i=0;i<m;i++) cin>>p[i].fi>>p[i].se;
    int ans = 0;
    for(int mask=0;mask<(1<<m);mask++){
        memset(a,0,sizeof(a));
        int cnt = 0;
        for(int i=0;i<m;i++){
            if((mask>>i)&1){
                int u = p[i].fi, v = p[i].se;
                a[u]++;
                a[v]++;
                a[lca(u,v)] -= 2;
                cnt++;
            }
        }
        int c = dfs2(1,0);
        int term = (1LL<<(n-c-1));
        ans = ans+(cnt%2 ? -term : term);
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3868
def GCD(n, m):
    if n % m == 0:
        return m
    else:
        return GCD(m, n % m)

def PF(n):
    pfArray = []
    i = 2
    while (i * i <= n):
        if n % i == 0:
            pfArray.append(i)
            j = 1
            while (n % (i ** j) == 0):
                n = n / (i ** j)
        i += 1
    if n != 1:
        pfArray.append(int(n))
    return pfArray

N_i = list(map(int, input().split(" ")))
A = max(N_i)
B = min(N_i)
print(len(PF(GCD(A, B)))+1)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void){
  int N;
  scanf("%d", &N);

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

  for (int i = 1; i < N; i++) {
    if(H[i-1] < H[i]) H[i]--;
    if(H[i-1] > H[i]){
      printf("No\n");
      return 0;
    }
  }

  printf("Yes\n");

  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);

    int odd = 0;
    rep(i, n) {
        cin >> a[i];
        if (a[i]%2) odd++;
    }

    cout << (odd > 0 ? "first" : "second") << endl;
}


Measured memory_bytes: 640
#include<stdio.h>

int main(){

  int a,b,c,d,e,f,data[6];
  double x, y, sum;

  while( scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f) != EOF ){

    data[0] = a * d;
    data[1] = b * d;
    data[2] = c * d;
    data[3] = d * a;
    data[4] = e * a;
    data[5] = f * a;

    y = data[1] - data[4];
    sum = data[2] - data[5];
    y = sum / y;
    x = (c - b * y) / a;

    printf("%.3f %.3f\n",x,y);

  }

  return 0;
}

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


int main(){

  int H,R;
  cin>>H>>R;

 if(H+R == 0) cout<<0<<endl;
 if(H+R > 0) cout<<1<<endl;
 if(H+R < 0) cout<<-1<<endl;

 return 0;
}


Measured memory_bytes: 3100
from pprint import pprint
N = int(input())
reds = []
for i in range(N):
    reds.append(tuple(map(int, input().split(" "))))
blues = []
for i in range(N):
    blues.append(tuple(map(int, input().split(" "))))
reds.sort(key=lambda x: (x[1], x[0]), reverse=True)
blues.sort()
picked = [False for _ in range(N)]
ans = 0
for blue in blues:
    for i, red in enumerate(reds):
        if blue[0] > red[0] and blue[1] > red[1] and not picked[i]:
            ans += 1
            picked[i] = True
            break
print(ans)

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    if(y%2!=0 || y<2*x || y>4*x )
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;


    }
}



Measured memory_bytes: 3496
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;



int main(){
    ll A, B, K;
    cin >> A >> B >> K;

    if(A >= K){
        cout << A - K << " " << B << endl;
    }else{
        cout << 0 << " " << max(A + B - K, (ll)0) << endl;
    }

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

#define MAX 100000

int n , m , q , from , to;
int rank[MAX] , parent[MAX];

int find(int x){
	
	if(x == parent[x]){
		return x;
	}else{
		return parent[x] = find(parent[x]);
	}
}

void unite(int x,int y){
	
	x = find(x);
	y = find(y);

	if(x == y){
		return;
	}

	if(rank[x] < rank[y]){
		parent[x] = y;
	}else{
		parent[y] = x;
		if(rank[x] == rank[y]){
			rank[x]++;
		}
	}
}

int main(void){

	scanf("%d %d",&n,&m);

	for(int i = 0; i < n; i++){
		rank[i] = 0;
		parent[i] = i;
	}

	for(int i = 0; i < m; i++){
		scanf("%d %d",&from,&to);

		if(find(from)==find(to)){
			continue;
		}
		unite(from,to);
	}

	scanf("%d",&q);

	int left,right;

	for(int i = 0; i < q; i++){
		scanf("%d %d",&left,&right);

		if(find(left)==find(right)){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	return 0;
}



Measured memory_bytes: 2460
N,M=map(int,input().split())
dp=[0]*(2*(10**5)+1)
bp=[0]*(2*(10**5)+1)
for _ in range(M):
  a,b=map(int,input().split())
  if a==1:
    if bp[b]==1:
      print('POSSIBLE')
      exit()
    dp[b]+=1
  if b==N:
    if dp[a]==1:
      print('POSSIBLE')
      exit()
    bp[a]+=1
print('IMPOSSIBLE')

Measured memory_bytes: 11892
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N)]
for i in range(M):
    l, r, d = map(int, input().split())
    G[l - 1].append((r - 1, d))
    G[r - 1].append((l - 1, -d))
q = deque()

x = [None] * N


def _BFS(start):
    q.append(start)
    while len(q) != 0:
        p = q.popleft()
        for index, d in G[p]:
            if x[index] is None:
                x[index] = x[p] + d
                q.append(index)
            elif x[index] != x[p] + d:
                return False
    return True


def BFS():
    for i in range(N):
        if x[i] is None:
            x[i] = 0
            if not _BFS(i):
                return "No"
    return "Yes"


print(BFS())


Measured memory_bytes: 66240
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);in(name)
#define vv(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define VV(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__));in(name)
#define vvv(type,name,h,w,...) vector<vector<vector<type>>>name(h,vector<vector<type>>(w,vector<type>(__VA_ARGS__)))
inline int scan(){ return getchar(); }
inline void scan(int &a){ scanf("%d", &a); }
inline void scan(unsigned &a){ scanf("%u", &a); }
inline void scan(long &a){ scanf("%ld", &a); }
inline void scan(long long &a){ scanf("%lld", &a); }
inline void scan(unsigned long long &a){ scanf("%llu", &a); }
inline void scan(char &a){ cin >> a; }
inline void scan(float &a){ scanf("%f", &a); }
inline void scan(double &a){ scanf("%lf", &a); }
inline void scan(long double &a){ scanf("%Lf", &a); }
inline void scan(vector<bool> &vec){ for(unsigned i = 0; i < vec.size(); i++) { int a; scan(a); vec[i] = a; } }
inline void scan(string &a){ cin >> a; }
template<class T> inline void scan(vector<T> &vec);
template<class T, size_t size> inline void scan(array<T, size> &vec);
template<class T, class L> inline void scan(pair<T, L> &p);
template<class T, size_t size> inline void scan(T (&vec)[size]);
template<class T> inline void scan(vector<T> &vec){ for(auto &i : vec) scan(i); }
template<class T, size_t size> inline void scan(array<T, size> &vec){ for(auto &i : vec) scan(i); }
template<class T, class L> inline void scan(pair<T, L> &p){ scan(p.first); scan(p.second); }
template<class T, size_t size> inline void scan(T (&vec)[size]){ for(auto &i : vec) scan(i); }
template<class T> inline void scan(T &a){ cin>>a; }
inline void in(){}
template <class Head, class... Tail> inline void in(Head &head, Tail&... tail){ scan(head); in(tail...); }
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}
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; }
using Graph = vector<vector<int>>;
/* 4方向への隣接頂点への移動を表すベクトル */
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

const long long INF = 1LL << 60;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    LL(N,A,B,C,D,E);
    ll a = min({A,B,C,D,E});
    cout << 5+( (N+a-1)/a -1) << endl;


}

Measured memory_bytes: 256
n, k = [int(t) for t in input().split()]
w = [int(input()) for i in range(n)]

def canMove(w, P, k):
    s = 0
    for i in range(len(w)):
        if s + w[i] > P:
            s = 0
            k -= 1
            if k <= 0: return False
        s += w[i]
    return True

hi = sum(w)
lo = max(w)

P = hi
while lo < hi:
    m = (lo + hi) // 2
    if canMove(w, m, k):
        P = m
        hi = m
    else:
        lo = m + 1

print(P)



Measured memory_bytes: 9560
#include <bits/stdc++.h>
using namespace std;
int main(void){
    std::deque<int> deq;
    int n,a,q,b1,b2,b3;
    cin >> n;
    for (int i=0;i<n;i++) {
        cin >> a;
        deq.emplace_back(a);
    }
    cin >> q;
    for (int j=0;j<q;j++) {
        cin >> b1 >> b2 >> b3;
        rotate(deq.begin()+b1,deq.begin()+b2,deq.begin()+b3);
    }
    for (int k=0;k<deq.size();k++) {
        if (k==deq.size()-1) {
            cout << deq[k] << endl;
        } else {
            cout << deq[k] << " ";
        }
    }
}



Measured memory_bytes: 3140
#include<stdio.h>

int main(){
	int distance, speed, time;
	scanf("%d %d %d", &distance, &time, &speed);
	if(distance/speed<time)printf("Yes\n");
	else if(distance/speed==time && distance%speed==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 1660
import math
from functools import reduce
N,X=map(int, input().split()) 
x = list(map(int, input().split()))
y=[0]*N
for i in range(N):
    y[i]=abs(x[i]-X)
def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
D=y[0]
for i in range(N):
    D=gcd(y[i],D)        
print(D)

Measured memory_bytes: 20436
n,m=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
D=[0 for i in range(m-1)]
for i in range(m-1):
    D[i]=X[i+1]-X[i]
D.sort()
ans=0
for i in range(m-n):
    ans+=D[i]
print(ans)

Measured memory_bytes: 13968
#include <bits/stdc++.h>
using namespace std;
#define pll pair<ll,ll>
typedef long long ll;
#define mod 1000000007
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define INF 1e15
const int N=2e5+5;
const int LG=21;
		
vector<ll> vis(N,0);
vector<ll> g[100005];
vector<ll> cnt(100005,0);
vector<ll> s_cnt(100005,0);
void dfs(ll s,ll c)
{
	vis[s]=1;
	cnt[s]=c;
	s_cnt[c]++;
	for( auto i:g[s])
	{
		if(!vis[i])
			dfs(i,c);
	}
}				
int main()
{
	ll n,m,k;
	cin>>n>>m>>k;
	for(ll i=0;i<m;i++)
	{
		ll u,v;
		cin>>u>>v;
		g[u].pb(v);
		g[v].pb(u);
	}
	
	ll c=1;
	for(ll i=1;i<=n;i++)
	{
		if(!vis[i])
		{
			dfs(i,c);
			c++;
		}
		
	}
	
	vector<ll> sub(100005,0);
	for(ll i=0;i<k;i++)
	{
		ll u,v;
		cin>>u>>v;
		if(cnt[u]==cnt[v])
			{sub[u]++;sub[v]++;}
		
	}
	for(ll i=1;i<=n;i++)
	{

		cout<<s_cnt[cnt[i]]-(int)g[i].size()-1-sub[i];
		cout<<" ";
	}
							
}


Measured memory_bytes: 11392
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;

int main(void) {
	int n;
	int l[201];
	int x = 0;
	cin >> n;
	FOR(i, 1, 2 * n) {
		cin >> l[i];
	}
	sort(l, l + 2 * n + 1);
	FOR(i, 1, 2 * n) {
		x += l[i];
		i++;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;


int main()
{
	int N;
	int C[20],V[20];
	cin >> N;	

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

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

	int ans = 0;

	for(int i=0;i<N;i++)
	{	
		int tmp = V[i] - C[i];

		if(tmp >= 0)
		{
			ans += tmp;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

int main(int argc, char const *argv[]) {
    int r,g;
    cin >> r >> g;
    int ans = 2*g-r;
    cout << ans << endl;
    return 0;
}

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

int main(){
    int N, W;
    cin >> N >> W;
    long w0, weight, value;
    long v[4][N];
    int count[4]={};
    long val[4]={};
    long wtmp, vtmp, ans;

    for(int i=0; i<N; i++){
        int ii=0;
        if(i==0){
            count[ii]++;
            cin >> w0 >> v[i][count[ii]-1];
        }else{
            cin >> wtmp >> vtmp;
            ii=wtmp-w0;
            count[ii]++;
            v[ii][count[ii]-1]=vtmp;
        }
    }

    for(int i=0; i<4; i++){
        sort( v[i],v[i]+count[i] );
    }
    for(int i=0; i<4; i++){
        for(int j=0; j< (int) count[i]/2; j++){
            swap(v[i][j],v[i][count[i]-1-j]);
        }
    }

    //cout << "count " << count[0] << " " << count[1] << " " << count[2] << " " << count[3] << endl;

    ans=0;
    weight=0;
    value=0;
    for( int i=-1; i<count[0]; i++ ){
        if(i!=-1){
            val[0]+=v[0][i];
        }
        for(int j=-1; j<count[1]; j++){
            if(j!=-1){
                val[1]+=v[1][j];
            }
            for(int k=-1; k<count[2]; k++){
                if(k!=-1){
                    val[2]+=v[2][k];
                }
                for(int l=-1; l<count[3]; l++){
                    if(l!=-1){
                        val[3]+=v[3][l];
                    }
                    weight = w0*(i+1) + (w0+1)*(j+1) + (w0+2)*(k+1) + (w0+3)*(l+1);
                    value = val[0]+val[1]+val[2]+val[3];
                    //cout << "i j k l weight value " << i+1 << " " << j+1 << " " << k+1 << " " << l+1 << " " << weight << " " << value << endl;
                    if( weight <= W && value > ans ){ 
                        ans=value;
                    } 
                }
                val[3]=0;
            }
            val[2]=0;
        }
        val[1]=0;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	long long n;
	cin >> n;
	vector<pair<long long, int>> v;
	long long s = sqrt(n);
	for (int i = 2; i <= s; i++) {
		int r = 0;
		while (n % i == 0) {
			r++;
			n /= i;
		}
		if (r != 0) v.push_back({i, r});
	}
	if (n != 1) v.push_back({n, 1});
	long long ans = 0;
	for (auto e : v) {
		long long x = e.second;
		for (int i = 1; x >= i; i++) {
			x-=i;
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3684
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

n = int(input())
xy = []
for i in range(n):
    x,y = map(int,input().split())
    xy.append([x,y])
ans = []
for i in range(n):
    for j in range(n):
        d = math.sqrt((xy[i][0]-xy[j][0])**2 + (xy[i][1]-xy[j][1])**2)
        ans.append(d)
print(sum(ans)/n)

Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  string S;
  cin>>S;
  
  if(S=="Sunny"){
    cout<<"Cloudy"<<endl;
  }
  
  else if(S=="Cloudy"){
cout<<"Rainy"<<endl;
  }
  
  else if(S=="Rainy"){
    cout<<"Sunny"<<endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
    #define all(v) v.begin(), v.end()
    #define Graph vector< vector<int> >
    typedef long long ll;
    typedef pair<int, int> P;
    const int INF = (1LL << 31) - 1;


    struct SegmentTree{
        int n;
        vector<int> value;
        int SIJK;

        SegmentTree(int N){
            SIJK = (1LL << 31) - 1; // compareの内容に応じて変える
            n = 1;
            while(n < N) n *= 2;
            value.assign(2 * n - 1, SIJK);
        }
        SegmentTree(vector<int> V){
            SIJK = (1LL << 31) - 1; // compareの内容に応じて変える
            n = 1;
            while(n < V.size()) n *= 2;
            value.assign(2 * n - 1, SIJK);
            rep(i, V.size()) value[i + n - 1] = V[i];
            for(int i = n - 2; i >= 0; i--){
                value[i] = compare(value[2 * i + 1], value[2 * i + 2]);
            }
        }

        int compare(int a, int b){
            return min(a, b); //問題に応じて変える
        }

        void update(int i, int x){
            i += n - 1;
            value[i] = x;
            while(i > 0){
                i = (i - 1)/2; // 親のノード
                value[i] = min(value[2 * i + 1], value[2 * i + 2]);
            }
        }

        int find(int a, int b, int k = 0, int l = 0, int r = -1){
            // [a, b) の区間に対するクエリについて
            // ノード k （区間 [l, r) 担当）が答える
            if(r < 0) r = n;
            if(r <= a || b <= l) return INF;
            if(a <= l && r <= b) return value[k];
            else{
                int m = (l + r) / 2;
                int tmp1 = find(a, b, 2 * k + 1, l, m);
                int tmp2 = find(a, b, 2 * k + 2, m, r);
                return compare(tmp1, tmp2);
            }
        }


    };


    int main(){
        int N, Q;
        cin >> N >> Q;
        SegmentTree sg(N);
        rep(i, Q){
            int c, x, y;
            cin >> c >> x >> y;
            if(c == 0) sg.update(x, y);
            else cout << sg.find(x, y + 1) << endl;
        }
    }


Measured memory_bytes: 3892
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--) 
#define Rep(i,a) for(int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
const int N = 1e6 + 10, mod = 1e9 + 7;
int n, f[N];
int main() {
	scanf("%d",&n);
	f[0] = f[1] = f[2] = 1; int s = 3;
	rep(i,3,n) f[i] = (s - f[i - 2]) % mod, s = (s + f[i]) % mod;
	int ans = 0;
	rep(i,1,n - 1) ans = (
		ans + 
		1LL * f[i - 1] * (n - 1) % mod * (n - 1) % mod + 
		1LL * f[i - 1] * i % mod
	) % mod;
	ans = (ans + 1LL * f[n - 1] * (n - 1) + f[n]) % mod;
	if (ans < 0) ans += mod;
	cout <<ans<<endl;
	return 0;
}


Measured memory_bytes: 4096
//比較関数を作った版
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

bool cm(const pair<pair<string,int>,int> &a, const pair<pair<string,int>,int> &b){
 if(a.first.first != b.first.first) return a.first.first < b.first.first;
 else return a.first.second > b.first.second;
}

int main(){
int n,p;
string s;
vector<pair<pair<string,int>,int>> mise;
cin >> n;
rep(i,n){
 cin >> s >> p;
 auto a = make_pair(s,p);
 mise.push_back( make_pair(a,i+1) );
}
sort(mise.begin(),mise.end(),cm);
rep(i,n){
 auto m = mise[i];
 cout << m.second << endl;
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> K;
    if (K == 0) {
        cout << 2 << endl;
        cout << 1 << " " << 1 << endl;
    } else if (K == 1) {
        cout << 2 << endl;
        cout << 0 << " " << 2 << endl;
    } else if (K < 50) {
        cout << K << endl;
        REP(i, K) {
            cout << K << " ";
        }
    } else {
        ll amari = K % 50;
        cout << 50 << endl;
        REP(i, 50) {
            if (i < amari) {
                cout << K / 50LL + 50LL << " ";
            } else {
                cout << K / 50LL + 49LL - amari << " ";
            }
        }
    }
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>

typedef long long ll;
typedef unsigned long long ull;

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

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

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


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

  ll N;
  cin >> N;

  long double v[N];
  REP(i, N){cin >> v[i];}

  sort(v, v + N);

 double ans;

  FOR(i, 1, N){
    ll val = pow(2, (N-i));

    if (i == 1){
      long double ans1 = v[0]/val;
      long double ans2 = v[1]/val;
      ans += ans1;
      ans += ans2;}

    else {
      double ans3 = v[i]/val;
      ans += ans3;
    }
  }
  cout << ans << endl;





  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,h,x;
	cin>>h>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		h-=x;
	}
	cout<<(h<=0?"Yes":"No")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
const ld eps = 1e-10;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n; cin >> n;
  set<int> sthon = {2, 4, 5, 7, 9};
  set<int> stpon = {0, 1, 6, 8};
  if(sthon.count(n%10)) cout << "hon" << "\n";
  else if(stpon.count(n%10)) cout << "pon" << "\n";
  else cout << "bon" << "\n";
  return 0;
}


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



int main() {
  int n;
  cin >> n;
  int a[1010];
  double result = 0.0;
  for(int i=0; i < n; i++){
    int a; cin >> a;
    result += 1.0 / a;
  }
  printf("%f\n", 1/result);
}


Measured memory_bytes: 256
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>

long long pow_mod(long long x, long long n, long long mod_num) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) { res = (res * x) % mod_num; }
        x = (x * x) % mod_num;
        n = (n >> 1);
    }
    return res;
}

class Combi_Num {
    public:
    long long mod_num;
    std::vector<long long> factorial, factorial_inv, inv;
    Combi_Num() {}
    Combi_Num(const int n, const long long mod_num_in) {
        mod_num = mod_num_in;
        factorial.resize(n+1, 0);
        factorial_inv.resize(n+1, 0);
        inv.resize(n+1, 0);
        factorial[0] = 1;
        factorial_inv[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= n; i++) {
            factorial[i] = (factorial[i-1] * i) % mod_num;
            inv[i] = pow_mod(i, mod_num - 2, mod_num);
            factorial_inv[i] = (factorial_inv[i-1] * inv[i]) % mod_num;
        }
    }

    long long combi(const int n, const int r) {
        return (factorial[n] * ((factorial_inv[r] * factorial_inv[n-r]) % mod_num)) % mod_num;
    }

    long long perm(const int n, const int r) {
        return (factorial[n] * factorial_inv[n-r]) % mod_num;
    }
};

const long long MOD = 1000000007;
const int MAX_NM = 200050;

int N, M, K;

Combi_Num cn = Combi_Num(MAX_NM, MOD);

int main(int argc, char **argv) {
    std::cin >> N >> M >> K;

    long long ret = 0;
    for (int d = 1; d <= N - 1; d++) {
        long long mul = (((M * M) % MOD) * (N - d)) % MOD;
        ret += ((d * mul) % MOD) * cn.combi(N*M-2, K-2);
        ret = ret % MOD;
    }

    for (int d = 1; d <= M - 1; d++) {
        long long mul = (((N * N) % MOD) * (M - d)) % MOD;
        ret += ((d * mul) % MOD) * cn.combi(N*M-2, K-2);
        ret = ret % MOD;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long ll;
int n,d,r;
string s;
map<string,int>m;
int main(){
	cin>>n;
	while(n--){
		cin>>s;
		m[s]++;
		d=max(d,m[s]);
	}
	for(map<string,int>::iterator it=m.begin();it!=m.end();it++){
		if(it->second==d)cout<<(it->first)<<endl;
	}
}

Measured memory_bytes: 25344
z = input()
x = int(z[:2])
y = int(z[2:])

if (0<x <= 12):
      if (0<y<= 12):
            print("AMBIGUOUS")
      else:
            print("MMYY")
elif (0<y <= 12):
      if (0<x<= 12):
            print("AMBIGUOUS")
      else:
            print("YYMM")
else:
      print("NA")



Measured memory_bytes: 3060
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::vec::Vec;
use std::{vec, cmp, num};


struct Scanner<'a> {
    cin: StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner {cin: cin}
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
                    .skip_while(|c| c.is_whitespace())
                    .take_while(|c| !c.is_whitespace())
                    .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

// create Vec<char> from String
#[allow(dead_code)]
fn to_chars(s: String) -> vec::Vec<char> {
    let mut cs = s.chars();
    let mut res = vec::Vec::new();
    while let Some(c) = cs.next() {
        res.push(c);
    }
    res
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);
    let mut s: Vec<Vec<char>> = Vec::new();
    for _i in 0..3 {
        let t: String = sc.read();
        s.push(to_chars(t));
    }
    println!("{}{}{}", s[0][0].to_uppercase().next().expect(""),
                       s[1][0].to_uppercase().next().expect(""),
                       s[2][0].to_uppercase().next().expect(""));
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
#define ALL(obj) (obj).begin(), (obj).end()
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}

int main(){
  
  int d;
  cin>>d;
  
  string ans = "Christmas";
  string add_ = " Eve";
  REP(i,abs(25-d)){
    ans = ans + add_;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int X,Y;
  cin>>X>>Y;
  cout <<X +Y/2<<endl;

}

Measured memory_bytes: 256
N = int(input())
cnt1 = list(map(int, input().split()))
cnt2 = list(map(int, input().split()))
 
max_candies = 0
 
for i in range(N):
    temp = sum(cnt1[:i + 1]) + sum(cnt2[i:])
    max_candies = max(temp, max_candies)
 
print(max_candies)

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using v = vector<T>;
template <class T>
using vv = v<v<T>>;
#define ALL(c) (c).begin(), (c).end()

int main()
{
    int N;
    cin >> N;
    vv<int> F(N, v<int>(10, 0));
    vv<ll> P(N, v<ll>(11, 0));
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 10; j++)
        {
            cin >> F[i][j];
        }
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < 11; j++)
        {
            cin >> P[i][j];
        }
    }
    ll ans = INT32_MIN;
    for (int bit = 1; bit < (1 << 10); bit++)
    {
        ll ans_i = 0;
        for (int i = 0; i < N; i++)
        {
            int ci = 0;
            for (int j = 0; j < 10; j++)
            {
                if (bit & (1 << j))
                {
                    if (F[i][j] == 1)
                    {
                        ci++;
                    }
                }
            }
            ans_i += P[i][ci];
        }
        ans = max(ans, ans_i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define limit(x, l, r) max(l, min(x, r))
#define lims(x, l, r) (x = max(l, min(x, r)))
#define isin(x, l, r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)), x.end())
#define show(x) cout << #x << " = " << x << endl;
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define bn(x) ((1 << x) - 1)
#define dup(x, y) (((x) + (y)-1) / (y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
  int n;
  cin>>n;
  vl T(n),A(n);
  rep(i,n)cin>>T[i];
  rep(i,n)cin>>A[i];
  srep(i,1,n-1){
    if(A[i]>A[i+1] && T[i]>T[i-1]){
      if(A[i] != T[i]){
        cout<<0<<endl;
        return 0;
      }
    }
  }

  ll mxT = T[0];
  vi J(n,0);
  srep(i,1,n){
    if(mxT>=T[i]) J[i]=1;
    if(mxT<T[i]){
      if(T[i]>A[i]){
        cout<<0<<endl;
        return 0;
      }
    }
    maxs(mxT,T[i]);
    
  }
  J[n-1] = 0;
  ll mxA = A[n-1];
  for(int i=n-2;i>=0;i--){
    if(mxA<A[i]){
      if(A[i]>T[i]){
        cout<<0<<endl;
        return 0;
      }
    }
    J[i]&=(mxA>=A[i]);
    maxs(mxA,A[i]);
  }
  mint ans = 1;
  rep(i,n){
    if(J[i]){
      ans*=min(T[i],A[i]);
    }
  }
  if(mxA!=mxT) cout<<0<<endl;
  else cout<<ans.x<<endl;
  return 0;
}


Measured memory_bytes: 2176
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------

int N;
int Ma, Mb;
VVI a(3, (VI(50)));
// a[0][i]=ai, a[1][i]=bi, a[2][i]=ci
VI sum(3, 0);  // ai, biの総和を記録

int dp[41][401][401];
// dp[i][Ga][Gb] =
// 1~iまでの薬品を幾つか選んで、
// a、bの和がGa、Gbグラムとなるようなコストの最小値
// (できなければINF)

int ans = INF;


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

  cin >> N >> Ma >> Mb;
  NREP(j, N) {
    REP(i, 3) {
      cin >> a[i][j];
      sum[i] += a[i][j];
    }
  }

  // i=0のときの初期条件
  REP(ga, sum[0] + 1) {
    REP(gb, sum[1] + 1) {
      dp[0][ga][gb] = INF;
    }
  }
  dp[0][0][0] = 0;

  NREP(i, N) {
    REP(ga, sum[0] + 1) {
      REP(gb, sum[1] + 1) {

        if (ga >= a[0][i] && gb >= a[1][i]) {
          dp[i][ga][gb] = min(dp[i - 1][ga][gb], dp[i - 1][ga - a[0][i]][gb - a[1][i]] + a[2][i]);
        } else {
          dp[i][ga][gb] = dp[i - 1][ga][gb];
        }
      }
    }
  }

  // a[N][ga][gb]がa、bをga、gbグラム作るときの最小コスト

  NREP(ga, sum[0]) {
    int gb = ga * Mb / Ma;
    if (ga * Mb == gb * Ma && gb <= sum[1]) {
      int cost = dp[N][ga][gb];
      if (ans > cost) {
        ans = cost;
      }
    }
  }

  cout << (ans >= INF ? -1 : ans) << endl;
  return 0;
}

Measured memory_bytes: 24960
while true
  n = gets.to_i
  break if n == 0
  ary = Array.new(n)
  ary[0] = 1
  (1..n).each do |i|
    ary[i] = ary[i-1]
    ary[i] += ary[i-2] if i > 1
    ary[i] += ary[i-3] if i > 2
  end
  puts (ary[-1] / 3650.0).ceil
end

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

int main() {
    int n, m, h, r;
    while (cin >> n, n) {
        vector<pair<int,int> > v;
        for (int i=0; i<n; ++i) {
            cin >> h >> r;
            v.push_back(make_pair(h, r));
        }
        cin >> m;
        for (int i=0; i<m; ++i) {
            cin >> h >> r;
            v.push_back(make_pair(h, r));
        }
        sort(v.begin(), v.end());
        int mx = 0, dp[200];
        for (int i=0; i<n+m; ++i) {
            dp[i] = 1;
            for (int j=0; j<i; ++j) {
                if (v[j].first < v[i].first && v[j].second < v[i].second) {
                    dp[i] = max(dp[i], dp[j] + 1);
                }
            }
            mx = max(mx, dp[i]);
        }
        cout << mx << endl;
    }
    return 0;
}

Measured memory_bytes: 1204
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str  = sc.nextLine();
        String[] astr = str.split(""); //状況に合わせて
        String str2  = sc.nextLine();
        String[] astr2 = str2.split(""); //状況に合わせて
        int flag = 0;
        sc.close();

        for(int i=0;i<astr.length;i++){
            if(astr[i].equals(astr2[i])){
                flag +=1;
            }
        }
        System.out.println(flag);
    }
}

Measured memory_bytes: 21588
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String a = sc.next();
        String b = sc.next();
        String c = sc.next();
        System.out.print(a.toUpperCase().charAt(0)); 
        System.out.print(b.toUpperCase().charAt(0)); 
        System.out.print(c.toUpperCase().charAt(0)); 
    }
}



Measured memory_bytes: 21844
//	created : 16/05/02
// 	author   : Rp7rf
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <set>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define MOD 1000000007
#define INF 1e9


int main(void){
  int n;
  while(cin>>n,n){
    int sum = 0;
    int ret = 0;
    int l = 0;
    for(int r = 0 ; r < n ; r ++){      
      sum += r;
      
      if(sum == n)ret++;
      if(sum > n){
        sum -= l + r;
        l++;
        r--;
//        cout<<r<<" "<<l<<" "<<sum<<endl;
        continue;
      }
//      cout<<r<<" "<<l<<" "<<sum<<endl;
    }
//    cout<<n<<" "<<sum<<endl;
    cout<<ret<<endl;
  }
}

Measured memory_bytes: 1160