akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T>
class BIT {
    int n;
    vector<T> val;
public:
    BIT(int n):n(n),val(n+1,0) {}
    void add(int i,T x=1) {
        i++;
        while(i <= n) {
            val[i] += x;
            i += i&-i;
        }
    }
    T sum(int i) {
        T ret = 0;
        i++;
        while(i > 0) {
            ret += val[i];
            i -= i&-i;
        }
        return ret;
    }
    // [l,r)
    T sum(int l,int r) { return sum(r-1)-sum(l-1); }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    int ng = 0,ok = inf;
    auto f = [&](int m) {
        vi sum(n+1,0);
        rep(i,n) sum[i+1] = sum[i]+(a[i] <= m ? 1 : -1);
        rep(i,n+1) sum[i] += 100000;
        ll cnt = 0;
        BIT<int> bt(200010);
        rep(r,n+1) {
            if(sum[r] > 0) cnt += bt.sum(sum[r]-1);
            bt.add(sum[r]);
        }
        return cnt > (ll)n*(n+1)/4;
    };
    while(abs(ok-ng) > 1) {
        int mid = (ng+ok)/2;
        if(f(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}


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

int main() {
    int h, w;
    cin >> h >> w;
    char a[h][w];
    rep(i, h) {
        rep(j, w) cin >> a[i][j];
    }

    int t[h] = {};
    int y[w] = {};

    rep(i, h) {
        rep(j, w) {
            if(a[i][j] == '#') break;
            if(j == w-1) t[i]++;
        }
    }

    rep(j, w) {
        rep(i, h) {
            if(a[i][j] == '#') break;
            if(i == h-1) y[j]++;
        }
    }

    int cntt = 0;
    int cnty = 0;
    rep(i, h) {
        if(t[i]>0) cntt++;
    }
    rep(i, w) {
        if(y[i]>0) cnty++;
    }

    //cout << cntt << " " << cnty << endl;

    char ans[h-cntt][w-cnty];
    int cntx = 0;
    rep(i, h) {
        int cntyy = 0;
        rep(j, w) {
            if(t[i]==0 && y[j]==0) {
                char tmp = a[i][j];
              	cout << tmp;
                //ans[cntx][cntyy] = tmp;
                //cntyy++;
            }
            if(j==w-1 && t[i] == 0) cout << endl;
        }
        cntx++;
    }

    /*cout << cntx << endl;
    rep(i, h) cout << t[i] << " ";
    cout << endl;
    rep(i, w) cout << y[i] << " ";
    cout << endl;
    

    rep(i, h-cntt) {
        rep(j, w-cnty) {
            cout << ans[i][j];
            if(j==w-cnty-1) cout << endl;
        }
    }
    */

    return 0;
}

Measured memory_bytes: 384
s=input()
t=input()
a=[s[i] for i in range(len(s))]
b=[t[i] for i in range(len(t))]
a.sort()
b.sort(reverse=True)
s=""
t=""
for i in a:
    s+=i
for i in b:
    t+=i
if s<t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(void)
{
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    
    printf("%lf %d",w*h/2,x*2 == w && y*2 == h);
    

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

// go run ./main.go < in

func main() {
	var a, b, c, d, e int
	fmt.Scan(&a, &b, &c, &d, &e)

	if a == 0 {
		fmt.Println("1")
	}
	if b == 0 {
		fmt.Println("2")
	}
	if c == 0 {
		fmt.Println("3")
	}
	if d == 0 {
		fmt.Println("4")
	}
	if e == 0 {
		fmt.Println("5")
	}
}


Measured memory_bytes: 1812
from itertools import product


def main():
    N = int(input())
    F = [list(map(int, input().split(' '))) for _ in range(N)]
    P = [list(map(int, input().split(' '))) for _ in range(N)]
    ans = - 10**10
    for pattern in product([0, 1], repeat=10):
        if sum(pattern) == 0:
            continue
        profit = 0
        for n in range(N):
            c = sum([1 if p == f == 1 else 0 for p, f in zip(pattern, F[n])])
            profit += P[n][c]
        ans = max([ans, profit])
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);
		int d_syurui = sc.nextInt();
		int komugi = sc.nextInt();
		int d_all=0;

		int[] donatu=new int[d_syurui];
		for(int i=0; i<d_syurui; i++){
			String source=sc.next();
				source=source.trim();
				donatu[i] = Integer.parseInt(source);
				d_all+=donatu[i];
		}

		int min=999999999;
		for(int i=0; i<d_syurui; i++){
			if(min>donatu[i]){
				min=donatu[i];
			}
			else{}
		}
		komugi=komugi-d_all;

		int d_kosu=d_syurui+komugi/min;

		System.out.println(d_kosu);

	}
}

Measured memory_bytes: 21716
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();
    	int C = sc.nextInt();
    	int ans = C - (A - B);
    	System.out.println(0 <= ans ? ans : 0);
    }
}

