akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint x, y, z;
    cin >> x >> y >> z;
    lint n = x + y + z;
    struct abc {
        lint amb, a, b, c;
        bool operator<(const abc &rhs) const { return amb > rhs.amb; };
    };
    vector<abc> abcs;
    for (int i = 0; i < n; ++i) {
        lint a, b, c;
        cin >> a >> b >> c;
        abcs.push_back({a - b, a, b, c});
    }
    sort(abcs.begin(), abcs.end());
    vector<lint> ac(n, 0), bc(n, 0);
    priority_queue<abc> pq;
    for (int i = 0; i < n; ++i) {
        if (i)
            ac[i] += ac[i - 1];
        pq.push({abcs[i].a - abcs[i].c, abcs[i].a, abcs[i].b, abcs[i].c});
        ac[i] += abcs[i].a;
        if ((int)pq.size() > x) {
            auto t = pq.top();
            pq.pop();
            ac[i] -= t.a;
            ac[i] += t.c;
        }
    }
    priority_queue<abc> pq2;
    for (int i = n - 1; i >= 0; --i) {
        if (i != n - 1)
            bc[i] += bc[i + 1];
        pq2.push({abcs[i].b - abcs[i].c, abcs[i].a, abcs[i].b, abcs[i].c});
        bc[i] += abcs[i].b;
        if ((int)pq2.size() > y) {
            auto t = pq2.top();
            pq2.pop();
            bc[i] -= t.b;
            bc[i] += t.c;
        }
    }
    lint ret = 0;
    for (int i = x - 1; i < n - y; ++i) {
        ret = max(ret, ac[i] + bc[i + 1]);
    }
    cout << ret << "\n";
    return 0;
}

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

#define maxn 100010
#define INF 1e15
#define ff first
#define ss second
#define endl '\n'
typedef long long ll;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s, t;
	cin >> s >> t;
	int n = s.size();
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (s[i] == t[i]) ++cnt;
	}
	cout << cnt << endl;
}

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

