akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <time.h>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <string.h>
#define sf scanf
#define pf printf
#define lf double
#define ll long long
#define p123 printf("123\n");
#define pn printf("\n");
#define pk printf(" ");
#define p(n) printf("%d",n);
#define pln(n) printf("%d\n",n);
#define s(n) scanf("%d",&n);
#define ss(n) scanf("%s",n);
#define ps(n) printf("%s",n);
#define sld(n) scanf("%lld",&n);
#define pld(n) printf("%lld",n);
#define slf(n) scanf("%lf",&n);
#define plf(n) printf("%lf",n);
#define sc(n) scanf("%c",&n);
#define pc(n) printf("%c",n);
#define gc getchar();
#define re(n,a) memset(n,a,sizeof(n));
#define len(a) strlen(a)
using namespace std;
//https://codeforces.com/contest/1213/problems
//https://codeforces.com/contest/1213/submit
ll a[100];
int main(){
    ll n;
    sld(n)
    re(a,0ll);

    for(int i = 0ll; i < 50ll; i ++){
        a[i] = 49ll;
    }
    ll count0 = n/50ll;
    ll count1 = n%50ll;
    for(int i = 0; i < 50; i ++){
        a[i] += count0;
    }
    for(int i = 0; i < count1; i ++){
        a[i] += 50ll;
        for(int j = 0; j < 50; j ++){
            if(i == j){
            }else{
                a[j] --;
            }
        }
    }
    pld(50ll) pn
    for(int i = 0; i < 49; i ++){
        pld(a[i]) pk
    }
    pld(a[49]) pn
    return 0;
}


Measured memory_bytes: 888
import copy

def partition(p, r):
    i = p
    for j in range(p, r):
        if A[r][1] >= A[j][1]:
            A[i], A[j] = A[j], A[i]
            i += 1
    A[r], A[i] = A[i], A[r]
    return i

def quick_sort(p, r):
    if p < r:
        q = partition(p, r)
        quick_sort(p, q-1)
        quick_sort(q+1, r)

def correct_same_num_suits(l, num, first, ele_cnt):
    suits = []
    for i in range(first, N):
        if num == l[i][1]:
            suits.append(l[i][0])
        if ele_cnt == len(suits):
            break
    return suits

def is_stable():
    idx = 0
    while idx < N-1:
        idx_incr_flg = True
        if A[idx][1] == A[idx+1][1]:
            num = A[idx][1]
            j = idx
            ele_cnt = 0
            while j < N and num == A[j][1]:
                ele_cnt += 1
                j += 1
            sorted_suits = correct_same_num_suits(A, num, idx, ele_cnt)
            orig_suits = correct_same_num_suits(orig_list, num, 0, ele_cnt)
            if sorted_suits != orig_suits:
                return False
            idx += len(sorted_suits)
            idx_incr_flg = False
        if idx_incr_flg:
            idx += 1
    return True


N = int(input())
A = []
for _ in range(N):
    suit, num = input().split()
    num = int(num)
    A.append([suit, num])
orig_list = copy.deepcopy(A)

quick_sort(0, N-1)

is_stable = is_stable()
if is_stable:
    print("Stable")
else:
    print("Not stable")

for card in A:
    print("%s %d" % (card[0], card[1]))


Measured memory_bytes: 39444
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		Map<Integer, Integer> map = new HashMap<>();
		long ans = 0l;
		for(; n>0; n--) {
			int x = sc.nextInt();
			ans += x;
			if(map.containsKey(x)) {
				map.put(x, map.get(x)+1);
			}else {
				map.put(x, 1);
			}
		}
		int q = sc.nextInt();
		ArrayList<Long> list = new ArrayList<>();
		for(; q > 0; q--) {
			int b = sc.nextInt(), c = sc.nextInt();
			if(map.containsKey(b)) {
				ans += map.get(b)*(c-b);
				if(map.containsKey(c)) {
					map.put(c, map.get(c)+map.get(b));
				}else {
					map.put(c, map.get(b));
				}
				map.remove(b);
			}
			list.add(ans);
		}
		for(long l : list) {
			System.out.println(l);
		}
	}
	
	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

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

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 64028
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S = list(_ for _ in input())
    S.sort()
    S = ''.join(S)
    if S == 'abc':        
        print('Yes')
    else:
        print('No')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3700
#include "bits/stdc++.h"
using namespace std;