Measured memory_bytes: 21972
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (true) {
			int h = Integer.parseInt(in.next());
			int w = Integer.parseInt(in.next());
			if (h == 0 && w == 0) {
				break;
			}
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println("");
		}
	}
}	


Measured memory_bytes: 32904
N = int(input())
A = [int(i) for i in input().split()]
B = [int(i) for i in input().split()]
ans = 0
for i in range(0, N):
    a = min(A[i], B[i])
    ans += a
    # 使ったヒーローの力を減算
    B[i] -= a

    b = min(A[i + 1], B[i])
    ans += b
    # 倒した分だけ残りのモンスターを減算
    A[i + 1] -= b
print(ans)


Measured memory_bytes: 19156
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;

void solve(){
    int n, k;
    cin>>n>>k;
    int a[n+5];
    f(i,n)cin>>a[i];
    sort(a,a+n);
    int ans = 0;
    f(i,k)ans += a[i];
    cout<<ans;
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3620
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int[] ans = new int[N];
		for (int i=0;i<N;i++) {
			int tmp = Integer.parseInt(sc.next());
			ans[tmp-1] = i+1;
		}
		for (int i=0;i<N;i++) {
			System.out.print(ans[i] + " ");
		}
	}
}

Measured memory_bytes: 49032
#include <stdio.h>
#include <algorithm>
#include <memory.h>
#include <iostream>
#include <vector>
#include <map>
#include <deque>
  
// Shabdan Batyrkulov
  
using namespace std;
  
#define pb push_back
#define fr first
#define sc second
#define mk make_pair
#define ll long long
#define ld long double
#define vi vector <int>
#define pii pair <int, int>
#define OK puts("OK");
#define sz(s) ((int)s.size())                                                                           
                                                                                                
const int N = (int)1e5 + 7;                                                                 
const int inf = (int)1e9 + 7;
const int MAX = (int)1e3+ 7;

ll get_ans(int h, int w) {
	ll ans = inf;
	for (int i = 0; i < h; i++) {
		ll cur = i * (ll)w;
		int x = h - i;
		int y = w;
		ll s1 = (x / 2) * (ll)w;
		ll s2 = (x / 2 + x % 2) * (ll) w;
		ans = min(ans, max(max(s1, s2), cur) - min(min(s1, s2), cur));
		s1 = x * (ll) (w / 2);
		s2 = x * (ll) (w / 2 + w % 2);
		ans = min(ans, max(max(s1, s2), cur) - min(min(s1, s2), cur));
	}	
	return ans;
}

int main () {  
	ll a, b; cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0) {
		puts("0");				
	} else {        
		cout << min(get_ans(a, b), get_ans(b, a));			
	}								
} 


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

int main()
{
    int l1, l2;
    char str[3][1000];
    scanf("%s %s %s", str[0], str[1], str[2]);
    l1 = strlen(str[0]);
    l2 = strlen(str[1]);
    if(str[0][l1-1]==str[1][0]&&str[1][l2-1]==str[2][0])
    {
        printf("YES");
        return 0;
    }
    printf("NO");
    return 0;
}


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

int h[110];

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

  int n; cin >> n;
  //int top = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
    //top = max(top,h[i]);
  }

  int ans = 0;
  while(1){
    int top2 = 114,k = 0;
    for(int i = 0; i < n; i++){
      if(h[i] != 0){
        if(top2 > h[i]){
          top2 = h[i];
          k = i;
        }
      }
    }
    if(top2 == 114) break;

    for(int i = k; i >= 0; i--){
      if(h[i] == 0) break;
      h[i]--;
    }
    for(int i = k+1; i < n; i++){
      if(h[i] == 0) break;
      h[i]--;
    }
    ans++;

  }
  cout << ans << endl;

  return 0;
}


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

