akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <complex>
#include <algorithm>
using namespace std;

typedef complex<double> p;
const double eps = 1e-9;

int n;
p ps[300];

int main() {
	while (cin >> n , n != 0) {
		for (int i = 0; i < n; i++) {
			double x, y;
			cin >> x >> y;
			ps[i] = p(x, y);
		}

		int ans = 1;
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j < n; j++) {
				if (!(norm(ps[i] - ps[j]) < 4.0)) continue;
				p v = ps[i] - ps[j], ve = v / abs(v);
				double l = sqrt(1 - norm(v) * 0.25);
				p vn1 = ve * p(0, 1) * l, vn2 = ve * p(0, -1) * l;
				p c1 = ps[j] + v * 0.5 + vn1, c2 = ps[j] + v * 0.5 + vn2;
				int count1 = 2, count2 = 2;
				for (int k = 0; k < n; k++) {
					if (k == i || k == j) continue;
					if (norm(c1 - ps[k]) < 1.0 + eps) count1++;
					if (norm(c2 - ps[k]) < 1.0 + eps) count2++;
				}
				ans = max(ans, count1);
				ans = max(ans, count2);
			}
		}

		cout << ans << endl;
	}
}

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

int main() {
    string S;
    cin >> S;
    int ans;
    if (S=="SSS") {
        ans = 0;
    }
    else if (S=="SRR" or S=="RRS") {
        ans = 2;
    }
    else if (S=="RRR") {
        ans = 3;
    }
    else {
        ans = 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector< vector<int> > Mat;
typedef tuple<int, int, int, int> T;

const int MOD = (int)1e9+7;
const int INF = (int)1e9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

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

    char x, y;
    cin >> x >> y;
    if(x < y) cout << "<" << endl;
    else if(x > y) cout << ">" << endl;
    else cout << "=" << endl;

    return 0;
}


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

res= 0
for aa in a:
    if aa%2==0:
        if aa %3 ==0:
            res+=1
            continue

        elif aa%5 ==0:
            res+=1
            continue
    else: 
        res+=1
        continue
            
if res==n:
    print ('APPROVED')
else:
    print('DENIED')



Measured memory_bytes: 3060
N, M = map(int, input().split())
A = []
B = []
C = []
D = []

for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

for i in range(M):
    c, d = map(int, input().split())
    C.append(c)
    D.append(d)

for i in range(N):
    m = 10**17
    for j in range(M):
        distance = abs(A[i]-C[j]) + abs(B[i]-D[j])
        if distance < m:
            m = distance
            ans = j+1

    print(ans)




Measured memory_bytes: 3064
def main():
    N = int(input())
 
    def judge(n):
        if n % 15 == 0 or n % 3 == 0 or n % 5 == 0:
            return 0
        else:
            return n
 
    result = [judge(x) for x in range(N + 1)]
    print(sum(result))
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 142468
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    const int MaxPayment = 100;

    public static void Main()
    {
        var n = int.Parse(Console.ReadLine());

        var xs = new bool[MaxPayment + 1];
        for (int i = 0; i < MaxPayment; i++)
        {
            int ii = i + 1;
            xs[ii] = ii >= 4 && xs[ii - 4] || ii >= 7 && xs[ii - 7] || ii % 4 == 0 || ii % 7 == 0;
        }
        Console.WriteLine(xs[n] ? "Yes" : "No");
    }
}

Measured memory_bytes: 13140
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int n,a=1;
  cin>>n;
  if(n==1)
    cout<<1<<endl;
  else{
    for(int i=0;i<100;i++){
      a*=2;
      if(a>n)
        break;
    }
    cout<<a/2<<endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[][] A = new int[2][N];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < N; j++) {
                    A[i][j] = in.nextInt();
                }
            }

            int[][] cumsum = new int[2][N];
            for (int i = 0; i < 2; i++) {
                for (int j = 0; j < N; j++) {
                    cumsum[i][j] = A[i][j] + (j - 1 >= 0 ? cumsum[i][j - 1] : 0);
                }
            }

            int max = 0;
            for (int j = 0; j < N; j++) {
                int row0 = cumsum[0][j];
                int row1 = cumsum[1][N - 1] - (j - 1 >= 0 ? cumsum[1][j - 1] : 0);
                max = Math.max(max, row0 + row1);
            }
            System.out.println(max);
        }
    }
}


Measured memory_bytes: 21844
package main

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

func main() {
	N := ReadInt()
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		m[ReadInt()]++
	}
	ans := 0
	for x, c := range m {
		if c >= x {
			ans += c - x
		} else {
			ans += c
		}
	}
	fmt.Println(ans)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


Measured memory_bytes: 8704
#include <bits/stdc++.h>
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define sz(v) (int)(v).size()
using namespace std;
using P = pair<int, int>;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	string s;
	cin >> s;
	if (s == "Sunny") cout << "Cloudy" << '\n';
	if (s == "Cloudy") cout << "Rainy" << '\n';
	if (s == "Rainy") cout << "Sunny" << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

#define MOD 1000000007
#define MAX_N 200

ll dp[MAX_N][MAX_N+1] = {0}; // dp[n][rest U] = ??´????????°

