akhauriyash/Code-Regression huggingface dataset:
import math

# ベクトル[p0->p1]に対する、点p2の位置（反時計回りならば、プラスを返す）
def ccw(p0, p1, p2):
    return (p1[0] - p0[0]) * (p2[1] - p0[1]) - (p1[1] - p0[1]) * (p2[0] - p0[0])


N = int(input())
pts = [(tuple(map(int, input().split())), i) for i in range(N)]

# 凸包を求める
pts.sort()

chU = [] # 上側
for pt, i in pts:
    while len(chU) >= 2 and ccw(chU[-2][0], chU[-1][0], pt) >= 0:
        chU.pop()
    chU.append((pt, i))

chL = [] # 下側
for pt, i in reversed(pts):
    while len(chL) >= 2 and ccw(chL[-2][0], chL[-1][0], pt) >= 0:
        chL.pop()
    chL.append((pt, i))

CH = chU[:-1] + chL[:-1] # ((x, y), i)


# 各点に対して、凸包上で隣接する２点との垂直二等分線がなす角度を求める（360°に対して占める割合が答え）
# （隣接する２辺の傾斜角の差に等しいので、それを計算する）
aIn = math.atan2(CH[-1][0][1] - CH[0][0][1], CH[-1][0][0] - CH[0][0][0])
ptNow = CH[-1][0]
anss = [0.0] * N
for i in reversed(range(len(CH))):
    iNow = CH[i][1]
    pt2 = CH[i - 1][0]
    aOut = math.atan2(pt2[1] - ptNow[1], pt2[0] - ptNow[0])
    anss[iNow] = ((aOut - aIn) % (2 * math.pi)) / (2 * math.pi)

    ptNow = pt2
    aIn = aOut

for ans in anss:
    print(ans)


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
long long p;
int n,e,w,s;
char ss[100005];
main()
{
	int t;
	scanf("%s",ss);
	for(int i = 0;ss[i];i++)
	{
		if(ss[i]=='N')
		n=1;
		if(ss[i]=='E')
		e=1;
		if(ss[i]=='W')
		w=1;
		if(ss[i]=='S')
		s=1;
	}
	if(n==s && e==w)
	printf("Yes");
	else
	printf("No");
}
/*
8 4
4 4 2 2
1234321
2 2 2 1

1211221

12211221
1111
*/


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

typedef struct node{
 int num;
 struct node *left;
 struct node *right;
}node;


node * makenode(int x){

 node *new=malloc(sizeof(node));
 new->right=NULL;
 new->left=NULL;
 new->num=x;

return new;
}


int main(){
 int n,i,x;
 char com[13];
 node *front=NULL;
 node *rear=NULL;
 node *new;
 node **p;
 node *q;

 scanf("%d",&n);

 for(i=0;i<n;i++){
  scanf("%s",com);

  if(com[0]=='i'){
    scanf("%d",&x);
    new=makenode(x);
    new->right=front;
    if(front!=NULL)front->left=new;
    else rear=new;
    front=new;
  }

  else if(strcmp(com,"deleteFirst")==0){
    front=front->right;
    if(front!=NULL){
       free(front->left);
       front->left=NULL;
    }
    else rear=NULL;
  }

  else if(strcmp(com,"deleteLast")==0){
    rear=rear->left;
    if(rear==NULL)front=NULL;
    else {
     free(rear->right);
     rear->right=NULL;
    }
  }

  else if(strcmp(com,"delete")==0){
    scanf("%d",&x);
    p=&front;
    while((*p)!=NULL && (*p)->num != x)p=&((*p)->right);
    if((*p)!=NULL){
     if((*p)->right == NULL){
        rear=rear->left;
        free((*p));
        (*p)=NULL;
     }
     else {
        (*p)->right->left=(*p)->left;
        (*p)=(*p)->right;
     }
    }
  }

 }

 q=front;
 while(q!=NULL){
  if(q==rear)printf("%d\n",q->num);
  else printf("%d ",q->num);
  q=q->right;
 }

return 0;
}


Measured memory_bytes: 32976
def solve():
    from sys import stdin
    input_lines = stdin
    
    paper = [0] * 196
    
    size = [[0, -1, 1, -14, 14], [0, -1, 1, -15, -14, -13, 13, 14, 15],
            [0, -1, 1, -15, -14, -13, 13, 14, 15, -28, -2, 2, 28]]
    
    for line in input_lines:
        x, y, s = map(int, line.split(','))
        
        pos = 30 + x + 14 * y
        s -= 1
        
        for move in size[s]:
            paper[pos+move] += 1
    
    zero_cnt = 0
    max_density = 0
    for i in range(30, 157, 14):
        line = paper[i:i+10]
        zero_cnt += line.count(0)
        max_density = max(max_density, max(line))
    
    print(zero_cnt)
    print(max_density)

