akhauriyash/Code-Regression huggingface dataset:
import Foundation
func toTuple<T>(_ args: [T]) -> (T, T) { (args[0], args[1]) }
func toTuple<T>(_ args: [T]) -> (T, T, T) { (args[0], args[1], args[2]) }
func toTuple<T>(_ args: [T]) -> (T, T, T, T) { (args[0], args[1], args[2], args[3]) }
func readInts() -> [Int] { readLine()!.split(separator: " ").map { Int($0)! } }
func readDoubles() -> [Double] { readLine()!.split(separator: " ").map { Double($0)! } }
func readStrings() -> [String] { readLine()!.split(separator: " ").map { String($0) } }

let (n, t) = toTuple(readInts())
var ans = 1001
for _ in 0..<n {
  let (ci, ti) = toTuple(readInts())
  guard ti <= t else { continue }
  ans = min(ans, ci)
}
print(ans == 1001 ? "TLE" : ans)

Measured memory_bytes: 13632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF=1e18,MOD=1e9+7;
const int iINF=1e9;
int main(){
    ll n,k,q;
    cin>>n>>k>>q;
    vector<ll>a(q);
    for(int i=0;i<q;i++)cin>>a[i];
    vector<int>participant(n,0);
    for(int i=0;i<q;i++){
        participant[a[i]-1]++;
    }
    for(int i=0;i<n;i++){
        if(k+participant[i]>q){
            cout<<"Yes"<<endl;
        }
        else cout<<"No"<<endl;
    }
    

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
  int k;
  string s;
  cin >> k >> s;
  int size = s.size();
  if(size<=k){
      cout << s << endl;
  }else{
      cout << s.substr(0,k) << "..." <<endl;
  }
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e9)
#define PI (acos(-1))
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl



int main() {
    int N;  cin >> N;
    vector<int> V(N);
    vector<int> C(N);
    rep(i, N) cin >> V[i];
    rep(i, N) cin >> C[i];

    int ans = 0;
    rep(i, N) {
        int m = V[i] - C[i];
        if (m > 0) {
            ans += m;
        }
    }

    print(ans);
}

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

int main(void)
{
  int a[10],b[10],c[10];
  int n,i,j,k,que1,que2,flag;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    que1=que2=-1;
    flag=0;
    for(j=0;j<10;j++)
      scanf("%d",&a[j]);
    for(j=0;j<10;j++){
      if(j==0 ||b[que1]<a[j])
	b[++que1]=a[j];
      else{
	if(que2==-1 || c[que2]<a[j]){
	  c[++que2]=a[j];
	}else
	  flag=2;
      }
    }
    if(flag==2)
      printf("NO\n");
    else 
      printf("YES\n");
 
  }
  
  return 0;
}

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

int main(void) {
  int n;
  cin >> n;
  vector<pair<int, int>> ab(n);
  int a[n], b[n];
  rep (i, n) {
    cin >> a[i] >> b[i];
    ab[i] = make_pair(b[i], -a[i]);
  }

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

  bool ok = true;
  ll now = 0;
  rep (i, n) {
    ll x, y;
    tie(x, y) = ab[i]; y *= -1;

    now += y;
    if (now > x) ok = false;
  }

  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 1;

int32_t GCD(int32_t a, int32_t b) {
  if (b == 0) return a;
  else return GCD(b, a%b);
}

int main(){
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int N;
  cin >> N;
  unordered_set<int> prime_us;
  bool non_pairwise = false;
  auto prime_fact = [&](int x) {
    if (non_pairwise == true) return;
    for (int b = 2; b * b <= x; ++b) {
      if (x % b != 0) continue;
      while (x % b == 0) {
        x /= b;
      }
      if (prime_us.count(b) != 0) {
        non_pairwise = true;
        //cout << x << "," << b << endl;
        return;
      }
      prime_us.emplace(b);
      //cout << x << "," << b << " emplaced" << endl;
    }
    if (x != 1) {
      if (prime_us.count(x) != 0) {
        non_pairwise = true;
        return;
      }
      prime_us.emplace(x);
    }

  };

  int32_t gcd;
  cin >> gcd;
  prime_fact(gcd);

  for (int i = 1; i < N; i++) {
    int32_t a;
    cin >> a;
    gcd = GCD(gcd, a);
    prime_fact(a);
  }

  if (non_pairwise == false) {
    cout << "pairwise coprime" << endl;
  } else if (gcd == 1) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }

  return 0;
}


Measured memory_bytes: 6488
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def LS(): return list(map(list, input().split()))
def S(): return list(input().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#solve
def solve():
    n, t = LI()
    ab = LIR(n)
    ab.sort(key=lambda x: x[0])
    dp = [0] * (t+1)
    for i in range(n):
        a, b = ab[i]
        for ti in range(t - 1, -1, -1):
            dp[min(ti + a, t)] = max(dp[min(ti + a, t)], dp[ti] + b)
    print(dp[t])
    return


#main
if __name__ == '__main__':
    solve()


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


int main()
{
	int a[3][3],i,j,n,k,x;
	int b[3][3];
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			b[i][j]=0;
		}
	}
	for(i=0;i<3;i++)
	{
		for(j=0;j<3;j++)
		{
			cin>>a[i][j];
		}
	}
	cin>>n;
	for(k=0;k<n;k++)
	{
		cin>>x;
		for(i=0;i<3;i++)
		{
			for(j=0;j<3;j++)
			{
				if (a[i][j]==x)
				{
					b[i][j]=1;
				}
			}
		}
	}
	
	if ((b[0][0]==1&&b[1][1]==1&&b[2][2]==1)||(b[0][0]==1&&b[0][1]==1&&b[0][2]==1)||(b[1][0]==1&&b[1][1]==1&&b[1][2]==1)||(b[2][0]==1&&b[2][1]==1&&b[2][2]==1)||
(b[0][0]==1&&b[1][0]==1&&b[2][0]==1)||(b[0][1]==1&&b[1][1]==1&&b[2][1]==1)||(b[0][2]==1&&b[1][2]==1&&b[2][2]==1)||(b[0][2]==1&&b[1][1]==1&&b[2][0]==1))
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;
	
	
}
	
 


