akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args) {
		Stack<Integer> myStack = new Stack<Integer>();
		Scanner sc = new Scanner(System.in);
		int a, b;
		while (sc.hasNext()) {
			
			String str = sc.next();
			if (str.charAt(0) == '+') {
				a = myStack.pop();
				b = myStack.pop();
				myStack.push(b + a);
			}
			else if (str.charAt(0) == '-') {
				a = myStack.pop();
				b = myStack.pop();
				myStack.push(b - a);
			}
			else if (str.charAt(0) == '*') {
				a = myStack.pop();
				b = myStack.pop();
				myStack.push(b * a);
			}
			else if (str.charAt(0) == '/') {
				a = myStack.pop();
				b = myStack.pop();
				myStack.push(b / a);
			}
			else {
				myStack.push(Integer.parseInt(str));
			}
		}
		System.out.println(myStack.pop());
	}
}



Measured memory_bytes: 26244
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		// 奇数
		if(n%2 == 1 && (n+1)/2 >= k) {
			System.out.println("YES");
		}
		// 偶数
		else if(n%2 == 0 && n/2 >= k) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
# -*- coding: utf-8 -*-
import numpy as np
from scipy.sparse.csgraph import csgraph_from_dense, dijkstra
def inpl(): return map(int, input().split())

sx, sy, tx, ty = inpl()
N = int(input())
X = np.zeros((1, N+2), dtype=np.float64)
Y = np.zeros((1, N+2), dtype=np.float64)
R = np.zeros((1, N+2), dtype=np.float64)

X[0][0] = sx
Y[0][0] = sy
X[0][N+1] = tx
Y[0][N+1] = ty

for i in range(N):
    X[0][i+1], Y[0][i+1], R[0][i+1] = inpl()

G = np.maximum(np.sqrt(np.square(X-X.T) + np.square(Y-Y.T)) - (R+R.T),
               np.zeros((N+2, N+2), dtype=np.float64)) 
G += np.diag(np.ones(N+2, dtype=np.float64)*np.inf)
G = csgraph_from_dense(G, null_value=np.inf)
print(dijkstra(G, indices=0)[-1])


Measured memory_bytes: 50956
N,K = map(int,input().split())
ary = [list(map(int,input().split())) for _ in range(N)]
a = sorted(ary)
ans = float("Inf")
for i in range(N-K+1):
    for j in range(i,N-K+1):
        lx = a[i][0]; rx = a[K+j-1][0]
        b = a[i:K+j]
        c = sorted(b,key=lambda x:(x[1]))
        for k in range(len(c)-K+1):
            by = c[k][1]; uy = c[k+K-1][1]
            ans = min(ans,(rx - lx) * (uy - by))
print(ans)

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

int main(){
	
	int n,m; cin>>n>>m;
	int d{};
	for(int i=0; i<m; i++){
		int a;
		cin >>a;
		d += a;
	}
	cout << (n-d>=0?n-d:-1) << endl;
	
}

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

int digNum(int n)
{
    int digit = 1;
    for (;;)
    {
        if (n / 10 >= 1)
            digit++;
        else
            return digit;
        n /= 10;
    }
}

int main()
{
    unsigned int N;
    cin >> N;
    int ans = 0;

    for (int i = 0; i <= N; i++)
    {
        if (digNum(i) % 2 == 1)
            ans++;
    }
    cout << --ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
#Bubble sort
cnt = 0
flag = 1
while flag:
    flag = 0
    for j in range(n-1, 0, -1):
        if A[j] < A[j-1]:
            A[j], A[j-1] = A[j-1], A[j] #swap by Python3
            cnt +=1
            flag = 1
print(' '.join(map(str, A)))
print(cnt)



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

int main() {
  int N;
  cin >> N;
int P[N],j;
int sam=0;
int small=200000000;
for(int i=0;i<N;i++)
{cin >>P[i];
 if(small>=P[i]){
		small=P[i];
		sam++;
		}
}
cout <<sam;}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	string s, t;
	cin >> s >> t;
	int a, b;
	string u;
	cin >> a >> b >> u;
	if (s == u) {
		--a;
	} else {
		--b;
	}
	cout << a << ' ' << b << '\n';
 	return 0;
}


