akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

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

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

P noAns = make_pair(0, 0);

P solve(int x, int y){
    if(x % 2 == 0 && y % 2 == 1){
        if(x - y / 2 <= 0){
            return noAns;
        }
        return make_pair(x - y / 2, y);
    }

    if(x % 2 == 1 && y % 2 == 0){
        if(x / 2 < y){
            return noAns;
        }
        return make_pair(x / 2 - y + 1, y * 2);
    }

    if(x / 2 >= y){
        return make_pair(x / 2 - y + 1, y * 2);
    }

    if(x - y / 2 > 0){
        return make_pair(x - y / 2, y);
    }
    return noAns;
}

signed main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }

        int ans = 0;
        int m;
        for(int i = 1; i * i <= n; i++){
            if(n % i != 0){
                continue;
            }
            if(i % 2 == 0 && n / i % 2 == 0){
                continue;
            }
            int x = i;
            int y = n / i;

            P p = solve(x, y);
            if(ans < p.second){
                ans = p.second;
                m = p.first;
            }

            p = solve(y, x);
            if(ans < p.second){
                ans = p.second;
                m = p.first;
            }
        }
        cout << m << " " << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
using namespace std;
#define pi pair<int32,int32>
#define pl pair<int64,int64>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}


int main(){
    int N,M; cin >> N >> M;
    int c[M];
    for (int i = 0; i < M; i++){
        cin >> c[i];
    }
    int dp[50050]; fill(dp,dp + 50050, MM);
    dp[0] = 0; dp[c[0]] = 1;
    for(int i = 0; i < M; i++){
        for(int m = 0; m < 50050; m++){
            if (dp[m-c[i]] != MM && m >= c[i]){
                dp[m] = min(dp[m], dp[m-c[i]] + 1);
            }
        }
    }
    cout << dp[N] << endl;
}


Measured memory_bytes: 3308
#include <bits/stdc++.h>
#define INF 2e9
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}

int main(){
  string S;
  cin >> S;
  vector<int> two_bit(pow(2, S.length()-1));
  llong ans = 0;
  if(S.length()==1) cout << S << endl;
  else{
    for(llong i=0; i<pow(2, S.length()-1); ++i){
      llong remain = i;
      for(int j=0; j<S.length()-1; ++j){
        two_bit[j] = remain / pow(2, S.length()-2-j);
        remain = remain % (llong) pow(2, S.length()-2-j);
      }
      int count = 0;
      for(int j=0; j<S.length()-1; ++j){
        ans += ctoi(S[S.length()-1-j]) * pow(10, count);
        if(two_bit[S.length()-2-j]==1) count = 0;
        else ++count;
      }
      ans += ctoi(S[0]) * pow(10, count);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 256
package main

import (
        "fmt"
)

func main() {
        var n int
        fmt.Scanf("%d", &n)

        var count int
        for i := 1; i <= n/2; i++ {
                count++
        }

        if n%2 == 0 {
                count--
        }

        fmt.Println(count)
}

Measured memory_bytes: 512
use List::Util 'min';

$d = 200001;
while(<>){
	chomp;
	if($. == 1){
		next;
	}elsif($. == 2){
		@a = (100001, split(/ /, $_));
	}elsif($. == 3){
		@b = (100001, split(/ /, $_));
	}else{
		($x, $y, $c) = split(/ /, $_);
		$now = $a[$x] + $b[$y] - $c;
		$d = min($d, $now);
	}
}

printf min($d, min(@a) + min(@b)) . "\n";


Measured memory_bytes: 28928
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] a = new int[n];
			for(int i = 0 ; i < n ; i++) {
				a[i] = sc.nextInt();
			}
			Arrays.sort(a);
			for(int i = 0 ; i < n - 1 ; i++) {
				if(a[i] == a[i + 1]) {
					System.out.println("NO");
					System.exit(0);
				}
			}
			System.out.println("YES");
		}

	}

}


Measured memory_bytes: 84800
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>
#include <cmath>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll H[100100];

int N;
ll A,B;
bool enough(int T){
    ll h[N];
    bool e = true;
    int t = T;
    REP(i,N){
        h[i] = H[i] - B*T;
        if(h[i] > 0){
            //t -= ceil(h[i]/(A-B));
            t -= h[i]/(A-B) + ((h[i] % (A-B)) != 0);
            if(t < 0) {
                e = false;
                break;
            }
        }
    }
    return e;
}

int main(){
    cin >> N >> A >> B;
    REP(i,N){
        ll h;
        cin >> h;
        H[i] = h;
    }
    ll l = 0; 
    ll r = 1e9;
    ll mid;
    while(l != r){
        mid = (l+r)/2;
        if(enough(mid)) r = mid;
        else l = mid+1;
    }
    cout << r << endl;
    //REP(i,1000){
    //    mid = (l+r)/2;
    //    if(enough(mid)) r = mid;
    //    else l = mid;
    //}
    //cout << r << endl;
    return 0;
}


