akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
using namespace std;

#define MAX 500000
#define INFINITY INT_MAX

int L[MAX/2+2], R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right)
{
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i = 0; i < n1; i++) L[i] = A[left + i];
  for(int i = 0; i < n2; i++) R[i] = A[mid + i];
  L[n1] = R[n2] = INFINITY;
  for(int i = 0, j = 0, k = left; k < right; k++)
  {
    cnt++;
    if(L[i] <= R[j]) A[k] = L[i++];
    else A[k] = R[j++];
  }
}

void mergeSort(int A[], int n, int left, int right)
{
  if(left+1 < right)
  {
    int mid = (left + right) / 2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main()
{
  int A[MAX], n;
  cnt = 0;

  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];

  mergeSort(A, n, 0, n);

  for(int i = 0; i < n; i++)
  {
    if(i) cout << " ";
    cout << A[i];
  }
  cout << endl;

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 7000
using System;
using System.Collections.Generic;
using System.Linq;
using console=System.Console;
namespace AtCoderTemplate
{
    public class App
    {
        public static void Main(string[] args)
        {
            string s="0";
        Console.WriteLine(
        console.ReadLine().ToCharArray().Select(c => "ACGT".Contains(c))
            .Select((b) =>
            {
                s=b?(int.Parse(s)+1).ToString():"0";
                return s;
            }).Select(v=>int.Parse(v)).Max());
        }
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>

using namespace std;

int main() {
	char S[16] = {};
	cin >> S;

	int l = strlen(S);
	int c = 0;
	for (int i = 0; i < l; i++) {
		if (S[i] == 'x') { c++; }
	}
	if (c >= 8) { cout << "NO" << endl; }
	else {
		cout << "YES" << endl;
	}
	return 0;
}

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

struct Info {
  int M, D, t, e, p;  
};

signed main() {
  int n;
  while ( cin >> n, n ) {
    vector<int> sum(1000, 0);
    int cnt = 0;
    vector<Info> dat;    
    while ( n-- ) {      
      int M, D, h, m, p;
      char e;
      scanf("%d/%d %d:%d %c %d", &M, &D, &h, &m, &e, &p);
      if ( e == 'I' ) {
	dat.emplace_back(Info{M, D, h*60+m, 0, p});
	cnt++;
      } else {
	dat.emplace_back(Info{M, D, h*60+m, 1, p});
	cnt--;
      }

      if ( cnt ) continue;
      vector<int> zero(1500, 0);
      vector<int> I(1000, 0);      
      for ( Info i : dat ) {
	if ( i.p != 0 ) continue;
	if ( i.e == 0 ) {
	  I[i.p] = i.t;	  
	} else {
	  for ( int j = I[i.p]; j < i.t; j++ ) {
	    zero[j]++;	    
	  }
	}
      }

      for ( Info i : dat ) {
	if ( i.p == 0 ) continue;
	if ( i.e == 0 ) {
	  I[i.p] = i.t;	  
	} else {
	  for ( int j = I[i.p]; j < i.t; j++ ) {
	    if ( zero[j] ) sum[i.p]++;	    
	  }
	}
      }

      dat.clear();      
    }

    int ma = 0;
    for ( int i = 0; i < 1000; i++ ) {
      ma = max(ma, sum[i]);
    }

    cout << ma << endl;
  }
  return 0;
}



Measured memory_bytes: 3152
import java.util.Scanner;

public class Main {
    
    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        int sheep = scanner.nextInt();
        int wolves = scanner.nextInt();

        if(sheep <= wolves) {
            System.out.println("unsafe");
        } else {
            System.out.println("safe");
        }

    }
}

Measured memory_bytes: 35780
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define NMAX 100
int n;
int rank[NMAX+1];
class Data{
public:
	int p;
	int No;
	Data(int _p,int _No):p(_p),No(_No){

	}
	bool operator < (const Data &o)const{
		return p > o.p;
	}
};

int main(){
	cin>>n;
	int limit=(n*(n-1))/2;
	int a,b,c,d;
	vector<Data> v;
	for(int i=1;i<=n;i++)
		v.push_back(Data(0,i));
	for(int i=0;i<limit;i++){
		cin>>a>>b>>c>>d;
		v[a-1].p+=c>d?3:c==d?1:0;
		v[b-1].p+=c<d?3:c==d?1:0;
	}
	sort(v.begin(),v.end());
	int r=0;
	int p=v.begin()->p+1;
	int t=0;
	for(vector<Data>::iterator it=v.begin();it!=v.end();it++){
//		cout<<(*it).No<<":"<<(*it).p<<":"<<p<<endl;
		if((*it).p<p){r+=t+1;p=(*it).p;t=0;}
		else if((*it).p==p){t++;}
		rank[(*it).No]=r;
	}
	for(int i=1;i<=n;i++){
		cout<<rank[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(void)
{
	int h1,h2,k1,k2,a,b,c,d,x,y,x1,x2,y1,y2;
	scanf("%d %d",&h1,&h2);
	scanf("%d %d",&k1,&k2);
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	x1=h1*a;
	x2=k1*a;
	y1=h2*b;
	y2=k2*b;
	h1=h1/10*c+x1;
	h2=h2/20*d+y1;
	k1=k1/10*c+x2;
	k2=k2/20*d+y2;
	x=h1+h2;
	y=k1+k2;
	if(x>y) printf("hiroshi\n");
	else if(x<y) printf("kenjiro\n");
	else printf("even\n");
	
	return 0;
}



Measured memory_bytes: 2120
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <math.h>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const long long MOD_NUM = 1000000007LL;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}

static void C_task();

int main()
{
	C_task();
	fflush(stdout);
	return 0;
}

static void C_task()
{
	int X;
	get1int(X);

	int val[] = { 100, 101, 102, 103, 104, 105 };
	int min[] = { 0, 1, 2, 3, 4, 5 };
	int rest = X;
	int surp = 0;
	while (surp = (rest % 100)) {
		if (surp >= 5) {
			rest -= 105;
		}
		else if (surp >= 4) {
			rest -= 104;
		}
		else if (surp >= 3) {
			rest -= 103;
		}
		else if (surp >= 2) {
			rest -= 102;
		}
		else if (surp >= 1) {
			rest -= 101;
		}
		if (rest < 0) {
			break;
		}
	}
	if (rest >= 0) {
		printf("1\n");
	}
	else {
		printf("0\n");
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MAX = 1000000;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  map<int, int> mp;
  for (int i = 0; i < N; i++){
    mp[A[i]]++;
  }
  vector<int> cnt(MAX + 1, 0);
  for (auto P : mp){
    for (int i = P.first; i <= MAX; i += P.first){
      cnt[i] += P.second;
    }
  }
  int ans = 0;
  for (auto P : mp){
    if (cnt[P.first] == 1){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 17180
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>

using namespace std;

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

int main(){
	string str;
	int c=0;
	while(cin>>str){
		string tmp = str;
		reverse(str.begin(),str.end());
		if(tmp == str) c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimization ("Ofast")
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define siz(s) (int)s.size()

template<class T> inline bool chmin(T &a, T b) {
	if(a>b){a=b;return true;}
	return false;
}
template<class T> inline bool chmax(T &a, T b) {
	if(a<b){a=b;return true;}
	return false;
}
template<class T> inline int getidx(vector<T> &v, T a) {
	return lower_bound(all(v), a) - v.begin();
}

constexpr int mod=1e9+7;
constexpr int inf=3e18;


signed main(){
	cin.tie(0);ios::sync_with_stdio(false);
	double n;cin>>n;
	printf("%.12lf\n",n*2*3.14159265);
}


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

int main(){
  int A, B;
  cin >> A >> B;
  
  int ans = 0;
  for(int i = A; i <= B; ++i){
    int a = i%10;
    int b = (i/10)%10;
    int c = (i/100)%10;
    int d = (i/1000)%10;
    int e = i/10000;
    if(a == e and b == d) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
def main():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]

    under = 0
    r = (max(H) + B - 1) // B
    c = A - B
    while r - under > 1:
        m = (r + under) // 2
        rem = 0
        for hi in H:
            hi -= B*m
            if hi <= 0: continue
            rem += (hi + c - 1) // c
        if rem <= m: r = m
        else: under = m
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 43996
package main

import (
	"fmt"
)

func main() {
	var n, a, x, y, max uint
	fmt.Scan(&n)

	statements := make([]statement, n)
	for i := uint(0); i < n; i++ {
		fmt.Scan(&a)

		s := make(statement)
		for j := uint(0); j < a; j++ {
			fmt.Scan(&x, &y)
			s[x-1] = y
		}
		statements[i] = s
	}

	for bit := uint(0); bit < 1<<n; bit++ {
		var (
			cnt uint
			ok  = true
		)

		for i := uint(0); i < n; i++ {
			if bit&(1<<i) == 0 {
				continue
			}

			cnt++
			for _x, _y := range statements[i] {
				if (bit>>_x)&1 != _y {
					ok = false
				}
			}
		}

		if ok && cnt > max {
			max = cnt
		}
	}

	fmt.Println(max)
}

type statement map[uint]uint


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
  ll n,p,m=1,e=0;
  cin >> n >> p;
  vector<ll> a(p,0),b(n,0);
  string s;
  cin >> s;
  reverse(all(s));
  if (p==2 || p==5){
    ll ans=0;
    rep(i,n){
      int u=s[i]-'0';
      if (u%p==0) ans+=n-i;
    }
    cout << ans << endl;
    return 0;
  }
  rep(i,n){
    ll u=s[i]-'0';
    e=(e+u*m)%p;
    a[e]++;
    b[i]=e;
    m=(m*10)%p;
  }
  ll ans=0,c=0;
  m=1;
  rep(i,n){
    ans+=a[c];
    // cout << c << endl;
    a[b[i]]--;
    ll u=s[i]-'0';
    c=(c+u*m)%p;
    m=(m*10)%p;
  }
  cout << ans << endl;
}


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

int main()
{
    int N;
    cin >> N;
    vector<int> X(N, 0);
    int maxn, minn;
    for (int i = 0; i < N; i++)
    {
        cin >> X[i];
    }
    sort(X.begin(), X.end());
    maxn = X[N - 1];
    minn = X[0];
    int ans = 10010010;
    for (int i = minn; i <= maxn; i++)
    {
        int tmp = 0;
        for (int j = 0; j < N; j++)
        {
            tmp += (i - X[j]) * (i - X[j]);
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int n,i,c=0;

    scanf("%d",&n);
    while(n)
    {
       c+=cheak(n);
       n--;
    }

    printf("%d",c);



}
int cheak(int n)
{
    int count=0;
     while(n/10!=0)
  {
      n=n/10;
      count++;
  }
  ++count;
  if(count%2==0)
    return 0;
  else
    return 1;
}


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

int main()
{

   int n;
   char c;
   set<char> s;


   while(cin >> n){
      for(int i = 0; i < n; i++){
         cin >> c;
         s.insert(c);
      }
      cout << (s.size() == 3 ? "Three" :"Four") << endl;
      s.clear();
   }


}



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

int main () {
  int w, h, c, rem[2], temp, r = 0, ans;

  cin >> w >> h >> c;
  rem[0] = w;
  rem[1] = h;
  while (true) {
    temp = rem[1];
    rem[1] = rem[0] % rem[1];
    rem[0] = temp;
    if (rem[1] == 0) {
      r = rem[0];
      break;
    }
  }
  ans = ((w * h) / (r * r)) * c;
  cout << ans << endl;
}

Measured memory_bytes: 3128
import sys

def input():
    return sys.stdin.readline().rstrip()

if __name__ == "__main__":
    a, b, k = map(int, input().split())

    mid = (a + b) // 2

    if a + (k - 1) >= mid:
        [print(i) for i in range(a, b+1)]
    else:
        [print(i) for i in range(a, a+k)]
        [print(i) for i in range(b-(k-1), b+1)]


Measured memory_bytes: 3060
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

#pragma warning(disable : 4996)

using namespace std;

const string JOI = "JOI";

int main()
{
	int H, W;

	scanf("%d", &H);
	scanf("%d", &W);

	vector<string> D(H);

	for (int i = 0; i < H; i++)
	{
		cin >> D[i];
	}

	string C1, C2; cin >> C1 >> C2;

	int sum = 0;

	for (int i = 0; i < H - 1; i++)
	{
		for (int j = 0; j < W - 1; j++)
		{
			string R1 = D[i].substr(j, 2);
			string R2 = D[i + 1].substr(j, 2);

			if (R1 == C1 && R2 == C2)
			{
				sum++;
			}
		}
	}

	int diff, ret = sum;

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			char prevch = D[i][j];

			for (int k = 0; k < 3; k++)
			{
			    diff = 0;
			    
				if (i != 0 && j != 0)
				{
					D[i][j] = JOI[k];
					
					string R1 = D[i - 1].substr(j - 1, 2);
					string R2 = D[i].substr(j - 1, 2);

					diff += (R1 == C1 && R2 == C2 ? 1 : 0);

					D[i][j] = prevch;

					string R3 = D[i - 1].substr(j - 1, 2);
					string R4 = D[i].substr(j - 1, 2);
					
					diff -= (R3 == C1 && R4 == C2 ? 1 : 0);
				}

				if (i != 0 && j + 1 != W)
				{
					D[i][j] = JOI[k];

					string R1 = D[i - 1].substr(j, 2);
					string R2 = D[i].substr(j, 2);

					diff += (R1 == C1 && R2 == C2 ? 1 : 0);

					D[i][j] = prevch;

					string R3 = D[i - 1].substr(j, 2);
					string R4 = D[i].substr(j, 2);

					diff -= (R3 == C1 && R4 == C2 ? 1 : 0);
				}

				if (i + 1 != H && j != 0)
				{
					D[i][j] = JOI[k];

					string R1 = D[i].substr(j - 1, 2);
					string R2 = D[i + 1].substr(j - 1, 2);

					diff += (R1 == C1 && R2 == C2 ? 1 : 0);

					D[i][j] = prevch;

					string R3 = D[i].substr(j - 1, 2);
					string R4 = D[i + 1].substr(j - 1, 2);

					diff -= (R3 == C1 && R4 == C2 ? 1 : 0);
				}

				if (i + 1 != H && j + 1 != W)
				{
					D[i][j] = JOI[k];

					string R1 = D[i].substr(j, 2);
					string R2 = D[i + 1].substr(j, 2);

					diff += (R1 == C1 && R2 == C2 ? 1 : 0);

					D[i][j] = prevch;

					string R3 = D[i].substr(j, 2);
					string R4 = D[i + 1].substr(j, 2);

					diff -= (R3 == C1 && R4 == C2 ? 1 : 0);
				}

				ret = max(ret, sum + diff);
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 4056
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
  ll a,b;
  cin>>a>>b;
  if(a<10&&b<10)
      cout<<a*b<<endl;
  else
  cout<<-1<<endl;  
}
return 0;
}

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

def gcd(x, y):
    if x == 0 or y == 0:
        return max(x, y)
    return gcd(y, x % y) if y!=0 else x

w = 0
B = [w]
for x in range(N-1, 0, -1):
    B += [gcd(B[-1], A[x])]

w = 0
M = 0
for x in range(N):
    M = max(M, gcd(w, B.pop()))
    w = gcd(w, A[x])

print(M)


Measured memory_bytes: 14052
// AtCoder template
// 見た奴全員saba!
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < n; ++i)

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

    int n; cin >> n;
    int a[n]; rep(i,n) cin >> a[i];
    int c1= 0,c2;
    rep(i,n) c1 += a[i];
    c1 /= n; c2 = c1 + 1;
    int ans1 = 0, ans2 = 0;
    rep(i,n){
        ans1 += (a[i] - c1)*(a[i] - c1);
        ans2 += (a[i] - c2)*(a[i] - c2);
    }
    cout << min(ans1,ans2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
// #define vi vector <int>
#define seti set<int>
#define mii map<int,int>
#define ull unsigned long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MAX 100100

using namespace std;


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

	double even = n/2;
	double odd = n - even;

	printf("%.7f", 1.0*odd/n);	
	return 0;
}


Measured memory_bytes: 256
fn main() {
    loop {
        let mut buf = String::new();
        std::io::stdin().read_line(&mut buf).unwrap();
        let mut iter = buf.trim().split_whitespace();
        let h: i32 = iter.next().unwrap().parse().unwrap();
        let w: i32 = iter.next().unwrap().parse().unwrap();

        if h == 0 && w == 0 {
            break;
        }
        for line_h in 0..h {
            for line_w in 0..w {
                if line_h == 0 || line_h == h - 1 {
                    print!("#");
                } else if line_w == 0 || line_w == w - 1 {
                    print!("#");
                } else {
                    print!(".");
                }
            }
            println!();
        }
        println!();
    }
}



Measured memory_bytes: 5024
#include<stdio.h>
#include<string.h>
#define MAX 1001


void swap(char str[],int a,int b){
char temp;
temp=str[a];
str[a]=str[b];
str[b]=temp;

return;
}



int main(){
char str[MAX];
int n,i,x,y,j;
char com[8];
char temp[MAX];

scanf("%s",str);
scanf("%d",&n);

for(i=0;i<n;i++){
 scanf("%s",com);
 scanf("%d %d",&x,&y);
 switch(com[2]){
  case 'i':
           for(j=x;j<=y;j++)printf("%c",str[j]);
           printf("\n");
           break;

  case 'p':
           scanf("%s",temp);
           for(j=x;j<=y;j++)str[j]=temp[j-x];
           break;

  case 'v':
           for(j=x;j<=(y+x)/2;j++)swap(str,j,y-(j-x));
           break;
 }
}

return 0;
}


Measured memory_bytes: 2104
#include<bits/stdc++.h>
using namespace std;
//D問題

int main(){
    long long a,b,n;
    cin >> a >> b>> n;
    if(b == 1){
        cout << 0 << endl;
        return 0;
    }

    if(n<b-1){
        long long x = a*n/b;
        long long y = n/b;   
        cout << x << endl;
    }
    if(n>=b-1){
        long long x = a*(b-1)/b;
        long long y = (b-1)/b;
        cout << x << endl;
    }
    return 0;
}


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

void DBG() { cerr << endl; }
template<typename Head, typename... Tail>
void DBG(Head H, Tail... T) { cerr << ' ' << H; DBG(T...); }
#ifdef NAIM
#define dbg(...) cerr << "(" << (#__VA_ARGS__) << "):", DBG(__VA_ARGS__)
#else 
#define dbg(...)
#endif

template<typename... Args>
void read(Args&... args) { ((cin >> args), ...); }

template<typename... Args>
void show(Args... args) { ((cout << args << " "), ...); }

#define ll long long
#define ints(a...) int a; read(a)
#define IN(a) for (auto &it : a) cin >> it

void solve() {
    ll a;
    long double b;
    read(a, b);
    cout << int64_t(a * b + 1e-3);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T = 1; 
    // cin >> T;
    while (T--) solve();
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().run();
	}
	int w;
	int h;
	int count;
	short[][] map;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			w = scan.nextInt();
			h = scan.nextInt();
			if(w == 0 && h == 0){
				break;
			}
			map = new short[h][w];
			for(int i = 0;i < h;i++){
				for(int j = 0;j < w;j++){
					map[i][j] = scan.nextShort();
				}
			}
			count = 0;
			for(int i = 0;i < w;i++){
				if(map[0][i] != 1){
					count += ski(0,i);
				}
			}
			System.out.println(count);
		}
	}
	public int ski(int y,int x){
		if(y == h-1 && x >= 0 && x < w){
			return 1;
		}
		int res = 0;
		if(map[y][x] == 2){
			if(y == h-2){
				return 1;
			}else if(map[y+2][x] == 1){
				return 0;
			}else{
				res += ski(y+2,x);
			}
		}else{
			if(x-1 >= 0 && map[y+1][x-1] == 0){
				res += ski(y+1,x-1);
			}
			if(map[y+1][x] != 1){
				res += ski(y+1,x);
			}
			if(x+1 < w && map[y+1][x+1] == 0){
				res += ski(y+1,x+1);
			}
		}
		return res;
	}
}

Measured memory_bytes: 29440
#include <cstdio>
#include <cstring>
#include <algorithm>
#define Abs(_A) (((_A) < 0) ? (-(_A)) : (_A))
char S[12];
int main(){
	scanf("%s", S);
	int ans = 9999999;
	int len = strlen(S);
	for(int i = 0; i < len; i++) S[i] -= '0';
	for(int i = 0; i <= len - 3; i++){
		int k = S[i] * 100 + S[i + 1] *10 + S[i + 2];
		if(Abs(k - 753) < ans) ans = Abs(k - 753);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n, m;
    std::cin >> n >> m;
    vec<vec<usize>> g(n);
    while (m--) {
        usize u, v;
        std::cin >> u >> v;
        u--, v--;
        g.at(u).push_back(v);
        g.at(v).push_back(u);
    }

    vec<i32> p(n, -1), que = {0};
    p.at(0) = 0;
    for (usize i=0; i<n; i++) {
        usize x = que.at(i);
        for (usize y: g.at(x)) if (p.at(y)==-1) {
            p.at(y)=x;
            que.push_back(y);
        }
    }

    std::cout << "Yes" << '\n';
    for (usize i=1; i<n; i++) {
        std::cout << p.at(i) + 1 << '\n';
    }
}


Measured memory_bytes: 12900
n, k = map(int, input().split())


c = 0 # グルーバル変数
# nが0になるまで割る
def cnt(num, radix):
    x = num // radix
    global c 
    c += 1
    if x == 0:
        return c
    else:
        return cnt(x, radix)

cnt(n, k)
print(c)

Measured memory_bytes: 2940
#include <iostream>
#include <cstdio>
using namespace std;
const int maxn = 1e5 + 10;
int a[maxn];

int main(void)
{
    int N;
    scanf("%d", &N);
    for(int i = 1; i <= N; i++) scanf("%d", a + i);
    int odd = 0, even = 0;
    for(int i = 1; i <= N; i++)
    {
        if(a[i] % 2) odd++;
        else even++;
    }
    even += odd / 2;
    odd = odd % 2;
    if(even && odd) puts("NO");
    else puts("YES");
    return 0;
}


Measured memory_bytes: 768
import fractions
length, target = map(int, input().split(" "))
nums = sorted([int(n) for n in input().split(" ")])
minimum = min(nums)
odd, even, gcd = 0, 0, minimum
for n in nums:
    if n % 2 == 0:
        even = 1
    else:
        odd = 1
    gcd = fractions.gcd(gcd, n)
if target > max(nums):
    print("IMPOSSIBLE")
elif target in nums:
    print("POSSIBLE")
else:
    if gcd == 1:
        print("POSSIBLE")
    else:
        if target % gcd == 0:
            print("POSSIBLE")
        else:
            print("IMPOSSIBLE")
    
    
    

Measured memory_bytes: 16284
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define pi pair<int, int>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define deb(x) cout << #x << ":" << x << endl;
/* freopen("input.txt", "r", stdin); */
/* freopen("output.txt", "w", stdout); */
const ll inf = 1e17 + 7, MOD = 1e7 + 9;


int main() {
	fastio();
	int n, k;
	cin >> n >> k;
	bool snu[n] = {0};
	int aji;
	int count = n;
	for(int i=0;i<k;i++) {
		int d;
		cin >> d;
		for(int j=0;j<d;j++) {
			cin >> aji;
			if(!snu[aji-1]) {
				snu[aji-1] = true;
				count--;
			}
		}
	}
	cout << count << "\n";
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
	int x;
	scanf("%d",&x);
	int sum = 0;
	int i = 0;
	while (sum + (i+1) < x)
	{
		i++;
		sum += i;
	}
	if (sum == x) printf("%d\n",i);
	else printf("%d\n",i+1);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long MOD = 1000000007;
int main(){
	int N, X;
	cin >> N >> X;
	vector<int> S(N);
	for (int i = 0; i < N; i++){
		cin >> S[i];
	}
	sort(S.rbegin(), S.rend());
	vector<vector<long long>> dp(N + 1, vector<long long>(X + 1, 0));
	dp[0][X] = 1;
	for (int i = 0; i < N; i++){
		for (int j = 0; j <= X; j++){
			dp[i + 1][j] += dp[i][j] * (N - 1 - i);
			dp[i + 1][j] %= MOD;
			dp[i + 1][j % S[i]] += dp[i][j];
			dp[i + 1][j % S[i]] %= MOD;
		}
	}
	long long ans = 0;
	for (int i = 0; i <= X; i++){
		ans += dp[N][i] * i;
		ans %= MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 161504
#include<iostream>
#include<cstring>
#include<cassert>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
#include<vector>
#include<time.h>
#include<algorithm>
using namespace std;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define rep(i,n) REP(i,1,n)
#define rep0(i,n) REP(i,0,n-1)
#define repG(i,x) for(int i=pos[x];~i;i=e[i].next)
#define ll long long
#define db double
const int N=1066667;
const int M=22;
const int INF=1e9+7;
int f[M][N],g[M][N][2],fp[N],t[M][N];
int n,mx=0,m,mi;
char s[N];
void ins(int a,int l){
	if(l<mx)return;
	if(l>mx){
		mi=a;
		mx=l;
		return;
	}
	mi=min(mi,a);
}
void print(int x,int w){
	if(!w)return;
	print(x>>1,w-1);
	putchar('0'+(x&1));
} 
int main(){
	scanf("%d%d",&n,&m);
	rep0(i,n)REP(j,(1<<i),(1<<(i+1))-1)fp[j]=i;
	fp[0]=-1;
	g[0][0][0]=g[0][0][1]=-1;
	rep(i,n){
		rep0(j,(1<<i)){
			if((j>>(i-1))&1){
				g[i][j][1]=i-1;
				g[i][j][0]=fp[j^((1<<i)-1)];
			}
			else{
				g[i][j][0]=i-1;
				g[i][j][1]=fp[j];
			}
		}
	}
	rep0(i,n+1){
		scanf("%s",s);
		rep0(j,(1<<i))f[i][j]=s[j]-'0';
	}
	rep0(i,n){
		rep0(j,(1<<(i+1)))rep0(k,n-i)rep0(l,(1<<k))t[k][l<<(i+1)|j]=0;
		rep0(j,(1<<i)){
			rep(k,n-i){
				rep0(l,(1<<k)){
					if(~g[k][l][0])t[g[k][l][0]][(l%(1<<g[k][l][0]))<<(i+1)|(j*2)]+=f[k][l<<i|j];
					if(~g[k][l][1])t[g[k][l][1]][(l%(1<<g[k][l][1]))<<(i+1)|(j*2+1)]+=f[k][l<<i|j];
				}
			}
		}
		rep0(j,(1<<(i+1))){
			int gg=0;
			rep0(k,n-i){
				rep0(l,(1<<k)){
					f[k][l<<(i+1)|j]=t[k][l<<(i+1)|j];
					gg+=f[k][l<<(i+1)|j];
				}
			}
			if(gg>=m)ins(j,i+1);
		}
	}
	print(mi,mx);
	puts("");
	return 0;
}




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

string shuffle(string str,int n){
    int len=str.size();
    string str1=str.substr(0,n);
    string str2=str.substr(n,len-n);
    string str3=str2+str1;
    return str3;
}

int main(){
    string str;
    while(1){
        cin>>str;
        if(str=="-") break;
        int m;
        cin>>m;
        for(int i=0;i<m;i++){
            int h;
            cin>>h;
            str=shuffle(str,h);
        }
        cout<<str<<endl;
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>				//Written by ThiDaiLoc
using namespace std;				//Team Three Wolves
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> trp;
typedef vector<ll> vi;
typedef vector<pll> vp;

#define fu(i,a,b)   for(ll i=a;i<=b;i++)
#define f1(i,n)     for(ll i=1;i<=n;i++)
#define fs(i,s)     for(ll i=0;i+1<=s.length();i++)
#define fd(i,b,a)   for(ll i=b;i>=a;i--)
#define fuv(i,a)    for(ll i=0;i<a.size();i++)
#define fdv(i,a)    for(ll i=(ll)a.size()-1;i>=0;i--)
#define ms(a,x)     memset(a, x, sizeof a)
#define prec(n)     fixed<<setprecision(n)
#define uni(a)      (a).erase(unique(all(a)), (a).end())
#define pb(i)       push_back(i)
#define pob         pop_back()
#define sc(a)       cin>>a
#define sc2(a,b)    cin>>a>>b
#define sc3(a,b,c)  cin>>a>>b>>c
#define pr(a)       cout<<a<<endl
#define pr2(a,b)    cout<<a<<" "<<b<<endl
#define rpr(a)      return cout<<a<<endl,0
#define prY         cout<<"YES"<<endl
#define prN         cout<<"NO"<<endl
#define bit(n,i)    (((n)>>(i))&1)
#define lowb(a,n,x) lower_bound(a,a+n,x) -a
#define lowb2(a,x)  lower_bound(all(a),x) -a.begin()
#define all(x)      (x).begin(), (x).end()
#define sz(a)       (ll)a.size()
#define le(s)       (ll)s.length()		
#define re          return 	
#define	mp(a,b)     make_pair(a,b)
#define	mp3(a,b,c)  make_pair(a,make_pair(b,c))
#define se          second
#define fi          first 
#define sse         second.second
#define sfi         second.first
#define soA         sort(A+1,A+1+n)
#define so(A,n)     sort(A+1,A+1+n)
#define sov(v)      sort(all(v))
#define sovr(v)     sort(all(v),greater<ll>())
#define debug(x)    cerr << #x << " = " << x << endl
#define INPUT       freopen("locin.txt", "r", stdin)
#define OUTPUT      freopen("locout.txt", "w", stdout)
inline ll isqrt(ll k) {ll r = sqrt(k) + 1; while (r * r > k) r--; return r;}
inline ll icbrt(ll k) {ll r = cbrt(k) + 1; while (r * r * r > k) r--; return r;}
inline ll mnz(ll& a,ll b){return a=(a>b?b:a);}
inline ll mxz(ll& a,ll b){return a=(a<b?b:a);}
inline string toString(ll n) {stringstream ss; ss << n;return ss.str();}
double const eps = 1e-6;
ll const Base=1e9+7,oo=1e17,MAXN=1e6;


pll A[MAXN+5];

ll Solves(){
	
	ll n,m,k,cnt=0,ans=0,x,y,q,c,sum=0,v,t;
	// PROCESS IN HERE
	
	cin>>n>>m>>k;
	f1(i,n)sc2(A[i].fi,A[i].se);
	queue<pll> qu;
	soA;
	f1(i,n){
		while(sz(qu) and qu.front().se<A[i].fi){
			sum-=k*qu.front().fi;
			qu.pop();
		}
		c=max(0LL,A[i].se-sum);
		v=(c/k+(c%k!=0));
		qu.push(mp(v,A[i].fi+2*m));
		sum+=k*v;
		ans+=v;
	}
	pr(ans);
	
	
	
	
	
	
	re 0;
	// Hack it if you can :)
}

int main(){
	//INPUT;
	if(fopen("locin.txt", "r"))INPUT;
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll test=1;
//	sc(test);
	fu(T,1,test){
//		cout<<"Case #"<<T<<": ";
		Solves();
	} 		
}

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

using namespace std;

multiset <int> s;
multiset <int> ::reverse_iterator rit;
multiset <int> ::iterator it;

vector <int> v;

main()
{
	int n;
	cin >> n;
	
	int p = (1 << n);
	
	for(int i = 1; i <= p; i++)
	{
		int x;
		cin >> x;
		
		s.insert(-x);
	}
	
	it = s.begin();
	v.push_back(*it);
	
	s.erase(it);
	
	for(int i = 1; i <= n; i++)
	{
		vector <int> t;
		
		for(auto j : v)
		{
			it = s.upper_bound(j);
			
			if(it == s.end())
			{
				cout << "No";
				return 0;
			}
			
			t.push_back(*it);
			s.erase(it);
		}
		
		for(auto j : t)
			v.push_back(j);
		
		sort(v.begin(), v.end());
	}
	
	cout << "Yes";
}

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

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  cin >> n;

  if(n % 10 == 3){
    cout << "bon\n";
  }else if(n % 10 == 0 || n % 10 == 1 || n % 10 == 6 || n % 10 == 8){
    cout << "pon\n";
  }else{
    cout << "hon\n";
  }
  return 0;
}



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

    string s;

    cin >> s;

    int len;

    len = (int)(s.length());

    int ct = 0;

    for(int i=0; i<=len/2-1; i++){
        if(s[i] != s[len-1-i])
            ct += 1;
    }

    cout << ct<< endl; 

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, A):
    A = [-1] + A
    ans = 0
    B = [0] * (N+1)
    ans = []
    for i in range(N, 0, -1):
        s = 0
        for j in range(i, N+1, i):
            s += B[j]
        if s % 2 != A[i]:
            B[i] = 1
            ans.append(i)
    
    print(len(ans))
    if ans:
        print(' '.join(map(str, ans)))


def main():
    N = read_int()
    A = read_int_n()
    slv(N, A)


if __name__ == '__main__':
    main()


Measured memory_bytes: 103148
while true
    an, bn, cn = gets.chomp.split.map{|x| x.to_i}
    exit if [an,bn,cn].uniq == [0]
    n = gets.to_i

    flag = [nil]
    (an + bn + cn).times { flag << 2 }
    arr = []
    n.times do 
        arr << gets.chomp.split.map{|x| x.to_i}
    end
    #p arr
    arr.sort!{ |x,y| x[3]<=>y[3] }.reverse!
    #p arr

    n.times do
    n.times do |i|
        a, b, c, r = arr[i]
        if r==1 then
            flag[a] = flag[b] = flag[c] = 1
        else
            if [flag[a],flag[b],flag[c]].count(1)==2
                fill = 0
            else
                fill = 2
            end
            flag[a] = fill if flag[a]==2
            flag[b] = fill if flag[b]==2
            flag[c] = fill if flag[c]==2
        end
    end
    end

    #p flag
    flag[1..-1].each { |x| puts x }

end

Measured memory_bytes: 7092
#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

int main(){
    ll X;cin>>X;
    bool end = 0;
    for(int i=-200;i<=200&&end!=1;i++){
        for(int j=-200;j<i;j++){
            if(pow(i,5)-pow(j,5)==X){
                cout << i << " " << j << endl;
                end = 1;
                break;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;

    string res = "No";
    if(s.at(2) == s.at(3) && s.at(4) == s.at(5))
    {
        res = "Yes";
    }

    cout << res << endl;
    // cout << fixed << setprecision(10);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){

  int ans = 0;
  string S;  cin >> S;
  for(int i = 0 ; i < 4 ; i++){
    if(S[i] == '+')  ans += 1;
    else             ans -= 1;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V

a#b = abs$a-b

main = do
    [n,k] <- map read.words<$>getLine
    hr <- V.unfoldr(B.readInt.B.dropWhile(<'!'))<$>B.getLine
    print $ f n k hr

inf = 10^18
f n k h=dp V.! (n-1) where
    dp = V.constructN n m
    m v0 | j==0 = 0
         | j<=k = V.foldl' (\a (s,sv)->min a (sv+(h V.! j)#s)) inf $ V.zip h $ V.slice 0 j v0
         | otherwise = V.foldl' (\a (s,sv)->min a (sv+(h V.! j)#s)) inf $ V.zip (V.slice (j-k) k h) $ V.slice (j-k) k v0
        where j = V.length v0


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
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; }
const ll MOD = 1e9+7;


int main(){
    ll N; 
    cin >> N;
    priority_queue<ll> A;
    map<ll, ll> X;
    map<ll, ll> Y;
    REP(i,N){
        ll a;
        cin >> a;
        Y[a]++;
        if(X.find(a) == X.end()){
            X[a] = i;
            A.push(a);
        }
    }

    vector<ll> ANS(N);
    ll num = 0;
    ll idx = 2*N;
    while(!A.empty()){
        ll a = A.top();
        A.pop();
        chmin(idx, X[a]);
        num += Y[a];

        ll diff = 0;
        if(A.empty()){
            diff = a;
        }
        else{
            ll next = A.top();
            diff = a - next;
        }
        ANS[idx] += diff*num;
    }

    for(auto&& ans : ANS){
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 15092
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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;}


struct Edge {
    int to;
    ll cost;
    Edge(int to,ll cost) : to(to),cost(cost){};
};
int n;
vector<vector<Edge>>g;
vector<int>ans;
vector<ll> dist;
void dfs(int v,int p) {
    if(dist[v]%2==0) {
        ans[v] = 0;
    }
    for(auto e: g[v]) {
        if(e.to == p) continue;
        dist[e.to] += dist[v] + e.cost;
        dfs(e.to,v);
    }
}
int main() {
    cin >> n;
    g.resize(n);
    ans.resize(n);
    dist.resize(n);
    rep(i,n) {
        ans[i] = 1;
        dist[i] = 0;
    }
    rep(i,n-1) {
        int u,v;
        ll w;
        cin >> u >> v >> w;
        u--;v--;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    dfs(0,-1);
    rep(i,n) cout << ans[i] << endl;
}

Measured memory_bytes: 13220
from collections import deque

n, k = map(int, input().split())
a = list(map(int, input().split()))
q = deque(a[:k])
plus = cur_plus = min_plus = sum(x for x in q if x > 0)
cur_minus = max_minus = sum(q) - plus
for b in a[k:]:
    c = q.popleft()
    q.append(b)
    if b > 0:
        plus += b
        cur_plus += b
    else:
        cur_minus += b
    if c > 0:
        cur_plus -= c
    else:
        cur_minus -= c
    max_minus = max(max_minus, cur_minus)
    min_plus = min(min_plus, cur_plus)
print(max(plus + max_minus, plus - min_plus))


Measured memory_bytes: 14636
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int main()
{
	LL N, K;
	in >> N >> K;
	std::vector<LL>x(N), y(N);
	rep(i, N) in >> x[i] >> y[i];

	rep(i, N)
	{
		std::map<std::pair<LL, LL>, LL>k;
		rep(j, N)
		{
			if (i == j) continue;
			LL dx = x[i] - x[j], dy = y[i] - y[j];
			if (dx < 0)
			{
				dx *= -1; dy *= -1;
			}
			if (dx != 0 && dy != 0)
			{
				LL g = gcd(std::abs(dx), std::abs(dy));
				dx /= g; dy /= g;
			}
			if (dx == 0) dy /= std::abs(dy);
			if (dy == 0) dx /= std::abs(dx);
			k[std::make_pair(dx, dy)]++;
			if (k[std::make_pair(dx, dy)] == K - 1)
			{
				out << 1 << std::endl;
				return 0;
			}
		}
	}
	out << 0 << std::endl;
}



Measured memory_bytes: 3324
import java.util.*;


public class Main {
    public static void main(String[] args){
        HashMap<Integer, Integer> count = new HashMap<Integer, Integer>();

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        for(int i = 0; i < n; i++){
            int a = sc.nextInt();
            if(count.containsKey(a)){
                count.put(a, count.get(a)+1);
            }else{
                count.put(a, 1);
            }
        }

        int ans = 0;
        for(Integer i : count.keySet()){
            if(i < count.get(i)){
                ans += count.get(i) - i;
            }else if(i > count.get(i)){
                ans += count.get(i);
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 61024
#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++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int ans = 0;
  int cnt = 0;
  rep(i, N) {
    if (S[i] == 'I') {
      cnt++;
    }
    else {
      cnt--;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define S second
#define INF (1e9)
#define N 105
using namespace std;

typedef pair<int,int> P;

int n, m, d[N][N];
int used[N], ans=0;

vector<P> idx;

set<vector<int> > memo;

void dfs(int x,vector<int> G){
  
  if(x>=2){

    int sum=0;

    for(int i=0;i<G.size();i++){
      
      int mincost=INF;
      
      for(int j=0;j<G.size();j++){
      
	if(G[i]!=G[j])
	  mincost=min(mincost,d[G[i]][G[j]]);
      
      }

      if(mincost!=INF) sum+=mincost;
    
    }
  
    ans=max(ans,sum);

  }
  
  sort(G.begin(),G.end());
  
  if(memo.count(G)) return ;
  memo.insert(G);
  
  if(x*(x-1)>m*m) return ;
  
  for(int i=0;i<n;i++){

    if(used[idx[i].S]) continue;

    used[idx[i].S]=1;
    
    int mincost=INF;

    vector<int> nG=G;

    nG.push_back(idx[i].S);
    
    for(int j=0;j<nG.size();j++)
      
      if(idx[i].S!=nG[j]&&used[nG[j]])
	mincost=min(mincost,d[idx[i].S][nG[j]]);
    
    if(!x||(mincost&&mincost!=INF)) dfs(x+1,nG);
    
    used[idx[i].S]=0;
    
  }
  
}

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

  int a, b , f;

  for(int i=0;i<n;i++) idx.push_back(P(0,i));
  
  for(int i=0;i<m;i++){
    
    cin>>a>>b>>f;
    
    d[a-1][b-1]=d[b-1][a-1]=f;
    
    idx[a-1].first++;
    idx[b-1].first++;
  }

  sort(idx.begin(),idx.end());
  
  vector<int> init;
  
  dfs(0,init);

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

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

return 0;
}

Measured memory_bytes: 636
A=int(input())
B=int(input())
C=int(input())
X=int(input())
ans=0
for i in range(A+1):
  for j in range(B+1):
    for k in range(C+1):
      if X== 500*i+100*j+50*k:
        ans+=1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF 1e18
#define INF 1e9
using namespace std;

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

    rep(i,a,b+1){
        if(i % k == 0){
            cout << "OK" << endl;
            return 0;
        }
    }
    cout << "NG" << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <cstdio>

int main()
{
	int d[5] = {0};
	for (int i = 1; i <= 3; ++i)
	{
		int a, b; scanf("%d%d", &a, &b); ++d[a]; ++d[b];
	}
	int num = 0;
	for (int i = 1; i <= 4; ++i) num += (d[i] % 2 != 0);
	puts(num <= 2 ? "YES" : "NO");
	return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        long x = long.Parse(Console.ReadLine());

        long m = 100;
        long ans = 0;

        while (true)
        {
            long tmp = (long)(m * 0.01d);
            m = m + tmp;
            ans++;
            if (m >= x) break;
        }

        Console.WriteLine(ans);
    }

}

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

int N;
vector<vector<ll>> dp;
vector<ll> a;
vector<ll> Sa;

ll solve(int n, int m){
    if(dp[n][m] != -1) return dp[n][m];
    if(n==m) {
        dp[n][m] = 0;
        // cout << n << " " << m << " " << dp[n][m] << endl;
        return dp[n][m];
    }
    if(n+1==m) {
        dp[n][m] = a[n] + a[m];
        // cout << n << " " << m << " " << dp[n][m] << endl;
        return dp[n][m];
    }

    dp[n][m] = 1e18;
    for(int i=n+1; i<=m; i++){
        dp[n][m] = min(dp[n][m], solve(n,i-1) + solve(i,m) + Sa[m] - Sa[n-1]);
    }
    // cout << n << " " << m << " " << dp[n][m] << endl;
    return dp[n][m];
}

int main(){
    cin >> N;
    a.resize(N+1,0);
    Sa.resize(N+1,0);
    for(int i=1; i<=N; i++){
        cin >> a[i];
        Sa[i] = Sa[i-1] + a[i];
    }

    dp.resize(N+1, vector<ll>(N+1,-1));
    cout << solve(1,N) << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()
#define int long long

const int maxn = 5e5 + 1;

using namespace std;

int n;
string s;

int ds(int x) {
    int ans = 0;
    while (x) {
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int ans = 1e18;
    for (int a = 1; a < n; a++) {
        int b = n - a;
        ans = min(ans, ds(a) + ds(b));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<string>


int main() {

	int a, b, c;
	std::cin >> a >> b >> c;
	int ans = 0;
	int na, nb, nc;
	for (int i = 0; i < 1000000; i++) {
		if (a % 2 == 0 && b % 2 == 0 && c % 2 == 0) {
			na = b / 2 + c / 2;
			nb = a / 2 + c / 2;
			nc = a / 2 + b / 2;
			a = na;
			b = nb;
			c = nc;
			ans++;
		}
		else {
			break;
		}
		if (i == 1000000 - 1) {
			ans = -1;
		}
	}
	
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
A += [0]

s = 0
for i in range(N):
    if A[i + 1] - A[i] == 1:
        s += C[A[i] - 1]
    else:
        continue

print(s + sum(B))

Measured memory_bytes: 3064