akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int main(void)
{
  char s[3];
  scanf("%s", s);

  int ans =0;
  if(s[0]=='R' && s[1]=='R' && s[2]=='R'){
    ans = 3;
  }
  else if((s[0]=='R' && s[1]=='R') || (s[1]=='R' && s[2]=='R')){
    ans = 2;
  }
  else if(s[0]=='R' || s[1]=='R' || s[2]=='R'){
    ans = 1;
  }
  else{
    ans = 0;
  }   

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

  return 0;
}


Measured memory_bytes: 1724
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let (n, t) = input!(usize, i64);
    let t_list = input!(i64; n);

    let mut total_time: i64 = 0;
    for i in 0..n-1 {
        total_time += t;
        if t_list[i] + t > t_list[i+1] {
            total_time -= t_list[i] + t - t_list[i+1];
        }
    }
    total_time += t;
    println!("{}", total_time);
}


Measured memory_bytes: 10492
N = int(input())
AB = sorted([[int(i) for i in input().split()] for i in range(N)], key = lambda x: x[1])

cur = 0
for i in range(N):
    cur += AB[i][0]
    if cur > AB[i][1]:
        print('No')
        break
else:
    print('Yes')

Measured memory_bytes: 89588
def count_ones(num):
    num = (num & 0x55555555) + (num >> 1 & 0x55555555) 
    num = (num & 0x33333333) + (num >> 2 & 0x33333333)
    num = (num & 0x0F0F0F0F) + (num >> 4 & 0x0F0F0F0F)
    num = (num & 0x00FF00FF) + (num >> 8 & 0x00FF00FF)
    num = (num & 0x0000FFFF) + (num >>16 & 0x0000FFFF)
    return num
ans = 0
cnt = 0
check = 0
n = int(input())
temp_n = 2**n-1
# print(bin(temp_n^255))
# print(count_ones(temp_n^255))
ls_xy = [[0,0] for i in range(n)]
for i in range(n):
    a = int(input())
    for j in range(a):
        x,y = map(int,input().split())
        if y == 1:
            ls_xy[i][0] += 2**(x-1)
        elif y == 0:
            ls_xy[i][1] += 2**(x-1)

for i in range(2**n):
    check = 0
    for j in range(n):
        if i&(2**j) == 0:
            # print("c",i,j)
            continue
        if (~i & (2**n-1)) & ls_xy[j][0] > 0 or i & ls_xy[j][1] > 0:
            check = 1
            # print("b",i,j)
            break
    if check == 0 and count_ones(i) > ans:
        ans = count_ones(i)
print(ans)




Measured memory_bytes: 3188
#include <iostream>
#include <string.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
const int mode=1e9+7;
int dp[2001][2001];
int main()
{
    int n,m;
    cin>>n>>m;
    int a[2001],b[2001];
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(int j=1;j<=m;j++)
        scanf("%d",&b[j]);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=m;j++)
        {
            dp[i][j]=dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
            if(a[i]==b[j])
                dp[i][j]+=dp[i-1][j-1]+1;
            if(dp[i][j]>=0)
                dp[i][j]=dp[i][j]%mode;
            else
                dp[i][j]+=mode;
        }
    }
    cout<<dp[n][m]+1<<endl;
    return 0;
}


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

int main(){
  int n;
  int i,num,w;
  pair<int,int> fish[100] ;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> num >> w;
    fish[i] = make_pair(-w,num);
  }
  sort(fish,fish+n);
  cout << fish[0].second << " " << (-1)*fish[0].first << endl;
}

Measured memory_bytes: 1168
d=1+8*gets.to_i
q=Math.sqrt(d).to_i
if q**2!=d
	puts :No;exit
end
k=(-1+q)/2
puts :Yes,k+1
puts [k,*k.times.map{|i|-~i*(i+2)/2}]*' '
k.times{|i|
	a=[k,i*-~i/2+1]
	i.times{|j|a<<a[-1]+1}
	(i+1...k).each{|j|a<<a[-1]+j}
	puts a*' '
}

Measured memory_bytes: 3836
n = input()
if n[-1]=='2' or n[-1]=='4' or n[-1]=='5' or n[-1]=='7' or n[-1]=='9':
	print('hon')
elif n[-1]=='0' or n[-1]=='1' or n[-1]=='6' or n[-1]=='8':
	print('pon')
else:
	print('bon') 

