akhauriyash/Code-Regression huggingface dataset:
#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 pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
int a[3][3],n;
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

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

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







int main() {

   int h,w;
   cin >> h >> w;
   char a[h][w];
   rep (i,h){
     rep (j,w){
      cin >> a[i][j];
     }
   }

  map <int,bool> yoko;
  rep (i,h){
    yoko[i]=true;
    rep (j,w){
      if (a[i][j]=='#'){
        yoko[i]=false;
        break;
      }
    }
  }

  map <int,bool> tate;
  rep (i,w){
    tate[i]=true;
    rep (j,h){
      if (a[j][i]=='#'){
        tate[i]=false;
        break;
      }
    }
  }


  rep (i,h){
    if (yoko[i]) continue;
    rep (j,w){
      if (tate[j]) continue;
      cout << a[i][j];

    }
    cout << endl;
  }
}

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

int main()
{
    long long int n;
    cin>>n;
    long long int sum=0;
    long long int minn=0x3f3f3f3f;
    for(long long int i=0; i<n; i++)
    {
        long long int a,b;
        cin>>a>>b;
        sum+=a;
        if(a>b)
            minn=min(minn,b);
    }
    minn!=0x3f3f3f3f?cout<<sum-minn<<endl:cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int  long long
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define fast  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod 998244353
// order_of_key and *find_by_order
#define N 100001
int power(int x, int y, int p)
{
	int res = 1;
	x = x % p;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % p;
		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}
int ans[200003];
int val[200002][2];
int32_t main() {
	fast;
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt1 = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '1')
			cnt1++;
	}
	if (cnt1 == 0) {
		for (int i = 0; i < n; i++) {
			cout << 1 << "\n";
		}
		return 0;
	}
	else if (cnt1 == 1) {
		for (int i = 0; i < n; i++) {
			if (s[i] == '0') {
				if (i == n - 1) {
					cout << 2 << "\n";
				}
				else {
					cout << 1 << "\n";
				}
			}
			else
				cout << 0 << "\n";
		}
		return 0;
	}
	int a = 0;
	int b = 0;
	for (int i = 0; i < 200002; i++) {
		val[i][0] = power(2, i, cnt1 - 1);
		val[i][1] = power(2, i, cnt1 + 1);
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '1') {
			a += val[n - i - 1][1];
			a %= cnt1 + 1;
			b += val[n - i - 1][0];
			b %= cnt1 - 1;
		}
	}
	for (int i = 0; i < 200002; i++) {
		int u = i;
		int f = 0;
		while (u) {
			u %= __builtin_popcountll(u);
			f++;
		}
		ans[i] = f;
	}

	for (int i = 0; i < n; i++) {
		if (s[i] == '1') {
			int x = b - val[n - i - 1][0];
			x += cnt1 - 1;
			x %= cnt1 - 1;
			cout << ans[x] + 1 << "\n";
		}
		else {
			int x = a + val[n - i - 1][1];
			x %= cnt1 + 1;
			cout << ans[x] + 1 << "\n";
		}
	}

}











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

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

  int ps[] = {a, b, a + b};
  bool ans = any_of(ps, ps + 3, [](int i)->bool { return i % 3 == 0; });
  cout << (ans ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int INF = 1e9;
int main()
{
	int N;
	string S;
	cin >> N >> S;
	int white = 0, black = 0;
	for(char& c : S)
	{
		if(c == '.') white++;
		else black++;
	}
	int leftWhite = 0, rightWhite = white;
	int leftBlack = 0, rightBlack = black;
	int ans = min(white, black);
	for(int inx = 0; inx < N; inx++)
	{
		if(S[inx] == '.')
		{
			leftWhite++;
			rightWhite--;
		}
		else
		{
			leftBlack++;
			rightBlack--;
		}
		ans = min(ans, leftBlack + rightWhite);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
H,W,K=map(int,input().split())

S=[]
for _ in range(H):
    S.append(list(input()))

ans=[[0]*W for i in range(H)]

#からだったら？
count=1
syote_zero=True
temp=[]
for h in range(H):
    index=0
    is_zero=True
    for w in range(W):
        if S[h][w]=="#":
            is_zero=False
            for i in range(index,w+1):
                ans[h][i]=count
            index=w+1
            count+=1
        if is_zero==False and w==W-1:
            for i in range(index,W):
                ans[h][i]=count-1
            
    if is_zero:
        if syote_zero:
            temp.append(h)
        else:
            ans[h]=ans[h-1]
    else:
        if syote_zero and temp:
            num=temp[-1]
            for t in temp:
                ans[t]=ans[num+1]
            syote_zero=False
        else:
            syote_zero=False

for l in ans:
    print(*l)

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

using namespace std;
#define mf 100000000000LL
int n,m,p;
vector<pair<int,int>> rad[3000];
long long dp[3000];
int rcnt[3000],mn;
bool nv[3000];
queue<pair<int,long long>> que;

void dfs(int now,long long sc)
{
    if(dp[now]>=sc||nv[now]) return;
    if(sc>1000000000||++rcnt[now]>mn) {
        nv[now] = true;sc=mf;
    }
    dp[now]=sc;

    for(int i=0;i<rad[now].size();++i){
        que.push(pair<int,long long>(rad[now][i].first,sc+rad[now][i].second-p));
    }
}

int main()
{
    scanf("%d%d%d",&n,&m,&p);mn = max(m,n);
    for(int i=1;i<=n;++i){
        dp[i] = -1000000000;
    }
    int a,b,c;
    for(int i=0;i<m;++i){
        scanf("%d%d%d",&a,&b,&c);
        rad[a].push_back(pair<int,int>(b,c));
    }
    que.push(pair<int,long long>(1,0));
    while(!que.empty()){
        pair<int,long long> now = que.front();que.pop();
        dfs(now.first,now.second);
    }

    if(dp[n]==-1000000000||dp[n]>1000000000) printf("-1\n");
    else printf("%lld\n",max(dp[n],0LL));
    return 0;
}


Measured memory_bytes: 896
import sys

X, N = map(int, input().split())
P = list(map(int, input().split()))
NL = [ i for i in range(0, 102) if i == X or i not in P ]

if len(P) == 0 or X not in P:
    print(X)
    sys.exit()

idx = NL.index(X)
if NL[idx + 1] - X >= X - NL[idx-1]:
    print(NL[idx-1])
else:
    print(NL[idx+1])


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

int main() {
  int s, w; cin >> s >> w;
  string ans = "safe";
  if (s <= w) ans = "unsafe";
  cout << ans << endl;
}

Measured memory_bytes: 3624
N = int(input())
maxv = 0
ans = 1
for i in range(N, 0, -1):
    if i % 2:
        continue
    tmp = 0
    tmpv = i
    while i % 2 == 0:
        tmp += 1
        i = i // 2
    if tmp > maxv:
        maxv = tmp
        ans = tmpv
print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define fi first
#define se second
#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 each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 200005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

ll dup(ll a, ll b) { return (a+b-1)/b;}
ll f(ll a, ll b) {
  if (a < b) swap(a,b);
  ll x = dup(a,b+1);
  return x;
}

ll fl(ll a, ll b, ll c) {
  ll l = 0, r = b+2;
  while (l+1<r) {
    ll x = (l+r)>>1;
    ll ra = a-x*c, rb = b-(x-1);
    bool ok = true;
    if (ra<0 || rb<0) ok = false;
    else if ((ra+1)*c < rb) ok = false;
    if (ok) l = x; else r = x;
  }
  return l;
}
ll fr(ll a, ll b, ll c) {
  ll l = 0, r = a+2;
  while (l+1<r) {
    ll x = (l+r)>>1;
    ll ra = a-x, rb = b-x*c;
    bool ok = true;
    if (ra<0 || rb<0) ok = false;
    if (ok) l = x; else r = x;
  }
  return l;
}

char sol1(ll a, ll b, ll l, ll r, ll c, int i) {
  if (i < l*(c+1)) {
    if (i%(c+1) == c) return 'B';
    return 'A';
  }
  int j = a+b-i-1;
  if (j < r*(c+1)) {
    if (j%(c+1) == c) return 'A';
    return 'B';
  }
  a -= l*c+r;
  b -= l+r*c;
  i -= l*(c+1);
  if (i < a) return 'A';
  return 'B';
}

int main() {
  int q;
  scanf("%d",&q);
  rep(qi,q) {
    ll a,b,s,t;
    scanf("%lld%lld%lld%lld",&a,&b,&s,&t);
    ll c = f(a,b);
    ll l = fl(a,b,c);
    string ans;
    if (1) {
      ll la = a-l*c;
      ll lb = b-l;
      ll r = fr(la,lb,c);
      for (int i = s-1; i < t; ++i) {
        ans += sol1(a,b,l,r,c,i);
      }
    } else {
    }
    cout<<ans<<endl;
  }
  return 0;
}






















Measured memory_bytes: 384
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include "bits/stdc++.h"

#define fastio      ios_base::sync_with_stdio(NULL); cin.tie(NULL); cout.tie(NULL);
#define TC          int t; cin >> t; for(int tc = 1; tc <= t; tc++)
#define read        freopen("input.txt", "r", stdin);
#define write       freopen("output.txt", "w", stdout);
#define nl          '\n'
#define pii		    pair<int, int>
#define ll 		    long long
#define pb		    push_back
#define eb		    emplace_back
#define all(v)	    v.begin(), v.end()
#define rall(v)	    v.rbegin(), v.rend()
#define d(x)	    cerr << #x << " = " << x << nl


using namespace std;

int main() {
	
    #ifndef ONLINE_JUDGE
        // read;
    #endif
    string s; int a; cin >> a >> s;
    for(int i = 0; i < (int) s.size(); i++) printf("%c", (s[i] + a > 90 ? s[i] + a - 26 : s[i] + a));
    cout << nl;
	

	return 0;
}

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

using namespace std;

int main(){
  long long n, m, k, a[200009], b[200009], ca[200009], cb[200009], mx=0;
  cin >> n >> m >> k;
  for(int i=0;i<n;i++)cin >> a[i];
  for(int i=0;i<m;i++)cin >> b[i];
  ca[0]=a[0];
  for(int i=1;i<n;i++){
    ca[i]=a[i]+ca[i-1];
  }
  cb[0]=b[0];
  for(int i=1;i<m;i++){
    cb[i]=b[i]+cb[i-1];
  }
  mx=upper_bound(cb, cb+m, k)-cb;
  for(int i=0;i<n;i++){
    if(ca[i]>k)break;
    long long rest=k-ca[i];
    mx = max(mx, i+1+(long long)(upper_bound(cb,cb+m,rest)-cb));
  }
  cout << mx << endl;
}

Measured memory_bytes: 9880
#include <stdio.h>
int main(){
int d, r, A, B;
double a, b, f;
scanf("%lf %lf",&a, &b);
A=a;
B=b;
d=a/b;
r=A%B;
f=a/b;
printf("%d %d %lf\n",d,r,f);
}

Measured memory_bytes: 1820
x = int(input())
s = 0
r = 0
def recur(i):
    global x
    global s
    global r
    if i < 0:
        if int(s) <= x:
            t = [False, False, False]
            while s > 0:
                c = s%10
                if c == 3:
                    t[0] = True
                if c == 5:
                    t[1] = True
                if c == 7:
                    t[2] = True
                s = s//10
            if t == [True, True, True]:
                r += 1
    else:
        b = s
        s = 10*b + 3
        recur(i-1)
        s = 10*b + 5
        recur(i-1)
        s = 10*b + 7
        recur(i-1)
        s = b

for w in range(12):
  if 10**w > x:
    break
  recur(w)
print(r)

Measured memory_bytes: 3064
#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 all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    int N;
    cin >> N;
    string s = to_string(N);
    int ans = 0;
    rep(i, s.size())
    {
        ans += s[i] - '0';
    }
    if (ans == 1)
    {
        ans = 10;
    }
    cout << ans;
    return 0;
}

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

#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


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

  vector<int> A(N);
  REP(i, N) cin >> A[i];

  sort(ALL(A));

  auto check = [&](int x){
    int ret = 0;
    REP(i, N){
      ret += A.end()-lower_bound(ALL(A), x-A[i]);
    }
    return (ret >= M);
  };

  int ok = -1;
  int ng = 200001;

  while(abs(ok-ng) > 1){
    int mid = (ok+ng)/2;
    (check(mid)? ok: ng) = mid;
  }

  vector<int> sum(N+1);
  REP(i, N) sum[i+1] += sum[i]+A[i];

  int ans = 0;
  int p = 0;
  REP(i, N){
    int it = A.end()-lower_bound(ALL(A), ok-A[i]);
    if(it != 0) ans += A[i]*it+sum[N]-sum[N-it];
    p += it;
  }

  cout << ans-(p-M)*ok << "\n";

  return 0;
}

Measured memory_bytes: 1792
n, k = [ int(v) for v in input().split() ]
num = [ int(v) for v in input().split() ]

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a

g = gcd(num[0], num[0])
for i in num:
    g = gcd(g, i)

print( "POSSIBLE" if k % g == 0 and k <= max(num) else "IMPOSSIBLE" )

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


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()

h = LIST()

dp = [INF] * n
dp[0] = 0

for i in range(n):
    if (i < n - 1):
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    if (i < n - 2):
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))

