akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;

int main() {
    int room[4][3][10] = {};
    int n, b, f, r, v;
    cin >> n;

    rep(i,n) {
        cin >> b >> f >> r >> v;
        room[b-1][f-1][r-1] += v;
    }

    rep(i,4) {
        rep(j,3) {
            rep(f,10) {
                cout << ' ' << room[i][j][f];
            }
            cout << endl;
        }
        if (i < 3) cout << "####################" << endl;
    }
}


Measured memory_bytes: 3100
import string

alphabets = {k:0 for k in string.ascii_lowercase}

while True:
  try:
    for c in input().lower():
      if alphabets.get(c) is None:
        continue
      alphabets[c] += 1
  except:
    break
for c, n in sorted(alphabets.items()):
  print("{} : {}".format(c, n))

Measured memory_bytes: 8044
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int t = sc.nextInt();
		
		String pre = "";
		int rst = 0;
		String[] s = new String[4];
		int[] u = new int[4];
		ArrayList<String> list = new ArrayList<String>();
		ArrayList<Integer> time = new ArrayList<Integer>();
		
		for(int i=0;i<n;i++){
			for(int j=0;j<4;j++) s[j] = sc.next();
			if(i!=0){
				u[0] = Integer.valueOf(s[0].substring(0, 2));
				u[1] = Integer.valueOf(s[0].substring(3, 5));
				u[2] = Integer.valueOf(pre.substring(0, 2));
				u[3] = Integer.valueOf(pre.substring(3, 5));
				rst = (u[1]-u[3]) + (u[0]-u[2])*60;
				if(rst>=t){
					list.add(s[1]);
					time.add(rst);
				}
			}
			pre = s[2];
		}
		
		System.out.println(list.size());
		for(int i=0;i<list.size();i++) System.out.println(list.get(i) + " " + time.get(i));
	}	
}

Measured memory_bytes: 17384
s = input()
a = -1
b = -1
c = -1
d = -1

for i in range(len(s)):
    if s[i] == "W":
        a = 1
    elif s[i] == "E":
        b = 1
    elif s[i] == "S":
        c = 1
    else:
        d = 1

if a * b == 1 and c * d == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc095/tasks/arc096_a
A, B, C, X, Y = read_ints()

# もし組み合わせて買ったほうがいいなら限界まで組み合わせて買う
buyed = min(X, Y)
c1 = min(A + B, 2 * C) * buyed
X -= buyed
Y -= buyed

if X:
    c2 = min(A, 2 * C) * X
elif Y:
    c2 = min(B, 2 * C) * Y
else:
    c2 = 0

print(c1 + c2)


Measured memory_bytes: 3316
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<utility>

#define INF 9999999999

using namespace std;

const int MAX_N = 101;

struct edge{
	int to;   //行き先
	int cost; //コスト
};

typedef pair<int,int>P;

int d[MAX_N];
vector<edge> edgelist[MAX_N];

void dijkstra(int s,int m)
{
	int k,l;
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = edgelist[v].begin();
		while(it != edgelist[v].end()){
			if(d[it->to] > d[v] + it->cost){
				d[it->to] = d[v] + it->cost;
				que.push(P(d[it->to],it->to));
			}
			it++;
		}
	}
}

