akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
struct node{
	int a,b;
	node(){}
	node(int a,int b):a(a),b(b){}
};
ll n;
vector<node> A,B;
inline ll calc1(vector<node> &a){return n/a[0].a*(a[0].b-a[0].a);}
inline ll calc2(vector<node> &a){
	ll i,t,ans=0;
	for(i=0;i<=n;++i){
		t=n-i;
		ans=max(ans,i/a[0].a*(a[0].b-a[0].a)+t/a[1].a*(a[1].b-a[1].a));
	}
	return ans;
}
inline ll calc3(vector<node> &a){
	ll i,j,t,ans=0;
	for(i=0;i<=n;++i)
		for(j=0;j<=n-i;++j){
			t=n-i-j;
			ans=max(ans,i/a[0].a*(a[0].b-a[0].a)+j/a[1].a*(a[1].b-a[1].a)+t/a[2].a*(a[2].b-a[2].a));
		}
	return ans;
}
int main(){
	int a1,a2,a3,b1,b2,b3;
	ll ans=0;
	scanf("%lld%d%d%d%d%d%d",&n,&a1,&a2,&a3,&b1,&b2,&b3);
	if(a1<b1)A.push_back(node(a1,b1));
	else if(b1<a1)B.push_back(node(b1,a1));
	if(a2<b2)A.push_back(node(a2,b2));
	else if(b2<a2)B.push_back(node(b2,a2));
	if(a3<b3)A.push_back(node(a3,b3));
	else if(b3<a3)B.push_back(node(b3,a3));
	if(A.size()==1)ans=calc1(A);
	else if(A.size()==2)ans=calc2(A);
	else if(A.size()==3)ans=calc3(A);
	n+=ans;ans=0;
	if(B.size()==1)ans=calc1(B);
	else if(B.size()==2)ans=calc2(B);
	else if(B.size()==3)ans=calc3(B);
	printf("%lld\n",n+ans);
	return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) = agc043b()

fun agc043b() {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.map { Character.getNumericValue(it) - 1 }.toIntArray()

    val isAnswerEven = aList
        .reduceIndexed { index, acc, a -> if ((n - 1) and index == index) acc xor a else acc }
        .let { it % 2 == 0 }

    if (!isAnswerEven) return println(1)

    if (aList.contains(1)) return println(0)

    val answer = aList.map { it / 2 }
        .reduceIndexed { index, acc, a -> if ((n - 1) and index == index) acc xor a else acc }
        .let { it % 2 == 0 }
        .let { if (it) 0 else 2 }

    println(answer)
}


Measured memory_bytes: 50312
#include <bits/stdc++.h>
using namespace std;
long long n[3];
int main(){
  cin>>n[0]>>n[1]>>n[2];
  if(!(n[0]&1)||!(n[1]&1)||!(n[2]&1))return cout<<0,0;
  sort(n,n+3);
  cout<<n[0]*n[1];
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;

    ll right = C - A - B;
    if (right <= 0) {
        cout << "No" << endl;
        return 0;
    }
    right *= right;

    ll left = 4 * A * B;
    if (left < right) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC129 E

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

l = input()
n = len(l)
dp = [[0]*2 for _ in range(n+1)]
dp[0][0] = 1

#dp[i][j] := i桁目までを見たとき
#            j=0 := i桁が一致
#            j=1 := L未満であることが確定

for i in range(n):
    #a+bのi桁目0
    if l[i] == '0':
        dp[i+1][0] += dp[i][0]
        dp[i+1][1] += dp[i][1]
    else:
        dp[i+1][1] += (dp[i][0] + dp[i][1]) % mod
    
    #a+bのi桁目1
    if l[i] == '0':
        dp[i+1][1] += dp[i][1]*2
        dp[i+1][1] %= mod
    else:
        dp[i+1][0] += dp[i][0]*2
        dp[i+1][0] %= mod
        dp[i+1][1] += dp[i][1]*2
        dp[i+1][1] %= mod

ans = (dp[-1][0] + dp[-1][1]) % mod
print(ans)

Measured memory_bytes: 54236
#include <bits/stdc++.h>
#define ll    long long int
#define ld    long double
#define pb    push_back
#define mp    make_pair
#define Maxn  1000007
#define ff    first
#define se    second
using namespace std;
int main() {
    ll l,r,x,y,z,t,mi=2000000005,i,j,flag=0;
    cin>>l>>r;
        for(i=l;i<=r;i++){
            if(i%2019==0){
                flag=1;
                break;
            }
        }
        if(flag==1){
            cout<<0;
        }
        else{
            l=l%2019;
            r=r%2019;
            for(i=l;i<=r;i++){
                for(j=l;j<=r;j++){
                    if(i!=j){
                    z=(i*j)%2019;
                    mi=min(mi,z);
                    }
                }
            }
            cout<<mi;
        }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  // 文字列で格納
  char c;
  cin >> c;
  if (islower(c)) cout << "a" << endl;
  else cout << "A" << endl;
  return 0;
}

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

using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    for(int i=1;i<b[0]-'0';i++){
        a+=a[0];
    }
    for(int i=1;i<a[0]-'0';i++){
        b+=b[0];
    }
    if(a<=b)cout<<a<<endl;
    else    cout<<b<<endl;
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

int main() {
	int n,m;
	cin >> n >> m;
	UnionFind tree(n+1);
	FOR(i, 1, m) {
		int x, y, z;
		cin >> x >> y >> z;
		tree.unite(x, y);
	}
	set<int> pars;
	FOR(i, 1, n) {
		pars.insert(tree.root(i));
	}
	pv(SZ(pars));
	return 0;
}

Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include <iostream> 
#include <algorithm> 
#include<string>
#include<queue>
#include<utility>
#include<fstream>
#include<queue>
#include<set>
#include<stack>
#include<map>
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define I(a) scanf("%d",&a)
#define I2(a,b) scanf("%d%d",&a,&b)
#define I3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define L(a) scanf("%lld",&a)
#define L2(a,b) scanf("%lld%lld",&a,&b)
#define L3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define PI(a) printf("%d",a)
#define PL(a) printf("%lld",a)
#define PT(t) printf("Case %d: ",t)
#define PB push_back
#define x first
#define y second
#define xx first.first
#define xy first.second
#define yx second.first
#define yy second.second
#define SC scanf
#define PC printf
#define NL printf("\n")
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define SZ(a) ((int)a.size())-1
#define f(i,a,b) for(int i=a;i<=b; i++)
#define fr(i,a,b) for(int i=a;i<=b; i++)
#define frr(i,a,b) for(int i=a;i>=b; i--)
#define frv(i,a)  for(int i=0;i<a.size();i++)
#define pi 2.0*acos(0.0)
#define R(a) freopen(a, "r", stdin);
#define W(a) freopen(a, "w", stdout);
#define CB(x) __builtin_popcount(x)
#define STN(a) stringtonumber<ll>(a)
#define lol printf("BUG\n")
#define Endl "\n"
#define mk make_pair
using namespace std;
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}
 
 
typedef pair<int,int >P;
//////////////////////////   
/////////////////////////
int main(){

   
 int n,m;
 I2(n,m);

 int ar[m+2];
 for(int i = 1;i<=m;i++)I(ar[i]);
 sort(ar +1, ar+ m+1);

 int ans = ar[m] - ar[1];

 vector<int>a;

 for(int i = 2;i<=m;i++){
     a.push_back(ar[i] - ar[i-1]);
 }
 sort(a.begin(), a.end());
 reverse(a.begin(), a.end());
 for(int i = 1;i<min(n,m);i++){
     ans -= a[i-1];
 }
 cout<<ans<<endl;

    return 0;
}

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

