akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
  int n,w;
  cin >> n >> w;

  vector<int> W(n);
  vector<long> V(n);
  for(int i = 0;i < n;i++) cin >> W[i] >> V[i];

  vector<vector<long long>> dp(n + 1,vector<long long>(w + 1));

  for(int i = 0; i < n;i++){
    for(int j = 0;j <= w;j++){
      if(j - W[i] >= 0){
        dp[i + 1][j] = max(
                           dp[i + 1][j],
                           dp[i][j - W[i]] + V[i]
                           );
      }
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
    }
  }

  cout << dp[n][w] << endl;
  
  return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d){cout<<"Yes";}
  else if(abs(a-b)<=d&&abs(c-b)<=d){cout<<"Yes";}
  else{cout<<"No";}
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 246912

static
int erat[ N + 1 ] = { 0 };

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i, j;

  for ( j = 2; j <= N; ++j )
  {
    if ( erat[ j ] )  continue ;

    for ( i = j * 2; i <= N; i += j )
    {
      erat[ i ] = -1;
    }
  }

  j = 0;
  for ( i = 2; i <= N; ++i )
  {
    j += !( erat[ i ] );

    erat[ i ] = j;
  }

  for ( ; ; )
  {
    int n;

    scanf ( "%d", &n );
    if ( !( n ) ) break ;

    printf ( "%d\n", erat[ n * 2 ] - erat[ n ] );
  }

  return ( 0 );
}

Measured memory_bytes: 0
#include<stdio.h>
#include<cctype>
int main (){
char ch;
while(1)
{
scanf("%c",&ch);
if ( ch == '\n' ) break;
if(islower(ch)){ch=toupper(ch);printf("%c",ch);}
else if(isupper(ch)){ ch=tolower(ch);printf("%c",ch);}
else printf("%c",ch);

}
printf("\n");
return 0;
}

Measured memory_bytes: 940
#include<stdio.h>
int main(void){
	int d, sum, x, y;
	while(scanf("%d", &d) != EOF){
		sum=x=y=0;
		for(;x<600;x+=d){
			y=x*x;
			sum += y*d;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <queue>
#define ll long long
#define N 10000
#define mod 998244353
#define LL 100
using namespace std;

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}


int main(){
    ll n,m,k;
    cin>>n>>m>>k;
    
    ll f[n+1];
    f[1]=m;
    f[0]=1;
    for (ll i=2; i<=n; i++){
        f[i]=f[i-1]*(m-1);
        f[i]%=mod;
    }
    
    ll p[n+k+1];
    p[1]=1;
    p[0]=1;
    for (int i=2; i<=n+k; i++){
        p[i]=p[i-1]*i;
        p[i]%=mod;
    }
    
    //cout<<p[2]<<endl;
    
    
    ll sum=0;
    for (ll i=0; i<=k; i++){
        if (n<=k) break;
        ll u=p[i]*p[n-i-1];
        ll s=modinv(u,mod);
        ll h=p[n-1]*s;
        h%=mod;
        sum+=f[n-i]*h;
        sum%=mod;
        //ll h=p[n-1]/p[i];
        //h/=p[n-i-1];
        //cout<<h<<endl;
        //sum+=f[n-i]*h;
    }
    cout<<sum<<endl;   
}

Measured memory_bytes: 8260
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input,
  "index" : 0,
  "max" : input.length,
  "next" : function(){
    if(!this.hasNext()){throw "NoSuchElementException:次に要素は無いよ";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  },
  "hasNext" : function(){return (this.index < this.max);}
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
  var P = one[0];
  var Q = one[1];
  var R = one[2];
  var output = [P + Q,Q + R, R + P];
  myout(Math.min.apply(null,output));
}

Measured memory_bytes: 11468
#ifndef Local
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define popCnt(x) (__builtin_popcountll(x))
typedef long long Long;

const int N = 1e3 + 5;

bool solve(const vector<pair<int, int>>& v, int r, int s) {
  int safe_l = 1, safe_r = r;
  for (int i = v.size() - 1; i >= 0; --i) {
    safe_r = min(safe_r, r);
    safe_l = max(safe_l, 1);

    auto curr = v[i];
    if (curr.first == 0) {
      if (curr.second == -1) {
        safe_l += 1;
      } else {
        safe_r -= 1;
      }
    } else {
      if (curr.second == -1) {
        safe_r += 1;
      } else {
        safe_l -= 1;
      }
    }
    if (safe_l > r || safe_r < 1 || safe_l > safe_r) {
      return false;
    }
  }

  return safe_l <= s && s <= safe_r;
}

int main() {
  srand(time(0));
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif

  int h, w, n;
  cin >> h >> w >> n;
  int sr, sc;
  cin >> sr >> sc;

  string s[2];
  cin >> s[0] >> s[1];

  vector<pair<int, int>> hor, ver;
  for (int i = 0; i < n; ++i) {
    for (int p = 0; p < 2; ++p) {
      if (s[p][i] == 'U') {
        ver.emplace_back(p, -1);
      }
      if (s[p][i] == 'D') {
        ver.emplace_back(p, +1);
      }
      if (s[p][i] == 'L') {
        hor.emplace_back(p, -1);
      }
      if (s[p][i] == 'R') {
        hor.emplace_back(p, +1);
      }
    }
  }

  cout << ((solve(hor, w, sc) && solve(ver, h, sr)) ? "YES\n" : "NO\n");
}


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

struct UnionFind{
    vi d;
    UnionFind(int n=0):d(n,-1) {}
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y){return find(x) == find(y);}
    int size(int x){return -d[find(x)];}
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a, b;
        cin >> a >> b;
        uf.unite(a,b);
    }
    int ans = 0;
    rep(i,n) ans = max(ans,uf.size(i));
    cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<int>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };

