akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,a,b,c;
    cin >> n >> a >> b >> c;
    int l[n];
    for(int i = 0; i < n; i++) {
        cin >> l[i];
    }

    int mincost=INT32_MAX;
    for(int bit = 0; bit < (1<<2*n); bit++) {
        int al=0;
        int bl=0;
        int cl=0;
        int ccost=-3;

        for(int i = 0; i < n; i++) {
            ccost++;
            if((bit&(1<<2*i))&&(bit&(1<<2*i+1))){
                al+=l[i];
            }
            else if((bit&(1<<2*i))&&!(bit&(1<<2*i+1))){
                bl+=l[i];
            }
            else if(!(bit&(1<<2*i))&&(bit&(1<<2*i+1))){
                cl+=l[i];
            }
            else ccost--;
        }
        if(al!=0&&bl!=0&&cl!=0){
            int cost=abs(a-al)+abs(b-bl)+abs(c-cl)+ccost*10;
            mincost=min(mincost,cost);
        }
    }
    cout << mincost << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

string s;

int main() {
    cin >> s;
    int slen = s.length();
    int now = 0;
    int x = 1;
    vector<int> cnt(2019, 0);
    ll sum = 0;
    reverse(s.begin(), s.end());
    for(int i = 0; i < slen; ++i) {
        int ch = s[i] - '0';
        cnt[now]++;
        now += (ch*x);
        now %= 2019;
        sum += cnt[now];
        x = x*10%2019;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3728
#pragma warning(disable: 4996)
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <sstream>
#include <fstream>
#include <math.h>
#include <algorithm>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)

int main() {
    string s,ft,bk;
    int q, t;
    cin >> s >> q;
    int chk = 0;
    rep(i, q) {
        cin >> t;
        if (t == 1)chk++;//chkが偶数の時は入れ替わりなし、奇数では入れ替わっている状態
        if (t == 2) {
            int f;
            string c;
            cin >> f >> c;
            if (f == 1) {
                if (chk % 2 == 0) {//そのまま前
                    ft = c + ft;
                }
                else {//入れ替わり状態なので後ろに
                    bk += c;
                }
            }
            else {
                if (chk % 2 == 0) {
                    bk += c;
                }
                else {
                    ft = c + ft;
                }
            }
        }
    }
    
    if (chk % 2 == 0) cout << ft <<  s << bk <<  endl;
    else {
        s = ft + s + bk;
        int n = s.size();
        rep(i,n) {
            cout << s[n - 1 - i];
        }
    }
    return 0;
}

Measured memory_bytes: 3812
require 'set'
 
Move = [ [2],
         [2, 5], [0, 1, 3, 6], [2, 7],
         [5], [1, 4, 6, 9], [2, 5, 7, 10], [3, 6, 8, 11], [7],
         [5, 10], [6, 9, 11, 12], [7, 10],
         [10] ]
R = [0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4]
C = [2, 1, 2, 3, 0, 1, 2, 3, 4, 1, 2, 3, 2]
 
def judge(brd, depth)
  ret = depth
  13.times do |i|
    if brd[i] > 0
      [R, C].each do |a|
        ret += (a[i] - a[brd[i]]).abs
      end
    end
  end
  ret
end
 
def solve(brd)
  q = [[judge(brd, 0), brd, 0]]
  set = Set.new([])
  set.add(brd)
  until q.empty?
    arr = q.shift
    q.delete(arr)
    x, b, d = arr
    return d if (1..11).all?{ |v| b[v] == v }
    next if x > 20
    13.times do |i|
      if b[i] == 0
        Move[i].each do |m|
          b[i], b[m] = b[m], b[i]
          nb = b.dup
          nx = judge(nb, d + 1)
          unless set.include?(nb)
            set.add(nb)
            q << [nx, nb, d + 1]
          end
          b[i], b[m] = b[m], b[i]
        end
      end
    end
  end
  false
end
 
while n = gets.to_i
  break if n == -1
  ans = solve([n, 4.times.map{ gets.split.map(&:to_i) } ].flatten)
  puts ans && ans <= 20 ? ans : 'NA'
end

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

typedef long long ll;
ll mod = 1000000007;

ll power(ll x, ll y)
{
    ll res = 1;
    x = x%mod;
    while (y)
    {
        if (y&1) res = ((res%mod)*(x%mod))%mod;

        y>>=1;
        x = ((x%mod)*(x%mod))%mod;
    }
    return res;
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    ll n;
    cin >> n;
    
    ll dp[10][10];

    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) dp[i][j]=0;

    }

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

        int l=i%10;
        int digits=log10(i);
        int f = (int)(i/pow(10,digits));

        dp[f][l]+=1;
    }

    ll answer=0;

    for(int i=1; i<=9; i++){

        for(int j=1; j<=9; j++) answer+=dp[i][j]*dp[j][i];
    }

    cout << answer << "\n";

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define f(i,n) for(int i=0;i<(n);i++)
#define P pair<int,int>
#define mod 1000000007
#define S second
#define F first
#define int long long
using namespace std;