Measured memory_bytes: 256
K, N = map(int, input().split())
A = list(map(int,input().split()))
B = []

for i in range(N):
    if i == 0:
        B.append(A[N-1] - A[0])
        B.append(A[0] + (K - A[1]))
    elif i == (N - 1):
        B.append(A[N-1] - A[0])
        B.append((K - A[N-1]) + A[N-2])
    else:
        B.append((K - A[i]) + A[i-1])
        B.append(A[i] + (K - A[i+1]))

print(min(B))

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

using vi = vector<int>;
using vll = vector<long long>;

constexpr long long mod = 1000000007;

#define rep(i, n) for (int i = 0; i < n; i++)

long long f(long long n, long long x, vll a, vll p) {
    if (n == 0) {
        return x <= 0 ? 0 : 1;
    } else if (x <= 1 + a[n - 1]) {
        return f(n - 1, x - 1, a, p);
    } else {
        return p[n - 1] + 1 + f(n - 1, x - 2 - a[n - 1], a, p);
    }
}

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

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

    vector<long long> a(n + 1, 0), p(n + 1, 0);
    a[0] = 1;
    p[0] = 1;

    for (int i = 1; i <= n; i++) {
        a[i] = 2 * a[i - 1] + 3;
        p[i] = 2 * p[i - 1] + 1;
    }

    cout << f(n, x, a, p) << endl;
}

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

int main()
{
  int n, k;
  string s;
  cin >> n >> k >> s;

  int l(0), r(0);
  while (r < n && s[r] == '1') r++;
  while (k > 0 && r < n) {
    while (r < n && s[r] == '0') r++;
    while (r < n && s[r] == '1') r++;
    k--;
  }

  int ans = r - l;
  while (r < n) {
    while (r < n && s[r] == '0') r++;
    while (r < n && s[r] == '1') r++;
    while (l < n && s[l] == '1') l++;
    while (l < n && s[l] == '0') l++;
    ans = max(ans, r - l);
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
n,k=[int(i) for i in input().split()]
p=[int(i) for i in input().split()]

ex=[0]*1001
tmp=0
for i in range(1,1001):
  tmp+=i
  ex[i]=tmp/i

sumEx=[0]*(n+1)
for i in range(n):
  sumEx[i+1]=sumEx[i]+ex[p[i]]

maxA=0
for i in range(k,n+1):
  maxA=max(maxA,sumEx[i]-sumEx[i-k])
print(maxA)

Measured memory_bytes: 32176
require 'matrix'


n, m, _ = gets.split.map(&:to_i)

a = n.times.map do
      gets.split.map(&:to_i)
    end

b = m.times.map do
      gets.split.map(&:to_i)
    end

ma = Matrix.rows(a)
mb = Matrix.rows(b)
mc = ma * mb

mc.row_vectors.each{|row| puts row.to_a.join("\s")}


Measured memory_bytes: 7636
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    vector<ll> v(n);
    rep(i,n+1)   cin >> v[i];
    sort(all(v));
    ll pf=0;
    ll mf=0;
    rep(i,n){
        if(v[i]<0) mf++;
        if(v[i]>0) pf++;
    }
    rep(i,n) sum+=abs(v[i]);
    if(pf==0) {
        sort(rall(v));
        sum-=abs(v[0]*2);
    }
    if(mf==0) {
        sum-=abs(v[0]*2);
    }
    cout<<sum<<endl;
    if(n==2){
        if(mf=0){
            cout<<v[1]<<" "<<abs(v[0])<<endl;
        }else if(pf==0){
            cout<<v[0]<<" "<<abs(v[1])<<endl;
        }else{
            cout<<v[1]<<" "<<abs(v[0])<<endl;
        }
        return 0;
    }
    if(pf==1){
        sort(rall(v));
        rep(i,n-1){
            cout<<v[i]<<" "<<v[i+1]<<endl;
            v[i+1]=v[i]-v[i+1];
        }
        return 0;
    }
    if(mf==1){
        rep(i,n-2){
            cout<<v[i]<<" "<<v[i+1]<<endl;
            v[i+1]=v[i]-v[i+1];
        }
            cout<<v[n-1]<<" "<<v[n-2]<<endl;

        return 0;
    }


    if(mf==0){
        rep(i,n-2){
        cout<<v[i]<<" "<<v[i+1]<<endl;
        v[i+1]=v[i]-v[i+1];
        }
        cout<<v[n-1]<<" "<<v[n-2]<<endl;
    }else if(pf==0){
        //cout<<"hoi";
        rep(i,n-1){
        cout<<v[i]<<" "<<v[i+1]<<endl;
        v[i+1]=v[i]-v[i+1];
        }
    }else{
        //最大値をとっておく
        sort(rall(v));
        ll plus = v[0];
        v.erase(v.begin());
        //最大値の次に来るマイナスをとる
        sort(all(v));
        //cout<<v[0]<<endl;
        a=v[0];
        v.erase(v.begin());
                //cout<<"size: "<<v.size()<<endl;

        //降順
        sort(rall(v));
        cout<<a<<" "<<v[0]<<endl;
        v[0]=a-v[0];
        //rep(i,v.size()) cout<<v[i]<<" ";
        ll st;
        n=v.size();
        rep(i,n-1){
            cout<<v[i]<<" "<<v[i+1]<<endl;
            v[i+1]=v[i]-v[i+1];
            st=i+1;
            if(v[i+2]<0) break;
        }
        cout<<plus<<" "<<v[st]<<endl;
        v[st]=plus-v[st];
        n=v.size();
        REP(i,st,n-1){
            //cout<<"i; "<<i<<endl;
            cout<<v[i]<<" "<<v[i+1]<<endl;
            v[i+1]=v[i]-v[i+1];
        }
        //cout<<plus<<" "<<v[v.size()-1]<<endl;
    }
    return 0;
}


Measured memory_bytes: 3976
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

void Merge(int *,int,int,int);
void MergeSort(int *,int,int);

int count=0;

int main(){
  int n,*A,i,left=0,right;

  scanf("%d",&n);
  A=(int *)malloc(sizeof(int)*n);
  for(i=0;i<n;i++) scanf("%d",&A[i]);

  right=n;
  MergeSort(A,left,right);

  for(i=0;i<n;i++){
    printf("%d",A[i]);
    if(i!=n-1)printf(" ");
  }printf("\n%d\n",count);


  free(A);
  return 0;
}
void Merge(int *A,int left,int mid,int right){

  int n1,n2,i,j,k,*L,*R;

  n1=mid-left;
  n2=right-mid;
  L=(int *)malloc(sizeof(int)*(n1+1));
  R=(int *)malloc(sizeof(int)*(n2+1));
  for(i=0;i<n1;i++) L[i]=A[left +i];
  for(i=0;i<n2;i++) R[i]=A[mid+i];
  L[n1]=INFINITY;
  R[n2]=INFINITY;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i++];
    }else{
      A[k]=R[j++];
    }
  }

  free(L);
  free(R);
}
void MergeSort(int *A,int left,int right){

  int mid;

  if(left+1<right){
    mid=(left+right)/2;
    MergeSort(A,left,mid);
    MergeSort(A,mid,right);
    Merge(A,left,mid,right);
  }

}

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

