akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;
//const int MOD = 998244353;

// Lib
//

vector<int> places[210000];
ll dp[210000];
void add(ll &a, ll b){
    a += b;
    if (a >= MOD) a -= MOD;
}

int main(){
#ifdef MYLOCAL
    ifstream in("input.txt");
    cin.rdbuf(in.rdbuf());
#endif
    int N; cin >> N;
    vector<int> c(N);
    for (int i = 0; i < N; ++i) cin >> c[i];

    // places[i] := (c[j] = i となるような j の集まり)
    for (int i = 0; i < 210000; ++i) places[i].clear();
    for (int i = 0; i < N; ++i) places[c[i]].push_back(i);

    // DP
    dp[0] = 1;
    for (int i = 1; i <= N; ++i) {
        // 特に操作しない場合
        add(dp[i], dp[i-1]);

        // 操作する場合
        int color = c[i-1];
        int it = lower_bound(places[color].begin(), places[color].end(), i-1)
                 - places[color].begin(); // c[i] が color 色の何番目の要素か
        if (it > 0) {
            int j = places[color][it - 1]; // c[j] = c[i] となる j
            if ((i-1) - j > 1) add(dp[i], dp[j+1]);
        }
    }
    cout << dp[N] << endl;
}


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

int main() {
  int a;
  cin>>a;
  vector<int> b(a);
  for(int i=0;i<a;i++){
    cin>>b.at(i);
  }
  sort(b.rbegin(),b.rend());
  cout<<b.at(0)-b.at(a-1)<<endl;
}

Measured memory_bytes: 3632
while True:
    s1 = s2 = 0
    n = int(input())
    if n == 0: break
    for i in range(n):
        a, b = map(int, input().strip().split())
        if a > b:
            s1 += a + b
        elif b > a:
            s2 += a + b
        else:
            s1 += a
            s2 += b
    print(s1, s2)

Measured memory_bytes: 6716
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    int ms = n + 1, mx = -1;
    for (int y = 0; y <= n; y++)
    {
        int x = a - y, z = b - y;
        int k = n - x - y - z;
        if (x >= 0 && z >= 0 && k >= 0) ms = min(ms, y), mx = max(mx, y);
    }
    cout << mx << ' ' << ms;
    return 0;
}


Measured memory_bytes: 256
S = input()
if(S == "SUN"):
    print(7)
elif(S == "MON"):
    print(6)
elif(S == "TUE"):
    print(5)
elif(S == "WED"):
    print(4)
elif(S == "THU"):
    print(3)
elif(S == "FRI"):
    print(2)
elif(S == "SAT"):
    print(1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long int n, i, res = 0;
    map<int, pair<long int, long int> > index;
    cin >> n;
    int a[n];
    for(i=0; i<n; i++){
        cin >> a[i];
        index[a[i]].first++;
    }
    for(auto it=index.begin(); it!=index.end(); it++){
        if(it->second.first > 1){
            it->second.second += (it->second.first*(it->second.first-1))/2;
            res += it->second.second;
        }
    }
    for(i=0; i<n; i++){
        long long int temp = res;
        temp -= index[a[i]].second;
        temp += ((index[a[i]].first-1)*(index[a[i]].first-2))/2;
        cout << temp << '\n';
    }
    return 0;
}


Measured memory_bytes: 10368
from collections import deque