Measured memory_bytes: 9052
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(N: int, M: int, a: "List[int]"):
    #dp[i] = i段目までの移動総数
    dp = [-1]*(N+1)
    dp[0]=1
    dp[1]=1 
    for i in range(M):
        dp[a[i]] = 0
    
    for i in range(2,N+1):
        if dp[i] == 0:
            continue
        dp[i] = dp[i-1]+dp[i-2]
        dp[i]%=MOD
    print(dp[N]%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(M)]  # type: "List[int]"
    solve(N, M, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 7840
#include <stdio.h>

#define MAX 100 
#define INF 1000000
#define W 0
#define B 1
#define NIL -2
 
int d[MAX],col[MAX],w[MAX][MAX];
  
void prim(int,int);

void prim(int G,int r){
 
  int u,min,i,pi[100],v;
  int count=0;
 
  for(u=0; u < G; u++){
 
    d[u] = INF;
    col[u] = W;
    pi[u] = NIL;
  }
 
  d[r] = 0;
 
  while(1){
   min = INF;
 
    for(i=0;i<G;i++){
 
      if(col[i] != B && d[i] < min){
 
    min = d[i];
    u = i;
 
 }

    }
 
    if(min == INF){
      break;
    }
 
    col[u] = B;
    count++;
 
    for(v=0;v<G;v++){
 
      if(col[v] != B && d[u] + w[u][v] < d[v]){
 
    pi[v] = u;
    d[v] =d[u] + w[u][v];
 
      }
    }
 
    if(count == G){
      break;
    }
     
 
  }
}

int main(){
 
  int g,r,c,v,k,u,i,j;
 
  scanf("%d",&g);
 
  for(i=0;i<g;i++){
    for(j=0;j<g;j++){
 
      w[i][j]=INF;
       
    }
  }
 
  for(i=0;i<g;i++){
   
    scanf("%d%d",&u,&k);  
  
    for(j=0;j<k;j++){
 
      scanf("%d%d",&v,&c);
      w[u][v]=c;
 
      // printf("u=%d,k=%d v,c : %d,%d\n",u,k,v,c);
 
    }
  }

 
  r=0;
 
   
  prim(g,r);
   
  for(v=0;v<g;v++){
     
    printf("%d %d\n",v,d[v]);
  }
   
  return 0;
}
 

Measured memory_bytes: 640
fun main(args: Array<String>) {
    edpc()
}

fun edpc() {
    val n = readLine()!!.toInt()
    val vacations = (1..n)
        .map { readLine()!!.split(" ").map { it.toLong() } }

    val dp = Array(n + 1) { LongArray(3) { 0 } }
    dp[0][0] = vacations[0][0]
    dp[0][1] = vacations[0][1]
    dp[0][2] = vacations[0][2]

    for (i in 1 until n) {
        for (j in 0..2) {
            for (k in 0..2) {
                if (j == k) continue
                dp[i][j] = Math.max(dp[i][j], dp[i - 1][k] + vacations[i][j])
            }
        }
    }

    val answer = dp[n - 1].max()!!

    println(answer)
}


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

int main(){
  int N,X,Y;
  cin >> N >> X >> Y;
  int a[N]={};
  int s1,s2;
  
  for(int i=1;i<N;++i){
    for(int j=i+1;j<=N;++j){
      s1 = j-i;
      s2 = abs(i-X)+abs(j-Y)+1;
      if(s1<=s2) a[s1] = a[s1] + 1;
      else a[s2] = a[s2] + 1;
    }
  }
  
  for(int k=1;k<=N-1;++k){
    cout<< a[k] <<endl;
  }   
      

  
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n,l,r,ans=0;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d%d",&l,&r);
		ans+=r-l+1;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	static public void  main(String[] args){
		Scanner scan = new Scanner(System.in);

		double pBTC = 380000.0;

		int n = scan.nextInt();
		double sum = 0;
		
		for(int i = 0; i < n; i++){
			double x =  scan.nextDouble();
			boolean jpy = scan.next().equals("JPY");
			if(jpy){
				sum += x;
			}else{
				sum += (pBTC * x);
			}
			// System.err.println(sum);
		}
		System.out.println(sum);
		
	}
}


Measured memory_bytes: 24404
import java.math.BigInteger;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			int N = sc.nextInt();
			long ans = 0;
			for (int i = 1; i <= N; i++) {
				for (int j = 1; j <= N; j++) {
					for (int k = 1; k <= N; k++) {
						int gcd = IntStream.of(i, j, k)
								.mapToObj(BigInteger::valueOf)
								.reduce(BigInteger::gcd)
								.orElse(BigInteger.ZERO)
								.intValue();
						ans += gcd;
					}
				}
			}
			System.out.println(ans);

		} finally

		{
			sc.close();
		}
	}

}


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

using namespace std;

long long gcd(long long x,long long y){
    return y?gcd(y,x%y):x;
}

int main()
{
    long long n,k;
    cin >>n >>k;
    n%=k;
    cout << min(n,k-n)<< endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  string s;
  cin >> n >> s;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<n;j++){
      s[i]++;
      if(s[i]>=91 ||s[i]<=64){
	s[i]=65;
      }
    }
  }
  cout << s <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <unordered_map>