print(dp[-1])


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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  
  while(x->left != NIL){
    x = x->left;
  }
  return x;
}

Node treeSearch(Node u, int k){
  
  if(u == NIL || k == u->key) return u;
  if(k < u->key) return treeSearch(u->left,k);
  else  return treeSearch(u->right,k);
  
}

Node treeSuccessor(Node x){
  Node y = NIL;
  
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  
  while(y != NIL && x == y->right){
    x =y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);
  
  if(y->left != NIL) x = y->left;
  else x = y->right;
  
  if(x != NIL) x->parent = y->parent;
  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;
  
  if(y != z) z->key = y->key;
  
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    
    if(k < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
  
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  
  if(u ->left != NIL) {
    inorder(u->left);
    printf(" %d",u->key);
  }
  
  else printf(" %d",u->key);
  
  if(u->right != NIL) inorder(u->right);
}

void preorder(Node u){
  printf(" %d",u->key);
  
  if(u->left != NIL) preorder(u->left);
  if(u->right != NIL) preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }
  return 0;
}

Measured memory_bytes: 19364
while True:
    N = int(input())
    if not N: break
    cells = [[int(x) for x in input().split()] for _ in range(N)]
    point = 0
    while True:
        flag = False
        for i, cell in enumerate(cells):
            j = 0
            while j < 5:
                s, color = j, cell[j]
                while j < 5 and cell[j] == color:
                    j += 1
                if color != 0 and j - s >= 3:
                    point += color * (j - s)
                    cell[s:j] = [0] * (j-s)
                    flag = True
        for i in range(5):
            for j in reversed(range(N)):
                s = j
                while s >= 0 and not cells[s][i]:
                    s -= 1
                if s >= 0:
                    cells[j][i], cells[s][i] = cells[s][i], cells[j][i]
        if not flag:
            break
    print(point)