using namespace std;

int main()
{
    #ifdef LOCAL_EXEC
    #else
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #endif // LOCAL_EXEC
    long long int n,k,i,j,x,d,sum=0;
    cin>>n>>k;
    bool A[n]={false};
    for(i=0;i<k;i++){
        cin>>d;
        for(j=0;j<d;j++){
            cin>>x;
            if(A[x-1]==false)
                A[x-1]=true;
        }
    }
    for(i=0;i<n;i++){
        if(A[i]==false)
            sum+=1;
    }
    cout<<sum;
    return 0;
}


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

#define ll long long
#define pb push_back
#define mkp make_pair
#define ld long double

using namespace std;

int n, a[200100], ct[200100], proh;
int maxa1, maxa2, num1, num2;

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

    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    maxa1 = 0;
    for(int i = 0; i < n; i+=2){
        ct[a[i]]++;
        if(maxa1 < ct[a[i]]){
            maxa1 = ct[a[i]];
            num1 = a[i];
        }
    }

    memset(ct, 0, sizeof(ct));
    for(int i = 1; i < n; i += 2){
        ct[a[i]]++;
        if(maxa2 < ct[a[i]]){
            maxa2 = ct[a[i]];
            num2 = a[i];
        }
    }

    int ans;
    if(num1 == num2){
        int proh1 = num1, proh2 = num2;
        int large1 = maxa1, large2 = maxa2;

        maxa1 = 0;
        memset(ct, 0, sizeof(ct));
        for(int i = 0; i < n; i+=2){
            ct[a[i]]++;
            if(maxa1 < ct[a[i]] && a[i] != proh1){
                maxa1 = ct[a[i]];
                num1 = a[i];
            }
        }

        maxa2 = 0;
        memset(ct, 0, sizeof(ct));
        for(int i = 1; i < n; i += 2){
            ct[a[i]]++;
            if(maxa2 < ct[a[i]] && a[i] != proh2){
                maxa2 = ct[a[i]];
                num2 = a[i];
            }
        }

        ans = max(large1 + maxa2, maxa1 + large2);
    } else ans = maxa1 + maxa2;

    cout << n - ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

typedef struct Card{
  char nam;
  int number;
}card;

int isStable(card [],card [],int);
void bubbleSort(card [],int);
void selection(card [],int);
void phyouzi(card [],int);

int main(){
  card c[100], c1[100];
  int i,n;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf(" %c%d", &c[i].nam, &c[i].number);
    c1[i] = c[i];
  }

  bubbleSort(c,n);
  selection(c1,n);

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

    if(i==n-1){
      printf("%c%d", c[i].nam, c[i].number);
    }
    else{
      printf("%c%d ", c[i].nam, c[i].number);
    }

  }
  printf("\n");

  printf("Stable\n");
  for(i=0; i<n; i++){
    if(i==n-1){
      printf("%c%d", c1[i].nam, c1[i].number);
    }
    else{
      printf("%c%d ", c1[i].nam, c1[i].number);
    }
  }
  printf("\n");

  if(isStable(c,c1,n)){
    printf("Stable\n");
  }
  else{
    printf("Not stable\n");
  }
  return 0;
}

