akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <climits>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <random>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e15
#define _INFLL (long long)-1e15
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> P;

/*******************************************************/

//solve x, y s.t. mx+ny=gcd(m,n)
class Extended_Euclid {
private:
	ll m, n;
	vvll mx_multiply(vvll mx1, vvll mx2) {
		vvll ret(mx1.size(), vll(mx2[0].size(), 0));
		Loop(i, mx1.size()) {
			Loop(j, mx1[0].size()) {
				Loop(k, mx2[0].size()) {
					ret[i][j] += mx1[i][k] * mx2[k][j];
				}
			}
		}
		return ret;
	}
public:
	ll x, y, gcd;
	Extended_Euclid(ll M, ll N) {
		m = M;
		n = N;
		vll r(100), k(100);
		bool swapflag = false, m_negflag = false, n_negflag = false;
		if (m < n) { swap(m, n); swapflag = true; }
		if (m < 0) { m *= -1; m_negflag = true; }
		if (n < 0) { n *= -1; n_negflag = true; }
		r[0] = m;
		r[1] = n;
		int h = 1;
		while (1) {
			k[h - 1] = r[h - 1] / r[h];
			r[h + 1] = r[h - 1] % r[h];
			if (r[h + 1] == 0) break;
			h++;
		}
		gcd = r[h];
		vvll mx1 = { {0, 1}, {1, (-1) * k[h - 1]} };
		Loopr(i, h - 1) {
			vvll mx2 = { { 0, 1 },{ 1, (-1) * k[i] } };
			mx1 = mx_multiply(mx1, mx2);
		}
		x = mx1[0][0];
		y = mx1[0][1];
		if (n_negflag) { n *= -1; y *= -1; }
		if (m_negflag) { m *= -1; x *= -1; }
		if (swapflag) { swap(m, n); swap(x, y); }
	}
};

//A[x] = x! O(x)
vll mod_factlist(ll x, ll mod) {
	if (x < 0) return{};
	else {
		vll ret((int)x + 1);
		ret[0] = 1;
		Loop1(i, (int)x) ret[i] = ret[i - 1] * i % mod;
		return ret;
	}
}

//x^y O(log y)
ll mod_pow(ll x, ll y, ll mod) {
	if (y == 1) return x;
	else {
		ll ans = mod_pow(x, y / 2, mod);
		ans = ans * ans % mod;
		if (y % 2 == 1) ans = ans * x % mod;
		return ans;
	}
}

//???1/x O(log x)
ll mod_inv(ll x, ll mod) {
	Extended_Euclid ee(x, mod * (-1));
	ll ret = ee.x;
	if (ret < 0) ret += (ret / mod*(-1) + 1) * mod;
	return ret;
}

int main() {
	ll a, b; cin >> a >> b;
	Extended_Euclid ee(a, b);
	cout << ee.x << " " << ee.y << endl;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
  cin>>n;
  int a[101];
  set<int> s;
  int flag=1;
  
  for (int i=0;i<n;i++)
    cin>>a[i];
  int sum=0;
  sum=accumulate(a,a+n,sum);
  int sum1=sum;
  for(int i=0;i<n-1;i++)
  { if(!(abs(2*accumulate(a,a+1+i,0)-sum)))
    {cout<<0;flag=0;break;
     
    }
    else 
      s.insert((abs(2*accumulate(a,a+1+i,0)-sum)));
     
  
  
  
  }
  if(flag==1)
  {auto it=s.begin();
  cout<<*it;
  }
 
return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Long A = sc.nextLong(); 
    Long B = sc.nextLong(); 
    Long C = sc.nextLong(); 
    Long D = sc.nextLong(); 

    Long BC =B/C;
    Long BD =B/D;
    Long BCD = B/(C*D/syori(C,D));
    Long B_ans = B + BCD - BC - BD;

    Long AC =(A-1)/C;
    Long AD =(A-1)/D;
    Long ACD = (A-1)/(C*D/syori(C,D));
    Long A_ans = A -1 + ACD - AC - AD;
    System.out.println(B_ans - A_ans);
  
  }

  public static Long syori(Long C, Long D){
    if(C>=D){
      if(C%D==0){ 
        return D;
      }else{
        return syori(D,C%D);
      }
    }else{
      if(D%C==0){ 
        return C;
      }else{
        return syori(C,D%C);
      }
    }
  }

  
}



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

