akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

#ifdef LOCAL
#define i64 "%lld"
#else
#define i64 "%I64d"
#endif

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

const int N = 110;

int n, a[N];

int cost(int x) {
    int res = 0;
    forn(i,n) res += (a[i]-x)*(a[i]-x);
    return res;
}

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

    int sum = 0;
    cin >> n;
    forn(i,n){ 
        cin >> a[i];
        sum += a[i];
    }
    int x = sum/n, y = x+1;
    cout << min(cost(x), cost(y)) << endl;

    return 0;
}


Measured memory_bytes: 256
n,x = map(int,input().split())
a = list(map(int,input().split()))
eat = 0

if a[0] > x:
	eat += a[0] - x
	a[0] = x
#if a[-1] > x:
#	eat += a[-1] -x
#	a[-1] = x

for i in range(1,n):
	s  = a[i-1]+a[i] 
	if s > x:
		eat += s - x
		a[i] -= s-x
else:
	print(eat)


Measured memory_bytes: 14540
N, M = map(int, input().split())
X = [[-1]*2 for i in range(N)]
for _ in range(M):
    a, b = sorted(map(int, input().split()))
    if a == 1:
        if X[b][1] > 0:
            print("POSSIBLE")
            break
        else:
            X[b][0] = 1
    if b == N:
        if X[a][0] > 0:
            print("POSSIBLE")
            break
        else:
            X[a][1] = 1
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 23540
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
const int INF = 1 << 22;
int N, M, R;
void wf(VVI &adj){
  for(int k = 0; k < N; ++k){
    for(int i = 0; i < N; ++i){
      for(int j = 0; j < N; ++j){
	adj[i][j] = min(adj[i][j], adj[i][k]+adj[k][j]);
      }
    }
  }
}
void print_adj(VVI adj){
  for(int i = 0; i < N; ++i){
    for(int j = 0; j < N; ++j){
      if(adj[i][j] >= INF){
	cout << "INF" << " ";
      }
      else{
	cout << adj[i][j] << " ";
      }
    }
    cout << endl;
  }
}
void db_print(int line[]){
  for(int i = 0; i < N; ++i){
    if(line[i] >= INF){
      cout << "INF" << " ";
    }
    else{
      cout << line[i] << " ";
    }
  }
  cout << endl;
}
int solve(VVI sea, VVI land, VI que){  
  int table[R][N];  
  fill_n((int *) table, R*N, INF);
  table[0][que[0]] = 0;
  for(int r = 1; r < R; ++r){
    //db_print(table[r-1]);
    for(int from = 0; from < N; ++from){
      for(int to = 0; to < N; ++to){
	if(from == to){
	  int cost = table[r-1][from];
	  cost += land[que[r-1]][que[r]];
	  table[r][to] = min(table[r][to], cost);
	}
	else{
	  int cost = table[r-1][from];
	  cost += land[que[r-1]][from];
	  cost += sea[from][to];
	  cost += land[to][que[r]];
	  table[r][to] = min(table[r][to], cost);
	}
      }
    }
    for(int i = 0; i < N; ++i){
      if(table[r][i] > INF){
	table[r][i] = INF;
      }
    }
  }
  int res = INF;
  //db_print(table[R-1]);
  for(int i = 0; i < N; ++i){
    res = min(res, table[R-1][i]);
  }
  return res;
}
int main(){
  while(true){
    cin >> N >> M;
    if((N|M) == 0){
      break;
    }
    VVI sea(N, vector<int>(N, INF));
    VVI land(N, vector<int>(N, INF));
    for(int i = 0; i < N; ++i){
      sea[i][i] = 0;
      land[i][i] = 0;
    }
    for(int i = 0; i < M; ++i){
      int x, y, t;
      char sl;
      cin >> x >> y >> t >> sl;
      --x; --y;
      if(sl == 'S'){
	sea[x][y] = sea[y][x] = min(sea[y][x], t);
      }
      else{
	land[x][y] = land[y][x] = min(land[y][x], t);
      }
    }
    wf(sea); wf(land);    
    //print_adj(sea);
    //print_adj(land);
    cin >> R;
    vector<int> que(R);
    for(int i = 0; i < R; ++i){
      cin >> que[i];
      --que[i];
    }    
    cout << solve(sea, land, que) << endl;
  }
  return 0;
}

Measured memory_bytes: 2644
a, b = map(int, input().split())
c = [0] * (10 ** 5)
for i in range(a):
    d, e = map(int, input().split())
    c[d-1] += e
f = 0
for i in range(10**5):
    f += c[i]
    if f >= b:
        print(i+1)
        exit()

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


const ll MAXX = 100005;

ll N, X;
ll b[MAXX], l[MAXX], u[MAXX];
ll D;
ll Sum[MAXX];
int inds[MAXX];


ll get_cost(int ind, ll A) {
    if (A <= b[ind]) {
        return A * l[ind];
    } else {
        return b[ind] * l[ind] + (A - b[ind]) * u[ind];
    }
}

