akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if (a==b)
    {
        /* code */
        cout<<c<<endl;
    }
    else if(a==c){
        cout<<b<<endl;
    }
    else
    {
        cout<<a<<endl;
    }
    
    
    
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var a = input[1].split(" ").map(i => parseInt(i));
  var dp = new Array(K+1).fill(0);
  for(var i=0;i<a[0];i++){
    dp[i]="Second";
  }
  for(var i=a[0];i<K+1;i++){
    var flag=0;
    for(var j=0;j<N;j++){
      if(dp[i-a[j]]=="Second"){
        flag=1;
        break;
      }
    }
    if(flag==1){
      dp[i]="First";
    }else{
      dp[i]="Second";
    }
  }
  ans=dp[K];

  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 17740
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define LONGMAX 1e18
#define dd double
#define MOD 998244353 
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type)) 
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define endl "\n"
#define test() ll t;cin>>t;while(t--)
#define pb push_back
#define ff first	
#define ss second
#define all(v) v.begin(),v.end()
#define s(ar,n) sort(ar,ar+n)
#define rs(ar,n) sort(ar, ar+n, greater<ll>()) 
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define ov(a,n) for(ll i=n-1;i>=0;i--)cout<<a[i]<<" ";nl
#define maxa(ar,N) *max_element(ar,ar+N)
#define mina(ar,N) *min_element(ar,ar+N)
#define INF 1e9
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
ll power(ll x, ll y){ll res=1;x=x%MOD;while(y>0){if(y&1)res = (res*x) % MOD;y = y>>1;x = (x*x) % MOD;}return res;}  
ll logtwo(ll n){if(n==1)return 0;return logtwo(n/2)+1;}
void ceilsearch(ll ar[],ll low,ll high,ll x,ll &y){if(low>high)return;ll mid=(low+high)/2;if(ar[mid]>=x){y=mid;ceilsearch(ar,low,mid-1,x,y);}else{ceilsearch(ar,mid+1,high,x,y);}}
signed main()
{
	fastio();	
  	long double A,B,C;
  	cin>>A>>B>>C;
  	long double K=A*B;
  	//cout<<K<<endl;
  	K=sqrtl(K);
  	K*=2;
  	if(A+B+K<C)
  		cout<<"Yes"<<endl;
  	else
  		cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int x[100000], y[100000], n, sum;
int main() {
	for (int i = 2; i < 100000; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
	while (true) {
		cin >> n; sum = 0; if (!n) { break; }
		for (int i = 2; i <= n / 2; i++) {
			if (x[i] == 1 && x[n - i] == 1) {
				sum++;
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 1556
x=input().split(" ")
a=int(x[0])
b=int(x[1])
c=int(x[2])

if a>b:
    temp = a
    a = b
    b = temp

if b>c:
    temp = b
    b = c
    c = temp

if a>b:
    temp = a
    a = b
    b = temp
    
print(str(a)+" "+str(b)+" "+str(c))





Measured memory_bytes: 5592
#include<stdio.h>
int main(void)
{
  long p=1,n,a,i,t=1000000000000000000;
	double m=1;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%ld",&a);
    p*=a;
    m*=a;
  }
  if(p>t||m>t){
    printf("-1\n");
  }
  else{
    printf("%ld\n",p);
  }
  return 0;
}


Measured memory_bytes: 1732
#include<stdio.h>
int main(void)
{
    int n,x,y,b,p,i,j,a[365];
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d %d %d %d",&x,&y,&b,&p);
        if(b>=5&&p<=2){
            if(x*b+y*p>(x*b+y*2)*0.8){
                a[i]=(x*b+y*2)*0.8;
            }
            else {
                a[i]=x*b+y*p;
            }
        }
        if(b<=5&&p>=2){
            if(x*b+y*p>(x*5+y*p)*0.8){
                a[i]=(x*5+y*p)*0.8;
            }
            else {
                a[i]=x*b+y*p;
            }
        }
        if(b<=5&&p<=2){
            if(x*b+y*p>(x*5+y*2)*0.8){
                a[i]=(x*5+y*2)*0.8;
            }
            else {
                a[i]=x*b+y*p;
            }
        }
        if(b>=5&&p>=2){
            a[i]=(x*b+y*p)*0.8; 
        }
    }
    for(j=0;j<n;j++){
        printf("%d\n",a[j]);
    }
    return 0;
}

Measured memory_bytes: 1028
#include <stdio.h>

int main(void){
	int a,b;
	a = 0;
	b = 0;

	scanf("%d %d",&a,&b);
	if(a < b){
		printf("a < b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else if(a == b){
		printf("a == b\n");
	}

	return 0;
}

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

int dp[50];

int main() {
  int n;
  cin >> n;
  dp[0] = 1;
  dp[1] = 1;
  for (int i = 0; i <= 44; i++) {
    dp[i + 2] = dp[i + 1] + dp[i];
  }
  cout << dp[n] << endl;
  return 0;
}


Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    
    string ans = "";
    int x = tx -sx;
    int y = ty -sy;
    for(int i = 1; i <= y; i++){
        ans += "U";
    }
    for(int i = 1; i <= x; i++){
        ans += "R";
    }
    for(int i = 1; i <= y; i++){
        ans += "D";
    }
    for(int i = 1; i <= x+1; i++){
        ans += "L";
    }
    for(int i = 1; i <= y+1; i++){
        ans += "U";
    }
    for(int i = 1; i <= x+1; i++){
        ans += "R";
    }
    ans += "DR";
    for(int i = 1; i <= y+1; i++){
        ans += "D";
    }
    for(int i = 1; i <= x+1; i++){
        ans += "L";
    }
    ans += "U";

    cout << ans << endl;


    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> arr(N);

    for(int i = 0; i < N; i++) {
        cin >> arr[i];
    }

    int ans = 0;
    for(int i = 0; i < N - 2; i++) {
        for(int j = i + 1; j < N - 1; j++) {
            for(int k = j + 1; k < N; k++) {
                if(arr[i] != arr[j] && arr[j] != arr[k] && arr[i] != arr[k] && arr[i] + arr[j] > arr[k] && arr[j] + arr[k] > arr[i] && arr[i] + arr[k] > arr[j]) {
                    ans++;
                }
            }
        }
    }
    cout << ans;
}

Measured memory_bytes: 3620
#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(){
	int n;
	cin >> n;
	int k = pow(2, 10);
	vector<vector<int>> a(n, vector<int>(10));
	vector<vector<int>> c(n, vector<int>(11));
	rep(i, n) rep(j, 10) cin >> a.at(i).at(j);
	rep(i, n) rep(j, 11) cin >> c.at(i).at(j);
	int ma = -2000000000;
	for(int i=1; i<k; i++){
    	bitset<10> b1(i);
		int sum = 0;
		rep(j, n){
			int cou = 0;
			rep(l, 10){
				if(a.at(j).at(l) == 1 && b1.test(l)) cou++;
			}
			sum += c.at(j).at(cou);
		}
		if(ma < sum) ma = sum;
	}
	cout << ma << endl;
	return 0;
}

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

int main() {
	
	int n, ans = 0;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);
	sort(a.begin(), a.end());
	for(int i=0; i+2<n; i++) {
		for(int j=i+1; j+1<n; j++) {
			for(int k=j+1; k<n; k++) {
				if(a[i] != a[j] && a[j] != a[k] && (a[i]+a[j]>a[k])) ans++;
			}
		}
	}
	printf("%d", ans);
	
	return 0;
}


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


int main()
{
  while(true)
  {
    int h,w;
    cin>>h>>w;
    if(h==0 && w==0) break;
    for (int i = 0; i < w; ++i)
    {
      cout<<"#";
    }
    cout<<endl;
    for (int i = 0; i < h-2; ++i)
    {
      cout<<"#";
      for (int i = 0; i < w-2; ++i)
      {
        cout<<".";
      }
      cout<<"#"<<endl;
    }
    for (int i = 0; i < w; ++i)
    {
      cout<<"#";
    }
    cout<<endl<<endl;
  }  
}


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

int N;

int main(){
    cin >> N;
    int m = N, tmp = 0;

    while(m != 0){
        tmp += m % 10;
        m /= 10;
    }
    cout << (N % tmp == 0 ? "Yes\n" : "No\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))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    int k,x;
    cin >> k >> x;
    nfor(i, x - k + 1, x + k)cout << i << endl;
    return 0;
}


Measured memory_bytes: 256
from math import gcd as g
n,x=map(int,input().split())
l=list(map(int,input().split()))
l=sorted(l)
if x<=l[0]:
    l.insert(0,x)
elif x>=l[-1]:
    l.append(x)
else:
    for i in range(n-1):
        if l[i]<=x<l[i+1]:
            l.insert(i+1,x)
            break
ans=0
for i in range(n):
    ans=g(ans,l[i+1]-l[i])
print(ans)
    
    
    


Measured memory_bytes: 20512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    ll N;
    cin >> N;
    if(N == 1){
        printf("1\n");
        return 0;
    }

    vector<ll> x(N), y(N);

    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
    }

    vector<llll> sa;
    ll a, b;
    for (int i = 0; i < N; i++) {
        for (int j = i+1; j < N; j++) {
            a = x[i] - x[j];
            b = y[i] - y[j];
            if(a < 0){
                a = -a;
                b = -b;
            }
            else if(a == 0){
                b = abs(b);
            }
            sa.push_back(make_pair(a, b));
        }
    }

    sort(ALL(sa));

    ll S = sa.size();
    ll k = 1;
    ll tmp = 1;
    a = sa[0].first; b = sa[0].second;
    for (int i = 1; i < S; i++) {
        if(a == sa[i].first && b == sa[i].second){
            tmp++;
        }
        else{
            k = max(tmp, k);
            tmp = 1;
            a = sa[i].first; b = sa[i].second;
        }
    }
    k = max(tmp, k);

    printf("%lld\n", N - k);

}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
//const int n_max=301;
//vector<pair<int,int> > g[n_max];


template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
	if(g[i][k] == INF || g[k][j] == INF) continue;
	g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

/*void dfs(int s, int cl, int cv, Matrix< int > &dp){
  for(auto i:g[cv]){
    int to=i.first;
    int c=i.second;
    if(dp[s][to]==INT_MAX){
      if(c<=cl){
	dp[s][to]=1;
	dfs(s,cl-c,to,dp);
      }
    }
  }
}*/

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

  int n,m,l;
  cin >> n >> m >> l;
  int a,b,c;
  Matrix< ll > g(n, vector< ll >(n, LLONG_MAX));
  rep(i,m){
    cin >> a >> b >>c;
    --a;--b;
//    g[a].pb(mp(b,c));
    g[b][a]=c;
    g[a][b]=c;
  }
  warshall_floyd(g, LLONG_MAX);
  Matrix< int > dp(n, vector< int >(n, INT_MAX));

  
  int q;
  cin >> q;
  int s[q],t[q];
  rep(i,q){
    cin >> s[i] >> t[i];
    --s[i];--t[i];
  }  
  rep(i,n) dp[i][i]=0;
  rep(i,n) rep(j,n){
    if(g[i][j]<=l){
     dp[i][j]=1;
    }
  }
/*  rep(i,n){
    dfs(i,l, i, dp);
  }*/
  rep(i,n) dp[i][i]=0;
  warshall_floyd(dp, INT_MAX);
  rep(i,q){
    if(dp[s[i]][t[i]]<INT_MAX){
      cout << dp[s[i]][t[i]]-1 << endl;
    }
    else{
      cout << -1 << endl;
    }

  }

  
  return 0;


}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
#define e_b emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;
template<class T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int a,b;
  cin >> a >> b;
  cout << a*b << endl;

  return 0;
}

