akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int w,a,b;
	cin >> w >> a >> b;
	if(a > b) swap(a,b);
	int ans;
	ans = b - w - a;
	if(ans > 0) cout << ans << endl;
	else cout << "0" << endl;
	return 0;
}

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

#define all(x) (x).begin(),(x).end()
#define puts(x) cout<< x << endl;
#define REP(i,m,n) for(int i=m;i<n;i++)
#define fore(i,a) for(auto i:a)
#define ll long long
using namespace std;

ll a,b;
int check=0;
int main(){
    cin>>a>>b;
    for(int i=1;i<=100000;i++){
        if(int(i*(0.08))==a&&int(i*(0.1))==b){
            puts(i);
            check=1;
            break;
        }
    }
    if(check==0){
        puts(-1);
    }
}

Measured memory_bytes: 256
N,M,C = map(int,input().split())
B = list(map(int,input().split()))
cnt = 0

for n in range(N):
    A = list(map(int,input().split()))
    m_sum = 0
    for m in range(M):
        m_sum+=A[m]*B[m]
    if m_sum+C > 0:
        cnt+=1
print(cnt)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        // 入力
        long[] tmp = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var x = tmp[0];
        var y = tmp[1];

        long ans = 0;
        long v = x;
        while (v <= y)
        {
            v = v*2;
            ans++;
        }

        Console.WriteLine(ans);

    }
}


Measured memory_bytes: 13396
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15

N,M = map(int,input().split())
edge = []
G = [[] for _ in range(N)]
G_inv = [[] for _ in range(N)]
for _ in range(M):
    a,b,c = map(int,input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G_inv[b].append(a)
    edge.append((a,b,-c))

can_reach_from_start = [False] * N
can_reach_from_goal = [False] * N
def dfs(i,reach,Gragh):
    for e in Gragh[i]:
        if reach[e]:
            continue
        reach[e] = True
        dfs(e,reach,Gragh)

can_reach_from_start[0] = True
dfs(0,can_reach_from_start,G)
can_reach_from_goal[-1] = True
dfs(N - 1,can_reach_from_goal,G_inv)

X = 0
for i in range(N):
    if can_reach_from_goal[i] and can_reach_from_start[i]:
        X += 1

new_edge = []
for a,b,c in edge:
    if can_reach_from_start[a] and can_reach_from_goal[b]:
        new_edge.append((a,b,c))

def beruman(N,edges,start = 0,negative_loop = False):
    find_negative = False #startを含む負の閉路が存在するか
    dist = [INF] * N
    dist[start] = 0

    for i in range(X):
        update = False
        for a,b,c in edges:
            if dist[a] != INF and dist[b] > dist[a] + c:
                dist[b] = dist[a] + c
                update = True

        if not update:
            break
        if i == X - 1:
            find_negative = True
    
    if negative_loop:
        return dist,find_negative
    else:
        return dist

dist,judge = beruman(N,new_edge,0,True)
if judge:
    print('inf')
else:
    print(-dist[-1])

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

const int N = 2e6;

int main() {
	clog << "Ready\n";
	
	int n;
	cin >> n;
	int mx = 0;
	int sum = 0;
	for (int i = 1; i <= n; ++ i) {
		int x;
		cin >> x;
		mx = max(mx, x);
		sum += x;
	}
	cout << sum - (mx / 2);
	return 0;
}



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

typedef long long LL;
const int N = 3005;
LL mod = 1e9 + 7;

int n, m, r[N], pref[N];
LL dp[N][N];
char s[N];

inline void modadd(LL &x, LL y) {
  x += y;
  if (x >= mod) x -= mod;
}

int main() {
  scanf("%d%d", &n, &m);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i ++) {
    r[i] = i;
    pref[i] = pref[i - 1] + s[i] - '0';
  }
  for (int i = 1, x, y; i <= m; i ++) {
    scanf("%d%d", &x, &y);
    r[x] = max(r[x], y);
  }
  int c = 0, R = 0, t;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i ++) {
    t = 0;
    if (R < r[i]) {
      c += (t = pref[r[i]] - pref[R]);
      R = r[i];
    }
    if (i == R)
      modadd(dp[i][0], dp[i - 1][0] + dp[i - 1][1]);
    else {
      for (int j = t - 1; j <= c && j <= R - i; j ++) {
  	if (j >= t) modadd(dp[i][j], dp[i - 1][j - t]);
  	if (j >= t - 1) modadd(dp[i][j], dp[i - 1][j - t + 1]);
      }
    }
  }
  printf("%lld\n", dp[n][0]);
  return 0;
}


Measured memory_bytes: 68352
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
signed main(){
  ll n,t,a;
  double h,b;
  cin>>n>>t>>a;
  vector<pair<double,ll> > pp(n);
  rep(i,n){
    cin>>h;
    b = abs(a - (t - h * 0.006));
    pp[i] = make_pair(b,i+1);
  }
  sort(pp.begin(),pp.end());
  cout<<pp[0].second<<"\n";
  return 0;
}

Measured memory_bytes: 256
// C - Low Elements
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
template<class T> T in(){T x;cin>>x;return x;}
template<class T> vector<T> inarr(int s,int e, T init){
	vector<T> v;T x;
	rp(i,0,s)v.push_back(init);
	rp(i,s,e){x=in<T>();v.push_back(x);}
	return v;
}