int main()
{
	int k,l,m,n,p,q,r,s,res=0;
	scanf("%d",&n); // 点数の入力
	scanf("%d",&m); //　枝数の入力
	for(int i=0;i<m;i++){
		edge e1,e2;
		scanf("%d",&p);
		scanf("%d",&q);
		scanf("%d",&r);
		e1.to = q-1;	e1.cost = r;
		e2.to = p-1;	e2.cost = r;
		edgelist[p-1].push_back(e1);
		edgelist[q-1].push_back(e2);
	}
	for(s=0;s<n;s++){
		fill(d,d+n,INF);
		dijkstra(s,m);
		vector<edge>::iterator it = edgelist[s].begin();
		while(it != edgelist[s].end()){
			if(d[(*it).to] < (*it).cost){
				res++;
			}
			it++;
		}
	}
	cout << res / 2;
}

Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N;
  cin >> N;
  int64_t answer = 0;
  for (int64_t i = 1; i <= N; ++i) {
    if (i % 3 == 0)
      ;
    else if (i % 5 == 0)
      ;
    else
      answer += i;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>

using namespace std;

typedef long long BigInt;

int main() {
  vector<BigInt> min_n, max_n, base;
  min_n.push_back(0);
  max_n.push_back(9);
  base.push_back(1);
  while (not (min_n[base.size() - 1] <= -(1LL << 31) and max_n[base.size() - 1] <= (1LL << 31))) {
    int p = base.size();
    base.push_back(base[p - 1] * 10);
    if (p % 2 == 0) {
      max_n.push_back(max_n[p - 1] + 9 * base[p]);
      min_n.push_back(min_n[p - 1]);
    } else {
      max_n.push_back(max_n[p - 1]);
      min_n.push_back(min_n[p - 1] - 9 * base[p]);
    }
  }
  while (true) {
    BigInt n;
    int p = 0;
    string md = "";
    cin >> n;
    if (n == 0) {
      return 0;
    }
    while (not (min_n[p] <= n and n <= max_n[p])) {
      ++p;
    }
    while (p > 0) {
      for (int d = 0; d < 10; ++d) {
        BigInt r = n + (p % 2 == 0? -1: 1) * base[p] * d;
        if (min_n[p - 1] <= r and r <= max_n[p - 1]) {
          n = r;
          md += '0' + d;
          break;
        }
      }
      --p;
    }
    if (0 <= n and n < 10) {
      md += '0' + n;
    } else {
      return 1;
    }
    cout << md << endl;
  }
}

Measured memory_bytes: 1220
N, M = map(int, input().split())
*A, = map(int, input().split())

ans = 'No'
count = 0
s = sum(A)
for a in A:
    if 4 * a * M >= s:
        count += 1
        if count >= M:
            ans = 'Yes'
            break

print(ans)

Measured memory_bytes: 3060
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	ll X,Y,A,B,C;
	cin>>X>>Y>>A>>B>>C;
	multiset<ll> red,green;
	multiset<ll,greater<ll>> colorless;
	vector<ll> red1,green1;
	FORI(i,0,A)
	{
		READV(x);
		red1.pb(x);
	}
	FORI(i,0,B)
	{
		READV(x);
		green1.pb(x);
	}
	FORI(i,0,C)
	{
		READV(x);
		colorless.insert(x);
	}
	sort(red1.begin(),red1.end(),greater<ll>());
	sort(green1.begin(),green1.end(),greater<ll>());
	FORI(i,0,X)
	{
		red.insert(red1[i]);
	}
	FORI(i,0,Y)
	{
		green.insert(green1[i]);
	}
	while (sz(colorless)>0)
	{
		ll p=*colorless.begin();
		colorless.erase(colorless.begin());
		if(*red.begin()<=*green.begin() && *red.begin()<p)
		{
			red.erase(red.begin());
			red.insert(p);
		}
		else if(*red.begin()>*green.begin() && *green.begin()<p)
		{
			green.erase(green.begin());
			green.insert(p);
		}
	}
	ll ans=0;
	for(auto x:red)
	{
		ans+=x;
	}
	for(auto x:green)
	{
		ans+=x;
	}
	cout<<ans<<endl;
	
	

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


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

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

def f(x):
    sum = 0
    while x > 0:
        sum += x % 10
        x //= 10
    return sum

count = 0
for i in range(N):
    if A <= f(i+1) <= B:
        count += i+1

print(count)


Measured memory_bytes: 8932
n = int(input())
a = list(map(int, input().split()))
mod = 10**9 + 7

ans = 1
cnt = [0, 0, 0]
for i in a:
    ans *= cnt.count(i)
    for j in range(3):
        if cnt[j] == i:
            cnt[j] += 1
            break
    ans %= mod
print(ans)


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

int main() {

    int n;
    int count = 0;
    string s,t,ans;

    cin >> n >> s >> t;

    for(int i=0;i<n;i++){
        ans[count] = s[i];
        count++;
        ans[count] = t[i];
        count++;
    }

    for(int i=0;i<n*2;i++){
        cout << ans[i];
    }
}

Measured memory_bytes: 256
N=int(input())
S=input()
ans=0

for i in range(N):
    A=S[:i]
    B=S[i:]
    sum=0
    l=set()
    for j in A:
        if (j in B) and (j not in l):
            sum+=1
            l.add(j)
    ans=max(sum,ans)
print(ans)


Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
double x[10], y[10], sum, cnt;
bool viz[10];
int n, st[10];
inline void Back(int k) {
    if (k == n + 1) {
        ++cnt;
        for (int i = 2; i <= n; ++i)
            sum += sqrt((x[st[i]] - x[st[i-1]]) * (x[st[i]] - x[st[i-1]]) + (y[st[i]] - y[st[i-1]]) * (y[st[i]] - y[st[i-1]]));
        return;
    }
    for (int i = 1; i <= n; ++i)
        if (!viz[i]) {
            st[k] = i;
            viz[i] = true;
            Back(k + 1);
            viz[i] = false;
        }
}
int main() {
    DAU
    cin >> n;
    for (int i = 1; i <= n; ++i)
        cin >> x[i] >> y[i];
    Back(1);
    cout << fixed << setprecision(10) << sum / cnt;
    PLEC
}


Measured memory_bytes: 3816
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
int x;
cin>>x;
if (x<1200){
    cout << "ABC" << endl; 
}else
{
    cout << "ARC" << endl;
}







  
 
//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int sum = 0;
    for(int i = 0; i < s.length(); i++) {
        if(s[i] == '1') sum++;
    }
    cout << sum << endl;


}

Measured memory_bytes: 256
from scipy.sparse.csgraph import floyd_warshall