Measured memory_bytes: 1792
/*
    Author : Pranav_Raut.
*/

#include<bits/stdc++.h>
using namespace std;
#define input(arr,n) for(ll i=0;i<n;i++){cin>>arr[i];}
typedef long long int ll;
ll MOD = 1000000007;
ll MAXN = 100005;


int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string a,b;

    cin>>a>>b;

    ll la = a.length();
    ll lb = b.length();
    ll arr[la+1][lb+1];

    for(ll i=0;i<=la;i++)
    {
        for(ll j=0;j<=lb;j++)
        {
            arr[i][j] = 0;
        }
    }

    for(ll i=1;i<=la;i++)
    {
        for(ll j=1;j<=lb;j++)
        {
            if(a[i-1]==b[j-1])
                arr[i][j] = arr[i-1][j-1] + 1;
            else
                arr[i][j] = max(arr[i-1][j],arr[i][j-1]);
        }
    }

    string ans = "";
    ll i = la, j = lb;
    while(1)
    {
        if(i==0||j==0)
            break;
        if(arr[i][j]==arr[i][j-1])
        {
            j--;
        }
        else if(arr[i][j]==arr[i-1][j])
        {
            i--;
        }
        else
        {
            i--;
            j--;
            ans = a[i] + ans;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int main() {
    int n, m;
    cin >> n >> m;
    vector<ll> x(n), y(n), z(n);
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i] >> z[i];
    }

    ll ans = 0;
    vector<ll> a(n);
    for(int i = 0; i < 8; i++){
        for(int j = 0; j < n; j++){
            ll tx = int(1&i) ? x[j] : -x[j];
            ll ty = int(1&i>>1) ? y[j] : -y[j];
            ll tz = int(1&i>>2) ? z[j] : -z[j];
            a[j] = tx + ty + tz;
        }
        sort(a.begin(),a.end());
        ll tmpans = 0;
        for(int j = 0; j < m; j++){
            tmpans += a[n-1-j];
        }
        ans = max(ans,tmpans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
 int main() {
   int A, B, C;
   std::cin >> A >> B >> C;
   if (A == B && B == C) {
     std::cout << "1" <<std::endl;
     return 0;
   } else if (A == B || A == C || B == C) {
     std::cout << "2" <<std::endl;
     return 0;
   } else {
     std::cout << "3" <<std::endl;
   }
   
   
   return 0;
   
 }

Measured memory_bytes: 256
$f{"0"} = "pon";
$f{"1"} = "pon";
$f{"2"} = "hon";
$f{"3"} = "bon";
$f{"4"} = "hon";
$f{"5"} = "hon";
$f{"6"} = "pon";
$f{"7"} = "hon";
$f{"8"} = "pon";
$f{"9"} = "hon";

chomp($s = <>);

$n = $1 if($s =~ /(\d)$/);

print "$f{$n}\n";


Measured memory_bytes: 4848
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;

void prvec(vector<ll> vec){
    ll n = vec.size();
    rep(i,n) cout << i << " " << vec.at(i) << "\n";
}

void pr2d(vector<vector<ll>> vvec){
    ll h = vvec.size();
    ll w = vvec.at(0).size();
    rep(i,h){
        rep(j,w){
            cout << vvec.at(i).at(j) << " ";
        }
        cout << "\n";
    }
}

int main(){
    ll s,w; cin >> s >> w;
    if(w>=s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
n=int(input())
ans = 0
for i in range(1,n+1):
    if i%2 == 0:
        continue
    count = 0
    for j in range(1, i+1):
        #print(i , j)
        if i%j == 0:
            count += 1
    if count == 8:
        ans += 1
print(ans)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
#define opt ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define lli long long int
#define mod		1000000007
#define inf     1000000000000000000
#define MX1		100005
#define MX2		10000004
#define pi		acos(-1)
#define pb      push_back
#define vlli    vector<lli>
#define plli    vector<pair<lli,lli> >
#define mp      make_pair
#define all(v)  v.begin(),v.end()
#define test    int t;cin>>t;
lli gcd(lli a, lli b){return b?gcd(b,a%b):a;}
lli power(lli a,lli b){lli ans=1;while(b){if(b&1){ans=(ans*a)%mod;}a=(a*a)%mod;b>>=1;}return ans;}
int main()
{
	opt;
	lli x,a,b;
	cin>>x>>a>>b;
	if(b<=a)
	cout<<"delicious\n";
	else if(b-a<=x)
	cout<<"safe\n";
	else
	cout<<"dangerous\n";

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1145141919
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}

class UnionFind
{
public:
    vector<ll> par; // 各元の親を表す配列
    vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL)
    {
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_)
    {
        siz.assign(sz_, 1LL); // assign: 再代入
        par.resize(sz_);      // resize: 再確保
        for (ll i = 0; i < sz_; ++i)
            par[i] = i; // 初期では親は自分自身
    }

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

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

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

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

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;
}

ll oddsolve(ll a) { return (a+1)/2 % 2; }
ll solve(ll a){
    if(a%2==1) return oddsolve(a);
    else return oddsolve(a+1)^(a+1);
}



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

    cout << (solve(B)^solve(A-1)) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include<debug.h>
#else
#define db(...) 21
#endif
#define found(m,x) ((m).find(x)!=(m).end())
#define uset unordered_set
#define umap unordered_map
#define a(x) x.begin(),x.end()
#define input(v,n) for(int i=0;i<n;i++)cin>>v[i]
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pi;

const int nax = 1e5+7;
const int mod = 1e9+7; //1e9+2667
const int inf = numeric_limits<int> :: max();
// ===================== MANASH =================== //

int n;

void test() {

    cin >> n;
    umap<int,int> m;
    for( int i = 1; i < n; i++) {
        int t;
        cin >> t;
        m[t]++;
    }
    for( int i = 0; i < n; i++) {
        if(not found(m,i+1)) {
            cout << 0 << '\n';
        }
        else cout << m[i+1] << '\n';
    }


}

signed main() {

    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef LOCAL
    freopen("input.txt","r",stdin);
    cout<<"Time Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec.\n";
    #endif

    int T = 1;
    
    //cin >> T;
    while(T--) {
        test();
        //cout << "\n";
    }
    return 0;

}

Measured memory_bytes: 11320
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto &__VA_ARGS__:(c))
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int H,W;
	cin>>H>>W;
	vector<string> S(H);
	fore(S,i) cin>>i;

	vector<int> di={-1,0,1,0};
	vector<int> dj={0,-1,0,1};

	auto bfs = [&](int r,int c) {
		vector<vector<int>> dist(H,vector<int>(W,-1));
		queue<pair<int,int>> q;
		dist[r][c]=0;
		q.emplace(r,c);
		while (!q.empty()) {
			int i,j;
			tie(i,j)=q.front();
			q.pop();

			rep(k,0,4) {
				int ni=i+di[k],nj=j+dj[k];
				if (ni<0||ni==H||nj<0||nj==W||S[ni][nj]=='#'||dist[ni][nj]!=-1) continue;
				dist[ni][nj]=dist[i][j]+1;
				q.emplace(ni,nj);
			}
		}

		int res=0;
		rep(i,0,H) rep(j,0,W) res=max(res,dist[i][j]);
		return res;
	};

	int res=0;
	rep(i,0,H) rep(j,0,W) if (S[i][j]!='#') res=max(res,bfs(i,j));
	cout<<res<<'\n';
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
template<class T,class U>inline void chmin(T &t,U f){if(t>f)t=f;}
template<class T,class U>inline void chmax(T &t,U f){if(t<f)t=f;}
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) > (b) ? (b) : (a))

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;

ll gcd(ll a,ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
#define INF INT_MAX/3
#define MAX_N 1000
ll n,x;
void solve(){
   cin.tie(0);
  ios::sync_with_stdio(false);
  cin>>n>>x;
  ll N = n;
  if(n>x) swap(n,x);
  cout<<3*(N-gcd(n,x))<<endl;
}
int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

aerials = [a,b,c,d,e]
maxA = max(aerials)
minA = min(aerials)

print(":(" if k < maxA-minA else "Yay!")

Measured memory_bytes: 3064
#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, m, k;
  cin >> n >> m >> k;

  bool ok = false;
  for (int nn = 0; nn <= n; nn++) {
    for (int mm = 0; mm <= m; mm++) {
      if (nn * (m - mm) + mm * (n - nn) == k) {
        ok = true;
      }
    }
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数

// デフォルト変数定義
int n,m,a,b,c=0,x,y,z;
double d,e,f;
string s,t;
//

signed main() {
  RAPID;
  IN(s);
  if(s[0]=='o') c+=100;
  if(s[1]=='o') c+=100;
  if(s[2]=='o') c+=100;
  OUT(700+c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int s,count = 1;
    cin >> s;
    vector<int> v;
    v.push_back(s);
    bool flag = true;
    while(flag)
    {
        if(s % 2 == 0)
        {
            s = s / 2;
        }
        else
        {
            s = 3 * s + 1;
        }
        count++;
        v.push_back(s);
        if(v.size() >= 2)
        {
            for(int i = 0;i < v.size() - 1;i++)
            {
                if(v.at(i) == s)
                {
                    flag = false;
                    break;
                }
            }
        }
    }
    cout << count;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdio>
#include <stack>
#include <queue>
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(){
    ll x,y;
    cin>>x>>y;
    ll ans=0;
    if(x==1){
        ans+=300000;
    }else if(x==2){
        ans+=200000;
    }else if(x==3){
        ans+=100000;
    }
    if(y==1){
        ans+=300000;
    }else if(y==2){
        ans+=200000;
    }else if(y==3){
        ans+=100000;
    }
    if(x==1 and y==1){
        ans+=400000;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list((map(int,input().split())))
a.sort(reverse=True)
p=1
ans=a[0]
i=1
while p<(n-1):
    ans+=(2*a[i])
    
    i+=1
    p+=2
if p!=(n-1):
    ans-=a[i-1]
print(ans)

Measured memory_bytes: 94112
M=10**9+7;x,y=map(int,input().split());d,m=divmod(x+y,3)
if m or y>2*x or x>2*y:print(0);exit()
x-=d;y-=d;s=t=1
for i in range(min(x,y)):s=s*(x+y-i)%M;t=t*(i+1)%M
print(s*pow(t,M-2,M)%M)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
int c[10]={};
for(int i=0;i<n;i++){
int s;cin>>s;
c[min(s/400,8)]++;
}
int ans=0;
for(int i=0;i<8;i++){
if(c[i]) ans++;
}
cout<<max(ans,1)<<" "<<ans+c[8]<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;

int main(){
    int d, t;
    double x=0,y=0;
    double angle=90;
    while(1){
        char c;
        cin>>d>>c>>t;
        if(d==0&&t==0)
            break;
        x+=d*cos(angle/180*acos(-1));
        y+=d*sin(angle/180*acos(-1));
        angle-=t;
    }
    cout<<(int)x<<endl;
    cout<<(int)y<<endl;
}

Measured memory_bytes: 1164
#define _GLIBCXX_DEBUG
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <map>
#include <list>
#include <cmath>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define mp make_pair
#define pb push_back
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9+7;

int x[10], y[10];

double dist(int i, int j) {
	double dx = x[i] - x[j];
	double dy = y[i] - y[j];
	return pow(dx*dx + dy*dy, 0.5);
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

	double ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			ans += dist(i, j);
		}
	}

	ans *= (2/(double)n);
	printf("%8lf", ans);
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> l(n);

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

  sort(l.begin(), l.end());

  int result = 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(l[i] + l[j] > l[k]) {
          result++;
        }
      }
    }
  }

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
while True:
    (n,m) = map(int,input().split())
    if n == 0 and m == 0:
        break
    iss = list(map(int, input().split()))
    best = max([ (iss[i] + iss[j] if not ( i == j) and iss[i] + iss[j] <= m else -1) for i in range(0,n) for j in range(0,n) ])
    if(best < 0):
        print("NONE")
    else:
        print(best)



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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1L << 30
#define long long long
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

long X ;


int main(){
	cin >> X;

	long n_500 = X/500;
	long n_5 = (X%500)/5;

	cout << (1000*n_500) + (n_5*5) << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int p,a[3005];
int iC[3005][3005];
int inv[3005],ans;
int xs[3005][3005];
int g[3005];

int main(){
	scanf("%d",&p);
	for(int i=0;i<p;i++) scanf("%d",&a[i]);
	iC[0][0]=1;
	for(int i=1;i<=3000;i++){
		iC[i][0]=iC[i][i]=1;
		for(int j=1;j<i;j++) iC[i][j]=iC[i-1][j-1]+iC[i-1][j],iC[i][j]%=p;
	}
	for(int i=1;i<=3000;i++){
		for(int j=0;j<=i;j++) if((j&1)^(i&1)) iC[i][j]=p-iC[i][j];
	}
	inv[1]=1;
	for(int i=2;i<p;i++) inv[i]=(p-p/i)*inv[p%i]%p;
	inv[0]=1;
	for(int i=1;i<p;i++) inv[i]=inv[i]*inv[i-1]%p;
	for(int i=1;i<p;i++) xs[1][i]=1;
	for(int i=2;i<p;i++){
		for(int j=i;j<p;j++) xs[i][j]=(xs[i-1][j-1]+xs[i][j-1])*i%p;
	}
	for(int i=p-1;i>=1;i--){
		ans=0;
		for(int j=0;j<=i;j++) ans=(ans+iC[i][j]*a[j])%p;
		for(int j=i+1;j<p;j++){
			ans=(ans-xs[i][j]*g[j]%p+p)%p;
		}
		g[i]=ans*inv[i]%p;
	}
	g[0]=a[0];
	for(int i=0;i<p;i++) printf("%d ",g[i]);
	
	return 0;
}

Measured memory_bytes: 70784
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <climits>
#include <ctime>
#include <random>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
//#define ll long long
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	string ac = to_string(a), bc = to_string(b);
	string a1 = string(b, ac[0]), b1 = string(a, bc[0]);
	if (a1 < b1)
		cout << a1;
	else
		cout << b1;
}

Measured memory_bytes: 256
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

func readLine(r *bufio.Reader) []byte {
	buf := make([]byte, 0, 1024)
	for {
		l, p, e := r.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return buf
}

func main() {
	r := bufio.NewReaderSize(os.Stdin, 4096)

	var H, W int

	fmt.Scan(&H)
	fmt.Scan(&W)
	s := make([]string, H)

	for i := 0; i < H; i++ {
		s[i] = string(readLine(r))
	}

	//out(H, W, s)
	ans := "Yes"
L:
	for y := 0; y < H; y++ {
		for x := 0; x < W; x++ {
			if s[y][x] == '#' {
				flg := 0
				if x != 0 {
					if s[y][x-1] == '#' {
						flg = 1
					}
				}
				if x != W-1 {
					if s[y][x+1] == '#' {
						flg = 1
					}
				}
				if y != 0 {
					if s[y-1][x] == '#' {
						flg = 1
					}
				}
				if y != H-1 {
					if s[y+1][x] == '#' {
						flg = 1
					}

				}
				if flg == 0 {
					ans = "No"
					break L
				}
			}
		}
	}
	out(ans)
}


Measured memory_bytes: 640
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read

n,m,*pqc = map(int, read().split())

g = {}
M = iter(pqc)

for p,q,c in zip(M,M,M):
    pc = ((p-1)<<20)+c
    qc = ((q-1)<<20)+c
    pp = (p-1)<<20
    qq = (q-1)<<20
    
    if pc not in g: g[pc] = []
    if qc not in g: g[qc] = []
    if pp not in g: g[pp] = []
    if qq not in g: g[qq] = []
    
    g[pc].append(qc)
    g[pc].append(pp)

    g[qc].append(pc)
    g[qc].append(qq)

    g[pp].append(pc)
    g[qq].append(qc)

if 0 not in g: g[0] = []

from collections import deque
q = deque([(0,0)])
res = {0:0}

mask = (1<<20)-1
while q:
    vl,dv = q.popleft()
    if res[vl] < dv: continue
    if (vl>>20) == n-1:
        res[(n-1)<<20] = dv+1
        break
    for tl in g[vl]:
        ndv = dv + (vl&mask==0 or tl&mask==0)
        if tl not in res or res[tl] > ndv:
            res[tl] = ndv
            if vl&mask==0 or tl&mask==0:
                q.append((tl,ndv))
            else:
                q.appendleft((tl,ndv))

if (n-1)<<20 in res:
    print(res[(n-1)<<20]//2)
else:
    print(-1)






Measured memory_bytes: 175664
#!/usr/bin/env python3

import sys
# import math
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product                # product(iter, repeat=n)
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4


def main():
    mod = 1000000007                  # 10^9+7
    inf = float('inf')
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():  return int(input())
    def mi():  return map(int, input().split())
    def mi_0(): return map(lambda x: int(x)-1, input().split())
    def lmi(): return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():  return list(input())
    
    
    a, b, c, d = mi()
    while True:
        if a > 0 and c > 0:
            c -= b
        else:
            break
        if a > 0 and c > 0:
            a -= d
        else:
            break
    print('Yes') if a > 0 else print('No')


if __name__ == "__main__":
    main()

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os, const map<T,U>& mp){ os << "{"; for(auto& p : mp){ os << p << ","; } os << "}"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int,int>;
using vi = std::vector<int>;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

int main(){
    int n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];
    sort(all(a));

    vector<ll> b(n+1,0);
    b[0] = a[0];
    for(int i=1;i<n;i++) b[i] = b[i-1] + a[i];

    for(int i=n-2;i>=0;i--){
        if(a[i+1] > 2*b[i]){
            cout << n - 1 - i << endl;
            return 0;
        }
    }
    cout << n << endl;
}


Measured memory_bytes: 1792
import java.util.Scanner;
public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            long x = scanner.nextLong();
            long y = scanner.nextLong();
            long i = 1;
            long a = x;
            while (a <= y){
                a=a*2;
                i++;
            }
           System.out.println(i-1);
        }
        
}

Measured memory_bytes: 20820
W,H,N = map(int,input().split())
x = [0]*N
y = [0]*N
a = [0]*N
Xmin = -1
Xmax = W+1
Ymin = -1
Ymax = H+1
for i in range(0,N):
	x[i],y[i],a[i] = map(int,input().split())
	if a[i] == 1 and Xmin < x[i]:
		Xmin = x[i]
	if a[i] == 2 and Xmax > x[i]:
		Xmax = x[i]
	if a[i] == 3 and Ymin < y[i]:
		Ymin = y[i]
	if a[i] == 4 and Ymax > y[i]:
		Ymax = y[i]

ans = 0

if Xmin == -1:
	Xmin = 0
if Xmax == W+1:
	Xmax = W
if Ymin == -1:
	Ymin = 0
if Ymax == H+1:
	Ymax = H
ans = (Xmax-Xmin)*(Ymax-Ymin)
if Xmin > Xmax or Ymin > Ymax:
	ans = 0
print(ans)


Measured memory_bytes: 3064
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		long N = sc.nextLong();
		long ans = 0;
		for(long i = 0; i < N; i++) {
			ans += i;
		}
		System.out.println(ans);
	}

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21204
#include<iostream>
#include<cmath>
 #include <stdlib.h>
#include<string>
using namespace std;
int main(){
	string a,b,temp;
	int ans;
	cin>>a>>b;
	temp=a+b;
	ans=atoi(temp.c_str());
	if(sqrt(ans)==int(sqrt(ans))){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 30;
const int MAX_W = 30;

/* typedef */

/* global variables */

int h, w, n;
char flds[MAX_H][MAX_W], flds0[MAX_H][MAX_W];
bool marked[MAX_H][MAX_W];

/* subroutines */

bool check() {
  memcpy(flds0, flds, sizeof(flds));

  bool changed = true;
  while (changed) {
    changed = false;

    // drop
    for (int x = 0; x < w; x++) {
      int y0, y1;
      for (y0 = y1 = 0; y0 < h; y0++)
	if (flds0[y0][x] != 0)
	  flds0[y1++][x] = flds0[y0][x];
      for (; y1 < h; y1++) flds0[y1][x] = 0;
    }

    // mark
    memset(marked, false, sizeof(marked));

    for (int y = 0; y < h; y++) {
      int x0, x1;
      for (x0 = x1 = 0; x0 < w;) {
	if (flds0[y][x0] == 0) x0++, x1++;
	else {
	  while (flds0[y][x0] == flds0[y][x1]) x1++;
	  if (x1 - x0 >= n)
	    for (int x = x0; x < x1; x++) marked[y][x] = true;
	  x0 = x1;
	}
      }
    }
      
    for (int x = 0; x < w; x++) {
      int y0, y1;
      for (y0 = y1 = 0; y0 < h;) {
	if (flds0[y0][x] == 0) y0++, y1++;
	else {
	  while (flds0[y0][x] == flds0[y1][x]) y1++;
	  if (y1 - y0 >= n)
	    for (int y = y0; y < y1; y++) marked[y][x] = true;
	  y0 = y1;
	}
      }
    }

    // vanish
    for (int y = 0; y < h; y++)
      for (int x = 0; x < w; x++)
	if (marked[y][x]) flds0[y][x] = 0, changed = true;
  }

  // check if all vanished
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (flds0[y][x] > 0) return false;
  return true;
}

/* main */

int main() {
  cin >> h >> w >> n;

  for (int y = h - 1; y >= 0; y--) {
    string line;
    cin >> line;
    for (int x = 0; x < w; x++)
      flds[y][x] = (line[x] == '.') ? 0 : line[x] - 'A' + 1;
  }

  bool ok = false;
  
  for (int y0 = 0; ! ok && y0 < h; y0++)
    for (int x0 = 0; ! ok && x0 < w - 1; x0++)
      if (flds[y0][x0] != flds[y0][x0 + 1]) {
	swap(flds[y0][x0], flds[y0][x0 + 1]);
	ok = check();
	swap(flds[y0][x0], flds[y0][x0 + 1]);
      }

  cout << (ok ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#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;
  vector<int> l(n);
  rep(i,n) cin >> l[i];
  int ans = 0;
  rep(i,n)rep(j,n)rep(k,n) {
    if (i < j && j < k) {
      if (l[i] == l[j]) continue;
      if (l[j] == l[k]) continue;
      if (l[k] == l[i]) continue;
      if ((ll)l[i]+l[j]+l[k] <= max({l[i], l[j], l[k]})*2) continue;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(int argc, char* argv[]) {
  queue<int> q;
  int x, y;

  cin >> x >> y;
  while(!(x == 0 && y == 0)){
    q.push(x);
    q.push(y);
    cin >> x >> y;
  }

  while(!q.empty()){
    x = q.front();
    q.pop();
    y = q.front();
    q.pop();
    for(int j = 0 ; j < x ; j++){
      for(int k = 0 ; k < y ; k++){
        if((j+k)%2 == 0){
          cout << "#";
        }else{
          cout << ".";
        }
      }
      cout << endl;
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 1196
#include <stdio.h>
#include <stdlib.h>

#define MAX_N (100000)
#define SIZE_BUF (30)

int main(int argc, char *argv[]) {
  // read inputs
  int N;
  char S[MAX_N], buf[SIZE_BUF];
  scanf("%d", &N);
  fgets(buf, SIZE_BUF, stdin);
  for (int i = 0; i < N; i++) {
    S[i] = fgetc(stdin);
  }

  // solve
  int xs[MAX_N];  // 0 is sheep, 1 is wolf
  for (int x0 = 0; x0 < 2; x0++) {
    xs[0] = x0;
    for (int x1 = 0; x1 < 2; x1++) {
      xs[1] = x1;
      for (int i = 1; i < N - 1; i++) {
        // determine x[i + 1] from xs[i - 1], xs[i], and S[i]
        const int x_cur = xs[i - 1], x_prev = xs[i];
        if (S[i] == 'o') {
          if (x_cur == 0) {
            xs[i + 1] = x_prev;
          } else {
            xs[i + 1] = !x_prev;
          }
        } else {
          if (x_cur == 0) {
            xs[i + 1] = !x_prev;
          } else {
            xs[i + 1] = x_prev;
          }
        }
      }
      // print candidate
      // for (int j = 0; j < N; j++) {
      //   printf("%c", xs[j] ? 'W' : 'S');
      // }
      // printf("\n");
      // check for consistency
      // printf("xs[N - 2] = %d, xs[N - 1] = %d, xs[0] = %d, S[N - 1] = %c\n",
      //        xs[N - 2], xs[N - 1], xs[0], S[N - 1]);
      if (S[N - 1] == 'o') {
        if ((xs[N - 1] == 0 && xs[N - 2] == xs[0]) ||
            (xs[N - 1] == 1 && xs[N - 2] != xs[0])) {
          ;  // ok so far
        } else {
          continue;  // inconsistent
        }
      } else {
        if ((xs[N - 1] == 0 && xs[N - 2] != xs[0]) ||
            (xs[N - 1] == 1 && xs[N - 2] == xs[0])) {
          ;  // ok so far
        } else {
          continue;  // inconsistent
        }
      }
      if (S[0] == 'o') {
        if ((xs[0] == 0 && xs[N - 1] == xs[1]) ||
            (xs[0] == 1 && xs[N - 1] != xs[1])) {
          ;  // ok so far
        } else {
          continue;  // inconsistent
        }
      } else {
        if ((xs[0] == 0 && xs[N - 1] != xs[1]) ||
            (xs[0] == 1 && xs[N - 1] == xs[1])) {
          ;  // ok so far
        } else {
          continue;  // inconsistent
        }
      }
      for (int i = 0; i < N; i++) {
        printf("%c", xs[i] ? 'W' : 'S');
      }
      printf("\n");
      return 0;
    }
  }

  // print ans
  printf("-1\n");

  return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

#define int long long

inline int read () {
	int ret = 0, t = 1;
	char c = getchar();
	while ((c < '0' || c > '9') && c != '-') c = getchar();
	if (c == '-') t = -1, c = getchar();
	while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
	return ret * t;
}

int n, k;

int a[200200] = {};

signed main () {
	n = read(), k = read();
	int i, j;
	for (i = 1; i <= n; i++) a[i] = read();
	sort(a + 1, a + n + 1);
	for (i = n - k, j = 0; i >= 1; i--) j += a[i];
	printf("%lld\n", j);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <string.h>
using namespace std;

vector<int> G[1010];
bool used[1010];
int match[1010];
int N,M;

bool dfs(int v){
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		int u = G[v][i],w = match[u];
		if(w<0 || !used[w] && dfs(w)){
			match[v] = u;
			match[u] = v;
			return true;
		}
	}
	return false;
}

int mat(){
	int ans = 0;
	memset(match,-1,sizeof(match));
	for(int v=1;v<=N+M;v++){
		if(match[v]<0){
			memset(used,0,sizeof(used));
			if(dfs(v)){
				ans++;
			}
		}
	}
	return ans;
}

int gcd(int n,int m){
    if(n%m==0) return m;
    else return gcd(m,n%m);
}

int main(){
    while(cin >> M >> N && M>0){
        for(int i=1;i<=N+M;i++){
            used[i] = 0;
            match[i] = 0;
            G[i].clear();
        }
        vector<int> R(N+1),B(M+1);
        for(int i=1;i<=M;i++){
            cin >> B[i];
        }
        for(int i=1;i<=N;i++){
            cin >> R[i];
        }
        for(int i=1;i<=M;i++){
            for(int j=1;j<=N;j++){
                if(gcd(B[i],R[j])!=1){
                    G[i].push_back(j+M);
                    G[j+M].push_back(i);
                }
            }
        }
        cout << mat() << endl;
    }
}


Measured memory_bytes: 4864
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	int m, d;
	cin >> m >> d>>m>>d;

	if (d == 1) { cout << 1; }
	else { cout << 0; }

	system("PAUSE");
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
#define fi first
#define se second
#define rep(i,n) for(int i = 1;i < n;i++)
#define drep(i,n) for(int i = n;i > 1;i--)
typedef pair<int,int> P;

int a[51];
pair<int,int> mn, mx;
int main(){
	int n, t, f;
	mn.fi = inf, mx.fi = -inf;
	scanf("%d", &n);
	for(int i = 0;i < n;i++){
		scanf("%d", &a[i]);
		if(mn.fi > a[i])mn = P(a[i], i+1);
		if(mx.fi < a[i])mx = P(a[i], i+1);
	}
	
	printf("%d\n", 2*n-1);
	if(abs(mn.fi) <= abs(mx.fi))t = mx.se, f = 0;
	else t = mn.se, f = 1;
	
	for(int i = 0;i < n;i++){
		printf("%d %d\n", t, i+1);
	}
	
	if(f == 0){
		rep(i,n)printf("%d %d\n", i, i+1);
	}else{
		drep(i,n)printf("%d %d\n", i, i-1);
	}
	return 0;
}

Measured memory_bytes: 256
using System;
using System.IO;
using System.Collections.Generic;
namespace I_am_the_green_coder{
    class Inonoa{
        // なんか入力用の関数作ったけどまだテストしてないので使う前に確かめて
        static void Main(){

            long n = long.Parse(Console.ReadLine());
            long[][] ab = new long[n][];
            for(long i=0;i<n;i++){
                string[] sab = Console.ReadLine().Split();
                ab[i] = new long[2]{long.Parse(sab[0]),long.Parse(sab[1])};
            }

            Array.Sort(ab,ABCompare);

            long jikan = 0;
            for(long i=0;i<n;i++){
                jikan += ab[i][0];
                if(jikan>ab[i][1]){
                    
                    Console.WriteLine("No");
                    return;
                }
            }

            Console.WriteLine("Yes");
        }

        static int ABCompare(long[] a, long[] b){
            if(a[1]<b[1])return -1;
            if(a[1]==b[1])return 0;
            return 1;
        }
    }
}

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

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

	if (n[0] == n[1] && n[1] == n[2] || n[2] == n[3] && n[1] == n[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 888
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 200005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
void fill(int a[],int b,int c){
	int i;
	FOR(i,0,b) a[i]=c;
	return;
}
ll inv[SIZE],f[SIZE],finv[SIZE];
void make_table(){
	int i;
	f[0]=f[1]=1; finv[0]=finv[1]=1;
	inv[1]=1;
	FOR(i,2,SIZE+1){
		inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
		f[i]=(f[i-1]*(ll)i)%MOD;
		finv[i]=(finv[i-1]*inv[i])%MOD;
	}
	return;
}
ll comb(int n,int k){
	if(n<0||k<0||n<k) return 0;
	return (((f[n]*finv[k])%MOD)*finv[n-k])%MOD;
}
int main(void)
{
	int h,w,a,b,i;
	ll ans=0;
	make_table();
	scanf("%d%d%d%d",&h,&w,&a,&b);
	FOR(i,b,w){
		ans+=(comb(i+h-a-1,i)*comb(w-i+a-2,a-1))%MOD;
		ans%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
}


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

main(){
    int n=0;
    long d=0;
    cin >> n;
    int a[n];
    for(int i=0; i<n; ++i){
        cin >> a[i];
        d += a[i];
    }
    sort(a, a+n);
    cout << a[0] << " " << a[n-1] << " " << d << endl;
}


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

int nextSun(string s) {
    if (s == "SUN") {
        return 7;
    }
    if (s == "MON") {
        return 6;
    }
    if (s == "TUE") {
        return 5;
    }
    if (s == "WED") {
        return 4;
    }
    if (s == "THU") {
        return 3;
    }
    if (s == "FRI") {
        return 2;
    }
    if (s == "SAT") {
        return 1;
    }
}

int main() {
    string s;
    cin >> s;
    
    cout << nextSun(s) << endl;

    return 0;
}

Measured memory_bytes: 256