akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int w,h;
int px,py,pa;
char f[22][22];
int dx[] = {0,0,-1,1};
int dy[] = {-1,1,0,0};
int main(void){
  int n;
  cin >> n;
  for(int k = 0; k < n; k++){
    cin >> h >> w;
    for(int y = 0; y < h; y++){
      for(int x = 0; x < w; x++){
	cin >> f[x][y];
	switch(f[x][y]){
	case '^': px = x; py = y; pa = 0; break;
	case 'v': px = x; py = y; pa = 1; break;
	case '<': px = x; py = y; pa = 2; break;
	case '>': px = x; py = y; pa = 3; break;
	}
      }
    }
    int m;
    cin >> m;
    for(int i = 0; i < m; i++){
      char c;
      cin >> c;
      if(c == 'S'){
	for(int nx = px + dx[pa],ny = py + dy[pa];0 <= nx && nx < w && 0 <= ny && ny < h; nx+=dx[pa],ny+=dy[pa]){
	  if(f[nx][ny] == '*'){
	    f[nx][ny] = '.';
	    break;
	  }
	  if(f[nx][ny] == '#') break;
	}
      }else{
	f[px][py] = '.';
	switch(c){
	case 'U': pa = 0; break;
	case 'D': pa = 1; break;
	case 'L': pa = 2; break;
	case 'R': pa = 3; break;
	}
	int nx = px + dx[pa];
	int ny = py + dy[pa];
	if(0 <= nx && nx < w && 0 <= ny && ny < h && f[nx][ny] == '.'){
	  px = nx;
	  py = ny;
	}
	switch(pa){
	case 0: f[px][py]='^'; break;
	case 1: f[px][py]='v'; break;
	case 2: f[px][py]='<'; break;
	case 3: f[px][py]='>'; break;
	}
      }
    }
    for(int y = 0; y < h; y++){
      for(int x = 0; x < w; x++){
	cout << f[x][y];
      }
      cout << endl;
    }
    if(n-k-1) cout << endl;
  }
}

Measured memory_bytes: 1152
#include <stdio.h>
 
int main(void){
    int number[5];
    int max, num,i,temp1,temp2;
    while (1){
        scanf("%d %d", &temp1, &temp2);
        if (temp1==0 && temp2 == 0){
        	break;
        }
        number[0] = temp1+temp2;
        max=number[0];
        num=0;
        for (i=1;i<5;i++){
            scanf("%d %d", &temp1, &temp2);
            number[i] = temp1 + temp2;
            if (max < number[i]){
                max = number[i];num = i;
            }
        }
        switch (num){
            case 0:
                printf("A %d\n", max);
                break;
            case 1:
                printf("B %d\n", max);
                break;
            case 2:
                printf("C %d\n", max);
                break;
            case 3:
                printf("D %d\n", max);
                break;
            case 4:
                printf("E %d\n", max);
                break;
            default:
                break;
        }
    }
     
    return (0);
}

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

int main(){
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> vec_b(m);
	for (int i = 0; i < m; i++) cin >> vec_b.at(i);
	vector<vector<int>> vec_a(n, vector<int>(m));
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> vec_a.at(i).at(j);
		}
	}
	int res = 0;
	for (int i = 0; i < n; i++) {
		int ans = c;
		for (int j = 0; j < m; j++) {
			ans += vec_a.at(i).at(j) * vec_b.at(j);
		}
		(ans > 0) ? res++ : res=res;
	}
	cout << res << endl;
}


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

int main()
{
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    rep(i, m) cin >> b[i];
    vector<int> a(m);
    int cnt = 0;
    rep(i,n){
        int ans = 0;
        rep(j, m) {
            cin >> a[j];
            ans += a[j]*b[j];
        }
        ans += c;
        if (ans > 0) cnt++;
    }
    cout << cnt << endl;

}

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

struct info{
	int a, b;

	bool operator< (const info &tmp) const {
		return b < tmp.b;
	}
};

bool cmp_a(info i1, info i2){
	return i1.a < i2.a; 
}

const int N = 1e5+10;
info v[N];
int n, m;

int main(){
	cin >> n >> m;
	for(int i=0; i < n; i++){
		cin >> v[i].a >> v[i].b;
	}
	sort(v, v+n, cmp_a);
	priority_queue<info> q;
	int index = 0;
	int ans = 0;
	for(int i=0; i <= m; i++){
		while(index < n and v[index].a <= i) q.push(v[index++]);
		if(q.size()) ans += q.top().b, q.pop();
	}
	cout << ans << endl;
}

Measured memory_bytes: 2168
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll ; 
typedef long double ld ;
typedef pair<ll , ll> pll ;

const ll N = 2e5 + 30 , Mod = 1e9 + 7 ;
const ll SQ = 330 ;

