akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n,q,b[100010];
long long a[100010],t;
vector<long long> v;
int main(){
	cin>>n>>t>>q;
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
		if(i)if(b[i-1]==1&&b[i]==2)v.push_back((a[i-1]+a[i])/2);
	}
	while(q--){
		cin>>n;n--;
		int k=lower_bound(v.begin(),v.end(),a[n])-v.begin();
		if(b[n]==1){
			if(k==v.size())cout<<a[n]+t<<endl;
			else cout<<min(a[n]+t,v[k])<<endl;
		}
		else {
			if(k==0)cout<<a[n]-t<<endl;
			else cout<<max(a[n]-t,v[k-1])<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 4436
n, m = gets.split.map &:to_i
s = Array.new(n,false)
t = []
m.times{
	a, b = gets.split.map &:to_i
	s[b-1] = true if a == 1
	t << a-1 if b == n
}

puts t.any?{|x|s[x]} ? "POSSIBLE" : "IMPOSSIBLE"

Measured memory_bytes: 4220
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

long long height(int cx, int cy, vector<vector<long long>> &points){
  int j;
  for (j=0; j < points.size(); j++){
    if (points[j][2] != 0) break;
  }
  long long hgt = abs(points[j][0] - cx) + abs(points[j][1] - cy) + points[j][2];
  long long htmp;
  long long ret = hgt;
  for (int i=0; i < points.size(); i++){
    htmp = max(hgt - abs(points[i][0] - cx) - abs(points[i][1] - cy), (long long)0);
    if (points[i][2] != htmp){
		ret = -1;
      	break;
    }
  }
  return ret;
}
      

int main(){
  long long N, x, y, h, ans, cx, cy;
  cin >> N;
  vector<vector<long long>> points;
  for (int i=0; i<N; i++){
    cin >> x >> y >> h;
    points.push_back(vector<long long>({x, y, h}));
  }
  for (cx = 0; cx <= 100; cx++){
    for (cy = 0; cy <= 100; cy++){
      ans = height(cx, cy, points);
      if (ans > -1) break;
    }
    if (ans > -1) break;
  }
  
  cout << cx << " " << cy << " " << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <variant>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x) begin(x),end(x)

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,k;
  cin>>n>>k;
  vector<vecint> a(61, vecint(n));
  REP(i,n) {
    cin>>a[0][i];
    --a[0][i];
  }
  REP(i,60) {
    REP(j,n) {
      a[i+1][j] = a[i][a[i][j]];
    }
  }
  int cur = 0;
  REP(i,60) {
    if ((k>>i)&1) {
      cur = a[i][cur];
    }
  }
  cout<<(cur+1)<<endl;
  return 0;
}


Measured memory_bytes: 51776
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000007;

int main () {

    int N, M, R;
    scanf("%d %d %d", &N, &M, &R);

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

    int map[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            map[i][j] = ((i == j)? 0 : INF);
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        a--; b--;
        map[a][b] = map[b][a] = min(map[a][b], c);
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (map[i][k] < INF && map[k][j] < INF) {
                    map[i][j] = min(map[i][k] + map[k][j], map[i][j]);
                }
            }
        }
    }

    sort(r, r + R);

    int ans = INF;
    do {
        int cost = 0;
        for (int i = 1; i < R; i++) {
            cost += map[r[i-1]][r[i]];
        }
        ans = min(ans, cost);
    } while (next_permutation(r, r + R));

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int n, a, b;
    std::cin>>n>>a>>b;

    int sum = 0;
    for(int i = 1;i <= n;i++){
        int d = [](int k) -> int {
                int res = 0;
                while(k > 0){
                    res += k % 10;
                    k /= 10;
                }
                return res;
        }(i);
        if(a <= d && d <= b){
            sum += i;
        }
    }
    std::cout<<sum<<std::endl;
    return 0;
}

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