Measured memory_bytes: 256
from heapq import heappush, heappop
class MinCostFlow:
    INF = 10**18

    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def addEdge(self, fr, to, cap, cost):
        forward = [to, cap, cost, None]
        backward = forward[3] = [fr, 0, -cost, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def flow(self, s, t, f):
        N = self.N; G = self.G
        INF = MinCostFlow.INF

        res = 0
        H = [0]*N
        prv_v = [0]*N
        prv_e = [None]*N

        d0 = [INF]*N
        dist = [INF]*N

        while f:
            dist[:] = d0
            dist[s] = 0
            que = [(0, s)]

            while que:
                c, v = heappop(que)
                if dist[v] < c:
                    continue
                r0 = dist[v] + H[v]
                for e in G[v]:
                    w, cap, cost, _ = e
                    if cap > 0 and r0 + cost - H[w] < dist[w]:
                        dist[w] = r = r0 + cost - H[w]
                        prv_v[w] = v; prv_e[w] = e
                        heappush(que, (r, w))
            if dist[t] == INF:
                return None

            for i in range(N):
                H[i] += dist[i]

            d = f; v = t
            while v != s:
                d = min(d, prv_e[v][1])
                v = prv_v[v]
            f -= d
            res += d * H[t]
            v = t
            while v != s:
                e = prv_e[v]
                e[1] -= d
                e[3][1] += d
                v = prv_v[v]
        return res

G=MinCostFlow(2502)
n,m=map(int,input().split())
S=[]
for _ in range(n):
    S.append(input())
    
os=0

for i in range(n):
    for q in range(m):
        cnt=i*m+q+1
        now=S[i][q]
        if now=="#":
            continue
        if now=="o":
            G.addEdge(0,cnt,1,0)
            os+=1
        if q<m-1 and S[i][q+1]!="#":
            G.addEdge(cnt,cnt+1,1000,-1)
        if i<n-1 and S[i+1][q]!="#":
            G.addEdge(cnt,cnt+m,1000,-1)
        G.addEdge(cnt,2501,1,0)

ans=G.flow(0,2501,os)
print(-ans)
            

Measured memory_bytes: 76720
#include <iostream>
using namespace std;
int main()
{
    int N, cnt=0,d1,d2;
    cin >> N;
    for (int i = 0;i < N;i++) {
        cin >> d1 >> d2;
        if (d1 == d2)cnt += 1;
        else cnt = 0;
        if (cnt >= 3) {
            cout << "Yes" << "\n";
            break;
        }
    }
    if (cnt<3) cout << "No" << "\n";
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[])
{
	string s; cin>>s;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='1')
            cout<<'9';
        
        else
        {
            cout<<'1';
        }
        
    }
    cout<<endl;

	return 0;
}


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