int main () {
    ios::sync_with_stdio(0), cin.tie(0) ;
    ll n ;
    cin >> n ;
    n -- ;
    cout << n / 2 << endl;
    
    return (0) ;
}

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

using ll = long long;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    rep(i, N - 1) cin >> C[i];
    int ans = B[A[0] - 1];
    rep(i, N - 1) {
        ans += B[A[i + 1] - 1];
        if (A[i + 1] == A[i] + 1) ans += C[A[i] - 1];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n = gets.to_i
w = gets.split(" ").map(&:to_i)

class Array
  def s1(t)
    self[0...t].inject(:+)
  end
  
  def s2(t)
    self.inject(:+) - s1(t)
  end

  def s1_minus_s2(t)
    s1(t) - s2(t)
  end
end

abs_nums = []
(1...n).each do |i|
  abs_nums.push((w.s1_minus_s2(i)).abs)
end

puts abs_nums.min

Measured memory_bytes: 1788
from bisect import bisect_left as bl
INF = 10 ** 20

def main():
  
  w, h = map(int, input().split())
  n = int(input())
  
  xlst = []
  ylst = []
  appx = xlst.append
  appy = ylst.append

  for i in range(n):
    x, y = map(int,input().split())
    appx(x)
    appy(y)
  
  sorted_xlst = sorted(xlst)
  sorted_ylst = sorted(ylst)

  #x, yの中央値の候補
  clx = sorted_xlst[n // 2 if n % 2 else n // 2 - 1]
  crx = sorted_xlst[n // 2]
  cly = sorted_ylst[n // 2 if n % 2 else n // 2 - 1]
  cry = sorted_ylst[n // 2]

  #x, yの中央値の候補のindex
  ilx = bl(sorted_xlst, clx)
  irx = bl(sorted_xlst, crx)
  ily = bl(sorted_ylst, cly)
  iry = bl(sorted_ylst, cry)

  sumx = sum(xlst)
  sumy = sum(ylst)

  #x, yそれぞれについての中央値と各点までの往復距離の総和
  xllen = (sumx - sum(sorted_xlst[:ilx]) * 2 - clx * (n - ilx * 2)) * 2
  xrlen = (sumx - sum(sorted_xlst[:irx]) * 2 - crx * (n - irx * 2)) * 2
  yllen = (sumy - sum(sorted_ylst[:ily]) * 2 - cly * (n - ily * 2)) * 2
  yrlen = (sumy - sum(sorted_ylst[:iry]) * 2 - cry * (n - iry * 2)) * 2

  ans = ansx = ansy = INF
  max_sumd = 0
  
  #各点について復路を省いた場合の距離の和を求める
  for i in range(n):
    xi = xlst[i]
    yi = ylst[i]

    cx, xlen = (crx, xrlen) if xi <= clx else (clx, xllen)
    cy, ylen = (cry, yrlen) if yi <= cly else (cly, yllen)

    dx = xi - cx if xi >= cx else cx - xi
    dy = yi - cy if yi >= cy else cy - yi

    if max_sumd > dx + dy:
      continue
    else:
      max_sumd = dx + dy
    
    tlen = xlen + ylen - max_sumd

    if ans > tlen:
      ans = tlen
      ansx = cx
      ansy = cy
    elif ans == tlen:
      if ansx > cx:
        ansx = cx
        ansy = cy
      elif ansx == cx:
        if ansy > cy:
          ansy = cy 
  
  print(ans)
  print(ansx, ansy)

main()


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'

int main(){
    int n, m;
    cin >> n >> m;
    vector<string> s(n);

    for(int i=0; i<n; ++i)
        cin >> s[i];
    
    const int dx[] = {1,0,-1,0};
    const int dy[] = {0,1,0,-1};

    for(int i=0; i<n; ++i){
        for(int j=0; j<m; ++j){
            if(s[i][j]=='#'){
                int count=0;
                for(int k=0; k<4; ++k){
                    int nx = i+dx[k];
                    int ny = j+dy[k];

                    if(nx < 0 || ny < 0 || nx >= n || ny >= m)
                        continue;
                    if(s[nx][ny]=='.')
                        count++;
                }

                if(count==4){
                    cout << "No";
                    return 0;
                }
            }
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 3600
count = 0
s = str(input())
if s[0] == 'R':
    count += 1
    if s[1] == 'R':
        count +=1
        if s[2] == 'R':
            count += 1
else:
    if s[1] == 'R':
        count += 1
        if s[2] == 'R':
            count +=1
    else:
        if s[2] == 'R':
            count +=1
print(count)

Measured memory_bytes: 9120
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 2 ** x 未満だとx段のピラミッド
H = ir()
x = 0
while True:
    if 2 ** x > H:
        break
    else:
        x += 1

answer = 0
for i in range(x):
    answer += 2 ** i

print(answer)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int n,k,arr[109];
long long dp[109][100009];
long long sum[109][100009];
long long mod = 1000000007;
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>arr[i];
	for(int i=0;i<=k;i++) sum[0][i] = 1;
	dp[0][0] = 1;
	for(int i=1;i<=n;i++){
		dp[i][0] = 1;
		sum[i][0] = 1;
		for(int j=1;j<=k;j++){
			dp[i][j] = sum[i-1][j];
			if(j-arr[i]-1 >= 0) dp[i][j] = (dp[i][j] - sum[i-1][j-arr[i]-1] + mod)%mod;
		}
		for(int j=1;j<=k;j++){
			sum[i][j] = (sum[i][j-1] + dp[i][j])%mod;
		}
	}
	cout<<dp[n][k]<<endl;
}


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

using namespace std;

int main () {
    string S, T;
    cin >> S >> T;
    int res  = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3908
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int fly[]={4,1,4,1,2,1,2,1},peo[8],remainder,num=0,point=0;
    while(cin>>peo[0]){
        for(int i=1;i<8;i++)cin>>peo[i];
        for(int i=0;i<8;i++){
            for(int j=0;j<8;j++)if(fly[(i+j)%8]<peo[j])num+=peo[j]-fly[(i+j)%8];
            if(remainder>num||i==0){
                remainder=num;
                point=i;
            }
            else if(remainder==num){
                for(int j=0;j<8;j++){
                    if(fly[(i+j)%8]>fly[(point+j)%8])break;
                    else if(fly[(i+j)%8]<fly[(point+j)%8]){
                        point=i;
                        break;
                        }
                    }
                }
            num=0;
        }
        for(int i=0;i<7;i++)cout<<fly[(point+i)%8]<<" ";
            cout<<fly[(point+7)%8]<<endl;
    }
}

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

const int MAX_M=1e5+5;

int X[MAX_M];
vector<int> diff;
int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++){
    cin>>X[i];
  }
  if(n>=m){
    cout<<0<<endl;
  }else{
   sort(X,X+m);
   for(int i=0;i<m-1;i++){
     diff.push_back(X[i+1]-X[i]);
   }
   sort(diff.begin(),diff.end(),greater<int>());
   int ans=X[m-1]-X[0];
   for(int i=0;i<n-1;i++){
     ans-=diff[i];
   }
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
int x[maxn];
int main(){
	int n,k;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>x[i];
	int ans=100*100*100+5;
	for(int p=1;p<=100;p++){
		int tmp=0;
		for(int i=1;i<=n;i++){
			tmp+=(x[i]-p)*(x[i]-p);
		}
		ans=min(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<28)
#define LLINF (1LL<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
typedef pair<int, int> P;

int main() {
    ll n, m, vote[100], sum = 0, ans = 0;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        cin >> vote[i];
        sum += vote[i];
    }
    for (int i = 0; i < n; i++) {
        if (vote[i] * 4 * m>=sum)ans++;
    }
    if (ans >= m)Yes;
    else No;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=5005;
int mod;
inline int Add(int x,int y){
    return (x+=y)>=mod?x-mod:x;
}
inline int Sub(int x,int y){
    return (x-=y)<0?x+mod:x;
}
inline int Mul(int x,int y){
    return 1ll*x*y%mod;
}
int n,k;
int dp[max_n][max_n];
int gx(int x){
    if(x<=k+1)return x-1;
    return n+2-x;
}
int main(){
    scanf("%d%d",&n,&mod);
    k=n/2;
    dp[n+1][0]=1;
    for(int i=n;i>=2;i--){
        int x=gx(i);
        for(int j=0;j<=n;j++){
            for(int k=0;k*x<=j;k++){
                dp[i][j]=Add(dp[i][j],dp[i+1][j-k*x]);
            }
        }
    }
    int ans=0;
    for(int i=0;i<=n;i++)ans=Add(ans,Mul(dp[2][i],n-i));
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 98048
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string a, b;
  cin >> a >> b;
  int num = stoll(a + b);
  int val = sqrt(num);
  if (val * val == num) {
    print("Yes");
  } else {
    print("No");
  }
}

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

namespace AtCoder.Contests.ABC165
{
    /// <summary>
    /// 
    /// </summary>
    static class A
    {
        static void Main(string[] args)
        {
            var k = NextInt();
            var a = NextInt();
            var b = NextInt();

            Console.WriteLine(b - (b % k) >= a ? "OK" : "NG");
        }

        #region Console
        static int _index = 0;
        static string[] _buffer;

        static string Next()
        {
            if (_buffer == null || _index >= _buffer.Length)
            {
                _buffer = Console.ReadLine().Split();
                _index = 0;
            }

            return _buffer[_index++];
        }
        static int NextInt()
        {
            return int.Parse(Next());
        }
        static long NextLong()
        {
            return long.Parse(Next());
        }
        static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        static int[] ReadIntArray()
        {
            return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        static int[] ReadIntArray(int n)
        {
            var a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadInt();
            }
            return a;
        }
        static long[] ReadLongArray()
        {
            return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        static long[] ReadLongArray(int n)
        {
            var a = new long[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = ReadLong();
            }
            return a;
        }
        static List<T> ReadObjects<T>(int n, Func<int[], T> creator)
        {
            var l = new List<T>(n);

            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                l.Add(creator(a));
            }

            return l;
        }

        static int[,] ReadMatrix(int n, int m)
        {
            var r = new int[n, m];
            for (int i = 0; i < n; i++)
            {
                var a = ReadIntArray();
                for (int j = 0; j < m; j++)
                {
                    r[i, j] = a[j];
                }
            }
            return r;
        }
        #endregion
    }
}


Measured memory_bytes: 27504
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int m1,m2,d1,d2;
    int cnt = 0, ans = 0;
    vector<int> vec(10);
    string S;

    cin >> m1 >> d1 >> m2 >> d2;
    if(m1 != m2) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
n=int(input())
b=[int(x) for x in input().split()]
a=[0]*n
a[0]=b[0]
a[n-1]=b[n-2]
for i in range(1,n-1):
    s=min(b[i],b[i-1])
    a.append(s)
    
print(sum(a))

Measured memory_bytes: 9120
import numpy as np

N, M, X = map(int, input().split())
C = np.zeros(N, dtype=np.int)
A = np.zeros((N, M), dtype=np.int)

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


least_cost = np.inf


for pattern in range(2 ** N):
	knowledge = np.zeros(M, dtype=np.int)
	cost = 0
	
	for i in range(N):
		if (pattern >> i) & 1:
			cost += C[i]
			for j in range(M):
				knowledge[j] += A[i, j]
	
	if np.all(knowledge >= X) and cost < least_cost:
		least_cost = cost


if np.isinf(least_cost):
	print(-1)
else:
	print(least_cost)


Measured memory_bytes: 27272
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
       
       if(A<=8 && B<=8){
           System.out.println("Yay!");
       }
       
       else{
           System.out.println(":(");
       }
    }
}

Measured memory_bytes: 21844
using System;
using System.Collections.Generic;

public class Hello{
    public static void Main(){
        var input = Console.ReadLine().Split(' ');
        var product = Console.ReadLine().Split(' ');
        var answer = "";
        List<int> voteList = new List<int>();
        int total = 0;
        
        for(var i = 0; i < int.Parse(input[0]);i++){
            total += int.Parse(product[i]);
            voteList.Add(int.Parse(product[i]));
        }
        voteList.Sort((a, b) => b - a);
        
        if((double)(voteList[int.Parse(input[1]) -1]) >= total / 4.0 / int.Parse(input[1])){
            answer = "Yes";
        }else{
            answer = "No";
        }
        
        Console.WriteLine(answer);
    }
}

Measured memory_bytes: 11220
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))

N = int(input())

cnt = 0
for i in range(1, N + 1):
    if len(str(i)) % 2 == 1:
        cnt += 1

print(cnt)


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

int a[100010];
int b[100010];
int main()
{
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	for(int i = 1; i <= n; i++){
		b[a[i]] = i;
	}
	for(int i = 1; i <= n; i++){
		cout << b[i] << " ";
	}
	return 0;
}


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

int main(){
    double n, a[1005], suma = 0;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> a[i];
        a[i] = 1/a[i];
        suma += a[i];
    }
    cout << 1/suma;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    CIN(ll, K);
    vector<pair<int,int>> ab(N);

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab.begin(),ab.end());

    ll k = 0;
    int ans;
    for (int i = 0; i < N; i++) {
        k += ab[i].second;
        if ( k >= K ) {
            ans = ab[i].first;
            break;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

signed main(){
    int n,x;
    cin >> n >> x;
    if(x == 1 || x == 2 * n - 1){
        cout << "No" << endl;
        return 0;
    }
    int ans[2 * n - 1];
    ans[n - 1] = x;
    int now = 1;
    for(int i = n - 2; i >= 0; i--){
        if(now == x) now++;
        ans[i] = now;
        now++;
    }
    now = 2 * n - 1;
    for(int i = n; i < 2 * n; i++){
        if(now == x) now--;
        ans[i] = now;
        now--;
    }
    cout << "Yes" << endl;
    REP(i,2 * n - 1){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 2304
import java.util.Scanner;

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

        if (n % 2 == 0) {
            for (int i = a.length - 1; i >= 0; i -= 2) {
                if (i != a.length - 1) {
                    System.out.print(" ");
                }
                System.out.print(a[i]);
            }
            for (int i = 0; i < a.length ; i += 2) {
                System.out.print(" " + a[i]);
            }
            System.out.println();
        } else {
            for (int i = a.length - 1; i >= 0; i -= 2) {
                if (i != a.length - 1) {
                    System.out.print(" ");
                }
                System.out.print(a[i]);
            }
            for (int i = 1; i < a.length ; i += 2) {
                System.out.print(" " + a[i]);
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 91168
#include<iostream>
#include <string>
#include<vector>
typedef long long ll;

using namespace std;
int main()
{
	int n;
	cin >> n;
	int copy = n;
	int sum;
	while (1) {
		sum += n % 10;
		n /= 10;
		if (n == 0) break;
	}
	if (copy%sum==0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
# AtCoder
N = int(input())
lst = [int(x) for x in input().split()]
ans = 0

for i in range(1, len(lst)-1):
    first = lst[i-1]
    second = lst[i]
    third = lst[i+1]

    if first < second < third or third < second < first:
        ans += 1

print(ans)


Measured memory_bytes: 3060
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*                                                    
      I ♥ CLARICE STARLING...                                                               
        EXPLAINATION BELOW->
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
const ll INF = (ll)2e18 + 77;
void solve()
{
   int n,i,ans=0;cin>>n;
   ll r;cin>>r;
   fo(i,0,n)
   {
       ll x,y;cin>>x>>y;
       if(x*x+y*y<=r*r)ans++;
   }
   cout<<ans<<"\n";
}
int main()
{
   fastio
   //Test_cases
   solve();
  return 0;
}
//**always check if you are not killing input in between
//map<ll,ll,greater<int>> to sort in descending order ,in iterator declaration no greater<int>
//if you want to apply lowerbound on set use s.lower_bound(key),not the one used for vector
// Syntax to create a min heap for priority queue priority_queue <int, vector<int>, greater<int>>; 
//for modinverse use modularexponention(x,M-2,M);
//for "each" subtraction from ans(ans-k) if(ans<0) do ans+=MOD,ans%=MOD
//vector<vector<int>>dp(201,vector<int>(n+1)); A way to initialize vector of vector
//string2=string1.substr(pos,length);if len no specified then till end
//void fill (ForwardIterator first, ForwardIterator last, const T& val);
//The range filled is [first,last), which contains all the elements between first and last, including the element pointed by first but not the element pointed by last.


//If wrong on pretest 2 means logically wrong
/* TIPS FOR DEBUGGING
 * Check if values are not overflowing (use long long where required)
 * Check if ranges are inclusive or not.
 * Check properly if greedy will work or not before using it.
 * Check EDGE CASES!! Seriously, even in 2B, saving 8 points by being
 * 2 minutes faster will bite you in the ass if you don't make sure
 * it works on edge cases.
 * Keep adding to this list.
*/


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;

public class Main {

	private static final double[] time500M  = {-1, 35.50,  37.50,  40.00,  43.00,  50.00,  55.00,  70.00, Double.MAX_VALUE};
	private static final double[] time1000M = {-1, 71.00,  77.00,  83.00,  89.00, 105.00, 116.00, 148.00, Double.MAX_VALUE};
	private static final String[] rankName = {"", "AAA", "AA", "A", "B", "C", "D", "E", "NA"};

	private static final int binSearch(double[] list, double val) {
		int min=0;
		int max=list.length-1;
		int mid=(min+max)/2;
		while(mid!=min) {
			if(list[mid]>val)
				max=mid;
			else
				min=mid;
			mid=(min+max)/2;
		}
		return max;
	}

	public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		LinkedList<Integer> res=new LinkedList<Integer>();

		String line=br.readLine();
		while(line!=null&&line.length()!=0) {
			String[] strArray=line.split(" ");
			double t5=Double.parseDouble(strArray[0]);
			double t1=Double.parseDouble(strArray[1]);
			int r5=binSearch(time500M, t5);
			int r1=binSearch(time1000M, t1);

			int rank=r5>r1?r5:r1;
			res.add(rank);

			line=br.readLine();
		}

		br.close();

		for(int val: res)
			System.out.println(rankName[val]);
	}
}

Measured memory_bytes: 17048
#include<iostream>

using namespace std;

int c[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};

int main()
{
    int a,b;
    cin>>a>>b;
    if(c[a]==c[b])cout<<"Yes";
    else cout<<"No";
}
/*code in 90 seconds*/

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

#pragma GCC optimze("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")

#define x first
#define y second
#define pb push_back
#define mp make_pair

#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()

#define ll long long

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s;
    cin >> n >> s;
    if (n & 1) {
        cout << "No\n";
    } else {
        string t = s.substr(0, n / 2), u = s.substr(n / 2, n / 2);
        if (t == u) {
            cout << "Yes\n";
        } else {
            cout << "No\n";
        }
    }
    return 0;
}


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

int main() {
    int a[3];
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    sort(a,a+3);
    printf("%d %d %d\n",a[0],a[1],a[2]);
}


Measured memory_bytes: 2676
#include<iostream>

using namespace std;

typedef long long ll;

ll n,m;
int a[100005];
int b[100005];
ll p;
ll ra[100005];
ll par[100005];
ll S[100005];
ll ans[100005];
void init(int n) {
  for(int i = 0; i < n; i++) {
    par[i] = i;
    S[i] = 1;
  }
  return;
}

int F(int x) {
  return par[x] == x ? x : par[x] = F(par[x]);
}

void U(int a, int b, int i) {
  int x = F(a);
  int y = F(b);
 
  if(x == y) {
    ans[i-1] = p;
    return;
  }
  else {
    if(ra[x] >= ra[y]) {
      par[y] = x;
      if(ra[x] == ra[y]) ra[x]++;
    }
      else par[x] = y;

    ans[i-1] = p - S[x] * S[y];
    p -= S[x] * S[y];
      S[y] += S[x];
      S[x] = S[y];
  }
  return;
}

ll nC2(ll n) {
  return n * (n-1) / 2;
}

int main() {
  cin >> n >> m;
  init(n);
  for(int i = 0; i < m; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }

  p = nC2(n);
  ans[m-1] = p;

  for(int i = m - 1; i > 0; i--) U(a[i],b[i],i);

  for(int i = 0; i < m; i++) {
    cout << ans[i] << endl;
  }
}
  
  


Measured memory_bytes: 5248
using System;
using System.Linq;

namespace Math_Functions_Distance
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] i = Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray();
            Console.WriteLine("{0}", Math.Sqrt(Math.Pow(i[2] - i[0], 2) + Math.Pow(i[3] - i[1], 2)));
        }
    }
}

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

int top, S[100];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top+1];
}

int main(int argc, char const *argv[])
{
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push (a+b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push (b - a);
		}
		else if (s[0] == '*')  {
			a = pop();
			b = pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}
	printf("%d\n", S[1]);

	return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    vector<array<ll,4>> dp0(n+1),dp1(n+1);
    for (int i = 0;i < n+1;++i) dp0[i].fill(0);
    for (int i = 0;i < n+1;++i) dp1[i].fill(0);
    dp0[0][0] = 1;
    for (int i = 0;i < n;++i) {
        for (int l = 0;l < k+1;++l) dp1[i+1][l] += dp1[i][l];
        for (int l = 0;l < k;++l) dp1[i+1][l+1] += dp1[i][l]*9;
        if (s[i] > '0') {
            for (int l = 0;l < k;++l) {
                dp0[i+1][l+1] += dp0[i][l];
                dp1[i+1][l+1] += dp0[i][l]*(s[i]-'0'-1);
            }
            for (int l = 0;l < k+1;++l) dp1[i+1][l] += dp0[i][l];
        } else for (int l = 0;l < k+1;++l) dp0[i+1][l] += dp0[i][l];
    }
    cout << dp0[n][k]+dp1[n][k] << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        int[] a1 = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] a2 = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int[] result = new int[n];
        for (int i = 0; i < n; i ++) {
            result[i] = a1.Where((x,y) => y<=i).Sum() + a2.Where((x,y) => y>=i).Sum();
        }
        Console.WriteLine(result.Max());
    }
}

Measured memory_bytes: 13396
#include <stdio.h>
int main(void){
    int N,a,b,c;
    scanf("%d",&N);
    while(N>0){
        scanf("%d %d %d",&a,&b,&c);
        if(a*a==b*b+c*c || b*b==c*c+a*a || c*c==a*a+b*b){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
        N--;
    }
    return 0;
}

Measured memory_bytes: 580
class UnionFind:
    def __init__(self, N):
        self.data = []
        for i in range(N):
            self.data.append(-1)
    def root(self, a):
        if self.data[a] < 0:
            return a
        else:
            self.data[a] = self.root(self.data[a])
            return self.data[a]
    def same(self, a, b):
        if self.root(a) == self.root(b):
            return 1
        else:
            return 0
    def unite(self, a, b):
        a = self.root(a)
        b = self.root(b)
        if a == b:
            return 0
        if self.data[a] < self.data[b]:
            self.data[a] += self.data[b]
            self.data[b] = a
        else:
            self.data[b] += self.data[a]
            self.data[a] = b
        return 1
s = input().split(" ")
N = int(s[0])
M = int(s[1])
a = []
b = []
for i in range(M):
    s = input().split(" ")
    a.append(int(s[0]) - 1)
    b.append(int(s[1]) - 1)
res = 0
for i in range(M):
    uf = UnionFind(N)
    for j in range(M):
        if j != i:
            uf.unite(a[j], b[j])
    if uf.same(a[i], b[i]) == 0:
        res += 1
print(res)

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

class Main {

    static int[] a;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    }
    
}

Measured memory_bytes: 43164
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int A[][] = new int[n][m];
        int b[] = new int[m];
         int seki;
            for(int i = 0; i < n; i++){
            for(int j = 0; j < m; j++){
                A[i][j] = scanner.nextInt();
            }
        }
        for(int i = 0; i < m; i++){
            b[i] = scanner.nextInt();
        }
       
        for(int i =0;i<n;i++){
            seki=0;
           for(int j =0;j<m;j++){ 
                seki= seki+A[i][j]*b[j];
           }    
                System.out.println(seki);
           
}
}
}

