akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    final Scanner scanner = new Scanner(System.in);

    scanner.nextLine();
    final String[] a = scanner.nextLine().split(" ");
    Map<Integer, Long> counts = new HashMap<>();
    long sum = 0;
    for (int i = 0; i < a.length; i++) {
      final int num = Integer.parseInt(a[i]);
      counts.put(
          num,
          counts.getOrDefault(num, 0L) + 1
      );
      sum += num;
    }

    final int q = scanner.nextInt();
    final int[][] bc = new int[q][2];

    for (int i = 0; i < q; i++) {
      bc[i][0] = scanner.nextInt();
      bc[i][1] = scanner.nextInt();

      final long replaceCount = counts.getOrDefault(bc[i][0], 0L);
      counts.put(
          bc[i][1],
          counts.getOrDefault(bc[i][1], 0L) + replaceCount
      );
      counts.remove(bc[i][0]);

      sum += replaceCount * (bc[i][1] - bc[i][0]);

      System.out.println(sum);
    }
  }
}


Measured memory_bytes: 77160
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
using namespace std;
int x,y,z;
int main()
{
	scanf("%d %d %d",&x,&y,&z);
	printf("%d\n",min(x*y,z));
	return 0;
}



Measured memory_bytes: 256
<?php
//error_reporting(0);
//$S = trim(fgets(STDIN));
list($H,$W) =  explode(" ",trim(fgets(STDIN)));
list($h,$w) =  explode(" ",trim(fgets(STDIN)));
//$A = explode(" ",trim(fgets(STDIN)));

