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

ll modinv(ll a,ll m){
   ll b=m,u=1,v=0;
   while(b){
      ll t=a/b;
      a-=t*b; 
      swap(a,b);
      u-=t*v; 
      swap(u,v);
   }
   u%=m;
   if(u<0) u+=m;
   return u;
}

ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}



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

  vector<vector<int>> a(n,vector<int>(k,0));

  rep(i,k){
     int d;
     cin>>d;
     rep(j,d){
        int s;
        cin>>s;
        a[s-1][i]++;
     }
  }

  ll ans=0;

  rep(i,n){
     bool f=true;
     rep(j,k){
        if(a[i][j]!=0) f=false;
       
     }

     if(f==true) ans++;
  }
  cout<<ans;

   return 0;
}



Measured memory_bytes: 3640
//============================================================================
// Name        : abc131_a.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : Hello World in C++, Ansi-style
//============================================================================

/*
 A - Security

 実行時間制限: 2 sec / メモリ制限: 1024 MB

 配点: 100 点

 問題文

 すぬけ君の管理する研究室の扉にはロックがかかっており、解錠にはセキュリティコードを入力する必要があります。
 セキュリティコードは 4 桁の数字列です。セキュリティコードが「入力しづらい」とは、同じ数字が連続する箇所が存在することを言います。
 現在のセキュリティコード S が与えられます。S が「入力しづらい」なら 'Bad' を、そうでなければ 'Good' を出力してください。

 制約

 ・S は半角数字のみからなる長さ 4 の文字列
 */
#pragma GCC optimize ("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define rep(i, m, n) for (int i = m; i < n; ++i)

/**
 * エントリポイント．
 * @return 0.
 */
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	char code[4];
	cin >> code;
	cout
			<< (code[0] != code[1] && code[1] != code[2] && code[2] != code[3] ?
					"Good" : "Bad") << endl;
	return 0;
}


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

int main() {
    long n;
    cin >> n;
    map<long, int> numbs;
    long numb;
    bool state = true;
    for(long i = 0; i < n; i++) {
        cin >> numb;
        if(numbs.find(numb) != numbs.end()) {
            state = false;
            break;
        }
        else {
            numbs[numb] = 1;
        }
    }
    if(state == true) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int N;
string S;

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

    cin >> N >> S;

    int ans = 0;
    char cur = '!';

    REP(i, N) {
        if(cur != S[i]) {
            ans++;
        }
        cur = S[i];
    }

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

    return 0;
}


Measured memory_bytes: 512
m, k = list(map(int, input().split()))
if m==1:
  if k==0:
    print("0 0 1 1")
  else:
    print(-1)
  exit()

if k>=2**m:
  print(-1)
  exit()

ans = []
for i in range(2**m):
  if i==k:
    continue
  ans.append(i)
ans.append(k)
for i in range(2**m-1, -1, -1):
  if i==k:
    continue
  ans.append(i)
ans.append(k)
print(*ans)

Measured memory_bytes: 19316
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int k = sc.nextInt();
    static int a = sc.nextInt();
    static int b = sc.nextInt();
    public static void main(String[] args) {
        for (int i = a; a <= b; a++){
            if (a % k == 0){
                System.out.println("OK");
                return;
            }
        }
        System.out.println("NG");

    }
}


Measured memory_bytes: 35732
enter = input().split()

def map_num(enter):

    input_list = []

    for num in enter:
        if num != ' ':
            input_list.append(int(num))

    return input_list[0], input_list[1]

a, b = map_num(enter)
# 偶数か奇数で出力を変更する.
result = a * b

# 偶数
if result % 2 == 0:
    print('Even')
# 奇数
elif result % 2 != 0:
    print('Odd')


Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,X,Y,A,B,i,j,k;

int main()
{
  cin>>A>>B;
  
  Y=B*10;
  
  for(i=0;i<10;i++)
  {
    X=(Y+i)*8/100;
    if(X==A)
    {
      cout<< Y+i;
      return 0;
    }
  }
  
  cout <<-1;
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    vi a(2);
    cin >> a[0] >> a[1];

    int res = 0;

    sort(all(a), greater<int>());

    res += a[0];
    a[0]--;
    sort(all(a), greater<int>());

    res += a[0];

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cmath>
#include <sstream>
#include <string>
using namespace std;

int main()
{
  int a, b; cin >> a >> b;
  stringstream ss;
  ss << a << b;
  int ans;
  ss >> ans;
  string res = "No";
  for(int i = 0; i < ans; i++){
    if(i * i == ans) res = "Yes";
  }
  cout << res << endl;
}


Measured memory_bytes: 256
using System;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var num = Console.ReadLine().Split(' ');

            if (num[0] == num[1] && num[1] == num[2])
            {
                Console.WriteLine("Yes");
            }
            else
            {
                Console.WriteLine("No");
            }

        }
    }
}


Measured memory_bytes: 13140
from collections import deque

