akhauriyash/Code-Regression huggingface dataset:
a_500 = int(input())
b_100 = int(input())
c_50 = int(input())
kadai = int(input())
sum_coins = []

for a in range(0, a_500+1, 1):
    for b in range(0, b_100+1, 1):
        for c in range(0, c_50+1, 1):
            sum_coins.append((500*a)+(100*b)+(50*c))
print(sum_coins.count(kadai))

Measured memory_bytes: 14036
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using namespace std;


void solve(std::string S){
  for (int i = 0; i < S.size(); ++i) {
    cout << "x";
  }
  std::cout << std::endl;
}

int main(){
  std::string S;
  std::cin >> S;
  solve(S);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
double eps=1e-8;
ll mod=1e9+7;
ll inf=1e9;
priority_queue<P,vector<P>,greater<P> > pq;
 
int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  for(ll b=k+1;b<=n;b++){
    ans+=n/b*(b-k);
    ans+=max(0LL,n%b-k+(k==0?0:1));
  }
  
  cout<<ans<<endl;
  return 0;
}

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

const ll INF = 1LL << 60;

vector<int> G[(int)1e5 + 5];

int color[(int)1e5 + 5];
ll N, M;

bool dfs(int v, int c) {
    color[v] = c;
    for (int i = 0; i < G[v].size(); i++) {
        // 隣接している頂点が同じ色
        if (color[G[v][i]] == c) return false;

        // 隣接している頂点がまだ塗られていない
        if (color[G[v][i]] == 0 && !dfs(G[v][i], -c)) return false;
    }

    return true;
}

int main() {
    cin >> N >> M;
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 二部グラフかどうかの判定フラグ
    bool nibu = true;
    for (int i = 0; i < N; i++) {
        if (color[i] == 0) {
            if (!dfs(i, 1)) {
                nibu = false;
                break;
            }
        }
    }

    if (nibu) {
        // 二部グラフの場合、異なる色通しで辺ができる
        // b2: 黒色で塗る
        // w2: 白色で塗る

        // 通らない場合
        // 通らないパターン
        // ll black = N / 2;
        // if (N % 2 == 1) {
        //     black++;
        // }
        // ll white = N / 2;

        // b2 = N / 2;
        // w2 = N - b2;

        // 通るパターン (1個ずつカウントアップ)
        ll b2 = 0, w2 = 0;
        rep(i, N) {
            if (color[i] == 1) {
                b2++;
            } else {
                w2++;
            }
        }
        // w2 = N - b2; (置き換えても通る)

        ll ans = b2 * w2 - M;
        cout << ans << endl;
    } else {
        // 全部の辺 - M
        ll ans = N * (N - 1) / 2;
        ans -= M;

        cout << ans << endl;
    }
}

Measured memory_bytes: 9896
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		boolean valid = false;
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				if (i*j==N) valid = true;
			}
		}
		System.out.println(valid?"Yes":"No");
	}
}

Measured memory_bytes: 23764
using System;
using System.Linq;

namespace ABC064
{
    class B
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            Console.WriteLine(a.Max() - a.Min());
        }
    }
}

Measured memory_bytes: 11348
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 4000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

std::vector<bool> IsPrime;

void sieve(size_t max){
    if(max+1 > IsPrime.size()){ 
        IsPrime.resize(max+1,true); 
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i)
        if(IsPrime[i])
            for(size_t j=2; i*j<=max; ++j) 
                IsPrime[i*j] = false;     
}

int main(){
	init();
	ll max=pow(10,5)+10;
	sieve(max);
	vector<ll>sum(max+10,0);
	for(int i=0;i<max;i++){
		if(IsPrime[i]&&IsPrime[(i+1)/2])sum[i+1]=sum[i]+1;
		else sum[i+1]=sum[i];
	}
	ll Q;cin>>Q;
	while(Q--){
		ll l,r;cin>>l>>r;
		r++;
		cout<<sum[r]-sum[l]<<endl;
	}
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int64_t f(int64_t b,int64_t n){
if(n<b)return n;
  else
    return f(b,n/b)+(n%b);
}
int main(){
int64_t N,S;
  cin>>N>>S;
  if(N<S)
    cout<<-1<<endl;
  else if(N==S)
    cout<<1+N<<endl;
  else{
  int64_t K=N-S;
    vector<int64_t>A={};
    for(int64_t i=1;i*i<=K;i++){
    if(K%i==0){
    if(K==i*i)
      A.push_back(i+1);
      else{
      A.push_back(i+1);
        A.push_back((K/i)+1);
      }
      
    }
    
    }sort(A.begin(),A.end());
    int64_t ans=-1;
    int64_t M=A.size();
    for(int i=0;i<M;i++){
     int64_t B=A.at(i);
      if(f(B,N)==S){ans=B; break;}
    }cout<<ans<<endl;
  
  }
          return 0;
}

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

using namespace std;

int main()
{
	int n;
	vector<double> a;

	cin >> n;
	
	a.resize(n);

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

	printf("%lf\n", 1.0 / sum);

	return 0;
}

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

#define ll long long
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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 N;
    cin >> N;
    vector<int> h(N);
    rep(i,N) cin >> h[i];

    vector<ll> dp(N,INF);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    REP(i,2,N)
    {
        dp[i] = min( dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i]-h[i-2]));
    }

    cout << dp[dp.size()-1] << endl;
}


Measured memory_bytes: 1408
fun main(args : Array<String>) {
    val antenas = mutableListOf<Int>()
    (0..4).forEach {
        antenas.add(readLine()!!.toInt())
    }
    val k = readLine()!!.toInt()

    (0..4).forEach { i ->
        ((i + 1)..4).forEach { j ->
            if (Math.abs(antenas[i] - antenas[j]) > k) {
                println(":(")
                return
            }
        }
    }
    println("Yay!")
}