int main() {
   int n,a,b;
   cin >> n >> a >> b;
   int ans=0;
   for(int i=1;i<=n;i++){
      int c=i,sum=0;
      while(c){
         sum+=c%10;
         c/=10;
      }
      if(sum>=a&&sum<=b)
      ans+=i;
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<set>

using namespace std;
string s,t;
set<string> S;

void Work()
{
    int lens=s.size();
    int lent=t.size();
    for(int i=0;i<lens;i++)
    {
        if(s[i]=='?'||s[i]==t[0])
        {
            string tmp=s;
            for(int j=0;j<i;j++)
                if(tmp[j]=='?')
                    tmp[j]='a';
            bool can=false;
            for(int j=0;j<lent;j++)
            {

                if(tmp[i+j]!='?'&&tmp[i+j]!=t[j])
                    break;
                tmp[i+j]=t[j];
                if(j == lent - 1) can = true;
            }
            if(can)
            {
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size()==0) cout<<"UNRESTORABLE"<<endl;
    else cout<<*S.begin()<<endl;
}
int main()
{
    cin>>s>>t;
    Work();
    return 0; 
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

type Dice = (Int, Int, Int, Int, Int, Int)

topd :: Dice -> Int
topd (a, _, _, _, _, _) = a

frontd :: Dice -> Int
frontd (_, b, _, _, _, _) = b

rightd :: Dice -> Int
rightd (_, _, c, _, _, _) = c

spinl :: Dice -> Dice
spinl (a, b, c, d, e, f) = (a, d, b, e, c, f)

spinr :: Dice -> Dice
spinr (a, b, c, d, e, f) = (a, c, e, b, d, f)

moven :: Dice -> Dice
moven (a, b, c, d, e, f) = (b, f, c, d, a, e)

moves :: Dice -> Dice
moves (a, b, c, d, e, f) = (e, a, c, d, f, b)

movee :: Dice -> Dice
movee (a, b, c, d, e, f) = (d, b, a, f, e, c)

movew :: Dice -> Dice
movew (a, b, c, d, e, f) = (c, b, f, a, e, d)

move :: Char -> Dice -> Dice
move 'N' = moven
move 'S' = moves
move 'E' = movee
move 'W' = movew

allMoves :: Dice -> [Dice]
allMoves d = concatMap spins $ map ($d) [id, moven, moves, movee, movew, moven . moven]
  where
    spins x = [x, spinl x, spinr x, spinl (spinl x)]

normalize :: Dice -> Dice
normalize = minimum . allMoves

makeDice [a, b, c, d, e, f] = (a, b, c, d, e, f)

main = do
    dices <- allMoves . makeDice . map read . words <$> getLine
    n <- readLn
    replicateM_ n $ do
        [t, f] <- map read . words <$> getLine
        print $ rightd $ head $ filter (\d -> topd d == t && frontd d == f) dices



Measured memory_bytes: 4004
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep1(n) rep2(i,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
int main(){
    ll a,b,ans=0;
    cin>>a;
    ll n=1000;
    for(int i=0;i<4;i++){
        b=a/n;
        if(b==2)ans++;
        a=a%n;
        n=n/10;
    }
    cout << ans<<endl;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] numberList = new long[n];
		BigInteger answer = BigInteger.ONE;
		for(int i = 0;i < n;i++) {
			long number = sc.nextLong();
			if(number == 0) {
				System.out.println(0);
				return;
			}
			numberList[i] = number;

		}

		for(int i =0;i < n;i++) {

			answer = answer.multiply(new BigInteger(String.valueOf(numberList[i])));
			if(answer.compareTo(new BigInteger(String.valueOf((long)Math.pow(10, 18)))) >=1) {
				System.out.println(-1);
				return;
			}
		}

		System.out.println(answer);
	}

}

Measured memory_bytes: 61992
// C# program to build the smallest number 
// by removing n digits from a given number 
using System;
using System.Collections.Generic;
using System.Linq;
class GFG
{
    static List<string> list = new List<string>(new string[] { "7", "5", "3" });
    public static void Main(String[] args)
    {
        ////var t = int.Parse(Console.ReadLine());
        ////while (t > 0)
        //{
        //    var input = Console.ReadLine().Split(' ');
        //    var n = int.Parse(input[0]);
        //    var k = int.Parse(input[1]);
        //    List<int> coll = new List<int>();
        //    for (int i = 0; i < n; i++)
        //    {
        //        coll.Add(int.Parse(Console.ReadLine()));
        //    }
        //    // var arr = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();
        //    // MAXXor(n, k, arr);
        //    ChrimasEve(n, k, coll);

        Console.WriteLine(Solve(long.Parse(Console.ReadLine())));
        Console.WriteLine();

    }

    static long Solve(long n)
    {
        return DFS("", n);
    }
    public static long DFS(string s, long n)
    {
        long res = 0;

        if (!string.IsNullOrEmpty(s))
        {
            if (Sheck(s, n))
            {
                res++;
            }
            else if (long.Parse(s) > n)
                return 0;
        }

        foreach (var next in list)
        {
            res += DFS(s + next, n);
        }
        return res;
    }

    private static bool Sheck(string s, long n)
    {
        long sl = long.Parse(s);
        if (sl > n)
        {
            return false;
        }
        if (!s.Contains("3") || !s.Contains("5") || !s.Contains("7"))
        {
            return false;
        }
        return true;
    }

}



Measured memory_bytes: 13268
from collections import deque
N = int(input())
A = list(map(int, input().split()))

L = [(10**18, 10**18, 10**18)] * (N + 1)
left = 0
right = 0
que = deque([])
for i, a in enumerate(A, start=1):
    right += a
    que.append(a)
    while len(que) > 1 and abs(right - left) > abs((right - que[0]) - (left + que[0])):
        q = que.popleft()
        left += q
        right -= q
    L[i] = (abs(left - right), left, right)

R = [(10**18, 10**18, 10**18)] * (N + 1)
left = 0
right = 0
que = deque([])
for i, a in enumerate(A[::-1], start=1):
    right += a
    que.append(a)
    while len(que) > 1 and abs(right - left) > abs((right - que[0]) - (left + que[0])):
        q = que.popleft()
        left += q
        right -= q
    R[i] = (abs(left - right), left, right)

# for i in range(1, N + 1):
#     L[i] = min(L[i], L[i - 1])
#     R[i] = min(R[i], R[i - 1])

R = R[::-1]

ans = 10**18
for mid in range(1, N):
    X = [L[mid + 1][1], L[mid + 1][2], R[mid + 1][1], R[mid + 1][2]]
    if min(X) == 0:
        continue
    ans = min(ans, max(X) - min(X))
print(ans)


Measured memory_bytes: 142980
import math

n,m,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
b = [0] + list(map(int,input().split()))

for i in range(1,n+1):
    a[i] += a[i-1]
for i in range(1,m+1):
    b[i] += b[i-1]
ans = 0
b_cnt = m
for a_cnt in range(len(a)):
    if a[a_cnt] > k:
        break
    
    while a[a_cnt] + b[b_cnt] > k:
        b_cnt -= 1
    
    ans = max(ans, a_cnt + b_cnt)

print(ans)

Measured memory_bytes: 42056
import java.util.Scanner;


public class Main {
    public static class UnionFindTree {
        private int[] parent;
        public UnionFindTree(int n) {
            parent = new int[n];
            for(int i = 0; i < n; i++) {
                parent[i] = i;
            }
        }

        public int root(int a) {
            if (parent[a] == a) {
                return a;
            } else {
                int b = root(parent[a]); //圧縮経路
                parent[a] = b;
                return b;
            }
        }

        public void union(int a, int b) {
            int aa = root(a);
            int bb = root(b);
            if ( aa == bb) return;
            parent[aa] = bb;
        }

        public boolean same(int a, int b) {
            return root(a) == root(b);
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int M = scanner.nextInt();
        int[] p = new int[N];
        for(int i = 0; i < N; i++) {
            p[i] = scanner.nextInt() - 1;
        }

        UnionFindTree ut = new UnionFindTree(N);
        for(int j = 0; j < M; j++) {
            ut.union(scanner.nextInt() - 1, scanner.nextInt() - 1);
        }

        int ret = 0;
        for(int i = 0; i < N; i++) {
            if(ut.same(i, p[i])) ret++;
        }
        System.out.println(ret);
    }
}


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

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9+7;

const i64 INF = 1e18+7;


signed main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    vector<int> a(n);
    vector<int> b(m);
    for(auto& y : a)
        cin >> y;
    for(auto& y : b)
        cin >> y;
    int s = *max_element(a.begin(), a.end()) + 1;
    int t = *min_element(b.begin(), b.end());
    for(int i = s; i <= t; ++i){
        if(x < i && i <= y){
            cout << "No War" << endl;
            return 0;
        }
    }
    cout << "War" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>

#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define repa(X,A,Y) for (int (X) = A;(X) <= (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const ll MAX_PRIME = 1e6+100;
ll N, P;
bool prime[MAX_PRIME];

void init_prime(ll p) {
  memset(prime, true, sizeof(prime));

  for (ll i = 2; i*i <= p; ++i) {
    if (prime[i] == true) {
      for (ll j = 2; i*j*i*j <= p; ++j) {
        prime[i*j] = false;
      }
    }
  }
}

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

  cin >> N >> P;

  if (N == 1) {
    cout << P << endl;
    return 0;
  }

  init_prime(P);


  ll ans = 1;
  for (ll i = 2; i*i <= P; ++i) {
    if (prime[i] && P%i == 0) {
      ll tmp = 0;
      while (P%i == 0) {
        P /= i;
        ++tmp;
      }

      while (tmp/N > 0) {
        ans *= i;
        tmp -= N;
      }
    }
  }

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


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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}


int main() {
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, ans =0;
	char c;
	cin >>c;

	cout << char(c+1) <<"\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>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pf push_front
#define mp make_pair
#define mt make_tuple
#define popb pop_back
#define popf pop_front
#define int long long int
#define vi         vector<int>
#define vll        vector<ll>
#define vpii       vector<pair<int,int>>
#define vpll       vector<pair<ll,ll>>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(container) int((container).size())
#define rep(i,a,b) for(i=a;i<b;i++)
#define tr(container,it)   for(auto it = container.begin(); it != container.end(); it++)
#define present(container, element) (container.find(element) != container.end())      //set,map etc.
#define cpresent(container, element) (find(all(container),element) != container.end())    //vector
#define hell 1000000007
#define PI 3.14159265
#define mod 998244353
#define fs first
#define sc second
#define TIME        cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";
void solve()
{
  int n,k,i,j;
  cin>>n>>k;
  int a[n],dp[n];
  rep(i,0,n)cin>>a[i];
  dp[0]=0;
  if(k>n)
  {
    for(i=1;i<n;i++)
    {
      dp[i]=INT_MAX;
      for(j=i-1;j>=0;j--)
      dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
    }
    cout<<dp[n-1];
    return;
  }
  for(i=1;i<=k;i++)
    {
      dp[i]=INT_MAX;
      for(j=i-1;j>=0;j--)
      dp[i]=min(dp[j]+abs(a[i]-a[j]),dp[i]);
    }
  for(i=k+1;i<n;i++)
  {
    dp[i]=INT_MAX;
    for(j=i-1;j>=i-k;j--)
    {
      dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
    }
  }
  cout<<dp[n-1];
}
signed main()
{
  fastio
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  int t;
  t=1;
  //cin>>t;
  while(t--)
  solve();
  TIME
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{   
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    vint sum(N+1);
    REP(i,N) sum[i+1]=sum[i]+a[i];

    map<int,int> cnt;
    REP(i,N+1) cnt[sum[i]]++;

    int ans=0;
    for(auto p:cnt){
        int x=p.second;
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 15872
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;
	cin>>n;
	ll arr[n];
	ll sum=0;
	for(ll i=0;i<n;i++)
		{
			cin>>arr[i];
			sum+=arr[i];
		}

	ll table[n+1][n+1];

	for(ll k=0;k<n;k++)
	{
		for(ll i=0,j=k;j<n;i++,j++)
		{
			if(k==0)
			{
				table[i][j]=arr[i];
			}
			else
			if(k==1)
			{
				table[i][j]=max(arr[i],arr[j]);
			}
			else
			{
				ll x=((i+2)<=j)?table[i+2][j]:0;
				ll y=((i+1)<=(j-1))?table[i+1][j-1]:0;
				ll z=(i<=(j-2))?table[i][j-2]:0;

				table[i][j]=max(arr[i]+min(x,y),arr[j]+min(y,z));
			}
		}
	}

	cout<<(2*table[0][n-1]-sum)<<endl;
	return 0;
}

Measured memory_bytes: 70144
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define POS(i,j) ((i)*11+(j))

int cmp(char *s,char *t){
  int i;
  for(i=0;s[i]!='\0' && t[i]!='\0';i++) if(s[i]!=t[i]) return 0;
  return s[i]==t[i];
}

void run(void){
  int n;
  scanf("%d",&n);
  char s[1100];
  int i;
  for(i=0;i<n;i++) scanf("%s",s+POS(i,0));
  for(i=1;i<n;i++){
    int last=0;
    while(s[POS(i-1,last)]!='\0') last++;
    if(s[POS(i-1,last-1)]!=s[POS(i,0)]){
      printf("No\n");
      return;
    }
  }
  for(i=0;i<n;i++){
    int j;
    for(j=i+1;j<n;j++){
      if(cmp(s+POS(i,0),s+POS(j,0))){
	printf("No\n");
	return;
      }
    }
  }
  printf("Yes\n");
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 128
x = int(input())
# p >= 2, b >= 1
if x == 1:
    ans = 1
else:
    ans = 0
    for i in range(1, x+1):
        for j in range(2, x+1):
            e = i**j
            if e <= x:
                ans = max(ans, e)
            else:
                break
print(ans)

Measured memory_bytes: 8964
n, k = [int(x) for x in raw_input().split(' ')]
d = [int(x) for x in raw_input().split(' ')]
def check(n, d):
    for v in d:
        if str(v) in str(n):
            return False
    return True
while True:
    if check(n, d):
        print n
        break
    n += 1



Measured memory_bytes: 3588
#include <iostream>
#include <stdio.h>
#include <map>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
    map<string, int> mp;
    int query, comment;
    scanf("%d", &query);

    char* str = (char*)malloc(20);
    memset(str, 0, sizeof(str));
    int num;
    for (int i = 0; i < query; i++)
    {
        scanf("%d", &comment);
        if (comment == 0)
        {
            scanf("%s %d", str, &num);
            mp[str] = num;
        }
        else
        {
            scanf("%s", str);
            printf("%d\n", mp[str]);
        }
    }
    return 0;
}



Measured memory_bytes: 26080
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        x: usize,
    }

    let mut quintcs: Vec<usize> = vec![0; 120];
    for i in 0..120 {
        quintcs[i] = i.pow(5);
    }

    for i in 1..120 {
        for j in 0..i {
            let a5 = quintcs[i];
            let b5 = quintcs[j];
            if x == a5 - b5 { println!("{} {}", i, j); break; }
            if x == a5 + b5 { println!("{} -{}", i, j); break; }
        }
    }
}


Measured memory_bytes: 2164
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main() {

    int n;
    scanf("%d", &n);
    int a;
    for (int i = 0; i < n; i++) {

        scanf("%d", &a);
        if (a % 2 == 0 && !(a % 3 == 0 || a % 5 == 0)) {
            printf("DENIED");
            return 0;
        }
    }
    printf("APPROVED");

    return 0;

}

Measured memory_bytes: 128
#include <stack>
#include <queue>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
 
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
#define INF (1<<29)

int main (){
	int NN,MM;
	cin >> NN >> MM;
	int tempa,tempb;
	int temp;
	pair<int,int> temppair;
	vector <pair< int , int > > cuts;
	rep(i,MM){
		cin >> tempa >> tempb;
		if(tempa>tempb){
			temp = tempa;
			tempa = tempb;
			tempb = temp;
		}
		temppair = make_pair(tempa,tempb);
		cuts.push_back(temppair);
	}
	sort(cuts.begin(),cuts.end());

	int ff = cuts[0].first;
	int fb = cuts[0].second;
	int ans = 0;
	rep(i,MM){
		if(cuts[i].first == ff)	{
			continue;
		}
		if( fb <= cuts[i].first ){
			ff = cuts[i].first;
			fb = cuts[i].second;
			ans ++;
		}
		if( fb > cuts[i].second ){
			fb = cuts[i].second;
		}
	}
	cout << ans+1 << endl;

	return 0;

}


Measured memory_bytes: 1400
H, W = map(int, input().split())
N    = int(input())
A    = list(map(int, input().split()))

R = []

for i, a in enumerate(A):
    R += [str(i+1)] * a

for h in range(H):
    if h % 2 == 0:
        print(' '.join(R[W*h:W*(h+1)]))
    else:
        print(' '.join(R[W*h:W*(h+1)][::-1]))


Measured memory_bytes: 3700
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int len = s.Length;
            char c = s[0];
            int cnt = 0;
            for (int i = 1; i < len; i++)
            {
                if(c != s[i])
                {
                    c = s[i];
                    cnt++;
                }
            }
            Console.WriteLine(cnt);
        }
    }
}


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

using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr ll mod = static_cast<ll>(1e9 + 7);

int x, a;
int main() {
	std::cin >> x >> a;

	if (x < a)
		std::cout << 0 << std::endl;
	else
		std::cout << 10 << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <map>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  int N, as[MAX_N];
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &as[i]);
  }

  // count occurence
  map<int, int> a_to_cnt;
  for (int i = 0; i < N; i++) {
    a_to_cnt[as[i]]++;
  }

  int is_yes = 1;
  if (N % 3 == 0) {
    const int M = N / 3;

    if (a_to_cnt.size() > 3) {
      is_yes = 0;
    } else {
      int x = 0;
      for (auto it = a_to_cnt.begin(); it != a_to_cnt.end(); it++) {
        if (it->second % M != 0) {
          is_yes = 0;
          break;
        } else {
          int num = it->second / M;
          for (int i = 0; i < num; i++) {
            x ^= it->first;
          }
        }
        // printf("%d -> %d\n", it->first, it->second);
      }
      if (x != 0) {
        is_yes = 0;
      }
    }
  } else {
    for (auto it = a_to_cnt.begin(); it != a_to_cnt.end(); it++) {
      if (!(it->first == 0 && it->second == N)) {
        is_yes = 0;
      }
      // printf("%d -> %d\n", it->first, it->second);
    }
  }

  if (is_yes) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
const ll MOD = 1000000007;

struct mint {
    ll x;  // cout << ans.x << endl; で出力する
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
  int H,W;
    cin >> H >> W;
    vector<string> a(H);
    vector<vector<mint>> dp(H,vector<mint>(W,0));
    rep(i,H) cin >> a[i];
    rep(h,H)rep(w,W){
      if(a[h][w] == '#'){
          dp[h][w] = 0;
          continue;
      }
      if(h==0 && w==0) dp[h][w] = 1;
      else if(h == 0 && w != 0)
          dp[h][w] = dp[h][w - 1];
      else if (h != 0 && w == 0)
          dp[h][w] = dp[h-1][w];
      else {
        dp[h][w] = dp[h-1][w] + dp[h][w-1];
      }
    }
    cout << dp[H - 1][W - 1].x << endl;
}

Measured memory_bytes: 9216
h, w, k = map(int, input().split())
C = []
for _ in range(h):
    C.append(input())

# print(h,w,k)
# print(*C,sep='\n',end='\n---\n')

ans = 0
for hbit in range(1<<h): # red row bit
    for wbit in range(1<<w): # red col bit
        c = 0
        for i in range(h):
            for j in range(w):
                if hbit>>i & 1 and wbit>>j & 1:
                    if C[i][j] =='#': c += 1
        if c == k: ans += 1

print(ans)


Measured memory_bytes: 9192
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

long long genMask(const vector<vector<pair<int, int>>>& g, int u, int v){
    queue<int> qu; qu.push(u);
    vector<long long> mask(g.size(), 0LL);
    while(!qu.empty()){
        int p = qu.front(); qu.pop();
        for(auto& t : g[p]){
            if(t.first == u || mask[t.first]) continue;
            mask[t.first] = mask[p] | (1LL << t.second);
            qu.push(t.first);
        }
    }
    return mask[v];
}

int main(){
    int N;
    while(cin >> N){
        vector<vector<pair<int, int>>> g(N);
        for(int i=0;i<N-1;i++){
            int a, b; cin >> a >> b;
            --a; --b;
            g[a].emplace_back(b, i);
            g[b].emplace_back(a, i);
        }
        int M; cin >> M;
        vector<long long> mask(N-1, 0LL);
        for(int i=0;i<M;i++){
            int u, v; cin >> u >> v;
            --u; --v;
            auto m = genMask(g, u, v);
            for(int j=0;j<N-1;j++) if(m&(1LL<<j)) mask[j] |= (1 << i);
        }
        vector<long long> dp(1<<M, 0);
        dp[0] = 1;
        for(auto& m : mask){
            vector<long long> next(1<<M, 0);
            for(int i=0;i<(1<<M);i++){
                next[i] += dp[i];
                next[i|m] += dp[i];
            }
            dp = next;
        }
        cout << dp.back() << endl;
    }
}

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

typedef long long ll;

const int N = 100 + 10;
int a[N];

int main() {
  	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
 	ll k;
  	string s;
  	cin >> s >> k;
  	ll n = s.size(), cnt = 1;
 	vector<ll> v;
  	for (int i = 1; i < n; i++) {
		if (s[i] == s[i - 1])
          	cnt++;
      	else {
          	v.push_back(cnt);
          	cnt = 1;
        }
    }
  	if (cnt)
      	v.push_back(cnt);
 	ll ans = 0;
  	if (v.size() == 1) {
      	cout << (k * n) / 2 << "\n";
      	return 0;
    }
  	for (int i = 1; i < v.size() - 1; i++)
      	ans += (v[i] / 2) * k;
  	if (s[0] == s[n - 1])
    	ans += ((v[0] + v[v.size() - 1]) / 2) * (k - 1) + v[0] / 2 + v[v.size() - 1] / 2;
	else
      	ans += (v[0] / 2) * k + (v[v.size() - 1] / 2) * k;
  	cout << ans << "\n";
}  

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int ans;
char s[10];
int main(){
	scanf("%s", s + 1);
	for(int i = 1; i <= 4; ++i){
		if(s[i] == '+') ans++;
		else ans--;
	}
	printf("%d\n", ans);
	return 0;
} 

Measured memory_bytes: 256
from math import ceil
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

min_val = min(a,b,c,d,e)
if n / min_val == 0:
    ans = 5
else:
    ans = ceil(4 + n / min_val) 
print(ans)

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

using namespace std;

const int maxn = 1e4+10;
const int maxd = 110;
const long long mod = 1e9+7;

typedef long long ll;

int n, d;

ll dp[maxn][maxd][3];

string num;

ll solve(int i, int m, int maior)
{
	if (i == n) return 0LL;
	if (dp[i][m][maior] != -1) return dp[i][m][maior];

	ll ans = 0LL;
	for (int j = 0; j <= 9; j++)
	{
		if (!i && !j) continue;

		int m1 = 2;
		if (maior == 1) m1 = 1;
		else if (!maior) m1 = 0;
		else if (j > ((int)num[i]-(int)'0')) m1 = 1;
		else if (j < ((int)num[i]-(int)'0')) m1 = 0;

		ll add = 0LL;

		if (i == n-1 && m1 != 1 && (m+j)%d == 0) add = 1LL;
		else if (i < n-1 && (m+j)%d == 0) add = 1LL;

		ans = (ans + add + solve(i+1, (m+j)%d, m1))%mod;
	}

	return dp[i][m][maior] = ans;
}

int main(void)
{
	cin >> num >> d;
	n = num.size();

	memset(dp, -1, sizeof dp);

	cout << solve(0, 0, 2) << "\n";
}

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

int N, fac;
long double sum;
pair<int, int> maps[10];

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

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> maps[i].first >> maps[i].second;
	}
	
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j < i; j++) {
			sum += sqrt(pow(maps[i].first - maps[j].first, 2) + pow(maps[i].second - maps[j].second, 2));
		}
	}

	sum *= 2; sum /= N;
	cout << fixed;
	cout.precision(7);
	cout << sum << "\n";
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
const int N = 1e5 + 5; 
using namespace std; 