Measured memory_bytes: 6744
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int N;
    cin >> N;
    long int tmp;
    vector<long int> A;
    for (int i = 0; i < N; i++)
    {
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());
    decltype(A)::iterator result = unique(A.begin(), A.end());
    A.erase(result, A.end());
    if (A.size() < N)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
    return 0;
}

Measured memory_bytes: 2420
//Author: Bishal Sarang
#include <bits/stdc++.h>
using namespace std;

//typedefs
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef map<int, int> mii;
typedef priority_queue<pii, vpii, greater<pii> > pq;
typedef tuple<int, int, int> tp;

//Constants
const int INF = (int)2 * 1e9;
const ll MOD = 1000000007;
const long double PI = 3.1415926;
const long double EPS = 1e-6;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what(x) cerr << #x << " => " << x << endl;
#define print_r(x) for(auto i = 0; i < x.size(); i++) what(x[i]);
#define print_grid(x) for(auto i = 0; i < x.size(); i++){for(auto j = 0; j < x[0].size(); j++){cout << x[i][j];}cout << endl;}
#define gridM(type, n, m) vector<vector<type>> grid(n, vector<type>(m))

template <typename T>vector<T> prefix_sum(vector<T> nums){vector<T> pre_sum(nums.size());partial_sum(nums.begin(), nums.end(), pre_sum.begin());return pre_sum;}
vector<string> split(string s, char sep){int prev_index = 0;int i = 0;vector<string> words;for(i = 0; i < s.size(); i++){if(s[i] == sep){words.push_back(s.substr(prev_index, i - prev_index));prev_index = i + 1;}}words.push_back(s.substr(prev_index, (s.size() - prev_index )));return words;}