for($i=0;$i<$H;$i++) {
  $box[$i]=str_pad("",$W,"0");
}
for($i=0;$i<$h;$i++) {
  $box[$i]=str_pad("",$W,"1");
}
for($i=0;$i<$H;$i++) {
  for($j=0;$j<$w;$j++) {
    $box[$i][$j]="2";
  }
}
$ret=0;
for($i=0;$i<$H;$i++) {
  $ret += substr_count($box[$i],"0");
}
printf("%d\n",$ret);


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

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if ((100 * r + 10 * g + b) % 4  == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 504
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


############ ---- Input Functions ---- ############
def in_int():
    return (int(input()))


def in_list():
    return (list(map(int, input().split())))


def in_str():
    s = input()
    return (list(s[:len(s) - 1]))


def in_ints():
    return (map(int, input().split()))


k, n  = in_ints()
a = in_list()

mx = 0
ans = 0
for i in range(n):
    next = 0
    if i == n-1:
        next = k + a[0]
    else:
        next = a[i+1]

    mx = max(mx, abs(a[i]- next))
    ans  += abs(a[i]- next)


print(ans - mx)

Measured memory_bytes: 25880
#include<stdio.h>

int main(void){
  int N;

  scanf("%d", &N);
  while(N%4!=0 && N>0){
    N -= 7;
  }
  if(N<0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}


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

struct action {
	int type;
	int num;
};
struct room {
	vector<int>edges;
	vector<int>switches;
	room():edges(), switches(){
	}
};
vector<action> memo[1 << 15][15];
int N, M;
bool cangoal = false;

struct aa {
	int now;
	bitset<15>lights;
	int time;
};
class Compare {
public:
	bool operator ()(const aa&l, const aa&r) {
		return  l.time > r.time;
	}
};

int main() {
	while (1) {
		
		queue<aa>que;
		cin >> N >> M;
		if (!N)break;
		vector<room>rooms(N);
		{
			cangoal = false;
			for (int i = 0; i < (1 << 15); ++i) {
				for (int j = 0; j < 15; ++j) {
					memo[i][j] = vector<action>();
				}
			}
			
			for (int i = 0; i < M; ++i) {
				int s, t; cin >> s >> t;
				s--; t--;
				rooms[s].edges.push_back(t);
				rooms[t].edges.push_back(s);
			}
			bitset<15>lights;
			for (int i = 0; i < N; ++i) {
				int l; cin >> l;
				lights[i] = l;
				assert(lights[0] == 1);
			}
			for (int i = 0; i < N; ++i) {
				int k; cin >> k;
				for (int j = 0; j < k; ++j) {
					int r; cin >> r;
					r--;
					rooms[i].switches.push_back(r);
				}
				sort(rooms[i].switches.begin(), rooms[i].switches.end());
			}
			que.push(aa{ 0,lights,0 });
		}
		vector<action>ans;
		while (!que.empty()) {
			aa atop(que.front());
			que.pop();
			if (atop.now == N - 1) {
				cangoal = true;
				if (atop.lights.count() == 1) {
					ans = memo[atop.lights.to_ulong()][atop.now];
					break;
				}
			}
			for (auto next : rooms[atop.now].edges) {
				if (atop.lights[next]) {
					if (memo[atop.lights.to_ulong()][next].empty()) {
						memo[atop.lights.to_ulong()][next] = memo[atop.lights.to_ulong()][atop.now];
						memo[atop.lights.to_ulong()][next].push_back(action{ 2,1 + next });
						que.push(aa{ next,atop.lights,atop.time+1 });
					}
				}
			}
			for (auto sw : rooms[atop.now].switches) {
				if (sw == atop.now)continue;
				bitset<15>nextlights(atop.lights);
				nextlights[sw] = !atop.lights[sw];
				if (memo[nextlights.to_ulong()][atop.now].empty()) {
					memo[nextlights.to_ulong()][atop.now] = memo[atop.lights.to_ulong()][atop.now];
					memo[nextlights.to_ulong()][atop.now].push_back(action{ !nextlights[sw],sw+1 });
					que.push(aa{ atop.now,nextlights,atop.time + 1 });
				}
			}
		}
		if (ans.empty()) {
			if (cangoal) {
				cout << "You can not switch off all lights." << endl;
			}
			else {
				cout << "Help me!" << endl;
			}
		}
		else {
			cout << "You can go home in " <<ans.size() << " steps." << endl;
			for (auto a : ans) {
				if (a.type == 0) {
					cout << "Switch on room " << a.num << "." << endl;
				}
				else if (a.type == 1) {
					cout << "Switch off room " << a.num <<"." << endl;
				}
				else {
					cout << "Move to room " << a.num << "." << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 31724
X,N=map(int,input().split())
P=list(map(int,input().split()))

minv=110
v=0

if X in P:
  for i in range(200):
    if not(i in P):
      if abs(X-i) < minv:
        minv=abs(X-i)
        v=i
else:
  v=X
       

print(v)


Measured memory_bytes: 9212
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int N, K;
	cin >> N >> K;
	
	const ll mod = 1e9 + 7;
	ll dp[100001] = {};
	dp[0] = 1;

	rep(i, N) {
		int a;
		cin >> a;

		rep1(j, K) dp[j] += dp[j - 1];

		auto are = dp - a - 1;
		for (int j = K; j > a; j--) {
			dp[j] -= are[j];
		}

		rep1(j, K) dp[j] %= mod;
	}

	co((dp[K] + mod) % mod);

	Would you please return 0;
}

Measured memory_bytes: 1024
N, K = map(int, input().split())
A = list(map(int, input().split()))
INF = (10 ** 6)*500

M = sum(A)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort(reverse=True)
    return divisors

T = make_divisors(M)

ans = INF
for t in T:
    p = []
    for a in A:
        p.append(a - a//t * t)
    p.sort()
    s, w = 0, 0
    for h in p:
        if s + h <= K:
            s += h
        else:
            w += t - h
    if s >= w:
        ans = t
        break

print(ans)


Measured memory_bytes: 42732
#include <iostream>
#include <cmath>
#define ull unsigned long long

using namespace std;

int main() {
  ull n, d,c=0;
  cin>>n>>d;
  for(ull i=0;i<n;++i)
  {
    ull x,y;
    cin>>x>>y;
    c+=sqrt(x*x+y*y)<=d;
  }
  cout<<c<<'\n';
}

Measured memory_bytes: 3664
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N, K = MAP()
	R, S, P = MAP()
	T = input().rstrip()

	Tokuten = [R, S, P]
	Te = ['r', 's', 'p']

	A = [-1] * N
	for i in range(N):
		now = 0 if T[i]=='s' else 1 if T[i]=='p' else 2
		if i-K < 0:
			A[i] = now
		else:
			past = A[i-K]
			if now == past:
				if i+K < N:
					future = 0 if T[i+K]=='s' else 1 if T[i+K]=='p' else 2
					for j in range(3):
						if not j in [now, future]:
							A[i] = j
			else:
				A[i] = now
	
	# print(A)

	ans = 0
	for i in range(N):
		te = A[i]
		if te==0 and T[i]=='s':
			ans += Tokuten[0]
		elif te==1 and T[i]=='p':
			ans += Tokuten[1]
		elif te==2 and T[i]=='r':
			ans += Tokuten[2]

	print(ans)

if __name__ == '__main__':
	main()

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

ans = 0
for i, a in enumerate(A):
    if a >= B[i]:
        ans += B[i]
        a -= B[i]
        if a >= B[i+1]:
            ans += B[i+1]
            B[i+1] = 0
        else:
            ans += a
            B[i+1] -= a
    else:
        ans += a

print(ans)




Measured memory_bytes: 19116
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			
			int N = scan.nextInt();
			long[]a= new long[N];
			long goukei = 1;
			long S = (long)1e18;
			
			for(int i = 0;i<N;i++) {
				a[i] = scan.nextLong();
				
				if(a[i]==0) {
					System.out.println(0);
					System.exit(0);
				}
			}
			
			BigDecimal ans = new BigDecimal(1);
			BigDecimal jou = new BigDecimal(S);
			
		
			
			for(int i = 0;i<N;i++) {
				ans = ans.multiply(new BigDecimal(a[i]));
				int p = ans.compareTo(jou);
				
				if(p>0) {
					System.out.println(-1);
					System.exit(0);
				}
				
			}
			
			
			
			System.out.println(ans.longValue());
			
			
			
			
			
			
			
			
			
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 61760
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    stack<int> S1;
    stack<P> S2;
    char ch;
    int sum=0;
    for(int i=0;cin>>ch;i++){
        if(ch=='\\') S1.push(i);
        else if(ch=='/' && S1.size() > 0){
            int j = S1.top();S1.pop();
            sum += i - j;
            int a = i - j;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push({j,a});
        }
    }
    vector<int> ans;
    while(S2.size()){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(),ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    REP(i,ans.size()){
        cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;
}


Measured memory_bytes: 3272
N = int(input())
strList = []
for i in range(N):
  strList.append(input())

count = 0

dict = {}

for i in range(N):
  charList = list(strList[i])
  charList.sort()
  key = "".join(charList)
  if not key in dict:
    dict[key] = 1
  else:
    dict[key] += 1  

# dictが持つvalue値を要素にfor文で回す
count = 0;
for v in dict.values():
  count += (v * (v-1) // 2)
print(count)
 

Measured memory_bytes: 24976
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd(a, b):
    if a == 0:
        return b
    if b == 0:
        return a

    if a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = gcd(ret, nums.pop())
    return ret


def solve(inputs):
    [S] = string_to_int(inputs[0])
    current = S
    appeared_set = {current}
    i = 1
    while 1:
        i += 1
        if current % 2 == 0:
            current /= 2
        else:
            current = 3 * current + 1

        if current in appeared_set:
            return i

        appeared_set.add(current)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)


Measured memory_bytes: 3436
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def main():
    C = []
    for i in range(3):
        C.append(input())
    print(C[0][0] + C[1][1] + C[2][2])

if __name__ == '__main__':
    main()


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	int N;
	cin >> N;
	vi a(N),b(N);
	rep(i,N){
		cin >> a[i] >> b[i];
	}
	#define all(v) v.begin(), v.end()
	sort(all(a)); sort(all(b));
	double left, right;
	if(N%2==1){
		left = a[N/2];
		right = b[N/2];
		cout << (int)(right - left + 1) << endl;
	}
	else{
		// 2で割った数を考える代わりに、割る前を数える
		left = (a[N/2] + a[(N/2 - 1)]);
		right = (b[N/2] + b[(N/2 - 1)]);
		cout << (int)(right - left + 1) << endl;
	}
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

Measured memory_bytes: 6360
import math
s = 0
K= int(input())

for i in range(1,K+1):
    for j in range(i,K+1):
        temp = math.gcd(i,j)
        for k in range(1,K+1):
            s += math.gcd(temp,k)
s = s*2

for i in range(1,K+1):
    temp = math.gcd(i,i)
    for k in range(1,K+1):
        s -= math.gcd(temp,k)

print(s)

Measured memory_bytes: 9208
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	double t, x;
	cin >> t >> x;
	cout << t / x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int pay = sc.nextInt();
        int len = sc.nextInt();
        boolean[] disable = new boolean[10];
        for (int i = 0; i < len; i++) {
            disable[sc.nextInt()] = true;
        }
        sc.nextLine();

        int base = 1;
        while (base < 100000) {
            if (base <= pay && disable[(pay % (base * 10)) / base]) {
                pay += base - (pay % base);
                base = 1;
            } else {
                base *= 10;
            }
        }
        System.out.println(pay);
    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  vector<int> c(a);
  lp(i,a){
    cin>>b.at(i);
    c.at(i)=b.at(i);
  }
  sort(c.begin(), c.end());
  reverse(c.begin(), c.end());
  lp(i,a){
    if(c.at(0)==b.at(i))cout<<c.at(1)<<endl;
    else cout<<c.at(0)<<endl;
  }
}

Measured memory_bytes: 3200
#include <stdio.h>
int main(void)
{
	int x, i;
	for (i = 1; i <= 10000; i++)
	{
		scanf("%d", &x);
		if (x == 0)
		{
			return 0;
		}
		printf("Case %d: %d\n", i, x);
	}
	return 0;
}

Measured memory_bytes: 2620
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef long double f3;
int la;
ll alp[]={2,3,5,7,11,13,17,19,23,29},a[233];
ll ch(ll x,ll y,ll p) {
	x%=p, y%=p; return (x*y-ll((f3(x)*y+0.5)/p)*p+p)%p;
}
ll qp(ll x,ll y,ll p) {ll re=1;for(;y;y>>=1,x=ch(x,x,p))if(y&1)re=ch(re,x,p);return re;}
ll gcd(ll x,ll y) {return y?gcd(y,x%y):x;}
bool check(ll a,ll n,ll r,ll s) {
	ll x=qp(a,r,n),lst=x;
	int i;
	for(i=1;i<=s;i++,lst=x) {
		x=ch(x,x,n);
		if(x==1&&lst!=1&&lst!=n-1) return 0;
	}return x==1;
}
bool MR(ll n) {
	ll r=n-1,s=0;
	for(;!(r&1);r>>=1,s++) ;
	int i;
	for(i=0;i<8;i++) {
		if(alp[i]==n) return 1;
		if(!check(alp[i],n,r,s)) return 0;
	}return 1;
}
ll PR(ll n,ll c) {
	ll x=rand()%(n-1),y=x,p;
	for(p=1;p==1;) {
		x=(ch(x,x,n)+c)%n, y=(ch(y,y,n)+c)%n, y=(ch(y,y,n)+c)%n;
		p=gcd(x>y?x-y:y-x,n);
	}return p;
}
void solve(ll n) {
	if(n<=1) return ;
	if(!(n&1)) {
		a[++la]=2; while(!(n&1)) n>>=1;
	}
	if(n<=1) return ;
	if(MR(n)) {a[++la]=n; return ;}
	ll t=n;
	for(;t==n;t=PR(n,rand()%(n-1)));
	solve(t);
	while(n%t==0) n/=t; 
	solve(n);
}
ll n,K,mod,ans;
ll qp2(ll x,ll y) {ll re=1;x%=mod;for(;y;y>>=1,x=x*x%mod) if(y&1) re=re*x%mod; return re;}
ll g(ll x) {return qp2(K,((x+1)>>1));}
ll h(ll x) {return ((x&1)?x:(x>>1))%mod;}
void dfs(int dep,ll now,ll mud) {
	if(dep==la+1) {
		if(((n/now)&1)&&(!(now&1))) return ;
		ans=(ans+g(n/now)*h(n/now)%mod*mud)%mod;
		return ;
	}
	dfs(dep+1,now,mud);
	mud=mud*(mod+1-a[dep]%mod)%mod;
	ll nxt=now*a[dep];
	for(;n%nxt==0;) {
		dfs(dep+1,nxt,mud); nxt=nxt*a[dep];
	}
}
int main() {
		ans=0;
		scanf("%lld%lld",&n,&K);
  mod=1000000007;
		la=0; solve(n);
		sort(a+1,a+la+1); la=unique(a+1,a+la+1)-a-1;
		dfs(1,1,1);
		printf("%lld\n",(ans+mod)%mod);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,A,B,C,D;
cin>>N;
A = N/1000;
N=N-A*1000;
B=N/100;
N=N-B*100;
C=N/10;
D=N-C*10;
if(B==C&&(A==B||C==D)){
cout<<"Yes";
}
else{
cout<<"No";
}
}

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

int main(){
    int S,W;
    cin >> S >> W;
if(S <= W){
    cout << "unsafe" << endl;
}else{
    cout << "safe" << endl;
    }
}

Measured memory_bytes: 3612
import collections
def f(l):
    res=[]
    l,res=res,l
    for i in range(len(res)):
        c=collections.Counter(res[i])
        for j in range(len(c)+1):
            l.append(res[i]+chr(97+j))
    return l

n=int(input())
if n==1:
    print("a")
else:
    ans=["a"]
    i=1
    while i<n:
        ans=f(ans)
        i+=1
    for i in range(len(ans)):
        print(ans[i])

Measured memory_bytes: 13276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll n,a,b; cin>>n>>a>>b;
	ll ans=n/(a+b);
	ans*=a;
	ll k = n%(a+b);
	ans+=min(k,a);
	cout<<ans;
	
	
	return 0;
}


Measured memory_bytes: 256
//https://atcoder.jp/contests/code-thanks-festival-2017-open/tasks/code_thanks_festival_2017_h
#include <iostream>
#include <vector>
#include <limits>
#include <numeric>
//cut begin
template<typename T>
struct PotentializedUnionFind{
private:
    private:
    std::vector<int> par;
    std::vector<int> size;
    std::vector<T> diff;
public:
    PotentializedUnionFind(int n){
        par.resize(n);
        std::iota(par.begin(),par.end(),0);
        size.resize(n);
        std::iota(size.begin(),size.end(),0);
        diff.assign(n,0);
    }

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

    T potential(int x){
        root(x);
        return diff[x];
    }

    T potential_diff(int x,int y){
        return potential(y)-potential(x);
    }

    bool same(int x,int y){//0-indexed
        return root(x)==root(y);
    }

    void unite(int x,int y,T w){//0-indexed,potential(y)-potential(x)=w
        w+=potential(x);
        w-=potential(y);
        
        x=root(x);
        y=root(y);
        if(x==y)return;

        if(size[x]<size[y]){
            par[x]=y;
            size[y]+=size[x];
            diff[x]=-w;
        }
        else{
            par[y]=x;
            size[x]+=size[y];
            diff[y]=w;
        }
    }
};
//cut end

int solve(){
    int n,m;
    std::cin>>n>>m;
    if(n==0&&m==0)return 1;
    PotentializedUnionFind<long long> pu(n);
    for (int i = 0; i < m; ++i){
        char c;
        std::cin>>c;
        int x,y,z;
        std::cin>>x>>y;
        --x;--y;
        if(c=='!'){
            std::cin>>z;
            pu.unite(x,y,z);
        }
        else{
            if(pu.same(x,y))std::cout<<pu.potential_diff(x,y)<<std::endl;
            else std::cout<<"UNKNOWN"<<std::endl;
        }
    }
    return 0;
}

int main(){
    while(solve()==0);
    return 0;
}


Measured memory_bytes: 5192
#include <iostream>
#include <algorithm>
#include <string>
#include <limits.h>
#include <vector>
#include <numeric>

using namespace std;

vector<pair<long long int, long long int>> getPrimeElements(long long int num) {

	long long int firstnum = num;

	vector<pair<long long int, long long int>> result;
	pair<long long int, long long int> wk;

	if (num % 2 == 0) {
		wk.first = 2;
		wk.second = 0;
		while (num % 2 == 0) {
			wk.second++;
			num /= 2;
		}

		result.push_back(wk);
	}

	long long int waru = 3;

	while (true) {

		if (num % waru == 0) {
			wk.first = waru;
			wk.second = 0;
			while (num % waru == 0) {
				wk.second++;
				num /= waru;
			}

			result.push_back(wk);
		}
		waru += 2;

		if (waru * waru > num) break;

	}

	if (num != 1) {
		wk.first = num;
		wk.second = 1;
		result.push_back(wk);

	}

	return result;
}


int getKeta(int num) {

	if (num == 0)return 1;

	int res = 0;

	while (num > 0) {
		num /= 10;
		res++;
	}

	return res;
}

vector<int> bunkai(int num) {

	string str = to_string(num);
	vector<int> res;

	for (int i = 0; i < str.size(); i++) {
		int a = str[i] - '0';
		res.push_back(a);
	}

	return res;

}


int main()
{
    
	long long int q, h, s, d;
	cin >> q >> h >> s >> d;

	long long int n;
	cin >> n;
	n *= 4;

	vector<pair<long long int, long long int>> a;
	pair<long long int, long long int> wk;
	
	wk.first = 1;
	wk.second = q;
	a.push_back(wk);

	wk.first = 2;
	wk.second = h;
	a.push_back(wk);

	wk.first = 4;
	wk.second = s;
	a.push_back(wk);

	wk.first = 8;
	wk.second = d;
	a.push_back(wk);

	bool flg = true;
	while (flg) {

		flg = false;

		for (int i = 0; i < 4 - 1; i++) {
			if ((a[i].second * 8) / a[i].first > (a[i+1].second * 8) / a[i+1].first) {
				wk = a[i];
				a[i] = a[i + 1];
				a[i + 1] = wk;
				flg = true;
			}
		}
	}

	long long int ans = 0;

	for (int i = 0; i < a.size(); i++) {

		ans += (n / a[i].first) * a[i].second;
		n %= a[i].first;

	}


	cout << ans << endl;




	return 0;

}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in);) {
            new Main().solve(sc);
        }
    }

    void solve(Scanner sc) {
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int max = Math.max(a, Math.max(b, c));

        if (a == max) {
            System.out.println(b * c / 2);
            return ;
        } else if (b == max) {
            System.out.println(a * c / 2);
            return;
        } else {
            System.out.println(a * b / 2);
            return;
        }
    }
}


Measured memory_bytes: 23380
/*
 * status: AC
 */
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

vector<vector<ll>> find(vector<ll> &A, int s, int t) {
	ll sum = A[t] - A[s];
	int u = upper_bound(A.begin() + s, A.begin() + t, A[s] + sum / 2) - A.begin();
	int l = u - 1;
	vector<vector<ll>> res;
	if(l > s) {
		vector<ll> tmp(2);
		tmp[0] = A[l] - A[s];
		tmp[1] = A[t] - A[l];
		res.push_back(tmp);
	}
	if(u < t) {
		vector<ll> tmp2(2);
		tmp2[0] = A[u] - A[s];
		tmp2[1] = A[t] - A[u];
		res.push_back(tmp2);
	}

	return res;
}

ll solve(vector<ll> &A, int p) {
	int N = A.size()-1;
	auto v1 = find(A, 0, p);
	auto v2 = find(A, p, N);

	ll res = (ll) 1e18;
	for(auto u1: v1) {
		for(auto u2: v2) {
			vector<ll> tmp = u1;
			tmp.insert(tmp.end(), ALL(u2));
			sort(ALL(tmp));
			res = min(res, tmp.back() - tmp.front());
		}
	}
	return res;
}

signed main(){
	int N;
	cin >> N;
	vector<ll> A(N+1);
	for(int i = 1; i <= N; ++i) {
		cin >> A[i];
		A[i] += A[i-1];
	}

	ll res = (ll)1e18;
	for(int i = 2; i < N; ++i) {
		res = min(res, solve(A, i));
	}
	cout << res << endl;

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin>>N;
	int a[N];
	for(int i=0; i<N; i++){
		cin>>a[i];
	}
	int cnt=0;
	for(int i=0; i<N; i++){
	cnt++;
	while(i+1<N&&a[i]==a[i+1]){i++;}
	if(a[i]<a[i+1]){
		while(i<N-1&&a[i]<=a[i+1]){
			i++;
		}
	}
	else{
		while(i<N-1&&a[i]>=a[i+1]){
			i++;
		}
	}
}
	cout<<cnt<<endl;

}


Measured memory_bytes: 640
a , b , c , d , e , f = map(int,input().split())
midp = [-1 for i in range(f+1)]
mizu = []
midp[0] = 0
for i in range(f+1):
    if midp[i] != -1:
        if i + a*100 <= f and midp[i+a*100] != 0:
            midp[i+a*100] = 0
            mizu.append(i+a*100)
        if i + b*100 <= f and midp[i+b*100] != 0:
            midp[i+b*100] = 0
            mizu.append(i+b*100)
ans = 0
cou = [a*100,0]
for i in mizu:
    sai = i*e//100
    sadp = [-1 for f in range(sai+1)]
    sadp[0] = 0
    maxsa = 0
    for j in range(sai+1):
        if sadp[j] != -1:
            if j + c <= sai and i + j + c <= f and sadp[j+c] != 0:
                sadp[j+c] = 0
                maxsa = max(maxsa,j+c)
            if j + d <= sai and i + j + d <= f and sadp[j+d] != 0:
                sadp[j+d] = 0
                maxsa = max(maxsa,j+d)
    if ans < maxsa/(i+maxsa):
        ans = maxsa/(i+maxsa)
        cou = [i+maxsa,maxsa]

print(*cou)

Measured memory_bytes: 9328
#include<iostream>
#include<algorithm>
typedef long long lint;
using namespace std;

lint mmax(lint a,lint b,lint c)
{
	b=max(b,c);
	a=max(a,b);
	return a;
}

lint mmin(lint a,lint b,lint c)
{
	b=min(b,c);
	a=min(a,b);
	return a;
}

int main()
{
	int H,W;
	lint sa,sb,sc;
	lint ans=1e18;
	
	cin >> H >> W;
	
	for(lint h=1;h<H;h++)
	{
		sa=h*W;
		
		sb=(H-h)*(W/2);
		sc=(H-h)*(W-W/2);
		ans=min(ans,mmax(sa,sb,sc)-mmin(sa,sb,sc));
		
		sb=((H-h)/2)*W;
		sc=(H-h-((H-h)/2))*W;
		ans=min(ans,mmax(sa,sb,sc)-mmin(sa,sb,sc));
	}
	swap(H,W);
	for(lint h=1;h<H;h++)
	{
		sa=h*W;
		
		sb=(H-h)*(W/2);
		sc=(H-h)*(W-W/2);
		ans=min(ans,mmax(sa,sb,sc)-mmin(sa,sb,sc));
		
		sb=((H-h)/2)*W;
		sc=(H-h-((H-h)/2))*W;
		ans=min(ans,mmax(sa,sb,sc)-mmin(sa,sb,sc));
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 205
#define inf ((int)1e9+10)
#define int long long
using namespace std;
int n,m,r,graph[maxn][maxn],ans=inf;
vector<int> v,a;
main()
{
	cin>>n>>m>>r;
	for(int i=0;i<r;i++)
	{
		int x;
		cin>>x;
		--x;
		v.push_back(x);
	}
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
		{
			if(i==j)
				graph[i][i]=0;
			else
				graph[i][j]=inf;
		}
	for(int i=0;i<m;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		--a,--b;
		graph[a][b]=graph[b][a]=c;
	}
	for(int k=0;k<n;k++)
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				graph[i][j]=min(graph[i][j],graph[i][k]+graph[k][j]);
	for(int i=0;i<r;i++)
		a.push_back(i);
	do
	{
		int sum=0;
		for(int i=1;i<r;i++)
			sum+=graph[v[a[i]]][v[a[i-1]]];
		ans=min(ans,sum);
	}while(next_permutation(a.begin(),a.end()));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main(){
	 
	int n;
	
	while( cin >> n ) {
		
	if( n == 0)
	break;
		
	int x, y, h, z; 
	int sum = 0;
		
	while(n--) {
		
		cin >> x >> y >> h >> z;
		
		int xyh = x + y + h;
		
		if( xyh <= 60 && z <= 2)
		sum += 600;
		
		else if( xyh <= 80 && z <= 5)
		sum += 800;
		
		else if( xyh <= 100 && z <= 10)
		sum += 1000;
		
		else if( xyh <= 120 && z <= 15)
		sum += 1200;
		
		else if( xyh <= 140 && z <= 20)
		sum += 1400;
		
		else if( xyh <= 160 && z <= 25)
		sum += 1600;
	}
	
	cout << sum << "\n";
}
  	return 0;
}


Measured memory_bytes: 2996
def solve(n,a)
  # コーナーケース
  if n == 0
    return 1 if a[0] == 1
    return -1
  end
  
  # これより下の層の葉の数
  b = Array.new(n+1,0)
  n.downto(1) do |i|
    b[i-1] = b[i] + a[i]
  end
  
  v = 1 # 頂点数
  ans = 1
  n.times do |d|
    return -1 if v < a[d]
    nv = (v - a[d]) * 2
    v = [nv, b[d]].min
    ans += v
  end
  return -1 if v != a[n]
  return ans
end

n = gets.to_s.to_i
a = gets.to_s.split.map { |v| v.to_i }
puts solve(n,a)


Measured memory_bytes: 21472
#include<stdio.h>

int main(void){
    int n,i,j,cnt;
    scanf("%d",&n);
    cnt = n;
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        for(j=0;j<i;j++){
            if(a[j]==a[i]){
                --cnt;
                break;
                //printf("%d\n",a[j]);
            }
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

const int bound = 314159;
bool ok[bound];
bool flag = false;

int main(){
	int n, x; cin >> n >> x;
	if( n == 2 ){
		if( x == 1 || x == 3 ){
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl << 1 << endl << 2 << endl << 3 << endl; 
		}
		return 0;
	}
	if( 1 < x && x < 2*n-1 ){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
		return 0;
	}
	fill_n( ok, bound, true );
	if( x == 2*n-2 ) flag = true;
	if( flag ){
		ok[x-2] = ok[x] = ok[x+1] = ok[x-1] = false;
	} else {
		ok[x+2] = ok[x] = ok[x-1] = ok[x+1] = false;
	}
	vector<int> a;
	for( int k = 1; k <= 2*n-1; ++k ){
		if( ok[k] ) a.push_back(k);
	}
	auto itr = a.begin();
	for( int k = 1; k <= 2*n-1; ++k ){
		if( k == n-1 ){
			cout << ( (flag) ? x-2 : x+2 ) << endl;
		} else if( k == n ) {
			cout << x << endl;
		} else if( k == n+1 ){
			cout << ( (flag) ? x+1 : x-1 ) << endl;
		} else if( k == n+2 ){
			cout << ( (flag) ? x-1 : x+1 ) << endl;
		} else {
			cout << (*itr) << endl;
			++itr;
		}
	}
	return 0;
}

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

using namespace std;

int peper[15][15];

void paint(int x, int y)
{
	if (0 <= x && 0 <= y && x <= 9 && y <= 9)	peper[y][x]++;
}

int main()
{
	int x, y;
	int size;
	
	while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
		peper[y][x]++;
		paint(x, y - 1);
		paint(x, y + 1);
		paint(x - 1, y);
		paint(x + 1, y);

		if (size > 1){
			paint(x + 1, y - 1);
			paint(x + 1, y + 1);
			paint(x - 1, y + 1);
			paint(x - 1, y - 1);
		}
		if (size > 2){
			paint(x, y - 2);
			paint(x, y + 2);
			paint(x - 2, y);
			paint(x + 2, y);
		}
	}
	int dark = 0;
	int blank = 0;
	
	for (int i = 0; i < 10; i++){
		for (int j = 0; j < 10; j++){
			if (peper[i][j] == 0)	blank++;
			dark = max(dark, peper[i][j]);
		}
	}
	printf("%d\n%d\n", blank, dark);
	return (0);
}

Measured memory_bytes: 1188
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};

fn main() {
  let a = read::<i32>();
  let b = read::<i32>();
  let c = read::<i32>();

  let max_v = max(10 * a + b + c, max(10 * b + a + c, 10 * c + b + a));

  println!("{}", max_v);
}



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

int main(){
    int N;
    cin >>N;
    int A[N];
    for(int i =0; i < N; i++){
        cin >> A[i];
    }
    int temp = 0;
    for(int i =0; i < N - 1; i++){
        for(int j = i + 1; j < N; j++){
            if(abs(A[i]-A[j]) >temp) temp =abs(A[i]-A[j]);
        }
    }
    cout << temp << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int f = 0;
    int cnt = N;
    while(true)
    {
        f += cnt % 10;
        if(cnt / 10 == 0)
        {
            break;
        }
        else
        {
            cnt /= 10;
        }
    }
    if(N % f == 0)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int h=0;
	h += n % 10;
	h += (n % 100) / 10;
	h += (n % 1000) / 100;
	h += (n % 10000) / 1000;
	h += (n % 100000) / 10000;
	h += (n % 1000000) / 100000;
	h += (n % 10000000) / 1000000;
	h += (n % 100000000) / 10000000;
	if (n%h == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

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

int main(){
    int N;
    cin >> N;
    double result = 0;
    double A;

    for (size_t i = 0; i < N; i++)
    {
        cin >> A;
        result += 1 / A;
    }

    cout << 1 / result << endl;

    
}

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


double table[100000];
double cusum[100000];

signed main() {
    int n,k;
    cin >> n >> k;

    vector<double> a(n);
    rep(i,n) cin >> a[i];

    table[0] = 0;
    table[1] = 1;
    for(int i = 2; i < 100000; i++){
        table[i] = table[i-1] + i;
    }
    for(int i = 0; i < n; i++){
        a[i] = table[(int)a[i]] / a[i];
    }
    cusum[0] = a[0];
    for(int i = 1; i < n; i++){
        cusum[i] = cusum[i-1] + a[i];
    }

    double ans = 0;
    for(int i = k - 1; i < n; i++){
        if(i == k - 1) ans = cusum[i];
        else ans = max(ans,cusum[i] - cusum[i - k]);
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	vector<int> c(n, 0);
	rep(i, m){
		int a, b;
		cin >> a >> b;
		a--; b--;
		if(a == 0){
			if(c.at(b) == 0) c.at(b) = 1;
			else{
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}else if(b == 0){
			if(c.at(a) == 0) c.at(a) = 1;
			else{
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}else if(a == n-1){
			if(c.at(b) == 0) c.at(b) = 1;
			else{
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}else if(b == n-1){
			if(c.at(a) == 0) c.at(a) = 1;
			else{
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

x = I()

if(x >= 400 and x < 600):
    result = 8
elif(x < 800):
    result = 7
elif(x < 1000):
    result = 6
elif(x < 1200):
    result = 5
elif(x < 1400):
    result = 4
elif(x < 1600):
    result = 3
elif(x < 1800):
    result = 2
else:
    result = 1

print(result)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a, b, c; cin >> a >> b >> c;

	if (a % 2 && b % 2 && c % 2) cout << min({a*b,a*c,b*c}) << endl;
	else cout << 0 << endl;


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    if (A<=5){
        cout << 0 << endl;
    }else if(A<=12){
        cout << B/2 << endl;
    }else{
        cout << B << endl;
    }

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int n;
  cin >> n;
  vector<int> k(101,0);
  if(n<=9){
    cout << 0 << endl;
    return 0;
  }
  rep(i,n-1){
    int y=i+2;
    int u=2;
    while(y>1){
      while(y%u==0){
        y/=u;
        k[u]++;
      }
      u++;
    }
  }
  int ans=0;
  int ka=0,kb=0,kc=0,kd=0,ke=0;
  rep(i,99){
    int w=i+2;
    if(k[w]>=2)ka++;
    if(k[w]>=4)kb++;
    if(k[w]>=14)kc++;
    if(k[w]>=24)kd++;
    if(k[w]>=74)ke++;
  }
  //cout << ka << kb << kc << kd << ke << endl;
  ans+=(ka-2)*kb*(kb-1)/2+(ka-1)*kd+ke+(kb-1)*kc;
  cout << ans << endl;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;

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

    int a_sum = accumulate(a.begin(), a.end(), 0);

    int res = 0;
    for (int i = 1; i < n; i++) {
        if (abs(n * a[res] - a_sum) > abs(n * a[i] - a_sum)) {
            res = i;
        }
    }

    cout << res << endl;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(void){
    int a,b;
    int sum,i;
    
    while(scanf("%d %d", &a, &b) != EOF){
        i = 0;
        sum = a + b;
        while(sum > 0){
            sum /= 10;
            i++;
        }
        
        printf("%d\n", i);
    }
    return 0;

}

//Ctrl???d??§??\????????????

Measured memory_bytes: 600
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a,b;
int f[510][510];
int main()
{
	scanf("%d%d",&a,&b);
	for(int i=1;i<=50;i++)
	for(int j=1;j<=100;j++)
	f[i][j]=1;
	a--,b--;
	for(int i=1;i<=49;i+=2)
	{
		if(a==0) break;
		for(int j=1;j<=99;j+=2)
		{
			f[i][j]=0;
			a--;
			if(a==0) break;
		}
	}
	for(int i=52;i<=100;i+=2)
	{
		if(b==0) break;
		for(int j=1;j<=99;j+=2)
		{
			f[i][j]=1;
			b--;
			if(b==0) break;
		}
	}
	printf("100 100\n");
	for(int i=1;i<=100;i++)
	{
		for(int j=1;j<=100;j++)
		if(f[i][j]==0) putchar('.');
		else putchar('#');
		puts("");
	}
}

Measured memory_bytes: 384
#include <stdio.h>

int main()
{
	int n, m, i, d, a[10000], s=0;
	scanf("%d %d", &n, &m);
	for (i = 0;i < m;i++)
	{
		scanf("%d", &a[i]);
		s = s + a[i];
	}
	if (s <= n)
	{
		d = n - s;
		printf("%d", d);
	}
	else
		printf("-1");
	return 0;
}

Measured memory_bytes: 1744
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		boolean flag = false;
		for (int i = 0; i < 3; i++) {
			if (n.charAt(i) == '7') {
				flag = true;
				break;
			}
		}
		if (flag) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 35620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define  int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
#define sz(x) (int)(x.size())
#define ff first
#define ss second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
inline ll gcd(ll a,ll b){if(a==0) return b;return gcd(b%a,a);}
inline ll power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p*p)%m;if(n%2) return (p*a)%m;else return p;}
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int k;
    cin>>k;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    if(k==1)
    {
        cout<<0<<endl;
        
        return 0;
    }
    map<int,int>mp;
    mp[0]=1;int s=0,x,ans=0;int vl[n];
    for(int i=0;i<=min(n-1,k-2);i++)
    {
        s=s+a[i];
        x=(s%k-(i+1)%k+k)%k;
        x=(x+k)%k;
        ans=ans+mp[x];
        mp[x]++;
        vl[i]=x;
    }
    int cr=0;
    mp[0]--;
    for(int i=k-1;i<n;i++)
    {
        
        s=s+a[i];
        x=(s%k-(i+1)%k+k)%k;
        x=(x+k)%k;
        ans=ans+mp[x];
        mp[x]++;
        vl[i]=x;
        mp[vl[cr]]--;
        cr++;
    }
   // cout<<endl;
    cout<<ans<<endl;
        return 0;
}


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

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

    vector<int> a;
    for (int i = s.find('1'); i < n; ) {
        int j = i;
        while (j < n && s[j] == '1') j++;
        a.push_back(j-i);
        i = j + 1;
    }
    int m = a.size();
    int dp[m+1][4];
    memset(dp, 0, sizeof dp);
    for (int i = m-1; i > 0; i--) {
        dp[i][0] = dp[i+1][2];
        dp[i][1] = (a[i] == 0 ? dp[i+1][0] :
                    max({a[i]-1+dp[i+1][1],
                                a[i] + dp[i+1][0],
                                dp[i+1][2]}));
        dp[i][2] = (a[i] == 0 ? dp[i+1][0] :
                    a[i-1] == 0 ? dp[i][0] :
                    max({a[i-1] + dp[i+1][3],
                                a[i]-1+dp[i+1][1],
                                a[i]+dp[i+1][0]}));
        dp[i][3] = (a[i-1] == 0 ? -(1<<30) :
                    a[i-1] == 1 ? dp[i][0] :
                    a[i] == 0 ? dp[i+1][0] :
                    // a[i-1] == 2 ? dp[i][1] :
                    max({a[i-1]-1+dp[i+1][3],
                                a[i]-1+dp[i+1][1],
                                a[i]+dp[i+1][0]}));
    }
    cout << dp[1][2] << endl;
}


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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n; cin >> n;
  vector<int> d(n);
  for(int i=0;i<n;++i) {
    cin >> d[i];
    d[i] = min(d[i], 24 - d[i]);
  }
  sort(d.begin(), d.end());
  // printv(d);
  vector<int> t(n+1);
  t[n] = 0;
  bool now = 0;
  for(int i=0;i<n;++i) {
    if(now) {
      t[i] = d[i];
    } else {
      t[i] = 24 - d[i];
    }
    now = !now;
  }
  
  sort(t.begin(), t.end());
  
  // printv(t1);
  // printv(t2);

  int mi = INF;

  for(int i=0;i<n+1;++i) {
    for(int j=i+1;j<n+1;++j) {
      mi = min(mi, min(abs(t[i] - t[j]), 24 - abs(t[i] - t[j])));
    }
  }

  cout << mi << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //a
  int x, y;
  cin >> x >> y;
  int a[222] = {};
  a[0] = 300000;
  a[1] = 200000;
  a[2] = 100000;
  x--;
  y--;
  cout << a[x] + a[y] + (x == 0 && y == 0 ? 400000 : 0) << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int n;
    cin>>n;
    ll int h[n];
    ll int i;ll int dp[n];
    for(i=0;i<n;i++)
    	cin>>h[i];
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    for(i=2;i<n;i++)
    	dp[i]=min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]));
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 5208
#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
#define int long long
typedef pair<int, int> P;
vector<P> v;
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    int A[100010];
    rep(i, N) cin >> A[i];
    int sum = 0;
    int S = 0;
    rep(i, N) S += A[i];
    rep(i, N / 2) sum += A[i];
    int L = N % 2 == 0, R = N / 2;
    while(R < N) {
        int tmp = (A[L] + A[R]) / 2;
        //cout << tmp << " " << sum << endl;
        v.push_back({tmp, sum});
        sum -= A[L], sum += A[R];
        L += 2, R += 1;
    }
    while(Q--) {
        int X; cin >> X;
        P p = {X, 0};
        auto itr = upper_bound(v.begin(), v.end(), p);
        if(itr == v.end()) itr--;
        cout << S - itr->second << endl;
        //cout << itr->first << " " << S - itr->second << endl;
    }


    return 0;
}
// X < 5
// 1 2 3 4
// 1 3 5 7 9 11 13 15 17
// .       .
// X = 5
// 4 2 1 3
// 1 3 5 7 9 11 13 15 17
// .       .   
// X = 6
//
//   3 1 2 4
// 1 3 5 7 9 11 13 15 17
//     .      .

// X = 8
//   4 3 2 1 
// 1 3 5 7 9 11 13 15 17
//     .      .   

// X = 9
//   4   2 1 3
// 1 3 5 7 9 11 13 15 17
//     
//   4   3 2 1
// 1 3 5 7 9 11 13 15 17
//         .     .

//   4   3   1  2
// 1 3 5 7 9 11 13 15 17

//   4   3   2     1
// 1 3 5 7 9 11 13 15 17


// 1 2 3
// 2 4 8 16 32 64

// X == 10
// 3 2 1
// 2 4 8 16 32 64

// X == 11
// 3   1 2
// 2 4 8 16 32 64
//   .    .
// X == 24
// 3   2 1
// 2 4 8 16 32 64
//       .  .
// X == 25
// 3   2    1   
// 2 4 8 16 32 64

Measured memory_bytes: 3444