akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(){
	long int n = 200010;
	char str[n];
	scanf("%s", str);
	long int  i = 0, sum = 0;
	while(str[i] != '\0'){
		sum += ((str[i] - '0') % 9);
      sum = sum % 9;
        i++;
	}
	if((sum % 9) == 0){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 1872
N, L = map(int, input().split())

R = [L + i - 1 for i in range(1, N + 1)]
# print(R)

abs_R = [abs(i) for i in R]
# print(abs_R)
idx = abs_R.index(min(abs_R))
# print(idx)
ans = 0
for i, r in enumerate(R):
    if i == idx:
        continue
    ans += r
print(ans)


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

void Main()
{
  int N; cin >> N;
  vector<int> cnt(100000);
  rep(i,100000) {cnt[i] = 0;}
  vector<int> a(N);
  rep(i,N) {cin >> a[i]; cnt[a[i]]++;}
  if (N==1) {cout << 1 << endl; return;}
  else if (N==2) {
    if (abs(a[0]-a[1]) <= 1) cout << 2 << endl;
    else cout << 1 << endl;
    return;
  }
  int maxnum = 0;
  rep(i,N-2) {maxnum = max(maxnum, cnt[i] + cnt[i+1] + cnt[i+2]);}
  cout << maxnum << endl;
}

int main()
{
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  Main();
  return 0;
}

Measured memory_bytes: 1024
while 1:
    m, f, r = map(int, raw_input().split())
    sum = m + f
    if sum == -2: break
    elif min(m, f) == -1: print 'F'
    elif sum >= 80: print 'A'
    elif sum >= 65: print 'B'
    elif sum >= 50: print 'C'
    elif sum >= 30:
        if r >= 50: print 'C'
        else: print 'D'
    else: print 'F'

Measured memory_bytes: 4208
#include <bits/stdc++.h>
using namespace std;
#define fori(i,n) for(int i =0;i<n;i++)
#define pb push_back
#define ll long long
#define int long long
#define F first
#define S second
#define mp make_pair
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cout.precision(15);
 
 
int mod = 998244353;
 
int pow(int a, int b) {
    int ans = 1;
    a %= mod;
    while(b) {
        if(b%2) {
            ans *= a;
            ans %= mod;
        }
        b /= 2;
        a *= a;
        a %= mod;
    }
    return ans;
}

int inv(int a) {
    return pow(a,mod-2);
}

int mul (int a,int b) {
    return ((a%mod)*(b%mod))% mod;
}

struct cmp {
    bool operator() (pair<int,int> a, pair<int,int> b) const {
        int x = a.F;
        int y = b.F;
        return x>=y;
    }
};

int dp[3003][30003];

int32_t main() {
    FAST;
    int t;
    // cin>>t;
    t = 1;
    while(t--) {
        int n,s;
        cin>>n>>s;
        int a[n+1];
        fori(i,n) cin>>a[i+1];
        dp[0][0] = 1;
        for(int i = 1;i <= n; i++) {
            for(int j = 0; j <=s; j++) {
                dp[i][j] = 2ll*dp[i-1][j];
                if(j >= a[i]) dp[i][j] += dp[i-1][j-a[i]];
                dp[i][j] %= mod;
            }
        }
        cout<<dp[n][s];
    }
    
    return 0;
}

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

signed main(){

  int q;
  cin>>q;
  set<int> s;
  while(q--){
    int c,x;
    cin>>c>>x;
    if(c==0){
      s.insert(x);
      cout<< s.size() <<endl;
    }
    else{
      cout<< s.count(x) <<endl;
    }
  }

}


Measured memory_bytes: 12392
A = int(input())
B = int(input())
C = int(input())
X = int(input())

ans = 0

for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (a*500) + (b*100) + (c*50) == X:
                ans+=1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
    double r,a,b;
    cin>>r;
    a=1.0*r*r*3.141592653589;
    b=1.0*2*r*3.141592653589;
    printf("%.10f\n %.10f\f",a,b);
    return 0;
}


Measured memory_bytes: 3196
/*
                   _ooOoo_
                  o8888888o
                  88" . "88　AC!AC!
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rep3(var, min, max) for (ll (var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll (var) = (max) - 1; (var) + 1 > (min); --(var))
#define Mp(a,b) make_pair((a),(b))
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
int main(){
    int n;
    cin>>n;
    ll res=0;
    V vec(n);
    rep(i,n)cin>>vec[i];
    rep(i,n){
        rep3(j,i+1,n){
            if(i==j)continue;
            res+=vec[i]*vec[j];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>

using namespace std;
#define modd 1000000007
#define moda 1000003


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par; 
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i; 
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d,e, H, W, Q;
long long A[200005] = {};
long long B[200005] = {};
long long C[200005] = {};
bool f, ff,fff;
string S;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <pl>vpl[100005];
vector <string> vs;
set<ll> llset;

struct ST
{
	long long hajime;
	long long owari;
	long long zahyou;
	int bangou;

	bool operator<(const ST& another) const
	{
		return hajime < another.hajime;//年齢を比較
	};

};



vector <ST> vst;
ST st[200005];



int main() {

	cin >> S;
	a = 0;
	b = 0;
	c = 0;
	f = false;

	for (int i = 0; i < S.size(); i++) {
		if (f == false && S[i] == 'A') {
			a++;
			f = false;
		}
		else if (f == true && S[i] == 'A') {
			a = 1;
			f = false;
		}
		else if (f == false && S[i] == 'B') {
			f = true;
		}
		else if (f==true && S[i] == 'C') {
			c+=a;
			f = false;
		}
		else {
			a = 0;
			f = false;
		}


	}

	cout << c << endl;

	return 0;

}


Measured memory_bytes: 6784
n,q = map(int,input().split())
s = "0"+input()+"0"
info = [input().split() for i in range(q)]

def solve(pos):
  for i in range(q):
    if s[pos] == info[i][0]:
      if info[i][1] == "L":
        pos = pos - 1
      else:
        pos = pos + 1
    if pos == 0:
      return True
    elif pos == n+1:
      return False
  return False

def solve2(pos):
  for i in range(q):
    if s[pos] == info[i][0]:
      if info[i][1] == "R":
        pos = pos - 1
      else:
        pos = pos + 1
    if pos == 0:
      return True
    elif pos == n+1:
      return False
  return False
ans = n
ng = n+2
ok = 0
while abs(ng - ok) > 1:
  mid = (ng+ok)//2
  if solve(mid):
    ok = mid
  else:
    ng = mid

ans = ans - ok

s = s[::-1]

ng = n+2
ok = 0
while abs(ng - ok) > 1:
  mid = (ng+ok)//2
  if solve2(mid):
    ok = mid
  else:
    ng = mid

ans = ans - ok

print(ans)


Measured memory_bytes: 94508
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

vector <int> edges[100005];
int cnt[100005];
ll k;

ll dfs(int cur, int par) {
    ll ret = max(0LL, k - cnt[par]);
    cnt[cur]++;
    for (int i : edges[cur]) {
        cnt[i]++;
    }

    for (int nxt : edges[cur]) {
        if (nxt == par) continue;
        ll d = dfs(nxt, cur);
        ret = ret * d % MOD;
    }

    return ret;
}

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

    int n;
    cin >> n >> k;

    for (int i = 1; i < n; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    fill(cnt, cnt+n, 0LL);
    cout << dfs(0, 0) << "\n";
    return 0;
}

Measured memory_bytes: 10752
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/














int P, Q, R;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> P >> Q >> R;
	int ans = min({ P + Q, P + R, Q + R });
	cout << ans << endl;
}







Measured memory_bytes: 256
N = int(input())
visit_list = list(map(int, input().split()))
visit_list.append(0)
visit_list.insert(0, 0)

total_visit_cost = 0
for i in range(len(visit_list)-1):
    total_visit_cost += abs(visit_list[i+1] - visit_list[i])

for i in range(1,N+1):
    diff = - abs(visit_list[i] - visit_list[i-1]) - abs(visit_list[i+1] - visit_list[i]) +\
        abs(visit_list[i+1]-visit_list[i-1])
    new_visit_cost = total_visit_cost + diff
    print(new_visit_cost)


Measured memory_bytes: 13920
#define ENABLE_DEBUG 1
// Kana's kitchen {{{
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
#define LOOP(k) for(i64 ngtkana_is_a_genius=0; ngtkana_is_a_genius<(i64)k; ngtkana_is_a_genius++)

using i32 = std::int_least32_t;
using i64 = std::int_least64_t;
using u32 = std::uint_least32_t;
using u64 = std::uint_least64_t;
using usize = std::size_t;

template <class T> using vec = std::vector<T>;
template <class T> using numr = std::numeric_limits<T>;

#ifdef NGTKANA
#include<debug.hpp>
#else
#define DEBUG(...)(void)0
#endif
/*}}}*/

int main(){
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15) << std::fixed;

    usize n;
    double d, x;
    std::cin >> n >> d >> x;

    double ans = 0, coeff = 1;
    for (usize i=n; i>=1; i--) {
        ans += coeff;

        coeff *= i+1;
        coeff /= i;
    }
    ans *= d + (n - 0.5) * x;

    std::cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define un unordered_map
#define us unordered_set
#define ll long long
#define l long 
using namespace std;
const int  mod= 1e9+7;
const int inf=1e9+3;

 int main()
 {
   
   // 1st 
    ll n,x,t;
     cin>>n>>x>>t;
      if(n==x)
       cout<<t;
       else
       {
            int ans=1;
           while(n>x)
           
           {
              n=n-x;
              ans++;
           }
           cout<<(t*ans);
       }
        
        
       return 0;
     
 }
  

Measured memory_bytes: 3564
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main() {
	string s;
	cin >> s;
	int n = 0;long long ans = 0;
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'B') {
			n++;
		}
		else {
			ans += n;
		}
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)
template<class T, class U> void umin(T& x, const U& y){ x = min(x, (T)y);}
template<class T, class U> void umax(T& x, const U& y){ x = max(x, (T)y);}
template<class T, class U> void init(vector<T> &v, U x, size_t n) { v=vector<T>(n, x); }
template<class T, class U> void init(vector<T> &v, U x, size_t n, size_t m...) { v=vector<T>(n); for(auto& a : v) init(a, x, m);}

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    int n;
    cin >> n;
    vector<int> a(4);
    vector<string> ss = {"AC", "WA", "TLE", "RE"};
    FOR(i, n){
        string s;
        cin >> s;
        if (s == "AC")
            a[0]++;
        else if (s == "WA")
            a[1]++;
        else if (s == "TLE")
            a[2]++;
        else
            a[3]++;
    }
    FOR(i, 4)
        cout << ss[i] << " x " << a[i] << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}



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

