akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535
typedef tree<int, null_type, less<int>, rb_tree_tag,                    //if using ll change int to ll
        tree_order_statistics_node_update> pbset;
#define fob(x) find_by_order(x)
#define ook(x) order_of_key(x)
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m,x,c;
    int f=0;
    cin>>n>>m>>x;
    int arr[n+1][m+1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        arr[i][j]=0;
    }
    for(int i=1;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        cin>>arr[i][j];
    }
    ll ans=1e14;int flg=0;
    int u=1<<n;
    for(int i=1;i<u;i++)
    {
        
        ll ar[m]={0};ll cst=0;
        for(int j=0;j<n;j++)
        {
            if(i&1<<j)
            {
                cst+=arr[j+1][0];
                for(int k=0;k<m;k++)
                ar[k]+=arr[j+1][k+1];
            }
        }
        int flag=1;
        for(int j=0;j<m;j++)
        {
            if(ar[j]<x)
            {
                flag=0;break;
            }
        }
        if(flag==1)
        {ans=min(ans,cst);flg=1;}
    }
    if(flg==0)
    cout<<-1;
    else
    cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N,M;
  cin >> N >> M;
  vint wa(N);
  vint ac(N);
  REP(i,M){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(0 == ac[p] && "WA" == s)wa[p]++;
    if(0 == ac[p] && "AC" == s)ac[p]++;
  }
  
  int ans_ac = 0;
  int ans_wa = 0;
  REP(i,N){
    if(ac[i]){
      ans_ac++;
      ans_wa += wa[i];
    }
  }
  
  cout << ans_ac << " " << ans_wa << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;

