akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

int main(void)
{
  int N;
  scanf("%d", &N);

  int i,j,k;
  for(i=0; i<N; ++i){

    int digits[2][80];
    for(j=0; j<2; ++j){
      for(k=0; k<80; ++k){
        digits[j][k] = 0;
      }
    }

    int overflow = 0; 

    for(j=0; j<2; ++j){
      char digit[256];
      scanf("%256s", digit);
      getchar();
      
      if(overflow || strlen(digit)>80){
        overflow = 1;
      }else{
        for(k=0; k<strlen(digit); ++k){
          digits[j][k] = digit[strlen(digit)-1-k]-'0';
        }
      }
    }

    if(!overflow){
      int sum[81];
      for(j=0; j<81; ++j){
        sum[j] = 0;
      }

      for(j=0; j<80; ++j){
        for(k=0; k<2; ++k){
          sum[j] += digits[k][j];
        }
        sum[j+1] += sum[j]/10;
        sum[j] %= 10;
      }

      if(sum[80]>0){
        overflow = 1;
      }else{
        int available = 0;
        for(j=80; j>=0; --j){
          if(available || sum[j]!=0 || j==0){
            available = 1;
            printf("%d", sum[j]);
          }
        }
        printf("\n");
      }
    }

    if(overflow){
      printf("overflow\n");
    }
  }

  return 0;
}

Measured memory_bytes: 0
//C++14 (Clang 3.8.0)

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

int main(){
    string S,C;
    cin>>S;
    int ans=0,s=0,t=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='T') {if(s>0){s--;}else ans++; }
        if(S[i]=='S') {s++;}
    }
    cout<<ans+s<<endl;
    return 0;
};


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

double kai(ll n){
    ll a = 1;
    for (int i = 1; i <= n; i++) {
        a*=i;
    }
    return a;
}
int permutationMethod(int n,int r){
    r = n - r;
    int sum = 1;
    int i;
    for (i=n;i>=r+1;i--)sum*=i;
    return sum;
}
double are(ll n){
    ll a = 0;
    for (int i = 0; i <= n-2; i++) {
        a += permutationMethod(n-2,i)*kai(n-2-i);
    }
    return a*2;
}