solve()


Measured memory_bytes: 5600
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <stdbool.h>
typedef long long ll;
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define max(l,r) ((l)>(r)?l:r)
#define min(l,r) ((l)<(r)?l:r)
const ll MOD = 1000000007;

int main(){
    //input
    int n;
    scanf("%d", &n);
    char s[101010];
    scanf("%s", s);

    //solve
    ll ans = 1;
    int cnt[28] = {0};
    rep(i ,n) cnt[s[i] - 'a']++;
    rep(i, 26) {
        ans *= cnt[i]+1;
        ans %= MOD;
    }
    ans = (ans - 1) % MOD;

    //output
    printf("%lld", ans);
}

Measured memory_bytes: 1780
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <climits>
#define bogo_sort   std::sort
#define bozo_sort   std::stable_sort
#define alles(obj)  obj.begin(), obj.end()
#define elif        else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo        std::cout <<
#define read        std::cin >>
#define endl        std::endl
#define fin         << '\n'
#define bash        push_back
#define fish        push_front
#define makePair    std::make_pair
#define _           << ' ' <<
// type-define
#define Stack       std::stack
#define Queue       std::queue
#define Deque       std::deque
#define PQueue      std::priority_queue
#define Set         std::set
#define Vector      std::vector
#define Pair        std::pair
#define Map         std::map
#define HashMap     std::unordered_map
#define Greater     std::greater
using String  =     std::string;
using llong   =     long long;
using boolean =     bool;
using Pii     =     Pair<int, int>;
using Vi      =     Vector<int>;
using Vii     =     Vector<Pii>;
// utils
constexpr int   dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int   dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int   INF  = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm   ( A x,  B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    inline boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        if ( n == 1 ) {
            echo 1 fin;
            return 0;
        }
        int max = 0;
        for ( int i = 2; i*i <= n; i++ ) {
            int tmp = i*i;
            while ( tmp*i <= n ) {
                tmp *= i;
            }
            chmax ( max, tmp );
        }
        echo max fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
cd = [list(map(int, input().split())) for _ in range(m)]

for i in range(n):
    a = ab[i][0]
    b = ab[i][1]

    md = float('inf')
    for j in range(m):
        c = cd[j][0]
        d = cd[j][1]

        dist = abs(a - c) + abs(b - d)
        if dist < md:
            ans = j + 1
            md = dist

    print(ans)


Measured memory_bytes: 3064
use std::io;

fn main() {
        let mut input = String::new();

        io::stdin()
                .read_line(&mut input)
                .expect("Failed to read line");

        let integers: Vec<String> = input.split(' ').map(|s| s.trim().to_string()).collect();

        let a: i32 = integers[0].parse().unwrap();
        let b: i32 = integers[1].parse().unwrap();

        if a % 2 == 0 || b % 2 == 0 {
                println!("Even");
        } else {
                println!("Odd");
        }
}

Measured memory_bytes: 2136
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) (vec).begin(),(vec).end()
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int k,ppp,stp,vis[1000100];
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>k;
	ppp=7%k;
	if(ppp==0){
		cout<<1<<endl;
		return 0;
	}
	stp=1;
	while(1){
		stp++;
		ppp=(ppp*10+7)%k;
		if(vis[ppp]){
			cout<<"-1"<<endl;
			return 0;
		}
		vis[ppp]=1;
		if(ppp==0){
			cout<<stp<<endl;
			return 0;
		}
	}
	return 0;
}


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

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> A(h, vector<int>(w)), B(h, vector<int>(w));
    for (auto &a: A)
        copy_n(istream_iterator<int>(cin), w, a.begin());
    for (auto &b: B)
        copy_n(istream_iterator<int>(cin), w, b.begin());

    int d = 12800;
    vector<vector<vector<bool>>> DP(h + 1, vector<vector<bool>>(w + 1, vector<bool>(2 * d + 1)));

    DP[0][0][d + 1] = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            for (int k = 0; k < 2 * d + 1; k++){
                if (!DP[i][j][k])
                    continue;
                int e = abs(A[i][j] - B[i][j]);
                DP[i + 1][j][k + e] = true;
                DP[i + 1][j][k - e] = true;
                DP[i][j + 1][k + e] = true;
                DP[i][j + 1][k - e] = true;
            }
        }
    }

    const int INF = 1e8;
    int ans = INF;
    for (int i = 0; i < 2 * d + 1; i++){
        if (DP[h - 1][w][i])
            ans = min(ans, abs(i - d - 1));
    }
    cout << ans << endl;
}

Measured memory_bytes: 21504
#include<bits/stdc++.h>
using namespace std;
map<int,int>mp;
map<char,int>::iterator it;
  vector<int>v;
  int arr[200000];