n, m, l = map(int, input().split())
inf = 10**12
d = [[inf for i in range(n)] for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for i in range(m):
    x,y,z = map(int,input().split())
    d[x-1][y-1] = z
    d[y-1][x-1] = z
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
dd = floyd_warshall(d)
ddd = [[inf for i in range(n)] for i in range(n)]
for i in range(n):
  for j in range(n):
    if dd[i][j] <= l:
      ddd[i][j] = 1
dddd =floyd_warshall(ddd)
q = int(input())
for i in range(q):
  s, t = map(int, input().split())
  if dddd[s-1][t-1] == inf:
    print(-1)
  else:
    print(int(dddd[s-1][t-1]-1))

Measured memory_bytes: 23640
#include <iostream>
#include <iomanip>
/*cout <<setprecision(11)<<ret<<endl;で、数字部分を計11桁表示*/
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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; }

//Shift+Command+bでデバッグ
//その後ターミナルで./a.outを実行
//入力を貼り付ける

//////////////////
//  A
/*int main(void){
    int x,a;cin>>x>>a;
    if(x<a) cout<<"0"<<endl;
    else cout<<"10"<<endl;
    return 0;
}*/
//////////////////
//  B
int main(void){
    int n,x;cin>>n>>x;
    int sum=0,cnt=1;

    rep(i,n){
        int l;cin>>l;
        sum+=l;
        if(sum>x){
            break;
        }else{
            cnt++;
        }
    }

    cout<<cnt<<endl;

    return 0;
}
//////////////////
//  C
/*int main(void){

    return 0;
}*/
//////////////////
//  D
/*int main(void){

    return 0;
}*/
//////////////////
//  E
/*int main(void){

    return 0;
}*/
//////////////////
//  F
/*int main(void){

    return 0;
}*/


Measured memory_bytes: 3592
from sys import stderr

def debug(*args):
    print(*args, file=stderr)

n_observatory_num, m_roads_num = map(int, input().split())
hi_heights = list(map(int, input().split()))

# def get_height_for(a_observaotry):
#     return hi_heights[a_observaotry+1]

ab_roads_fromto = [map(int, input().split()) for _ in range(m_roads_num)]


observatory_x_connected_to = {}

for a, b in ab_roads_fromto:
    a -= 1
    b -= 1
    if not a in observatory_x_connected_to:
        observatory_x_connected_to[a] = []
    if not b in observatory_x_connected_to:
        observatory_x_connected_to[b] = []

    observatory_x_connected_to[a].append(b)
    observatory_x_connected_to[b].append(a)

# debug(observatory_x_connected_to)

result = 0
for observatory_i, observatory_i_height in enumerate(hi_heights):
    # observatory_i_height = get_height_for(observatory_i)
    if not observatory_i in observatory_x_connected_to:
        # debug('good no connection' + str(observatory_i))
        result += 1
        continue

    good = True
    for connected_to in observatory_x_connected_to[observatory_i]:
        if observatory_i_height <= hi_heights[connected_to]:
            good = False
            # debug('not good' + str(observatory_i))
            break
    
    if good:
        # debug('good highest' + str(observatory_i))
        result += 1

print(result)


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

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	int n;
	int sum = 0;
	cin >> n;
	string s = to_string(n);
	for (int i = 0; i < s.size(); i++) {
		sum = sum + s[i] - '0';
	}

	if (n % sum == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args&&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | ";
    __f(comma + 1, args...);
}
#define pi 3.141592653589
#define MOD 1000000007
#define to() int t; cin>>t; while(t--)
#define pb push_back
#define in insert
#define mp make_pair
#define ff first
#define ss second
#define si(s) s.size()
#define fori(it,v) for(it=v.begin();it!=v.end(); it++) 
#define for1(low,high,k) for(int i=low;i<high;i+=k)
#define for11(low,high,k) for(int j=low;j<high;j+=k)
#define for2(low,high,k) for(int i=low;i<=high;i+=k)
#define rev(high,low,k)  for(int i=high;i>=low ;i-=k)
#define all(x) x.begin(), x.end()
#define fil(x,i) memset(x,i,sizeof(x));
#define setbits(x) __builtin_popcount(x)
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define read freopen("input.txt","r",stdin)
#define write freopen("output.txt","w",stdout) 
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
const int N=25+5;

int main()
{
	boost;
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif
    string s;
    cin>>s;
    int n=s.size();
    if(s[n-1]=='s') s+="es";
    else s+='s';
    cout<<s<<endl;

return 0;
}


Measured memory_bytes: 3668
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	a := sc.nextInt()
	b := sc.nextInt()
	c := sc.nextInt()

	if b-a == c-b {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i=0; i<n; i++)
#define M_PI 3.14159265358979323846
#define MOD 1000000007
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> ipair;
typedef pair<ll, ll> llpair;

int a;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    cin>>a;
    cout<<a + pow(a, 2) + pow(a, 3)<<"\n";
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
  string s;
  cin >> s;

  ll ans = 0;
  ll tmp = 0;
  for (ll i = 0; i < s.size(); ++i) {
    if (s[i] == 'A' || s[i] == 'C' || s[i] == 'G' || s[i] == 'T') tmp++;
    else {
      ans = max(ans, tmp);
      tmp = 0;
    }
  }
  ans = max(ans, tmp);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