Measured memory_bytes: 3652
N = int(input())
T = list(map(int, input().split(' ')))
M = int(input())
PX_list = [list(map(int, input().split(' '))) for i in range(M)]

unused = sum(T)

for PX in PX_list:
    print(unused - T[PX[0] - 1] + PX[1])

Measured memory_bytes: 3060
#include <cstring>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;

#define PI 3.14159265359
#define all(v) v.begin(),v.end()
#define sortva(v) sort(all(v))
#define sortvd(v) sort(v.rbegin(),v.rend())
#define sortaa(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n),reverse(a,a+n)
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define sfstr(v) scanf("%s", v);
#define sz(v) (int)v.size()
#define ndl puts("")
#define SS stringstream
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

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

ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }

void PLAY() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(10);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int cnt[100010], a[100010];

int main() {
	//PLAY();

	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	
	int res = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] > n)
			res++;
		else
			cnt[a[i]]++;
	}
	for (int i = 1; i <= n; i++)
		if (cnt[i] < i)
			res += cnt[i];
		else
			res += cnt[i] - i;
	
	cout << res << endl;

	return 0;
}

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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;

double p[3005], dp[3005];

int main() {
    int n;
    scanf("%d", &n);
    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        scanf("%lf", &p[i]);
        for (int j = i; j >= 1; j--) dp[j] = (dp[j] * (1 - p[i])) + (dp[j - 1] * p[i]);
        dp[0] *= (1 - p[i]);
    }

    double res = 0;
    for (int i = (n + 1) / 2; i <= n; i++) res += dp[i];

    printf("%.10lf\n", res);
    return 0;
}


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