int main(){
  int n;
  int sum = 0;
  cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  string x;
  
  for(int i=0;i<n;i++){
    cin >> s.at(i) >> t.at(i);
    sum += t.at(i);
  }
  
  cin >> x;
  
  for(int i=0;i<n;i++){
    sum -= t.at(i);
    if(x == s.at(i)){
      break;
    }
  }
  
  cout << sum << endl;
  
}


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

using namespace std;
using namespace __gnu_pbds;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , k;
    cin>>n>>k;
    if(n == k){
        cout<<0<<endl;
    }else if(n > k){
        cout<<min(n % k , abs((n % k) - k));
    }else {
        cout<<min(abs(n - k) , abs(abs(n - k) - k));
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 3620
import java.util.Scanner;

//public class atcoder0221_B{
public class Main{

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int[] A = new int[9];
		String[] Ans = new String[9];
		for(int i=0;i<9;i++) {
				A[i]=scan.nextInt();
//          System.out.println(i+"A："+A[i]);

		}
		for(int i=0;i<9;i++) {
				Ans[i]="false";
		}
		int N = scan.nextInt();
		int[] K = new int[N];
		for(int i=0; i<N;i++) {
			K[i] = scan.nextInt();
//          System.out.println(i+"K："+K[i]);
		}

		String result = "No";

		for(int Kout:K) {
			int i = 0;
			for(int Aout:A) {
				if(Kout==Aout) {
					Ans[i]="true";
				}
				i++;
			}

		}

		if(Ans[0].equals("true")&&Ans[1].equals("true")&&Ans[2].equals("true")
				|| Ans[3].equals("true")&&Ans[4].equals("true")&&Ans[5].equals("true")
				|| Ans[6].equals("true")&&Ans[7].equals("true")&&Ans[8].equals("true")
				|| Ans[0].equals("true")&&Ans[3].equals("true")&&Ans[6].equals("true")
				|| Ans[1].equals("true")&&Ans[4].equals("true")&&Ans[7].equals("true")
				|| Ans[2].equals("true")&&Ans[5].equals("true")&&Ans[8].equals("true")
				|| Ans[0].equals("true")&&Ans[4].equals("true")&&Ans[8].equals("true")
				|| Ans[2].equals("true")&&Ans[4].equals("true")&&Ans[6].equals("true")) {
			result="Yes";
		}

		System.out.println(result);
//      for(String test:Ans){
//      System.out.println(test);
//      }
	}
}

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

using namespace std;

typedef long long ll;

#define faster ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define mem(x, n) memset(x, n, sizeof(x))
#define all(x) x.begin(), x.end()
#define endl "\n"

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