def main():
    base_distance = int(input().rstrip())
    min_distance, max_distance = (int(i) for i in input().rstrip().split(' '))
    if (max_distance // base_distance) * base_distance >= min_distance:
        print('OK')
    else:
        print('NG')


if __name__ == '__main__':
    main()


Measured memory_bytes: 9168
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if(A <= C && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3652
K, N = map(int, input().split())

A = list(map(int, input().split()))

if len(A) == 2:
    dist = A[1] - A[0]
    if 2 * dist > K:
        dist = K - dist

minDist = float("inf")
for i in range(N-1):
    if K - (A[i+1] - A[i]) < minDist:
        minDist = K - (A[i+1] - A[i])

minDist = min(minDist, A[N-1]-A[0])

print(minDist)


Measured memory_bytes: 100688
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define MAX 1e9
 
ll modpow(ll base, ll exp, ll modulus) {base %= modulus;ll result = 1;while (exp > 0) {if (exp & 1) result = (result * base) % modulus;base = (base * base) % modulus;exp >>= 1;}return result;}
const ld pi=acos(-1);

int main(){
    IOS;
    ll n,m;cin>>n>>m;
    if(n<m)f(i,0,m)cout<<n;
    else f(i,0,n)cout<<m;
    return 0;  
} 

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

using namespace std;

int main(){
    string s1,s2,ans="YES";
    cin >> s1 >> s2;
    for(int i=0;i<3;i++){
        if(s1[i]!=s2[2-i])
        ans = "NO";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    ll n, x; cin >> n >> x;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll c = 0;
    rep(i, n) {
        if (a[i] > x) {
            c += a[i] - x;
            a[i] = x;
        }
    }
    rep(i, n-1) {
        if (a[i] + a[i+1] > x) {
            c += a[i] + a[i+1] - x;
            if (a[i+1] < a[i] + a[i+1] - x) {
                a[i+1] = 0;
                a[i] -= a[i] - x;
            } else {
                a[i+1] -= a[i] + a[i+1] - x;
            }
        }
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 1024
n, m = gets.strip.split.map(&:to_i)
abs = n.times.map { gets.strip.split.map(&:to_i) }

abs.sort! {|a, b| (b[1] <=> a[1]).nonzero? || b[0] <=> a[0]}
days = (1..m).to_a

ans = 0
abs.each do |day, reward|
    index = days.bsearch_index { |d| d >= day }
    if index
        days.delete_at(index)
        ans += reward
    end
end

puts ans

Measured memory_bytes: 13416
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <utility>

using namespace std;
#define sz size()
#define rep(i, a, n) for(int i = (a);i < (n);i++)
#define lep(i, a, n) for(int i = (a);i <= (n);i++)
//#define clr(i,n) memset(i, i+sizeof(i), n)
#define pb push_back
#define print(X) cout << (X) << endl;
typedef long long ll;
typedef pair<int, int> P;
int n, m, l;
string s, t;
//int d[100000], dp[100][100];
vector<int> d;

int check(int level, int p, int k) {
    int distP = abs(level - p);
    int distQ = abs(level - k);

    printf("d[] : %d <> %d\n", p, k);
    if (p > k)return p;

    if (distP <= distQ)return p;
    return k;
}

int levelUp(int level, int enemy, int x) {
    if (enemy >= level + x)return -1;
    int ans = max(1, x - abs(level - enemy));
    return ans;
}

bool func(int x) {
    int level = 1;
    int battle = 0;
    int enemy = 0;

//    do{
//        int *p = lower_bound(d, d+n, level);
//        int *k = p-1;
//        enemy = check(level, *p, *k);
//        int up = levelUp(level, enemy, x);
//        if(up == -1)return false;
//
//        level += up;
//        battle++;
//    }while(enemy < d[n-1]);
    if (x == 1) {
        int a = 33 + 4;
    }
    while (level + x <= d[n - 1]) {
        int p = lower_bound(d.begin(), d.end(), level) - d.begin();
        int k = p - 1;

        int enemy1 = (k < 0) ? -1 : d[k];
//        int enemy2 = (p >= n) ? ((d[p] >= level + x) ? -1 : d[p]) : -1;
        int enemy2;
        if (p >= n)
            enemy2 = -1;
        else if (d[p] >= level + x) {
            enemy2 = -1;
        } else {
            enemy2 = d[p];
        }
        if (enemy1 == -1 && enemy2 == -1) return false;

        if (enemy1 == -1) enemy = enemy2;
        else if (enemy2 == -1) enemy = enemy1;
        else {
            if (abs(enemy1 - level) < abs(enemy2 - level)) {
                enemy = enemy1;
            } else {
                enemy = enemy2;
            }
        }
        int up = max(1, x - abs(level - enemy));
        level += up;
        battle++;
    }
    battle++;
    return (battle >= m);
}

//Xをきめる
int solve() {
    int MAXX = 1e9;
    int MINX = 0;
    int ok = d[0] - 1;
    int ng = 1e9;
    int ansX = -1;
    while (ng - ok > 1) {
//        int x = (MAXX + MINX) / 2;
        int x = (ok + ng) / 2;
//        printf("X:%d\n", x);
        if (func(x)) {
            // ansX = x;
//            MINX = x;
            ok = x;
        } else {
//            MAXX = x;
            ng = x;
        }
//        getchar();
    }
//    printf("MAX = %d|MIN = %d\n", MAXX, MINX);
//    if (MAXX == 1 && !func(MAXX)) return -1;

    if (ok == d[0] - 1) return -1;
    return ok;
}

int main() {
    while (cin >> n >> m, (n + m)) {
        d.resize(n);
        rep(i, 0, n)cin >> d[i];

        print(solve());
    }
    return 0;
}




Measured memory_bytes: 3388
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>



template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WG = vector< Edges< T > >;
using UG = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

int n,k;



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

  cin>>n>>k;
  UG es(n);

  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    es[a].PB(b);
    es[b].PB(a);
  }

  vector<int> res(n,inf);

  res[0]=k;

  queue<P> q;
  q.push(P(0,0));
  while(!q.empty()){
    P p=q.front(); q.pop();
    int x=p.F;
    if(p.S==0){
      rep(i,es[x].size()){
        res[es[x][i]]=k-i-1;
        q.push(P(es[x][i],1));
      }
    }else{
      int j=0;
      rep(i,es[x].size()){
        if(res[es[x][i]]!=inf) continue;
        res[es[x][i]]=k-j-2;
        j++;
        q.push(P(es[x][i],1));
      }
    }
  }

  int ans=1;
  rep(i,n){
    ans*=res[i];
    ans%=M;
  }
  
  cout<<ans<<endl;

}


Measured memory_bytes: 8948
let [|N;K|] =
    stdin.ReadLine().Split()
    |> Array.map int
let p =
    stdin.ReadLine().Split()
    |> Array.map int

let p' =
    p
    |> Array.map (fun x -> (float(x)+1.0)/2.0)
    |> Array.scan (+) 0.0

[|0..(N-K)|]
|> Array.map (fun x -> p'.[x+K]-p'.[x])
|> Array.max
|> stdout.WriteLine

Measured memory_bytes: 50444
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		ArrayList<Integer>[] edge = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			edge[i] = new ArrayList<>();
		}
		int a, b;
		for (int i = 0; i < n - 1; i++) {
			a = sc.nextInt() - 1;
			b = sc.nextInt() - 1;
			edge[a].add(b);
			edge[b].add(a);
		}
		ArrayDeque<Integer> deque = new ArrayDeque<>();
		boolean[] memo = new boolean[n];
		int[] fen = new int[n];
		deque.add(0);
		memo[0] = true;
		while (!deque.isEmpty()) {
			int tmp = deque.poll();
			for (int i : edge[tmp]) {
				if (!memo[i]) {
					deque.add(i);
					fen[i] = fen[tmp] + 1;
					memo[i] = true;
				}
			}
		}

		deque = new ArrayDeque<>();
		memo = new boolean[n];
		int[] snuke = new int[n];
		deque.add(n-1);
		memo[n-1] = true;
		while (!deque.isEmpty()) {
			int tmp = deque.poll();
			for (int i : edge[tmp]) {
				if (!memo[i]) {
					deque.add(i);
					snuke[i] = snuke[tmp] + 1;
					memo[i] = true;
				}
			}
		}

		int fcnt = 0, scnt = 0;
		for (int i = 0; i < n; i++) {
			if (fen[i] <= snuke[i]) {
				fcnt++;
			} else {
				scnt++;
			}
		}
		System.out.println((fcnt > scnt) ? "Fennec" : "Snuke");
	}
}