using namespace std;

int main() {
    string s;
    cin >> s;

    vector<char> characters(s.begin(), s.end());
    char first { *characters.begin() };

    auto firstCharacterCount { count(characters.begin(), characters.end(), first) };

    sort(characters.begin(), characters.end());
    characters.erase(unique(characters.begin(), characters.end()), characters.end());

    auto numOfUniqueCharacters {static_cast<int>(characters.size()) };

    auto text = (firstCharacterCount == 2 && numOfUniqueCharacters == 2) ? "Yes" : "No";

    cout << text << endl;

    return 0;
}

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

using namespace std;

int main(){
	string S;
	cin >> S;
	int countp=0, countm=0;
	for (int i = 0; i < 4; i++) {
		if (S[i] == '+')
			countp++;
		else
			countm++;
	}
	cout << countp - countm << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000
int main()
{
  unsigned short *A,*B;
  int n,C[VMAX+1],i,j;
  scanf("%d",&n);
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);
  for(i=0;i<=VMAX;i++)
  {
    C[i]=0;
  }
  for(i=0;i<n;i++)
  {
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<=VMAX;i++)
  {
    C[i] = C[i] + C[i-1];
  }
  for(j=1;j<=n;j++)
  {
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }
  for(i=1;i<=n;i++)
  {
    printf("%d",B[i]);
    if(i!=n)
    printf(" ");
  }
  printf("\n");
  return 0;
}



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

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

  cout << max({A + B, A - B, A * B}) << endl;
  return 0;
}

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


int main() {
  char a,b,c,d;
  cin >> a >> b >> c >> d;
  int A=a-'0';
  int B=b-'0';
  int C=c-'0';
  int D=d-'0';
  
  if(A+B+C+D==7) {
	cout<<A<<"+"<<B<<"+"<<C<<"+"<<D<<"="<<7<<endl;
	return 0;
  }
  if(A+B+C-D==7) {
	cout<<A<<"+"<<B<<"+"<<C<<"-"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A+B-C+D==7) {
	cout<<A<<"+"<<B<<"-"<<C<<"+"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A+B-C-D==7) {
	cout<<A<<"+"<<B<<"-"<<C<<"-"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A-B+C+D==7) {
	cout<<A<<"-"<<B<<"+"<<C<<"+"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A-B+C-D==7) {
	cout<<A<<"-"<<B<<"+"<<C<<"-"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A-B-C+D==7) {
	cout<<A<<"-"<<B<<"-"<<C<<"+"<<D<<"="<<7<<endl;
	return 0;
  }  
  if(A-B-C-D==7) {
	cout<<A<<"-"<<B<<"-"<<C<<"-"<<D<<"="<<7<<endl;
	return 0;
  }  
  return 0;
}    

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())

L = list(map(int,input().split()))

L.sort()

con = 0

for i in range(0,N):
  for j in range(i + 1,N):
    a = L[i]
    b = L[j]
    #a + bよりでかい最小の数のインデックス
    p = bisect_left(L,a + b)
    #cとbの間の区間を取る
    con += (p - 1) - j