int N;
vi P;

int solve(){
	int ans=0;
	int minP = INT_MAX;
	rp(i,0,N){
		if(minP >= P[i]){
			minP = P[i];
			ans++;
		}
	}
	return ans;
}

int main(){
	cin>>N;
	P = inarr<int>(0,N,0);
	cout<< solve() <<endl;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    set<char>mset;
    map<char,int>mmap;
    for(int i=0;i<s.size();i++)
    {
        mset.insert(s[i]);
        mmap[s[i]]++;
    }
    if(mset.size()==2)
    {
        set<char>::iterator it;
        for(it=mset.begin();it!=mset.end();it++)
        {
            char c=*it;
            if(mmap[c]!=2)
            {
                cout << "No" << endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
 
import static java.lang.System.out;
import static java.lang.Integer.parseInt;
 
public class Main {
    static class Element {
        long t, c;
        Element(long t,long c){
            this.t=t;this.c=c;
        }
    }
 
    static int NN = 100007;
    static ArrayList<Element>[] G = new ArrayList[NN];
    static long z[] = new long[NN];
 
    static void dfs(int x, int p) {
        for (Element e : G[x]) {
            if ((e.t - p) != 0) {
                z[(int) e.t] = z[x] + e.c;
                dfs((int) e.t, x);
            }
        }
    }
 
    public static void main(String[] args) throws IOException {
        for(int i=0;i<NN;i++) G[i]=new ArrayList<Element>();
        //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for(int i=0;i<n-1;i++){
            int a=sc.nextInt();
            int b=sc.nextInt();
            int c=sc.nextInt();
            G[a].add(new Element(b,c));
            G[b].add(new Element(a,c));
        }
        int q=sc.nextInt();
        n=sc.nextInt();
        dfs(n,0);
        for(int j=0;j<q;j++){
            int a=sc.nextInt();
            int b=sc.nextInt();
 
            out.println(z[a]+z[b]);
        }
    }
}

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

#define REP(i,n) for ( int i=1; i<=int(n); i++ )  
#define MP make_pair
#define PB push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define X first
#define Y second
template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template <class T>  
inline bool RD(T &ret) {  
        char c; int sgn;  
        if (c = getchar(), c == EOF) return 0;  
        while (c != '-' && (c<'0' || c>'9')) c = getchar();  
        sgn = (c == '-') ? -1 : 1 , ret = (c == '-') ? 0 : (c - '0');  
        while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');  
        ret *= sgn;  
        return 1;  
}  
template <class T>  
inline void PT(T x) {  
        if (x < 0) putchar('-') ,x = -x;  
        if (x > 9) PT(x / 10);  
        putchar(x % 10 + '0');  
}


const int INF = 0x3f3f3f3f;
const int inf = INF;
typedef long long LL;
typedef pair<int, int> pii;
typedef long double LD;

const int N = 1e3 + 100;
char str[N];
bool vis[300];
int main() {
	scanf("%s", str);
	for(int i = 0; str[i];i ++) vis[str[i]] = 1;
	if(vis['N'] ^ vis['S']) return puts("No") * 0;
	if(vis['W'] ^ vis['E']) return puts("No") * 0;
	puts("Yes");
}




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

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h);
    //vector<string> ans(h);
    char ans[h][w];
    rep(i, h)
        cin >> s.at(i);

    rep(i, h) {
        //printf("i = %d\n", i);
        rep(j, w) {
            //printf("j = %d\n", j);
            if (s.at(i).at(j) == '#') {
                //ans.at(i).at(j) = '#';
                ans[i][j] = '#';
                continue;
            }
            vector<int> dx{-1, 0, 1, -1, 1, -1, 0, 1};
            vector<int> dy{-1, -1, -1, 0, 0, 1, 1, 1};
            
            int sum = 0;
            for (int k = 0; k < 8; k++) {
                //printf("k = %d\n", k);
                int x = j + dx.at(k);
                int y = i + dy.at(k);
                if (x < 0 || y < 0 || w <= x || h <= y)
                    continue;
                //printf("x = %d, y = %d\n", x, y);
                if (s.at(y).at(x) == '#')
                    sum++;
                //printf("x = %d, y = %d\n", x, y);
            }
            //printf("before i = %d, j = %d sum = %d\n", i, j, sum);
            //ans.at(i).at(j) = (char)('0' + (char)sum);
            //ans.at(i).at(j) = (char)('0');
            ans[i][j] = (char)('0' + (char)sum);
            //printf("after i = %d, j = %d\n", i, j);
        }
    }

    rep(i, h) {
        rep(j, w) {
            cout << ans[i][j];
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int A,B,C ;
    cin>>A>>B>>C ;
    if ( A==B || B==A ) {
        cout<<C ;
    }
    else if (C==B || B==C ) {
        cout<<A ;
    }
    else {
        cout<<B ;
    }
        return 0;
}


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

using namespace std;

const int N = 2010, mod = 1e9 + 7;

long long d[N];

int main() {
    int n;
    cin >> n;
    d[3] = 1;
    for (int i = 4; i <= n; ++i) {
        d[i] = (d[i - 1] + d[i - 3]) % mod;    
    }
    cout << d[n] << '\n';
    return 0;
}

Measured memory_bytes: 3632
var toInt = x=>parseInt(x,10);
var toIntArr = arr=>arr.map(x=>toInt(x));
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

function Main(input){
	input = input.split('\n');
	var temp = input[0].split(' ');
	var h = toInt(temp[0]);
	var w = toInt(temp[1]);
	var ss = [];
	var ans = [];
	for(var i = 0; i < h; i++){
		ss[i] = input[i+1];
	}

	var mine = 0;
	for(var j = 0; j < h; j++){
		ans[j] = '';
		for(var k = 0; k < w; k++){
			if(ss[j][k] === '.'){
				mine = 0;
				if(j !== 0){
					if(k !== 0 && ss[j-1][k-1] === '#') mine++;
					if(ss[j-1][k] === '#') mine++;
					if(k !== w-1 && ss[j-1][k+1] === '#') mine++;
				}
				if(k !== 0 && ss[j][k-1] === '#') mine++;
				if(k !== w-1 && ss[j][k+1] === '#') mine++;
				if(j !== h-1){
					if(k !== 0 && ss[j+1][k-1] === '#') mine++;
					if(ss[j+1][k] === '#') mine++;
					if(k !== w-1 && ss[j+1][k+1] === '#') mine++;
				}
				ans[j] += String(mine);
			}else{
				ans[j] += '#';
			}
		}
	}

	ans.forEach(function(item,index,array){
		console.log(item);
	})
}



Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005],b[200005];
int main()
{
	ll n,m,k,x;
	cin>>n>>m>>k;
	for(ll i=1;i<=n;i++){
		cin>>x;
		a[i]=a[i-1]+x;
	}
	for(ll i=1;i<=m;i++){
		cin>>x;
		b[i]=b[i-1]+x;
	}
	ll j=m,ans=0;
	for(ll i=0;i<=n;i++)
	{
		if(a[i]>k) break;
		while(a[i]+b[j]>k) j--;
		ans=max(ans,i+j);
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 6692
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod = 1000000007;
const int inf = 0x3f3f3f3f;
const ll inff = 0x7ffffffffff;
ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
//head
int n;
string x;
int c[5];
int main() {
	cin >> n;
	rep(i, 1, n) {
		cin >> x;
		if(x == "AC") c[1]++;
		if(x == "WA") c[2]++;
		if(x == "TLE") c[3]++;
		if(x == "RE") c[4]++;
	}
	cout << "AC x " << c[1] << endl;
	cout << "WA x " << c[2] << endl;
	cout << "TLE x " << c[3] << endl;
	cout << "RE x " << c[4];
	return 0;
}

Measured memory_bytes: 3652
import java.util.*;

public class Main{
	public static void main(String[]args){
      Scanner sc =  new Scanner(System.in);
      long S = Long.parseLong(sc.next());
      
      long x1 = 1000000000, y1 = 1;
      long x2 = (x1-S%x1)%x1;
      long y2 = ((S-1)/x1+1);
	  System.out.println("0 0 "+x1+" "+y1+" "+x2+" "+y2);
	}
}


Measured memory_bytes: 23636
n, q = map(int,input().split())
s = "a" + input() + "b"
T = [list(input().split()) for i in range(q)] + [["a", "L"], ["b", "R"]]
n = len(s)
q = len(T)

ans = 0

l = 0
r = n
m = (l+r)//2
while r-l > 1:
    a = m
    for i in range(q):
        if T[i][0] == s[a]:
            if T[i][1] == "L":
                a -= 1
            else:
                a += 1
        if a < 0 or a >= n:
            break
    
    if a >= n:
        r = m
    else:
        l = m
    m = (l+r)//2
# print(l, r)
ans += n-l-1
# print("pl",n-l-1)


l = -1
r = n-1
m = (l+r)//2
while r-l > 1:
    a = m
    for i in range(q):
        if T[i][0] == s[a]:
            if T[i][1] == "L":
                a -= 1
            else:
                a += 1
        if a < 0 or a >= n:
            break
    
    if a < 0:
        l = m
    else:
        r = m
    m = (l+r)//2
# print(l, r)
ans += r
# print("pl",r)

print(n - ans)

Measured memory_bytes: 90896
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N, K;
  cin >> N >> K;
  priority_queue<int> que;
  rep(i,N){
    int a;
    cin >> a;
    que.push(a);
  }

  while(!que.empty()){
    if(K == 0) break;
    que.pop();
    K--;
  }
  
  ll sum = 0;
  while(!que.empty()){
    sum += que.top();
    que.pop();
  }

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



Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); i++)
#define loops(i,f,n) for(int i = (f); i < (n); i++)
#define INF 9999999
#define in(a) cin>>a
#define out(a) cout<<a<<endl
int main()
{
	int h, w;
  cin>>h>>w;
	vector<vector<char>> grid(h + 2, vector<char>(w + 2, '#'));
	loops(i,1,h+1)
	{
		string s;
		cin >> s;
		loops(j,1, w+1)
		{
			grid[i][j] = s[j-1];
		}
	}
	loop(i, h+2)
	{
		loop(j, w+2)
		{
			cout << grid[i][j];
		}
		cout << endl;
	}
}

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

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split()))
    As.sort(reverse=True)
    alice = 0
    bob   = 0
    for i in range(len(As)):
        if i%2 == 0:
            alice += As[i]
        else:
            bob   += As[i]
    print(alice - bob)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string str;