ll K;
int main()
{
	ll N;
	cin >> N >> K;
	ll t = N % K;
  	ll ans;
  	ans = min(t,abs(t-K));
    cout << ans << endl;
}

Measured memory_bytes: 256
// ------------------------------------
// Date:2018/ 3/17
// Problem:One storoke path d.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl

typedef long long ll;

static const int MOD = 1000000007;
static const int MAX_N = 8;

int p[MAX_N];
bool l[MAX_N][MAX_N];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  memset(l, false, sizeof(l));
  int N, M;
  cin >> N >> M;

  
  REP(i, N) {
    p[i] = i;
  }
  vector< int > a(M);
  vector< int > b(M);
  //cout << "ok" << endl;
  REP(i, M) {
    int ai, bi;
    cin >> ai >> bi;
    ai--;
    bi--;
    l[ai][bi] = l[bi][ai] = true;
  }

  bool ok;
  ll ans = 0ll;
  do {
    ok = true;
    if (p[0] != 0) continue;
    REP(i, N - 1) {
      if (!l[p[i]][p[i + 1]]) ok = false;
    }
    if (ok) ans++;
  } while (next_permutation(p, p + N));

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



Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;


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

	cin >> H >> W >> K;
	vector<vector<int>>v(H, vector<int>(W));
	vector<pair<int, int>>p(H * W + 1);
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> v[i][j];
			p[v[i][j]] = { i,j };
		}
	}
	cin >> N;
	vector<int>sum(H*W + 1);
	for (int i = K + 1; i <= H*W; i++) {
		sum[i] = sum[i - K];
		sum[i] += abs(p[i].first - p[i - K].first) + abs(p[i].second - p[i - K].second);
	}
	for (int i = 0; i < N; i++) {
		cin >> L >> R;
		cout << sum[R] - sum[L] << endl;
	}
	return 0;
}

Measured memory_bytes: 2560
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Card {
    char suit;
    int value;

    bool operator<(const Card& c) const {
        return this->value < c.value;
    }
    bool operator<=(const Card& c) const {
        return this->value <= c.value;
    }
    Card& operator=(int val) {
        this->value = val;
        return *this;
    }
};
#define MAX 100000
#define SENTINEL 2000000000
Card L[MAX/2+2],R[MAX/2+2];
void merge(Card *a,int n, int l,int mid,int r) {
    int n1=mid-l;
    int n2=r-mid;
    rep(i,n1) L[i]=a[l+i];
    rep(i,n2) R[i]=a[mid+i];
    L[n1]=SENTINEL;
    R[n2]=SENTINEL;
    int i,j;
    i=j=0;
    for(int k=l;k<r;k++) {
        if(L[i]<=R[j]) a[k]=L[i++];
        else a[k]=R[j++];
    }
}
void merge_sort(Card *a,int n,int l,int r) {
    if(l+1<r) {
        int mid=(l+r)/2;
        merge_sort(a,n,l,mid);
        merge_sort(a,n,mid,r);
        merge(a,n,l,mid,r);
    }
}
int partition(Card *a,int p,int r) {
    int i,j;
    Card x;
    x=a[r];
    i=p-1;
    for(int j=p;j<r;j++) {
        if(a[j]<=x) {
            i++;
            swap(a[i],a[j]);
        }
    }
    swap(a[i+1],a[r]);
    return i+1;
}

void quick_sort(Card *a,int n,int p,int r) {
    int q;
    if(p < r) {
        q = partition(a,p,r);
        quick_sort(a,n,p,q-1);
        quick_sort(a,n,q+1,r);
    }
}

Card A[MAX],B[MAX];
int main() {
    int n;
    cin>>n;
    rep(i,n) {
        cin>>A[i].suit>>A[i].value;
        B[i]=A[i];

    }

    merge_sort(A,n,0,n);
    quick_sort(B,n,0,n-1);
    bool is_stable = true;

    rep(i,n) is_stable &= A[i].suit == B[i].suit;

    if(is_stable) cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    rep(i,n) cout<<B[i].suit<<" "<<B[i].value<<endl;

    return 0;
}

Measured memory_bytes: 3512
// finish date: 2018/04/10

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvvi vector<vector<vector<int>>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define bigmod 1000000007
#define INF 1050000000
#define pii pair<int,int>