print(con)



Measured memory_bytes: 3188
#include<iostream>
#include<queue>

const static int MAX = 100;
int R[MAX][MAX];
int color[MAX], ar[MAX];
int n;

int search(int i){
    std::queue<int> qu;
    if(color[i] == 1){
	return 1;
    }
    qu.push(i);
    color[i] = 1;
    ar[i] = 0;
    while(!qu.empty()){
	int cur = qu.front();
	int flag = 0;
	for(int j = 0; j < n; j++){
	    if(R[cur][j] == 1 && color[j] == 0){
		qu.push(j);
		color[j] = 1;
		ar[j] = ar[cur] + 1;
		flag = 1;
	    }
	}
	if(flag == 0){
	    qu.pop();
	}
    }
    return 0;
}

int main(void){
    int u, k, v;
    std::cin >> n;

    for(int i = 0; i < MAX; i++){
	for(int j = 0; j < MAX; j++){
	    R[i][j] = 0;
	}
    }

    for(int i = 0; i < MAX; i++){
	color[i] = 0;
    }

    for(int i = 0; i < n; i++){
	std::cin >> u >> k;
	u--;
	for(int j = 0; j < k; j++){
	    std::cin >> v;
	    v--;
	    R[u][v] = 1;
	}
    }

    search(0);

    for(int i = 0; i < n; i++){
	if(color[i] == 0){
	    std::cout << i + 1 << " " << -1 << std::endl;
	}else{
	    std::cout << i + 1 << " " << ar[i] << std::endl;
	}
    }

    return 0;
}



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

bool check(){

  ll X=ans[0];
  
  ll sum=0;
  for(ll x:ans){
    sum+=x;
    X= __gcd(X,x);
  }

  //  cout<<sum<<' '<<X<<endl;
  for(ll x:ans){
    if( __gcd(sum-x,x) ==1 )return false;
  }

  if( X!=1)return false;
  return true;
}

void solve(){

  if(n==3){
    ans.push_back(2);
    ans.push_back(5);
    ans.push_back(63);
    return;
  }
  
  if(n<=5000){
    ans.push_back(2);
    ans.push_back(3);
    ans.push_back(4);
    ans.push_back(9);
    for(ll i=0;i<n-4;i++)ans.push_back(6*(i+1));
    return;
  }

  ll total=0;
  int cc=0;
  vector<ll> X,Y,YY,Z;
  for(ll i=2;i<=30000;i++){
    if(i%2==0 && i%3>0){
      X.push_back(i);
    }else if(i%2>0 && i%3==0){
      if(cc%2==0) Y.push_back(i);
      else YY.push_back(i);
      cc++;
    }else if(i%6==0){
      Z.push_back(i);
    }
  }

  reverse(X.begin(),X.end());
  reverse(Y.begin(),Y.end());
  reverse(YY.begin(),YY.end());
  reverse(Z.begin(),Z.end());
  //  cout<<X.size()<<' '<<Y.size()<<' '<<YY.size()<<endl;
  
  while( (int)ans.size() < n ){
    
    if((int)( ans.size() + Z.size()) >= n )break;

    
    if( X.size() >= 2  && (int)ans.size()+2 <=n ){
      for(int i=0;i<2;i++){
        ans.push_back(X.back());
        X.pop_back();
      }
    }

    
    if( YY.size() >= 2  && (int)ans.size()+2 <=n ){
      for(int i=0;i<2;i++){
        ans.push_back(YY.back());
        YY.pop_back();
      }
    }
    
    if( Y.size() >= 2  && (int)ans.size()+2 <=n ){
      for(int i=0;i<2;i++){
        ans.push_back(Y.back());
        Y.pop_back();
      }
    }


  }
  //  cout<<X.size()<<' '<<Y.size()<<endl;
  
  while( (int)ans.size() < n ){
    ans.push_back(Z.back());
    Z.pop_back();
  }
}

int main(){
  while(cin>>n){
    ans.clear();
    
    solve();

        assert(check());
        for(ll x:ans)cout<<x<<endl;
  }

  return 0;
}


Measured memory_bytes: 896
n = int(input())
A = list(map(int, input().split()))

dp = [[0]*(n+1) for i in range(n+1)]

for d in range(1, n+1):
    for i in range(n+1-d):
        j = i+d
        if (n-d)%2 == 0:
            dp[i][j] = max(dp[i+1][j]+A[i], dp[i][j-1]+A[j-1])
        else:
            dp[i][j] = min(dp[i+1][j]-A[i], dp[i][j-1]-A[j-1])
print(dp[0][n])

Measured memory_bytes: 113116
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int a, b;
    cin >> a >> b;
    if (a % b == 0)
        cout << 0;
    else
        cout << 1;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <fstream>
#include <cassert>
#include <ctime>
#include <list>
#include <numeric>
#include <iomanip>


using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#ifndef M_PI
const double M_PI=acos(-1);
#endif
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int((a).size()))
#define F first
#define S second
int dx[]={0,1,0,-1,1,1,-1,-1},dy[]={1,0,-1,0,1,-1,1,-1};


bool ispr[123456*2+100];
int n;

void solve(){
  int ans = 0;
  for(int i=n+1;i<=2*n;++i)
    ans += !ispr[i];
  cout << ans <<endl;
}

main(){
  ispr[0] = ispr[1] = true;
  for(int i = 2;i<123456*2+100;++i)
    if(!ispr[i])
      for(int j = i * 2;j<123456*2+100;j+=i)
        ispr[j] = true;
  
  while(cin>>n,n) solve();
}