signed main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<a+d-b-c<<endl;
	return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define ep emplace_back
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin >> n;
	string s;cin >> s;
	rep(i,s.size()){
		s.at(i) = (s.at(i) - 'A' + n) % 26 + 'A';
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  vector<int> a(4);
  for (int i = 0; i < 4; ++i) {
    scanf("%d", &a[i]);
  }
  sort(a.begin(), a.end());
  int sum = 0;
  for (int i = 0; i < 4; ++i) sum = sum * 10 + a[i];
  if (sum == 1479) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int N,K;
int A[100010]={0},a[100010]={0},num=0;
int main(void)
{
	int min = 999999999;
	cin>>N>>K;
	for (int i = 0; i < N; i++)
	{
		scanf("%d",&A[i]);
		if(A[i]<min)
			min=A[i];
	}
	a[num]=0;
	num++;
	for (int i = 0; i < N; i++)
	{
		if(min==A[i])
		{
			a[num]=i+1;
			num++;
		}
	}
	int l=0,k=a[l],ans=0;
	l++;
	while(k<=N-1)
	{

		k+=K-1;
		ans++;
		if(k>=a[l]&&l<num)
		{
			k++;
			l++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 640
A, B, C, D, E, F = map(int, input().split())

ans = [0, 0]
maxno = 0

a = 0
while True:
    aaa = 100*A*a
    if aaa > F:
        break

    b = 0
    while True:
        bbb = aaa+100*B*b
        if bbb > F:
            break
        
        c = 0
        while True:
            if not bbb:
                break
            ccc = C*c
            if ccc > F:
                break

            d = 0
            while True:
                ddd = ccc+D*d
                if bbb+ddd > F:
                    break

                if ddd/bbb > E/100:
                    break

                no = ddd / (bbb+ddd)

                if no >= maxno:
                    ans = [bbb+ddd, ddd]
                    maxno = no
                
                d += 1
            c += 1
        b += 1
    a += 1

print(*ans)

Measured memory_bytes: 9196
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()
    dp = [[0 for _ in range(n + 1)] for _ in range(3)]

    for index, ti in enumerate(t, 1):
        if index <= k:
            if ti == 'r':
                dp[2][index] = p
            elif ti == 's':
                dp[0][index] = r
            elif ti == 'p':
                dp[1][index] = s
        else:
            if ti == 'r' and dp[2][index - k] == 0:
                dp[2][index] = p
            elif ti == 's' and dp[0][index - k] == 0:
                dp[0][index] = r
            elif ti == 'p' and dp[1][index - k] == 0:
                dp[1][index] = s

    ans = 0

    for d in dp:
        ans += sum(d)

    print(ans)


if __name__ == '__main__':
    main()


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

int main()
{
	int tt=1;
	//cin>>tt;
	while(tt--)
	{
		int n,h;
		cin>>h>>n;

		ll sum=0;
		for (int i = 0; i < n; ++i)
		{
			int x;
			cin>>x;
			sum+=x;
		}

		if(sum<h)
			cout<<"No";
		else
			cout<<"Yes";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
int main(){
  cin >> n;
  vector<double> v(n);
  for(int i=0 ; i<n ; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  double ans = v[0];
  for(int i=1 ; i<n ; i++){
    ans = (v[i] + ans)/2;
  }
  cout << ans << endl;
  return 0;
}


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

int a, b, c, fa, fb, fc, ga, gb, gc, n;
int main() {
	scanf("%d", &n);
  	for (int i = 0; i < n; i++) {
      scanf("%d%d%d", &a, &b, &c);
      fa = max(gb + b, gc + c);
      fb = max(ga + a, gc + c);
      fc = max(ga + a, gb + b);
      ga = fa; gb = fb; gc = fc;
    }
	printf("%d\n", max(ga, max(gb, gc)));
  	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int i = a; i <= (b); ++i) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	set<int>b;
	rep0(i, 2) {
		int a;
		cin >> a;
		b.insert(a);

	}
	cout << b.size() << endl;
	return 0;
}
 

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

using namespace std;

void solve() {
    string s, t; cin >> s >> t;
    int a, b; cin >> a >> b;
    string u; cin >> u;
    if (u == s) cout << a - 1 << ' ' << b;
    else cout << a << ' ' << b - 1;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
}


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

ans = -1*(10**18)
for si in range(N):
  x = si
  s = list()
  total = 0
  l = 0
  while(1):
    x = PList[x]-1
    s.append(CList[x])
    l += 1
    total += CList[x]
    if x == si:
      break
  t = 0
  for i in range(l):
    t += s[i]
    if i+1 > K:
      break
    now = t
    if total > 0:
      e = (K-i-1)//l
      now += total*e
    ans = max(ans, now)  
print(ans)

  

Measured memory_bytes: 80988
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;

void main()
{
    string s;
    while( (s=readln.strip) != "0 0") {
        auto n = map!(to!int)(s.strip.split);
        int h = n[0], w = n[1];

        foreach(i;0..h) {
            foreach(j;0..w) {
              write((i+j)%2==0 ? '#':'.');
            }
            writeln();
        }
       writeln();
    }
}

Measured memory_bytes: 2480
#include <stdio.h>

int main(int argc, char **argv)
{
    int n, k, x, y;
    scanf("%d %d %d %d", &n, &k, &x, &y);

    int price;
    if (n > k) {
        price = k*x + (n-k)*y;
    } else {
        price = n * x;
    }
    printf("%d\n", price);
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int x = 0;
    while (a > 0 && c > 0) {
        if (x++ % 2 == 0) {
            c -= b;
        } else {
            a -= d;
        }
    }
    if (a <= 0) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}

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

using namespace std;

int mapa[112345];
vector <int> ligacao[112345];

void DFS(int pos) {

    for (int i = 0;i < ligacao[pos].size(); i++) {
        if (!mapa[ligacao[pos][i]]) {
            mapa[ligacao[pos][i]] = 1;
            DFS(ligacao[pos][i]);
        }
    }
}

int main() {
    int nun_c, nun_l, x, y, res=0;
    scanf("%d%d", &nun_c, &nun_l);

    for (int i = 0;i < nun_l; i++) {
        scanf("%d%d", &x, &y);
        ligacao[x].push_back(y);
        ligacao[y].push_back(x);
    }
    for (int i = 1; i <= nun_c; i++) {
        if(!mapa[i]) {
            res++;
            DFS(i);
        }
    }

    printf("%d\n", res-1);


    return 0;
}

Measured memory_bytes: 10424
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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 ll mod=1e9+7;

const ll INF=1e10+100;

int main()
{
    string s;
    cin >> s;
    ll n=s.length();
    set<ll> t;
    rep(i,n){
        t.insert(s[i]);
    }
    if(t.size()==n) cout << "yes" << endl;
    else cout << "no" << endl;
    return 0;
} 

Measured memory_bytes: 3624
from collections import Counter

N=int(input())
A=list(map(int,input().split()))

A_=Counter(A)
A_=A_.most_common()
A_.sort(reverse=True)


ans=[]
cnt=0
for a in A_:
    if a[1]==2 or a[1]==3:
        ans.append(a[0])
        cnt+=1
    elif a[1]>=4:
        ans.append(a[0])
        cnt+=1
        if cnt==1:
            ans.append(a[0])
            cnt+=1
    if cnt>=2:
        break
if len(ans)<2:
    print(0)
    exit()
print(ans[0]*ans[1])

Measured memory_bytes: 21540
#include <bits/stdc++.h>
using namespace std;
#define sz(x) ((int) (x).size())
#define forn(i,n) for (int i = 0; i < int(n); ++i)
typedef long long ll;
typedef long long i64;
typedef long double ld;
const int inf = int(1e9) + int(1e5);
const ll infl = ll(2e18) + ll(1e10);

const int maxn = 100100;
vector<int> g[maxn];
bool used[maxn];

int main() {
    #ifdef LOCAL
    assert(freopen("b.in", "r", stdin));
    #else
    #endif
    int n, m;
    cin >> n >> m;
    forn (i, m) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    deque<int> path;
    path.push_back(0);
    used[0] = true;
    while (true) {
        int u = path.back();
        for (int v: g[u]) {
            if (!used[v]) {
                used[v] = true;
                path.push_back(v);
                break;
            }
        }
        if (u == path.back())
            break;
    }

    while (true) {
        int u = path.front();
        for (int v: g[u]) {
            if (!used[v]) {
                used[v] = true;
                path.push_front(v);
                break;
            }
        }
        if (u == path.front())
            break;
    }
    cout << sz(path) << '\n';
    for (int u: path)
        cout << u + 1 << ' ';
    cout << '\n';
}


Measured memory_bytes: 6784
#include<stdio.h>
int main(void){
    int N, K, x, i, ans;
    scanf("%d %d", &N, &K);
    ans = 0;
    for(i = 0; i < N; i++){
        scanf("%d", &x);
        if(x - 0 < K - x) ans += (x - 0) * 2;
        else ans += (K - x) * 2;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[][][] house = new int[4][3][10];
        int i, j, k;
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 3; j++) {
                for (k = 0; k < 10; k++) {
                    house[i][j][k] = 0;
                }
            }
        }
        int n = Integer.parseInt(br.readLine());
        String[] input;
        int b, f, r ,v;
        for (i = 0; i < n; i++) {
            input = br.readLine().split(" ");
            b = Integer.parseInt(input[0]) - 1;
            f = Integer.parseInt(input[1]) - 1;
            r = Integer.parseInt(input[2]) - 1;
            v = Integer.parseInt(input[3]);
            house[b][f][r] += v;
        }
        String output;
        for (i = 0; i < 4; i++) {
            for (j = 0; j < 3; j++) {
                output = "";
                for (k = 0; k < 10; k++) {
                    output += " " + house[i][j][k];
                }
                System.out.println(output);
            }
            if (i != 3) System.out.println("####################");
        }
    }
}

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


int arr[400][400];

int cnt[400];
bool chk[400];
int idx[400];
int main() {
	int n,m;
	scanf("%d%d", &n,&m);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			scanf("%d", &arr[i][j]);
		}
	}
	int left = 1;
	int right = 310;
	int ans = 310;
	while (left <= right) {
		int mid = (left + right) / 2;
		memset(cnt, 0, sizeof(cnt));
		memset(chk, 0, sizeof(chk));
		memset(idx, 0, sizeof(idx));
		for (int i = 0; i < n; i++) {
			cnt[arr[i][0]]++;
		}

		bool flag2 = false;
		while (true) {
			bool flag = false;
			for (int i = 1; i <= m; i++) {
				if (cnt[i] > mid) {
					flag = true;
					chk[i] = true;
				}
			}
			if (!flag) {
				break;
			}
			for (int i = 0; i < n; i++) {
				while (idx[i] != m && chk[arr[i][idx[i]]]) {
					cnt[arr[i][idx[i]]]--;
					idx[i]++;
					cnt[arr[i][idx[i]]]++;
				}
				if (idx[i] == m) {
					flag2 = true;
					break;
				}
			}
			if (flag2)break;
		}
		if (flag2) {
			left = mid + 1;
		}
		else {
			right = mid - 1;
			ans = std::min(ans, mid);
		}
		

	}
	printf("%d", ans);

}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
  int c[3][3];
  int a[3],b[3];
  bool f=false;
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++)
      cin>>c[i][j];
  for(a[0]=0;a[0]<=100&&!f;a[0]++){
   	for(int i=0;i<3;i++)
      b[i]=c[0][i]-a[0];
    for(int i=1;i<3;i++)
      a[i]=c[i][0]-b[0];
    if(a[1]+b[1]==c[1][1] && a[1]+b[2]==c[1][2] && a[2]+b[1]==c[2][1] && a[2]+b[2]==c[2][2])
      f=true;
  }
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}

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