int main() {
	int N;
	char v[MAX_N];
	char buf[100];
	int sz = 0;
	ll ans = -1;
	int i, j;

	scanf("%d", &N);
	for (i = 0; i < N; ++i) {
		scanf("%s", buf);
		if (buf[0] != '-') v[sz++] = buf[0];
	}
	N = sz;

	if (N == 0) {
		ans = 1;
	}
	else if (v[0] == 'D') {
		ans = 0;
	}
	else {
		dp[0][1] = 1; // v[0] : 'U'
		for (i = 0; i < N-1; ++i) {
			for (j = 0; j < N; ++j) {
				if (v[i+1] == 'U') {
					dp[i+1][j+1] = (dp[i+1][j+1] + dp[i][j]) % MOD;
					if (j >= 1) {
						dp[i+1][j] = (dp[i+1][j] + j * dp[i][j]) % MOD;
					}
				}
				else { // D
					if (j >= 1) {
						dp[i+1][j] = (dp[i+1][j] + j * dp[i][j]) % MOD;
						dp[i+1][j-1] = (dp[i+1][j-1] + j * j * dp[i][j]) % MOD;
					}
				}
			}
		}
		ans = dp[N-1][0];
	}

	printf("%lld\n", ans);

	return 0;
}

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

int main() {
  int N;
  vector<int> L(100);
  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  
  int all = 0;
  for(int i = 0; i < N; i++) {
    all += L.at(i);
  }
  
  int longest = 0;
  for(int i = 0; i < N; i++) {
    if(L.at(i) > longest) {
      longest = L.at(i);
    }
  }
  
  int all2 = all - longest;
  
  if(all2 > longest) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

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

#define SZ(x) (((int)x.size()))

typedef long long ll;
typedef long double ld;

using namespace std;

int n;
ld sum, a;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		sum += (ld)1 / a;
	}
	cout << setprecision(10) << fixed << (ld)1 / sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define mod 1000000007
#define lol 200005
#define debug(x) cout<<#x<<" is "<<x<<endl;
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=b;i>=a;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vp vector<pair<double,double>>
#define vpp vector<pair<int, pair<int,int>>>
#define pp pair<int,int>

int dp[100005];

int fun(int A[], int n)
{
   dp[0]=0;
   dp[1]=abs(A[1]-A[0]);
   ffor(i,2,n+1)
   {
   	 dp[i] = min(abs(A[i]-A[i-1]) + dp[i-1] , abs(A[i]-A[i-2]) + dp[i-2]);
   }
   return dp[n];
}

int main()
{
	int n;
	cin>>n;
	int A[n];
	ffor(i,0,n) cin>>A[i];
	memset(dp,-1,sizeof(dp));
	cout<<fun(A,n-1)<<endl;
}

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

int n, m, k;
vector<string> a;

bool Read() {
  cin >> n;
  if (cin.eof())
    return 0;
  cin >> m >> k;
  a.resize(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];

  return 1;
}

void Process() {
  int rm = 0, cm = 0, ans = 0;
  while (rm < (1 << n)) {
    cm = 0;
    while (cm < (1 << m)) {
      vector<string> b = a;
      for (int i = 0; i < n; i++)
        if (rm & (1 << i))
          for (int j = 0; j < m; j++)
            b[i][j] = '.';
      for (int j = 0; j < m; j++)
        if (cm & (1 << j))
          for (int i = 0; i < n; i++)
            b[i][j] = '.';
      int ct = 0;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
          if (b[i][j] == '#')
            ct++;
      if (ct == k) 
        ans++;
      ++cm;
    }
    ++rm;
  }
  cout << ans << "\n";
}

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

  while (Read())
    Process();

  return 0;
}

Measured memory_bytes: 3660
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) int((a).size())
#define out(a) cout<<(a)<<endl;
const int INF=INT_MAX;
const int MAX = 510000;
const ll MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

int main(){
  ll n,ans=0;cin>>n;
  vll a(n);
  rep(i,0,n)cin>>a[i];
  for(int i=0;i<n;i+=2){
    if(a[i]%2){ans++;}
  }
  cout<<ans<<endl;
}







Measured memory_bytes: 3624
import sys

read = sys.stdin.read
readline = sys.stdin.readline

K, N, *A = map(int, read().split())
A.append(K + A[0])
D = 0
for i, j in zip(A, A[1:]):
    d = j - i
    if d > D:
        D = d

print(K - D)


Measured memory_bytes: 25196
//pushpush

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define nxvarep(n,x,a) ll n,x;cin>>n>>x;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    nvarep(n,a);
    vector<ll>pl,mi;
    rep(i,0,n){
        if(i%2==0)pl.pb(a[i]);
        else mi.pb(a[i]);
    }
    if(n%2==0){
        reverse(range(mi));
        rep(i,0,mi.size()){
            cout<<mi[i];
            cout<<spa;
        }
        rep(i,0,pl.size()){
            cout<<pl[i];
            if(i==pl.size()-1)break;
            cout<<spa;
        }
    }else{
        reverse(range(pl));
        rep(i,0,pl.size()){
            cout<<pl[i];
            cout<<spa;
        }
        rep(i,0,mi.size()){
            cout<<mi[i];
            if(i==mi.size()-1)break;
            cout<<spa;
        }
    }
    cout<<nnn;
    return 0;
}