int main() {
  int N;
  int a[110];
  cin >> N;
  for (int i = 0; i < N; i++) cin >> a[i];

  sort(a, a + N, greater<int>());
  int Alice = 0;
  int Bob = 0;
  for (int i = 0; i < N; i++) {
    if (i % 2 == 0) {
      Alice += a[i];
    } else {
      Bob += a[i];
    }
  }
  cout << Alice - Bob << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

 int isPrime(int x){
                     int i;

                     if(x<2)return 0;
                     else if(x==2)return 1;
                     if(x%2==0)return 0;
                     for(i=3;i*i<=x;i+=2){
                                         if(x%i==0)return 0;
                                          }
                     return 1;
                     }


 int main(){
            int n,i,x,num=0;
            scanf("%d",&n);
            for(i=0;i<n;i++){
                             scanf("%d",&x);
                             num=num+isPrime(x);
                             }
            printf("%d\n",num);
            return 0;
            }




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

int main() {
  int k, a, b;
  cin >> k >> a >> b;
  bool res = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0) {
      res = true;
    }
  }
  if (res) {
    cout << "OK" << endl;
  }
  else {
    cout << "NG" << endl;
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
int qmin(int a, int b){
	return (a < b) ? a : b;
}

int n;
char s[500500]; 
int Z[2][500500];
bool nok[500500];

void Zalgo(int dir){
	int l = 0, r = 0;
	Z[dir][0] = n;
	for(int i = 1; i < n; i++){
		if(i <= r) Z[dir][i] = qmin(Z[dir][i-l], r-i+1);
		while(i + Z[dir][i] < n && s[i + Z[dir][i]] == s[Z[dir][i]]) Z[dir][i]++;
		if(i+Z[dir][i]-1 > r){
			l = i;
			r = i+Z[dir][i]-1;
		}
	}
}

int main(){
	scanf("%s", s);
	n = strlen(s);
	bool all_same = 1;
	rep(i, n){
		if(s[i] != s[0]) all_same = 0;
	}
	if(all_same){
		cout << n << endl << "1" << endl;
		return 0;
	}
	Zalgo(0);
	for(int i = 0; i + i < n; i++){
		swap(s[i], s[n-i-1]); 
	}
	Zalgo(1);
	for(int i = 1; i <= n; i++){
		for(int j = 2; i*j <= n; j++){
			if(Z[0][i*(j-1)] >= i){
				nok[i*j] = 1;
			} else break;
		} 
		for(int j = 2; i*j <= n; j++){
			if(Z[1][i*(j-1)] >= i){
				nok[n - i*j] = 1;
			} else break;
		}
	}
	if(!nok[n]){
		cout << "1" << endl << "1" << endl; 
	} else {
		int cnt = 0;
		for(int i = 1; i < n; i++){
			if(!nok[i]) cnt++;
		}
		cout << "2" << endl << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const ll INF = ll(1e9);
ll dist[101][101];
bool ex[1001];
ll we[1001];
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,m; cin>>n>>m;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= n; j++)
		{
			dist[i][j]=INF;
			if(i==j) dist[i][j]=0;
		}
	}
	vector<ii> vec;
	for(int i = 0; i < m; i++)
	{
		int u, v; cin>>u>>v;
		int w; cin>>w;
		vec.pb(mp(u,v));
		we[i]=w;
		dist[u][v]=dist[v][u]=w;
	}
	for(int k = 1; k <= n; k++)
	{
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= n; j++)
			{
				dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
			}
		}
	}
	
	for(int i = 0; i < vec.size(); i++)
	{
		int u = vec[i].fi; int v = vec[i].se;
		int w = we[i];
		for(int j = 1; j <= n; j++)
		{
			for(int k = j + 1; k <= n; k++)
			{
				if((dist[j][u]+dist[v][k]+w==dist[j][k])||(dist[j][v]+dist[u][k]+w==dist[j][k]))
				{
					ex[i]=1;
				}
			}
		}
	}
	int ans = 0;
	for(int i = 0; i < m; i++)
	{
		if(!ex[i]) ans++;
	}
	cout<<ans<<'\n';
}


Measured memory_bytes: 384
#include <iostream>
  
using namespace std;
 
long long n,s,dp[11][1001];
int main(void){
   
  dp[0][0] = 1;
   
  for(int i=0;i<101;i++)
    for(int j=9;j>=0;j--)
      for(int k=0;i+k<1001;k++)
        dp[j+1][k+i]+=dp[j][k];

  while(cin >> n >> s, n|s)
    cout << dp[n][s] << endl;

  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++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; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(void){
    cout.tie(0);
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll a,b,k;
    cin >> a >> b >> k;
    rep(i,k){
      if(i % 2 == 0){
        if(a % 2 != 0){
          --a;
          b += a / 2;
          a /= 2;
        }else{
          b += a / 2;
          a /= 2;
        }
      }else{
        if(b % 2 != 0){
          --b;
          a += b / 2;
          b /= 2;
        }else{
          a += b / 2;
          b /= 2;
        }
      }
    }
    cout << a << " " << b << endl;
}

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


int main(void) {
    using namespace std;

    long h, w, n;
    cin >> h >> w >> n;

    long sr, sc;
    cin >> sr >> sc;
    sr--, sc--;

    string s, t;
    cin >> s;
    cin >> t;

    long hma=h-1, wma=w-1, hmi=0, wmi=0;

    for(int i=n-1; i>=0; i--) {
        switch(t[i]) {
            case 'L':
                wma++;
                break;
            case 'R':
                wmi--;
                break;
            case 'U':
                hma++;
                break;
            case 'D':
                hmi--;
                break;
            default:
                assert(false);
        }
        wma = min(wma, w-1), hma = min(hma, h-1);
        wmi = max(0l, wmi), hmi = max(0l, hmi);

        switch(s[i]) {
            case 'L':
                wmi++;
                break;
            case 'R':
                wma--;
                break;
            case 'U':
                hmi++;
                break;
            case 'D':
                hma--;
                break;
            default:
                assert(false);
        }
        if(!(wmi <= wma && hmi <= hma)) {
            cout << "NO" << endl;
            return 0;
        }
        wma = max(0l, wma), hma = max(0l, hma);
        wmi = min(wmi, w-1), hmi = min(hmi, h-1);
    }

    if(wmi <= sc && sc <= wma && hmi <= sr && sr <= hma) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 776
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#define ordered_set tree<pair<int,int>, null_type,less<pair<int,int>>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
#define int long long int
//#define ll long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;
#define deb1a(v) cout << #v << "--->" << endl; for (auto it : v)  cout << it << " "; cout << endl;
#define deb2a(v) cout << #v << "--->" << endl;for (auto it:v){for(auto it1 : it){cout << it1 << " ";}cout<< endl;}
#define deb3a(v) cout << #v << "-->" << endl; for(auto it:v){cout << it.fi << " " << it.se << endl;}
#define mod 998244353
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
#define db1(x) cout<<#x<<"="<<x<<endl
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}
// vector<vector<int>> dir = {{1, 0}, {-1, 0}, {0, 1}, {0, -1},{1,1},{1,-1},{-1,1},{-1,-1}};
#define double long double

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int t;
    if(h1==h2){
        t = m2 - m1;
    }
    else{
        t = 60 - m1 + m2;
        t += 60 * (h2 - (h1 + 1));
    }
    cout << max((int)0, t - k);
}