int main(){
    int K, A, B ;
    cin >> K >> A >> B ;
    for(int i = A ; i <= B ; i++){
        if(i % K == 0){
            cout <<  "OK" << endl ;
            return 0;
        }
    }
    cout << "NG" << endl ;
    return 0 ;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define OUT(x) cout << (x) << endl;
#define OUTA(a, n) \
    REP(i, n) { cout << (a[i]) << (i == n - 1 ? "\n" : " "); }
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main()
{
    ll N, A, B;
    cin >> N >> A >> B;
    ll ans = max(0LL, ((N - 1) * B + A - ((N - 1) * A + B)) + 1);
    OUT(ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(){
   int n,i,j,cnt = 0,sum,ans = 0;
   scanf("%d",&n);
   int x[n];
   for(i = 0; i < n; i++){
      scanf("%d",&x[i]);
   }
   while(cnt < n){
      sum = 0;
      if(cnt==0){
         for(j = 0; j < n; j++){
            sum += (x[j]-1)*(x[j]-1);
         }
         ans = sum;
         cnt++;
      }else{
         i = 2;
         while(i<=100){
            sum = 0;
            for(j = 0; j < n; j++){
               sum += ((x[j]-i)*(x[j]-i));
               if(sum > ans){
                  break;
               }
            }
            if(sum < ans){
               ans = sum;
            }
            cnt++;
            i++;
         }
      }
   }
   printf("%d",ans);
   return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


int digit(ll n) {
    int x = 0;
    while (n > 0) {
        n /= 10;
        x++;
    }
    return max(1, x);
}

signed main()
{
    int n;
    cin >> n;

    int d = digit(n);

    int cnt = 0;
    for (int D = 3; D <= d; D++) {
        ll n_pat = 1; rep(i, D) n_pat *= 3;
        rep (pat, n_pat) {
            ll t = pat;
            ll v = 0;
            int c7 = 0;
            int c5 = 0;
            int c3 = 0;
            rep(i, D) {
                if (t % 3 == 0) {
                    v = 10 * v + 7;
                    c7 ++;
                }
                else if (t % 3 == 1) {
                    v = 10 * v + 5;
                    c5++;
                }
                else {
                    v = 10 * v + 3;
                    c3++;
                }
                t /= 3;
            }

            if (c7 == 0 || c5 == 0 || c3 == 0) {
                continue;
            }

            if (v > n) {
                continue;
            }

            cnt++;
        }
    }

    put(cnt);

    return 0;
}

Measured memory_bytes: 3644
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::HashMap;
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

const M: i64 = 1000000007;

fn main() {
    let s: i64 = read();

    let mut fact = vec![1, 1];
    let mut ifact = vec![1, 1];
    let mut inv = vec![1, 1];
    for i in 2..=4000i64 {
        fact.push(fact.last().unwrap() * i % M);
        inv.push((M - (M / i) * inv[(M % i) as usize] % M) % M);
        ifact.push(ifact.last().unwrap() * inv.last().unwrap() % M);
    }

    let combi =
        |n: i64, m: i64| fact[n as usize] * ifact[(n - m) as usize] % M * ifact[m as usize] % M;

    let ans = (1..=2000)
        .take_while(|n| 3 * n <= s)
        .map(|n| {
            let ss = s - n * 3;

            // println!("{} {}", n, combi(ss + n - 1, n - 1));
            combi(ss + n - 1, n - 1)
        })
        .fold(0, |acc, a| (acc + a) % M);

    println!("{}", ans);
}


Measured memory_bytes: 2228
#include<bits/stdc++.h>
using namespace std;
int main(){
  int k;
  cin >>k;
  string s;
  cin >> s;
  
  for(int i=0;i<s.size();i++){ 
    if(i>k-1){
      cout  << "..." ;
      break;
    }
    cout << s[i] ;
   
  }
  cout << endl;
}
    

Measured memory_bytes: 3512
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;

int main(){

	int tri[3];
	int s = 0, e = 0, t = 0, d = 0;

	while (cin >> tri[0] >> tri[1] >> tri[2]){
		sort(tri, tri + 3);
		if (tri[2] >= tri[0] + tri[1]) break;
		s++;
		if (pow(tri[2], 2) == pow(tri[0], 2) + pow(tri[1], 2)) t++;
		if (pow(tri[2], 2) > pow(tri[0], 2) + pow(tri[1], 2)) d++;
		if (pow(tri[2], 2) < pow(tri[0], 2) + pow(tri[1], 2)) e++;
	}

	cout << s << " " << t << " " << e << " " << d << endl;
	return 0;
}

Measured memory_bytes: 1180
#include <iostream>
#include <vector>
#include <map>

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n, MOD;
    cin >> n >> MOD;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        --a[i];
    }
    vector<ll> P(n);
    P[0] = a[0] % MOD;
    for (int i = 1; i < n; ++i)
        P[i] = (P[i - 1] + a[i]) % MOD;
    map<ll, ll> pref;
    ll odp = 0;
    for (int i = 0; i < n; ++i)
    {
        if (pref.find(P[i]) != pref.end())
            odp += pref[P[i]];
        if (P[i] == 0 && i + 1 < MOD)
            ++odp;
        ++pref[P[i]];
        if (i - MOD + 1 >= 0)
            --pref[P[i - MOD + 1]];
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll              long long int
#define vll             vector<ll>
#define vs              vector <string>                                    
#define mll             map<ll,ll>
#define pll             pair<ll, ll>
#define vpll            vector < pair<ll,ll> >
#define itr             vll::iterator
#define all(c)          c.begin(),c.end()
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define ps(x,y)         fixed<<setprecision(y)<<x
#define pb              push_back
#define mb              make_pair
#define ff              first
#define ss              second
#define max3(a,b,c)     max(max(a,b),c)                                    
#define min3(a,b,c)     min(min(a,b),c)  
#define mod             1000000007
#define inf             1000000000000000001
#define from(i, n)      for(__typeof(n) i = 0; i <  n; ++i)
#define fromj(i, j, n)  for(__typeof(n) i = j; i <  n; ++i)
#define printv(v)       from(i,v.size())cout<<v[i]<<" ";cout<<"\n";
#define w(x)            int x; cin>>x; while(x--)
 
using namespace std;
using namespace __gnu_pbds; 
 
void c_p_c()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
}
 
bool func(const pll &a, const pll &b){
    if(a.ss==b.ss)return a.ff<b.ff;
    return a.ss < b.ss;
}
 
typedef tree<int, null_type, less<int >, rb_tree_tag, 
             tree_order_statistics_node_update> pbds; 
 
int main(){
    c_p_c();
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    vll v(n),sum(n);
    from(i,n){
    	cin>>v[i];
    	if(i==0)sum[0]=v[0];
    	else sum[i]=v[i]+sum[i-1];
    } 	
    vector<vll >ar(n,vll(n,0));
    fromj(i,1,n){
    	fromj(j,i,n){
    		ar[j-i][j]=inf;
    		fromj(k,j-i,j){
    			if(j-i>0)
    			ar[j-i][j]=min(ar[j-i][j],-sum[j-i-1]+sum[j]+ar[j-i][k]+ar[k+1][j]);
    		    else ar[j-i][j]=min(ar[j-i][j],sum[j]+ar[j-i][k]+ar[k+1][j]);
    		}
    	}
    }
    /*from(i,n){
    	from(j,n)cout<<ar[i][j]<<" ";
    	cout<<"\n";
    }*/
    cout<<ar[0][n-1];
}    

Measured memory_bytes: 4436
#include<stdio.h>
int main()
{
	int a,b,sum=0;
	scanf("%d%d",&a,&b);
	if(a>=b)
	{
		sum=sum+a;
		a--;
		if(a>=b)
			sum=sum+a;
		else
			sum=sum+b;
	}
	else
	{
		sum=sum+b;
		b--;
		if(b>=a)
		{
			sum=sum+b;
		}
		else
			sum=sum+a;
	}
	printf("%d\n",sum);
	return 0;
}

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

int main(void){
    int matrix[100][100];
    int vector[100];
    int product[100];
    int i,j,columns,rows;

    scanf("%d %d",&columns,&rows);
    getchar();

    for(i=0;i<columns;i++){
        char buf[512];
        char *p_buf;
        gets(buf);

        j=0;
        p_buf=strtok(buf," ");
        matrix[i][j]=atoi(p_buf);
        j++;
        while(p_buf!=NULL){
            p_buf=strtok(NULL," ");
            if(p_buf!=NULL){
                matrix[i][j]=atoi(p_buf);
                j++;
            }
        }
    }

    for(j=0;j<rows;j++){
        scanf("%d",&vector[j]);
        getchar();
    }

    for(i=0;i<columns;i++){
        product[i]=0;
        for(j=0;j<rows;j++){
            product[i]+=matrix[i][j]*vector[j];
        }
        printf("%d\n",product[i]);
    }

    return 0;
}

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

cnt = 0
b = []
for i in range(n):
    if a[i] < 0:
        cnt += 1
    b.append(abs(a[i]))

if cnt % 2 == 0:
    ans = sum(b)
    print(ans)
else:
    ans = sum(b) - 2 * min(b)
    print(ans)


Measured memory_bytes: 14412
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    int n=len(s);
    int ans=0;
    bool flag=true;
    if(n==1){
      cout<<s.front()<<endl;;
      return 0;
    }
    rep(i,n){
      if(i==0) continue;
      if(s[i]!='9') flag=false;
    }
    if(flag){
      rep(i,n) ans+=s[i]-'0';
    }else{
      rep(i,n){
      if(i==0) ans+=s[0]-'0'-1;
      else ans+=9;
      }
    }
    cout<<ans<<endl;
}

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

int main(){
    int L;  cin >> L;
    vector<ll> a(L+1,0);
    for(int i=1; i<=L; i++) cin >> a[i];

    vector<vector<ll>> dp;
    dp = vector<vector<ll>>(L+2, vector<ll>(5,0));
    for(int i=1; i<=L; i++){
        ll prev = inf;
        for(int t=0; t<=4; t++){
            prev = min(prev, dp[i-1][t]);
            if(t==0 || t==4) dp[i][t] = prev + a[i];
            if(t==1 || t==3) dp[i][t] = prev + (a[i]==0 ? 2:a[i]%2);
            if(t==2) dp[i][t] = prev + 1 - a[i]%2;
        }
    }

    ll ans = inf;
    for(int t=0; t<=4; t++) ans = min(ans, dp[L][t]);
    cout << ans << endl;
}


Measured memory_bytes: 15872
#include<iostream>
#include<cmath>
using namespace std;        
    
 bool isPrime(int x){
    if(x==2) return true;
    if(x<2||x%2==0) return false;
    
    int i=3;
    
    while(i<=sqrt(x)){
        if(x%i==0) return false;
        i=i+2;
    }
    return true;
}
int main(){
    int x,n,cnt=0;
    cin>>n;
    
    
    for(int j=0;j<n;j++){
        cin>>x;
        if(isPrime(x)) cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;
int main(int argc, char *argv[])
{
    
    
    cin.tie(0) ;
    ios::sync_with_stdio(false) ;
    
    int n;
    cin >> n;
    vector<int> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
    }
    
    sort(A.begin(), A.end(), std::greater<int>());
    
    u64 ans = (u64) A[0];
    
    for (int i = 2; i <= n - 1; i++) {
        ans += (u64) A[i/2];
    }
    
    cout << ans << endl;
    
    
    return 0;
    
}


Measured memory_bytes: 3980
#include <iostream>
#include <stdlib.h>
using namespace std;

int main(){
        int s[3];
        const char* c;//const is must.
        int count = 0;
        string str;
        cin >> str;
        c = str.c_str();
        for(int i =0; i < 3; i++){
                if (c[i] == '1') count++;
        }
        cout << count;
        return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <ctype.h>

using namespace std;
 
int main(){

	char ch;
	
	while(1){
		scanf("%c",&ch);
		if (ch == '\n') break;
		
		else if (islower(ch)) printf("%c",toupper(ch));
		
		else if (isupper(ch)) printf("%c",tolower(ch));
		
		else cout << ch;

	}
	cout << endl;
		
    return 0;
}

Measured memory_bytes: 1152
#include <cstdio>
#include <cstdlib>

int main()
{
  int N, K, card[500][500], seq[1000];
  while (scanf("%d %d", &N, &K) != EOF) {
    for (int i = 0; i < K; ++i) {
      for (int j = 0; j < N/2; ++j) {
	scanf("%d", &card[i][j]);
	--card[i][j];
      }
    }

    const int lower = N/8, upper = 3*N/8;
    bool ok = false;
    while (!ok) {
      for (int i = 0; i < N; ++i) {
	if (rand()&1)
	  seq[i] = 1;
	else
	  seq[i] = 0;
      }

      ok = true;
      for (int i = 0; i < K && ok; ++i) {
	int sum = 0;
	for (int j = 0; j < N/2; ++j)
	    sum += seq[card[i][j]];

	if (lower > sum || sum > upper)
	  ok = false;
      }
    }

    for (int i = 0; i < N; ++i)
      printf("%d", seq[i]);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 1620
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    a, b = (int(_) for _ in input().split())
    orig_a = 0
    for i in range(b-a):
        orig_a +=i
    print(orig_a - a)
    
if __name__ == '__main__':
    main()


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

//#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define LL long long

int main() {
	char c;
	cin >> c;
	if(c >= 'a' && c <= 'z') {
		cout << 'a' << endl;
	} else {
		cout << 'A' << endl;
	}

	return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> H(N);
    for (auto& i : H) cin >> i;
    vector<bool> good(N, true);
    for (int i = 0, A, B; i < M; i++) {
        cin >> A >> B;
        if (H[A - 1] == H[B - 1]) good[A - 1] = good[B - 1] = false;
        else if (H[A - 1] > H[B - 1]) good[B - 1] = false;
        else if (H[A - 1] < H[B - 1]) good[A - 1] = false;
    }
    cout << count(good.begin(), good.end(), true) << endl;
}

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

ll fast(ll a, ll b)
{

    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % m;
        a = (a * a) % m;
        b = b / 2;
    }
    return ans;
}

int main()
{
    ll n, k;
    cin >> n >> k;
    ll arr[n];
    ll fac[n + 2];
    fac[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        fac[i] = (fac[i - 1] * i) % m;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }
    sort(arr, arr + n);
    ll sum1 = 0;
    for (int i = 0; i < n - k + 1; i++)
    {
        ll p1 = fac[n - i - 1];
        ll p2 = fast(fac[k - 1], m - 2);
        ll p3 = fast(fac[n - i - k], m - 2);
        //  cout << p1 << " " << p2 << " " << p3 << "\n";
        ll p = (((p1 * p2) % m) * p3) % m;
        sum1 += ((arr[i] * p) + m) % m;
    }
    //cout << sum1 << "\n";
    ll sum2 = 0;
    for (int i = n - 1; i >= k - 1; i--)
    {
        ll p1 = fac[i];
        ll p2 = fast(fac[k - 1], m - 2);
        ll p3 = fast(fac[i - k + 1], m - 2);
        //  cout << p1 << " " << p2 << " " << p3 << "\n";
        ll p = (((p1 * p2) % m) * p3) % m;
        sum2 += ((arr[i] * p) + m) % m;
    }
    // cout << sum2 << "\n";
    ll p1 = sum2 - sum1;
    // cout << p1 << "\n";
    ll p = (sum2 - sum1 + 2 * m) % m;
    cout << p << "\n";

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
    int a, b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
}


Measured memory_bytes: 2068
#include <iostream>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <complex>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <queue>

#define IO ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
const ll INF = 1e18;
const int N = 3e3 + 5, inf = 1e9, mod = 1e9 + 7;
using namespace std;
int n;
ld arr[N], ans = 0.0, dp[N][N] = {};

ld solve(int pos, int h)
{
    if(pos == n)
        return (h > n / 2);
    if(dp[pos][h] != -1)
        return dp[pos][h];
    return dp[pos][h] = (solve(pos + 1, h + 1) * arr[pos]) + (solve(pos + 1, h) * (1.0 - arr[pos]));
}

int main()
{
    IO
    for(int i = 0; i < N; i++)
        for(int j = 0; j < N; j++)
            dp[i][j] = -1.0;
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    cout << fixed << setprecision(10) << solve(0, 0) << '\n';
    return 0;
}

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

public class Main {
    public static long solve[][] = new long[1001][1001];
    public static char grid[][] = new char[1001][1001];
    public static long H,W;
    public static void main(String args[])throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String HW[]=br.readLine().split(" ");
        H=Long.parseLong(HW[0]);
        W=Long.parseLong(HW[1]);
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
                solve[i][j]=-1;
        }
        solve[(int)H-1][(int)W-1]=1;
        for(int i=0;i<H;i++)
        {
            String S=br.readLine();
            for(int j=0;j<W;j++)
                grid[i][j]=S.charAt(j);
        }
        /*for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
                System.out.print(grid[i][j]);
            System.out.println();
        }*/
        System.out.println(DP(0,0));
        /*System.out.println("\n\n\n");
        for(int i=0;i<H;i++)
        {
            for(int j=0;j<W;j++)
                System.out.print(solve[i][j]+" ");
            System.out.println();
        }*/
    }
    public static long DP(int x,int y)
    {
        if(solve[x][y]==-1)
        {
            if(x==H||y==W||grid[x][y]=='#')
                return 0;
            else
                solve[x][y]=DP(x,y+1)+DP(x+1,y);
        }
        return solve[x][y]%1000000007;
    }
}

Measured memory_bytes: 38900
n = int(input())
p = []
for i in range(n):
    a = int(input())
    p.append(a)
q = sorted(p, reverse=True)
max1 = q[0]
max2 = q[1]
max1_i = p.index(max1)
max2_i = p.index(max2)
for i in range(n):
    if i == max1_i:
        print(max2)
    else:
        print(max1)

Measured memory_bytes: 70104
#include <iostream>
#include <bits/stdc++.h>
#define loop(i,N) for(int i=0;i<N;i++)
#define vi vector<int>
#define vs vector<string>
#define vl vector<long long int>
#define vpi vector<pair<int,int>>
#define msi map<string,int>
#define mil map<int,long long int>
#define lli long long int

using namespace std ;

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a+b>=c)
        cout<< "Yes"<<endl;
    else
        cout<< "No"<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll par[100009],vis[100009],vis2[100009];
vector<ll> v[100009];
void bfs(ll node,ll n)
{
    vis[node] = 1;
    for(ll i = 1;i<=n;i++)
        par[i] = -1;
    queue<ll> q;
    q.push(node);
    while(!q.empty())
    {
        ll temp = q.front();
        q.pop();

        if(temp==n)
            break;
        for(ll i=0;i<v[temp].size();i++)
        {
            if(vis[v[temp][i]]==0)
            {
                vis[v[temp][i]]= 1;
                q.push(v[temp][i]);
                par[v[temp][i]] = temp;
            }
        }
    }
}
ll bfs2(ll node)
{
    vis2[node] = 1;
    queue<ll> q;
    q.push(node);
    ll cnt = 1;
    while(!q.empty())
    {
        ll temp = q.front();
        q.pop();
        for(ll i=0;i<v[temp].size();i++)
        {
            if(vis2[v[temp][i]]==0)
            {
                cnt++;
                vis2[v[temp][i]]= 1;
                q.push(v[temp][i]);
            }
        }
    }
    return cnt;
}
vector<ll> p;
void path(ll n)
{

    if(n==-1)
        return;
    path(par[n]);
    p.push_back(n);
}
int main()
{
    ll i,n,j,x,y;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        cin>>x>>y;
        v[x].push_back(y);
        v[y].push_back(x);

    }
    bfs(1,n);
    path(n);
    vector<ll> v1,v2;
    for(i=0,j=p.size()-1;i<=j;i++,j--)
    {
        v1.push_back(p[i]);
        v2.push_back(p[j]);
        vis2[p[i]] = 1;
        vis2[p[j]] = 2;
    }
    ll pq = 0;

    for(i=0;i<v1.size();i++)
    {
        pq+= bfs2(v1[i]);
    }
    if(pq<=n-pq)
    {
        cout<<"Snuke"<<endl;
    }
    else cout<<"Fennec"<<endl;



}


Measured memory_bytes: 13172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    sort(ALL(A));

    ll tmp = 0;
    ll ans = -1;
    for (int i = 0; i < N - 1; i++) {
        tmp += A[i];
        if(tmp * 2 < A[i+1]){
            ans = i;
        }
    }

    ans = N - ans - 1;

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

Measured memory_bytes: 3988
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto K = s[1].to!long;
    auto A = readln.split.map!(to!long).array;

    auto B = new long[](N+1);
    foreach (i; 0..N) B[i+1] = (B[i] + A[i]) % K;

    long ans = 0;
    long[long] cnt;
    auto C = new long[](N+1);

    foreach (i; 0..N+1) {
        long z = ((B[i] - i) % K + K) % K;
        if (i >= K) {
            cnt[C[i - K.to!int]] -= 1;
        }
        if (z in cnt) ans += cnt[z];
        cnt[z] += 1;
        C[i] = z;
    }

    ans.writeln;
}