#define STRINGSIZE 20

int main(void){
	int i,j;
	char istr[STRINGSIZE],ostr[STRINGSIZE]={};
	scanf("%s",istr);
	for(i=0;istr[i]!='\0';i++){
		if(istr[i]=='0'){
			for(j=0;;j++){
				if(ostr[j]=='\0'){
					ostr[j]='0';
					break;
				}
			}
		}
		if(istr[i]=='1'){
			for(j=0;;j++){
				if(ostr[j]=='\0'){
					ostr[j]='1';
					break;
				}
			}
		}
		if(istr[i]=='B'){
			for(j=0;;j++){
				if(ostr[0]=='\0'){break;
				}else{
					if(ostr[j]=='\0'){
						ostr[j-1]='\0';
						break;
					}
				}
			}
		}
	}
	printf("%s\n",ostr);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b=0,c;
  cin>>a;
  c=a;
  while(a!=0){
    b+=a%10;
    a/=10;
  }
  if(c%b==0){
    cout<<"Yes"<<endl;
    
  }else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashMap<Integer,Integer> map = new HashMap<>();
		long sum=0;
		for(int i=0;i<n;i++){
			int a = sc.nextInt();
			map.put(a,map.getOrDefault(a,0)+1);
			sum=sum+a;
		}
		int q = sc.nextInt();
		for(int i=0;i<q;i++){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int d =0;
			if(map.get(a)!=null){
				d=map.get(a);
			}
			int e=0;
			if(map.get(b)!=null){
				e=map.get(b);
			}
			int r = (b-a);
			long f = r*d;
			sum=sum+f;
			map.remove(a);
			if(d!=0)map.put(b,d+e);
			//printMap(map);
			System.out.println(sum);
		}
		
	}
	private static void printMap(Map < Integer, Integer > map) {
        for (Integer s: map.keySet()) {
            System.out.println(s);
        }
    }
}