Measured memory_bytes: 103048
X, Y = map(int, input().split())

if (2*X-Y)%3==0 and (2*Y-X)%3==0:
    a = (2*X-Y)//3
    b = (2*Y-X)//3
    if a>=0 and b>=0:
        MOD = 10**9+7
        n = a+b+1
        fac = [1]*(n+1)
        rev = [1]*(n+1)
        
        for i in range(1,n+1):
            fac[i] = i*fac[i-1]%MOD
            rev[i] = pow(fac[i], MOD-2, MOD)
        comb = lambda a,b:(fac[a]*rev[a-b]*rev[b])%MOD
        print(comb(a+b, a))
    else:
        print(0)
else:
    print(0)


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

class UnionFind {
public:
    vector<int> par, rank;
    UnionFind(int n);
    int root(int a);
    bool isConnect(int a, int b);
    void connect(int a, int b);
};

inline UnionFind::UnionFind(int n) {
    par.resize(n);
    rank.resize(n);
    for(int i = 0; i < n; ++i) {
        par[i] = i;
    }
}

inline int UnionFind::root(int a) {
    if(par[a] == a) return a;
    else return par[a] = root(par[a]);
}

inline bool UnionFind::isConnect(int a, int b) {
    return root(a) == root(b);
}

inline void UnionFind::connect(int a, int b) {
    a = root(a);
    b = root(b);
    if(a == b) return;
    if(rank[a] < rank[b]) {
        par[a] = b;
    } else {
        par[b] = a;
        if(rank[a] == rank[b]) rank[a]++;
    }
}