int main() {
    ll n;
    vector<ll> x(10);
    vector<ll> y(10);
    double sum = 0;
    std::cin >> n;
    for (int i = 0; i < n; i++) {
        std::cin >> x[i] >> y[i];
    }
    for (int i = 0; i < n; i++) {
        for (int j = i+1; j < n; j++) {
            sum += sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
            
        }
    }
    if(n==2){
       std::cout <<setprecision(10) << sum << std::endl;
        return 0;
    }
    std::cout <<setprecision(10)<< sum*are(n)/kai(n) << std::endl;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<deque>
#include<queue>
using namespace std;

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

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

int main()
{
  ll n, d;
  cin >> n >> d;
  int res = 0;
  rep (i, n) {
    ll x, y;
    cin >> x >> y;
    if (d * d >= x * x + y * y) {
      res++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 3620
# (c) midandfeed
while(1):
	m, f, r = [int(x) for x in input().split()]
	if(m+f+r == -3):
		break
	else:
		temp = m+f
		if( (m==-1) or (f==-1) ):
			print("F")
		elif (temp >= 80):
			print("A")
		elif (temp >= 65):
			print("B")			
		elif (temp >= 50):
			print("C")		
		elif (temp >= 30):
			if (r >= 50):
				print("C")
			else:
				print("D")
		else:
			print("F")
			

Measured memory_bytes: 7800
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		
		for(long i = 0 ; i <= 1000 ;i++) {
			for(long j = -1000 ; j <= 1000 ; j++) {
				long A = (long)Math.pow(i,5);
				long B = (long)Math.pow(j,5);	
				if(A <= B) {
					continue;
				}
				if(A - B == n) {
					System.out.println(i +" "+ j);
					return;
				}
				}
		}
	

	}

}


Measured memory_bytes: 38888
function Main(input) {
    var N = parseInt(input[0], 10);
    var Y = parseInt(input[1], 10);

    for (var a = 0; a <= N; a++) {
        for (var b = 0; (a + b) <= N; b++) {
            var c = N - a - b;
            var total = a * 10000 + b * 5000 + c * 1000;
            if (total === Y) {
                console.log(`${a} ${b} ${c}`);
                return;
            }
        }
    }
    console.log('-1 -1 -1');
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 11468
#include <cstdio>
int a[205], n;
bool check() {
    for(int i = 1; i <= n; i++)
        if(a[i] & 1) return false;
    return true;
}
int main() {
    int cnt = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) 
        scanf("%d", &a[i]);
    while(check()) {
        cnt ++;
        for(int i = 1; i <= n; i++) a[i] /= 2;
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
d="zyxwvutsrqponmlkjihgfedcba"
s=input()
if s=="zyxwvutsrqponmlkjihgfedcba":print(-1)
else:
    if len(s)!=26:
        for i in range(1,1+26):
            if d[-i] not in s:print(s+d[-i]);exit()
    else:
        from bisect import bisect_left as bl,bisect_right as br
        de=[s[-1]]
        for i in range(2,27):

            if de[-1]<s[-i]:de.append(s[-i])
            else:print(s[:-i]+de[bl(de,s[-i])]);exit()

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

using namespace std;

#define ll long long

signed main() {
	int n;
	cin >> n;
	vector<pair<ll, ll>> tasks(n);
	for (int i = 0; i < n; i++) {
		cin >> tasks[i].second >> tasks[i].first;
	}

	sort(tasks.begin(),tasks.end()); // 締め切りの早い順にソート
	ll t = 0; // 現在時刻
	for (int i = 0; i < n; i++) {
		t += tasks[i].second; // task[i]をこなす
		if (t > tasks[i].first) { // 締め切りを超えたらNo
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 3328
#light "off"
open System;;
open System.IO;;

let reader = new StreamReader(new BufferedStream(Console.OpenStandardInput ()))
let writer = new StreamWriter(new BufferedStream(Console.OpenStandardOutput ()))

let skipSpaces () = while reader.Peek () <= int ' ' do reader.Read () |> ignore done;;
let read f = skipSpaces (); [|while reader.Peek () > int ' ' do yield char (reader.Read ()) done |] |> System.String |> f;;
let readint () = skipSpaces (); let mutable ans = 0 in while reader.Peek () > int ' ' do ans <- ans * 10 + (reader.Read () - int '0'); done; ans;;
let write (s : string) = writer.Write s;;
let writeln (s : string) = writer.WriteLine s;;

let rec keta n = if n = 0 then 0 else 1 + keta (n / 10);;
let N = readint ();;
{1..N} |> Seq.filter (fun x -> keta x % 2 = 1) |> Seq.length |> printfn "%d";

reader.Close();;
writer.Close();;

Measured memory_bytes: 14044
#include<iostream>
#include<algorithm>

using namespace std;

typedef long long ll;

#define rep(i,n) for(ll i=0;i<(n);i++)
#define INF (1e12)

ll V,E;
ll G[100][100];

int main() {
    cin >> V >> E;
    rep(i,V)rep(j,V)G[i][j] = INF;
    rep(i,V)G[i][i] = 0;

    rep(i,E) {
        ll s,t,d;
        cin >> s >> t >> d;
        G[s][t] = d;
    }


    rep(k,V) {
        rep(i,V) {
            rep(j,V)
                G[i][j] = min(G[i][j],G[i][k] + G[k][j]);
        }
    }

    rep(i,V) {
        if(G[i][i] != 0){
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    rep(i,V) {
        rep(j,V) {
            if(G[i][j] < INF / 2)cout << G[i][j];//負の辺があるとINFより小さくなることがある
            else cout << "INF";
            cout << ((j < V - 1) ? " " : "");
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3172
/*input
998244353 99824435
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<int,int>
#define f first
#define s second
#define pb emplace_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define sz(_a) (ll)(_a.size())
#define FILL(n) memset(n,0,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
const ll maxn=100005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int arr[maxn];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b;
    cin>>a>>b;
    if((a+b)%2!=0) cout<<"IMPOSSIBLE";
    else cout<<(a+b)/2;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
template <typename T> void max_self(T& a, T b) {
    a = max(a, b);
}
 
// dp[n][m]
 
bool first_row_or_column(pair<int,int> p) {
    return p.first == 0 || p.second == 0;
}
 
const int INF = 1e9 + 5;
 
int main() {
    string a, b;
    cin >> a >> b;
    vector<vector<pair<int,pair<int,int>>>> dp(a.length() + 1,
        vector<pair<int,pair<int,int>>>(b.length() + 1, {-INF,{0,0}}));
    dp[0][0] = {0, {0,0}};
    // dp[i][j] - the max total length so far
    for(int i = 0; i < (int) a.length(); ++i) {
        for(int j = 0; j < (int) b.length(); ++j) {
            if(a[i] == b[j]) {
                max_self(dp[i+1][j+1], make_pair(dp[i][j].first + 1, make_pair(i,j)));
            }
            max_self(dp[i+1][j], make_pair(dp[i][j].first, make_pair(i,j)));
            max_self(dp[i][j+1], make_pair(dp[i][j].first, make_pair(i,j)));
        }
    }
    pair<int,pair<int,int>> answer = {0,{0,0}};
    for(int i = 0; i <= (int) a.length(); ++i) {
        for(int j = 0; j <= (int) b.length(); ++j) {
            max_self(answer, make_pair(dp[i][j].first, make_pair(i, j)));
        }
    }
    string s;
    pair<int,int> cur = answer.second;
    while(!first_row_or_column(cur)) {
        int i = cur.first;
        int j = cur.second;
        pair<int,int> previous = dp[i][j].second; // a cell from which we came to (i,j)
        
        if(previous == make_pair(i - 1, j - 1)) {
            assert(a[i-1] == b[j-1]);
            s += a[i-1];
        }
        cur = previous;
    }
    
    reverse(s.begin(), s.end());
    cout << s << endl;
}



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

int main() {
  string S,T,U;
  cin >> S >> T >> U;
  
  cout << char(S.at(0) - 'a' + 'A') << char(T.at(0) - 'a' + 'A') << char(U.at(0) - 'a' + 'A') <<endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        System.out.println(Math.max(0, a - 2 * b));
    }
}


Measured memory_bytes: 21972
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
xyc = [list(map(int,input().split())) for _ in range(M)]

ans = min(a) + min(b)

for x,y,c in xyc:
  ans = min(ans, a[x-1]+b[y-1]-c)

print(ans)

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

int main(){
    int A,B;cin >> A >> B;
    if(A <= 9 && B <= 9)cout << A * B << endl;
    else cout << -1 << endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int n;
  scanf("%d",&n);

  int c[500];
  int s[500];
  int f[500];

  for(int i = 0; i < n-1; ++i){
    scanf("%d %d %d",&c[i], &s[i], &f[i]);
  }
  int time;
  for(int j = 0; j < n ; ++j){
    time = 0;
    for(int i = j; i < n-1; ++i){
      int tmp_s = s[i];
      if(time < s[i]){
        time = s[i] + c[i];
      }else{
        while( tmp_s < time ){
          tmp_s += f[i];
        }
      time = tmp_s + c[i];
      }
    }
    printf("%d\n",time);
  }

  return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

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

Measured memory_bytes: 256
n = int(input())
table = {}
for i in range(n):
    a = int(input())
    table[i] = a-1

is_visited = [ False for _ in range(n) ]
is_visited[0] = True

cnt = 0
now = 0
while True:
    is_visited[now] = True
    if now == 1:
        print(cnt)
        break
    nxt = table[now]
    if is_visited[nxt]:
        print(-1)
        break
    now = nxt
    cnt += 1

Measured memory_bytes: 17892
'use strict';
(function(stdin) {
    var inputs = stdin.toString();
    var cols = inputs.split('\n')[0].split(' ').map(Number);
    var a = cols[0];
    var b = cols[1];
    if (a < b) {
        console.log('a < b');
    }else if(a > b){
        console.log('a > b');
    }if (a == b) {
        console.log('a == b');
    }
   }(require('fs').readFileSync('/dev/stdin', 'utf8')));

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

int main(){
  
  int n,l;
  cin>>n>>l;
  
  int sum = n*l - n + (n*(n+1))/2;
  if(l>=0)
    cout<<sum-l;
  else if(sum<0){
   cout<<sum-(l+n-1); 
  }
  else if(l==0)
    cout<<sum;
  else if(l<0 &&  sum>=0)
    cout<<sum;
 
  return 0;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;




void _main() {
        for (int i = 1; i <= 5; i++) {
                int x; cin >> x;
                if (x == 0) {
                        cout << i;
                        return;
                }
        }
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}

Measured memory_bytes: 3604
def min_item_num(weights, num_item, num_vehicle, capacity):
    item_idx = 0
    for _ in range(num_vehicle):
        load = 0
        while load + weights[item_idx] <= capacity:
            load += weights[item_idx]
            item_idx += 1
            if item_idx == num_item:
                return num_item
    return item_idx


def main():
    num_item, num_vehicle = list(map(int, input().split(" ")))
    weights = [int(input()) for _ in range(num_item)]
    left = 0
    right = 10000 * 100000
    while right - left > 1:
        center = (left + right) // 2
        min_item = min_item_num(weights, num_item, num_vehicle, center)
        if num_item <= min_item:
            right = center
        else:  # min_vehicle > num_item:
            left = center
    print(right)


if __name__ == "__main__":
    main()



Measured memory_bytes: 9560
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <vector>
#define ll long long int
#define mp make_pair
#define pb push_back
#define vi vector<int>
using namespace std;
struct objects{
    int weight,value;
};
ll solve(){
   int n,w;
   cin>>n>>w;
   objects object[n];
   int totalvalue=0;
   for(int i=0;i<n;i++){
       cin>>object[i].weight>>object[i].value;
       totalvalue+=object[i].value;
   }
   ll dp[totalvalue+1];
   dp[0]=0;
   int ans=0;
   for(int i=1;i<=totalvalue;i++){
       dp[i]=1e18;
   }
   for(int i=0;i<n;i++){
       for(int j=totalvalue;j>=0;j--){
           if(j>=object[i].value){
                dp[j]=min(dp[j],dp[j-object[i].value]+object[i].weight);
           }
           if(dp[j]<=w){
               ans=max(ans,j);
               
           }
       }
   }
   return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);;
    cout<<solve();
}


Measured memory_bytes: 4360
import java.util.Scanner; 
 public class Main {
    public static void main(String[] args) {     
         Scanner sc = new Scanner(System.in);
              int w = sc.nextInt();
                int n = sc.nextInt();
                int[] values = new int[w];
         for (int i = 0; i < values.length; i++) {
          values[i] = i + 1;
                 }
         for (int i = 0; i < n; i++) {
         String str = sc.next();
         String[] ab = str.split(",");
         int a = Integer.parseInt(ab[0]) - 1;
         int b = Integer.parseInt(ab[1]) - 1;
         int j = values[a];
          values[a]= values[b];
          values[b]= j;     
         }
         for(int i=0;i<values.length; i++){
         	System.out.println(values[i]);
         }   
                                } 
                            } 

Measured memory_bytes: 25980
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int h[n+1];
	for(int i=1;i<=n;i++)
	cin>>h[i];
	
	 int dp[n+1];
	  FILL(dp,n+1,1e9+10);
	dp[1]=0;
	for(int i=1;i<=n;++i){
    for(int j=1;j<=k;j++)
    {
    	int temp=dp[i]+abs(h[i+j]-h[i]);
    	if(i+j<=n)
    	chmin(dp[i+j],temp);
    }
  }

	cout<<dp[n]<<"\n";
	
	return 0;
}

Measured memory_bytes: 4348
// AOJ 1165 "角角画伯，かく悩みき" (ICPC国内予選 2010 Problem A)
#include <iostream>
#include <vector>
#include <climits>

using namespace std;

int main() {
    while (true) {
        int N;
        vector<pair<int, int> > s;
        pair<int, int> p;
        cin >> N;
        if (N == 0) {
            break;
        }
        p.first = p.second = 0;
        s.push_back(p);
        int xsize, ysize;
        int xmax = 0;
        int xmin = 0;
        int ymax = 0;
        int ymin = 0;
        for (int i = 1; i < N; i++) {
            int dx[] = {-1, 0, 1, 0};
            int dy[] = {0, -1, 0, 1};
            int n, d;
            cin >> n >> d;
            int x = s[n].first + dx[d];
            int y = s[n].second + dy[d];
            p.first = x;
            p.second = y;
            s.push_back(p);
            xmax = max(xmax, x);
            xmin = min(xmin, x);
            ymax = max(ymax, y);
            ymin = min(ymin, y);
        }
        xsize = xmax - xmin + 1;
        ysize = ymax - ymin + 1;
        cout << xsize << " " << ysize << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
    vector<int> vec;
    int n,k;
    cin>>n>>k;
    int p;
    rep(i,n){
        cin>>p;
        vec.push_back(p);
    }
    sort(vec.begin(),vec.end());
    int sum=0;
    rep(i,k){
        sum+=vec[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


a,b,k = map(int, input().split())

if b-a+1 <= 2*k:
  for i in range(a,b+1):
    print(i)
else:
  for i in range(a,a+k):
    print(i)
  for i in range(b-k+1,b+1):
    print(i)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n)cin >> a[i];
    ll ans = 0;
    ll mx = a[0];
    rep(i, n){
        if(mx > a[i]){
            ans += mx - a[i];
        }else if(mx < a[i]){
            mx = a[i];
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 1e5 + 5;

ll v[MAXN];
ll dpa[MAXN], dpb[MAXN];

void solve(){
	int n;
	ll a, b;
	scanf("%d%lld%lld", &n, &a, &b);
	if (a > b){
		swap(a, b);
	}
	REPN(i, 1, n){
		scanf("%lld", &v[i]);
	}
	dpa[1] = dpb[1] = 1;
	int last = -1;
	for(int i = 2, j = 1; i <= n; i++){
		if (i > 2 && v[i] - v[i - 2] < a){
			printf("0\n");
			return;
		}
		
		if (v[i] - v[i - 1] < a){
			dpa[i] = dpb[i - 1];
		} else {
			dpa[i] = (dpa[i - 1] + dpb[i - 1]) % MOD;
		}
		
		for(; v[i] - v[j] >= b; j++);
		if (j == 1){
			if (last == -1){
				dpb[i] = 1;
			}
		} else {
			if (last <= j){
				dpb[i] = dpb[j - 1];
				if (last < j){
					dpb[i] = (dpb[i] + dpa[j - 1]) % MOD;
				}
			}
			
		}
		
		if (v[i] - v[i - 1] < a){
			last = i;
		}
	}
	
	/*REPN(i, 1, n){
		printf("%lld %lld\n", dpa[i], dpb[i]);
	}*/
	
	ll ans = (dpa[n] + dpb[n]) % MOD;
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    ll N, R; cin >> N >> R;
    if(N < 10){
        R += 100*(10-N);
    }
    cout << R << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)

n = int(input())
edges = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    edges[a-1].append((b-1,i))
    edges[b-1].append((a-1,i))

def dfs(v, c=-1, p=-1):
    k = 1
    for nv, ei in edges[v]:
        if nv == p:
            continue
        if k == c:
            k += 1
        ans[ei] = k
        k += 1
        dfs(nv, ans[ei], v)

ans = [None]*(n-1)
dfs(0)

print(max(ans))
for i in ans:
    print(i)

Measured memory_bytes: 100252
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
string S;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>S;
    if(S=="zyxwvutsrqponmlkjihgfedcba") cout <<-1<<"\n";
    else{
        if(S.length()<26){
            set<char> s;
            rep(i,0,S.length()){
                s.insert(S[i]);
            }
            cout << S;
            for (char i='a';i<='z';i++){
                if(s.find(i)==s.end()){
                    cout <<i<<"\n";
                    break;
                }
            }
        }
        else{
            vector<char> v;
            v.pb(S[S.length()-1]);
            rer(i,S.length()-1,0){
                if(S[i]<S[i+1]){
                    sor(v);
                    rep(j,0,i){
                        cout <<S[j];
                    }
                    cout <<*lb(v,S[i])<<"\n";
                    break;
                }
                else{
                    v.pb(S[i]);
                }
            }
        }
    }
}

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

int n;
string goal;

int solve(string s, int k)
{
    if(k == n)
        return 0;
    if(s[k] == goal[k])
        return solve(s, k+1);

    int d = goal[k] - s[k];

    int ret = INT_MAX;
    for(int i=k; i<n; ++i){
        s[i] = (s[i] - '0' + d + 10) % 10 + '0';
        ret = min(ret, solve(s, k+1) + 1);
    }
    return ret;
}

int main()
{
    for(;;){
        cin >> n;
        if(n == 0)
            return 0;

        string s;
        cin >> s >> goal;

        cout << solve(s, 0) << endl;
    }
}

Measured memory_bytes: 1212
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k= sc.nextInt();
        int n= sc.nextInt();
        int max = 0;
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        
        for (int i = 0; i < n - 1; i++) {
            int dis = Math.abs(a[i+1] - a[i]); 
            max = Math.max(max, dis);
        }
        int ldis = a[0] + k - a[n-1];
        max = Math.max(max, ldis);
        
        System.out.println(k - max);
    }
}


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

int main() {
  int k; cin >> k;
  int n = 7;
  rep(i,k) {
    if (n%k==0) {
      cout << i+1 << endl;
      return 0;
    }
    
    n = n * 10 + 7;
    n %= k;
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int maxn = 2e5+10;
int k, pos, val;
int cnt[15][10], s[15][10];
queue<int> ans;
void solve()
{
    int sum = 0;
    cnt[1][0] = 1;
    for(int i = 1; i <= 9; i++) cnt[1][i] = 1, sum++, s[1][i] = sum;
    for(int i = 2; i <= 11; i++)
    {
        cnt[i][0] = cnt[i-1][0]+cnt[i-1][1];
        for(int j = 1; j <= 8; j++)
        {
            cnt[i][j] = cnt[i-1][j-1]+cnt[i-1][j]+cnt[i-1][j+1];
            sum += cnt[i][j]; s[i][j] = sum;
            if(s[i][j]>=k)
            {
                pos = i; val = j;
                return ;
            }
        }
        cnt[i][9]=cnt[i-1][8]+cnt[i-1][9];
        sum += cnt[i][9]; s[i][9] = sum;
        if(s[i][9]>=k)
        {
            pos = i; val = 9;
            return ;
        }
    }
}
void get()
{
    ans.push(val);
    if(val==1) k -= s[pos-1][9];
    else k -= s[pos][val-1];
    for(int i = pos-1; i >= 1; i--)
    {
        int sum = 0;
        for(int j = max(0, val-1); j <= min(val+1, 9); j++)
        {
            sum += cnt[i][j];
            if(sum>=k)
            {
                ans.push(j);
                k -= (sum-cnt[i][j]);
                val = j;
                break;
            }
        }
    }
}
int main()
{
    //freopen("/Users/zhangkanqi/Desktop/11.txt","r",stdin);
    scanf("%d", &k);
        if(k<10) { printf("%d\n", k);return 0;}
        solve();
        get();
        while(!ans.empty()) printf("%d", ans.front()), ans.pop();
        printf("\n");
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  map<string ,int> memo;
  rep(i,n){
    string s;
    cin >> s;
    memo[s] += 1;
  }
  int ans = 0;
  for(auto p : memo) ans = max(ans,p.second);
  for(auto p : memo){
    if(ans == p.second){
      cout << p.first << endl; 
    }
  }
  return 0;
}


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

struct Edge{
    int to; //辺の行先
    ll weight; //辺の重み
    Edge(int t,ll w):to(t),weight(w){}
};
using Graph=vector<vector<Edge>>;

void KIdfs(const Graph&G,int v,int p,vector<int> &color){
    for(auto nv:G[v]){
        if(nv.to==p){
            continue;
        }
        if(color[v]==0){
            if(nv.weight%2==0){
                color[nv.to]=0;
            }
            else{
                color[nv.to]=1;
            }
        }
        else{
            if(nv.weight%2==0){
                color[nv.to]=1;
            }
            else{
                color[nv.to]=0;
            }
        }
        KIdfs(G,nv.to,v,color);
    }
}

int main(){
    int N;
    cin>>N;
    Graph G(N);
    rep(i,N-1){
        int from,to;
        ll weight;
        cin>>from>>to>>weight;
        from--;to--;
        G[from].push_back(Edge(to,weight));
        G[to].push_back(Edge(from,weight));
    }
    vector<int>color(N,0);
    KIdfs(G,0,-1,color);
    rep(i,N){
        cout<<color[i]<<endl;
    }
}

Measured memory_bytes: 11264
#include <algorithm>
#include <cstdio>
#include <ctype.h>
#include <functional>
#include <iostream>
#include <cassert>
#include <cfloat>
#include <climits>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;
long long gcd(long long m, long long n)
{
	// 引数に０がある場合は０を返す
	if ((0 == m) || (0 == n))
		return 0;
	if (n > m) {
		swap(m, n);
	}
	// ユークリッドの方法
	while (n>0)
	{
		m = m % n;
		swap(m, n);
	}
	return m;
}
int main() {
	long long N, X;
	cin >> N >> X;
	long long n;
	n = gcd(N, X);

	cout << (3 * (N / n) - 3)*n << endl;

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("trapv")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using vi = vector<ll>;
using pi = pair<ll, ll>;
using vpi = vector<pi>;
const int maxn = 2e5 + 55;
const int mod = 1e9 + 7;
bool prime(ll a) {
	for(ll d = 2; d*d <= a; d++) {
		if(a%d) continue;
		return false;
	}
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll a;
	cin >> a;
	while(!prime(a)) a++;
	cout << a;
}


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

using namespace std;
string s;
int mar[200000];
int main() {
    ios_base::sync_with_stdio(0);
    cin >> s;
    long long ans = 1;
    for (int i = 0; i < s.size(); i++) {
        ans += i - mar[s[i]];
        mar[s[i]]++;
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 720
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

auto solve(int n, vector<int> &sosu) {
    vector<int> ans;
    for (int i = 6; i < 300001; i++) {
        if (sosu[i] == 1) {
            if (n % i == 0) {
                ans.push_back(i);
            }
        }
    }
    return ans;
}

int main(void) {
    int n;
    vector<vector<int>> ans;
    vector<int> nKeep;

    vector<int> sosu(300001, 0);
    for (int i = 6; i < 300001; i++) {
        if (i % 7 == 1 || i % 7 == 6) {
            sosu[i] = 1;
        }
    }

    for (int i = 6; i < 300001; i++) {
        if (sosu[i] == 1) {
            for (int j = 2 * i; j < 300001; j += i) {
                sosu[j] = 0;
            }
        }
    }

    while (1) {
        cin >> n;
        if (n == 1) {
            break;
        }
        nKeep.push_back(n);
        ans.push_back(solve(n, sosu));
    }

    for (int i = 0; i < nKeep.size(); i++) {
        cout << nKeep[i] << ": ";
        for (int j = 0; j < ans[i].size(); j++) {
            cout << ans[i][j];
            if (j == ans[i].size() - 1)
                cout << endl;
            else
                cout << " ";
        }
    }
}


Measured memory_bytes: 3984
#include <iostream>
#include <cstdio>
#include <queue>
#include <map>
#include <array>

using namespace std;

struct Edge{
  int to;
  int cost;
};

typedef pair<int, int> P; // min distance, vertex id


const int kInf = 1 << 30;

const char kBlank = '.';
const char kWall = '#';
const char kFriendInk = 'o';
const char kEnemyInk = 'x';
const char kStart = 'S';
const char kGoal = 'G';
const int kMaxBoardSize = 32;
const int kMaxVertex = kMaxBoardSize*kMaxBoardSize;

vector<Edge> G[kMaxVertex];
int d[kMaxVertex];
char field[kMaxBoardSize*kMaxBoardSize];

int way[4] = {-1, +kMaxBoardSize, +1, -kMaxBoardSize};

inline int xy2pos(int x, int y){
  return y*kMaxBoardSize + x;
}

inline int pos2x(int pos){
  return pos % kMaxBoardSize;
}

inline int pos2y(int pos){
  return pos / kMaxBoardSize;
}

void SetCost(int pos){
  for(int i=0; i<4; i++){
	int npos = pos + way[i];
	if(field[npos] == kWall){
	  continue;
	}else if(field[npos] == kFriendInk){
	  G[pos].push_back({npos, 1});
	}else if(field[npos] == kBlank || field[npos] == kStart || field[npos] == kGoal){
	  G[pos].push_back({npos, 2});
	}
	for(int n=1; n<=3; n++){
	  int npos = pos + n*way[i];
	  if(field[npos] == kWall){
		break;
	  }
	  G[pos].push_back({npos, 2 + n});
	}
  }
}


void Dijkstra(int start){
  priority_queue<P, vector<P>, greater<P> > q;
  fill(d, d + kMaxVertex, kInf);
  d[start] = 0;
  q.push(P(0, start));

  while(q.size()){
	P p = q.top();
	q.pop();
	int from = p.second;
	if(d[from] < p.first){
	  continue;
	}
	SetCost(from);
	for(int i=0; i<G[from].size(); i++){
	  Edge e = G[from][i];
	  // new route requires less cost
	  if(d[e.to] > d[from] + e.cost){
		d[e.to] = d[from] + e.cost;
		q.push(P(d[e.to], e.to));
	  }
	}
  }
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  for(int i=0; i<kMaxBoardSize*kMaxBoardSize; i++){
	field[i] = kWall;
  }

  int R, C;
  cin >> R >> C;
  int S, G;
  for(int y=1; y<=R; y++){
	for(int x=1; x<=C; x++){
	  cin >> field[xy2pos(x, y)];
	  if(field[xy2pos(x,y)] == kStart){
		S = xy2pos(x, y);
	  }else if(field[xy2pos(x,y)] == kGoal){
		G = xy2pos(x, y);
	  }
	}
  }

  Dijkstra(S);
  cout << d[G] << endl;
}

Measured memory_bytes: 3320
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
cnt = 0

lsum = [0]

for i in range(1, n+1):
    lsum.append(lsum[i-1] + a[i-1])
counter = Counter(lsum)
for elem, num in counter.most_common():
    cnt += num*(num-1) // 2

print(cnt)


Measured memory_bytes: 48668
def linearSearch(A,key):
    for i in range(len(A)):
        if A[i]==key:
            return i
        else: pass
    return -1


n=int(input())
s=list(input().split())
q=int(input())
t=input().split()

cnt=0
for i in range(q):
    x=linearSearch(s,t[i])
    if x!=(-1):
        cnt+=1
        
print(cnt)



Measured memory_bytes: 6068
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    int n, x, t;
    cin >> n >> x >> t;

    cout << ((n + x - 1) / x) * t << endl;

    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll  long long
#define ull unsigned long long
using namespace std;
const int N=1e6+5,M=1e9+7;
const ull base=13331;
const double Pi=acos(-1.0);
const ll C=299792458;
char a[N];
struct node{
	int x,v;
}h[N];
int main(){
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	int tot=0;
	int l=1,r=1;
	for(l=1,r=1;r<=n&&l<=n;r++){
		if(a[r]==a[l])continue;
		else {
			h[++tot].x=a[l]-'0';
			h[tot].v=r-l;
			l=r;
		}
	}
	h[++tot].x=a[l]-'0';
	h[tot].v=r-l;
	int sum=0;
	int ans=0;
	for(int i=1;i<=2*k;i++){
		sum+=h[i].v;
	}
	if(h[2*k].x==0)ans=max(ans,sum+h[2*k+1].v);
	else ans=max(ans,sum);
	for(l=2,r=2*k+1;r+1<=n;l++,r++){
		sum-=h[l-1].v;
		sum+=h[r].v;
		if(h[r].x==0){
			ans=max(ans,sum+h[r+1].v);
		}
		else ans=max(ans,sum);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3072
n=int(input())
t=['S','H','C','D']
trunp=[[False for i in range(13)],[False for i in range(13)],[False for i in range(13)],[False for i in range(13)]]
for i in range(n):
    [type,num]=input().split()
    num=int(num)-1
    if type=='S':
        trunp[0][num]=True
    elif type=='H':
        trunp[1][num]=True
    elif type=='C':
        trunp[2][num]=True
    elif type=='D':
        trunp[3][num]=True
for i in range(4):
    for j in range(13):
        if trunp[i][j]==False:
            print('%s %d' % (t[i],j+1))


Measured memory_bytes: 5604
#include <iostream>
#include <string>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;

int main() {

  string s, t;
  cin >> s >> t;

  int cnt = 0;
  rep(i, 3) if (s[i] == t[i]) cnt++;

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))


#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))


int main()
{
    ll a, b, v, w, t;
    std::cin >> a >> v >> b >> w >> t;
    ll dist = std::abs(b - a);
    if (w >= v)
    {
        std::cout << "NO" << std::endl;
        return 0;
    }
    ll sub = std::abs(w - v);
    if (sub * t >= dist) { std::cout << "YES" << std::endl; }
    else
    {
        std::cout << "NO" << std::endl;
    }

    return 0;
}

/*
int main()
{
    ll n, k;
    std::cin >> n >> k;
    std::vector<ll> vec(n);
    for (ll i = 0; i != n; ++i) { std::cin >> vec[i]; }

    for (ll i = 0; i != k; ++i)
    {

    }


    return 0;
}
*/

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

int main(){
    int n;cin >> n;
    vector<pair<ll,P>> table;
    rep(i,n){
        ll a,b;cin >> a >> b;
        P p = make_pair(a,b);
        pair<ll,P> q = make_pair(ll(a)+ll(b),p);
        table.push_back(q);
    }
    sort(table.rbegin(),table.rend());
    ll ans = 0;
    rep(i,n){
        P p = table[i].second;
        if(i%2==0) ans += p.first;
        else ans -= p.second;
    }
    cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using edge = pair<ll, P>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N;
    cin >> N;
    vector<int> V(N);
    rep(i, N) cin >> V[i];
    unordered_map<int, int> even;
    unordered_map<int, int> odd;
    rep(i, N) {
        if (i % 2 == 0) {
            even[V[i]]++;
        } else {
            odd[V[i]]++;
        }
    }
    int max_even = -1;
    int max_even_num = -1;
    int max_odd = -1;
    int max_odd_num = -1;
    for (auto p : even) {
        if (max_even < p.second) {
            max_even = p.second;
            max_even_num = p.first;
        }
    }
    for (auto p : odd) {
        if (max_odd < p.second) {
            max_odd = p.second;
            max_odd_num = p.first;
        }
    }
    if (max_even_num != max_odd_num) {
        cout << N / 2 - max_even + N / 2 - max_odd << endl;
    } else {
        int max_even2 = 0;
        int max_odd2 = 0;
        for (auto p : even) {
            if (max_even2 < p.second && p.first != max_even_num) {
                max_even2 = p.second;
            }
        }
        for (auto p : odd) {
            if (max_odd2 < p.second && p.first != max_odd_num) {
                max_odd2 = p.second;
            }
        }
        if (max_even2 > max_odd2) {
            cout << N / 2 - max_even2 + N / 2 - max_odd << endl;
        } else {
            cout << N / 2 - max_even + N / 2 - max_odd2 << endl;
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


Measured memory_bytes: 4760
# Header {{{

def assert(p)
  raise 'Assertion Failed' unless p
end

# Requires {{{
require 'set'
# }}}

# Constants {{{
INF = 10**9
# }}}

# IO {{{
class MyIO
  def initialize
    @input = $stdin
    @output = $stdout
  end

  # @param filename [String]
  def set_input(filename)
    @input = File.open(filename, 'r')
  end

  def set_output(filename)
    @output = File.open(filename, 'w')
  end

  def int
    gets.to_i
  end

  def ints
    split.map(&:to_i)
  end

  def split
    @input.gets.chomp.split(' ')
  end
  alias_method :strings, :split

  def gets
    @input.gets.chomp
  end

  def puts(*args)
    @output.puts(*args)
  end
end

io = MyIO.new
# }}}

# Algorithms {{{

def lower_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] < val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] >= val
    low
  else
    high
  end
end

def upper_bound(arr, val)
  assert(arr.is_a?(Array))
  low, high = 0, arr.size
  while high - low > 1
    mid = (low + high) / 2
    if arr[mid] <= val
      low = mid
    else
      high = mid
    end
  end
  if arr[low] > val
    low
  else
    high
  end
end

# }}}

# }}}

# io.set_input('inputs/2.txt')
# io.set_output('my_outputs/2.txt')

while true
  n = io.int
  break if n == 0
  bigger_chars = Hash.new { |h, k| h[k] = Set.new }
  prev_word = ''
  ok = true
  n.times do |i|
    word = io.gets
    [prev_word.length, word.length].min.times do |j|
      if prev_word[j] == word[j]
        next
      elsif bigger_chars[word[j]].include?(prev_word[j])
        ok = false and break
      else
        bigger_chars[prev_word[j]] << word[j]
        # Update dependencies
        ('a'..'z').each do |c|
          q = bigger_chars[c].to_a
          while !q.empty?
            tc = q.pop
            bigger_chars[c] << tc
            q += (bigger_chars[tc] - bigger_chars[c]).to_a
          end
        end
        break
      end
    end
    if prev_word.start_with?(word) && prev_word != word
      ok = false
    end
    prev_word = word
  end
  io.puts ok ? 'yes' : 'no'
end

# vim: foldmethod=marker

Measured memory_bytes: 6816
#include <bits/stdc++.h>
using namespace std;
int main() {
  for(int N; cin>>N&&N;){
    int n=1000, a=0;
    while(1) {
      if(n-500>=N) n-=500,a++;
      else if(n-100>=N) n-=100,a++;
      else if(n-50>=N) n-=50,a++;
      else if(n-10>=N) n-=10,a++;
      else if(n-5>=N)n-=5,a++;
      else if(n-1>=N)n--,a++;
      else break;
    }cout <<a<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
import java.util.Scanner;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) {
            h[i] = sc.nextInt();
        }

        int ans = h[0];
        for (int i = 1; i < n; i++) {
            if (h[i - 1] < h[i]) {
                ans += h[i] - h[i - 1];
            }
        }
        System.out.println(ans);
    }
}


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

int main() {
  int N,A,B,C;
  cin >>N;
  for(int i=0;i<N;i++){
    cin>>A;
    if(A%2==0){
      if(A%3==0||A%5==0){
        continue;
      }
      cout<<"DENIED"<<endl;
      return 0;
    }
  }
  cout <<"APPROVED"<< endl;
}


Measured memory_bytes: 256
n = int(input())
if n < 2:
    print(1)
elif n < 4:
    print(2)
elif n < 8:
    print(4)
elif n < 16:
    print(8)
elif n < 32:
    print(16)
elif n < 64:
    print(32)
else:
    print(64)


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

using namespace std;
typedef long long ll;

#define pb push_back
#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define forrn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define PYMOD(a, m) ((((a) % (m)) + (m)) % (m))
#define all(v) v.begin(), v.end()
#define mp make_pair
#define ff first
#define ss second

const int mod = 1e9 + 7;

void insrange(vector<int>& v, int l, int r) {
    forrn(i, l, r)
        v.pb(i);
}

vector<int> solve(int n, int a, int b) {
    if (1ll * a * b < n || a + b - 1 > n)
        return vector<int>();
    vector<int> ans;
    int cn = n - a + 1;
    insrange(ans, cn, n + 1);
    for (int i = 1; i < b; i++) {
        int left = n - ans.size();
        if (left == b - i) {
            insrange(ans, cn - 1, cn);
            cn--;
        } else if (b - i - 1 + a <= left) {
            insrange(ans, cn - a, cn);
            cn -= a;
        } else {
            insrange(ans, b - i, cn);
            cn = b - i;
        }
    }
    return ans;
}

int main() {
    // Code here:

    int n, a, b;
    cin >> n >> a >> b;

    vector<int> ans = solve(n, a, b);
    if (ans.empty())
        cout << -1 << endl;
    else {
        for (int u : ans)
            cout << u << " ";
        cout << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3440