akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define sz(a) ((int)(a).size())
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define trav(it, a) for(auto& it : a)
#define allin(it, a) for(auto it : a)
#define read(v, a, b) for(int i=(a); i<(b); i++) scanf("%d", &v[i]);
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define db(x) cerr << #x << " == " << x << endl

const int maxn = 1e5 + 100;

int main(){
	int n;
	scanf("%d", &n);
	vector<double> dp(n + 1);
	//dp[i] - prob of having exactly i heads
	dp[0] = 1;
	for(int coin = 0; coin < n; ++coin)
	{
		double p;
		scanf("%lf", &p);
		for (int i = coin + 1; i >= 0; i--)
		{
			dp[i] = (i == 0? 0 : dp[i-1] * p) + dp[i] * (1 - p);
		}
	}
	double answer = 0;
	for(int i = 0; i <= n/2; i++)
		answer += dp[n-i];
    printf("%.10lf\n", answer);
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
using namespace std;
int main(void) {
	int N;
	int K;
	cin >> N >> K;
	string S;
	cin >> S;
	if (S[K - 1] == 'A') {
		S[K - 1] = 'a';
	}
	else if (S[K - 1] == 'B') {
		S[K - 1] = 'b';
	}
	else if (S[K - 1] == 'C') {
		S[K - 1] = 'c';
	}
	cout << S;
}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    vector<int> a(n);
    map<int, int> mp;
    
    for (auto& x: a) {
        cin >> x;
        mp[x] = 1;
    }
    
    int cnt = 0;
    for (auto& it: mp) {
        it.second = cnt++;
//        cout << ">> " << it.first << endl;
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int diff = abs(i - mp[a[i]]);
        //cout << ">> " << i << ' ' <<  mp[a[i]] << " " << a[i] << endl;
        ans += (diff & 1);
    }
    cout << ans / 2 << endl;
    
    return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include <algorithm>
#include <functional>
#include<vector>
#include<math.h>
#include<bitset>
#include<string>
#include <deque>
#include<queue>
#include <iomanip>
#include<map>
#include <random>
#include<type_traits>
#include<stack>
#include <sstream> 
#include <limits>
#include <numeric>
#include<string.h>
using namespace std;
#define ll long long int
#define all(v) begin(v), end(v)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
//typedef vector<int> V;
//typedef vector<V> VV;
//typedef vector<VV> VVV;
using namespace std;
int tru[103];

int main() {
	int p[1000],n,m,k[1000],a,s[15][15];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> k[i];
		for (int j = 0; j < k[i]; j++) {
			cin >> a;
			s[i][j]=a-1;
		}
	}
	for (int i = 0; i < m; i++) {
		cin >> p[i];
	}
	int sum = 0;
	for (int i = 0; i< pow(2, n); i++) {
		int flag = 0,ss=0;
		for (int j = 0; j < m; j++) {
			int c = 0;
			for (int l = 0; l < k[j]; l++) {
				if (i & (1 << s[j][l])) {
					c++;
				}
			}
			if (c % 2 == p[j])ss++;
		}
		if (ss==m) {
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main()
{
	
	int N, Q;
	string S;
	
	cin >> N >> Q;
	cin >> S;
	
	int l[Q], r[Q];
	
	ll ans;
	for(int i=0; i<Q; ++i)
		cin >> l[i] >> r[i];
	
	vector<int> vec(N);
	int count = 0;
	for(int i=0; i<N-1; ++i)
    {
		if(S[i] == 'A' && S[i+1] == 'C')
        {
			count++;
			vec[i] = count;
		}
		else
			vec[i] = count;
	}
	
	vec[N-1] = count;
	
	for(int i=0; i<Q; ++i)
		cout << vec[r[i]-2] - vec[l[i]-2] << endl;
	
	return 0;
}


Measured memory_bytes: 2176
defmodule Main do
  def main do
    [n, _m, x] =
      IO.read(:line) |> String.trim() |> String.split(" ") |> Enum.map(&String.to_integer/1)

    list_of_lists =
      Enum.reduce(1..n, [], fn _, acc ->
        IO.read(:line)
        |> String.trim()
        |> String.split(" ")
        |> Enum.map(&String.to_integer/1)
        |> List.duplicate(1)
        |> Kernel.++(acc)
      end)

    Enum.reduce(1..n, [], fn i, acc ->
      combination(list_of_lists, i) ++ acc
    end)
    |> Enum.filter(&pass?(&1, x))
    |> Enum.map(&bill/1)
    |> Enum.min(fn -> -1 end)
    |> IO.puts()
  end

  defp pass?(list_of_lists, x) do
    List.zip(list_of_lists)
    |> tl()
    |> Enum.map(&(Tuple.to_list(&1) |> Enum.sum()))
    |> Enum.all?(&(&1 >= x))
  end

  defp bill(list_of_lists) do
    List.zip(list_of_lists) |> hd() |> Tuple.to_list() |> Enum.sum()
  end

  defp combination(_, 0), do: [[]]
  defp combination([], _), do: []

  defp combination([x | xs], n) do
    for(y <- combination(xs, n - 1), do: [x | y]) ++ combination(xs, n)
  end
end

Measured memory_bytes: 32636
head=[int(n) for n in input().split()]
costList=[]

for n in range(head[0]):
    costList.append([int(n) for n in input().split()])

enableList=[]
for cost in costList:
    if cost[1] <= head[1]:
        enableList.append(cost[0])

if len(enableList) == 0:
    print("TLE")
else:
    print(min(enableList))

Measured memory_bytes: 3060
#include <stdio.h>

int main(){

  int i;
  int w[3];

  int h1,m1,s1;
  int h2,m2,s2;

  for(i=0;i<3;i++){
    scanf("%d %d %d %d %d %d",&h1,&m1,&s1,&h2,&m2,&s2);
    w[i]=(3600*h2+60*m2+s2)-(3600*h1+60*m1+s1);
  }

  for(i=0;i<3;i++){

    h1=w[i]/3600;
    m1=(w[i]-h1*3600)/60;
    s1=w[i]-h1*3600-m1*60;

    printf("%d %d %d\n",h1,m1,s1);

  }

  return 0;

}

Measured memory_bytes: 596
module AOJ_Volume0028;

import std.stdio,std.string,std.conv;

int main()
{
	int[101] count;
	int max;
	string s;

	while((s = readln.chomp).length != 0)
	{
		int value = s.to!int;
		count[value]++;
	}
	max = count[0];
	foreach(i;0..100)
	{
		if(max < count[i]) max = count[i];
	}
	foreach(i;0..100)
	{
		if(max == count[i]) writeln(i);
	}

	return 0;
}

Measured memory_bytes: 1048
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	int n;
	cin >> n;
	int a, b;
	a = n / 100;
	if (n % 5 == 0){
		b = (n % 100) / 5;
	}
	else {
		b= (n % 100) / 5+1;
	}

	if (b <= a) {
		cout << 1;
	}
	else {
		cout<<0;
	}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)


vector<LL> dp;

void dfs(LL now,string val,LL next){
    val.push_back(next + '0');
    dp.push_back(std::stol(val));
    if(now == 11)return;

    if(next == 0){
        dfs(now+1,val,0);
        dfs(now+1,val,1);        
    }
    else if(0 < next && next < 9){
        dfs(now+1,val,next-1);
        dfs(now+1,val,next);
        dfs(now+1,val,next+1);
    }
    else if(next == 9){
        dfs(now+1,val,8);
        dfs(now+1,val,9);
    }
}

int main() {
    LL K;cin >> K;
    for(LL i = 1;i <= 9;i++)dp.push_back(i);
    for(LL i = 1;i <= 8;i++){
        string tmp = std::to_string(i);
        dfs(0,tmp,i-1);
        dfs(0,tmp,i);
        dfs(0,tmp,i+1);
    }
    dfs(0,"9",8);
    dfs(0,"9",9);

    sort(all(dp));

    cout << dp[K-1] << endl;

}

Measured memory_bytes: 67808
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using II = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VII = vector<II>;
const int MOD = 1e9 + 7;
class UnionFind {
public:
  VI par, rank;
  UnionFind(int n) {
    par = VI(n); iota(par.begin(), par.end(), 0);
    rank = VI(n, 0);
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) { return; }
    if (rank[x] < rank[y]) {
      par[x] = y;
    } else {
      par[y] = x;
      if (rank[x] == rank[y]) { rank[x]++; }
    }
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int N;
int solve(const VII& A, const VII& B) {
  UnionFind uf(N);
  vector<bool> used(N);
  int ans = 0;
  int k = N - 1;
  REP (i, N) {
    while (used[k]) {
      k--;
    }
    int j = k;
    if (i < N - 1) {
      while (uf.same(A[i].second, B[j].second)) {
        j--;
      }
      used[j] = true;
      uf.unite(A[i].second, B[j].second);
    }
    ans += min(A[i].first, B[j].first);
  }
  return ans;
}
int solve2(const VII& A, const VII& B) {
  UnionFind uf(N);
  vector<bool> used(N);
  int ans = 0;
  int k = 0;
  for (int i = N - 1; i >= 0; i--) {
    while (used[k]) {
      k++;
    }
    int j = k;
    if (i > 0) {
      while (uf.same(A[i].second, B[j].second)) {
        j++;
      }
      used[j] = true;
      uf.unite(A[i].second, B[j].second);
    }
    ans += min(A[i].first, B[j].first);
  }
  return ans;
}

signed main() {
  cin >> N;
  VII A(N), B(N);
  REP (i, N) {
    cin >> A[i].first >> B[i].first;
    A[i].second = i; B[i].second = i;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  cout << min({solve(A, B), solve(B, A), solve2(A, B), solve2(B, A)}) << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int N, Q;
vector <int> nums(0);
LP table = make_pair(0, 1);

int main(){
    cin >> N >> Q;
    REP(i, N){
        int in;
        cin >> in;
        llong odd = table.first;
        llong even = table.second;
        if(in % 2 == 0){
            table.first += odd;
            table.second += even; 
        }
        else{
            table.first += even;
            table.second += odd;
        }
    }
    if( Q == 0){
        cout << table.second << endl;
    }
    else{
        cout << table.first << endl;
    }
}

Measured memory_bytes: 256
def abc142_c2():    
    n = int(input())
    a = list(map(int, input().split()))
    # ansを格納する空のリストを準備
    ans = [0] * n

    # enumerate()でインデックスと取り出してansに格納
    for val, num in enumerate(a, 1):
        ans[num - 1] = val
    # リストの前に*をつけるとアンパックされる
    print(*ans)
if __name__ ==  '__main__':
    abc142_c2()    

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

using namespace __gnu_pbds;  
using namespace std;

typedef long long ll;

typedef tree<
pair <int, int>,
null_type,
less<pair <int, int>>,
rb_tree_tag,
tree_order_statistics_node_update>
os;

double getTime() {
  return clock() / (double) CLOCKS_PER_SEC;
}

void read() {};

template<typename T, typename... Args>
void read(T& a, Args&... args) {
  cin >> a;
  read(args...);
}

void print() {};

template <typename T, typename... Args>
void print(T a, Args... args) {
  cout << a << " \n"[sizeof...(args) == 0];
  print(args...);
}

int main() {
  string s; cin >> s;
  if(s[2] == s[3] and s[4] == s[5]) {
    print("Yes");
  }
  else {
    print("No");
  }
}

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

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))   //最大値を求める
#define MIN(x) *min_element(ALL(x))   //最小値を求める
#define D()
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 10000007      //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

signed main()
{
    int K;
    string S;
    cin >> K >> S;
    if(S.length() <= K){
        cout << S;
    }else{
        cout << S.erase(K) << "...";
    }
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(){

  int n,m,i,j,p,x;
  int t[110];
  int drink[110]={0};
  int ans[110]={0};

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&t[i]);
  }

  scanf("%d",&m);
  for(i=1;i<=m;i++){
    scanf("%d %d",&p,&x);
    for(j=1;j<=n;j++){
      if(p==j){
        ans[i]+=x;
      }else{
        ans[i]+=t[j];
      }
    }
  }

  for(i=1;i<=m;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

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

using namespace std;

int main(){

    int N;cin >> N;

    vector<int> vec(N);
    int a;
    rep(i,N){
        cin >> a;vec[i] = a;
    }
    sort(vec.begin(),vec.end(),greater<int>());
//    sort(vec.rbegin(),vec.rend());
    int r = 0;
    rep(i,N){
        if (i % 2 == 0) r += vec[i];
        else r -= vec[i];
     }
     cout << r << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
typedef pair<int, int> p;
 
int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    ll ans = 0;

    for(ll bit = 0; bit < (1LL << (s.length() - 1)); bit++) {
        ll x = 0;
        for(ll i = 0; i < s.length() - 1; i++) {
            x *= 10LL;
            x += ll(s[i] - '0');
            if(bit & (1 << i)) {
                ans += x;
                x = 0;
            }
        }
        x *= 10LL;
        x += ll(s[s.length() - 1] - '0');
        ans += x;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
var
    nm,i,x:longint;
    n:string;
begin
    readln(n);
    x:=pos(' ',n);
    delete(n,x,1);
    val(n,nm);
    for i:=1 to trunc(sqrt(nm))+1 do
    if(sqr(i)=nm)then
    begin
        writeln('Yes');
        exit;
    end;
    writeln('No');
end.



Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<stdio.h>
    
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define _USE_MATH_DEFINES
#define f first
//#define s second
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define INF 1000000000000000000
#define MAXN (int)(1e7)+1
#define MOD 1000000007
    
using namespace std;
    
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pwi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vector<pair<ll,ll > > > wGraph;
typedef vector<vector<ll> > graph;
//typedef vector<vector<ll> > matrix;

    
int main(){
    
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout<<std::fixed;
    cout<<std::setprecision(2);
    
    ll X, K ,D;
    cin>>X>>K>>D;

    X = abs(X);
    ll quantos_D_termina_X = X/D;
    ll quantos_X_sobra_de_D = X%D;

    ll residuo = K-quantos_D_termina_X;

    if(K < quantos_D_termina_X) cout<<abs(X-D*K)<<endl;
    else cout<<abs(quantos_X_sobra_de_D - D*(residuo % 2 == 1))<<endl;

    return 0;   
}

Measured memory_bytes: 3612
#include <iostream>

using namespace std;
int main() {
	int N, M;
	int pow2 = 1;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		pow2 = pow2 * 2;
	}
	cout << pow2*(M * 1900 + (N - M) * 100) << "\n";
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(a) (a).begin(), (a).end()

using namespace std;

int main() {
    int N;
    cin >> N;
    int A, B;
    cin >> A >> B;

    int ok = 0;
    for (int i = 0; i <= N; i++) {
        string str = to_string(i);

        int sum = 0;
        REP(j, str.size()) { sum += str[j] - '0'; }

        if (A <= sum && sum <= B) ok += i;
    }

    cout << ok << endl;

    return 0;
}


Measured memory_bytes: 256
<?php
$a = array(0, 0, 0, 0, 0);
fscanf(STDIN, "%d %d %d %d %d", $a[0], $a[1], $a[2], $a[3], $a[4]);
rsort($a);
fprintf(STDOUT, "%d %d %d %d %d\n", $a[0], $a[1], $a[2], $a[3], $a[4]);

Measured memory_bytes: 6536
#include <cstdio>
typedef long long ll;
ll seq[1005], arr[505][505], row[505], col[505];
inline bool chk(int n)
{
	for (int i = 2; i * i <= n; i++)
	{
		if (!(n % i))
			return false;
	}
	return true;
}
inline ll gcd(ll x, ll y)
{
	while (y)
	{
		auto r = x % y;
		x = y;
		y = r;
	}
	return x;
}
inline ll lcm(ll x, ll y)
{
	if (!x || !y)
		return x + y;
	return (__int128)x * y / gcd(x, y);
}
int main()
{
	// freopen("AGC027-D.in", "r", stdin);
	int n, cnt = 0, cur = 2;
	bool flg = false;
	scanf("%d", &n);
	if (n & 1 ^ 1)
	{
		flg = true;
		n++;
	}
	while (cnt <= n * 2)
	{
		if (chk(cur))
			seq[cnt++] = cur;
		cur++;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			arr[i][j] = 1;
	}
	cur = 0;
	for (int i = 0; i < n; i += 2)
	{
		int x = i, y = 0;
		while (x < n && y < n)
			arr[x++][y++] *= seq[cur];
		cur++;
	}
	for (int i = 2; i < n; i += 2)
	{
		int x = 0, y = i;
		while (x < n && y < n)
			arr[x++][y++] *= seq[cur];
		cur++;
	}
	cur = cnt - 1;
	for (int i = 0; i < n; i += 2)
	{
		int x = i, y = 0;
		while (x >= 0 && y < n)
			arr[x--][y++] *= seq[cur];
		cur--;
	}
	for (int i = 2; i < n; i += 2)
	{
		int x = n - 1, y = i;
		while (x >= 0 && y < n)
			arr[x--][y++] *= seq[cur];
		cur--;
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i & 1 ^ 1; j < n; j += 2)
			arr[i][j] = lcm(lcm(i ? arr[i - 1][j] : 0, j ? arr[i][j - 1] : 0),
							lcm(arr[i + 1][j], arr[i][j + 1])) + 1;
	}
	if (flg)
		n--;
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < n; j++)
			printf("%lld%c", arr[i][j], " \n"[j + 1 == n]);
	}
	return 0;
}


Measured memory_bytes: 4992
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;

int main(){
int r,c;
cin >> r >> c;
int graph[r+1][c+1] ;

for(int i = 0; i<r+1; i++){
     for(int j = 0; j<c+1; j++){
          graph[i][j] = 0;
     }
}

for(int i = 0; i<r; i++){
     for(int j = 0; j<c; j++){
         cin >> graph[i][j];
     }
}
for(int i = 0; i<r; i++){
     for(int j = 0; j<c; j++){
          graph[i][c] += graph[i][j];
          graph[r][j] += graph[i][j];
          graph[r][c] += graph[i][j];
     }
}
for(int i = 0; i<r+1; i++){
     for(int j = 0; j<c+1; j++){
          if(j==c){
               cout << graph[i][j] ;
          }else{
               cout << graph[i][j] << " " ;
          }
     }cout << endl;
}
return 0;
}


Measured memory_bytes: 3116
#include<cstdio>
#include<iostream>
using namespace std;
char s[4^10];
int main(void){
	int n,x,w,u,cnt,i;
	while(1){
		cin>>n;
		if(n==-1) break;
		cnt=0;
		while(1){
			s[cnt]=n%4+'0';
			n=n/4;
			cnt++;
			if(n==0){
				cnt--;
				break;
			}
			if(n<4){
				s[cnt]=n+'0';
				break;
			}
		}
		for(i=cnt;i>=0;i--) cout<<s[i];
		cout<<endl;
	}
	return 0;
}

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

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

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

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

vector<long long> lis_and_lds(long long n, long long a, long long b) {
    assert(a + b <= n + 1 && n <= a * b);
    vector<long long> res;
    for (int i = b-1; i >= 0; --i) res.push_back(i);
    if (a == 1) return res;

    long long rem = n - b;
    long long p = rem / (a-1);
    long long r = rem % (a-1);

    long long c = r;
    long long d = a-1-r;

    for (int i = 0; i < c; ++i) {
        int sz = (int)res.size();
        for (int j = 0; j < p+1; ++j) {
            res.push_back(sz + p - j);
        }
    }
    for (int i = 0; i < d; ++i) {
        int sz = (int)res.size();
        for (int j = 0; j < p; ++j) {
            res.push_back(sz + p-1 - j);
        }
    }

    return res;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    if (a + b > n + 1 || n > a * b) {
        cout << "-1\n";
        return 0;
    }
    auto ans = lis_and_lds(n, a, b);
    rep(i, n) cout << ans[i] + 1 << (i == n-1 ? '\n' : ' ');
}


Measured memory_bytes: 7492
#include <bits/stdc++.h>
using namespace std;
struct unionFind {
	vector<int> par;
	unionFind(int n) : par(n) {
		for (int i = 0; i < n; i++) {
			par[i] = i;
		}
	}
	int root(int x) {
		if (par[x] == x)
			return x;
		else
			return par[x] = root(par[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x != y)
			par[x] = y;
		return;
	}
};
int main() {
	int n, m;
	cin >> n >> m;
	unionFind t(n);
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		t.unite(a, b);
	}
	vector<int> cnt(n, 0);
	for (int i = 0; i < n; i++) {
		cnt[t.root(i)]++;
		// cout << t.root(i) << endl;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, cnt[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 11104
a,b,c=map(int,input().split())

if a%2!=0 or b%2!=0 or c%2!=0:
  print(0)
  exit()
elif a==b==c:
  print(-1)
  exit()
    
ans=0  

while a%2==0 and b%2==0 and c%2==0:
  num_a,num_b,num_c=a/2,b/2,c/2
  a=num_b+num_c
  b=num_a+num_c
  c=num_a+num_b
  ans+=1
print(ans)


Measured memory_bytes: 9160
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define bit(n,k) (((ll)n>>(ll)k)&1) /*nのk bit目*/
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
//ll MOD=1000000007LL;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;
//const ll MAX_V=114514LL;
//const ll MAX = 500010LL;
const ll mod=MOD;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
vl dx={0,0,1,-1};
vl dy={1,-1,0,0};

//素因数分解O(√n)
map<ll,ll>prime_factor(ll n){
  map<ll,ll>res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

const ll MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
//finvが階乗の逆元

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll a, ll n, ll mod) {
  
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll N=2000010;
vl arr(N);
void Eratosthenes(){
	for(ll i = 0; i < N; i++){
		arr[i] = 1;
	}
        arr[1]=0;
	for(ll i = 2; i < sqrt(N); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) < N; j++){
				arr[i *(j + 2)] = 0;
			}
		}
	}
}
//素数判定O(√n)
bool is_prime(ll n){
  for(ll i=2;i*i<=n;i++){
    if(n%i==0)return false;
  }
  return n!=1;
}


int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  cout << fixed << setprecision(10);
  /*--------------------------------*/
  ll n;cin>>n;
  ll d;cin>>d;
  vl x(n),y(n);
  rep(i,n)cin>>x[i]>>y[i];
  ll cnt=0;
  rep(i,n){
    if(x[i]*x[i]+y[i]*y[i]<=d*d)cnt++;
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 21948
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Comparison
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  string a, b;
  cin >> a >> b;
  int an = a.size(), bn = b.size();

  if (an != bn) {
    if (an > bn) puts("GREATER");
    else puts("LESS");
    return 0;
  }

  for (int i = 0; i < an; i++)
    if (a[i] != b[i]) {
      if (a[i] > b[i]) puts("GREATER");
      else puts("LESS");
      return 0;
    }

  puts("EQUAL");
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int N, freq[1000010] = {};
	scanf("%d", &N);
	for(int i = 1; i <= N; i++){
		int temp;
		scanf("%d", &temp);
		freq[temp]++;
	}
	int ans = 0;
	for(int i = 1; i <= 1000000; i++){
		if(freq[i] == 0)
			continue;
		if(freq[i] == 1)
			ans++;
		for(int j = 2; j * i <= 1000000; j++)
				freq[j * i] = 0;
	}
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 5616
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip>
using namespace std;
#define int long long


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

    string s,t; cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end(),greater<char>());

    if(s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string> 
#include <cmath>  
#include <cstdlib>
#include <ctime>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <functional>
#include <cctype>

#define BIT(a) (1 << (a))

using namespace std;

long long MOD = 1000000007;


long long mod_pow(long long x, long long n){
    long long res = 1;
    for(int i = 0;i < 60; i++){
        if(n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

int a[105];

int main(void){
	int N;
	int D, X;
	cin >> N >> D >> X;
	long long ans = 0;
	for (int i = 0; i < N; i++){
		cin >> a[i];
	}
	for (int i = 0; i < N; i++){
		int day = 1;
		while (day <= D){
			ans++;
			day += a[i];
		}
	}

	cout << ans+X << endl;
	return 0;


}



Measured memory_bytes: 256
SA = input()
SB = input()
SC = input()
la = len(SA)
lb = len(SB)
lc = len(SC)
turn = SA[0]
ai = 0
bi = 0
ci = 0
while True:
    if turn == 'a':
        if ai == la:
            print('A')
            break
        turn = SA[ai]
        ai += 1
    elif turn == 'b':
        if bi == lb:
            print('B')
            break
        turn = SB[bi]
        bi += 1
    else:
        if ci == lc:
            print('C')
            break
        turn = SC[ci]
        ci += 1




Measured memory_bytes: 61612
// Ivan Carvalho
// Problem X - Educational Dynamic Programming Contest - AtCoder
#include <bits/stdc++.h>
using namespace std;

typedef tuple<int,int,int> trinca;
typedef long long ll;

const int MAXW = 2*1e4 + 10;

vector<trinca> guloso;
ll dp[MAXW];
int N;

int main(){

	cin >> N;
	for(int i = 1;i<=N;i++){
		int w,s,v;
		cin >> w >> s >> v;
		guloso.push_back(make_tuple(s+w,w,v));
	}

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

	for(trinca davez : guloso){
		int solid = get<0>(davez), w = get<1>(davez);
		ll v = get<2>(davez);
		for(int i = MAXW-1;i>=0;i--){
			if(i + w <= solid){
				dp[i+w] = max(dp[i+w],dp[i] + v);
			}
		}
	}

	ll best = 0;
	for(int i = 0;i<MAXW;i++) best = max(best,dp[i]);
	cout << best << endl;

	return 0;

}

Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>
int main(void)
{
    int n,x,t;
    int min;
    int mod;
    scanf("%d",&n);
    scanf("%d",&x);
    scanf("%d",&t);
    mod = n%x;
    if (mod > 0)
    {
        min = n/x*t+t;
    }
    else
    {
        min = n/x*t;
    }
    printf("%d",min);
    
}

Measured memory_bytes: 2120
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz size()
#define ll long long
#define all(_v) _v.begin(), _v.end()
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pvllvll pair <vector <ll>, vector <ll> >
#define ld long double
#define veci vector <int>
#define vecll vector <ll>


const int dx[4] = {1, -1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const double PI = 3.1415926535897932384626433832795;
const double eps = 1e-9;
const int MOD1 = 1e9 + 7;
const int MOD2 = 998244353;

ll dp[3100][3100][4];
ll a[3100][3100];
void solve() {
    int r, c, k;
    cin >> r >> c >> k;
    for(int i = 1; i <= k; ++i) {
        int u, v;
        ll x;
        cin >> u >> v >> x;
        a[u][v] = x;
    }
    for(int i = 1; i <= r; ++i) {
        for(int j = 1; j <= c; ++j) {
            ///i - 1, j
            for(int k2 = 0; k2 <= 3; ++k2) {
                dp[i][j][0] = max(dp[i][j][0], dp[i - 1][j][k2]);
                if(a[i][j])
                dp[i][j][1] = max(dp[i][j][1], dp[i - 1][j][k2] + a[i][j]);
            }
            ///i, j - 1
            for(int k = 0; k <= 3; ++k) {
                dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k]);
                if(k && a[i][j]) dp[i][j][k] = max(dp[i][j][k], dp[i][j - 1][k - 1] + a[i][j]);
            }
        }
    }
    cout << max({dp[r][c][0], dp[r][c][1], dp[r][c][2], dp[r][c][3]});
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
    ///cin >> T;
    while(T--) solve(), cout << '\n';
    return 0;
}


Measured memory_bytes: 366864
def a():
    N,M = map(int,input().split())

    SC = [0]*M
    for _ in range(M):
        S,C = map(int,input().split())
        S -= 1
        SC[_] = (S,C)

    def b(i):
        i = str(i)
        if len(i) != N:
            return 0
        for k,v in SC:
            if int(i[k]) != v:
                return 0
        return 1

    for i in range(0,1000):
        if b(i):
            return i

    return -1

print(a())




Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N,D;
    cin >> N >> D;
    vector<vector<int>> X(N,vector<int> (D));
    for(int i = 0;i<N;++i){
        for(int j = 0;j<D;++j){
            cin >> X.at(i).at(j);
        }
    }
    int num = 0;
    for(int i = 0;i<N - 1;++i){
        for(int j = i + 1;j<N;++j){
            double sum = 0,b = 0;
            for(int k = 0;k<D;++k){
                b += pow(abs(X.at(i).at(k) - X.at(j).at(k)),2);
            }
            sum = sqrt(b);
//                cout << sum << endl;
            if(floor(sum) == sum){
                ++num;
            }
        }
    }
    cout << num << endl;
}

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

int main() {
	int n; cin >> n;
	int res;
	if (n < 10) {
		res = n;
	}
	else {
		if (n < 100) res = 9;
		else {
			if (n < 1000) res = 9 + n - 99;
			else {
				if (n < 10000) res = 9 + 999 - 99;
				else {
					if (n < 100000) res = 9 + 900 + n - 9999;
					else res = 9 + 900 + 90000;
				}
			}
		}
	}
	cout << res;
}

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

int main(){
	int n;
	scanf("%d",&n);
	int arr[n];
	int arre[n];
	
	for(int i=0;i<n;i++){
		scanf("%d",&arr[i]);
		arre[i]=arr[i];
	}
	
	sort(arre,arre+n);
	int sum=0;
	for(int i=0;i<n;i++){
		if(arr[i]!=arre[i]){
			sum++;
		}
	}
	if(sum==2 || sum==0){
		printf("YES");
	}else{
		printf("NO");
	}
	return 0;
}














Measured memory_bytes: 256
#include<stdio.h>
main(){
  int a,b;
  int c=0;
  int i=0;
  double f,g,h,j=0;
  while(scanf("%d,%d",&a,&b)!=EOF){
    c=c+a*b;
    h=h+b;
    j=j+1;
  }
  f=h/j;
  i=h/j;
  g=f-i;
  if(g>=0.5){
    i=i+1;
  }
  printf("%d\n%d\n",c,i);
  return 0;
}
  

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int K;
    cin >> K;
    string S;
    cin >> S;
    if(S.size()<=K){
        cout << S << endl;
    }else{
        for(int i=0;i<K;i++){
            cout << S.at(i);
        }
        cout << "..." << endl;
    }
}


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

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

	vector<char> s(n);
	for (int i = 0; i < n; i++) {
		char s_in;
		cin >> s_in;
		s.at(i) = s_in;
	}

	string j = "";
	for (int i = 0; i < n - 1; i++) {
		if (s.at(i) != s.at(i + 1)) {
			j += s.at(i);
		}
	}

	int ans = j.size() + 1;
	cout << ans << endl;
}


Measured memory_bytes: 512
fun isRGB(str: String, l: Int, m: Int, r: Int): Boolean {
    return str[l] != str[m] &&
            str[m] != str[r] &&
            str[r] != str[l]
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val input = readLine()!!

    val rn = input.filter { it == 'R' }.length.toLong()
    val gn = input.filter { it == 'G' }.length.toLong()
    val bn = input.filter { it == 'B' }.length.toLong()

    val w = (0 until n).map { m ->
        (1..n).map { d ->
            when {
                m - d < 0 -> 0
                m + d >= n -> 0
                isRGB(input, m - d, m, m + d) -> 1
                else -> 0
            }
        }.sum()
    }.sum()

    val answer = rn * gn * bn - w
    println(answer)
}

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

#define ll long long
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int MAX = 1e5 + 5;

int main()
{
	IOS
	int t = 1;
	//cin >> t;
	while(t--)
	{
		int n;
		cin >> n;
		if(n % 1000 == 0) cout << 0;
		else
		{
			int div = n / 1000;
			if(div * 1000 < n) div += 1;
			cout << div * 1000 - n;
		}
	}
	return 0;
}


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

using namespace std;
using ll = long long;

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	vector<string> a(n);
	for (auto &el : a) {
		cin >> el;
	}
	int ans = 0;
	for (int m1 = 0; m1 < (1 << n); m1++) {
		for (int m2 = 0; m2 < (1 << m); m2++) {
			vector<char> rows(n), cols(m);
			for (int i = 0; i < n; i++) {
				rows[i] = (m1 >> i) & 1;
			}
			for (int j = 0; j < m; j++) {
				cols[j] = (m2 >> j) & 1;
			}
			int cnt = 0;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					cnt += (a[i][j] == '#' && !rows[i] && !cols[j]);
				}
			}
			ans += (cnt == k);
		}
	}
	cout << ans;
}

