akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
/*
 * 最大公約数を求める
 * ユークリッドの互除法
 * bの方が必ず大きいとする
 */
long long euclid(vector<long long> v){
	int j;
	/*
	 * リストは最初昇順に並んでる
	 * 値が一番小さいもので割り切れるかどうかを試す
	 * 割り切れたら、その要素は削除する
	 * 割り切れない場合、その項を余りに変える
	 */
	while (v.size() > 1) {
		for (size_t i = 1; i < v.size(); i++) {
			v[i] = v[i] % v[0];
		}
		sort(v.begin(), v.end());
		// 割り切れたものは削除
		j = 0;
		while (v[j] == 0) {
			v.erase(v.begin()+j);
		}
	}
	return v[0];
}

int main(int argc, char const *argv[]) {
	int n;
	long long k,temp;
	vector<long long> v;

	cin >> n >> k;

	for (size_t i = 0; i < n; i++) {
		cin >> temp;
		v.push_back(temp);
	}

	// そーと
	sort(v.begin(), v.end());

	// A_1 ~ A_nの最大公約数
	long long x = euclid(v);

	if (k % x != 0 || k > v.back()) {
		cout << "IMPOSSIBLE" << '\n';
	}
	else {
		cout << "POSSIBLE" << '\n';
	}

	return 0;
}


