akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
 
N = int(input())
A = list(map(int, input().split()))
s = sum(A)
r = [s - 2 * sum(A[1::2])]

for i in range(N-1):
    r.append(2 * A[i] - r[i])
    
r = map(str, r)
print(" ".join(r))

'''
5
3 8 7 5 5
'''

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

int main() {
int N;//餅の枚数
  cin >> N;
vector<int> diameter(N);//diameterは直径
  int i;
  int previous =101;
  int counter;
  for(i = 0; i < N; i++)
  cin >> diameter.at(i);//入力完了
  int max, j;
  j = 0;

  for (counter = 0; counter < N; counter++){
  max = 0;//最大値の初期化
    for (i = 0; i < N; i++){
  if(max < diameter.at(i) && diameter.at(i) < previous){
    j = max;
    max = diameter.at(i);
    diameter.at(i) = j;}//より大きな餅との交換
  }//最大の餅の抽出
  previous = max;//最大の餅を直前の記憶装置に代入
   if (max == 0)
     break;
  }
  cout << counter << endl;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int a = sc.nextInt();
			String str = "ai1333";
			
			int b = a/100;
			if(b>0)
			for(int i=1;i<=b;i++) {
				str += 3;
			}
			System.out.println(str);
		}
	
	}
}


Measured memory_bytes: 26204
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int n;
	int x;
	int A[100001] = { 0 };
	int B[100001] = { 0 };
	int ans;
	bool flg = false;
	bool flg2 = true;

	cin >> n;
	for (int i = 0; i < n/2; i++)
	{
		cin >> x;
		A[x]++;
		cin >> x;
		B[x]++;
	}
	int maxA = 0;
	int maxB = 0;
	for (int i = 0; i <= 100000; i++)
	{
		if (A[i] > A[maxA]) {
			maxA = i;
		}if (B[i] > B[maxB]) {
			maxB = i;
		}
	}

	if (maxA == maxB && A[maxA] + B[maxB] == n) {
		flg = true;
	}

	if (maxA == maxB) {
		flg2 = false;
	}

	/*cout << "aaa" << maxA << "  " << maxB << endl;
	cout << "max" << A[maxA] << " " << B[maxB] << endl;*/
	sort(A, A + 100000, greater<int>());
	sort(B, B + 100000, greater<int>());

	/*cout << "105<><><" << A[105] << endl;

	for (int i = 0; i < 10; i++)
	{
		
	}*/

	
	if (flg2) {
		//cout << "A" << endl;
		//cout << "NN" << n / 2 << "A[0]" << A[0] << endl;
		ans = (n / 2) - A[0];
		//cout << "x" << ans;
		ans += (n / 2 - B[0]);
		//cout << "y" << ans << endl;
	}
	else {
		/*cout << "B" << endl;
		cout << n / 2 << " " << A[0] << B[1] << endl;*/
		int x = n - A[0] - B[1];
		int y = n - A[1] - B[0];
		ans = min(x, y);
	}

	if (flg) {
		cout << n / 2 << endl;
	}
	else {
		cout << ans << endl;
	}

	return 0;

}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
	static final int MOD = 1000000007;
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer, Integer> map = new HashMap<>();
		for (int i = 2; i <= n; i++) {
		    int x = i;
		    for (int j = 2; j * j <= x; j++) {
		        while (x % j == 0) {
		            if (map.containsKey(j)) {
		                map.put(j, map.get(j) + 1);
		            } else {
		                map.put(j, 1);
		            }
		            x /= j;
		        }
		    }
		    if (x != 1) {
		        if (map.containsKey(x)) {
		            map.put(x, map.get(x) + 1);
		        } else {
		            map.put(x, 1);
		        }
		    }
		}
		int[] arr = new int[5]; //2, 4, 14, 24, 74
		for (int x : map.values()) {
		    if (x >= 2) {
		        arr[0]++;
		    }
		    if (x >= 4) {
		        arr[1]++;
		    }
		    if (x >= 14) {
		        arr[2]++;
		    }
		    if (x >= 24) {
		        arr[3]++;
		    }
		    if (x >= 74) {
		        arr[4]++;
		    }
		}
		long ans = 0;
		ans += arr[4];
		ans += arr[3] * (arr[0] - 1);
		ans += arr[2] * (arr[1] - 1);
		ans += arr[1] * (arr[1] - 1) / 2 * (arr[0] - 2);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23124
using System;
using System.Numerics;
namespace ConsoleApp1123
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine().Trim().Split(' ');
            var a = int.Parse(s[0]);
            var b = int.Parse(s[1]);
            for (int i = 0; i < 1010; i++)
            {
                if (i * 8 / 100 == a && i * 10 / 100 == b)
                {
                    Console.WriteLine(i);
                    return;
                }
            }

            Console.WriteLine(-1);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
#include<ctype.h>

int main(void){
   int i,s[26]={};
   char str;
   while ( scanf("%c", &str) != EOF ){
      if( isalpha(str)){
        if( isupper(str) ){str=tolower(str);}
        ++s[str-'a'];
      }
   }
   for( i=0 ; i < 26 ; i++){
      printf("%c : %d\n",i+'a', s[i]);
   }
   return 0;
}




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