Measured memory_bytes: 31776
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

int main(){
  int N, ds = 1;
  while(scanf("%d", &N) && N){
    int c = 2, board[10][10] = {};
    board[0][0] = 1; board[0][1] = 2;
    int x = 1, y = 0;
    while(c <= N*N){
      c++;
      if(y == N-1){
	if(!board[y-1][x+1]) y--;
	  x++;
	  board[y][x] = c;
	  //	  printf("%d %d\n", y, x);
      }else if(x == N-1){
	if(!board[y+1][x-1]) x--;
	y++;
	board[y][x] = c;
	//	printf("%d %d\n", y, x);
      }else if(y == 0){
	if(!board[y+1][x-1]){
	  y++; x--;
	}else{
	  x++;
	}
	board[y][x] = c;
	//	printf("%d %d\n", y, x);
      }else if(x == 0){
	if(!board[y-1][x+1]){
	  y--; x++;
	}else{
	  y++;
	}
	board[y][x] = c;
	//	printf("%d %d\n", y, x);
      }else{
	if(!board[y-1][x+1]){
	  y--;
	  x++;
	  board[y][x] = c;
	  //	  printf("%d %d\n", y, x);
	}else if(!board[y+1][x-1]){
	  y++;
	  x--;
	  board[y][x] = c;
	  //	  printf("%d %d\n", y, x);
	}
      }
    }

    printf("Case %d:\n", ds);
    rep(i, N){
      rep(j, N) printf("%3d", board[i][j]);
      puts("");
    }
    ds++;
  }
  return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<ll>> P(N, vector<ll>(11));
    rep(i, N) {
        rep(j, 10) { cin >> F[i][j]; }
    }

    rep(i, N) {
        rep(j, 11) { cin >> P[i][j]; }
    }

    ll ans = -1e10;
    for (int bit = 1; bit < (1 << 10); bit++) {
        vector<int> open(10, 0);
        rep(i, 10) {
            if (bit & (1 << i)) {
                open[i] = 1;
            }
        }

        ll temp = 0;
        rep(i, N) {
            int cnt = 0;
            rep(j, 11) {
                if (F[i][j] == 1 && F[i][j] == open[j])
                    cnt++;
            }

            temp += P[i][cnt];
        }

        ans = max(ans, temp);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int h = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();
		if(y + r <= h && y - r >= 0 && x + r <= w && x - r >= 0){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 26364
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
int main(){
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0;i < n;i++)cin >> a[i];

	ll ans = 0;
	sort(a.begin(),a.end(),greater<ll>());

	ans += a[0];
	int cnt = 1;
	
	for(int i = 1;i < n;i++){
		if(cnt == n-1)break;
		else if(cnt == n-2){
			ans += a[i];
			break;
		}
		else{
			ans += 2 * a[i];
			cnt += 2;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 4840
# AGC018A - Getting Difference
from fractions import gcd


def main():
    n, k = tuple(map(int, input().rstrip().split()))
    A = tuple(map(int, input().rstrip().split()))
    M = max(A)
    G = A[0]
    for i in A[1:]:
        G = gcd(G, i)
    flg = k <= max(A) and k % G == 0
    print("POSSIBLE" if flg else "IMPOSSIBLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 16280
#include<stdio.h>
int main(){
  int a[3],i,j,k;
  for(i=0;i<3;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<3;i++){
    for(j=i+1;j<3;j++){
      if(a[i]>a[j]){
        k=a[i];
        a[i]=a[j];
        a[j]=k;
      }
    }
  }
  for(i=0;i<3;i++){
    printf("%d",a[i]);
    if(i<2){
      printf(" ");
    }
 }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2728
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
const vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
ll GCD(ll a,ll b) {return b ? GCD(b,a%b):a;}
ll LCM(ll c,ll d){return c/GCD(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
template<class T>void debag(const vector<T> &a){cerr<<"debag :";for(auto v:a)cerr<<v<<" ";cerr<<"\n";}
template<class T>void print(const vector<T> &a){for(auto v:a)cout<<v<<" ";cout<<"\n";}
template<class T> struct RollingHash{
    using ull=unsigned long long int;
    const ull M=(1ull<<61)-1;
    const ull mask30 = (1ull << 30) - 1;
    const ull mask31 = (1ull << 31) - 1;
    const ull mask61 =M;
    vector<ull> hash,pows;
    ull base;

        // mod 2^61-1
    ull cal_mod(ull x){
        ull xu=(x>>61);
        ull xd=(x&mask61);
        ull res=xu+xd;
        if(res>=M)res-=M;
        return res;
    }

    //a*b mod 2^61-1
    ull mul(ull a,ull b){
        ull au=(a>>31),bu=(b>>31);
        ull ad=(a&mask31),bd=(b&mask31);
        ull mid=ad*bu+au*bd;
        ull midu=(mid>>30);
        ull midd=(mid&mask30);
        return cal_mod(au*bu*2+midu+(midd<<31)+ad*bd);
    }


    RollingHash(const T &a,ull base):hash(a.size()+1,0),pows(a.size()+1,1){
		for(int i = 0; i <int (a.size()); i++) {
            pows[i + 1] =mul(pows[i], base);
            hash[i + 1] =cal_mod(mul(hash[i], base) + ull(a[i]));
            if(hash[i+1]>=M)hash[i+1]-=M;
		}
    }
    //[b1,b1+len]と[b2,b2+len]が一致するかどうか
    bool match(int b1, int b2,int len){
        ull h1 = cal_mod(hash[b1+len]+M-mul(hash[b1], pows[len]));
        ull h2 = cal_mod(hash[b2 + len]+M-mul(hash[b2],pows[len]));
        return (h1 == h2);
    }
    //[l,l+len]のハッシュ値
    ull get(int l, int len){
        return cal_mod(hash[l+len] + M - mul(hash[l], pows[len]));
    }
};
constexpr int Hash_Num=2;
struct base_t{
    int use[Hash_Num];
    int &operator[](int i){return use[i];}
    base_t(){
        mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
        for(int i=0;i<Hash_Num;i++)use[i]=rnd()%10000+2;
    }
}bases;
int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    RollingHash<string> rh(s,bases[0]);
    int l=0,r=n/2+1,mid;
    while(r-l>1){
        int mid=(l+r)/2;
        map<unsigned long long,int> mp;
        bool ok=false;
        for(int i=0;i<n-mid+1;i++){
            unsigned long long val=rh.get(i,mid);
            if(mp.count(val)){
                if(i-mp[val]>=mid)ok=true;
            }else{
              mp[rh.get(i,mid)]=i;
            }
        }
        if(ok)l=mid;
        else r=mid;
    }
    cout<<l<<"\n";
}

Measured memory_bytes: 4016
#include<bits/stdc++.h>
using namespace std;
const int N=310;
char s[N][N];
int n,ans;
int main(){
	scanf("%d",&n);
	for(int i=0; i<n; ++i)
		scanf("%s",s[i]);
	for(int i=0; i<n; ++i){
		int flag=1;
		for(int j=0; j<n; ++j)
			for(int k=0; k<n; ++k)
				if(s[j][(i+k)%n]!=s[k][(i+j)%n])
					flag=0;
		ans+=flag*n;
	}
	printf("%d",ans);
	return 0;
}

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

int main(){
    int n; cin >> n;
    map<string, int> m;
    for(int i = 0; i < n; i++){
        string s; cin >> s;
        m[s]++;
    }
    int ans = 0;
    for(auto &x: m){
        ans = max(ans, x.second);
    }
    vector<string> lis;
    for(auto &x: m){
        if(x.second == ans){
            lis.push_back(x.first);
        }
    }
    sort(lis.begin(), lis.end());
    for(int i = 0; i < lis.size(); i++){
        cout << lis[i] << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef map<int,int> M;
typedef vector<int> V;
typedef queue<int> Q;
typedef pair<long,long> PLL;
typedef map<long,long> MLL;
typedef vector<long long> VLL;
typedef vector<pair<int,int>> VP;
typedef vector<vector<int>> VV;
#define INF (int)(1e9)
#define MAXX 1.1529215e+18
#define inf 999999
#define EPS (1e-7)
#define MOD (1e9+7)
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define ALL(a)  a.begin(),a.end()
#define RALL(a) a.begin(),a.end(),greater<int>()
#define PRALL(a) a.begin(),a.end(),greater<pair<int,int>>()
#define ROT(a) a.begin(),a.begin()+1,a.end()
#define RROT(a) a.begin(),a.end()-1,a.end()
#define PB push_back
#define MP make_pair
#define PI acos(-1.0)
/*--------------------------------------------*/

int main(){
    int n,m;cin>>n>>m;
    V k(m),p(m);
    vector<vector<int>> s(m,vector<int>(n));
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>s[i][j];
        }
    }    
    rep(i,m){
        cin>>p[i];   
    }    
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){        
        V h;
        for(int i=0;i<n;i++){
            if(bit&(1<<i)){
                h.PB(i+1);
            }
        }
        //switch h[g]がon;
        bool flag=true;
        rep(j,m){
            int cnt=0;
            int pos_K=k[j];
            int pos_P=p[j];
            rep(l,pos_K){
                rep(g,(int)h.size())
                if(h[g]==s[j][l])cnt++;
            }
            if(cnt%2!=pos_P){
                flag=false;
                break;
            } 
        }if(flag)ans++;
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int a[100500], b[100500];
int mid[100500], mid2[100500];
map<int, int> fa, ok;
int findfa(int x)
{
	if(fa[x] == x) return x;
	return fa[x] = findfa(fa[x]);
}
int main()
{
	fa[-1] = -1;
	int n = 0;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", a + i), a[0] ^= a[i];
	for(int i = 1; i <= n; i++) scanf("%d", b + i), b[0] ^= b[i];
	for(int i = 0; i <= n; i++) mid[i] = a[i], mid2[i] = b[i];
	sort(mid, mid + n + 1), sort(mid2, mid2 + n + 1);
	for(int i = 0; i <= n; i++)
	{
		fa[a[i]] = a[i], fa[b[i]] = b[i];
		if(mid[i] != mid2[i])
		{
			puts("-1");
			return 0;
		}
	}
	int tot = 0;
	for(int i = 0; i <= n; i++)
	{
		if(a[i] != b[i])
		{
			if(i) tot++;
			fa[findfa(a[i])] = findfa(b[i]);
			ok[a[i]] = ok[b[i]] = 1;
		}
	}
	if(tot == 0) cout << 0 << endl;
	if(tot > 0)
	{
		ok[a[0]] = ok[b[0]] = 1;
		for(int i = 0; i <= n; i++)
			if(ok[a[i]] && a[i] == findfa(a[i]))
			{
				tot++;
				fa[a[i]] = -1;
			}
		cout << tot - 1 << endl;
	}
	return 0;
}
//ans=不同位置数+数字的轮换数（包括0）-1

Measured memory_bytes: 20608
import bisect
N, K = map(int, input().split())
a=list(map(int, input().split()))
nlis=[0]*200001
s=0
for i in range(N):
    if nlis[a[i]]==0:
        s+=1
    nlis[a[i]]+=1
nlis.sort(reverse=True)

print(sum(nlis[K:]))

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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, x, t;
    cin >> n >> x >> t;

    cout << (n + x - 1) / x * t << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N, K;
    cin >> N >> K;
    vector<long long> P(N), C(N);
    for(int i = 0; i < N; i++) {
        cin >> P[i];
        P[i]--;
    }
    for(int i = 0; i < N; i++) cin >> C[i];
    long long ans = -1e18;
    vector<int> used(N, 0);
    vector<vector<long long>> vec(N);
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(used[i] == 1) continue;
        int flag = 0;
        int ind = i, ind2 = i;
        while(flag == 0 || ind != ind2){
            flag = 1;
            vec[cnt].push_back(C[ind]);
            used[ind] = 1;
            ind = P[ind];
        }
        cnt++;
    }
    vector<vector<long long>> memo(cnt, vector<long long>(N, -1e18));
    for(int i = 0; i < cnt; i++){
        long long siz = vec[i].size();
        long long temp = 0;
        long long res = 0;
        for(int j = 0; j < siz; j++){
            long long t = 0;
            for(int k = 0; k < siz; k++){
                t += vec[i][(j + k) % siz];
                memo[i][k] = max(memo[i][k], t);
            }
            temp += vec[i][j];
        }
        if(temp > 0) {
            res += K / siz * temp;
            long long temp2 = 0;
            if(K / siz > 0){
                temp2 = (K / siz - 1) * temp;
                long long m = *max_element(memo[i].begin(), memo[i].begin() + siz);
                temp2 += m;
            }
            long long t = -1e18;
            int flag = 0;
            for(int j = 0; j < K % siz; j++){
                t = max(t, memo[i][j]);
                flag = 1;
            }
            if(flag == 1) res += t;
            ans = max(res, ans);
            ans = max(temp2, ans);
        }
        else{
            long long r = -1e18;
            int flag = 0;
            for(int j = 0; j < min(K, siz); j++){
                r = max(r, memo[i][j]);
                flag = 1;
            }
            if(flag == 1) res += r;
            ans = max(res, ans);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 36684
#!/usr/bin/env python3
import sys
from collections import deque

input = sys.stdin.readline


def S():
    return input().rstrip()


def I():
    return int(input())


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


n = I()
al = list(MI())

al.sort()
al.reverse()

ans = 0
q = deque()
for a in al:
    if q:
        ans += q.popleft()
        q.append(a)
        q.append(a)
    else:
        q.append(a)

print(ans)


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

using namespace std;

int a[100100];


int main()
{
//    freopen("int.txt","r",stdin);

    int a,c;
    while(cin>>a>>c&&a&&c)
    {
        for(int i=0; i<a; i++)
        {
            for(int j=0; j<c; j++)
            {
                if(i==0||j==0||i==a-1||j==c-1)
                    cout<<"#";
                else
                    cout<<".";
            }
            cout<<endl;

        }
        cout<<endl;

    }
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
#define popcnt(a) __builtin_popcount(a)

#define error(args...)                       \
{                                            \
    cerr<<"LINE "<<__LINE__;                 \
    string _s = #args;                       \
    replace(_s.begin(), _s.end(), ',', ' '); \
    stringstream _ss(_s);                    \
    istream_iterator<string> _it(_ss);       \
    err(_it, args);                          \
    cerr<<endl;                              \
}
void err(istream_iterator<string> it)
{
} 
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
  cerr<<' '<< *it << " = " << a ;
  err(++it, args...);
} 
typedef long long ll;
const int N = 1e5+1 , M = 5e5+1, OO = 0x3f3f3f3f,MOD = 1e9+7;
vector<int>adj[N];
int par[N],sz[N];
int n,m,k;
void init()
{
  fill(sz,sz+n,1);
  iota(par,par+n,0);
}
int find(int p)
{
  return p==par[p]?p:par[p]=find(par[p]);
}
bool sameset(int a,int b)
{
  return find(a)==find(b);
}
void join(int a,int b)
{
  a = find(a),b = find(b);
  
  if(a==b) return;
  if(sz[a] < sz[b]) swap(a,b);

  par[b]=a;
  sz[a]+=sz[b];
}

int main()
{
  scanf("%d%d%d",&n,&m,&k);
  init();
  for(int i=0;i<m;++i)
  {
    int u,v;
    scanf("%d%d",&u,&v);
    u--,v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
    join(u,v);
  }
  for(int i=0;i<k;++i)
  {
    int u,v;
    scanf("%d%d",&u,&v);
    u--,v--;
    if(sameset(u,v))
    {
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    
  }
  for(int i=0;i<n;++i)
  {
    error(i+1,sz[find(i)],adj[i].size());
    printf("%ld ",sz[find(i)]-adj[i].size()-1);
  }
  
    
  
  #ifdef _LOCAL_DEFINE  
  cerr << (double)clock() * 1.0 / CLOCKS_PER_SEC << endl;
  #endif
  return 0; 
}

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

int main()
{
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  else if(s == "Cloudy") cout << "Rainy" << endl;
  else cout << "Sunny" << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define rgt register
#define rint rgt int
#define N 2003
using namespace std;
template<class K>inline bool cmax(K&a,const K&b){return(a<b)?a=b,1:0;}
template<class K>inline bool cmin(K&a,const K&b){return(a>b)?a=b,1:0;}
int n,m,T,lx,ly,rx,ry,ans;
int s[N][N],x[N][N],y[N][N];
char c[N];bool b[N][N];
inline int read() {
	rgt int s=0;
	rgt char c=getchar();
	while(!isdigit(c)) c=getchar();
	while(isdigit(c)) s=(s<<1)+(s<<3)+c-'0',c=getchar();
	return s;
}
inline int getsum(rgt int lx,rgt int ly,rgt int rx,rgt int ry) {
	return s[rx][ry]-s[lx][ry]-s[rx][ly]+s[lx][ly];
}
inline int getx(rgt int lx,rgt int ly,rgt int rx,rgt int ry) {
	return x[rx][ry]-x[lx][ry]-x[rx][ly]+x[lx][ly];
}
inline int gety(rgt int lx,rgt int ly,rgt int rx,rgt int ry) {
	return y[rx][ry]-y[lx][ry]-y[rx][ly]+y[lx][ly];
}
int main()
{
	int i,j;
	n=read(),m=read(),T=read();
	for(i=1;i<=n;i++) {
		scanf("%s",c+1);
		for(j=1;j<=m;++j)
			b[i][j]=c[j]-'0',
			s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+b[i][j];
	}
	for(i=1;i<=n;i++)
		for(j=2;j<=m;j++)
			x[i][j]=x[i-1][j]+x[i][j-1]-x[i-1][j-1]+(b[i][j]&&b[i][j-1]);
	for(i=2;i<=n;i++)
		for(j=1;j<=m;j++)
			y[i][j]=y[i-1][j]+y[i][j-1]-y[i-1][j-1]+(b[i][j]&&b[i-1][j]);
	while(T--) {
		lx=read(),ly=read(),rx=read(),ry=read();
		ans=getsum(lx-1,ly-1,rx,ry);
		ans-=getx(lx-1,ly,rx,ry);
		ans-=gety(lx,ly-1,rx,ry);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 52736
#include<bits/stdc++.h>
#define LL long long
#define fr(i,x,y) for(int i=(x);i<=(y);i++)
#define rf(i,x,y) for(int i=(x);i>=(y);i--)
#define frl(i,x,y) for(int i=(x),z=y;i<z;i++)
using namespace std;
const int N=200002;
const int p=1e9+7;
int n;
vector<int> a[N];

void read(int &x){
	char ch=getchar();x=0;
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}

void read(LL &x){
	char ch=getchar();x=0;
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';ch=getchar()) x=(x<<3)+(x<<1)+ch-'0';
}

LL inv[N];
void init(){
	inv[1]=inv[0]=1; //??????
	frl(i,2,N) inv[i]=-p/i*inv[p%i]%p;
}

int s[N<<1],L;
int b[N],sz[N];
vector<int> v;
int d[N];
LL sum;
int predfs(int x,int fa){ //guaguade
	b[x]=1;int xx=0;
	frl(i,0,a[x].size())
	 if (a[x][i]!=fa){
	 	int tmp=a[x][i];
	 	if (b[tmp]||(xx=predfs(tmp,x))){
	 		s[++L]=x;
	 		if (xx==0) return tmp;
	 		return x==xx?0:xx;
		}
	 }
	return 0;
}

void dfs(int x,int fa){
	sz[x]=1;b[x]=1;
	frl(i,0,a[x].size()){
		int tmp=a[x][i];
		if (tmp==fa||d[tmp]==-1) continue;
		dfs(tmp,x);
		if (tmp<fa) sz[x]+=sz[tmp];
	}
	if (d[x]!=-1) sum=sum*inv[sz[x]]%p;
}

LL solve(int u){
	L=0;
	predfs(u,0);
	/*if (L==0){
		puts("0");
		exit(0);
	}*/
	fr(i,1,L) d[s[i]]=-1;
	sum=1;fr(i,1,L) dfs(s[i],0);
	LL s1=1,s2=1;
	fr(i,1,L) s[i+L]=s[i];s[0]=s[L];s[2*L+1]=s[1];
	fr(o,1,L)
	 if (s[o-1]>=s[o+1]){
	 	frl(i,o,o+L)
	 	 frl(j,0,a[s[i]].size())
	 	  if (a[s[i]][j]<s[i+1]) sz[s[i]]+=sz[a[s[i]][j]];
	 	fr(i,1,L) s1=s1*inv[sz[s[i]]]%p;
	 	break;
	 }
	fr(i,1,L) sz[s[i]]=1;
	rf(o,L<<1,L)
	 if (s[o+1]>=s[o-1]){
	 	rf(i,o,o-L+1)
	 	 frl(j,0,a[s[i]].size())
	 	  if (a[s[i]][j]<s[i-1]) sz[s[i]]+=sz[a[s[i]][j]];
	 	fr(i,1,L) s2=s2*inv[sz[s[i]]]%p;
	 	break;
	 }
	return (s1+s2)*sum%p;
}

int main(){
	//freopen("1.in","r",stdin);
	//freopen("1.out","w",stdout);
	//int n=20;
	read(n);
	init();
	int x,y;
	fr(i,1,n<<1){
		read(x);read(y);
		a[x].push_back(y+n);
		a[y+n].push_back(x);
	}
	//fr(i,1,n<<1) sort(a[i].begin(),a[i].end());
	fr(i,1,n<<1) if (a[i].size()==0) return puts("0"),0;
	LL ans=1;
	fr(i,1,n<<1)
	 if (!b[i]) ans=ans*solve(i)%p;
	ans+=p;ans%=p;
	fr(i,1,2*n) ans=ans*i%p;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 20096
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <bitset>
using namespace std;

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

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

    vector<int64_t> sums;
    for (int i = 0; i < n; i++) {
        int64_t sum = 0;
        for (int j = i; j < n; j++) {
            sum += a[j];
            sums.push_back(sum);
        }
    }

    int64_t ans = 0;
    for (int64_t i = 50; i >= 0; i--) {
        int64_t mask = (ans | (1LL << i));
        int cnt = 0;

        for (int64_t sum : sums) {
            if ((sum & mask) == mask) cnt++;
        }
        if (cnt >= k) ans = mask;
    }
    cout << ans << endl;

    return 0;
}

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

typedef struct kouzou{
  char name[100];

  int a;
} kouzou2;


kouzou2 Q[100005];
int head, tail,num;



void enqueue(kouzou2 t){

  Q[tail]=t;
  tail=(tail+1)%100005;

}




kouzou2 dequeue(){
  kouzou2 t = Q[head];
  head = (head+1)%100005;
  return t;
}


int min(int i,int j){return i<j?i:j;}


int main (){
  int elaps=0,c;
  int i,q;
  kouzou2 d;
  scanf("%d %d",&num,&q);
  for(i=1;i<=num;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].a);
  }
  head=1;
  tail=num+1;


  while(head!=tail){
    
    d=dequeue();
    c=min(q,d.a);
    d.a-=c;
    elaps+=c;
    
    if(d.a>0)enqueue(d);
    else{
      printf("%s %d\n",d.name,elaps);
    }
  }
  return 0;
}



Measured memory_bytes: 11952
S = list(input())
lenS = len(S)
T = list(input())
lenT = len(T)
Flag = False
for i in range(lenS - lenT, -1 , -1):
    for j in range(lenT - 1, -1 , -1):
        if S[i + j] != "?" and T[j] != S[i + j]:
            break
    else:
        Flag = True
        for j in range(lenT - 1 , -1 , -1):
            S[i + j] = T[j]
        break
if Flag:
    for i in range(lenS):
        if S[i] == "?":
            S[i] = "a"
    print("".join(S))
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)

int main(void){
  int n,m;
  while(cin>>n>>m,n+m){
    int sun = 0, sum = 0;
    vector<int> in(n);
    vector<int> im(m);
    rep(i,n)cin>>in[i],sun+=in[i];
    rep(i,m)cin>>im[i],sum+=im[i];
    
    bool find = false;
    rep(i,n){
      if(find)break;
      rep(j,m){
	//cout<<in[i]<<" "<<im[j]<<endl;
	//cout<<sun+im[j]-in[i] <<" "<<sum+in[i]-im[j]<<endl;
	if(sun + im[j] - in[i] == sum + in[i] - im[j]){
	  cout<<in[i]<<" "<<im[j]<<endl;
	  find = true;
	  break;
	} 
      }
    }
    if(!find)cout<<-1<<endl;

  }
}

Measured memory_bytes: 1196
#include <cstdio>

int N;
char S[300010];
int num[300010], num2[300010];
int res;

void solve()
{
	int i;
	for(i=0; i<N; i++){
		if(S[i] == 'W')
			num[i+1] = num[i] + 1;
		else
			num[i+1] = num[i];
	}
	for(i=N-1; i>=0; i--){
		if(S[i] == 'E')
			num2[i] = num2[i+1] + 1;
		else
			num2[i] = num2[i+1];
	}
	res = 1000000000;
	for(i=0; i<N; i++){
		int tmp = num[i] + num2[i+1];
		if(tmp < res)
			res = tmp;
	}
	printf("%d\n", res);
}

int main()
{
	scanf("%d", &N);
	scanf("%s", S);
	solve();
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;

int main() {
    int a,b,k; cin >> a >> b >> k;

    set<int> ans;

    for (int i = 0; i < k; ++i) {
        if(a + i <= b) {
            ans.insert(a + i);
        }
        if(b - i >= a){
            ans.insert(b - i);
        }
    }

    for(auto itr : ans){
        print(itr);
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; scanf("%d",&N);
	vector<int> X(N);
	indexed_set st;
	for (int i=0; i<N; i++)
		scanf("%d",&X[i]), st.insert({X[i],i});
	for (int i=0; i<N; i++) {
		ii cur={X[i],i};
		st.erase(cur);
		printf("%d\n",st.find_by_order((N-1)/2)->first);
		st.insert(cur);
	}
	return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
using namespace std;

ll n, k;
vector<pair<int, int>> arr;

int main(void) {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        int a, b;
        cin >> a >> b;
        arr.push_back(make_pair(a, b));
    }
    sort(arr.begin(), arr.end());
    ll count = k;
    int i = -1;
    while (count > 0) {
        i++;
        count -= arr[i].second;
    }
    cout << arr[i].first << endl;
    return 0;
}

Measured memory_bytes: 1400
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll int MOD=1e9+7;
#define INF 2*1e9
#define N 310000 
using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    cin>>n;
    int a[200];
    rep(i,n){
        cin>>a[i];
    }
    sort(a,a+n);
    int m,M;
    m=a[0];M=a[n-1];
    int num=upper_bound(a,a+n,m)-lower_bound(a,a+n,m);
    if(num==1){
        if(M!=2*m){
            cout<<"Impossible";return 0;
        }
        rep2(i,m+1,M){
            int s=upper_bound(a,a+n,i)-lower_bound(a,a+n,i);
            if(s<2){
                cout<<"Impossible";return 0;
            }
        }
        cout<<"Possible";
    }
    else if(num==2){
        if(m*2-1!=M){
            cout<<"Impossible";return 0;
        }
        rep2(i,m+1,M){
            int s=upper_bound(a,a+n,i)-lower_bound(a,a+n,i);
            if(s<2){
                cout<<"Impossible";return 0;
            }
        }
        cout<<"Possible";
    }
    else{
        cout<<"Impossible";return 0;
    }
}



Measured memory_bytes: 256
<?php
  fscanf(STDIN, "%d%d", $l, $r);
  if($r-$l >= 2018){
      echo 0;
      exit;
  }
  $min = PHP_INT_MAX;
  for($i=$l; $i<$r; $i++){
     for($j=$i+1; $j<=$r; $j++){
         $min = min($min, ($i*$j)%2019);
     }
  }
  echo $min;
  

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  long long int pa, pb;
  cin >> pa >> pb;
  for(int i=1; i<n; i++){
    long long int a, b;
    cin >> a >> b;
    long long int j = max((pa+a-1)/a,(pb+b-1)/b);
    pa=a*j;
    pb=b*j;
  }
  long long int ans = pa+pb;
  cout << ans << endl;
  return 0;
}

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

#define M_PI       3.14159265358979323846   // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a,n) for(ll a = 0;a < n;a++)
#define repi(a,b,n) for(ll a = b;a < n;a++)

using namespace std;

static const ll INF = 1e15;

int main() {
	ll n, m;
	cin >> n >> m;
	vector<ll> vs(m);
	for (int i = 0; i < m; i++) {
		int k;
		cin >> k;
		ll bits = 0;
		rep(j, k) {
			ll a;
			cin >> a;
			a--;
			bits |= (1LL << a);
		}
		vs[i] = bits;
	}
	vector<ll> ps(m);
	rep(i, m) {
		cin >> ps[i];
	}
	ll sum = 0;
	rep(i, 1LL << n) {
		bool ok = true;
		rep(j, m) {
			ll s = i & vs[j];
			if (__builtin_popcountll(s) % 2 != ps[j]) {
				ok = false;
				break;
			}
		}
		if (ok) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


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

int main(){
    ll a, b, k;
    cin>>a>>b>>k;
    ll flag=0;
    ll ans;
    for(ll i=a;i>=1;--i){
        if(a%i==0){
            if(b%i==0){
                ans=i;
                flag++;
            }
            if(flag==k){
                break;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fod(i,a,b) for(int i=a;i>=b;i--)
#define me0(a) memset(a,0,sizeof(a))
#define me1(a) memset(a,-1,sizeof(a))
#define op freopen("in.txt", "r", stdin)
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
void read(int& val) { int x = 0; int bz = 1; char c; for (c = getchar(); (c<'0' || c>'9') && c != '-'; c = getchar()); if (c == '-') { bz = -1; c = getchar(); }for (; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - 48; val = x * bz; }
const int maxn = 1e6+10;


int main(){
    int x,y;
    cin>>x>>y;
    if(y&1){
        cout<<"No"<<endl;return 0;
    }
    int mi = x*2,mx = x*4;
    if(mi<=y&&y<=mx){
        cout<<"Yes"<<endl;
    }
    else {
        cout<<"No"<<endl;
    }
    return 0;
}

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

void dfs(vector<vector<int>> &tree, int now, ll count, int bf, vector<ll> &ans, vector<ll> &hv){
	count += hv.at(now);
	ans.at(now) = count;
	// cerr << now << endl;
	for(auto i : tree.at(now)){
		if(i == bf) continue;
		dfs(tree, i, count, now, ans, hv);
	}
}

int main(){
	int n, q;
	cin >> n >> q;
	vector<vector<int>> tree(n, vector<int>());
	rep(i, n-1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		tree.at(a).push_back(b);
		tree.at(b).push_back(a);
	}
	vector<ll> hv(n, 0);
	rep(i, q){
		int p, x;
		cin >> p >> x;
		p--;
		hv.at(p) += x;
	}
	vector<ll> ans(n, 0);
	dfs(tree, 0, 0, -1, ans, hv);
	rep(i, n){
		if(i != 0) cout << " ";
		cout << ans.at(i);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 32128
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <queue>
#include <vector>
#include <cmath>
#include <map>
#include <stack>
#include <algorithm>
typedef long long int ll;
using namespace std;
const int INF = 5*1e9;
const int MAX = 1e2+10;
int a[MAX];

int main(){
    //freopen("/Users/mac/Desktop/C++?¨????/test/test.txt", "r", stdin);
    int n;
    int sum=0;
    scanf("%d",&n);
    for (int i=0; i<n; i++) {
        scanf("%d",&a[i]);
    }
    for (int i=0; i<n; i++) {
        int mini=i;
        for (int j=i; j<n; j++) {
            if (a[j]<a[mini]) {
                mini=j;
            }
        }
        int t;
        t=a[i];
        a[i]=a[mini];
        a[mini]=t;
        if (i!=mini) {
            sum++;
        }
    }
    for (int i=0; i<n; i++) {
        if (i) {
            printf(" ");
        }
        printf("%d",a[i]);
    }
    printf("\n%d\n",sum);
    return 0;
}

Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int sum=0;
    if(k>=a)
    {
        sum=a*1;
        k=k-a;
        if(k>=b)
        {
            k=k-b;
            if(k>=c)
            {
                sum+=c*-1;
            }
            else
            {
                sum+=k*-1;
            }
        }
    }
    else
    {
        sum=k;
    }
    cout<<sum<<endl;
    return 0; 
}

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

#define ll long long
#define endl '\n'
#define REP(i, a, n) for(int i=a; i<n; ++i)
#define pb push_back
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const double PI = 3.141592653589793238460;
const ll mod = 1e9 + 7;

void FAST(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

int main(){
  FAST();

  int n;
  cin >> n;
  map<string, int> abc;
  map<string,int>::iterator it;

  REP(i, 0, n){
      string str;
      cin >> str;
      abc[str]++;
  }
  int largest = 0;
  for (it = abc.begin(); it != abc.end(); it++)
      largest = max(largest, it->second);

  for (it = abc.begin(); it != abc.end(); it++)
    if(it->second == largest)
        cout << it->first << endl;

  return 0;
}


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

using namespace std;

const int N = 5005;
long long n, a, b, x[N];
long long f[N][N], pos[N], p[N][N];

main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> a >> b;
	for(int i = 1; i <= n; ++i) cin >> x[i];
	memset(f, 127, sizeof(f));
	long long oo = f[0][0];
	f[0][0] = 0;
	for(int i = 1; i <= n; ++i) {
		pos[x[i]] = i;
	}
	for(int i = 0; i < n; ++i) {
		for(int j = 0; j <= n; ++j) {
			if(j < x[i + 1]) {
				f[i+1][j] = min(f[i+1][j], f[i][j] + a);
				f[i+1][x[i+1]] = min(f[i+1][x[i+1]], f[i][j]);
			}
			else{
				f[i+1][j] = min(f[i+1][j], f[i][j] + b);
			}
		}
	}
	for(int i = 0; i <= n; ++i) oo = min(oo, f[n][i]);
	cout << oo << '\n'; 
}

Measured memory_bytes: 197248
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=(l);i<(r);i++)
#define LINF (ll)1e18
#define INF (int)1e9
#define range(i) i.begin(),i.end()
#define Yes(i) out(i?"Yes":"No");return 0
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    int a;
    in(a);
    while(a%4&&a>6){
        a-=7;
    }
    out(a%4?"No":"Yes");
}








Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>

using namespace std;
typedef long long ll;

ll N, K;

int main() {
	cin >> N >> K;
	cout << N - K + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

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

    int q;
    cin >> q;

    vector<int> l(q),r(q);

    for(int i = 0; i < q; i++){
        cin >> l[i];
        cin >> r[i];
    }

    vector<bool> era(100002,true);

    era[0] = era[1] = false;

    for(int i = 2; i < 100002; i++){
        if(era[i]){
            for(int j = 2*i; j < 100002; j += i){
                era[j] = false;
            }
        }
    }

    vector<int> total(100001,0);

    for(int i = 1; i < 100001; i++){
        if(era[i] && era[(i+1)/2]){
            total[i] = total[i-1] + 1;
            //cout << total[i] << endl;
        }else{
            total[i] = total[i-1];
        }
    }

    for(int i = 0; i < q; i++){
        cout << total[r[i]]-total[l[i]-1] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1792
/**************************************************
  Solution to: ABC 173 A - Payment
  Writer: InvisibleCyclist
  By/Based on:
**************************************************/
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	cin>>n;
	if(n%1000==0){
		cout<<"0"<<endl;
	}
	else
		cout<<1000-(n%1000)<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int N, M;
	cin >> N >> M;
	vector<int> X(M);
	for (int i = 0; i < M; ++i) cin >> X[i];
	sort(X.begin(), X.end());
	vector<int> L;
	for (int i = 1; i < M; ++i) L.push_back(X[i] - X[i - 1]);
	sort(L.begin(), L.end());
	int ans = 0;
	for (int i = 0; i < M - 1 && i < M - N; ++i) ans += L[i];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1276
use std::io::Read;
use std::cmp::min;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

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

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let a: usize = iterator.next().unwrap().parse().unwrap();
    let b: usize = iterator.next().unwrap().parse().unwrap();

    let ans: usize = min(n * a, b);

    return ans.to_string();
}


Measured memory_bytes: 2160
#include<cstdio>
#include<algorithm>
using namespace std;

#define MAXN 100
int N,M,X,Y,x[MAXN+5],y[MAXN+5];

int main(){
    scanf("%d%d%d%d",&N,&M,&X,&Y);
    for(int i=1;i<=N;i++)
        scanf("%d",&x[i]);
    for(int i=1;i<=M;i++)
        scanf("%d",&y[i]);
    for(int Z=X+1;Z<=Y;Z++){
        bool flag=1;
        for(int i=1;i<=N;i++)
            if(x[i]>=Z){
                flag=0;
                break;
            }
        for(int i=1;i<=M;i++)
            if(y[i]<Z){
                flag=0;
                break;
            }
        if(flag){
            puts("No War");
            return 0;
        }
    }
    puts("War");
}


Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        // 入力値を受け取る
        Scanner sc = new Scanner(System.in);
        // 入力された３つの整数
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        // 条件を満たすか判定する
        int[] arr = new int[]{a,b,c};
        Arrays.sort(arr);

        // 入力された結果を表示する
        System.out.printf("%d %d %d\n",arr[0],arr[1],arr[2]);
        sc.close();
    }
}


Measured memory_bytes: 26372
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#define all(c) c.begin(), c.end()
#define pb push_back
#define ll long long
#define ull unsigned long long
const int MAXN = 1e3 + 5;
const int MOD = 1e9 + 7;
using namespace std;
int pw(int n,int k)
{
int p = 0;
while(n < k)
{
	++p;
	n*=2;
}
return p;
}

int main()
{

long double n,k;
cin >> n >> k;

long double ans = 0.0;

for(int i = 1 ; i <= n ; i++)
	 {
	 	
	 long double x = ((1 / n) * (long double) pow((1/2.0) , (long double)pw(i,k)));
	 ans+=x;

	 }

	 cout << fixed << setprecision(12) << ans ;


} 

Measured memory_bytes: 512
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
//[no]param
//0:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
function myconv(i,no){switch(no){case 0:return i;case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));}}

function Main(input) {
  input = myconv(input,4);
  if(input[0] + input[1] + input[2] <= 21){
     myout("win");
     }else{
     myout("bust");
     }
}

Main(myin());


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

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

#define MOD 1000000007

int main(void) {
    ll K, A, B;
    cin >> K >> A >> B;
    cout << (A <= B / K * K  ? "OK" : "NG") << endl;
    return 0;
}


Measured memory_bytes: 3636