// ユークリッドの互除法
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(){
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i,n) cin >> t[i];

    ll L = t[0];
    rep(i,n-1){
        L = lcm(L, t[i+1]);
    }

    cout << L << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
// #define int ll
#define pb push_back
#define pob pop_back
#define __bp __builtin_popcount
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pdd = pair<ld,ld>;
using vint = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
#define F first
#define S second
const int N = 1e6+5;//(1 << 18) + 5;
//const ll inf = 1e18+7;
const int Inf = 1e9+7;
const ll INF = 1e18+7;
const int Mod = 1e9+7;
const ld eps = 1e-9;
#ifndef M_PI
#define M_PI 3.1415926535
#endif

void io()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cerr.tie(NULL);
//	freopen("sweets.in", "r", stdin);
//	freopen("sweets.out", "w", stdout);
//	cout << setprecision(7) << fixed;
}

int n, m;
int h, w;
int fx, fy;
int sx, sy;
char arr[1001][1001];

int cc[1001][1001];
int cnt = 0;
int used[1001][1001];

const int sh[][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};

bool ok(int x, int y)
{
	return x < n && y < m && x > -1 && y > -1;
}

void dfs(int x, int y)
{
	if (used[x][y] || (arr[x][y] == '#'))
		return;
	used[x][y] = 1;
	cc[x][y] = cnt;
	for (int i = 0; i < 4; ++i)
	{
		int nx = x + sh[i][0]; int ny = y + sh[i][1];
		if (ok(nx, ny))
			dfs(nx, ny);
	}
}