void read(){
  //stime = clock();
  #ifdef DEBUG
    freopen("in.txt", "r", stdin);
   #endif // DEBUG
   cin.sync_with_stdio(false);
   cin.tie(0);
}

int main(){
 read();
 char c; cin >> c;
 cout << char(c + 1);
 return 0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
V=list(map(int,input().split()))
total = 0
if N<=K:
  for i in range(N):
    if V[i] > 0:
      total += V[i]
  print(total)
else:
  max = 0
  for L in range(K+1):
    for R in range(K-L+1):
#      print(L,R)
      p = K-L-R
      V0 = []
      if L>0:
        V0 = V0 + V[0:L]
#        print(V[0:L])
      if R>0:
        V0 = V0 + V[N-R:N]
#        print(V[N-R:N])
      V0.sort()
#      print(V0)
      for ii in range(len(V0)):
        if p <= 0:
            break
        if V0[ii] < 0:
          V0[ii] = 0
          p -= 1
        else:
          break
#      print(V0)
      su = sum(V0)
#      print(su)
      if max < su:
        max = su
  print(max)  
          


Measured memory_bytes: 3064
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <map>
#include <list>
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
using namespace std;
typedef pair<int,int> P;
#define N 200000
int main(void){
    bool from_one[N+5]={};
    bool to_last[N+5]={};
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        if(a==1)from_one[b]=true;
        if(b==n)to_last[a]=true;
    }
    for(int i=1;i<=n;i++){
        if(from_one[i]&&to_last[i]){
            printf("POSSIBLE\n");
            return 0;
        }
    }
    printf("IMPOSSIBLE\n");
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
//macros
using namespace std;
typedef long long ll;
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
const long long int mod = 1e9 + 7;
int main()
{
    int a,b,c,k,sum=0;
    cin >> a >> b >> c >> k;
    sum = a+b+c;
    int ma = max(a,b);
    ma = max(ma,c);
    ma = ma*pow(2,k) - ma;
    sum += ma;
    cout << sum << endl;

}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(){

  int n,s1=1145141919,s2,result=-1145141919;

  cin>>n>>s2;
  for(int i=1;i<n;i++){
    s1=min(s1,s2);
    cin>>s2;
    result=max(result,s2-s1);
  }
   
  cout<<result<<endl;

  return 0; 

}



Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 10, MAXN = 2e5 + 10, z = 2e3 + 1, mod = 1e9 + 7;
int fc[MAXN], ifc[MAXN], x[MAXN], y[MAXN], dp[N][N], ans, n;
int power(int a, int b) {
	if (!b)
		return 1;
	int rtr = power(a, b / 2);
	if (b % 2)
		return 1ll * rtr * rtr % mod * a % mod;
	return 1ll * rtr * rtr % mod;
}
void getFc() {
	fc[0] = ifc[0] = 1;
	for (int i = 1; i < MAXN - 5; i++) {
		fc[i] = 1ll * fc[i - 1] * i % mod;
		ifc[i] = 1ll * ifc[i - 1] * power(i, mod - 2) % mod;
	}
	return;
}
int ch(int x, int y) {
	if (x > y)
		return 0;
	return 1ll * fc[y] * ifc[x] % mod * ifc[y - x] % mod;
}
int main() {
	getFc();
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> x[i] >> y[i], dp[z - x[i]][z - y[i]]++;
	for (int i = 1; i < N - 2; i++)
		for (int j = 1; j < N - 2; j++) 
			dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % mod;
	for (int i = 0; i < n; i++)
		ans = (ans + dp[z + x[i]][z + y[i]] - ch(2 * x[i], 2 * (x[i] + y[i]))) % mod;
	ans = 1ll * (1ll * ans * power(2, mod - 2)) % mod;
	cout << (ans + mod) % mod;
	return 0;
}


Measured memory_bytes: 66304
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
        long[] a = la(in.readLine(), 2);
        long N=a[0], X=a[1];
        long sum=N;
        int flag=0;
        N=N-X;
        while (flag==0) {
            long k=N/X;
            if (N%X==0) {
                sum+=((2*k-1)*X);
                flag=1;
            }
            else {
                sum+=(2*k*X);
                long temp=X;
                X = N%X;
                N=temp;
            }
        }
        out.write(sum+"\n");
        out.flush();
    }
    
    private static int ip (String s) {
        int n = Integer.parseInt(s);
        return n;
    }
    
    private static long lp (String s) {
        long n = Long.parseLong(s);
        return n;
    }
    
    private static double dp (String s) {
        double n = Double.parseDouble(s);
        return n;
    }
    
    private static int[] ia (String s, int n) {
        String[] s1 = s.split(" ");
        int[] A = new int[n];
        for (int i=0; i<n; i++) {
            A[i] = Integer.parseInt(s1[i]);
        }
        return A;
    }
    
    private static long[] la (String s, int n) {
        String[] s1 = s.split(" ");
        long[] A = new long[n];
        for (int i=0; i<n; i++) {
            A[i] = Long.parseLong(s1[i]);
        }
        return A;
    }
    
    private static double[] da (String s, int n) {
        String[] s1 = s.split(" ");
        double[] A = new double[n];
        for (int i=0; i<n; i++) {
            A[i] = Double.parseDouble(s1[i]);
        }
        return A;
    }

}