N, M = map(int, input().split())
d = {}
for _ in range(M):
    A, B = map(int, input().split())
    if A not in d:
        d[A] = [B]
    else:
        d[A].append(B)
    if B not in d:
        d[B] = [A]
    else:
        d[B].append(A)

ans = [(-1, float("inf"))] * N
cnt = 0
# stack = [(1, 0)]
queue = deque([(1, 0)])

while queue:
    val, step = queue.popleft()
    next_vals = d[val]
    for nxt in next_vals:
        #        if ans[nxt - 1][1] > step + 1:
        if ans[nxt - 1][0] == -1:
            cnt += 1
            ans[nxt - 1] = (val, step + 1)
            queue.append((nxt, step + 1))

if cnt < N - 1:
    print("No")
else:
    print("Yes")
    for i in range(1, N):
        print(ans[i][0])

Measured memory_bytes: 49772
from itertools import product

h, w, k = map(int, input().split())
AL = []
count = 0
for i in range(h):
    c = list(input())
    AL.append(c)
for a in product(range(2), repeat=h):
    for b in product(range(2), repeat=w):
        black = 0
        for i in range(h):
            for j in range(w):
                if AL[i][j] == "#" and (a[i] and b[j]):
                    black += 1
        if k == black:
            count += 1
print(count)

Measured memory_bytes: 9204
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var s string
	var sum = 0

	fmt.Scanf("%s", &s)
	slice := strings.Split(s, "")
	for i := 0; i < len(slice); i++ {
		a, _ := strconv.Atoi(slice[i])
		sum += a
	}
	fmt.Printf("%v\n", sum)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 4785309
#define long long
using namespace std;
int a[p];
signed main()
{
	int n;
	cin>>n;
	for(fint i=1;i<=n;i++)
	cin>>a[i];
	long long ans=0;
	for(fint i=2;i<=n;i++)
	if(a[i]<a[i-1])
	ans+=a[i-1]-a[i],a[i]=a[i-1];
	cout<<ans;
	return 0;
}

Measured memory_bytes: 4412
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def rev(i):
    ni = i
    ans = 1
    t = 10**9+5
    mod = 10**9+7
    while t > 0:
        if t&1:
            ans = (ans*ni)%mod
        t >>= 1
        ni = (ni**2)%mod
    return ans

def main():
    n,k = map(int,ipt().split())
    a = [(abs(int(i)),int(i)) for i in ipt().split()]
    Mi = 10**9
    Ma = -10**9
    mod = 10**9+7
    a.sort(reverse=True)
    if n == k:
        ans = 1
        for i in a:
            ans = (ans*i[1])%mod
        print(ans)
        exit()
    for i in a:
        if Ma < i[1]:
            Ma = i[1]
        if Mi > i[1]:
            Mi = i[1]
    if Ma < 0 and k&1:
        ans = 1
        for i,ai in enumerate(a[::-1]):
            ans = (ans*ai[0])%mod
            if i == k-1:
                break
        print((-ans)%mod)
        exit()
    pp = None
    pm = None
    ans = 1
    s = 1
    for i,ai in enumerate(a[:k:]):
        ans = ans*ai[0]%mod
        if ai[1] == 0:
            print(0)
            exit()
        elif ai[1] > 0:
            pp = ai[0]
        else:
            pm = ai[0]
            s *= -1
    if s == 1:
        print(ans)
        exit()
    np = 0
    nm = 0
    for ai in a[k::]:
        if ai[1] > 0 and not np:
            np = ai[0]
        elif ai[1] < 0 and not nm:
            nm = ai[0]
        if np and nm:
            break
    if pp == None:
        if np == None:
            print(0)
        else:
            print(ans*rev(pm)*np%mod)
    elif nm == None and np == None:
        print(0)
    elif nm == None:
        print(ans*rev(pm)*np%mod)
    elif np == None:
        print(ans*rev(pp)*nm%mod)
    else:
        if nm*pm < np*pp:
            print(ans*rev(pm)*np%mod)
        else:
            print(ans*rev(pp)*nm%mod)



    return None

if __name__ == '__main__':
    main()


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

nlist = [0] * N
for i in A:
    nlist[i-1] += 1

nlist.sort(reverse = True)
cnt = 0
for i in range(K,N):
    if nlist[i] == 0: break
    cnt += nlist[i]

print(cnt)

Measured memory_bytes: 24748
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int x,a;
    cin >> x >> a;
    if(x<a)cout << 0 << endl;
    else cout << 10 << endl;
    
    return 0;
}

Measured memory_bytes: 888
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 5e5 + 5;

int fw[maxn][26];

void upd(int pos, int add, int kind) {
	for (int i = pos + 1; i < maxn; i += -i & i) {
		fw[i][kind] += add;
	}
}

int get(int r, int kind) {
	int sum = 0;
	for (int i = r + 1; i > 0; i -= -i & i) {
		sum += fw[i][kind];
	}
	return sum;
}