Measured memory_bytes: 3536
#![allow(unused_macros)]
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(unused_imports)]
//
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
//
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 mut $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")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::max($x, max!( $($y),+)));
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => (::std::cmp::min($x, min!( $($y),+)));
}

// solution 
use std::cmp;
use std::collections::{HashMap, HashSet, BTreeMap, BTreeSet};
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut sum1 = 0;
    let mut sum2 = 0;
    let mut count1 = 0;
    let mut count2 = 0;
    let mut sign1: i64 = 1;
    let mut sign2: i64 = -1;

    for &aa in a.iter() {
        sum1 += aa;
        sum2 += aa;
        if sign1*sum1 <= 0 {
            count1 += sum1.abs() + sign1.abs();
            sum1 = sign1;
        }

        if sign2*sum2 <= 0 {
            count2 += sum2.abs() + sign2.abs();
            sum2 = sign2;
        }

        sign1 = sign1 - 2*sign1;
        sign2 = sign2 - 2*sign2;
    }

    println!("{}", cmp::min(count1, count2));
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
 
int main(){
    long long n, m, k;
    cin >> n >> m >> k;
    vector<long long> a(n);
    vector<long long> b(m);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    for(int i=0; i<m; i++){
        cin >> b.at(i);
    }
    vector<long long> A;
    vector<long long> B;
    A.push_back(0);
    B.push_back(0);
    for(int i=0; i<n; i++){
        A.push_back(A.at(i)+a.at(i));
    }
    for(int i=0; i<m; i++){
        B.push_back(B.at(i)+b.at(i));
    }
 
    int ans = 0, j = m;
    for(int i=0; i<=n; i++){
        if(A.at(i) > k){
            break;
        }
        while(B.at(j) > k - A.at(i)){
            j--;
        }
        ans = max(ans, i+j);
    }
    cout << ans << endl;
    return 0;
    
}