vint g[1000001];
int dist[1000001];
bool used2[1000001];

void dj()
{
	for (int i = 0; i <= cnt; ++i)
		dist[i] = Inf;
	dist[cc[sx][sy]] = 0;
	set<pii> s;
	s.insert({0, cc[sx][sy]});
	while (s.size())
	{
		pii p = *s.begin();
		s.erase(s.begin());
		int v = p.S;
		// cerr << "V: " << v << '\n';
		for (int to: g[v])
		{
				// cerr << "FROM: " << v << ' ' << to << endl;
			int nd = dist[v] + 1;
			if (dist[to] > nd)
			{
				// cerr << "FROM: " << v << ' ' << to << endl;
				// cerr << "DIST: " << dist[to] << '\n';
				s.erase({dist[to], to});
				dist[to] = nd;
				s.insert({dist[to], to});
			}
		}
	}
}

void solve()
{
	cin >> n >> m >> sx >> sy >> fx >> fy;
	--sx; --sy; --fx; --fy;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < m; ++j)
			cin >> arr[i][j];
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (!used[i][j] && (arr[i][j] != '#'))
			{
				++cnt;
				dfs(i, j);
			}
		}
	}
	// cerr << cnt << '\n';
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < m; ++j)
		{
			if (!used[i][j])
				continue;
			for (int sx = -2; sx < 3; ++sx)
			{
				for (int sy = -2; sy < 3; ++sy)
				{
					int nx = i + sx; int ny = j + sy;
					if (ok(nx, ny) && (used[nx][ny]))
					{
						int c1 = cc[nx][ny];
						int c2 = cc[i][j];
						if (c1 != c2)
						{
							g[c2].pb(c1);
							g[c1].pb(c2);
							// cerr << c2 << ' ' << c1 << '\n';
						}
					}
				}
			}
		}
	}
	for (int i = 0; i < cnt; ++i)
	{
		sort(g[i].begin(), g[i].end());
		auto p = unique(g[i].begin(), g[i].end());
		while (g[i].end() != p)
			g[i].pob();
	}
	dj();
	cout << (dist[cc[fx][fy]] < Inf ? dist[cc[fx][fy]]: -1) << '\n';
}