Measured memory_bytes: 5484
import java.util.*;
import java.util.Collections;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int range = sc.nextInt() * 2 + 1;
    int cnt = 0;
    while (true) {
      cnt++;
      N -= range;
      if (N <= 0) {
        break;
      }
    }
    System.out.println(cnt);
  }
}


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

using namespace std;
 
#define vi vector<vector<int> >
#define pb push_back
#define mp make_pair

const int Max = 1e5+5;
int dist[Max]={};
bool visited[Max];
vi adj(Max);
int indeg[Max]={};

void dfs(int u){
    assert(!visited[u]);
    visited[u]=true;
    for(int d=0;d<adj[u].size();d++){
        int b=adj[u][d];
        dist[b]=max(dist[b],dist[u]+1);
        --indeg[b];
        if(indeg[b]==0){
            dfs(b);
        }
    }
}

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int s,d;
        cin>>s>>d;
        adj[s].pb(d);
        ++indeg[d];
    }
    memset(visited,false,sizeof(visited));
    for(int i=1;i<=n;i++){
        //cout<<dist[i]<<" ";
        if(!visited[i] && indeg[i]==0){
            dfs(i);
        }
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        ans=max(ans,dist[i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9728
from bisect import bisect_left, bisect_right


def ii():
    return list(map(int, input().split()))


[N, Q] = ii()
S = input()
Q_list = [ii() for _ in range(Q)]

AC_idx = []
try:
    start_idx = 0
    while True:
        found_idx = S.index("AC", start_idx)
        AC_idx.append(found_idx)
        start_idx = found_idx + 1
except ValueError as e:
    pass

for q in Q_list:
    left_idx = bisect_left(AC_idx, q[0] - 1)
    right_idx = bisect_right(AC_idx, q[1] - 2)
    print(right_idx - left_idx)


Measured memory_bytes: 30252
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;

int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


int main()
{
	ll S;
	cin >> S;
	int ans = cnt_digit(S);
	for (ll A = 1ll; A * A <= S; A++)
	{

		if (S % A != 0)
		{
			continue;

		}
		const ll B = S / A;

		const int cur = max(cnt_digit(A), cnt_digit(B));


		if (ans > cur)
		{
			ans = cur;
		}
	}

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


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)

MOD = 10**9+7


def main(input, print):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    plus = []
    neg = []
    for i in range(n):
        if a[i] < 0:
            neg.append(a[i])
        else:
            plus.append(a[i])
    is_ans_plus = False
    if len(plus) > 0:
        if n == k:
            is_ans_plus = len(neg) % 2 == 0
        else:
            is_ans_plus = True
    else:
        is_ans_plus = k % 2 == 0
    ans = 1
    if is_ans_plus:
        neg = sorted(neg, key=abs, reverse=True)
        plus = sorted(plus, key=abs, reverse=True)
        pair = []
        for i in range(1, len(neg), 2):
            pair.append(neg[i-1]*neg[i])
        s = 1
        if k % 2 == 1:
            ans = plus[0]
            s = 2
        for i in range(s, len(plus), 2):
            pair.append(plus[i-1]*plus[i])
        pair = sorted(pair, reverse=True)
        for i in range(k//2):
            ans = ans * pair[i] % MOD
    else:
        a = sorted(a, key=abs)
        for i in range(k):
            ans = ans * a[i] % MOD

    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


Measured memory_bytes: 111032
from itertools import permutations
import math

N = int(input())
A = [(0, 0) for x in range(N)]

for i in range(N):
    x, y = map(int, input().split())
    A[i] = (x, y)

pA = permutations(A)

route_count = 0
sum_route_length = 0
for route in pA:
    route_count += 1
    for i in range(1, len(route)):
        distance = math.sqrt(pow(route[i-1][0] - route[i][0], 2) + pow(route[i-1][1] - route[i][1], 2))
        sum_route_length += distance

average = sum_route_length / route_count

print(average)

Measured memory_bytes: 40556
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

void _main() {
    string S;
    cin >> S;
    vector<int> a(S.size() + 1, 0);
    map<int, int> mp;
    int ans = 0, p = 1;
    mp[0] = 1;
    REP (i, S.size()) {
        a[i + 1] = (a[i] + p * (S[S.size() - i - 1] - '0')) % 2019;
        ans += mp[a[i + 1]];
        mp[a[i + 1]]++;
        (p *= 10) %= 2019;
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	int b = 1, e = n;
	for(auto i = 0; i < m; ++i){
		int l, r;
		cin >> l >> r;
		b = max(b, l);
		e = min(e, r);
	}
	cout << max(0, e - b + 1) << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = [int(i) for i in input().split()]

ans = 0
anstmp = 0
bef = h[0]
for i in range(1, len(h)):
  if bef >= h[i]:
    anstmp += 1
    bef = h[i]
  else:
    if anstmp > ans:
      ans = anstmp
    anstmp = 0
    bef = h[i]
if anstmp > ans:
  ans = anstmp
print(ans)

Measured memory_bytes: 14252
import java.util.*;
import java.math.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int m = sc.nextInt();
    int[] ap = new int[a];
    int[] bp = new int[b];
    int res = Integer.MAX_VALUE;
    int mid = res;
    for(int i = 0; i < a; ++i) {
      ap[i] = sc.nextInt();
      mid = Math.min(mid, ap[i]);
    }
    int now = res;
    for(int i = 0; i < b; ++i) {
      bp[i] = sc.nextInt();
      now = Math.min(now, bp[i]);
    }
    res = mid + now;
    
    for(int i = 0; i < m; ++i) {
      int an = sc.nextInt();
      int bn = sc.nextInt();
      int cp = sc.nextInt();
      res = Math.min(res, ap[an - 1] + bp[bn - 1] - cp);
    }
    System.out.println(res);
  }
}


Measured memory_bytes: 132692
#include <iostream>
using namespace std;
int main(void){
    int a,b,i;
    i=0;
    while(1){
        if(i>=7){break;}
        cin>>a>>b;
        if(a<=b){cout<<b-a<<endl;}
        else if(a>=b){cout<<a-b<<endl;}
        i++;
    }
}
    



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i=0; i<s.size(); i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3728
a, b, c = map(int, input().split())
k = int(input())
d = max(a, max(b, c))
if d == a:
    print((a * (2 ** k)) + b + c)
elif d == b:
    print(a + (b * (2 ** k)) + c)
else:
    print(a + b + (c * (2 ** k)))

Measured memory_bytes: 3060
package main

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

func main() {
	var s string

	scanner := bufio.NewScanner(os.Stdin)

	scanner.Scan()

	for _, c := range(scanner.Text()) {
		if c > 0x40 && (c-0x41)%0x20 < 0x1a {
			c ^= 0x20
		}
		s += string(c)
	}
	fmt.Println(s)
}



Measured memory_bytes: 1860
#include <bits/stdc++.h>
#define fi first
#define se second
#define int long long
using namespace std;

signed main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto& e : a)
        cin >> e;
    int s = 0;
    for(int i = 0; i < n; ++i) {
        if(i % 2 == 0)
            s += a[i];
        else
            s -= a[i];
    }
    cout << s << ' ';
    for(int i = 0; i < n - 1; ++i) {
        s = a[i] - s / 2;
        s <<= 1;
        cout << s << ' ';
    }
    cout << '\n';
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
#define INFTY 1000000
using namespace std;

const int N = 100;
int n;
int D[N], W[N][N];
bool V[N];

void dijkstra() {
  int nn, minD, cost = 0;

  REP(i, n) D[i] = INFTY;
  D[0] = 0;
  nn = 0;

  while (true) {
    minD = INFTY;
    REP(i, n) {
      if (!V[i] && D[i] < minD) {
        minD = D[i];
        nn = i;
      }
    }
    if (minD == INFTY) break;

    V[nn] = true;
    REP(i, n) {
      if (!V[i] && D[nn] + W[nn][i] < D[i]) {
        D[i] = D[nn] + W[nn][i];
      }
    }
  }
}

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

  cin >> n;
  REP(i, n) D[i] = INFTY;
  REP(i, n) {
    REP(j, n) W[i][j] = INFTY;
  }

  REP(i, n) {
    int id, k, v, c;
    cin >> id >> k;
    REP(j, k) {
      cin >> v >> c;
      W[id][v] = c;
    }
  }

  dijkstra();
  REP(i, n) {
    cout << i << " " << D[i] << endl;
  }
}


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

int N,M;
int root;
vector<int> G[100010];
vector<bool> rootf(100010,true);
vector<int> tt(100010,0);
vector<int> ans(100010,-1);
queue<int> que;

int main(){
	cin >> N >> M;
	for(int i=0;i<N+M-1;i++){
		int s,t;
		scanf("%d%d",&s,&t);
		G[s].push_back(t);
		rootf.at(t)=false;
		tt.at(t)++;
	}
	
	for(int i=1;i<=N;i++)if(rootf.at(i))root=i;
	ans.at(root)=0;
	que.push(root);
	
	while(que.empty()==0){
		int s=que.front();
		que.pop();
		for(auto t:G[s]){
			ans.at(t)=s;
			tt.at(t)--;
			if(tt.at(t)==0)que.push(t);
		}
	}
	
	for(int i=1;i<=N;i++)printf("%d\n",ans.at(i));
	return 0;
}

Measured memory_bytes: 7040
#include <bits/stdc++.h>
#include<iterator>
#include<vector>
#include<algorithm>


#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pci pair<char,int>
#define un unsigned

#define mod 1000000007
#define MAXN 100000
using namespace std; 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)


int main() 
{ 
    
    int a,b;
    cin>>a>>b;
    int temp1 = ceil(a/0.08);
    int temp2 = ceil(b/0.1);
    int abc = max(temp1,temp2);
    int x = abc*0.08;
    int y = abc*0.1;
    if(a == x && b == y)
    {
        cout<<abc;
        return 0;
    }
    cout<<-1;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    ll l,r;cin>>l>>r;
    int d;cin>>d;
    ll buf1=l/d,buf2=r/d;
    if(l%d==0)buf1--;
    cout<<buf2-buf1<<endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

int main() {
  int K,N,max_dis=0,temp=0;
  cin >> K >> N;
  
  vector<int> A(N);
  rep(i,N)
    cin >> A.at(i);

  	rep(i,N-1){
      temp = A.at(i+1) - A.at(i);
      max_dis = max(max_dis,temp);
    }
  	//最後の点と初めの点の距離
   temp = A.at(0) + K - A.at(N-1);
   max_dis = max(max_dis, temp);
  
   cout << K - max_dis << endl;

    
  
}

Measured memory_bytes: 1024
#!/usr/bin/env python
# -*- coding:utf-8 -*-

from __future__ import division, print_function, absolute_import, unicode_literals

def main():
    N, M = map(int, input().split())
    p = [1] + [1] * (N-1)
    plob = [True] + [False] * (N-1)
    for _ in range(M):
        x, y = map(int, input().split())
        x -= 1
        y -= 1
        if p[x] == 0:
            continue
        p[x] -= 1
        p[y] += 1
        if plob[x] is True:
            if p[x] == 0:
                plob[x] = False
                plob[y] = True
            else:
                plob[y] = True
        # print(p)
        # print(plob)
    print(sum(plob))
    # for i in range(N):
    #     if plob[i]:
    #         print(i+1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5372
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let v: Vec<char> = get!(String).chars().collect();
    let t = v[0];
    let mut p = 'a';
    let mut count = 1;
    let mut count2 = 0;
    for i in 1..v.len() {
        if v[i] == t {
            count += 1;
        } else {
            if p == 'a' {
                p = v[i];
                count2 += 1;
            } else if p == v[i] {
                count2 += 1;
            }
        }
    }
    // println!("count: {}, count2: {}", count, count2);
    // println!("t: {}, p: {}", t, p);
    if count == 2 && count2 == 2 {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define all(v)    begin(v), end(v)
#define in        []{lint n; cin>>n; return n;}()

int main() { cin.tie(0); ios::sync_with_stdio(false);
    lint N = in, M = in;

    if( N == 1 && M == 1 ) {
        cout << 1 << "\n";
        return 0;
    }

    if( N == 1 ) {
        cout << M-2 << "\n";
        return 0;
    }

    if( M == 1 ) {
        cout << N-2 << "\n";
        return 0;
    }

    cout << max(lint(0),N-2) * max(lint(0),M-2) << "\n";
}


Measured memory_bytes: 256
import scala.io.StdIn.{readLine, readInt}

object Main extends App {
  var n = readInt
  val arr = readLine.split(" ").map(_.toInt)
  println(arr.mkString(" "))

  for (i <- 1 until n) {
    val e = arr(i)
    var j = i - 1
    while (j >= 0 && arr(j) > e) {
      arr(j + 1) = arr(j)
      j -= 1
    }
    arr(j + 1) = e
    println(arr.mkString(" "))
  }

}


Measured memory_bytes: 45772
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Data{
    int A;
    string S;
    
    bool operator<( const Data& right ) const {
        return A == right.A ? S < right.S : A < right.A;
        //return A < right.A;
    }
};

int Func(int T, vector<int> v){
    int M = v.size();
    
    int MP = 0;
    MP += 10*(M-1);

    int temp = 0;
    for (int i=0;i<M;i++) {
        temp += v[i];
    }
    MP += abs(temp-T);
    return MP;
}

int main(){
    int N, A, B, C;
    int l[8];
    
    // 入力
    cin >> N >> A >> B >> C;
    for (int i=0;i<N;i++) cin >> l[i];
    
    int MP_min = 3000;
    int MP;
    for (int i=0;i<pow(4,N);i++) {
        vector<int> v_A{};
        vector<int> v_B{};
        vector<int> v_C{};
        int temp = i;
        for (int j=0;j<N;j++) {
            int pow4 = pow(4,N-1-j);
            int flag = temp/pow4;
            temp = temp%pow4;
            if (flag==1) v_A.push_back(l[j]);
            else if (flag==2) v_B.push_back(l[j]);
            else if (flag==3) v_C.push_back(l[j]);
            //cout << flag << " " ;
        }
        //cout << endl;
        if (v_A.size()*v_B.size()*v_C.size() > 0) {
            MP = 0;
            MP += Func(A, v_A);
            MP += Func(B, v_B);
            MP += Func(C, v_C);
            //cout << MP << endl;
            if (MP < MP_min) MP_min = MP;
            //if (MP <= 243) cout << i << " " << MP << endl;
        }
    }
    
    // 出力
    cout << MP_min << endl;
    //for (int i=0;i<N;i++) cout << l[i] << endl;
    
    return 0;
}


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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    string n;
    cin >> n;
    if (n[0] == '9' || n[1] == '9')
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 3536
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 6
char table[MAX][MAX];
char table_copy[MAX][MAX];
char table_ori[MAX][MAX];
int H,W,K;
int count(){
    int ret = 0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(table[i][j] == '#')
                ret++;
        }
    }
    return ret;
}
int main(){
   int ans=0;
   scanf("%d %d %d",&H,&W,&K);
   for(int i=0;i<H;i++)
       scanf("%s",table[i]);
   memcpy(table_ori,table,sizeof(table));


   for(int bit1=0;bit1<(1<<W);bit1++){
       memcpy(table,table_ori,sizeof(table));
       for(int i=0;i<W;i++){
            if(bit1 & (1<<i)){
                for(int j=0;j<H;j++)
                    table[j][i] = '*';
            }
       }

       memcpy(table_copy,table,sizeof(table));

       for(int bit2=0;bit2<(1<<H);bit2++){
            memcpy(table,table_copy,sizeof(table));
            for(int k=0;k<H;k++){
                if(bit2 & 1<<k){
                    for(int l=0;l<W;l++)
                        table[k][l] = '*';
                }
            }
            if(count() == K) ans++;
        }
    }

   printf("%d",ans);
}


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

int cnt_digits(ll n) {
    return to_string(n).size();
}

int main(){
    ll n;
    cin >> n;
    int ans = cnt_digits(n);
    for (ll a=1LL; a*a<=n; a++) {
        if (n%a!=0) continue;
        ll b = n/a;
        int tmp = max(cnt_digits(a), cnt_digits(b));
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<numeric>
#define int long long
#define ld long double
#define all(x) x.begin(),x.end()
const int maxn=1000000;
#define what_is(x) cerr << #x << " is " << x << endl;
const int MOD = 1e9 + 7;
using namespace std;
string abc="abcdefghijklmnopqrstuvwxyz";
int powmod(int a, int b, int MOD = MOD){
    if(!a and !b)    return 1ll;
    if(!a)    return a;
    int res = 1ll;
    b %= (MOD - 1ll), a %= MOD;
    while(b){
        if(b%2 == 1)    res = (res * a) % MOD;
        a = (a * a) % MOD;
        b /= 2;
    }
    return res;
}
int popcount(uint32_t n)
{
    n = n - ((n >> 1) & 0x55555555);
    n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
    return ((n + (n >> 4) & 0xF0F0F0F) * 0x1010101) >> 24;
}
bool check(int n) {return (((double)sqrt(n)-floor((double)sqrt(n)))==0);}
vector<bool> sieve(maxn + 1, true);
void fillprime() {
    sieve[0] = sieve[1] = false;
    for (int i = 2; i <= maxn; ++i) {
        if (sieve[i] && (int) i * i <= maxn) {
            for (int j = i * i; j <= maxn; j += i) {
                sieve[j] = false;
            }
        }
    }
}
const int nn=1e5+5;

void solve() {
   int x,y;
   cin>>x>>y;
   if((x==1 and y==2) or (x==2 and y==1)) cout<<3;
   else if((x==2 and y==3) or (x==3 and y==2)) cout<<1;
   else cout<<2;

}
int32_t main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    //fillprime();

    //int t;cin>>t;while(t--)
        solve();
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define ld long double
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define setbits(x) (__builtin_popcount(x))
int mod=1000000007;
int INF64=mod*mod+1;

void solve(){
	string s;
	cin>>s;
	cout<<s;
	if(s.back()=='s')
		cout<<"es";
	else
		cout<<"s";
}

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

	int T;
	//cin>>T;
	 T=1;
	for(int i=1;i<=T;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define each(it,o) for(auto it= (o).begin(); it != (o).end(); ++ it)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define inrep int t;cin>>t; while(t--)
#define pb emplace_back
using namespace std;
using namespace __gnu_pbds; 


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii > vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll > vpll; 
typedef vector<string> vs;
typedef long double ld;
const ll MOD = 1e9+7;
template<typename T> istream& operator>> ( istream &in,vector<T> &v ) {

    for ( unsigned   i=0; i<v.size(); i++ )
        in>>v[i];
    return in;
}

ll extended_GCD(ll a , ll b , ll &x , ll &y){
    if(a == 0){
        x = 0;
        y = 1;
        return b;
    }
    ll x1 , y1;
    ll gcd = extended_GCD(b%a , a , x1 , y1);
    x = y1 - (b/a)*x1; 
    y = x1;
    return gcd;
}
ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}
ll modinv(ll a , ll mod ){
    ll x , y;
    extended_GCD(a , mod , x , y);
    if(x < 0) x += mod;
    return x;
}

ll mul(ll a,ll b,ll m)
{
    return (a%m*b%m)%m;
}
  
 


int main()
{
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    vector<int> dp(1000005,0);
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        dp[a[i]]++;
    }
    int ans = 0;
    sort(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(dp[a[i]])
        {
            for(int j=a[i]*2;j<=1000000;j=j+a[i])
            {
                dp[j] = 0;
            }
        }
        if(dp[a[i]]>1)
            dp[a[i]] = 0;
    }
    for(int i=1;i<=1000000;i++)
    {
        ans+=(dp[i]);
    }
    cout<<ans;

    
    
    return 0;
}

Measured memory_bytes: 7872
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
l = 0
r = 10 ** 10
c = a - b
while l + 1 != r:
    m = (l + r) // 2
    tmp = 0
    for i in range(n):
        if h[i] > b * m:
            tmp += ((h[i] - b * m) // c + (1 if (h[i] - b * m) % c else 0))
    if tmp > m:
        l = m
    else:
        r = m
print(r)

Measured memory_bytes: 7044
from collections import defaultdict
n=int(input())
MAX=10000

d = defaultdict(int)

def col(x,y,z):
    if x == y and x == z  :
        return 1
    if x == y or y == z or z == x :
        return 3
    return 6

# x <= y <= z
for i in range(1,MAX):
    wkx = i**2
    if wkx > MAX:
        break
    for j in range(i,MAX):
        wky = wkx + j**2  + i * j
        if wky > MAX :
            break
        for k in range(j,MAX):
            wkz = wky + k**2 + i * k  + j * k
            if wkz > MAX :
                break
            d[wkz] = d[wkz] + col(i,j,k)
            
for i in range(n):
    k = i + 1
    print(d[k])


Measured memory_bytes: 71000
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
vector<int> e[N];
int vis[N],d[N];
map< pair<int,int>,int > mp;
pair<int,int> mk(int x,int y){
	if(x>y) swap(x,y);
	return make_pair(x,y);
}
void dfs(int x,int fath){
	vis[x]=1; 
//	cout<<x<<endl;
	for(int i=0;i<e[x].size();++i){
		int v=e[x][i];
		if(v==fath) continue;
		if(vis[v]){
			if(mp.count(mk(x,v))) continue;
			mp[mk(x,v)]=1;
			if(d[v]&1)  ++d[v],cout<<v<<" "<<x<<endl;
			else ++d[x],cout<<x<<" "<<v<<endl;
			continue;
		}
		dfs(v,x);
		if(mp.count(mk(x,v))) continue;
		mp[mk(x,v)]=1;
		if(d[v]&1) cout<<v<<" "<<x<<endl,++d[v];
		else cout<<x<<" "<<v<<endl,++d[x];
	}
}
signed main(){
	int n,m,u,v;
	cin>>n>>m;
	if(m&1) return puts("-1"),0;
	for(int i=1;i<=m;++i){
		cin>>u>>v;
		e[u].push_back(v);
		e[v].push_back(u);
	}
	dfs(1,0);
	return 0;
}

Measured memory_bytes: 28388
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 1e5;

struct Edge {

  int from, to, len;

  Edge(int f, int t, int l) {
    from = f; to = t; len = l;
  }
};

int L;

int main() {

  cin >> L;
  vector<Edge> ans;
  int r = 1, i = 1;

  while (2*r <= L) {
    ans.push_back(Edge(i, i+1, 0));
    ans.push_back(Edge(i, i+1, r));
    i++; r *= 2;
  }

  while (r != L) {
    int j = (int)log2(L-r);
    ans.push_back(Edge(j+1, i, r));
    r += (int)pow(2, j);
  }

  cout << i << " " << ans.size() << endl;
  FORE (e, ans) {
    cout << e.from << " " << e.to << " " << e.len << endl;
  }
  return 0;

}

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

vector<vector<int>> g;
vector<int> color;
bool dfs(int u, int p, int c) {
    if (~color[u]) return color[u] != color[p];
    color[u] = c;
    for (int v: g[u]) if (v != p) if (!dfs(v, u, c ^ 1)) return false;
    return true;
}

int main() {
    int n, m; cin >> n >> m;
    g.resize(n);
    for (int i = 0; i < m; i++) {
        int a, b; cin >> a >> b; a--, b--;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }
    color.assign(n, -1);
    long long all = 0;
    if (!dfs(0, -1, 0)) {
        all = 1LL * n * (n - 1) / 2;
    } else {
        for (int i = 0; i < n; i++) all += color[i];
        all *= n - all;
    }
    cout << all - m << endl;
    return 0;
}


Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int n,p,res,p_max;
int main(){
  scanf("%d",&n);
  for(int i=0;i<n;++i){
    scanf("%d",&p);
    res+=p;
    p_max=max(p_max,p);
  }
  printf("%d",(res-(p_max/2)));
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
#define INF 1e9
#define All(x) (x).begin(), (x).end()
typedef long long ll;
using namespace std;


int main() {
  int x,n;
  cin>>x>>n;
  vector<int> p(110);
  rep(i,n){
    int a;
    cin>>a;
    p[a]=1;
  }
  int ans=INF;
  for(int i=x;i<=101;i++){
    if(p[i]==0){
      ans=i;
      break;
    }
  }

  for(int i=x - 1;i>=0;i--){
    if(p[i]==0 && abs(x-ans)>=abs(i-x)){
      ans=i;
      break;
    }
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define vec vector<int>
#define fo(i, n) for (int i = 0; i < n; i++)
#define foo(i, a, b) for (int i = a; i < b; i++)
#define mp make_pair
#define deb(x) cout << #x << " --> " << x << endl;

#define deb1a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        cout << it << " ";        \
    }                             \
    cout << endl;
#define deb2a(v)                  \
    cout << #v << "--->" << endl; \
    for (auto it : v)             \
    {                             \
        for (auto it1 : it)       \
        {                         \
            cout << it1 << " ";   \
        }                         \
        cout << endl;             \
    }

#define mod 1000000007
#define so(v) sort(v.begin(),v.end())
#define fi first
#define se second
//#define endl "\n"
int power(int x, unsigned int y, int p){ int res = 1;x = x % p;while (y > 0)  { if (y & 1)res = (res*x) % p;y = y>>1;  x = (x*x)% p;} return res;}
int mI(int a, int m)  {return power(a, m - 2, m);}


int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t = 1;
    //cin>>t;
    while(t--){
        int n;
        cin>>n;
        string s;
        cin>>s;
        vector<vec> v(n+1,vec(3,0));
        map<char,int> m;
        m['R'] = 0;
        m['G'] = 1;
        m['B'] = 2;

        for (int i = n - 1; i >= 0;i--){
            fo(j,3){
                v[i][j] = v[i + 1][j];

            }
            v[i][m[s[i]]]++;
        }
        int ans = 0;
        //deb2a(v);
        fo(i,n){
            foo(j,i+1,n){
                if(s[i]==s[j])
                    continue;
                int diff = j - i;
                int val = 3 - m[s[i]] - m[s[j]];
                ans += v[j + 1][val];
                // cout << i << " " << j << endl;
                // deb(ans);
                if(j+diff<n&&m[s[j+diff]]==val)
                    ans--;
                //deb(ans);
            }
        }
        cout << ans;
    }
}


Measured memory_bytes: 3884
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String[] tokens = in.readLine().split(" ");
		in.close();
		int N = Integer.parseInt(tokens[0]);
		int K = Integer.parseInt(tokens[1]);
		int result = 0;
		if (K == 1) {
			result = 0;
		} else {
			result = N - (K - 1) - 1;
		}
		System.out.println(result);
	}

}

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

const int N = 1e5;
int a[N];

signed main(){

  int n; cin >> n;
  int odd = 0,even = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    if(a[i]%2 == 1) odd++;
    else even++;
  }

  if(even != n) cout << "first" << endl;
  else cout << "second" << endl;

  return 0;
}


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

int counter(int i, int j, vector<vector<char>> S) {
    int count = 0;
    if (S[i-1][j] == '#') count++;
    if (S[i-1][j+1] == '#') count++; 
    if (S[i][j+1] == '#') count++;
    if (S[i+1][j+1] == '#') count++;
    if (S[i+1][j] == '#') count++;
    if (S[i+1][j-1] == '#') count++;
    if (S[i][j-1] == '#') count++;
    if (S[i-1][j-1] == '#') count++;    
    return count;
}


int main(){
int H, W; cin >> H >> W;
vector<vector<char>> S(H, vector<char>(W));
for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
        cin >> S[i][j];
    }
}