void solve() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        uf.connect(a, b);
    }
    set<int> st;
    rep(i, N) st.insert(uf.root(i));
    cout << st.size() << '\n';
}

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


Measured memory_bytes: 5760
n = int(input())

balls = [0]*n
for i in range(n):
    x, y = map(int,input().split())
    balls[i] = (x, y)


if n == 1:
    print(1)
else:
    diff = {}
    
    for i in range(n):
        for j in range(n):
            if i == j:
                continue
            vec = (balls[i][0]-balls[j][0], balls[i][1]-balls[j][1])
            if vec not in diff:
                diff[vec] = 1
            else:
                diff[vec] += 1
    
    print(n-max(diff.values()))
        

Measured memory_bytes: 9280
n = int(input())
l = [list(map(int, input().split())) for l in range(n)]
tmp = 0
ans = False
for i in range(n):
    if l[i][0] == l[i][1]:
        tmp += 1
        if tmp == 3:
            ans = True
            break
    else:
        tmp = 0
if ans:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9188
#include<iostream>
#include<vector>
#include<string.h>
using namespace std;

int h,w,s;
int cost[32][32];
int sum[33][33];
int num[32][32][32][32];
int cap[32][32][32][32];
int M;

int calc_sum(int x1,int y1,int x2,int y2){
	x1++;y1++;x2++;y2++;
	return sum[y2][x2]-sum[y2][x1-1]-sum[y1-1][x2]+sum[y1-1][x1-1];
}

typedef pair<int,int> A;

A dfs(int x1,int y1,int x2,int y2){
	if(num[y1][x1][y2][x2]>=0) return make_pair(num[y1][x1][y2][x2],cap[y1][x1][y2][x2]);
	if(calc_sum(x1,y1,x2,y2)<M) return make_pair(0,10000000);
	A res=make_pair(1,calc_sum(x1,y1,x2,y2)-M);

	for(int x=x1;x+1<=x2;x++){
		if(calc_sum(x1,y1,x,y2)<M || calc_sum(x+1,y1,x2,y2)<M) continue;
		A ans1=dfs(x1,y1,x,y2);
		A ans2=dfs(x+1,y1,x2,y2);
		A temp=make_pair(ans1.first+ans2.first,min(ans1.second,ans2.second));
		if(temp.first>res.first) res=temp;
		else if(temp.first==res.first && temp.second>res.second) res=temp;
	}

	for(int y=y1;y+1<=y2;y++){
		if(calc_sum(x1,y1,x2,y)<M || calc_sum(x1,y+1,x2,y2)<M) continue;
		A ans1=dfs(x1,y1,x2,y);
		A ans2=dfs(x1,y+1,x2,y2);
		A temp=make_pair(ans1.first+ans2.first,min(ans1.second,ans2.second));
		if(temp.first>res.first) res=temp;
		else if(temp.first==res.first && temp.second>res.second) res=temp;
	}
	num[y1][x1][y2][x2]=res.first;
	cap[y1][x1][y2][x2]=res.second;
	
	return res;
}

void solve()
{
	memset(num,-1,sizeof(num));
	memset(sum,0,sizeof(sum));
	for(int y=1;y<=h;y++){
		for(int x=1;x<=w;x++){
			int t;cin>>t; 
			cost[y-1][x-1]=t;
			sum[y][x]=sum[y][x-1];
			sum[y][x]+=cost[y-1][x-1];
		}
	}

	for(int x=1;x<=w;x++){
		for(int y=1;y<=h;y++){
			sum[y][x]+=sum[y-1][x];
		}
	}

	M=calc_sum(0,0,w-1,h-1)-s;
	A Ans=dfs(0,0,w-1,h-1);
	cout<<Ans.first<<" "<<Ans.second<<endl;
}

int main()
{
	while(cin>>h>>w>>s && !(h==0 && w==0 && s==0)){
		solve();
	}
	return 0;
}

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

using namespace std;
typedef long long ll;

const long long int MOD = 1000000007;
int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int n;
  cin >> n;
  int a[n];
  for(int i = 0;i < n;i++)
    scanf("%d", a + i);
  int prev[n];
  prev[0] = a[0] == 0 ? -1 : 0;
  for(int i = 1;i < n;i++){
    prev[i] = a[i] == 0 ? prev[i - 1] : i;
  }

  ll res = 0;
  for(int i = 0;i < n;i++){
    int x = a[i];
    res++;
    if(i){
      res += i - prev[i - 1] - 1;
      for(int j = prev[i - 1];j >= 0;j = (j ? prev[j - 1] : -1)){
        if(x & a[j])break;
        x |= a[j];
        res++;
        if(j)
          res += j - prev[j - 1] - 1;
      }
    }
  }
  cout << res;
}



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

int main() {
	int n, k;
	cin >> n >> k;
	int a[100000];
	for (int i = 0;i < k;i++)cin >> a[i];
	sort(a, a + k);
	reverse(a, a + k);
	if (k == 1) {
		cout << a[0] - 1 << endl;
		return 0;
	}
	for (int i = 1;i < n&&a[0]>0;i++) {
		a[0] -= a[i];
	}
	if (a[0] <= 0) {
		cout << 0 << endl;
	}
	else {
		cout << a[0] - 1 << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))