Measured memory_bytes: 40504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pair<int, int>> vpii;
typedef pair<int, int> pii;
#define PB push_back
#define EB emplace_back
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define N 100'005
int p[N];
int d[N]={};
int s[N];

int par(int i){
	while(i!=p[i]) i=p[i];
	return i;
}

void mer(int a, int b){
	a=par(a);
	b=par(b);
	if(d[a]<d[b]) swap(a, b); // become d[a]>d[b]
	p[b]=a;
	LAR(d[a], d[b]+1);
	s[a]+=s[b];
}

int a[N], b[N];
ll c[N];

int main(){
	REP(i, N) p[i]=i;
	fill(s, s+N, 1);
	int n, m; scanf("%d%d", &n, &m);
	REP(i, m) scanf("%d%d", a+i, b+i);
	reverse(a, a+m);
	reverse(b, b+m);
	ll ans=n*(n-1LL)/2;
	REP(i, m){
		c[m-1-i] = ans;
		int x = a[i], y = b[i];
		x = par(x); y = par(y);
		if(x != y){
			ans -= ((ll) s[x]) * s[y];
			mer(x, y);
		}
	}
	REP(i, m) printf("%lld\n", c[i]);
}


Measured memory_bytes: 4096
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD = 1000000007;
using namespace std;