int main() {
    int N;
    cin >> N;
    int in1, in2;
    map<int, int> red, blue;
    rep(i, N) {
        cin >> in1 >> in2;
        red[in1] = in2;
    }
    rep(i, N) {
        cin >> in1 >> in2;
        blue[in1] = in2;
    }
    int ans = 0;
    for (auto r = red.rbegin(); r != red.rend(); r++) {
        int mi = INF;
        auto e = red.begin(); //この値は適当
        for (auto b = blue.begin(); b != blue.end(); b++) {
            if (r->first >= b->first) continue;
            if (r->second < b->second && b->second < mi) {
                mi = b->second;
                e = b;
            }
        }
        if (mi != INF) {
            ans++;
            blue.erase(e);
        }
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n, m;
    cin >> n >> m;
    vs32 a(m), c(m, 0);
    int b;
    rep (i, m)
    {
        cin >> a[i] >> b;
        int temp;
        rep (j, b)
        {
            cin >> temp;
            --temp;
            c[i] |= 1 << temp;
        }
    }

    vs32 dp(1 << n, 1e9);
    dp[0] = 0;

    rep (i, m)
    {
        for (int j = ((1 << n) - 1); j >= 0; --j)
        {
            dp[j] = MIN(dp[j], dp[j & ~c[i]] + a[i]);
        }
    }

    int ans;
    if (dp[(1 << n) - 1] == 1e9)
    {
        ans = -1;
    }
    else
    {
        ans = dp[(1 << n) - 1];
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 256
def furui(n):
  if n <= 1:
    return []

  primes = []
  target = [i for i in range(2, n+1)]

  while(True):
    if target[0] ** 2 > n:
      break
    primes.append(target[0])
    target = list(filter(lambda x: (x % primes[-1]) != 0, target))
    # print(target)

  primes.extend(target)
  return primes

primes = furui(10**5 + 10)

X = int(input())
for p in primes:
  if p >= X:
    ans = p
    break

print(ans)


Measured memory_bytes: 7448
#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 repr(i,n) for(int i=(int)(n-1);i>=0;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define print(x) cout << 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())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef set<int> S;
typedef complex<double> P;

#define INF INT_MAX/3
#define MAX_N 1000000001


int main(){
    int n;
    cin >> n;
    vector<P> v;
    rep(i, n) {
        double x, y;
        cin >> x >> y;
        v.pb(P(x, y));
    }

    if (n % 2) {
        cout << "NA" << endl;
    } else {
        vector<P> center;
        int d = n / 2;
        rep(i, d) {
            center.pb((v[i] + v[i + d]) / 2.0);
        }
        bool ok = true;
        rep(i, d - 1)repl(j, i + 1, d) if (abs(center[i] - center[j]) > 1e-4) ok = false;

        if (ok) printf("%.5f %.5f\n", center[0].real(), center[0].imag());
        else cout << "NA" << endl;
    }

    return 0;
}

Measured memory_bytes: 3268
#include <stdio.h>

int main(){
	
	char s[100];
	int n,i;
	int ans[5] = {0};
	
	scanf("%d",&n);
	for(i = 0;i < n;++i){
		scanf("%s",s);
		
		switch(s[0]){
			
		case 'A':
			ans[0]++;
			break;
		case 'W':
			ans[1]++;
			break;
		case 'T':
			ans[2]++;
			break;
		case 'R':
			ans[3]++;
			break;
		default: break;
		}
	}
	
	printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",ans[0],ans[1],ans[2],ans[3]);
	return 0;
}


Measured memory_bytes: 1708
arr = [0]*5
for i in range(5):
    arr[i] = int(input())
time = 0
for ar in arr:
    time += (-(-ar//10))*10
amari = []
for i in arr:
    amari.append(i%10)
amari.sort()
while 0 in amari:
    amari.remove(0)
if amari == []:
    amari.append(10)
print(time - (10-amari[0]))


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

typedef long long ll;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

const int N = 100005;
vector<int> g[N];
int cnt[N];
P es[N];
int col[N];
int deg[N];

void dfs(ll v,ll pre){
  cnt[v]=1;
  for(ll nv : g[v]){
    if(nv==pre)continue;
    dfs(nv,v);
    cnt[v]+=cnt[nv];
  }
}

void ddfs(ll v,ll pre,ll c){
  col[v]=c;
  for(ll nv : g[v]){
    if(nv==pre)continue;
    ddfs(nv,v,c);
  }
}

bool solve(){
  int n,x,y;
  scanf("%d%d%d", &n, &x, &y);
  x--; y--;

  memset(deg,0,sizeof(deg));

  rep(i,n-1){
    int a,b;
    scanf("%d%d", &a, &b);
    a--;b--;
    g[a].push_back(b);
    g[b].push_back(a);
    es[i] = {a,b};
    deg[a]++;
    deg[b]++;
  }

  if(n==2) return true;
  if(n%2==1) return false;

  dfs(0,-1);
  memset(col,-1,sizeof(col));
  rep(i,n-1){
    ll a=es[i].fi, b=es[i].se;
    if(cnt[a]<cnt[b]) swap(a,b);
    if(cnt[b]==n-cnt[b]){
      ddfs(a,b,0);
      ddfs(b,a,1);
      deg[a]--;
      deg[b]--;
      break;
    }
  }

  if(col[x]==col[y]) return false;

  int cnt1[2] = {0,0};
  rep(i,n){
    if(deg[i]>2) return false;
    if(deg[i]==1) cnt1[col[i]]++;
  }

  if(cnt1[0]!=2 || cnt1[1]!=2) return false;

  return (deg[x]==1 && deg[y]==1);
}

int main(){
  if(solve()) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}



Measured memory_bytes: 16088
N,K=list(map(int,input().split()))
l=list(map(int,input().split()))
import math
if N==1:
   if l[0]==K:
      print("POSSIBLE")
      exit()
   else:
      print("IMPOSSIBLE")
      exit()
A=math.gcd(l[0],l[1])
if K<=max(l):
   for i in range(max(0,N-2)):
      A=math.gcd(A,l[i+2])
   if K%A==0:
      print("POSSIBLE")
   else:
      print("IMPOSSIBLE")
else:
   print("IMPOSSIBLE")

Measured memory_bytes: 19816
def resolve():
    A_list = []

    A_list.append(list(map(int, input().split())))
    A_list.append(list(map(int, input().split())))
    A_list.append(list(map(int, input().split())))


    N = int(input())

    b_list = []
    for i in range(N):
        b_list.append(int(input()))

    for i in b_list:
        for j in range(len(A_list)):
            for k in range(len(A_list[j])):
                if A_list[j][k] == i:
                    A_list[j][k] = 0 


    if A_list[0][0] == 0 and A_list[0][1] == 0 and A_list[0][2] == 0:
        print("Yes")
        return

    if A_list[1][0] == 0 and A_list[1][1] == 0 and A_list[1][2] == 0:
        print("Yes")
        return

 
    if A_list[2][0] == 0 and A_list[2][1] == 0 and A_list[2][2] == 0:
        print("Yes")
        return

    if A_list[0][0] == 0 and A_list[1][0] == 0 and A_list[2][0] == 0:
        print("Yes")
        return

    if A_list[0][1] == 0 and A_list[1][1] == 0 and A_list[2][1] == 0:
        print("Yes")
        return

    if A_list[0][2] == 0 and A_list[1][2] == 0 and A_list[2][2] == 0:
        print("Yes")
        return

    if A_list[0][0] == 0 and A_list[1][1] == 0 and A_list[2][2] == 0:
        print("Yes")
        return

    if A_list[0][2] == 0 and A_list[1][1] == 0 and A_list[2][0] == 0:
        print("Yes")
        return


    print("No")
    return

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 3188
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))

t = input()
last = ["" for _ in range(k)]
move = {"r": "p", "p": "s", "s": "r"}
pts = {"r": r, "p": p, "s": s}
score = 0

for i in range(n):
    if move[t[i]] != last[i%k]:
        score += pts[move[t[i]]]
        last[i%k] = move[t[i]]
    else:
        last[i%k] = ""

print(score)

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

using namespace std;

const int N = 100005;

int n, m, a[N];
long long add[N], del[N];

int main(){
  scanf("%d%d", &n, &m);
  for(int i = 1; i <= n; ++i){
    scanf("%d", &a[i]);
  }
  for(int i = 1; i < n; ++i){
    int l = a[i], r = a[i + 1];
    if(r > l){
      add[m] += r - l;
      add[r] -= r - l;
      add[l] += r - l;
      add[r] += r + 1;
      add[l] -= r + 1;
      del[r] += 1;
      del[l] -= 1;
    }
    else{
      swap(l, r);
      add[r] += m - r + l;
      add[l] -= m - r + l;
      add[m] += m + l + 1;
      add[r] -= m + l + 1;
      del[m] += 1;
      del[r] -= 1;
      add[l] += l + 1;
      del[l] += 1; 
    }
  }
  for(int i = m - 1; i > 0; --i){
    add[i] += add[i + 1];
    del[i] += del[i + 1];
  }
  long long res = 1LL << 62;
  for(int i = 1; i <= m; ++i){
    add[i] -= 1LL *del[i] * i;
    res = min(res, add[i]);
  } 
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2176
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<stdio.h>
#include<locale.h>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long int ll;
const ll cs=1000000000;
const ll md=1000000007;
//35
string s;

int main()
{
 cin >> s;
 int ans=0;
 int gp=0;
 for(int i=0;i<s.size();i++)
 {
	if(s[i]=='p'&&gp==0){ans--; gp++;} //gを出す
	else if(s[i]=='p'&&gp!=0){gp--;} //pを出す
	else if(s[i]=='g'&&gp==0){gp++;} //gを出す
	else if(s[i]=='g'&&gp!=0){ans++; gp--;} //pを出す
//	printf("%d %d\n",ans,gp);
 }
 printf("%d\n",ans);
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int n = N%10;
  if(n==3){
    cout << "bon";
  }else{
    if(n==0 || n==1 || n==6 || n==8){
      cout <<"pon";
    }else{
      cout << "hon";
    }
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)

int main()
{
	ll k,n,ans=0,max=0;
	string s;

	cin >> k >> n;

	vecll a(n);

	forll(i, 0, n)
		cin >> a[i];

	ll buf;

	forll(i, 0, a.size())
	{
		if(i==(a.size()-1))
			buf= abs(a[i]-(a[0]+k));
		else
			buf = abs(a[i] - a[i + 1]);
		if (max < buf)
			max = buf;
	}

	ans = k - max;

	cout << ans << endl;

}

Measured memory_bytes: 1792
// #define _GLIBCXX_DEBUG
// #pragma GCC optimize("Ofast")
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
// #include <atcoder/all>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define reps(i, s, n) for (int i = s; i < (int)(n); ++i)
using namespace std;
using i64 = int_fast64_t;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

void solve() {
    VV<int> c(3, V<int>(3));
    rep(i, 3) rep(j, 3) cin >> c[i][j];
    bool ans = false;
    rep(i, 101) rep(j, 101) rep(k, 101) {
        int b1 = c[0][0] - i;
        int b2 = c[1][1] - j;
        int b3 = c[2][2] - k;
        V<int> A = {i, j, k};
        V<int> B = {b1, b2, b3};
        bool flag = true;
        rep(ii, 3) rep(jj, 3) {
            if (c[ii][jj] != A[ii] + B[jj]) {
                flag = false;
            }
        }
        if (flag) ans = true;
    }

    if (ans)
        cout << "Yes\n";
    else
        cout << "No\n";
}
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    // cout << fixed << setprecision(15);
    solve();
}

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

#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;

typedef long long ll;

int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);}
int lcm(int a,int b){
	return a/gcd(a,b)*b;}
int search(int a[],int n,int key){
	int i=0;
	a[n]=key;
	while(a[i]!=key)i++;
	return i!=n;
}
int main(){
	int i,n,a[100001],q,key,ans=0;
	
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>key;
		if(search(a,n,key))ans++;
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    pii p[N];
    rep(i, N){
        cin >> p[i].first;
        p[i].second = i;
    }
    sort(p, p+N);
    int m = N+1, ans = 0;
    rep(i, N){
        if(p[i].second <= m){
            ans++;
            m = p[i].second;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+50;
char s[N];int n;
int main(){
    scanf("%s",s+1);n=strlen(s+1);
    for(int i=1;i<=n;i++)if(s[i]=='?')s[i]='D';
    puts(s+1);
    return 0;
}

Measured memory_bytes: 3940
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N, K; cin >> N >> K;
  int A[N]; rep(i,N) cin >> A[i];
  sort(A,A+N);
  int GCD = A[0];
  rep(i,N) GCD = __gcd(GCD, A[i]);

  if (K%GCD==0 && K<=A[N-1]) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;




  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 3936
from collections import defaultdict

def calc(a):
    a1, a2 = 0, 0
    if '.' in a:
        a = a.rstrip('0')
        cnt = len(a) - a.index('.') - 1
        a1, a2 = -cnt, -cnt
    a = int(a.replace('.', ''))

    while a % 2 == 0:
        a1 += 1
        a //= 2
    while a % 5 == 0:
        a2 += 1
        a //= 5
    return a1, a2

d = defaultdict(int)
N = int(input())
A = []
for _ in range(N):
    a = input()
    a1, a2 = calc(a)
    d[(a1, a2)] += 1

ans = 0
key = list(d.keys())
for i in range(len(key)):
    a1, a2 = key[i]
    v = d[(a1, a2)]
    if a1 >= 0 and a2 >= 0:
        ans += v * (v - 1) // 2
    for j in range(i + 1, len(key)):
        b1, b2 = key[j]
        if (a1 + b1) >= 0 and (a2 + b2) >= 0:
            ans += v * d[(b1, b2)]

print(ans)

Measured memory_bytes: 9460
N = int(input())
rec = []
for i in range(N - 1):
    c, s, f = map(int, input().split())
    rec.append((c, s, f))

for i in range(N):
    t = 0
    for j in range(i, N - 1):
        c, s, f = rec[j][0], rec[j][1], rec[j][2]
        if t <= s:
            t = s
        elif t % f == 0:
            pass
        else:
            t = t + f - (t % f)

        t += c

    print(t)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int p[n];
    for(int i=0;i<n;i++)cin>>p[i];
    sort(p,p+n);
    int x=0;
    for(int i=0;i<k;i++)x+=p[i];
    cout<<x<<endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<multiset<int>> cnt(N + 1);
  vector<int64_t> A(N);
  int64_t res = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    int64_t b = A[i] + i + 1;
    if (b < N + 1) cnt[b].insert(i);
    if (i - A[i] + 1 >= 0) res += cnt[i - A[i] + 1].size();
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 23496
#include<bits/stdc++.h>
using namespace std;
#define int long long 
signed main()
{
    // freopen ("input.txt","r",stdin);
    // freopen ("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int k,n,i,max;
    cin>>k>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    max=k-a[n-1]+a[0];
    for(i=0;i<n-1;i++)
    {
        if(a[i+1]-a[i]>max)
        max=a[i+1]-a[i];
    }
    cout<<k-max;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int tt,n,x,i,j,d,s,t,flag=0,f;

	ios_base::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
    
    
    d=0;
    	cin>>n;
    	vector<int> a(n),b(n);
    	for(i=0;i<n;i++)
{
    	    cin>>b[i];

}
a[0]=0;
   a[1]=abs(b[1]-b[0]);
    	for(i=2;i<n;i++)
    	{
	a[i]=std::min(a[i-1]+abs(b[i]-b[i-1]),a[i-2]+abs(b[i]-b[i-2]));

						  
						
					}
cout<<a[n-1]<<endl;

				
	
	return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n){return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),m=getInt();
		ArrayList<ArrayList<Integer>>a=new ArrayList<>();

		for(int i=0;i<n;++i) {
			ArrayList<Integer>d=new ArrayList<>();
			a.add(d);
			INS(m).forEach(d::add);
		}

		HashMap<Integer,Integer>count=new HashMap<>();
		int r=n;
		for(int i=0;i<m-1;++i){
			count.clear();
			for(int j=0;j<n;++j) {
				count.merge(a.get(j).get(0),1,Integer::sum);
			}
			r=Math.min(r,count.values().stream().max(Comparator.naturalOrder()).get());
			int hoge=count.entrySet().stream().max(Entry.comparingByValue()).get().getKey();
			a.stream().forEach(o->o.removeIf(oo->oo==hoge));
		}
		System.out.println(r);
	}
}


Measured memory_bytes: 46704
#pragma once
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endlhttps:  // stopwatch.onl.jp/#
#endif
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> list(N);
  int max = -1;
  int maxad = -1;
  int semimax = -1;
  for (int i = 0; i < N; i++) {
    cin >> list[i];
    if (list[i] > max) {
      semimax = max;
      max = list[i];
      maxad = i;
    } else if (list[i] > semimax) {
      semimax = list[i];
    }
  }
  for (int i = 0; i < N; i++) {
    if (i == maxad){
      cout << semimax <<endl;
    } else {
      cout << max <<endl;
    }
  }
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/

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

int main() {
    int n = 0;
    int a[100] = {0};
    int A = 0, B = 0;
    cin >> n;
    rep(i, n) {
        cin >> a[i];
    }
    sort(a, a + 100, greater<>());
    rep(i, n) {
        if (i % 2 == 0) {
            A += a[i];
        } else {
            B += a[i];
        }
    }
    cout << A - B << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


int main() {

	int n, m;
	cin >> n >> m;
	vector<int> x(m);
	rep(i, m) {
		cin >> x[i];
	}

	if (n >= m) {
		cout << 0 << endl;
		return 0;
	}
	sort(x);
	int sum = x[m - 1] - x[0];
	vector<int> dis;
	rep(i, m - 1) {
		dis.push_back(x[i + 1] - x[i]);
	}
	sort(dis);
	reverse(dis);
	rep(i, n - 1) {
		sum -= dis[i];
	}
	cout << sum << endl;
	return 0;
}





Measured memory_bytes: 1276
a1,b1=map(int,input().split())
a2,b2=map(int,input().split())
a3,b3=map(int,input().split())
a4,b4=map(int,input().split())
a5,b5=map(int,input().split())
a6,b6=map(int,input().split())
a7,b7=map(int,input().split())

print(a1-b1)
print(a2-b2)
print(a3-b3)
print(a4-b4)
print(a5-b5)
print(a6-b6)
print(a7-b7)



Measured memory_bytes: 5592
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;

void run (void) {
  i32 n;
  scanf("%" SCNi32, &n);
  i32 *a = (i32 *) calloc (n + 1, sizeof (i32));
  i32 i,j;
  for (i = 1; i <= n; ++i) {
    scanf("%" SCNi32, a + i);
  }
  i32 ans[100];
  for(i = 0; i < n; ++i) {
    for (j = n - i; j >= 1; --j) {
      if (a[j] == j) {
	ans[i] = j;
	break;
      }
    }
    if (j < 1) {
      puts ("-1");
      return;
    }
    for (; j + 1 <= n - i; ++j) {
      a[j] = a[j + 1];
    }
  }
  for (i = n - 1; i >= 0; --i) {
    printf("%" PRIi32 "\n", ans[i]);
  }
}

int main (void) {
  run ();
  return 0;
}


Measured memory_bytes: 128
import sys
if sys.version_info[0]>=3: raw_input=input
a=[1,1,2]
for i in range(3,31): a.append(a[i-1]+a[i-2]+a[i-3])
while True:
	n=int(raw_input())
	if n==0: break
	print((a[n]+3649)//3650)

Measured memory_bytes: 4212
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf pop_front()
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define loopl(i,a,b) for(lli i=a;i<b;i++) 
#define loop(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
#define inf 1000000000000000
#define lld long double
#define pll pair<long long int,long long int>
#define vll vector<lli>
#define stp setprecision(15)
#define eps 0.000001
#define endl '\n'
#define ll lli
 
using namespace std ;
 
typedef tree<pll,null_type,less<pll>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
#define N 200010
#define lg 19



int main() 
{ 

/////////////////////////////////////
    
    fastio;
 
/////////////////////////////////////    

    lli n,k;
    cin>>n>>k;

    lli a[n],full[n]={0},part[n]={0};

    loopl(i,0,n) cin>>a[i];

    loopl(i,0,n)
    {
        loopl(j,0,n)
        {
            if(a[i] > a[j]) full[i]++;
        }
    }

    loopl(i,0,n)
    {
        loopl(j,i+1,n)
        if(a[i] > a[j]) part[i]++;
    }

    //loopl(i,0,n) cout<<i<<" "<<full[i]<<" "<<part[i]<<endl;

    lli ans=0;

    loopl(i,0,n)
    {
        lli o = part[i]%mod;
        o = (o*k)%mod;
        lli  p = k*(k-1)/2;
        p%= mod;
        ans = (ans + o + full[i]*p)%mod ;
    }
    cout<<ans;

}   




Measured memory_bytes: 256
def reconstruct(preorder, inorder, postorder):
    if len(preorder) == 0:
        return
    node_no = preorder[0]
    node_div = inorder.index(node_no)

    reconstruct(preorder[1:node_div+1], inorder[:node_div], postorder)
    reconstruct(preorder[node_div+1:], inorder[node_div+1:], postorder)

    postorder.append(node_no)
    return

def main():
    input()
    preorder = [int(x) for x in input().split()]
    inorder = [int(x) for x in input().split()]

    postorder = []
    reconstruct(preorder, inorder, postorder)
    print(" ".join(map(str, postorder)))

main()


Measured memory_bytes: 5604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	ll n;
	cin>>n;
	n--;
	cout <<a[n];
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[1005]; 
int main()
{
	int a,b,c,k;cin>>a>>b>>c>>k;
	while(k--)
	{
		if(b<=a) b=b*2;
		else if(c<=b)
		c=c*2;
	}
	if(c>b&&b>a)
	cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
} 

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

const int INFY = numeric_limits<int>().max();
int n;
typedef vector<vector<int>> GM;

int prim(GM &G) {
    vector<bool> inmst(n, false);
    vector<int> d(n, INFY);
    vector<int> p(n, -1);

    d[0] = 0;
    while(true) {
        int u = -1, minv = INFY;
        for (int i = 0; i < n; ++i) {
            if(!inmst[i] && d[i] < minv) {
                u = i;
                minv = d[i];
            }
        }
        if (u == -1) break;
        inmst[u] = true;
        for (int i = 0; i < n; ++i) {
            if (!inmst[i] && G[u][i] != INFY) {
                if (G[u][i] < d[i]) {
                    d[i] = G[u][i];
                    p[i] = u;
                }
            }
        }
    }
    int sum = 0;
    for (int i = 0; i < n; ++i) {
        if(p[i] != -1) sum += G[i][p[i]];
    }
    return sum;
}

int main() {
    cin >> n;
    GM G(n, vector<int>(n));
    for(int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            int c;
            cin >> c;
            G[i][j] = c == -1 ? INFY : c;
        }
    }
    cout << prim(G) << endl;
}



Measured memory_bytes: 3140
import java.util.*;
public class Main {
        public static void main(String[] args){
                Scanner sc = new Scanner(System.in);
                int[] a = new int[3];
                for(int i = 0 ; i < 3 ; i++){
                        a[i] = sc.nextInt();
                }
                sc.close();
                System.out.println(a[0] * a[1] / 2);
        }
}

Measured memory_bytes: 35552
#include <stdio.h>
#define N 3
int A[N][N] = {
	{1,2,3},
	{4,5,6},
	{7,8,0},
};
int Ax[9] = {2,0,1,2,0,1,2,0,1};
int Ay[9] = {2,0,0,0,1,1,1,2,2};
int C[N][N];
int Puzzle_8(int,int,int);
int manhattan();
int main() {
  int i, j, x, y;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j){
      scanf("%d",&C[i][j]);
      if (C[i][j] == 0) {
	x = i;
	y = j;
      }
    }
  }
  for(i = 0;;i++){
    //printf("%d\n",i);
    if(Puzzle_8(x,y,i) == 1){
      printf("%d\n",i);
      break;
    }
  }
  return 0;
}
int Puzzle_8(int x, int y,int tesu) {
  int i,j,nextx,nexty;
  int Dx[4] = {0,1,0,-1};
  int Dy[4] = {1,0,-1,0};
  // printf("%d\n",manhattan());

  if (manhattan() == 0)return 1;
  if(manhattan() > tesu){
    return 0;
  }
  //上から時計回りに調べていく
  for (i = 0; i < 4;i++) {
    nextx = x + Dx[i];
    nexty = y + Dy[i];
    //0が場外に出てしまうなら次を試す。
    if (0 > nextx || 0 > nexty || nextx > 2 || nexty > 2)continue;
    C[x][y] = C[nextx][nexty];
    C[nextx][nexty] = 0;
    /*
    for (int i = 0; i < N; ++i) {
      for (int j = 0; j < N; ++j) {
      printf("%d", C[i][j]);
      }
      printf("\n");
    }
    */
    //次を試す
    if(Puzzle_8(nextx, nexty,tesu-1) == 1)return 1;
    //元に戻す
    C[nextx][nexty] = C[x][y];
    C[x][y] = 0;
  }
  return 0;
}
int manhattan(){
  int i,j,x,y,sum = 0,key;
  for(i =0;i < N;i++){
    for(j= 0;j< N;j++){
     key = C[i][j];
     if(key == 0)continue;
     x= j - Ax[key];
     if(x < 0)x = (-1)*x;
     y = i - Ay[key];
     if(y < 0)y = (-1)*y;
     sum = sum + x+y;
   }
  }
  return sum;
}




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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

long long int n=1,cnt=0,ans=1,a[100000],b[100000],c=1,d=1,cmp,data,m,h,x,y,xcmp=0,ycmp=0,sum=0;

string s,w;

vector<int> z;

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

       cin >> s >> w;
       sort(s.begin(),s.end());
       sort(w.begin(),w.end());
       reverse(w.begin(),w.end());
       Yes(s<w);
return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#define INF 0x3f3f3f3f
using namespace std;
queue<char> A,B,C;
char tmp[105];

int main()
{
    scanf(" %s",tmp);
    int len = strlen(tmp);
    for(int i=0;i<len;i++){
        A.push(tmp[i]);
    }
    scanf(" %s",tmp);
    len = strlen(tmp);
    for(int i=0;i<len;i++){
        B.push(tmp[i]);
    }
    scanf(" %s",tmp);
    len = strlen(tmp);
    for(int i=0;i<len;i++){
        C.push(tmp[i]);
    }
    char turn = 'a';
    char win;
    while(1){
        if(turn == 'a'){
            if(A.empty()){
                win = 'A';
                break;
            }
            turn = A.front();
            A.pop();
        }
        else if(turn == 'b'){
            if(B.empty()){
                win = 'B';
                break;
            }
            turn = B.front();
            B.pop();
        }
        else{
            if(C.empty()){
                win = 'C';
                break;
            }
            turn = C.front();
            C.pop();
        }
    }
    printf("%c\n",win);
    return 0;
}


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

using namespace std;

int main()
{
	int n;
	cin >> n;
	string s;
	cin >> s;
	vector<int> left(n),right(n);

	left[0]=0;
	for(int i=1;i<n;i++)
	{
		if(s[i-1]=='W')left[i]=left[i-1]+1;
		else left[i]=left[i-1];
	}
	right[n-1]=0;
	for(int i=n-1-1;i>=0;i--)
	{
		if(s[i+1]=='E')right[i]=right[i+1]+1;
		else right[i]=right[i+1];
	}
/*
	for(int i=0;i<n;i++)
		cout << left[i];
	cout << endl;
	for(int i=0;i<n;i++)
		cout << right[i];
	cout <<endl;
*/
	int ans=100000000;
	for(int i=0;i<n;i++)
	{
		int tmp=left[i]+right[i];
		if(tmp<ans)ans=tmp;
	}

	cout << ans << endl;


}

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

long long N, M, a[100009][3], maxn = -(1LL << 60);

int main() {
	cin >> N >> M;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j < 3; j++) cin >> a[i][j];
	}
	for (int i = 0; i < 8; i++) {
		vector<long long>vec;
		for (int j = 1; j <= N; j++) {
			long long S = 0;
			for (int k = 0; k < 3; k++) { if ((i / (1 << k)) % 2 == 0) S += a[j][k]; else S -= a[j][k]; }
			vec.push_back(S);
		}
		sort(vec.begin(), vec.end()); reverse(vec.begin(), vec.end());
		long long ans = 0;
		for (int j = 0; j < M; j++) ans += vec[j];
		maxn = max(maxn, ans);
	}
	cout << maxn << endl;
	return 0;
}