Measured memory_bytes: 8148
import math

a, b, h, m = input().split()

a = int(a)
b = int(b)
h = int(h)
m = int(m)

kakudo_a = h * 30 + m * 0.5
kakudo_b = m * 6
kakudo = abs(kakudo_a - kakudo_b)

print('{:.20f}'.format(math.sqrt(a * a + b * b - (2 * a * b * math.cos(math.radians(kakudo))))))


Measured memory_bytes: 62520
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt(), M = s.nextInt(), C = s.nextInt(), m = 0, n = 0;
		int[] B = new int [M], A = new int [M];
		for (int i = 0; i < M; i++) B[i] = s.nextInt();
		for (int j = 0; j < N; j++){
			m = 0;
			for (int k = 0; k < M; k++){
				A[k] = s.nextInt();
				m += A[k] * B[k];
			}
			if (m + C > 0) n++;
		}
		System.out.println(n);
	}
}


Measured memory_bytes: 22356
n,s=`dd`.split
n=n.to_i
f=->c{ a=0; [0]+s.chars.map{|x|a+=x==c ? 1 : 0} }
w=f[?W]
e=f[?E]
puts (1..n).map{|i|w[i-1]+(e[n]-e[i])}.min

Measured memory_bytes: 44764
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    ll ret = 0;
    vector<bool> lose(n, false);
    for (int i = 0; i < n; ++i) {
        if (i - k >= 0 && t[i] == t[i - k] && !lose[i - k]) {
            lose[i] = true;
            continue;
        }
        if (t[i] == 'r') {
            ret += p;
        } else if (t[i] == 's') {
            ret += r;
        } else if (t[i] == 'p') {
            ret += s;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 512
using System;
using System.Linq;

namespace ExaWizB {
    class Program {
        static void Main(string[] args) {
            var n = int.Parse(Console.ReadLine());
            var s = Console.ReadLine();
            var red = s.Count(c => c == 'R');
            var blue = n - red;
            Console.WriteLine(red > blue ? "Yes" : "No");
        }
    }
}

Measured memory_bytes: 11220
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0 ; i < n ; i++) {
            a[i] = sc.nextInt();
        }
        int sum = 0;
        for (int i = 0 ; i < n ; i++) {
            sum += (d + a[i] - 1) / a[i];
        }
        sum += x;
        System.out.println(sum);
    }

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
long long a[100001],c,n,z,x,mini=999999999999;
long long s;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        if(a[i]<0)s++;
        mini=min(mini,abs(a[i]));
    }
    if(s%2!=0)
    {
        x=0;
        for(int i=1; i<=n; i++)
            x+=abs(a[i]);
        cout<<x-(2*mini)<<endl;
    }
    else
    {
        x=0;
        for(int i=1; i<=n; i++)x+=abs(a[i]);
        cout<<x<<endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(0);

	int n, q;
	cin >> n >> q;
    vector<vector<int>> tr(n+1); 
    for(int i=1; i<n; ++i){
        int a, b;
        cin >> a >> b;
        tr[a].push_back(b);
        tr[b].push_back(a);
    }
    vector<int> v(n+1,0);
    for(int i=0; i<q; ++i){
        int p, x;
        cin >> p >> x;
        v[p] += x;
    }

    stack<int> s; s.push(1);
    vector<int> flg(n+1,1); flg[1]=0;
    while(!s.empty()){
        int z=s.top();
        s.pop();
        flg[z]=0;
        for(int i : tr[z]){
            if(flg[i]){
                v[i] += v[z];
                s.push(i);
                flg[i]=0;
            }
        }
    }

	for(int i=1; i<=n; ++i) cout << v[i] << " ";
    cout << endl;
}