Measured memory_bytes: 3652
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout

	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
		if len(os.Args) > 2 {
			wfp, _ = os.Create(os.Args[2])
		}
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)

	n := getNextInt(scanner)
	k := getNextInt64(scanner)

	aa := make([]int, n)
	ff := make([]int, n)

	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		ff[i] = getNextInt(scanner)
	}

	sort.Ints(aa)
	sort.Ints(ff)
	foods := make([]Food, n)
	for i := 0; i < n; i++ {
		foods[i].a = aa[i]
		foods[i].f = ff[n-1-i]
		foods[i].sum = int64(foods[i].a) * int64(foods[i].f)
	}
	l := int64(0)
	r := int64(1e18)

	for l < r {
		sum := int64(0)
		m := (l + r) >> 1
		for i := 0; i < n; i++ {
			if foods[i].sum <= m {
				continue
			}
			sum += int64(foods[i].a) - m/int64(foods[i].f)
		}
		if sum <= k {
			r = m
			continue
		}
		l = m + 1
	}

	fmt.Fprintln(writer, r)

	writer.Flush()
}

type Food struct {
	a, f int
	sum  int64
}


Measured memory_bytes: 12160
function Main(input){
var S = input.split("");
var n = 1;
for(i=0;i<=(S.length-2);i++){
  var comp = S[i]===S[i+1];
  if(comp === true){
    n = 0;
    console.log("Bad");
    break;
  }
}
if(n === 1){
  console.log("Good");
}
}
  Main(require('fs').readFileSync('/dev/stdin','utf8'));

Measured memory_bytes: 7372
module Main (main) where

import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  putStrLn $ pretty $ solve n

type Input  = (Int)
type Output = Bool

solve :: Input -> Output
solve = any (=='9') . show

pretty :: Bool -> String
pretty = toYesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

toYesNo :: Bool -> String
toYesNo b = if b then "Yes" else "No"

Measured memory_bytes: 380
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    C=[list(map(int,input().split())) for _ in range(3)]

    if(not (C[1][0]-C[0][0]==C[1][1]-C[0][1]==C[1][2]-C[0][2])):
        print("No")
        return
    if(not (C[2][0]-C[1][0]==C[2][1]-C[1][1]==C[2][2]-C[1][2])):
        print("No")
        return
    if(not (C[0][0]-C[2][0]==C[0][1]-C[2][1]==C[0][2]-C[2][2])):
        print("No")
        return
    if(not (C[0][1]-C[0][0]==C[1][1]-C[1][0]==C[2][1]-C[2][0])):
        print("No")
        return
    if(not (C[0][2]-C[0][1]==C[1][2]-C[1][1]==C[2][2]-C[2][1])):
        print("No")
        return
    if(not (C[0][0]-C[0][2]==C[1][0]-C[1][2]==C[2][0]-C[2][2])):
        print("No")
        return
    print("Yes")
resolve()

Measured memory_bytes: 38384
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))

int main(void){
    int sx,sy,tx,ty;
    scanf("%d%d%d%d",&sx,&sy,&tx,&ty);

    for(int i=sy;i<ty;i++) printf("U");
    for(int i=sx;i<tx;i++) printf("R");
    for(int i=ty;i>sy;i--) printf("D");
    for(int i=tx;i>sx;i--) printf("L");

    printf("L");
    for(int i=sy;i<ty+1;i++) printf("U");
    for(int i=sx;i<tx+1;i++) printf("R");
    printf("DR");
    for(int i=ty;i>sy-1;i--) printf("D");
    for(int i=tx;i>sx-1;i--) printf("L");
    printf("U\n");

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = -INT_MAX;
int main() {
	cin >> A >> B;
	ans = max(A + B, A - B);
	ans = max(ans, A*B);
	cout << ans << endl;
}

Measured memory_bytes: 256
def calc():
    i_list = input().split()
    r = int(i_list[0])
    d = int(i_list[1])
    x2000 = int(i_list[2])

    x_last = x2000

    for i in range(1,11):
        x_next = x_last * r - d
        print(x_next)
        x_last = x_next

    return


if __name__ == '__main__':
    calc()


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

int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	int x = a > c ? a : c;
	int y = b < d ? b : d;
	if (y - x > 0)
		printf("%d\n", y - x);
	else
		printf("0\n");
	return 0;
}

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