signed main()
{
	io();
	int tt = 1;
//	cin >> tt;
	while (tt--)
		solve();
}
//overflows!!!

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N; cin >> N;
	vector<ll> A(N);
	for (ll& a : A) cin >> a;

	ll xorSum = 0;
	ll addSum = 0;
	ll ans = 0;
	for (int i = 0, j = 0; i < N; i++) {
		while (j < N && (xorSum ^ A[j]) == (addSum + A[j])) {
			xorSum ^= A[j];
			addSum += A[j];
			j++;
		}
		ans += j - i;
		xorSum ^= A[i];
		addSum -= A[i];
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 1792
#include <math.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;


int main() {
    int K;
    string S;
    cin >> K >> S;
    string ans = "";
    if (S.size() <= K) {
      ans = S;
    } else {
      for (int i = 0; i < K; i++) {
        ans += S[i];
      }
      ans += "...";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, W, w[100], v[100];
ll dp[100][100001];
int f(int i, int a)
{
    if(i == n)
        if(a != 0)
            return 1e9+1;
        else
            return 0;
    if(dp[i][a] != -1)
        return dp[i][a];
    return dp[i][a] = min(f(i+1, a-v[i]) + w[i], f(i+1, a));
}
int main()
{
    cin >> n >> W;
    for(int i=0; i<n; ++i)
        cin >> w[i] >> v[i];
        memset(dp, -1, sizeof dp);
    for(int i=1e5; i>=0; --i)
        if(f(0, i) <= W)
        {
            cout << i;
            return 0;
        }
}

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

fn main() {
    let s: Vec<char> = read::<String>().chars().collect();
    let mut c0 = 0;
    let mut c1 = 0;
    for i in &s {
        if *i == '0' {
            c0 += 1;
        } else {
            c1 += 1;
        }
    }
    println!("{}", 2 * std::cmp::min(c0, c1));
}

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

Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long int 
signed main(){
    int n;
    cin >> n;
    vector<int> a(n + 1),b(n);
    for(int i = 0; i < n + 1; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        cin >> b[i];
    }
    int sum = 0;
    for(int i = 0; i < n; i++){
       sum += min(a[i],b[i]);
        b[i] -= min(a[i],b[i]);
        sum += min(b[i], a[i + 1]);
        if(a[i + 1] <= b[i])
        a[i + 1] = 0;
        else
        a[i + 1] -= b[i];
    }
    cout << sum << endl;
}

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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

struct Segment {
  int64 s, t;
};

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

  int n;
  cin >> n;
  vector<Segment> segments;
  for (int i = 0; i < n; i++) {
    int64 x, l;
    cin >> x >> l;
    segments.push_back(Segment{x - l, x + l});
  }
  sort(segments.begin(), segments.end(), [](const auto& s1, const auto& s2) {
    return s1.t < s2.t;
  });
  int ans = 0;
  int64 last_t = INT64_MIN;
  for (const auto& segment : segments) {
    if (segment.s < last_t) continue;
    ans++;
    last_t = segment.t;
  }
  cout << ans << endl;
}

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

int main() {
  int64_t N,ans=0;
  cin >> N;
  vector<int64_t>A(N);
  vector<int64_t>B(N+1,0);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    B.at(A.at(i))++;
  }
  for(int i=1;i<=N;i++){
    ans+=(B.at(i)*(B.at(i)-1))/2;
  }
  for(int i=0;i<N;i++){
    cout << ans-B.at(A.at(i))+1 << endl;
  }
}

Measured memory_bytes: 5760
import bisect
n = int(input())
a = sorted(map(int, input().split()))

ai = a[-1]
half_ai = ai // 2

i_left = bisect.bisect_left(a, half_ai)
i_right = bisect.bisect_right(a, half_ai)
if (a[i_left] == half_ai):
    print(ai, half_ai)
    exit()

if (i_left == i_right and i_left == 0):
    print(ai, a[0])
    exit()

if (abs(half_ai - a[i_left - 1]) >=
        abs(half_ai - a[i_right]) and i_right != len(a) - 1):
    print(ai, a[i_right])
else:
    print(ai, a[i_left - 1])


Measured memory_bytes: 19916
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
    input <- getContents
    let [n, m] : list : _ = map read . words <$> lines input :: [[Int]]
    ( putStrLn
        . show
        . sum
        . map ((`div` 2) . (<*>) (*) (subtract 1))
        . map length
        . group
        . sort
        . map (`mod` m)
        . scanl (+) 0
        )
        list


Measured memory_bytes: 13820
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

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

	int N=in(),M=in();
	vector<ll> V(N),W(N);
	ll sumV=0;
	REP(i,N){
		V[i]=in();
		W[i]=in();
		sumV+=V[i];
	}
	
	vector<vector<ll>> dp(N+1,vector<ll>(sumV+1,(1LL<<60)));
	dp[0][0] = 0;

	REP(i,N){
		REP(j,sumV+1){
			if(j+V[i]<=sumV) chmin(dp[i+1][j+V[i]],dp[i][j]+W[i]);
			chmin(dp[i+1][j],dp[i][j]);
		}
	}
	
	int ans = 0;
	for(int i=0;i<=sumV;i++){
		if(dp[N][i]<=M) ans = i;
	}
	out(ans);
	return 0;
}