for (int i = 0; i < H; i++) {
    S[i].push_back('.');
    S[i].insert(S[i].begin(), '.');        
}
vector<char> line(W + 2);
for (int j = 0; j < W + 2; j++) {
    line[j] = '.';
}
S.push_back(line);
S.insert(S.begin(), line);

for (int i = 1; i < S.size() - 1; i++) {
    for (int j = 1; j < S[0].size() - 1; j++) {
        if (S[i][j] == '#') {
            cout << '#';
        } else {
            cout << counter(i, j, S);
        }
    }
    cout << endl;
}

}



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

int main() {

    int ans = 700;

    for(int i=0; i<3; i++){
        char c;
        cin >> c;
        if(c == 'o'){
            ans += 100;
        }
    }

    cout << ans << endl;

    return 0;
}

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

const ll INF = 1001001001;

const double PI=3.141592653;

const ll sosu = 1000000007;//大きい素数

//提出のときに言語がc＋＋似合っていることを確認する

//絶対値の関数
int z(int a,int b){
  if(a>b) return a-b;
  else return b-a;
}



int main(){
  string s,t;
  cin>>s>>t;
  ll cnt=0;
  ll len=s.size();
  for(ll i=0;i<len;i++){
    if(s.at(i)!=t.at(i)){
      cnt++;
    }
  }
  cout<<cnt<<endl;
  return 0;
  
  
}