def main():
    n, q = map(int, input().split())
    tree = [[] for _ in range(n)]
    for i in range(n-1):
        a, b = map(int, input().split())
        tree[a-1].append(b-1)
        tree[b-1].append(a-1)
    
    ans = [0]*n
    for _ in range(q):
        p, x = map(int, input().split())
        ans[p-1] += x
    
    not_yet = deque([0])
    already = [False]*n
    already[0] = True
    
    while not_yet:
        key = not_yet.popleft()
        for value in tree[key]:
            if already[value]:
                continue
            already[value] = True
            not_yet.append(value)
            ans[value] += ans[key]
    
    print(*ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 56152
# -*- coding: utf-8 -*-
# 標準入力を取得
N, X, M = list(map(int, input().split()))

# 求解処理
s = {X}
l = [X]
i = 0
while True:
    a = l[-1]**2 % M
    if a in s:
        i = l.index(a)
        break
    else:
        s.add(a)
        l.append(a)

loop_length = len(l) - i
loop_cnt = (N - i) // loop_length
loop_res = (N - i) % loop_length
ans = sum(l[:i]) + loop_cnt * sum(l[i:]) + sum(l[i: i + loop_res])

# 結果出力
print(ans)


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



Measured memory_bytes: 3616
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let W: Vec<Vec<char>> = (0..N)
        .map(|_| {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().chars().collect()
        })
        .collect();

    let ans = if (1..N).all(|i|
        (0..i).all(|j| W[i] != W[j]) &&
        W[i][0] == W[i - 1][W[i - 1].len() - 1]) { "Yes" }
        else { "No "};

    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define watch(x) cout << (#x) << " is " << (x) << endl; cout.flush()
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;


int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("B.txt", "r", stdin);
    #endif
    int n, k, ans=0;
    string str;
    cin >> n >> k >> str;
    str += 'x';
    string s;
    for(int i=0; i<n; i++){
        if(str[i]!=str[i+1]){
            s += str[i];
        }
        else ans++;
    }
    cout << ans + min(k, max(0, sz(s)-1)/2) * 2 + (sz(s)%2==0&&k>max(0, sz(s)-1)/2?1:0);
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define int long long
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second
main(){
  int n;
  cin>>n;
  string s;
  set<string>st;
  r(i,n){
    cin>>s;
    st.insert(s);
  }
  if(st.size()==3)cout<<"Three"<<endl;
  else cout<<"Four"<<endl;
}

Measured memory_bytes: 256
use proconio::{input, fastout};
use std::cmp::*;

#[fastout]
fn main() {
    input!{
        x:usize, y:usize, a:usize, b:usize, c:usize,
        mut p: [i64; a],
        mut q: [i64; b],
        mut r: [i64; c],
    }
    p.sort();
    p.reverse();
    q.sort();
    q.reverse();
    r.extend_from_slice(&p[0..x]);
    r.extend_from_slice(&q[0..y]);
    r.sort();
    r.reverse();
    let r_iter = r[0..x+y].iter();
    let tot: i64 = r_iter.sum();
    println!("{}", tot)
}

Measured memory_bytes: 9896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<int, pair<int, int>> PP;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const ll mod = 1e+9 + 7;
const int INF = 1001001001;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

struct edge{
    int u, v;
    edge(int u, int v) : u(u), v(v) {}
};

vector<int> graph[55];
vector<edge> edges;
bool edge_used[55][55];
bool used[55];
set<int> s;     // 閉路を形成する頂点集合

set<int> dfs(int from, int parent = -1){
    used[from] = true;
    set<int> res;
    for(int to : graph[from]){
        if(to == parent)    continue;
        if(edge_used[from][to]) continue;
        edge_used[from][to] = true;
        edge_used[to][from] = true;

        if(used[to]){
            s.insert(to);
            res.insert(to);
        }
        else{
            set<int> cycle = dfs(to, from);
            if(cycle.size() > 0){
                for(auto it : cycle)    res.insert(it);
                if(res.find(from) != res.end()) res.erase(from);
                else    s.insert(from);
            }     
        }
    }
    if(res.size() > 0)  s.insert(from);
    return res;
}

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

    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        --a, --b;
        graph[a].push_back(b);
        graph[b].push_back(a);
        edges.push_back(edge(a, b));
    }
    
    dfs(0);

    int res = 0;
    for(int i = 0; i < m; ++i){
        int u = edges[i].u, v = edges[i].v;
        if(s.find(u) != s.end() && s.find(v) != s.end())    continue;
        ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
N,A,B,C = map(int, input().split())
ls = []
for _ in range(N):
    ls.append(int(input()))

def dfs(i, a, b, c, N):
    global ls,A,B,C

    if i == N:
        mp = 0

        for ans_item, item in zip([A,B,C], [a,b,c]):
            if len(item) == 0:
                return float("inf")
            elif len(item) > 1:
                mp += (len(item) - 1) * 10
            total = sum(item)
            if ans_item == total:
                pass
            else:
                mp += abs(ans_item-total)
        
        return mp

    l = ls[i]
    mps = []
    mps.append(dfs(i+1, a+[l], b, c, N))
    mps.append(dfs(i+1, a, b+[l], c, N))
    mps.append(dfs(i+1, a, b, c+[l], N))
    mps.append(dfs(i+1, a, b, c, N))
    return min(mps)

print(dfs(i=0, a=[], b=[], c=[], N=N))


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

// Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

// Type / Class / Struct Definitions:
using namespace std;

using ll = long long;
using ull = unsigned long long;

// Constants:
const int INF = (1ll << 30) - 1;  // approx 1.07e9
const ll INFLL = 1ll << 60;       // approx 1.15e18
const int MOD = 1e9 + 7;          // 998244353
const long double EPS = 1.0e-14;

// Global Variables:

// Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

// ================ Main Loop ================
int main() {
    int n;
    string s;
    cin >> n >> s;

    if(n < 3) {
        cout << 0 << endl;
        return 0;
    }

    int r = 0, g = 0, b = 0;
    vector<tuple<int, int, int>> cnt(n);
    for(int i = n - 1; i >= 0; i--) {
        switch(s[i]) {
            case 'R':
                r++;
                break;
            case 'G':
                g++;
                break;
            case 'B':
                b++;
                break;
        }
        cnt[i] = make_tuple(r, g, b);
    }

    vector<ll> rg(n), rb(n), gr(n), gb(n), br(n), bg(n);
    for(int i = n - 2; i >= 0; i--) {
        int xr, xg, xb;
        tie(xr, xg, xb) = cnt[i];
        rg[i] = rg[i + 1];
        rb[i] = rb[i + 1];
        gr[i] = gr[i + 1];
        gb[i] = gb[i + 1];
        br[i] = br[i + 1];
        bg[i] = bg[i + 1];

        switch(s[i]) {
            case 'R':
                rg[i] = rg[i + 1] + xg;
                rb[i] = rb[i + 1] + xb;
                break;
            case 'G':
                gr[i] = gr[i + 1] + xr;
                gb[i] = gb[i + 1] + xb;
                break;
            case 'B':
                br[i] = br[i + 1] + xr;
                bg[i] = bg[i + 1] + xg;
                break;
        }
    }

    ll ans = 0;
    rep(i, n - 2) {
        switch(s[i]) {
            case 'R':
                ans += gb[i];
                ans += bg[i];
                break;
            case 'G':
                ans += rb[i];
                ans += br[i];
                break;
            case 'B':
                ans += rg[i];
                ans += gr[i];
        }
    }

    for(int d = 1; d < n; d++) {
        rep(i, n - d * 2) {
            if(s[i] != s[i + d] && s[i + d] != s[i + d * 2] && s[i + d * 2] != s[i]) {
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}
// ===========================================

// Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


Measured memory_bytes: 3756
n = int(input())
a = list(map(int, input().split()))

count = 0
for i in range(n-2):
  if (a[i] > a[i+1] and a[i+1]>a[i+2] ) or (a[i] < a[i+1] and a[i+1]<a[i+2] ):
    count += 1
print(count)

Measured memory_bytes: 3060
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main() {
		new AOJ0208();
	}
	
	class AOJ0208{
		public AOJ0208() {
			char[] table = {'0','1','2','3','5','7','8','9'};
			while(true){
				long n = in.nextLong();
				if(n==0)break;
				String a = Long.toOctalString(n);
				String result = "";
				for(int i=0;i<a.length();i++){
					result+=table[Integer.parseInt(a.charAt(i)+"")];
				}
				System.out.println(result);
			}
		}
	}
}

Measured memory_bytes: 61408
# C - Chocolate Bar

H, W = map(int, input().split())

def ans_every_h1(H,W):
    piece = [0]*3
    for h1 in range(1,H):
        piece[0] = h1*W
        piece[1] = ((H - h1)//2) * W
        piece[2] = H*W - piece[0] - piece[1]
        ans_list.append(max(piece) - min(piece))
        
        piece[1] = (H - h1) * (W//2)
        piece[2] = H*W - piece[0] - piece[1]
        ans_list.append(max(piece) - min(piece))

if H%3 == 0 or W%3 == 0:
    print(0)
else:
    ans_list = []
    ans_every_h1(H,W)
    ans_every_h1(W,H)
    print(min(ans_list))

Measured memory_bytes: 18964
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>

#pragma GCC optimization ("O3")

#define endl '\n'
#define pb push_back
#define fr first
#define sc second
#define ll long long int
#define ld long double
#define bit(idx) idx&(-idx)
#define bin(x, a) bitset<a>(x)
#define all(A) A.begin(), A.end()
#define de(x) cout << #x << " = " << x << endl;
#define row vector<ll>
#define matrix vector<row>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
/// find_by_order(x) -> x-th element in the set
/// order_of_key(x)  -> how many elements are smaller than x
/// insert(x) -> inserts x into the set



int main(){
	/// ios_base::sync_with_stdio(false); cin.tie(NULL);
	ll n; cin >> n;
	ll ans1 = LLONG_MIN, ans2 = LLONG_MAX, ans3 = LLONG_MIN, ans4 = LLONG_MAX;
	for(int i = 0; i < n; i ++){
		ll x, y; cin >> x >> y;
		ans1 = max(ans1, x + y);
		ans2 = min(ans2, x + y);
		ans3 = max(ans3, x - y);
		ans4 = min(ans4, x - y);
	}
	cout << max(ans1 - ans2, ans3 - ans4) << endl;
}
/**

*/

Measured memory_bytes: 3512
#include <cstdio>
#include <vector>

int main(){
	std::vector< std::vector<int> > M;
	int n, r, k, c;
	scanf("%d", &n);
	M.resize(n);
	for (int i=0;i<n;i++){
		M[i].resize(n);
		scanf("%d %d", &r, &k);
		for (int j=0; j<k;j++){
			scanf("%d", &c);
			M[i][c-1]=1;
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			printf("%d", M[i][j]);
                        if (j!=n-1) printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2728
n = int(input())
a = list(map(int, input().split()))
a.sort()
MAX = int(1e6) + 10
sieve = [0] * int(MAX)
for i in a:
    sieve[i] += 1
ans = 0
for idx, val in enumerate(sieve):
    if val == 0:
        continue
    elif val > 1:
        sieve[idx] = 0
    else:
        ans += 1
    for i in range(idx * 2, MAX, idx):
        sieve[i] = 0
print(ans)

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

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans;
    rep(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3604
#include <bits/stdc++.h>
#define GET_REP(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_REP(__VA_ARGS__, irep, _rep)(__VA_ARGS__)
#define rep1(...) GET_REP(__VA_ARGS__, irep1, _rep1)(__VA_ARGS__)
#define _rep(i, n) irep (i, 0, n)
#define _rep1(i, n) irep1(i, 1, n)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define irep1(i, a, n) for (int i = a; i <= (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(X, x) for (auto &&X : x)
#define all(x) begin(x), end(x)
#define debug(x) cout << #x " => " << (x) << endl
#ifdef LOCAL
  #include "../../Lib/cout_container.hpp"
#endif
using lint = long long;
constexpr int MOD = (int)1e9 + 7;
constexpr double EPS = 1e-9;
using namespace std;
namespace { struct INIT { INIT() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } } INIT; }

int count_bit(unsigned long long data) {
  data = (data & 0x5555555555555555) + ((data & 0xAAAAAAAAAAAAAAAA) >> 1);
  data = (data & 0x3333333333333333) + ((data & 0xCCCCCCCCCCCCCCCC) >> 2);
  data = (data & 0x0F0F0F0F0F0F0F0F) + ((data & 0xF0F0F0F0F0F0F0F0) >> 4);
  data = (data & 0x00FF00FF00FF00FF) + ((data & 0xFF00FF00FF00FF00) >> 8);
  data = (data & 0x0000FFFF0000FFFF) + ((data & 0xFFFF0000FFFF0000) >> 16);
  data = (data & 0x00000000FFFFFFFF) + ((data & 0xFFFFFFFF00000000) >> 32);
  return data;
}

int main(void) {
  int n;
  cin >> n;
  vector<vector<pair<int, int>>> xy(n);
  rep (i, n) {
    int a;
    cin >> a;
    xy[i].resize(a);
    rep (j, a) {
      int x, y;
      cin >> x >> y;
      xy[i][j].first = --x, xy[i][j].second = y;
    }
  }
  int maxbit = 1 << n, maxi = 0;
  rep (bit, maxbit) {
    bool ok = true;
    rep (i, n) {
      if (bit & (1 << i)) {
        allrep (p, xy[i]) {
          if (p.second != ((bit >> p.first) & 1)) {
            ok = false;
            break;
          }
        }
      }
    }
    if (ok) maxi = max(maxi, count_bit(bit));
  }
  cout << maxi << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
struct Card
{
    char c;
    int a;
    bool operator<(Card &b)const
    {
        return a<b.a;
    }
}arr[100],arr1[100];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr[i].c>>arr[i].a,arr1[i]=arr[i];
    for(int i=0;i<n-1;i++)
        for(int j=0;j<n-1-i;j++)
        if(arr[j+1]<arr[j])
            swap(arr[j],arr[j+1]);
    for(int i=0;i<n;i++)
    {
        if(i)cout<<' ';
        cout<<arr[i].c<<arr[i].a;
    }
    cout<<endl;
    cout<<"Stable"<<endl;
    for(int i=0;i<n-1;i++)
    {
        int MIN=i;
        for(int j=i;j<n;j++)
        {
            if(arr1[j]<arr1[MIN])
                MIN=j;
        }
        if(MIN!=i)swap(arr1[i],arr1[MIN]);
    }
    int flag=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i].c!=arr1[i].c)flag=1;
        if(i)cout<<' ';
        cout<<arr1[i].c<<arr1[i].a;
    }
    cout<<endl;
    if(flag)
        cout<<"Not stable"<<endl;
    else cout<<"Stable"<<endl;
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i,s,n) for(int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main(){
    int n, k, q;
    cin >> n >> k >> q;
    int a[n];
    rep(i, n) a[i] = k - q;
    rep(i, q) { 
        int j;
        cin >> j;
        a[j - 1]++;
    }
    rep(i,n){
        if(a[i]>0)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    return 0;
}

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

using namespace std;

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

int main(){
	string s; cin >> s;
	int n = s.size();
	int maxi = 0;
	int j;
	forn(i, n){
		forn(j, n-i+1){
			string a = s.substr(i, j);
			int flag = 0;
			forn(k, a.size()){
				if(a[k] != 'A' && a[k] !='C' && a[k] != 'G' && a[k] != 'T'){
					flag = 1; break;
				}
			}
			if(flag == 0) maxi = max(maxi, j);
		}
	}
	cout << maxi << endl;
}

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

using namespace std;

typedef long long  ll;

#define SIZ 1000000000
#define mod 10000007

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	ll n,m,k;
	cin >> n >> m >> k;
	
	vector<ll> u(n + 1), v(m + 1);
	u[0] = v[0] = 0;
	
	
	for(ll i = 1; i <= n; i++) cin >> u[i], u[i] += u[i - 1];
	for(ll i = 1; i <= m; i++) cin >> v[i], v[i] += v[i - 1];
	
	ll cnt = 0;
	
	ll j = m, res = 0;
	for(ll i = 0; i <= n; i++){
		if(u[i] > k) break;
		
		while(j >= 0 && u[i] + v[j] > k){
			j--;
		}
		
		cnt = max(cnt, i + j);
	}
	
	cout << cnt << "\n";
}


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

int main() {
  int N;
  cin >> N;
  
  vector<long double> A(N);
  long double gyakusuu;
  long double wa=0;
  
  for(int i=0; i<N ;i++){
    cin >> A.at(i);
    gyakusuu = 1/A.at(i);
    wa = wa + gyakusuu;
  }
  
  cout << fixed << setprecision(10);
  
  cout << 1/wa << endl;
  
}



Measured memory_bytes: 3824
#include <bits/stdc++.h>
#include <random>
#include <ctime>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx2")
#define ll long long
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define pll pair<ll,ll>
#define ld double
#define pld pair<ld,ld>
#define pii pair<int,int>
#define sqr(a) ((a)*(a))
#define all(v) v.begin(),v.end()

using namespace std;
//using namespace __gnu_pbds;

const ll MOD = 998244353;
const ll INF = 1e18;
const ld E = 1e-12;
const ld PI=acos(-1);
mt19937_64 rnd(time(0));
ll p1 = 31, p2 = 37, p3 = 7, p4 = rnd() % 100 + 1, md1 = MOD, md2 = 998244353, md3 = 998244357, md4 = rnd() % 1000000000;

//using ord_set=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

ll n, m, a[1000001], b[1000001], pr[1000001];

ll binpow(ll h, ll r, ll md = MOD)
{
    ll l = 1;
    while (r)
    {
        if (r & 1) l *= h, l %= md;
        h *= h;
        h %= md;
        r /= 2;
    }
    return l;
}

ll gcd(ll x, ll y)
{
    if (x < y) swap(x, y);
    while (x && y)
    {
        x %= y;
        swap(x, y);
    }
    return x + y;
}

#define dies_from_cringe exit(0)

void solve()
{
    cin >> n;
    ll p, ans=0;
    for (int i = 1; i <= n; i++)
    {
        p=n/i;
        ans+=p*(p+1)/2*i;
    }
    cout << ans << "\n";
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //freopen("capitals.in","r",stdin);
    //freopen("capitals.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    //cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

/*
1
3 3
10 1 2
5 1 1
*/


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int d,g;
  cin >> d >> g;
  int p[d],c[d];
  int res=0;
  rep(i,d){
    cin >>  p[i] >> c[i];
    res+=p[i]*100*(i+1) + c[i];
  }
  rep(i,1<<(d+1)){
    int ans=0;
    int poi=0;
    int last=-1;
    rep1(j,d){
      if(i & 1<<j){
	ans+=p[j-1];
	poi+=100*j*p[j-1];
	poi+=c[j-1];
      }
      else last=j;
    }
    if(last!=-1){
      if(poi<g){
	if(poi+100*last*(p[last-1]-1)<g ) continue;
	else{
	  int toita=(g-poi)/100/last;
	  if((g-poi)%(100*last)!=0) toita+=1;
	  ans+=toita;	  
	}
      }
    }
    res = min(res,ans);      
  }
  cout << res << endl;


  
  return 0;
    

}


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

int main(void){
  int number[4][3][10] = {0};
  int N;
  cin >> N;
  int b,f,r,v;
  for(int i = 0; i < N; i++ ){
    cin >> b >> f >> r >> v;
    number[b-1][f-1][r-1] += v;
  }
  for(int bb = 0; bb < 4; bb++ ){
    for(int ff = 0; ff < 3; ff++ ){
      for( int rr = 0; rr < 10; rr++ ){
        cout << " " << number[bb][ff][rr];
      }
      cout << endl;
    }
    if(bb != 3) cout << "####################" << endl;
  }


  return 0;
}

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

int main() {
  int n;
  int d[51];
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> d[i];
  }
  
  int ans = 0;
  for(int i=0; i<n; i++){
    for(int j=i+1; j<n; j++){
      ans += d[i]*d[j];
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int outputStr;

  scanf("%d", &outputStr);


  printf("%d", outputStr / 60 / 60);
  printf(":");

  printf("%d", outputStr/ 60 % 60);

  printf(":");
  printf("%d\n", outputStr % 60);
  return (0);
}




Measured memory_bytes: 2712
#include <stdio.h>

int main(void) {
	long a, b, c, d,k,x,tmp,r;
	scanf("%ld", &a);
	scanf("%ld", &b);
	scanf("%ld", &c);
	scanf("%ld", &d);
	long c1 = c;
	long d1 = d;
	x = c * d;
	if (c1 < d1) {
		tmp = c1;
		c1 = d1;
		d1 = tmp;
	}
	r = c1 % d1;
	while (r != 0) {
		c1 = d1;
		d1 = r;
		r = c1 % d1;
	}
	x = x / d1;
	k = b-a+(a-1)/c+(a-1)/d-b/c-b/d+b/x-(a-1)/x+1;
	printf("%ld", k);
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    vector<int>::iterator iter = max_element(A.begin(), A.end());
    size_t max_idx = distance(A.begin(), iter);

    int sum = 0;
    if (max_idx == 0) {
        for (int i = 1; i < A.size(); i++) {
            sum += A[i];
        }
    } else {
        for (int i = 0; i < max_idx; i++) {
            sum += A[i];
        }
        for (int i = max_idx + 1; i < A.size(); i++) {
            sum += A[i];
        }
    }
    cout << (*iter < sum ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#pragma comment(linker, "/STACK:32000000")
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0, _= (n); i < _; ++i)
#define DWN(i, n) for (int i = (n) - 1; i >= 0; --i)
#define FOR(i, l, r) for (int i = (l), _ = (r); i < _; ++i)
#define EDGE(u, v, e) for (int e = head[u], v; e != nil && (v = to[e], true); e = next[e])

using namespace std;

typedef unsigned int uint;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;

inline bool read(int& val)    { return scanf("%d",    &val) != -1;}
inline bool read(int64& val)  { return scanf("%I64d", &val) != -1;}
inline bool read(double& val) { return scanf("%lf",   &val) != -1;}
inline bool read(char* val)   { return scanf("%s",     val) != -1;}
template<class T1, class T2>
inline bool read(T1& a, T2& b)
{ return read(a) && read(b); }
template<class T1, class T2, class T3>
inline bool read(T1& a, T2& b, T3& c)
{ return read(a) && read(b) && read(c); }
template<class T1, class T2, class T3, class T4>
inline bool read(T1& a, T2& b, T3& c, T4& d)
{ return read(a) && read(b) && read(c) && read(d); }
template<class T1, class T2, class T3, class T4, class T5>
inline bool read(T1& a, T2& b, T3& c, T4& d, T5& e)
{ return read(a) && read(b) && read(c) && read(d) && read(e); }

const int nil = -1;
const int N = 1111111;

struct graphics
{
	int n;
	int head[N];

	int id;
	int to[N];
	int next[N];
	int type[N];

	void init(int n) {
		this->n = n;
		REP (i, n) head[i] = nil;
	}
	void add1(int a, int b, int t) {
		to[id] = b; next[id] = head[a]; type[id] = t; head[a] = id++;
	}
	void add(int a, int b, int t) {
		add1(a, b, t); add1(b, a, t);
	}

	int belong[2][N]; int cnt[2][N];
	int stack[N], top;
	void dfs(int u, int t, int p) {
		top = 0; stack[top++] = u;
		while (top > 0) {
			u = stack[--top];
			if (belong[t][u] == nil) {
				belong[t][u] = p; cnt[t][p]++;
				if (t == 0) {
					EDGE(u, v, e) if(type[e] == 0) {
						stack[top++] = v;
					}
				} else {
					EDGE(u, v, e) if(type[e] == 1) {
						stack[top++] = v;
					}
				}
			}
		}
	}

	map<pair<int, int>, int> mp;
	void solve() {
		REP (t, 2) {
			REP (i, n) belong[t][i] = nil;
			REP (i, n) if (belong[t][i] == nil)
				dfs(i, t, i);
		}
		REP (i, n) {
			mp[make_pair(belong[0][i], belong[1][i])]++;
		}
	}
} g;

int main() {
	int n; read(n);
	int k, l; read(k, l);
	g.init(n);
	REP (i, k) {
		int a, b; read(a, b); a--; b--;
		g.add(a, b, 0);
	}
	REP (j, l) {
		int a, b; read(a, b); a--; b--;
		g.add(a, b, 1);
	}
	g.solve();
	REP (i, n) {
		printf("%d%c", g.mp[make_pair(g.belong[0][i], g.belong[1][i])], i == n - 1 ? '\n' : ' ');
	}
	return 0;
}



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

int main() {
    ll n, k;
    cin >> n >> k;
    vl a(n);
    ll atot = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        atot += a[i];
    }
    vl f(n);
    for (int i = 0; i < n; ++i) {
        cin >> f[i];
    }
    if (atot <= k) {
        cout << 0 << "\n";
        return 0;
    }
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    priority_queue<pair<ll, ll>, vector<pll>, less<pll>> pq;
    for (int i = 0; i < n; ++i) {
        pq.emplace(a[i] * f[i], f[i]);
    }
    auto check = [&](ll mid) {
        vl costs(n, 0);
        for (int i = 0; i < n; ++i) {
            costs[i] = (mid) / f[i];
        }
        sort(costs.begin(), costs.end());
        ll cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += max(0LL, a[i] - costs[i]);
        }
        // auto pqt = pq;
        // ll cnt   = 0;
        // while (!pqt.empty()) {
        //     auto p = pqt.top();
        //     pqt.pop();
        //     cnt += (p.first - mid + p.second - 1) / p.second;
        // }
        return cnt <= k;
    };
    ll ng = 0;
    ll ok = 1'000'000'000'000;
    while (ng + 1 != ok) {
        ll mid = (ok + ng) / 2;
        if (check(mid))
            ok = mid;
        else
            ng = mid;
    }
    cout << ok << "\n";
    return 0;
}

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

template<typename Monoid>
struct SegmentTree{
    typedef function<Monoid(Monoid,Monoid)> F;
    int n;
    F f;
    Monoid id;
    vector<Monoid> dat;
    SegmentTree(int n_,F f,Monoid id):f(f),id(id){init(n_);}
    void init(int n_){
        n=1;
        while(n<n_) n<<=1;
        dat.assign(n<<1,id);
    }
    void build(const vector<Monoid> &v){
        for (int i=0;i<v.size();++i) dat[i+n]=v[i];
        for (int i=n-1;i;--i) dat[i]=f(dat[i<<1|0],dat[i<<1|1]);
    }
    void update(int k,Monoid x){
        dat[k+=n]=x;
        while(k>>=1) dat[k]=f(dat[k<<1|0],dat[k<<1|1]);
    }
    Monoid query(int a,int b){
        if (a>=b) return id;
        Monoid vl=id,vr=id;
        for (int l=a+n,r=b+n;l<r;l>>=1,r>>=1){
            if (l&1) vl=f(vl,dat[l++]);
            if (r&1) vr=f(dat[--r],vr);
        }
        return f(vl,vr);
    }
    // most left position that meets condition "check"
    template<typename C>
    int find(int a,int b,const C &check,int k,int l,int r){
        if (!check(dat[k])||r<=a||b<=l) return -1;
        if (l+1==r) return k-n;
        int vl=find(a,b,check,k<<1|0,l,(l+r)>>1);
        if (~vl) return vl;
        return find(a,b,check,k<<1|1,(l+r)>>1,r);
    }
    template<typename C>
    int find(int a,int b,const C &check){
        return find(a,b,check,1,0,n);
    }
    Monoid operator[](int i){return dat[i+n];}
};

// https://onlinejudge.u-aizu.ac.jp/courses/library/3/DSL/all/DSL_2_A

void DSL_2_A(){
    int n,q; cin >> n >> q;
    SegmentTree<int> seg(n,[](int a,int b){return min(a,b);},INT_MAX);
    for (;q--;){
        int c,x,y; cin >> c >> x >> y;
        if (!c) seg.update(x,y);
        else cout << seg.query(x,y+1) << '\n';
    }
}

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


Measured memory_bytes: 3888
#include<iostream>
#include<bits/stdc++.h> 
using namespace std;
int main()
{
	int n;
	scanf("%d", &n);
	double a[n],ans;
	for(int i = 0; i < n; i++){
        scanf("%lf", &a[i]);
        ans+=1/a[i];
	}
	printf("%f\n", 1/ans);
    return 0;
}

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

using ll = long long;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

typedef tuple<int, ll> Edge;
class Dijkstra {
public:
	// edges[from] = Edge(to, cost);
	vector<vector<Edge>> edges;

	Dijkstra(int size) {
		edges = make_v<vector<Edge>>(size);
	}

	vector<ll> get_shortest_path(int start) {
		int node_num = edges.size();
		assert(start < node_num);
		
		typedef tuple<ll, int> P;
		priority_queue<P, vector<P>, greater<P>> que;
		auto d = make_v<ll>(node_num);
		fill_v(d, INF_LL);
		d[start] = 0;
		que.push(P(0, start));
		
		while (not que.empty()) {
			P p = que.top(); que.pop();
			int v = get<1>(p);
			if (d[v] < get<0>(p)) continue;
			REP(i, edges[v].size()) {
				Edge e = edges[v][i];
				int to = get<0>(e); ll cost = get<1>(e);
				ll new_cost = d[v] + cost;
				if (d[to] > new_cost) {
					d[to] = new_cost;
					que.push(P(d[to], to));
				}
			}
		}
		return d;
	}
};

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	int N, M, start; cin >> N >> M >> start;
	Dijkstra dj(N);
	REP(i, M) {
		int from, to; ll cost; cin >> from >> to >> cost;
		dj.edges[from].pb(Edge(to, cost));
	}

	auto d = dj.get_shortest_path(start);
	for (auto c : d) {
		if (c == INF_LL)
			cout << "INF";
		else
			cout << c;
		cout << endl;
	}

	return 0;
}



Measured memory_bytes: 19356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i <= (n); i++)
#define zep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define printa(x,m,n) for(int i = (m); i <= n; i++){cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    
    ll d, t, s; cin >> d >> t >> s;
    print((s * t >= d)? "Yes" : "No")

    return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int w,a,b;
	cin>>w>>a>>b;
	if(a > b) swap(a,b);
	int r = a + w;
	cout<<max(0, b-r)<<endl;
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(input()) for x in range(N)]

import math

cnt = 0
for i in range(N) :
    cnt += 1
    if a[i] == 2 :
        continue
    else :
        for j in range(2, int(math.sqrt(a[i])) + 1) :
            if a[i] % 2 == 0 :
                cnt -= 1
                break
            if a[i] % j == 0 :
                cnt -= 1
                break
            
print(cnt)


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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<string> pic(H);
    for (int i = 0; i < H; i++){
        cin >> pic.at(i);
    }

    //N段目
    for (int i = 0;i < H + 2; i++){
        cout << "#";

        if(i == 0||i == H + 1){
            for (int j = 0; j < W; j++){
                cout << "#";
            }
        }
        else{          
            cout << pic.at(i - 1);           
        }

        cout << "#" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream& operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream& operator<<(ostream &os, vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream& operator<<(ostream &os, set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream& operator<<(ostream &os, pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream& operator<<(ostream &os, map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << "=>" << v.second << ","; os << "}"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

vector<int> makePrimeLst(int N)
{
    if (N < 2) return vector<int>();
    if (N == 2) return vector<int>{2};
    vector<int> ans;
    vector<int> alive(N+1, 1);
    for (int i=2; (long long)i*i<=(long long)N; i++)
    {
        if (alive[i]) ans.push_back(i);
        for (int t = i; t<=N; t += i) alive[t] = 0;
    }
    for (int i=ans.back()+1; i<=N; i++) if (alive[i]) ans.push_back(i);
    return ans;
}

map<int, int> primeFactorize(int N, vector<int> &primeLst)
{
    map<int, int> ans;
    for (auto v : primeLst)
    {
        while (!(N % v))
        {
            N /= v;
            ans[v]++;
        }
        if (N == 1) return ans;
    }
    ans[N]++;
    return ans;
}

constexpr lint MOD = 1000000007;
vector<lint> fac, facInv, inv;
void facInit(int nmax)
{
    fac = facInv = inv = vector<lint>(nmax + 1, 1);
    for (int i = 2; i <= nmax; i++)
    {
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        facInv[i] = facInv[i-1] * inv[i] % MOD;
    }
}
lint nCr(int n, int r)
{
    if (n<r || r<0) return 0;
    return (fac[n] * facInv[r] % MOD) * facInv[n-r] % MOD;
}

int main()
{
    facInit(1000000);
    lint N, M;
    cin >> N >> M;
    vector<int> lst = makePrimeLst(100000);
    map<int, int> info = primeFactorize(M, lst);

    lint ans = 1;
    for (auto v : info) (ans *= nCr(N - 1 + v.second, N - 1)) %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 24192
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define var auto
using namespace std;
using ll = long long;
using P = pair<int, int>;
#ifdef DEBUG
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; cout << a << endl; return 1; } cout << a << endl; return 0; }
#else
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; }
#endif
const ll INF = 1LL << 60;
const int MAX_WEIGHT = 10e4+10;
const int MAX_ITEM = 10e1+10;
ll dp[MAX_WEIGHT][MAX_ITEM] = {0};

int main() {
  int n,w;
  cin >> n >> w;
  ll weight[n], value[n];
  rep(i,n) cin >> weight[i] >> value[i];

  // W が 0->MAX_WEIGHT だけ回す
  rep(i,MAX_WEIGHT) {
    // N が 0->N だけ回す
    rep(j,n) {
      // 価値が最大化になるようにバッグに品物を詰める
      chmax(dp[i][j+1], dp[i][j] + 0);

      // N番目の品物が入るか?      
      if (i >= weight[j]) {
        // N番目の品物を入れてみる
        chmax(dp[i][j+1], (dp[i - weight[j]][j]) + value[j]);
      }
    }
  }

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


Measured memory_bytes: 86144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
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; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;


int main() {
    ll a,b,c,d,taka,ao;
    cin >> a >> b >> c >> d;
    if (c%b==0) taka = c/b;
    else taka = c/b + 1;
    if (a%d==0) ao = a/d;
    else ao = a/d + 1;
    if (taka > ao) cout << "No" << endl;
    else if (taka < ao) cout << "Yes" << endl;
    else cout << "Yes" << endl; 

}

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

using namespace std;

class BIT{
public:
    int *p;
    int num;
    BIT(int arg){
        p = new int[arg+1];
        for(int i=0;i<arg+1;i++) p[i] = 0;
        num = arg;
    }
    
    //return sum of p[1] ... p[arg]
    int sum(int arg){
        int ret=0;
        while(arg > 0){
            ret += p[arg];
            arg -= arg & -arg;
        }
        return ret;
    }

    //add value to index-th node
    void add(int index, int value){
        while(index <= num){
            p[index] += value;
            index += index & -index;
        }
    }
};

int main(){
    int n, m, tmp;
    int mod = 100000;
    int ret = 0;

    cin >> n >> m;
    BIT bit(n);
    for(int i=1;i<n;i++){
        cin >> tmp;
        bit.add(i,tmp%mod);
    }
    int pos = 0;
    for(int i=0;i<m;i++){
        cin >> tmp;
        ret += abs(bit.sum(pos) - bit.sum(pos+tmp)) % mod;
        ret %= mod;
        pos += tmp;
//        cout << "ret = " << ret << endl;
//        cout << "pos = " << pos << endl;
    }
    cout << ret << endl;
}

Measured memory_bytes: 1260
#include <iostream>
#include <stack>
#include <vector>

struct Node {
	std::vector<Node*> nextList;
	int counter;
	int result;
	bool checked = false;
};

void solve(Node *node, int count) {
	const int count2 = count + node->counter;
	node->result = count2;
	for(auto &next : node->nextList) {
		if(!next->checked) {
			next->checked = true;
			solve(next, count2);
		}
	}
}

void solve(Node *node) {
	node->checked = true;
	solve(node, 0);
}

int main() {
	int N, Q;
	std::cin >> N >> Q;

	std::vector<Node> nodeList(N);
	for(int i = 0; i < N - 1; i++) {
		int a, b;
		std::cin >> a >> b;

		const int aa = a - 1;
		const int bb = b - 1;
		nodeList[aa].nextList.emplace_back(&nodeList[bb]);
		nodeList[bb].nextList.emplace_back(&nodeList[aa]);
	}

	for(int i = 0; i < Q; i++) {
		int p, x;
		std::cin >> p >> x;
		const int pp = p - 1;
		nodeList[pp].counter += x;
	}

	solve(&nodeList[0]);

	std::cout << nodeList.front().result;
	for(auto p = nodeList.begin() + 1; p != nodeList.end(); p++) {
		std::cout << " " << p->result;
	}
	std::cout << std::endl;

	return 0;
}


Measured memory_bytes: 22656
#パクリ
import itertools

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

lis=list(itertools.permutations(P))
lis.sort()

#indexで要素の何番目か取得
print(abs(lis.index(P)-lis.index(Q)))


Measured memory_bytes: 8052
N, M = map(int, input().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 and M > 1:
    print(M - 2)
elif N > 1 and M == 1:
    print(N - 2)
else:
    print((M - 2) * (N - 2))

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main {
    public static final int DICE_NUM = 6;
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	String[] inputs = scan.nextLine().split(" ");
	int[] face = new int[DICE_NUM];
	for (int i = 0; i < DICE_NUM; i++) {
	    face[i] = Integer.parseInt(inputs[i]);
	}
	Dice dice = new Dice(face);
	int q = Integer.parseInt(scan.nextLine());
	int[] side = new int[4];
	for (int i = 0; i < q; i++) {
	    String[] topfront = scan.nextLine().split(" ");
	    int top = Integer.parseInt(topfront[0]);
	    int front = Integer.parseInt(topfront[1]);
	    dice.setTop(top);
	    while(dice.getFace(1) != front) {
		dice.turnRight();
	    }
	    System.out.println(dice.getFace(2));
	}
    }
}
class Dice{
    int NORTH = 4;
    int SOUTH = 1;
    int WEST = 3;
    int EAST = 2;
    int TOP = 0;
    int BOTTOM = 5;
    int[] face = new int[6];
	
    Dice(int[] face){
	this.face = face;
    }

    void setTop(int top){
	int cnt = 0;
	while(face[TOP] != top && cnt < 4){
	    turnSouth();
	    cnt++;
	}
	while(face[TOP] != top){
	    turnEast();
	}
    }

    void turnRight(){
	turnEast();
	turnSouth();
	turnWest();
    }

    void turnEast(){
	int bottom = face[BOTTOM];
	int west = face[WEST];
	face[BOTTOM] = face[EAST];
	face[EAST] = face[TOP];
	face[WEST] = bottom;
	face[TOP] = west;
    }

    void turnWest(){
	int bottom = face[BOTTOM];
	int east = face[EAST];
	face[BOTTOM] = face[WEST];
	face[WEST] = face[TOP];
	face[EAST] = bottom;
	face[TOP] = east;
    }
	
    void turnNorth(){
	int bottom = face[BOTTOM];
	int south = face[SOUTH];
	face[BOTTOM] = face[NORTH];
	face[NORTH] = face[TOP];
	face[SOUTH] = bottom;
	face[TOP] = south;
    }

    void turnSouth(){
	int bottom = face[BOTTOM];
	int north = face[NORTH];
	face[BOTTOM] = face[SOUTH];
	face[SOUTH] = face[TOP];
	face[NORTH] = bottom;
	face[TOP] = north;
    }
    int getFace(int index){
	return face[index];
    }
}
    

Measured memory_bytes: 26088