Measured memory_bytes: 1400
D,N = map(int, input().split())
List = []
if D == 0:
    if N == 100:
        ans = 101
    else:
        ans = N
elif D == 1:
    if N == 100:
        ans = 10100
    else:
        ans = N * 100
else:
    if N == 100:
        ans = 1000000 + 10000
    else:
        ans = N * 10000
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include<algorithm>
#include<string>
#include <cmath>
#include <vector>
#include <map>
#include <cstdio>
#pragma region Macros
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ALL(x) (x).begin(),(x).end()
#define swap(a,b) (a += b,b = a - b,a -= b)
#define CEIL(a,b) ((a+b-1)/b)
#define LAST(X) X[X.size()-1]
#define MOD 1000000007
int GCD(int a, int b) // assuming a,b >= 1
{
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	if (a % b == 0)
		return b;
	return GCD(b, a % b);
}
int LCM(int a, int b) // assuming a,b >= 1
{
	return  a * b / GCD(a, b);
}
inline bool BETWEEN(int x, int min,int max) {
	if (min <= x && x <= max)
		return true;
	else
		return false;
}

using namespace std;
#pragma endregion
signed main() {
	int N, H, W;
	cin >> N >> H >> W;
	cout << (N - H + 1) * (N - W + 1);
}

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

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int N, M, X, Y; cin >> N >> M >> X >> Y;
    vector<int> x(N), y(M);
    REP(i, N) cin >> x[i];
    x.push_back(X);
    REP(i, M) cin >> y[i];
    y.push_back(Y);
    ASC(x); ASC(y);
    if (x[N] >= y[0]) cout << "War" << endl;
    else cout << "No War" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n,m;
vector<int> adjlist[N];
int S, T;
int p[N],col[N], num[N];
int ans = 0;
void dfs2(int u){
    for (auto v : adjlist[u]){
        if (p[v] == u){
            dfs2(v);
            num[u] += num[v];
        }
    }
    ans += abs(num[u]);
}
void dfs1(int u){
    for (auto v : adjlist[u]){
        if (col[v] == -1){
            col[v] = 1^col[u];
            p[v] = u;
            dfs1(v);
        }
        else if (p[u] != v) S = v, T = u;
    }
}
int main(){
    scanf("%d%d",&n,&m);
    for (int i = 0,a,b; i < m; i++){
        scanf("%d%d",&a,&b);
        adjlist[a].push_back(b);
        adjlist[b].push_back(a);
    }
    memset(col,-1,sizeof(col));
    col[1] = 0;
    p[1] = 0;
    dfs1(1);
    for (int i = 1; i <= n; i++){
        num[i] = col[i]?-1:1;
    }
    dfs2(1);
    if (n == m){
        //printf("%d %d\n",S,T);
        if (col[S] != col[T]){
            //printf("even cycle");
            int c = S;
            vector<int> li;
            while (c != T){
                li.push_back(num[c]); c = p[c];
            }
            sort(li.begin(),li.end());
            int x = li[li.size()/2];
            c = S;
            while (c != T){
                num[c] -= x; c = p[c];
            }
            ans = abs(x);
            for (int i = 1; i <= n; i++){
                ans += abs(num[i]);
            }
        }
        else{
            //printf("odd cycle\n");
            int x = num[1]/2;
            //printf("difference is %d\n",num[T]);
            for (int i = 1; i <= n; i++){
                num[i] = col[i]?-1:1;
            }
            num[S] -= x;
            num[T] -= x;
            ans = abs(x);
            dfs2(1);
        }
    }
    if (num[1]) printf("-1");
    else printf("%d",ans);
}


Measured memory_bytes: 12156
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = readline() |> chomp
	cn = 0
	cw = 0
	cs = 0
	ce = 0
	for i in 1:length(s)
		if s[i] == 'N'
			cn = 1
		elseif s[i] == 'W'
			cw = 1
		elseif s[i] == 'S'
			cs = 1
		elseif s[i] === 'E'
			ce = 1
		end
	end
	println(cn==cs&&cw==ce?"Yes":"No")
end
main()


Measured memory_bytes: 108340
#include <stdio.h>

int main(){
  int A, B;
  scanf("%d %d",&A,&B);
  if(A>9){
    printf("-1\n");
  }else if(B>9){
    printf("-1\n");
  }else{
    printf("%d\n", A*B);
  }
  return 0;//
}

Measured memory_bytes: 1696
N = int(input())

ans = [0] * (N-1)
CSF = [[int(i) for i in input().split()] for i in range(N-1)]

for i in range(N-1):
    now = 0
    for tranit_time, start, interval in CSF[i:]:
        if now <= start:
            now = start
            now += tranit_time
        else:
            if (now - start) % interval == 0:
                now += tranit_time
            else:
                now += interval - ((now - start) % interval)
                now += tranit_time
    ans[i] = now

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

Measured memory_bytes: 3188
#include <cstdio>
#include <set>
#include <map>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

char buf[100];
ll as[10];
int main(void) {
  int n;
  scanf("%d", &n);
  map<char, int> mm;
  REP(i, n) {
    scanf("%s", buf);
    mm[buf[0]]++;
  }
  REP(i, 5) {
    as[i] = mm["MARCH"[i]];
  }
  ll res = 0;
  REP(i, 5) {
    REP(j, i) {
      REP(k, j) {
        res += as[i]*as[j]*as[k];
      }
    }
  }
  printf("%lld\n", res);
  
  return 0;
}


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