Measured memory_bytes: 256
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
remain = [1]*N
for _ in range(M):
    A, B = list(map(int, input().split()))
    if H[A-1]<=H[B-1]:
        remain[A-1] = 0
    if H[B-1]<=H[A-1]:
        remain[B-1] = 0
print(sum(remain))

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

using namespace std;

#define pb push_back
#define fs first
#define sc second
#define sz size
#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define forni(i, n) for (ll i = 2; i <= (ll) (n); ++i)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using ll = long long;
const ll inf = 1e9+7; 

const double PI =  3.141592653589793;

int main(){
	IO;
	double w,h,x,y;
	ll multiple=0;
	cin>>w>>h>>x>>y;
	if(w/2==x && h/2==y)multiple=1;
	printf("%.9f %lld\n",w*h/2.0,multiple);
	return 0;
}

// _   .-')                .-. .-')                 .-')                                               
//( '.( OO )_              \  ( OO )               ( OO ).                                             
// ,--.   ,--.).-'),-----. ,--. ,--.  .-'),-----. (_)---\_) ,--. ,--.     .-----.  ,-.-')  .-'),-----. 
// |   `.'   |( OO'  .-.  '|  .'   / ( OO'  .-.  '/    _ |  |  | |  |    '  .--./  |  |OO)( OO'  .-.  '
// |         |/   |  | |  ||      /, /   |  | |  |\  :` `.  |  | | .-')  |  |('-.  |  |  \/   |  | |  |
// |  |'.'|  |\_) |  |\|  ||     ' _)\_) |  |\|  | '..`''.) |  |_|( OO )/_) |OO  ) |  |(_/\_) |  |\|  |
// |  |   |  |  \ |  | |  ||  .   \    \ |  | |  |.-._)   \ |  | | `-' /||  |`-'| ,|  |_.'  \ |  | |  |
// |  |   |  |   `'  '-'  '|  |\   \    `'  '-'  '\       /('  '-'(_.-'(_'  '--'\(_|  |      `'  '-'  '
// """    """     """""""" """  """"      """""""  """""""  """"""""      """"""   """         """""""

Measured memory_bytes: 256