akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
using namespace std;
typedef long long LL;
const int N=2e5;
int gi() {
	int w=0;bool q=1;char c=getchar();
	while ((c<'0'||c>'9') && c!='-') c=getchar();
	if (c=='-') q=0,c=getchar();
	while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
	return q? w:-w;
}
int d[N],p[N],to[N],x[N];
int n;
inline void mul(int *a,int *b) {
	for (int i=1;i<n;i++) x[i]=a[b[i]];
	for (int i=1;i<n;i++) a[i]=x[i];
}
int main()
{
	n=gi();int i,a,b,m;LL k,S=gi();
	for (i=1,a=S;i<n;i++)
		b=gi(),d[i]=b-a,a=b;
	
	for (i=1;i<n;i++) p[i]=to[i]=i;
	for (i=1,m=gi(),cin>>k;i<=m;i++)
		a=gi(),swap(p[a-1],p[a]);
	while (k) {
		if (k&1) mul(to,p);
		mul(p,p);k>>=1;
	}
	for (i=1;i<=n;i++) printf("%lld.0\n",S),S+=d[to[i]];
	return 0;
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
// cin.eof() 入力個数の問題

int main() {
   int n;
   cin>>n;
if(n%1000==0) cout<<0<<endl;
else
{


   cout<<1000*((n/1000)+1)-n<<endl;
    }    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define print1(a) cout << (a) << '\n'
#define print2(a,b) cout << (a) << ' ',print1(b)
#define print3(a,b,c) cout << (a) << ' ',print2(b,c)
#define print4(a,b,c,d) cout << (a) << ' ',print3(b,c,d)
#ifdef i_am_noob
#define debug(a) print2(#a,a)
#else
#define debug(a) 
#endif
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
 
using namespace std;
using namespace __gnu_pbds;
 
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
 
inline int add(int a, int b){return (a+b>=MOD?a+b-MOD:a+b);}
inline int sub(int a, int b){return (a+MOD-b>=MOD?a-b:a+MOD-b);}
int Pow(int a, int b){
	if(!b) return 1;
	int tmp=Pow(a*a%MOD,b>>1);
	return (b&1?tmp*a%MOD:tmp);
}
inline int inverse(int n){return Pow(n,MOD-2);}
 
const int maxn=100005;
//i_am_noob
string str;

signed main(){
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> str;
	sort(all(str));
	if(str[0]==str[1]&&str[1]!=str[2]&&str[2]==str[3]) print1("Yes");
	else print1("No");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

string N;

int main(void){
    
    cin >> N;
    
    int cnt = 0; int num = 0;
    for(int i = 0; i < N.size(); ++i){
        if(num != N[i] - '0'){
            num = N[i] - '0';
            cnt = 0;
        }
        ++cnt;
        if(cnt >= 3){ printf("Yes\n"); return 0; }
    }
    printf("No\n");
    
    return 0;
}



Measured memory_bytes: 256
import math
a,b,x = map(int,input().split())
v = a*a*b
tg = (2*v - 2 * x) / (a**3)
if v < 2*x :
    ans = math.degrees(math.atan(tg))
else:
    w = x *2 /(a*b)
    tgt = b/w
    ans = math.degrees(math.atan(tgt))
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define foro(i, n) for(i=0; i<n; i++)
#define forl(i, n) for(i=1; i<=n; i++)
#define x first
#define y second
constexpr int INF = 1e9 + 1;
constexpr ll LLINF = 1e18 + 1;

int main()
{
	int i, j, k, l, tmp;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	foro(i, n){
		cin >> k;
		if(!(k&1) && (k%3!=0 && k%5!=0)){
			printf("DENIED\n");
			return 0;
		}
	}
	printf("APPROVED\n");
}


Measured memory_bytes: 256
a1 = list(map(int,input().split()))
a2 = list(map(int,input().split()))
a3 = list(map(int,input().split()))
a = a1 + a2 + a3
n = int(input())
for i in range(n):
    b = int(input())
    a = [0 if b == a[i] else a[i] for i in range(9)]

if(a[0] == a[1] == a[2] or a[3] == a[4] == a[5] or a[6] == a[7] == a[8] or
a[0] == a[3] == a[6] or a[1] == a[4] == a[7] or a[2] == a[5] == a[8] or
a[0] == a[4] == a[8] or a[2] == a[4] == a[6]):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef  double ld;
#define A 1000000007ll
#define D 1000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI 3.14159265358979323
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n"

int main() 
{
    FAST;
    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    ll p[a],q[b],r[c];
    for(int i=0;i<a;i++)
        cin>>p[i];
    for(int i=0;i<b;i++)
        cin>>q[i];
    for(int i=0;i<c;i++)
        cin>>r[i];
    sort(p,p+a,greater<ll> ());
    sort(q,q+b,greater<ll> ());
    sort(r,r+c,greater<ll> ());
    ll sum=0;
    for(int i=0;i<x;i++)
        sum+=p[i];
    for(int i=0;i<y;i++)
        sum+=q[i];
    ll w=x-1,e=y-1,t=0;
    while(t<c)
    {
        if(w>=0 && e>=0)
        {
            if(r[t]>min(p[w],q[e]))
            {
                sum+=r[t]-min(p[w],q[e]);
                if(p[w]<q[e])
                    w--;
                else
                    e--;
                t++;
                continue;
            }
            else
                break;
        }
        if(w<0 && e>=0)
        {
            if(r[t]>q[e])
            {
                sum+=r[t]-q[e];
                e--;
                t++;
                continue;
            }
            else
                break;
        }
        if(w>=0 && e<0)
        {
            if(r[t]>p[w])
            {
                sum+=r[t]-p[w];
                w--;
                t++;
                continue;
            }
            else
                break;
        }
        if(w<0 && e<0)
            break;
    }
    cout<<sum;
    subt;   
    return 0;
}

Measured memory_bytes: 2560
//答案错误 
#include<stdio.h>
#include<algorithm>
using namespace std;
struct Gcl
{
	long long num;
	long long shijian;
};
bool cmp(Gcl a,Gcl b){
	if(a.shijian==b.shijian){
		return a.num>b.num; 
	}else{
		return a.shijian<b.shijian;
	}
}struct Gcl s[200010]={};
int main()
{
	
	long long n,i,sum=0;//leap=0;
	while(~scanf("%lld",&n)){
		long long leap=0;
		for(i=0;i<n;i++){
			scanf("%lld%lld",&s[i].num,&s[i].shijian);
		}sort(s,s+n,cmp);
		for(i=0;i<n;i++){
			sum+=s[i].num;
			if(sum>s[i].shijian){
				leap=1;
				break;
			}
		}if(leap==1){
			printf("No\n");
		}else{
			printf("Yes\n");
		}leap=0;sum=0;
	}
} 

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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

string s;

int main() {
  cin >> s;
  int n = s.length();
  int res = 0;
  for(auto i : s) res += i - '0';
  res = max(res, 9 * (n - 1));
  range(i, 0, n) {
    if(s[i] == '0') continue;
    int add = 0;
    range(j, 0, i) add += s[j] - '0';
    add += s[i] - '1';
    add += (n - i - 1) * 9;
    res = max(res, add);
  }
  cout << res;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    // cout << fixed << setprecision(20);
    int n;cin >> n;
    vector<int> a(n);REP(i,n)cin >> a[i];
    sort(all(a));
    REP(i,n-1){
        if(a[i] == a[i+1]){
            cout << "NO" << '\n';
            return 0;
        }
    }
    cout << "YES" << '\n';
        
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	long N = sc.nextLong();
    	long M = sc.nextLong();
    	long ans = 0;
    	if (N == 1 && M == 1) {
    		ans = 1;
    	} else if (N == 2 || M == 2) {
    		ans = 0;
    	} else if (N == 1) {
    		ans = M - 2;
    	} else if (M == 1) {
    		ans = N - 2;
    	} else {
    		ans = (N - 2) * (M - 2);
    	}
    	System.out.println(ans);
    }
}

Measured memory_bytes: 21716
# _*_ coding:utf-8 _*_
#  Atcoder_nikkeitouitu_Contest-B
#  TODO https://atcoder.jp/contests/nikkei2019-qual/tasks/nikkei2019_qual_b
from collections import Counter

def solveProblem(strLength,strA,strB,strC):
	# 1文字目を見る→文字数をカウントする→最も多い文字が決まる→それ以外の文字を直す→n文字繰り返し
	answer = 0
	for i in range(0,strLength,+1):
		charList = [strA[i],strB[i],strC[i]]
		constructSet = set(charList) # 3つの文字の内重複しない文字の集合を出す
		constLen = len(constructSet)-1 # 集合の長さを求める＋ある一つの文字を指定して残りの文字を書き換えるため-1
		answer = answer+constLen
	return answer

if __name__ == '__main__':
	N = int(input().strip())
	A = str(input().strip())
	B =  str(input().strip())
	C = str(input().strip())
	solution = solveProblem(N,A,B,C)
	print("{}".format(solution))


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

long long n, k, a, b, r, mini = LLONG_MAX, d[2001];
vector<long long> adj[2001];
vector<pair<long long, long long> > edg;
void distance(long long node){
	for(int i = 0; i < adj[node].size(); i++){
		if(d[adj[node][i]] == -1 || d[adj[node][i]] > d[node]+1){
			d[adj[node][i]] = d[node]+1;
			distance(adj[node][i]);
		}
	}
}

int main(){
	cin >> n >> k;
	for(int i = 0; i < n-1; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
		edg.push_back(make_pair(a, b));
	}
	if(k % 2 == 0){
	    for(int i = 1; i <= n; i++){
		    memset(d, -1, sizeof(d));
		    d[i] = 0;
		    distance(i);
		    r = 0;
			for(int j = 1; j <= n; j++){
				if(d[j] > k/2) r++;
			}
			mini = min(mini, r);
		}
	} else {
	    for(int i = 0; i < n-1; i++){
	        memset(d, -1, sizeof(d));
	        d[edg[i].first] = d[edg[i].second] = 0;
	        distance(edg[i].first);
	        distance(edg[i].second);
	        r = 0;
	        for(int j = 1; j <= n; j++){
	            if(d[j] > (k-1)/2) r++;
	        }
	        mini = min(mini, r);
	    }
	}
	cout << mini;
}

Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
l = [a,b,c,d,e]
h = 0
j =[]
for i in range(0, 5):
    f = l[i] // 10
    g = l[i] % 10
    if not(g == 0):
        f = f + 1
        j.append(g)
    f = f * 10
    h = h + f
    
if not(j == []):
    h = h + min(j) -10
print(h) 

Measured memory_bytes: 3064
#include <algorithm>  //min, max, sort, unique, fill
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>  //pair, swap,
#include <vector>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using VI = vector<ll>;
using VB = vector<bool>;
using VP = vector<P>;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) for (ll i = 0; i < (n); i++)

static const ll kIntMax = numeric_limits<ll>::infinity();
static const double kFloatMax = numeric_limits<double>::infinity();

vector<ll> vi;

int main() {
  string s("ABC");
  int n;
  cin >> n;
  s[2] += n / 1000;
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<array>
#include<deque>
#include<queue>
#include<cmath>
#include<stdio.h>

using std::cout;
using std::cin;
using std::setw;
using std::setfill;
using std::string;
using std::pair;
using std::make_pair;
using std::vector;
using std::array;
using std::queue;
using std::deque;
using std::priority_queue;
using std::next_permutation;
//using std::iota;
using std::sort;
using std::greater;
using std::max;
using std::min;
using std::sin;
using std::cos;
using std::log;

using lli = long long int;
using ulli = unsigned long long int;

#define INF 999999999;
#define MOD 1000000007;
#define PI 3.141592653589793;

#define EVEL 1

#ifndef EVEL
#define dbug(X) std::cout << #X << ":" <<X<<" " ;
#define dbugf(s) std::cout << s << " ";
#define dbugln std::cout<<"\n";
#else
#define dbug(X) {}
#define dbugf(s) {}
#define dbugln {}
#endif

int n;
const double theta = 3.141592653589793/3;
array<double, 2> first = {0.0, 0.0}, second = {100.0, 0.0};
array<double, 2> a, b;
queue<array<double, 2>> lines[2];

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

	cin >> n;
	lines[0].push(first);lines[0].push(second);
	for(int i = 0; i < n; i++){
		first = lines[i%2].front();lines[i%2].pop();
		second = lines[i%2].front();lines[i%2].pop();
		double l = sqrt((second[0]-first[0])*(second[0]-first[0]) + (second[1]-first[1])*(second[1]-first[1]))/3;
		double phi = atan2(second[1]-first[1], second[0]-first[0]);
		a[0] = first[0];
		a[1] = first[1];
		b[0] = first[0] + (second[0] - first[0])/3;
		b[1] = first[1] + (second[1] - first[1])/3;
		lines[(i+1)%2].push(first);
		a = b;
		b[0] = a[0] + l * cos(phi+theta);
		b[1] = a[1] + l * sin(phi+theta);
		lines[(i+1)%2].push(a);
		a = b;
		b[0] = second[0] - (second[0] - first[0])/3;
		b[1] = second[1] - (second[1] - first[1])/3;
		lines[(i+1)%2].push(a);
		lines[(i+1)%2].push(b);
		while(!lines[i%2].empty()){
			first = second;
			second = lines[i%2].front();lines[i%2].pop();
			double l = sqrt((second[0]-first[0])*(second[0]-first[0]) + (second[1]-first[1])*(second[1]-first[1]))/3;
			double phi = atan2(second[1]-first[1], second[0]-first[0]);
			a[0] = first[0];
			a[0] = first[0];
			a[1] = first[1];
			b[0] = first[0] + (second[0] - first[0])/3;
			b[1] = first[1] + (second[1] - first[1])/3;
			lines[(i+1)%2].push(first);
			a = b;
			b[0] = a[0] + l * cos(phi+theta);
			b[1] = a[1] + l * sin(phi+theta);
			lines[(i+1)%2].push(a);
			a = b;
			b[0] = second[0] - (second[0] - first[0])/3;
			b[1] = second[1] - (second[1] - first[1])/3;
			lines[(i+1)%2].push(a);
			lines[(i+1)%2].push(b);
		}
		lines[(i+1)%2].push(second);
	}

	while(!lines[n%2].empty()){
		a = lines[n%2].front();lines[n%2].pop();
		printf("%.8lf %.8lf\n", a[0], a[1]);
	}

	return 0;
}



Measured memory_bytes: 3700
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
using namespace std;
typedef long long ll;


typedef pair<ll, pair<int, int>> P;
const ll INF = 1LL << 50;

int main(){
  int N;
  cin >> N;
  priority_queue<P, vector<P>, greater<P>> que;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      int a;
      cin >> a;
      if(i > j) que.push(P(a, pair<int, int>(i, j)));
    }
  }

  ll d[N][N];
  fill(d[0], d[N], INF);
  for(int i = 0; i < N; i++) d[i][i] = 0;

  ll ans = 0;
  while(!que.empty()){
    P p = que.top();
    que.pop();

    ll cost = p.first;
    //a > b
    int a = p.second.first;
    int b = p.second.second;

    if(d[a][b] > cost){
      //cout << a << " " << b << " " << cost << endl;
      //a-bに辺を追加
      ans += cost;
      d[a][b] = cost;
      d[b][a] = cost;
      for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
          d[i][j] = min(d[i][j], d[i][a] + cost + d[j][b]);
          d[j][i] = d[i][j];
        }
      }
    } else if(d[a][b] == cost){
      //何もしない
    } else {
      //構築不可能
      //cout << a << " " << b << " " << cost << endl;
      cout << -1 << endl;
      return 0;
    }
  }

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


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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> TUP;
#define a first
#define b second
#define sz size()
#define pb(x) push_back(x) 
#define bg begin()
#define ed end()
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define mp(x,y) make_pair(x,y)
const ll MOD=1000000007;