//C++14 (GCC 5.4.1)
int main() {
    int A,B,X;

    cin >>A>>B>>X;
    //-----------------------------------
    bool is=(A<=X && X<=A+B);
    cout << ((is) ? "YES" : "NO") <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
#include <climits>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<string> VS;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<PII> VPI;
typedef vector<PLL> VPL;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ub upper_bound
#define lb lower_bound

const int MAX=1001001;
const int mod=1000000007;
ll fac[MAX],finv[MAX],inv[MAX];

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

ll modinv(ll a){
  return modpow(a,mod-2);
}

void init(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  rep(i,MAX){
    if(i>1){
      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 com(int n,int k){
  if(n<k) return 0;
  if(n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int main(){
  int N;
  cin>>N;
  ll ans=0;
  ll mod=1e9+7;
  init();
  ll sum=0;
  ll tmp=0;
  rep(i,N){
    ll tmp=com(i-1,N-1-i)%mod*fac[i]%mod*fac[N-1-i]%mod;
    (ans+=(tmp+mod-sum)%mod*i%mod)%=mod;
    sum=tmp;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 23680
#include<stdio.h>
#include<strings.h>

int main(void){
    int k,n;
    scanf("%d %d", &k,&n);
    int pos[n],dis[n];
    int i;
    for(i=0;i<n;i++){
        scanf("%d", &pos[i]); //0 to i-1
    }
    for(i=0;i<n-1;i++){
        dis[i] = pos[i+1] - pos[i];
    }
    dis[n-1] = k - pos[n-1] + pos[0];

    int maxd = 0;
    for(i=0;i<n;i++){
        if(maxd < dis[i]) maxd = dis[i];
    }

    printf("%d", k-maxd);
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
struct SegTree {
    int N;
    vector<int> A;
    function<int(int, int)> F;
    int U;
    SegTree(const vector<int> &B, function<int(int, int)> f, int unit) {
        N = 1; while (N < B.size()) N *= 2;
        A.resize(N * 2, unit);
        F = f;
        U = unit;
        for (int i = 0; i < B.size(); i++) {
            A[N + i] = B[i];
        }
        for (int i = N - 1; i > 0; i--) {
            A[i] = F(A[2*i+0], A[2*i+1]);
        }
    }
    int query(int L, int R) {
        int ans = U;
        L += N, R += N;
        while (L < R) {
            if (L & 1) ans = F(ans, A[L++]);
            if (R & 1) ans = F(ans, A[--R]);
            L /= 2, R /= 2;
        }
        return ans;
    }
};
int main() {
    int N; cin >> N;
    vector<pair<int, int>> A(N);
    for (int i = 0; i < N; i++) cin >> A[i].first >> A[i].second;
    int ans = 0;
    auto f = [&]() {
        vector<int> L(N), R(N);
        for (int i = 0; i < N; i++) {
            L[i] = A[i].first;
            R[i] = A[i].second;
        }
        SegTree Lmax(L, [](int x, int y) { return max(x, y); }, -1e9);
        SegTree Rmin(R, [](int x, int y) { return min(x, y); }, 1e9);
        for (int i = 0; i < N; i++) {
            int t = R[i] - L[i] + 1;
            t += max(0, min(Rmin.query(0, i), Rmin.query(i + 1, N)) - max(Lmax.query(0, i), Lmax.query(i + 1, N)) + 1);
            ans = max(ans, t);
        }
        for (int i = 1; i < N; i++) {
            int t = max(0, Rmin.query(0, i) - Lmax.query(0, i) + 1) + max(0, Rmin.query(i, N) - Lmax.query(i, N) + 1);
            ans = max(ans, t);
        }
    };
    sort(begin(A), end(A));
    f();
    sort(begin(A), end(A), [](auto &p, auto &q) { return make_pair(p.second, -p.first) < make_pair(q.second, -q.first); });
    f();
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3840
#include <iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;

int main(void){
  int n;
  cin >> n;
  int sum = 0;
  vector<pair<string,int>> p(n);
  for(int i = 0;i < n;i++){
       cin >> p[i].first >> p[i].second;
       sum += p[i].second;
  }
  string x;
  cin >> x;
  for(int i = 0;i < n;i++){
        sum -= p[i].second;
        if(x == p[i].first)break;
  }
  cout << sum << endl;
}


Measured memory_bytes: 3596
def myfunc(op):
    if op == 1:
        return "+"
    else:
        return "-"


a, b, c, d = [int(i) for i in list(input())]

for j in range(8):
    op = [1, 1, 1]
    for i in range(3):
        if (j >> i) & 1:
            op[i] = -1
    if a + b * op[0] + c * op[1] + d * op[2] == 7:
        x = myfunc(op[0])
        y = myfunc(op[1])
        z = myfunc(op[2])
        print(f"{a}{x}{b}{y}{c}{z}{d}=7")
        exit()

Measured memory_bytes: 9204
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int gcd(int x,int y){
	
	if(x%y==0){
		return y;
	}else{
		return gcd(y,x%y);
	}
	
}


int main() {
	
	ll N,M;
	string S,T;
	cin>>N>>M>>S>>T;
	ll ans;

	if(N>M){
		ans=gcd(N,M);
	}else{
		ans=gcd(M,N);
	}
  ans=N/ans*M;
  
  map<ll,int> A;
    ll k=ans/N,l=ans/M;
    fx(N){
    A[k*x+1]=1;
  }
  fx(M){
    if(A[l*x+1]==1){
      if(T.at(x)!=S.at(x*N/M)){
        ce("-1")
        return 0;
      }
    }
  } 
  
	ce(ans)

}

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

int main() {
  int H, W;
  cin >> H >> W;
  
  vector<vector<char>> A(H, vector<char>(W));
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A.at(i).at(j);
    }
  }
  
  vector<bool> h(H);
  vector<bool> w(W);
  
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if(A.at(i).at(j) == '#') {
        h.at(i) = true;
        w.at(j) = true;
      }
    }
  }
  
  for (int i = 0; i < H; i++) {
    if(h.at(i) == true) {
      for (int j = 0; j < W; j++) {
        if(w.at(j) == true) {
          cout << A.at(i).at(j);
        }
      }
      cout << endl;
    }
  }
}

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

int main(){
    int N, D, X;
    cin >> N;
    int A[N];
    cin >> D >> X;
    for(int i=0; i<N; i++){
        cin >> A[i];
    }

    int ans = X;

    for(int i=0; i<N; i++){
        int tmp = (D-1) / A[i];
        ans += (tmp + 1);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3528
import java.util.*;

public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      	String s=sc.next();
      	int o=0;
      	int l=s.length();
      	for(int i=0;i<l/2;i++){
        	char a=s.charAt(i);
          	char b=s.charAt(l-i-1);
          	if(a!=b)o++;
        }
     	 System.out.println(o);
    }
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main() {
    int n, m;
    cin >> n >> m;
    vector<bool> ac(n, false);
    vector<int> pe(n, 0);
    int p; string s;
    for (int i = 0; i < m; ++i) {
        cin >> p >> s;
        p--;
        if (s == "AC") ac[p] = true;
        else {
            if (!ac[p]) pe[p]++;
        }
    }

    int resac = 0;
    int respe = 0;
    for (int i = 0; i < n; ++i) {
        if (ac[i]) resac++;
        if (ac[i]) respe += pe[i];
    }
    cout << resac << " " << respe << endl;
}


Measured memory_bytes: 3676
class Solver(object):
    def __init__(self):
        self.n = int(input())
        self.a_s = list(map(int, input().split(" ")))
        self._evens = None

    def solve_archive(self):
        if len(self.evens) == 0:
            return 0
        number = min(self.evens)

    def solve(self):
        print(sum(map(Solver.count_multiple_of_two, self.a_s)))

    @staticmethod
    def count_multiple_of_two(number):
        counter = 0
        while number % 2 == 0:
            number /= 2
            counter += 1
        return counter

    @property
    def evens(self):
        if self._evens is None:
            self._evens = []
            for a in self.a_s:
                if a % 2 == 0:
                    self._evens.append(a)
        return self._evens


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 4148
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define rep(i, a, b) for(ll i = a; i < b; ++i)
using namespace std;
typedef long long ll;
typedef vector<ll> vll;

int main()
{
	FIO;
    ll n, x, s = 0LL; cin >> n;
    map<ll, ll> mp;
    rep(i, 0, n) {
        cin >> x;
        s += x;
        mp[x]++;
    }
    ll q; cin >> q;
    rep(i, 0, q) {
        ll a, b; cin >> a >> b;
        s += mp[a] * b - mp[a] * a;
        cout << s << '\n';
        mp[b] += mp[a];
        mp.erase(a);
    }
	return 0;
}

Measured memory_bytes: 7528
#pragma GCC optimize(3)
#pragma GCC optimize(s)
#include <cstdio>
using namespace std;

inline int mypow(const int& x,const int& y)
{
	int sum=1;
	for(int i=1;i<=y;i++)
		sum*=x;
	return sum;
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=6;i>=0;i--) {
		int t=mypow(2,i);
		if(t<=n) {
			printf("%d\n",t);
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#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() {
  int n;
  ll d;
  cin >> n >> d;
  int ans = 0;
  rep(i, n) {
    ll x, y;
    cin >> x >> y;
    if(x*x + y*y <= d*d) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
//<<setprecision(30)
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int main(){
  ll k; cin>>k;
  queue<ll> que;
  rep1(i,9){
    que.push(i);
  }
  rep1(i,k){
    ll res = que.front();
    if(i==k){
      cout<<res<<endl;
      return 0;
    }
    if(res%10==0){
      que.push(10*res+res%10);
      que.push(10*res+res%10+1);
    }else if(res%10==9){
      que.push(10*res+res%10-1);
      que.push(10*res+res%10);
    }else{
      que.push(10*res+res%10-1);
      que.push(10*res+res%10);
      que.push(10*res+res%10+1);
    }
    
    que.pop();
    
  }
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl

const int MN = 3010;

int dp[MN][MN];
pii pre[MN][MN];

int main() {
	string s, t; cin >> s >> t;
	int n = s.size(), m = t.size();

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (s[i-1] == t[j-1]) {
				if (dp[i][j] < dp[i-1][j-1] + 1) {
					dp[i][j] = dp[i-1][j-1] + 1;
					pre[i][j] = mp(i-1, j-1);
				}
			} else {
				if (dp[i][j] < dp[i][j-1]) {
					dp[i][j] = dp[i][j-1];
					pre[i][j] = mp(i, j-1);
				}
				if (dp[i][j] < dp[i-1][j]) {
					dp[i][j] = dp[i-1][j];
					pre[i][j] = mp(i-1, j);
				}
			}
		}
	}

	int val = dp[n][m];
	string ans;
	int pi = n, pj = m;

	while (pi > 0 && pj > 0) {
		if (s[pi-1] == t[pj-1]) {
			ans.pb(s[pi-1]);
			--pi; --pj;
			continue;
		}
		pii pr = pre[pi][pj];
		pi = pr.fi; pj = pr.se;
	}

	reverse(ALL(ans));
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 106368
#include <iostream>

using namespace std;





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

    int x,y,z;
    cin >> x >> y >> z;
    int a=x, b=y, c=z;
    a = y, b = x;
    a = z, c = y;

    cout << a;
    cout << " " << b;
    cout << " " << c;


}




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

#define FOR(i,s,t) for(int i=s;i<t;i++)
#define REP(i,n) FOR(i,0,n)
#define PRINT(s) cout << s << "\n"
#define SORT(A) sort(A.begin(), A.end())
#define EACHPRINT(A, T) for_each(begin(A), end(A), [&](T i){ cout << i << " "; });cout << "\n"

typedef long lint;
typedef pair<lint, lint> P;

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

    vector<lint> a;

    REP(_, N) {
      lint x; cin >> x; a.push_back(x);
    }

    lint max_a = *max_element(a.begin(), a.end());

    lint res = 0;
    REP(i, N) {
      lint current_a = a[i];
      if( abs((max_a)/2 - current_a) < abs(max_a/2 - res)) {
        res = current_a;
      }
    }

    cout << max_a << " " << res << "\n";
    return 0;
}


Measured memory_bytes: 1400
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{ll n,a,b;
cin>>n>>a>>b;
ll rem=n%(a+b);
ll ans=(n/(a+b))*a;
if(rem){
    ans+=min(a,rem);
}cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int x,y,i,z;
    cin >> x >> y;
    
    for(i=1;i<=10000;i++){
        if(x==0 && y==0){
            break;
        }
        if(x>y){
        cout << y <<" "<< x<<endl;
        cin >> x >> y;
       
        }
        else{
          cout << x <<" "<< y<<endl;
          cin >> x >> y;
        }
    }
    
}


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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

void solve() {
    i64 n, w;
    cin >> n >> w;

    vector<i64> dp(w + 1);
    for (i64 i = 0; i < n; i++) {
        i64 wi, vi;
        cin >> wi >> vi;

        for (i64 j = w; j >= wi; j--) {
            dp[j] = max(dp[j], dp[j - wi] + vi);
        }
    }
    cout << *max_element(all(dp)) << endl;
}

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


Measured memory_bytes: 3960
<>;map{push@$_,$_[--$|]for@_=glob}<>;sub f{my($x,$b,$w)=($_,1,1);$_-"@_"and f($x),$b=$b*$c%($==1e9+7),$w=$w*$d%$=for@$x;$c=$w;$d=$b+$w}$_=1;f;print$d%$=

Measured memory_bytes: 185600
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vi vector <ll> 
#define qu queue <ll>
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


void solve()
{
    int k, a, b; cin >> k >> a >> b;
    for (int i=a; i<=b; i++)
    {
        if (i%k==0)
        {
            nout("OK"); return;
        }
    }
    nout("NG");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3612
#include<iostream>

using namespace std;

int main(){
  int sm=0, mx=0, a[4];
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  for(int i=0;i<3;i++){
    sm += abs(a[i]- a[(i+1)%3]);
    mx = max(mx,abs(a[i]- a[(i+1)%3]));
  }
  cout << sm-mx << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
//import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		//System.setIn(new FileInputStream("./input.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
		
		int n = Integer.parseInt(br.readLine());
		boolean[] dict = new boolean[(int) Math.pow(5, 12)];
		char[] c;
		for(int i = 0; i < n; ++i) {
			c = br.readLine().toCharArray();
			if(c[0] == 'i'){
				// insert
				dict[hash(Arrays.copyOfRange(c, 7, c.length))] = true;
			}else{
				// find
				if(dict[hash(Arrays.copyOfRange(c, 5, c.length))] == true){
					sb.append("yes\n");
				}else{
					sb.append("no\n");
				}
			}
		}
		System.out.print(sb);
	}
	public static int hash(char[] c){
		int a;
		int hash = 0;
		for(int i = 0; i < c.length; ++i) {
			switch(c[i]){
			case 'A':
				a = 1;
				break;
			case 'C':
				a = 2;
				break;
			case 'G':
				a = 3;
				break;
			default:
				a = 4;
				break;				
			}
			hash = hash*5 + a;
		}
		return hash;
	}
}

Measured memory_bytes: 311852
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
#define int ll
signed main(){
    int n; cin >> n;
    vector<int>p(n);  rep(i,n) cin >> p[i];
    vector<int>a(n),b(n);
    int maxi = 40000;
    rep(i,n){
        a[i] = maxi*(i+1);
        b[i] = maxi*(n-i-1)+1;
    }
    rep(i,n){
        a[p[i] - 1] += i;
    }
    join(a); cout << endl;
    join(b); cout << endl;
}






Measured memory_bytes: 1256
#include<stdio.h>

int main(){
 int W,H;
 int x,y,r;
 scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
 if(x>=r && (W-x)>=r && y>=r && (H-y)>=r)
 printf("Yes\n");
 else printf("No\n");
 return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
	int n, u, v, i, j, a, b, d[100003] = {}, p, par[100003], lim, dmax;
	vector<int> g[100003];
	queue<int> q, th;

	scanf("%d%d%d", &n, &u, &v);
	for (i = 0; i < n - 1; i++) {
		scanf("%d%d", &a, &b);
		g[a - 1].push_back(b - 1);
		g[b - 1].push_back(a - 1);
	}

	q.push(v - 1);
	d[v - 1] = 1;
	while (!q.empty()) {
		p = q.front();
		q.pop();
		for (i = 0; i < g[p].size(); i++) {
			if (d[g[p][i]] == 0) {
				d[g[p][i]] = d[p] + 1;
				q.push(g[p][i]);
			}
		}
	}

	par[v - 1] = -1;
	for (i = 0; i < n; i++) {
		for (j = 0; j < g[i].size(); j++) {
			if (d[i] < d[g[i][j]]) {
				par[g[i][j]] = i;
			}
		}
	}

	p = u - 1;
	lim = (d[u - 1] + 1) / 2 + 1;
	while (d[p] > lim) {
		p = par[p];
	}

	th.push(p);
	while (!th.empty()) {
		p = th.front();
		th.pop();
		dmax = max(dmax, d[p]);
		for (i = 0; i < g[p].size(); i++) {
			if (d[p] < d[g[p][i]]) {
				th.push(g[p][i]);
			}
		}
	}

	printf("%d\n", dmax - 2);

	return 0;
}

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

int main() {
  int n, max_w;
  cin >> n >> max_w;
  vector<int> v(n);
  vector<int> w(n);
  rep (i, n) {
    cin >> w.at(i) >> v.at(i);
  }
  vector<vector<ll>> dp(n+1,vector<ll>(100001, 1000000000001));
  dp[0][0] = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= 100000; j++) {
      if (dp.at(i).at(j) == 1000000000001) continue;
      dp.at(i+1).at(j) = min(dp.at(i+1).at(j), dp.at(i).at(j));
      dp.at(i+1).at(j+v.at(i)) = min(dp.at(i+1).at(j+v.at(i)), dp.at(i).at(j) + w.at(i));
    }
  }
  ll maximum = 0;
  rep (i, 100001) {
    if (dp.at(n).at(i) <= max_w) maximum = max(maximum, (ll)i);
  }
  cout << maximum << endl;
  return 0;
}


Measured memory_bytes: 80256
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;

  int a[n],m=0;
  for(int i=2;m<n;i+=2){
    int b=5*i+1;
    int j;
    for(j=3;j*j<=b;j+=2){
      if(b%j==0) break;
    }
    if(j*j>b) a[m++]=b;
  }

  for(int i=0;i<n-1;i++) cout << a[i] << ' ' << endl;
  cout << a[n-1] << endl;
    
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
   
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>

const int inf = 1e7;

signed main()
{
    fast;
    
    int n,m,k;
    cin >> n >> m >> k;
    
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    
    string grid[n];
    f(i,n) cin >> grid[i];
    
    queue<pii> q;
    q.push({x1,y1});
    
    int dis[n][m];
    f(i,n) f(j,m) dis[i][j] = inf;
    
    set<int> row[n];
    set<int> col[m];
    
    f(i,n) f(j,m) row[i].insert(j);
    f(i,n) f(j,m) col[j].insert(i);
    
    row[x1].erase(y1);
    col[y1].erase(x1);
    dis[x1][y1] = 0;
    
    while(!q.empty())
    {
        auto x = q.front(); q.pop();
        
        int dd = dis[x.F][x.S] + 1;
       
        while(1)
        {
            if(row[x.F].empty()) break;
            
            auto v = row[x.F].upper_bound(x.S);
            
            if(v == row[x.F].begin()) break;
            
            --v;
            
            int xx = (*v);
            
            if(abs(x.S-xx) > k) break;
            
            if(grid[x.F][xx] == '@') break;
            
            dis[x.F][xx] = dd;
            
            q.push({x.F,xx});
            
            row[x.F].erase(xx);
            col[xx].erase(x.F);
        }
        
        while(1)
        {
            if(row[x.F].empty()) break;
            
            auto v = row[x.F].upper_bound(x.S);
            
            if(v == row[x.F].end()) break;
            
            int xx = (*v);
           
            if(abs(x.S-xx) > k) break;
           
            if(grid[x.F][xx] == '@') break;
           
            dis[x.F][xx] = dd;
            
            q.push({x.F,xx});
            
            row[x.F].erase(xx);
            col[xx].erase(x.F);
        } 
        
        while(1)
        {
            if(col[x.S].empty()) break;
            
            auto v = col[x.S].upper_bound(x.F);
            
            if(v == col[x.S].begin()) break;
            
            --v;
            
            int xx = (*v);
            
            if(abs(x.F-xx) > k) break;
            
            if(grid[xx][x.S] == '@') break;
           
            dis[xx][x.S] = dd;
            
            q.push({xx,x.S});
            
            row[xx].erase(x.S);
            col[x.S].erase(xx);
        }
        
        while(1)
        {
            if(col[x.S].empty()) break;
            
            auto v = col[x.S].upper_bound(x.F);
            
            if(v == col[x.S].end()) break;
            
            int xx = (*v);
            
            if(abs(x.F-xx) > k) break;
            
            if(grid[xx][x.S] == '@') break;
          
            dis[xx][x.S] = dd;
            
            q.push({xx,x.S});
            
            row[xx].erase(x.S);
            col[x.S].erase(xx);
        }
        
    }
    
    
    if(dis[x2][y2] == inf) cout << -1;
    else cout << dis[x2][y2];
}

Measured memory_bytes: 148668
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] x = new Integer[n];
        Arrays.setAll(x, i -> Integer.parseInt(sc.next()));
        sc.close();

        // 主処理
        Integer[] clone = x.clone();

        Arrays.sort(x);
        int centerL = x[(n / 2) - 1];
        int centerR = x[n / 2];

        String[] array = new String[n];
        for (int i = 0; i < n; i++) {
            int num = clone[i];
            if (num <= centerL) {
                array[i] = Integer.toString(centerR);
            } else {
                array[i] = Integer.toString(centerL);
            }
        }

        String result = String.join("\n", array);

        // 出力
        System.out.println(result);
    }
}


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

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

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

int main() {
	long n,i,k,ans=0;
	cin >> n >> k;
	vector<long> h(n);
	for(i=0; i<n; i++){
		cin >> h[i];
	}
	sort(h.begin(),h.end());
	for(i=0; i<n-k; i++){
		ans+=h[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())

lm = 0
rm = 10**5+1
for _ in range(M):
    l, r = map(int, input().split())
    lm = max(lm, l)
    rm = min(rm, r)

ans = rm - lm + 1
print(ans if ans >= 0 else 0)


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

const string YES = "Yes";
const string NO = "No";

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    int n = stoi(a + b);
    int sqr = (int)sqrt(n);
    if (sqr * sqr == n) cout << YES << '\n';
    else cout << NO << '\n';
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

    int count = 0;

    for(int  X = 0 ; X <= K ; X ++){
      for(int  Y = 0 ; Y <= K ; Y ++){
        int Z = S - X - Y ;
        if( Z >= 0 && Z <= K ){
          count ++;
        }
      }
    }
    System.out.println(count);
  }
}


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


int main(){
  int N,sum,max;
  vector<int> prices;
  cin>>N;
  sum=0;
  max=0;
  
  for(int i=0;i<N;i++){
    int price;
    cin>>price;
    sum = sum + price;
    if(max<price){
      max=price;
    }
  }
  sum = sum - max/2;
  cout<<sum;
}

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

// #include <iomanip>

using ll = long long;

int main() {
  int N;

  std::cin >> N;

  std::vector<ll> A(N);

  for (int i=0; i<N; i++)
    std::cin >> A[i];

  std::vector<ll> dp_p(N+1);
  std::vector<ll> dp_n(N+1);

  dp_n[0] = -1e10;

  for (int i=0; i<N; i++) {
    dp_p[i+1] = std::max(dp_p[i]+A[i], dp_n[i]-A[i]);
    dp_n[i+1] = std::max(dp_p[i]-A[i], dp_n[i]+A[i]);
  }

  // for (int i=1; i<N+1; i++)
  //   std::cerr << std::setw(4) << dp_p[i];
  // std::cerr << std::endl;
  // for (int i=1; i<N+1; i++)
  //   std::cerr << std::setw(4) << dp_n[i];
  // std::cerr << std::endl;

  std::cout << dp_p[N] << std::endl;

  return 0;
}


Measured memory_bytes: 2688
#include <stdio.h>

main(void)
{
	int a,b,c,n,m,H=0;
	
	scanf("%d",&n);
	
	for(m=0;m<n;m++){
		H=0;
		scanf("%d %d %d",&a,&b,&c);
		
		if(a*a==b*b+c*c)H=1;
		if(b*b==a*a+c*c)H=1;
		if(c*c==a*a+b*b)H=1;
		
		if(H==1)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

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

using i64 = int64_t;

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

    return 0;
}


Measured memory_bytes: 256
import sys
from math import ceil
def input(): return sys.stdin.readline().strip()


def main():
    L = int(input())
    """
    L=Xのときにグラフが作れたとして、L=X*2, L=X+1の２パターンを
    構成できたら辺の数をlog(L)の増大率で任意のLに対して目的のグラフを構成できる。
    L=X+1の場合はスタートとゴールの間に長さLの辺を追加するだけでよい。
    L=X*2の場合はL=Xのときの辺長をすべて２倍して、さらにゴールから長さ0, 1の二重辺をつけ足せばよい。
    """

    # 先に頂点と辺の数だけ求める
    N = 2
    M = 2
    even = 0
    order = [L]
    while L != 2:
        if L % 2 == 0:
            N += 1
            M += 2
            L //= 2
            even += 1
        else:
            M += 1
            L -= 1
        order.append(L)
    print("{} {}".format(N, M))
    order.pop()
    
    # 次に各辺間の距離を求める
    #print(order)
    print("{} {} {}".format(1, 2, 0))
    print("{} {} {}".format(1, 2, 2** even))
    edge = 2
    while order:
        L = order.pop()
        if L % 2 == 0:
            even -= 1
            print("{} {} {}".format(edge, edge + 1, 0))
            print("{} {} {}".format(edge, edge + 1, 2 ** even))
            edge += 1
        else:
            print("{} {} {}".format(1, edge, (L - 1) * 2 ** even))
            


if __name__ == "__main__":
    main()


Measured memory_bytes: 38344
import sys
ans=1
n=int(input())
a=list(map(int, input().split()))
for i in range(n):
    if a[i]==0:
        print("0")
        sys.exit()
for i in range(n):
    if a[i]*ans<=10**18:
        ans*=a[i]
    else:
        print("-1")
        sys.exit()
print(ans)

Measured memory_bytes: 21792
#include <cstdio>

int main(){
    int N, X;
    scanf("%d %d", &N, &X);
    int L[N];
    for(int i = 0; i < N; i++){
        scanf("%d", &L[i]);
    }
    
    int D[N+1];
    D[0] = 0;
    for(int i = 1; i < N+1; i++){
        D[i] = D[i-1] + L[i-1];
    }

    int count = 0;
    for(int i = 0; i < N+1; i++){
        if(D[i] <= X){
            count++;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		String s = String.valueOf(n);
		int total = 0;

		for (int i =0; i < s.length(); i++){
			char ch = s.charAt(i);
			total += Character.getNumericValue(ch);
		}
		if (n % total == 0){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
    vector<int> x(10000);


    
    for(int i = 0; i < 10000; i++){
        cin >> x.at(i);
        if(x.at(i) == 0){
            break;
        }
        cout << "Case " << i + 1 << ": " << x.at(i) << endl; 
    }
}





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

using namespace std;

const int MAXN=2e4+1;

int h,n,a[MAXN],b[MAXN],dp[MAXN],max_a=0,ans=-1;

int main() {
	scanf("%d %d",&h,&n);
	for(int i=1; i<=n; ++i) {
		scanf("%d %d",&a[i],&b[i]);
		max_a=max(max_a,a[i]);
	}
	memset(dp,-1,sizeof(dp));
	dp[0]=0;
	for(int i=1,j; i<=n; ++i)
		for(j=a[i]; j<=h+max_a; ++j)
			if(dp[j-a[i]]!=-1 && (dp[j]==-1 || dp[j]>dp[j-a[i]]+b[i])) {
				dp[j]=dp[j-a[i]]+b[i];
				if(j>=h && (ans==-1 || ans>dp[j])) ans=dp[j];
			}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from itertools import groupby
def resolve():
    n,k=map(int,input().split())
    A=list(map(lambda x:int(x)-1,input().split()))
    S=[0]*(n+1)
    for i in range(n):
        S[i+1]=S[i]+A[i]
        S[i+1]%=k
    T=[(s,i) for i,s in enumerate(S)]
    T.sort()

    ans=0
    for key,group in groupby(T,lambda x:x[0]):
        G=[i for s,i in group]
        n=len(G)
        r=0
        for l in range(n):
            while(r+1<n and G[r+1]-G[l]<k):
                r+=1
            ans+=r-l
    print(ans)
resolve()

Measured memory_bytes: 99928
import math

def comb(n, k, MOD, N):
    fact = [1]*(N+1)
    rfact = [1]*(N+1)
    r = 1
    for i in range(1, N+1):
        fact[i] = r = r * i % MOD
    rfact[N] = r = pow(fact[N], MOD-2, MOD)
    for i in range(N, 0, -1):
        rfact[i-1] = r = r * i % MOD
    return fact[n] * rfact[k] * rfact[n-k] % MOD

x, y = map(int, input().split())
mod = 10**9+7

diff = abs(x-y)
if (min(x, y) - diff) % 3 != 0 or (min(x, y) - diff) < 0:
    print(0)
else:
    count = (min(x, y) - diff) // 3
    print(comb(2*count+diff, count, mod, 10**6))

Measured memory_bytes: 82164
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll MOD = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
int n,k,r,s,p;
cin >> n >> k >> r >> s >> p;
string t;
cin >> t;
int sum = 0;
for(int i = 0;i<n;i++){
    if(t[i]=='r') sum += p;
    else if(t[i]=='s') sum += r;
    else sum += s;
}
vector<bool>b(n,0);
for(int i = 0;i<k;i++){
    for(int j = i+k;j<n;j = j+k){
        if(t[j]==t[j-k]&&b[j-k]==0){
            b[j] = 1;
            if(t[j]=='r') sum -= p;
            else if(t[j]=='s') sum -= r;
            else sum -= s;
        }
    }
}
cout << sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3732
#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() {
  ll n, k;
  cin >> n >> k;

  ll res = min(n % k, abs(n % k - k));

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int st[25]={0,1,2,3,4,5,6,7,8,9,5,4,3,2,1,0,1,2,3,4,5,6,7,8,9};
  int n,s,g,i;
  scanf("%d",&n);
  
  while(n--){
    scanf("%d %d",&s,&g);

      for(i=(s>g&&s<6)?15-s:s;st[i]!=g;i++)
	printf("%d ",st[i]);
      printf("%d\n",st[i]);

  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(void) {
  int n,ans=0,a=0;
  cin >> n;
  for(int i=1;i<=n;i+=2) {
    a=0;
    for(int j=1;j<=i;j++) {
      if(i % j == 0) ++a;
    }
    if(a==8) ++ans;
  }
  cout << ans << endl;
}



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

int main()
{
    int P,Q,R;
    cin >> P >> Q >> R;

    int ans;
    ans = min(P + Q , min(Q + R,R + P));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
 
x = int(input())
 
 
def make_divisors(n):
    divisors = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n // i)
 
    # divisors.sort()
    return divisors
 
 
for i in range(len(make_divisors(x))):
    for j in range(130):
        if j ** 5 - (j - make_divisors(x)[i]) ** 5 == x:
            print(j, j - make_divisors(x)[i])
            sys.exit()

Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
    
int main(){ 
    long long n;
    cin >> n;
    long long temp;
    long long ans = n-1;
    for(long long i = 1; i <= sqrt(n); i++){
        if(n % i == 0){
            temp = n / i;
            ans = min(ans, temp-1+i-1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//in the name of god
#include <bits/stdc++.h>
using namespace std;
#define MAX_N (int)1e5+20
#define INF 1e9+20
#define pb push_back
#define F first
#define S second
typedef long long LL;
typedef pair<int,int> pii;
const int delta=(int)1e9+7;
string s,x; int t;
int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin>>s;
	for(int i=0;i<8;++i){
		x=s[0]; t=(int)(s[0]-'0');
		for(int j=0;j<3;++j){
			if(i&(1<<j)){x+="+"; x+=s[j+1]; t+=(int)(s[j+1]-'0');}
			else{x+="-"; x+=s[j+1]; t-=(int)(s[j+1]-'0');}
		} x+="=7";
		if(t==7){
			cout<<x; break;
		}
	}
	return cout<<endl,0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
using namespace std;
using lint = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int ans = -1;
  int A, B;
  cin >> A >> B;
  rep(i, 10001) {
    int a = i * 0.08;
    int b = i * 0.1;
    if (a == A && b == B) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int divisor(int x){
    set<int> se;
    for(int i = 1; i * i <= x; i++){
        if(x % i == 0) {
            se.insert(i);
            se.insert(x/i);
        }
    }
    return se.size();
}

int main(){
    int n; cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i+=2){
        if(divisor(i) == 8) {
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
ex3_2
tomatokan
*/
#include<stdio.h>

int main(void){
    int n,k,i,l;
    scanf("%d",&n);
    scanf("%d",&k);
    i=1;
    l=k;/*l=k^i*/
    while(n>=l){/*n>=l ならn>=k^i*/
        i++;
        l=l*k;
    }
    printf("%d\n",i);
    return 0;
}

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

using namespace std;

struct Rest
{
  int no;
  string name;
  int point;
};

bool res_compare(const Rest &res1 , const Rest &res2) {
  int ret = 1;
  int comp = res1.name.compare(res2.name);

  if(comp > 0 ) ret = 0;
  if(comp < 0 ) ret = 1;
  if(comp == 0) {
    if(res1.point >= res2.point){
      ret = 1;
    }else{
      ret =  0;
    }
  }

  return ret;
}

int main () {
  int n = 0;
  cin >> n ;
  
  vector<Rest> res(n);
  
  string rn;
  int rr;
  
  for (int i = 0 ; i < n ; i++){
    cin >> rn >> rr;
    //cout << rn << " " << rr << endl;
    Rest r ;
    r.no = i + 1;
    r.name = rn;
    r.point = rr;
    res.at(i) = r;
  }
  
  sort(res.begin(),res.end(),res_compare);

  for(int i = 0 ; i < res.size() ; i++) {
    cout << res.at(i).no 
      //<< " " << res.at(i).name << ":" << res.at(i).point 
      << endl;
  }

  return 0;
}

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

#print(A,B)

for i in range(N):
  if A+1<B:
    A +=1
  else:
    A += -1
    if A <1:
      ans="Borys"
      break
  #print(i,A,B)
    
  if A<B-1:
    B += -1
  else:
    B += 1
    if B >N:
      ans="Alice"
      break
  #print(i,A,B)
else:
  ans="Draw"
  
print(ans)

Measured memory_bytes: 3060
main :: IO ()                                                                                                              
main = do                                                                                                                  
  sa <- getLine                                                                                                            
  sb <- getLine                                                                                                            
  sc <- getLine                                                                                                            
  putStrLn $ solve 'a' sa sb sc                                                                                            
                                                                                                                           
solve :: Char -> String -> String -> String -> String                                                                      
solve 'a' [] _ _ = "A"                                                                                                     
solve 'b' _ [] _ = "B"                                                                                                     
solve 'c' _ _ [] = "C"                                                                                                     
solve x as bs cs                                                                                                           
  | x == 'a' = solve (head as) (tail as) bs cs                                                                             
  | x == 'b' = solve (head bs) as (tail bs) cs                                                                             
  | x == 'c' = solve (head cs) as bs (tail cs)

Measured memory_bytes: 508