sums = [0] * (N + 1)
xors = [0] * (N + 1)
for i in range(1, N + 1):
    sums[i] = sums[i - 1] + A[i - 1]
    xors[i] = xors[i - 1] ^ A[i - 1]

ans = 0
for i in range(N):
    l = i
    r = N
    while l + 1 < r:
        m = (l + r) // 2
        if sums[m + 1] - sums[i] == xors[m + 1] ^ xors[i]:
            l = m
        else:
            r = m
    ans += l - i + 1
print(ans)

Measured memory_bytes: 35768
#include <stdio.h>

int main(void)
{
	char cup1, cup2;
	int ball[3] = {1, 0, 0};
	int temp;
	
	while (scanf("%c,%c", &cup1, &cup2) != EOF){
		cup1 -= 'A';
		cup2 -= 'A';
		
		temp = ball[cup1];
		ball[cup1] = ball[cup2];
		ball[cup2] = temp;
	}
	
	if (ball[0] == 1){
		printf("A\n");
	}
	else if (ball[1] == 1){
		printf("B\n");
	}
	else {
		printf("C\n");
	}
	
	return (0);
}

Measured memory_bytes: 0
#Train Ticket
A, B, C, D = input()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
if A+B+C+D == 7:
    print(str(A) + "+" + str(B) + "+" +str(C)+"+"+str(D)+"=7")
elif A+B+C-D == 7:
    print(str(A)+"+"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A+B-C+D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
elif A+B-C-D == 7:
    print(str(A)+"+"+str(B)+"-"+str(C)+"-"+str(D)+"=7")
elif A-B+C+D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"+"+str(D)+"=7")
elif A-B+C-D == 7:
    print(str(A)+"-"+str(B)+"+"+str(C)+"-"+str(D)+"=7")
elif A-B-C+D == 7:
    print(str(A)+"-"+str(B)+"-"+str(C)+"+"+str(D)+"=7")
else:
    print(str(A)+"-"+str(B)+"-"+str(C)+"-"+str(D)+"=7")

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

vector<long long int> a;
vector<vector<long long int>> dp;

long long int f(int left, int right){
    if(dp[left][right] != 0) return dp[left][right];
    if(left == right)        return dp[left][right] = a[left];

    return dp[left][right] = max(a[left]  - f(left+1, right  ), 
                                 a[right] - f(left,   right-1));
}

int main(){
    int n;
    cin >> n;
    a.resize(n);
    dp.resize(n, vector<long long int>(n));

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

    cout << f(0,n-1) << endl;
    return 0;
}

Measured memory_bytes: 70912
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
	FAST_IO
	
	LL N, A, B, complete;
	cin >> N >> A >> B;
	complete = N / (A + B);
	N -= complete * (A + B);
	
	cout << complete * A + min(A, N) << "\n";
	
	return 0;
}


Measured memory_bytes: 256
local n,k=io.read("n","n")
if k==0 then
    print(n*n)
else
    local sum=0
    for i=1,n do
        sum=sum+math.max(0,i-k)*(n//i)+math.max(0,n%i-k+1)
    end
    print(sum)
end

Measured memory_bytes: 2756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a;i<(int)b;++i)
int main(){
  string s,t;cin>>s>>t;
  sort(s.begin(),s.end());
  sort(t.rbegin(),t.rend());
  if(s<t)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
from heapq import *
N, M, S = map(int, input().split())
graph = [[] for _ in range(N)]
amax = 0
for i in range(M):
  u, v, a, b = map(int, input().split())
  u -= 1
  v -= 1
  graph[u].append([v, a, b])
  graph[v].append([u, a, b])
  amax = max(amax, a)
  
lcoins = amax * (N-1)
  
cost = list()
time = list()
for _ in range(N):
  c, d = map(int, input().split())
  cost.append(c)
  time.append(d)

INF = float('INF')
M = 2500
if(S >= M):
  S = M-1

dist = [[INF] * M for _ in range(N)]
dist[0][S] = 0
q = [(0, S, 0)]

while q:
  dv, num, v = heappop(q)
  
  if dist[v][num] < dv:
    continue
    
  if num + cost[v] < M and dv + time[v] < dist[v][num+cost[v]]:
    dist[v][num+cost[v]] = dv + time[v]
    heappush(q, (dv+time[v], num+cost[v], v))
    
  for next, a, b in graph[v]:
    if num >= a and dv+b < dist[next][num-a]:
      dist[next][num-a] = dv+b
      heappush(q, (dv+b, num-a, next))
      
for i in range(1,N):
  print(min(dist[i]))

Measured memory_bytes: 26156
#include<iostream>
#include<map>
#include<algorithm>
#define int long long
using namespace std;
map<int,int>memo;
int a,b,c,d;
int dfs(int n){
	if(n==0)
		return 0;
	if(n==1)
		return d;
	if(memo.count(n))
		return memo[n];
	int l2=(n/2)*2;
	int r2=((n+1)/2)*2;
	int l3=(n/3)*3;
	int r3=((n+2)/3)*3;
	int l5=(n/5)*5;;
	int r5=((n+4)/5)*5;
	int res=1e18;
	if(n<res/d)
		res=n*d;
	res=min(res,llabs(l2-n)*d+a+dfs(l2/2));
    res=min(res,llabs(r2-n)*d+a+dfs(r2/2));
    res=min(res,llabs(l3-n)*d+b+dfs(l3/3));
    res=min(res,llabs(r3-n)*d+b+dfs(r3/3));
    res=min(res,llabs(l5-n)*d+c+dfs(l5/5));
    res=min(res,llabs(r5-n)*d+c+dfs(r5/5));
    memo[n]=res;
    return res;
}
signed main(){
	int t;
	cin>>t;
	while(t--){
		memo.clear();
		int n;
		cin>>n>>a>>b>>c>>d;
		cout<<dfs(n)<<endl;
	}
}

Measured memory_bytes: 4388
X = int(input())
lis = [1]
blflag = False

for i in range(X):

    i += 2

    cnt = 2
    while True:

        if i ** cnt <= X:
            lis.append( i ** cnt )

        elif cnt == 2:
            blflag = True
            break

        else:
            break

        cnt += 1

    if blflag:
        break

lis.sort()

print (lis[-1])
    


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int r;
	cin >> r;
	cout << r*r << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>
#include <bitset>

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
  int n;
  cin >> n;

  vector<int> vl(n, 0), cl(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> vl[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> cl[i];
  }

  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (vl[i] - cl[i] > 0) {
      sum += vl[i] - cl[i];
    }
  }
  cout << sum << endl;
  return 0;
}


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