string target = "keyence";
int main(){
	cin>>str;
	if(str == target){
		puts("YES");
		return 0;
	}
	int n = str.size();
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			//delete [i,j]
			string S = "";
			for(int k=0;k<n;k++){
				if(i<=k && k<=j){
					continue;
				}
				else S.push_back(str[k]);
			}
			if(S == target){
				puts("YES");
				return 0;
			}
		}
	}
	puts("NO");
}

Measured memory_bytes: 3624
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
#pragma endregion

// {waapu, h, w}
using p = tuple<int, int, int>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int h_size, w_size;
    cin >> h_size >> w_size;
    int h_from, w_from;
    cin >> h_from >> w_from;
    --h_from;
    --w_from;
    int h_to, w_to;
    cin >> h_to >> w_to;
    --h_to;
    --w_to;
    vector can_go(h_size, vector<bool>(w_size));
    rep(h, h_size)
    {
        rep(w, w_size)
        {
            char c;
            cin >> c;
            can_go[h][w] = (c == '.');
        }
    }

    // dijkstra
    int ans = -1;
    priority_queue<p, vector<p>, greater<p>> pq;
    vector used(h_size, vector<bool>(w_size, false));
    pq.emplace(0, h_from, w_from);
    while (not pq.empty())
    {
        auto [cost, h, w] = pq.top();
        pq.pop();
        if (h == h_to and w == w_to)
        {
            ans = cost;
            break;
        }
        if (used[h][w])
        {
            continue;
        }
        used[h][w] = true;
        FOR(dh, -2, 3)
        {
            FOR(dw, -2, 3)
            {
                auto h_new = h + dh, w_new = w + dw;
                if (h_new < 0 or h_new >= h_size or w_new < 0 or w_new >= w_size)
                {
                    continue;
                }
                if (not can_go[h_new][w_new] or used[h_new][w_new])
                {
                    continue;
                }
                int dcost = (abs(dh) + abs(dw) > 1);
                pq.emplace(cost + dcost, h_new, w_new);
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    string s;
    cin >> s;
    int len = s.size();

    ll res = 0;
    ll tmp = 0;
    for (int i = 0; i < 1<<(len - 1); ++i) {
        for (int j = 0; j < len; ++j) {
            tmp *= 10;
            tmp += s[j] - '0';
            if(j == len - 1){
                res += tmp;
                tmp = 0;
                continue;
            }
            if(i & (1<<j)){
                res += tmp;
                tmp = 0;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int c1, c2, c3;
    while(cin >> c1 >> c2 >> c3) {
        int cnt = 0;
        for(int i = 1; i <= 10; ++i) {
            if(i == c1 || i == c2 || i == c3) continue;
            if(c1+c2+i <= 20) ++cnt;
        }
        if(cnt >= 4) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}

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

int main(){
    long long n;
    cin >> n;
    long long ans = n+2;
    for(long long i = 1; i * i <= n; i++){
        if(n % i == 0){
            ans = min(ans, i + n/i);
        }
    }
    ans -= 2;
    cout << ans << endl;
}

Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <ctime>
#include <cstring>
#include <cassert>
#include <bitset>
#include <sstream>
#include <queue>

#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define sz(a) ((int) (a).size())
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

typedef long long int64;
typedef long double ldb;

const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = acos(-1);

template <class T> T sqr (T x) {return x * x;}
template <class T> T abs (T x) {return x < 0 ? -x : x;}

int main () {
    ios_base::sync_with_stdio(0);
//	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);

	long long n, a, b;
	cin >> n >> a >> b;

	if (a > b || (a != b && n == 1)) {
		cout << 0 << endl;
		return 0;
	}

	long long left = (n - 1) * a + b;
	long long right = a + (n - 1) * b;
	cout << right - left + 1 << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  int64_t n;
  cin >> n;
  vector<int64_t> h(n);
  rep(i,n){
    cin >> h[i];
  }
  int64_t hmax = 0;
  int64_t cnt = 0;
  rep(i,n){
    if(hmax <= h[i]){
      hmax = h[i];
      cnt++;
    }
  }
  cout << cnt << endl;
}
    
    


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/











int N; ll A[3010];
//---------------------------------------------------------------------------------------------------
int vis[3010][3010];
ll memo[3010][3010];
ll dp(int L, int R) {
    if (L > R) return 0;
    if (vis[L][R]) return memo[L][R];
    vis[L][R] = 1;

    int diff = N - (R - L + 1);

    ll res = 0;
    if (diff % 2 == 0) {
        // X-Yを最大化したい
        res = -infl;
        chmax(res, dp(L + 1, R) + A[L]);
        chmax(res, dp(L, R - 1) + A[R]);
    } else {
        // X-Yを最小化したい
        res = infl;
        chmin(res, dp(L + 1, R) - A[L]);
        chmin(res, dp(L, R - 1) - A[R]);
    }

    return memo[L][R] = res;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;
    rep(i, 0, N) cin >> A[i];

    cout << dp(0, N - 1) << endl;
}


Measured memory_bytes: 105472
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){init(mx);}
    void init(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;i++){
            fac[i]=fac[i-1]*i%mod;
            inv[i]=mod-inv[mod%i]*(mod/i)%mod;
            finv[i]=finv[i-1]*inv[i]%mod;
        }
    }
    ll operator()(int n,int k){
        if(n<k)return 0;
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
    }
};

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    ll ans=0;
    Combination comb(n-1);
    rep(i,k+1){
        ll tmp=(comb(n-1,i)*modpow(m-1,n-1-i))%mod;
        ans=(ans+tmp)%mod;
    }
    ans=(ans*m)%mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 7824
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *


def solve(H: int, W: int, A: "List[str]"):
    queue = deque()

    rem = H * W
    visited = [True] * ((W+2) * (H+2))
    for i in range(W+2):
        visited[i] = False
        visited[(W + 2) * (H + 1) + i] = False
    for i in range(H+2):
        visited[(W + 2) * i] = False
        visited[(W + 2) * i + (W + 1)] = False

    for i in range(H):
        l = A[i]
        for j in range(W):
            if l[j] == '#':
                queue.append((i+1, j+1, 0))
                k = i * (W + 2) + j
                visited[k] = False

    ret = 0
    while queue:
        i, j, n = queue.popleft()
        k = i * (W + 2) + j
        if not visited[k] and 0 < n:
            continue
        visited[k] = False
        ret = n
        rem -= 1

        if rem == 0:
            break

        if visited[k - 1]:
            queue.append((i, j - 1, n + 1))
        if visited[k + 1]:
            queue.append((i, j + 1, n + 1))

        if visited[k - (W + 2)]:
            queue.append((i - 1, j, n + 1))
        if visited[k + (W + 2)]:
            queue.append((i + 1, j, n + 1))
    return ret


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    A = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    result = solve(H, W, A)
    print(result)

if __name__ == '__main__':
    main()

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

int main() {
  string S;
  ll Q;
  cin >> S;
  cin >> Q;
  S.reserve(Q);
  char flg;
  char flg2;
  string add;
  string mae = "";
  string ato = "";
  bool is_reverse = false;
  rep(i, Q)
  {
    cin >> flg;
    if(flg == '1'){
      is_reverse = !is_reverse;
    } 
    else{
      cin >> flg2 >> add;
      if(is_reverse){
        if(flg2 == '2'){
          // S = add + S;
          mae = add + mae;
        }else{
          // S = S + add;
          ato += add;
        }
      }else{
        if(flg2 == '1'){
          mae = string(add) + mae;
          // S = add + S;
        }else{
          // S = S + add;
          ato += add;
        }
      }
    }
  }
  S = mae + S + ato;
  if(is_reverse){
    std::reverse(S.begin(), S.end());
  }
  cout << S << endl;
  return 0;
}



Measured memory_bytes: 1276
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <complex>
#include <string>
#include <sstream>

#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cstring>

using namespace std;

#define all(c) c.begin(),c.end()
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

typedef long long ll;
typedef vector<int> vi;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& val){
    os << "[ ";
    for(typename vector<T>::const_iterator it=val.begin();
        it != val.end();++it){
        os << *it << " ";
    }
    os << "]";
    return os;
}
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};

inline int mc(char c){
// '>' (大なり記号): 東向きの矢印が書かれたタイル
// '<' (小なり記号): 西向きの矢印が書かれたタイル
// '^' (べき記号) : 北向きの矢印が書かれたタイル
// 'v' (小文字ブイ): 南向きの矢印が書かれたタイル
// '.' (ピリオド) : 何も書かれていないタイル
    switch(c){
    case '>':
        return 0;
    case '<':
        return 2;
    case '^':
        return 1;
    case 'v':
        return 3;
    case '.':
        return -1;
    }
    return -1;
}

string solve(vector<string> field){

    int W = field[0].size();
    int H = field.size();
    vector<vector<char> > alr(H,vector<char>(W,false));

    int nx = 0;
    int ny = 0;
    while(mc(field[ny][nx]) != -1){
        if(alr[ny][nx]){
            return "LOOP";
        }
        alr[ny][nx] = true;
        int d = mc(field[ny][nx]);
        ny += dy[d];
        nx += dx[d];
    }
    stringstream ss;
    ss << nx << " " << ny;
    return ss.str();
}
int main(){
    while(true){
        int W,H;
        cin >> H >> W;
        if(W == 0 and H == 0) break;
        vector<string> field(H);
        for(int i=0;i<H;i++){
            cin >> field[i];
        }
        cout << solve(field) << endl;
    }
    return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
int a[200001];
int main(){
	int k,n;
	cin>>k>>n;
	for (int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+1+n);
	int sub=k-a[n]+a[1];
	for (int i=2;i<=n;i++){
		sub=max(sub,a[i]-a[i-1]);
	}
	cout<<k-sub<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main() 
{
	int n; 
	cin >> n;
	string st[] = { "AC", "WA", "TLE", "RE" };
	int stn[4] = { 0, 0, 0, 0 };
	for (int i = 0; i < n; i++) {
		string inp;
		cin >> inp;
		for (int j = 0; j < 4; j++) {
			if (st[j] == inp) {
				stn[j]++;
				break;
			}
		}
	}
	for (int i = 0; i < 4; i++) {
		cout << st[i] << " x " << stn[i] << endl;
	}
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define REP0(i, n) for (ll i = 0; i < n; i++)
#define REP1(i, n) for (ll i = 1; i <= n; i++)
#define ARRSET(name, i) memset(name, i, sizeof(name))
#define Cn2(i) ((i)*((i)-1)>>1)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> llp;
const ll INF = 9.22e18;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n;
    cin >> n;
    ll cnt = 0;
    while (n--) {
        ll a, b;
        cin >> a >> b;
        cnt += b-a+1;
    }
    cout << cnt << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
ll dx[4]={0,-1,0,1};
ll dy[4]={1,0,-1,0};
/****************************/
int n,m,k;
int main()
{
	cin>>n>>m>>k;
	ll ans=n/m;
	if(n%m)
	{
		ans++;
	}
	ans*=k;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int n,k;
vector<int>v[100010];
int p[100010];
int gp[100010];
int ans[100010];
void dfs(int nw,int a,int aa){
	p[nw]=a;
	gp[nw]=aa;
	for(int i=0;i<v[nw].size();i++){
		int to=v[nw][i];
		if(to==a)continue;
		dfs(to,nw,a);
	}
}
void dfs2(int x){
	int lft=k-1;
	if(p[x]!=-1)lft--;
	for(int i=0;i<v[x].size();i++){
		int to=v[x][i];
		if(to==p[x])continue;
		ans[to]=lft;
		lft--;
		dfs2(to);
	}
}
int main() { 
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>k;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		a--;b--;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	dfs(0,-1,-1);
	ans[0]=k;
	dfs2(0);
	long long aans=1;
	for(int i=0;i<n;i++){
		aans=aans*ans[i]%(long long)(1e9+7);
	}
	cout<<aans<<endl;
    return 0; 
}

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

typedef long long LL;

const int N=20,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m;
struct side0{
  int x,y;
}a[N*N+9];
int to[N+9];

void into(){
  scanf("%d%d",&n,&m);
  for (int i=0;i<m;++i){
	scanf("%d%d",&a[i].x,&a[i].y);
	--a[i].x;--a[i].y;
	to[a[i].x]|=1<<a[i].y;
	to[a[i].y]|=1<<a[i].x;
  }
}

int inv[N*N+9],fac[N*N+9],ifac[N*N+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=m;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int c[(1<<N)+9],ce[(1<<N)+9];

void Get_e(){
  for (int s=0;s<1<<n;++s){
	c[s]=c[s>>1]+(s&1);
	for (int i=0;i<n;++i)
	  if (s>>i&1){
		int t=to[i]&s;
		ce[s]=ce[s^1<<i]+c[t];
	    break;
	  }
  }
}

struct side{
  int y,next;
}e[N*2+9];
int lin[N+9],cs;

void Ins(int x,int y){e[++cs].y=y;e[cs].next=lin[x];lin[x]=cs;}
void Ins2(int x,int y){Ins(x,y);Ins(y,x);}

int vis[N+9];

int Dfs_vis(int k){
  int res=1<<k;
  vis[k]=1;
  for (int i=lin[k];i;i=e[i].next)
	if (!vis[e[i].y]) res|=Dfs_vis(e[i].y);
  return res;
}

int num[(1<<N)+9];

void Get_num(){
  for (int s=0;s<1<<n-1;++s){
	cs=0;
	for (int i=0;i<n;++i) lin[i]=vis[i]=0;
    for (int i=0;i<n-1;++i)
	  if (s>>i&1) Ins2(a[i].x,a[i].y);
    for (int i=0;i<n;++i)
	  if (!vis[i]){
		int t=Dfs_vis(i);
	    num[s]+=ce[t]-c[t]+1;
	  }
  }
}

struct state{
  int c,cnt,sum;
}dp[(1<<N)+9];

void Get_dp(){
  dp[0].cnt=1;dp[0].sum=0;
  for (int s=0;s<1<<n-1;++s)
	for (int i=0;i<n-1;++i){
      if (s>>i&1) continue;
	  int delta=num[(1<<n-1)-1^s]-num[(1<<n-1)-1^s^1<<i];
	  dp[s|1<<i].c=dp[s].c+delta+1;
	  int cnt=mul(dp[s].cnt,mul(fac[dp[s].c+delta],ifac[dp[s].c]));
	  int sum=mul(dp[s].sum,mul(fac[dp[s].c+delta+1],ifac[dp[s].c+1]));
	  sadd(dp[s|1<<i].cnt,cnt);
	  sadd(dp[s|1<<i].sum,add(sum,mul(cnt,c[s]+1)));
	}
}

void work(){
  Get_inv();
  Get_e();
  Get_num();
  Get_dp();
}

void outo(){
  printf("%d\n",dp[(1<<n-1)-1].sum);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 20172
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function root(uf::Array{Int,1},x)
	s=x
	while uf[s]!=s
		s=uf[s]
	end
	s
end
function same(uf::Array{Int,1},x,y)
	root(uf,x)==root(uf,y)?true:false
end
function unite(uf::Array{Int,1},x,y)
	l = root(uf,x)
	r = root(uf,y)
	if l < r
		uf[r] = l
	elseif l > r
		uf[l] = r
	end
end

function main()
	h,w = readline() |> split |> parseMap
	s = String["" for i in 1:h]
	for i in 1:h
		s[i] = readline() |> chomp
	end
	uf = Int[i for i in 1:h*w]
	for i in 1:h
		for j in 1:w
			if i>1
				if s[i][j]!=s[i-1][j]
					unite(uf,w*(i-1)+j,w*(i-2)+j)
				end
			end
			if i<h
				if s[i][j]!=s[i+1][j]
					unite(uf,w*(i-1)+j,w*i+j)
				end
			end
			if j>1
				if s[i][j]!=s[i][j-1]
					unite(uf,w*(i-1)+j,w*(i-1)+j-1)
				end
			end
			if j<w
				if s[i][j]!=s[i][j+1]
					unite(uf,w*(i-1)+j,w*(i-1)+j+1)
				end
			end
		end
	end
	b = Dict{Int,Int}()
	v = Dict{Int,Int}()
	for i in 1:h
		for j in 1:w
			if s[i][j]=='#'
				r = root(uf,w*(i-1)+j)
				if haskey(b,uf[r])
					b[uf[r]]+=1
				else
					b[uf[r]] = 1
				end
			else
				r = root(uf,w*(i-1)+j)
				if haskey(v,uf[r])
					v[uf[r]]+=1
				else
					v[uf[r]] = 1
				end
			end
		end
	end
	ans = 0
	for k in keys(b)
		if haskey(v,k)
			ans += b[k]*v[k]
		end
	end
	println(ans)
end

main()

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

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a + b < c + d) { cout << "Right" ;}
    else if(a + b > c + d) { cout << "Left" ;}
    else { cout << "Balanced" ;}
}


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

int main(){
  string S;
  cin >> S;
  
  int A = (S[0] - '0') * 10 + (S[1] - '0');
  int B = (S[2] - '0') * 10 + (S[3] - '0');
  
  bool YYMM = (1 <= B && B <= 12);
  bool MMYY = (1 <= A && A <= 12);
  
  if (YYMM) {
    if (MMYY) {
      puts("AMBIGUOUS");
    }else{
      puts("YYMM");
    }
  }else{
    if(MMYY){
      puts("MMYY");
    }else{
      puts("NA");
    }
  }  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(2e5)+10;
int n,q,vis[maxn];
ll m,s,cnt;
struct node {
	int x,y,z;
} d[maxn];
struct Seg {
	int fa[maxn],sz[maxn];
	void init() {
		for (int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	}
	int find(int x) {
		if (fa[x]==x) return x;
		return fa[x]=find(fa[x]);
	}
	void connect(int x,int y) {
		x=find(x); y=find(y);
		if (x==y) return;
		fa[x]=y; sz[y]+=sz[x];
	}
} A,B;
int main() {
	//freopen("1.txt","r",stdin);
	read(n); read(m); read(q);
	int x,y,z,flag=0; A.init();
	for (int i=1;i<=q;i++) {
		read(x); read(y); read(z);
		x++; y++;
		d[i].x=x; d[i].y=y; d[i].z=z;
		if (!z) A.connect(x,y);
	}
	for (int i=1;i<=q;i++) {
		x=d[i].x; y=d[i].y; z=d[i].z;
		if (!z) continue;
		x=A.find(x); y=A.find(y);
		if (x==y) { printf("No\n"); return 0; }
		flag=1;
	}
	for (int i=1;i<=n;i++)
		if (A.find(i)==i) cnt++;
	if (m==n-1) {
		if (flag) printf("No\n");
		else printf("Yes\n");
		return 0;
	}
	if (m-(n-cnt)<=cnt*(cnt-1)/2) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

class Fraq{
  public:
  ll denominator;
  ll numerator;
  Fraq(){
    denominator = 0;
    numerator = 1;
  }
  Fraq(ll d, ll n){
    denominator = d;
    numerator = n;
  }
Fraq reduction(){
    Fraq res;
    ll x = max(denominator, numerator), y = min(denominator, numerator);
    while(x != 0 && y != 0){
      x %= y;
      swap(x, y);
    }
    x = max(x, y);
    res.denominator = denominator / x;
    res.numerator = numerator / x;
    return res;
  }

  Fraq operator + (const Fraq &f)const{
    Fraq res(denominator * f.numerator + f.denominator * numerator, numerator * f.numerator);
    return res.reduction();
  }
};


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

  string str;
  while(cin >> str){
    if(str == "#") return 0;
    ll north = 0, west = 0;
    vector<bool> b; //true:north false:west
    for(ll i = 0; i < str.length(); i++){
      if(str[i] == 'n'){
        b.push_back(true);
        north++;
        i += 4;
      }else if(str[i] == 'w'){
        b.push_back(false);
        west++;
        i += 3;
      }else{
        assert(false);
      }
    }
    if(west == 0){
      cout << 0 << endl;
      continue;
    }else if(north == 0){
      cout << 90 << endl;
      continue;
    }

    reverse(b.begin(), b.end());
    Fraq ans(((b[0] == false)? 90 : 0), 1);

    for(ll i = 1; i < b.size(); i++){
      if(b[i] == false){
        ans = ans + Fraq(90, pow(2, i));
      }else{
        ans = ans + Fraq(-90, pow(2, i));
      }
    }

    ans = ans.reduction();
    if(ans.numerator == 1) cout << ans.denominator << endl;
    else cout << ans.denominator << '/' << ans.numerator << endl;
  }
}

Measured memory_bytes: 1240
#include <iostream>
#include <vector>
#include <cstring>

using namespace std;

const int MAX = 100;
const int INFTY = 1<<21;
int dp[MAX][500][500];// = {{{-1}}};

int main(){
    int N, Ma, Mb;
    cin >> N >> Ma >> Mb;
    vector<int> a(N), b(N), c(N);
    int total_a = 0, total_b = 0;
    for(int i=0;i<N;i++){
        cin >> a[i] >> b[i] >> c[i];
        total_a += a[i];
        total_b += b[i];
    }
    for(int i=0;i<MAX;i++) for(int j=0;j<500;j++) for(int k=0;k<500;k++) dp[i][j][k] = INFTY;
    dp[0][0][0] = 0;

    for(int i=0;i<N;i++){
        for(int A=0;A<=total_a;A++){
            for(int B=0;B<=total_b;B++){
                    if(dp[i][A][B] == INFTY) continue;
                    dp[i+1][A+a[i]][B+b[i]] = min(dp[i+1][A+a[i]][B+b[i]], dp[i][A][B] + c[i]); // add i-th medicine
                    dp[i+1][A][B] = min(dp[i+1][A][B], dp[i][A][B]);
            }
        }
    }
    int ans = INFTY;
    for(int A=1;A<=total_a;A++){
        for(int B=1;B<=total_b;B++){
            if(A*Mb == B*Ma) ans = min(ans, dp[N][A][B]);
        }
    }

    if(ans == INFTY){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 97920
import java.util.*;
import java.io.*;
public class Main{
   public static void main(String[] main) throws Exception{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringTokenizer st = new StringTokenizer(br.readLine());
      PrintWriter out = new PrintWriter(System.out);
      int a = Integer.parseInt(st.nextToken());
      out.println(a+a*a+a*a*a);
      out.close();
   }
}

Measured memory_bytes: 32800
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (a); v < (b); ++v)
#define FORE(v, a, b) for(int v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(int v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define LLI long long int
using namespace std;
template <typename T> using V = vector<T>;
template <typename T, typename U> using P = pair<T,U>;
template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}

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

  int n; cin >> n;
  vector<int> p(n);
  REP(i,n) cin >> p[i];

  sort(ALL(p));

  p[n-1] /= 2;

  cout << accumulate(ALL(p),0) << endl;
  
  return 0;
}


Measured memory_bytes: 256
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int main(){
    int F;cin >> F;
    cout<<(F-30)/2<<endl;
}



Measured memory_bytes: 3108
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    static int lower_bound(List<Integer> list, int key) {
        int l = -1;
        int h = list.size();

        while (h - l > 1) {
            int m = (h + l) / 2;
            if (list.get(m) >= key) {
                h = m;
            } else {
                l = m;
            }
        }
        return h;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        List<Integer> l = new ArrayList<>();
        l.add(sc.nextInt());
        for (int i = 1; i < N; i++) {
            int n = sc.nextInt();
            int lbIdx = lower_bound(l, n);
            if (lbIdx == l.size()) {//key is bigger than biggest , overwrite biggest
                l.set(l.size() - 1, n);
            }else if (l.get(lbIdx) == n) {//found the same number, insert
                if (lbIdx > 0) {
                    l.set(lbIdx - 1, n);
                } else {
                    l.add(0, n);
                }
            } else {// key is smaller than lower bound
                if (lbIdx > 0) {
                    l.set(lbIdx - 1, n);
                } else {
                    l.add(0, n);
                }
            }
        }

        System.out.println(l.size());
        ;

    }

}

Measured memory_bytes: 53028
#include <iostream>
using namespace std;
int main(){
        int x,y;
        while(true){
                cin >> x >> y;
                if(x+y==0)
                        break;
                if(x>y)
                        cout << y<< " "<<x << endl;
                else
                        cout <<x<<" "<<y<<endl;
        }
        return 0;
}

Measured memory_bytes: 3044
//BISMILLAHIR RAHMANIR RAHIM
#include <bits/stdc++.h>
#define mem(a, b) (memset(a, b, sizeof(a)))
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define PI acos(-1)
#define INF 2147483647
#define MOD 1000000007
#define MAX 100005
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<int, ii> pii;
typedef vector<ii> vii;
typedef priority_queue<int,vector<int>,greater<int> > PQ;

int Set(int mask, int pos){return mask = mask | (1<<pos);}
bool check(int mask, int pos){return (bool)(mask & (1<<pos));}

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

    int n, k;

    cin>>n>>k;

    vector<int> v(n);

    for(int i = 0; i < n; i++)
        cin>>v[i];

    sort(v.begin(), v.end());

    int sum = 0;
    for(int i = 0; i < k; i++) {
        sum += v[i];
    }

    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3656
x,y = map(int,input().split())

s = [1,3,5,7,8,10,12]
s1 = [4,6,9,11]
s2 = [2]

if x in s:
    if y in s:
        print('Yes')
        exit()
elif x in s1:
    if y in s1:
        print('Yes')
        exit()
elif x in s2:
    if y in s2:
        print('Yes')
        exit()

print('No')


Measured memory_bytes: 9108
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define popb(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  int n,x=0,ans;
  string s;
  cin>>n>>s;
  ans=x;
  rep(i,0,s.size()+1){
    if(s[i]=='I')x++;
    else  x--;
    ans=max(ans,x);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256