akhauriyash/Code-Regression huggingface dataset:
public class Main {
     
    public void run(java.io.InputStream in, java.io.PrintStream out) {
        final java.util.Scanner sc = new java.util.Scanner(in);
        long[][] a;
        long[][] b;
        long[][] r;
        int n, m, l;
 
        n = sc.nextInt();
        m = sc.nextInt();
        l = sc.nextInt();
        a = new long[n][m];
        b = new long[m][l];
        for (int i = 0; i < n; ++i)
        for (int j = 0; j < m; ++j) {
            a[i][j] = sc.nextLong();
        }
        for (int i = 0; i < m; ++i)
        for (int j = 0; j < l; ++j){
            b[i][j] = sc.nextLong();
        }
         
        r = new long[n][l];
        for (int i = 0; i < n; ++i)
        for (int j = 0; j < l; ++j) {
            r[i][j] = 0;
            for (int k = 0; k < m; ++k) {
                r[i][j] += a[i][k] * b[k][j];
            }
        }
         
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < l; ++j) {
                out.print(r[i][j]);
                if (j + 1 == l) out.println();
                else out.print(" ");
            }
        }
                 
        sc.close();
    }
 
    public static void main(String[] args) {
        (new Main()).run(System.in, System.out);
    }
 
}


Measured memory_bytes: 53824
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll n, sum = 0;
  cin >> n;
  map<ll, ll> mp;
  rep(i, n) {
    ll a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  ll q;
  cin >> q;
  rep(_, q) {
    ll b, c;
    cin >> b >> c;
    mp[c] += mp[b];
    sum += mp[b] * (c - b);
    mp.erase(b);
    cout << sum << endl;
  }
}

Measured memory_bytes: 7540
#include <stdio.h>
#include <string.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define mp make_pair

#define INF (1LL<<60)

struct MinCostFlow {
    static const int N=1024*4, M=1024*16;
    typedef long long cost_t;
    int E, head[N], u[M], v[M], capa[M], rev[M], next[M];
    cost_t cost[M];
    int s, t, flow[M], prev[N];
    cost_t r, h[N], dist[N];
    void init() { E=0; memset(head, -1, sizeof(head)); }
    void add_edge(int _u, int _v, int ca, cost_t co) {
        u[E]=_u; v[E]=_v; capa[E]=ca; cost[E]=co; rev[E]=E+1, next[E]=head[u[E]]; head[u[E]]=E; E++;
        u[E]=_v; v[E]=_u; capa[E]=0; cost[E]=-co; rev[E]=E-1, next[E]=head[u[E]]; head[u[E]]=E; E++;
    }
    void ready(int _s, int _t) {
        s=_s; t=_t;
        r=0;
        memset(flow, 0, sizeof(flow));
        memset(h, 0, sizeof(h));
    }
    cost_t min_cost() { return r; }
    bool pour(int f) {
        while(f>0) {
            priority_queue<pair<cost_t, int> > q;
            std::fill_n(dist, N, INF);
            dist[s]=0;
            q.push(mp(0, s));
            while(!q.empty()) {
                pair<cost_t, int> z(q.top());
                q.pop();
                int cur=z.second;
                if(dist[cur]<-z.first) continue;
                for(int x=head[cur]; x!=-1; x=next[x]) if(capa[x]-flow[x]>0) {
                    if(dist[v[x]]>dist[cur]+cost[x]+h[cur]-h[v[x]]) {
                        dist[v[x]]=dist[cur]+cost[x]+h[cur]-h[v[x]];
                        prev[v[x]]=x;
                        q.push(mp(-dist[v[x]], v[x]));
                    }
                }
            }
            if(dist[t]==INF) return false;
            rep(i, N) h[i]+=dist[i];
            int d=f;
            for(int cur=t; cur!=s; cur=u[prev[cur]]) {
                d=min(d, capa[prev[cur]]-flow[prev[cur]]);
            }
            f -= d;
            r += d*h[t];
            for(int cur=t; cur!=s; cur=u[prev[cur]]) {
                flow[prev[cur]]+=d;
                flow[rev[prev[cur]]]-=d;
            }
        }
        return true;
    }
} mcf;

int N, A[1000], B[1000];

int indexOf(const vector<int>& v, int val) {
    return lower_bound(v.begin(), v.end(), val)-v.begin();
}

int main() {
    scanf("%d", &N);
    rep(i, N) scanf("%d%d", A+i, B+i);
    vector<int> v;
    rep(i, N) {
        v.push_back(A[i]);
        v.push_back(B[i]);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    const int BIAS = 2000000;
    mcf.init();
    rep(i, N) {
        mcf.add_edge(0, 2+i, 1, 0);
        mcf.add_edge(2+i, 2+N+indexOf(v, B[i]), 1, BIAS-A[i]);
        mcf.add_edge(2+i, 2+N+indexOf(v, A[i]), 1, BIAS-B[i]);
    }
    rep(i, v.size()) {
        mcf.add_edge(2+N+i, 1, 1, 0);
    }
    mcf.add_edge(0, 1, N, BIAS);
    mcf.ready(0, 1);
    mcf.pour(N);
    printf("%d\n", BIAS*N-(int)mcf.min_cost());
    return 0;
}

Measured memory_bytes: 0
N = int(input())
v = [[0]*3 for _ in range(N)]
for i in range(N):
  a = list(map(int,input().split()))
  for k in range(3):
    v[i][k] = a[k]
dp = [[0]*3 for _ in range(N+1)]
for i in range(1, N+1):
  for j in range(3):
    for k in range(3):
      if j != k:
        dp[i][j] = max(dp[i][j], dp[i-1][k] + v[i-1][j])
print(max(dp[N]))

Measured memory_bytes: 42536
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n, k;
	cin>>n>>k;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=k+1;i<=n;i++){
		if(a[i]>a[i-k]) cout<<"Yes\n";
		else cout<<"No\n";
	}
}