Measured memory_bytes: 3860
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

int main(void){
  string s;
  string res = "",n;
  getline(cin,s);
  s += " ";
  for(int i = 0 ; i < s.size() ; i ++){
    if(s[i] == ' '){
      if(3 <= n.size() && n.size() <= 6)res += n + " ";
      n = "";
    }else{
      if(s[i] != '.' && s[i] != ','){
	n += s[i];
      }
    }
  }	        
  for(int i = 0 ; i < res.size() - 1 ; i ++)
    cout<<res[i];
  cout<<endl;
}

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

int main() {
  int n, m;
  cin >> n >> m;
  
  if (m==n) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
// https://qiita.com/e869120/items/eb50fdaece12be418faa

#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<ll> a(n, 0);
    rep(i, n) {
        cin >> a[i];
    }

    ll res = LINF;
    for (int bit = 0; bit < (1 << n); bit++) {
        ll num = 0;
        ll sum = 0;
        ll minh = 0;
        rep(i, n) {
            if (a[i] > minh) {
                num++;
                minh = a[i];
                continue;
            }
            if ((bit >> i) & 1) {
                minh = minh + 1;
                sum += minh - a[i];
                num++;
            }
        }
        if (num >= k) {
            chmin(res, sum);
        }
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i < (ll)(n); ++i)
#define MAX 500000001000000000
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans, cnt;

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

	ll X;
	cin >> X;

	ll n = 1000;
	repk(i,-n, n) {
		repk(j,-n, n) {
			ll ii = i * i;
			ll jj = j * j;
			if ((ii * ii * i)  - (jj * jj * j) == X) {
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}

	
	return 0;
}


Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int a = str.length();
        
        if(str.charAt(a-1) == '3'){
            System.out.println("bon");
        }else if(str.charAt(a-1) == '0' || str.charAt(a-1) == '1' || 
        str.charAt(a-1) == '6' || str.charAt(a-1) == '8'){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }
    }
}


Measured memory_bytes: 35596
n,m = gets.split.map(&:to_i)
set = []
n.times do
  set << gets.split.map(&:to_i)
end
set.sort_by!{|k,v| k}
sum = 0
set.each do |a,b|
  if m-b >= 0
    sum += a*b
    m -= b
  else
    sum += a*m
    break
  end
end
puts sum


Measured memory_bytes: 12688