Measured memory_bytes: 1908
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = a[0]
if n%2==0:
    ans += 2*sum(a[1:n//2])
else:
    ans += 2*sum(a[1:(n-1)//2])
    ans += a[(n-1)//2]
print(ans)

Measured memory_bytes: 31444
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

#define MAX_V 120000
#define MAX_E 220000

typedef pair<int, int> P;

int par[MAX_V];
int rnk[MAX_V];

// n要素で初期化
void init(int n){
	for(int i = 0; i < n; i++){
		par[i] = i;
		rnk[i] = 0;
	}
}

// 木の根を求める
int find(int x){
	if(par[x] == x){
		return x;
	}
	return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite(int x, int y){
	int x_par = find(x);
	int y_par = find(y);
	if(x_par == y_par){
		return;
	}
	
	if(rnk[x_par] < rnk[y_par]){
		par[x_par] = y_par;
	}else{
		par[y_par] = x_par;
		if(rnk[x_par] == rnk[y_par]){
			rnk[x_par]++;
		}
	}
}

bool same(int x, int y){
	return (find(x) == find(y));
}

struct edge{
	int u, v, cost;
};

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

edge es[MAX_E];
int V, E;

int kruskal(){
	sort(es, es + E, comp);
	init(V);
	int res = 0;
	for(int i = 0; i < E; i++){
		edge e = es[i];
		if(!same(e.u, e.v)){
			unite(e.u, e.v);
			res += e.cost;
		}
	}
	return res;
}

int main(){
	
	int N;
	
	cin >> N;
	
	vector<P> v1, v2;
	
	for(int i = 0; i < N; i++){
		int x, y;
		cin >> x >> y;
		P p;
		p.first = x;
		p.second = i;
		v1.push_back(p);
		p.first = y;
		v2.push_back(p);
	}
	
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	
	V = N;
	E = 2 * N - 2;
	
	for(int i = 0; i < N - 1; i++){
		es[i].u = v1[i].second;
		es[i].v = v1[i + 1].second;
		es[i].cost = v1[i + 1].first - v1[i].first;
	}
	
	for(int i = 0; i < N - 1; i++){
		es[i + N - 1].u = v2[i].second;
		es[i + N - 1].v = v2[i + 1].second;
		es[i + N - 1].cost = v2[i + 1].first - v2[i].first;
	}
	
	for(int i = 0; i < E; i++){
		//cout << es[i].u << " " << es[i].v << " " << es[i].cost << endl;
	}
	
	int ans = kruskal();
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 5228
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt(),k=s.nextInt(),m=s.nextInt();
		StringJoiner sj=new StringJoiner(" ");
		for(int i=0;i<n;++i)
			sj.add(i<k?""+m:"9999999");
		System.out.println(sj);
	}
}


Measured memory_bytes: 42424
package main

import (
	"fmt"
)

func digit(n int) int {
	c := 0
	for n != 0 {
		n /= 10
		c++
	}
	return c
}

func solve() {
	var n int
	fmt.Scan(&n)

	count := 0
	for i := 1; i <= n; i++ {
		if digit(i)%2 == 1 {
			count++
		}
	}

	fmt.Println(count)
}

func main() {
	solve()
}


Measured memory_bytes: 512
stack = []
for char in input().split():
    if char in ['+', '-', '*']:
        a = int(stack.pop())
        b = int(stack.pop())
        if char == '+':
            stack.append(a + b)
        elif char == '-':
            stack.append(b - a)
        else:
            stack.append(a * b)
    else:
        stack.append(char)
print(stack.pop())



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

int main() {
	int n;
	cin >> n;
	int arr[n + 1];
	for(int i = 1; i <= n; i++)
        cin >> arr[i];

    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if((i&1) && ((i&1) == (arr[i]&1)))
            ans++;
    }

    cout << ans << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a[4],b[4],c[5]={};
  int cun=0,cum=0;
  for(int i=1;i<=3;i++){
    cin>>a[i]>>b[i];
    c[a[i]]++;
    c[b[i]]++;
  }
  for(int i=1;i<=4;i++){
    if(c[i]==2){
      cun++;
    }else if(c[i]==1){
      cum++;
    }
  }
  if(cun==2 && cum==2){
    cout<<"YES\n";
  }else{
    cout<<"NO\n";
  }
  return 0;
}

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

using namespace std;

int main() {
  int d, n; cin >> d >> n;
  if(n == 100) {
    int cur = 101;
    while(d--) {
      cur *= 100;
    }
    cout << cur << '\n';
    return 0;
  }
  while(d--) n *= 100;
  cout << n << '\n';
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,ans=0 ;
    scanf ("%d",&n) ;
    for (int i=0; i<n; i++) {
        int l,r ;
        scanf ("%d%d",&l,&r) ;
        ans+=r-l+1;
    }
    printf ("%d\n",ans) ;
    return 0 ;    
}

Measured memory_bytes: 128
#include <stdio.h>
int n,mg[105][105];
int d[105];
int t = 0;
int F[105] = {0};
int k = 0;

void visited(int u) {
  int i,j,v;
  t++;  
  d[u] = t;

  for(v=0;v<n;v++) {
    if(mg[u][v] == 1 && d[v] == 0 ) {
      visited(v);
    }
  }
  
  t++;
  F[u] = t;

}

int main() {
  int i,j,k,l,u,fg,t;

  for(i=0;i<n;i++) d[i] = 0;

  scanf("%d",&n);

  for(i=0;i<n+1;i++)
    for(j=0;j<n+1;j++) {
      mg[i][j] = 0;

    }

  for(i=0;i<n;i++){

    scanf("%d %d ",&k,&u);
    for(j=0;j<u;j++) {
      scanf("%d",&fg);
      mg[k -1][fg-1] = 1;
    }
  }
  for(i=0;i<n;i++) {
    if(d[i] == 0) 
    visited (i);
  }
    
  for(i=0;i<n;i++) {
    printf("%d %d %d\n",i+1,d[i],F[i]);
  }
  return 0;

    
    
}




Measured memory_bytes: 2076
# import bisect
# from collections import Counter, defaultdict, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    a, p =list(map(int,ipti().split()))
    p += a*3
    print(p//2)

if __name__ == '__main__':
    main()

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

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

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

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


ll n, k, ans=0;

void solve()
{
    cin >> n >> k;
    while (n>0) {
        n/=k;
        ans++;
    }nout(ans);
}

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

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

main = do
  n <- (read::String->Int) <$> getLine
  ts <- (map (read::String->Int)) . words <$> getLine
  m <- (read::String->Int) <$> getLine
  pxs <- (map ((map (read::String->Int)) . words)) . lines <$> getContents

  forM_ pxs $ \(p:x:[]) ->
    print (sum ts - (ts!!(p-1)) + x)


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

const int N = 200005;

int n;
long long ans = 1E18, a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    for (int i = 1; i < n; i++) {
        ans = min(ans, abs(a[n] - 2 * a[i]));
    }
    cout << ans;
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int main(void)
{
	//変数の宣言
	int n;
	static int v[100010];
	static int even[100010];
	static int odd[100010];
	int i;
	int evenmax;
	int evennumformax;
	int oddmax,oddnumformax;
	int ans;
	//データの読み込み
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		scanf("%d",&v[i]);
	}
	
	for(i=0;i<100000;i++){
		even[i]=0;
		odd[i]=0;
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<n;i=i+2){
		even[v[i]]++;
//		printf("%dを一つカウントeven[%d]=%d\n",v[i],v[i],even[v[i]]);
	}
	for(i=1;i<n;i=i+2){
		odd[v[i]]++;
//		printf("%dを一つカウントeven[%d]=%d\n",v[i],v[i],odd[v[i]]);
	}
//	printf("チェック１\n");
	
	evenmax=0;
	
	for(i=1;i<100001;i++){
		if(evenmax<even[i]){
//			printf("%dが%d回\n",i,even[i]);
			evenmax=even[i];
			evennumformax=i;
		}
	}
	
//	printf("evenmax=%d,evennumformax=%d\n",evenmax,evennumformax);
	
	oddmax=0;
	
	for(i=1;i<100001;i++){
		if(i!=evennumformax){
			if(oddmax<odd[i]){
//				printf("%dが%d回\n",i,odd[i]);
				oddmax=odd[i];
				oddnumformax=i;
			}
		}
	}
	
//	printf("oddmax=%d,oddnumformax=%d\n",oddmax,oddnumformax);
	ans=n-evenmax-oddmax;
//	printf("偶数番目の最頻値は%dで%d回出てきました\n",oddmax,oddnumformax);
	
	
	oddmax=0;
	evenmax=0;
	
	for(i=1;i<100001;i++){
		if(oddmax<odd[i]){
			oddmax=odd[i];
			oddnumformax=i;
		}
	}
	
	for(i=1;i<100001;i++){
		if(i!=oddnumformax){
			if(evenmax<even[i]){
				evenmax=even[i];
				evennumformax=i;
			}
		}
	}
	
	if(ans>n-evenmax-oddmax){
		ans=n-evenmax-oddmax;
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
		printf("%d\n",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 1280
a = input().split()

ans = 0
for i in range(int(a[0])+1):
    i=str(i)
    i.split()
    sum_num=0
    for j in i:
        sum_num+=int(j)
    if sum_num>=int(a[1]) and sum_num<=int(a[2]):
        ans += int(i)

print(ans)

Measured memory_bytes: 3060
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;

/*
 * Union-Find tree
 * header requirement: vector
 */
class UnionFind {
private:
  std::vector<int> disj;
  std::vector<int> rank;
public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
	++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) {
    return root(x) == root(y);
  }
};


vector<pair<ll, PI> > calc(const VL &x, const VL &y) {
  ll tot = 0;
  int n = x.size();
  vector<PL> p(n);
  REP(i, 0, n) {
    p[i] = PL(x[i], i);
  }
  sort(p.begin(), p.end());
  vector<pair<ll, PI> > pool;
  REP(i, 0, n - 1) {
    int u = p[i].second;
    int v = p[i + 1].second;
    ll dist = min(abs(x[u] - x[v]), abs(y[u] - y[v]));
    pool.push_back(make_pair(dist, PI(u, v)));
  }
  return pool;
}

int main(void){
  int n;
  cin >> n;
  VL x(n), y(n);
  REP(i, 0, n) {
    cin >> x[i] >> y[i];
  }
  vector<pair<ll, PI> > pool = calc(x, y);
  {
    vector<pair<ll, PI> > pool2 = calc(y, x);
    REP(i, 0, pool2.size()) {
      pool.push_back(pool2[i]);
    }
  }
  sort(pool.begin(), pool.end());
  UnionFind uf(n);
  ll tot = 0;
  REP(i, 0, pool.size()) {
    pair<ll, PI> t = pool[i];
    int u = t.second.first;
    int v = t.second.second;
    if (uf.is_same_set(u, v)) {
      continue;
    }
    uf.unite(u, v);
    tot += t.first;
  }
  cout << tot << endl;
}


Measured memory_bytes: 9656
#include <stdio.h>

int combination(int n, int r)
{
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1) + combination(n - 1, r));
}
int main(void) {
    int n,m;
    scanf("%d %d",&n,&m);
    if(n>1&&m>1){
        printf("%d",combination(n,2)+combination(m,2));
    }
    else if(n<2&&m>1){
        printf("%d",combination(m,2));
    }
    else if(n>1&&m<2){
        printf("%d",combination(n,2));
    }
    else{
        printf("0");
    }

    return 0;
}

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

/*
long long fib(long long n){
    if(memo[n] != -1) return memo[n];
    else if(n == 0 || n == 1) return memo[n] = 1;
    else return memo[n] = fib(n - 1) + fib(n - 2);
}
*/

int main(){
    int n;
    cin >> n;
    vector<long long> memo(n + 1);
    memo[0] = 1;
    memo[1] = 1;
    for(int i = 2; i <= n; i++){
        memo[i] = memo[i - 1] + memo[i - 2];
    }
    cout << memo[n] << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, M;
cin >> N >> M;  
int A[N][M] = {0};
int B[M][1] = {0}; 
int C[N][1] = {0}; 

for (int i = 0; i < N; i++){
  for (int j = 0; j < M; j++){
cin >> A[i][j]; 
}
}
for (int j = 0; j < M; j++){
cin >> B[j][0]; 
}
for(int i = 0; i < N; i++){
  int S = 0; 
  for(int j = 0; j < M; j++){
    S += A[i][j] * B[j][0]; 
}
  C[i][0] = S; 
}
for(int i = 0; i < N; i++){
  cout << C[i][0] << endl; 
}
}


Measured memory_bytes: 3148
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;

int n, m, g[MAXN][MAXN], h[MAXN], s[MAXN], top;
char str[MAXN];

int main(){
	int i, j, ans;
	scanf("%d%d", &n, &m);
	for(i = 1; i <= n; ++ i){
		scanf("%s", str + 1);
		for(j = 1; j <= m; ++ j)
			g[i][j] = int(str[j] == '#');
	} ans = max(n, m);
	for(i = 1; i < n; ++ i){
		for(j = 1, top = 0; j < m; ++ j){
			if(g[i][j] ^ g[i][j + 1] ^ g[i + 1][j] ^ g[i + 1][j + 1]) h[j] = 0;
			else ++ h[j];
			while(top && h[j] <= h[s[top]]){
				ans = max(ans, (j - s[top - 1]) * (h[s[top]] + 1));
				-- top;
			} s[++ top] = j;
		}
		for(; top; -- top)
			ans = max(ans, (m - s[top - 1]) * (h[s[top]] + 1));
	}
	printf("%d\n", ans);
	return 0;
}

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

int main(){
	int x;
	cin >> x;
	vector<int> d(x+1);
	if (x<100) {cout << '0'; return 0;}
	if (x<106) {cout << '1'; return 0;}
	for(int i = 0; i< 100;i++) d[i]=0;
	d[100] = d[101] = d[102] = d[103] = d[104] = d[105] = 1;
	for (int i = 106; i < x+1; i++){
		d[i] = (d[i-100] || 
				d[i-101] ||
				d[i-102] || 
				d[i-103] || 
				d[i-104] || 
				d[i-105]);
		}
	d[x] ? cout << '1' : cout << '0';  
	
	
 }


Measured memory_bytes: 764
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

ans = 10 ** 18


def calc(flag):
    total = 0
    count = 0
    for a in A:
        if flag:
            if total + a > 0:
                total += a
            else:
                count += 1 - (total + a)
                total = 1
            flag = False
        else:
            if total + a < 0:
                total += a
            else:
                count += (total + a) - (-1)
                total = -1
            flag = True
    return count

print (min(calc(True), calc(False)))


            

Measured memory_bytes: 14340
import sys
input = sys.stdin.readline
n,p=map(int,input().split())
s=input()
ans=0

if p == 2 or p == 5:
  for i in range(n):
    if int(s[i]) % p == 0:
        ans += i + 1
  print(ans)
  exit()
    
total=[0]*p#pで割った余りで分類
total[0]=1#t[0]=0の分をあらかじめカウント
t=[0]*(n+1)#s[i:n]を格納する用の配列
for i in range(n-1,-1,-1):
    t[i]=t[i+1]+int(s[i])*pow(10,n-1-i,p)#s[i:n]を漸化式で付け加えていく
    total[t[i]%p]+=1
    
for i in range(p):
    ans+=total[i]*(total[i]-1)//2
print(ans)

Measured memory_bytes: 75424
import java.util.*;
public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();
        for (int i=0;i<10;i++){
            x = r*x-D;
            System.out.println(x);
        }
        sc.close();
    }
}

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

int main() {
	int64_t n, m;
	cin >> n >> m;
	int64_t x[n], y[m], mod = 1e9 + 7;
	for (auto &i : x) {
		cin >> i;
	}
	for (auto &i : y) {
		cin >> i;
	}
	int64_t a = 0, b = 0;
	for (int64_t i = 0; i < n; i++) {
		(a += x[i] * (i - (n - i - 1))) %= mod;
	}
	for (int64_t i = 0; i < m; i++) {
		(b += y[i] * (i - (m - i - 1))) %= mod;
	}
	cout << a * b % mod << endl;
	return 0;
}

Measured memory_bytes: 1792
n,m = map(int,input().split())
lists = []
L = []
R = []
for i in range(m):
    l,r = map(int,input().split())
    L.append(l)
    R.append(r)
ll = max(L)
rr = min(R)
ans = len(list(range(ll,rr+1)))
print(ans)

Measured memory_bytes: 12324
#include <bits/stdc++.h>
using namespace std;
int main() {
  int A,B,C;
  cin>>A>>B>>C;
  string S;

  if((A==B)&&(A==C)){
    S="No";
  }else if(A==B){
    S="Yes";
  }else if(A==C){
    S="Yes";
  }else if(B==C){
    S="Yes";
  }else{
    S="No";
  }
  cout<<S<<endl;

}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int h, m, s;

        h = n/3600;
        m = (n-h*3600)/60;
        s = n - (h*3600 + m*60);

        System.out.println(h+":"+m+":"+s);
    }
}