int main(){
	long long n,ans=0;
	string s;
	map<string,long long> co;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		sort(s.begin(),s.end());
		auto itr=co.find(s);
		if(itr!=co.end()){
			ans+=co[s];
			co[s]++;
		}else{
			co[s]=1;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136
#include <iostream>
using namespace std;
int main (){
	int a, b, c, x;
	cin >> a >> b >> c >> x;
	int count = 0;
	for (int i = 0; i <= a; i++){
		for (int j = 0; j <= b; j++){
			for (int k = 0; k <= c; k++){
				if (500*i+100*j+50*k==x) count++;
			}
		}
	}
	cout << count << endl;
	return 0;
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;
using ld = long double;
const int MOD = 1e9+7;


int main() {
    int a, b; cin >> a >> b;
    cout << max({a+b, a*b, a-b}) << endl;

    return 0;
}


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

#define forsn(i,s,n) for(tint i=(s);i<(tint)(n); i++)
#define forn(i,n) forsn(i,0,n)
#define dforn(i,n) for(tint i = tint(n)-1; i >= 0; i--)
#define debug(x) cout << #x << " = "  << x << endl

using namespace std;

typedef long long tint;

random_device rd;
mt19937 gen(rd());

uniform_int_distribution<tint> dis(1, 10000);

void imprimirVector (vector<tint> v)
{
	if (!v.empty())
	{ 
		tint p = tint(v.size());
		cout << "[";
		forn(i,p-1)
			cout << v[i] << ",";
		cout << v[p-1] << "]" << endl;
	}
	else
		cout << "[]" << endl;
}

int main()
{
	#ifdef ACMTUYO
		assert(freopen("entrada.in", "r", stdin));
	#endif
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	tint n,x,y;
	while (cin >> n >> x >> y)
	{
		x--;
		y--;
		vector<tint> d(n);
		forn(j,n)
		forn(i,j)	
			d[min(j-i,abs(i-x)+1+abs(j-y))]++;
		forsn(r,1,n)
			cout << d[r] << "\n"; 
		
		
	}
	
	
	return 0;
}






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

#define ll long long int
#define vl vector<ll>
#define vvl vector<vl>
#define INF 1e12

int main() {

    ll N, K;
    cin >> N >> K;

    vl A;
    ll a;
    for (ll i = 0; i < N; i++) {
        cin >> a;
        A.push_back(a);
    }

    sort(A.begin(), A.end());

    ll m = 1e9+7;
    vector<ll> modinv(1e5+9);
    modinv[1] = 1;
    for (int i = 2; i <= N; i++) {
        modinv[i] = modinv[m%i] * (m-m/i) % m;
    }

    ll max_sum = 0;
    ll min_sum = 0;
    ll cmb = 1;
    for (int i = K; i <= N; i++) {
        // cout << i << " " << cmb << endl;
        max_sum += (A[i-1] * cmb);
        max_sum %= m;
        min_sum += (A[N-i] * cmb);
        min_sum %= m;
        cmb *= i;
        cmb %= m;
        cmb *= modinv[i-K+1];
        cmb %= m;
    }

    if (max_sum - min_sum >= 0) {
        cout << (max_sum - min_sum) % m << endl;
    }
    else {
        cout << max_sum - min_sum + m << endl;
    }

    return 0;
}


Measured memory_bytes: 1908
#include<iostream>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
using ll = long long;
#define what(x) cerr << #x << " is " << x << endl;

int main(){
    int N;
    cin >> N;
    set<int> d;
    for(int i = 0; i < N; ++i) {
        int x;
        cin >> x;
        d.insert(x);
    }
    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main()
{
    int n, sum;

    while (true){
        int cnt = 0;

        scanf(" %d %d", &n, &sum);
        if (n == 0 && sum == 0){
            break;
        }

        for (int i = 1; i <= n - 2; i++){
            for (int j = i + 1; j <= n - 1; j++){
                for (int k = j + 1; k <= n; k++){;
                    if (i + j + k == sum){
                        cnt++;
                    }
                }
            }
        }
        
        printf("%d\n", cnt);
    }
    
    return 0;
}
        

Measured memory_bytes: 1028
#include <bits/stdc++.h>                                                                        
                                                                                                
using namespace std;                                                                            
                                                                                                
#define all(x) x.begin(), x.end()                                                               
#define rep(i, n) for (int i = 0; i < n; ++i)                                                   
#define reps(i, m, n) for (int i = m; i <= n; ++i)                                              
                                                                                                
using i64 = long long;                                                                          
using pii = pair<i64, i64>;                                                                     
                                                                                                
template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}      
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}      
                                                                                                
constexpr int INF = 0x3f3f3f3f;                                                                 
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;                                                      
constexpr int MOD = int(1e9) + 7;                                                               
                                                                                                
signed main()                                                                                   
{                                                                                               
  ios::sync_with_stdio(false);                                                                  
  cin.tie(nullptr);                                                                             
                                                                                                
  int a, b, c;                                                                                  
  cin >> a >> b >> c;                                                                           
                                                                                                
  cout << (b-a == c-b ? "YES" : "NO") << "\n";                                                  
                                                                                                
  return 0;                                                                                     
}                                                                                               

Measured memory_bytes: 256
#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 n,k,d,a;
bool snake[120];
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>>n>>k;
	for(int i=1;i<=k;i++){
		cin>>d;
		while(d--){
			cin>>a;
			snake[a]=true;
		}
	}
	int num=0;
	for(int i=1;i<=n;i++)
		num+=(snake[i]==false);
	cout<<num<<endl; 
	return 0;
}


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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> s[i] >> c[i];
        s[i]--;
    }

    for (int i = 0; i <= pow(10, N); i++) {
        string n = to_string(i);
        if ((int)n.length() != N)
            continue;

        bool ok = true;
        for (int k = 0; k < M; k++) {
            if (n[s[k]] - '0' != c[k]) {
                ok = false;
            }
        }

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


Measured memory_bytes: 764
n = int(input())
num_list = input().split()

mod_value = 10**9 + 7
sum_all = 0
sum_int = 0

for index in range(len(num_list) - 1):
  sum_int += int(num_list[index])
  sum_all += sum_int * int(num_list[index + 1])
  if sum_all > mod_value:
    sum_all %= mod_value

print(sum_all)


Measured memory_bytes: 25108
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
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; }

int main(){
	int n; cin >> n;
	int conti = 0;
	bool ok = false;
	rep(i,0,n){
		int a,b; cin >> a >> b;
		if(a == b){
			conti++;
			if(conti == 3){
				ok = true;
			}
		}else{
			conti = 0;
		}
	}
	if(ok){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		if (S.length() == 2)
			System.out.println(S);
		else
			System.out.println(S.charAt(2) +"" +S.charAt(1)+"" +S.charAt(0));
	}
}	


Measured memory_bytes: 21332
#include"bits/stdc++.h"
using namespace std;
int main(){
    // input
    int H,W;
    cin >> H >> W;
    string S[50];
    for(int i=0; i<H; i++) cin >> S[i];

    // initialize
    int white = 0;
    int cost[50][50];
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cost[i][j] = 3000;
            if(S[i][j] == '.') white++;
        }
    }
    
    // bfs
    int dy[4] = {-1,1,0,0};
    int dx[4] = {0,0,-1,1};
    queue<pair<int,int>> que;
    cost[0][0] = 1;
    que.push(make_pair(0,0));
    while(!que.empty()){
        int y = que.front().first;
        int x = que.front().second;
        que.pop();
        for(int i=0; i<4; i++){
            if(y+dy[i] < 0 || y+dy[i] >= H || x+dx[i] < 0 || x+dx[i] >= W) continue;
            if(S[y+dy[i]][x+dx[i]] == '#') continue;
            if(cost[y+dy[i]][x+dx[i]] > cost[y][x]+1){
                cost[y+dy[i]][x+dx[i]] = cost[y][x]+1;
                que.push(make_pair(y+dy[i],x+dx[i]));
            }
        }
    }

    // output
    if(cost[H-1][W-1] == 3000) cout << -1 << endl;
    else cout << white - cost[H-1][W-1] << endl;
}

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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,k;
	cin >> n >> k;
	long long s;
	cin >> s;
	
	if(s<1000000000){
		vector<long long> res(n);
		for(int i=0;i<k;i++) res[i]=s;
		for(int i=k;i<n;i++) res[i]=s+1;
		
		for(int i=0;i<n;i++) cout << res[i] << " ";
		cout << "\n";
	}else{
		
		vector<long long> res(n);
		for(int i=0;i<k;i++) res[i]=s;
		for(int i=k;i<n;i++) res[i]=s-1;
		
		for(int i=0;i<n;i++) cout << res[i] << " ";
		cout << "\n";
	}
	return 0;
}