int main()
{

int n,a;
cin>>n;
for(int i=1;i<=n;i++)
{
    cin>>a;
    arr[a-1]=i;
}
for(int i=0;i<n;i++)
{
    cout<<arr[i]<<" ";
}


}


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

using namespace std;

#define INF (int)(1e9)

// Relevant constraints
// 2 <= N <= 10^5
// 1 <= K <= 100
// 2 secs

// Generalized version of frog1
// to K possible steps instead of 2
// Naturally, this turns the complexity
// required from O(n) to O(nK)
// This is acceptable for our constraints

// Recurrence to optimize:
// c(n) = min({c(n - 1) + cost(n, n - 1), c(n - 2) + cost(n, n - 2), ...,
//             c(n - k) + cost(n, n - k)})

// It doesn't matter how we use K in the future
// so that parameter is irrelevant for larger values
// and doesn't need to be stored
unordered_map<int, int> map_dp;
int solve_memo(const vector<int> &h, int n, int k) {
	if (n < 0)
		return INF;
	if (n == 0)
		return 0;
	if (map_dp.find(n) != map_dp.end())
		return map_dp[n];

	int min_n = INF;
	for (int i = 1; i <= k; ++i) {
		if (n - i < 0)
			continue;

		min_n = min(min_n,
			    solve_memo(h, n - i, k) + abs(h[n] - h[n - i]));
	}

	return map_dp[n] = min_n;
}

int solve_tab(const vector<int> &h, int n, int k) {
	vector<int> dp(n);

	// Initial conditions
	dp[0] = 0;
	dp[1] = abs(h[0] - h[1]);

	for (int i = 2; i < n; ++i) {
		int min_n = INF;
		for (int j = 1; j <= k; ++j) {
			if (i - j < 0)
				break;

			min_n = min(min_n, dp[i - j] + abs(h[i] - h[i - j]));
		}
		dp[i] = min_n;
	}

	// dp[n - 1] represents the minimum cost
	// to get to stone n
	// in general dp[i] represents the minimum
	// cost to get to stone i
	return dp[n - 1];
}

int main() {

	cin.tie(NULL);
	ios_base::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;

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

	// n - 1 to accomodate the array size
	cout << solve_memo(h, n - 1, k) << '\n';
	// cout << solve_tab(h, n, k) << '\n';

	return 0;
}


Measured memory_bytes: 11044
#pragma region Macros
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define rep2(i, a, b) for(ll i = a; i <= b; ++i)
#define rep(i, n) for(i = 0; i < n; ++i)
#define rep3(i, a, b) for(ll i = a; i >= b; --i)
using namespace std;

// _________コーディングはここから！！___________

int n, m, k, i;
constexpr int N = 200010;
int a[N], b[N];
constexpr int sz = 4500000;
char reader[sz];
char *pos = reader;
int nn, now, ans;
int kk;
main() {
    reader[fread(reader, sizeof(char), sizeof(char) * sz, stdin)];
    while('0' <= *pos) n = n * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) m = m * 10 + *pos++ - '0';
    pos++;
    while('0' <= *pos) k = k * 10 + *pos++ - '0';
    nn = n;
    pos++;
    rep(i, n) {
        while('0' <= *pos) a[i + 1] = a[i + 1] * 10 + *pos++ - '0';
        pos++;
        a[i + 1] += a[i];
        if(a[i + 1] > k) {
            nn = i;
            ++i;
            for(; i < n; ++i) {
                while('0' <= *pos) pos++;
                pos++;
            }
            break;
        }
    }
    while(*pos and *pos <= 32) pos++;
    rep(i, m) {
        while('0' <= *pos) b[i + 1] = b[i + 1] * 10 + *pos++ - '0';
        pos++;
        b[i + 1] += b[i];
        if(b[i + 1] > k) {
            m = i;
            break;
        }
    }
    now = ans = nn;
    for(i = 1; i <= m; i++) {
        kk = k - b[i];
        while(a[now] > kk) now--;
        ans = max(ans, i + now);
    }
    pos = reader;
    i = 0;
    do {
        *pos++ = ans % 10 + '0';
        ans /= 10;
        i++;
    } while(ans);
    reverse(reader, reader + i);
    fwrite(reader, sizeof(char), sizeof(char) * i, stdout);
}


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

#define pb push_back
#define mk make_pair
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define all(S) (S).begin(), (S).end()
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugM(M, l, c ) rep( i, 0, l ){ rep( j, 0, c ){ cout << M[i][j] << " "; } cout << endl; }
#define debugP(p) cout << #p << " = " << p.x << " --- " << #p << " = " << p.y << endl;
#define MAXN 100010

using namespace std;

typedef long long int ll;
typedef pair<int, int> ii;
const int INF = 0x3f3f3f3f;