Measured memory_bytes: 4420
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(){
  int N;
  scanf("%d",&N);
  int n;
  int A[N];
  int odd_count=0;
  int even_count=0;
  for(n=0;n<N;n++){
    scanf("%d",&A[n]);
  }
  for(n=0;n<N;n++){
    if(A[n] % 2 ==0){
      even_count++;
    }
    else{
      odd_count++;
    }
  }
  printf("%d",(int)(pow(3,N)-pow(2,even_count)));


}


Measured memory_bytes: 128
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long int ll;

char a,b;

int main(){
    cin>>a>>b;
    cout<<(int(a)<int(b) ? "<":int(a)>int(b) ? ">":"=")<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

typedef long long ll;

#define min(a, b) ((a) < (b)) ? (a) : (b)
#define max(a, b) ((a) > (b)) ? (a) : (b)
#define swap(a, b, typ) \
    do { \
        typ tmp = a; \
        a = b; \
        b = tmp; \
    } while (0)

#define MAX_N 100

int main(void) {
    int n;
    char s1[MAX_N + 2], s2[MAX_N + 2];

    scanf("%d\n", &n);

    if (n % 2 == 1) {
        printf("No\n");
        return 0;
    }

    fgets(s1, n + 1, stdin);
    s1[n] = '\0';
    strncpy(s2, s1 + n / 2, n / 2 + 1);
    s1[n / 2] = '\0';

    if (strcmp(s1, s2) == 0) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, n) for (ll i = 0; i < n; i++)
#define REPR(i, n) for (ll i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll h, w, l, sx, sy, gx, gy;
string t[2100000];
ll v1[4] = { 0,0,1,-1 }, v2[4] = { 1,-1,0,0 };

#define PP pair<ll, P>
int main() {
    cin >> h >> w >> l;
    vector<vector<ll>> s(h, vector<ll>(w, INF));
    vector<vector<ll>> used1(h, vector<ll>(w, INF));
    vector<vector<ll>> used2(h, vector<ll>(w, INF));
    cin >> sx >> sy >> gx >> gy;
    sx--;
    sy--;
    gx--;
    gy--;
    REP(i, h){
        cin >> t[i];
    }
    priority_queue<PP, vector<PP>, greater<PP>> q;
    s[sx][sy] = 0;
    q.push(PP(0, P(sx, sy)));
    while (!q.empty()) {
        PP now = q.top();
        q.pop();
        ll a = now.second.first, b = now.second.second;
        if (s[a][b] < now.first) continue;
        //cout << a << " ! " << b << endl;
        REP(nxt, 4) {
            if (nxt <= 1) used1[a][b] = min(used1[a][b], s[a][b] + 1);
            if (nxt >= 2) used2[a][b] = min(used2[a][b], s[a][b] + 1);
            REPO(j, l){
                // cout << nxt << " " << j << endl;
                ll x = a + v1[nxt] * j, y = b + v2[nxt] * j;
                if (0 > x or x >= h or 0 > y or y >= w) break;
                if(t[x][y] == '@') break;
                //cout << nxt << " !! " << j << endl;
                if (nxt <= 1 and used1[x][y] < s[a][b] + 1) break;
                if (nxt >= 2 and used2[x][y] < s[a][b] + 1) break;
                if (nxt <= 1) used1[x][y] = min(used1[x][y], s[a][b] + 1);
                if (nxt >= 2) used2[x][y] = min(used2[x][y], s[a][b] + 1);
                if(s[x][y] > s[a][b] + 1){
                    s[x][y] = s[a][b] + 1;
                    q.push(PP(s[x][y], P(x, y)));
                }
            }
        }
    }
    /*
    REP(i, h){
        REP(j, w){
            cout << (s[i][j] >= INF ? -1 : s[i][j]) << " ";
            
        }
        cout << endl;
    }
    */
    cout << (s[gx][gy] >= INF ? -1 : s[gx][gy]) << endl;
}


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

int main(void){
    int a,b;
    char op;
    while(1){
        cin >> a;
        cin >> op;
        cin >> b;
        if(op == '+'){
            cout << a + b << endl;
        } else if(op == '-' ){
            cout << a - b << endl;
        } else if(op == '*'){
            cout << a * b <<endl;
        } else if(op == '/'){
            cout << a / b << endl;
        } else {
            break;
        }
    }    
    return 0;
}


Measured memory_bytes: 3080
/**
 * 
 * 1 <= N <= 10^5
 * 0 <= M <= N - 1
 * 1 <= a1
 */

#include <iostream>
#include <math.h>
#define INF 100000000
#define MOD 1000000007
using namespace std;

int main(){
    int N, M;
    int a[1000000] = {0};

    cin >> N;
    cin >> M;
    for(int i = 0; i < M; i++) cin >> a[i];

    long DP[100001] = {0};
    int j = 0;

    DP[0] = 1;
    for(int i = 1; i <= N; i++){
        if(a[j] == i){
            DP[i] = 0;
            j++;
            continue;
        }
        if(i == 1) DP[i] = DP[i - 1];
        else DP[i] = (DP[i - 1] + DP[i - 2]) % MOD;
    }
    
    cout << DP[N] << endl;
}

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

void MySwap(int &a, int &b){
  int tmp = a;
  a = b;
  b = tmp;
}
  

int partition(int *A, int p, int r){
  int x = A[r];
  int i = p - 1;
  for(int j = p; j < r; j++){
    if(A[j] <= x){
      MySwap(A[++i], A[j]);
    }
  }
  MySwap(A[++i], A[r]);
  return i;
}

int main(){
  int A[100000], n, place;
  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];
  place = partition(A, 0, n-1);
  for(int i = 0; i < n; i++)
    cout << (i==place?"[":"") << A[i] << (i==place?"]":"") << (i==n-1?'\n':' ');
  return 0;
}