int main() {
  int N, M, R;
  cin >> N >> M >> R;

  vector<int> r(R);
  for(auto& i: r) cin >> i, --i;

  vector<vector<int>> c(N, vector<int>(N, 1e9));
  for(auto i=0; i<N; ++i) c[i][i] = 0;
  for(auto i=0; i<M; ++i) {
    int A, B, C;
    cin >> A >> B >> C;
    --A; --B;
    c[A][B] = c[B][A] = C;
  }
  for(auto k=0; k<N; ++k) for(auto i=0; i<N; ++i) for(auto j=0; j<N; ++j) c[i][j] = min(c[i][j], c[i][k]+c[k][j]);

  int res = 1e9;
  sort(begin(r), end(r));
  do {
    auto sum = 0;
    for(auto i=1; i<R; ++i) sum += c[r[i-1]][r[i]];
    res = min(res, sum);
  } while(next_permutation(begin(r), end(r)));
  cout << res << endl;
}


Measured memory_bytes: 384
using System;

namespace AtCoder_20190705
{
    class Program
    {
        static int Solve()
        {
            int money = int.Parse(Console.ReadLine());
            int balance = money - int.Parse(Console.ReadLine());
            int someCake = int.Parse(Console.ReadLine());
            while (balance >= someCake)
            {
                balance -= someCake;                
            }
            if (true)
            {

            }
            return balance;
        }
        static void Main(string[] args)
        {
            Console.WriteLine(Solve());
        }
    }
}


Measured memory_bytes: 11092
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={-1,-1,-1,0,0,1,1,1};
vl dy={1,-1,0,1,-1,1,0,-1};
vvl G(114514);
vl flag(114514);
vl dp(114514);
ll dfs(ll now,ll pr){
    if(flag[now])return dp[now];
    flag[now]=1;
    vl res;
    for(auto to:G[now]){
        if(to==pr)continue;
        res.push_back(dfs(to,now));
    }
    if(res.size()==0)return dp[now]=0;
    ll fan=0;
    sort(res.begin(),res.end());
    reverse(res.begin(),res.end());
    rep(i,res.size())fan=max(fan,res[i]+i+1);
    return dp[now]=fan;
}
int main(){
    ll n;cin>>n;
    for(ll i=1;i<n;i++){
        ll a;cin>>a;a--;
        G[a].push_back(i);
    }
    cout<<dfs(0,-1)<<endl;
}



Measured memory_bytes: 17280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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

	
	int N, K;
	cin >> N >> K;

	if (K > (N - 1) * (N - 2) / 2) co("-1");
	else {
		K = (N - 1) * (N - 2) / 2 - K;

		vector<int> A, B;
		int kei = N - 1 + K;
		for (int i = 2; i <= N; i++) {
			for (int j = i + 1; j <= N; j++) {
				if (K) {
					A.pb(i);
					B.pb(j);
					K--;
				}
			}
		}

		co(kei);
		rep1(i, N - 1) {
			cosp(1);
			co(i + 1);
		}
		rep(i, A.size()) {
			cosp(A[i]);
			co(B[i]);
		}
	}


	Would you please return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;

#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPE(i,a,n) for(int i=a;i<=n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define SRTVG(v) sort(v.begin(),v.end(),greater<>())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}
template<class T> void YesNo(T& a) {if(a){cout << "Yes" << ENT;}else{cout << "No" << ENT;}}
template<class T> void YESNO(T& a) {if(a){cout << "YES" << ENT;}else{cout << "NO" << ENT;}}
template<class T,class U> void cinn(T& n,U a) {REP(i,0,n) cin >> a[i];}