Measured memory_bytes: 65964
/*
 * Author:  heyuhhh
 * Created Time:  2020/6/21 20:03:18
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#include <functional>
#include <numeric>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << std::endl; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
  template <template<typename...> class T, typename t, typename... A> 
  void err(const T <t> &arg, const A&... args) {
  for (auto &v : arg) std::cout << v << ' '; err(args...); }
#else
  #define dbg(...)
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e5 + 5;

void run() {
    int n, k; cin >> n >> k;
    vector <int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += a[i];
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[n];
    for( int i = 0; i < n; ++i ) cin >> a[i];
    sort( a, a + n );
    int l = a[n / 2 - 1];
    int r = a[n / 2];
    cout << r - l << endl;
    return 0;
}



Measured memory_bytes: 640
#include<algorithm>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstdio>
#include<iomanip>
#include<cmath>
using namespace std;

int main(){
//    cout << fixed << setprecision(10);
    string s;
    cin >> s;
    
    if (s[2] == s[3] && s[4] == s[5]) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;

int main(){
    string str;
    cin >> str;
    if(str[0]==str[1]&&str[2]==str[3]&&str[0]!=str[2])  cout <<"Yes\n";
    else if(str[0]==str[2]&&str[1]==str[3]&&str[0]!=str[1])  cout <<"Yes\n";
    else if(str[0]==str[3]&&str[1]==str[2]&&str[0]!=str[1])  cout <<"Yes\n";
    else if(str[1]==str[2]&&str[0]==str[3]&&str[1]!=str[0])  cout <<"Yes\n";
    else if(str[1]==str[3]&&str[0]==str[2]&&str[1]!=str[0])  cout <<"Yes\n";
    else if(str[2]==str[3]&&str[0]==str[1]&&str[2]!=str[0])  cout <<"Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
aaa = list(map(int, input().split()))
bbb = list(map(int, input().split()))
ccc = list(map(int, input().split()))

ans = sum(bbb)
for a1, a2 in zip(aaa, aaa[1:]):
    if a1 == a2 - 1:
        ans += ccc[a1 - 1]
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    i64 r, d, x;
    std::cin >> r >> d >> x;
    for (int i = 1; i <= 10; i++) {
        x = r * x - d;
        std::cout << x << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    A = list(map(int,input().split()))
    S = input()
    ans = '0'
    for i in range(N):
        if S[i]=='1':
            l = []
            for j in range(i+1,N):
                if S[j]=='0':
                    l.append(A[j])
            for k in range(len(l)):
                l.sort()
                for j in range(len(l)-1):
                    if l[j+1]^l[j] < l[j+1]:
                        l[j+1],l[j] = l[j],l[j+1]^l[j]
                
            s = A[i]
            for j in range(len(l)-1,-1,-1):
                if s^l[j] < s:
                    s ^= l[j]
            if s != 0:
                ans = '1'
    print(ans)
def main():
    T = int(input())
    for t in range(T):
        solve()

if __name__ == '__main__':
    main()

Measured memory_bytes: 69188
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <cstring>

using namespace std;

const int N=131073;
const int P=1000000007;

int n,m;
int a[17];
long long f[17][N];
long long fac[N],_fac[N];
long long ans;

inline long long ksm(long long base,long long x){
	long long wes=1;
	while(x){
		if(x&1) wes*=base,wes%=P;
		base*=base,base%=P;
		x>>=1;
	}
	return wes;
}

#define multi(x,y) (((x)*(y))%P)
#define upd(x,y) x+=y,x%=P

inline long long C(int x,int y){
	//printf("C:(%d,%d)\n",x,y);
	if(x<0) return 0;
	if(y>x || y<0) return 0;
	return multi(fac[x],multi(_fac[y],_fac[x-y]));
}

inline void solve_dp(){
	f[0][0]=1;
	for(int i=0;i<m;i++){
		//f[i+1][?] <- f[i][j]
		for(int j=0;j<(1<<n);j++){
			//add_trans
			for(int k=0;k<n;k++){
				if((j^(1<<k))==(j+(1<<k))){
					upd(f[i+1][j^(1<<k)],multi(f[i][j],C(a[i+1]-j-1,(1<<k)-1)));
				}
			}
			//direct_trans
			upd(f[i+1][j],f[i][j]);
		}
	}
	/*
	for(int i=1;i<=m;i++){
		printf("%d :",i);
		for(int j=0;j<(1<<n);j++) printf("%lld ",f[i][j]);
		printf("\n");
	}
	printf("\n");
	*/
	for(int j=0;j<(1<<n);j++){
		int cnt=0;
		for(int k=0;k<n;k++) if((j&(1<<k))!=0) f[m][j]*=fac[1<<k],f[m][j]%=P,cnt++;
		f[m][j]*=fac[(1<<n)-j-1],f[m][j]%=P;
		if(cnt&1) upd(ans,P-f[m][j]);
		else upd(ans,f[m][j]);
	}
}