Measured memory_bytes: 31892
import java.util.Scanner;

public class Main {
    private static int a, b, c;
    private static int count;

    public static void main(String[] args) {
        init();

        if (a + b >= c) {
            count += (c + b);
        } else {
            count += (a + 2 * b);
            if (c > a + b) count++;
        }

        System.out.println(count);
    }

    public static void init() {
        Scanner scanner = new Scanner(System.in);
        a = scanner.nextInt();
        b = scanner.nextInt();
        c = scanner.nextInt();
        count = 0;
    }
}

Measured memory_bytes: 23124
use std::cmp::max;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n:usize,
        s:chars,
    }
    let mut now_max = 0;
    let mut now_num = 0;
    for i in 0..s.len() {
        if s[i] == 'I' {
            now_num += 1;
        } else {
            now_num -= 1;
        }
        now_max = max(now_max, now_num);
    }
    println!("{}", now_max);
}


Measured memory_bytes: 4352
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=pin()[:-1]
  B=pin()[:-1]
  C=pin()[:-1]
  ans=0
  for i in range(N):
    l=[A[i],B[i],C[i]]
    t=len(list(set(l)))
    ans+=t-1
  print(ans)
  return 
main()

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct pos{
    int mx, mn;
};

int main(){
    int h,w,n;cin >> h >> w >> n;
    int x,y;cin >> y >> x;
    --x;--y;
    string s,t;cin >> s >> t;
    vector<int> dire(4);
    dire[0] = y;
    dire[1] = x;
    dire[2] = y;
    dire[3] = x;
    // dire[i][0] = max
    // dire[i][1] = min
    // 0 : up / 1 : right / 2 : down / 3 : left 
    rep(i,n){
        // s
        if(s[i]=='U'){
            --dire[0];
        }else if(s[i]=='R'){
            ++dire[1];
        }else if(s[i]=='D'){
            ++dire[2];
        }else if(s[i]=='L'){
            --dire[3];
        }

        if(dire[0]<0 || dire[1]>=w || dire[2]>=h || dire[3]<0){
            cout << "NO" << endl;
            return 0;
        }
        
        // t
        if(t[i]=='U'){
            dire[2] = max(0, dire[2] -1);
        }else if(t[i]=='R'){
            dire[3] = min(w-1, dire[3] +1);
        }else if(t[i]=='D'){
            dire[0] = min(h-1, dire[0] +1);
        }else if(t[i]=='L'){
            dire[1] = max(0, dire[1] -1);
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 776
use std::io::Read;

fn main() {
    let mut buf = String::new();

    std::io::stdin().read_to_string(&mut buf).unwrap();

    let mut iter = buf.split_whitespace();

    let a: usize = iter.next().unwrap().parse().unwrap();
    let b: usize = iter.next().unwrap().parse().unwrap();
    let c: usize = iter.next().unwrap().parse().unwrap();

    if a == b {
        if b == c {
            println!("No");
        } else {
            println!("Yes");
        }
    } else {
        if a == c {
            println!("Yes");
        } else if b == c {
            println!("Yes");
        } else {
            println!("No");
        }
    }
}

Measured memory_bytes: 4352
import itertools
import math
n = int(input())

placed = []

for i in range(n):
    a = list(map(int,input().split()))
    placed.append(a)

l = list(range(8))
perm = tuple(itertools.permutations(l))

for v in perm:
    flag = True
    
    for j in range(len(placed)):
        if v[placed[j][0]] != placed[j][1]:
            flag = False
            break 
    if flag == False:
        continue
    for i in range(8):
        k = 1
        # print(i)
        while  i+k<=7:
            # print(v,i,v[i],k,len(v))
            if i+k<=7:
                # print(i+k)
                if v[i+k] == v[i]+k or v[i+k] == v[i]-k:
                    flag = False
                    break
                # if v[i+k] == v[i]-k:
                #     flag = False
                #     break
            k += 1
        if flag == False:
            break
            
    if flag == True:
        # print(v)
        for r in range(8):
            for c in range(8):
                if c == v[r]:
                    print("Q",end = "")
                else:
                    print(".",end = "")
            print("")
                
        break
  
    # print(v[4],v)
    



Measured memory_bytes: 10672
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,q;
    string s;
    cin>>n>>s>>q;
    vector<set<int>> t(26);
    rep(i,n){
        int x=s[i]-'a';
        t[x].insert(i);
    }
    rep(i,q){
        ll tp;cin>>tp;
        if(tp==1){
            //j文字目をcに置き換える
            int j;char c;cin>>j>>c;j--;
            int pre=s[j]-'a',now=c-'a';
            t[pre].erase(j);
            s[j]=c;
            t[now].insert(j);
        }else{
            //l文字目からr文字目まで何種類の文字が使われているのかを調べる
            ll l,r;cin>>l>>r;l--;r--;
            ll res=0;
            rep(j,26){
                auto itr1=t[j].lower_bound(l);
                auto itr2=t[j].lower_bound(r+1);
                if(itr1!=itr2)res++;
            }
            cout<<res<<endl;
        }
    }
}

Measured memory_bytes: 27252
#include <bits/stdc++.h>
#define repl(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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; }
//ミョ(-ω- ?)
int main() {
    int w,a,b;
    cin >> w >> a >> b;
    if(a > b)swap(a,b);
    cout << max(0,b-(w+a)) << endl; 
    return 0;
}

Measured memory_bytes: 256
while True:
    n,k=[int(i) for i in input().split()]
    if n==0 and k==0:
        break
    a=[int(input()) for i in range(n)]
    s=sum(a[0:k])
    max=s
    for i in range(k,n):
        s=s+a[i]-a[i-k]
        if s>max:
            max=s
    print(max)


Measured memory_bytes: 9888
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;

int main(int argc, const char * argv[]) {
    
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n; cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        mp[a]++;
    }
    
    if (mp[0] == n) {
        cout << "Yes" << endl;
        return 0;
    }
    if (n % 3 != 0) {
        cout << "No" << endl;
        return 0;
    }
    
    vector<int> num;
    for (auto &iter : mp) {
        for (int i = 0; i < iter.second / (n / 3); i++) {
            num.push_back(iter.first);
        }
    }
    if (num.size() == 3 && (num[0] ^ num[1] ^ num[2]) == 0) {
        cout << "Yes" << endl;
    } else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 3840
#include<stdio.h>

int main(){
	int H,W;
	scanf("%d %d",&H,&W);
	char a[H][W];
	for(int i=0;i<H;i++)scanf("%s",a[i]);
	
	int comph[H],compw[W];
	
	for(int i=0;i<H;i++){
		int tmp=0;
		for(int j=0;j<W;j++){
			if(a[i][j]=='#')tmp++;
		}
		if(tmp==0)comph[i]=1;
		else comph[i]=0;
	}
	
	for(int j=0;j<W;j++){
		int tmp=0;
		for(int i=0;i<H;i++){
			if(a[i][j]=='#')tmp++;
		}
		if(tmp==0)compw[j]=1;
		else compw[j]=0;
	}
	
	for(int i=0;i<H;i++){
		if(comph[i]==1)continue;
		for(int j=0;j<W;j++){
			if(compw[j]==1)continue;
			printf("%c",a[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
*A, = map(int, input().split())
p = 10**9+7
DP = [[None for j in range(k+1)] for i in range(n+1)]
for i in range(n+1):
    DP[i][0] = 1
for j in range(1, k+1):
    DP[0][j] = 0
for i in range(1, n+1):
    for j in range(1, k+1):
        DP[i][j] = (DP[i][j-1]+DP[i-1][j]) % p
        if j > A[i-1]:
            DP[i][j] = (DP[i][j]-DP[i-1][j-1-A[i-1]]) % p
print(DP[n][k])


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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  
  int step = a + b;
  int minute = c;
  for(int i = 0; i++ < 500000; minute += 60) {
    if(minute % step <= a) {
      cout << minute << endl;
      exit(0);
    }
  }
  cout << -1 << endl;
}

Measured memory_bytes: 1164
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
typedef long long ll;

const ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long 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() {
	ll n, a, b, i, d[2222], j, k, ans = 1e+15,count=0;
	char s[2222];
	cin >> n>>s;
	vector<int> list[2222];
	queue<int> q;
	for (i = 1; i <= n; i++)
		d[i] = 0;
	for (i = 0; i < n-1; i++) {
		cin >> a >> b;
		list[a].push_back(b);
		list[b].push_back(a);
		d[a]++;
		d[b]++;
	}
	for (i = 0; i < n; i++)
		if (s[i] == '1')
			count++;
	if (count == 1) {
		cout << "0" << endl;
		return 0;
	}
	for (i = 1; i <= n; i++) {
		if (d[i] > 1) {
			int cd[2222], p[2222], sum[2222], c[2222],ma[2222],maxum[2222],mp[2222];
			k = 0;
			for (j = 1; j <= n; j++) {
				cd[j] = d[j];
				p[j] = 0;
				sum[j] = 0;
				c[j] = 0;
				ma[j] = 0;
				maxum[j] = 0;
				if (d[j] == 1)
					q.push(j);
				if (s[j - 1] == '1')
					p[j]++;
			}
			while (!q.empty()) {
				int t = q.front();
				if (ma[t] * 2 > sum[t]) {
					k += sum[t] - ma[t];
					sum[t] = ma[t] * 2 - sum[t];
				}
				else {
					k += sum[t] / 2;
					sum[t] = sum[t] % 2;
				}
				sum[t] += p[t];
				maxum[t] += p[t];
				for (auto& e : list[t]) {
					if (c[e] == 0) {
						cd[e]--;
						sum[e] += sum[t];
						maxum[e] += maxum[t];
						if (sum[t] > ma[e])
							mp[e] = t;
						ma[e] = max(ma[e], sum[t]);
						p[e] += p[t];
						if (cd[e] == 1&&e!=i)
							q.push(e);
					}
				}
				c[t]++;
				q.pop();
			}
			if (ma[i] * 2 <= maxum[i]-maxum[mp[i]]+sum[mp[i]] && sum[i] % 2 == 0) {
				k += sum[i] / 2;
				ans = min(k, ans);
			}
		}
	}
	if (ans < 1e+12)
		cout << ans << endl;
	else
		cout << "-1" << endl;
}

Measured memory_bytes: 5120
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

int n;
int h[100010];
int dp[100010];

void chmin(int a, int *b)
{
	if (*b > a)
		*b = a;
}

int main(int argc, char const *argv[])
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		dp[i] = 2147483647;
		scanf("%d", h+i);
	}
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		if(i+1 < n) chmin(dp[i] + abs(h[i + 1] - h[i]), &dp[i + 1]);
		if(i+2 < n) chmin(dp[i] + abs(h[i + 2] - h[i]), &dp[i + 2]);
	}

	printf("%d", dp[n - 1]);
	return 0;
}


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

int main(){
    int n, m, i;
    cin >> n >> m;
    int a[n+1] = {};
    pair<int, int> p[m];
    for(i=0; i<m; i++){
        cin >> p[i].second >> p[i].first;
        if(p[i].second == 1){
            a[p[i].first] = 1;
        }
    }
    sort(p, p+m);
    for(i=m-1; i>=0; i--){
        if(p[i].first != n){
            break;
        }
        if(a[p[i].second] == 1){
            cout << "POSSIBLE";
            return 0;
        }
    }
    cout << "IMPOSSIBLE";
    return 0;
}

Measured memory_bytes: 2560