Measured memory_bytes: 26300
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
class lazy_segment_tree{
    private:
        static int calc_size(int n){
            int m = 1;
            while(m < n){
                m *= 2;
            }
            return m;
        }

        void eval(int i, int l, int r){
            if(lazy[i] != 0){
                node[i] += lazy[i];
                if(r - l > 1){
                    lazy[i * 2 + 1] += lazy[i] / 2;
                    lazy[i * 2 + 2] += lazy[i] / 2;
                }
                lazy[i] = 0;
            }
        }

        void add(int s, int t, int x, int i, int l, int r){
            eval(i, l, r);

            if(t <= l || r <= s){
                return ;
            }

            if(s <= l && r <= t){
                lazy[i] += (r - l) * x;
                eval(i, l, r);
                return;
            }

            int m = l + (r - l) / 2;
            add(s, t, x, 2 * i + 1, l, m);
            add(s, t, x, 2 * i + 2, m, r);
            node[i] = node[2 * i + 1] + node[2 * i + 2];
        }

        T query(int s, int t, int i, int l, int r){
            eval(i, l, r);

            if(t <= l || r <= s){
                return 0;
            }

            if(s <= l && r <= t){
                return node[i];
            }

            int m = l + (r - l) / 2;
            T vl = query(s, t, i * 2 + 1, l, m);
            T vr = query(s, t, i * 2 + 2, m, r);
            return vl + vr;
        }