void init(){
	scanf("%d%d",&n,&m);
	for(int i=m;i>=1;i--) scanf("%d",&a[i]),a[i]=(1<<n)-a[i]+1;
	fac[0]=_fac[0]=1;
	for(int i=1;i<=(1<<n);i++) fac[i]=multi(fac[i-1],i),_fac[i]=ksm(fac[i],P-2);
	solve_dp();
	printf("%lld\n",multi(ans,(1<<(n))));
}

int main(){
	init();
	return 0;
}

Measured memory_bytes: 18176
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    
    vector<int> V(N);
    for(int i=N/2; i<N; i++){
        V[i] = A[i];
    }
    
    for(int i=N/2 - 1; i>=0; i--){
        int cur = i + i + 1;
        int sum = 0;
        while(cur < N){
            sum += V[cur];
            cur += i+1;
        }
        if((A[i]==0 && sum%2==0) || (A[i]==1 && sum%2==1)) V[i] = 0;
        else if((A[i]==0 && sum%2==1) || (A[i]==1 && sum%2==0)) V[i] = 1;
    }
    
    int M = 0;
    for(int i=0; i<N; i++){
        if(V[i]==1) M++;
    }
    
    cout << M << endl;
    if(M==0) return 0;
    for(int i=0; i<N; i++){
        if(V[i]==1) cout << i + 1 << " ";
    }
    cout << endl;
    
    return 0;
}



Measured memory_bytes: 2432
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int A, B, C, D; cin >> A >> B >> C >> D;
	cout << ((A > B) ? B : A) + ((C > D) ? D : C) << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int ans = 0;
        for (int i = 1; i < N; i++) {
            ans += i;
        }
        for (int i = 1; i < M; i++) {
            ans += i;
        }

        System.out.println(ans);
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};

int main(){
    string s;   cin >> s;
    cout << s;
    if(s.back()=='s') cout << "es" << endl;
    else cout << "s" << endl;
}


Measured memory_bytes: 3600
<?php
// C
fscanf(STDIN, '%d', $n);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));
$buka = array_fill(0, $n, 0);
for ($i = 0; $i < $n - 1; $i++) {
    $buka[$a[$i] - 1]++;
}
echo implode(PHP_EOL, $buka);

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