int get(int l, int r, int kind) {
	return get(r, kind) - get(l - 1, kind);
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s; int n;
	cin >> n >> s;
	//s = '$' + s;
	for (int i = 0; i < n; i++) {
		upd(i, 1, s[i] - 'a');
	}

	int q; cin >> q; while (q--) {
		int t; cin >> t;
		if (t == 1) {
			int pos; char c;
			cin >> pos >> c;
			pos--;
			upd(pos, -1, s[pos] - 'a');
			upd(pos, 1, c - 'a');
			s[pos] = c;
		} else {
			int l, r; cin >> l >> r; l--; r--;
			int cnt = 0;
			for (int i = 0; i < 26; i++) {
				if (get(l, r, i)) { 
					cnt++; 
				}
			}
			cout << cnt << '\n';
		}
	}


	return 0;
}

/*


*/

Measured memory_bytes: 51740
#include <bits/stdc++.h>
#include <vector>
#include<math.h>
#include<string.h>
using namespace std;
#define MAX 200005
#define MOD 1000000007
#define INF 1000000000000000000
#define EPS 0.0000000001
#define CHAINS 18
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
int P[MAX];
int members[MAX];
int Find(int x)
{
    if(P[x]==x) return x;
    else
    {
        P[x]=Find(P[x]);
        return P[x];
    }
}
bool Join(int x,int y)
{
    int PoX=Find(x),PoY=Find(y);
    if(PoX==PoY) return false;
    else if(members[PoX]>members[PoY])
    {
        members[PoX]+=members[PoY];
        members[PoY]=0;
        P[PoY]=PoX;
    }
    else
    {
        swap(PoX,PoY);
        members[PoX]+=members[PoY];
        members[PoY]=0;
        P[PoY]=PoX;
    }
    return true;
}
int main()
{
    int n,m,u,v,i;
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)
    {
        P[i]=i;
        members[i]=1;
    }
    for(i=0;i<m;i++)
    {
        scanf("%d %d",&u,&v);
        Join(u,v);
    }
    int ans=1;
    for(i=1;i<=n;i++)
    {
        ans=max(ans,members[i]);
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 5368
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0;i<n;i++)
#define P pair<ll,ll>
#define F first
#define S second
#define all(a) (a.begin(),a.end())
long long INF=1000000000000000000;
long long mod=1000000007;
int main(void){
    ll x;cin>>x;
    ll com=0;ll ans;
    rep(i,2000000){
        com+=i;
        if(com>=x){ans=i;break;}
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int n,x,t;
  cin >> n >> x >> t;
  int ans=0;
  ans+=n/x*t;
  if(n%x!=0) ans+=t;

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


Measured memory_bytes: 3632
N = int(input())
cnt = 0
for i in range(100+1):
    if 4*i>N:
        break
    for j in range(100+1):
        if 7*j>N:
            break
        if 4*i+7*j==N:
            cnt += 1

if cnt>0:
    print('Yes')
else:
    print('No')


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

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vi A(n), B(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
  for (int i = 0; i < n; ++i) cin >> B[i];
  int res = -1;
  for (int mask = 0; mask < (1<<n); ++mask) {
    int cont1 = 0;
    int cont2 = 0;
    for (int i = 0; i < n; i += 2) {
      if (mask&(1<<i)) ++cont1;
    }
    for (int i = 1; i < n; i += 2) {
      if (mask&(1<<i)) ++cont2;
    }
    if (cont1 != cont2) continue;
    vpi Par;
    vpi Sen;
    for (int i = 0; i < n; i += 2) {
      if (mask&(1<<i)) Sen.push_back(pi(B[i],i));
      else Par.push_back(pi(A[i],i));
    }
    for (int i = 1; i < n; i += 2) {
      if (mask&(1<<i)) Par.push_back(pi(B[i],i));
      else Sen.push_back(pi(A[i],i));
    }
    sort(Par.begin(), Par.end());
    sort(Sen.begin(), Sen.end());
    vpi R(n);
    for (int i = 0; i < (int)Par.size(); ++i) R[2*i] = Par[i];
    for (int i = 0; i < (int)Sen.size(); ++i) R[2*i+1] = Sen[i];
    bool pots = true;
    for (int i = 1; i < n; ++i) {
      if (R[i-1].first > R[i].first) {
        pots = false;
        break;
      }
    }
    if (!pots) continue;
    int resu = 0;
    for (int i = 0; i < n; ++i) {
      int ind = i;
      while (R[ind].second != i) ++ind;
      while (ind != i) {
        ++resu;
        swap(R[ind], R[ind-1]);
        --ind;
      }
    }
    if (res == -1) res = resu;
    res = min(res, resu);
  }
  cout << res << endl;
}


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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  vector<string> op(N-1);
  rep(bit,1<<(N-1)){
    int total=S.at(0)-'0';
    for(int i=0;i<(N-1);i++){
      if(bit & (1<<i)){
        total -= S.at(i+1) - '0';
        op.at(i) = "-";
        continue;
      }
      total += S.at(i+1) - '0';
      op.at(i) = "+";
    }
    if(total==7){
      cout << S.at(0);
      rep(i,N-1){
        cout << op.at(i);
        cout << S.at(i+1);
      }
      cout << "=7" <<endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

A=[]
for i in range(N):
    a, b = map(int, input().split())
    A.append([a, b])

A.sort(key=lambda x:x[0])

cnt = 0
for i in range(N):
    cnt += A[i][1]
    if cnt >= K:
        print(A[i][0])
        break

Measured memory_bytes: 21248
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <queue>
#include <iomanip>

using namespace std;
int Q;
bool prime[100001];
int s[100001];

int main() {
  cin >> Q;
  for (int i=1; i<=100000; i++) {
    prime[i] = true;
  }
  prime[1] = false;
  int i=2;
  while (i*i <= 100000) {
    while (!prime[i]) {
      i++;
    }
    int k = i+i;
    while (k <= 100000) {
      prime[k] = false;
      k += i;
    }
    i++;
  }
  int sum = 0;
  for (int i=1; i<=100000; i+=2) {
    if (prime[i] && prime[(i+1)/2]) {
      sum++;
    }
    s[i] = sum;
  }
  for (int i=0; i<Q; i++) {
    int l, r;
    cin >> l >> r;
    int ans;
    if (l == 1) {
      ans = s[r];
    } else {
      ans = s[r] - s[l-2];
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 1152
#
# abc069 b
#

import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """internationalization"""
        output = """i18n"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """smiles"""
        output = """s4s"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """xyz"""
        output = """x1z"""
        self.assertIO(input, output)


def resolve():
    s = input()
    print(s[0]+str(len(s)-2)+s[-1])


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16180
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll n,a,b;
	cin>>n>>a>>b;
	ll ans = (n/(a+b))*a;
	ll rem = n - (n/(a+b))*(a+b);
	ans += min(a,rem);
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n = int(input())
nn = int(math.sqrt(n))
# print(nn)
print(nn**2)


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

using namespace std;
int n;
int main()
{
    ios::sync_with_stdio (false)   ;
    while (cin >> n)
    {
        int ans=INT_MAX ;
        for (int i=1;i<=n/2 ; i++)
        {
            int t =0;
            int a =i ;
            int b=n-i;
            while (a)
            {
                t+=a%10 ;
                a/=10;
            }
            while (b)
            {
                t+=b%10;
                b/=10;
            }
            ans=min (t,ans) ;
         }
         cout<<ans<<endl ;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    vector<int> vec(5);
    int k;
    for(int i=0;i<5;i++){
        cin>>vec.at(i);
    }
  cin>>k;
    sort(vec.begin(),vec.end());
    reverse(vec.begin(),vec.end());
    int t=0;
    for(int i=1;i<5;i++){
        if(vec.at(0)-vec.at(i)>k){
            t=t+1;
        }
    }
        for(int i=2;i<5;i++){
        if(vec.at(0)-vec.at(i)>k){
            t=t+1;
        }
    }
            for(int i=3;i<5;i++){
        if(vec.at(0)-vec.at(i)>k){
            t=t+1;
        }
    }
                for(int i=4;i<5;i++){
        if(vec.at(0)-vec.at(i)>k){
            t=t+1;
        }
    }
    if(t==0){
        cout<<"Yay!"<<endl;
    }
    else{
        cout<<":("<<endl;
    }
}

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

void solve(long long N, long long A, long long B){
    if (A == 0) cout << 0 << '\n';
    else if (N <= A) cout << N << '\n';
    else if (N <= A + B) cout << A << '\n';
    else if (N % (A + B) == 0) cout << A * (N / (A + B)) << '\n';
    else if (N % (A + B) <= A) cout << A * (N / (A + B)) + (N % (A + B)) << '\n';
    else cout << A * (N / (A + B)) + A << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back

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

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int cost;
    bool fst=true;
    while(cin>>cost,cost)
    {
	if(!fst) cout<<endl;
	fst=false;
	int a,b,c,d; cin>>a>>b>>c>>d;
	int ra,rb,rc,rd;
	int Min=1e9;

	for(int i=0;i<=a;i++) for(int j=0;j<=b;j++)
	for(int k=0;k<=c;k++) for(int l=0;l<=d;l++)
	{
	    int change=(10*i+50*j+100*k+500*l)-cost;
	    if(change<0) continue;
	    if(i && change%50/10 || j && change%100/50 ||
	       k && change%500/100 || l && change/500) continue;
	    int cnt=a-i+b-j+c-k+d-l+change%50/10+change%100/50+change%500/100+change/500;
	    if(cnt<Min){
		Min=cnt;
		ra=i; rb=j; rc=k; rd=l;
	    }
	}
	if(ra) cout<<10<<" "<<ra<<endl;
	if(rb) cout<<50<<" "<<rb<<endl;
	if(rc) cout<<100<<" "<<rc<<endl;
	if(rd) cout<<500<<" "<<rd<<endl;
    }
}


Measured memory_bytes: 3032
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
int N ; cin >> N ;
  vector<int> A(N);
  for(int i = 0 ; i < N; i++){
    cin >> A[i];}
  
  sort(A.begin(), A.end());
  
  int s = A[0];
  int t = A[N-1];
  
  int max_cnt = 0;
  
  if( N <= 10000){
 for(int X = s ; X <= t ; X++){
   
   int cnt = 0;
   for(int i = 0; i < N ;i++){
     if( A[i] == X || A[i] == X + 1 || A[i] == X - 1){cnt++;} }
   
   max_cnt = max(max_cnt,cnt);}
  
  cout << max_cnt << endl;}
  
  else{
 for(int X = s;  X <= t ; X++){
   
   int total = 0;
   
  auto c1 = lower_bound(A.begin(),A.end(), X-1);
  auto c2 = upper_bound(A.begin(),A.end(), X+1);
   //A[i] >= X - 1なる最初のi*はlower_boundで調べられる
   //A[j] <= X + 1 なる最後のj*は、upper_bound - 1で調べられる
   //求めたいのは cnt = j* - i* + 1 ==( c2 - 1 - c1 + 1 )== cnt2 - cnt1
  
   int cnt1 = distance(A.begin(),c1);
   int cnt2 = distance(A.begin(),c2);
   
   total += cnt2 - cnt1;
   
   max_cnt = max(max_cnt, total);}
   
   cout << max_cnt << endl;}
  
  return 0;
}
     
     
     
     
     

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main(){
  long a, b, c, k;
  cin >> a >> b >> c >> k;
  if(a-b > 1000000000000000000|| a-b < -1000000000000000000){
    cout << "Unfaif" << endl;
  }
  else if(k%2){
    cout << -a+b << endl;
  }
  else cout << a-b << endl;
}


Measured memory_bytes: 256
s = list(input())
 
s_split = []
tmp = []
for i in range(len(s) - 1):
    tmp.append(s[i])
    if s[i] == 'L' and s[i + 1] == 'R':
        s_split.append(tmp)
        tmp = []
tmp.append(s[-1])
s_split.append(tmp)
 
out = ''
for _split in s_split:
    for i in range(len(_split) - 1):
        if _split[i] == 'R' and _split[i + 1] == 'L':
            idx = i
 
    tmp = [0] * len(_split)
    if len(_split) % 2 == 0:
        for i in range(len(_split)):
            tmp[idx] = len(_split) // 2
            tmp[idx + 1] = len(_split) // 2
 
    else:
        r_int = 0
        l_int = 0
        for i in range(len(_split)):
            dist = abs(idx - i)
            if dist % 2 == 0:
                r_int += 1
            else:
                l_int += 1
        tmp[idx] = r_int
        tmp[idx + 1] = l_int
 
    for i in range(len(_split)):
        out += ' ' + str(tmp[i])
 
print(out[1:])

Measured memory_bytes: 10412
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

typedef pair<ll, int> ll_i;
vector<ll_i> g[100000];  // cost, to
vector<ll> dijkstra(int num, int start) {
  priority_queue<ll_i, vector<ll_i>, greater<ll_i> > que;
  vector<ll> dp(num, 1e18);
  dp[start] = 0;
  que.push(make_pair(0, start));
  while (!que.empty()) {
    ll_i v = que.top();
    que.pop();
    if (dp[v.second] < v.first) continue;
    for (auto u : g[v.second]) {
      if (dp[v.second] + u.first < dp[u.second]) {
        dp[u.second] = dp[v.second] + u.first;
        que.push(make_pair(dp[u.second], u.second));
      }
    }
  }
  return dp;
}

int main() {
  int v, e, r;
  cin >> v >> e >> r;
  for (int i = 0; i < e; ++i) {
    int s, t, d;
    cin >> s >> t >> d;
    g[s].push_back(make_pair(d, t));
  }
  vector<ll> ans = dijkstra(v, r);
  for (int i = 0; i < v; ++i) {
    if (ans[i] == 1e18) {
      cout << "INF" << endl;
    } else {
      cout << ans[i] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 19408
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;

  map<ll,ll> mp;

  rep(i,100)rep(j,100)rep(k,100) {
    ll i1 = i+1;
    ll j1 = j+1;
    ll k1 = k+1;

    ll now = i1*i1 + j1*j1 + k1*k1 + i1*j1 + j1*k1 + k1*i1;
    ++mp[now];
  }

  for (ll i = 1; i <= n; ++i) {
    cout << mp[i] << endl;
  }
}


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

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define PB push_back
#define MP make_pair
#define ALL(v) v.begin(), v.end()

const int MAX = 1e5+10;
const int MOD = 1e9+7;

ll fac[MAX<<2];  // fac[n] = n!
ll finv[MAX<<2]; // (fac[n] * finv[n]) % MOD = 1
ll inv[MAX<<2];  // (n * inv[n]) % MOD = 1

void init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    FOR (i, 2, MAX<<2) {
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i]*(MOD/i) % MOD;
        finv[i] = finv[i-1]*inv[i] % MOD;
    }
}

ll nPk (int n, int k) {
    if (k == 0) return 1;
    if (n < k || k < 0 || n < 0) return 0;
    return fac[n]*finv[n-k]%MOD;
}

int N, K;
vi adj[MAX];
bool used[MAX];

ll dfs(int n) {
    used[n] = true;
    ll res;
    if (n == 0) res = nPk(K, adj[0].size()+1);
    else res = nPk(K-2, adj[n].size()-1);
    FORE (x, adj[n]) if (!used[x])
        res = (res * dfs(x)) % MOD;
    return res;
}

ll solve() {
    if (K == 1) {
        if (N == 1) return 1;
        else return 0;
    }
    if (N == 1) return K;
    return dfs(0);
}

int main() {
    init();
    cin >> N >> K;
    REP (i, N-1) {
        int a, b; cin >> a >> b; a--; b--;
        adj[a].PB(b);
        adj[b].PB(a);
    }
    cout << solve() << endl;
}

Measured memory_bytes: 18688
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(W: int, a: int, b: int):
    ret = max(0, abs(a - b) - W)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    W = int(next(tokens))  # type: int
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    solve(W, a, b)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from math import*
def main():

    n = int(input())
    ab = [list(map(int, input().split())) for _ in [0]*n]
    k = 10000
    ans2 = 0
    for i in range(k):
        t = 2*i*pi/k
        s = sin(t)
        c = cos(t)
        ans = [0, 0]
        for a, b in ab:
            if a*s+b*c >= 0:
                ans[0] += a
                ans[1] += b
        ans2 = max(ans2, ans[0]**2+ans[1]**2)
    print(ans2**0.5)


main()


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

using namespace std;

const int MAX_N = 200010;
double dp[MAX_N];

int main() {
  int N, K;
  cin >> N >> K;
  for (int i = K; i < MAX_N; i++) dp[i] = 1.0;
  for (int i = K - 1; i >= 0; i--) dp[i] = dp[i * 2] * 0.5;

  double sum = 0;
  for (int i = 1; i <= N; i++) sum += dp[i];
  printf("%.16lf\n", sum / N);

  return 0;
}


Measured memory_bytes: 1792
N,Q = map(int,input().split())
S = input()
t = [0]*(N+1)

for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)
  
for j in range(Q):
  l,r = map(int,input().split())
  print(t[r-1] - t[l-1])

Measured memory_bytes: 13200
var
  ch:char;
  st:string; 
begin
  while not eof do 
   begin
     read(ch); 
     if (ch='1') or (ch='0') then 
      st:=st+ch; 
     if (ch='B') and (length(st)>0) then  
      delete(st,length(st),1);
   end;
  writeln(st); 
end.

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>

// num????´???°??????1, ?´???°??§????????????0???????????¢??°
int primenumber(int num) {
    int i, ans = 1, nmax = (int)sqrt((double)num);

    if (num == 1) {
        ans = 0;
    } else {
        for (i = 2; i <= nmax; i++) {
            if (num % i == 0) {
                ans = 0;
                break;
            }
        }
    }

    return ans;
}

int main(void) {
    int i, n, num, ans = 0;

    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d", &num);
        if (primenumber(num) == 1) ans++;
    }
    printf("%d\n", ans);

    return 0;
}

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

#define rep(...) repN((__VA_ARGS__,rep3,rep2,loop,~))(__VA_ARGS__)
#define loop(n) rep2(_loop_,n)
#define rep2(i,n) rep3(i,0,n)
#define rep3(i,begin,end) for(int i = (int)(begin), i##_end = (int)(end); i < i##_end; ++i)
#define repN(a) repX a
#define repX(a0,a1,a2,x,...) x

void solve(int N, int A, int B){
	int ans = 0;
	rep(n, 1, N + 1){
		int num = n;
		int sum = 0;
		while(num){
			sum += num % 10;
			num /= 10;
		}
		if(A <= sum && sum <= B) ans += n;
	}
	printf("%d\n", ans);
}

int main(void){
	int N;
	int A;
	int B;
	scanf("%d", &N);
	scanf("%d", &A);
	scanf("%d", &B);
	solve(N, A, B);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,k,s;cin>>n>>k>>s;
  V<ll> ans(n);
  rep(i,0,n){
    if(i<k)ans[i]=s;
    else {
      if(s==mod-7)ans[i]=s-1;
      else ans[i]=s+1;
    }
  }

  rep(i,0,n){
    cout<<ans[i]<<" ";
  }cout<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 2176
#include<stdio.h>
#include<memory.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
using namespace std;
unordered_map<int, vector<int> >m;
int ans;
void dfs(int i, vector<int>&vis, vector<int>&depth)
{
    if(vis[i])return;
    vis[i] = 1;
    if(m.count(i))
    {
        for(auto v : m[i])
        {
            dfs(v, vis, depth);
            depth[i] = max(depth[v]+1, depth[i]);
            ans = max(ans, depth[i]);            
        }
    }
}
int main()
{
    int N, M;
    ans = 0;
    scanf("%d%d", &N, &M);
    vector<int>vis(N+1, 0);
    vector<int>depth(N+1, 0);
    for(int i=0; i<M; i++)
    {
        int v1, v2;
        scanf("%d%d", &v1, &v2);
        m[v1].push_back(v2);
    }
    for(int i=1; i<=N; i++)
    {
        if(vis[i])continue;
        dfs(i, vis, depth);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 12580
#include<stdio.h>
main(void){
	int a,b,d,r;
	double f;
	scanf("%d %d",&a,&b);
	f=(double)a/b;
	d=a/b;
	r=a%b;
	printf("%d %d %f\n",d,r,f);
	return 0;
}

Measured memory_bytes: 636
N = int(input())
a = list(map(int,input().split()))
import heapq
heapq.heapify(a)
for i in range(N-1):
  x = heapq.heappop(a)
  y = heapq.heappop(a)
  z = (x+y)/2
  heapq.heappush(a,z)
answer = heapq.heappop(a)
print(answer)

Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] Xz = new int[M];
        for (int i = 0; i < M; i++){
            Xz[i] = sc.nextInt();
        }
        Arrays.sort(Xz);
        int[] diffz = new int[M];
        for (int i = 1; i < M; i++){
            diffz[i] = Xz[i] - Xz[i - 1];
        }
        Arrays.sort(diffz);
        int[] diffzT = new int[M];
        for (int i = 0; i < M; i++){
            diffzT[M - i - 1] = diffz[i];
        }
        int sum = 0;
        for (int i = 0; i < M; i++){
            if (i < N - 1){
                continue;
            }
            sum += diffzT[i];
        }

        System.out.println(sum);

    }
}

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

int main(){
    string s,t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[i]){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3848
K = int(input())
S = list(input())
MOD = 10**9 + 7
N = len(S)
M = K+N

#nCrは以下のやつ全てを使ってください
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]
 
gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]
 
def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

ans = 0
for i in range(N,M+1):
    ans += nCr(i-1,N-1)*pow(26,M-i,MOD) * pow(25,i-N,MOD)
    ans %= MOD
print(ans)

Measured memory_bytes: 213872
#include <string>
#include <vector>
#include <unordered_map>
#include <set>
#include <map>
#include <iostream>
using namespace std;
using ll = long long;
const int N = 4010;
ll cntrR[N], cntlR[N];
ll cntrG[N], cntlG[N];
ll cntrB[N], cntlB[N];
int cntr, cntg, cntb;
string s;
int n;
int main() {
    cin >> n >> s;
    for(int i = 0; i < n; i ++) {
        cntlR[i] = cntr;
        cntlG[i] = cntg;
        cntlB[i] = cntb;
        if(s[i] == 'R') {
            cntr ++;
        } else if(s[i] == 'G') {
            cntg ++;
        } else {
            cntb ++;
        }
    }
    for(int i = 0; i < n; i ++) {
        cntrB[i] = cntb - cntlB[i];
        cntrG[i] = cntg - cntlG[i];
        cntrR[i] = cntr - cntlR[i];
        if(s[i] == 'R') {
            cntrR[i] --;
        } else if(s[i] == 'G') {
            cntrG[i] --;
        } else {
            cntrB[i] --;
        }
    }
    ll sum = 0;
    for(int i = 1; i < n-1; i ++) {
        if(s[i] == 'R') {
            sum += cntrB[i] * cntlG[i];
            sum += cntrG[i] * cntlB[i];
            for(int j = 1; i - j >= 0 && i + j < n; j ++) {
                if((s[i-j] == 'B' && s[i+j] == 'G' )||( s[i-j] == 'G' && s[i+j] == 'B'))
                sum --;
            }
        } else if(s[i] == 'G') {
            sum += cntlB[i] * cntrR[i];
            sum += cntrB[i] * cntlR[i];
            for(int j = 1; i - j >= 0 && i + j < n; j ++) {
                if((s[i-j] == 'R' && s[i+j] == 'B' )||( s[i-j] == 'B' && s[i+j] == 'R'))
                sum --;
            }
        } else {
            sum += cntlR[i] * cntrG[i];
            sum += cntlG[i] * cntrR[i];
            for(int j = 1; i - j >= 0 && i + j < n; j ++) {
                if((s[i-j] == 'R' && s[i+j] == 'G' )||( s[i-j] == 'G' && s[i+j] == 'R'))
                sum --;
            }
        }
    }
    cout << sum << endl;
} 

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

#define ll long long
#define pb push_back

const int maxn = 3e5 + 20;

int a[maxn];

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

	int n , m;
	cin >> n >> m;

	set<pair<int , int> > st;
	for(int i = 0; i < n; i++)
		cin >> a[i] , st.insert({a[i] - a[i] / 2 , i});

	while(m--)
	{
		int i = st.rbegin() -> second;
		st.erase({a[i] - a[i] / 2 , i});
		a[i] /= 2;
		st.insert({a[i] - a[i] / 2 , i});
	}

	ll res = 0;
	for(int i = 0; i < n; i++)
		res += a[i];
	
	cout << res << endl;
}










 


Measured memory_bytes: 5376
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,q;
	cin>>n>>q;
	vector<int> s(n),t(n),x(n);
	using tpl=pair<pii,pair<pii,int>>;
	vector<tpl> v;
	FOR(i,0,n){
		cin>>s[i]>>t[i]>>x[i];
		v.PB(MP(MP(s[i]-x[i],1),MP(MP(s[i],t[i]),x[i])));
		v.PB(MP(MP(t[i]-x[i],2),MP(MP(s[i],t[i]),x[i])));
	}
	vector<int> d(q+1,mod*2),ans(q+1,mod);
	FOR(i,0,q){
		cin>>d[i];
		v.PB(MP(MP(d[i],3),MP(MP(d[i],i),0)));

	}
	sort(v.begin(),v.end());
	int nn=v.size();
	set<pii> state;//x[i],s[i]
	state.insert(MP(mod,mod));
	FOR(i,0,nn){
		int t=v[i].ST.ST,f=v[i].ST.ND,si=v[i].ND.ST.ST,ti=v[i].ND.ST.ND,xi=v[i].ND.ND;
		if(f==1){
			state.insert(MP(xi,si));
		}else if(f==2){
			state.erase(MP(xi,si));
		}else{
			auto itr=state.begin();
			pii pr=*itr;
			ans[ti]=pr.ST;
			if(ans[ti]==mod)ans[ti]=-1;
		}
	}


	FOR(i,0,q)cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 27492
#include <iostream>
#include <string>
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
using namespace std;

string S;
 
void solve()
{
  int sum = 0;
  forn (i, S.size()) {
    int n = (int)(S[i] - '0');
    sum += n;
  }
  if(stoi(S) % sum == 0){
     cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
  
}

int main(void)
{
  cin >> S;
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int x;
		int ans = 0;
		
		for(int i = 0; i < n; i++){
			x = scan.nextInt();
			if(isprime(x))ans++;
		}
		System.out.println(ans);
	}
	
	public static boolean isprime(int x){
		if(x == 2){
			return true;
		}
		
		if(x < 2 || x % 2 == 0){
			return false;
		}
		
		int i = 3;
		while(i <= Math.sqrt(x)){
			if(x % i == 0){
				return false;
			}
			i += 2;
		}
		
		return true;
	}
}

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

int main(int argc, const char * argv[]) {
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            cout << i << "x" << j << "=" << i*j << "\n";
        }
    }
    return 0;
}

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

int main() {
  
  int N; cin >> N; int tmp = 1;
  
  for (int i = 0; i < N; i++) {
    
    int a; cin >> a;
    
    if (tmp == a) tmp++;
    
  }
  
  if (tmp == 1) cout << -1 << endl;
  
  else cout << N - tmp + 1 << endl;
  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  string s;
  cin >> s;
  s[3] = '8';
  cout << s << endl;
  return 0;
}

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

int main()
{
    ll k;
    cin >> k;

    ll ans = 0;
    for(ll i = 1;i <= k;i++){
        for(ll j = 1;j <= k;j++){
            for(ll n = 1;n <= k;n++){
                ans += __gcd(i, __gcd(j, n));
            }
        }
    }

    cout << ans;

    return 0;
}

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

int calc_gcd(int a,int b){
  if(a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  
  int r = a%b;
  while(r != 0){
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}

int main(){
  int K;
  cin >> K;
  int sum = 0;
  
  for(int i = 1; i<= K; i++){
    for(int j = 1; j <= K; j++){
      for(int k = 1; k <= K; k++){
        int gcd2 = calc_gcd(j,k);
        int gcd3 = calc_gcd(i,gcd2);
        sum += gcd3;
      }
    }
  }
  cout << sum << endl;
}

    

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

int main()
{
	string sa,sb;
	cin >> sa >> sb;
	int la,lb;
	la = sa.length();
	lb = sb.length();
	bool find;
	for(int i=0; i<la; i++){
		find = true;
		for(int j=0; j<lb; j++){
			int k = (i+j) % la;
			if(sa[k] != sb[j]){
				find = false;
				break;
			}
		}
		if(find) break;
	}
	if(find) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 1184
n = int(input())
s = [list(input()) for _ in range(n)]

s0 = list(s[0])
s0.sort()
t0 = s0[::1]


for i in range(len(s0)):
    for j in range(1,n):
        if s0[i] in s[j] :
            s[j].remove(s0[i])
        else:
            t0.remove(s0[i])
            break


print(*t0,sep='')


Measured memory_bytes: 3060