    public:
        int n;
        vector<T> node, lazy;
        T init;
        function<T(T, T)> f;

        lazy_segment_tree(int n, T init, function<T(T, T)> f)
            : n(calc_size(n)), node(calc_size(n) * 2, init) , lazy(calc_size(n) * 2, 0), init(init), f(f) {}

        void update(int i, const T& x){
            node[i + n] = x;
            for(int j = (i + n) / 2; j > 0; j /= 2){
                node[j] = node[j * 2] + node[j * 2 + 1];
            }
        }

        T query(int s, int t){
            return query(s, t, 0, 0, n);
        }

        void add(int s, int t, int x){
            add(s, t, x, 0, 0, n);
        }
};

signed main(){
    int n, q;
    cin >> n >> q;

    lazy_segment_tree<int> lst(n+1, 0, [](int a, int b){return a+b;});
    rep(i, q){
        int qq;
        cin >> qq;

        if(qq == 0){
            int s, t, x;
            cin >> s >> t >> x;
            lst.add(s, t+1, x);
        }

        if(qq == 1){
            int i;
            cin >> i;
            cout << lst.query(i, i+1) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 7080
def main():
    n,x=list(map(int,input().split()))
    a=list(map(int,input().split()))
    a.sort()
    ans=0
    if(sum(a)<x):
        ans-=1
    for i in range(n):
        if(x-a[i]>=0):
            ans+=1
            x-=a[i]
    print(ans)


if __name__=="__main__":
    main()

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef long long int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 3 * 100'000 + 5;

i64 n;
i64 a[MAXN];

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    i64 a, b;
    cin >> a >> b;
    cout << a * b << endl;

    return 0;
}

Measured memory_bytes: 3640
function Main(input) {

  var input = input.split("\n");
  var n = input[0];
  var sp = new Array();


  for(var i=1; i<=n;i++){
    var spa = input[i].split(" ");
    sp.push({id:i, city:spa[0], rate:  parseInt(spa[1], 10)});
  }

  sp.sort((a, b) => {
    if (a.city < b.city) return -1;
    if (a.city > b.city) return 1;
    if (a.rate > b.rate) return -1;
    if (a.rate < b.rate) return 1;
    return 0;
  });
  sp.forEach(function(e, i) {
    console.log(sp[i]["id"]);
  });

  
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const ll LINF = 1e18;
int main() {
	int n, cnt = 0, tmp = 0, ans;
	bool f[8] = {};
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] < 3200) {
			f[a[i] / 400] = true;
		} else {
			tmp++;
		}
	}
	for (int i = 0; i < 8; i++) {
		if (f[i]) {
			cnt++;
		}
	}
	ans = cnt + tmp;
	if (cnt == 0) {
		cnt++;
	}
	cout << cnt << " " << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define ll long long
#define double long double
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue
using namespace std;
signed main() {
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i < n; i++) {
		if (i > (n - i) / i)break;
		if ((n - i) % i == 0) {
			if (i >= (n - i) / i)break;
			ans += (n - i) / i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

N, K = gets_i_list
R, S, P = gets_i_list
t_list = gets_nsp_list

points = {
  "r" => P,
  "s" => R,
  "p" => S
}
ans = 0
N.times do |i|
  if i < K || t_list[i] != t_list[i-K]
    ans += points[t_list[i]]
  else
    t_list[i] = "x"
  end
end

puts ans

Measured memory_bytes: 8956
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
	int a[5],b[5],min=10000,sum=0;
	for (int i = 0; i < 5; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < 5; i++)
	{
		if (a[i] % 10)
		{
			b[i] = (a[i] / 10 + 1) * 10;
		}
		else
		{
			b[i] = a[i];
		}
		sum += b[i];
	}
	for (int i = 0; i < 5; i++)
	{
		if (sum - b[i] + a[i] < min)
		{
			min = sum - b[i] + a[i];
		}
	}
	cout << min;
	return 0;
}

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

using namespace std;

#define int long long
const int N = (int) 1e5 + 7;
const int C = (int) 1e18;
int h, w, n;
int mnf, mns;
int f[N];
int s[N];
vector<pair<int, int>> a[N];
vector<pair<int, int>> b[N];

void dfsa(int i);
void dfsb(int i);

void dfsa(int i) {
  mnf = min(mnf, f[i]);
  for (auto &it : a[i]) {
    int j = it.first;
    int val = it.second;
    if (s[j] == C) {
      s[j] = val - f[i];
      dfsb(j);
    } else {
      if (s[j] != val - f[i]) {
        cout << "No\n";
        exit(0);
      }
    }
  }
}

void dfsb(int i) {
  mns = min(mns, s[i]);
  for (auto &it : b[i]) {
    int j = it.first;
    int val = it.second;
    if (f[j] == C) {
      f[j] = val - s[i];
      dfsa(j);
    } else {
      if (f[j] != val - s[i]) {
        cout << "No\n";
        exit(0);
      }
    }
  }
}

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

  cin >> h >> w >> n;
  for (int i = 1; i <= h; i++) {
    f[i] = C;
  }
  for (int i = 1; i <= w; i++) {
    s[i] = C;
  }
  for (int k = 1; k <= n; k++) {
    int i, j, x;
    cin >> i >> j >> x;
    a[i].push_back({j, x});
    b[j].push_back({i, x});
  }
  for (int i = 1; i <= h; i++) {
    if (f[i] == C) {
      mnf = (int) 1e18, mns = (int) 1e18;
      f[i] = 0;
      dfsa(i);
      if (mnf + mns < 0) {
        cout << "No\n";
        return 0;
      }
    }
  }
  cout << "Yes\n";
}


Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

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

  int n, m, x;
  cin >> n >> m >> x;
  
  vector<int> cost(n);
  vector<vector<int>> understand(n, vector<int>(m));

  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    for (int j = 0; j < m; j++) {
      cin >> understand[i][j];
    }
  }
  
  int min_cost = INF;
  for (int i = 0; i < (1<<n); i++) {
    vector<int> ru(m, 0);
    int rc = 0;
    for (int j = 0; j < n; j++) {
      if ((i>>j)&1) {
        rc += cost[j];
        for (int k = 0; k < m; k++) {
          ru[k] += understand[j][k];
        }
      }
    }

    bool fl = true;
    for (int l = 0; l < m; l++) {
      if (ru[l] < x) {
        fl = false;
        break;
      }
    }

    if (fl) min_cost = min(min_cost, rc);
  }

  cout << ((min_cost == INF) ? -1 : min_cost) << endl;
}