void bubbleSort(card x[],int n){
   int i, j;
  card tmp;

  for(i=0; i<n; i++){
    for(j=n-1; j>=i+1; j--){
      if(x[j].number < x[j-1].number){
    tmp = x[j];
    x[j] = x[j-1];
    x[j-1] = tmp;
      }
    }
  }
}

void selection(card x[],int n){
  int i,j, min;
  card tmp;

  for(i=0; i<n; i++){
    min=i;
    for(j=i; j<n; j++){
      if(x[j].number < x[min].number) min=j;
    }
    tmp=x[i];
    x[i] = x[min];
    x[min] = tmp;
  }
}
void phyouzi(card x[],int n){
  int i;

  for(i=0; i<n; i++){
    if(i>0){
      printf(" ");
    }
    printf("%c%d", x[i].nam, x[i].number);
  }
  printf("\n");
}

int isStable(card c[],card c1[],int n){
  int i;
  for(i=0; i<n; i++){
    if(c[i].nam != c1[i].nam)
      return 0;
  }
  return 1;
}



Measured memory_bytes: 2036
n=int(input())
a=list(map(int,input().split()))
from fractions import gcd
import functools
l=[(t.append(gcd(t[i-1],a[i])),t)[1] for t in [[a[0]]] for i in range(1, n)][0]
r=[(t.append(gcd(t[i-1],a[n-1-i])),t)[1] for t in [[a[n-1]]] for i in range(1, n)][0][::-1]
print(functools.reduce(lambda x,y:max(x,y),[gcd(l[i-1]if 0<i else r[i+1],r[i+1]if i<n-1 else l[i-1])for i in range(n)]))

Measured memory_bytes: 14052
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto d = readln.chomp.split.to!(int[]);
  int res;
  foreach (_; 0..2) {
    if (d[0] > d[1]) {
      res += d[0];
      d[0]--;
    } else {
      res += d[1];
      d[1]--;
    }
  }
  res.writeln;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    // 整数の入力
    int n;
    cin >> n;
    int p[n];
    for(int i=0; i < n; i++)
        cin >> p[i];

    int count = 0;
    for(int i=1; i < n-1; i++){
        if(max(p[i-1], p[i+1]) > p[i] && min(p[i-1], p[i+1]) < p[i]){
            count++;
            // cout << p[i];
        }
    }
    // cout << a << ", " << b << ", " << c << endl;
    // scanf("%d %d %d",&a,&b, &c);
    cout << count << endl;
    return 0;
}


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