Measured memory_bytes: 16372
#include <cstdio>

int main()
{
  long long x;
  scanf("%lld", &x);
  long long p = 0;
  long long i;
  for (i = 1; true; ++i)
  {
    p += i;
    if (p >= x) break;
  }
  printf("%lld\n", i);
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline
from operator import itemgetter

def main():
    N = int(input())
    arm = []
    for _ in range(N):
        x,l = map(int,input().split())
        arm.append((x-l,x+l))
    
    count = 0
    arm.sort(key=itemgetter(1))
    
    right = -10**10
    for l,r in arm:
        if right <= l:
            right = r
            count += 1
    
    print(count)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 18248
//
// Created by hide on 2020/05/15.
//

//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード(アルファベット順,bits/stdc++.hは使わない派閥)
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
//#define S second //pairの二つ目の要素
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)


int main() {
    double A,B,H,M;
    cin >> A >> B >> H >> M;
    double min_deg = 360 * M/60.0f;
//    double hour_deg = 360 * H/12.0f + 5.0*M/60.0f;
    double hour_deg = 360 * H/12.0f + 30.0*M/60.0f;
    double B_x = B*sin(deg_to_rad(min_deg));
    double B_y = B*cos(deg_to_rad(min_deg));
    double A_x = A*sin(deg_to_rad(hour_deg));
    double A_y = A*cos(deg_to_rad(hour_deg));

    cout <<  std::setprecision(20)<< sqrt(pow(A_x-B_x,2.0) + pow(A_y-B_y,2.0));

//    double deg = abs(a-b);
//    cout << a << " " << b << " " << deg << endl;
//    deg = std::max(deg, 360-deg);
//    deg = deg_to_rad(deg);
//    double length = sqrt(A*A+B*B-2*A*B*cos(deg));
//    cout  << length << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair <ll,ll> P;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n-1; i > 0; i--)
#define FOR(i, n, m) for(int i = n; i < (int)(m); i++)
#define PRINT(x) cout << x << endl
#define ALL(v) v.begin(), v.end()
#define INF (ll)1e18
#define PI 3.14159265358979

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

ll MOD = 1000000007;

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

    vector<ll> T(N);
    REP(i, N) cin >> T[i];

    vector<ll> A(N);
    REP(i, N) cin >> A[i];

    if (!(T.front() <= A.front()) || !(T.back() >= A.back())) {
        PRINT(0);
        return 0;
    }

    vector<ll> v(N);
    v[0] = T.front();
    v.back() = A.back();
    REP(i, N-1) {
        if (T[i] < T[i+1]) {
            if(T[i+1] > A[i+1]) {
                PRINT(0);
                return 0;
            }
            v[i+1] = T[i+1];
        }
        if (A[i] > A[i+1]) {
            if (A[i] > T[i]) {
                PRINT(0);
                return 0;
            }
            v[i] = A[i];
        }
    }
    ll ans = 1;
    REP(i, N) {
        if (v[i] == 0) {
            ans *= min(T[i], A[i]);
            ans %= MOD;
        }
    }
    PRINT(ans);
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(int i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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 dx[4]={0,1,0,-1},dy[4]={-1,0,1,0};
int ddx[6]={0,1,0,-1,1,-1},ddy[6]={-1,0,1,0,1,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int obs[200][200];
int sy,sx;
int t,n;
int mas[200][200];



int main(){
	while(1){
		cin>>t>>n;
		if(t==0&&n==0)break;
		REP(i,200)
			REP(j,200){
			obs[i][j]=0;
			mas[i][j]=-1;
			}
		REP(i,n){
			int a,b;
			cin>>a>>b;
			obs[b+100][a+100]=1;
		}
		cin>>sx>>sy;
		sy+=100,sx+=100;
		int ans=0;
		queue<Pi> q;
		q.push(Pi(sy,sx));
		mas[sy][sx]=0;
		while(q.size()){
			Pi tp=q.front();q.pop();
			ans++;
			if(mas[tp.first][tp.second]==t)continue;
			for(int i=0;i<6;i++){
				int ny=tp.first+ddy[i];
				int nx=tp.second+ddx[i];
				if(mas[ny][nx]==-1&&obs[ny][nx]==0){
					q.push(Pi(ny,nx));
					mas[ny][nx]=mas[tp.first][tp.second]+1;
				}
			}
		}
		
		
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3480
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

int main() {
    int n, k;
    cin >> n >> k;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    i64 ans = 2e9;
    for (int i = 0; i < n - k + 1; i++) {
        ans = min(ans, as[i + k - 1] - as[i]);
    }
    cout << ans << endl;

}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

class edge{
public:
  int to, w;
  bool used;
  edge(int to, int w): to(to), w(w), used(false){};

  void print(){
    cout << " to: "  << to << " w: " << w << endl;
  }
};

class node{
public:
  int num;
  vector<edge> edges;
  node(int num): num(num){}
  node(){
    num = -1;
  }

  void print(){
    cout << "num: " << num << endl;
    for(int i=0; i<edges.size(); i++){
      edges[i].print();
    }
  }
};

class graph{
public:
  int num;
  static int nums;
  vector<node> nodes;
  graph(int num): num(num){
    for(int i=1; i<=num; i++){
      nodes.push_back(node(++nums));
    }
  }

  void print(){
    for(int i=1; i<=num; i++){
      nodes[i].print();
    }
  }

  int solve(){
    for(int i=1; i<=num; i++){
      dijkstra(i);
    }

    int ans=0;
    for(int i=1; i<=num; i++){
      node now = nodes[i];
      for(int j=0; j<now.edges.size(); j++){
        if(!now.edges[j].used) {
          ans++;
        }
      }
    }

    return ans/2;
  }

  void dijkstra(int s){
    typedef pair<int, int> P;
    const int inf = 1e7;

    int prev[num+1];
    int dis[num+1];
    for(int i=1; i<=num; i++){
      prev[i] = -1;
      dis[i] = inf;
    }

    priority_queue<P, vector<P>, greater<P> > pq;
    pq.push(P(0, s));
    dis[s] = 0;

    while(!pq.empty()){
      P now = pq.top(); pq.pop();
      int n = now.second, d = now.first;
      if(dis[n] < d) continue;

      for(int i=0; i<nodes[n].edges.size(); i++){
        int newd = dis[n]+nodes[n].edges[i].w,
          next = nodes[n].edges[i].to;
        if(newd < dis[next]){
          pq.push(P(newd, next));
          dis[next] = newd;
          prev[next] = n;
        }
      }
    }

    for(int i=1; i<=num; i++){
      int to = i, from = prev[i];
      while(from != -1){
        for(int j=0; j<nodes[from].edges.size(); j++){
          if(nodes[from].edges[j].to == to){
            nodes[from].edges[j].used = true;
          }
        }
        for(int j=0; j<nodes[to].edges.size(); j++){
          if(nodes[to].edges[j].to == from) {
            nodes[to].edges[j].used = true;
          }
        }
        to = from; from = prev[from];
      }
    }
  }
};

int graph::nums = 0;

int main(){
  int n, m; cin >> n >> m;
  graph g(n);

  for(int i=0; i<m; i++){
    int a, b, c; cin >> a >> b >> c;
    g.nodes[a].num = a;
    g.nodes[a].edges.push_back(edge(b, c));
    g.nodes[b].num = b;
    g.nodes[b].edges.push_back(edge(a, c));
  }

  //g.print();

  cout << g.solve() << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
m = 1000
stocks = 0
drops = [False]*(n-1)
for i in range(n-1):
    if a[i] > a[i+1]:
        drops[i] = True
for i in range(n-1):
    if drops[i]:
        m+=stocks*a[i]
        stocks = 0
    else:
        stocks+=m//a[i]
        m -= (m//a[i])*a[i]
print(m + stocks*a[-1])

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<v.size()-1) cout<<sep;} cout<<endl

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int k;
    string s;
    cin>>k;
    cin>>s;

    string ans="";
    if(s.size()<=k) ans = s;
    else{
        ans = s.substr(0,k) + "...";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace _20170409_AOJ
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] iArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            int r = iArr[0];
            int c = iArr[1];

            int[,] rcArr = new int[r + 1, c + 1];
            for (int i = 0; i < r; i++)
            {
                int[] rArr = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
                for (int j = 0; j < c; j++)
                {
                    rcArr[i, j] = rArr[j];
                    rcArr[r, j] += rArr[j];
                }
                rcArr[i, c] = rArr.Sum();
                rcArr[r, c] += rcArr[i, c];
            }

            for (int i = 0; i < r + 1; i++)
            {
                for (int j = 0; j < c; j++)
                {
                    Console.Write("{0} ", rcArr[i, j]);
                }
                Console.WriteLine(rcArr[i, c]);
            }

            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 9844
#include <cstdio>

int solve(int n, int x);
int main() {
    while(1) {
        int n, x;
        scanf("%d %d", &n, &x);
        if (n == 0 && x == 0) break;
        printf("%d\n", solve(n, x));
    }
    return 0;
}

int solve(int n, int x) {
    int count = 0;
    for (int i=1; i<n-1; i++) {
        for (int j=i+1; j<n; j++) {
            int c = x - (i + j);
            if (j < c && c <= n) count++;
        }
    }
    return count;
}

Measured memory_bytes: 1028
main () {
    int x, y;
    scanf("%d %d", &x, &y);
    while (x != 0 || y != 0) {
        if (x <= y) printf("%d %d\n", x, y);
        else printf("%d %d\n", y, x);
        scanf("%d %d", &x, &y);
    }
}


Measured memory_bytes: 2112
#include <iostream>

using namespace std;

int main()
{
    int K, S;
    cin >> K >> S;

    int count = 0;
    for (int i = 0; i <= K; i++) {
        for (int j = 0; j <= K; j++) {
            if ((0 <= S - (i + j)) && (S - (i + j) <= K)) {
                count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}

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

#define RATE 380000.0

using namespace std;

int main() {
	double sum = 0.0, num;
	int N;
	string str;

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> num >> str;
		if (str == "JPY") sum += num;
		else sum += num * RATE;
	}

	cout <<  setprecision(15)<<sum << endl;

	return 0;
}

Measured memory_bytes: 256
def main():
    A,B,C,K=[int(x) for x in input().split()]
    if abs(A-B)>10**18:
        print("Unfair")
    else:
        if K%2==0:
            print(A-B)
        else:
            print(B-A)

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
using System;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] AB = ToIntArray(Console.ReadLine().Split(' '));

            Console.WriteLine(AB[0] * AB[1]);
        }
    }
    //2回位使ったら追加する
    class MyLibrary
    {
        public static int[] ToIntArray(string[] stringArray)
        {
            int length = stringArray.Length;
            int[] intArray = new int[length];
            for (int i = 0; i < length; i++)
            {
                intArray[i] = int.Parse(stringArray[i]);
            }
            return intArray;
        }
    }
}

Measured memory_bytes: 27528
import re

if __name__ == '__main__':
	N = int(input())
	S = input()
	res = [0 for _ in range(N)]

	for i in range(N):
		a = S[:i]
		b = S[i:]
		count = set()

		for j in range(len(a)):
			for k in range(len(b)):
				if a[j] == b[k]:
					count.add(str(a[j]))
					break

		res[i] = len(count)

	print(max(res))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rrep(i,n) for(int i=(int)n-1;i>=0;--i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T& a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U& u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U& u,const V... v){for(auto& e:u)fill_v<T>(e,v...);}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    map<int, P> mp;
    rep(i, n) {
        if (i % 2 == 0) mp[b[i]].first++;
        else mp[b[i]].second++;
    }
    int cnt = 0;
    rep(i, n) {
        if (i % 2 == 0) {
            if (mp[a[i]].first == 0) {
                cnt++;
            } else {
                mp[a[i]].first--;
            }
        } else {
            if (mp[a[i]].second == 0) {
                cnt++;
            } else {
                mp[a[i]].second--;
            }
        }
    }
    cout << cnt/2 << endl;
}


Measured memory_bytes: 10312