Measured memory_bytes: 11092
n = int(input())
a = [int(i) for i in input().split()]
aa = [0]*(10**5+1)
for i in a:
    aa[i-1]+=1

q= int(input())
s = sum(a)
l = []

for i in range(q):
    b,c =map(int,input().split())
    if aa[b-1]>0:
        aa[c-1]+=aa[b-1]
        s-=b*aa[b-1]
        s+=c*aa[b-1]
        aa[b-1]=0
    l.append(s)

for i in l:
    print(i)

Measured memory_bytes: 20324
mod = 998244353
n = int(input())
d = list(map(int,input().split()))
from collections import Counter
c = Counter(d)
ans = 1
b = 1
if c[0]!=1 or d[0]!=0:ans = 0 
for i in range(max(d)+1):
    ans = (ans*b**c[i])%mod
    b = c[i]
print(ans)

Measured memory_bytes: 19744
while True:
  s = raw_input().split()
  a = int(s[0])
  op = s[1]
  b = int(s[2])
  if op == '?':
    break
  elif op == '+':
    print (a+b)
  elif op == '-':
    print (a-b)
  elif op == '*':
    print (a*b)
  elif op == '/':
    print (a/b)

Measured memory_bytes: 6372
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using Debug = System.Diagnostics.Debug;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;