Measured memory_bytes: 3472
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
using namespace std;
typedef long long ll;
ll get(ll n){ll ret=0;while(n){n/=10;ret++;}return ret;}
int main(){
    ll i,n,ans=233;
    cin>>n;
    for(i=1;i*i<=n;i++)
        if(n%i==0) ans=min(ans,get(n/i));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>

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

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

#define int long long

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

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

int n;
ll a[500000];
vector<int> graph[500000];
ll mark[500000];

ll dfs(int v)
{
    mark[v] = 1;
    ll leaf = 0;
    int t = 0;
    ll max_leaf = 0;
    for (auto u : graph[v])
    {
        if (mark[u] == 0)
        {
            ll x = dfs(u);
            leaf += x;
            max_leaf = max(max_leaf, x);
            t = 1;
        }
    }
    if (t == 0)
    {
        return a[v];
    }
    if (leaf < a[v])
    {
        cout << "NO";
        exit(0);
    }
    long long r = leaf - a[v];
    long long up = leaf - 2 * r;
    if (up < 0)
    {
        cout << "NO";
        exit(0);
    }
    if (max_leaf * 2 > leaf + up)
    {
        cout << "NO";
        exit(0);
    }
    return up;
}

signed main()
{
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    if (n == 2)
    {
        if (a[1] == a[2])
        {
            cout << "YES";
        }
        else
        {
            cout << "NO";
        }
        return 0;
    }
    for (int i = 0; i < n - 1; i++)
    {
        int v, u;
        cin >> v >> u;
        graph[v].push_back(u);
        graph[u].push_back(v);
    }
    int v = 0;
    for (int i = 1; i <= n; i++) if (graph[i].size() > 1) v = i;
    if (dfs(v) == 0)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}


Measured memory_bytes: 24832
#include<stdio.h>


int main(){
  int i,j,k,tmp,N,A[100];


  scanf("%d", &N);
  for(i = 0;i<N;i++) scanf("%d", &A[i]);

  for(i=0;i<N;i++){
    if(i>0)printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");



for(i=1;i<N;i++){

  tmp=A[i];
  j=i-1;
  while(j>=0 && A[j]> tmp){

    A[j+1]=A[j];

    j--;
  }

  A[j + 1]=tmp;

 for(k=0;k<N;k++){
    if(k>0)printf(" ");
    printf("%d",A[k]);
  }
  printf("\n");
 }

  
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>

using namespace std;

class Dice{
public:
    int dice[6];

    void move(char c){
        int tmp;
        switch(c){
            case('S'):
                tmp = dice[5];
                dice[5] = dice[1];
                dice[1] = dice[0];
                dice[0] = dice[4];
                dice[4] = tmp;
                break;
            case('N'):
                tmp = dice[5];
                dice[5] = dice[4];
                dice[4] = dice[0];
                dice[0] = dice[1];
                dice[1] = tmp;
                break;
            case('E'):
                tmp = dice[5];
                dice[5] = dice[2];
                dice[2] = dice[0];
                dice[0] = dice[3];
                dice[3] = tmp;
                break;
            case('W'):
                tmp = dice[5];
                dice[5] = dice[3];
                dice[3] = dice[0];
                dice[0] = dice[2];
                dice[2] = tmp;
                break;
        }
    }
};

int main()
{
    Dice dice;

    for(int i=0; i<6; ++i){
        cin >> dice.dice[i];
    }
    int n;
    cin >>n;
    for(int i=0; i<n; ++i){
        int top, mae;
        cin >> top >> mae;
        for(int s=0; s<4; ++s){
            dice.move('S');
            for(int e=0; e<4; ++e){
                dice.move('E');
                for(int n=0; n<4; ++n){
                    dice.move('N');
                    if( top == dice.dice[0] and mae== dice.dice[1]){
                        cout << dice.dice[2] << endl;
                        goto dend;
                    }
                }
            }
        }
        dend:
        ;
    }

    return 0;
}


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

int main() {
	int sx, sy, tx, ty;
	
	cin >> sx >> sy >> tx >> ty;

	for (int i = 0; i < tx - sx; i++)cout << "R";
	for (int j = 0; j < ty - sy; j++)cout << "U";
	for (int i = 0; i < tx - sx; i++)cout << "L";
	for (int j = 0; j < ty - sy; j++)cout << "D";

	cout << "D";
	for (int i = 0; i < tx - sx+1; i++)cout << "R";
	for (int j = 0; j < ty - sy+1; j++)cout << "U";
	cout << "LU";
	for (int i = 0; i < tx - sx+1; i++)cout << "L";
	for (int j = 0; j < ty - sy+1; j++)cout << "D";
	cout << "R";
}

Measured memory_bytes: 256
# from sys import stdin

# # 解説のコード
# def get_result(data):
#     N, X, Y = data
#     dist_cnt = [0 for i in range(N)]
#     for i in range(1, N+1):
#         for j in range(i+1, N+1):
#             min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
#             dist_cnt[min_dist] += 1
#     for i in range(1, N):
#         print(dist_cnt[i])


# if __name__ == '__main__':
#     data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
#     get_result(data)

from sys import stdin
from collections import deque


# 重みなしグラフの隣接リスト
# 0-indexed nodes
def get_adj_list(num_nodes, data, undirected=True):
    graph = [[] for _ in range(num_nodes)]
    for val in data:
        x, y = val
        graph[x-1] = graph[x-1] + [y-1]
        if undirected:
            graph[y-1] = graph[y-1] + [x-1]
    return graph


# BFS
def breadth_first_search(adj_list, start_node):
    N = len(adj_list)
    order = [-1] * N # a bfs ordering of each vertex
    parent = [-1] * N # parent of each vertex in the bfs search tree
    depth = [-1] * N # the depth of each vertex
    q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
    num = 0 # current ordering
    while q:
        v, p, d = q.popleft()
        if order[v] < 0: # visited v for the first time
            order[v] = num
            parent[v] = p
            depth[v] = d
            num += 1
            for u in adj_list[v]:
                if order[u] >= 0: continue
                q.append((u, v, d+1))
    return order, parent, depth

# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    adj_list = get_adj_list(N, _data)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        _, _, depth = breadth_first_search(adj_list, i)
        for j in range(i, N):
            dist_cnt[depth[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)


Measured memory_bytes: 53212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k,r,s,p;
typedef struct{
    string t;
    int flag;
}Str;
ll score(char c){
    if(c=='r') return p;
    else if(c=='s') return r;
    else return s;
}
int main(void){
    
    cin >> n >> k >> r >> s >> p;
    string t; cin >> t;
    int used[100001] ={0};
    ll sum = 0;
    for(int i=0;i<t.size();i++){
        if(i<k) sum+=score(t[i]),used[i]=1;
        else{
            if(used[i-k]&&t[i]==t[i-k]);
            else sum+=score(t[i]),used[i]=1;
        }
        //cout << sum << endl;
    }
    cout << sum << endl;
}




Measured memory_bytes: 896
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define MAX(X, Y) (((X) > (Y))? (X) : (Y))
#define MIN(X, Y) (((X) < (Y))? (X) : (Y))
int compare_int(const void *a, const void *b){
  return *(long int*)b - *(long int*)a; // 大きい順
}
int compare_int_small(const void *a, const void *b){
  return *(long int*)a - *(long int*)b; // 小さい順
}
// 公約数
long long int gcd(long long int a, long long int b){
  if(b == 0){
    return a;
  }else{
    return gcd(b, a % b);
  }
}
// 最小公倍数 = a * b / 最大公約数
// 公倍数
long long int lcm(long long int a, long long int b){
  return a * b / gcd(a, b);
}

#define TRUE 1
#define FALSE 0
#define MAX_NUM 101
int top = 0;
int x = 0;
int *Stack = NULL;
char *S = NULL;

void initialize(){
  // Stackにはint型の数値のみ入れる。演算子は入ることがない
  Stack = (int *)malloc(MAX_NUM * sizeof(int));
  top = 0;
}

void finalize(){
  if(Stack != NULL){
    free(Stack);
    // 今まで確保していた領域を今後辿れないようにNULLとしておく
    Stack = NULL;
  }
}

int isEmpty(){
  if(top < 0){
    return TRUE;
  }else{
    return FALSE;
  }
}

int isFull(){
  if(top >= MAX_NUM - 1){
    return TRUE;
  }else{
    return FALSE;
  }
}

int push(int x){
  //  printf("push x = %d\n",x);
  if(isFull() != FALSE){
    //    fprintf(stderr, "pushしたのは%d top = %d\n", Stack[top], top);
    printf("Error! Overfllow\n");
    return 0;
  }else{
    top++;
    if(Stack != NULL){
      Stack[top] = x;
    }
    return 0;
  }
}

int  pop(){
  if(isEmpty() != FALSE){
    printf("Error! Underfllow\n");
    return 0;
  }else{
    top--;
    // return では取りだす値を返す
    //    fprintf(stderr, "popしたのは%d top = %d\n", Stack[top + 1], top);
    return Stack[top+1];
  }
}

// 10min
int main(void){
  char *ptr = NULL;
  int num = 0;
  long int ans = 0;
  initialize();

  // malloc 追加。追加したら2つ目のサンプルNGになった。4以降取り込まない
  // 10^6の数字は7Byte * 100
  // 演算子は1Byte * 100
  // 空白は 1 Byte * 100
  // 余裕を見て、倍の2000
  S = (char *)malloc(2000 * sizeof(char));
  // mallocでは欲しい個数(ここでは2000)とそのサイズ(ここではsizeof(char))をかけ算して確保したい領域を指定すると良い
  //  S = (char *)malloc(1000000001);
  if(S == NULL){
    printf("メモリが確保できません\n");
    exit(EXIT_FAILURE);
  }
  
  fgets(S, 2000, stdin);
  //　なぜかSに文字列が途中までしか取り込めてない。謎。<- fgetsのやり方がよくなかった
  //  printf("aa %s\n", S);
  ptr = strtok(S, " ");
  //  fprintf(stderr, "まずpushする %s\n", ptr);
  // 分解したけど、え、記号と数値わけるよね、、あ。演算子は3つだけ
  // 違う。文字列思ったように取得できてない。
  num = atoi(ptr);

  push(num);

  while(ptr != NULL){
    ptr = strtok(NULL, " ");
    if(ptr != NULL){
      //      printf("%s\n", ptr);
      // 演算子かそうでないかで処理をわける
      if(*ptr == '+' || *ptr == '-' || *ptr == '*'){
	long int a, b;

        //fprintf(stderr, "演算子！popする！ %c\n", *ptr);
	a = pop();
	b = pop();
	if(*ptr == '+'){
	  ans = b + a;
	}else if(*ptr == '-'){
	  ans = b - a;
	  //	  printf("b - a = %ld\n", ans);
	}else if(*ptr == '*'){
	  ans = b * a;
	}
	push(ans);
      }else{
	//fprintf(stderr, "数値！pushする！%d\n", atoi(ptr));
	num = atoi(ptr);
	push(num);
      }      
    }
  }
  // ansの位置を間違えてた。while文の中にあった
  ans = pop();
  free(S);

  // 一旦やってみたけど違う、、、
  printf("%ld\n", ans);
  finalize();

  return 0;
}



Measured memory_bytes: 2088
#include <iostream>
#include <string>
using namespace std;
int main(){
    string a,b,c; cin >> a >> b >> c;
    int alen = a.size();
    int blen = b.size();
    if(a[alen-1] == b[0] && b[blen-1] == c[0]) puts("YES");
    else puts("NO");
    return 0;
}

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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



// Main Code

ll dp[N];
unordered_set<ll> s;

ll findans(ll curr)
{
	if(curr < 0) return 0;
	if(dp[curr] != -1) return dp[curr];
	return dp[curr] = (findans(curr-1) + findans(curr-2)) % M;
}

int main()
{
	ll n, m;
	cin>>n>>m;
	memset(dp, -1, sizeof(dp));
	dp[0] = 1;
	rep(i, 0, m)
	{
		ll x;
		cin>>x;
		dp[x] = 0;
	}
	cout<<findans(n)<<endl;
	// cout<<findans(n-1)<<" "<<findans(n-2)<<endl;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>  // ios_base::sync_with_stdio(false);

#define MAXN 500005          // cin.tie(NULL);
#define di pair<int, int>
#define tri pair<int, di>
#define bi pair<bool, int>
using namespace std;
void swap(int ar[],int  i,int j)
    {int aux = ar[j]; ar[j] = ar[i]; ar[i] = ar[j];}

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<long long> fila;
    di ops[m];

    for(int k = 0; k < n; k++){
        long long a;
        cin >> a;
        fila.push(-a);
    }
        
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        ops[i].first = b; 
        ops[i].second = a;

    }

    sort(ops, ops+m);
    reverse(ops, ops+m);

    for(int k = 0; k < m; k++){
        
        
        for(int i = 0; i < ops[k].second; i++){
            if(fila.top() > -ops[k].first){
                fila.pop();
                fila.push(-ops[k].first);
            }
            else{
                break;
            }
        }
    }

    long long suma = 0;
    for(int i = 0; i < n; i++){
        long long a = fila.top();
        fila.pop();
        suma += a;
    }

    cout << -suma;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;cin >> n;
  vector<int> a(n);
  vector<pair<int,int>> ans;
  int l=1e7,h=-1e7;
  int li,ri;
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(l>a[i]){
      l=a[i];
      li=i;
    }
    if(h<a[i]){
      h=a[i];
      ri=i;
    }
  }
  if(abs(h)>=abs(l)){
    if(l<0){
      for(int i=0;i<n;i++){
        if(a[i]<0){
          ans.push_back(make_pair(ri+1,i+1));
          a[i]+=a[ri];
        }
      }
    }
    for(int i=0;i<n-1;i++){
      if(a[i]>a[i+1]){
        ans.push_back(make_pair(i+1,i+1+1));
        a[i+1]+=a[i];
      }
    }
  }
  else{
    if(h>0){
      for(int i=0;i<n;i++){
        if(a[i]>0){
          ans.push_back(make_pair(li+1,i+1));
          a[i]+=a[li];
        }
      }
    }
    for(int i=n-1;i>0;i--){
      if(a[i-1]>a[i]){
        ans.push_back(make_pair(i+1,i));
        a[i-1]+=a[i];
      }
    }
  }
  cout << ans.size() << endl;
  for(int i=0;i<ans.size();i++){
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}

Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:1024000000,1024000000")
/* vim: set fdm=marker */
//{{{
#define __ return
int ATTENTION() {
	/* pls IGNORE this function and go down and HACK me
	 * read this AFTER contest
	 * this function is empty and it will not be called !
	 */

	http://codeforces.com/group/Pmz2A2x7ES
	/* I created a group there.
	 * I hope with the group, people can finish
	 * past contests, which is important for 
	 * increasing rating.
	 * I am still getting familiar with this function.
	 */
	 __ 0;
}
// deprecated because mac doesn't support this...
/* #include <bits/stdc++.h> */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int iinf = 0x7fffffff;
const ll linf = ~(1LL<<63);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef map<ll, int> mli;
typedef map<ll, ll> mll;
template<typename T>
inline T gcd(T a, T b) {
	if(a < 0) return gcd(-a, b);
	if(b < 0) return gcd( a,-b);
	if(a < b) return gcd(b, a);
	if(b == 0) return a;
	return gcd(b, a%b);
}

ll qpow(ll a, ll n, ll mod) {
	a %= mod;
	ll ans = 1LL;
	while(n) {
		if(n & 1) ans = (ans*a % mod);
		a = (a*a % mod);
		n >>= 1;
	}
	return ans;
}

inline ll rev(ll a, ll p) {
	return qpow(a, p - 2, p);
}

#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define rep(x, st, en) for(int x = st; x < en; x++)
#define rer(x, st, en) for(int x = st; x >= en; x--)
#define pb push_back
#define mp make_pair
#define dbgm(msg, var) cerr<<#msg<<" "<<#var<<" = "<<var<<endl; 
#define dbg(var) cerr<<#var<<" = "<<var<<endl;
#define X first
#define Y second
// build prefix sum
template<typename T>
inline void BPS(T* DST, T* SRC, int N, int s = 0) {
	DST[s] = SRC[s];
	rep(i, 1, N) DST[s + i] = DST[s + i - 1] + SRC[s + i];
}
inline int in() { int x; cin>>x; return x; }
#ifdef ALNDBG
namespace alndbg {
	clock_t s, e;
}
#endif

inline void tic() {
#ifdef ALNDBG
	alndbg::s = clock();
#endif
}

inline void toc() {
#ifdef ALNDBG
	alndbg::e = clock();
	cerr<<1000.0 * (alndbg::e - alndbg::s) / CLOCKS_PER_SEC<<" ms"<<endl;
#endif
}



//}}}

// -------------------- Spliters ------------------------
// BFS求最短路小心vis可能访问过
const int maxn = 10001;
ll a[maxn];
int lg2[maxn];

int main() {
  int n;
  scanf("%d", &n);
  rep(i,0,n) {
    scanf("%lld", &a[i]);
    ll q = a[i];
    while(q % 2 == 0) {
      q /= 2;
      lg2[i]++;
    }
  }

  int sum = 0;
  rep(i,0,n) sum += lg2[i];
  printf("%d\n", sum);


	return 0;
}
// --USE C++11
// *-USE O2



Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		Combination com = new Combination();
		long n=sc.nextLong();
		int a=sc.nextInt(), b=sc.nextInt();
		int mod = (int)Math.pow(10, 9) +7;
		long ans = com.pow(2, n, mod)-1;
		ans -= com.nCk(n, a, mod);
		ans -= com.nCk(n, b, mod);
		while(ans<0) {
			ans += mod;
		}
		if(n==2) {
			System.out.println(0);
		}else {
			System.out.println(ans);	
		}
		
	}
	
	
}

class Combination {
	public long nCk(long n,long k,int M) {
        long ret = 1;
        long min = Math.min(k, n-k);
        for(long i=n-min+1;i<=n;i++) {
            ret = (ret * i) % M;
        }
        for(int i=1;i<=min;i++) {
            ret = (ret * pow(i,M-2,M)) % M;
        }
        return ret;
    }

	public long pow(long a,long b,int M) {
        long ret = 1;
        long tmp = a;
        while(b>0) {
            if((b&1)==1) ret = (ret * tmp) % M;
            tmp = (tmp * tmp) % M;
            b = b>>1;
        }
        return ret;
    }
}

Measured memory_bytes: 22608
#include<cstdio>
#include<algorithm>
using namespace std;
 
int dp[10001];
int N,W;
int main() {
    scanf("%d%d",&N,&W);
 
    for(int i = 0;i < N;i++) {
        int v,w;
        scanf("%d%d",&v,&w);
        for(int j = w;j <= W;j++) {
            dp[j] = max(dp[j],dp[j - w] + v);
        }
    }
    printf("%d\n",dp[W]);
    return 0;
}


Measured memory_bytes: 2772
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
using namespace std ;

int main(){
  int N; cin>>N;
  pair<pair<string,int>,int> p[110];

  for(int i=0;i<N;i++){
    string s; int tmp; cin >>s>>tmp;
    p[i]=make_pair(make_pair(s,-tmp),i);
  }

  sort(p,p+N);

  for(int i=0;i<N;i++){
    cout<<p[i].second+1<<endl;
  }

}


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

using namespace std;

typedef long long LL;

char s[110];
int N;
char now[110],nxt[110];

bool sm(int len,char x)
{
	for (int i=0;i<len;i++)
	if (now[i] != x) return false;
	return true;
}

int check(char x)
{
	for (int i=0;i<N;i++)
		now[i] = s[i];
	int len = N;
	while(true)
	{
		if (sm(len,x)) break;
		len--;
		for (int i=0;i<len;i++)
			if (now[i] == x || now[i+1] == x)
				nxt[i] = x;
			else
				nxt[i] = '?';
		for (int i=0;i<len;i++)
			now[i] = nxt[i];
	}
	return N - len;
}

int main()
{
	scanf("%s",s);
	N = strlen(s);
	int ans = 10000;
	for (int i=0;i<N;i++) 
		ans = min(ans,check(s[i]));
	printf("%d\n",ans);
}

Measured memory_bytes: 764
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (n, m) = (v[0], v[1]);
    let mut graph = vec![(false, false); n];
    for i in 0..m {
        let v = read_vec::<usize>();
        let (a, b) = (v[0] - 1, v[1] - 1);
        if a == 0 {
            graph[b].0 = true;
        }
        if a == n - 1 {
            graph[b].1 = true;
        }
        if b == 0 {
            graph[a].0 = true;
        }
        if b == n - 1 {
            graph[a].1 = true;
        }
    }
    for (f1, f2) in graph {
        if f1 && f2 {
            println!("POSSIBLE");
            return;
        }
    }
    println!("IMPOSSIBLE");
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

int n, m;
int a[1 << 17];
vector<int> ans;

vector<int> v;
int main() {
	cin >> n >> m;
	int cnt = 0;
	rep(i, m) {
		cin >> a[i];
		if (a[i]%2) {
			cnt++; v.push_back(a[i]);
		}
	}
	if (cnt > 2) {
		cout << "Impossible" << endl;
	}
	else {
		if (cnt == 0) {
			int x = a[0];
			if (x % 2) {
				rep(i,x / 2)ans.push_back(2);
			}
			else {
				int le = 0, ri = x - 1;
				int id = 0;
				while (ri - le > 1) {
					if (id == 0) {
						le += 2;
					}
					else {
						ri -= 2;
					}
					id ^= 1;
				}
				rep(i, le / 2)ans.push_back(2);
				ans.push_back(1);
				for (int i = le + 1; i < x - 2; i += 2)ans.push_back(2);
			}
			rep1(i, m - 1) {
				ans.push_back(a[i]);
			}
			ans.push_back(1);
			//a
			rep(i, m) {
				if (i > 0)cout << " "; cout << a[i];
			}
			cout << endl;
		}
		else {
			rep(i, v[0] / 2)ans.push_back(2);
			if (cnt == 1) {
				cout << v[0];
				rep(i, m) {
					if (a[i] % 2)continue;
					cout << " " << a[i];
					ans.push_back(a[i]);
				}
				ans.push_back(1);
				cout << endl;
			}
			else {
				cout << v[0];
				rep(i, m) {
					if (a[i] % 2)continue;
					cout << " " << a[i];
					ans.push_back(a[i]);
				}
				ans.push_back(2);
				vector<int> u;
				rep(i, v[1] / 2)u.push_back(2);
				reverse(u.begin(), u.end());
				rep(i, u.size())ans.push_back(u[i]);
				cout << " " << v[1] << endl;
			}
		}
		cout << ans.size() << endl;
		rep(i, ans.size()) {
			if (i > 0)cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}
	//stop
		return 0;
}



Measured memory_bytes: 640
#include<cstdio>
#include<map>
using namespace std;
typedef long long int ll;

int h[100000];


int n;
int m;


int main(){
	int n,a[3];
	int ans[100005];
	char s[100005][5];
	scanf("%d",&n);
	for(int i=0;i<3;i++) scanf("%d",a+i);
	for(int i=0;i<n;i++) scanf("%s",s[i]);
	for(int i=0;i<n;i++){
		int l = s[i][0] - 'A';
		int r = s[i][1] - 'A';
		if(a[l]==0&&a[r]==0){
			printf("No\n");
			return 0;
		}
		if(a[l]>a[r]){
			a[r]++;
			a[l]--;
			ans[i] = 'A'+r;
		}else if(a[0]+a[1]+a[2]==2&&a[l]==1&&a[r]==1&&i<n-1){
			int la = s[1+i][0] - 'A';
			int ra = s[i+1][1] - 'A';
			if(la==l||ra==l){
			a[l]++;
			a[r]--;
			ans[i] = 'A'+l;
			}else{
			ans[i] = 'A'+r;
			a[l]--;
			a[r]++;
			}
		}else{
			a[l]++;
			a[r]--;
			ans[i] = 'A'+l;
		}
	}
	printf("Yes\n");
	for(int i=0;i<n;i++){
		printf("%c\n",(char)ans[i]);
	}
}


Measured memory_bytes: 2576
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>

using namespace std;
using ll = long long;
using ull = unsigned long long;


#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)

auto sumdig(ll num) {
	ll dig, sum;
	sum = 0;
	while (num) {
		dig = num % 10;
		sum = sum + dig;
		num = num / 10;
	}
	return sum;
}




int main() {

	int r, g, b, n;
	cin >> r >> g >> b >> n;
	int ans = 0;

	rep(i, 0, n/r+1) {
		rep(j, 0, n/g+1) {
			int cur = i * r + g * j;
			if ((n - cur >= 0)
				&& (n - cur) % b == 0) {
				ans += 1;
			}
			
		}
	}

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

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

class Program
{
	static void Main() => new Program().Solve();

	void Solve()
	{
		var x = ReadLong();
		Console.WriteLine(x >= 30 ? "Yes" : "No");
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 27540
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
#define ll long long int
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
ll n, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/


int main()
{
	ll a, b, c;
	cin >> a >> b >> c;
	if (a < c - b) {
		cout << 0 << endl;
		return 0;
	}
	if (c - b < 0) {
		cout << 0 << endl;
		return 0;
	}
	if (a == 1 && b == c) {
		cout << 1 << endl;
		return 0;
	}
	if (a == 1 && b != c) {
		cout << 0 << endl;
		return 0;
	}

	cnt = (a - 2)*(c - b) + 1;
	cout << cnt << endl;

}

Measured memory_bytes: 256
#include <iostream>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int main(){
	ll n; cin >>n;
	for(int i=1;i<=3500;i++){
		for(int j=1;j<=3500;j++){
            if(4.0*i*j-n*i-n*j==0) continue;
			int a=n*i*j/(4*i*j-n*i-n*j);
			double b=(1.0*n*i*j)/(4.0*i*j-n*i-n*j);
			if(a==b && a>0){
				cout << i << " "<< j << " "<< a << endl;
				return 0;
			}
		}
	}
}

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

int main(){
	int n[10000], x[10000], count[10000], m, i, j, k, l;
	for(m = 0; m <= 9999; m++){
		cin >> n[m] >> x[m];
		if((n[m] == 0) and (x[m] == 0)){
			break;
		}
	}
	
	for(i = 0; i <= m-1; i++){
		count[i] = 0;
		for(j = 1; j <= n[i]; j++){
			for(k = 1; k <= n[i]; k++){
				for(l = 1; l <= n[i]; l++){
					if(j+k+l == x[i] and j != k and k != l and j != l)	count[i]++;
				}
			}
		}
	}
	
	for(i = 0; i <= m-1; i++){
		cout << count[i]/6 << endl;
	}
	
	return 0;
}
 

Measured memory_bytes: 1180
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
lint a[200100],f[200100];
int main()
{
	int n;lint k;
	cin>>n>>k;
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>f[i];
	sort(a,a+n);reverse(a,a+n);
	sort(f,f+n);
	lint hi=123456789012345678LL,lo=0;
	while(hi>lo){
		lint mi=(hi+lo)/2;
		lint sum=0;
		rep(i,n){
			sum+=max(0LL,a[i]-mi/f[i]);
		}
		if(sum<=k) hi=mi;else lo=mi+1;
	}
	cout<<hi<<endl;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define all(a) (a).begin(), (a).end()

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

using ll = long long;

ll X, Y;

int main()
{
  std::cin >> X >> Y;

  if( X % Y == 0 )
  {
    puts("-1");

    return 0;
  }

  std::cout << X << std::endl;

  return 0;
}

Measured memory_bytes: 256
s=input()
s1 = []
s2 = []
ans1 = 0
ans2 = 0
for i in range(len(s)):
    if i%2 != 0:
        s1.append('0')
    else:
        s1.append('1')
for i in range(len(s)):
    if i%2 == 0:
        s2.append('0')
    else:
        s2.append('1')

for x, y in zip(s, s1):
    if x != y:
        ans1 +=1
for x, y in zip(s, s2):
    if x != y:
        ans2 +=1

print(min(ans1,ans2))

Measured memory_bytes: 10572
#include<bits/stdc++.h>
using namespace std;
using namespace std;
int main(){
    string s;
    cin>>s;
    int counter=0,ans=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='A'||s[i]=='T'||s[i]=='C'||s[i]=='G')
        {
            counter++;
        }
        else
        {
            counter=0;
        }
        ans=max(ans,counter);
    }
    cout<<ans<<endl;
    return 0;
}

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

class Dice
{
public:
	int n[6];
	
	void Input()
	{
		cin >> n[0] >> n[1] >> n[2] >> n[3] >> n[4] >> n[5];
	}
	
	void Set(int a, int b, int c, int d, int e, int f)
	{
		n[0] = a;
		n[1] = b;
		n[2] = c;
		n[3] = d;
		n[4] = e;
		n[5] = f;
	}
	
	void Roll(char c)
	{
		switch(c)
		{
			case 'N':
				Set(n[1], n[5], n[2], n[3], n[0], n[4]);
				break;
			case 'W':
				Set(n[2], n[1], n[5], n[0], n[4], n[3]);
				break;
			case 'S':
				Set(n[4], n[0], n[2], n[3], n[5], n[1]);
				break;
			case 'E': 
				Set(n[3], n[1], n[0], n[5], n[4], n[2]);
				break;
		};
	}
	
	bool operator==(Dice d)
	{
		for(int i = 0; i < 6; ++i)
		{
			if(n[i] != d.n[i])
			{
				return false;
			}
		}
		
		return true;
	}
	
	bool Equal(Dice d)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			d.Roll(cmd[i]);
			if(*this == d)
			{
				return true;
			}
		}
		
		return false;
	}
	
	int Find(int t, int f)
	{
		string cmd = "NNNNWNNNWNNNENNNENNNWNNN";
		for(int i = 0; i < cmd.length(); ++i)
		{
			Roll(cmd[i]);
			if(n[0] == t && n[1] == f)
			{
				return n[2];
			}
		}
		
		return 0;
	}
};

int main()
{
	Dice d[128];
	int N;
	cin >> N;
	
	bool diff = true;
	for(int i = 0; i < N; ++i)
	{
		d[i].Input();
		for(int j = 0; j < i && diff; ++j)
		{
			if(d[i].Equal(d[j]))
			{
				diff = false;
			}
		}
	}
	
	cout << (diff ? "Yes" : "No") << endl;
	
	return 0;
} 


Measured memory_bytes: 3216
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}