Measured memory_bytes: 3652
s = list(input())

length = len(s)
count = 0

for i in range(length-1):
    if i == length:
        break
    if s[i] == s[i+1]:
        if s[i] == '0':
            s[i+1] = '1'
            count += 1
        else:
            s[i+1] = '0'
            count += 1


print(count)

Measured memory_bytes: 3956
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

int main() {
    map<int, bool> m;

    int n;
    cin >> n;

    bool isYes = true;

    rep(i, 0, n)
    {
        int a;
        cin >> a;
        if (m.count(a) == 1)
        {
            isYes = false;
            break;
        }
        m[a] = true;
    }

    cout << ((isYes)?"YES":"NO") << endl;
}


Measured memory_bytes: 9600
a, b, c = map(int, input().split())

if a == b == c and a % 2 == 0:
	print(-1)
else:
	cnt = 0
	for _ in range(10**5):
		if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
			print(cnt)
			break
		else:
			a, b, c = (b + c) / 2, (c + a) / 2, (a + b) / 2
			cnt += 1

Measured memory_bytes: 3188
/*
!لَا أَبْرَحُ حَتَّىٰ أَبْلُغَ
فَصَبْرٌ جَمِيلٌ
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define Tesla              file();
#define fr(x,y) for(int x=0; x<(y); ++x)
const double PI = acos(-1), EPS = 1e-7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };
const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
ll mod = 998244353;
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}
void file() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif  !ONLINEJUDGE
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}
int main()
{
	Tesla
		int n;
	cin >> n;
	while (n>0)
	{
		if (n % 10 == 7)
		{
			cout << "Yes";
			return 0;
		}
		n/=10;

	}
	cout << "No" ;

}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    double d,e;
    cin>>d>>e;
    if(!d&&!e)break;
    double ans=1e9;
    for(double i=0;i<=d;i++){
      ans=min(ans,abs(sqrt(i*i+(d-i)*(d-i))-e));
    }
    cout<<fixed<<setprecision(20)<<ans<<endl;
  }
}



Measured memory_bytes: 3284
s = gets.to_i

def f(n)
  if n % 2 == 0
    return n / 2
  else
    return (3 * n) + 1
  end
end

before = s
h = []

h[s] = 1

1000000.times do |i|
  curr = f(before)
  if(h[curr])
    puts i + 2
    exit
  else
    h[curr] = 1
  end

  before = curr
end


Measured memory_bytes: 1788
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
a,b,c,d = map(int,input().split())
while(1):
    c -= b
    if (c<=0):
        print ('Yes')
        break
    a -= d
    if (a<=0):
        print ('No')
        break

Measured memory_bytes: 9168
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
void f(int a,int b) {
	string s = to_string(a);
	string t = to_string(b);
	cout << max(s.size(), t.size()) << endl;
}
int main() {
	int n, p[100010];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int cnt = 0;
	for (int i = 0; i < n - 1; i++) {
		if (p[i] == i + 1) {
			swap(p[i], p[i + 1]);
			cnt++;
			i = -1;
		}
	}
	if (p[n - 1] == n) {
		swap(p[n - 1], p[n - 2]);
		cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int a = scan.nextInt(), b = scan.nextInt();
		if(a%b==0) out.println(-1);
		else out.println(a);
		out.close();
	}
	
	static class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			try	{
				br = new BufferedReader(new InputStreamReader(System.in));
				st = new StringTokenizer(br.readLine());
			} catch (Exception e){e.printStackTrace();}
		}

		public String next() {
			if (st.hasMoreTokens())	return st.nextToken();
			try {st = new StringTokenizer(br.readLine());}
			catch (Exception e) {e.printStackTrace();}
			return st.nextToken();
		}

		public int nextInt() {return Integer.parseInt(next());}

		public long nextLong() {return Long.parseLong(next());}

		public double nextDouble() {return Double.parseDouble(next());}

		public String nextLine() {
			String line = "";
			if(st.hasMoreTokens()) line = st.nextToken();
			else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
			while(st.hasMoreTokens()) line += " "+st.nextToken();
			return line;
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for(int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n){
			long[] a = new long[n];
			for(int i = 0; i < n; i++) a[i] = nextLong();
			return a;
		}

		public double[] nextDoubleArray(int n){
			double[] a = new double[n];
			for(int i = 0; i < n; i++) a[i] = nextDouble();
			return a;
		}

		public char[][] nextGrid(int n, int m){
			char[][] grid = new char[n][m];
			for(int i = 0; i < n; i++) grid[i] = next().toCharArray();
			return grid;
		}
	}

}

Measured memory_bytes: 22996
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <map>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))
using namespace std;

int main(void) {
	/*int n, k;
	scanf("%d %d", &n, &k);
	if (k == 1) {

		printf("%d\n", 0);
	}
	else {
		printf("%d\n", n - k);
	}*/

	int n;
	scanf("%d", &n);
	vector<pair<int, int>> v;
	vector<pair<int, int>> data;
	for (int i = 0; i < n; i++) {
		int x, y;
		scanf("%d %d", &x, &y);
		v.push_back(make_pair(x, y));
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j) {
				data.push_back(make_pair(v[i].first - v[j].first, v[i].second - v[j].second));
			}
		}
	}
	sort(data.begin(), data.end());
	int oldf = 1000000000;
	int olds = 1000000000;
	int count = 0;
	int max = -1;
	for (vector<pair<int, int>>::iterator it = data.begin(); it != data.end(); it++) {
		if (oldf == (*it).first && olds == (*it).second) {
			count++;
		}
		else {
			max = (max < count) ? count : max;
			oldf = (*it).first;
			olds = (*it).second;
			count = 1;
		}
	}
	max = (max < count) ? count : max;
	printf("%d\n", v.size() - max);
	return 0;
}

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