static class P
{
    static void Main()
    {
        var nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        long[] accums = new long[n + 1];
        for (int i = 1; i < accums.Length; i++)
            accums[i] = accums[i - 1] + int.Parse(Console.ReadLine()) - k;
        var list = accums.Distinct().ToList();
        list.Sort();
        SegmentTree<int> segTree = new SegmentTree<int>(list.Count, 0, (x, y) => x + y);
        long res = 0;
        for (int i = 0; i < accums.Length; i++)
        {
            var ind = list.BinarySearch(accums[i]);
            res += segTree.Query(0, ind);
            segTree.Operate(ind, 1);
        }
        Console.WriteLine(res);
    }
}


class SegmentTree<T>
{
    public int Size { get; private set; }
    T IdentityElement;
    T[] Data;
    Func<T, T, T> Merge;
    int LeafCount;

    public SegmentTree(int size, T identityElement, Func<T, T, T> merge) : this(Enumerable.Repeat(identityElement, size).ToArray(), identityElement, merge) { }

    public SegmentTree(T[] elems, T identityElement, Func<T, T, T> merge)
    {
        Size = elems.Length;
        Merge = merge;
        IdentityElement = identityElement;
        LeafCount = 1;
        while (LeafCount < elems.Length) LeafCount <<= 1;

        Data = new T[LeafCount * 2];
        elems.CopyTo(Data, LeafCount);
        for (int i = LeafCount - 1; i >= 1; i--) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]);
    }

    public T this[int index]
    {
        get { return Data[LeafCount + index]; }
        set { Update(index, value); }
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Update(int i, T x)
    {
        i += LeafCount;
        Data[i] = x;
        while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public void Operate(int i, T x)
    {
        i += LeafCount;
        Data[i] = Merge(Data[i], x);
        while (0 < (i >>= 1)) Data[i] = Merge(Data[i * 2], Data[i * 2 + 1]);
    }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Query(int l, int r)
    {
        l += LeafCount;
        T lRes = IdentityElement;
        r += LeafCount;
        T rRes = IdentityElement;
        while (l <= r)
        {
            if (l % 2 == 1) lRes = Merge(lRes, Data[l]);
            if (r % 2 == 0) rRes = Merge(Data[r], rRes);
            l = (l + 1) / 2;
            r = (r - 1) / 2;
        }
        return Merge(lRes, rRes);
    }
}


Measured memory_bytes: 35436
#include<iostream>
using namespace std;
int main(){
	int x,y;
	while(1){
		cin>>x>>y;
		if(x>y){
			x+=y;
			y=x-y;
			x=x-y;
			cout<<x<<' '<<y<<endl;
		}else if(x==0&&y==0){
			break;
		}else{
			cout<<x<<' '<<y<<endl;
		}
	}
		return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
int h,w;
vector<string> fi;


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



int par[200005];//iの一つ上にあるやつ
int r[200005];//iの属するグループの"大きさ"（計算を速くするため）

void init(int n){
    for(int i=0;i<n;i++){
        par[i]=i;
        r[i]=0;
    }
}//全部バラバラの状態

int find(int x){
    if(par[x]==x){
        return x;
    }else{
        return par[x]=find(par[x]);
    }
}//一番上の付け根を求める

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y) return;
    
    if(r[x]<r[y]){
        par[x]=y;
    }else{
        par[y]=x;
        if(r[x]==r[y]) r[x]++;
    }
}//xとyのグループを付け根でくっつける