int main() {
int N;
cin>>N;
vector<int> a(N);
for(int i=0;i<N;i++) cin>>a[i];

long ans=0;
for(int i=0;i<N-1;i++){
  ans+=a[i]/2;
  a[i]-=a[i]/2*2;
  int t=min(a[i],a[i+1]);
  ans+=t;
  a[i]-=t;
  a[i+1]-=t;
}
ans+=a[N-1]/2;
a[N-1]-=a[N-1]/2*2;
cout<<ans<<endl;
}


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template <class T> inline bool chmax(T &a, T b) {if(a < b) {a= b;return 1;}return 0;}
template <class T> inline bool chmin(T &a, T b) {if(a > b) {a= b;return 1;}return 0;}
ll mod= 1e9 + 7;



int main(){
  int x,y;
  cin >> x>>y;
  int d[13]={0,1,3,1,2,1,2,1,1,2,1,2,1};
  if(d[x]==d[y]){cout << "Yes" << endl;}else{cout << "No" << endl;}
}


Measured memory_bytes: 3576
N = int(input())
A, B = [int(v) for v in input().split()]
P = [int(v) for v in input().split()]

num1 = 0
num2 = 0
num3 = 0
for v in P:
    if v <= A:
        num1 += 1
    elif A < v <= B:
        num2 += 1
    else:
        num3 += 1

print(min([num1, num2, num3]))

Measured memory_bytes: 3064
# -*- coding:utf-8 -*-

def solve():
    """ 
    dic[a] := 数字aが紙に書かれているか否か（True/False）
    """
    N = int(input())
    dic = {}
    for i in range(N):
        a = int(input())
        if not a in dic:
            dic[a] = True
            continue
        if dic[a] == True:
            dic[a] = False
        else:
            dic[a] = True
    
    ans = 0
    for key in dic:
        if dic[key]: ans += 1
    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 15072
import java.util.*;

public class Main{
    private static final Scanner scan = new Scanner(System.in);
    static boolean flag = false;

    public static void main(String[] args){

        int n = scan.nextInt();
        Integer[] d = new Integer[6];
        Dice[] dices = new Dice[n];


        for(int i = 0; i < n ; i++){
            for(int j = 0; j < 6; j++){
                d[j] = scan.nextInt();
            }
            Object[] objs = (Object[]) d;
            dices[i] = new Dice((Object[]) objs);
        }

        boolean ans = true;
        for(int i = 0; ans && i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(dices[i].equals(dices[j])){
                    ans = false;
                    break;
                }
            }
        }
        System.out.println(ans? "Yes" : "No");
    }
}

class Dice{

    int[] _d = new int[6];
    public static final int
        TOP = 0, SOUTH = 1, EAST = 2,
        WEST = 3, NORTH = 4, BOTTOM = 5; // ?????°

    public Dice(Object... obj){ // ?????????????????????
Integer c[]=new Integer[6];
        for(int i = 0; i < 6; i++){

// System.out.println(obj.getClass());
            if(obj instanceof Integer[]){
// System.out.println("qwe");
                Integer[] d = (Integer[])obj;
                _d[i] = d[i];
            }
        }
    }

    public int[] showAll(){
        return _d;
    }

    @Override
    public boolean equals(Object obj){
        boolean result = false;
        Dice dice = (Dice) obj;
        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollEast();
            }
            for(int j = 0; j < 4; j++){
                if(Arrays.equals(showAll(), dice.showAll())){
                    result = true;
                    break;
                }
                dice.rollNorth();
            }
            if(Arrays.equals(showAll(), dice.showAll())){
                result = true;
                break;
            }
            dice.rollRight();
        }
        return result;
    }

    public void rollSouth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[NORTH];
        _d[NORTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[SOUTH];
        _d[SOUTH] = tmp;
    }

    public void rollNorth(){
        int tmp = _d[TOP];
        _d[TOP] = _d[SOUTH];
        _d[SOUTH] = _d[BOTTOM];
        _d[BOTTOM] = _d[NORTH];
        _d[NORTH] = tmp;
    }

    public void rollEast(){
        int tmp = _d[TOP];
        _d[TOP] = _d[WEST];
        _d[WEST] = _d[BOTTOM];
        _d[BOTTOM] = _d[EAST];
        _d[EAST] = tmp;
    }

    public void rollWest(){
        int tmp = _d[TOP];
        _d[TOP] = _d[EAST];
        _d[EAST] = _d[BOTTOM];
        _d[BOTTOM] = _d[WEST];
        _d[WEST] = tmp;
    }

    public void rollRight(){
        int tmp = _d[SOUTH];
        _d[SOUTH] = _d[WEST];
        _d[WEST] = _d[NORTH];
        _d[NORTH] = _d[EAST];
        _d[EAST] = tmp;
    }
}

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

using namespace std;