int main()
{
	string s;
	cin >> s;
	int l1 = 0;
	int l2 = 0;

	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'A')
		{
			l1 = i;
			break;
		}
	}
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] == 'Z')
		{
			l2 = i;
		}
	}
	cout << l2 - l1 + 1 << endl;

	return 0;
}

Measured memory_bytes: 640
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2020;
int n , m;
char s[N][N];
int a[N][N],up[N],_;
pii st[N];

int main(){
    scanf("%d%d",&n,&m);
    int ans=max(n,m);
    rep(i,0,n) scanf("%s",s[i]);
    rep(i,1,n) rep(j,1,m)
        a[i-1][j-1]=(s[i-1][j-1]^s[i-1][j]^s[i][j-1]^s[i][j])==0;
    rep(i,0,n-1) {
        _=0;
        rep(j,0,m-1) {
            if(a[i][j] == 1) up[j]++;
            else up[j]=0;
            int w=0;
            while(_>0&&up[j]<st[_-1].fi) {
                w+=st[_-1].se;
                ans=max(ans,(st[_-1].fi+1)*(w+1));
                --_;
            }
            st[_++]=mp(up[j],w+1);
        }
        int w=0;
        while(_>0) {
            w+=st[_-1].se;
            ans=max(ans,(st[_-1].fi+1)*(w+1));
            --_;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 20096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int A, B, C;
	cin >> A >> B >> C;
	
	if (A < C && C < B) co("Yes");
	else if (B < C && C < A) co("Yes");
	else co("No");

	Would you please return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
template < class R > inline void Readin( R &K ) {bool F=K=0;char C=getchar();while(C<'0'||C>'9')
{if(C=='-')F=1;C=getchar();}while(C<='9'&&C>='0')K=(K<<1)+(K<<3)+C-'0',C=getchar();if(F)K=-K;}
template < class R > inline void Checkmax( R &A , R B ) { if( A < B ) A = B ; }
template < class R > inline void Checkmin( R &A , R B ) { if( A > B ) A = B ; }
bool Map[500] ;
char C[1005] ;
int main() {
	scanf( "%s" , C ) ;
	for(register int i = strlen( C ) ; i-- ; )
		Map[C[i]] = true ;
	return not printf( "%s\n" , ( Map['N'] == Map['S'] and Map['E'] == Map['W'] ) ? "Yes" : "No" ) ;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 100'000
#define N_ACT 3
i64 N;
i64 plan[MAX_N][N_ACT];
i64 dp[2 * MAX_N][N_ACT];

void solve() {
    REP(i, 2 * MAX_N) REP(j, N_ACT) dp[i][j] = 0;
    REP(a, N_ACT) dp[0][a] = plan[0][a];

    REP(i, N - 1) {
        REP(a, N_ACT) {
            chmax(dp[i + 1][a], dp[i][(a + 1) % N_ACT] + plan[i + 1][a]);
            chmax(dp[i + 1][a], dp[i][(a + 2) % N_ACT] + plan[i + 1][a]);
        }
    }

    i64 res = 0;
    REP(a, N_ACT) chmax(res, dp[N - 1][a]);
    cout << res << endl;
}

int main() {
    cin >> N;
    REP(i, N) REP(j, N_ACT) cin >> plan[i][j];

    solve();

    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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 ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  string s;
  cin >> s;

  vi alphabet(26,0);

  rep(i,s.size()){
    if(alphabet[s[i]-'a']){
      cout << "no" << endl;
      return 0;
    }
    alphabet[s[i]-'a'] += 1;
  }

  cout << "yes" << endl;
  return 0;
} 

Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<ctime>
#include<cstdlib>
#include<numeric>
#include<typeinfo>
#include<cstdio>
#include<cctype>
using namespace std;
typedef long long ll;
#define loop(i,a,b) for(i=a;i<b;i++)
#define rloop(i,a,b) for(i=a;i>=b;i--)
const int inf=1e8;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009

int main(void){
	vector<int> a;
	char temp[100];
	while(scanf("%s",temp)!=EOF){
		if(isdigit(temp[0])){
			int c=atoi(temp);
			a.push_back(c);
		}else{
			int b1,b2;
			b2=a.back();
			a.pop_back();
			b1=a.back();
			a.pop_back();
			if(temp[0]=='+'){
				a.push_back(b1+b2);
			}else if(temp[0]=='-'){
				a.push_back(b1-b2);
			}else{
				a.push_back(b1*b2);
			}
		}
	}
	cout<<a.back()<<endl;
}

Measured memory_bytes: 3176
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Compression;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var W = ReadInt();
            WriteLine(W * 32);
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}



Measured memory_bytes: 17952
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_2_C&lang=jp
# Priority Queue

from collections import deque
import sys
input = sys.stdin.readline
import heapq

def loop_proc():
    (n1,n2) = map(int,input().split())
    wl =[]
    for i in range(n1):
        wl.append(list())
    for i in range(n2):
        l = list(map(int,input().split()))  
        if (l[0] == 0 ):
            n = l[1]
            d = l[2]
            heapq.heappush(wl[n],-1 * d)
        elif (l[0] == 1 ):
            if ( len(wl[l[1]]) != 0 ):
                tl = wl[l[1]]
                a = heapq.heappop(tl) 
                heapq.heappush(tl,a) 
                print (int(a) * -1 )
        elif (l[0] == 2 ):
            if ( len(wl[l[1]]) != 0 ):
                tl = wl[l[1]]
                heapq.heappop(tl)  


if __name__ == '__main__':
    loop_proc()
#   import cProfile
#   pr = cProfile.Profile()
#   pr.runcall(loop_proc)
#   pr.print_stats()


Measured memory_bytes: 13748
#include <iostream>
#include <vector>
using namespace std;
#define MAX 1000000007

int counter = 0;

void merge(vector<int> &array, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> array1;
    vector<int> array2;
    for (int i = 0; i < n1; i++)
    {
        array1.push_back(array[left + i]);
    }
    array1.push_back(MAX);
    for (int i = 0; i < n2; i++)
    {
        array2.push_back(array[mid + i]);
    }
    array2.push_back(MAX);

    int c1 = 0, c2 = 0;
    for (int i = 0; i < n1 + n2; i++)
    {
        if (array1[c1] < array2[c2])
        {
            array[left + i] = array1[c1];
            c1++;
        }
        else
        {
            array[left + i] = array2[c2];
            c2++;
        }
        counter++;
    }
}

void mergeSort(vector<int> &array, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(array, left, mid);
        mergeSort(array, mid, right);
        merge(array, left, mid, right);
    }
}

int main()
{
    int num;
    cin >> num;
    vector<int> array;
    for (int i = 0; i < num; i++)
    {
        int v;
        cin >> v;
        array.push_back(v);
    }

    mergeSort(array, 0, num);

    for (vector<int>::iterator itr = array.begin(); itr != array.end(); ++itr)
    {
        if (itr != array.begin())
            cout << " ";
        cout << *itr;
    }
    cout << endl;
    cout << counter << endl;
}



Measured memory_bytes: 7788
S=input()
dp=[0]*len(S)
a=0
for i in range(len(S)):
  if S[i]=='R':
    a+=1
  else:
    dp[i]+=a//2
    dp[i-1]+=a-a//2
    a=0
for i in range(len(S)-1,-1,-1):
  if S[i]=='L':
    a+=1
  else:
    dp[i]+=a//2
    dp[i+1]+=a-a//2
    a=0
print(*dp)

Measured memory_bytes: 10768