bool same(int x,int y){
    return find(x)==find(y);
}//同じグループにいるかどうか

//void dfs(int sx,int sy){
    
    
//}

int main(){
    cin>>h>>w;
    fi.resize(h);
    for(int i=0;i<h;i++){
        cin>>fi[i];
    }
    init(h*w);
   
    
    
    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            for(int dir=0;dir<4;dir++){
                
                int nx=x+dx[dir];
                int ny=y+dy[dir];
                if(nx>=0&&nx<h&&ny>=0&&ny<w){
                    if(fi[x][y]!=fi[nx][ny]){
                        unite(x*w+y,nx*w+ny);
                    }
                }
            }
        }
    }
    
    ll ans=0;
    ll black[200005]={0},white[200005]={0};
    for(int x=0;x<h;x++){
        for(int y=0;y<w;y++){
            if(fi[x][y]=='#') black[find(x*w+y)]++;
            if(fi[x][y]=='.') white[find(x*w+y)]++;
        }
    }
    for(int i=0;i<200005;i++){
        ans+=black[i]*white[i];
    }
    
    
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 4864
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            var N = Sarray()[0];
            var dct = new Dictionary<string, long>();
            for (var i = 0; i < N; ++i)
            {
                var s = ReadLine().ToCharArray();
                Array.Sort(s);
                var ss = new string(s);
                if (!dct.ContainsKey(ss)) dct.Add(ss, 0);
                ++dct[ss];
            }
            var ans = 0L;
            foreach (var kv in dct)
                ans += kv.Value * (kv.Value - 1) / 2;
            WriteLine(ans);
            //Out.Flush();
        }
    }
}

Measured memory_bytes: 31192
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>
#include<deque>
#include<list>


using namespace std;

typedef long long ll;

typedef pair<int, int> pii;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;
const int BIG_INT = 1000000000;



int main() {
	int n;
	cin >> n;
	int ans = n / 2;
	if (n % 2 == 1) {
		ans++;
	}

	cout << ans << endl;
}



Measured memory_bytes: 256