int main(){
  int l,r,d;
  cin >> l >> r >> d;

  int ans = 0;
  for(int i = l; i <= r; i++){
    if(i%d==0) ans++;
  }

  cout << ans << endl;

  return 0;
}

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

struct Point {
	double x,y;
};

vector<Point> ans;

// l:left, r:right, d:depth
void koch(Point l, Point r, int d) {
	if (d == 0) {
		ans.push_back(l);
		return;
	}
	Point s, t, u;
	double th = M_PI / 3;
	s.x = (2*l.x + 1*r.x) / 3;
	s.y = (2*l.y + 1*r.y) / 3;
	t.x = (1*l.x + 2*r.x) / 3;
	t.y = (1*l.y + 2*r.y) / 3;
	u.x = (t.x-s.x)*cos(th) - (t.y-s.y)*sin(th) + s.x;
	u.y = (t.x-s.x)*sin(th) + (t.y-s.y)*cos(th) + s.y;
	koch(l, s, d-1);
	koch(s, u, d-1);
	koch(u, t, d-1);
	koch(t, r, d-1);
}

int main(){
	int n;
	cin >> n;
	Point left, right;
 	left.x = left.y = 0;
	right.x = 100;
	right.y = 0;
	koch(left, right, n);
	// 最後の点が入らないので
	ans.push_back(right);
	for (int i=0;i<ans.size();++i) {
		printf("%.8f %.8f", ans[i].x, ans[i].y); cout << endl;
	}
	return 0;
}