Measured memory_bytes: 2176
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
if (N % 10 == 9 or N // 10 == 9):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 27176
box=[list(map(int,input().split())) for i in range(3)]
flag=1
for j in range(3):
    checker=[]
    for i in range(3):
        if j==2:
            a11=box[j][i]-box[0][i]
        else:
            a11=box[j][i]-box[j+1][i]
        checker.append(a11)
    if checker.count(checker[0])==3:
        continue
    else:
        flag=0
        break

for j in range(3):
    checker=[]
    for i in range(3):
        if j==2:
            a11=box[i][j]-box[i][0]
        else:
            a11=box[i][j]-box[i][j+1]
        checker.append(a11)
    if checker.count(checker[0])==3:
        continue
    else:
        flag=0
        break
if flag:print("Yes")
else:print("No")

Measured memory_bytes: 3064
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    S = input().strip()
    ans="No"
    for i in range(len(S)):
        if S[i]=='7':
            ans="Yes"
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 78264
#include<iostream>
#include<cstdio>
using namespace std;
long long n,k,m,ans;
int main()
{
	cin>>n>>k;
if (k==0)
    {
        cout<<(long long)n*n<<endl;
        return 0;
    }
    
    for (int i=k+1;i<=n;i++)
    {
   
        m=n/i;
        ans+=(long long)(i-k)*m;
        ans+=max(n%i-k+1,0ll);
    }
    cout<<ans<<endl;
    return 0;
	}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<map>
#include<time.h>
#include<queue>
#include<algorithm>
#include<vector> 
#include<set>
using namespace std;
int main() {
	string s;
	int ans=0;
	cin>>s;
	for(int i=1;i<s.size();i++){
		if(s[i]!=s[i-1]){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include<iomanip>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define ffrvs(ii,nn,mm) for(int ii=nn;ii>=mm;ii--)
#define srt(vvv) sort(vvv.begin(),vvv.end())
#define srtrvs(vvv) reverse(vvv.begin(),vvv.end())
#define Graph vector<vector<int>>

i64 inf = 1000000007;
i64 giant = 4000000000000000037;

using namespace std;

i64 cup(i64 xxx, i64 yyy) {//切り上げ
	return (xxx + yyy - 1) / yyy;
}

//メモリ置き場
int n;
vector<int> hgt;
int top = 0;
int ans = 0;

//inputします
void input() {
	cin >> n;
	hgt.resize(n);
	ff(i, 0, n) {
		cin >> hgt[i];
		if (top <= hgt[i]) {
			ans++;
			top = hgt[i];
		}
	}
}

//ライブラリ置き場



//main
int main() {
	input();

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

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int y = sc.nextInt();
		int man_bill = -1;
		int gosen_bill = -1;
		int sen_bill = -1;
		final int man = 10000;
		final int gosen = 5000;
		final int sen = 1000;
		
		for (int i=0; i<=n; i++) {
			for (int j=0; j+i<=n; j++) {
				int c= n-j-i;
				int tot = i*man + j*gosen + c*sen;
				if (y == tot) {
					man_bill = i;
					gosen_bill = j;
					sen_bill = c;
				}
			}
		}
		
		System.out.println(man_bill + " " + gosen_bill + " " + sen_bill);
	}
}


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

int main(){
    int n;
    cin>>n;
    if(n>=64){
        cout<<"64";
    }else if(n>=32){
        cout<<"32";
    }else if(n>=16){
        cout<<"16";
    }else if(n>=8){
        cout<<"8";
    }else if(n>=4){
        cout<<"4";
    }else if(n>=2){
        cout<<"2";
    }else if(n>=1){
        cout<<"1";
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s,t;
  cin>>s;
  cin>>t;
  int count=0;
  for(int i=0;i<3;i++)
  {
    if(s[i]==t[i])
      count++;
 
  }
     cout<<count<<"\n";
  return 0;
}

Measured memory_bytes: 256
import sys
N,H=map(int,input().split(' '))
mdmg=0
mth=0
th=[]
for i in range(N):
  a,b=map(int,input().split(' '))
  if mdmg==a and mth>=b:
    th.append(mth)
    mth=b
  elif mdmg<a: 
    mdmg=a
    th.append(mth)
    mth=b
  else: th.append(b)
th.sort()
th.reverse()
count=0
for i in th:
  if(i>=H or mth>=H):
    count+=1
    print(count)
    sys.exit()
  elif i<mdmg:
    break
  else:
    count+=1
    H-=i
if mdmg>mth: mth=mdmg
H-=mth
if H%mdmg==0:
  count+=int(H/mdmg)+1
else:
  count+=int(H/mdmg)+2
print(count)

Measured memory_bytes: 55512
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	h, w := nextInt(), nextInt()
	var ans string
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if next() == "snuke" {
				ans = fmt.Sprintf("%s%d", string('A'+j), 1+i)
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import math
N,K=map(int,input().split())
tree=[]
ans=0
for i in range(N):
    tree.append(int(input()))
tree.sort()
#print(tree)
for i in range(N-K+1):
    if i==0:
        ans=tree[K+i-1]-tree[i]
        #print(ans)
    elif ans>=tree[K+i-1]-tree[i]:
        ans = tree[K + i - 1] - tree[i]
        #print(ans)
print(ans)


Measured memory_bytes: 50392
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<set>
#include<stack>
#include<cstdlib>
#include<algorithm>
#include<random>
#include<cassert>
using namespace std;
#define LL long long
#define ROOP() while(true)
int main(){
	ROOP(){
		LL n;
		cin >> n;
		if(n==0) break;
		vector<int> table;
		int first;
		cin >> first;
		table.push_back(1);
		int size = 1;
		
		for(LL i=2; i-1<n; i++){
			int ishi;
			cin >> ishi;
			if(i%2==1){ //奇数
				if(size%2==1){//firstと同じ
					if(ishi==first) table.back() += 1;
					else{
						table.push_back(1);
						size++;
					}
				}
				else{//firstの反対
					if(ishi!=first) table.back() += 1;
					else{
						table.push_back(1);
						size++;
					}
				}
			}
			else{ //偶数
				if(size%2==1){//firstと同じ
					if(ishi==first) table.back() += 1;
					else{
						int tmp = table.back();
						table.pop_back();
						size--;
						if(size<=0){
							table.push_back(0);
							first *= -1;
							first++;
							size++;
						}
						table.back() += tmp + 1;
					}
				}
				else{//firstの反対
					if(ishi!=first) table.back() += 1;
					else{
						int tmp = table.back();
						table.pop_back();
						size--;
						if(size<=0){
							table.push_back(0);
							first *= -1;
							first++;
							size++;
						}
						table.back() += tmp + 1;
					}
				}
			}
		}
		LL ans = 0;
		LL tmp;
		if(first == 0) tmp=0;
		else tmp=1;
		for(LL i=tmp; i<size; i+=2){
			ans += table.at(i);
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main()
{
    long long n;
    cin>>n;
    vector<long long> arr(n);
    map<long long,long long> mp;
    long long int sum=0;
    for(long long i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
        sum+=arr[i];
    }
    long long k;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        long long x,y;
        cin>>x>>y;
            sum=sum-(mp[x]*x)+(mp[x]*y);
            mp[y]=mp[y]+mp[x];
            mp[x]=0;
       cout<<sum<<endl;
    }
    return 0;
}


Measured memory_bytes: 9908
h, w = map(int, input().split())
grid = [str(input()) for _ in range(h)]
dp = [[0] * 1050 for _ in range(1050)]
MOD = int(1e9+7)
dp[0][0] = 1
for i in range(h):
    for j in range(w):
        if i + 1 < h and grid[i+1][j] == '.':
            dp[i+1][j] += dp[i][j]
        if j + 1 < w and grid[i][j+1] == '.':
            dp[i][j+1] += dp[i][j]
        dp[i][j] %= MOD
print(dp[h-1][w-1])

Measured memory_bytes: 165236
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define mymalloc(p,n) {p = malloc((n)*sizeof(*p));if ((p)==NULL) {printf("not enough memory?\n"); exit(1);};}

typedef struct{
	double x;
	double y;
}point;


void setPoint(point *p,double x,double y){
	p->x=x;
	p->y=y;
}

void printPoint(point p){
	printf("%lf %lf\n",p.x,p.y);
}



point plus(point p,point q){
	point r;
	r.x=p.x+q.x;
	r.y=p.y+q.y;
	return r;
}

point scal(double a,point p){
	point r;
	r.x=a*p.x;
	r.y=a*p.y;
	return r;
}


point minus(point p){
	return scal(-1,p);
}


point calcU(point s,point t){
	point half,u,delta,delta2;
	half=scal(1/2.0,plus(s,t));
	delta=plus(t,minus(s));
	delta2.y=delta.x;
	delta2.x=-delta.y;
	delta2=scal(sqrt(3)/2.0,delta2);
	u=plus(half,delta2);
	return u;
}

void koch(point p1,point p2,int n){
	point s,u,t;
	if(n==0){
		printPoint(p1);
	}
	else{
		s=plus(p1,scal(1/3.0,plus(p2,minus(p1))));
		t=plus(p1,scal(2/3.0,plus(p2,minus(p1))));
		u=calcU(s,t);
		koch(p1,s,n-1);
		koch(s,u,n-1);
		koch(u,t,n-1);
		koch(t,p2,n-1);
	}
}

main(){
	int n;
	point p1,p2;
	setPoint(&p1,0,0);
	setPoint(&p2,100,0);
	scanf("%d",&n);
	koch(p1,p2,n);
	printPoint(p2);
	return 0;
}
	

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    int n, x, t;
    cin >> n >> x >> t;
    cout << ((n - 1) / x + 1) * t << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
void rp(int &n, int m){
  n = min(n, m);
}
struct S{
  int u, t, p;
  S(int u, int t, int p) :
    u(u), t(t), p(p) {}
  S() {}
  bool operator < (const S& s) const{
    return t > s.t;
  }
};

int main(){
  int n, m;
  while(cin>>n>>m && n){
    int d[100][100];
    REP(i, n)REP(j, n)d[i][j] = INF;
    REP(i, m){
      int u, v, c; cin>>u>>v>>c;
      u--; v--;
      d[u][v] = c;
      d[v][u] = c;
    }
    int dist[100][2];
    REP(i, n)dist[i][0] = dist[i][1] = INF;
    dist[0][0] = 0;
    priority_queue<S> que;
    que.push(S(0, 0, 0));
    while(!que.empty()){
      S s = que.top(); que.pop();
      if(s.u == n-1){
        cout<<s.t<<endl;
        break;
      }
      REP(to, n) if(d[s.u][to] != INF){
        int nt = s.t + d[s.u][to];
        if(dist[to][s.p] > nt){
          dist[to][s.p] = nt;
          que.push(S(to, nt, s.p));
        }
        if(s.p < 1){
          REP(to2, n)if(d[to][to2] != INF){
            int nt = s.t;
            if(dist[to2][1] > nt){
              dist[to2][1] = nt;
              que.push(S(to2, nt, 1));
            }
          }
        }
      }
    }
  }
  return 0;
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    if(A%2==0 && A == B && B == C){
        cout << -1 << endl;
        return 0;
    }

    int ans = 0;
    while(true){
        if(A%2==1 || B%2==1 || C%2==1) break;
        int nA = (B+C)/2;
        int nB = (C+A)/2;
        int nC = (A+B)/2;
        A = nA;  B = nB;  C = nC;
        ans++;
    }
    cout << ans << endl;
}


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

int main(void)
{
    double x1, y1, x2, y2, d;
    scanf("%lf", &x1);
    scanf("%lf", &y1);
    scanf("%lf", &x2);
    scanf("%lf", &y2);

    d = sqrt(pow((x1 - x2), 2) + pow((y1 - y2), 2));

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

    return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <algorithm>
const int mod=1e9+7;
using LL=long long;
using std::cout;using std::endl;using std::cin;
using std::vector;using std::string;using std::set;using std::multiset;
using std::pair;using std::map;
using std::min;using std::max;
using std::make_pair;
std::ostream& operator<<(std::ostream& os,std::map<int,int>& obj){for(std::map<int,int>::iterator itr=obj.begin();itr!=obj.end();itr++){os<<itr->first<<"^"<<itr->second<<" ";}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<std::map<int,int>>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<std::endl;}return os;}
std::ostream& operator<<(std::ostream& os,std::vector<int>& obj){for(auto itr=obj.begin();itr!=obj.end();itr++){os<<*itr<<endl;}return os;}

namespace ndifix{
template<class T>void sort(T &v){std::sort(v.begin(),v.end());}
}

int main(){
  int a,b;cin>>a>>b;
  if(b%a==0)cout<<a+b<<endl;
  else cout<<b-a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;

int main() {
    int n , q, t = 0;
    cin >> n >> q;
    vector<pair<string, int> > queue(n+1);
    for(size_t i = 0; i < n; i++)
    {
        cin >> queue[i].first >> queue[i].second;
    }
    int begin = 0, end = n, i = 0;
    while(true) {
        if(queue[begin].second <= q) {
            t += queue[begin].second;
            cout << queue[begin].first << " " << t << endl;
            begin = (begin+1)%(n+1);
        } else {
            t += q;
            queue[begin].second -= q;
            queue[end] = queue[begin];
            begin = (begin+1)%(n+1);
            end = (end+1)%(n+1);
        }
        if(begin == end) break;
    }
}



Measured memory_bytes: 5956
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
int dx[]={-2,-2,-1,-1,1,1,2,2};
int dy[]={1,-1,2,-2,2,-2,1,-1};
int a[26],b[26];
int main(){
  int t;
  cin>>t;
  while(t--){
    int n,d;
    cin>>n>>d;
    if(n%2)cout<<(n-1)*127+d<<endl;
    else cout<<(n)*127-d<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

#include <numeric>
#include <algorithm>



using namespace std;

int main()
{

    int a;

    cin >> a;


    uint64_t ans = 0;

    for(int i = 1; i <= a; ++i)
        for(int j = 1; j <= a; ++j)
            for(int k = 1; k <= a; ++k)
            {
                if(i == j  && j == k && i == k)
                    ans += i;
                else
                    ans += gcd(i, gcd(j, k));
            
            }   

    cout << ans << "\n";

    return 0;
}

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

#define rep(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++i)
#define per(i, a, b) for (int i = (a), i##end = (b); i >= i##end; --i)

namespace IO {
    #define gc getchar()
    template <typename T>
    inline void read(T& x) {
        x = 0; bool f = 1; char ch;
        for (ch = gc; ch < '0' || '9' < ch; ch = gc) if (ch == '-') f ^= 1;
        for (; '0' <= ch && ch <= '9'; ch = gc) x = (x << 3) + (x << 1) + (ch ^ 48);
        x = f ? x : -x;
    }
    #undef gc
}

const int MAXN = 2000;
const int P = 1e9 + 7;

int f[MAXN], S;

int main() {
    IO::read(S);
    f[0] = 1;
    rep(i, 3, S) {
        per(j, i - 3, 0) (f[i] += f[j]) %= P;
    }
    printf("%d\n", f[S]);
    return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pi;
const int MAXN=105;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define db(x) cerr<<#x<<" = "<<x<<"\n"
#define LOW(v,x) (lower_bound(all(v),(x))-(v).begin())
 
const int MAXS=40005;
int N,K,S;
ll dp[MAXN][MAXS];
ll p[MAXN][MAXS];
ll x[MAXS];
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>K>>N;
	S=sqrt(K);
	dp[0][0]=1;
	FOR(s,1,S){
		dp[0][s]=0;
		p[0][s]=1;
	}
	FOR(s,1,S){
		dp[1][s]=1;
		p[1][s]=s;
	}
	FOR(i,2,N+1){
		DEC(s,S,1){
			if(K/(s+1)<S&&S<=K/s){
				x[s]=(x[s+1]+(ll)(K/s-S)*p[i-2][s]%MOD)%MOD;
			}
			else{
				x[s]=(x[s+1]+(ll)(K/s-K/(s+1))*p[i-2][s]%MOD)%MOD;
			}
			//~ FOR(j,ns+1,S){
				//~ if(K/(j+1)<S&&S<=K/j){
					//~ dp[i][s]=(dp[i][s]+(ll)(K/j-S)*p[i-2][j]%MOD)%MOD;
					//~ break;
				//~ }
				//~ dp[i][s]=(dp[i][s]+(ll)(K/j-K/(j+1))*p[i-2][j]%MOD)%MOD;
			//~ }
		}
		FOR(s,1,S){
			assert(K/s>=S);
			dp[i][s]=p[i-1][S];
			if(K/s==S)continue;
			int m=K/s;
			int ns=K/m;
			dp[i][s]=(dp[i][s]+x[ns+1])%MOD;
			dp[i][s]=(dp[i][s]+(ll)(m-K/(ns+1))*p[i-2][ns]%MOD)%MOD;
		}
		FOR(s,1,S)p[i][s]=(dp[i][s]+p[i][s-1])%MOD;
	}
	//~ FOR(i,1,N)FOR(s,1,S)cout<<dp[i][s]<<" \n"[s==S];
	cout<<dp[N+1][1]<<"\n";
}
/*
*/

Measured memory_bytes: 65408
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#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
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace std;
using namespace __gnu_pbds;
#define sim template < class c
#define int long long
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << '\n'; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef tree< pair<int,int>, null_type, less<pair<int,int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef long long ll;
const ll MOD = 1e9 + 7 ;
const ll N = 2e5 + 10 ;
const ll INF = 1e18 + 10 ;
int n , m , X ;
vector<vector<int> > v ;
vector<int> algo ;
vector<int> c ;
int cost = 0 ;
int answer = INF ;
void dfs(int x){
    debug() << imie(x) ;
    if ( x == n ){
        for(int i = 0; i < m; i++){
            if ( algo[i] < X ) return ;
        }
        answer = min(answer, cost) ;
        return ;
    }
    for(int i = 0; i < m; i++){
        algo[i] += v[x][i] ;
    }
    cost += c[x] ;
    dfs(x + 1) ;
    for(int i = 0; i < m; i++){
        algo[i] -= v[x][i] ;
    }
    cost -= c[x] ;
    dfs(x + 1) ;
}
signed main(){
    fastio
    cin >> n >> m >> X ;
    v = vector<vector<int> > (n, vector<int>(m));
    algo = vector<int>(m) ;
    c = vector<int>(n) ;
    for(int i = 0; i < n; i++){
        cin >> c[i] ;
        for(int j = 0; j < m; j++){
            cin >> v[i][j] ;
        }
    }
    dfs(0) ;
    if ( answer == INF ) cout << -1 << endl;
    else cout << answer << endl;
    return 0; 
}

Measured memory_bytes: 3616
import java.util.*;
import java.lang.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long d = sc.nextLong();
		int c=0;
		while(n-->0){
		    long x  = sc.nextLong();
		    long y = sc.nextLong();
		    double p = Math.sqrt(x*x + y*y);
		    if(p<=d) c++;
		}
		System.out.println(c);
	}
}


Measured memory_bytes: 60280
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
void _main()
{
    char X, Y;
    cin >> X >> Y;
    if (X < Y) cout << '<' << endl;
    else if (X > Y) cout << '>' << endl;
    else cout << '=' << endl;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,d;
	cin>>n>>d;
	vi in(n+1,d),t(n+1,d);
	rep(i,n)cin>>in[i+1];
	rep(i,n)t[i+1]=min(t[i],abs(t[i]-in[i+1]));
	
	vi out(n+1,1);
	for(int i=n;i>=1;i--){
		if(out[i]<=in[i]/2)out[i-1]=out[i];
		else out[i-1]=out[i]+in[i];
	}
	int q;cin>>q;
	while(q--){
		int a;cin>>a;
		if(t[a-1]&&t[a-1]>=out[a])cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
}








Measured memory_bytes: 7808
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define INF 1200000000


int main(){
    
    vector<string> S(111),ans(111);
    string con;
    int L,N;
    cin>>N>>L;
    rep(i,0,N)cin>>S.at(i);
    rep(i,0,N){
        rep(j,0,N-1){
            if(S.at(j)>S.at(j+1)){
                con = S.at(j+1);
                S.at(j+1)=S.at(j);
                S.at(j)=con;
            }
        }
    }

    rep(i,0,N){
    cout<<S.at(i);
    }
    cout<<endl;
}




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

using namespace std;

using ll=long long;
struct Dsu {
    int n;
    vector<int> p;
    vector<ll> r; // for weight now
    vector<int> cnt;
    
    Dsu(int _n) { n = _n; p.resize(n); r.resize(n); init(); }
    inline void init() {
        for (int i = 0; i < n; i++) {
            p[i] = i;
            r[i] = 1;
        }
        cnt.assign(n, 0);
    }
    inline int find(int x) {
        return p[x] == x ? x: p[x] = find(p[x]);
    }
    inline bool join(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (r[x] < r[y]) swap(x, y);
        p[y] = x; r[x] += r[y];
        cnt[x] += cnt[y];
        return true;
    }
    inline bool check(int x, int y) {
        return find(x) == find(y);
    }
    ll weight(int x) {
        return r[find(x)];
    }
    void add_unused_edge(int x) {
        cnt[find(x)]++;
    }
    int use_edge(int x) {
        int res = cnt[find(x)];
        cnt[find(x)] = 0;
        return res;
    }
};

struct Edge {
    int x, y, z;
    Edge() {}
    Edge(int _x, int _y, int _z) : x(_x), y(_y), z(_z) {}
    bool operator<(const Edge& _oth) const {
        return z < _oth.z;
    }
};

void solve() {
    int n,m;
    cin >> n >> m;
    Dsu d(n);
    for (int i = 0; i < n; i++) {
        cin >> d.r[i];
    }
    vector<Edge> es(m);
    for (int i = 0; i < m; i++) {
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        es[i] = {x,y,z};
    }
    sort(es.begin(), es.end());
    int res = 0;
    for (auto& e: es) {
        d.join(e.x,e.y);
        d.add_unused_edge(e.x);
        if (d.weight(e.x) >= e.z) {
            res += d.use_edge(e.x);
        }
    }
    res = m-res;
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <string.h>
#include <list>
#include <vector>
#include <deque>
#include <numeric>

using namespace std;
int main() {
	int n, x=0,m;
	for (int i = 0; i< 4; i++) {
		cin >> n;
		x += n;
	}
	m = x / 60;
	cout << m << endl << x - m * 60 << endl;

}

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

int sum[100001],p;
string s;

int main()
{
	cin >> s;
	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='R')
		{
			p=i;
			while(s[p]=='R') p++;
			if((p-i)%2) 
			{
				sum[p]+=(p-i)/2;
				sum[p-1]+=(p-i)/2;
			}
			else
			{
				sum[p]+=(p-i+1)/2;
				sum[p-1]+=(p-i-1)/2;
			}
			i=p;
		}
	}
	for(int i=s.length()-1;i>=0;i--)
	{
		if(s[i]=='L')
		{
			p=i;
			while(s[p]=='L') p--;
			if((i-p)%2)
			{
				sum[p+1]+=(i-p)/2+1;
				sum[p]+=(i-p)/2+1;
			}
			else
			{
				sum[p]+=(i-p+1)/2+1;
				sum[p+1]+=(i-p-1)/2+1;
			}
			i=p;
		}
	}
	for(int i=0;i<s.length();i++)
		cout << sum[i] << " ";
	cout << endl;
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i = 0; i < n; i++) {
        cin >> s.at(i);
    }

    int m;
    cin >> m;
    vector<string> t(m);
    for(int i = 0; i < m; i++) {
        cin >> t.at(i);
    }

    map<string, int> money;
    for(string ss : s) {
        money[ss]++;
    }
    for(string tt : t) {
        money[tt]--;
    }

    int max = 0;
    for(auto x : money) {
        if(x.second > max) {
            max = x.second;
        }
    }
    cout << max << endl;


}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <queue>
#include <queue>
#include <stack> 
#include <sstream>
#include <set>

typedef  long long ll;
const int dx[8]={1,0,-1,0,1,-1,-1,1};
const int dy[8]={0,1,0,-1,1,1,-1,-1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = { 0, 1, 0,-1};
const int INF = 1e9;
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
int guki (int a){
    if(a%2==0) return 0;
    else return 1;
}
int gcd(int a, int b){
    if(a%b==0){
        return b;
    }else{
        return (gcd(b,a%b));
    }
}
int lcm(int a, int b){
    int x = gcd(a,b);
    return (a*b/x);
}

using namespace std;
ll k (ll a){
    a--;
    ll ans =0;
    while(a != 0){
        ans += a;
        a--;
        
    }
    return ans;
}


char grid[505][505];
int h,w;
pair<int, int> st,en;
int score[505][505];

void bfs(int x, int y){
    queue<pair<int, int>> Q;
    score[x][y] = 0;

    Q.push(make_pair(x,y));

    while(!Q.empty()){
        pair<int ,int> p = Q.front(); Q.pop();
        int hh = p.second;
        int ww = p.first;

        REP(i,4){
            int nx = ww + dr[i];
            int ny = hh + dc[i];

            if(nx < 0 || w <= nx || ny < 0 || h <= ny){
                continue;
            }

            if(grid[nx][ny] == '#' && score[nx][ny] > (score[x][y]+1)){
                Q.push(make_pair(nx,ny));
                score[nx][ny] = score[x][y] +1;
            }

            if(score[nx][ny] > (score[x][y] +1)  && grid[nx][ny] != '#'){
                Q.push(make_pair(nx,ny));
                score[nx][ny] = score[x][y];
            }
        }
    }
}

int n,m;
int a[1500];

int dfs(int x,int cnt,int i){
    if(cnt == 0) return x;
    if(x >= m) return 0;

    x = max(x,dfs(x+a[i],cnt-1,i+1));
    return x;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1),b,c(n+1);
    FOR(i,1,n+1){
        cin >> a[i];
    }
    int ans = 0;
    for(int i = n; 0<i;i--){
        int x = 0;
        for(int j = i;j <=n;j+=i){
            x += c[j];
        }

        if(x %2 != a[i] ){
            c[i] = 1;
            ans ++;
        }
    }

    cout << ans <<endl;

    for(int i = 1; i<=n;i++){
        if(c[i] == 1){
            cout << i << " ";
        }
    }

    cout <<endl;
    
}



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

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

	int iminimum = 2018;
	for(int in=l; in<r; in++){
		for(int im=in+1; im<r+1; im++){
			int jn = in%2019;
			int jm = im%2019;
			iminimum = min(iminimum, (jn*jm)%2019 );
			if(iminimum==0) {
				cout <<0 <<endl;
				return 0;
			}
		}
	}
	cout <<iminimum <<endl;

	return 0;
}


Measured memory_bytes: 256
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp;

struct Scanner<'a> {
    cin : StdinLock<'a>,
}

impl<'a> Scanner<'a> {
    fn new(cin : StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read1<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn read<T: FromStr>(&mut self) -> T {
        self.read1().unwrap()
    }
}

fn main(){
	let cin = stdin();
	let cin = cin.lock();
	let mut sc = Scanner::new(cin);
	let n : usize = sc.read();
        let mut arr : Vec<usize>  = Vec::new();
        arr.push(0);
        for _ in 0..n {
            arr.push(sc.read());
        }
        let mut i = 1;
        let mut cnt = 0;
        loop {
            let next = arr[i];
            arr[i] = 0;
            match next {
                0 => {
                    cnt = 0;
                    break;
                },
                2 => {
                    cnt += 1;
                    break;
                },
                _ => {
                    i = next;
                    cnt += 1;
                }
            }
        }
        println!("{}", if cnt == 0 {
            -1
        } else {
            cnt
        });
}



Measured memory_bytes: 4352
#![allow(unused_macros, unused_imports, dead_code)]

use std::io;

fn read_line() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s
}

macro_rules! from_line {
    ($($a:ident : $t:ty),+) => {
        $(let $a: $t;)+
        {
            let _line = read_line();
            let mut _it = _line.trim().split_whitespace();
            $($a = _it.next().unwrap().parse().unwrap();)+
            assert!(_it.next().is_none());
        }
    };
}

fn read_vec() -> Vec<i32> {
    let line = read_line();
    let it = line.trim().split_whitespace();
    it.map(|s| s.parse().unwrap()).collect()
}

fn main() {
    from_line!(N: usize);
    let A0 = read_vec();
    let A1 = read_vec();

    let result = (0..N).map(|i| &A0[0..i+1].iter().sum::<i32>() + &A1[i..N].iter().sum::<i32>()).max().unwrap_or(0);
    println!("{}", result);
}

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

void solve(){
  ll a,b;
  scanf("%lld",&a);
  b=360;
  while(b%a != 0)
    b+=360;

  printf("%lld\n",b/a);
}
int main()
{
    // ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
 #ifndef ONLINE_JUDGE   
  freopen("input.txt",  "r",  stdin);
  freopen("output.txt", "w", stdout); 
 #endif
 
     int t=1; 
     // cin >> t;
     while (t--) solve();
 
     return 0;
}



Measured memory_bytes: 3784
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  int sum = 0;
  for(int i = 0, temp; i < m; ++i){
    cin >> temp;
    sum += temp;
  }
  cout << (sum <= n ? n - sum : -1) << endl;
}

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

int main(){
	ios::sync_with_stdio(0);
	cout << setprecision(10) << fixed;
	int s, w;
	cin >> s >> w;
	if (w >= s){
		cout << "unsafe";
	}
	else{
		cout << "safe";
	}
	return 0;
}



Measured memory_bytes: 3688