int main()
{
    int cnt = 0;
    string s;
    cin >> s;
    int len = s.size();
    int l = 0,r = len-1;
    while(l <= r)
    {
        //cout << "123" << endl;
        if(s[l] != s[r])
        {
             cnt ++;
             l ++;
             r --;
        }
        else
        {
            l ++;
            r --;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, t) = readLine()!!.split(" ").map(String::toInt)
    (1..n).map {
        readLine()!!.split(" ").map(String::toInt).let { if (it[1] > t) 1111 else it[0] }
    }.run { print(if (min()!! > 1000) "TLE" else min()) }
}

Measured memory_bytes: 37824
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
#define rep(i, a, b) for(ll i = (ll)a; i < (ll)b; i++)
using namespace std;

ll gcd(ll a, ll b) {
  if(a % b == 0) return b;
  return gcd(b, a%b);
}

ll lcm(ll a, ll b) {
  return a / gcd(a,b) * b;
}

int main() {
  int n;
  cin >> n;
  vector<ll> v(n);
  rep(i, 0, n) cin >> v[i];
  ll m = v[0];
  rep(i, 1, n) {
    m = lcm(m, v[i]);
  }
  cout << m << "\n";
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
	double eye[40][2];
	int num[4][2]={0};
	int i,j;

	for(i=0; scanf("%lf %lf",&eye[i][0],&eye[i][1])!=EOF; i++)
		for(j=0; j<2; j++)
			if(eye[i][j]>=1.1)
				num[0][j]++;
			else if(eye[i][j]>=0.6)
				num[1][j]++;
			else if(eye[i][j]>=0.2)
				num[2][j]++;
			else
				num[3][j]++;
	for(i=0; i<4; i++)
		printf("%d %d\n",num[i][0],num[i][1]);

	return 0;
}

Measured memory_bytes: 628
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 0, b = 0, c, d, n, k = 0, ans = 0;
string s, t;


int main()
{
	cin >> a >> b; vector<int>x(a);
	rep(i, a)
		cin >> x[i];
	sort(all(x), greater<int>());
	int sum = 0;
	rep(i, b)
		sum += x[i];
	cout << sum << endl;
	

	return 0;
}


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

using ll = long long;
using Pair = std::pair<int, int>;

int n, m, h, k;
int hori_bars[101000]; //?????´??????????£?
int stat[1010]; //????£??????\?¶??????????->??????
int last[1010]; //????£??????\?¶??????????->??????
int score[1010]; //????£??????\?¶??????????->????????¢
Pair swapping[100010]; //?¨??£?->????£?????????????????????´???(????????§?????????

int main() {
    while(std::cin >> n >> m >> h >> k, n + m + h + k) {
    
    for(int i = 0; i < n; ++i) {
        std::cin >> score[i];
    }
    std::vector<Pair> bars;
    bars.reserve(m);
    for(int i = 0; i < m; ++i) {
        int a, b;
        std::cin >> a >> b;
        --a;
        bars.emplace_back(Pair{b, a});
    }
    std::sort(bars.begin(), bars.end());
    
    for(int i = 0; i < bars.size(); ++i)
        hori_bars[i] = bars[i].second;
    
    for(int i = 0; i < n; ++i)
        stat[i] = i;
    
    for(int i = 0; i < m; ++i) {
        swapping[i] = {stat[hori_bars[i]], stat[hori_bars[i] + 1]};

        std::swap(stat[hori_bars[i]], stat[hori_bars[i] + 1]);
    }
    
    for(int i = 0; i < n; ++i) {
        last[stat[i]] = i;
    }
    
    int ans = 0, base;
    for(int i = 0; i < n; ++i) {
        if(stat[i] < k) {
            ans += score[i];
        }
    }
    base = ans;
    
    for(int i = 0; i < m; ++i) {
        auto a = swapping[i].first;
        auto b = swapping[i].second;
        
        if(a < k && b < k || a >= k && b >= k)
            continue;
        
        if(a < k) {
            ans = std::min(ans, base - score[last[a]] + score[last[b]]);
        }
        std::swap(a, b);
        if(a < k) {
            ans = std::min(ans, base - score[last[a]] + score[last[b]]);
        }
    }
    
    std::cout << ans << std::endl;
    }
}

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

const int MX = 100005;
vector<P> g[MX];
int x[MX];
bool used[MX];

vector<int> ans;
int dfs(int v) {
  used[v] = true;
  int res = x[v];
  for (P e : g[v]) {
    if (used[e.first]) continue;
    int r = dfs(e.first);
    if (r) ans.push_back(e.second);
    res ^= r;
  }
  return res;
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> a(n);
  rep (i, n) cin >> a[i].first >> a[i].second;
  sort(a.begin(), a.end());
  x[0] = a[0].second;
  rep(i, n - 1) x[i + 1] = a[i].second ^ a[i + 1].second;
  x[n] = a[n - 1].second;

  rep(i, m) {
    int l, r ;
    cin >> l >> r;
    l = lower_bound(a.begin(), a.end(), P(l, 0)) - a.begin();
    r = upper_bound(a.begin(), a.end(), P(r, 1)) - a.begin();
    g[l].emplace_back(r, i + 1);
    g[r].emplace_back(l, i + 1);
  }

  rep(i, n + 1) {
    if (used[i]) continue;
    if (dfs(i)) {
      cout << -1 << endl;
      return 0;
    }
  }
  
  cout << ans.size() << endl;
  sort(ans.begin(), ans.end());
  rep (i, ans.size()) cout << ans[i] << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 15228
def solve():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    a = A[-1] - A[0]
    
    ma = 0
    for i in range(N-1):
        ma = max(ma, A[i+1]-A[i])
    
    return min(a, K-ma)

print(solve())

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int n, k;
	cin >> n;
	cin >> k;
	int ans = 0;
	while (n--) {
		int x;
		cin >> x;
		ans += min(x, k - x) * 2;
	}
	cout << ans << "\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	hawawa();
}


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

using namespace std;
using ll = long long;

int main() {
    int N = 0;
    cin >> N;
    vector<double> A(N,0);
    for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    }
    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());
    double ans = 0;

    for(int i = 0; i < N; i++) {
        ans += A.at(i)/pow(2, i + 1);
    }
    cout << ans + A.at(A.size() - 1)/pow(2, A.size() ) << endl;

    return 0;
}