int atcoder(){
    //入力
    ll n;
    cin >> n;
    ll ans = 0;
    
    REP(i,1,n+1){
        ans += i;
    }
    
    cout << ans;
    
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define REPS(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
using ll = long long;
using ld = long double;

int main(void) {
    string S;
    cin >> S;

    int size = S.size();
    // 回文判定
    string S_reverse = S;
    reverse(S_reverse.begin(), S_reverse.end());
    bool ok = true;
    REP (i, size) {
        if (S.at(i) != S_reverse.at(i)) {
            ok = false;
        }
    }
    // 1文字目から(size-1)/2文字目の回文判定
    string tmp, tmp_reverse;
    tmp = tmp_reverse = S.substr(0, (size-1)/2);
    reverse(tmp_reverse.begin(), tmp_reverse.end());
    for (int i = 0; i < (size-1)/2; i++) {
        if (tmp.at(i) != tmp_reverse.at(i)) {
            ok = false;
        }
    }
    // (size+3)/2文字目からN文字目の回文判定
    tmp = tmp_reverse = S.substr((size+3)/2-1, (size-1)/2);
    reverse(tmp_reverse.begin(), tmp_reverse.end());
    for (int i = 0; i < (size-1)/2; i++) {
        if (tmp.at(i) != tmp_reverse.at(i)) {
            ok = false;
        }
    }
    if (ok) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 2123
char s[N];
vector<int> g[N];
map<int, ll> x[N], y[N], z[N]; // sum, count, min

void dp(int a, int p){
	if(x[a].find(p) != x[a].end()) return;
	ll xx = 0, yy = s[a];
	for(int i : g[a]){
		if(i == p) continue;
		dp(i, a);
		xx += x[i][a] + y[i][a];
		yy += y[i][a];
	}
	ll zz = xx%2;
	for(int i : g[a]){
		if(i == p) continue;
		LAR(zz,  z[i][a]+y[i][a]-(xx-(x[i][a]+y[i][a])));
	}
	x[a][p] = xx;
	y[a][p] = yy;
	z[a][p] = zz;
	DEBUG("%d -> %d: sum=%lld, count=%lld, min=%lld\n", p+1, a+1, xx, yy, zz);
}

int main(){
	int n; scanf("%d%s", &n, s);
	REP(i, n) s[i]-='0';
	REP(i, n-1){
		int a, b; scanf("%d%d", &a, &b); a--; b--;
		g[a].EB(b);
		g[b].EB(a);
	}
	ll ans = LLONG_MAX;
	REP(i, n){
		dp(i, -1);
		if(z[i][-1]==0) SML(ans, x[i][-1]/2);
	}
	if(ans==LLONG_MAX) ans = -1;
	printf("%lld\n", ans);
}


Measured memory_bytes: 2048
object Main extends App {

  import scala.io.StdIn._

  val Array(a, b, c) = readLine.trim.split(' ').map(_.toInt)
  println(a * b / 2)
  implicit class Extension[T](val value :T) extends AnyVal {
    @inline
    def let[A](@inline func: T ⇒ A): A = func(value)
    @inline
    def also(@inline func: T ⇒ Unit): T = {func(value); value}
  }
}

Measured memory_bytes: 25424
from collections import deque
n, q = map(int, input().split())
process = deque([tuple(map(str, input().split())) for _ in range(n)])

answer = []
time_count = 0
while process:
    name, time = process.popleft()
    time = int(time)

    if time - q > 0:
        time_count += q
        process.append((name, time - q))
    else:
        time_count += time
        answer.append((name, time_count))

for process in answer:
    name, time = process
    print(name, time)


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

void YES(bool b) {cout << (b?"YES\n":"NO\n");}
void Yes(bool b) {cout << (b?"Yes\n":"No\n");}
void yes(bool b) {cout << (b?"yes\n":"no\n");}
void Yay(bool b) {cout << (b?"Yay!\n":":(\n");}

long long powmod(long long a,long long b){
    long long c=1;
    while(b>0){
        if(b&1) c=a*c%mod;
        a=a*a%mod;
        b>>=1;
    }
    return c;
}

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

vvll v;
vll ans;

void dfs(ll cur, ll pre=-1){
	for(auto&& next:v[cur]){
		if(next==pre) continue;
		ans[next]+=ans[cur];
		dfs(next,cur);
	}
}

int main()
{
	ll n,q,a,b,p,x;
	cin >> n >> q;
	v.resize(n);
	rep(i,n-1){
		cin >> a >> b;
		a--;
		b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	ans.resize(n);
	rep(i,q){
		cin >> p >> x;
		ans[--p]+=x;
	}
	dfs(0);
	for(auto&& e:ans) cout << e << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 24320
from collections import defaultdict
n, m = map(int, input().split())
cnt = defaultdict(int)
for _ in range(m):
    a, b = map(int, input().split())
    cnt[a] += 1
    cnt[b] += 1

if all(v % 2 == 0 for v in cnt.values()):
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9448
A, B, K = [int(x) for x in input().split()]

fA = set([i for i in range(1, A + 1) if A % i == 0])
fB = set([i for i in range(1, B + 1) if B % i == 0])

f = sorted(list(fA.intersection(fB)))
print(f[-K])


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

int main(){
	int n;
	while(cin >> n, n){
		//n++;
		vector<int> dp(n), vec(n);
		//t[0] = 0;
		/*for(int i = 1;i < n;i++){
			cin >> v[i];
			t[i] = max(t[i-1]+v[i], v[i]);
		}*/
		for(int i=0;i<n;i++)cin >> vec[i];
		dp[0]=vec[0];
		for(int i=1;i<n;i++)dp[i]=max(dp[i-1]+vec[i],vec[i]);
		cout << *max_element(dp.begin(), dp.end()) << endl;
	}
	return 0; 
}

/*
7
-5
-1
6
4
9
-6
-7
*/

Measured memory_bytes: 3104
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 0
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}

	mm := map[int]int{}
	for i := 0; i < 1<<uint(n); i++ {
		sum := 0
		for j := 0; j < n; j++ {
			sum += aa[j] * (i >> uint(j) & 1)
		}
		mm[sum] = 1
	}

	m := getNextInt(scanner)
	for i := 0; i < m; i++ {
		if mm[getNextInt(scanner)] == 1 {
			fmt.Fprintln(writer, "yes")
			continue
		}
		fmt.Fprintln(writer, "no")
	}
}



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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
 
using ll = long long;
const ll INF = 1e18L + 5;
const ll MOD = 1e9 + 7;
const int res = 0;


int main(){
	int n;
	scanf("%d", &n);
	vector<int> dp(3, 0);
	for(int day = 1; day <=n ;++day) {
			vector<int> gains(3);
			for(int i = 0; i < 3; ++i) {
				scanf("%d", &gains[i]);
			}
			vector<int> new_dp(3, 0 );
			for(int i = 0; i < 3; ++i) {
				for(int j = 0; j < 3; ++j) {
					if(i != j) {
						new_dp[i] = max(new_dp[i], dp[j] + gains[j]);
					}
				}
			}
			dp = new_dp;
	}
	printf("%d\n", max({dp[0], dp[1], dp[2]}));
}



Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
char a[105],b[105];
bool cmp1(char a,char b){
return (a<b);

}
bool cmp2(char a,char b){
return (a>b);

}

int main(){
    int i,j;
    cin>>a;cin>>b;
    for(i=0;a[i];i++);
    for(j=0;b[j];j++);
    sort(a,a+i,cmp1);
    sort(b,b+j,cmp2);
    int o,l;if(i>j){o=j;}else{o=i;}
    for(l=0;l<o;l++){
        if(a[l]>b[l]){printf("No");break;}
        if(a[l]<b[l]){printf("Yes");break;}
    }
    if(l==o){
        if(o==j){printf("No");}
        else if(o==i){printf("Yes");}
        else{printf("No");}

    }

return 0;

}


Measured memory_bytes: 256
//abc163A
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int main(void) {
  float n, k, i, cou=0, tmp;
  scanf("%f", &n);
  printf("%f", n * 2*M_PI);
  return 0;
}

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

using namespace std;

const int MAX = 200010 ;
long long a[MAX] , b[MAX] , arra[MAX] , arrb[MAX] ;
int n ;

int leftidx(long long now , long long cur)
{
    int l = 0 , r = n-1 ;
    int ans = n-1 ;
    while(l <= r)
    {
        int mid = (l + r) >> 1 ;
        if(now + arrb[mid] >= cur)
            r = mid-1 , ans = min(ans , mid) ;
        else
            l = mid+1 ;
    }
    return ans ;
}

int rightidx(long long now , long long cur)
{
    int l = 0 , r = n-1 ;
    int ans = 0 ;
    while(l <= r)
    {
        int mid = (l + r) >> 1 ;
        if(now + arrb[mid] <= cur)
            l = mid+1 , ans = max(ans , mid) ;
        else
            r = mid-1 ;
    }
    return ans ;
}

bool check(long long x , long long y)
{
    return (x >= y && x <= y*2-1) ;
}

int main()
{
    cin>>n ;
    for(int i = 0 ; i < n ; ++i)
        cin>>a[i] ;
    for(int i = 0 ; i < n ; ++i)
        cin>>b[i] ;
    long long ans = 0 ;
    for(int i = 0 ; i <= 28 ; ++i)
    {
        long long mod = (1ll << i) * 2 ;
        for(int j = 0 ; j < n ; ++j)
            arra[j] = a[j] % mod , arrb[j] = b[j] % mod ;
        sort(arrb , arrb + n) ;
        int cnt = 0 ;
        for(int j = 0 ; j < n ; ++j)
        {
            int l = leftidx(arra[j] , (1 << i));
            int r = rightidx(arra[j] , (1 << i)*2-1);
            if(check(arra[j] + arrb[l] , (1 << i)) && check(arra[j] + arrb[r] , (1 << i)))
                cnt += r-l+1 ;
            l = leftidx(arra[j] , (1 << i) * 3) ;
            r = rightidx(arra[j] , (1 << i) * 4 - 1) ;
            if(check(arra[j] + arrb[l] , (1 << i)*3) && check(arra[j] + arrb[r] , (1 << i)*3))
                cnt += r-l+1 ;
        }
        if(cnt & 1)
            ans += (1 << i) ;
    }
    return cout<<ans<<"\n" , 0 ;
}


Measured memory_bytes: 6528
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<map>
using namespace std;
typedef long long int ll;
 
ll gcd(ll a, ll b){
    if (b == 0) return a;

    return gcd(b, a % b);
}

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

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

Measured memory_bytes: 3584
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll N,M,b,c,now,ans;
bool flag=true;

int main(){
//     ifstream in("input.txt");
//     cin.rdbuf(in.rdbuf());
    cin>>N>>M;
    ll A[N];
    rep(i,N)cin>>A[i];
    pair<ll,ll> p[M];
    rep(i,M){
        cin>>b>>c;
        p[i]=make_pair(c,b);
    }
    sort(A,A+N);
    sort(p,p+M);
    // rep(i,N){
    //     out(A[i]);
    // }
    // rep(i,M){
    //     printf("%lld %lld\n",p[i].first,p[i].second);
    // }
    for(int i=M-1;i>=0;i--){
        if(!flag)break;
        rep(j,p[i].second){
            if(A[now]<=p[i].first){
                A[now]=p[i].first;
                now++;
            }
            else{
                flag=false;
                break;
            }
        }
    }
    rep(i,N){
        ans+=A[i];
    }
    out(ans);


}


Measured memory_bytes: 2560
n, x = map(int,input().split())
A = list(map(int,input().split()))

class SegTree:
    def __init__(self, init_val, ide_ele, segfunc):
        self.n = len(init_val)
        self.num = 2**(self.n-1).bit_length()
        self.ide_ele = ide_ele
        self.segfunc = segfunc
        self.seg = [ide_ele]*2*self.num
        # set_val
        for i in range(self.n):
            self.seg[i+self.num] = init_val[i]
        # built
        for i in range(self.num-1, 0, -1):
            self.seg[i] = self.segfunc(self.seg[2*i], self.seg[2*i+1])

    def update(self, k, x):
        k += self.num
        self.seg[k] = x
        while k:
            k = k >> 1
            self.seg[k] = self.segfunc(self.seg[2*k], self.seg[2*k+1])

    def query(self, l, r):
        if r <= l:
            return self.ide_ele
        l += self.num
        r += self.num
        res = self.ide_ele
        while l < r:
            if r & 1:
                r -= 1
                res = self.segfunc(res, self.seg[r])
            if l & 1:
                res = self.segfunc(res, self.seg[l])
                l += 1
            l = l >> 1
            r = r >> 1
        return res

seg = SegTree(A, 10**18, min)
ans = 10**18
for k in range(n):
    t = k*x
    for i in range(n):
        if k <= i:
            t += seg.query(i-k, i+1)
        else:
            t += min(seg.query(0, i+1), seg.query(n-(k-i), n))
    ans = min(t, ans)
print(ans)

Measured memory_bytes: 70820
using System;

class Program
{
  static void Main(string[] args)
  {
    string[] input = Console.ReadLine().Split(' ');
    int r = int.Parse(input[0]);
    int g = int.Parse(input[1]);
    int b = int.Parse(input[2]);
    
    if((100 * r + 10 * g + b) % 4 == 0) Console.WriteLine("YES");
    else Console.WriteLine("NO");
  }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
int R;
  cin>>R;
  if(R<1200){
    cout<<"ABC"<<endl;
  }
  else if(1200<=R&&R<2800){
    cout<<"ARC"<<endl;
  }
  
  else if(2800<=R){
    cout<<"AGC"<<endl;
  }
}


Measured memory_bytes: 256
visitor, capacity, limit = map(int, input().split())

visitorList = []

for _ in range(visitor):
    arrivalTime = int(input())
    visitorList.append(arrivalTime)
    
visitorList.sort()
start = visitorList[0]
end = start + limit

count = 0
bus = 1

for j in visitorList:
    if start <= j <= end:
        count += 1
        if count <= capacity:
            continue
        else:
            bus += 1
            start = j
            end = j + limit
            count = 1
    else:
        bus += 1
        start = j
        end = j + limit
        count = 1
        
print(bus)


Measured memory_bytes: 7384
#include <stdio.h>
int main() {
    int a = 0, b = 0, c = 0, y = 0;
    double x = 0;
    //printf("A B C\n");
    scanf("%d%d%d", &a, &b, &c);
    x = b / a * 1.0;
    y = x;
    if(a>b){
        printf("0\n");
    }else{
        if(x>=c){
            printf("%d\n", c);
        }else{
            printf("%d\n", y);
        }
    }
    return 0;
}

Measured memory_bytes: 128
let n = read_int ();;

type unionfind = { size : int array; parent : int array };;
let init_unionfind n = {size = Array.make n 1; parent = Array.init n (fun i -> i)};;
let rec find uf x = (
    if uf.parent.(x) = x then
      x
    else (
      let y = find uf (uf.parent.(x)) in
      uf.parent.(x) <- y;
      y
    )
  );;
let unite uf x y = (
    let x = find uf x in
    let y = find uf y in
    if x <> y then (
      let x, y = if uf.size.(x) > uf.size.(y) then x, y else y, x in
      uf.size.(x) <- uf.size.(x) + uf.size.(y);
      uf.parent.(y) <- x;
    );
  );;

let uf = init_unionfind 200000;;

for i = 0 to n - 1 do
  let x, y = Scanf.scanf " %d %d" (fun x y -> x - 1, y - 1 + 100000) in
  unite uf x y
done

let row = Array.make 200000 0;;
let col = Array.make 200000 0;;

for i = 0 to 99999 do
  let j = find uf i in
  row.(j) <- row.(j) + 1;
done;;

for i = 100000 to 199999 do
  let j = find uf i in
  col.(j) <- col.(j) + 1;
done;;

let ans = ref (-n);;
for i = 0 to 199999 do
  ans := !ans + row.(i) * col.(i);
done;;

Printf.printf "%d\n" !ans;;


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

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int N, A, B;
    io.read(N, A, B);
    cout << min(B, N * A);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N, M;
int A[100010], B[100010];
vector<int> G[100010];
int used[100010];

vector<int> func(int s) {
  vector<int> v{s};
  bool update = true;
  while (update) {
    update = false;
    for (int nxt : G[v.back()]) {
      if (used[nxt]) continue;
      used[nxt] = 1;
      v.emplace_back(nxt);
      update = true;
      break;
    }
  }
  return v;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> A[i] >> B[i];
    A[i]--; B[i]--;
    G[A[i]].emplace_back(B[i]);
    G[B[i]].emplace_back(A[i]);
  }
  used[A[0]] = used[B[0]] = 1;
  vector<int> a = func(A[0]);
  vector<int> b = func(B[0]);
  reverse(a.begin(), a.end());
  cout << a.size() + b.size() << endl;
  for (int i = 0; i < a.size(); i++) {
    cout << a[i] + 1 << " ";
  }
  for (int i = 0; i < b.size(); i++) {
    cout << b[i] + 1 << " \n"[i + 1 == b.size()];
  }

  return 0;
}

Measured memory_bytes: 8056
#include <stdio.h>
int main(){
	long long int N,i,j;
	long long int m=0,a=0,r=0,c=0,h=0;
	char s[100005][15];
	long long int result;
	scanf("%lld",&N);
	
	for(i=0;i<N;i++)
	{
		scanf("%s",s[i]);
		if(s[i][0]=='M')
		{
			m++;
		}else if(s[i][0]=='A')
		{
			a++;
		}else if(s[i][0]=='R')
		{
			r++;
		}else if(s[i][0]=='C')
		{
			c++;
		}else if(s[i][0]=='H')
		{
			h++;
		}
	}
	
	result=m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h;
	printf("%lld",result);
	
	}

Measured memory_bytes: 1664
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <assert.h>
using namespace std;
#define LL long long
#define pii pair < int , int >
#define mp make_pair
#define pb push_back
#define fi first
#define se second

int n;
double A[105];

int main(){

	// ios_base::sync_with_stdio(0);
	// cin.tie(0);
	// cout.tie(0);

	scanf("%d",&n);
	for ( int i = 0; i < n; i++ ){
		scanf("%lf",&A[i]);
	}
	sort(A,A+n);
	double sum = A[0];
	for ( int i = 1; i < n; i++ ) {
		sum = ( sum + A[i] ) / 2.0;
	}
	printf("%.10lf\n",sum);

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define N 500000
#define INFTY 1000000001

int n,count=0;
int L[N],R[N];

void merge(int *,int,int,int);
void mergeSort(int *,int,int);

int main(){
  int i,A[N];
  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf(" %d",&A[i]);
  }
  mergeSort(A,0,n);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1){
      printf(" ");
    }
  }
  printf("\n");
  printf("%d\n",count);

  return 0;
}