int main(){int N, K; 
cin >> N >> K;
long ans;
if(K % 2 == 1){
    ans = pow(N / K, 3);
}
else{
    ans = pow(N / K, 3) + pow(N / (K / 2) - N / K, 3);
}

cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MAX(a, b)  a>b?a:b
#define MIN(a, b)  a<b?a:b

int main()
{
	int n, k;

	cin >> k >> n;

	int first;
	int cur=0, prev=0;
	int max_dist=0, dist=0;

	cin >> first;
	prev = first;

	for(int i=1 ; i < n ; i++) {
		cin>>cur;
		max_dist = MAX(max_dist, cur-prev);
		prev = cur;
	}

	dist = first + k - cur;
	max_dist = MAX(max_dist, dist);

	cout<<k-max_dist<<endl;

	return 0;
}


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

using namespace std;

#define NMAX 1000

const double PI=atan2(0.0,-1.0);

int main(){

	double ansx[NMAX+1],ansy[NMAX+1];
	double x,y;
	double sita;

	x=0,y=0;
	for(int i=1;i<=NMAX;i++){
		sita=atan2(y,x)+PI/2;
		x=x+cos(sita);
		y=y+sin(sita);
		ansx[i]=-1*x;
		ansy[i]=y;
	}

	int n;

	while(1){

		cin>>n;
		if(n==-1) break;
		cout<<ansy[n]<<endl;
		cout<<ansx[n]<<endl;

	}

}

Measured memory_bytes: 1336
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    S = ST()
    print(S.count("ABC"))
if __name__ == '__main__':
    main()

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

typedef long long ll;
typedef pair <ll, int> pii;

const int MAXN = 2e5 + 5;
const ll INF = 1e18;

int N;
int a[MAXN];
int lower[MAXN], upper[MAXN];
ll suff[MAXN];
ll cum[MAXN], cumcum[MAXN];
stack <int> rig;
stack <pii> lft;

void load() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
}

int div2(int x) {
	if (x >= 0 || !(x % 2))
		return x / 2;
	return (x - 1) / 2;
}

ll solve() {
	for (int i = 1; i < N; i++) {
		double tmp = log2((double)a[i] / a[i + 1]);
		lower[i] = div2(ceil(tmp) + 1);
		upper[i] = div2(floor(tmp));
	}
	
	for (int i = 1; i <= N; i++)
		cum[i] = cum[i - 1] + lower[i - 1];
	
	for (int i = 1; i <= N; i++)
		cumcum[i] = cumcum[i - 1] + cum[i];
		
	rig.push(N + 1);
	cum[N + 1] = -INF;
	for (int i = N; i; i--) {
		while (!rig.empty() && cum[rig.top()] > cum[i])
			rig.pop();
		suff[i] = cumcum[rig.top() - 1] - cumcum[i] - (rig.top() - i - 1) * cum[i] + suff[rig.top()];
		rig.push(i);
	}
	
	ll sol = 2 * suff[1], pref = 0, sum = 0;
	for (int i = 1; i <= N; i++) {
		pref += upper[i - 1];
		int len = 1;
		for (; !lft.empty() && lft.top().first > pref; lft.pop()) {
			sum += (ll)lft.top().second * (lft.top().first - pref);
			len += lft.top().second;
		}
		lft.push({pref, len});
		sol = min(sol, 2 * sum + i + 2 * suff[i + 1]);
	}
	
	return sol;
}

int main() {
	load();
	printf("%lld\n", solve());
	return 0;
}

Measured memory_bytes: 10496