//a,b x
int main(){
	ll N; cin>>N;
	string s; cin>>s;
	ll lcnt=0,rcnt=0;
	rep(i,N){
		if(s[i]=='(') lcnt++;
		else{
			if(lcnt>=1) lcnt--;
			else{
				rcnt++;
			}
		}
	}
	if(rcnt>=1){
		rep(i,rcnt) cout<<'(';
	}
	cout<<s;
	if(lcnt>=1){
		rep(i,lcnt) cout<<')';
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
#define MAXN 105
#define MAXK 100005

using namespace std;
using ll = long long;

int n, k;
int A[MAXN];
ll dp[MAXN][MAXK];
ll pref[MAXN][MAXK];

ll solve(int i, int c);

void prefill(int ind) {
  if (pref[ind][0] != -1) {
    return;
  }
  for (int i = 0; i < MAXK; i++) {
    pref[ind][i] = solve(ind, i);
    if (i > 0) {
      pref[ind][i] += pref[ind][i - 1];
      pref[ind][i] %= MOD;
    }
  }
}

ll solve(int i, int c) {
  if (c < 0) {
    return 0;
  }
  if (i == n) {
    return c == 0;
  }
  ll& res = dp[i][c];
  if (res != -1LL) {
    return res;
  }
  prefill(i + 1);
  res = pref[i + 1][c];
  if (c > A[i]) {
    res += MOD - pref[i + 1][c - A[i] - 1];
    res %= MOD;
  }
  //for (int j = 0; j <= A[i]; j++) {
  //  res += solve(i + 1, c - j);
  //  res %= MOD;
  //}
  // cout << i << ' ' << c << ' ' << res << '\n';
  return res;
}

int main() {
  fill(&dp[0][0], &dp[0][0] + MAXN * MAXK, -1LL);
  fill(&pref[0][0], &pref[0][0] + MAXN * MAXK, -1LL);
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cout << solve(0, k) << '\n';
  return 0;
}


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

using ll = long long;

// sum_(i = l to r-1) a_i / (r-l) >= K
// sum >= K * r - K * l
// pref_r - pref_l >= K * r - K * l

const int MAXN = 3e5;
int N;
ll K;

ll v[MAXN];

vector<ll> vals;

int lookup(ll a) {
	return int(lower_bound(vals.begin(), vals.end(), a) - vals.begin());
}

int bit[MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N >> K;
	v[0] = 0;
	vals.push_back(v[0]);
	ll s = 0;
	for (int i = 1; i <= N; i++) {
		ll a; cin >> a;
		s += a;
		v[i] = s - K * i;
		vals.push_back(v[i]);
	}
	sort(vals.begin(), vals.end());
	vals.erase(unique(vals.begin(), vals.end()), vals.end());

	ll ans = 0;
	for (int i = 0; i <= N; i++) {
		int a = lookup(v[i]);
		for (int j = a+1; j; j -= (j & -j)) {
			ans += bit[j];
		}
		for (int j = a+1; j <= int(vals.size()); j += (j & -j)) {
			bit[j]++;
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 4336
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	string s;
	cin>>s;
	sort(all(s));
	bool h=true;
	rep(i,s.size()-1)if(s[i]==s[i+1])h=false;
	if(h)cout<<"yes"<<endl;
	else cout<<"no"<<endl;
}







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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define X first
#define Y second

using namespace std;
using ll = long long;
using P = pair<int, int>;

const double PI = 3.14159265358979;

void solve()
{
  ll n, x, y;
  cin >> n;
  vector<ll> d1(n);
  vector<ll> d2(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> x >> y;
    d1[i] = x + y;
    d2[i] = x - y;
  }
  sort(ALL(d1));
  sort(ALL(d2));
  cout << max(d1.back() - d1[0], d2.back() - d2[0]);
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 6352
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  REP(i, n) cin >> a[i];
  double c = 1, p = 0;
  REP(i, n) c *= a[i];
  REP(i, n) p += c/a[i];
  double ans = (double) c/p;
  printf("%.10lf\n", ans);

  return 0;
}

Measured memory_bytes: 256
import sys, math
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    S = input()
    T = input()
    l = []
    N, M = len(S), len(T)
    for i in range(N-M+1):
        if all(T[j] == S[i+j] or S[i+j] == '?' for j in range(M)):
            w = S[:i]+T+S[i+M:]
            w = w.replace('?', 'a')
            l.append(w)
    if l:
        print(sorted(l)[0])
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Measured memory_bytes: 62524
#include <bits/stdc++.h>
#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--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main(){
    ll N, M, K;
    cin >> N >> M >> K;

    ll A[N], B[M], a[N+1], b[M+1];
    a[0] = 0; b[0] = 0;
    REP(i, N){
        cin >> A[i];
        a[i+1] = a[i] + A[i];
    }
    REP(i, M){
        cin >> B[i];
        b[i+1] = b[i] + B[i];
    }

    ll j = M, ans = 0;
    REP(i, N+1){
        if(a[i] > K){
            break;
        }

        while (b[j] > K - a[i]){
            j--;
        }

        ans = max(ans, i+j);
        
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9848
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdio>
#include<utility>
#include<set>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
#define all(L) L.begin(),L.end()
using ll=long long;
#define RO 1
#define SI 2
#define PA 3

int N,K;
string S,T;

void dfs(int m,int bits,int &count){
    if(m>N) return;
    if(bits==0b111) count++;
    dfs(10*m+7,bits|0b100,count);
    dfs(10*m+5,bits|0b010,count);
    dfs(10*m+3,bits|0b001,count);
}

int main(){
    string s;cin>>s;
    int n=s.size();
    ll ans=0;
    for(int bits=0;bits<(1<<(n-1));bits++){
        int st=0;
        for(int i=0;i<n;i++){
            if(((bits>>i)&1||i==n-1)){
                ans+=stoll(s.substr(st,i+1-st).c_str());
                st=i+1;
            }
        }
    }
    cout<<ans<<endl;
}   




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

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

#define F first
#define S second

typedef pair<li, li> PI;
map<PI, li> cnt;

int main(void)
{
	string a, b;
	cin >> a >> b;
	if (a == "D") {
		cout << (b == "D" ? "H" : "D") << endl;
	} else {
		cout << (b == "D" ? "D" : "H") << endl;
	}

	return 0;
}

Measured memory_bytes: 3604
/*      ###########################
        #  Author : Pranay Garg   #
        #  College : SGSITS       #
        ###########################
*/      
#include<bits/stdc++.h>
#define ll long long int
#define ironman ios_base::sync_with_stdio(false);cin.tie(NULL);
#define MOD 1000000007
#define endl '\n'
#define INF 1e18L+1
using namespace std;
void fastio()
{
    ironman
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
        freopen("error.txt","w",stderr);
    #endif
}
ll parent[100005];
ll find(ll a)
{
    std::vector<ll> v;
    while(parent[a]>0)
    {
        v.push_back(a);
        a = parent[a];
    }
    for(ll i=0;i<v.size();i++)
        parent[v[i]] = a;
    return a;
}
bool prime[100005];
void SieveOfEratosthenes(int n) 
{  
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
}  
void union1(ll a, ll b)
{
    a = find(a);
    b = find(b);
    if(a!=b)
    {
        parent[a] = min(parent[a],parent[b]);
        parent[b] = a;
    }
}  
// ll h,w;
// char arr[1002][1002];
// ll dp[1002][1002];
// void solve(ll i,ll j,ll &count)
// {
//     //cout << i << " " << j << endl;
//     if(i>=h||j>=w)
//         return;
//     if(i==h-1 && j==w-1)
//     {
//         //cout << "hii" << endl;
//         count = (count%MOD+1)%MOD;
//         return;
//     }
//     if(arr[i][j]=='#')
//         return;
//     else
//     {
//         solve(i+1,j,count);
//         solve(i,j+1,count);
//     }
// }
int main()
{
    //fastio();
    ll h,w;
    cin >> h >> w;
    char arr[h][w];
    ll dp[h][w];
    memset(dp,0,sizeof(dp));
    // dp[i][j] represents number of ways to reach i,j;
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            cin >> arr[i][j];
        }
    }
    dp[0][0] = 1;
    for(ll i=0;i<h;i++)
    {
        for(ll j=0;j<w;j++)
        {
            if(i==0 && j==0)
                continue;
            if(arr[i][j]=='#')
                continue;
            if(i==0)
            {
                dp[i][j] = dp[i][j-1]%MOD;
            }
            else if(j==0)
            {
                dp[i][j] = dp[i-1][j]%MOD;
            }
            else
            {
                // if(arr[i-1][j]=='.')
                    dp[i][j]+=dp[i-1][j]%MOD;
//                if(arr[i][j-1]=='.')
                    dp[i][j]+=dp[i][j-1]%MOD;
            }
        }
    }
    // for(ll i=0;i<h;i++)
    // {
    //     for(ll j=0;j<w;j++)
    //     {
    //         cout << dp[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[h-1][w-1]%MOD << endl;
}

Measured memory_bytes: 9088
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;
#define rep(i,s,e) for(int i = (s);i <= (e);i++)


i64 n;
i64 k;

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

    i64 result = 0;

    if(k == 0)
    {
        cout << n * n << endl;
        return 0;
    }

    for(i64 b = k + 1;b <= n;b++)
    {
        i64 one = b - k;
        i64 cou = (n - k) / b;

        result += cou * one;

        i64 a = k + b * cou;
        result += min(n - a + 1, b * cou + b - a);
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdint>

using Int = std::int64_t;

Int solve(Int x) {
	if (x == 1)
		return 1;
	else
		return 1 + solve(x / 2) * 2;
}

int main() {
	Int h;
	std::cin >> h;

	std::cout << solve(h) << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <stdbool.h>
//#include <limits.h>
//#include <math.h>

typedef struct StrCnt{
  char *s;
  int cnt;
} Str;

//昇順
int des_acs(const void *a, const void *b)
{
  if (((Str *)a)->cnt == ((Str *)b)->cnt)
    return strcmp((((Str *)a)->s), (((Str *)b)->s));
  else
    return ((Str *)b)->cnt - ((Str *)a)->cnt;
}

//降順
int des(const void *a, const void *b)
{
  return strcmp((char *)b, (char *)a);
}

int main() {
  int n;
  scanf("%d\n", &n);
  char s[n][15];
  for (int i=0; i<n; i++)
    scanf("%s", s[i]);
  qsort(s, n, sizeof(char)*15, des);
  //for (int i=0; i<n; i++) printf("%s\n", s[i]);
  Str cnt[n];
  cnt[0].s = s[0];
  cnt[0].cnt = 1;
  int j = 0;
  for (int i=1; i<n; i++) {
    if (strcmp(s[i], cnt[j].s)) {
      j++;
      cnt[j].s = s[i];
      cnt[j].cnt = 1;
    } else {
      cnt[j].cnt++;
    }
  }
  j++;
  qsort(cnt, j, sizeof(Str), des_acs);
  int max = cnt[0].cnt, k = 0;
  while (cnt[k].cnt == max && k<j) {
    printf("%s\n", cnt[k].s);
    k++;
  }
  return 0;
}


Measured memory_bytes: 9352
#include <bits/stdc++.h>
using namespace std;
int N; 
long long A[110]; 
long long INF = 1145141919810364; 
struct edge{
	int to; 
	long long cap;
	int rev; 
}; 
vector<edge> E[110]; // 0がS, [1,N]が宝石, N+1がT
int level[110]; 
int iter[110]; 
void add_edge(int from, int to, long long cap){
	E[from].push_back((edge){to, cap, (int) E[to].size()}); 
	E[to].push_back((edge){from, 0, (int) E[from].size()-1}); 
}
void bfs(int s){
	fill(level, level + N+2, -1); 
	queue<int> que; 
	level[s] = 0; 
	que.push(s); 
	while(que.size()){
		int v = que.front(); que.pop(); 
		for(auto i : E[v]){
			edge &e = i; 
			if(e.cap > 0 && level[e.to] < 0){
				level[e.to] = level[v] + 1; 
				que.push(e.to); 
			}
		}
	}
}
long long dfs(int v, int t, long long f){
	if(v == t) return f; 
	for(int &i = iter[v]; i < (int) E[v].size(); i++){
		edge &e = E[v].at(i); 
		if(e.cap > 0 && level[v] < level[e.to]){
			long long d = dfs(e.to, t, min(f, e.cap)); 
			if(d > 0){
				e.cap -= d; 
				E[e.to].at(e.rev).cap += d; 
				return d; 
			}
		}
	}
	return 0; 
}
long long max_flow(int s, int t){
	long long flow = 0; 
	while(1){
		bfs(s); 
		if(level[t] < 0) return flow; 
		fill(iter, iter + N+2, 0); 
		long long f; 
		while((f = dfs(s, t, INF)) > 0){
			flow += f; 
		}
	}
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> N;
	long long mx = 0; 
	for(int i = 1; i <= N; i++){
		cin >> A[i];
		if(A[i] > 0) mx += A[i]; 
		if(A[i] >= 0){
			add_edge(0, i, A[i]); 
			add_edge(i, N+1, 0); 
		}else{
			add_edge(0, i, 0); 
			add_edge(i, N+1, -A[i]); 
		}
	}
	for(int i = 1; i <= N; i++){
		for(int j = i+1; j <= N; j++){
			if(j % i) continue; 
			add_edge(j, i, INF); 
		}
	}
	long long ans = max_flow(0, N+1); 
	cout << mx - ans << "\n"; 
}

Measured memory_bytes: 3624
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<long> bs;
  for (int i = 1; i <= N; ++i) {
    long tmp;
    cin >> tmp;
    bs.push_back(tmp - i);
  }
  sort(bs.begin(), bs.end());

  long median = 0;
  median = bs[N / 2];

  long f = 0;
  for (auto &e : bs) {
    f += abs(e - median);
  }
  cout << f << endl;
  return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int n, h, w;
  cin>>n>>h>>w;
  int a, b;
  int ans=0;
  REP(i, n){
    cin>>a>>b;
    if(a>=h && b>= w) ++ans;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
bool f[15][1005];
int n,m,sum[15],co[15],ans=1e9,k;
void check(int t){
	FILL(sum,0);
	bool anf;
	FOR(i,1,m){
		anf=0;
		FOR(j,1,n){
			sum[co[j]]+=f[j][i];
			if(sum[co[j]]>k){
				anf=1;break;
			}
		}
		if(anf){
			FILL(sum,0);
			FOR(j,1,n){
				sum[co[j]]+=f[j][i];
				if(sum[co[j]]>k)RE;
			}
			t++;
		}
	}
	gmin(ans,t);
}
void dfs(int p){
	if(p==n+1){
		check(co[n]-1);RE;
	}
	co[p]=co[p-1];
	dfs(p+1);
	co[p]=co[p-1]+1;
	dfs(p+1);
}
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>m>>k;
	char c;
	FOR(i,1,n){
		FOR(j,1,m){
			cin>>c;
			f[i][j]=c-'0';
		}
	}
	co[1]=1;
	dfs(2);
	cout<<ans;
	RE 0;
}




Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int[] n = Input.Line<int[]>();
        Array.Sort(n);
        Console.WriteLine((n[0]*n[1])/2);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(0);
    }
    public static T Line<T>()
    {
        foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        int c = queue.Count();
        if (typeof(T) == typeof(int[]))
        {
            int[] ret = new int[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<int>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(long[]))
        {
            long[] ret = new long[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<long>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(string[]))
        {
            string[] ret = new string[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<string>();
            return (T)(object)ret;
        }
        else if (typeof(T) == typeof(double[]))
        {
            double[] ret = new double[c];
            for (int i = 0; i < c; i++) ret[i] = Cin<double>();
            return (T)(object)ret;
        }
        else return (T)(object)(0);
    }
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}

void solve() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    cout << min(a, b)+min(c, d);
}

int main() {
    init();
    int t = 1; //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, K;
  int R, S, P;
  string T;
  cin >> N >> K;
  cin >> R >> S >> P;
  cin >> T;
  i64 score = 0;
  F0R(i, N) {
    if (i >= K && T[i - K] == T[i]) {
      T[i] = '*';
      continue;
    }
    score += T[i] == 'r' ? P : T[i] == 's' ? R : S;
  }
  cout << score;
}
#endif


Measured memory_bytes: 512
#include <iostream>
#include <string>

int main()
{
	std::string N;

	std::cin >> N;

	long long answer=0;
	for (const auto& str:N)
	{
		switch (str)
		{
		case '1':
			answer += 1;
			break;
		case'2':
			answer += 2;
			break;
		case'3':
			answer += 3;
			break;
		case'4':
			answer += 4;
			break;
		case'5':
			answer += 5;
			break;
		case'6':
			answer += 6;
			break;
		case'7':
			answer += 7;
			break;
		case'8':
			answer += 8;
			break;
		case'9':
			answer += 9;
			break;
		case'0':
			answer += 0;
			break;

		default:
			break;
		}
	}

	if (answer % 9 == 0)
	{
		std::cout << "Yes" << std::endl;
	}
	else
	{
		std::cout << "No" << std::endl;
	}
}



Measured memory_bytes: 3376
import java.util.*;

public class Main{
   public static void main(String[] args) {
	  Scanner sc =new Scanner(System.in);
for(;;){
int []p=new int[2];
int n=sc.nextInt();
if(n==0)break;
for(;n>0;n--){
	  int a=sc.nextInt();
	  int b=sc.nextInt();
	  if(a>b)p[0]+=a+b;
	  else if(a<b)p[1]+=a+b;
	  else for(int i=0;i<2;i++)p[i]+=a;
  }
System.out.println(p[0]+" "+p[1]);
  }
}
   }

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

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

  int ans = 0;
  for ( int i = 1; i <= n; i++ ) {
    ans += b[a[i]];
    if ( i != n && a[i+1] == a[i]+1 ) { ans += c[a[i]]; }
  }

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


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, r;
    cin >> n >> r;
    cout << (n >= 10 ? r : r + 100 * (10 - n)) << '\n';
    return 0;
}


Measured memory_bytes: 256
main :: IO ()
main = do
  [a, b] <- map read . words <$> getLine
  s <- getLine
  let validLength = length s == a + b + 1
  let validHyphen = s !! a == '-'
  let validChar = not (any (not . (`elem` "0123456789")) (take a s ++ drop (a + 1) s))
  putStrLn $ if validLength && validHyphen && validChar then "Yes" else "No"

Measured memory_bytes: 508
import math
import numpy
time = input().split()
short = int(time[2])
longs = int(time[3])

short_niddle = (short*60 + longs)*360/(12*60)
long_niddle = longs*360/60


angle = abs(short_niddle-long_niddle)
if 180 <= angle:
    angle = 360 - angle
a = int(time[0])
b = int(time[1])

co = math.cos(math.radians(angle))
kotae = a**2 + b**2 -2*a*b*co
print(math.sqrt(kotae))

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

#define ll long long
#define REP(x,a,b) for(int x=a;x<=b;x++)
#define rep(x,n) for(int x=0;x<n;x++)
#define cint(x) int x;cin>>x;
#define cins(x) string x;cin>>x;
#define pb push_back
#define repv(x,v) for(int x=0;x<v.size();x++)
typedef pair<int,int> P;

int main(){
	
	for(int n;cin>>n,n;){
		vector<int>f;
		vector<int>v;
		rep(i,n){
			cins(s);
			if(s=="x"){
				f.pb(1);
				v.pb(0);
			}
			else{
				f.pb(0);
				stringstream ss;
				ss<<s;
				int t;
				ss>>t;
				v.pb(t);
			}
		}
		int flg=0;
		for(int i=0;i+1<f.size();i++)if(f[i]&&f[i+1])flg=1;
		if(flg){
			cout<<"none"<<endl;
			continue;
		}
		int mn=-1145141919;
		int mx=1145141919;
		for(int i=0;i+1<v.size();i++){
			if(i%2){//2,4,6,
				if(f[i]){
					mn=max(mn,v[i+1]+1);
				}
				else if(f[i+1]){
					mx=min(mx,v[i]-1);
				}
				else if(v[i]<=v[i+1]){
					flg=1;
				}
			}
			else{//1,3,5,
				if(f[i]){
					mx=min(mx,v[i+1]-1);
				}
				else if(f[i+1]){
					mn=max(mn,v[i]+1);
				}
				else if(v[i]>=v[i+1]){
					flg=1;
				}
			}
		}
		if(flg){
			cout<<"none"<<endl;
			continue;
		}
		if(mx>mn){
			cout<<"ambiguous"<<endl;
			continue;
		}
		if(mx==mn){
			cout<<mx<<endl;
			continue;
		}
		if(mx<mn){
			cout<<"none"<<endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 1260
using System;
public class hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        var inning = 1;
        var outcount = 0;
        var runners = 0;
        var runs = 0;
        while (inning <= n)
        {
            var cmd = Console.ReadLine().Trim();
            switch (cmd)
            {
                case "HIT":
                    if (runners == 3) runs++;
                    else runners++;
                    break;
                case "HOMERUN":
                    runs += runners + 1;
                    runners = 0;
                    break;
                case "OUT":
                    if (outcount == 2)
                    {
                        Console.WriteLine(runs);
                        runs = 0;
                        outcount = 0;
                        runners = 0;
                        inning++;
                    }
                    else outcount++;
                    break;
            }
        }
    }
}

Measured memory_bytes: 9208
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

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

using namespace std;

int main(){
	int N;
	cin >>N;
	int A[100001],B[100001];
	rep(i,N+1)cin >> A[i];
	rep(i,N)cin >> B[i];
	B[N+1] =0;

	long long sum=0;
	rep(i,N)sum+=B[i];

	int a=0,b;
	rep(i,N+1){
		b = A[i]-a;
		if(b<0)sum +=b,b=0;
		a = B[i] - b;
		if(a <0)a =0;
	}
	cout <<sum;
}

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

int main() {
  ll a, b, x;
  cin >> a >> b >> x;
  ll ans = b/x;
  if(a%x==0) ans -= a/x-1;
  else ans -= a/x;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string>
using namespace std;
int main(void){
    string S;
    cin >> S;
    char a,b;
    int count[2] = {0};
    for(int i=0;i<S.size();i++){
        if(i == 0){
            a = S[i];
            count[0]++;
            continue;
        }
        if(S[i] == a){
            count[0]++;
        }
        else{
            if(count[1] == 0){
                b = S[i];
                count[1]++;
            }
            else if(S[i] == b){
                count[1]++;
            }
        }
    }
    if(count[0] == 2 && count[1] == 2){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
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; }
 
int main()
{
    int n, k; cin >> n >> k;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    set<int> s;
    vector<int> num(k+1, 0);
    int left = 0, right=0, ans = INF;

    while(left < n && right <= n){
        while(s.size()<k){
            right++;
            if(right>n) break;
            if(a[right-1] <= k) {
                num[a[right-1]]++;
                s.insert(a[right-1]);
            }
        }
        
        if(left==0 && right==n+1 && s.size()<k){
            ans = 0;
            break;
        }
        if(s.size()<k) break;

        chmin(ans, right-left);
        // printf("left=%d right=%d, %d\n", left, right, ans);
        while(left<=right){
            left++;
            if(a[left-1] <= k){
                num[a[left-1]]--;
                if(num[a[left-1]]==0){
                    s.erase(a[left-1]);
                    break;
                }
            }
            chmin(ans, right-left);
        }
        // printf("left=%d right=%d, %d\n", left, right, ans);
    }
    pr(ans);
    return 0;}


Measured memory_bytes: 8280
x,y = map(int,input().split())
if(x+y==2):
  print(1000000)
else:
  answer = 0
  if(x==2):
    answer+=200000
  elif(x==3):
    answer+=100000
  elif(x==1):
    answer+=300000
  if(y==2):
    answer+=200000
  elif(y==3):
    answer+=100000
  elif(y==1):
    answer+=300000
  print(answer)


Measured memory_bytes: 9120