Measured memory_bytes: 3336
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public final class Main {

    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final long a = in.nextLong();
        final long b = in.nextLong();
        final long n = in.nextLong();
        in.nextLine();
        System.out.println(f(a, Math.min(n, b - 1), b));
    }

    private static long f(long a, long mid, long b) {
        return Math.floorDiv(a * mid, b) - a * Math.floorDiv(mid, b);
    }
}


Measured memory_bytes: 35792
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
    char x[200000];
    int depth=0;
    int ans=0;
    cin >> x;
    for(int i=0;x[i]!='\0';++i){
        if(x[i]=='S'){
            ++depth;
            ++ans;
        }else if(x[i]=='T' && depth>0){
            --depth;
            --ans;
        }else{
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#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 all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

template <class T>
struct dijkstra
{
  using P=pair<T,int>;
  priority_queue<P,vector<P>,greater<P>> q;
  vector<vector<P>>edge;
  vector<T>dist;
  int sz;
  dijkstra(int size){
    sz=size;
    edge.resize(size);
  }
  void reset(){
    dist.assign(sz,-1);
    q=priority_queue<P,vector<P>,greater<P>>();
  }
  void ae(int to,int from,T cost){
    edge[to].push_back({cost,from});
  }
  T cal(int start,int end){
    reset();
    q.push({0,start});
    while(!q.empty()){
      P tp=q.top();q.pop();
      if(dist[tp.second]!=-1)continue;
      dist[tp.second]=tp.first;
      for(P nn:edge[tp.second]){
        if(dist[nn.second]!=-1)continue;
        q.push({nn.first+tp.first,nn.second});
      }
    }
    return dist[end];
  }
  T getd(int end){
    return dist[end];
  }
};
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x,y,xx,yy,n;
  cin>>x>>y>>xx>>yy>>n;
  using cd=complex<double>;
  using p=pair<cd,double>;

  cd s(x,y),t(xx,yy);
  dijkstra<double> dj(n+2);
  vector<p> cir(n+2);
  cir[0]={s,0};
  cir[n+1]={t,0};
  rep(i,n)
  {
    double x,y,r;
    cin>>x>>y>>r;
    cir[i+1]={(cd){x,y},r};
  }
  rep(i,n+2)rep(j,n+2)
  {
    if(i==j)continue;
    dj.ae(i,j,max(0.0,abs(cir[i].first-cir[j].first)-cir[i].second-cir[j].second));
  }
  cout<<setprecision(12)<<dj.cal(0,n+1)<<endl;

  return 0;

}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/02/28  Problem: ABC 104 A / Link: http://abc104.contest.atcoder.jp/tasks/abc104_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */


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

	string ans = "";
	int R; cin >> R;
	if (R < 1200)ans = "ABC";
	else if (R < 2800)ans = "ARC";
	else ans = "AGC";
	
	cout << ans << "\n";

	return 0;
}


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


int main(){

  int i;
  char x;
  int ans;

  cin >> i;
  cin >> x;
  ans = i;
  while(1){
    if(x == '='){
      cout << ans << endl;
      break;
    }
    cin >> i ;
    if(x == '+') ans += i;
    if(x == '-') ans -= i;
    if(x == '*') ans *= i;
    if(x == '/') ans /= i;
    cin >> x;
  }

  return 0;
}

Measured memory_bytes: 1164
n=int(input())

AB=[list(map(int,input().split())) for i in range(n)]

AB.sort(key=lambda x:x[0]+x[1],reverse=True)

if len(AB)%2==1:
    AB.append([0,0])

s=0
for i in range(0,len(AB),2):
    s+=AB[i][0]-AB[i+1][1]