int main()
{
    int N, K;
    string S;

    cin >> N >> K;
    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';
    }
    else if (S[K - 1] == 'D')
    {
        S[K - 1] = 'd';
    }
    else if (S[K - 1] == 'E')
    {
        S[K - 1] = 'e';
    }
    else if (S[K - 1] == 'F')
    {
        S[K - 1] = 'f';
    }
    else if (S[K - 1] == 'G')
    {
        S[K - 1] = 'g';
    }
    else if (S[K - 1] == 'H')
    {
        S[K - 1] = 'h';
    }
    else if (S[K - 1] == 'I')
    {
        S[K - 1] = 'i';
    }
    else if (S[K - 1] == 'J')
    {
        S[K - 1] = 'j';
    }
    else if (S[K - 1] == 'K')
    {
        S[K - 1] = 'k';
    }
    else if (S[K - 1] == 'L')
    {
        S[K - 1] = 'l';
    }
    else if (S[K - 1] == 'M')
    {
        S[K - 1] = 'm';
    }
    else if (S[K - 1] == 'N')
    {
        S[K - 1] = 'n';
    }
    else if (S[K - 1] == 'O')
    {
        S[K - 1] = 'o';
    }
    else if (S[K - 1] == 'P')
    {
        S[K - 1] = 'p';
    }
    else if (S[K - 1] == 'Q')
    {
        S[K - 1] = 'q';
    }
    else if (S[K - 1] == 'R')
    {
        S[K - 1] = 'r';
    }
    else if (S[K - 1] == 'S')
    {
        S[K - 1] = 's';
    }
    else if (S[K - 1] == 'T')
    {
        S[K - 1] = 't';
    }
    else if (S[K - 1] == 'U')
    {
        S[K - 1] = 'u';
    }
    else if (S[K - 1] == 'V')
    {
        S[K - 1] = 'v';
    }
    else if (S[K - 1] == 'W')
    {
        S[K - 1] = 'w';
    }
    else if (S[K - 1] == 'X')
    {
        S[K - 1] = 'x';
    }
    else if (S[K - 1] == 'Y')
    {
        S[K - 1] = 'y';
    }
    else if (S[K - 1] == 'Z')
    {
        S[K - 1] = 'z';
    }

    cout << S << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	SPEED
	int a,b ;
	cin >> a;
	cin >> b;
	if ((a==1 && b==3) || (b==1 && a==3))
	{
		cout << 2;
	}
	else if ((a==2 && b==3) || (b==2 && a==3))
	{
		cout << 1;
	}
	else
	{
		cout << 3;
	}
}


Measured memory_bytes: 256
#include<stdio.h>
 
 int main()
 {
   int r,c;
   while(scanf("%d%d",&r,&c)!=EOF&&(r||c))
   {
     if(r%2&&c%2)
       printf("no\n");
     else
       printf("yes\n");                               
   }
   return 0;    
 }

Measured memory_bytes: 0
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <set>

//#define DEBUG 1

#define for0(i,n) for (int i=0; i<n; i++)
#define forr(i,n) for (int i=n-1; i>=0; i--)
#define fori(i,a,b) for (int i=a; i<=b; i++)
#define iter(c) for(auto it=c.begin(); it!=c.end(); it++)
#define vec(x) vector< x >
#define pb push_back
#define ms(a,z) memset(a,z,sizeof(a));
#define mp make_pair
#define X first
#define Y second
#define sqr(x) 1LL*(x)*(x)
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define all(a) a.begin(),a.end()
#define size(x) (int)(x).size()
#define read(x) int x; scanf("%d",&x);
#ifdef DEBUG
#define nl cout<<"\n";
#define pr(x) cout<<(x)<<" ";
#define prl(x) cout<<#x " = "<<x<<endl;
#define prp(x) cout<<"("<<(x).first<<" "<<(x).second<<") ";
#define printv(v) {for(int _=0; _<size(v); _++) cout<<v[_]<<" "; cout<<"\n";}
#define printa(a,s) {for (int _=0; _<s; _++) cout<<a[_]<<" "; cout<<"\n";}
#define print2D(a,m,n) {for (int _=0; _<m; _++) {for (int __=0; __<n; __++) cout<<a[_][__]<<" "; cout<<"\n";} cout<<"\n";}
#define debug cout<<"ok at line "<<__LINE__<<endl;
#else
#define nl
#define pr(x)
#define prl(x)
#define prp(x)
#define printv(v)
#define printa(a,s)
#define print2D(a,m,n)
#define debug
#endif

using namespace std;

typedef long long ll;

const int INF = 2147483647;
const long long INFL = 9223372036854775807LL;
const double EPSILON = 0.00000001;
const long long MOD = 1000000007;

ll score(ll b1, ll b2, ll b3)
{
    ll M = max(b1,max(b2,b3));
    ll m = min(b1,min(b2,b3));
    return M - m;
}

ll solve(ll H, ll W)
{
    ll best = INFL;
    for (ll i=1; i<H; i++) {
        ll b1 = i*W;
        ll remain = H-i;
        //case 1
        ll b2 = remain/2 * W;
        ll b3 = (remain-remain/2) * W;
        ll s1 = score(b1,b2,b3);
        //pr(b1) pr(b2) pr(b3) nl

        //case 2
        b2 = remain* (W/2);
        b3 = remain * (W-W/2);
        ll s2 = score(b1,b2,b3);
        //pr(b1) pr(b2) pr(b3) nl

        best = min(best,min(s1,s2));
    }
    return best;
}