int main(void) {
	int n, x, d;
	int v[105];
	
	cin >> n >> d >> x;
	rep(i, 0, n) cin >> v[i];
	
	int ans = n;
	for(int i = 1; i <= d; i++) {
		rep(j, 0, n) {
			int aux = (i * v[j]) + 1;
			if(aux <= d) {
				ans++;
			}
		}
	}
	ans += x;
	cout << ans << endl;
	
	return 0;
}


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

t = 0
tmp = 0
for i in range(n):
  t += A[i]  
  if i%2 == 1:
    if t >= 0:
      tmp += abs(-1-t)
      t = -1      
  else:
    if t <= 0:
      tmp += abs(1-t)
      t = 1      
  
ans = tmp

t = 0
tmp = 0
for i in range(n):
  t += A[i]  
  if i%2 == 0:
    if t >= 0:
      tmp += abs(-1-t)
      t = -1
      
  else:
    if t <= 0:
      tmp += abs(1-t)
      t = 1      
  
ans = min(ans,tmp)  
print(ans)

Measured memory_bytes: 14468
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    string S;
    cin>>S;

    rep(i,S.size()-1){
        if(S.substr(i,2)=="AC"){
            cout << "Yes"<<endl;
            return 0;
        }
    }
    cout << "No"<<endl;

    



}


Measured memory_bytes: 3612
import sys
from itertools import accumulate
N = int(input())
S = input()

if S == '.'*N or S == '#'*N:
    print(0)
    sys.exit()

ind1 = 0
for i, x in enumerate(S):
    if x == '#':
        ind1 = i
        break
num = 0
for i, x in enumerate(S[::-1]):
    if x == '.':
        num = i
        break
ind2 = N - num
s = S[ind1:ind2]
if len(s) == 0:
    print(0)
    sys.exit()

a = s.split('.')
b = s.split('#')
aa = []
bb = []
for x in a:
    if len(x) != 0:
        aa.append(len(x))
for x in b:
    if len(x) != 0:
        bb.append(len(x))
c = [0] + list(accumulate(aa))
d = [0] + list(accumulate(bb))
ls = []
for i in range(len(c)):
    ls.append(c[i] + d[-1] - d[i])
print(min(ls))


Measured memory_bytes: 19300
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int n = sc.nextInt();
        int[] w= new int[n];
        int sum=0, temp=0;
        for(int i=0;i<n;i++){
          w[i] = sc.nextInt();
          sum+=w[i];
        }
        int res =sum;
        for(int i=0;i<n;i++){
          temp+=w[i];
          sum-=w[i];
          res=Math.abs(temp-sum)<res?Math.abs(temp-sum):res;
        }
        System.out.println(res);
            
        // 出力
       
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
int main() {
    vector<vector<char>> data(3, vector<char>(3));

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> data.at(i).at(j);
        }
    }

    cout << data.at(0).at(0) << data.at(1).at(1) << data.at(2).at(2) << endl;
    return 0;
}

Measured memory_bytes: 256
h, w = list(map(int, input().split()))
si, sj = list(map(int, input().split()))
ti, tj = list(map(int, input().split()))
s = [None] * h
for i in range(h):
    s[i] = input()

# 移動Aで探索する方向
d_a = [(-1,0), (0,-1),(1,0),(0,1)]
# 移動Bで探索する方向
d_b = [ (i, j) for j in range(-2, 3) for i in range(-2, 3)]

# 距離情報を一番遠い値で初期化
#import numpy as np
INF = int(1e9)
#dist = np.full((h+2, w+2), INF)
dist = [[INF for j in range(w+2)] for i in range(h+2)]

# マップ境界と壁を距離0にして探索させない
for i in range(h+2):
    dist[i][0] = 0
    dist[i][-1] = 0
for j in range(w+2):
    dist[0][j] = 0
    dist[-1][j] = 0
for i in range(h):
    for j in range(w):
        if s[i][j]=='#': dist[i+1][j+1] = 0
#dist = [[INF for j in range(w)] for i in range(h)]

# 01-BFS探索用キュー
from collections import deque
q = deque()

# 開始位置
dist[si][sj] = 0
q.append((si,sj))

while (len(q)>0):
    i, j = q[0]
    d = dist[i][j]
    q.popleft()
    # 移動Aによるコスト
    for v in range(len(d_a)):
        di, dj = d_a[v][0]+i, d_a[v][1]+j
        if (di, dj) == (ti, tj):
            print(d)
            exit(0)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d
        q.appendleft((di, dj))
    # 移動Bによるコスト
    for v in range(len(d_b)):
        # マップ境界で2以上移動したときに、反対の境界に向かうように剰余を取る
        di, dj = (d_b[v][0]+i)%(h+2), (d_b[v][1]+j)%(w+2)
        if (dist[di][dj]<=d):
            continue # 探索済みコスト以上
        dist[di][dj] = d+1
        q.append((di, dj))

ans = dist[ti][tj]
if ans == INF:
    ans = -1