int main() {
	faster;

	ll n;
	cin >> n;

	vector<ll> a(n);

	for (auto &x : a) {
		cin >> x;
	}
	sort(a.begin(),a.end());
	ll ans = 0;

	for (int i = 0; i < a.size(); i++) {
		for (int j = i + 1; j< a.size(); j++) {
			for (int k = j + 1; k < a.size(); k++) {
				if (a[i] != a[j] && a[j] != a[k]) {
					if (a[i] + a[j] > a[k] && a[i] + a[k] > a[j]
						&& a[k] + a[j] > a[i] 
					 ) {
						ans++;
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

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

int N, arr[101];

int main() {
  cin >> N;
  for(int i = 0; i < N; i++) cin >> arr[i];
  
  int ans = 0x7fffffff;
  for(int i = -100; i <= 100; i++) {
    int v = 0;
    for(int j = 0; j < N; j++)
      v += (arr[j] - i) * (arr[j] - i);
    ans = min(v, ans);
  }
  cout << ans;
}

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

int main()
{
    int N, K, i, left, right, dropped;
    cin>>N>>K;
    left = 1;
    right = K;
    int* arr = new int[N+1];
    for(i=1;i<=N;i+=1)
    {
        cin>>arr[i];
    }
    while(right<N)
    {
        dropped = left;
        left = left+1;
        right = right+1;
        if(arr[dropped]<arr[right])
        {
            cout<<"Yes"<<endl;
        }
        else
        {
            cout<<"No"<<endl;
        }
    }
}


Measured memory_bytes: 4408
// package agc.agc024;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n ; i++) {
            a[i] = in.nextInt();
        }
        int[] dp = new int[n+1];
        for (int i = 0; i < n ; i++) {
            dp[a[i]] = Math.max(dp[a[i]-1]+1, 1);
        }
        int best = 0;
        for (int i = 1 ; i <= n; i++) {
            best = Math.max(best, dp[i]);
        }
        out.println(n - best);
        out.flush();
    }

    public static void debug(Object... o) {
        System.err.println(Arrays.deepToString(o));
    }

    public static class InputReader {
        private static final int BUFFER_LENGTH = 1 << 12;
        private InputStream stream;
        private byte[] buf = new byte[BUFFER_LENGTH];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        private int next() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public char nextChar() {
            return (char) skipWhileSpace();
        }

        public String nextToken() {
            int c = skipWhileSpace();
            StringBuilder res = new StringBuilder();
            do {
                res.append((char) c);
                c = next();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        public int nextInt() {
            return (int) nextLong();
        }

        public long nextLong() {
            int c = skipWhileSpace();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            return Double.valueOf(nextToken());
        }

        int skipWhileSpace() {
            int c = next();
            while (isSpaceChar(c)) {
                c = next();
            }
            return c;
        }

        boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    int K, S;
    cin >> K >> S;
    int ans = 0;
    for(int i = 0; i <= K; i++){
        for(int j = 0; j <=K; j++){
            int a = S - i - j;
            if(a <= K && 0 <= a) ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char a[20],b[20],c[20];
int main()
{
char i,j,k;
while(scanf("%s%s%s",a,b,c)!=EOF)
{
if(a[0]>='A'&&a[0]<='Z')
i=a[0];
else
i=a[0]-'a'+'A';
if(b[0]>='A'&&b[0]<='Z')
j=b[0];
else
j=b[0]-'a'+'A';
if(c[0]>='A'&&c[0]<='Z')
k=c[0];
else
k=c[0]-'a'+'A';
printf("%c%c%c\n",i,j,k);
}
return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define ff first
#define ss second
#define ll long long
#define W(x) cerr << "\033[31m"<<  #x << " = " << x << "\033[0m" << endl;

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef set<int> si;
typedef vector<vi> vii;
typedef vector<ii> vpi;
typedef vector<ll> vll;
int oo = (1e9) + 7;
ll oo2 = 1ll*oo*oo;

vi g[5];
int a1, b1, a2, b2, a3, b3;
vector<bool> visited(5, false);
vector<int> children(5, 0);

void dfs(int v) {
    visited[v] = true;

    for(int edge : g[v]) {
        if(!visited[edge]) {
            dfs(edge);
            children[v]++;
        }
    }
}

int main() {
    cin >> a1 >> b1 >> a2 >> b2 >> a3 >> b3;
    g[a1].push_back(b1);
    g[b1].push_back(a1);
    g[a2].push_back(b2);
    g[b2].push_back(a2);
    g[a3].push_back(b3);
    g[b3].push_back(a3);
    bool res = false;
    for(int i = 1; i <= 4; i++) {
        visited.assign(5, false);
        children.assign(5, 0);
        dfs(i);
        bool tmp = true;
        for(int k : children) {
            if(k >= 2) tmp = false;
        }
        res |= tmp;
    }
    res ? puts("YES") : puts("NO");


    return 0;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
ans = []
if y-x>=0:
    ans.append(y-x)
if -y-x>=0:
    ans.append(-y-x+1)
if y+x>=0:
    ans.append(y+x+1)
if -y+x>=0:
    ans.append(-y+x+2)
print(min(ans))


Measured memory_bytes: 61772
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1;; i++) {
		if (i*(i + 1) / 2 >= n) {
			break;
		}
	}
	int K = i;
	for (i = K; i >= 1; i--) {
		if (n >= i) {
			printf("%d\n", i);
			n -= i;
		}
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    a -= c;
    cout << a / (b + c);
}

Measured memory_bytes: 3608
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#define ll long long
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static int buf[20],len; len=0;
	if(x<0)x=-x,putchar('-');
	for(;x;x/=10)buf[len++]=x%10;
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]+'0');
}
inline void writeln(ll x){write(x); putchar('\n');}
inline void writesp(ll x){write(x); putchar(' ');}
struct Data{
	int x,y;
}a[maxn];
int p[maxn],mark[maxn];
int n;
bool cmp1(Data a,Data b){return a.y<b.y;}
bool cmp2(int x,int y){return a[x].x<a[y].x;}
int calc()
{
	memset(mark,0,sizeof(mark));
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(!mark[i]){
			mark[i]=1; ++cnt;
			int now=p[i];
			while(!mark[now]){
				mark[now]=1;
				now=p[now];
			}
		}
	return cnt;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i].x=read();
	for(int i=1;i<=n;i++)
		a[i].y=read();
	std::sort(a+1,a+n+1,cmp1);
	for(int i=1;i<=n;i++)
		p[i]=i;
	std::sort(p+1,p+n+1,cmp2);
	for(int i=1;i<=n;i++)
		if(a[p[i]].x>a[i].y){
			puts("No"); return 0;
		}
	if(calc()>=2){
		puts("Yes"); return 0;
	}
	for(int i=1;i<n;i++)
		if(a[p[i+1]].x<=a[i].y){
			puts("Yes"); return 0;
		}
	puts("No");
	return 0;
}

Measured memory_bytes: 2048
import java.io.InputStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    /** 区切り文字 */
    private static final String DELIMITER = ",";

    /**
     * メインメソッド
     *
     * @param args
     */
    public static void main(String[] args) {
        // ローカルテスト用。提出時は"System.in"に修正。
        InputStream input = System.in;
        // File input = new File("D:/Temp/AOJ/0011_DrawingLots.txt");

        try (Scanner scanner = new Scanner(input)) {
            int[] numbers = createFirstNumbers(Integer.parseInt(scanner
                    .nextLine()));
            int loopNum = Integer.parseInt(scanner.nextLine());

            for (int i = 0; i < loopNum; i++) {
                // 入れ替え前の順番を一時的に記憶しておく。
                int[] copy = Arrays.copyOf(numbers, numbers.length);
                // 入れ替え対象の番号を、配列のインデックスで表す。
                int[] changeNums = convert(scanner.nextLine().split(DELIMITER));

                numbers[changeNums[0]] = copy[changeNums[1]];
                numbers[changeNums[1]] = copy[changeNums[0]];
            }

            for (int number : numbers) {
                System.out.println(number);
            }
        } catch (Exception e) {
            // 対応しない。
        }
    }

    /**
     * 最初の数字の並びを格納した配列を作成する。
     *
     * @param numberOfArray 配列の要素数
     * @return 1?の数字を格納した配列
     */
    private static int[] createFirstNumbers(int numberOfArray) {
        int[] result = new int[numberOfArray];
        Arrays.fill(result, 1);
        for (int i = 1; i < result.length; i++) {
            result[i] = result[i - 1] + 1;
        }

        return result;
    }

    /**
     * 入れ替え対象のインデックスを格納したString配列を、int配列に変換する。
     *
     * @param target
     * @return
     */
    private static int[] convert(String[] target) {
        int[] result = new int[2];
        result[0] = Integer.parseInt(target[0]) - 1;
        result[1] = Integer.parseInt(target[1]) - 1;

        return result;
    }
}

Measured memory_bytes: 25852
/*
    /\ In The Name of ALLAH /\
    Author : Jawahiir Nabhan
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{
    int n,x,t; cin>>n>>x>>t;
    int cnt = n/x;
    if(n % x) cnt++;
    cout<<cnt*t<<endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>

using namespace std;

typedef pair<long long,bool> Pair;
const long long INF = 1LL<<60;
const long long MAX_LENGTH=3010;
long long DP[3011][3011];

int main(){

string s,t;

cin >> s >> t;

for(long long i = 0;i<=MAX_LENGTH;++i) for(long long j = 0; j <= MAX_LENGTH;++j) DP[i][j] = 0;

for(long long i = 1;i <= s.length();++i){

 for(long long j = 1; j <= t.length();++j){

    if(s[i-1] == t[j-1]){

        DP[i][j] = DP[i-1][j-1]+1;

    }
    else{

        DP[i][j] = max(DP[i][j-1],DP[i-1][j]);

    }

 }

}

// cout << DP[s.length()][t.length()]<< endl;

long long LCS_Length = DP[s.length()][t.length()];
long long s_count = s.length();
long long t_count = t.length();
string ans = "";

long long i = 0;

while(LCS_Length != 0){

    if(DP[s_count - 1][t_count] == DP[s_count][t_count]) --s_count; 
    else if(DP[s_count][t_count - 1] == DP[s_count][t_count]) --t_count; 
    else if(DP[s_count - 1][t_count - 1] == DP[s_count][t_count] - 1){

        ans+=s[s_count - 1];
        --s_count;
        --t_count;
        --LCS_Length;
    }

}

reverse(ans.begin(), ans.end());
cout << ans << endl;

return 0;

}   


Measured memory_bytes: 71168
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
     // 自分の番で全部偶数にできれば勝ち
    val n = readInteger()
    val isExistOdd = IntArray(n) { readInteger() }.find { it % 2 == 1 }
    val ans = if (isExistOdd == null) "second" else "first"
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 43224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			
			int a = sc.nextInt();
			String op = sc.next();
			int b = sc.nextInt();
			
			switch(op) {
			case "+":
				System.out.println(a+b);
				break;
			case "-":
				System.out.println(a-b);
				break;
			case "*":
				System.out.println(a*b);
				break;
			case "/":
				System.out.println(a/b);
				break;
			case "?":
				return;
			}
		}

	}
}




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

#ifndef DEBUG
#define DEBUG false
#endif

#define REP(t,i,a,b) for(t i = a; i < b; ++i)

typedef long long ll;

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;

int main (void) {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    int n, k;
    string s;
    cin >> n >> k;
    cin >> s;

    // 初期の幸福な人の数を計算
    int h = 0;
    REP(int, i, 0, n) {
        if (i == 0 && s[i] == 'L') continue;
        else if (i == n-1 && s[i] == 'R') continue;

        if (s[i] == 'L' && s[i-1] == s[i]) ++h;
        else if (s[i] == 'R' && s[i+1] == s[i]) ++h;
    }

    cout << std::min(n-1, h+2*k) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <queue>

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define MAX_NUM 200000
typedef long long int ll;
using namespace std;

int main(void) {
	ll n=0,k=0, ans=0;
	cin >> n >> k;
	vector<ll> enemy(MAX_NUM);

	rep(i, n) cin >> enemy[i];
	sort(enemy.begin(), enemy.end());
	rep(i, k) enemy.pop_back();
	rep(i, enemy.size()) ans += 1LL * enemy[i];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define m 1000000007
int main() {
	int n , k;
	int ans = 0;
	cin >> n >> k;
	int a[n+1];
	for(int i = 0 ; i <= n ; i++)a[i] = i;
	long long int pre[n+1], suf[n+1];
	memset(pre,0,sizeof(pre));
	memset(suf,0,sizeof(suf));
	for(int i = 0 ; i <= n; i++){
		if(i == 0)pre[i] = a[i];
		else pre[i] = pre[i-1]+a[i];
	}
	for(int i = n ; i>= 0;i--){
		if( i == n )suf[i] = a[i];
		else suf[i] = suf[i+1]+a[i];
	}
	int l = k-1;
	int r = n-k+1;
	while(l <= n && r >= 0){
		ans = (ans + (suf[r]-pre[l]+1))%m;
		l++;
		r--;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 7536
S =input()
if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S =='WED':
    print('4')
elif S =='THU':
    print('3')
elif S =='FRI':
    print('2')
elif S =='SAT':
    print('1')

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<map>
#include<queue>
using namespace std;
int a, w;
char c[55][55];
queue <pair<int, int>> q;
int f[55][55];
int g[4] = { 0,-1,0,1 };
int h[4] = { -1,0,1,0 };
int main() {
	cin >> a >> w;
	int sum = 0;
	for (int i = 0; i<a; i++) {
		for (int j = 0; j<w; j++) {
			cin >> c[i][j];
			if (c[i][j] == '.')sum++;
		}
	}
	sum -= 2;
	for (int i = 0; i<55; i++) {
		for (int j = 0; j<55; j++) {
			f[i][j] = -1;
		}
	}
	f[0][0] = 0;
	q.push({ 0,0 });
	while (!(q.empty())) {
		pair<int, int> b = q.front();
		int x = b.first, y = b.second;
		for (int i = 0; i<4; i++) {
			int nx = x + g[i];
			int ny = y + h[i];
			if (nx >= a || nx<0 || ny >= w || ny<0)continue;
			if (c[nx][ny] != '#'&&f[nx][ny] == -1) {
				f[nx][ny] = f[x][y] + 1;
				q.push({ nx,ny });
			}
		}
		q.pop();
		if (f[a - 1][w - 1] != -1)goto age;
	}
	cout << -1 << endl;
	return 0;
age:;
	cout << sum - (f[a - 1][w - 1] - 2) - 1 << endl;
	return 0;
}


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

using namespace std;
class saleData
{
public:

	int hireNo;
	long saleValue = 0;

	void addSale(long value)
	{
		if(saleValue < 1000000)
		{
			saleValue += value;
		}
	}

	bool judge()
	{
		if(saleValue >= 1000000)
		{
			return true;
		}
		return false;
	}
};
int main()
{
	while(1)
	{
		int dataCount;
		cin >> dataCount;
		vector<saleData> vobj;

		if(dataCount == 0)
		{
			break;
		}
		bool dataFlag = false;
		for(int i = 0; i < dataCount; i++)
		{
			long hireNo;
			long price;
			long No;
			cin >> hireNo >> price >> No;

			for(int j = 0; j < vobj.size(); j++)
			{
				if(vobj.size() == 0)
				{
					break;
				}
				if(vobj[j].hireNo == hireNo)
				{
					vobj[j].addSale(price * No);
					dataFlag = true;
					break;
				}
			}
			if(dataFlag == false)
			{
				saleData sObj;
				sObj.hireNo = hireNo;
				sObj.addSale(price * No);
				vobj.push_back(sObj);
			}
		}
		dataFlag = false;
		for(int i = 0; i < vobj.size() ; i++)
		{
			if(vobj[i].judge() == true)
			{
				cout << vobj[i].hireNo << endl;
				dataFlag = true;
			}
		}
		if(dataFlag == false)
		{
			cout << "NA" << endl;
		}


	}



}

Measured memory_bytes: 3024
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
typedef long long ll;
typedef long double ld;
const long long INF = 1e18;
# define len(x) ((int)(x).size())
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define foreps(i, m, n) for(int i = m;i < n;i++)
# define ALL(x) (x).begin(), (x).end()
# define rall(x) (x).rbegin(), (x).rend()
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; }

int main() {
    string O, E; cin >> O >> E;

    string ans = "";
    if (len(O) < len(E)) {
        rep(i, len(O)) {
            ans += O.at(i); ans += E.at(i);
        }
        ans += E.at(len(E) - 1);
    }
    else if (len(E) < len(O)) {
        rep(i, len(E)) {
            ans += O.at(i); ans += E.at(i);
        }
        ans += O.at(len(O) - 1);
    }
    else {
        rep(i, len(O)) {
            ans += O.at(i); ans += E.at(i);
        }
    }
    cout << ans << endl;
}

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

bool reach(int start, int goal, string S) {
    rep2(i, start, goal+1) {
        if (S[i] == '#' && S[i+1] == '#') {
            return false;
        }
    }
    return true;
}

int main() {
    int N, A , B , C , D;
    string S;
    cin >> N >> A >> B >> C >> D >> S;
    S = '#' + S + 'S';
    if (!reach(A, C, S) || !reach(B, D, S)) {
        cout << "No" << endl;
        return 0;
    }

    if (C > D) {
        bool skip = false;
        rep2(i, B, D+1) {
            if (S[i-1] == '.' && S[i] == '.' && S[i+1] == '.') {
                skip = true;
            }
        }
        if (!skip) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 844
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  ll n,m;
  cin>>n>>m;
  if(n==1 && m==1){
    cout<<1<<endl;
    return 0;
  }
  if(n>m)swap(n,m);
  //  cout<<n<<" "<<m<<endl;
  if(n==1)
    cout<<max(m-2,0LL)<<endl;
  else
    cout<<(n-2)*(m-2)<<endl;

}


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

int main(){
  char s[3];
  // 文字列の入力
  scanf("%s", &s);

  // 連続した雨の日数を数える
  int count = 0;

  for(int i=0; i<3; i++){
    if(count==0){
      if(s[i]=='R'){
        count++;
      }
    }else{
      if(s[i]=='R'){
        count++;
      }else{
        printf("%d", count);
        return 0;
      }
    }
  }

  printf("%d", count);
  return 0;
}


Measured memory_bytes: 1684
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;

int main()
{
    int N;
    cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; ++i) cin >> p[i];

    int cnt = 0;
    for(int i = 1; i <= N; ++i){
        if(i != p[i-1])
            cnt++;
    }
    if(cnt < 3)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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 P = 1000000007;
const int INF = 2147483647;
const ll LLINF = 1LL<<60;



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

string s;
cin >> s;
int ans=0;
rep(i,s.length()/2){
    if(s[i]!=s[s.length()-i-1])ans++;
}
fin(ans);

//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define range(i, l, r) for(int (i) = (l); (i) < (r); (i)++)
#define reversed_range(i, l, r) for (int (i) = (r) - 1; (i) >= l; (i)--)
using namespace std;
template <typename T>
using vec = vector<T>;
using lint = long long;
using ulint = unsigned long long;
using pint = pair<int, int>;
using plint = pair<lint, lint>;

template <typename S, typename T>
ostream& operator <<(ostream& os, pair<S, T> p) {
    os << "(";
    os << p.first << ", " << p.second;
    return os << ")";
}

template <typename T>
ostream& operator <<(ostream& os, vec<T> v) {
    os << "[";
    for (int i = 0; i < v.size() - 1; i++) {
        os << v.at(i) << ", ";
    }
    return os << v.at(v.size() - 1) << "]";
}

template <typename T>
ostream& operator <<(ostream& os, set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename T>
ostream& operator <<(ostream& os, unordered_set<T>& s) {
    os << "{";
    auto it_first_item = s.begin();
    cout << *it_first_item;
    for (auto it = ++it_first_item; it != s.end(); it++) {
        cout << ", " << *it;
    }
    return cout << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

template <typename K, typename V>
ostream& operator <<(ostream& os, unordered_map<K, V> m) {
    os << "{";
    auto it_first_item = m.begin();
    cout << it_first_item->first << ": " << it_first_item->second;
    for (auto it = ++it_first_item; it != m.end(); it++) {
        cout << ", " << it->first << ": " << it->second;
    }
    return os << "}";
}

int main() {
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    lint N;
    cin >> N;
    vector<string> names;
    range(i, 0, N) {
        string name;
        cin >> name;
        names.emplace_back(name);
    }
    const vec<char> valid_first_letters = {'M', 'A', 'R', 'C', 'H'};
    unordered_map<char, lint> count_num_names_of_starting;
    for (const auto name : names) {
        const char first_letter = name.at(0);
        if (find(valid_first_letters.begin(), valid_first_letters.end(), first_letter) != valid_first_letters.end()) {
            count_num_names_of_starting[first_letter] += 1;
        }
    }
    // cout << count_num_names_of_starting << "\n";
    lint num_combinations = 0;
    range(i, 0, 3) range(j, i + 1, 4) range(k, j + 1, 5) {
        const lint count_1 = count_num_names_of_starting[valid_first_letters.at(i)];
        const lint count_2 = count_num_names_of_starting[valid_first_letters.at(j)];
        const lint count_3 = count_num_names_of_starting[valid_first_letters.at(k)];
        num_combinations += count_1 * count_2 * count_3;
    }
    cout << num_combinations << "\n";
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}
const ll P =  1000000007;
ll factorial(ll n){
   ll ans = 1;
   for(int i = n;i>=1;i--){
     ans *= i;
     ans %= P;
   }
   return ans;
}
using Graph = vector<vector<int>>;

ll kzyou(ll a,ll k){//aのk乗を返す
    ll zyou = 1;
    for(ll i = 1;i<=k;i++){
        zyou *= a;
    }
    return zyou;
}

int main(){
  int N;
  cin >> N;
  map<pair<int,int>, int> ma;
  for(int i = 1;i<=N;i++){
    string s = to_string(i);
    int p = (int)s[0] - 48;//先頭の数字
    int q = (int)s[s.size()-1] - 48;//末尾の数字
    ma[make_pair(p,q)]++;
  }
  ll ans = 0;
  for(int i = 1;i<=N;i++){
    string s = to_string(i);
    int p = (int)s[0] - 48;//先頭の数字
    int q = (int)s[s.size()-1] - 48;//末尾の数字
    ans += ma[make_pair(q,p)];
  }
  cout << ans << endl;
 }


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    char s[200];
    char p[100];
    int len,i = 0,j,k;
    scanf("%s\n",s);
    scanf("%s\n",p);
    while(s[i] != '\0') i++;
    len = i;
    for(i = len;i<len*2;i++){
        s[i] = s[i - len];
    }
    for(i = 0;i < len*2;i++){
        if(s[i] == p[0]){
            j = 0;
            k = i;
            while(s[k] == p[j]){
                j++;
                k++;
                if(p[j] == '\0'){
                    printf("Yes\n");
                    return 0;
                }
            }
        }
    }
    printf("No\n");
    return 0;
}

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

diff_m = 0
diff_p = []
mcount = 0

if sum(B) > sum(A):
    print(-1)

else:
    for i in range(N):
        difftmp = A[i] - B[i]
        
        if difftmp < 0:
            diff_m += difftmp
            mcount += 1
        
        else:
            diff_p.append(difftmp)
    

    if diff_m == 0:
        print(0)

    else:
        diff_p.sort(reverse = True)

        for j in range(0,N):
            diff_m = diff_m + diff_p[j]
 

            if diff_m >= 0:
                print(j+1 + mcount)
                break

            else:
                continue

Measured memory_bytes: 18524
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int n, k, v[51], left[51], right[52], sum, ans=-1e9;
    vector<int> w;
    cin >> n >> k;
    v[0] = left[0] = right[n+1] = 0;
    for(int i=1;i<=n;i++){
        cin >> v[i];
        left[i] = left[i-1] + v[i];
    }
    for(int i=n;i>=1;i--){
        right[i] = right[i+1] + v[i];
    }
    for(int i=0;i<=min(k, n);i++){
        for(int j=0;i+j<=min(k, n);j++){
            w.clear();
            
            for(int l=1;l<=i;l++){
                w.push_back(v[l]);
            }
            for(int l=0;l<j;l++){
                w.push_back(v[n-l]);
            }
            sort(w.begin(), w.end());
            sum = left[i] + right[n+1-j];
            for(int l=0;l<min(k-i-j, i+j);l++){
                if(w[l]<0){
                    sum -= w[l];
                }else{
                    break;
                }
            }
            ans = max(ans, sum);
            //cout << i << ", " << j << " : " << sum << endl;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#define long long long
using namespace std;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF = 0x3f3f3f3f;


signed main()
{
  cin.tie(nullptr), ios::sync_with_stdio(false);
  int q;
  deque<int> dq;

  cin >> q;
  while(q--) {
    int com, d, x;
    cin >> com;

    if (com == 0) {
      cin >> d >> x;
      d == 0 ? dq.push_front(x) : dq.push_back(x);
    } else if (com == 1) {
      cin >> x;
      cout << dq[x] << '\n';
    } else {
      cin >> d;
      d == 0 ? dq.pop_front() : dq.pop_back();
    }
  }

  return 0;
}




Measured memory_bytes: 4644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    rep(i,n) {
        cin >> a[i];
    }
    rep(i,n) {
        cin >> b[i];
    }
    int ans = 0;
    rep(i,n) {
        int sum = 0;
        int j = 0;
        for (; ;) {
            sum += a[j];
            if (j < i) j++;
            else break;
        }
        for (; j < n; j++) {
            sum += b[j];
        }
        ans = max(sum, ans);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  ll n;
  cin>>n;
  vector<ll> h;
  for(ll i=0; i<n; i++){
    ll x;
    cin>>x;
    h.push_back(x);
  }
  for(int i=n-1; i>0; i--){
    if(h[i]>=h[i-1]){}
    else if(h[i]+1==h[i-1]) h[i-1]--;
    else {
      cout<<"No";
      return 0;
    }
  }
  cout << "Yes";
}


Measured memory_bytes: 1400