#include <unordered_set>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define REV(i,a,n) for(int i=n;i>=a;--i)
#define all(e) e.begin(),e.end()
#define rall(e) e.rbegin(),e.rend()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define mod 1000000007
#define show(n) cerr<<#n<<" = "<<n<<endl
#define shows(n) for(auto z:n){cerr<<z<<", ";}cerr<<endl

#define yes cout << "YES" << endl
#define no cout << "NO" << endl

using namespace std;

using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using pint = pair<int,int>;

const int INF = (1 << 30);

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

    ll n;
    cin >> n;
    rep(i, 31){
        if(((1 << i) - 1) <= n && n < (1 << (i + 1)) - 1){
            cout << i << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3176
n = int(input())
l = list(map(int, input().split()))
 
ans = 0

def func(l, pn):
  ans = 0
  sum_ = 0
  for i in range(n):
    sum_ += l[i]
    if sum_ >= 0 and pn[i] < 0:
      ans += sum_+1
      sum_ = -1
    elif sum_ <= 0 and pn[i] > 0:
      ans += -sum_+1
      sum_ = 1
    else:
      continue
  return ans

pn1 = [1 if i%2 == 0 else -1 for i in range(n)]
pn2 = [-1 if i%2 == 0 else 1 for i in range(n)]

print(min(func(l, pn1), func(l, pn2)))

Measured memory_bytes: 14464
s = input()
S = ''.join(list(reversed(s)))
N = len(S)

i = 0
while True:
    l = N - i
    if l>=5 and (S[i:i+5]=='maerd' or S[i:i+5]=='esare'):
        i += 5
    elif l>=6 and S[i:i+6]=='resare':
        i += 6
    elif l>=7 and S[i:i+7]=='remaerd':
        i += 7
    else:
        print("NO")
        exit()
    if i == N:
        print('YES')
        exit()


Measured memory_bytes: 9744
s=list(input())
rensa=1
now=s[0]
ans=1
for i in range(1,4):
    if now==s[i]:
        rensa+=1
    else:
        now=s[i]
        if rensa>ans:
            ans=rensa
        rensa=1
if rensa>ans:
    ans=rensa 
print("Yes" if ans>=3 else "No")

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

int n;

void solve() {
	int res = 1;
	for (int i = 0; i < n; i++) {
		res += i + 1;
	}
	cout<<res<<endl;
}

int main(int argc, const char *argv[]) {
	while (cin>>n) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdint.h>

int main(void){
    int n;
    scanf("%d", &n);
    int64_t sum = 0;
    for(int i=1; i<=n; i++){
        for(int j=i; j<=n; j+=i){
            sum += j;
        }
    }
    printf("%lld", sum);
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int>ans(n,0);
  for(int i = 1;i < n;i++){
    int a;
    cin >> a;
    a--;
    ans[a]++;
  }
  for(int i = 0;i < n;i++) cout << ans[i] << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;

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

  int N,A;
  cin >> N >> A;

  cout << N*N-A << endl;
  return 0;
}


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

int main(){
   int N;
   cin >> N;
   map<int, int> A;
   //vector<int> A(N);
   int key;
   for (int i=1; i<=N; i++){
      cin >> key;
      A[key] = i;
   }

   //for (int i=1; i<=N; i++)
   //   cout << A[i];

   for (int i=1; i<=N; i++)
      cout << A[i] << " ";

   //vector<int> Ans(0);
   //for (int i=1; i<=N; i++){
   //   for (int j=0; j<N; j++){
   //      if (i == A.at(j)){
   //         Ans.push_back(j+1);
   //         break;
   //      }
   //   }
   //}

   //for (int i=0; i<N; i++)
   //   if (i !=N-1)
   //      cout << Ans.at(i) << " ";
   //   else
   //      cout << Ans.at(i) << endl;
}



Measured memory_bytes: 5504
numA, numB, numCoupon = map(int, input().split(' '))
priceA = list(map(int, input().split(' ')))
priceB = list(map(int, input().split(' ')))

# initial best price
bestPrice = min(priceA) + min(priceB)

for n in range(numCoupon):
  # get coupon details
  typeA, typeB, discount = map(int, input().split(' '))
  # calculate price when this coupon is used
  currentPrice = priceA[typeA-1] + priceB[typeB-1] - discount
  # update best price
  if currentPrice < bestPrice:
    bestPrice = currentPrice

print(bestPrice)


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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    cout << (1800*m+100*n)*pow(2,m) << endl;
    return 0;
}


Measured memory_bytes: 256
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

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

int main() {
    int N;cin >> N;
    string S,T;cin >> S >> T;
    int canexcept = 0;
    for(int i = 0;i<N;i++){
        string Q,R;
        Q = S.substr(i,N-i);
        R = T.substr(0,N-i);
        if(Q == R) canexcept = max(canexcept,N-i);
    }
    cout << 2*N-canexcept << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int[] l = new int[n];
    for(int i = 0; i < n; i++){
      l[i] = sc.nextInt();
    }
    Arrays.sort(l);
    int sum = 0;
    for(int i = n-1; n - k <= i; i--){
      sum += l[i];
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,ans=0;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a;
		cin>>a;
		ans+=a;
	} 
	if(ans>n) cout<<"-1";
	else cout<<n-ans;
	return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 3e5 + 10; 
const double pi = acos(-1.0);

inline ll read()
{
    ll kk=0,f=1;
    char cc=getchar();
    while(cc<'0'||cc>'9'){if(cc=='-')f=-1;cc=getchar();}
    while(cc>='0'&&cc<='9'){kk=(kk<<1)+(kk<<3)+cc-'0';cc=getchar();}
    return kk*f;
}

struct apple
{
	int n;//a0,b1,c2
	int dv;//deliciousness 
}ap[maxn];

//int p[maxn],q[maxn],r[maxn];
bool cmp(apple a,apple b);
int main(void)
{
	int x,y,a,b,c;
	x =read();
	y =read();
	a =read();
	b =read();
	c =read();
	
	int cnt=0,sum=0;
	for(int i=0;i<a;i++){
		ap[cnt].n=0;
		ap[cnt++].dv=read();
	}
	for(int i=0;i<b;i++){
		ap[cnt].n=1;
		ap[cnt++].dv=read();
	}
	for(int i=0;i<c;i++){
		ap[cnt].n=2;
		ap[cnt++].dv=read();
	}
	sort(ap,ap+a+b+c,cmp);
	
	sum=x+y;
	cnt=0;
	ll ans= 0;
	while(sum)//(x>0||y>0) )//&&cnt<sum)
	{
		if(ap[cnt].n==0)
		{
			if(x>0)
			{
				ans+=ap[cnt].dv;
			//	printf("\nx:%d",ans);
				x--;
				sum--;
			}
		}
		else if(ap[cnt].n==1)
		{
			if(y>0)
			{
				ans+=ap[cnt].dv;
			//	printf("\ny:%d",ans);
				y--;
				sum--;
			}
		}
		else
		{
				ans+=ap[cnt].dv;
			//	if(ap[cnt])
			//	printf("\nc:%d",ans);
				sum--;
		}	
		cnt++;
	}
	printf("%lld",ans);
	return 0;
}
bool cmp(apple a,apple b)
{
	return a.dv>b.dv;
}

Measured memory_bytes: 2560
turn = int(input())
taro, hana = 0, 0
for i in range(turn):
    p1, p2 = input().split()
    if p1 > p2:
        taro += 3
    elif p1 == p2:
        taro += 1
        hana += 1
    else:
        hana += 3
print(taro, hana)


Measured memory_bytes: 5604
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 5*1e5+5;

long long dpl[N], dpr[N];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	string s;	
	cin >> s;
	int n = s.length() + 1;
	dpr[n] = 0;
	for(int i=n-1;i>=0;i--) {
		if(s[i] == '>') dpr[i] = dpr[i+1] + 1;
		else dpr[i] = 0;
	}
	dpl[0] = 0;
	for(int i=1;i<=n;i++) {
		if(s[i-1] == '<') dpl[i] = dpl[i-1] + 1;
		else dpl[i] = 0;
	}
	long long ret = 0;
	for(int i=0;i<=n;i++) ret += max(dpl[i], dpr[i]);
	cout << ret;
	return 0;
}


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

int main(){
  long long n;
  cin >> n;
  long long sum = 0;
  vector<long long> vec;
  for(int i=0; i<n; i++){
    long long num;
    cin >> num;
    vec.push_back(num);
    if(i % 2 == 0) sum += num;
    else sum -= num;
  }
  cout << sum << " ";
  for(int i=0; i<n-1; i++){
    sum = (vec[i]-sum/2)*2;
    cout << sum << " ";
  }
  return 0;
}
  
  
  
  

Measured memory_bytes: 2164
#include<iostream>
#include<string>
using namespace std;
string S; int n;
int main() {
	cin >> n >> S; int cnt = 0;
	for (int i = 0; i < S.size() / 2; i++) {
		if (S[i] == '<' && S[S.size() - 1 - i] == '>')cnt++;
		else break;
	}
	cout << n - cnt << endl;
	return 0;
}

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

const int N = 310;

int n, a[N][N];
int e[N][N];
long long ans;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) cin >> a[i][j];

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) if (i != j) {
			for (int k = 1; k <= n; ++k) if (k != i && k != j) {
				if (a[i][j] > a[i][k] + a[k][j]) {
					return printf("-1\n"), 0;
				}
				if (a[i][j] == a[i][k] + a[k][j]) {
					e[i][j]++;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) if (i != j && !e[i][j]) {
			ans += a[i][j];
		}
	}

	cout << ans / 2 << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll k;
    cin >> k;
    vector<ll> a(50, 0);
    rep(i, 50)a[i] = i + k / 50;
    k %= 50;
    rep(i, k){
        ll mn = 1001001001001001001;
        int idx;
        rep(j, 50){
            if(mn > a[j]){
                mn = a[j];
                idx = j;
            }
        }
        rep(j, 50){
            if(j == idx)a[j] += 50;
            else a[j]--;
        }
    }
    cout << 50 << endl;
    rep(i, 50)cout << a[i] << ' ';
    cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// __uint128_t
const ll MOD = 1e9+7;



int main(){
    string S; cin >> S;
    ll ans = 0;
    vector<char> C = {'A', 'T', 'G', 'C'};
    for(int i = 0; i < S.size(); i++){
        ll cnt = 0;
        
        while(i < S.size() && find(C.begin(), C.end(), S[i]) != C.end()){
            i++;
            cnt++;
        }
        if(cnt) i--;
        ans = max(ans, cnt);
    }
    cout << ans << endl;

} 


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

int main() {
  int H,W;
  cin >> H >> W;
  vector<string> l(H);
  for(int i = 0;i < H;i++){
    cin >> l.at(i);
  }
  for(int i = 0;i < W+2;i++){
    cout << "#";
  }
  cout << endl;
  for(int i = 0;i < H;i++){
    cout << "#";
    cout << l.at(i);
    cout << "#" << endl;
  }
  for(int i = 0;i < W+2;i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int K;
  cin >> N>>K;
  vector<long long> ten(N);
  vector<long long>kekka(N);
  for(int i=0;i<N;i++){
    cin >> ten.at(i);
  }
  for(int b=0;b<N-K;b++){
    if(ten.at(b)<ten.at(b+K)){
      cout << "Yes"<<endl;
    }
    else{
      cout << "No"<<endl;
    }
  }
}


Measured memory_bytes: 6368
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;


int32_t main() {

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

    int l,r;
    cin>>l>>r;
    if(r-l>2019) cout<<0<<endl;
    else{
        int ans = 2020;
        for(int i=l;i<r;i++){
            for(int j=l+1;j<=r;j++){
                ans = min(ans,i%2019*j%2019);
            }
        }
        cout<<ans<<endl;
    }    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

// ALDS1_4_B
public class Main {
	boolean binarySearch(int[] array, int target, int min, int max) {
		if (max < min) return false;
		int mid = (max + min) / 2;
		if (array[mid] > target) return binarySearch(array, target, min, mid - 1);
		if (array[mid] < target) return binarySearch(array, target, mid + 1, max);
		return true;
	}
	
	void run() {
		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		for (int i = 0; i < q; i++) {
			if (binarySearch(S, sc.nextInt(), 0, S.length - 1)) count++;
		}
		System.out.println(count);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}



Measured memory_bytes: 81524
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int arr[100+5];
 
 int main()
 {
   int N;
   int count=0;
   cin>>N;
   for(int i=0;i<N;i++) cin>>arr[i];
   for(int i=0;i<N;i++)
   {
     int mini=i;
     for(int j=i;j<N;j++)
     {
       if(arr[j]<arr[mini])
       {
         mini=j;                    
       }        
     }       
     if(mini!=i)
     {
       count++;
       swap(arr[i],arr[mini]);           
     }
   }
   for(int i=0;i<N-1;i++) cout<<arr[i]<<" ";
   cout<<arr[N-1]<<endl;
   cout<<count<<endl;
   //while(1);
   return 0;
 }
 
 
 

Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int n,k;
const int INF = numeric_limits<int>::max();
int h[100005];
int dp[200005];

int main(){
	cin>>n>>k;
	for(int i=1; i<=n; i++) cin>>h[i];
	for(int i=1; i<=n; i++) dp[i] = INF;
	dp[1] = 0;
	for(int i=1; i<=n; i++){
		for(int j=1; j<=k; j++){
			dp[i+j] = min(dp[i+j],abs(h[i]-h[j+i])+dp[i]);
		}
	}
	cout<<dp[n];
}

Measured memory_bytes: 4380
#include <iostream>

int main() {
  int K;
  std::cin >> K;
  for (int i = 1, remainder = 0; i <= K; ++i) {
    remainder = (remainder * 10 + 7) % K;
    if (remainder == 0) {
      std::cout << i << std::endl;
      return 0;
    }
  }
  std::cout << -1 << std::endl;
  return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll A(5);
  REP(i,5) IN(A[i]);

  ll min_index = 0;
  REP(i,5) if(A[i]<A[min_index]) min_index = i;

  ll tmp = N/A[min_index];
  if(tmp*A[min_index]!=N) tmp++;

  OUT(tmp+4);


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define F(i) for(int i=0;i<n;i++)
#define G(i) for(int i=0;i<m;i++)
const int N=111;
char c[N][N];
bool L[N],C[N];
int n,m;
int main(){
	cin>>n>>m;
	F(i)G(j)
		cin>>c[i][j];
	F(i)G(j)
		L[i]|=c[i][j]=='#';
	G(i)F(j)
		C[i]|=c[j][i]=='#';
	F(i){
		G(j)
			if(L[i]&&C[j])
				cout<<c[i][j];
		if(L[i])
			cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
//============================================================================
// Name        : test.cpp
// Author      : Qihan
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <bits/stdc++.h>
#define Lowbit(x) (x & (-x))
using namespace std;
typedef long long int LLI;
typedef pair<int,int> PII;
const int maxn = (300000 + 10);

struct Seg{
	int l,r,len;
}op[maxn];

bool cmp(Seg a,Seg b){
	return a.len < b.len;
}

int c[maxn];

void add(int x,int change,int n){
	while(x < n){
		c[x] += change;
		x += Lowbit(x);
	}
}

int sum(int x){
	int ans = 0;
	while(x > 0){
		ans += c[x];
		x -= Lowbit(x);
	}
	return ans;
}

int main(){
//	freopen("/home/qihan/Documents/in","r",stdin);
	int n,m;
	memset(c,0,sizeof(c));
	scanf("%d%d",&n,&m);
	for(int i = 1;i <= n;i ++){
		scanf("%d%d",&op[i].l,&op[i].r);
		op[i].len = op[i].r - op[i].l + 1;
	}
	sort(op + 1,op + 1 + n,cmp);
	int k = 1;
	for(int i = 1;i <= m;i ++){
		for(;k <= n && op[k].len < i;k ++){
			add(op[k].l,1,300000);
			add(op[k].r + 1,-1,300000);
		}
		int ans = n - k + 1;
		for(int j = i;j <= m;j += i){
			ans += sum(j);
		}
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 5632
import java.io.*;
import java.util.*;

public class Main{
	//ai+aj=i-j
	//i-ai=aj+j
	public static void main(String[] args) throws Exception{
		pw=new PrintWriter(System.out);
		sc = new MScanner(System.in);
		int n=sc.nextInt();
		int[]in=sc.intArr(n);
		HashMap<Integer, Integer>map=new HashMap<>();
		long ans=0;
		for(int i=0;i<n;i++) {
			int dif=i-in[i];
			ans+=map.getOrDefault(dif, 0);
			map.put(i+in[i], map.getOrDefault(i+in[i], 0)+1);
		}
		pw.println(ans);
		pw.flush();
	}
	static PrintWriter pw;
	static MScanner  sc;
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
}


Measured memory_bytes: 66060
def maxHeapify(i, node_list):
    n = len(node_list)
    if 2*i+1 < n and node_list[2*i+1] > node_list[i]:
        i_largest = 2*i+1
        # node_list[i], node_list[2*i+1] = node_list[2*i+1], node_list[i]
    else:
        i_largest = i
    if 2*i+2 < n and node_list[2*i+2] > node_list[i_largest]:
        i_largest = 2*i+2
        # node_list[i], node_list[2*i+2] = node_list[2*i+2], node_list[i]

    if i_largest != i:
        node_list[i], node_list[i_largest] = node_list[i_largest], node_list[i]
        maxHeapify(i_largest, node_list)




n = int(input())
node_list = [int(i) for i in input().split()]
for i in range(n//2, -1, -1):
    maxHeapify(i, node_list)
print(' ' + ' '.join([str(node) for node in node_list]))



Measured memory_bytes: 63988
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
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; }


const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}





int main() {
  long long N,K;
  scanf("%lld%lld", &N,&K);
  
  COMinit();
  FOR(i,1,K){
    cout << COM(N-K+1,i)*COM(K-1,i-1)%MOD << endl;
  }

}



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

int main(){
    int a=0, b=0, c=0, n;
    
    for(int i=0; i<10; i++){
        cin >> n;
        if(n>a){
            c=b; b=a; a=n;
        }else if(n>b){
            c=b; b=n;
        }else if(n>c) c=n;
    }
    cout << a << endl << b << endl << c << endl;
    
    return 0;
}

Measured memory_bytes: 1160
def f(n):
    if n < 1:
        s = 0
    elif n == 1:
        s = 1
    else:
        s = ((n+1) // 2) % 2
        if n % 2 == 0:
            s ^= n
    return s

A, B = list(map(int, input().split()))
print(f(A-1) ^ f(B))


Measured memory_bytes: 3060
N=int(input())
S=input()
S=list(S)
p=[]
A=list("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
for i in S:
  for j,a in enumerate(A):
    if i==a:
      p.append(A[j+N])
      break
print(''.join(list(p)))

Measured memory_bytes: 3316
n,d = list(map(int,input().split(' ')))
x = [None]*n
y = [None]*n
ans = 0
for i in range(n):
    x[i],y[i] = list(map(int,input().split(' ')))
    if (x[i]**2+y[i]**2)**0.5 <= d:
        ans += 1
print(ans)

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

// #define int long long // intで書いたけど心配なときにlong longに変換する
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}


int t[20][20];
int DP[100000];

void solve(int N) {
    REP(i, N) REP(j, N+1) cin >> t[i][j];
    REP(ptn, 1 << N) DP[ptn] = INF;
    DP[0] = 0;

    int tmin;
    int nptn;
    REP(ptn, 1 << N) {
        REP(i, N) {
            if(1 << i & ptn) continue;
            tmin = t[i][0];
            REP(j, N) {
                if(1 << j & ptn) chmin(tmin, t[i][j+1]);
            }
            nptn = ptn | (1<<i);
            DP[nptn] = min(DP[nptn], DP[ptn] + tmin);
        }
    }
    print(DP[(1<<N)-1]);

}

signed main() {
    int N;
    while(true) {
        cin >> N;
        if(N == 0) {
            break;
        } else {
            solve(N);
        }
    }

    return 0;
}

// https://github.com/kurokoji/.cpp-Template/wiki テンプレートについて
// http://www.creativ.xyz/dump-cpp-652 dump()について
// https://gist.github.com/rigibun/7905920 色々


Measured memory_bytes: 3408
#include <stdio.h>

#define PE(a, b) {(a) += (b); if((a) >= mod) (a) -= mod;}

const int mod = 1000000007;
long long int dp[62][3];

int main(){
  int i, j;
  long long int n;
  scanf("%lld", &n);

  dp[0][0] = 1;
  for(i = 0; i < 61; n >>= 1, i++){
    for(j = 0; j <= 2; j++){
      int y = j - (n & 0x1) + 1;
      PE(dp[i+1][y>>1], dp[i][j]);
      PE(dp[i+1][y-(y>>1)], dp[i][j]);
      PE(dp[i+1][1+(y>>1)], dp[i][j]);
    }
  }
  printf("%lld\n", dp[61][0]);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int MAXN=100005;

int n;
int a[MAXN*2];

bool check(int x){
    for(int i=0;i<n-1;i++){
        if(a[n+i]>=x&&a[n+i+1]>=x) return 1;
        if(a[n-i]>=x&&a[n-i-1]>=x) return 1;
        if(a[n+i]<x&&a[n+i+1]<x) return 0;
        if(a[n-i]<x&&a[n-i-1]<x) return 0;
    }
    return a[1]>=x;
}

int main(){

	scanf("%d",&n);
	for(int i=1;i<2*n;i++) scanf("%d",&a[i]);
	int l=1,r=2*n;
	while(r-l>1){
	    int mid=(l+r)>>1;
        if(check(mid)) l=mid;
        else r=mid;
	}
	printf("%d",l);

	fclose(stdin);
	fclose(stdout);
}


Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public  static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

//        int n = sc.nextInt();
//        int k = sc.nextInt();
        char c[]=sc.nextString().toCharArray();
        int x=c.length,y=x;
        for (int i = 0; i < c.length; i++) {
			if(c[i]=='0' && i%2==0)x--;
			if(c[i]=='1' && i%2==1)x--;
			if(c[i]=='1' && i%2==0)y--;
			if(c[i]=='0' && i%2==1)y--;
		}

               
        out.println(min(x,y));
        out.flush();
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

//class P implements Comparable<P>{
//    int id,T;
//    P(int id, int T) {
//        this.id=id;
//        this.T=T;
//    }
//    public int compareTo(P p){
//        return id-p.id; //des
//    }
//}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
    	int r[] = new int[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextInt(); 
		}
    	return r;
    }
    public long[] nextLongArray(int size) throws IOException{
    	long r[] = new long[size];
    	for (int i = 0; i < size; i++) {
			r[i] = this.nextLong(); 
		}
    	return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 26580
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    s = input()
    print(s[:3:])

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 37396
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int cnt1 = min(N, M / 2);
    N -= cnt1;
    M -= cnt1 * 2;
    cout << cnt1 + (M / 4) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define IL inline
#define _  20005
#define ll long long
#define RG register
using namespace std ;

IL int gi() {
	RG int data = 0 , fu = 1 ; RG char ch = 0 ;
	while(ch != '-' && (ch < '0' || ch > '9')) ch = getchar() ; if(ch == '-') fu = -1 , ch = getchar() ;
	while('0' <= ch && ch <= '9') data = (data << 1) + (data << 3) + (ch ^ 48) , ch = getchar() ; return data * fu ;
}

int n , B[_] , q[_] , nq ;

int main() {
	n = gi() ;
	for(int i = 1; i <= n; i ++) B[i] = gi() ;
	for(int i = 1; i <= n; i ++) {
		if(nq < B[i] - 1) return puts("-1") , 0 ;
		for(int j = nq; j >= B[i] ; j --) q[j + 1] = q[j] ;
		q[B[i]] = i ;
		++ nq ;
	}
	for(int i = 1; i <= n; i ++) cout << B[q[i]] << endl ;
	cout << endl ;
	return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<functional>
#include<stdio.h>
using namespace std;

int main()
{
	//ifstream cin;
	//cin.open("input.txt");
	int n,k,a,odd=0,even=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a;
		if(a%2)
			odd++;
	}
	if(odd%2)
		cout<<"NO";
	else
		cout<<"YES";	

	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.par=[i for i in range(n)]
        self.size=[1]*n
    def find(self,x):
        if x==self.par[x]:
            return self.par[x]
        else:
            self.par[x]=self.find(self.par[x])
            return self.par[x]
    def unite(self,x,y):
        x=self.find(x)
        y=self.find(y)
        if x==y:
            return
        if self.size[x]>self.size[y]:
            self.size[x]+=self.size[y]
            self.par[y]=x
        else:
            self.size[y]+=self.size[x]
            self.par[x]=y

n=int(input())

x_list=[]
y_list=[]

for i in range(n):
    x,y=map(int,input().split())
    x_list.append((x,i))
    y_list.append((y,i))
x_list.sort()
y_list.sort()
edges=[]

for i in range(1,n):
    edges.append((x_list[i][0]-x_list[i-1][0],x_list[i][1],x_list[i-1][1]))

    edges.append((y_list[i][0]-y_list[i-1][0],y_list[i][1],y_list[i-1][1]))

edges.sort()
uf=UnionFind(n)
ans=0
for e in edges:
    wt=e[0]
    x=e[1]
    y=e[2]
    if uf.find(x)==uf.find(y):
        continue
    ans+=wt
    uf.unite(x,y)
print(ans)



Measured memory_bytes: 53720
from collections import defaultdict
d = int(input())
c = list(map(int,input().split()))
s = []
for i in range(d):
    s.append(list(map(int,input().split())))
dic = defaultdict(int)
for i in range(1,d+1):
    maxscore = 0
    maxcontest = -1
    for k in range(26):
        score = 0
        score += s[i-1][k-1]
        score += c[k]*(i-dic[k])
        if score > maxscore:
            maxscore = score
            maxcontest = k
    print(maxcontest+1)
    dic[maxcontest] = i


Measured memory_bytes: 68736
#include <iostream>
#include <string.h>
using namespace std;

int main() {
	int n, k;	char s[256];
	cin >> n >> s >> k;
	char sum;

	sum = s[k-1];

	for (int i = 0; i < n; i++) {
		if (s[i] != sum) {
			s[i] = '*';
		}
	}

	cout << s << endl;

	return 0;
}

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

using namespace std;

int main() {

	int n,x;
	cin >> n >> x;

	vector<int> l;
	l.push_back(0);
	for (int i = 1; i < n+1; i++) {
		l.push_back(0);
		cin >> l[i];
	}

	int d=0;
	int counter = 1;
	for (int i = 1; i < n + 1; i++) {
		d = d + l[i];
		if (d <= x) {
			counter++;
		}
		else {
			cout << counter << endl;
			return 0;
		}
	}
	cout << counter << endl;

}

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

int main()
{
    long long N;
    std::cin >> N;
    long long n_r = 0, n_g = 0, n_b = 0;
    std::vector<char> S(N);
    for (long long i = 0; i < N; i++)
    {
        char c;
        std::cin >> c;
        S[i] = c;
        if (c == 'R')
        {
            n_r++;
        }
        else if (c == 'G')
        {
            n_g++;
        }
        else if (c == 'B')
        {
            n_b++;
        }
        else
        {
            return -1;
        }
    }

    long long count = 0;
    for (long long j = 1; j < N - 1; j++)
    {
        for (long long diff = 1; j - diff >= 0 && j + diff < N; diff++)
        {
            long long i = j - diff;
            long long k = j + diff;
            if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i])
            {
                count++;
            }
        }
    }
    std::cout << n_r * n_g * n_b - count << std::endl;
}

Measured memory_bytes: 3656