bool criterion(ll k) {
    ll q = k / X, r = k % X;

    ll sum = D;
    rep(i, q) {
        sum += Sum[inds[i]];
    }
    rep(i, N) {
        ll nsum = sum + get_cost(inds[i], r);
        if (i < q) {
            nsum += Sum[inds[q]] - Sum[inds[i]];
        }
        if (nsum >= 0) {
            return true;
        }
    }

    return false;
}


int main() {
    cin >> N >> X;
    rep(i, N) {
        cin >> b[i] >> l[i] >> u[i];
    }

    D = 0;
    rep(i, N) {
        D -= l[i] * b[i];
        Sum[i] = l[i] * b[i] + u[i] * (X - b[i]);
    }

    iota(inds, inds + N, 0);
    sort(inds, inds + N, [&](int i, int j) { return Sum[i] > Sum[j]; });


    ll lb = -1, ub = N * X;
    while (ub - lb > 1) {
        ll mid = (ub + lb) / 2;
        if (criterion(mid)) ub = mid;
        else lb = mid;
    }

    cout << ub << endl;

}

Measured memory_bytes: 3840
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
int n,d,x;
int main(){
  cin >> n >> d >> x;
  int ans = x;
  REP(i,n){
    int k;
    cin >> k;
    ans += 1 + (d-1)/k;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define loop(i,b,e) for(int i=b;i<=e;i++)
#define loop2(i,e,b) for(int i=e;i>=b;i--)
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define X real()
#define Y imag()
#define cp(a,b)	( (conj(a)*(b)).imag() )
#define length(a) (hypot((a).imag(), (a).real()))
typedef complex<double> point;
typedef long long ll;
typedef unsigned long long ull;
double PI = 3.141592653589793;
const double EPS = 1e-9;
const int N = 1e6 + 5;
const ll mod = 1e9 + 7;
const int oo = 1e9;
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };

int n = 3;
int t[30];

int main() {
	n = 3;
	int ans = oo;
	loop(i, 0, n - 1)
		scanf("%d",&t[i]);
	do {
		int curr = 0;
		loop(i, 1, n - 1)
			curr += abs(t[i] - t[i - 1]);
		ans = min(ans, curr);
	} while (next_permutation(t, t + n));
	printf("%d",ans);
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		int N = 10000;
		int[] array = new int[N];
		Scanner scan = new Scanner(System.in);
		for (int i = 0; i < N; i++) {
			array[i] = scan.nextInt();
			if (array[i] == 0) {
				break;
			}
		}
		for (int i = 0; i < array.length; i++) {
			if (array[i] != 0) {
				System.out.println("Case " + (i+1) + ": " + array[i]);
			}
		}
	}

}