int main(void) {
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> v(N);
  v[0] = 0;
  for (int i = 1; i < N; i++) {
    v[i] = v[i - 1] + (S[i] == 'C' && S[i - 1] == 'A' ? 1 : 0);
  }
  for (int i = 0; i < Q; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    cout << v[r] - v[l] << endl;
  }
  return 0;
}

Measured memory_bytes: 1408
from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations # (string,3) 3回
from collections import deque
from collections import defaultdict
import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
n = I()
S = input()
dic = defaultdict(int)
for i in range(len(S)):
    dic[S[i]] += 1
#print(dic)
res = 1
for k,v in dic.items():
    res *= (v+1)
    res %= mod
print(res % mod -1)


Measured memory_bytes: 5904
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  for(int i=1;i<n;i++){
    if(a[i-1]>a[i]){
     a[i]++;
     if(a[i-1]>a[i]){
        cout<<"No"<<endl;
        return 0;
     }
   }
 }
 cout<<"Yes"<<endl;
return 0;
}

Measured memory_bytes: 4004
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <set>
#include <algorithm>

using namespace std;

set<string> c;

string s;

int K, n;

int main()
{
	ios::sync_with_stdio(false);
	cin >> s >> K;
	n = s.size();
	for (int i = 0; i < n; i++)
	{
		string cur = "";		
		for (int j = 0; j < K && i + j < n; j++)
			cur += s[i + j], c.insert(cur);
	}
	set<string>::iterator it = c.begin();
	while (--K)
		it++;
	cout << *it << endl;
	return 0;	
}


Measured memory_bytes: 1664
import Data.List

readPS :: [(Int,Int)]->IO [(Int,Int)]
readPS lst = do
    line <- getLine
    let (p,s) = read ("("++line++")")::(Int,Int)
    if (p,s)==(0,0) then return lst else return =<< readPS ((p,s):lst)

readQ :: IO [Int]
readQ = do
    str <- getContents
    return $ map (\x->read x::Int) $ lines $ str

score :: [(Int,Int)]->Int->Int
score ps p = snd $ head $ filter (\x->(fst x)==p) ps