print(ans)


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

using namespace std;

int g[100001], l[100001], r[100001];
priority_queue <pair<int,int>> Qr;
priority_queue <pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> Ql;

int main()
{
    int n, I=1, d=0, k;
    long long s=0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        g[i] = 1;
        cin >> l[i] >> r[i];
        Qr.push({l[i],i});
        Ql.push({r[i],i});
    }
    I = 2;
    for (int i = 0; i < n; i++)
    {
        while (g[Ql.top().second] == 0)
        {
            Ql.pop();
        }
        while (g[Qr.top().second] == 0)
        {
            Qr.pop();
        }
        if (I == 1)
        {
            k = Ql.top().second;
            I = 2;
        }
        else
        {
            k = Qr.top().second;
            I = 1;
        }
        g[k] = 0;
        if (d < l[k])
        {
            s += l[k]-d;
            d = l[k];
        }
        else if (d > r[k])
        {
            s += d-r[k];
            d = r[k];
        }
    }
    s += abs(d);
    long long S = s;
    s = 0;
    d = 0;
    for (int i = 0; i < n; i++)
    {
        g[i] = 1;
        Qr.push({l[i],i});
        Ql.push({r[i],i});
    }
    I = 1;
    for (int i = 0; i < n; i++)
    {
        while (g[Ql.top().second] == 0)
        {
            Ql.pop();
        }
        while (g[Qr.top().second] == 0)
        {
            Qr.pop();
        }
        if (I == 1)
        {
            k = Ql.top().second;
            I = 2;
        }
        else
        {
            k = Qr.top().second;
            I = 1;
        }
        g[k] = 0;
        if (d < l[k])
        {
            s += l[k]-d;
            d = l[k];
        }
        else if (d > r[k])
        {
            s += d-r[k];
            d = r[k];
        }
    }
    s += abs(d);
    cout << max(S, s);
    return 0;
}


Measured memory_bytes: 4840
import sys
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
  res = 0
  print(res)
  sys.exit()
  
res = 1
for i in range(n):
  if(res > pow(10,18)):
    break
  else:
    res = res * a[i]
if(res > pow(10,18)):
   res = -1
print(res)




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

int main() {
  int N,K;
  cin>>N>>K;
  int x =1;
  
  for(int i=0;i<N;i++){
    if (x*2<x+K){
      x*=2;
    }
    else{
      x+=K;
    }
  }
  cout<<x<<endl;


}


Measured memory_bytes: 256
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

#include <string>
using std::string;

int main(void){
    string s;
    string ans = "No";

    cin >> s;

    int i = 0;
    while(s[i] == 'h' && s[i+1] == 'i'){
        i += 2;
    }
    
    if(s[i] == NULL && s[i+1] == NULL){
        ans = "Yes";
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let X: usize = read();
    let T: usize = read();
    println!("{}", ((((N - 1) / X) + 1) * T))
}


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

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL) ;
	
	int x ,k ,d ; 
	cin >> x >> k >> d ; 
	x = abs(x);
	int r = x%d ; 
	int q = x/d  ;
	if(q >= k )
	{
		cout << x - k*d ; 
	}
	else 
	{
		int rem =  k - q ; 
		if(rem%2 == 0 )
			cout << r  ;
		else 
			cout << abs(r - d) ; 


	}

}    



Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int N = 1e5 + 10 , M = 5e5+10 ,  MOD = 1e9+7;
const int OO = 0x3f3f3f3f;
const double EPS = 1e-3;
 