Measured memory_bytes: 10696
solve [_] [] = 0
solve (a0:a1:as) (b:bs) | (a0 + a1) < b = (a0 + a1) + solve (0:as) bs
                        | (a0 + a1) > b && a0 > b = b + solve (a1:as) bs
                        | (a0 + a1) > b && a0 <= b = b + solve ((a1+a0-b):as) bs
                        | otherwise = b + solve (0:as) bs

main = do
    n <- readLn :: IO Int
    as <- map read . words <$> getLine :: IO [Int]
    bs <- map read . words <$> getLine :: IO [Int]
    print $ solve as bs


Measured memory_bytes: 106164
import java.util.*;

public class Main {

    static int gcd (int a, int b) {return b>0?gcd(b,a%b):a;}
    static int mod = 1000000007;

    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<String> set = new HashSet<>();
        for(int i=0;i<N;i++){
            String S = sc.next();
            set.add(S);
        }

        System.out.println(set.size());



    }

}









Measured memory_bytes: 77200
#include<stdio.h>
int main()
{
    int a,b,i,j,k;
    scanf("%d",&a);
    int x[a][6];
    for(i=0;i<a;i++){
        for(j=0;j<6;j++){
            scanf("%d",&x[i][j]);
        }
    }
  
    for(i=0;i<a-1;i++){
        for(j=i+1;j<a;j++){
            for(k=0;k<122;k++){
                if(x[i][0]==x[j][0]&&x[i][5]==x[j][5]){
                    if(x[i][1]==x[j][1]&&x[i][4]==x[j][4]){
                        if(x[i][2]==x[j][2]&&x[i][3]==x[j][3]){
                            puts("No");
                            return 0;
                        }
                    }
                    else{
                        b=x[j][1];x[j][1]=x[j][2];x[j][2]=x[j][4];
                        x[j][4]=x[j][3];x[j][3]=b;
                    }
                }
                if(k%2){
                    b=x[j][1];x[j][1]=x[j][0];x[j][0]=x[j][4];
                    x[j][4]=x[j][5];x[j][5]=b;
                }
                else{
                    b=x[j][5];x[j][5]=x[j][2];x[j][2]=x[j][0];
                    x[j][0]=x[j][3];x[j][3]=b;
                }
            }
        }
    }
    puts("Yes");
    return 0;
}


Measured memory_bytes: 2132
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define INF 1000000000001
#define DIM 100001
#define mod 1000000007
#define PI 3.1415926535897932384626433
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define T true
#define F false
#define fi first
#define endl "\n"
#define se second
#define DIM 100001
#define pb push_back
#define amen exit(0);
#define qwe return 0;
#define mod 1000000007
#define INF 1000000000001
#define gg cout<<"OPS"<<endl;
#define PI 3.1415926535897932384626433
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define time cout << "\nTime Elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " sec\n";
typedef char ch;
typedef bool boll;
typedef string st;
typedef long long ll;
typedef long double ld;
typedef set < string > sst;
typedef set < long long > sll;
typedef unsigned long long ull;
typedef queue < long long > que;
typedef deque < long long > deq;
typedef vector < long long > vec;
typedef map < long long, long long > mll;
typedef pair < long long, long long > pll;
typedef pair < long long, unsigned long long > pul;
typedef vector < pair < long long, long long > > vpl;
typedef tree <ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> myset;
ll n,z,x,s;
int main()
{
     fast;
     ll x;
     cin>>x;
     cout<<abs(x-1)<<endl;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;

int main(){
    ll A,B,K;
    cin >> A >> B >> K;
    if(A < K){
        K-=A;
        A=0;
        if(B<K) B = 0;
        else B-=K;
    }
    else A-=K;
    cout << A << " " << B << endl;
}

Measured memory_bytes: 3684
n = int(input())
a_ = list(map(int, input().split(' ')))
a = [-1]
i = 0
while  i < n:
    if a[-1] != a_[i]:
        a.append(a_[i])
    i += 1
a = a[1:]
n = len(a)

ret = 1

i = 0
while i < n-2:
    if (a[i] > a[i+1] and a[i+1] < a[i+2]) or (a[i] < a[i+1] and a[i+1] > a[i+2]):
        ret += 1
        i += 2
    else:
        i += 1
        
print(ret)

Measured memory_bytes: 14436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    int k;
    cin >> s >> k;
    int sl = s.length();
    
    rep(i, sl) {
        if (s[i] == 'a') {
            continue;
        }
        
        if (('z' - s[i] + 1) <= k) {
            k -= 'z' - s[i] + 1;
            s[i] = 'a';
        }
    }
    
    if (k > 0) {
        k %= 'z' - 'a' + 1;
        s[sl - 1] += k;
    }
    
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 592
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn gcd(mut a: usize, mut b: usize) -> usize {
    while b != 0 {
        let c = a % b;
        a = b;
        b = c;
    }
    a
}

fn main() {
    input! { x:usize, y:usize }
    println!("{}", gcd(x, y));
}



Measured memory_bytes: 5036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//cout << fixed << setprecision(17) << res << endl;
 
int main() {
    ll d, n;
    cin >> d >> n;
    ll k = 1;
    if (n == 100) ++n;
    for (ll i = 0; i < d; ++i) {
        k *= 100;
    }
    cout << n * k << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<climits>
#include<cstring>
#include<queue>
#include<map>
#include<functional>
using namespace std;

typedef unsigned long long ull;

const int INF = INT_MAX/3;

int main(){
    int N;
    cin >> N;
    vector<ull> a(N);
    vector< pair<ull, int> > pairList;
    for (int i=0;i<N;i++){
        cin >> a[i];
        pairList.push_back(make_pair(a[i], i+1));
    }
    pairList.push_back(make_pair(0, 0));

    sort(pairList.begin(), pairList.end(), greater< pair<ull, int> >());

    vector<ull> count(N+1, 0ull);
    int secondMin = INF;
    for(int i=0;i<N;i++){
        secondMin = min(secondMin, pairList[i].second);
        count[secondMin] += (pairList[i].first - pairList[i+1].first)*(i+1);
    }

    for(int i=1;i<N+1;i++){
        cout << count[i] << endl;
    }

    return 0;
}

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

 return 0;
}
  

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
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;}
int const INF = 1001001001;


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