int n, cnt[N], mn[N];
char s[N]; 

template < typename T >
inline T read()
{
	T x = 0, w = 1; char c = getchar();
	while(c < '0' || c > '9') { if(c == '-') w = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * w; 
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("cpp.in", "r", stdin);
#endif
	n = read <int> ();
	for(int i = 0; i < 26; i++) mn[i] = 0x3f3f3f3f;
	for(int len, i = 1; i <= n; i++)
	{
		for(int j = 0; j < 26; j++) cnt[j] = 0; 
		scanf("%s", s + 1), len = strlen(s + 1); 
		for(int j = 1; j <= len; j++) cnt[s[j] - 'a']++; 
		for(int j = 0; j < 26; j++) mn[j] = min(mn[j], cnt[j]); 
	}
	for(int j = 0; j < 26; j++) mn[26] += mn[j];
	if(!mn[26]) { puts(""); return 0; }
	for(int j = 0; j < 26; j++)
		for(int i = 1; i <= mn[j]; i++) printf("%c", 'a' + j);
	puts(""); 
	return 0; 
}


Measured memory_bytes: 3108
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int cmp_str(const void* a,const void*b){
    return strcmp(a,b);
}

int main(){
    int N;
    scanf("%d",&N);
    char S[N+1][11];
    for (int i=0; i<N; i++) {
        scanf("%10s ",S[i]);
    }
    qsort(S,N,sizeof(S[0]),cmp_str);
    
    int sum=1;
    for (int i=1; i<N; i++) {
        if(strcmp(S[i],S[i-1])!=0){
            sum++;
        }
    }
    
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 5736
n = int(input())
t,a = map(int,input().split())
h = list(map(int,input().split()))
ans = 0
for i,l in enumerate(h):
    k = t-l*0.006
    if(i == 0):
        abs1 = abs(a-k)
        ans = i+1
    elif(abs1 > abs(a-k)):
        abs1 = abs(a-k)
        ans = i+1
print(ans)

Measured memory_bytes: 3064
#pragma region header
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };
constexpr ll mod = 1e9 + 7;
constexpr ll inf = INT32_MAX / 2;
constexpr ll INF = LLONG_MAX / 2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
bool isprime(ll a)//素数判定、primeならtrue,違うならfalse
{
    if (a < 2) return false;
    else if (a == 2) return true;
    else if (a % 2 == 0) return false;
    double m = sqrt(a);
    for (int i = 3; i <= m; i += 2)
    {
        if (a % i == 0)
        {
            return false;
        }
    }

    // 素数である
    return true;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}


Measured memory_bytes: 3612
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<vector>
#include<cstring>
#define INF 1000000000
using namespace std;
int s,w;
int main(){
    cin>>s>>w;
    if(s<=w)
        cout<<"unsafe";
    else
        cout<<"safe";
    
    
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
using namespace std;

set <long long> get_divisors(long long N){
  set <long long> ret;
  if(N == 1){
    return ret;
  }
  ret.insert(N);
  if(N == 2){
    return ret;
  }
  for(long long i = 2; i < sqrt(N) + 1; i++){
    if(N % i == 0){
      ret.insert(i);
      ret.insert(N / i);
    }
  }
  return ret;
}
int main(){
  long long N;
  cin >> N;

  int ans = 0;
  set <long long> divisors1 = get_divisors(N);
  for(auto it = divisors1.begin(); it != divisors1.end(); it++){
    long long tmp = N;
    while(tmp % *it == 0){
      tmp /= *it;
    }
    if(tmp % *it == 1){
      ans ++;
    }
  }

  set <long long> divisors2 = get_divisors(N - 1);
  ans += divisors2.size();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

int findIndex(vector<int> vec, int value)
{
    vector<int>::iterator iter = std::find(vec.begin(), vec.end(), value);
    size_t index = distance(vec.begin(), iter);
    if(index == vec.size())
    {
        return -1;
    }
    return index;
}

int main()
{
    int n, m, x;
    cin >> n >> m >> x;

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

    int rightCost = 0;
    for (int i = x + 1; i <= n; i++)
    {
        if (findIndex(vec, i) != -1)
        {
            rightCost++;
        }
    }

    int leftCost = 0;
    for (int i = x - 1; i >= 0; i--)
    {
        if (findIndex(vec, i) != -1)
        {
            leftCost++;
        }
    }
    
    cout << min(leftCost, rightCost) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
const int MaxN=100010;
int N,a[MaxN*2];
bool b[MaxN*2];
bool chk(int M){
	for(int i=1;i<2*N;i++)b[i]=0;
	for(int i=2;i<2*N;i++)if((a[i]<M)==(a[i-1]<M))b[i-1]=b[i]=1;
	for(int i=N,j=N;i;i--,j++){
		if(b[i])return a[i]>=M;
		if(b[j])return a[j]>=M;
	}
	return a[1]>=M;
}
int main(){
	scanf("%d",&N);
	for(int i=1;i<2*N;i++)scanf("%d",a+i);
	int l=1,r=2*N,mid;
	while(r-l>1)chk(mid=l+r>>1)?l=mid:r=mid;
	printf("%d\n",l);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

int sum_digit(int n){
  if( n == 0 ) return 0;
  else return n%10 + sum_digit(n/10);
}

int main()
{
  int i,N; cin >> N;
  vector<int> d(N);
  for(i = 0; i < N; i++){
  	cin >> d.at(i);
  }
  
  vector<int> bakket(101);
  
  for(i = 0; i < N; i++){
  	bakket.at(d.at(i))++;
  }
  
  int count = 0;
  for(i = 0; i < 101; i++){
  	if(bakket.at(i) != 0) count++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import itertools
N= int(input())
kisou = []
gusou = []
for num in [i for i in range(N+1)][1:]:
    if num%2==0:
        gusou.append(num)
    else:
        kisou.append(num)
print(len(list(itertools.product(kisou, gusou))))

Measured memory_bytes: 3188
// Problem : B - Count Balls
// Contest : AtCoder Beginner Contest 158
// URL : https://atcoder.jp/contests/abc158/tasks/abc158_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

/*/ Author:Amar1503/*/
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("Ofast")
#define fio ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define ull unsigned long long
#define ll long long
#define inf INT_MAX
#define mninf INT_MIN
#define Mod 1000000007
#define endl "\n"
#define cp(x) cout<<(x)<<" "
#define cl(x) cout<<(x)<<endl
#define ct(x,y) cout<<(x)<<" "<<(y)<<endl;
#define nl   cout<<endl
//const double PI=3.1415926535897932384626433832;
//looping
#define For(i,a,b) for(int i=a;i<b;i++)
#define test(t)  int (t); cin>>(t); while((t)--)
#define array(a,n) int (n); cin>>(n); int a[n]; for(int i=0;i<(n);i++) cin>>a[i];
#define trace(x) clog<<#x<<": "<<x<<" "<<endl
#define trace2(x,y) clog<<#x<<": "<<x<<"     "<<#y<<" "<<y<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define printa(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define printv(v)  for(int i=0;i<(v).size();i++) cout<<v[i]<<" "
//containers
#define F first
#define S second
#define pb emplace_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define all(v) (v).begin(),(v).end()
#define mp make_pair
#define itr(it, a) for(auto it = (a).begin(); it != (a).end(); it++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ers(v)   sort(all(v)); (v).erase(unique(all(v)),(v).end())
#define printmatrix(a,n,m) for(int i=0;i<n;i++){ for(int j=0;j<m;j++) cout<<a[i][j]<<" "; cout<<endl;}
typedef vector<int> vi;
typedef vector< vector< int > > vvi;
typedef pair <int, int> pii;
typedef vector < pair <int, int> > vpii;
// cout<<"\nTime Elapsed : " << 1.0*clock() /CLOCKS_PER_SEC << " s\n";
int dx[8]={1,1,1,-1,-1,-1,0,0};
int dy[8]={1,0,-1,1,-1,0,1,-1};
#define int long long
/*/----------------------------Code begins----------------------------------/*/
int32_t main(){
fio;
int n,b,r;
cin>>n>>b>>r;
if(b==0)
cout<<0;
else {
	int sum=n/(b+r)*b;
	n%=(b+r);
	sum+=min(b,n);
	cout<<sum;
}
}









Measured memory_bytes: 256
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

a,b=map(int,input().split())

faca=fac(a)
facb=fac(b)

Fa=set()
Fb=set()
for i in faca:
      Fa.add(i[0])
for i in facb:
      Fb.add(i[0])
Fu=Fa&Fb
if a==1 or b==1:
      print(1)
else:
      print(len(Fu)+1)
                  


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

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const double eps = 1e-9;
const double pi = atan2(0, -1);

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int n, m;
    cin >> n >> m;
    int cnt[n];
    fill(cnt, cnt + n, 0);
    rep(i, 0, m)
    {
        int a, b;
        cin >> a >> b;
        cnt[a - 1]++;
        cnt[b - 1]++;
    }
    int ans = 0;
    rep(i, 0, n)
        if (cnt[i] & 1)
            ans++;
    cout << (ans == 0 ? "YES\n" : "NO\n");
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<map>
#include<string>
#include<iostream>

using namespace std;
int main(void){
    map<string,string> table;
    string input;
    table["A"] = "T";
    table["T"] = "A";
    table["C"] = "G";
    table["G"] = "C";

    cin>>input;

    cout<<table[input]<<endl;

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int main(){
    int ans = 0;
    int N,M;
    cin >> N >> M;
    vvi path(N,vi(N,0));

    rep(i,M){
        int a,b;
        cin >>a>>b;
        path[a-1][b-1] = 1;
        path[b-1][a-1] = 1;
    }

    vi order(N-1);
    rep(i,N-1){
        order[i]=i;
    }

    do{
        bool judge = true;
        if(path[0][order[0]+1]==0)  judge =false;
        rep(i,N-2){
            if(path[order[i]+1][order[i+1]+1]==0) judge = false;
        }
        if(judge) ans++;
    }while(nepe(order));
    cout << ans <<endl;
}

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

int main()
{
    int N, X, Y;
    cin >> N >> X >> Y;
    int minimum = INT_MAX;
    map<int, int>m;


    for(int i = 1; i <= N; i++)
    {
        for(int j = 1; j <= N; j++)
        {
            minimum = min({abs(j-i), abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(j-X)});
            if (m.find(minimum) == m.end())
            {
                m[minimum] = 1;
            } 
            else
            {
                m[minimum] += 1;
            }
        }

        // minimum = INT_MAX;
    }

    int idx = 1;
    for(auto it = m.begin(); it != m.end(); it++)
    {
        if(it->first == idx)
        {
            cout << it->second/2 << endl;
            idx++;
        }
    }
    for(int i = idx+1; i <= N; i++)
    {
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch){
    if (ch == 'A'){
        return 1;
    }
    else if(ch == 'C'){
        return 2;
    }
    else if ( ch == 'G'){
        return 3;
    }
    else if(ch == 'T'){
        return 4;
    }
    else return 0;
}

//文字から数値に変換してkeyを生成する
long long getKey(char str[]){

    long long sum = 0,p=1,i;

    for(i = 0; i< strlen(str);i++){
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){
    return key % M;
}

int h2(int key){
    return 1 + (key % (M-1));
}

int find(char str[]){
    long long key, i ,h;
    key = getKey(str); //文字列を数値に変換する
    for(i = 0; ;i++){
        h = (h1(key) + i * h2(key)) % M;
        if(strcmp(H[h],str) == 0){
            return 1;
        }
        else if(strlen(H[h]) == 0){
            return 0;
        }
    }
    return 0;
}

int insert(char str[]){
    long long key,i, h;
    key = getKey(str);
    for(i=0;;i++){
        h=(h1(key) + i*h2(key)) % M;
        if(strcmp(H[h],str) == 0){
            return 1;
        }
        else if(strlen(H[h]) == 0){
            strcpy(H[h],str);
            return 0;
        }
    }
    return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for(i =0; i< M; i++){
        H[i][0] = '\0';
    }
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%s %s",com,str);

    if(com[0] == 'i'){
        insert(str);
    }
    else{
        if(find(str)){
            printf("yes\n");
        }
        else{
            printf("no\n");
        }
    }
    }
    return 0;

}


Measured memory_bytes: 16044