int main() {
	int H, W, D, A, Q, L, R;
	static long long X[90000] = {};
	pair<int, int> P[90000];
	cin >> H >> W >> D;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> A;
			A--;
			P[A] = { i, j };
		}
	}
	for (int i = 0; i < H * W; i++) {
		if (i < D) X[i] = 0;
		else {
			X[i] = X[i - D] + (abs(P[i].first - P[i - D].first) + abs(P[i].second - P[i - D].second));
		}
	}
	cin >> Q;
	for (int i = 0; i < Q; i++) {
		cin >> L >> R;
		L-- , R--;
		cout << X[R] - X[L] << endl;
	}
}

Measured memory_bytes: 2560
using System;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            for (int i = 1; i <= 3; i++)
            {
                if (A != i && B != i) Console.WriteLine(i);
            }
        }
    }
}

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

int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    string s2 = s;
    sort(s.begin(),s.end());
    int ans = 0;
    for(int i=0;i<n;i++) {
        if(s[i] == 'R' && s2[i] == 'W') {
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3900
n = int(input())
h = list(map(int, input().split()))
h[0] -= 1
for i in range(1,n):
    if (h[i] > h[i - 1]):
        h[i] -= 1
for i in range(1,n):
    if (h[i] < h[i - 1]):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 14396
#include<bits/stdc++.h>
using namespace std;
int f(int k){
  int ans=0,c,i;
  if(k==0) return 0;
  else{
    while(k>0){
      bitset<20> b(k);
      c=0;
      for(i=0;i<20;i++) if(b.test(i)) c++;
      k%=c;
      ans++;
    }
    return ans;
  }
}
int main() {
  int n,i,c=0,xp=0,xm=0,k;
  string x;
  cin>>n>>x;
  vector<int> mp(n),mm(n);
  for(i=0;i<n;i++) if(x.at(i)=='1') c++;
  for(i=0;i<n;i++){
    if(i==0){
      mp.at(0)=1;
      if(c>1) mm.at(0)=1;
    }
    else{
      mp.at(i)=2*mp.at(i-1)%(c+1);
      if(c>1) mm.at(i)=2*mm.at(i-1)%(c-1);
    }
  }
  for(i=0;i<n;i++){
    if(x.at(i)=='1'){
      xp=(xp+mp.at(n-1-i))%(c+1);
      if(c>1) xm=(xm+mm.at(n-1-i))%(c-1);
    }
  }
  for(i=0;i<n;i++){
    if(c==0) cout<<1<<endl;
    else if(c==1&&x.at(i)=='1') cout<<0<<endl;
    else{
      if(x.at(i)=='0') k=(xp+mp.at(n-1-i))%(c+1);
      else if(x.at(i)=='1') k=(xm+c-1-mm.at(n-1-i))%(c-1);
      cout<<1+f(k)<<endl;
    }
  }
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define odd(x) ((x) % (2))
#define fastio ios_base::sync_with_stdio(false), cin.tie(0);
#define fileio freopen("template.in", "r", stdin), freopen("template.out", "w", stdout);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;

int main() {
    fastio;
    //fileio;
        
    string s, t;
    cin >> s >> t;
    int best = INT_MAX;

    FOR(i, 0, s.size() - t.size() + 1) {
        string t2 = s.substr(i, t.size());
        int diff = 0;
        FOR(j, 0, t.size()) { 
            if (t2[j] != t[j]) {diff++;}
        }
        best = min(best, diff);
    }
    cout << best << "\n";
    return 0;
}


Measured memory_bytes: 3656
/**
 * @author      : Luis Miguel Baez <es.luismiguelbaez@gmail.com>
 * @created     : August 27, 2020
 */

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ms(arr, value) memset(arr, value, sizeof(arr))
#define finally(value) {cout << value << '\n'; return;}
#define ll    int64_t

const int oo = int(1e9);
const ll lloo  = (ll)(1e18);

template <typename T>
struct edge {
    int from;
    int to;
    T cost;
};

template <typename T>
struct link {
    int to;
    T cost;
    bool operator>(const link& other) const {return cost > other.cost;}
    bool operator<(const link& other) const {return cost < other.cost;}
};

template <typename T>
class graph {
public:
    vector<edge<T>> edges;
    vector<vector<link<T>>> adj;
    int n;
    graph(int sz) : n(sz) {
        adj.resize(n);
    }
    virtual void add(int from, int to, T cost) = 0;
};

template <typename T>
class digraph : public graph<T> {
public:
    using graph<T>::edges;
    using graph<T>::adj;
    using graph<T>::n;

    digraph(int sz) : graph<T>(sz) {}

    void add(int from, int to, T cost = 1) {
        assert(0 <= from && from < n && 0 <= to && to < n);
        edges.push_back({from, to, cost});
        adj[from].push_back({to, cost});
    }
    
    digraph<T> reverse() const {
        digraph<T> rev(n);
        for (auto &e : edges) {
            rev.add(e.to, e.from, e.cost);
        }
        return rev;
    }
};

class Task {
public:
    int n, m;
    
    vector<bool> visited;
    vector<int> max_depth;

    void dfs(const digraph<int> &g, int node) {
        visited[node] = true;
        for(link<int> neighbor: g.adj[node]) {
            if(!visited[neighbor.to]) { 
                dfs(g, neighbor.to);
            }
            max_depth[node] = max(max_depth[node], 1 + max_depth[neighbor.to]);
        }
    }

    void solveOne(istream &in, ostream &out) {
        in >> n >> m;
        digraph<int> g(n);
        visited.resize(n, false);
        max_depth.resize(n, 0);
        int x, y;
        for(int i = 0; i < m; ++i){
            in >> x >> y, x--, y--;
            g.add(x, y);
        }

        for(int node = 0; node < n; ++node){
            if(!visited[node]) {
                dfs(g, node);
            }
        }
        out << *max_element(max_depth.begin(), max_depth.end()) << endl;
    }
    
    void solve(istream &in, ostream &out) {
        int t=1;
        while(t--) solveOne(in, out);
    }
};

auto main() -> int {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    Task solver;
    istream &in(cin);
    ostream &out(cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 13532
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

vector<int> v;
vector<int> c;
int main() {
    int n;
    cin>>n;
    int x;
    for(int i=0;i<n;++i)cin>>x,v.push_back(x);
    for(int i=0;i<n;++i)cin>>x,c.push_back(x);
    int ans=0;
    for(int s=1;s<(1<<n);++s){
        int val=0,cost=0;
        for(int i=0;i<n;++i){
            if(s&(1<<i)){
                val+=v[i];
                cost+=c[i];
            }
        }
        ans=max(ans,val-cost);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define pi 3.14159265358979323846
int i;
int main(){
    int x;cin>>x;
    int happy=0;
    
    while(x>=500){
        happy+=1000;
        x-=500;
    }
    while(x>=5){
        happy+=5;
        x-=5;
    }

    cout<<happy<<endl;
    return 0;
}

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

#define INF 0x3f3f3f3f
#define int long long
#define pii pair<int, int>

const int N = 100005;

vector<int> adj[N];
int dp[N];
bool vis[N];

int dfs(int u) {
    if(vis[u])
        return dp[u];
    vis[u] = true;
    int i, temp;
    temp = 0;
    for(i = 0 ; i < adj[u].size() ; i++) {
        temp = max(temp, dfs(adj[u][i]) + 1);
    }
    return dp[u] = temp;
}

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

    int n, m, i, u, v, ans;
    cin >> n >> m;
    for(i = 0 ; i < m ; i++) {
        cin >> u >> v;
        adj[u].push_back(v);
    }
    ans = 0;
    for(i = 1 ; i <= n ; i++) {
        if(!vis[i]) {
            dfs(i);
            ans = max(ans, dp[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8704
#include <bits/stdc++.h> 
#define FOR(i,a,b) for(int i=(a);i<=(b);++i) 
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i) 
#define REP(i,n) for(int i=0;i<(n);++i)
#define RREP(i,n) for(int i=(n);i>0;--i)
#define CI cin>> 
#define CO cout<<
#define EN <<endl 
#define all(x) (x).begin(),(x).end()
using namespace std;
template <typename T> istream& operator >> (istream& is, vector<T>& vec) { for (T& x : vec) is >> x; 	return is; }
using ll = long long;
using VI = vector<int>;

int main() {
	int a, b, t; CI a >> b >> t;
	CO t / a * b EN;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;


void solve()
{
	int n;
	cin >> n;
	ll cnt[10][10] = {};
	for (int i = 1; i <= n; ++i)
	{
		string s = to_string(i);
		cnt[s[0] - '0'][s.back() - '0']++;
	}
	ll ans = 0;
	rep(i,10){
		rep(j,10){
			ans += cnt[i][j] * cnt[j][i];
		}
	}
	cout << ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const int MOD = 1000000007;
//const int MOD = 998244353;
template<class T> inline int add(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a+=b;if(a>=M)a%=M;return a;};
template<class T> inline int mul(T& a, T b, T M = MOD){if(a>=M)a%=M;if(b>=M)b%=M;a*=b;if(a>=M)a%=M;return a;};
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

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

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

int n, a[210000], b[210000];
int dp[210000][3];
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  if(n % 2 == 0){
    dp[0][0] = a[0];dp[1][1] = a[1];dp[2][0] = a[0]+a[2];
    repd(i,3,n){
      dp[i][0] = dp[i-2][0] + a[i];
      dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + a[i];
    }
    cout << max(dp[n-1][1], dp[n-2][0]) << endl;
    
  }else{
    dp[0][0] = a[0];dp[1][1] = a[1];dp[2][0] = a[0]+a[2];dp[2][2] = a[2];
    repd(i,3,n){
      dp[i][0] = dp[i-2][0] + a[i];
      dp[i][1] = max(dp[i-2][1], dp[i-3][0]) + a[i];
      dp[i][2] = max(dp[i-2][2], dp[i-3][1]) + a[i];
    }
    cout << max(dp[n-1][2], dp[n-2][1]) << endl;
  }
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int i;
  while(cin >> i && i){
    vary(int,a,i,0);
    rep(j,i){
      cin >> a[j];
    }
    int suf = 0,n = 32;
    while(n > 0){
      n -= (n-1)%5;
      cout << n << endl;
      n -= a[suf];
      n = (n < 0) ? 0 : n;
      cout << n << endl;
      ++suf;
      suf %= i;
    }
  }
  return 0;
}

Measured memory_bytes: 3088
#include<stdio.h>
int ex(int, int);
int A[20],n;
int main(){
  int i, j, m, input;
  scanf("%d",&n);
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
  scanf("%d",&m);
  for(i=0; i<m; i++){
    scanf("%d",&input);
    ex(input,0) ? printf("yes\n") : printf("no\n");
  }
  return 0;
}

int ex(int x, int i){
  int j;
  if(x == 0) return 1;
  for(j=i; j<n; j++)
    if(ex(x-A[j],j+1)) return 1;
  return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<functional>
#include<map>
#define INF 999999999
typedef long long ll;
 
int main() {
	int r,g;
	std::cin >> r >> g;
	std::cout << g * 2 - r << std::endl;
 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
    
ll n,capacity,a[101],w[101];    
ll dp[101][100005];

    ll M(ll i,ll k)
    {
        if(i==0||k==0)
            return 0;
        
        if(dp[i][k]!=-1)
            return dp[i][k];
            
        if(a[i]<=k)
            return dp[i][k]=max(w[i]+M(i-1,k-a[i]),M(i-1,k));
        
        else
            return dp[i][k]=M(i-1,k);
            
    }
    
    int main()
    {
        cin>>n>>capacity;
        for(ll i=1;i<=n;i++)
            cin>>a[i]>>w[i];
            
        memset(dp,-1,sizeof dp);
            
        cout<<M(n,capacity)<<"\n";    
        return 0;
    }
    

Measured memory_bytes: 79104
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}
long long int gcd(long long int a, long long int b){
  if( a == 0 || b == 0 ) return 0;
  long long int c;
  while( a != 0 ){
    c = a; a = b%a; b = c;
  }
  return b;
}
long long int lcm(long long int a, long long int b){
  if( a == 0 || b == 0 ) return 0;
  return ( a / gcd(a, b) ) * b;
}

int main() {
  long long int n, m; cin >> n >> m;
  string s, t;
  cin >> s >> t;
  long long int lp = lcm(n, m);
  long long int ln = lp/n;
  long long int lm = lp/m;
  long long int p = lcm(ln, lm);
  for(long long int i=0; i<lp; i+=p){
    if(i%ln == 0 && i%lm == 0){
      if(s[i/ln] != t[i/lm]){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << lp << endl;

  return 0;
}


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

signed main(){
  int N;
  cin>>N;
  int gohyaku=N/500;
  int goen=N%500/5;
  int ans=gohyaku*1000+goen*5;
  cout<<ans<<endl;
}

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


int main(){
  string s;
  cin >> s;
  int n = s.size();
  int l = 0;
  vector<char> ans;
  rep(i,n){
    if(s[i]=='0') ans.push_back('0');
    else if(s[i]=='1') ans.push_back('1');
    else {
      if(ans.size()>0) ans.pop_back();
    }
  }
  rep(i,ans.size()) cout <<  ans[i];
  cout << endl;
  return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int x1,y1,x2,y2; std::cin>>x1>>y1>>x2>>y2;
    int x3 = x2+(-y2+y1);
    int y3 = y2+( x2-x1);
    int x4 = x3+(-y3+y2);
    int y4 = y3+( x3-x2);
    std::cout << x3 << " " << y3 << " " << x4 << " " << y4 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(long (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

int main() {
    int h, w, c = 0;
    cin >> h >> w;
    REP(i,h) {
        REP(j,w) {
            char a;
            cin >> a;
            if (a == '#') c++;
        }
    }
    
    if (c == h + w - 1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
a = [(num,i) for i,num in enumerate(a)]
a.sort(reverse=True)
dp=[[0]*(n+1) for _ in range(n+1)]
for i in range(n+1):
    for j in range(n-i+1):
        if i>0:
            dp[i][j] = max(dp[i][j],dp[i-1][j]+a[i+j-1][0]*abs(a[i+j-1][1]-(i-1)))
        if j>0:
            dp[i][j] = max(dp[i][j],dp[i][j-1]+ a[i+j-1][0]*abs(a[i+j-1][1]-(n-j)))
ans = max(dp[i][n-i] for i in range(n+1))
print(ans)


Measured memory_bytes: 106184
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int ans = a - b;
  if(ans < 0) ans = 0;
  cout << ans << endl;
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <stdio.h>
#include <time.h>
#include <algorithm>
#include <cfloat>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long int          ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

struct Edge {
    Edge(int arg_to, int arg_cost) {
        to   = arg_to;
        cost = arg_cost;
    }
    int to, cost;
};

struct Info {
    Info(int arg_node_id, int arg_depth) {
        node_id = arg_node_id;
        depth   = arg_depth;
    }
    bool operator<(const struct Info &arg) const { return depth < arg.depth; }

    int node_id, depth;
};

int *        depth_table, *parent, *max_dist;
vector<Edge> G[100000];

void calcDepth(int node_id, int depth, int parent_id) {
    depth_table[node_id] = depth;
    parent[node_id]      = parent_id;
    for (int i = 0; i < G[node_id].size(); i++) {
        if (G[node_id][i].to == parent_id) continue;
        calcDepth(G[node_id][i].to, depth + 1, node_id);
    }
}

int main() {
    int N;
    scanf("%d", &N);

    depth_table = new int[N];
    parent      = new int[N];
    max_dist    = new int[N];

    for (int i = 0; i < N; i++) max_dist[i] = -1;

    int from, to, cost;
    for (int loop = 0; loop < N - 1; loop++) {
        scanf("%d %d %d", &from, &to, &cost);
        G[from].push_back(Edge(to, cost));
        G[to].push_back(Edge(from, cost));
    }

    calcDepth(0, 0, -1);

    priority_queue<Info> Q;

    for (int i = 0; i < N; i++) {
        Q.push(Info(i, depth_table[i]));
    }

    int ans = 0;
    int max1, max2;

    while (!Q.empty()) {
        max1 = 0, max2 = 0;

        for (int i = 0; i < G[Q.top().node_id].size(); i++) {
            if (G[Q.top().node_id][i].to == parent[Q.top().node_id]) continue;

            if (max1 < max_dist[G[Q.top().node_id][i].to] +
                           G[Q.top().node_id][i].cost) {
                max2 = max1;
                max1 = max_dist[G[Q.top().node_id][i].to] +
                       G[Q.top().node_id][i].cost;
            } else if (max2 < max_dist[G[Q.top().node_id][i].to] +
                                  G[Q.top().node_id][i].cost) {
                max2 = max_dist[G[Q.top().node_id][i].to] +
                       G[Q.top().node_id][i].cost;
            }
        }
        ans                       = max(ans, max1 + max2);
        max_dist[Q.top().node_id] = max1;
        Q.pop();
    }

    printf("%d\n", ans);

    return 0;
}



Measured memory_bytes: 16708
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " <<"LINE:"<<__LINE__<<"  "<< #i <<":"<< i << std::endl

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<ll, ll>;

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

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

  ll n,k;
  std::cin>>n>>k;

  if((2*k+2*n-1)*n>((2*k+5*n-1)/2)*n){
    std::cout<<-1<<"\n";
    return 0;
  }

  if(n%2){
    rep(i,0,(n+1)/2){
      std::cout<<i+k<<" "<<i+k+(n+1)/2+n-1<<" "<<k+2*n+2*i<<"\n";
    }
    rep(i,0,(n-1)/2){
      std::cout<<i+k+(n+1)/2<<" "<<i+k+n<<" "<<k+2*n+1+2*i<<"\n";
    }
  }else{
    rep(i,0,n/2){
      std::cout<<i+k<<" "<<i+k+3*n/2<<" "<<k+2*n+1+2*i<<"\n";
      std::cout<<i+k+n/2<<" "<<i+k+n<<" "<<k+2*n+2*i<<"\n";
    }
  }

  return 0;
}

Measured memory_bytes: 2304
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#define rip(i,n) for(int i=0;i<n;i++)
#define ll long long
#define lb long double
#define vec vector<int>
using namespace std;
int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if ((((((c - 1) / b) + 1) * 2) - 1) > (((a - 1) / d) + 1) * 2)cout << "No" << endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 3620
#include<stdio.h>
int main(void){
    int a,b,s;
    scanf("%d%d",&a,&b);
    if(a<b){
        s=a;
        a=b;
        b=s;
    }
    for(;;){
        if(b==0)break;
        s=a%b;
        a=b;
        b=s;
    }
    printf("%d\n",a);
    return 0;
}


Measured memory_bytes: 2056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ProgramingStudying2
{
    class Program
    {
        static void Main(string[] args)
        {
            var nw = Console.ReadLine().Split();
            var n = int.Parse(nw[0]);
            var W = int.Parse(nw[1]);

            var w = new int[n];
            var v = new long[n];

            for(int i = 0; i < n; i++)
            {
                var wv = Console.ReadLine().Split();
                w[i] = int.Parse(wv[0]);
                v[i] = long.Parse(wv[1]);
            }
            const long INF = (long)1e9 + 7;

            //i番目までの荷物から価値j以上となるように取った時の重さの総和の最小値
            var dp = new long[n + 1, 100001];
            for(int i = 0; i <= n; i++)
            {
                for(int j = 0; j <= 100000; j++)
                {
                    dp[i, j] = INF;
                }
            }
            dp[0, 0] = 0;

            for(int i = 1; i <= n;i++)
            {
                for(int j = 0; j <= 100000; j++)
                {
                    if (j - v[i - 1] >= 0)
                    {
                        dp[i, j] = Math.Min(dp[i - 1, j], dp[i - 1, j - v[i - 1]] + w[i - 1]);
                    }
                    else
                    {
                        dp[i, j] = dp[i - 1, j]; 
                    }
                }
            }

            var ans = 100000;
            while(dp[n,ans] > W)
            {
                ans--;
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 106488
m,d=map(int,input().split())
ans=0
for i in range(1,m+1):
  for j in range(1,d+1):
    a=int(str(j)[0])
    if j//10==0:
      b=1
    else:
      b=int(str(j)[1])
    if a*b==i and 1<a and 1<b:
      ans+=1
print(ans)

Measured memory_bytes: 3060
N = int(input())
def solve(N):
    if N == 1: return 1
    l = [0] * (N+1)
    l[0] = 2
    l[1] = 1
    for i in range(2, N+1):
        l[i] = l[i-1] + l[i-2]
    return l[N]
print(solve(N))

Measured memory_bytes: 3060
N = int(input())
B = False
kaisu = 0
array = list(map(int,input().split()))

def calc(n):
  return int(n) / 2
  
  
while not B:
  for i in array:
    if i % 2 == 1:
      B = True
  if not B:
    array = list(map(calc, array))
    kaisu += 1
  else:
    break
        
print(kaisu)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    deque<int> d;
    for(int i = 0; i < n; i++) {
        int ai;
        cin >> ai;
        if((n ^ i) % 2) {
            d.push_front(ai);
        } else {
            d.push_back(ai);
        }
    }
    for(int x : d) {
        cout << x << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3072
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      ret += a[i] * a[j];
    }
  }
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define ll long long int
#define v vector
#define MP make_pair
#define F first
#define S second
#define M 1000000007
#define endl "\n"
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

template<typename T>
inline void print(v<T >&a){
	for(int i=0;i<a.size();i++)
		cout<<a[i]<<" ";
	cout<<endl;
}

template<typename T>
inline void inp(v<T >&a){
	for(int i=0;i<a.size();i++){
		cin>>a[i];
	}
}

template <typename T>inline void out(T t){cout << t << " " ;}
template<typename T, typename... A>
inline void out(T t, A... args){
	cout << t <<" " ;out(args...);
}

int main(){
	fastio();
	string s;
	cin>>s;
	int ans=0,t=0;
	for(int i=0;i<3;i++){
		if(s[i]=='S')t=0;
		if(s[i]=='R')t++;
		ans=max(ans,t);
	}
	cout<<ans<<endl;
		
return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n,m,a;
  cin >> n;
  while(n!=0){
    int i,j,k,l;
    int v[51][31]={{}};
    for(i=0;i<n;i++){
      cin >> m;
      for(j=0;j<m;j++){
	cin >> a;
	v[i][a]=1;
      }
    }
    vector <int> g[51];
    vector <int> p[51];
    for(i=0;i<n;i++) g[i].push_back(i);
    bool f =false,x;
    for(i=1;i<31;i++){
      //cout << "day" << i << endl;
      for(k=0;k<n;k++) {
	sort(g[k].begin(),g[k].end());
	g[k].erase(unique(g[k].begin(), g[k].end()), g[k].end());
	p[k].clear();
	for(l=0;l<g[k].size();l++) p[k].push_back(g[k][l]);
	//for(l=0;l<p[k].size();l++) cout << p[k][l] << " ";
	//cout << endl;
      }
      for(j=0;j<n;j++){
	if(v[j][i]==0) continue;
	for(k=j+1;k<n;k++){
	  if(v[k][i]==0) continue;
	  //cout << i << ":" << j << ":" << k << endl;
	  for(l=0;l<p[j].size();l++) g[k].push_back(p[j][l]);
	  for(l=0;l<p[k].size();l++) g[j].push_back(p[k][l]);
	}
      }
      bool li[51];
      for(j=0;j<n;j++) {
	for(k=0;k<n;k++) li[k]=false;
	for(k=0;k<g[j].size();k++) {
	  //cout << g[j][k] << " ";
	  li[g[j][k]]=true;
	}
	//cout << endl;
	x=true;
	for(k=0;k<n;k++) if(!li[k]) x=false;
	if(x){
	  f=true;
	  break;
	}
      }
      if(f) {
	cout << i << endl;
	break;
      }
    }
    if(!f) cout << -1 << endl;
    cin >> n;
  }
}

Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  int count = 0;
  int s[5];
  int div[5] = {10, 100, 1000, 10000, 100000};
  
  cin >> A >> B;
  
  for ( int i = A; i <= B ; i++ ) {
    
    for( int j = 0; j < 5; j++ ) {
      s[j] = ( i - i / div[j] * div[j] ) / ( div[j] / 10 );
    }
    
    if ( s[0] == s[4] && s[1] == s[3] ) {
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
import math

def koch(n, a, b):
    if n == 0: return

    s, t, u = [0, 0], [0, 0], [0, 0];
    th = math.pi * 60.0 / 180.0;

    s[0] = (2.0 * a[0] + 1.0 * b[0]) / 3.0
    s[1] = (2.0 * a[1] + 1.0 * b[1]) / 3.0
    t[0] = (1.0 * a[0] + 2.0 * b[0]) / 3.0
    t[1] = (1.0 * a[1] + 2.0 * b[1]) / 3.0
    u[0] = (t[0] - s[0]) * math.cos(th) - (t[1] - s[1]) * math.sin(th) + s[0]
    u[1] = (t[0] - s[0]) * math.sin(th) + (t[1] - s[1]) * math.cos(th) + s[1]

    koch(n - 1, a, s)
    print "%.8f %.8f" % (s[0], s[1])

    koch(n - 1, s, u);
    print "%.8f %.8f" % (u[0], u[1])

    koch(n - 1, u, t)
    print "%.8f %.8f" % (t[0], t[1])

    koch(n - 1, t, b);

def main():
    a, b = [0, 0], [0, 0]

    n = int(raw_input())

    a[0], a[1] = 0, 0
    b[0], b[1] = 100, 0;

    print "%.8f %.8f" % (a[0], a[1])
    koch(n, a, b);
    print "%.8f %.8f" % (b[0], b[1])

main()

Measured memory_bytes: 6728
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  // ios_base::sync_with_stdio(false);
  // cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vvl A = VVL(9, N, 0);
  REP(j, N) {
    ll x, y, z;
    cin >> x >> y >> z;
    REP(p, 8) {
      ll i = p;
      ll score = 0;
      score += (i % 2 == 0) ? x : (-x);
      i /= 2;
      score += (i % 2 == 0) ? y : (-y);
      i /= 2;
      score += (i % 2 == 0) ? z : (-z);
      A[p][j] = score;
    }
  }
  REP(i, 8) sort(ALL(A[i]), REV(ll));
  ll ans = 0;
  REP(i, 8) {
    ll score = 0;
    REP(j, M) { score += A[i][j]; }
    ans = max(score, ans);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int a,b,c; cin>>a>>b>>c;
	int v=(c/a)*a;
	if(v>=b)cout<<"OK\n";
	else cout<<"NG\n";
}

Measured memory_bytes: 3652
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.NoSuchElementException;

public class Main {

	void solve() {
		n = in.nextInt();
		a = in.nextInt();
		ret = n*n-a;
		out.println(ret);
	}

	// only call
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

	// predefined
	FastScanner in = new FastScanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	int n, m, a, b, c, d, e, f;
	int ret;
	ArrayList<Integer> list = new ArrayList<>();
	ArrayDeque<Integer> q = new ArrayDeque<>();

	// 2D-map
	int H, W;
	final int[] dw = new int[] { 0, 1, 0, -1, 1, 1, -1, -1 };
	final int[] dh = new int[] { 1, 0, -1, 0, 1, -1, 1, -1 };

	boolean inField(int nw, int nh) {
		if (nw < 0 || nw >= W || nh < 0 || nh >= H) {
			return false;
		}
		return true;
	}

	// Yes/No
	static String yesno(boolean f) {
		return yesno(f, "Yes", "No");
	}

	static String yesno(boolean f, String yes, String no) {
		return (f ? yes : no);
	}

	// library
	class FastScanner {
		private final InputStream in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		FastScanner(InputStream in) {
			this.in = in;
		}

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

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

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

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

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

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

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

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

Measured memory_bytes: 22996
S = input()

ans = 'AC'

if S[0] != 'A' or S[2:-1].count('C') != 1:
    ans = 'WA'

S = list(S)
if S.count('C')>0:
    S.remove('C')

if (''.join(S[1:])).islower() == False:
    ans = 'WA'

print(ans)

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

int main(){
	int N;
	cin >> N;
	
	vector<int> vec(N);

    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }

    int count=1;
    sort(vec.begin(), vec.end());

    for(int i=0;i<N-1;i++){
        if(!(vec.at(i)==vec.at(i+1))){
            count++;
        }
    }
	
    cout << count << endl;
	
}


Measured memory_bytes: 256
Q, H, S, D = map(int, input().split())
N = int(input())

nQ = 4 * Q
nH = 2 * H
nS = S
nD = D / 2

if nD < min(nQ, nH, nS):
    ans = D * (N // 2) + min(nQ, nH, nS) * (N - (N // 2) * 2)
else:
    ans = min(nQ, nH, nS) * N
print(ans)


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

int n,x[81019];
int a[81019],b[81019];
signed main(){
	cin>>n;
	rep(i,n){
		int c;cin>>c;
		x[c]=i;
	}
	rep(i,n){
		a[i]=40000*(i+1);
		b[i]=40000*(n-i)+x[i+1];
	}
	rep(i,n)cout<<a[i]<<" ";
	cout<<endl;
	rep(i,n)cout<<b[i]<<" ";
	cout<<endl;
}


Measured memory_bytes: 1152
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<functional>
#include<math.h>

using namespace std;

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

	string s;
	int k;
	cin >> s >> k;

	set<string> sub;

	for(int i=1;i<=5;i++){
		for(int j=0;j<s.size();j++){
			sub.insert(s.substr(j,i));
		}
	}
	auto itr = sub.begin();

	for(int i=1;i<k;i++) itr++;

	cout << *itr << "\n";
	
	return 0;
}

Measured memory_bytes: 1664