akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <queue>
#include <iomanip>
using namespace std;

int seat[17], countdown[17];
int arrival[100], sit[100];

int main() {
    memset(seat, -1, sizeof seat);
    memset(countdown, 0, sizeof countdown);
    queue<int> q;
    for (int m=0; m<1000; ++m) {
        if (m%5 == 0 && m/5 < 100) {
            q.push(m/5);
            arrival[m/5] = m;
        }
        for (int i=0; i<17; ++i) {
            if (countdown[i]) {
                --countdown[i];
                if (countdown[i] == 0) {
                    seat[i] = -1;
                }
            }
        }
        while ( ! q.empty()) {
            bool change = false;
            int num = (q.front()%5 == 1 ? 5 : 2);
            int time = 17*(q.front()%2) + 3*(q.front()%3) + 19;
            for (int i=0; i+num-1<17; ++i) {
                bool ok = true;
                for (int j=i; j<=i+num-1; ++j) {
                    if (0 <= seat[j]) ok = false;
                }
                if (ok) {
                    change = true;
                    for (int j=i; j<=i+num-1; ++j) {
                        seat[j] = q.front();
                        countdown[j] = time;
                    }
                    sit[q.front()] = m;
                    q.pop();
                    break;
                }
            }
            if ( ! change) break;
        }
    }
    int n;
    while (cin >> n) {
        cout << sit[n] - arrival[n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1200
#include<iostream>
using namespace std;
int maxx=0,minn=1000000000,n;
int main()
{
	cin>>n;
	long long int a,b=-10000000000;
	cin>>a;
	minn=a;
	for(int  i=2;i<=n;i++)
	{
		cin>>a;
		
		if(b<a-minn)
		b=a-minn;
		if(a<minn)
		minn=a;
		
	}
	cout<<b<<endl;
	return 0;
}


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

int main(){
  int m, f, b;
  cin >> m >> f >> b;
  if (m >= b)
    cout << 0 << endl;
  else if (m+f >= b)
    cout << b-m << endl;
  else
    cout << "NA" << endl;
  return 0;
}

Measured memory_bytes: 3088
n, m = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0 
ans = 'No'
total = sum(a)
for i in a:
  if i - total*1/(4*m) >= 0:
    cnt += 1
  if cnt == m:
    ans = 'Yes'
    break
print(ans)

Measured memory_bytes: 3060
N,K=map(int,raw_input().split())
hlist=[]

for i in range(N):
	hlist.append(int(raw_input()))

hlist.sort()

i=0
j=K-1

minn=100000000000
for i in range(N-K+1):
	diff=hlist[i+K-1]-hlist[i]
	if diff<minn:
		minn=diff

print(minn)



Measured memory_bytes: 8964
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    string S; cin >> S;
    int ans1=0;
    int ans2=0;
    for(int i=0;i<S.size();i++){
        int s = S[i]-'0';
        if(i%2==0) {ans1 += abs(1-s); ans2 += abs(0-s);}
        else {ans1 += abs(0-s); ans2 += abs(1-s);}
    }
    if(ans1<ans2) cout << ans1 << endl;
    else cout << ans2 << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
struct P {
	bool st, en;
	int si;
};
P a[100000];
bool b[100000];
int main() {
	int n, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		if (c == 0) b[i] = false;
		else b[i] = true;
	}
	int f = 0,sum=0;
	for (int i = 0; i < n;) {
		int j = i;
		bool l = b[i];
		while (b[j] == l&&j<n) {
			j++;
			l = !l;
		}
		a[f] = P{ b[i],!l,j - i };
		sum = max(sum, j - i);
		i = j;
		f++;
	}
	for (int i = 0; i < f; i++) {
		if (i == 0 && i != f - 1) {
			sum = max(sum, a[i].si + a[i + 1].si);
		}
		else if (i == f - 1) {
			sum = max(sum, a[i].si + a[i - 1].si);
		}
		else {
			sum = max(sum, a[i].si + a[i - 1].si + a[i + 1].si);
		}
	}
	cout << sum << endl;
}

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

using namespace std;
using ll = long long;

class UnionFindTree{
private:
  // indexの数の親ノード(ある集合の親を見つけたいときはここを直接参照せず、findを使う)
  vector<int> par;
  // indexを根とする木のランク
  vector<int> rank;
  // 集合のサイズ
  vector<int> cnts;
  // 木の最大値
  int treeSize;
public:
  UnionFindTree(int initTreeSize = 1000){
    // 引数で与えられた値を最大格納数とするUnionFindTreeの作成
    treeSize = initTreeSize;
    init(initTreeSize);
  }
  void init(int sz){
    par.clear(),rank.clear(),cnts.clear();
    treeSize=sz;
    for(int i = 0; i < sz; i++){
      par.push_back(i);
      rank.push_back(0);
      cnts.push_back(1);
    }
  }
  // 与えられた数が格納されている木のルートを探索
  int find(int x){  
    if(par[x] == x)return x;
    else return par[x] = find(par[x]);
  }
  // 和集合をとる。ただしここでは各集合の親の付け替えは起こらない
  void unite(int x,int y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(rank[x] < rank[y]){
      par[x] = y;
      cnts[y]+=cnts[x];
    }
    else{
      par[y] = x;
      cnts[x]+=cnts[y];
      if(rank[y] == rank[x])rank[x]++;
    }
  }
  // xの属する集合のサイズ
  int getCnt(int x){
    return cnts[find(x)];
  }
  bool same(int x,int y){
    return find(x) == find(y);
  }
    
};


ll N, M;
int A[100010];
int B[100010];
UnionFindTree uft(100010);

int main(){

    cin >> N >> M;
    for(int i = 0; i < M; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
    }
    ll tot = 0;
    vector<ll> ans;
    for(int i = M - 1; i >= 0; i--){
        int a = A[i];
        int b = B[i];
        ans.push_back(N * (N - 1) / 2 - tot);
        if(!uft.same(a, b)){
            ll acnt = uft.getCnt(a);
            ll bcnt = uft.getCnt(b);
            uft.unite(a, b);
            tot += acnt * bcnt;
        }
    }
    reverse(ans.begin(), ans.end());
    for(ll a : ans){
        cout << a << endl;
    }


    return 0;
}


Measured memory_bytes: 4200
#include <iostream>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for(int (i) = (0); (i) < (n); (i)++)
//#define int long long
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>

using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  if(n == m)cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) (a*a)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

LL a[100000];
int main() {

	int n;
	scanf("%d", &n);
	REP(i, n)scanf("%lld", &a[i]);
	reverse(a, a + n);
	LL ma = 2, mi = 2;
	REP(i, n) {
		ma = (ma / a[i]) * a[i] + a[i] - 1;
		mi = ((mi - 1) / a[i] + 1)*a[i];
		if (ma < mi) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << mi << " " << ma << endl;
	return 0;
}

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

int main() {
	
	int a, b, k;
	cin >> a >> b >> k;
	if(a < b) swap(a, b);
	
	int cnt = 0;
	int i;
	for(i = a; i >= 1; i--){
		if(a % i == 0 && b % i == 0){
			cnt++;
		}
		if(cnt == k){
			break;
		}
	}
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	for i := len(s); i >= len(t); i-- {
		found := true
		for j := range t {
			if v := s[i-len(t)+j]; v != t[j] && v != '?' {
				found = false
				break
			}
		}
		if found {
			fmt.Println(strings.Replace(s[:i-len(t)]+t+s[i:], "?", "a", -1))
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}


Measured memory_bytes: 640
#include <iostream>

void funcB() {
  int n, m, sum = 0, temp;
  std::cin >> n >> m;
  for (int i = 0; i < m; i++) {
    std::cin >> temp;
    sum += temp;
  }
  temp = n - sum;
  std::cout << (temp < 0 ? -1 : temp);
}

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

Measured memory_bytes: 3624
#include <iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#define pb              push_back
#define pi              acos(-1.0)
#define loop(i,a,n)     for(int i=a;i<n;i++)
#define rloop(i,n,a)    for(int i=n;i>=a;i--)
#define ll              long long int
#define ff              first
#define ss              second
#define pii             pair<ll,ll>
#define sc1(a)          scanf("%d",&a)
#define sc2(a,b)        scanf("%d %d",&a,&b)
#define sc3(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define all(v)          v.begin(),v.end()
#define ms(a,b)         memset(a,b,sizeof a)
#define FastIO          ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define fileout         freopen("output.txt","w",stdout)
#define filein          freopen("input.txt","r",stdin)
#define inf             2e9+5
#define Q               int q;cin>>q;while(q--)
#define check           cout<<"HI"<<endl;

//int x[]= {-1,0,0,1};
//int y[]= {0,-1,1,0};

using namespace std;

int main()
{
    int n,k;
    ll ans=0;
    cin >> n >> k;
    int a[n+5];
    loop(i,0,n)cin >> (a[i]);
    sort(a,a+n);
    loop(i,0,k)ans+=a[i];
    cout<<ans<<endl;

}












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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    int ans = 0;
    for(int i=1; i<N; i++) if(A[i-1] < A[i]) ans++;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3108
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

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


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	ll n,ans=1,t;
	std::cin >> n;
	rep(i, 0, n) {
		std::cin >> t;
		ans = lcm(ans, t);
	}

	outn(ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>

using namespace std;

int main() {
    long long H, W;
    cin >> H >> W;

    long long ans = 0;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    }
    else {
    ans = (H * W + 1) / 2;
    cout << ans << endl;
    }
   // printf("%lld", ans);
}


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

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

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 11


int main()
{
    while(true){
        int n,x; cin >> n >> x;
        if(n == 0 && x == 0) break;
        int ans = 0;
        for(int i = 1; i <= n; i++){
            for(int j = i+1; j <= n; j++){
                int k = x - i - j;
                if(k <= n && k > j) ans++;
            }
        }
        cout << ans << endl;
    }
}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  ll ans = 1;
  rep(i, N) ans = min(2*ans, ans + K);

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



char buf[20];

int main(){

	scanf("%s",buf);

	for(int i = 0; buf[i] != '\0'; i++){
		if(buf[i] == ','){

			buf[i] = ' ';
		}
	}

	printf("%s\n",buf);

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main() {
  int k,a,b;
  cin>>k;
  cin>>a>>b;
  if(k >= a && k <=b) {
    cout<<"OK";
    return 0;
  } else {
    int i=2;
    while(k*i <= b){
      if(k*i >= a && k*i <=b){
        cout<<"OK";
        return 0;
      }
      i++;
    }
  }
  cout<<"NG";
  return 0;
}


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

#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--)
#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)) //最小値を求める

int main(){
    int L,R,D;
    cin >> L >> R >> D;
    int count = 0;
    FOR(i,L,R){
        if(i%D == 0) count++;
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;

int main(){
  string s;
  int u=0;
  cin >> s;
  for(int i=0;i<3;i++){
    if(s[i]==s[i+1]&&u==0){
      cout << "Bad" << endl;
      u=1;
    }
  }
  if(u==0) cout <<  "Good" << endl; 
}

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

#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::ios;
using std::string;

namespace AOJ {
    struct Node {
        Node *next, *prev;
        int key;
        Node() : next{nullptr}, prev{nullptr}, key{-1} {}
    }; // namespace AOJ

    class DoublyLinkedList {
      private:
        Node *head, *tail;

      public:
        DoublyLinkedList();

        void insert(int key);
        Node *find(int key);
        void deleteKey(int key);
        void deleteNode(Node *found);
        void deleteFirst();
        void deleteLast();
        void trace();
    };
} // namespace AOJ

AOJ::DoublyLinkedList::DoublyLinkedList() : head{new Node}, tail{new Node} {
    head->next = tail;
    tail->prev = head;
}

void AOJ::DoublyLinkedList::insert(int key) {
    Node *newNode = new Node;
    newNode->key = key;

    newNode->next = head->next;
    head->next->prev = newNode;
    head->next = newNode;
    newNode->prev = head;
}

AOJ::Node *AOJ::DoublyLinkedList::find(int key) {
    Node *node = head->next;
    while (node != tail && node->key != key) {
        node = node->next;
    }
    return node;
}

void AOJ::DoublyLinkedList::deleteKey(int key) {
    deleteNode(find(key));
}

void AOJ::DoublyLinkedList::deleteNode(Node *found) {
    if (found != tail) {
        found->prev->next = found->next;
        found->next->prev = found->prev;
        delete found;
    }
    return;
}
void AOJ::DoublyLinkedList::deleteFirst() {
    deleteNode(head->next);
}

void AOJ::DoublyLinkedList::deleteLast() {
    deleteNode(tail->prev);
}

void AOJ::DoublyLinkedList::trace() {
    Node *node = head->next;
    while (true) {
        if (node->next == nullptr)
            break;
        else if (node != head->next)
            cout << " ";
        cout << node->key;
        node = node->next;
    }
    cout << endl;
}

int main() {
    fastIO;
    AOJ::DoublyLinkedList *dll = new AOJ::DoublyLinkedList();

    int n;
    cin >> n;

    while (n--) {
        string command;
        int key;

        cin >> command;

        if (command == "insert") {
            cin >> key;
            dll->insert(key);
        } else if (command == "delete") {
            cin >> key;
            dll->deleteKey(key);
        } else if (command == "deleteFirst") {
            dll->deleteFirst();
        } else if (command == "deleteLast") {
            dll->deleteLast();
        }
    }
    dll->trace();
}


Measured memory_bytes: 34268
import sys
ls = [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]
k = int(input())
print(ls[k-1])

Measured memory_bytes: 3060
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


n = ip()                                     #入力整数1つ
#p,q,r= (int(i) for i in input().split())       #入力整数横2つ以上
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#a.pop(0)は10^5あるときTLEしやすい!注意!抜くなら逆ソート!
#これを消すとなぜかWAになる呪い
l = 0
r = sum(a)
s = rem
for i in range(n):
    l+=a[i]
    r-=a[i]
    s = min(s,abs(r-l))
print(s)

Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    int cntr = 0, cntw = 0;
    rep(i,s.size()){
        if(s[i] == 'R') cntr++;
        else cntw++;
    }
    int ans1 = 0;
    rep(i,cntr){
        if(s[i] == 'W') ans1++;
    }
    cout << min(ans1, cntw) << endl;
    return 0;
}

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

#define M 10000
#define F 5000
#define S 1000

int failed() {
  	cout << "-1 -1 -1" << endl; 
  	return 0;
}

int main() {
    int n, amount, TOTAL, NUM;
    scanf("%d %d", &n, &amount);
  	TOTAL = amount;
  	NUM = n;
	if ((amount > M * n) || (amount < S * n)) {
    	return failed();
    }
	int cs = amount / S;
  	if (cs == n) {
     	cout << "0 0 " << cs << endl;
      	return 0;
    }
  	int total, sub;
  	for(int i = 0; i <= cs / 5; i++) {
    	for(int j = 0; j <= cs / 10; j++) {
          	sub = cs - i * 5 - j * 10;
          	if (sub < 0) continue;
        	total = M * j + F * i + S * sub;
          	if (total == amount && (i + j + sub) == n) {
            	cout << j << " " << i << " " << sub << endl;
              	return 0;
            }
        }
    }
  	  	
	return failed(); 
}

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

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

using namespace std;

struct Point
{
	double x, y;

	Point() : x(0), y(0)
	{
		return;
	}

	Point(double x,double y) : x(x), y(y)
	{
		return;
	}

	Point operator - (const Point &a) const
	{
		return Point(x - a.x,y - a.y);
	}

	bool operator < (const Point &a) const
	{
		return x == a.x ? y < a.y : x < a.x;
	}

	void input()
	{
		char c;
		cin >> x >> c >> y;
	}

	double det(const Point &a)
	{
		return x * a.y - y * a.x;
	}
};


vector< Point > convex_hull(vector< Point > ps)
{
	int N = ps.size();
	sort(ps.begin(),ps.end());

	int k = 0;
	vector<Point> convex(N*2);

	rep(i,N)
	{
		while (2 <= k && (convex[k-1] - convex[k-2]).det(ps[i] - convex[k-1]) <= 0 )
		{
			k--;
		}
		convex[k++] = ps[i];
	}

	for(int i = N-2,t = k; 0 <= i;i--)
	{
		while (t < k && (convex[k-1] - convex[k-2]).det(ps[i] - convex[k-1]) <= 0 )
		{
			k--;
		}
		convex[ k++ ] = ps[i];
	}

	convex.resize(k-1);
	return convex;
}

int main()
{
	int n;
	while (cin >> n && n)
	{
		vector< Point > ps( n );

		rep(i,n)
		{
			ps[i].input();
		}

		vector< Point > convex = convex_hull( ps );

		cout << n - convex.size() << endl;
	}

	return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
int n,t;
int dp[3050][3050];
int mx[3050];
pair <int,int> p[3050];

int main()
{
    cin>>n>>t;
    for(int i=1;i<=n;++i)
    {
        int a,b;cin>>a>>b;
        p[i]=make_pair(a,b);
    }
    sort(p+1,p+n+1);
    for(int i=n;i;--i)mx[i]=max(mx[i+1],p[i].second);
    int ans=0;
    for(int i=1;i<=n;++i)
    {
        for(int j=1;j<t;++j)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=p[i].first)
                dp[i][j]=max(dp[i][j],dp[i-1][j-p[i].first]+p[i].second);
        }
        ans=max(ans,dp[i][t-1]+mx[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 35968
N, M = map(int, input().split())
SC = [tuple(map(int, input().split())) for _ in range(M)]

for i in range(999):
    si = str(i)
    if len(si) != N:
        continue
    for s, c in SC:
        if si[s-1] != str(c):
            break
    else:
        print(i)
        break
else:
    print(-1)

Measured memory_bytes: 9080
a,b,c,d = map(int,input())
if a + b + c + d == 7:
    print(str(a)+ "+" +str(b) +"+"+ str(c) +"+"+ str(d)+ "=7")
elif a + b + c - d == 7:
    print(str(a)+ "+" +str(b) +"+"+ str(c) +"-"+ str(d)+ "=7")
elif a + b - c + d == 7:
    print(str(a)+ "+" +str(b) +"-"+ str(c) +"+"+ str(d)+ "=7")
elif a - b + c + d == 7:
    print(str(a)+ "-" +str(b) +"+"+ str(c) +"+"+ str(d)+ "=7")
elif a + b - c - d == 7:
    print(str(a)+ "+" +str(b) +"-"+ str(c) +"-"+ str(d)+ "=7")
elif a - b - c + d == 7:
    print(str(a)+ "-" +str(b) +"-"+ str(c) +"+"+ str(d)+ "=7")
elif a - b + c - d == 7:
    print(str(a)+ "-" +str(b) +"+"+ str(c) +"-"+ str(d)+ "=7")
else:
    print(str(a)+ "-" +str(b) +"-"+ str(c) +"-"+ str(d)+ "=7")

Measured memory_bytes: 3064
#include <iostream>
#include<cstring>
#include<cmath>
using namespace std;

int minCost(int h[],int n){
    int dp[n];
    memset(dp,-1,sizeof(dp));
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    return dp[n-1];
}

int main() {
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    cin>>h[i];
    cout<<minCost(h,n);
    return 0;
}

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

int main () {
  string s; cin >> s;
  string ans = "";
  for (int i = 0; i < s.size(); i++) {
    if ((i+1) % 2 != 0) ans.push_back(s[i]);
  }
  cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<pair<int, bool>> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i).first;
    a.at(i).first--;
    a.at(i).second = 0;
  }
  int start = 0;
  int tmp = a.at(start).first;
  a.at(start).second = 1;
  if (a.at(start).first == 1) {
    cout << 1;
    return 0;
  }
  int count = 1;
  for (;;) {
    int b = tmp;
    if (a.at(b).first == 1) {
      break;
    }
    if (a.at(b).second == 1) {
      cout << -1;
      return 0;
    }
    a.at(b).second = 1;
    count++;
    tmp = a.at(b).first;
  }
  count++;
  cout << count;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define LB lower_bound
#define UB upper_bound
#define pi pair<ll,ll>
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

int main()
{
    FAST
    ll a;cin>>a;
    cout<<a+a*a+a*a*a;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define int long long

using namespace std;

struct Fleur{
    int poids;
    int valeur;
};

int32_t main()
{
    int nbFleur;
    cin >> nbFleur;

    Fleur fleur[nbFleur];

    int nbFeuille = 1 << ((int)ceil(log2(nbFleur+1)));

    int arbre[nbFeuille*2] = {0};

    for(int iFleur = 0; iFleur < nbFleur; iFleur++) {
        cin >> fleur[iFleur].poids;
    }

    for(int iFleur = 0; iFleur < nbFleur; iFleur++) {
        cin >> fleur[iFleur].valeur;
        int total = 0;
        int debut = nbFeuille, fin = fleur[iFleur].poids+nbFeuille-1;

        while(debut <= fin) {
            if(debut%2==1) {
                total = max(total, arbre[debut]);
                debut++;
            }
            if(fin%2==0) {
                total = max(total, arbre[fin]);
                fin--;
            }
            debut /= 2;
            fin /= 2;
        }

        arbre[fleur[iFleur].poids + nbFeuille] = max(arbre[fleur[iFleur].poids + nbFeuille], total + fleur[iFleur].valeur);

        int id = fleur[iFleur].poids + nbFeuille;
        while(id != 1) {
            id /= 2;
            arbre[id] = max(arbre[id*2], arbre[id*2+1]);
        }

    }

    cout << arbre[1];

    return 0;
}


Measured memory_bytes: 7424
n,l=map(int,input().split())

num=1+l-1
number=[]
for _ in range(n):
  number.append(num)
  num+=1

if 0 in number:
  print(sum(number))
    
else:
  if all(i<0 for i in number):
    print(sum(number)-max(number))
    
  else:
    print(sum(number)-min(number))

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

#define ll long long int

int main(){
    ll n;
    string c;
    cin >> n;
    set<string>s;
    for (int i = 0; i < n;i++)
    {
        cin >> c;
        s.insert(c);
    }
    cout << (int)s.size() << endl;
    return 0;
}

Measured memory_bytes: 19236
#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>
#include<string>
#include<map>
#include<queue>

using namespace std;

int main(void){

    int n; cin >> n;
    int ans = 0;
    vector<int> p(n);
    vector<int> vmin(n);

    for(int i = 0;i < n;i++) cin >> p[i];

    vmin[0] = p[0];

    for(int i = 1;i < n;i++){
        vmin[i] = min(vmin[i-1], p[i]);
    }

    for(int i = 0;i < n;i++){
        if(vmin[i] >= p[i]) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main()
{
  ios::sync_with_stdio(false);
  int a, b, c;
  string s = "No";
  cin >> a >> b;

  for (c = 1; c < 4; ++c)
  {
    if ((a * b * c) & 1)
    {
      s = "Yes";
      break;
    }
  }

  cout << s << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

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

	int x = min(A, B);
	int y = max(0, (A + B) - N);
	cout << x << " " << y << endl;

	return 0;
}


Measured memory_bytes: 256
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def __add__(self,other):
        return Vector(self.x+other.x,self.y+other.y)
    
    def __sub__(self,other):
        return Vector(self.x-other.x,self.y-other.y)
    
    def __mul__(self,scalar):
        return Vector(self.x*scalar,self.y*scalar)
    def __rmul__(self, scalar):
        return Vector(self.x*scalar,self.y*scalar)
    
   
    def __repr__(self):
        return str([self.x,self.y])
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y-vector1.y*vector2.x

cx,cy,r = map(int,input().split())
c = Vector(cx,cy)
q = int(input())

for i in range(q):
    x1,y1,x2,y2 = map(int,input().split())
    p1 = Vector(x1,y1)
    p2 = Vector(x2,y2)
    d = p2-p1
    m = p1+(dot(c-p1,d)/d.norm_2()*d)
    #h = abs(cross(c-p1,d))/d.norm()
    l = math.sqrt(r**2-(m-c).norm_2())
    
    a = m-(l/d.norm()*d)
    b = m+(l/d.norm()*d)   
    
    if abs(a.x)<10**(-9):
        a.x = 0
    if abs(a.y)<10**(-9):
        a.y = 0
    if abs(b.x)<10**(-9):
        b.x = 0
    if abs(b.y)<10**(-9):
        b.y = 0
        
    if a.x<b.x:
        print('{} {} {} {}'.format(a.x,a.y,b.x,b.y))
    elif a.x>b.x:
        print('{} {} {} {}'.format(b.x,b.y,a.x,a.y))
    else:
        if a.y<b.y:
            print('{} {} {} {}'.format(a.x,a.y,b.x,b.y))
        else:
            print('{} {} {} {}'.format(b.x,b.y,a.x,a.y))


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

using namespace std;

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

static long long lcm (long long a, long long b) {
    long long ab_gcd = gcd(a, b);
    return a / ab_gcd * b;
}

int main (void) {
    int N;
    cin >> N;
    vector<long long> T(N);
    for ( int i=0; i<N; i++ ) {
        cin >> T.at(i);
    }

    long long ans = 1;
    for ( int i=0; i<N; i++ ) {
        ans = lcm(ans, T.at(i));
    }

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


Measured memory_bytes: 256
function Main(input) {
    input = input.split("\n");
    var n = parseInt(input[0], 10);
    var a = input[1].split(' ');
    a = a.map(str => parseInt(str, 10));
    a = a.map(num => {return 1/num});
    ht = a.reduce((ht,data) => {return ht + data});

    console.log(1/ht);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <iostream>

#include <vector>

using std::cin;
using std::cout;
using std::endl;

using std::vector;

static bool
all_even(vector<int> const &A)
{
  for (auto it = A.begin(); it != A.end(); it++)
  {
    if (*it % 2 != 0)
    {
      return false;
    }
  }
  return true;
}

static void
all_div2(vector<int> &A)
{
  for (auto it = A.begin(); it != A.end(); it++)
  {
    *it /= 2;
  }
}

int
main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int n = 0; n < N; n++)
  {
    cin >> A[n];
  }
  int count = 0;
  while (all_even(A))
  {
    all_div2(A);
    count++;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
let rec d n ret =
  if n = 0 then ret
  else d (n / 10) (ret + 1)

let rec ans i n =
  if n mod i = 0 then d (n / i) 0
  else ans (i - 1) n

let () =
  let n = read_int () in
  let m = int_of_float (sqrt (float_of_int n)) in
  print_int (ans m n)


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define inf 1000000000000000007
#define eps 0.000001
#define pi 3.141592653589793
#define pii pair<int,int>
#define pdd pair<ld,ld>
#define pll pair<ll,ll>
#define ff first
#define ss second
#define vii vector<int>
#define vpl vector<pll>
#define vll vector<ll>
#define sti stack <int>
#define stll stack <ll>
#define mseti multiset <ll>
#define msetd multiset <ll, greater <ll> >
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound 
#define stp setprecision(12)//use fixed before stp
#define endl '\n'
ll e[100009];
void dfs(vll v[],ll q)
{
    e[q]=1;
    for(auto i:v[q])
    {
        if(e[i]==0)
            dfs(v,i);
    }
}
int main()
{  
    FAST
    ll n,m;
    cin>>n>>m;
    vll v[n+1];
    ll x,y,z;
    for(ll i=0;i<m;i++)
    {
        cin>>x>>y>>z;
        v[x].pb(y);
        v[y].pb(x);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++)
    {
        if(e[i]==0)
        {
            ans++;
            dfs(v,i);
        }
    }
    cout<<ans;
}

Measured memory_bytes: 9600
($N,$M)=glob<>;
@@=(9e9)x2**$N;
$@[0]=0;
$A=<>,$C=0,map($C|=1<<$_-1,glob<>),map$@[$_|$C]-=$-=$@[$_|$C]-$A-$@[$_],0..$#@for 1..$M;
print$@[-1]<9e9?$@[-1]:-1

Measured memory_bytes: 1280
#include"bits/stdc++.h"
#include<iostream>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, c) for(int i = 0; i < (int)c; i++)
const ll inf = ll(1e18)+1;

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

	rep(i,k) {
		if (a>=b) {
			b *= 2;
		}
		else {
			c *= 2;
		}
	}

	if (a<b && b<c) {
		cout << "Yes" << endl;
	}
	else {

		cout << "No" << endl;
	}
	


	return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
int main()
{
  long long int a, b, tmp, ans;
  scanf("%lld %lld", &a, &b);

  if(b - a == 0){
    ans = a;
  }
  if(b - a == 1){
    ans = a ^ b;
  }

  tmp = (b - a + 1) % 4;
  if(a % 2 == 0){
    if(tmp == 0){
      ans = 0;
    }
    if(tmp == 1){
      ans = b;
    }
    if(tmp == 2){
      ans = 1;
    }
    if(tmp == 3){
      ans = 1 ^ b;
    }
  }
  if(a % 2 != 0){
    if(tmp % 4 == 1){
      ans = a;
    }
    if(tmp % 4 == 2){
      ans = a ^ b;
    }
    if(tmp % 4 == 3){
      ans = a ^ 1;
    }
    if(tmp % 4 == 0){
      ans = a ^ b ^ 1;
    }
  }

  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X;
  cin>>N>>X;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
    int a=0;
    for(int i=0;i<N;i++){
      a+=vec.at(i);
    }
  if(a<=X) cout<<N+1<<endl;
  else{
  int z=0;
  int count=0;
  for(int i=0;i<N;i++){
    z+=vec.at(i);
    count++;
    if(z>X) break;
  }
  cout<<count<<endl;
  }
}

Measured memory_bytes: 3624
'''
    Auther: ghoshashis545 Ashis Ghosh
    College: jalpaiguri Govt Enggineering College

'''
from os import path
import sys
from functools import cmp_to_key as ctk
from collections import deque,defaultdict as dd 
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]

def bo(i):
    return ord(i)-ord('a')

file = 0

def solve():
    



    # for _ in range(ii()):

    n=ii()
    m={}
    a=["AC","WA","TLE","RE"]
    m['WA']=0
    m['TLE']=0
    m["AC"]=0
    m["RE"]=0
    for i in range(n):
        s=si()
        m[s]+=1
    for i in a:
        print(i,end=" x ")
        print(m[i])












  
















if __name__ =="__main__":

    if(file):

        if path.exists('input1.txt'):
            sys.stdin=open('input1.txt', 'r')
            sys.stdout=open('output1.txt','w')
        else:
            input=sys.stdin.readline
    solve()

Measured memory_bytes: 70340
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include <map>
#include <set>
using namespace std;

int main() {
    long long a, b, c, d, n;
    cin >> a >> b >> c >> d;
    long long  p = c, q = d;
    if (c > d) swap(c, d);
    while(d%c>0){
        d %= c;
        swap(c, d);
    }
    n = p * q / c;
    long long x = b / p - (a - 1) / p, y = b / q - (a - 1) / q;
    long long z = b / n - (a - 1) / n;
    long long ans = b - a + 1 - x - y + z;
    cout << ans << endl;
}

Measured memory_bytes: 256
N, M = gets.split(' ').map(&:to_i)
pos = [nil] * (N + 1)
rel = Array.new(N + 1){Array.new}
M.times do |i|
  l, r, d = gets.split(' ').map(&:to_i)
  rel[l].push([r, d])
  rel[r].push([l, -d])
end

ans = 'Yes'
1.upto(N) do |i|
  next if pos[i]
  pos[i] = 0
  queue = [i]
  while !queue.empty?
    l = queue.shift
    rel[l].each do |r, d|
      if pos[r] == nil
        queue.push(r)
        pos[r] = pos[l] + d
      elsif pos[r] - pos[l] != d
        ans = 'No'
        break
      end
    end
  end
  break if ans == 'No'
end

puts ans

Measured memory_bytes: 53184
#include<bits/stdc++.h>
 using namespace std;
 #define int long long
 #define endl "\n"
 const int mod=1e9+7;
 #define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 #define clr(a,x) memset(a,x,sizeof(a))
 #define T int t;cin>>t; while(t--)
 #define vll vector<int> 
 #define v22 vactor<vector<int>>
#define pb push_back
 #define sz size
 #define str to_string
 #define um unordered_map<int,int>
 #define intt stoll
 #define sv() sort(a.begin(),a.end())
 #define vp vector<pair<int, int>> b(n) 
 vll p(1e7 + 1, 1);
int32_t main()
{
   int n,w;
   cin>>n>>w;
   vll a(n),b(n);
   for(int i=0;i<n;i++)
   cin>>a[i]>>b[i];
   int dp[n+1][w+1];
   for(int i=0;i<=n;i++)
   {
  for(int j=0;j<=w;j++)
  {
     if(i==0 || j==0)
     dp[i][j]=0;
     else if(a[i-1]<=j)
     {
        int c=a[i-1];
        dp[i][j]=max(b[i-1]+dp[i-1][j-c],dp[i-1][j]);
     }
     else
dp[i][j]=dp[i-1][j];
  }
   }
cout<<dp[n][w];
}

Measured memory_bytes: 160276
#include <bits/stdc++.h>
using namespace std;
 
int main(){ 
    int a,b,k;
    cin>>a>>b;

    if((a+b)%2==0){
        if(a>=b){
            k=(a-b)/2;
            cout<<a-k<<endl;
        }
        else {
            k=(b-a)/2;
            cout<<a+k<<endl;
        }
    }else cout<<"IMPOSSIBLE"<<endl;

    return 0;
}

Measured memory_bytes: 384
/*
memo
????????°??????

*/

#include<iostream>
#include<cstring>
#include<vector>
using namespace std;

int m, n;
int ma[300];
int ka[300][300];
vector<int> g[300];
bool go[300], ba[300];
void iki(int x)
{
	//????????§????????¨????????????????????????

	//????????????????????´??????????????????????????°?????¨??????
	//????????´??????????????°???????????????
	//???????????????????????§??????????????¶???????????????????????????????????£???
	//??????????????°????????????????????°????????????????????°?????¨???????????????????????????
	//?????????????????????????????°?????¨??°?????°????????´???????¨???????????????????
	//????????????????????´???????????£???????????´???????????????????????????????????????
	//??´?????????????????????????????´??????????§???????????????????????????????????????´????????????????????¨??????????????°????????????????????????????????????

	int i;

	if (go[x]) return;
	go[x] = true;				//????????°??????
	if (x == n + 1) return;
	for (i = 1; i <= m; i++)
	{
		int y = x + i;
		if (y <= n+1)
		{
			y = y + ma[y];
			if (y>0)
			{
				if (y > n + 1) y = n + 1;
				//if (ka[y][x] == 1)break;
				//ka[y][x] = 1;

				g[y].push_back(x);
				iki(y);
			}
		}

	}
	return;
}

void kae(int x)
{
	//????????§?????°?????¨????????´???????????????????????????????????¨???????????????????????????

	//????????????????????´?????????????§??????¨??????????????????????????°????????????????????§???????????´?????????????????????
	//??????????????§?????£?????´??????????????¨?????????????????°???????????????


	int i;
	if (ba[x]) return;
	ba[x] = true;
	if (x == 0) return;
	for (i = 0; i<g[x].size(); i++)
	{
		kae(g[x][i]);
	}
	return;
}

int main()
{
	int i;
	while (cin >> m, m)
	{
		cin >> n;

		//---------------?????????--------------------//
		for (i = 0; i<300; i++)
		{
			g[i].clear();
			ma[i] = 0;
			//for (int j = 0; j<300; j++)
			//{
			//	ka[i][j] = 0;
			//}
		}
		memset(go, 0, sizeof(go));
		memset(ba, 0, sizeof(ba));


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

		iki(0);
		kae(n + 1);


		/*
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << go[i] << "  " ;
		}
		cout << endl;
		for (i = 0; i <= n + 1; i++)
		{
			cout << "  " << ba[i] << "  ";
		}
		*/



		for (i = 0; i <= n + 1; i++)
		{
			if (go[i])
			{
				if (ba[i] == 0)
				{
					cout << "NG\n";
					break;
				}
			}
			if (i == n + 1) cout << "OK\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3124
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,s,f) for(i=s;i<f;i++)
#define print(v) for(auto &z:v) cout<<z<<' ';cout<<'\n'
#define hi cout<<'h'<<'i'<<'\n' 
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define B begin()
#define E end()
#define sz(v) (int)((v).size())
#define vi vector<int>
#define vii vector<pair<int,int>>
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define clk1 clock_t start_time=clock()
#define clk2 cout<<(clock()-start_time)/(double)CLOCKS_PER_SEC
#define clean(arr) memset(arr,0,sizeof(arr))
#define mod 1000000007
#define mod2 998244353
#define space 100005
//<<fixed << setprecision(9)


ll EE(ll a, ll b, ll *x, ll *y)
{
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1;
    ll gcd = EE(b%a, a, &x1, &y1); 
  
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

ll inverse(ll a, ll m)
{
    ll x,y;
    EE(a,m,&x,&y);
    if(x<0) x += m;
    return x;
}


int main()
{
    int n,i,j,t;
    boost;
    int k;
    cin>>n>>k;
    int arr[n+1];
    rep(i,1,n+1)cin>>arr[i];
    sort(arr+1,arr+n+1);
    ll ans=0;
    ll num=1,den=1;
    ans+=arr[k]-arr[n-k+1];
    rep(i,1,n-k+1)
    {
        num*=(k+i-1);
        num%=mod;
        den*=i;
        den%=mod;
        ll temp=num*inverse(den,mod);
        temp%=mod;
        ans+= temp*(arr[i+k]-arr[n-k+1-i]);
        ans%=mod;
    }
    if(ans<0)ans+=mod;
    cout<<ans;

    return 0;
}



Measured memory_bytes: 640
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int A = int.Parse(input[0]);
            var op = input[1];
            int B = int.Parse(input[2]);
            Console.WriteLine(op == "+" ? A + B : A - B);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
	int a[4], b[2], sum;
	
	sum = 0;
	
	for (int i = 0; i < 4; i++){
		cin >> a[i];
	}
	
	cin >> b[0] >> b[1];
	
	if (b[0] <= b[1]){
		sum += b[1];
	}
	else {
		sum += b[0];
	}
	
	
	sort(a, a + 4);
	
	sum += a[1] + a[2] + a[3];
	
	cout << sum << endl;
}

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

#define rep(i,c) for(int i = 0; i < (int)c; ++i)
using llint = long long int ;
using namespace std;



int main(){
    long long int A,B;
    cin>>A>>B;
    if(A>B) swap(A,B);
    int b=B;
    while (B%A!=0)
    {
        B+=b;
    }
    cout<<B<<endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int n; cin >> n;
  vector<int> a(n), b(n), c(n);
  REP(i, n) cin >> a[i];
  sort(ALL(a));
  REP(i, n) cin >> b[i];
  sort(ALL(b));
  REP(i, n) cin >> c[i];
  sort(ALL(c));
  long long ans = 0;
  REP(i, n) {
    long long cc = n;
    cc -= upper_bound(ALL(c), b[i]) - c.begin();
    long long aa = lower_bound(ALL(a), b[i]) - a.begin();
    ans += cc * aa;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long lli;
lli n;
vector<lli> a;
int pos(){
    cout << "Possible" << endl;
    return 0;
}
int imp(){
    cout << "Impossible" << endl;
    return 0;
}
int main(){
    cin >> n;
    a = vector<lli> (n);
    for(lli i = 0;i < n;i++) cin >> a[i];
    sort(a.begin(),a.end());
    if(a.back()%2){
        for(lli i = a.back();i >= (a.back()+1)/2+1;i--){
            if(upper_bound(a.begin(),a.end(),i) - lower_bound(a.begin(),a.end(),i) < 2) return imp();
        }
        if(upper_bound(a.begin(),a.end(),(a.back()+1)/2) - lower_bound(a.begin(),a.end(),(a.back()+1)/2) != 2) return imp();
        if(a.front() < (a.back()+1)/2) return imp();
        else return pos();
    }else{
        for(lli i = a.back();i >= a.back()/2 + 1;i--){
            if(upper_bound(a.begin(),a.end(),i) - lower_bound(a.begin(),a.end(),i) < 2) return imp();            
        }
        if(upper_bound(a.begin(),a.end(),a.back()/2) - lower_bound(a.begin(),a.end(),a.back()/2) != 1) return imp();
        if(a.back() < (a.back()/2)) return imp();
        else return pos();
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
arr = gets.chomp.split(' ').map(&:to_i)
total = 0
arr.each { |i| total += i }
result = total
(1...n).each do |i|
  tmp = 0
  (i...n).each do |j|
    tmp += arr[j]
  end
  result = [result, (total - tmp - tmp).abs].min
end
puts result

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

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 1e5 + 9, M = 1e5 + 9, OO = (int) 1e6 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

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

int n, mem[N][4], gain[N][3];

int dp(int i, int act) {
	if (i == n)
		return 0;
	ll a = 0, b = 0, c = 0;

	int &ret = mem[i][act];
	if (ret != -1)
		return ret;
	if (act != 0)
		a = dp(i + 1, 0) + gain[i][0];
	if (act != 1)
		b = dp(i + 1, 1) + gain[i][1];
	if (act != 2)
		c = dp(i + 1, 2) + gain[i][2];
	ret = max(a, max(b, c));
	return ret;
}

int main() {

	INPUT();
	cin >> n;
	clr(mem, -1);
	for (int i = 0; i < n; ++i) {
		cin >> gain[i][0] >> gain[i][1] >> gain[i][2];
	}
	cout<<dp(0,3);

	return 0;

}


Measured memory_bytes: 9216