akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=105;
int a[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    int ans=1<<30;
    for(int i=-100;i<=100;i++){
        int sum=0;
        for(int j=1;j<=n;j++)
            sum+=(a[j]-i)*(a[j]-i);
        ans=min(ans,sum);
    }
    printf("%d\n",ans);
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans;
  if (a == b) {
    ans = a + b;
  } else {
    int mx = max(a, b);
    ans = mx + mx - 1;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<map>
#include<cstdlib>
#include<cctype>
#include<algorithm>

int main()
{
	int n;
	std::string str;
	
	while(1)
	{
		std::map<std::string,int> words[26];
		
		std::getline(std::cin,str);
		n=atoi(str.c_str());
		if(n==0)break;
		
		for(int i=0;i<n;i++)
		{
			int begin=0;
			bool inword=false;
			std::getline(std::cin,str);
			
			for(int i=0;i<str.size();i++)
			{
				if(isalpha(str[i])==0)
				{
					if(inword)
					{
						inword=false;
						std::string word=str.substr(begin,i-begin);
						if(words[word[0]-'a'].find(word)==words[word[0]-'a'].end())
						{
							words[word[0]-'a'].insert(std::pair<std::string,int>(word,1));
						}
						else
						{
							(words[word[0]-'a'])[word]++;
						}
					}
				}
				else if(!inword)
				{
					inword=true;
					begin=i;
				}
			}
			if(inword)
			{
				std::string word=str.substr(begin);
				if(words[word[0]-'a'].find(word)==words[word[0]-'a'].end())
				{
					words[word[0]-'a'].insert(std::pair<std::string,int>(word,1));
				}
				else
				{
					(words[word[0]-'a'])[word]++;
				}
			}
		}
		
		std::getline(std::cin,str);
		if(words[str[0]-'a'].size()==0)
		{
			std::cout<<"NA"<<std::endl;;
		}
		else
		{
			bool first=true;
			int i=0;
			
			std::multimap<int,std::string,std::greater<int> > output;
			
			for(std::map<std::string,int>::iterator it=words[str[0]-'a'].begin();it!=words[str[0]-'a'].end();it++)
			{
				output.insert(std::pair<int,std::string>((*it).second,(*it).first));
			}
			
			for(std::multimap<int,std::string>::iterator it=output.begin();it!=output.end();it++)
			{
				if(first){first=false;}
				else{std::cout<<' ';}
				std::cout<<(*it).second;
				if(++i>=5)break;
			}
			std::cout<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using pii = pair<int,int>; 
using db = double; 
using vi = vector<int>; 
#define fir first
#define sec second
#define pb push_back
#define lowbit(x) ((x)&(-(x))) 

const int maxn = 200006; 

vector<pii> e[maxn]; 
int n; 
ll s[maxn]; 

ll sum = 0; 
ll l; 
void dfs(int x, int f) {
	s[x] = 1; 
	ll maxs = 0; 
	for (auto i : e[x]) 
		if (i.fir != f) {
			dfs(i.fir, x); 
			s[x] += s[i.fir]; 
			sum += min(s[i.fir],n-s[i.fir]) * i.sec; 
			maxs = max(maxs, s[i.fir]); 
		}
	if (n-s[x] <= n/2 && maxs <= n/2) {
		if (maxs*2 == n) {
			for (auto i : e[x]) 
				if (i.fir != f && s[i.fir] == maxs) 
					l = min(l, (ll)i.sec); 
		}
		else if ((n-s[x])*2 == n) {
			for (auto i : e[x]) 
				if (i.fir == f) 
					l = min(l, (ll)i.sec); 
		}
		else {
			for (auto i : e[x]) 
				l = min(l, (ll)i.sec); 
		}
	} 
}
/*
ll dfs2(int x, int f) {
	set<ll> S; 
	for (auto i : e[x])
		if (i.fir != f) 
			S.insert(dfs2(i.fir, x)+i.sec); 
	if (S.size() >= 2)
		if (s[x] >= n-s[x]) 
			l = min(l, *S.begin()+*(++S.begin())); 
	else if (f == 0 && !S.empty()) l = min(l, *S.begin());
	if (S.empty()) return 0; 
	return *S.begin(); 
}*/

int main() {
	scanf( "%d", &n ); 
	l = 0x3f3f3f3f3f3f3f3fll; 
	for (int i = 1; i < n; ++i) {
		int a, b, c; 
		scanf( "%d%d%d", &a, &b, &c ); 
		e[a].pb({b,c}); 
		e[b].pb({a,c}); 
	}
	dfs(1,0); 
	//dfs2(1,0); 
	cout<<sum*2-l<<endl; 
}


Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll k;
    cin>>k;
    if(k==0){
        cout << 2<<endl<<0<<" "<<0<<endl;
        return 0;
    }
    ll m=(k-1)/50;
    ll a[50];
    a[0]=50+m;
    k%=50;
    if(k==0)k=50;
    for(ll i=1;i<50;i++){
        if(i<k){
            a[i]=a[0]-i;
        }else{
            a[i]=a[0]-i-1;
        }
    }
    cout << 50<<endl;
    for(int i=0;i<50;i++)cout << a[i]<<" ";
    cout << endl;
    return 0;
}


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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll ans = 0;
    rep(i, N) cin >> A[i];
    cout << (all_of(A.begin(), A.end(), [](ll x) { return x % 2 == 0; }) ? "second" : "first") << endl;
    return 0;
}


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

int main(){
    long long int k,a,b;
    cin >> k;
    cin >> a >> b;
    long long int br=0;
    for(int i=a;i<=b;i++){
        if(i%k==0){
            cout << "OK";
            br=1;
            break;
        }
    }
    if(br==0){
        cout << "NG";
    }
    return 0;
}

Measured memory_bytes: 3636
package main

import(
    "fmt"
    "sort"
    "strings"
)



func main() {
    var n,m,x int
    fmt.Scan(&n,&m,&x)
    mp := make(map[int]int)
    for i:=0; i<m; i++{
        var a int
        fmt.Scan(&a)
        mp[a]++
    }
    ans := 10000000
    sum := 0
    for i:=x; i<=n; i++{
        if mp[i] > 0{
            sum++
        }
    }
    ans = min32(ans,sum)
    sum = 0
    for i:=x; i>=0; i--{
        if mp[i] > 0{
            sum++
        }
    }
    ans = min32(ans,sum)
    fmt.Println(ans)
}





// Pairsort
type Pair struct {
    first,second int64
}

type By func(p1, p2 *Pair) bool

func (by By) Sort(pairs []Pair) {
    ps := &pairSorter{
            pairs : pairs,
            by: by,
    }
    sort.Sort(ps)
}

type pairSorter struct {
    pairs []Pair
    by func(p1, p2 *Pair) bool
}

func (s *pairSorter) Len() int {
    return len(s.pairs)
}

func (s *pairSorter) Swap(i, j int) {
    s.pairs[i], s.pairs[j] = s.pairs[j], s.pairs[i]
}

func (s *pairSorter) Less(i, j int) bool {
    return s.by(&s.pairs[i], &s.pairs[j])
}

func first (p1, p2 *Pair) bool {
        return p1.first < p2.first
}

func second (p1, p2 *Pair) bool {
        return p1.second < p2.second
}
// end



func abs32(a int) int {
    if a<0{
        return -a
    }
    return a
}

func abs64(a int64) int64 {
    if a<0{
        return -a
    }
    return a
}

func min32(a, b int) int {
    if a >= b {
        return b
    }
    return a
}

func max32(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func min64(a, b int64) int64 {
    if a >= b {
        return b
    }
    return a
}

func max64(a, b int64) int64 {
    if a >= b {
        return a
    }
    return b
}

func gcd(a, b int64) int64 {
    if a % b == 0 {
        return b
    } else {
        return gcd(b, a%b)
    }
}

func lcm(a, b int64) int64 {
    return a / gcd(a, b) * b
}

func scanNums(len int) (nums []int){
    var num int
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanNums64(len int) (nums []int64){
    var num int64
    for i:=0; i<len; i++{
        fmt.Scan(&num)
        nums = append(nums,num)
    }
    return
}

func scanString(len int) (str []string){
    var s string
    for i:=0; i<len; i++{
        fmt.Scan(&s)
        str = append(str,s)
    }
    return
}

func scanTwoNums(n,m int) ([][]int){
    Nums := make([][]int, n)
    for i:=0; i<n; i++{
        Nums[i] = make([]int, m)
    }
    return Nums
}

func SortString(s string) string{
    t := strings.Split(s, "")
    sort.Strings(t)
    return strings.Join(t, "")
}


Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
using ll = long long;
int main()
{
    string s;
    cin >> s;
    bool flag = true;
    for(int i = 0;i < s.size() / 2;i++)
    {
        if(s[i] != s[s.size() - 1 - i])
        {
            flag = false;
            break;
        }
    }
    string t = s.substr(0,(s.size() - 1) / 2);
    int l = (s.size() + 2) / 2,r = s.size() - 1;
    string u = s.substr(l,r - l + 1);
    for(int i = 0;i < t.size() / 2;i++)
    {
        if(t[i] != t[t.size() - 1 - i])
        {
            flag = false;
            break;
        }
    }
    for(int i = 0;i < t.size() / 2;i++)
    {
        if(u[i] != u[u.size() - 1 - i])
        {
            flag = false;
            break;
        }
    }
    if(flag)
    {
        cout << "Yes\n";
    }
    else
    {
        cout << "No\n";
    }
    
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math/rand"
	"os"
	"strconv"
)

var MIN int = 0

var sc = bufio.NewScanner(os.Stdin)

var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }

type Node struct {
	key, pri    int
	left, rigth *Node
}

func next() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i

}

func rigthRotate(t *Node) *Node {
	s := t.left
	t.left = s.rigth
	s.rigth = t
	return s
}

func leftRotate(t *Node) *Node {
	s := t.rigth
	t.rigth = s.left
	s.left = t
	return s
}

func insert(t *Node, key int, pri int) *Node {
	if t == nil {
		return &Node{key: key, pri: pri}
	}
	if key == t.key {
		return t
	}
	if t.key > key {

		t.left = insert(t.left, key, pri)
		if t.pri < t.left.pri {
			t = rigthRotate(t)
		}
	} else {
		t.rigth = insert(t.rigth, key, pri)
		if t.pri < t.rigth.pri {
			t = leftRotate(t)
		}

	}
	return t
}

func find(t *Node, key int) bool {
	if t == nil {
		return false
	}

	if t.key == key {
		return true
	}

	if t.key > key {
		return find(t.left, key)

	} else if t.key < key {
		return find(t.rigth, key)

	}
	panic("error")
}

func erase(t *Node, key int) *Node {
	if t == nil {
		return nil
	}
	if key == t.key {
		if t.left == nil && t.rigth == nil {
			return nil

		} else if t.left == nil {
			t = leftRotate(t)
		} else if t.rigth == nil {
			t = rigthRotate(t)

		} else {
			if t.left.pri > t.rigth.pri {
				t = rigthRotate(t)

			} else {

				t = leftRotate(t)

			}

		}
		return erase(t, key)

	}
	if key < t.key {
		t.left = erase(t.left, key)

	} else {
		t.rigth = erase(t.rigth, key)

	}
	return t
}

func getMin(t *Node) int {
	if t.left != nil {
		return getMin(t.left)
	}
	return t.key

}

func main() {
    	defer writer.Flush()

	sc.Split(bufio.ScanWords)

	var head *Node

	N, L := next(), next()

	items := make([]int, N)
	memo := make(map[int]int, N)

	for i := 0; i < N; i++ {
		items[i] = next()
	}

	for j := 0; j < L-1; j++ {
		head = insert(head, items[j], rand.Int())
		memo[items[j]] += 1
	}

	for i := L - 1; i < N; i++ {
		head = insert(head, items[i], rand.Int())
		memo[items[i]] += 1
		if i == N-1 {
			printf("%d\n", getMin(head))
		} else {
			printf("%d ", getMin(head))

		}

		r, ok := memo[items[i-L+1]]
		if ok {
			if r <= 1 {
				head = erase(head, items[i-L+1])
			}
			memo[items[i-L+1]] -= 1
		}
	}
}




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

int main(){
    int H,A;
    cin >> H >> A;
    int ans;
    ans = H/A;
    int amari = H%A;
    if ( amari != 0 ){
        cout << ans + 1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
from sys import exit
# A,B,C = [int(n) for n in input().split()]
# N = int(input())
# a = [int(input()) for _ in range(N)]
S = str(input())
# L = len(S)
# T = str(input())
if S == "A":
    print("T")
elif S == "T":
    print("A")
elif S == "G":
    print("C")
elif S == "C":
    print("G")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <numeric>

using namespace std;

#define int long long
typedef long double ld;
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<vi>
#define viii vector<vii>
#define vpii vector<pii>
#define vb vector<bool>
#define vbb vector<vb>
#define vs vector<string>
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define in(a, x) for (int i = x; i < (a).size(); ++i) cin >> (a)[i]
#define out(a) for (auto qwe : a) cout << qwe << " "

const int INF = 1e9;
const int INF64 = 1e18;
const int MOD = 1e9 + 7;
const int MOD9 = 1e9 + 9;
const int MOD3 = 998244353;
const int P = 37;

const int mxn = 300;

vii dp;
vi a;

void f(int l, int r) {
    if (dp[l][r] != -INF || l > r) return;

    f(l + 1, r);
    f(l, r - 1);

    dp[l][r] = max(a[l] - dp[l + 1][r], a[r] - dp[l][r - 1]);
}

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

    int n;
    cin >> n;

    a.resize(n + 1);
    in(a, 1);

    dp.assign(n + 1, vi(n + 1, -INF));

    for (int j = 1; j <= n; ++j) {
        dp[j][j] = a[j];
    }

    f(1, n);

    cout << dp[1][n];
}

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

int a[505][505];
vector<vector<int>> actions;

void moveCoin(int y, int x, int dy, int dx) {
    a[y][x]--;
    a[dy][dx]++;
    actions.push_back({y + 1, x + 1, dy + 1, dx + 1});
}

int main() {
    int h, w;
    cin >> h >> w;
    rep(y, h) rep(x, w) cin >> a[y][x];

    int ans = 0;
    rep(y, h) rep(x, w) {
        if (a[y][x] % 2 == 0 || (y == h - 1 && x == w - 1)) continue;

        int dy = y + 1, dx = x + 1;
        if (dx < w && a[y][dx] % 2 == 1)
            moveCoin(y, x, y, dx);
        else if (dy < h && a[dy][x] % 2 == 1)
            moveCoin(y, x, dy, x);
        else if (dx < w)
            moveCoin(y, x, y, dx);
        else if (dy < h)
            moveCoin(y, x, dy, x);

        ans++;
    }

    cout << ans << endl;
    for (auto e : actions) {
        rep(i, 3) cout << e[i] << ' ';
        cout << e[3] << endl;
    }
    return 0;
}


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

#define mp make_pair
#define pb push_back
#define fst first
#define snd second
#define int long long
#define MMAX 16384
#define fast_io() ios::sync_with_stdio(false)
#define FOR(i, l, r) for(int i = (l); i < (r); i++)

typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef set<int> si;
typedef double ld;
typedef pair<ld, ld> dd;

const ll INF = 1000000000000000000LL;
const int NMAX = 1e6+4;
const int mod = 1e9+7;
const ld eps = 1e-10;
const ld PI = acos(-1);

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

signed main(){
    fast_io();
    int T;
    cin >> T;
    FOR(_,0,T){
        int A, B, C, D;
        cin >> A >> B >> C >> D;
        int g = gcd(B, D);
        int c = C - C%g;
        int a = c + A%g;
        if(a <= C) a += g;
        if(D < B || A < B) {cout << "No" << endl; continue;}
        if(a < B) cout << "No" << endl;
        else cout << "Yes" << endl; 
    }
}

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

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

int main() {
  int a,n,b,h,w,k,f=0,ans=0;
  string word;
  bool flag=false;
  cin>>a;
  rep(i,50000){
    if ((int)((i+1)*1.08)==a){cout<<i+1<<endl;flag=true;break;}
    //else if((int)((i+1)*1.08)>a){break;}
  }
  if(!flag){cout<<":("<<endl;}
  vector<vector<int>> sss(h,vector<int>(w));
  //vector<int> a(k),b(k);
  char x;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()[:-1]
    if S[2:3] == S[3:4] and S[4:5] == S[5:6]:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()

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

int main(){

    int n=3;
    vector<int> A(n);
    for (int i = 0; i < n;i++){
        cin >> A[i];
    }
	sort(A.begin(),A.end());
	int min = A[0]+A[1];

	cout <<min  <<endl;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<bitset>
#include<deque>
#include<iterator>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include <cmath>
#include<vector>
using namespace std;
#define pb push_back
#define pf push_front
#define M 1000000007
#define ll long long int
int main()
 {
 	 
     ll n,i;
     cin>>n;
     ll arr[n+1]={0};
     ll brr[n];
     for(i=0;i<n;i++)
     	cin>>brr[i];
     for(i=0;i<n-1;i++)
     {
     	arr[brr[i]-1]++;
     }
     for(i=0;i<n;i++)
         cout<<arr[i]<<endl;
     return 0;
 }


Measured memory_bytes: 6748
#include<stdio.h>
int main()
{
    long int N,digit,temp,Sum=0,S;
    scanf("%Id",&N);
    temp = N;
    while(temp>0)
    {
        digit = temp%10;
        Sum = Sum + digit;
        temp/=10;

    }
    S = Sum;
     if(N%S==0)
            printf("Yes\n");
    else
           printf("No\n");


    return 0;

}


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

static const ll MOD = 1e9 + 7;

int main(){
    int N; cin >> N;
    vector<ll> key;
    vector<int> cnt(3, 0);
    for(int i = 0; i < N;i++){
        ll a;cin >> a;
        bool flag = 1;
        int num;
        for(int j = 0; j < key.size(); j++){
            if(key[j] == a){
                num = j;
                flag = 0;
                break;
            }
        }
        if(flag){
            num = key.size();
            key.push_back(a);
        }
        if(key.size() > 3){
            cout << "No\n";
            return 0;
        }
        cnt[num]++;
    }
    if(key.size() == 1){
        if(key[0] == 0) cout << "Yes\n";
        else cout << "No\n";
    }else if(key.size() == 2){//2つの場合はどっちかが0
        if(key[0] == 0){
            if(cnt[0] * 2 == cnt[1]){
                cout << "Yes\n";
            }else{
                cout << "No\n";
            }
        }else if(key[1] == 0){
            if(cnt[1] * 2 == cnt[0]){
                cout << "Yes\n";
            }else{
                cout << "No\n";
            }
        }else{
            cout << "No\n";
        }
    }else{//3つの場合全てが同じ数
        ll t = key[0]^key[1]^key[2];
        if(t== 0 && cnt[0] == cnt[1] && cnt[1] == cnt[2]){
            cout << "Yes\n";
        }else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 256
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

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


long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

const int N = 2222;

bitset<N*N> dp;

int a[N];

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
	int n = readInt();
	dp[0] = 1;
	int sum = 0;
	for (int i = 1; i <= n; i++) {							
		int x = readInt();
		sum += x;
		dp |= (dp << x);
	}
	int ans = (sum + 1) / 2;
	while(!dp[ans]) ans++;
	cout << ans;
	return 0;
}

Measured memory_bytes: 2176
x1, y1, x2, y2 =map(int,input().split())
x3 = x2 - (y2 - y1)
y3 = y2 + (x2 - x1)
x4 = x1 - (y2 - y1)
y4 = y1 + (x2 - x1)
print('%d %d %d %d'%(x3,y3,x4,y4))

Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(b==0){
		cout<<0<<endl;
		return 0;
	}
	if(b==100)b++;
	cout<<b;
	while(a--)cout<<"00";
	cout<<endl;
	return 0;
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define forn(low,high,i) for(i = low;i < high;i++)
#define forrev(high,low,i) for(i = high; i >= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define line cout << __LINE__;
#define prv(a) for(auto x : a) cout << x << ' ';cout << '\n';
#define decimal_digits cout << fixed << setprecision(15);
#define dbg2(a,b) cerr << #a << " = " << a << " " << #b << " = " << b << '\n';        
#define debug(x) cerr << __LINE__ << ' ' << #x << " = " << x << '\n';
#define dln cerr << '\n';
#define dsp cerr << ' ';
#define pln cout << '\n';
#define psp cout << ' ';

typedef unordered_map<int,int> umi;
typedef unordered_map<ll,ll> uml;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;


clock_t time_p = clock();

void ktj(){
  time_p = clock() - time_p;
  cerr << "Time elapsed : " << (float)(time_p)/CLOCKS_PER_SEC << "\n";
}

int main(){
  fastio

  ll n,i,j,k;
  cin >> n;
  vl a(n + 1), b(n + 1);
  ll sum = 0;
  forn(1,n + 1,i){
    cin >> a[i];
    sum += a[i];
  }

  sum /= 2;

  for(i = 2; i <= n - 1; i += 2){
    sum -= a[i];
  }

  b[1] = sum;

  forn(1,n,i){
    b[i + 1] = a[i] - b[i];
  }

  forn(1,n + 1,i){
    cout << 2 * b[i] << ' ';
  }
  cout << '\n';

  ktj();
}


Measured memory_bytes: 2944
N = int(input())
H = list(map(int,input().split()))
for i in range(N-1,0,-1):
    if H[i-1]>H[i] and abs(H[i-1]-H[i])>1:
        print("No")
        exit()
    elif H[i-1]>=H[i] and H[i-1]-H[i]>0:
        H[i-1] -=1
    elif H[i-1]<=H[i]:
        continue
print("Yes")


Measured memory_bytes: 14396
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main(){
    int n, sum=0;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a.at(i);
        if(a.at(i) % 2 == 1)sum++;
    }
    if(sum % 2 == 0)cout << "YES";
    else cout << "NO";
}


Measured memory_bytes: 640
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;
set<char> st;

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

  cin >> s;
  n = Size(s);
  rep(i, n) st.insert(s[i]);
  if (Size(st) == n)
    Cout("yes");
  else
    Cout("no");
  return 0;
}

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

x = dict()
for i in range(N):
    if A[i] in x:
        x[A[i]] += 1
    else:
        x[A[i]] = 1

m=0
m2 = 0
flag = False
tmp=0
for idx in x:
    tmp=m
    if x[idx]>=2:
        m=max(m,idx)
        if m!=tmp:
            if x[idx]>=4:
                flag=True
            else:
                flag=False


for idx in x:
    if x[idx]>=2:
        if idx!=m:
            m2 = max(m2,idx)

if flag:
    ans = m**2
else:
    ans = m*m2
print(ans)

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

Measured memory_bytes: 1852
#include <bits/stdc++.h>
#include<string.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(i=s;i<e;i++)
#define rf(i,s,e) for(i=s-1;i>=e;i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int   long long
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define vl vector<long long>
#define inf (1LL<<61)
#define vi vector<int> 
#define vii vector< vector<int> >
#define vll vector< vector<long long> >
#define vpi vector< pair<int,int> >   
#define vpl vector< pair<ll,ll> >   
#define viii vector< vector<vector<int> > >
typedef pair<pair<int, int>,int> P;
#define mod %1000000007
#define pi 3.14159265358979323846//20 decimals
#define ld long double

bool comp(pair<int,int> p1,pair<int,int> p2)
{
    if(p1.ff!=p2.ff)
        return p1.ff<p2.ff;
    else
        return p1.ss<p2.ss;
}

int32_t main()
{                
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif*/
    string s;int w;
    cin>>s>>w;
    string ans="";
    for(int i=0;i<s.length();i+=w)
    {
        ans+=s[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
num = int(input())
num_list = [int(i) for i in input().split()]
count = 1
Flag = True

while True:
    for i in range(num):
        if num_list[i] % (2 ** count) != 0:
            Flag = False
            break
    if Flag == False:
        break
    count += 1

print(count - 1)

Measured memory_bytes: 3188
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100

int main(){
  int x[N];
  char s[N];
  int top=0;
  
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      x[top-2] = x[top-2] + x[top-1];
	top--;
   
      
    } else if ( s[0] == '-' ){
      x[top-2] = x[top-2] - x[top-1];
      top--;
      
    } else if ( s[0] == '*' ){
      x[top-2] = x[top-2] * x[top-1];
      top--;

      
    } else {
      x[top] = atoi(s);
      top++;
      
    }
  }
  printf("%d\n",x[top-1]);      
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i< (n); i++)
int main(){
long long int h=0, w=0;
cin >> h >> w;
if (w==1 || h==1) cout << 1 << endl;
else if (h%2==0) cout << (h*w)/2 << endl;
else if (w%2==0) cout << (h*w)/2 << endl;
else cout << h*(w-1)/2 + (h+1)/2 << endl;


}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    int mini = n + 1;
    int odp = 0;
    for (int i = 0; i < n; ++i)
    {
        int p;
        cin >> p;
        mini = min(mini, p);
        if (p == mini)
            ++odp;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 3005;
const int mod = 998244353;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll dp[maxn][maxn],cnt[maxn][maxn];
int a[maxn];
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i = 1;i <= n;++i)scanf("%d",&a[i]);
    ll ans = 0;
    for(int i = 1;i <= n;++i)
    {
        for(int j = 0;j <= m;++j)
        {
            cnt[i][j]=cnt[i-1][j];
            if(j>=a[i]){
                cnt[i][j]+=cnt[i-1][j-a[i]];
                cnt[i][j]%=mod;
                dp[i][j]=cnt[i-1][j-a[i]];
            }
        }
        cnt[i][a[i]]+=i;
        cnt[i][a[i]]%=mod;
        dp[i][a[i]]=(dp[i][a[i]]+i)%mod;
        ans=(ans+1ll*(n-i+1)*(dp[i][m]))%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 141184
// Aizu 2832 All Japan Association of Return home
// 2017.11.25 bal4u@uu

#include <stdio.h>

typedef long long ll;

char buf[20], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, d, t, f, t0, f0, dt, df, num;
	ll ans;

	fgets(p=buf, 20, stdin), n = getint(), p++, d = getint();

	ans = 0, t0 = 0, f0 = 0, num = 0;
	while (n--) {
		fgets(p=buf, 20, stdin),  t = getint(), p++, f = getint()-1;
		df = f - f0; if (df < 0) df = -df;
		dt = t - t0;
		if (dt < df) goto na;
		if (dt >= f0 + f) {
			ans += (ll)num * f0;
			num = 0;
		} else {
			if (num + 1 > d) goto na;
			ans += (ll)num * dt;
		}
		f0 = f, t0 = t, num++;
	}
	ans += (ll)num * f0;
	printf("%lld\n", ans);
	return 0;
na:	puts("-1");
	return 0;
}

Measured memory_bytes: 1820
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
using namespace std;
typedef long long int ll;
using ull = unsigned long long;


mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}

int last[26];
int c[26];
int s[365][26];
int a[365];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int d; cin >> d;
    for(int i=0;i<26;i++){
    	cin >> c[i];
    }
    for(int i=0;i<d;i++){
    	for(int j=0;j<26;j++){
    		cin >> s[i][j];
    	}
    }
    for(int i=0;i<d;i++){
    	int mx=0;
    	int id=0;
    	for(int j=0;j<26;j++){
    		if(mx<(i+1-last[j])*c[j]+s[i][j]){
    			mx=(i+1-last[j])*c[j]+s[i][j];
    			id=j;
    		}
    	}
    	a[i]=id+1;
    	last[id]=i+1;
    }
    for(int i=0;i<26;i++){
    	last[i]=0;
    }
    int res=0;
    for(int i=0;i<d;i++){
    	res+=s[i][a[i]-1];
    	last[a[i]-1]=i+1;
    	for(int j=0;j<26;j++){
    		res-=c[j]*(i+1-last[j]);
    	}
    }
    for(int i=0;i<1e6;i++){
    	int day,qq;
    	day=myRand(d)+1;
    	qq=myRand(26)+1;
    	int resres=res;
    	int qqq=a[day-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres+=c[qq-1]*(i+1-last[qq-1]);
            resres+=c[qqq-1]*(i+1-last[qqq-1]);
        }
        a[day-1]=qq;
        resres-=s[day-1][qqq-1];
        resres+=s[day-1][qq-1];
        last[qq-1]=last[qqq-1]=0;
        for(int i=0;i<d;i++){
            if(a[i]==qq){
                last[a[i]-1]=i+1;
            }
            if(a[i]==qqq){
                last[a[i]-1]=i+1;
            }
            resres-=c[qq-1]*(i+1-last[qq-1]);
            resres-=c[qqq-1]*(i+1-last[qqq-1]);
		}
		if(resres>=res){

		}
		else{
			a[day-1]=qqq;
		}
    }
    for(int i=0;i<d;i++){
    	printf("%d\n",a[i]);
    }
}



Measured memory_bytes: 3820
#include<stdio.h>

int main(){
  int n;
  while(scanf("%d",&n), n){
    int i, k, num[4000], flag=0;
    long unitPrice[4000], saleQuantity[4000], earning[4000]={0};
    for(i=0; i<n; i++){
      scanf("%d%ld%ld", &num[i], &unitPrice[i], &saleQuantity[i]);
      earning[i] = unitPrice[i]*saleQuantity[i];
      for(k=0; k<i; k++){
        if(num[i] == num[k]){
          earning[k] = earning[i] + earning[k];
          earning[i] = 0;
        }
      }
    }

    for(i=0; i<n; i++){
      if(earning[i]>=1000000){
        printf("%d\n", num[i]);
	flag+=1;
      }
    }
    if(flag == 0){
      printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 684
#include<bits/stdc++.h>
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i+=1)
#define reps(i,a,b) for(int i=a;i>=b;i-=1)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pi pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define in1(x) int x; cin>>x;
#define in2(x, y) int x, y; cin>>x>>y;
#define in3(x, y, z) int x, y, z; cin>>x>>y>>z;
#define in4(x, y, z, w) int x, y, z, w; cin>>x>>y>>z>>w;
#define mi unordered_map<int,int>
#define mem(x) memset(x, 0, sizeof(x))
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
using namespace std;

//bool primes[1000001];vi prime;
//void seive(){memset(primes, true, sizeof(primes));primes[0] = primes[1] = false;for(int i = 2; i*i<=1000000;i += 1){
//if(primes[i]){for(int j = i*i; j <= 1000000;j += i) primes[j] = false;}}rep(i, 2, 1000001){if(primes[i]) prime.pb(i);}}

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

int32_t main(void){
	IOS;
	
	long double a, b;
	cin>>a>>b;
	cout<<(int)(a*b)<<endl;
	
}


Measured memory_bytes: 3764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct data
{
    ll val[32];
    ll ind[32];
    data()
    {
        ;
    }
};
ll a[200009];
data arr[200009];
vector<pair<ll,ll> > v;
ll sol(ll n)
{

    return (n*(n+1))/2;
}
int main()
{
    ll i,j,n,x,k,y,lo,hi;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    if(n==1)
    {
        cout<<1<<endl;
        return 0;
    }
    data p;
    lo = hi = 0;
    for(i=0;i<n;i++)
    {
        j = 0;
        x = a[i];
        while(a[i]!=0)
        {
            arr[i].val[j] = a[i]%2;
            a[i] = a[i]/2;
            j++;
        }
        a[i] = x;
    }

    for(i=0;i<32;i++)
    {
        p.val[i] = arr[0].val[i];
        p.ind[i] = 0;
    }
    ll ans= 0;
    for(i=1;i<n;i++)
    {
        /*for(j=31;j>=0;j--)
            cout<<p.val[j];
        cout<<endl;
        for(j=31;j>=0;j--)
            cout<<arr[i].val[j];
        cout<<"val i =  "<<a[i]<<endl;*/
        hi = i;
        //cout<<lo<<" "<<hi<<" "<<ans<<endl;
        x = -1;
        for(j=0;j<32;j++)
        {
            if(p.val[j]==1 && arr[i].val[j]==1)
            {

                x = max(x,p.ind[j]);
            }
        }
        //cout<<"x = "<<x<<endl;
        if(x!=-1)
        {
            //cout<<" ans = "<<ans<< " "<<sol(hi-lo)<<endl;
            v.push_back(make_pair(lo,hi-1));
            //cout<<"now ans = "<<ans<<endl;
            lo = x+1;
            for(j=0;j<32;j++)
            {
                if(p.ind[j]<=x)
                {
                    p.val[j] = 0;
                    p.ind[j] = 0;
                }
            }
        }
        /*cout<<"After"<<endl;
        for(j=31;j>=0;j--)
            cout<<p.val[j];
        cout<<endl;
        /*for(j=31;j>=0;j--)
            cout<<p.ind[j];
        cout<<"ind "<<endl;*/
        for(j=0;j<32;j++)
        {
            if(arr[i].val[j]==1)
            {
                p.val[j] = 1;
                p.ind[j] = i;
            }

        }

    }
    //cout<<lo<<" "<<hi<<" "<<ans<<endl;
    //ans+= sol(hi-lo+1);
    v.push_back(make_pair(lo,hi));
    for(j=1;j<v.size();j++)
    {
        if(v[j].first<=v[j-1].second)
        {
            ans-= sol(v[j-1].second-v[j].first+1);
        }
    }
    //cout<<ans<<endl;
    for(j=0;j<v.size();j++)
    {
        ans+= sol(v[j].second-v[j].first+1);
    }

    cout<<ans<<endl;


}


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

using namespace std;

int main(){
  
  int k;
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2] >> k;
  sort(v.begin(),v.end(),greater<int>());
  for(int i = 0;i < k;i++)v[0] *= 2;
  cout << v[0] + v[1] + v[2] << endl;
    
  
  
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
#include <functional>
#include <cctype>

using namespace std;

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

int n, m;
vector<int> a;
vector<int> pos;
vector<int> b;
vector<char> ID;
int k;

inline int ev(int a) {
	return a / 10 + a % 10;
}

int calc()
{
	int sum = 0;
	REP(i, pos.size()) {
		if((n - pos[i])%2 != 0)
			sum += b[pos[i]];
		else
			sum += ev(2 * b[pos[i]]);
	}
	// cout  << k + sum << endl;
	return k + sum;
}

int dfs(const int d)
{
	if(d == pos.size()) {
		return (calc()%10 == 0)? 1 : 0;
	}
	int c = 0;
	REP(j, m) {
		b[pos[d]] = a[j];
		c += dfs(d + 1);
	}
	return c;
}

int main()
{
	// 入力
	cin >> n;
	ID.reserve(n);
	b.reserve(n);
	REP(i, n) {
		cin >> ID[i];
		if(ID[i] == '*') {
			pos.push_back(i);
		}
		else b[i] = ID[i] - '0';
		if((n - i)%2 != 0) k += b[i];
		else k += ev(2 * b[i]);
	}
	cin	>> m;
	a.reserve(m);
	REP(i, m)
		cin >> a[i];

	cout << dfs(0) << endl;

	return 0;
}

Measured memory_bytes: 1536
program sample
    implicit none
    character(100)::s
    integer(8) :: i,j,m,n,k
    integer(8),allocatable :: x(:),y(:)
  
    read(*,*) n
    allocate(x(n))
    read(*,*)x
    call msort(x)
    m=0
    do i=1,n-2
        do j=i+1,n-1
            do k=j+1,n
                if(x(i)+x(j)>x(k) .and. x(i)/=x(j) .and. x(j)/=x(k))then
                    m=m+1
                end if
            end do
        end do
    end do
    write(*,*)m
  
    stop
    contains
    recursive subroutine msort(x)
    implicit none
    integer(8), intent(inout) :: x(:)
 
    integer(8) :: n, mid, i, j, k
    integer(8), allocatable :: tmp(:)
    
    n = size(x)
    
    if(n == 1) then
      return
    end if
 
    !
    ! 前半と後半に分けてソート
    ! 1~midとmid+1~nをそれぞれソート済みにする
    !
    mid = n / 2
    call msort(x(:mid))
    call msort(x(mid+1:))
 
    !
    ! tmpという配列にxを一時的に保管
    ! マージソートは外部ソート
    !
    allocate(tmp(n))
    tmp = x
 
    ! tmpの後半部分を左右反転
    do k = n, mid+1, -1
      tmp(k) = x(mid + n - k + 1)
    end do
 
    ! iは前半のリストのうちまだ見ていないものの最小値
    ! jは後半のリストのうちまだ見ていないものの最小値
    ! kは見た回数の合計
    i = 1
    j = n
 
    do k = 1, n
      !
      ! 一番左と一番右のうち小さい方をxに入れていく
      ! ここが等号つき不等号なので、安定ソートとなる
      !
      if(tmp(i) <= tmp(j)) then
        x(k) = tmp(i)
        i = i + 1
      else
        x(k) = tmp(j)
        j = j - 1
      end if
    end do
    
    deallocate(tmp)
    return
  end subroutine msort
end program sample
  



Measured memory_bytes: 2808
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vll(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

ll sum(ll n)
{
	return n*(n+1)/2;
}

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		ll n;
		sll(n);
		ll ans = 0;
		for (int i=1 ; i<=n ; i++)
		{
			ans+=i*sum(n/i);
		}
		cout << ans << endl;
		return 0;
}







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

using namespace std;

typedef long long int li;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

vi par,sz,vis,dis;
vector<vi> graph;
vector<vector<pair<li,li>>> wgraph;

void init(li n)
{
    par.resize(n);
    sz.resize(n);
    wgraph.resize(n);
    dis.resize(n);
    vis.resize(n);
    graph.resize(n);

    f(i,0,n-1)
    {
        par[i]=i;
        sz[i]=1;
        dis[i]=INT_MAX;
    }
}

li root(li a)
{
    while(a!=par[a])
    {
        par[a]=par[par[a]];
        a=par[a];
    }

    return a;
}

void unio(li a,li b)
{
    li r_a=root(a);
    li r_b=root(b);

    if(par[r_a]!=r_b)
    { 
        if(sz[r_a]<sz[r_b])
        {
            par[r_a]=par[r_b];
            sz[r_b]+=sz[r_a];
            sz[r_a]=0;
        }
        else
        {
            par[r_b]=par[r_a];
            sz[r_a]+=sz[r_b];
            sz[r_b]=0;
        }
    }
}

void dijkstra(li start)
{
    dis[start]=0;

    multiset<pair<li,li>> s;

    s.insert({0,start});

    while(!s.empty())
    {
        pair<li,li> tp=*s.B;
        s.erase(s.begin());

        li p=tp.S;

        if(!vis[p]) 
        {
            vis[p]=1;

            for(pair<li,li> v:wgraph[p])
            {
                if(dis[p]+v.S<dis[v.F])
                {
                    dis[v.F]=dis[p]+v.S;
                    s.insert({dis[v.F],v.F});
                }
            }
        }
    }
}

int main()
{    
    

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li a,b;

    cin>>a>>b;

    if(a%b)
        cout<<a/b+1;
    else
        cout<<a/b;

    return 0;
}

Measured memory_bytes: 256
use std::io;

fn main() {
    let input = input_number();
    let r = input[0] as usize;
    let c = input[1] as usize;
    let mut rc: Vec<Vec<i64>> = vec![];
    for _ in 0..r {
        rc.push(input_number());
    }

    for i in 0..r {
        for j in 0..c {
            print!("{} ", rc[i][j]);
            if j == c - 1 {
                let sum = rc[i].iter().fold(0, |sum, j| sum + j);
                print!("{}", sum);
            }
        }
        println!("");
    }
    let mut allsum = 0;
    for i in 0..c {
        let sum = (0..r).fold(0, |sum, j| sum + rc[j][i]);
        allsum += sum;
        print!("{} ", sum);
    }
    print!("{}", allsum);
    println!("");
}

#[allow(dead_code)]
fn input_number() -> Vec<i64> {
    let mut input = String::new();
    io::stdin()
        .read_line(&mut input)
        .expect("Failed to read line");
    let vec: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse().unwrap_or(0))
        .collect();
    vec
}

#[allow(dead_code)]
fn input() -> (char, usize) {
    let mut s = String::new();
    io::stdin().read_line(&mut s).expect("");
    let mut iter = s.trim().split_whitespace();
    let c: char = iter.next().unwrap().chars().nth(0).unwrap();
    let n: usize = iter.next().unwrap().parse().unwrap();
    (c, n)
}



Measured memory_bytes: 5052
sentence = input()
N = int(sentence)
sentence = input()
a_str = sentence.split()
a_list = [int(a) for a in a_str]
sentence = input()
b_str = sentence.split()
b_list = [int(b) for b in b_str]
a_list.reverse()
b_list.reverse()
remain = a_list.pop(0)
total_number = 0
for i, b in enumerate(b_list):
    if remain >= b:
        total_number += b
        remain = a_list[i]
    else:
        total_number += remain
        b_remain = b - remain
        monster_a = a_list[i]
        if monster_a >= b_remain:
            total_number += b_remain
            remain = monster_a - b_remain
        else:
            total_number += monster_a
            remain = 0
print(total_number)


Measured memory_bytes: 27840
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstdio>
#define F(i,n) for(int i=0;i<(int)(n);i++)
#define INF 100000000
#define ll long long

using namespace std;
typedef pair<int, int> P;

bool c(int r,int f[50],int ma) {
 int g[] = { 5,7,5,7,7 };
 int d = 0;
 int q = 0;
 for (int j = r; j<ma; j++) {
  if (q == 5)return true;
  d += f[j];
  if (d == g[q]) {
   d = 0;
   q++;
   continue;
  }
  else if (d < g[q])continue;
  else return false;
 }
}
int main() {
 int n;
 int b[50];
 string a;
 while (1) {
  cin >> n;
  if (n == 0)break;
  F(i, n) {
   cin >> a;
   b[i] = a.size();
  }
  F(i, n) {
   if  (c(i,b,n)){
    cout << i + 1 << endl;
    break;
   }
  }
 }
 return 0;
}


Measured memory_bytes: 3076