int main(){
    int H, W, K; std::cin >> H >> W >> K;
    std::vector<std::string> c(H);
    for(int i(0); i < H; ++i) std::cin >> c[i];

    std::vector<bool> ver(H), hor(W);
    int ans(0);
    for(int i(0), i_len(1 << H); i < i_len; ++i){
        for(int j(0); j < H; ++j){
            ver[j] = ((i >> j) & 1);
        }
        for(int j(0), j_len(1 << W); j < j_len; ++j){
            for(int k(0); k < W; ++k){
                hor[k] = ((j >> k) & 1);
            }
            int cnt(0);
            for(int h(0); h < H; ++h){
                for(int w(0); w < W; ++w){
                    if(ver[h] && hor[w] && c[h][w] == '#') ++cnt;
                }
            }
            if(cnt == K) ++ans;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3628
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstring>
#define reg register
#define EN std::puts("")
#define LL long long
inline LL read(){
	register LL x=0;register int y=1;
	register char c=std::getchar();
	while(c<'0'||c>'9'){if(c=='-') y=0;c=std::getchar();}
	while(c>='0'&&c<='9'){x=x*10+(c^48);c=std::getchar();}
	return y?x:-x;
}
int a[15];
inline LL add(LL x){
	a[0]=0;
	if(x==699){
		int hhhhh;
		hhhhh=3;
	}
	while(x) a[++a[0]]=x%10,x/=10;
	if(a[0]==1){
		if(a[1]==9) return 10;
		else return a[1]+1;
	}
	reg int i=1;
	while(a[i]==9||a[i]>a[i+1]){
		i++;
		if(i==a[0]) break;
	}
	if(i==a[0]&&a[i]==9){
		a[++a[0]]=1;
		while(i) a[i--]=0;
	}
	else{
		a[i]++;i--;
		while(i) a[i]=std::max(0,a[i+1]-1),i--;
	}
	LL ret=0;
	for(reg int i=a[0];i;i--) ret=ret*10+a[i];
//		std::printf("%lld\n",ret);
	return ret;
}
int main(){
	int k=read();
	reg LL ans=1;
	for(reg int i=2;i<=k;i++) ans=add(ans);
	std::printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_map>
#include <map>

//#define INF 100000000
//#define MOD (int) (1e9+7)
#define rep(i, a) for (int i = 0; i < (a); i++)
using namespace std;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    cout << n*(n-1)/2 + m*(m-1)/2 << endl;
}

Measured memory_bytes: 256