int main()
{
    #ifdef DEBUG
    freopen("A.txt","r",stdin);
    //freopen("","w",stdout);
    #endif

    ll H, W;
    scanf("%lld %lld",&H,&W);

    ll ans1 = solve(H,W);
    ll ans2 = solve(W,H);
    cout<<min(ans1,ans2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) cerr << #x << "=" << static_cast<bitset<16> >(x) << endl;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;
/** Problem0121 : Seven Puzzle **/
map<string, int> list;
int d[4] = {1, -1, 4, -4};

int main()
{
	queue<string> Q;
	Q.push("01234567");
	list["01234567"] = 1;
	
	while (Q.size()) {
		string s = Q.front(); Q.pop();
		int pos = (int)s.find("0", 0);
		rep(i, 4) {
			int npos = pos+d[i];
			if (0<=npos && npos<8 && !(npos==3 && pos==4) && !(pos==3 && npos==4)) {
				string ns = s;
				swap(ns[pos], ns[npos]);
				if (list[ns] == 0) {
					Q.push(ns);
					list[ns] = list[s]+1;
				}
			}
		}
	}
	
	while (1) {
		string in;
		rep(i, 8) {
			char c; cin>>c;
			in+=c;
		}
		if (cin.eof()) break;
		cout << list[in]-1 << endl;
	}
}

Measured memory_bytes: 3440
def solve(N, list):
    d = set()
    for i, l in enumerate(list):
        if l in d:
            return "No"
        if i > 0 and l[0] != list[i - 1][-1]:
            return "No"
        d.add(l)
    return "Yes"


if __name__ == "__main__":
    l = input()
    N = int(l)
    list = [input() for _ in range(0, N)]
    print(solve(N, list))


Measured memory_bytes: 3060
N, A, B = map(int, input().split())
V = sorted([int(i) for i in input().split()], reverse = True)

VA = V[:A]
print(sum(VA) / A)

last = VA[-1]
x = VA.count(last)
y = V.count(last)

def comb(n, k):
    k = min(k, n - k)
    result = 1
    for i in range(n, n - k, -1):
        result *= i
    for i in range(1, k + 1):
        result //= i 
    return result

if V.count(V[0]) > A:
    ans = 0
    u = min(V.count(V[0]), B)
    for i in range(A, u + 1):
        ans += comb(y, i)
else:
    ans = comb(y, x)
    
print(ans)

Measured memory_bytes: 3064
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val p = List.fill(n)(sc.nextInt)
    sc.close()

    if (p.zipWithIndex.count(z => z._1 != z._2 + 1) <= 2) println("YES")
    else println("NO")
  }
}

Measured memory_bytes: 25524
#include <iostream>

using namespace std;

int n,k;
int q[200005],hh,tt;

int main()
{
    scanf("%d%d",&n,&k);
    for(int i=0;i<k;i++)scanf("%d",q+i);
    hh=0,tt=k;
    for(int i=k,x;i<n;i++)
    {
        scanf("%d",&x);
        puts(x>q[hh++]?"Yes":"No");
        q[tt++]=x;
    }
    return 0;
}

Measured memory_bytes: 4464
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
#define INF 999999999
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using llong = long long;
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  vec a(n);
  vec b(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
  }
  map<pll,ll> bn;
  for(ll i=0;i<n;i++) {
    for(ll j=0;j<3;j++) {
      for(ll k=0;k<3;k++) {
        ll y=a[i]-j;
        ll x=b[i]-k;
        if(x>-1&&y>-1&&x+2<w&&y+2<h) {
          bn[pll(y,x)]++;
        }
      }
    }
  }
  vec bnn(10);
  for(auto p:bn) {
    bnn[p.second]++;
    bnn[0]++;
  }
  bnn[0]=(h-2)*(w-2)-bnn[0];
  for(ll i=0;i<10;i++) {
    cout << bnn[i] << endl;
  }
}

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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long 
 
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
	     cin>>a[i];
	}
	ll tot=0;
	for(int i=0;i<n-1;i++)
	{
	     for(int j=i+1;j<n;j++)
	     {
	          tot+=a[i]*a[j];
	     }
	}
	cout<<tot;

	return 0;
}

Measured memory_bytes: 3548
//
// Created on 2020/03/01.
//

//#include <bits/stdc++.h>
#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 <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

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


    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N,M;
int aa[100001];

int main() {

  cin >> N >> M;

  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    aa[a]++;
    aa[b]++;
  }

  for(int i = 1; i <= N; i++) {
    if(aa[i] % 2 == 1) {cout << "NO" <<endl; return 0;}
  }
  cout << "YES" <<endl;
}


Measured memory_bytes: 640
n = int(raw_input())
s = ''

for i in range(1, n+1):
    if i%3 == 0:
        s = s + ' ' + str(i)
    else:
        temp = ''
        temp = str(i)
        for j in range(len(temp)):
            if temp[j] == '3':
                s = s + ' ' + str(i)
                break
print s

Measured memory_bytes: 6456
H,W = map(int,input().split())
c = [list(map(int,input().split())) for _ in range(10)]
A = [list(map(int,input().split())) for _ in range(H)]

N  = 10
d = c
for k  in range(N):
    for i in range(N):
        for j in range(N):
            d[i][j] = min(d[i][j], d[i][k]+d[k][j])

ans = 0
for aa in A:
    for a in aa:
        if a!=-1:
           ans += d[a][1]
           
print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h> 
using namespace std; 
  
// Function to count all possible 
// triangles with arr[] elements 
int findNumberOfTriangles(long long int arr[], long long int n) 
{ 
    // Count of triangles 
    int count = 0; 
  
    // The three loops select three 
    // different values from array 
    for (int i = 0; i < n; i++) { 
        for (int j = i + 1; j < n; j++) { 
  
            // The innermost loop checks for 
            // the triangle property 
            for (int k = j + 1; k < n; k++) {
    if(arr[i]!=arr[j]&&arr[j]!=arr[k]&&arr[i]!=arr[k]){
                if ( 
                    arr[i] + arr[j] > arr[k] 
                    && arr[i] + arr[k] > arr[j] 
                    && arr[k] + arr[j] > arr[i]) 
                    count++; 
        } }
    } }
    return count;
}
 