#define clr(arr,val) memset(arr , val , sizeof (arr))
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n)-1;i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define ALL(v) ((v).begin()) , ((v).end())
#define SZ(v)  ((int)((v).size()))
typedef pair <int,int> pii ;
typedef vector < pii > vii ;
typedef vector < int > vi;
int dx[]={1,0,-1,0};int dy[]={0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[6]={2,1,-1,-2,-1,1};int dy[6]={0,1,1,0,-1,-1}; //Hexagonal Direction
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 

int n , x , dis[N] , a;



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

    cin >> n >> x;
  //  vi a(n+1);

    for(int i = 1 ; i <= n ; ++i){  
        cin >> a;
        dis[i] = dis[i-1] + a;
    }
    int cnt = 0;
    for(int i = 0 ; i <= n ; ++i){
        if(dis[i] <= x)
            cnt++;
    }

    cout << cnt << "\n";

    
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>
#include<unordered_map>
#include<deque>
#include<cmath>





using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const ll INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


void solve() {
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int xx, yy;
    for (int i = 0; i < n; ++i) {
        cin >> xx;
        x = max(x, xx);
    }
    for (int i = 0; i < m; ++i) {
        cin >> yy;
        y = min(y, yy);
    }
    if (y > x) {
        cout << "No War\n";
    }
    else {
        cout << "War\n";
    }

}


//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();



#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}


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

box = [0] * (N + 1)

for i in range(N, 0, -1):
    cnt = 0
    for j in range(i*2, N+1, i):
        cnt += box[j]
    if cnt%2 != alist[i-1]:
        box[i] = 1

M = sum(box)
ans = []
for i in range(1, N+1):
    if box[i]:
        ans.append("{}".format(i))

print(M)
print(" ".join(ans))

Measured memory_bytes: 22200
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int N,r[575],i,j;
double x=0,p[575];
double max(double a,double b){return a>b?a:b;}
double min(double a,double b){return a<b?a:b;}
double ch(int r1,int r2)
{
	double a=1.0*r1+r2,b=1.0*r1-r2;
	return sqrt((a*a)-(b*b));
}

int main()
{
	scanf("%d",&N);
	for(i=0;i<N;i++)
	{
		double t=0,a=0;
		scanf("%d",&r[i]);
		t=r[i];
		for(j=0;j<i;j++)
		{
			t=max(t,p[j]+ch(r[i],r[j]));
		}
		p[i]=t;
		x=max(x,p[i]+r[i]);
	}
	printf("%.5lf\n",x);
	return 0;
}

Measured memory_bytes: 640
import math
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
n,m = map(int,input().split())
n_num = 0
m_num = 0
if n >= 2:
    n_num = comb(n ,2)
    
if m >= 2:
    m_num = comb(m,2)
print(n_num+m_num)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

int main() {
  ll n,k;
  cin >> n >> k;
  vector<ll> A(n);
  vector<ll> F(n);

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

  sort(A.begin(),A.end(),greater<ll> ());
  sort(F.begin(),F.end());

  ll l = -1, r = 1e12 + 1;

  while(r - l > 1) {
    //  cout << "l = "<<l<<"  r = "<<r<<endl;
    ll mid = (l + r) / 2;
    ll K = 0;
    for(int i = 0; i < n; i++) {
      ll tmp = A[i] * F[i];
      if(tmp <= mid) continue;
      else {
	if((tmp - mid) % F[i] == 0) {
	  K += (tmp - mid) / F[i];
	}
	else {
	  K += (tmp - mid) / F[i] + 1;
	}
      }
    }

    if(K > k) l = mid;
    else r = mid;
  }

  cout << r << endl;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  vector<int> B(*max_element(A.begin(), A.end()) + 1, 0);
  for (int a : A) {
    for (int b = a; b < (int)B.size(); b += a) {
      B[b]++;
    }
  }
  int res = 0;
  for (int a : A) {
    if (B[a] == 1) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 7828
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>
//#include <boost/multiprecision/cpp_int.hpp>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;
using pil = std::pair<int, long long>;
using pli = std::pair<long long, int>;
using plpii = std::pair<long long, std::pair<int, int>>;
using pdd = std::pair<double, double>;

const long long INF = 1000000000000000001;
const long long _MOD = 1000000007;
const long long MOD = 998244353;
const int ALPHABET = 27;
const double pi = 3.14159265358979;

using namespace std;
//namespace mp = boost::multiprecision;

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

	ll ans = n * (n + 1) / 2;
	REP(i, 2, n + 1) {
		for (int j = i; j <= n; j += i) {
			ans += j;
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int color(int a) {
    int b = a/400;
    if (a >= 3200) b = 8;
    return b;
}

int main() {

    int a, n, x = 0, num = 0;
    cin >> n;

    set<int> st;
    REP(i, n) {
        cin >> a;
        if (a >= 3200) x++;
        st.insert(color(a));
    }

    for (auto a: st) {
        num++;
    }

    if (num == 1 && x == n) {
        cout << 1 << " " << n << endl;
        return 0;
    }
    
    cout << (x ? num - 1 : num) << " " << (x ? num + x -1 : num) << endl;
    
    return 0;
}

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

mt19937 mt(time(nullptr));
// uniform_int_distribution< int > rand_int(0, 10) // rand[0, 10] inclusive

bool solve(ul n, ul k) {
  if (k==1) return false;
  while (n%k==0) n/=k;
  return (n%k==1 ? true : false);
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ul n;
  cin >> n;
  vector< ul > cand;
  for (ul i=1; i*i<=n; ++i) {
    if (n%i==0) {
      cand.push_back(i);
      cand.push_back(n/i);
    }
    if ((n-1)%i==0) {
      cand.push_back(i);
      cand.push_back((n-1)/i);
    }
  }
  sort(cand.begin(), cand.end());
  ul ans = 0;
  for (ul i=0; i<cand.size(); ++i) {
    if (cand[i]==1) continue;
    if (i>0 && cand[i-1]==cand[i]) continue;
    if (solve(n, cand[i])) {
      ans++;
    }
  }
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
//V<ll>fac,rfac;void setFac(int n,int mod){fac=rfac=V<ll>(++n);fac[0]=1;FOR(i,1,n)fac[i]=fac[i-1]*i%mod;rfac[n-1]=modInv(fac[n-1],mod);FORR(i,n-1,1)rfac[i-1]=rfac[i]*i%mod;}
const int IINF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
ll s;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> s;
  ll t = (s-1)/IINF + 1;
  s = t*IINF - s;
  cout << "0 0 1000000000 1 " << s << " " << t << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void run(){
		int [] i = new int[1000];
		for(;sc.hasNextInt();){
			i[sc.nextInt()]++;
		}
		int max = 0;
		for(int j = 0;j < 1000;j++){
			if(i[j] > max) max = i[j];
		}
		for(int j = 0;j < 1000;j++){
			if(i[j] == max) System.out.println(j);
		}
	}
	public static void main(String[] args){
		Main m = new Main();
		m.run();
	}
}

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

using namespace std;

using int64 = long long;
const int mod = 1e9 + 9;

const int64 infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

template< typename T >
ostream &operator<<(ostream &os, const vector< T > &v) {
  for(int i = 0; i < (int) v.size(); i++) {
    os << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return os;
}

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}


int get2(int64 x, int64 y) {
  if(x % y == 0) return x / y;

  int64 d = x / y + 1;
  for(int i = 30; i >= 0; i--) {
    int64 Q = x - d * (1 << i);
    if(Q >= 0 && Q / y == x / y) {
      return get2(Q, y);
    }
  }
  return get2(x - x / y - 1, y);
}

int main() {
  int N, A[200], K[200];
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i] >> K[i];
  }
  int ret = 0;
  for(int i = 0; i < N; i++) {
    ret ^= get2(A[i], K[i]);
  }
  if(ret == 0) puts("Aoki");
  else puts("Takahashi");
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (long long int i = 0; i < (n); i++)
#define rep1(i,n) for (long long int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

char a[1000][1000];
int main()
{
    int n;
    cin >> n;
    int ans = 0;
    rep1(i,n+1) {
        string tmp = to_string(i);
        if (tmp.length() % 2 == 1)
            ans++;
    }

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


Measured memory_bytes: 256
/// Kazuki Hoshino


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<pi> vpi;
#define inf 1000000000
#define mod 1000000007
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define rep1(i, a, b) for(int i =a; i >=b; i--)
#define f first
#define ss second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define endl '\n'
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

ll n, x, a[1010], cur = 1, ans, sum;

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

//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);


cin >> n >> x;

rep(i, 1, n){
    cin >> a[i];
    sum+=a[i];
}

if(sum<x){
    cout << n-1 << endl;
    return 0;
}

if(sum==x){
    cout << n << endl;
    return 0;
}

sort(a+1, a+n+1);

ans = 0;
while(a[cur]<=x){
    x-=a[cur];
    ans++;
    cur++;
    if(cur>n)break;
}


cout << ans << endl;





return 0;}
///....


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
S = sum(A)
T = [0]*N
T[1] = A[0]
for i in range(2,N):
    T[i] = T[i-1] + A[i-1]
print(min([abs(2*T[i]-S) for i in range(1,N)]))

Measured memory_bytes: 28792
#include <algorithm>
    #include <bits/stdc++.h>
    #include <cctype>
    #include <cmath>
    #include <cstdio>
    #include <iomanip>
    #include <iostream>
    #include <list>

    #include <stack>
    #include <string>
    #include <vector>
    #include <bits/stdc++.h>
    #define INFINI (1000 * 1000 * 1000)

    using namespace std;
    //#define s(T) scanf("%d", &T)
    #define sl(T) scanf("%lld", &T)
    #define fill(a, val) memset(a, val, sizeof(a))
    #define mp make_pair
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define DREP(x) sort(all(x)); x.erase(unique(all(x)), x.end())
    #define INDEX(a, val) (lower_bound(all(a), val) - a.begin())

    typedef long long ll;


    bool compare_first(pair<int,int>a,pair<int,int >b)
    {
        return a.first<b.first;
    }

     bool compare_second(pair<int,pair<int , int> > a,pair<int,pair<int , int> > b)
    {
        return a.second.first<b.second.first;
    }


    ll min(ll a,ll b)
    {
        if(a>b)return b;
        return a;
    }
     ll max(ll a,ll b)
    {
        if(a>b)return a;
        return b;
    }

    ll toINT(string s)
    {
        ll a=0;
        for(ll index=0;index<s.size();index++)
            a=a*10+(s[index]-'0');
        return a;
    }



    int main() {
      ios::sync_with_stdio(false);


int a,b,c;
cin>>a>>b>>c;

int ans=3;
if(a==b&&a==c)
    ans=1;
else if(a==b||a==c||b==c)
    ans=2;

    cout<<ans<<endl;

return 0;
    }

/*

 }
 */


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
ll n,sum;
ll a[maxn],cnt[maxn];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		cnt[a[i]]++;
	}
	for(int i = 1;i <= n;i++){
		sum += cnt[i] * (cnt[i] - 1) / 2;	
	}
//	cout << sum << endl;
	for(int i = 0;i < n;i++){
		int x = a[i];
		ll ans = sum - ((cnt[x] * (cnt[x] - 1) / 2) - (cnt[x] -  1) * (cnt[x] - 2) / 2);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 4736
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstring>
#include<complex>
#include<stack>
#include<queue>
#include<unordered_map>
#include<map>
using namespace std;

int main() {

  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int count = 0;
  int i, j, k;
  for (i = a; i >= 0; i--) {
    for (j = b; j >= 0; j--) {
      k = (x - 500 *i - 100*j) / 50;
      if (0 <= k && k <= c) {
        count++;
      }
    }
  }
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

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

  int num = a * pow(10, static_cast<int>(log10(b)) + 1) + b;
  int sqrt_num = static_cast<int>(sqrt(num));
  cout << (num == sqrt_num * sqrt_num ? "Yes" : "No") << endl;

  return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >>b >>c >>d;

  if (a + b == c + d) {
    cout << "Balanced" << endl;
  }
    else if( a + b > c + d){
      cout << "Left" << endl;
    }
    else{
      cout << "Right" << endl;
    }      
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

const int mod = 998244353;

int main() {
	// freopen("input.txt", "r", stdin);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	ll ans = 1;
	vector<int> d(n);
	for (int& i : d) {
		cin >> i;
	}
	sort(d.begin() + 1, d.end());
	vector<int> cnt(n + 1);
	for (int i = 1; i < n; i++) {
		cnt[d[i - 1]]++;
		if (d[i] == 0) {
			ans = 0;
			break;
		}
		ans = ans * cnt[d[i] - 1] % mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
// n文字すべてが異なるとすると、答えはcomb(n,1) + comb(n,2) + comb(n,3) + ... + comb(n,n) = 2^n - 1
// ここから、同じ文字を選んだ組み合わせの数を引けば答えになりそう。
// →違った。その考えだと、ある文字を二つ以上選ぶ通りと別の文字を二つ以上選ぶ通りに共通部分が生じ、数え上げが困難になってしまう。
// ある文字cについて、2文字以上使わない条件を満たす、文字cの選び方は、(cの出現回数 + 1)
// (どれか1つを取るケース及び文字cを取らないケース)
// すると、答えは、Π(cの出現回数 + 1) - 1となる
// 最後に引いた1は、空文字列の場合
#include <bits/stdc++.h>
using namespace std;

int alphabet['z' - 'a' + 1];
const long long MOD = 1000000007;

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

    for(auto &p : S) ++alphabet[p - 'a'];
    long long res = 1;
    for(int i = 0; i < 'z' - 'a' + 1; ++i) {
        res *= (alphabet[i] + 1);
        res %= MOD;
    }
    cout << (res - 1 + MOD)%MOD << endl;
    return 0;
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)1e5
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int main(){
	ll n,x;cin>>n;vi v(n+1,0);for(ll i=1;i<n;i++) cin>>x,v[x]++;
	for(ll i=1;i<=n;i++) cout<<v[i]<<endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int a,b;cin>>a>>b;

  vector<int>v(999,0);
  rep(i,0,999){
    v[i+1]=v[i]+i+1;
  }
  out(v[b-a]-b);

  return 0;
}


Measured memory_bytes: 256
def amida(n,m,s,l)
  a=Array.new(n) {|i| i+1}
  l.each do |i|
    i.each_with_index do |j,id|
      a[id],a[id+1]=a[id+1],a[id] if j==1
    end
  end
  return a[s-1]==m ? true : false
end

loop do
  break if gets.chomp=="0"
  n,m,s,d,l=$_.to_i,gets.to_i,gets.to_i,gets.to_i,[]
  d.times do
    l<<gets.chomp.split("").map(&:to_i)
  end
  if amida(n,m,s,l) then puts 0
  else
    bf=false
    ll= Marshal.load(Marshal.dump(l))
    l.each_with_index do |i, idi|
      i.each_with_index do |j, idj|
        if j==1 then
          ll[idi][[0,idj-1].max]=1
          ll[idi][idj]=1
          ll[idi][[n-2,idj+1].min]=1
        end
      end
    end
    ll.each_with_index do |i, idi|
      i.each_with_index do |j, idj|
        if j==0 then
          l3= Marshal.load(Marshal.dump(l))
          l3[idi][idj]=1
          puts "#{idi+1} #{idj+1}" if bf=amida(n,m,s,l3)
        end
        break if bf
      end
      break if bf
    end
    puts 1 unless bf
  end
end

Measured memory_bytes: 9072