int main(){
  int A,B,As,q,w,r,t;
  int cnt = 0;
  cin >> A >> B;
  for (A; A <= B; A++){
    As = A;
    q = As / 10000;
    t = As % 10;
    As /= 10;
    w = (As/100)%10;
    r = As % 10;
    if (q == t && w == r){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

	cout << r * r << endl;
}

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

#include <cstdlib>  // abs() for integer 絶対値求めやつ

#include <cmath>    // abs() for float, and fabs()

#include <algorithm>
#include <vector>
#define rep(i,n) for(int i = 0; i< (n);i++)

#define sort(a) sort((a).begin(),(a).end());

#define che(a,string) cout<<string<<":"<<(a)<<endl;

#define ch(a,string) cout<<string<<":"<<(a)<<" ";

using namespace std;

typedef pair<int,int> p;

int main(){
	int n ;
	cin>>n;
	cout<<"ABC"<<n<<endl;
}

Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <unordered_map>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug "<< i << std::endl

//const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  //問題文中の添え字が0-indexか1-indexか確認!

  ll n;
  std::cin>>n;

  std::vector<P> x(n);

  std::vector<ll> ans(n*n,-1);

  rep(i,0,n){
    ll temp;
    std::cin>>temp;
    ans[temp-1]=i;
    x[i]={temp-1,i};
  }

  std::sort(all(x));

  ll now=0;

  rep(i,0,n){
    ll value=x[i].second;

    ll count=0;
    while(count<value){
      if(ans[now]==-1){
        count++;
        ans[now]=value;
      }
      now++;
    }
  }

  now=n*n-1;

  for(ll i=n-1;i>=0;i--){
    ll value=x[i].second;

    ll count=0;
    while(count<n-1-value){
      if(ans[now]==-1){
        count++;
        ans[now]=value;
      }
      now--;
    }
  }

  rep(i,0,n){
    ll itr=x[i].first,value=x[i].second;

    ll count=0;
    rep(j,0,itr)if(ans[j]==value)count++;

    if(count!=value){
      std::cout<<"No";
      return 0;
    }
  }

  std::cout<<"Yes\n";

  rep(i,0,n*n)std::cout<<ans[i]+1<<" ";

  return 0;
}


Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
string a,b;
int sum;
int main(){
	cin>>a>>b;
	int n=a.length();
	for(int i=0;i<=n;i++){
		if(a[i]!=b[i]){
			sum++;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 3848
n=int(input())
S=[input() for _ in range(n)]
s=[0]*5

for i in range(n):
    if S[i][0]=="M":
        s[0]+=1
    elif S[i][0]=="A":
        s[1]+=1
    elif S[i][0]=="R":
        s[2]+=1
    elif S[i][0]=="C":
        s[3]+=1
    elif S[i][0]=="H":
        s[4]+=1
#print(s)
ans=0
for i in range(3):
    for j in range(i+1,4):
        ans+=s[i]*s[j]*sum(s[j+1:])
print(ans)

Measured memory_bytes: 9752
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef pair<ut,pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef priority_queue<ut,VI> PQ;
const int SIZE=2*1e5;
const LL INF=-1+(1LL<<61);
const LL p=7+1e9;
LL t[SIZE],F[SIZE];

LL solve(){

	LL N,D,ans=0,now,people=0;
	cin >> N >> D;
	F[0]=0;
	FOR(i,1,N+1){
		cin >> t[i] >> F[i];
		F[i]--;
		if(t[i-1]+F[i-1]+F[i]<=t[i]){
				ans+=F[i-1]*people;
				people=0;
		}
		else if(t[i-1]+abs(F[i-1]-F[i])>t[i] or people==D){
			return -1;
		}
		else{
			ans+=(t[i]-t[i-1])*people;
		}
		people++;
	}
	ans+=(F[N])*people;
	return ans;
}
int main(){
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 4616
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N; cin >> N; int mi = inf; int a[N]; int ans = 0;
  rep(i, N){
    cin >> a[i];
    if(mi>a[i]){
      ans++; mi = a[i];
    }
  }
  cout << ans << endl;  
}

Measured memory_bytes: 1024
// in the name of Allah

#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

const ll mod = 1000000007;

inline ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

inline ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

inline ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

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

	ll a, b, c;
	cin >> a >> b >> c;
	cout << min(a*b, c) << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = []
Y = []
for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)


ans = -float("inf")

left = -float("inf")
right = float("inf")
for i in range(N):
    left = max(left, X[i]-Y[i])
    right = min(right, X[i]-Y[i])

ans = max(ans, left - right)

left = -float("inf")
right = float("inf")
for i in range(N):
    left = max(left, X[i]+Y[i])
    right = min(right, X[i]+Y[i])

ans = max(ans, left - right)

print(ans)


Measured memory_bytes: 100420
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# [競プロ等におけるpython3の標準入力 - Qiita](https://qiita.com/zenrshon/items/c4f3849552348b3dbe67)

# 数値の数の読み込み
n = int(input())
# 数値読み込み
a = [int(i) for i in input().split()]
a.sort(reverse=True)
print(sum(a[1::2]))

Measured memory_bytes: 2940
from itertools import permutations
def check(queen):
    for r1, c1 in queen:
        if any((r1 != r2 or c1 != c2) and (r1 == r2 or c1 == c2 or r1 + c1 == r2 + c2 or r1 - c1 == r2 - c2) for r2, c2 in queen):
            return False
    return True
N = int(input())
queen, row, col = [], list(range(8)), list(range(8))
for _ in range(N):
    r, c = map(int, input().split())
    queen.append((r, c))
    row.remove(r)
    col.remove(c)
for l in permutations(col):
    queen_tmp = queen[:] + [(r, c) for r, c in zip(row, l)]
    if check(queen_tmp):
        board = [''.join('Q' if (r, c) in queen_tmp else '.' for c in range(8)) for r in range(8)]
        print(*board, sep='\n')
        break

Measured memory_bytes: 7760
from operator import itemgetter
N = int(input())
guide = []
for i in range(N):
  lst = input().split(' ')
  guide.append([i+1,lst[0],int(lst[1])])
guide = sorted(guide, key=itemgetter(2),reverse=True)
guide = sorted(guide, key=itemgetter(1))
for i in range(N):
  print(guide[i][0])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef long long ll;
const int N=100010;
const ll INF=1e18+10;
const int P=1e9+7;
typedef pair<ll,ll> PLL;
int n;
ll A,B,s[N];
map<ll,int> S[2];
map<ll,int>::iterator it;
inline void add(int &x,int y)
{
	x=(x+y)%P;
}
int main()
{
	scanf("%d",&n);
	scanf("%lld%lld",&A,&B);
	//cin>>A>>B;
	for(int i=1;i<=n;i++)
		scanf("%lld",s+i);
	S[0][-INF]=1;
	S[1][-INF]=1;
	int now;
	for(int i=2;i<=n;i++)
	{
		int t1=0,t2=0;
		if(S[0].begin()->X+B<=s[i])
		{
			add(t1,S[0].begin()->Y);
		}
		if(S[1].begin()->X+A<=s[i])
		{
			add(t2,S[1].begin()->Y);
		}
		if(s[i]-A<s[i-1])
		{
			S[0].clear();
		}
		if(s[i]-B<s[i-1])
		{
			S[1].clear();
		}
		add(S[1][s[i-1]],t1);
		add(S[0][s[i-1]],t2);
		if(i<n)
		{
			while(S[0].size()>1)
			{
				it=S[0].begin();
				it++;
				if(it->X+B<=s[i+1])
				{
					add(it->Y,S[0].begin()->Y);
					S[0].erase(S[0].begin());
				}
				else
					break;
			}
		}
		if(i<n)
		{
			while(S[1].size()>1)
			{
				it=S[1].begin();
				it++;
				if(it->X+A<=s[i+1])
				{
					add(it->Y,S[1].begin()->Y);
					S[1].erase(S[1].begin());
				}
				else
					break;
			}
		}
	}
	int ans=0;
	for(it=S[0].begin();it!=S[0].end();it++)
		add(ans,it->Y);
	for(it=S[1].begin();it!=S[1].end();it++)
		add(ans,it->Y);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return a;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int main() {
  int N,K,S; cin >>N >>K >>S;
  const int MAXA = 1000000000;
  /* 1<=A.at(i)<=10^9である長さNの数列A。
     Aの部分数列で和がSになるものがちょうどK個あるものを求めよ
  */

  int rest;
  if (S < MAXA){
    // SをK個並べ、それ以外はMAXAを並べればよい
    rest = MAXA;
  }else{
    // S = MAXAをK個並べ、それ以外は1を並べればよい
    rest = 1;
  }

  for (int i=0; i<K; i++){
    cout <<S;
    if (i == N-1) cout <<endl;
    else cout <<" ";
  }
  for (int i=K; i<N; i++){
    cout <<rest;
    if (i == N-1) cout <<endl;
    else cout <<" ";
  }
}

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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()

int main() {
    string s;
    cin >> s;
    string ans = "";
    bool existA = false;
    bool existB = false;
    rep(i, 3) {
        if(s.at(i) == 'A') existA = true;
        if(s.at(i) == 'B') existB = true;    
    }
    if(existA && existB) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n;
	cin>>n;
	cout<<(n/2) * (n/2) + (n&1?n/2:0);
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3568
/*
 * atcoder/abc126/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
#include <queue>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(ll __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

/*
 *  頂点0をb=falseとして子供を決定していく. 偶数ならb, 奇数なら!b
 */
struct Edge {
  ll v; ll w;
};

const ll MAX = 100100;
ll N;
vector<Edge> G[MAX];
vector<ll> colors(MAX, -1);

vector<ll> A;
void solve() {
  cin >> N;
  ll u, v, w;
  loop(n,0,N-1) {
    cin >> u >> v >> w;
    u--;v--;
    G[u].push_back({ v, w });
    G[v].push_back({ u, w });
  }

  queue<ll> Q;
  Q.push({ 0 });
  colors[0] = 0;

  while (Q.size()) {
    ll u = Q.front(); Q.pop();
    for (auto&& edge: G[u]) {
      ll v = edge.v, w = edge.w;
      if (colors[v] >= 0) continue;
      if (w&1) colors[v] = 1-colors[u];
      else colors[v] = colors[u];
      Q.push(v);
    }
  }

  loop(n,0,N) cout << colors[n]%2 << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 8704
class Solver(object):
    def __init__(self):
        self.n, self.k = list(map(int, input().split(" ")))
        self.x_s = sorted(list(map(int, input().split(" "))))
 
    def solve(self):
        candidates = []
        for i in range(self.n - self.k + 1):  # 0 .. n-k
            candidates.append((i, i + self.k - 1))
            # print(self.x_s[i:i+self.k])
        best_candidate = candidates[0]
        best_distance = self.distance(best_candidate)
        for c in candidates[1:]:
            d = self.distance(c)
            if d < best_distance:
                best_candidate = c
                best_distance = d
        # print(best_candidate)
        print(best_distance)
 
    def distance(self, candidate):
        left = self.x_s[candidate[0]]
        right = self.x_s[candidate[1]]
        # X X X 0
        if right <= 0:
            return abs(left)
        # 0 X X X
        elif left >= 0:
            return abs(right)
        # X 0 X X
        elif abs(left) < abs(right):
            return abs(left) + abs(left) + abs(right)
        # X X 0 X
        else:
            return abs(right) + abs(right) + abs(left)
 
    def filter(self):
        # Only want -k .. k elements
        right = None
        counter = 0
        for i, v in enumerate(self.x_s):
            if v >= 0:
                counter += 1
                if counter == self.k:
                    right = i + 1
                    break
        if right is None:
            right = len(self.x_s)
 
        left = None
        counter = 0
        for i, v in reversed(list(enumerate(self.x_s))):
            if v <= 0:
                counter += 1
                if counter == self.k:
                    left = i
                    break
        if left is None:
            left = 0
        return self.x_s[left:right]
 
 
if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 14368
/*
 * 17-08-06_ARC080_C.cpp
 *
 *  Created on: 2017/08/06
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int N;
int mult4, even, odd;
int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (a % 4 == 0) {
			mult4++;
		} else if (a % 2 == 0) {
			even++;
		} else {
			odd++;
		}
	}
	if (even == 0 && mult4 + 1 >= odd) {
		cout << "Yes" << endl;
	} else {
		if (mult4 >= odd) {
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
#define SortAsc(c) std::sort(c.begin(), c.end())
#define SortDesc(c) std::sort(c.rbegin(), c.rend())
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};

int N, M, Q;
vector<int> a, b, c, d;

int calc(vector<int> &A) {
  //   for (int i = 0; i < A.size(); i++) {
  //     cout << A[i] << " ";
  //   }
  //   cout << endl;

  int value = 0;
  for (int i = 0; i < Q; i++) {
    if (A[b[i] - 1] - A[a[i] - 1] == c[i]) {
      value += d[i];
    }
  }

  return value;
}

int searchMax(vector<int> &A) {
  if (A.size() == N) {
    return calc(A);
  }

  int maxValue = 0;

  int v = 1;
  if (A.size() > 0) {
    v = A.back();
  }
  for (int i = v; i <= M; i++) {
    A.push_back(i);
    int res = searchMax(A);
    maxValue = max(res, maxValue);
    A.pop_back();
  }

  return maxValue;
}

int main() {
  cin >> N >> M >> Q;

  a.resize(Q);
  b.resize(Q);
  c.resize(Q);
  d.resize(Q);
  for (int i = 0; i < Q; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }

  vector<int> A(0);

  cout << searchMax(A) << endl;
}

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

int gcd(int x, int y){
    int r;
    if(x == 0 || y == 0)
        return 0;
    while((r = x % y) != 0){
        x = y;
        y = r;
    }
    return y;
}

int main(){
    int N, K, A[100000];
    cin >> N >> K;
    // 最初からKが含まれるなら"POSSIBLE"
    for(int i=0;i<N;i++){
        cin >> A[i];
        if(A[i] == K){
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    
    // A[0]~A[N-1]全ての最大公約数Gを求める
    int G = A[0];
    for(int i=1;i<N;i++)
        G = gcd(G, A[i]);
    // 降順ソート
    sort(A, A + N, greater<int>());
    // Kが最大値Mより大きいと"IMPOSSIBLE"
    if(A[0] < K){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    
    // KがGで割り切れるなら"POSSIBLE"
    if(K%G == 0)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i, x) for (ll i = 0; i < (x); i++)

using namespace std;
typedef long long int ll;

int main(void) {
  ll N, M, K;
  cin >> N >> M >> K;
  vector<ll> a(N+1), b(M+1);
  for (int i = 1; i <= N; i++) { cin >> a[i]; a[i] += a[i-1]; }
  for (int i = 1; i <= M; i++) { cin >> b[i]; b[i] += b[i-1]; }

  ll ans = 0;
  rep(i, N + 1) {
    if (a[i] > K) continue;
    ll k = K - a[i];
    // cout << "i = " << i << " k = " << k << endl;
    ll ok = 0, ng = M + 1;
    while (ok + 1 < ng) {
      ll m = (ok + ng) / 2;
      if (b[m] <= k) ok = m;
      else ng = m;
    }
    ans = max(ans, i + ok);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6408
#include <iostream>
#include <string>
#include<cstdlib>
using namespace std;
struct T{
    int key;
    T *parent,*left,*right;
};
    T *root=NULL;
void insert(int k){
    T *y=NULL;
    T *x=root;
    T *z=new T();
    *z={NULL};
    z->key=k;
    while(x!=NULL){
        y=x;
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    z->parent=y;
    if(y==NULL){
        root=z;
    }
    else if(z->key < y->key){
        y->left=z;
    }
    else{
        y->right=z;
    }
}
T* minimum(T *z){
    while(z->left!=NULL){
        z=z->left;
    }
    return z;
}
T* Tfind(T *x,int k){
    T *z=new T();
    *z={NULL};
    z->key=k;
    while(x!=NULL){
        if(z->key==x->key){
            return x;
        }
        if(z->key < x->key){
            x=x->left;
        }
        else{
            x=x->right;
        }
    }
    return NULL;
}
void transplant(T *u,T *v){
    if(u->parent==NULL){
        root=v;
    }
    else if(u==u->parent->left){
        u->parent->left=v;
    }
    else{
        u->parent->right=v;
    }
    if(v!=NULL){
        v->parent=u->parent;
    }
}
void tdelete(int k){
    T *y;
    T *z= new T();
    *z={NULL};
    z=Tfind(root,k);
    if(z->left==NULL){
        transplant(z,z->right);
    }
    else if(z->right==NULL){
        transplant(z,z->left);
    }
    else{
        y=minimum(z->right);
        if(y->parent!=z){
            transplant(y,y->right);
            y->right=z->right;
            y->right->parent=y;
        }
        transplant(z,y);
        y->left=z->left;
        y->left->parent=y;
    }
}
void Preorder(T *root){
    if(root!=NULL){
        cout<<" "<<root->key;
        Preorder(root->left);
        Preorder(root->right);
    }
}
void Inorder(T *root){
    if(root!=NULL){
        Inorder(root->left);
        cout<<" "<<root->key;
        Inorder(root->right);
    }
}
int main(){
    int n,k;
    string s;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="insert"){
            cin>>k;
            insert(k);
        }
        else if(s=="find"){
            cin>>k;
            if(Tfind(root,k)!=NULL){
                cout<<"yes"<<endl;
            }
            else{
                cout<<"no"<<endl;
            }
        }
        else if(s=="delete"){
            cin>>k;
            tdelete(k);
        }
        else{
            Inorder(root);
            cout<<endl;
            Preorder(root);
            cout<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 26596
#include <iostream>
#include <cstdio>
#include <string>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>

using namespace std;

struct node{
    node(){
		parent=-1;
		depth=0;
		s=-1;
	}
	void set(const int c1,const int c2){
		if(c1!=-1&&c2!=-1){
			leaf.resize(2);
			leaf[0]=c1;
			leaf[1]=c2;
		}else if(c1!=-1||c2!=-1){
			leaf.resize(1);
			if(c1!=-1){
				leaf[0]=c1;
			}else{
				leaf[0]=c2;
			}
		}else{
			leaf.resize(0);
		}
	}
	int s;
	int height;
	int parent;
	int depth;
	vector<int> leaf;
};

int dp(int id,int d);
node dnode[100000];
int main()
{
	int N,id,c1,c2;
	queue<int> que;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>id>>c1>>c2;
		dnode[id].set(c1,c2);
	}
	//*
	for(int i=0;i<N;i++){
		if(dnode[i].leaf.size()){
			for(int j=0;j<dnode[i].leaf.size();j++){
				dnode[dnode[i].leaf[j]].parent=i;
				if(dnode[i].leaf.size()==2){
					dnode[dnode[i].leaf[j]].s=dnode[i].leaf[1-j];
				}
			}
		}
	}//*/
	for(int i=0;i<N;i++){
		if(dnode[i].parent==-1){
			/*
			for(que.push(i);!que.empty();que.pop()){
				for(int j=0;j<dnode[que.front()].leaf.size();j++){
					dnode[dnode[que.front()].leaf[j]].depth=dnode[que.front()].depth+1;
					if(dnode[dnode[que.front()].leaf[j]].leaf.size()){
						que.push(dnode[que.front()].leaf[j]);
					}
				}
			}//*/
			dp(i,0);
			break;
		}
	}//*/
	for(int i=0;i<N;i++){
		cout<<"node "<<i<<": parent = "<<dnode[i].parent<<", sibling = "<<dnode[i].s<<", degree = "<<dnode[i].leaf.size()<<", depth = "<<dnode[i].depth<<", height = "<<dnode[i].height;
		if(dnode[i].parent==-1){
			cout<<", root";
		}else if(dnode[i].leaf.size()){
			cout<<", internal node";
		}else{
			cout<<", leaf";
		}
		cout<<endl;
	}
}
int dp(int id,int d)
{
	dnode[id].depth=d;
	if(dnode[id].leaf.size()){
		int h1,h2;
		h1=dp(dnode[id].leaf[0],d+1);
		if(dnode[id].leaf.size()==2){
			h2=dp(dnode[id].leaf[1],d+1);
		}else{
			h2=0;
		}
		dnode[id].height=h1>h2?h1:h2;
		return dnode[id].height+1;
	}else{
		dnode[id].height=0;
		return 1;
	}
}

Measured memory_bytes: 5104
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long a, long long b){
    if(a >b) swap(a, b);
    REP(i, b){
        cout<<a;
    }
    cout<<endl;
}

int main(){
    long long a;
    scanf("%lld",&a);
    long long b;
    scanf("%lld",&b);
    solve(a, b);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int a, b;
    cin >> a >> b;
    // ans * 0.08 = a
    // ans * 0.10 = b
    // ans = a / 0.08
    // ans = b / 0.10
    // bが100のとき、ans=1000
    int ans = -1;
    for (int i = 1; i < 1001; i++) {
        int tax8 = (int)(i * 0.08);
        int tax10 = (int)(i * 0.10);
        if (a == tax8 && b == tax10) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


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

using ll=long long;

using T=vector<ll>;
class SegmentTree{
    int N;
    int M;
    vector<T> dat;
    
    T merge(T& x,T& y){
        T res(x.size());
        for(int i=0;i<x.size();i++){
            res[i]=max(x[i],y[i]);
        }
        return res;
    }
    T query_impl(int a,int b,int k,int l,int r){
        if(a<=l && r<=b) return dat[k];
        if(b<=l || r<=a) return T(M);
        int mid=(l+r)/2;
        T x1=query_impl(a,b,k*2+1,l,mid);
        T x2=query_impl(a,b,k*2+2,mid,r);
        return merge(x1,x2);
    }
    public:
    SegmentTree(int n,int m):M(m){
        N=1;
        while(N<n){
            N*=2;
        }
        dat.assign(2*N-1,T(m,0));
    }
    void update(int pos,T& vec){
        pos+=N-1;
        dat[pos]=vec;
        while(pos){
            int par=(pos-1)/2;
            int c1=par*2+1;
            int c2=par*2+2;
            dat[par]=merge(dat[c1],dat[c2]);
            pos=par;
        }
    }
    ll query(int a,int b){
        T res=query_impl(a,b,0,0,N);
        return accumulate(res.begin(),res.end(),0LL);
    }
    
};

vector<ll> asum;
ll dfs(int a,int b,int lb,int ub,SegmentTree& seg){
    if(a==b) return 0;
    int mid=(a+b)/2;
    int opt=max(lb,mid);
    ll res=0;
    for(int i=max(lb,mid);i<ub;i++){
        ll sc=seg.query(mid,i+1)-(asum[i]-asum[mid]);
        if(res<sc){
            opt=i;
            res=sc;
        }
    }

    ll lres=dfs(a,mid,lb,opt+1,seg);
    ll rres=dfs(mid+1,b,max(opt-1,0),ub,seg);
    return max({lres,rres,res});
}
int main(){
    int n,m;
    cin>>n>>m;
    
    vector<ll> a(n-1);
    asum.assign(n,0);
    for(int i=0;i<n-1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++){
        asum[i+1]=asum[i]+a[i];
    }
    
    vector<vector<ll>> b(n,vector<ll>(m));
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
        }
    }
    SegmentTree seg(n,m);
    for(int i=0;i<n;i++) seg.update(i,b[i]);
    cout<<dfs(0,n,0,n,seg)<<endl;

    return 0;
}

Measured memory_bytes: 34560
from collections import defaultdict

N = int(input())
a = list(map(int, input().split()))
ans = 0

d = defaultdict(int)

for i in a:
    d[i] += 1

tmp = sorted(d.items(), reverse=True)
cnt = 0
ans = 0
for i, j in tmp:
    if cnt == 0 and j >= 4:
        ans = i * i
        break
    if j >= 2 and cnt == 0:
        ans += i
        cnt += 2
    elif j >= 2 and cnt == 2:
        ans = ans * i
        break

print(ans)

Measured memory_bytes: 21412
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC104
{
    class Program
    {
        static int D;
        static int G;
        static int[] p;
        static int[] c;

        static void Main(string[] args)
        {
            Init();
            Proc();
        }

        static void Init()
        {
            var DG = Read();
            D = DG[0];
            G = DG[1];
            p = new int[D];
            c = new int[D];

            for (int i = 0; i < D; i++)
            {
                var pc = Read();
                p[i] = pc[0];
                c[i] = pc[1];
            }
        }

        static void Proc()
        {
            int minCount = int.MaxValue;

            for (uint bit = 0; bit < (1 << D); bit++)
            {
                //Console.WriteLine($"===========================");
                int tempCount = 0;
                int tempPoint = 0;

                // 全問正解の得点を加算
                SumPointComplete(bit, ref tempPoint, ref tempCount);

                if (tempPoint < G)
                {
                    // 目標未達の場合は得点の高い問題から加算
                    AddPointMiddle(bit, ref tempPoint, ref tempCount);
                }

                // 必要正解数の最小値を更新
                minCount = Math.Min(tempCount, minCount);
            }

            Console.WriteLine(minCount);
            Console.ReadLine();
        }

        static void SumPointComplete(uint bit, ref int point, ref int count)
        {
            //Console.WriteLine(Convert.ToString(bit, toBase: 2));
            // ボーナスの組み合わせを全探索
            for (int i = 0; i < D; i++)
            {
                if (((bit >> i) & 1) == 1)
                {
                    // 全問正解分の得点
                    point += p[i] * (100 * (i + 1));
                    // ボーナス得点
                    point += c[i];
              
                    count += p[i];
                }
                //Console.WriteLine($"[all]point:{point}, count:{count}");
            }

        }

        static void AddPointMiddle(uint bit, ref int point, ref int count)
        {

            //Console.WriteLine($"[mid start]point:{point}, count:{count}");

            for (int k = (D - 1); k >= 0; k--)
            {
                if (((bit >> k) & 1) == 1)
                {
                    // XXX: 全問正解した問題も加算対象になっている
                    // FIX: 当該ケースをガード
                    continue;
                }

                int tempCount = 0;
                while (point < G && tempCount < p[k])
                {
                    point += (100 * (k + 1));
                    tempCount++;
                    count++;

                    //Console.WriteLine($"point:{point}, G:{G}, tempCount:{tempCount}, p[k]:{p[k]}");
                }
            }
            //Console.WriteLine($"[mid end]point:{point}, count:{count}");
        }

        static int[] Read()
        {
            return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        }
    }
}

Measured memory_bytes: 13396
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int H = sc.nextInt();
            int W = sc.nextInt();
            if(H == 0 && W ==0){
                break;
            }else{
                for(int i = 0; i < H; i++){
                    for(int j = 0; j < W; j++){
                        if(i > 0 && i < (H-1) && j > 0 && j < (W-1)){
                            System.out.print(".");
                        }else{
                            System.out.print("#");
                        }
                    }
                    System.out.println();
                }
                System.out.println();
            }
        }
    }
}



Measured memory_bytes: 34876
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
typedef pair<int,int>   ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef set<int>        si;
typedef set<ii>         sii;

#define all(x) x.begin(), x.end()
#define clr(x,v) memset(x,v,sizeof x)
#define pb push_back
#define x first
#define y second
#define endl "\n"
#define MOD int(1e9+7)
#define N 200123
int n, t, ans;
int gcd (int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> t;
    for(int i=1;i<=t;i++){
        for(int j=1;j<=t;j++){
            for(int k=1;k<=t;k++)ans+=gcd(i,gcd(j,k));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3648
/*
 * kuki.cpp
 *
 *  Created on: 2018/04/19
 *      Author: J01003
 */
#include<iostream>
using namespace std;

int main(){

	int S,h,m,s,a;

	cin>>S;

	a=60;

	s=S;
	m=s/a;
	s%=a;

	h=m/a;

	m%=a;

	cout<<h<<":"<<m<<":"<<s<<endl;

	return 0;
}



Measured memory_bytes: 3096
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main(){
    int k;cin>>k;
    vector<int> v(8);
    vector<int> u(8,-1);
    vector<int> ans(8);
    for(int i=0;i<8;i++) v[i]=i;
    for(int i=0;i<k;i++){
        int r,c;cin>>r>>c;
        u[r]=c;
    }
    do{
        int flag=1;
        for(int i=0;i<8;i++){
            if(u[i]!=-1){
                if(u[i]!=v[i]) flag=0;
            }
        }
        if(flag){
            for(int i=0;i<8;i++){
                for(int j=0;j<8;j++){
                    if(i==j) continue;
                    if(abs(i-j)==abs(v[i]-v[j])) flag=0;
                }
            }
        }
        if(flag) ans=v;
    }while(next_permutation(v.begin(),v.end()));
    for(int i=0;i<8;i++){
        for(int j=0;j<8;j++){
            if(ans[i]==j) cout<<'Q';
            else cout<<'.';
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3148