void merge(int *A,int l,int m,int r){
  int n1,n2,i,j,k;
  n1=m-l;
  n2=r-m;

  for(i=0;i<n1;i++){
    L[i]=A[l+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[m+i];
  }
  L[n1]=INFTY;
  R[n2]=INFTY;
  i=0;
  j=0;

  for(k=l;k<r;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
    }
    else{
      A[k]=R[j];
      j=j+1;
    }
    count++;
  }
}

void mergeSort(int *A,int l,int r){
  int m;
  if(l+1<r){
    m=(l+r)/2;
    mergeSort(A,l,m);
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }
}



Measured memory_bytes: 5640
#include <iostream>
#include <vector>
#include <cmath>

int b()
{
    std::string a;
    std::cin >> a;
    
    int len = (int)a.length();
    int le = (len - 1) / 2;
    int rs = (len + 3) / 2;
    
    bool isStrong = true;
    for(int i = 0; i < le; i++)
    {
        char c1 = a[i];
        char c2 = a[len - 1 - i];
        char c3 = a[le - 1 - i];
        char c4 = a[rs - 1 + i];
        if(c1 == c2 && c2 == c3 && c3 == c4)
        {
            continue;
        }
        isStrong = false;
    }
    
    if(isStrong)
    {
        std::cout << "Yes";
    }
    else
    {
        std::cout << "No";
    }
    
    return 0;
}