index :: [(Int,Int)]->Int->Int
index ps s = (length $ takeWhile (/=s) s') + 1
    where s' = reverse $ sort $ nub $ map snd ps 

main :: IO ()
main = do
    ps <- readPS []
    q <- readQ
    mapM_ print $ map (index ps . score ps) q

Measured memory_bytes: 4040
#include "bits/stdc++.h"
using namespace std;

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/09/20  Problem: ACPC2017_day3_a  / Link:   ----- */
/* ------??????------



-----?????????????????§----- */
/* -----?§£??¬???-----



----?§£??¬???????????§---- */

LL N;

LL ans = 0LL;

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

	string s;
	cin >> s;
	int now = 0;
	FOR(i, 0, SZ(s)) {
		int p = s[i] - 'A';
		if (now >= p)ans++;
		now = p;
	}
	
	cout << ans << "\n";

	return 0;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(long long N, std::vector<long long> a){
    vector<long long> b(3, 0);
    for(ll i = 0; i < N; ++i){
        if(a[i]%2) b[0]++;
        else if(a[i]%4) b[1]++;
        else b[2]++;
    }
    if(b[1]){
        if(b[2] < b[0]) cout << NO << endl;
        else cout << YES << endl;
    }else{
        if(b[2]+1 < b[0]) cout << NO << endl;
        else cout << YES << endl;
    }
    return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };




void solve() {
    string s; ll k; cin >> s >> k;
    ll n = s.size();
	unordered_map<char, int> m;
	rep(i, n){
		m[s[i]]++;
	}
	if(m.size() == 1){
		cout << n*k/2 << endl;
		return;
	}
	vec memo(n);
	ll cnt1 = 0;
	rep(i, n-1){
		if(memo[i] == 0 && s[i] == s[i+1]){
			memo[i+1] = 1;
			cnt1++;
		}
	}
	if(k == 1){
		cout << cnt1 << endl;
		return;
	}
	string t = s+s;
	vec tmemo(t.size());
	ll cnt2 = 0;
	rep(i, t.size()-1){
		if(tmemo[i] == 0 && t[i] == t[i+1]){
			tmemo[i+1] = 1;
			cnt2++;
		}
	}
	cout << (cnt2-cnt1)*(k-1) + cnt1 << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


Measured memory_bytes: 4352
from collections import deque

n = int(input())
graph = {}
for i in range(1, n):
    a, b = map(int,input().split())
    try:
        if graph[a] is not None:
            graph[a].append(b)
    except:
        graph[a] = [b]
    try:
        if graph[b] is not None:
            graph[b].append(a)
    except:
        graph[b] = [a]
c = list(map(int, input().split()))
c.sort()
M = sum(c) - c[-1]
q = deque([1])
a = [0 for i in range(n)]
visited = []
while q:
    for x in list(q):
        visited.append(x)
        for y in graph[x]:
            if not y in visited:
                q.append(y)
        a[x-1] = str(c.pop())
        q.popleft()
print(M)
print(' '.join(a))

Measured memory_bytes: 8476
#include <cstdio>
#include <iostream>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <queue>
#include <math.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

template<class T>
bool umax(T &a, const T &b){
    if (a<b) {
        a=b; return true;
    }
    return false;
}

template<class T>
bool umin(T &a, const T &b) {
    if (b<a) {
        a=b; return true;
    }
    return false;
}

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


int dx[5]={1,0,-1,0};
int dy[5]={0,1,0,-1};

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};
vector<int>G[10010];
vector<int>c(10010,0);
int num[10010];
bool used[10010];
int now_c=0;
int dfs(int s){
    if(used[s]){
        return 0;
    }else{
        used[s]=true;
    }

    num[s]=c[now_c];
    now_c++;

    for(int i=0; i<G[s].size(); i++){
        dfs(G[s][i]);
    }
    return 0;
}


int main() {
    int N; cin >> N;
    vector<pair<lli,lli>>p(N);
    rep(i,N){
        cin >> p[i].second >> p[i].first;
    }
    sort(p.begin(), p.end());
    lli time=0ll;


    for(auto a: p){
        time+=a.second;
        if(a.first < time){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

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

using namespace std;

int dp[(int)1e5+5];
int main()
{

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



    fill(dp, dp+(int)1e5+5 , INT_MAX );

    dp[1] = 0;
    int n;
    cin>>n;
    vector <int> v(n+3,0);
    for( int i = 1; i <= n ; i++ ) {

        cin>>v[i];

    }
    for( int i = 1; i <= n ; i++ ) {

        dp[i+1] = min( dp[i]+abs(v[i+1]-v[i]) , dp[i+1] );
        dp[i+2] = min( dp[i]+abs(v[i+2]-v[i]) , dp[i+2] );

    }
    cout<<dp[n]<<"\n";
}


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

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

    int len = s.length() - 1;
    string head;
    string tail;

    while (len > 0) {
        if (len % 2 == 0) {
            head = s.substr(0, len/2);
            tail = s.substr(len/2, len/2);
            if (head == tail) {
                cout << head.length() + tail.length() << endl;
                return 0;
            } else {
                len--;
            }
        } else {
            len--;
        }
    }

    return 0;
}

Measured memory_bytes: 256
require 'set'
gets
a = gets.split.map(&:to_i)

s1 = Set.new
s1 << [a[0], false]
s1 << [a[1], false]

a.each do |i|
  s2 = Set.new
  s1.each do |j|
    if j[1]
      s2 << [j[0].gcd(i), true]
    else
	    s2 << [j[0], true]
    	s2 << [j[0].gcd(i), false]
    end
  end
  s1 = s2
end

p s1.select{|e|e[1]}.max_by{|e|e[0]}[0]



Measured memory_bytes: 15004
#include<stdio.h>

signed main()
{
  int a,b;
  scanf("%d %d",&a,&b);

  if( a >= 13 ) printf("%d\n",b);
  if( a >= 6 && a <= 12 ) printf("%d\n",b / 2);
  if( a <= 5 ) printf("0\n");

  return 0;
}

Measured memory_bytes: 128
h, w = map(int, input().split())
S = [list(input()) for i in range(h)]
U = [-1, 0]
L = [0, -1]
D = [1, 0]
R = [0, 1]
UL = [-1, -1]
UR = [-1, 1]
DL = [1, -1]
DR = [1, 1]
direction = [U,D,L,R,UL,UR,DL,DR]
for i in range(h):
    for j in range(w):
        count = 0
        if S[i][j] == ".":
            for d in direction:
                x, y = d
                if h > i+x >= 0 and w > j+y >= 0:
                    if S[i+x][j+y] == "#":
                        count += 1
            S[i][j] = count
for i in range(h):
    print(*S[i], sep='')

Measured memory_bytes: 3572
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,x,n) for(int i=(x);i<(n);i++)
#define EREP(i,n) for(int i=1;i<(n);i++)
using namespace std;
int main(){
	long int n,a[100000],b[100000],ans=0;
	cin>>n;
	REP(i,n){
		cin>>a[i]>>b[i];
	}
	for(int i=0;i<n;i++){
		ans+=(b[i]-a[i])+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let x: usize = scan(tokens);
    let a: usize = scan(tokens);
    if x < a {
        println!("0");
    } else {
        println!("10");
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){

	ios::sync_with_stdio(false);
	cin.tie(nullptr);

	int A, B; cin >> A >> B;

	int ans = 0;
	int count = 1;
	while (count < B){
		count += (A-1);
		ans++;
	}
	cout << ans << endl;
}

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

int main()
{
  long long a,b,v,w,t;
  string ans;
  
  cin >> a >> v >> b >> w >> t;
  ans="NO";
  if (v > w)
  {
    if (t >= ((double)abs(a-b)/(v-w)))
        ans="YES";
  }
  
  cout << ans << endl;
	
}


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

int N;
int a[200010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  int pos[200010];
  for (int i = 0; i < N; i++) {
    pos[a[i]] = i;
  }
  set<int> st;
  st.emplace(-1);
  st.emplace(N);
  ll ans = 0;
  for (int i = 1; i <= N; i++) {
    int L = pos[i] - *(--st.lower_bound(pos[i]));
    int R = *(st.upper_bound(pos[i])) - pos[i];
    ans += (ll)L * R * i;
    st.emplace(pos[i]);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
using P = pair <int,int>; //to, cost
using WeightedGraph = vector<vector <P>>; //to cost
const long long INF = 1LL << 60;
const int MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int f=0, d = 0;
    int n; cin>>n;
    vector <int> a(n);
    rep(i,n) cin>>a[i]; 
    rep(i,n){
        if(a[i] % 4 == 0) f++;
        else if(a[i] % 2 == 0) d++;
    } 
    int nd = n - f - d;
    nd -= f;
    if(d == 0) nd--;
    if(nd >0) cout<<"No"<<endl; else cout<<"Yes"<<endl;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

int main() {
	
	char com[20];
	
	priority_queue<int> PQ;
	
	while(1){
		scanf("%s",com);
		if(com[0]=='i'){
			int key;scanf("%d",&key);
			PQ.push(key);
		}else if(com[1]=='x'){
			printf("%d\n",PQ.top());
			PQ.pop();
		}else if(com[0]=='e'){
			break;
		}
	}
	
	return 0;
}

Measured memory_bytes: 6524
import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
from collections import Counter
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
def gcd(a,b):
    if b==0: return a
    else:
        return gcd(b,a%b)
def lcm(a,b):
    return a*b//gcd(a,b)

n=int(input())
A=list(map(int,input().split()))
ans=A[0]
for i in range(n-1):
    ans=lcm(ans,A[i+1])

ans-=1
q=0
for i in range(n):
    q+= ans%A[i]
print(q)

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
long long int n,m,p,q,arr[200009],i,j,k,l;
int main()
{
    scanf("%lld",&n);
   if(n%2==1)
    printf("0");
   else{
    l=0;
    m=0;
    p=n;
    q=n;
    j=0;
    while(p){
        i=p/2;
        l+=i;
        p=i;
    }
    while(q){
        i=q/5;
        m+=i/2;
        q=i;
    }
    l=min(l,m);
    printf("%lld\n",l);
   }
}


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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define yes "Yes"
#define yse "Yes"
#define no "No"

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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 MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(v.begin(), v.end());
// int sum = accumulate(v, v + v.size(), 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

int main()
{
    ll x;
    cin >> x;

    ll ans = 0;

    ans += (x / 500) * 1000;

    int sub = x % 500;
    ans += (sub / 5) * 5;

    cout << ans << endl;
}

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

int main() {
  int a[5], max=9, c, cmax = 0, ans = 0;
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  for(int i = 0; i < 5; i++) {
    if(a[i] % 10 < max && a[i]%10 != 0){
      max = a[i]%10;
      cmax = a[i];
      c=i;
    }
    if(cmax == 0) cmax = a[i];
  }
  a[c] = 0;
  for(int i = 0; i < 5; i++) {
    if(a[i] % 10 != 0) a[i] = (a[i] / 10 * 10) + 10;
    ans += a[i];
  }
  cout << ans + cmax;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007
int main() {
	ll n,cnt=1;
	cin>>n;
	ll ans=0;
	while(n!=0){
		ans+=cnt;
		cnt*=2;
		n/=2;
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 256
import sys
import bisect

input = sys.stdin.readline


def get_primes(n):
    sieve = [1] * n
    for i in range(3, int(n ** 0.5) + 1, 2):
        if sieve[i]:
            sieve[i * i:: 2 * i] = [0] * ((n - i * i - 1) // (2 * i) + 1)
    return [2] + [i for i in range(3, n, 2) if sieve[i]]


def main():
    Q = int(input())
    lr = [[int(x) for x in input().split()] for _ in range(Q)]

    P = get_primes(10 ** 5 + 1)
    setP = set(P)
    like = []
    for p in P:
        if (p + 1) // 2 in setP:
            like.append(p)


    for l, r in lr:
        li = bisect.bisect_left(like, l)
        ri = bisect.bisect_right(like, r)
        print(ri - li)


if __name__ == '__main__':
    main()


Measured memory_bytes: 23044
/// @file
/// @copyright 2018 thousand
#include <bits/stdc++.h>
using std::accumulate;
using std::cin;
using std::cout;
using std::endl;
using std::vector;

namespace {
int N, f_N;

/// @brief Returns sum of digits.
int F(int X) {
  vector<int> digits;
  while (X) {
    digits.push_back(X % 10);
    X /= 10;
  }
  return accumulate(digits.begin(), digits.end(), 0);
}

/// @brief Returns if X is a harshad number.
bool IsHarshad(int X) {
  return X % F(X) == 0;
}
}  // namespace

int main() {
  cin >> N;
  cout << (IsHarshad(N) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>

using namespace std;

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

    sort(a, a+n);

    int m = a[n-1];
    int idx = 0;
    int d = 0;
    for (int i = 1; i < n-1; i++) {
        if (min(m-a[i], a[i]) > d) {
            d = min(m-a[i], a[i]);
            idx = i;
        }
    }
    
    cout << m << " " << a[idx];

    
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main() {
    int a, b, c;
    cin >> a >> b >> c;

    if (a == b && b == c) {
        cout << 1 << endl;
    }
    else if (a == b || b == c || c == a) {
        cout << 2 << endl;
    }
    else {
        cout << 3 << endl;
    }
}

Measured memory_bytes: 256
R,G,B,N = map(int,input().split())

rn = N // R
gn = N // G

ans = 0

for i in range(rn + 1):
  for j in range(gn + 1):
    n = N
    n -= R*i + G*j
    if n >= 0 and n % B == 0:
      ans += 1
print(ans)
  

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

int main(){

  int h,m,s,x,y,z;

  while(true){
    cin >> h >> m >> s;
    if(h == -1 && m == -1 && s == -1) break;

    s += (h*3600) + (m*60);

    s = 7200 - s;
    z = s * 3;

    h = s/3600;
    m = (s%3600)/60;
    s = (s%3600)%60;

    x = z/3600;
    y = (z%3600)/60;
    z = (z%3600)%60;

    printf("%02d:%02d:%02d\n",h,m,s);
    printf("%02d:%02d:%02d\n",x,y,z);
  }
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){

    int n,W;
    cin>>n>>W;

    vector<int>wt(n),val(n);
    for(int i=0;i<n;i++){
        cin>>wt[i]>>val[i];
    }

    int sum = 0;

    for(int i=0;i<n;i++){
        sum+=val[i];
    }

    vector<ll> dp(sum+1,1e18L+5);

    dp[0] = 0;

    for(int item = 0;item<n;item++){
        for(int valo=sum-val[item];valo>=0;valo--){
            dp[valo+val[item]]=min(dp[valo+val[item]],dp[valo]+wt[item]);
        }
    }

    ll ans = 0;

    for(int i=0;i<=sum;i++){
        if(dp[i]<=W){
            ans=max(ans,(ll)i);
        }
    }

    cout<<ans<<endl;



}


Measured memory_bytes: 1152
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>
#include <cassert>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1001001001;

// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

struct P{
    P(){}
    P(ll _r, ll _i):r(_r), i(_i){}
    void real(const ll& v){r = v;}
    void imag(const ll& v){i = v;}
    ll r, i;
};

ll real(const P& p){return p.r;}
ll imag(const P& p){return p.i;}
ll norm(const P& p){ll r = real(p), i = imag(p); return r * r + i * i;}

P operator+(const P& lhs, const P& rhs){
    return P(real(lhs)+real(rhs), imag(lhs)+imag(rhs));
}
P operator-(const P& lhs, const P& rhs){
    return P(real(lhs)-real(rhs), imag(lhs)-imag(rhs));
}
P operator-(const P& p){
    return P(-real(p), -imag(p));
}

ll cross(const P& lhs, const P& rhs){
    return real(lhs)*imag(rhs) - imag(lhs)*real(rhs);
}

ll dot(const P& lhs, const P& rhs){
    return real(lhs)*real(rhs) + imag(lhs)*imag(rhs);
}

ll distance(const P& a, const P& b, const P& p){
    ll c = cross(p-a, b-a);
    return c * c;
}

bool doesLineCrossCircle(const P& a, const P& b, const P& cc, const ll& radius){
    if(distance(a, b, cc) > radius * radius * norm(b-a)){return false;}
    if(norm(a-cc) > radius * radius && norm(b-cc) > radius * radius){
       return dot(cc-a, b-a) * dot(cc-b, b-a) <= 0;
    }
    return (norm(a-cc) < radius * radius) ^ (norm(b-cc) < radius * radius);
}

int N, M;
P wps[100100]; ll wrs[100100];

int main(){
    while(std::cin >> N, N){
        assert(N < 100100);
        REP(i, N){
            ll re, im;
            std::cin >> re >> im >> wrs[i];

            wps[i].real(re); wps[i].imag(im);
        }

        std::cin >> M;
    
        REP(i, M){
            P taro, oni;
            ll re, im;
            std::cin >> re >> im;
            taro.real(re); taro.imag(im);
            std::cin >> re >> im;
            oni.real(re); oni.imag(im);

            bool f = false;
            REP(j, N){
                // assert(norm(taro-wps[j]) != wrs[j] * wrs[j] &&
                //       norm(oni-wps[j]) != wrs[j] * wrs[j]);
                // if(real(taro) == real(oni) &&
                //    imag(taro) == imag(oni)){
                //     continue;
                // }
                if(doesLineCrossCircle(taro, oni, wps[j], wrs[j])){
                    f = true;
                }
            }

            if(f){
                puts("Safe");
            }else{
                puts("Danger");
            }
        }
    }
}

Measured memory_bytes: 1140
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n;
    int ret = 0;
    cin >> n;
    vector<int> v(n);
    vector<int> pos;
    vector<int> neg;
    for(int i=0;i<n;++i)
    {
        cin >> v[i];
        if(v[i] >= 0) pos.push_back(v[i]);
        if(v[i] < 0) neg.push_back(v[i]);
    }

    sort(pos.begin(), pos.end());
    sort(neg.rbegin(), neg.rend());
    if(pos.size() == 0)
    {
        int tmp = neg[0];
        cout << (accumulate(neg.begin(), neg.end(), 0) - neg[0] * 2) * -1 << endl;
        for(int i=0;i<n-1;++i) {
            cout << tmp << " " << neg[i+1] << endl;
            tmp -= neg[i+1];
        }
    }
    else if(neg.size() == 0)
    {
        int tmp = pos[0];
        cout << (accumulate(pos.begin(), pos.end(), 0) - pos[0] * 2) << endl;
        for(int i=0;i<n-2;++i) {
            cout << tmp << " " << pos[i+1] << endl;
            tmp -= pos[i+1];
        }
        cout << pos[pos.size() - 1] << " " << tmp << endl;;
    }
    else
    {
        int tmp = neg[0];
        cout << accumulate(pos.begin(), pos.end(), 0) + -1 * accumulate(neg.begin(), neg.end(), 0)<< endl;
        for(int i=0;i<(pos.size()-1);++i)
        {
            cout << tmp << " " << pos[i] << endl;
            tmp -= pos[i];
        }
        cout << pos[pos.size() - 1] << " " << tmp << endl;
        tmp = pos[pos.size() - 1] - tmp;
        for(int i=0;i<(neg.size() - 1);++i)
        {
            cout << tmp << " " << neg[i+1] << endl;
            tmp -= neg[i+1];
        }
    }
}

Measured memory_bytes: 2808
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

using ll = long long int;
using namespace std;

int main(){
  ll N;
  string S;

  cin >> N;
  cin >> S;

  ll NR = 0, NG = 0, NB = 0;
  for(ll i = 0; i < N; i++){
    if(S[i] == 'R'){
      NR++;
    }
    else if(S[i] == 'G'){
      NG++;
    }
    else{
      NB++;
    }
  }

  ll ans = NR * NG * NB;
  for(ll i = 0; i < N; i++){
    for(ll j = 1; j < N; j++){
      if(i+2*j < N && S[i]!=S[i+j] && S[i]!=S[i+2*j] &&S[i+2*j]!=S[i+j]){
        ans--;
      }
    }
  }

  cerr << "Answer:" << endl;
  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 3620
s = input()

for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        print(*[i + 1, i + 2])
        exit()
for i in range(len(s) - 2):
    if s[i] == s[i + 2]:
        print(*[i + 1, i + 3])
        exit()
print(*[-1, -1])


Measured memory_bytes: 3188
n,m = gets.split.map(&:to_i)
d = m.times.map{gets.split.map(&:to_i)}
m.times do |i|
    d[i] << i
end
d.sort_by!{|i,j,k|j}
a = Hash.new(0)
m.times do |i|
    a[d[i][0]] += 1
    d[i] << a[d[i][0]]
end
d.sort_by!{|i,j,k,l|k}
m.times do |i|
    puts ("00000"+(d[i][0].to_s))[-6..-1]+("00000"+(d[i][3].to_s))[-6..-1]
end

Measured memory_bytes: 37564
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	/**
	 * @param args
	 * @throws IOException
	 */
	public static void main(String[] args) throws IOException {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);
		String input = br.readLine();
		for (int i = input.length() - 1; i > 0; i--) {
			System.out.print(input.charAt(i));
		}
		System.out.println(input.charAt(0));
	}
}

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define SORTG(v) sort(v.begin(),v.end(),greater<>())
#define SORT(v) sort(v.begin(),v.end())
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/3

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<string> Vs;

template<class T> void chmax(T& a, T b) {if(a<b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a>b){a=b;}}
void YesNo(int a){cout<<((a)?"Yes":"No")<<endl;}
void YESNO(int a){cout<<((a)?"YES":"NO")<<endl;}
void AorB(int a,string b,string c){cout<<((a)?b:c)<<endl;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void start(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);}

signed main(){start();
    int n,count=0;
    cin>>n;
    map<int,int> mp;
    REP(i,0,n){
        int t;
        cin>>t;
        mp[t]++;
    }
    for(auto x : mp){
        if(x.second>1) count+=x.second-1;
    }
    if(count%2==1) cout<<mp.size()-1<<endl;
    else cout<<mp.size()<<endl;
    return 0;
}


Measured memory_bytes: 6528
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.InputMismatchException;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
	
	 static Scanner in = new Scanner(System.in);
	 
   
	public static void main(String args[])throws IOException  {
   
    	
        String s=in.nextLine(); 
        int len1=s.length();
        String s1=s;
        String str="keyence";
        int len=str.length();
        int pos=s.indexOf(str);
        if(pos!=-1&&(pos==0||pos==len1-len))
        {
    		System.out.println("YES");
    		return ;
    	}
        int t=len1-len;
        for(int i=1;i<len1-t;i++)
        {
        	s=s.substring(0,i)+s.substring(i+t,len1);
        	if(s.equals(str))
        	{
        		System.out.println("YES");
        		return ;
        	}
        	s=s1;
        }
    		System.out.println("NO");	
     	
    }

	
	
 
	
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef vector<int> vi;

template<class T> inline T re(){
	T N = 0; char c = getchar(); bool neg = 0;
	for (; c < '0' || c > '9'; c = getchar()) neg |= c == '-';
	for (; c >= '0' && c <= '9'; c = getchar())
		N = (N<<3)+(N<<1) + c - '0';
	return neg ? -N : N;
}

char buf[105];
int main(){
	scanf("%s", buf);
	buf[0] = '2'; buf[1] = '0', buf[2] = '1', buf[3] = '8';
	puts(buf);
	return 0;
}


Measured memory_bytes: 256