int main() 
{   
    long long  int n,i,j,k,l;
    cin>>n;
 long long  int arr[n];
   for(i=0;i<n;i++)
   cin>>arr[i];
    int size = sizeof(arr) / sizeof(arr[0]); 
  
    cout << findNumberOfTriangles(arr, size); 
  
    return 0; 
} 

Measured memory_bytes: 3628
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n;
	while(cin >> n) {
		vector<int> a(n);
		REP(i, n) cin >> a[i];
		sort(ALL(a));
		int val;
		vector<P> ans;
		if(a[n-1] <= 0) {
			int sum = a[n-1];
			REP(i, n-1) {
				ans.emplace_back(sum, a[i]);
				sum -= a[i];
			}
			val = sum;
		} else if(a[0] >= 0) {
			int sum = a[0];
			FOR(i, 1, n-1) {
				ans.emplace_back(sum, a[i]);
				sum -= a[i];
			}
			ans.emplace_back(a[n-1], sum);
			val = a[n-1] - sum;
		} else {
			int ma = a[n-1];
			int mi = a[0];
			FOR(i, 1, n-1) {
				if(a[i] >= 0) {
					ans.emplace_back(mi, a[i]);
					mi -= a[i];
				}
			}
			FOR(i, 1, n-1){
				if(a[i] < 0) {
					ans.emplace_back(ma, a[i]);
					ma -= a[i];
				}
			}
			ans.emplace_back(ma, mi);
			val = ma - mi;
		}
		cout << val << endl;
		REP(i, SZ(ans)) {
			cout << ans[i].F <<  ' ' << ans[i].S << endl;
		}
	}
	return 0;
}


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

// 二つの直方体をくっつけて1つの直方体にするので、
// 二つの直方体の内どれか対応する二つの寸法が等しくなければならない
// つまり、直方体の寸法は、両方ともA×B×()、B×C×()、C×A×()のどれか ()は任意の整数
// それぞれの場合について、最小になるようにする

int main() {
    long long A,B,C;
    cin >> A >> B >> C;
    vector<long long> res{A*B*(C%2), B*C*(A%2), C*A*(B%2)};
    cout << *min_element(res.begin(),res.end()) << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	var root *elem
	for i := 0; i < n; i++ {
		sc.Scan()
		line := sc.Text()
		if line == "print" {
			printIn(root)
			fmt.Println(strings.Join(in, ""))
			printPre(root)
			fmt.Println(strings.Join(pre, ""))
			in = []string{}
			pre = []string{}
		} else if line == "find" {
			sc.Scan()
			num, _ := strconv.Atoi(sc.Text())
			fmt.Println(find(root, num))
		} else {
			sc.Scan()
			num, _ := strconv.Atoi(sc.Text())
			root = insert(root, num)
		}
	}
}

var pre []string

func printPre(elem *elem) {
	if elem == nil {
		return
	}
	pre = append(pre, " "+strconv.Itoa(elem.key))
	printPre(elem.left)
	printPre(elem.right)
}

var in []string

func printIn(elem *elem) {
	if elem == nil {
		return
	}
	printIn(elem.left)
	in = append(in, " "+strconv.Itoa(elem.key))
	printIn(elem.right)
}

type elem struct {
	paremnt *elem
	left    *elem
	right   *elem
	key     int
}

func insert(root *elem, zkey int) *elem {
	// new Value
	z := &elem{nil, nil, nil, zkey}
	if root == nil {
		return z
	}

	// search parent
	parentOfZ := root
	for {
		if parentOfZ.key > z.key {
			if parentOfZ.left == nil {
				parentOfZ.left = z
				break
			}
			parentOfZ = parentOfZ.left
		} else {
			if parentOfZ.right == nil {
				parentOfZ.right = z
				break
			}
			parentOfZ = parentOfZ.right
		}
	}

	z.paremnt = parentOfZ
	return root
}

func find(root *elem, zkey int) string {
	// search parent
	s := root
	for {

		if s.key == zkey {
			return "yes"
		}

		if s.key > zkey {
			if s.left == nil {
				break
			}
			s = s.left
		} else {
			if s.right == nil {
				break
			}
			s = s.right
		}
	}
	return "no"
}



Measured memory_bytes: 80924
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <sstream>
#include <queue>
#include <iomanip>
#include <algorithm>
using namespace std;

typedef long long ll;

const int Maxn = 2005;
const int Maxm = 2000005;

int n;
int a[Maxn];
vector <int> seq1, seq2;
bool dp1[Maxm], dp2[Maxm];