Measured memory_bytes: 43060
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 05/31/20 18:19:58
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int n; cin>>n;
  vector<pair<int,int>> AB(n);
  for (int i = 0; i < n; i++)
    cin>>AB[i].first>>AB[i].second;
  vector<int> A(n), B(n);
  for (int i = 0; i < n; i++) {
    A[i] = AB[i].first;
    B[i] = AB[i].second;
  }
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (n%2==0) {
    int al = A[(n-1)/2]*2;
    int ar = A[n/2]*2;
    int bl = B[(n-1)/2]*2;
    int br = B[n/2]*2;
    int am = (al+ar)/2;
    int bm = (bl+br)/2;
    int ans = bm-am+1;
    cout << ans << endl;
  } else {
    int aa = A[n/2];
    int bb = B[n/2];
    int ans = bb-aa+1;
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 6368
#include <stdio.h>

int main(void){

	double class;
	
	while(scanf("%lf", &class) != EOF){
		if(class <= 48.00){
			printf("light fly\n");
		}else if(class <= 51.00 && class > 48.00){
			printf("fly\n");
		}else if(class <= 54.00 && class > 51.00){
			printf("bantam\n");
		}else if(class <= 57.00 && class > 54.00){
			printf("feather\n");
		}else if(class <= 60.00 && class > 57.00){
			printf("light\n");
		}else if(class <= 64.00 && class > 60.00){
			printf("light welter\n");
		}else if(class <= 69.00 && class > 64.00){
			printf("welter\n");
		}else if(class <= 75.00 && class > 69.00){
			printf("light middle\n");
		}else if(class <= 81.00 && class > 75.00){
			printf("middle\n");
		}else if(class <= 91.00 && class > 81.00){
			printf("light heavy\n");
		}else if(class > 91.00){
			printf("heavy\n");
		}	
	}
	
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;

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

bool comp( const pair<int,int> &l, const pair<int,int> &r ){
	int ll = l.first*l.first+l.second*l.second;
	int rr = r.first*r.first+r.second*r.second;
	if( ll == rr ){
		return l.second < r.second;
	}else{
		return ll < rr;
	}
}

int main(){
	vector< pair<int,int> > v;
	for(int h=1; h<150; h++){
		for(int w=h+1; w<150; w++){
			v.push_back( make_pair<int,int>(w,h) );
		}
	}
	sort( v.begin(), v.end(), comp );
	int iw, ih;
	while( cin >> ih >> iw, iw||ih ){
		int l = iw*iw+ih*ih;
		rep(i,v.size()){
			int vl = v[i].first*v[i].first+v[i].second*v[i].second;
			if( (l < vl) ||
				(l==vl && ih<v[i].second) ){
				cout << v[i].second << " " << v[i].first << endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1332
#include <iostream>
#include <string>
#include <cstring>
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <iomanip>
#include <vector>
#define int long long
using namespace std;
signed main(){
    int r,d,x;
    cin>>r>>d>>x;
    int a=x;
    for(int i=0;i<10;i++){
        a=a*r-d;
        cout<<a<<endl;
    }
    return 0;
}


















Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
		String s;
		int inCnt = 0;
		while ((s = stdIn.readLine()) != null) {
			String[] se = s.split(" ");
			if (se[1].equals("?"))
				break;
			int a = Integer.valueOf(se[0]);
			int b = Integer.valueOf(se[2]);
			doMain(++inCnt, a, se[1], b);
		}
		System.exit(0);
	}

	private static void doMain(int inCnt, int a, String op, int b) {
		int r = 0;
		switch (op) {
		case ("+"):
			r=a+b;
			break;
		case ("-"):r=a-b;
			break;
		case ("*"):r=a*b;
			break;
		case ("/"):r=a/b;
			break;
		}
		System.out.printf("%d\n", r);

	}
}

Measured memory_bytes: 24644
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


from collections import defaultdict
n,m = map(int, input().split())
d = {}
was = 0
acs = 0
for i in range(m):
    p, s = input().split()
    p = int(p)
    if s=="WA":
        if p not in d:
            d[p] = 1
        elif d[p]==-1:
            pass
        else:
            d[p] += 1
    else:
        if p not in d:
            d[p] = -1
            acs += 1
        elif d[p]>=0:
            was += d[p]
            d[p] = -1
            acs += 1
print(acs, was)

Measured memory_bytes: 82560
N, A, B, C = map(int, input().split())
dt = {'AB': (0, 1), 'AC': (0, 2), 'BC': (1, 2)}
Q = [dt[input()] for _ in range(N)]


class Game:
    def __init__(self, ABC):
        self.ABC = ABC
        self.ds = {0: 'A', 1: 'B', 2: 'C'}
        self.ans = []

    def add_q0(self, q0, q1):
        self.ans.append(self.ds[q0])
        self.ABC[q0] += 1
        self.ABC[q1] -= 1

    def add_q1(self, q0, q1):
        self.ans.append(self.ds[q1])
        self.ABC[q0] -= 1
        self.ABC[q1] += 1


def solve1(ABC):
    G = Game(ABC)
    for q0, q1 in Q:
        if G.ABC[q0] == G.ABC[q1] == 0:
            print('No')
            exit()
        elif G.ABC[q0] == 0:
            G.add_q0(q0, q1)
        else:
            G.add_q1(q0, q1)
    print('Yes')
    print(*G.ans, sep='\n')


def solve2(ABC):
    G = Game(ABC)
    for i, (q0, q1) in enumerate(Q):
        if G.ABC[q0] == G.ABC[q1] == 0:
            print('No')
            exit()
        elif G.ABC[q0] == 0:
            G.add_q0(q0, q1)
        elif G.ABC[q1] == 0:
            G.add_q1(q0, q1)
        elif G.ABC[q0] == G.ABC[q1] == 1 and sum(ABC) == 2 and i < N - 1:
            if q0 in Q[i + 1]:
                G.add_q0(q0, q1)
            else:
                G.add_q1(q0, q1)
        else:
            # 余裕の無い方に足しておく
            if G.ABC[q0] <= G.ABC[q1]:
                G.add_q0(q0, q1)
            else:
                G.add_q1(q0, q1)
    print('Yes')
    print(*G.ans, sep='\n')


S = A + B + C
if S == 0:
    print('No')
elif S == 1:
    solve1([A, B, C])
else:
    solve2([A, B, C])


Measured memory_bytes: 12408
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll a, b, k;
  cin >> a >> b >> k;
  ll x, y;
  if (k < a) x = a-k, y = b;
  else if (k < a+b) x = 0, y = b - (k-a);
  else x = 0, y = 0;
  printf("%lld %lld\n", x, y);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;


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

  int n,m;
  cin >> n >> m;
  
  vector <ll>a[8]; 
  
  REP(i,n){
    ll x,y,z;
    cin >> x >> y >> z;
      a[0].push_back(x + y - z);
      a[1].push_back(-x + y - z);
      a[2].push_back(x + y + z);
      a[3].push_back(-x + y + z);
      a[4].push_back(x - y - z);
      a[5].push_back(-x - y - z);
      a[6].push_back(x - y + z);
      a[7].push_back(-x - y + z);
  }
  


  
  ll ans = 0;

  REP(i,8){
    ll sum = 0;
    vector<ll> b;
    REP(j,n){
    b.push_back(a[i][j]);
    }
    sort(b.begin(),b.end());
    reverse(b.begin(),b.end());
    REP(j,m){
      sum += b[j];
    }
    ans = max(ans,sum);
}
  
  
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n;
  string s;
  cin >> n >> s;
  bool a[] = {true, false};
  bool b[] = {true, false};
  vector<bool> v(n+1);
  REP(i, 2) REP(j, 2){
    v[0] = a[i];
    v[1] = b[j];
    FOR(k, 1, n){
      if(v[k]){
        if(s[k] == 'o'){
          v[k+1] = v[k-1];
        }else{
          v[k+1] = !v[k-1];
        }
      }else{
        if(s[k] == 'x'){
          v[k+1] = v[k-1];
        }else{
          v[k+1] = !v[k-1];
        }
      }
    }
    if(v[0] != v[n]) continue;
    if(v[0]){
      if(s[0] == 'o' && v[n-1] != v[1]) continue;
      if(s[0] == 'x' && v[n-1] == v[1]) continue;
    }else{
      if(s[0] == 'x' && v[n-1] != v[1]) continue;
      if(s[0] == 'o' && v[n-1] == v[1]) continue;
    }
    REP(k, n){
      if(v[k]) printf("S");
      else printf("W");
    }
    printf("\n");
    return 0;
  }
  cout << -1 << endl;
  return 0;
}

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

int main(){
    string s;
    cin >> s;
    vector<bool> dp(100005, false);
    dp[0] = true;
    rep(i,s.size()-4){
        if(!dp[i]) continue;
        if(s[i] == 'd' && s[i+1] == 'r' && s[i+2] == 'e' && s[i+3] == 'a' && s[i+4] == 'm') dp[i+5] = true;
        if(s[i] == 'd' && s[i+1] == 'r' && s[i+2] == 'e' && s[i+3] == 'a' && s[i+4] == 'm' && s[i+5] == 'e' && s[i+6] == 'r') dp[i+7] = true;
        if(s[i] == 'e' && s[i+1] == 'r' && s[i+2] == 'a' && s[i+3] == 's' && s[i+4] == 'e') dp[i+5] = true;
        if(s[i] == 'e' && s[i+1] == 'r' && s[i+2] == 'a' && s[i+3] == 's' && s[i+4] == 'e' && s[i+5] == 'r') dp[i+6] = true;
    }
    if(dp[s.size()]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3776
def bsearch(q, items)
  lb, ub = 0, items.length
  while ub - lb > 1
    mid = (ub+lb)/2
    if items[mid] <= q
      lb = mid
    else
      ub = mid
    end
  end
  items[lb] === q
end

def solve(qs, items)
  items.sort!
  qs.select {|q| bsearch(q, items)}.count
end

gets
items = gets.split(" ").map(&:to_i)
gets
qs = gets.split(" ").map(&:to_i)
puts solve(qs, items)



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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  double a,b,x;cin>>a>>b>>x;

  double small_vol = min<double>(x, a*a*b-x);
  double theta = atan( a*a*a/(2.0*small_vol) );
  if(x<=a*a*b/2)theta = atan( 2.0*small_vol/(a*b*b) );

  theta = M_PI/2-theta;
  double result = theta/(M_PI/180.0);
  cout<<fixed<<setprecision(12)<<result<<endl;

  return 0;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define UB upper_bound
#define LB lower_bound
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

LL n, m;
const LL MOD = 1000000007;
LL dp[2][2][3001];

int main() {
	cin >> n >> m;
	
	int fr = 0, to = 1;
	inc(i, n) { dp[to][0][i] = 1; }
	dp[to][1][n] = 1;
	
	inc(j, m) {
		swap(to, fr);
		incII(i, 0, n) { inc(f, 2) { dp[to][f][i] = 0; } }
		incII(i, 0, n) {
		inc(f, 2) {
			if(i != 0) { (dp[to][f][i + 0] += dp[fr][f][i]) %= MOD; }
			if(i != n) { (dp[to][f][i + 1] += dp[fr][f][i]) %= MOD; }
		}
		}
		(dp[to][1][n] += dp[to][0][n]) %= MOD;
		dp[to][0][n] = 0;
		
		swap(to, fr);
		incII(i, 0, n) { inc(f, 2) { dp[to][f][i] = 0; } }
		incII(i, 1, n) {
		inc(f, 2) {
			(dp[to][f][i - 1] += dp[fr][f][i]) %= MOD;
			(dp[to][f][i + 0] += dp[fr][f][i]) %= MOD;
		}
		}
	}
	
	LL ans = 0;
	incII(i, 0, n) { (ans += dp[to][1][i]) %= MOD; }
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
constexpr int64_t mod=1e9+7;

int main()
{
  int r,g,b;
  cin>>r>>g>>b;
  if((2*g+b)%4==0)
  {
    cout<<"YES"<<endl;
  }
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
A, B, C, X, Y = [int(_) for _ in input().split()]

def solve(A, B, C, X, Y):
    if Y > X:
        X, Y = Y, X
        A, B = B, A
    # X > Y
    A0 = 0
    B0 = 0
    r = 0
    if A + B > C * 2:
        r += Y * C * 2
        X -= Y
        Y = 0
    else:
        if B > C * 2:
            r += C * 2 * Y
            X -= Y
            Y = 0
        else:
            r += B * Y
            Y = 0
    if A > C * 2:
        r += C * 2 * X
        X = 0
    else:
        r += A * X
        X = 0
    return r

print(solve(A, B, C, X, Y))



Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int main(){
  for(string str;cin>>str,str[0]!='#';){
    int len=str.size();
    string m;
    for(int i=1;i<len;i++){
      int dp[300][300]={};
      for(int j=0;j<i;j++){
	for(int k=0;i+k<len;k++){
	  dp[j+1][k+1]=max(dp[j][k+1],max(dp[j+1][k],dp[j][k]+(str[j]==str[i+k])));
	}
      }
      int y=i,x=len-i;
      string c;
      while(dp[y][x]){
       if(y&&dp[y-1][x]==dp[y][x]){
	 y--;
       }else if(x&&dp[y][x-1]==dp[y][x]){
	 x--;
       }else{
	 c+=str[y-1];
	 y--;
	 x--;
       }
      }
      if(c.size()>m.size()){
	m=c;
      }
    }
    cout<<string(m.rbegin(),m.rend())<<endl;
  }
}

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


public class Data
{
	public int I { get; private set; }
	public int P { get; private set; }
	public int Y { get; private set; }
	
	public Data(int i, int p, int y)
	{
		I = i;
		P = p;
		Y = y;		
	}	
}


public class C
{	
	public static void Main()
	{	
		string[] args;
		args = Console.ReadLine().Split(' ');
		int N = Int32.Parse(args[0]);
		int M = Int32.Parse(args[1]);
		
		List<Data> list = new List<Data>(M);
		for(int i = 0; i < M; i++)
		{
			args = Console.ReadLine().Split(' ');
			int P = Int32.Parse(args[0]);
			int Y = Int32.Parse(args[1]);
			list.Add(new Data(i,P,Y));			
		}	
		
		var sortedList = list.OrderBy(d => d.P).ThenBy(d => d.Y);
		
		int[] upper = new int[M];
		int[] lower = new int[M];
		int prevP = -1;
		int x = -1;
		foreach(Data data in sortedList)
		{
			x = (prevP == data.P) ? x + 1 : 1;
			prevP = data.P;
			
			upper[data.I] = data.P;
			lower[data.I] = x;
		}
		
		for(int i = 0; i < M; i++)
			Console.WriteLine($"{upper[i]:D6}{lower[i]:D6}");
	}
	
}

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

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

typedef long long ll;
const ll MOD = 1e9 + 7;

struct Point {
  double x, y;
};

double dist(const Point &a, const Point &b) {
  double dx = a.x - b.x;
  double dy = a.y - b.y;
  return std::sqrt(dx * dx + dy * dy);
}

int main() {
  int N;
  std::cin >> N;

  std::vector<Point> ps(N);
  rep(i, N) {
    std::cin >> ps[i].x >> ps[i].y;
  }

  auto f = [&](double x, double y) {
    double ret = 0;
    rep(i, N) {
      ret = std::max(ret, dist(Point{x, y}, ps[i]));
    }
    return ret;
  };

  const double EPS = 1e-10;
  auto g = [&](double x) {
    double l = 0;
    double r = 1000;
    while(r - l > EPS) {
      double ml = (l*2 + r) / 3;
      double mr = (l + r*2) / 3;
      if(f(x, ml) > f(x, mr)) {
        l = ml;
      } else {
        r = mr;
      }
    }
    return f(x, l);
  };

  double l = 0;
  double r = 1000;
  while(r - l > EPS) {
    double ml = (l*2 + r) / 3;
    double mr = (l + r*2) / 3;
    if(g(ml) > g(mr)) {
      l = ml;
    } else {
      r = mr;
    }
  };

  std::cout << std::fixed << std::setprecision(10) << g(l) << '\n';
}

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

typedef long long ll;

ll dig(ll a) {
    ll ans = 0;
    while(a){
	a /= 10; ans++;
    }
    return ans;
}

int main () {

    ll N; cin >> N;
    ll ans = INT_MAX;
    for(ll i=1; i*i<=N; i++) {
	if( N%i == 0 ) {
	    ans = min(ans, max(dig(i),dig(N/i)));
	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
abc = [LIST() for _ in range(N-1)]
graph = defaultdict(list)
for a, b, c in abc:
	graph[a-1].append((b-1, c))
	graph[b-1].append((a-1,c))

Q, K = MAP()
xy = [LIST() for _ in range(Q)]

dist = [-1]*N  # K から各頂点への最短距離
dist[K-1] = 0

def dfs(node):
	for to, cost in graph[node]:
		if dist[to] != -1:
			continue
		dist[to] = dist[node]+cost
		dfs(to)
dfs(K-1)
# print(dist)

for x, y in xy:
	print(dist[x-1]+dist[y-1])


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

int countFriends(int n, vector<bool> &is_visit, vector<vector<int> > &friends) {
  int num = 1;
  vector<int> list = friends.at(n);
  int size = list.size();

  REP(i, size) {
    int tmp_n = list.at(i);
    if (is_visit.at(tmp_n)) continue;
    is_visit.at(tmp_n) = true;
    num += countFriends(tmp_n, is_visit, friends);
  }

  return num;
}

int main() {
  IN(int, N);
  IN(int, M);
  vector<vector<int> > friends(N);
  REP(i, M) {
    IN(int, A);
    A--;
    IN(int, B);
    B--;
    friends.at(A).push_back(B);
    friends.at(B).push_back(A);
  }

  vector<bool> is_visit(N, false);
  int max = 0;
  REP(i, N) {
    if (is_visit.at(i)) continue;
    is_visit.at(i) = true;
    int num = countFriends(i, is_visit, friends);
    if (num > max) max = num;
  }
  cout << max << endl;

  return 0;
}


Measured memory_bytes: 35956
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    int a[200000];
    int ans[200000];
    int i;
    cin >> n;
    ans[1] = 0;
    for(i=2;i<=n;i++){
        ans[i] = 0;
        cin >> a[i];
        ans[a[i]] += 1;
    }
    for(i=1;i<=n;i++){
        cout << ans[i] << endl;
    }
}

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

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

    int ans = 1;
    int max = 0;
    for (int i=1; i<=N; i++) {
        int n = i;
        int c = 0;
        while ((n % 2)==0) {
            n /= 2;
            c++;
        }
        if (c>max) {
            ans = i;
            max = c;
        }
    }

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

Measured memory_bytes: 256
#include"bits/stdc++.h"
// #include "prettyprint.hpp"

using namespace std;

typedef long long ll;

#define rep(i, n) for(ll i=0; i<n; i++)
#define repr(i, n) for(ll i=n; i>=0; i--)
#define reps(i, s, e) for(ll i=s; i<e; i++)
#define all(x) x.begin(),x.end()


int main(){
	int N,K;

	cin >> N >> K;

	vector <ll> H(N);

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

	sort(all(H));

	ll ans  = 0;

	if(K<N){
		rep(i,N-K) ans += H[i];
	}

	cout << ans << endl;

	return 0;
}	

Measured memory_bytes: 1792
#define _GLIBCXX_DEBUG
    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef pair<int, int> pii;
    typedef map<int, int> mii;
    typedef map<char,int> mci;
    typedef vector<int> vi;
    typedef vector<vi> vvi;
    typedef vector<ll> vll;
    typedef vector<pair<int,int>> vii;
    typedef vector<char> vc;
    typedef vector<vc> vcc;
    #define all(x) (x).begin(), (x).end()
    #define rall(x) (x).rbegin(), (x).rend()
    #define pb push_back
    #define mp make_pair
    #define F first
    #define S second
    #define in insert
    #define sz(v) v.size()
    #define mina(a,b) (a)=min((a),(b));
    #define maxa(a,b) (a)=max((a),(b));
    const int INF = 1e9 + 5;
    
    void solve(){
        int r,d;
        vi x(11);
        cin>>r>>d>>x[0];
        for(int i = 1; i <= 10; i++){
            x[i]=x[i-1]*r-d;
            cout<<x[i]<<endl;
        }
    }
    int main(){
        int T=1;
        //cin>>T;
        for(int i = 0; i < T; i++) solve(); 
    }

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


int main(){
  int S; cin >> S;
  int y=S/100;
  int m=S%100;
  if(y>=1&&y<=12){
    if(m>=1&&m<=12){
      cout << "AMBIGUOUS" << endl;
    }else{
      cout << "MMYY" << endl;
    }
  }else{
    if(m>=1&&m<=12){
      cout << "YYMM" << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 256
import bisect
# from collections import Counter, defaultdict, deque, namedtuple
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, k = list(map(int,ipti().split()))
    h = [0] * n
    for i in range(n):
        h[i] = int(input())

    h.sort()

    ans = INF
    for i in range(n-k+1):
        temp = h[i+k-1] - h[i]
        ans = min(ans, temp)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 45144
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <unordered_set>
#include <stack>
#include <algorithm>
#include <queue>
#include <ctime>
#include <iomanip>
#include <tuple>
#include <functional>
#include <map> 
#include <numeric> 
#include <math.h>

using namespace std;


#define ll long long
#define pi pair<int, int>
#define vi vector<int>
#define vp vector<pi>
#define msa(A, a, n) memset(A, a, n*sizeof(A))
#define msv(A, a) fill(A.begin(), A.end(), a);
#define msc(A, n) memset(A, '\0', n)
#define rep_itr(itr, c) for(itr = (c).begin(); itr != (c).end(); itr++)
#define rep(i, a, b) for(int i = a; i < b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
#define pern(i, b) per(i, b - 1, 0)
#define repn(i, b) rep(i, 0, b)
#define repe(i, a, b) for(int i = a; i <= b; i++)
#define repen(i, b) repe(i, 1, b)
#define fast ios_base::sync_with_stdio();cin.tie(0);
#define endl "\n"
//#define MYDEBUG 

void my_return(int code)
{
#ifdef MYDEBUG
	std::cout << "\n\nTime = " << fixed << std::setprecision(3) << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
	exit(code);
}

const unsigned int M = 1000000007;

int main()
{
	fast
#ifdef MYDEBUG
		freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif


	int n;
	cin >> n;
	vi arr(n);
	ll sum = 0, res = 0;
	repn(i, n) cin >> arr[i], sum += arr[i];

	repn(i, n - 1) {
		ll remainder = sum - arr[i];
		res += ((remainder % M) * (arr[i] % M)) % M;
		sum -= arr[i];
	}

	cout << res % M << endl;


	my_return(0);
}


Measured memory_bytes: 4408
#import <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    ll n,ans=0;
    cin>>n; if(n==1)cout<<"0\n",exit(0);
    map<ll,ll> fac;

    for(ll i=2; n>1 && i*i<=n ;++i)if(n%i==0) fac[i]++,n/=i,i--;
    fac[n]++;

    for(auto x:fac){
        ll i;
        for(i=1;(i+1)*i/2 <= x.second;i++);
        ans+=i-1;
    }
    cout<<ans<<endl;
}


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

int main() {
  int H, N;
  cin >> H >> N;
  REP(i, N) {
    int A;
    cin >> A;
    H -= A;
  }
  cout << (H > 0 ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
L=int(input())
N=L.bit_length()
a=[]
x,y=1,1
for b in range(N-1):
    a.append((x,x+1,0))
    a.append((x,x+1,y))
    x+=1
    y*=2
x=2**(N-1)
for b in range(N-1,-1,-1):
    if L-x>=2**b:
        a.append((b+1,N,x))
        x+=2**b
print(N,len(a))
for l in a:
    print(*l)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    map<ll, int> hist;
    rep(i, N) {
        ll a;
        cin >> a;
        hist[a]++;
    }

    ll h = 0;
    for(auto i = hist.rbegin(); i != hist.rend(); i++) {
        if(h == 0 && i->second >= 4) {
            cout << i->first * i->first << endl;
            return 0;
        } else if(h > 0 && i->second >= 2) {
            cout << h * i->first << endl;
            return 0;
        } else if(i->second >= 2) {
            h = i->first;
        }
    }
    cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
#define PI 3.14159265358979323846264338327950L
typedef unsigned long long uint64;
using namespace std;
int main(){
   int a;
   cin >> a;
   cout << a+(a*a)+(a*a*a) << endl;
  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#define MOD 1000000007

int i;

struct edge {
    int to;
    int cost;
};

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


int main(void) {
    int i,j,k;
    ll n;
    ll ans;
    ll r,d,x;
    cin >> r >> d >> x;
    
    for(i=0;i<10;i++){
        x = r*x-d;
        cout << x << endl;
    }
    return 0;
}


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


using namespace std;


long long comb2(long long x) {
    if (x < 2)
        return 0;
    return (x * (x - 1)) / 2;
}


int main() {
    long long N, P;
    string S;
    cin >> N >> P;
    cin >> S;

    if (P == 2 || P == 5) {
        long long ans = 0;
        for (long long i = S.length() - 1; i >= 0; i--) {
            if ((S[i] - '0') % P == 0) {
                ans += (i + 1);
            }
        }
        cout << ans << endl;
        return 0;
    }

    vector<long long> r_cnt(P, 0);
    r_cnt[0]++;
    long long r = 0;
    long long base = 1;
    for (long long i = S.length() - 1; i >= 0; i--) {
        r += (S[i] - '0') * base;
        r %= P;
        r_cnt[r]++;
        base = (base * 10) % P;
    }

    long long ans = 0;
    for (auto c : r_cnt) {
        ans += comb2(c);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3692
# https://atcoder.jp/contests/abc074/tasks/arc083_a
# Cだけど水パフォ

import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))

# 水と砂糖の操作は独立にできる
# 知りたいのは砂糖の質量と水の質量
# 砂糖の質量の増加の仕方と水の質量の増加の仕方は全探索できる
# F<3000なので、1グラムずつ調べても10*7でpypyならギリok


from itertools import product
A, B, C, D, E, F = read_ints()

# 水の質量の増加の仕方
# Aの倍数とBの倍数はありえる #かつF[g]以下
candi_water = set()
for pa, pb in product(range(F // (A ** 100) + 2), range(F // (B ** 100) + 2)):
    candi = pa * A * 100 + pb * B * 100
    if candi > F:
        continue
    candi_water.add(candi)


# 砂糖の質量の増加の仕方
candi_suger = set()
for pa, pb in product(range(F // (C) + 2), range(F // (D) + 2)):
    candi = pa * C + pb * D
    if candi > F:
        continue
    candi_suger.add(candi)


# 全組み合わせを全探索
most = -1
ans = (-1, -1)
# print(candi_water, candi_suger)
for a, b in product(candi_water, candi_suger):
    if a == 0 or a + b > F or 100 * b > E * a:  # ビーカーに入らないか溶け残るか
        continue
    noudo = b / (a + b)
    if noudo > most:
        most = noudo
        ans = (a + b, b)
        # print(most, ans)
print(*ans)


Measured memory_bytes: 41820
w, h, n = gets.chomp.split(" ").map{|i| i.to_i}
x, y, a = Array.new(3){Array.new(n)}
for i in 0...n
    x[i], y[i], a[i] = gets.chomp.split(" ").map{|i| i.to_i}
end

field = Array.new(w){Array.new(h){false}}

def ok(i, j, _x, _y, a)
  case a
  when 1
    if i < _x
      true
    else
      false
    end
  when 2
    if i >= _x 
      true
    else
      false
    end
  when 3
    if j < _y
      true
    else
      false
    end
  when 4
    if j >= _y
      true
    else
      false
    end
  end
end

for k in 0...n
  for i in 0...w
    for j in 0...h
      if ok(i, j, x[k], y[k], a[k])
        field[i][j] = true
      end
    end
  end
end

ans = 0
for i in 0...w
  for j in 0...h
    if field[i][h-1-j]
      #print "x"
    else
      #print "."
      ans += 1
    end
  end
  #print "\n"
end
puts ans

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 1e5 + 2;


void solve() {
      int i = 0, j = 0, k = 0, n = 0, m = 0;
      // int  
      int h1, m1, h2, m2;
      cin >> h1 >> m1 >> h2 >> m2 >> k;
      m = (h2 - h1) * 60 + m2 - m1;
      m -= k;
      cout << max(m, 0LL) << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1; 
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

Measured memory_bytes: 3648
n = int(input())
a = list(map(int,input().split()))
b = sorted(a)
if a == b:
    print("YES")
else:
    c = 0
    for i in range(n):
        if a[i] == b[i]:
            pass
        else:
            c+=1
    if c == 2:
        x = []
        y = []
        for i in range(n):
            if a[i] == b[i]:
                pass
            else:
                x.append(a[i])
                y.append(i)
        a[y[1]] = x[0]
        a[y[0]] = x[1]
        
        if a == b:
            print("YES")
        else:
            print("NO")
    else:
        print("NO")

Measured memory_bytes: 3064
def resolve():
	x1,y1,x2,y2=map(int,input().split())
	x3=y1-y2+x2
	y3=x2-x1+y2
	x4=y1-y2+x1
	y4=x2-x1+y1

	print('{} {} {} {}'.format(x3,y3,x4,y4))		

resolve()

Measured memory_bytes: 38384
#include <stdio.h>

int main(void) {
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a>=0&&a<=10000&&b>=0&&b<=10000&&c>=0&&c<=10000){
		if(a<b){
			if(b<c) printf("%d %d %d\n",a,b,c);
			else{
				if(a<c) printf("%d %d %d\n",a,c,b);
				else printf("%d %d %d\n",c,a,b);
			}
		}
		else{
			if(b>c) printf("%d %d %d\n",c,b,a);
			else{
				if(a>c) printf("%d %d %d\n",b,c,a);
				else printf("%d %d %d\n",b,a,c);
			}
		}
	}
	return 0;
}



Measured memory_bytes: 2100
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 100007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
int main()
{
   ll n;
   cin >> n;
   ll d = n - 1;
   for (ll i = 2; i <= (ll)sqrt(n); i++)
   {
      if (n % i == 0 && d > i + n / i - 2)
      {
         d = i + n / i - 2;
      }
   }
   cout << d << endl;
   return 0;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(void){
   int a,b;cin >> a >> b;
   cout << max(0,a-2*b) << endl;
}

Measured memory_bytes: 256
S = input()
Q = int(input())
reverse = False
before = []
after = []
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        reverse = not reverse
    else:
        T, F, C = q
        if (F == '1' and not reverse) or (F == '2' and reverse):
            before.append(C)
        else:
            after.append(C)

if not reverse:
    answer = ''.join(before[::-1]) + S + ''.join(after)
else:
    answer = ''.join(after[::-1]) + S[::-1] + ''.join(before)
print(answer)

Measured memory_bytes: 12052
#include <stdio.h>

int main(){
	int x;
	int a;
	int b;
	int xa;
	int xb;
	scanf("%d %d %d", &x, &a, &b);
	xa=x-a;
	if(xa<0){
		xa*=-1;
	}
	xb=x-b;
	if(xb<0){
		xb*=-1;
	}
	if(xa>xb){
		printf("B");
	}else{
		printf("A");
	}

	
	return 0;
}

Measured memory_bytes: 1632
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(n):
    if p[i] == i + 1:
        if i != n - 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            ans += 1
        else:
            p[i], p[i - 1] = p[i - 1], p[i]
            ans += 1

print(ans)

Measured memory_bytes: 14008