Measured memory_bytes: 4172
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
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 (b < a) { a = b; return true; } return false; }

using Weight = int;
using Flow = int;
struct Edge {
	int s, d; Weight w; Flow c;
	Edge() {};
	Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
	bool operator<(const Edge &e)const { return w < e.w; }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int s, int d, Weight w = 1) { g[s].emplace_back(s, d, w); }

//??¨?????±???
//?????????: ???????????????????????????????????§?????¨????????°
vector<int> depth(const Graph &g, int root) {
	vector<int> ret(g.size(), INF);
	using State = tuple<int, int, int>;
	stack<State> st; st.emplace(root, -1, 0);
	while (st.size()) {
		int s, p, d; tie(s, p, d) = st.top(); st.pop();
		ret[s] = d;
		for (auto &e : g[s]) {
			if (e.d == p)continue;
			st.emplace(e.d, s, d + 1);
		}
	}
	return ret;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	double p; cin >> p;
	int N; cin >> N;
	Graph g(N);
	rep(i, 0, N - 1) {
		int x, y, c; cin >> x >> y >> c;
		x--, y--;
		add_edge(g, x, y, c);
	}
	vector<int> d = depth(g, 0);
	double a = 0;
	auto dfs = [&](const Graph &g, int root) {
		int n = g.size();
		vector<bool> f(n);
		stack<int> st; st.emplace(root);
		while (st.size()) {
			int u = st.top(); st.pop();
			f[u] = true;
			for (auto &e : g[u]) {
				if (f[e.d])continue;
				a += e.w * pow(p, d[e.d]);
				st.emplace(e.d);
			}
		}
	};
	dfs(g, 0);
	dump(a);
	double ans = a;
	auto dfs2 = [&](const Graph &g, int root) {
		int n = g.size();
		vector<bool> f(n);
		stack<int> st; st.emplace(root);
		while (st.size()) {
			int u = st.top(); st.pop();
			f[u] = true;
			ans += a * pow(p, d[u]);
			for (auto &e : g[u]) {
				if (f[e.d])continue;
				st.emplace(e.d);
			}
		}
	};
	dfs2(g, 0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 10876
#include <stdio.h>

int main(){
char S[3],T[3];
int i;

  for(i=0;i<3;i++){
scanf("%c",&S[i]);
}

for(i=0;i<3;i++){
  if(i==0)
    scanf("\n%c",&T[i]);
  else
scanf("%c",&T[i]);
}

int count=0;

for(i=0;i<3;i++){
	if(S[i]==T[i]){
		count++;
		}		
}
printf("%d",count);
}

Measured memory_bytes: 128
#include <stdio.h>
int main()
{
	int a,b,h,S;
	scanf("%d%d%d",&a,&b,&h);
	S=(a+b)*h/2 ;
	if(h%2==0)
	{
		printf("%d",S);
	}
	else
	{
	printf("NO");
		
	}
	return 0;	
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

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

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define rep(i,x) for(int i=0;i<(x);++i)
#define rep1(i,x) for(int i=1;i<=(x);++i)
#define rrep(i,x) for(int i=(x)-1;i>=0;--i)
#define rrep1(i,x) for(int i=(x);i>=1;--i)
#define FOR(i,a,x) for(int i=(a);i<(x);++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>istream&operator>>(istream&is,vector<T>&vec){rep(i,vec.size())is>>vec[i];return is;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 1e9;
const ll linf = 3e18;
const double eps = 1e-9;

signed main()
{
    int N, Q; cin >> N >> Q;

    vi c(N);

    rep(i, N) cin >> c[i];

    sort(all(c));

    rep(i, Q) {
        int q; cin >> q;

        int ma = 0;

        for (int i = q; i <= 300000; i += q) {
            ma = max(ma, *(lower_bound(all(c), i) - 1) % q);
        }

        cout << ma << endl;
    }
}

Measured memory_bytes: 2324
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextWord() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, e := strconv.Atoi(nextWord())
	if e != nil {
		panic(e)
	}
	return i
}

func max(lhs, rhs int) int {
	if lhs > rhs {
		return lhs
	}
	return rhs
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()

	var ans int
	if a > b {
		ans += a
		ans += max(a-1, b)
	} else {
		ans += b
		ans += max(b-1, a)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
import itertools

S=list(input())
N=len(S)

lis=list(range(1,N))
combi=[]
for i in range(N):
    a=list(itertools.combinations(lis,i))
    combi.extend(a)

ans=0  
for s in combi:
    sum=0
    temp=[]
    for i in range(N):
        if i in s:
            sum+=int("".join(temp))
            temp=[S[i]]
        else:
            temp.append(S[i])
    sum+=int("".join(temp))
    ans+=sum
print(ans)




Measured memory_bytes: 3064
SA = list(map(str, input()))
SB = list(map(str, input()))
SC = list(map(str, input()))

card = SA.pop(0)

if len(SA) == 0:
    print('A')
    exit()

while True:
#    print(card)
    if card == 'a':
        if len(SA) == 0:
            print('A')
            break
        card = SA.pop(0)
    if card == 'b':
        if len(SB) == 0:
            print('B')
            break
        card = SB.pop(0)
    if card == 'c':
        if len(SC) == 0:
            print('C')
            break
        card = SC.pop(0)


Measured memory_bytes: 3064