void Solve(const vector <int> &V, bool dp[], int x)
{
	dp[0] = true;
	int s = 0;
	for (int i = 0; i < V.size(); i++) {
		int to = min(s, x - V[i]);
		for (int j = to; j >= 0; j--) if (dp[j])
			dp[j + V[i]] = true;
		s += V[i];
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	sort(a, a + n);
	int sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i++)
		if (sum1 <= sum2) { seq1.push_back(a[i]); sum1 += a[i]; }
		else { seq2.push_back(a[i]); sum2 += a[i]; }
	int g = (sum1 + sum2) / 2;
	Solve(seq1, dp1, g);
	Solve(seq2, dp2, g);
	int mx = 0;
	int j = g;
	for (int i = 0; i <= g; i++) if (dp1[i]) {
		while (i + j > g || !dp2[j]) j--;
		mx = max(mx, i + j);
	}
	printf("%d\n", sum1 + sum2 - mx);
	return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>

int main(int argc, void **argv)
{
	int A, B, T;
	int n;

	scanf("%d %d %d", &A, &B, &T);

	n = (T / A) * B;
	printf("%d\n", n);

	return 0;
}

Measured memory_bytes: 128
n = int(input())
n_sqrt = int(n ** 0.5) + 1
ans = float('inf')
for i in range(1, n_sqrt + 1):
    if n % i == 0:
        j = int(n // i)
        max_len = max(len(str(i)), len(str(j)))
        ans = min(max_len, ans)
print(ans)

Measured memory_bytes: 3060
require 'set'

reverse = { ?N => ?S, ?S => ?N, ?E => ?W, ?W => ?E }

n, x0, y0, t = gets.split.map(&:to_i)
junction = {}
n.times do
  x1, y1, x2, y2 = gets.split.map(&:to_i)
  dx, dy = x2 - x1, y2 - y1
  l = dx.abs + dy.abs
  dx /= l
  dy /= l
  dir = dx > 0 ? ?E :
        dx < 0 ? ?W :
        dy > 0 ? ?N :
                 ?S
  l.times do
    (junction[[x1, y1]] ||= Set.new) << dir
    (junction[[x1 + dx, y1 + dy]] ||= Set.new) << reverse[dir]
    x1 += dx
    y1 += dy
  end
end

initial_states = Set[*junction[[x0, y0]].map {|dir| [x0, y0, dir] }]

def diff(dir)
  dx = (dir == ?E ? 1 : dir == ?W ? -1 : 0)
  dy = (dir == ?N ? 1 : dir == ?S ? -1 : 0)
  [dx, dy]
end

t.times do
  buckets = (0..9).map { Set.new }
  dist, observed_dir = gets.chomp.split
  dist = dist.to_i
  initial_states.each do |x, y, dir|
    dx, dy = diff(dir)
    buckets[dist - 1] << [x + dx, y + dy, dir]
  end

  9.downto(1) do |d|
    buckets[d].each do |x, y, dir|
      junction[[x, y]].each do |next_dir|
        next if next_dir == reverse[dir]
        dx, dy = diff(next_dir)
        buckets[d - 1] << [x + dx, y + dy, next_dir]
      end
    end
  end

  initial_states = Set.new
  buckets[0].each do |x, y, dir|
    if dir == observed_dir
      junction[[x, y]].each do |next_dir|
        next if next_dir == reverse[dir]
        initial_states << [x, y, next_dir]
      end
    elsif junction[[x, y]].include?(observed_dir)
      initial_states << [x, y, observed_dir] unless observed_dir == reverse[dir]
    end
  end
end

initial_states.map {|a| a[0..1] }.uniq.sort.each {|a| puts a * " " }



Measured memory_bytes: 9184
import numpy as np
flag=0
N=int(input())
A=np.array(list(map(int,input().split())))
B=np.array(list(map(int,input().split())))
if np.sum(A-B)<0:
    flag=-1
D=np.sort(A-B)
failNum=0
failSum=0
for i in range(N):
    if D[i]<0:
        failNum+=1
        failSum+=D[i]
passNum=0
if flag==0:
    while failSum<0:
        failSum+=D[N-1-passNum]
        passNum+=1
if flag==-1:
    print(-1)
else:
    print(failNum+passNum)        


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

int main(){
    ll K, A, B;
    cin >> K >> A >> B;
    if(A + 2 >= B || K + 1 <= A) cout << K + 1 << endl;
    else if((K-A+1)%2==0){
        cout << A + (K-A+1)/2*(B-A) << endl;
    }else{
        cout << A + (K-A+1)/2*(B-A) + 1 << endl;
    } 
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

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















 
int main(){
    ll n, p;
    string s;
    cin >> n >> p >> s;
    if(p == 2 || p == 5){
        ll ans = 0;
        for(ll i = n - 1; i >= 0; i--){
            if((s[i] - '0') % p == 0){
                ans += i + 1;
            }
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> cnt(p);
    ll ans = 0, r = 0, k = 1;
    for(ll i = n - 1; i >= 0; i--){
        r += (s[i] - '0') * k;
        r %= p;
        k *= 10;
        k %= p;
        ans += cnt[r]++ + (r == 0);
    }
    cout << ans << endl;
}

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

int main()
{

	int a,b,c,d;
	cin>>a>>b>>c>>d;
	
		int ans;
		if(a<=c&&b>=d)
		{
			ans = d-c;
		}
		else if(a>=c&&b<=d)
		{
			ans = b-a;
		}
		else if(b<d)
		{
			ans = b-c;
		}
		else
		{
			ans = d-a;
		}
		if(ans<0)
		{
			ans = 0;
		}
		cout<<ans<<endl; 
	
	return 0;
}

Measured memory_bytes: 256