ll a,b; char op;
cin >> a >> op >>  b;

if(op == '+') cout << a + b << endl;
else cout << a - b << endl;
return 0;
}

Measured memory_bytes: 256
def cur(n):
    if ans[n]!=[]: return ans[n]
    for x in cur(n-1):
        tmp1=[0]+[x[i] for i in range(n-1)]
        tmp2=[0]+[x[i]+1 for i in range(n-1)]
        ans[n].append(tmp1)
        ans[n].append(tmp2)
        if max(x)!=0:
            for k in range(1,max(x)+1):
                tmp3=[0]+[x[i] for i in range(n-1)]
                for i in range(1,n):
                    if tmp3[i]==k: tmp3[i]=0
                    elif tmp3[i]<k: tmp3[i]+=1
                ans[n].append(tmp3)
    
    return ans[n]

def pri(x):
    s=""
    for i in range(p):
        s+=chr( ord("a")+x[i] )
    print(s)

p=int(input())
ans=[[] for i in range(11)]
ans[1]=[[0]]
ans[2]=[[0,0],[0,1]]
cur(p)

ans[p].sort()
pri(ans[p][0])
for i in range(1,len(ans[p])):
    if ans[p][i]!=ans[p][i-1]: pri(ans[p][i])

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

#define REP(i,n) for(int i=0,_n=(int)(n); i < _n; i++)
typedef long long ll;

int main2() {
  int N, x;
  scanf("%d%d", &N, &x);

  int M = 2 * N - 1;
  if (x == 1 || x == M) {
    printf("No\n");
    return 0;
  }

  printf("Yes\n");
  int o = x - N;
  REP(i, M) 
    printf("%d\n", (i+o+M) % M + 1);

  return 0;
}

int main() {
  while (!cin.eof()) {
    main2();
    cin >> ws;
  }
  return 0;
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <random>
#include <chrono>
#include <tuple>
#include <random>
#include <cmath>

using namespace std;

typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);

const ll SIZE = 1e6 * 2 + 10, INF = 1e9 * 1e9 + 10;



int main()
{
    fastInp;

    ll n, x, t;
	cin >> n >> x >> t;

	cout << ((n - 1) / x + 1) * t;
    
    return 0;
}

Measured memory_bytes: 3656
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){

	ll n, m, a[100009][3], maxn=-(1LL<<60);
	cin >> n >> m;
	for(int i=1; i<=n; i++){
		for(int j=0; j<3; j++){
			cin >> a[i][j];
		}
	}
	for(int i=0; i<8; i++){
		vector<ll> vec;
		for(int j=1; j<=n; j++){
			ll s=0;
			for(int k=0; k<3; k++){
				if((i/(1<<k))%2==0){
					s+=a[j][k];
				} else {
					s-=a[j][k];
				}
			}
			vec.push_back(s);
		}
		sort(vec.begin(), vec.end());
		reverse(vec.begin(), vec.end());
		ll ans=0;
		for(int j=0; j<m; j++){
			ans+=vec[j];
		}
		maxn=max(maxn, ans);
	}
	cout << maxn << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
long N=5e5,m,n,s,d=1,c;
int main(){
  c=getchar();
  while(d){
    for(m=0;c=='<';m++,c=getchar());
    for(n=0;c=='>';n++,c=getchar());
    s+=(d=(m>n?m:n)+m*(m-1)/2+n*(n-1)/2);
  }
  printf("%ld\n",s);
}


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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

struct Edge
{
    int from, to;
    string tag;
    Edge(int f, int t, string s) : from(f), to(t), tag(s) {}
};

struct State
{
    int cur, len;
    string s;
    State(int c, int l, string s) : cur(c), len(l), s(s) {}
};

bool operator<(const State &e, const State &f)
{
    return e.s > f.s;
}

using Graph = vector<vector<Edge>>;

int n, m, st, gt;

string dijkstra(const Graph &g)
{
    // 頂点iにj文字で辞書順最小
    vector<vector<string>> dp(n, vector<string>(510, "~"));
    dp[st][0] = "";
    std::priority_queue<State> que;
    que.emplace(st, 0, dp[st][0]); // P(dis, pos)
    while (!que.empty())
    {
        int v = que.top().cur;
        int len = que.top().len;
        string str = que.top().s;
        que.pop();
        if (dp[v][len] < str)
            continue;
        for (const auto &e : g[v])
        {
            string nxt = str + e.tag;
            int sz = nxt.size();
            if (sz > 500)
                continue;
            if (dp[e.to][sz] <= nxt)
                continue;
            dp[e.to][sz] = nxt;
            que.emplace(e.to, sz, dp[e.to][sz]);
        }
    }
    string ret = "~";
    for (int i = 1; i < 500; i++)
    {
        if (ret <= dp[gt][i])
            continue;
        if (i > 300)
            return "NO";
        ret = dp[gt][i];
    }
    if (ret == "~")
        return "NO";
    return ret;
}

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

    while (cin >> n >> m >> st >> gt, n || m || st || gt)
    {
        Graph g(n);
        for (int i = 0; i < m; i++)
        {
            int x, y;
            string s;
            cin >> x >> y >> s;
            g[x].push_back(Edge(x, y, s));
        }
        cout << dijkstra(g) << endl;
    }
}