print(s)

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	string s;
	bool flag[4] = {false, false, false, false};

	cin >> s;

	REP(i, s.size()) {
		if (s[i] == 'N') {
			flag[0] = true;
		}
		else if (s[i] == 'S') {
			flag[1] = true;
		}
		else if (s[i] == 'E') {
			flag[2] = true;
		}
		else {
			flag[3] = true;
		}
	}

	if (flag[0] && !flag[1]) {
		cout << "No" << endl;
	}
	else if (!flag[0] && flag[1]) {
		cout << "No" << endl;
	}
	else if (flag[2] && !flag[3]) {
		cout << "No" << endl;
	}
	else if (!flag[2] && flag[3]) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using LL = long long;

int main() {
	LL X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	if (X / D > K) {
		cout << X  - K * D << endl;
		return 0;
	}
	LL s = X / D;
	LL ans;
	if ((K - s) % 2 == 0) {
		ans = X % D;
	}
	else {
		ans= D - X % D;
	}

	cout << abs(ans) << endl;

	return 0;

}

Measured memory_bytes: 3592
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	a := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&a[i])
	}
	sort.Sort(sort.IntSlice(a))
	fmt.Println(a[len(a)/2] - a[len(a)/2-1])
}

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

int main() {
  int N;
  
  cin >> N;
  vector <int>x(N);

  int sum =0;
  int tmp;
  for(int i =0;i<N;i++){
    cin >> tmp;
    x.at(i) = tmp;
    sum += tmp;
  }
  int ave0,ave1;

  //    cout << "sum:" << sum << endl;
  
  ave0 = sum/N;
  ave1 = ave0+1;
  
 //   cout << "ave0:" << ave0 << " ave1:" << ave1 << endl;
  
  int res;
  int dis0=0;
  int dis1=0;
  
  for(int i=0;i<N;i++){
    dis0 += (ave0-x.at(i))*(ave0-x.at(i));
    dis1 += (ave1-x.at(i))*(ave1-x.at(i));
  }
  
//  cout << "dis0:" << dis0 << " dis1:" << dis1 << endl;
  
  if(dis0 < dis1){
    res = dis0;
  }
  else{
    res = dis1; 
  }
  cout << res << endl;
}







Measured memory_bytes: 256
#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 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 1000000007
#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 = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}};

void solve()
{
    string s;
    cin >> s;
    int val = 0;
    fo(i, s.size()) {
        val += (s[i] - '0');
        val %= 9;
    }
    if(val)
    {

        cout << "No";
    }
    else
    {
        cout << "Yes\n";
    }
    
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    srand(time(0));

    // FILE *fin = freopen("ip.txt","r",stdin);
    // FILE *fout = freopen("op.txt","w",stdout);
    int t = 1, nn = 1;
    //cin >> t;
    while (t--)
    {
        // cout << "Case #" << nn << ":"
        //      << " ";
        // nn++;
        solve();
    }
}

Measured memory_bytes: 3724
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <queue>
#include <stack>
#include <functional>
using ll = long long;
using namespace std;
int main() {
	ll n, m, k, ans = 0, A[10101];
	cin >> n >> m >> k >> ans;
	if (abs(m - n) <= ans && abs(k - m) <= ans)
		cout << "Yes" << endl;
	else if (abs(k - n) <= ans)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

struct Point {
  double x, y;
};

int N;

void dfs(int n, Point p1, Point p2) {
  if ( n == N ) return;

  double th = M_PI*60.0/180.0;
  Point s = {(2.0*p1.x+p2.x)/3.0, (2.0*p1.y+p2.y)/3.0};  
  Point t = {(p1.x+2.0*p2.x)/3.0, (p1.y+2.0*p2.y)/3.0};  
  Point u = {(t.x-s.x)*cos(th) - (t.y-s.y)*sin(th) + s.x,
	     (t.x-s.x)*sin(th) + (t.y-s.y)*cos(th) + s.y};	     

  dfs(n+1, p1, s);
  printf("%.8f %.8f\n", s.x, s.y);

  dfs(n+1, s, u);
  printf("%.8f %.8f\n", u.x, u.y);

  dfs(n+1, u, t);
  printf("%.8f %.8f\n", t.x, t.y);

  dfs(n+1, t, p2);
}

int main() {
  cin >> N;

  printf("%.8f %.8f\n", 0.0, 0.0);
  dfs(0, Point{0.0, 0.0}, Point{100.0, 0.0});  
  printf("%.8f %.8f\n", 100.0, 0.0);  
  
  return 0;
}



Measured memory_bytes: 3208
INF=10**9+7
H,W=map(int,input().split())
S=list()
q=list()

S.append(["#"]*(W+2))
for i in range(H):
  S.append(["#"]+list(input())+["#"])
S.append(["#"]*(W+2))


m=0
for y in range(1,H+1):
  for x in range(1,W+1):
    if S[y][x]=="#":
      continue
    D=[[INF]*(W+2) for _ in range(H+2)]
    D[y][x]=0
    q.clear()
    q.append([x,y])
    while len(q)>0:
      c=list(q.pop(0))
      for dx,dy in [[-1,0],[1,0],[0,-1],[0,1]]:
        ny,nx=c[1]+dy,c[0]+dx
        if S[ny][nx]=="." and D[ny][nx]==INF:
          D[ny][nx]=D[c[1]][c[0]]+1
          q.append([nx,ny])
          m=max(m,D[ny][nx])
print(m)


Measured memory_bytes: 3188