signed main(){
    int h,w;
    cin >> h >> w;

    int a[26] = {0};
    rep(i,h*w){
        char c;
        cin >> c;
        a[c-'a']++;
    }
    rep(i,26){
        cerr << i << " " << a[i] <<endl;
    }


    if(h%2 == 0 && w%2 == 0){
        rep(i,26){
            if(a[i]%4 != 0){
                cout << "No" <<endl;
                return 0;
            }
        }
        cout << "Yes" << endl;
        return 0;
    }

    if(h%2 == 1 && w%2 == 1){
        rep(i,26){
            if(a[i]%2 == 1){
                a[i]--;
                break;
            }
        }
        rep(i,h/2+w/2){
            int c = 0;
            rep(j,26){
                if(a[j]%4 == 2){
                    a[j] -= 2;
                    c = 1;
                    break;
                }
            }
            if(c == 0){
                rep(j,26){
                    if(a[j]%2 == 0 && a[j] != 0){
                        a[j] -= 2;
                        c = 1;
                        break;
                    }
                }
            }
        }
        int cnt = 0;
        rep(i,26){
            if(a[i]%4 != 0){
                cout << "No" << endl;
                return 0;
            }
            cnt += a[i];
        }
        if(cnt == h*w-w-h+1)cout << "Yes" << endl;
        else cout <<"No" << endl;
        return 0;
    }

    if(h%2 == 0){
        int tmp = h;
        h = w;
        w = tmp;
    }

    rep(i,w/2){
        int c = 0;
        rep(j,26){
            if(a[j]%4 == 2){
                a[j] -= 2;
                c = 1;
                break;
            }
        }
        if(c == 0){
            rep(j,26){
                if(a[j]%2 == 0 && a[j] != 0){
                    a[j] -= 2;
                    c = 1;
                    break;
                }
            }
        }
    }
    int cnt = 0;
    rep(i,26){
        if(a[i]%4 != 0){
            cout << "No" << endl;
            return 0;
        }
        cnt += a[i];
    }
    if(cnt == h*w -w)cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    bool ok=true;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    for(int i=n-1; i>0; i--){
        if(a[i-1]>a[i]){
            if(a[i-1] - a[i] == 1) a[i-1]--;
            else ok = false;
        }
    }
    if(ok) cout << "Yes"<< endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 640
N=int(input())
A=[]
for _ in range(N):
    A+=[int(input())]

pre=[]
suf=[]
temp=-10000000000
for i in range(len(A)):
    temp=max(A[i],temp)
    pre+=[temp]

temp=-100000000000
for i in range(len(A)-1,-1,-1):
    temp=max(temp,A[i])
    suf+=[temp]
suf=suf[::-1]
ans=[]
for i in range(len(A)):
    if i==0:
        ans+=[suf[1]]
    elif i==len(A)-1:
        ans+=[pre[len(A)-2]]
    else:
        ans+=[max(pre[i-1],suf[i+1])]
for x in ans:
    print(x)

Measured memory_bytes: 80196
let rn_to_an r = 
  if r = "M" then 1000
  else if r = "D" then 500
  else if r = "C" then 100
  else if r = "L" then 50
  else if r = "X" then 10
  else if r = "V" then 5
  else if r = "I" then 1
  else 0

let rec sum_rm = function
  | [] -> 0
  | [x] -> x
  | x :: y :: rest when x < y -> y - x + sum_rm rest
  | x :: y :: rest -> x + sum_rm (y :: rest)

let _ =
  try
    while true do
      let rlst = List.map rn_to_an (Str.split (Str.regexp "") (read_line ())) in
      Printf.printf "%d\n" (sum_rm rlst)
    done
  with
    End_of_file -> ()

Measured memory_bytes: 2244
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
# from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
a=list(map(int,input().split()))

tmp=[0,abs(a[0])]
for i in range(n):
    if tmp[1]<abs(a[i]):
        tmp[0]=i
        tmp[1]=abs(a[i])
# print(tmp)

lst=[]

for i in range(n):
    a[i]+=a[tmp[0]]
    lst.append([tmp[0]+1,i+1])

# print(a[tmp[0]])
if a[tmp[0]]<0:
    for i in range(n-1):
        a[-2-i]+=a[-1-i]
        lst.append([n-i,n-i-1])
else:
    for i in range(n-1):
        a[i+1]+=a[i]
        lst.append([1+i,2+i])
# print(a)
# print(lst)
print(len(lst))
for i in lst:
    print(*i)

Measured memory_bytes: 40528
int main() {
	int n;
	int a[100];
	scanf("%d", &n);
	for (int i = 0;i<n;i++) {
		scanf("%d", &a[i]);
	}
	int m;
	int p[100];
	int x[100];
	scanf("%d", &m);
	for (int i = 0;i<m;i++) {
		scanf("%d %d", &p[i], &x[i]);
	}
	int sum;
	for (int k = 0;k < m;k++) {
		sum = 0;
		for (int j = 0;j < n;j++) {
			sum += a[j];
		}
		
		sum -= a[p[k] - 1];
		sum += x[k];
		
		printf("%d\n", sum);
	}
}

Measured memory_bytes: 128
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve(){
	int h, w;
	cin >> h >> w;
	vector<string> inputs;
	REP(i, h) {
		string s;
		cin >> s;
		inputs.push_back(s);
	}
	int erased = 1;
	while (erased) {
		erased = 0;
		for (char target = 'A'; target <= 'Z'; ++target) {
			pair<int, int> left = mp(10000, 10000);
			pair<int, int> right = mp(-1, -1);
			REP(i, h) {
				REP(q, w) {
					if (inputs[i][q] == target) {
						left.first = min(left.first, i);
						left.second = min(left.second, q);
						right.first = max(right.first, i);
						right.second = max(right.second, q);
					}
				}
			}
			if (right.first == -1) continue;
			int ok = 1;
			for (int i = left.first; i <= right.first; ++i) {
				for (int q = left.second; q <= right.second; ++q) {
					if (inputs[i][q] != target && inputs[i][q] != '?') {
						ok = 0;
					}
				}
			}
			if (ok == 0) continue;
			erased = 1;
			for (int i = left.first; i <= right.first; ++i) {
				for (int q = left.second; q <= right.second; ++q) {
					inputs[i][q] = '?';
				}
			}
		}
	}
	REP(i, h) {
		REP(q, w) {
			if (inputs[i][q] != '.' && inputs[i][q] != '?') {
				cout << "SUSPICIOUS" << endl;
				return;
			}
		}
	}
	cout << "SAFE" << endl;
}

#undef int
int main() {
	init();
	int t;
	cin >> t;
	REP(tea,t)
	solve();
}


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

using namespace std;

using namespace atcoder;

using mint = modint998244353;

struct S{
    mint a;
    int size;
};

struct F{
    mint a,b;
};

S op(S l,S r){
    return S{l.a+r.a,l.size+r.size}; //sizeはmergeした要素の個数
}
S e(){
    return S{0,0};
}
S mapping(F l,S r){
    return S{r.a*l.a+r.size*l.b,r.size}; //ai←b*ai+c
}
F composition(F l,F r){
    return F{r.a*l.a,r.b*l.a+l.b}; //ai←b*ai+cをmerge
}
F id(){
    return F{1,0};
}
int main(){
    int n,q;
    cin >> n >> q;
    vector<S> a(n);
    rep(i,n){
        int x;
        cin >> x;
        a[i]=S{x,1};
    }
    lazy_segtree<S,op,e,F,mapping,composition,id> seg(a);
    
    rep(i,q){
        int t;
        cin >> t;
        if(t==0){
            int l,r,c,d;
            cin >> l >> r >> c >> d;
            seg.apply(l,r,F{c,d});
            
        }
        if(t==1){
            int l,r;
            cin >> l >> r;
            cout << seg.prod(l,r).a.val() << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 19296
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bit = 0;
        for (int i=0; i<N; i++) {
            bit |= sc.nextInt();
        }
        System.out.println(Integer.numberOfTrailingZeros(bit));
    }
}


Measured memory_bytes: 21844
n=int(input())
d,x=map(int, input().split())
a=[int(input()) for i in range(n)]
ans=0

for i in range(n):
    ans+=1
    if d%a[i] != 0:
        ans+=d//a[i]
    else:
        ans+=(d//a[i])-1
print(ans+x)

Measured memory_bytes: 3064
S = input()

ans = True

if S[0] != 'A':
    ans = False

if not ('a' <= S[1] and S[1] <= 'z'):
    ans = False

cnt = 0
for s in S[2:-1]:
    if s == 'C':
        cnt += 1
    else:
        if not ('a' <= s and s <= 'z'):
            ans = False

if cnt != 1:
    ans = False

if not ('a' <= S[-1] and S[-1] <= 'z'):
    ans = False

if ans:
    print("AC")
else:
    print("WA")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
int main()
{
    ll n, q;
    cin >> n;
    ll a;
    vi n1(100001, 0);
    ll ans = 0;
    rep(i, n)
    {
        cin >> a;
        n1[a]++;
        ans += a;
    }
    cin >> q;
    vl b(q, 0), c(q, 0);
    rep(i, q)
    {
        cin >> b[i] >> c[i];
    }
    ll temp;
    rep(i, q)
    {
        ans += c[i] * n1[b[i]] - b[i] * n1[b[i]];
        n1[c[i]] += n1[b[i]];
        n1[b[i]] = 0;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 5100
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main(){
	string str;
	int count=0;
	cin>>str;
	if(str[0]!='C')
		count++;
	if(str[1]!='O')
		count++;
	if(str[2]!='D')
		count++;
	if(str[3]!='E')
		count++;
	if(str[4]!='F')
		count++;
	if(str[5]!='E')
		count++;
	if(str[6]!='S')
		count++;
	if(str[7]!='T')
		count++;
	if(str[8]!='I')
		count++;
	if(str[9]!='V')
		count++;
	if(str[10]!='A')
		count++;
	if(str[11]!='L')
		count++;
	if(str[12]!='2')
		count++;
	if(str[13]!='0')
		count++;
	if(str[14]!='1')
		count++;
	if(str[15]!='6')
		count++;

	cout<<count;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream> 
using namespace std; 
int main(){
	int N;
	cin >> N;
	for (int i=0; i<N; i++){
		int K, P;
		cin >> K >> P;
		if (0 == K%P){
			cout << P << endl;
		}
		else{
			cout << K%P << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3100
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// AtCoder_B
		Scanner sc = new Scanner(System.in);

		String S = sc.nextLine();
		String T = sc.nextLine();

		int ans = T.length();

		for(int i=0; i <= S.length()-T.length(); i++) {
			String SWk = S.substring(i, i+T.length());
			int cnt = 0;
			for(int j=0; j < T.length(); j++) {
				if(SWk.charAt(j) != T.charAt(j)) {
					cnt++;
				}
			}
			if(ans > cnt) {
				ans = cnt;
			}
		}

		System.out.println(ans);

	    // Scannerクラスのインスタンスをクローズ
		sc.close();
	}
}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define contains(v, t) (find(v.begin(), v.end(), t) != v.end())
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;

int sumOfDigit(int num) {
  int sum = 0;
  while (num > 0) {
    sum += num % 10;
    num /= 10;
  }
  return sum;
}

int main() {
  int n;
  cin >> n;
  int ans = INT_MAX;
  for(int i = 1; i <= n / 2; i++) {
    int j = n - i;
    ans = min(ans, sumOfDigit(i) + sumOfDigit(j));
  }
  cout << ans;
}


Measured memory_bytes: 256
fn readline() -> i64 {
    let reader = std::io::stdin();
    let mut line = String::new();
    let _l = reader.read_line(&mut line);
    let vec: Vec<&str> = line.split_whitespace().collect();
    let n: i64 = vec[0].parse().unwrap();
    return n;
}

fn main() {
    let mut done: bool = false;
    while !done {
        let a = readline();
        if 0 < a {
            let mut v = Vec::<i64>::new();
            let mut sum: i64 = 0;
            for _x in 0 .. a {
                let k = readline();
                //let xu: usize = x as usize;
                v.push(k);
                sum = sum + k;
            }
            v.sort();
            sum = sum - v[0] - v[(a - 1) as usize];
            sum = sum / (a - 2);
            println!("{}", sum);
        } else {
            done = true;
        }
    }
    //println!("{}", a);
}



Measured memory_bytes: 1088
#include<stdio.h>
int main(void){
 int value;
 int sum=0;
 int min,max;
 int current=0;
 int temp=100;
 int i;
scanf("%d %d %d",&value,&min,&max);
for(i=1;i<=value;i++){
  temp=i;
  current=0;
   while(temp>0){
       current+=temp%10;
       temp/=10;
   }
   if(current>=min && current<=max){ sum+=i;
                                   }
}
printf("%d",sum);
}

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

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;
const long long MOD = (long long)1e9 + 7;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    sort(begin(a), end(a));
    int ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            if(a[i] == a[j]){
                continue;
            }
            for(int k = j + 1; k < n; k++){
                if(a[j] == a[k]){
                    continue;
                }
                if(a[i] + a[j] <= a[k]){
                    break;
                }
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
#define INF 100000000
template<class T> inline bool chmax(T& a, T b)
 { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b)
 { if (a > b) { a = b; return 1; } return 0; }

using namespace std;

int main(){
  int i,j,k,flag=0;
  string s,t;
  char temp;

  cin >> s >>t;

  for(i=0;i<s.length();i++){
    temp=s[s.length()-1];
    for(j=s.length()-1;j>0;j--){
      s[j]=s[j-1];
    }
    s[0]=temp;
    if(s==t)flag =1;
  }

  if(flag) cout <<"Yes"<<endl;
  else cout<<"No"<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  double a,b,x;
  cin >> a >> b >> x;
  double v = a*a*b;
  if(x*2<=v){
    cout << atan((a*b*b)/(2*x))/PI*180.0 << endl;
  }else{
    cout << atan((a*a*b-x)*2/(a*a*a))/PI*180.0 << endl;
  }
}


Measured memory_bytes: 384
// 基本テンプレート
 
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
 
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int N, T;
int t[200010];
 
signed main() {
    cin >> N >> T;
    rep(i,0,N) cin >> t[i];

    int ans = T;
    rep(i,1,N) {
        ans += min(t[i] - t[i-1], T);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
vector<int> bfs(auto &G, int s) {
    int n = G.size();
    vector<int> d(n, -1);
    queue<int> q; q.push(s); d[s] = 0; while (q.size()) {
        int p = q.front(); q.pop();
        for (auto &v : G[p]) {
            if (~d[v])
                continue;
            d[v] = d[p] + 1;
            q.push(v);
        }
    }
    return d;
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, x, y; cin >> n >> x >> y; x--, y--;
    vector<vector<int> > G(n);
    for (int i = 0 ; i < n - 1;  i++)
        G[i].push_back(i + 1),
        G[i + 1].push_back(i);
    G[x].push_back(y);
    G[y].push_back(x);
    vector<vector<int> > d;
    for (int i = 0 ; i < n ; i++)
        d.push_back(bfs(G, i));
    vector<int> cnt(n, 0);
    for (int i = 0 ; i < n ; i++)
        for (int j = i + 1 ; j < n ; j++)
            cnt[d[i][j]]++;
    for (int i = 1 ; i< n ; i++)
        cout << cnt[i] << '\n';
}


Measured memory_bytes: 16128
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c,n;
	cin>>a>>b>>c;
	n=c-(a-b);
	cout<<(n<0?0:n)<<endl;
}


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

use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let H: usize = iterator.next().unwrap().parse().unwrap();
    let W: usize = iterator.next().unwrap().parse().unwrap();
    let h: usize = iterator.next().unwrap().parse().unwrap();
    let w: usize = iterator.next().unwrap().parse().unwrap();

    let ans = (H - h) * (W - w);
    return ans.to_string();
}


Measured memory_bytes: 2132
N=int(input())
cnt=0
p=0
S= [sorted(input())for i in range(N)]
for i in range(N):
  S[i]="".join(S[i])
S.sort()
for i in range(1,N):
  if S[i]==S[i-1]:
    cnt += 1
  else:
    p=p+(cnt+1)*cnt//2
    cnt=0
p=p+(cnt+1)*cnt//2
print(p)

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

int main(){
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    vector<int>c(n);
    c[0]=0;
    
    int mini=INT_MAX;
    for(int i=1;i<n;i++){
        mini=INT_MAX;
        for(int j=i-1;j>=max(i-k,0);j--){
            mini=min(mini,c[j]+abs(v[i]-v[j]));
        }
        c[i]=mini;
    }
    cout<<c[n-1];
    
    
    
}
        

Measured memory_bytes: 1024
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i != 0:
        if a[i] - a[i - 1] == 1:
            ans += c[a[i] - 2]
print(ans)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define forr(i,p,n) for(ll i=p;i<n;i++)
#define tam 4000
#define offset 8010
using namespace std;
typedef long long  ll;
typedef pair<int,int> ii;
typedef pair<ll,ii> iii;
typedef pair<map<ll,ll> ,ll> mi;
typedef pair<ii,ii> iiii;
typedef vector<ll> vi;
const ll MOD=1e9+7;
double val[4200];
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int n;
    cin>>n;
    forr(i,0,n)
    {
        cin>>val[i];
    }
    sort(val,val+n);
    val[1]=(val[0]+val[1])/2;
    forr(i,2,n)
    {
        val[i]=(val[i]+val[i-1])/2;
    }
    printf("%.6lf",val[n-1]);
}


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

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld; 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

struct gausselim
{
	ll cnt[61][2];
	int rank;
	ll cyc[61];
	ll tmp;
	void init()
	{
		for(int i = 0; i < 61; i++)
		{
			cyc[i] = cnt[i][0] = cnt[i][1] = 0;
		}
		rank = tmp = 0;
	}
	void addval(ll x)
	{
		for(int i = 0; i < 61; i++)
		{
			cnt[i][(x>>i)&1]++;
		}
	}
	void add(ll x)
	{
		tmp|=x;
		for(int i = 60; i >= 0; i--)
		{
			if(x&(1LL<<i))
			{
				if(cyc[i]==0)
				{
					cyc[i] = x;
					rank++;
					break;
				}
			}
			x = min(x, (x^cyc[i]));
		}	
	}
};

void solve()
{
	int n; cin>>n;
	vi a(n);
	for(int i=0;i<n;i++) cin>>a[i];
	string s; cin>>s;
	gausselim G;
	G.init();
	for(int i=n-1;i>=0;i--)
	{
		if(s[i]=='0')
		{
			G.add(a[i]);
		}
		else
		{
			int oldrank = G.rank;
			G.add(a[i]);
			if(G.rank!=oldrank)
			{
				cout<<1<<'\n'; return ;
			}
			else
			{
				continue;
			}
		}
	}
	cout<<0<<'\n';
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int t; cin>>t;
	while(t--) solve();
}


Measured memory_bytes: 3624
// Crt. 2020-01-07  10:08:32
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 3003
using namespace std;
const int Mod = 1e9 + 7;

inline void inc(int &x, int y) {
    x += y, x -= x >= Mod ? Mod : 0;
}

inline int MOD(const int &x) {
    return x >= Mod ? x - Mod : x;
}

int n, m, f[N][N][2];

int main(){
#ifdef LOCAL_JUDGE
    freopen("work.in", "r", stdin);
    freopen("work.out", "w", stdout);
#endif

    cin >> n >> m;

    f[0][0][1] = 1;
    for (int i = 1; i <= n; ++i)
        f[0][i][0] = 1;

    for (int i = 0; i <= m; ++i) {
        for (int j = 0; j <= n; ++j) {
            for (int k = 0; k <= 1; ++k) {
                if (0 < j) {
                    inc(f[i + 1][j][k | (j == 1)], f[i][j][k]);
                    inc(f[i + 1][j - 1][k | (j == 1)], f[i][j][k]);
                }
                if (j < n) {
                    inc(f[i + 1][j][k], f[i][j][k]);
                    inc(f[i + 1][j + 1][k], f[i][j][k]);
                }
            }
        }
    }

//    for (int i = 1; i <= m; ++i)
//        for (int j = 0; j <= n; ++j)
//            for (int k = 0; k <= 1; ++k)
//                cout << i << " " << j << " " << k << " " << f[i][j][k] << endl;

    int ans = 0;
    for (int i = 0; i <= n; ++i)
        inc(ans, f[m][i][1]);

    cout << ans << endl;

	return 0;
}


Measured memory_bytes: 70656
#include <cstdio>
int H,W,a[210][210],f[210][210][210];
bool vis[210][210][210];
int F(int x1,int y1,int x2,int y2){
	if(x1>=H||y1>=W||x2>=H||y2>=W)return 0;
	if(x1==H-1&&y1==W-1&&x2==H-1)return a[x1][y1];
	if(vis[x1][y1][x2])return f[x1][y1][x2];
	vis[x1][y1][x2]=1;
	int&g=f[x1][y1][x2];
	g=0;
	for(int d1=0;d1<2;d1++){
		for(int d2=0;d2<2;d2++){
			int tmp=F(x1+d1,y1+1-d1,x2+d2,y2+1-d2);
			if(tmp>g)g=tmp;
		}
	}
	g+=x1==x2&&y1==y2?a[x1][y1]:a[x1][y1]+a[x2][y2];
	return g;
}
int main(){
	scanf("%d%d",&H,&W);
	for(int i=0;i<H;i++)for(int j=0;j<W;j++)scanf("%d",a[i]+j);
	printf("%d\n",F(0,0,0,0));
}

Measured memory_bytes: 42624
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	vector<int> v(3);
	int s;
	CIN3(v[0], v[1], v[2]);
	s = v[0] + v[1] + v[2];
	if(s % 2 == 1){
		COUT("No");
		return 0;
	}
	s /= 2;
	if(v[0] == s || v[1] == s || v[2] == s) {
		COUT("Yes");
	} else COUT("No");

}


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

int tot;
string s;

int main() {
    cin >> s;
    for (int i = 0; i < s.length(); i++){
        tot += s[i]-'0';
    }
    if (tot % 9 == 0) cout << "Yes\n";
    else cout << "No\n";
}


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

x1 = sum(A) - 2 * sum(A[1::2])
ans = []
ans.append(x1)
for i in range(N-1):
    x1 = 2 * A[i] - x1
    ans.append(x1)
print(*ans)

Measured memory_bytes: 15432
#include<iostream>
#include<string.h>
using namespace std;
int main()
{
    int a,b,c,i,count=0;
    cin>>a>>b>>c;
    for(i=a;i<=b;i++)
    {
       if(i%c==0)
       count++;
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3608
n = int(input())
line = list(map(int, input().split()))
money = 1000
stock = 0

for i in range(n-1):
  if stock == 0:
    if line[i] < line[i+1]:
      buy_stock = money // line[i]
      stock += buy_stock
      money -= buy_stock * line[i]
  else:
    if line[i] > line[i+1]:
      get_money = stock * line[i]
      money += get_money
      stock = 0

money += stock * line[n-1]
print(money)

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using namespace std;
int n,x,f[3];
int main()
{
	cin>>n;
	for (int i=1;i<=n;++i)
	{
		cin>>x;
		if (x%4==0)
			++f[2];
		else
		{
			if (x%2==0)
				++f[1];
			else
				++f[0];
		}
	}
	if (f[0]>f[2]+1||((f[0]==f[2]+1)&&f[1]))
		puts("No");
	else
		puts("Yes");
	return 0;
}

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

import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	Scanner sc = new Scanner(System.in);

	int INF = 1 << 28;
	double EPS = 1e-9;

	int n, r;
	int[] a,b;
	
	void run() {
		for(;;){
			n=sc.nextInt();
			r=sc.nextInt();
			if((n|r)==0){
				break;
			}
			a=new int[n];
			b=new int[n];
			for(int i=0;i<n;i++){
				a[i]=n-i;
			}
			for(int k=0;k<r;k++){
				System.arraycopy(a, 0, b, 0, n);
				int p=sc.nextInt();
				int c=sc.nextInt();
				for(int i=0;i<c;i++){
					a[i]=b[p-1+i];
				}
				for(int i=0;i<p-1;i++){
					a[c+i]=b[i];
				}
				// debug(a);
			}
			println(""+a[0]);
		}
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s) {
		System.out.print(s);
	}

	void println(String s) {
		System.out.println(s);
	}

	public static void main(String[] args) {
		// System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		new Main().run();
	}
}

Measured memory_bytes: 12000
import math


def resolve():
    import sys
    input = sys.stdin.readline
    row = [int(x) for x in input().rstrip().split(" ")]
    a = row[0]
    b = row[1]

    x = (b-1) / (a-1)
    print(math.ceil(x))




if __name__ == "__main__":
    resolve()


Measured memory_bytes: 8980
#include <stdio.h>
int main(){
	char str[4];
	int count = 0;
	scanf("%s", str);
	for(int i = 0; i < 3; i++)
		if(str[i] == 'R')
			count++;
	if(count != 2)
		printf("%d", count);
	else{
		for(int i = 0; i < 3; i++)
			if(str[i] == 'S')
              if(i == 1)
				printf("1");
              else
			    printf("2");
	}
	return 0;
}

Measured memory_bytes: 1724
N = int(input())
S = input()
total = S.count("R") * S.count("G") * S.count("B")
sub = 0
for i in range(N):
    for j in range(i + 1, N):
        if S[i] == S[j]:
            continue
        h = j + j - i
        if h > N - 1 or S[j] == S[h] or S[h] == S[i]:
            continue
        sub += 1
print(total - sub)

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

using namespace std;

int main()
{
  int n;
  cin>>n;
  int niza[n];
  int sorted[n];
  for(int i=0; i<n; i++)
  {
    cin>>niza[i];
    sorted[i]=niza[i];
  }
  sort(sorted,sorted+n);
  int cnt=0;
    for(int i=0; i<n ;i++)
  {
      if(niza[i]!=sorted[i])cnt++;
  }
  if(cnt>2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 256
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n,k;
  cin >> n >> k;
  vector<int>p(n);
  rep(i,n)cin >> p.at(i);
  vector<double>c(n);
  vector<double>d(n);
  
  double allsum =0;
  rep(i,n){
    double sum =0;
    double count=0;
    for(int j=1;  j<= p.at(i) ;j++){
      sum += j;
      count ++;
    }
    c.at(i) = sum / count;
    allsum += sum / count;
    d.at(i) = allsum;
  }
/*  rep(i,n) cout << c.at(i) <<" | ";
  cout << endl;
  rep(i,n) cout << d.at(i) <<" | ";
  cout << endl;
  */

  double ma =0;
  ma = max(ma, d.at(k-1));
//  cout << d.at(k-1) <<" | ";
  
  int countB = 0;
  for(int i=k; i<n; i++){   
//    cout << d.at(i) -d.at(countB) <<" | ";
    ma = max(ma, d.at(i) - d.at(countB) );
       countB ++;
  }
//  cout << endl;
  printf("%.10f\n", ma);
}

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

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

	ll ans = (b*(n - 1) + a) - (a*(n - 1) + b) + 1;
	if (ans < 0) {
		ans = 0;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
using namespace std;
//_____
#define pb emplace_back
#define fi first
#define se second
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__)
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
#define let const auto
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3fLL
#define NIL -1
//_______

int N, m;
vector <pii> G[10010];
bool vis[10010];

int MST()
{
   priority_queue< pii, vector<pii>, greater<pii> >pq;
   pq.emplace( pii(0,0) );
   int sum = 0;

   while (!pq.empty()) {
      let tmp = pq.top(); pq.pop();
      if ( vis[tmp.se]++ ) continue;
      sum += tmp.fi;
      for(let e: G[tmp.se])
         pq.emplace(e);
   }
   return (sum);
}


signed main()
{
   FAST();
   cin >> N >> m;

   while (m--) {
      int a, b, c;
      cin >> a >> b >> c;
      G[a].pb(pii(c,b));
      G[b].pb(pii(c,a));
   }

   outl( MST() );
}




Measured memory_bytes: 7892
needs = [int(input()) for _ in range(5)]

ans = 0
min_wait = 99
for t in needs:
    wait = t % 10
    if wait == 0:
        ans += t
    else:
        min_wait = min(min_wait, t % 10)
        ans += (t // 10 + 1) * 10
if min_wait != 99:
    ans = ans - 10 + min_wait

print(ans)


Measured memory_bytes: 2940
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const double PI=3.14159265358979323846;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int w,h,n;
  cin>>w>>h>>n;
  int a1=0,a2=w,a3=0,a4=h;
  rep(i,n){
    int x,y,a;
    cin>>x>>y>>a;
    if(a==1){
      chmax(a1,x);
    }
    else if(a==2){
      chmin(a2,x);
    }
    else if(a==3){
      chmax(a3,y);
    }
    else{
      chmin(a4,y);
    }
  }
  if(a2<a1 || a4<a3){
    cout<<0<<'\n';
  }
  else{
    w-=a1+(w-a2);
    h-=a3+(h-a4);
    cout<<h*w<<'\n';
  }
  return(0);
}


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

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

	int r, D, x;
	cin >> r >> D >> x;

	int a = x;
	for( int i = 0; i < 10; ++i ) {
		a = r*a - D;
		cout << a << '\n';
	}

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
struct edge{ll to, cost;};
typedef pair<ll,ll> P;
struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    rep(i,V){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    rep(i,V){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};
class UnionFind
{
public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
 
  UnionFind(int n) {
    init(n);
  }
 
  void init(int n) {
    for(int i=0; i<n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
 
  int root(int x) {
    if(par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
 
  bool same(int x, int y) {
    return root(x) == root(y);
  }
 
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if(x == y) return;
 
    if(depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if(depth[x] == depth[y])
        depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
} 
int main(){
string s; cin>>s;
ll n = s.size();
ll g=0, p = 0;
ll ca = 0;
if(n%2==0){
for(ll i=0; i<n/2; i++){
if(s.at(i)=='p') ca--;
}
for(ll i=n/2; i<n; i++){
if(s.at(i)=='g') ca++;}
cout << ca << endl;}
else{
for(ll i=0; i<n/2+1; i++){
if(s.at(i)=='p') ca--;
}
for(ll i=n/2+1; i<n; i++){
if(s.at(i)=='g') ca++;}
cout << ca << endl;}}

Measured memory_bytes: 3696
#!/usr/bin/env python3

import itertools
import math


EPS = 1e-6


def dot(a, b):
    return a.real * b.real + a.imag * b.imag


def enclose_triangle(p1, p2, p3):
    v12 = p2 - p1
    v23 = p3 - p2
    v31 = p1 - p3
    an1 = dot(v12, -v31)
    an2 = dot(-v12, v23)
    an3 = dot(-v23, v31)
    if an1 < 0 + EPS or an2 < 0 + EPS or an3 < 0 + EPS:
        vx = max(v12, v23, v31, key=abs)
        rad = abs(vx) / 2
        if vx == v12:
            cent = (p1 + p2) / 2
        elif vx == v23:
            cent = (p2 + p3) / 2
        else:
            cent = (p3 + p1) / 2
    else:
        a = p1
        b = p2
        c = p3
        a2 = abs(v23) ** 2
        b2 = abs(v31) ** 2
        c2 = abs(v12) ** 2
        u = a2 * (b2 + c2 - a2) * a + b2 * (c2 + a2 - b2) * \
            b + c2 * (a2 + b2 - c2) * c
        u /= a2 * (b2 + c2 - a2) + b2 * (c2 + a2 - b2) + c2 * (a2 + b2 - c2)
        rad = abs(u - p1)
        cent = u
    return rad, cent


def enclose_points(n, ps):
    assert n >= 2
    if n == 2:
        return abs(ps[1] - ps[0]) / 2
    for p1, p2, p3 in itertools.combinations(ps, 3):
        rad_cand, cent_cand = enclose_triangle(p1, p2, p3)
        for q1 in ps:
            dist = abs(cent_cand - q1)
            if dist >= rad_cand + EPS:
                break
        else:
            return rad_cand


def main():
    n = int(input())
    ps = []
    for _ in range(n):
        x, y = (float(z) for z in input().split())
        ps.append(complex(x, y))
    res = enclose_points(n, ps)
    print("{:.16f}".format(res))


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  double L; cin >> L;
  double result = pow(L/3,3);
  cout << setprecision(10) << result << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace Csharp_practice{
    class Program{
        static void Main(string[] args){
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            int[] ar = new int[n];
            int ans = 0;
            for (int i = 0; i < n; i++)
            {
                ar[i] = int.Parse(str[i]);
            }

            for (int i = 1; i < n-1; i++)
            {
                if((ar[i] - ar[i-1])*(ar[i]-ar[i+1]) <0)
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);
        }

        
    }
}


// string[] str = Console.ReadLine().Split(' ');

Measured memory_bytes: 11092
#include <iostream>
#include <climits>
#include <memory.h>
#include <random>
#include <ctime>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <bitset>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
#ifdef LOCAL
    #define DEBUG(x) { cerr << "# " << #x << ": " << x << endl;}
#else
    #define DEBUG(x)
#endif
mt19937_64 mt(time(0));
/*++++++++++++++++++++++++++++++++++++coding area start+++++++++++++++++++++++++++++++++++++++++*/
const int MAXN = 2e5 + 10;
const LL inf = 1e11;
LL nums[MAXN];




/*-------------------------------------coding area end------------------------------------------*/
int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout.precision(10); cout << fixed;
    #ifdef LOCAL
//        freopen("../test.txt", "r", stdin);
//        freopen("../output.txt", "w", stdout);
    #endif
/*++++++++++++++++++++++++++++++++++++coding area start+++++++++++++++++++++++++++++++++++++++++*/

    int n; cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> nums[i];
        nums[i] -= i;
    }
    sort(nums+1, nums+n+1);
    int m = (n+1) / 2;
    LL ret = 0;
    for (int i = 1; i <= n; i++) {
        ret += abs(nums[m] - nums[i]);
    }
    cout << ret << endl;





/*-------------------------------------coding area end------------------------------------------*/

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


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

void solve()
{
	int a, b, c, d;
	while(cin >> a >> b >> c >> d)
	{
		int e, f, g, h;
		cin >> e >> f >> g >> h;
		int sum1 = a + b + c + d;
		int sum2 = e + f + g + h;
		if(sum1 >= sum2)
		{
			cout << sum1 << endl;
		}
		else
		{
			cout << sum2 << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 1164