int main(int argc, const char * argv[])
{
    b();
    return 0;
}

Measured memory_bytes: 256
import copy
import sys
import math

def main():
	n = int(input())
	c, s, f = [], [], []
	for _ in range(n-1):
		tmp = list(map(int,input().split()))
		c.append(tmp[0])
		s.append(tmp[1])
		f.append(tmp[2])
	#print(c)
	#print(s)
	#print(f)
	for i in range(n-1):
		currenttime = s[i] + c[i]
		#print('from st.' + str(i))
		for j in range(i+1,n-1):
			#print('current st.'  + str(j))
			#print('reach time: ' + str(currenttime))
			if(currenttime <= s[j]):
				currenttime = c[j] + s[j]
				#print('tokudeparture time: ' + str(c[j] +  s[j]))
			else:
				#print('departure time: ' + str(math.ceil((currenttime - s[j]) / f[j] - 1) * f[j] +  s[j]))
				currenttime = math.ceil((currenttime - s[j]) / f[j]) * f[j] +  s[j] + c[j]
		print(currenttime)
	print(0)

def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

Measured memory_bytes: 42844
from math import factorial

N, M, K = map(int, input().split())
mod = 10 ** 9 + 7

def Comb(N, K):
    a = factorial(N) % mod
    b = factorial(K) % mod
    c = factorial(N-K) % mod
    return (a * pow(b, mod-2, mod) * pow(c, mod-2, mod)) % mod


c = Comb(N*M-2, K-2)

ans = 0

for d in range(M):
    ans += d * (M - d) * (N ** 2)
    ans %= mod

for d in range(N):
    ans += d * (N - d) * (M ** 2)
    ans %= mod

ans *= c
ans %= mod

print(ans)

Measured memory_bytes: 5468