Measured memory_bytes: 25312
import math,fractions
a,b=list(map(int,input().split()))

def f(n):
    a=[1]
    while n%2==0:
        a.append(2)
        n//=2
    f=3
    while f*f<= n:
        if n%f==0:
            a.append(f)
            n//= f
        else:
            f+= 2
    if n!=1:
        a.append(n)
    return a

def g(n,r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))
 
ans=set(f(a))&set(f(b))
#print(ans)
print(len(ans))

Measured memory_bytes: 5048
#include<iostream>
#include<cmath>
using namespace std;
int main() {
  int n,t,a; cin >> n >> t >> a;
  int ans;
  int h[1050];
  double r[1050];
  double ans_value=99999999.9;
  for(int i=0;i<n;i++){cin >> h[i];
    if(ans_value>=abs(t-0.006*h[i]-a)){
      ans_value = abs(t-0.006*h[i]-a);
      ans = i+1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {

	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var numBall = Number(tmp[0]);
	var maxKind = Number(tmp[1]);
	var A = line[1].split(" ");

	var obj = {};
	for(var i = 0; i < A.length; i++){
		if(!obj[A[i]]) obj[A[i]] = 0;
		obj[A[i]]++;
	}
	var ary = [];
	for(var key in obj){
		ary.push(obj[key]);
	}
	ary.sort(function(a,b){
		return a-b;
	});
	var chTimes = ary.length - maxKind;
	var ans = 0;
	if(chTimes > 0){
		for(var j = 0; j < chTimes; j++){
			ans += ary[j];
		}
	}
	console.log(ans);
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 51016
#include <iostream>
using namespace std;
int P[10010];
int root(int a) {
 if (P[a] == a) return a;
 return (P[a] = root(P[a]));
}
bool is_same_set(int a, int b) {
 return root(a) == root(b);
}
void unite(int a, int b) {
 P[root(a)] = root(b);
}

int main() {
 int n, q;
 cin >> n >> q;
 for (int i = 0; i<n; i++) {
  P[i] = i;
 }
 for (int i = 0; i<q; i++) {
  int com, x, y;
  cin >> com >> x >> y;
  if(com) {
   if(is_same_set(x,y)) { cout << 1 << endl; }
   else { cout << 0 << endl; }
  }
  else {
   unite(x, y);
  }
 }
}


Measured memory_bytes: 1320
#include<iostream>
#include<map>
using namespace std;
int main(){
	long n,m;
	cin >> n >> m;
	map<long,long> M;
	for(int i=0;i<n;i++){
		int a;
		cin >> a;
		M[a]++;
	}
	for(int i=0;i<m;i++){
		int b,c;
		cin >> b >> c;
		M[c]+=b;
	}
	long ans=0;
	for(auto i=M.end();;i--){
		if(i==M.end()) i--;
		ans+=min(n,i->second)*i->first;
		n-=i->second;
		if(n<=0) break;
		if(i==M.begin()) break;
	}
	cout << ans << endl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
int main(){
  int n,m,a,b,l,r,ans=0;
  std::cin>>n>>m;
  std::vector<std::pair<int,int>> v(m);
  for(int i=0;i!=m;++i){
    std::cin>>a>>b;
    v[i]={b,a};
  }
  std::sort(v.begin(),v.end());
  l=v[0].second;
  r=v[0].first;
  ++ans;
  for(int i=1;i!=m;++i){
    if(v[i].second>l){
      l = v[i].second;
      if(v[i].second>=r){
        r = v[i].first;
        ++ans;
      }
    }
  }
  std::cout<<ans<<"\n";
}
  

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

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

    vector<pair<int,int>> ans;
    if(n%2==1){
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(i+j==n) continue;
                ans.push_back({i,j});
            }
        }
    }
    else{
        for(int i=1;i<=n;i++){
            for(int j=i+1;j<=n;j++){
                if(i+j==n+1) continue;
                ans.push_back({i,j});
            }
        }
    }

    cout<<ans.size()<<endl;
    rep(i,ans.size()){
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
}

Measured memory_bytes: 3736