akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;

const ll mod = 1000000007;
const double pi = 3.1415926535897932384626;

ll powmod(ll a, ll b) {ll res = 1; ll rem = a % mod; for (; b; b >>= 1) {if (b & 1) res = (res * rem) % mod; rem = (rem * rem) % mod;} return res;}

const int N = 100008;

vector< pair<int, ll> > G[N];
ll dis[N];

void dfs(int u, int p)
{
    int l = int(G[u].size());

    for (int i = 0; i < l; ++i) {
	int to = G[u][i].fi;
	ll di = G[u][i].se;
	if (to == p) continue;
	dis[to] = dis[u] + di;
	dfs(to, u);
    }

    return;
}	    

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    
    int n = 0;
    scanf("%d", &n);

    for (int i = 1; i < n; ++i) {
	int u = 0;
	int v = 0;
	ll d = 0ll;
	scanf("%d %d %lld", &u, &v, &d);
	G[u].eb(mp(v, d));
	G[v].eb(mp(u, d));
    }

    int q = 0;
    int k = 0;
    scanf("%d %d", &q, &k);

    dfs(k, 0);

    for (int i = 1; i <= q; ++i) {
	int u = 0;
	int v = 0;
	scanf("%d %d", &u, &v);
	ll ans = dis[u] + dis[v];
	printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 15872
n, m = list(map(int, input().split()))

a_list_list = []

for i in range(0, n):
    a_list_list.append(input().split()[0])

b_list_list = []

for i in range(0, m):
    b_list_list.append(input().split()[0])

def is_match(source_list_list, b_list_list, source_start_x):

    for k in range(len(b_list_list)):
        for l in range(len(b_list_list[0])):
            if source_list_list[k][source_start_x + l] != b_list_list[k][l]:
                return False

    return True

# def debug_print(source):
#     print('==============')
#     for row in source:
#         print(row)
#     print('==============')

is_ok = False

# debug_print(b_list_list)

for j in range(0, n-m+1):
    target_a_list_list = a_list_list[j:j+m]
    for i in range(0, n-m+1):
        # debug_print(target_a_list_list)
        if is_match(target_a_list_list, b_list_list, i):
            is_ok = True
            break
    if is_ok:
        break

ans = 'Yes' if is_ok else 'No'

print(ans)


Measured memory_bytes: 3064
fn read() -> (i32, i32) {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let vec: Vec<i32> = s
        .trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect();
    (vec[0], vec[1])
}

fn main() {
    let (x, y) = read();
    let vec1 = [1, 3, 5, 7, 8, 10, 12];
    let vec2 = [4, 6, 9, 11];
    let vec3 = [2];

    println!(
        "{}",
        match (x, y) {
            _ if vec1.contains(&x) && vec1.contains(&y) => "Yes",
            _ if vec2.contains(&x) && vec2.contains(&y) => "Yes",
            _ if vec3.contains(&x) && vec3.contains(&y) => "Yes",
            _ => "No",
        }
    );
}


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

int main(){
	int N;
	cin >> N;
	vector<int> d(N);
	for(auto itr = d.begin(); itr != d.end(); itr++){
		int temp;
		cin >> temp; 
		*itr = temp;
	}
	sort(d.begin(), d.end());
	auto itr = unique(d.begin(), d.end());
	d.erase(itr, d.end());
	cout << d.size() << endl;
	return 0;
}

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

using namespace std;

int main() {
  string w;
  cin >> w;
  
  int a[1000];
  for(int i = 0; i < 1000; i++)
    a[i] = 0;

  for(char ch = 'a'; ch <= 'z'; ch++) {
    for(int i = 0; i < w.size(); i++)
      if(w[i] == ch) a[ch-'0']++;
  }
  bool flag = 0;
  for(int i = 0; i < 1000; i++) {
    if(a[i] % 2 == 0) flag = 1;
    else {
      cout << "No" << endl;
      return 0;
    }
  }
  if(flag) cout << "Yes" << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
#define 	pi 				3.14159265358979
#define 	mod 			1000000007
#define 	ll  			long long int
#define 	rep(i, a, b) 	for(ll i = a ; i < b ; i++)
#define     repn(i, a, b)   for(ll i = a ; i > b ; i--)
#define 	mod1 			1000003
#define     mod2            998244353
#define     inf             2e18
#define 	hi   			"hello"
#define 	nl 				"\n"
#define 	ws 				" "
#define     sz              size()
#define     len             length()
#define 	F 				first
#define 	S 				second
#define 	PB 				push_back
#define 	MP				make_pair
#define 	B 				begin()
#define     RB              rbegin()
#define 	E 				end()
#define     UB              upper_bound
#define     LB              lower_bound
#define     present(k, m)   (m.find(k)!=m.end())?1:0
#define 	all(v) 			v.begin(), v.end()
#define 	reset(a, val) 	memset(a, val, sizeof(a))
#define     pll             pair<ll, ll>
#define     vll             vector<ll>
#define     vpll            vector<pll>
#define 	vs 				vector<string>
#define     vc              vector<char>
#define     sqr(a)          ((a)*(a))
#define 	print1(a) 		for(auto i : a)cout<<i<<" ";cout<<"\n"
#define 	print2(a) 		for(auto i : a)cout<<i;cout<<"\n"
#define 	print3(a) 		for(auto i : a)cout<<i<<nl;
#define 	boost 			ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

// ostringstream str1;
// str1 << n;
// string tmp = str1.str();
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) { return (a.second < b.second); }
 
bool compare(const pair<string, int>&a, const pair<string, int>&b){ return a.second<b.second; }
 
double logn(double n, double r) { return (n > r - 1) ? 1 + logn(n / r, r) : 0; }
 
// vll pwx(32);
// void cal(ll x){ pwx[0] = 1; rep(i, 1, 32)pwx[i] = x*pwx[i-1]; }
 
/* ################################################################ */

#define space 200005

void solve(){

    ll a, b, c, k, cnt = 0;
    cin >> a >> b >> c;
    cin >> k;

    while(a >= b){
        b *= 2;
        cnt++;
    }

    while(b >= c){
        c *= 2;
        cnt++;
    }

    if(cnt <= k){
        cout << "Yes\n";
        return;
    }

    cout << "No\n";
}

int main(){
    boost;
    // cal(3);
    int t = 1, k = 1;
    // cin>>t;
    while(t--){
        // cout<<"Case #"<<k<<": ";
        solve();
        k++;
    }
}


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

#ifdef LOCAL
    #define D(a) cerr << #a << " = " << a << endl
#else 
    #define D(a) 8 
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define all(a) (a).begin(),(a).end()
#define dforn(i,n) dforsn(i,0,n)
#define forn(i,n) forsn(i,0,n)
#define si(a) int((a).size())
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first
#define endl '\n'
using pii = pair<int,int>;
using vi = vector<int>;
using ll = long long;

int main() {
	fastio;
	
    int n; cin >> n;
    map<string, int> m;
    vi c(26, 50);
    forn(_, n) {
        string s; cin >> s;
        vi a(26);
        for (char x : s)
            a[int(x-'a')]++; 
        forn(i, 26) 
            c[i] = min(c[i], a[i]);
    }
    string ans;
    forn(i, 26) forn(j, c[i]) ans += char('a'+i);
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
#define big_sort(v) sort(all(v), [](long a, long b) { return a > b; })//大きい順にソート
using ll = long long;
using vi = vector<long>;
using vvi = vector<vi>;
using vs = vector<string>;
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
/*
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
*/
int main() {
  ll x,cnt=0,money=100;
  cin >> x;
  while(true){
    money*=1.01;
    cnt++;
    if(money>=x){
      cout << cnt << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<boost/multiprecision/cpp_int.hpp>
using big_int = boost::multiprecision::cpp_int;
#define ll long long
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define MAX_CHAR 128
using namespace boost::multiprecision;
using namespace std;

int main() 
{
	ll i,j,k,n,x,t;
	string s;
	ll h;
	cin>>h>>n;
	int a[n];
	ll sum=0;
	for(i=0;i<n;i++)
	{
	    cin>>a[i];
	    sum=sum+a[i];
	}
	if(sum>=h)
	cout<<"Yes";
	else cout<<"No";
	return 0;
}

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

int main()
{
    char a,b,c,d;
    cin>>a>>b>>c>>d;
    int x,y;
    x=(a-'0')*10+b-'0';
    y=(c-'0')*10+d-'0';
    if(x>=1&&x<=12&&y>=1&&y<=12)
        cout<<"AMBIGUOUS"<<endl;
    else if(x>=1&&x<=12)
        cout<<"MMYY"<<endl;
    else if(y>=1&&y<=12)
        cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

vector<vector<int> > split_vector(vector<int> &a, int pivot){
    vector<vector<int> > res;
    a.push_back(pivot);
    for(int i = 0; i < a.size(); i++){
        vector<int> tmp;
        while(i < a.size() && a[i] > pivot){
            tmp.push_back(a[i++]);
        }
        if(tmp.size() != 0) res.push_back(tmp);
    }
    a.pop_back();
    return res;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    vector<int> b = a;
    sort(b.begin(), b.end());
    int ans = INF;
    rep(i, 0, n){
        vector<vector<int> > d = split_vector(a, b[i] - 1);
        vector<int> cand;
        // cout << " now" << i << endl;
        // for(int ii = 0; ii < d.size(); ii++){
        //     for(int jj = 0; jj < d[ii].size(); jj++){
        //         if(jj) cout << ' ';
        //         cout << d[ii][jj];
        //     }
        //     cout << endl;
        // }
        // cout << endl;
        rep(j, 0, d.size()){
            // cout << j << " " << d[j].size() << endl;
            sort(d[j].begin(), d[j].end());
            if(d[j].size() < k) continue;
            rep(l, 0, d[j].size() - k + 1){
                cand.push_back(d[j][l]);
            }
        }
        if(cand.size() < q) continue;
        sort(cand.begin(), cand.end());
        int tmp = cand[q - 1] - cand[0];
        ans = min(ans, tmp);
    }
    cout << ans << endl;
}

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

inline ll add(ll x, ll y) {return (x+y)%MOD;}

int main(){
    ll N; cin >> N;
    ll dp[61][3];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    REP(i,60) REP(j,3){
        ll nn = (N>>(59-i))&1;
        REP(a,2) REP(b,2) {
            int ni = i+1;
            int nj = 2;
            if(b<a) continue;
            if(a+b>nn && j==0) continue;
            if(a+b<nn && j==0) nj = 1;
            else if(a+b==2 && j==1 && nn==1) nj = 1;
            else if(a+b==2 && j==1 && nn==0) nj = 0;
            else if(a+b==1 && j==1 && nn==0) nj = 1;
            else if(a+b==nn && j==0) nj = 0;
            dp[ni][nj] = add(dp[ni][nj], dp[i][j]); 
        }
    }
    ll ans = 0;
    REP(j,3) ans = add(ans, dp[60][j]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
 
int main(){
 int a,b;
  cin >> a >> b;
  if(a==b){
    rep(i,a){cout << a ;}
    cout << endl;
  }
  else if(a>b){
    rep(i,a){cout << b;}
    cout << endl;
  }
  else{
    rep(i,b){cout<< a;}
    cout << endl;
  }
}

Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $n);
$numbers = fgets(STDIN);
$exploded_numbers = explode(' ', trim($numbers));

$total = 0;
for ($i=0; $i<$n; $i++) {
  for ($j=$i+1; $j<$n; $j++) {
    $total += $exploded_numbers[$i] * $exploded_numbers[$j];
  }
}

echo $total;

Measured memory_bytes: 4732
#include <iostream>
#include <vector>

using namespace std;

using ll = long long;

int main() {
    int n;
    int x, a;
    cin >> n >> x;
    vector<int> input;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        input.push_back(a);
    }
    ll count = 0;
    for (int i=0; i<input.size()-1; ++i) {
        int tempSum = input[i]+input[i+1];
        if (tempSum > x) {
            int eat = tempSum-x;
            if (eat > input[i+1]) {
                input[i] -= eat-input[i+1];
                input[i+1] = 0;
            } else {
                input[i+1] -= eat;
            }
            count += eat;
        }
    }
    cout << count << endl;
}


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

#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 FORR(i,m,n) for(int i=(m) ; i>=(n) ; i--)

typedef long long ll;
typedef unsigned long long ull;

const int INF = 1000000000;

int main(){
   int n,m;cin>>n>>m;
   vector<int> x(n+1);
   vector<int> y(m+1);
   cin >> x[0];
   cin >> y[0];
   FOR(i,1,n+1)cin>>x[i];
   FOR(i,1,m+1)cin>>y[i];

   if(*max_element(x.begin(),x.end()) < *min_element(y.begin(),y.end())){
      cout << "No War";
   }else{
      cout << "War";
   }
   return 0;
}

Measured memory_bytes: 256
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

a, b, C = map(int, readline().split())
sinC = math.sin(math.radians(C))
cosC = math.cos(math.radians(C))

print(a * b * sinC / 2, a + b + (a ** 2 + b ** 2 - 2 * a * b * cosC) ** .5, b * sinC,sep='\n')



Measured memory_bytes: 5736
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		sc.fill(a);

		long sum = Arrays.stream(a).sum();
		int index = 0;
		for (int i = 0; i < a.length; i++) {
			if (Math.abs(sum - a[i] * N) < Math.abs(sum - a[index] * N)) {
				index = i;
			}
		}

		System.out.println(index);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 27732
def read_n_lows_input(n):
    Alist=[int(input()) for i in range(n)]
    return Alist

def print_list(A):
    print(*A, sep=" ")

def print_list_multi_low(A):
    for i in A:
        print(i)
    
def insertion_sort(A, n, g, cnt):
    for i in range(g-1, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v
    return A, cnt

def shell_sort(A, n):
    cnt = 0
    G0 = [797161, 265720, 88573, 29524, 9841, 3280, 1093, 364, 121, 40, 13, 4, 1]
    G = [i for i in G0 if i <= n]
    m = len(G)
    print(m)
    print_list(G)
    for i in range(m):
        A, cnt = insertion_sort(A, n, G[i], cnt)
    print(cnt)
    print_list_multi_low(A)

n=int(input())
A = read_n_lows_input(n)

shell_sort(A, n)



Measured memory_bytes: 45520
# ABC084C - Special Trains
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    arr = tuple(tuple(map(int, input().split())) for _ in range(n - 1))
    for i in range(n):
        cur = 0
        for c, s, f in arr[i:]:
            if cur <= s:
                cur = s + c
            elif cur % f == 0:
                cur += c
            else:
                cur += f - cur % f + c
        print(cur)


if __name__ == "__main__":
    main()

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

int main() {
  int N;
  cin >> N;
  
  vector<int> b(N-1);
  for( int i = 0; i < N-1; i++ ) cin >> b.at(i);
  
  int ans = 0;
  if( N == 2 ){ //bの長さが1のとき
    ans = b.at(0) * 2;
    cout << ans << endl;
    return 0; 
  }
  for( int i = 0; i < N-1; i++ ){
    if( i == 0 ){
      ans += b.at(i);
    }else{
      ans += min( b.at(i-1), b.at(i) );
    }
  }
  ans += b.at(N-2);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define inf 2147483647
#define eps 1e-9
using namespace std;
typedef long long ll;
int n,tot,a[800001];
char s[500001];
void mul(int a[],int &n,int k){ int p=0; tot=0; for(int i=1;i<=n;i++){ p=a[i]*k+p; a[i]=p%10; tot+=a[i]; p/=10; } if(p)a[++n]=p; tot+=p; }
void add(int a[],int &n,int k){
    int p=0; tot-=a[1]; a[1]+=k; p=a[1]/10; a[1]%=10; tot+=a[1];
    for(int i=2;i<=n;i++){ tot-=a[i]; a[i]+=p; p=a[i]/10; a[i]%=10; tot+=a[i]; if(!p)break; }
    if(p)a[++n]=p; tot+=p;
}
int main(){
    scanf("%s",s); n=strlen(s); for(int i=1;i<=n;i++){ a[i]=s[n-i]-'0'; }
    mul(a,n,9); for(int i=1;i<=n;i++){ add(a,n,9); if(tot%9==0&&i*9>=tot)return printf("%d",i),0; }
    return 0;
}

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

#define ll long long
#define ld long double
#define ull unsigned long long
#define pw(x) (1LL << (x))

#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n"
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int K, S, cnt = 0;
    cin >> K >> S;

    for (int X = 0; X <= K; ++X)
        for (int Y = 0; Y <= K; ++Y)
        {
            int Z = S - X - Y;
            cnt += (Z >= 0 && Z <= K);
        }

    cout << cnt;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define NUMBER 100


void print_array(int array[],int num)
{
	int i;
	
	for(i = 0; i < num - 1; i++){
		
		printf("%d ", array[i]);
	}
	printf("%d\n", array[i]);
	
}
	
void insertSort(int array[],int num)
{
	int i, v, j;
	for(i = 1; i <= num - 1; i++){
		print_array(array, num);
		v = array[i];
		j = i - 1;
		while(j >= 0 && array[j] > v){
			array[j + 1] = array[j];
			j--;
			
		}
		array[j + 1] = v;
	
    }
}

int main(void)
{
	int i, num;
	int array[NUMBER];

	scanf("%d", &num);
	
	for(i = 0; i < num; i++)
	{
		scanf("%d", &array[i]);
	}
	
	insertSort(array , num);
	
	print_array(array , num);
	
	
	return 0;
}


Measured memory_bytes: 2112
import java.util.*;

class Main{
    public static void main(String[] args){
        
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        String S = sc.next();
        String d = "EW";
        int[] e = new int[N];
        if(S.charAt(0)==d.charAt(0)){
            e[0] = 1;
        }
        else{
            e[0] = 0;
        }

        for(int i=1; i<N; i++){
            if(S.charAt(i)==d.charAt(0)){
                e[i] = e[i - 1] + 1;
            }
            else{
                e[i] = e[i - 1];
            }
        }
        int[] sum = new int[N];
        sum[0] = e[N - 1] - e[0];
        int ans = sum[0];
        for(int i=1; i<N; i++){
            sum[i] = i - e[i - 1] + e[N - 1] - e[i];
            ans = Math.min(ans, sum[i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 30400
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
int main()
{
	int i,p,l,t;
	string st;
	cin >> st;
	p=0; t=0;
	l=st.size();
	for(i=0; i<l; i++)
	{
		if(st[i]=='S') 
			p++;
		else if(p>0)
		{
			t++;
			p--;
		}
	}
	cout <<l-2*t;
}


Measured memory_bytes: 640
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(ll i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
constexpr ll mod = 1000000007;
constexpr ll INF = 1000000099;
constexpr ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}

template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}

template<typename T,typename Y>
ostream& operator<<(ostream& os,const pair<T,Y>& p){
   return os<<"{"<<p.fs<<","<<p.sc<<"}";
}
template<typename T> ostream& operator<<(ostream& os,const V<T>& v){
   os<<"{";
  for(auto e:v)os<<e<<",";
  return os<<"}";
}
template<typename ...Args>
void debug(Args&... args){
  for(auto const& x:{args...}){
    cerr<<x<<' ';
  }
  cerr<<ENDL;
}

ll n,a,b,c,d;


signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  int qq;cin>>qq;
  while(qq--){
    cin>>n>>a>>b>>c>>d;

    using Pa = pair<ll,ll>;
    map<ll,ll> D;//----------------
    priority_queue<Pa,vector<Pa>,greater<Pa> > q;
    D[n]=0;
    q.emplace(D[n],n);//最短距離、ゴール頂点番号
    D[0]=LINF;


  while(!q.empty()){
    ll spath=q.top().first;
    ll v=q.top().second;
    q.pop();

    if(D.count(v) && D[v]<spath) continue;
    D[v]=spath;
    rep(i,-4,5){
      if(v+i<0)continue;
      
      if(abs(i)<2 && (v+i)%2==0 && (!D.count((v+i)/2) || D[(v+i)/2]>D[v]+d*abs(i)+a)){
        D[(v+i)/2]=D[v]+d*abs(i)+a;
        q.emplace(D[(v+i)/2],(v+i)/2);
      }

      if(abs(i)<3 && (v+i)%3==0 && (!D.count((v+i)/3) || D[(v+i)/3]>D[v]+d*abs(i)+b)){
        D[(v+i)/3]=D[v]+d*abs(i)+b;
        q.emplace(D[(v+i)/3],(v+i)/3);
      }

      if(abs(i)<5 && (v+i)%5==0 && (!D.count((v+i)/5) || D[(v+i)/5]>D[v]+d*abs(i)+c)){
        D[(v+i)/5]=D[v]+d*abs(i)+c;
        q.emplace(D[(v+i)/5],(v+i)/5);
      }

      if(v+i==0){
        chmin(D[v+i],D[v]+d*abs(i));
      }
    }
    if(log10(v)+log10(d)<18.5)chmin(D[0],D[v]+v*d);
    //cerr<<v<<ENDL;
  } 
    cout<<D[0]<<ENDL;

  }
}
//! ( . _ . ) ! 
//CHECK overflow,vector_size,what to output?

Measured memory_bytes: 4696
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

const int inf = 1e5+1;
ll m[inf];
int main() {
  ll n,k;
  cin >> n >> k;
  rep(i,n){
    ll a,b;
    cin >> a >> b;
    m[a]+=b;
  }
  int ans;
  rep(i,inf){
    k -= m[i];
    if(k<=0){
      ans = i;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include "stdio.h"
#include "ctype.h"

int i;
char ch;
int cnt=0;
char out[1200];
int main(){
	while(1){
		scanf("%c",&ch);
		if(ch=='\n') break;
		if(islower(ch)){
			out[cnt]=toupper(ch);
		}else{
			if(isupper(ch)){
				out[cnt]=tolower(ch);
			}else{
				out[cnt]=ch;
			}
		}
		cnt++;
	}//文字数=cnt
	
	for(i=0;i<cnt;i++) printf("%c",out[i]);
	printf("\n");
 return 0;	
}

Measured memory_bytes: 524
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Map<Integer,Integer> map = new HashMap<Integer,Integer>();
        Scanner sc = new Scanner(System.in);
        long sum = 0;
        int n = sc.nextInt();
        for(int i = 0 ; i < n ; i++){
            int a = sc.nextInt();
            sum += a;
            map.merge(a,1,Integer::sum);
        }
        int q = sc.nextInt();
        for(int i = 0 ; i < q ;i++){
            int b = sc.nextInt();
            map.merge(b,0,Integer::sum);
            int c = sc.nextInt();
            map.merge(c,0,Integer::sum);
            sum += (c-b)*map.get(b);
            System.out.println(sum);
            map.merge(c,map.get(b),Integer::sum);
            map.put(b,0);
        }
    }
}

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


int main() {
	int a, b; CI a >> b;
	if (b % a) CO b - a EN;
	else CO b + a EN;
}


Measured memory_bytes: 256
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

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


int main() {

	long long n; cin >> n;
	long long mul = 1;
	bool flg1 = false;
	bool flg2 = false;
	for (long long i = 1; i <= n; i++) {
		long long a; cin >> a;
		if (a == 0) {
			flg2 = true;
			break;
		}
		if (a > ((long long)1e18 / mul)) {
			flg1 = true;
		}
		if (flg1 == false) mul *= a;
	}

	if (flg1 == false and flg2 == false) cout << mul;
	else if (flg1 == true and flg2 == false) cout << -1;
	else if (flg1 == false and flg2 == true) cout << 0;
	else if (flg1 == true and flg2 == true) cout << 0;

	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
int x, y;
int dpx[2][20010], dpy[2][20010];
vector<int> vx, vy;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s >> x >> y;
  int l = 0, r = 0, turn = 0;
  while (r < s.size() && s[r] == 'F') r++;
  dpx[0][10000+r-l] = 1;
  dpy[0][10000] = 1;
  l = r;
  while (l < s.size()) {
    while (l < s.size() && s[l] == 'T') l++, r++, turn ^= 1;
    while (r < s.size() && s[r] == 'F') r++;
    if (turn == 0) vx.emplace_back(r-l);
    else vy.emplace_back(r-l);
    l = r;
  }
  for (int i = 0; i < vx.size(); i++) {
    fill_n((int*)dpx[1], 20010, 0);
    for (int j = 0; j < 20010; j++) {
      if (j-vx[i] >= 0) dpx[1][j-vx[i]] |= dpx[0][j];
      if (j+vx[i] < 20010) dpx[1][j+vx[i]] |= dpx[0][j];
    }
    swap(dpx[0], dpx[1]);
  }
  for (int i = 0; i < vy.size(); i++) {
    fill_n((int*)dpy[1], 20010, 0);
    for (int j = 0; j < 20010; j++) {
      if (j-vy[i] >= 0) dpy[1][j-vy[i]] |= dpy[0][j];
      if (j+vy[i] < 20010) dpy[1][j+vy[i]] |= dpy[0][j];
    }
    swap(dpy[0], dpy[1]);
  }
  cout << (dpx[0][10000+x] && dpy[0][10000+y] ? "Yes" : "No") << endl;

  return 0;
}

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

#define mp make_pair

inline int read()
{
	int x=0;char ch=getchar();
	for(;!isalnum(ch);ch=getchar());
	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}

const int xx=1e6+10;

int hd[xx],nt[xx],to_1[xx],to_2[xx],num=0;
int head[xx],nxt[xx<<1],to[xx<<1],cnt=0;
int id[xx],n,m,all,mx=0;
int f[xx],que[xx],ft=0,bk=0;
int anc[xx],son[xx];
bool use[xx];

inline void add(int v,int u)
{
	nxt[++cnt]=head[v];
	to[head[v]=cnt]=u;
}

inline void init(int g)
{
	anc[g]=g;
	son[g]=id[g]=use[g]=0;
}
inline int find(int g)
{
	return anc[g]==g?g:anc[g]=find(anc[g]);
}
inline void mg(int x,int y)
{
	int v=find(x),u=find(y);
	if(v==u) return;
	if(son[v]<son[u]) anc[v]=u;
	else
	{
		anc[u]=v;
		if(son[v]==son[u]) ++son[v];
	}
}

int main()
{
	n=all=read(),m=read();
	for(register int i=1,a,b,c;i<=m;++i)
	{
		a=read(),b=read(),c=read();
		nt[++num]=hd[c];
		to_1[num]=a,to_2[num]=b;
		hd[c]=num;
		mx=max(mx,c);
	}
	for(register int i=1;i<=mx;++i)
	{
		for(register int j=hd[i];j;j=nt[j])
			init(to_1[j]),init(to_2[j]);
		for(register int j=hd[i];j;j=nt[j])
			mg(to_1[j],to_2[j]);
		for(register int j=hd[i],k;j;j=nt[j])
		{
			k=find(to_1[j]);
			if(!id[k]) id[k]=++all;
			if(!use[to_1[j]]) add(id[k],to_1[j]),add(to_1[j],id[k]);
			if(!use[to_2[j]]) add(id[k],to_2[j]),add(to_2[j],id[k]);
		}
	}
	f[1]=1,que[ft]=1;
	while(ft<=bk)
	{
		int v=que[ft++];
		for(register int i=head[v],j;i;i=nxt[i])
			if(!f[j=to[i]])
			{
				f[j]=f[v]+1;
				que[++bk]=j;
			}
	}
	if(!f[n]) puts("-1");
	else printf("%d\n",(f[n]-1)>>1);
	return 0;
}

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

int main(){
    char c; cin >> c;
    if (c=='a' || c=='i' || c=='u' || c=='e' || c=='o'){
        cout << "vowel" << endl;
    } else {
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define N 11
int main()
{
    int length;
    char s[N];
    int i;
    int p=0;
    scanf("%s",s);
    length=strlen(s);
   
    if(length%2!=0){
        printf("No\n");
    }else{
        for(i=0;i<length/2;i++){
            if(s[2*i]!='h'||s[2*i+1]!='i'){
                p=1;
            }
        }
        if(p!=1)
            printf("Yes\n");
        else{
            printf("No\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

enum MOD = (10 ^^ 9) + 7;

void main()
{
    long X = lread();
    long l = 1;
    long r = 50000;
    while (1 < r - l)
    {
        long m = (l + r) / 2;
        if (m * (m + 1) / 2 < X)
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    writeln((l * (l + 1) / 2 == X) ? l : r);
}


Measured memory_bytes: 256
function main(input) {
    var array = input.split('\n');
    var numbers=array[1].split(' ');
    var counter = 0;

    for(i=0; i< numbers.length; i++){
        counter += numbers[i]-1;
    }
    
    console.log(counter);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main()
{
    char s[3];
    int ans=700;
    cin >> s;
    for(int i=0;i<3;i++){
        if(s[i]=='o'){
            ans+=100;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <math.h>
using namespace std;
inline int getprime(int x) {
	int i = sqrt(x);
	while (i > 1) {
		if (x % i == 0) return 0;
		else i--;
	}
	return 1;
}
int main() {
	int n;
	cin >> n;
	int x;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cin >> x;
		cnt += getprime(x);
	}
	cout << cnt << endl;
	return 0;

}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;++i)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main(){
  int n,m;cin>>n>>m;
  vector<P> p;
  int a;
  fol(i,n){
    cin>>a;
    p.pb(make_pair(a,1));
  }
  int b,c;
  fol(i,m){
    cin >> b >> c;
    p.pb(make_pair(c,b));
  }
  sort(p.rbegin(),p.rend());
  ll ans = 0;
  int x;
  x = 0;
  while(n>0){
    a = p[x].first, b = min(p[x].second, n);
    ans += (ll)a * b;
    n -= b;
    x++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (auto &e : a) {
    cin >> e.first >> e.second;
  }
  sort(begin(a), end(a));

  vector<int> v;
  for (auto e : a) {
    if (v.empty() || v.back() <= e.first) {
      v.push_back(e.second);
    } else {
      *rbegin(v) = min(v.back(), e.second);
    }
  }
  cout << v.size() << endl;
  return 0;
}


Measured memory_bytes: 1024
/* Code by : Suraj (@suraj1611) */

#include<bits/stdc++.h>
#include <string>

using namespace std;

#define ll long long int
#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define mx INT_MAX
#define mn INT_MIN
#define md 1000000007
#define pb push_back
#define mp make_pair
#define maxsize 1100005
#define lb cout<<endl;
#define endl "\n"
#define F first
#define S second
#define label cout<<"hello!"<<endl
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll x, ll  y) 
{ 
	ll m=md;
   	ll ans=1;
    while (y > 0) 
    {
        if (y & 1)
            ans = (ans * x) % m;
        x = (x * x) % m;
        y >>= 1;
    }
    return ans;
} 

int main()
{
	IOS


	ll n;cin>>n;
	ll a[n];
	rep(i,n)
	{
		cin>>a[i];
	}

	ll c=1,cur=a[0];
	rep1(i,n-1)
	{
		if(a[i]>=cur)
			cur=a[i],c++;
	}

	cout<<c<<endl;



    return 0;
}


Measured memory_bytes: 256
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan,sqrt
import cmath as cma
import copy as cp
import sys
import re
sys.setrecursionlimit(10**7)
EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf
MOD = 10**9 + 7

def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
def adj(n): return [[] for _ in range(n)]

s = sinput()
ans = s[:3]
print(ans)


Measured memory_bytes: 37584
s = input()
t = input()

ans = 'UNRESTORABLE'
def test(i):
    for ns, nt in zip(s[i:i+len(t)], t):
        if ns == '?':
            continue
        if ns != nt:
            return False
    return True

for i in range(len(s) - len(t) + 1):
    if test(i):
        re_s = s.replace('?', 'a')
        ans = re_s[:i] + t + re_s[i+len(t):]

print(ans)


Measured memory_bytes: 61996
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	int tmp;
	vector<string>s(n);
	vector<string>s2(n);
	vector<int>p(n);
	vector<int>t(n);
	for (int i = 0; i < n; i++) {
		cin >> s[i] >> p[i];
		t[i] = i;
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n-1; j++) {
			if (s[j] > s[j+1]) {
				swap(t[j], t[j+1]);
				swap(s[j], s[j+1]);
				swap(p[j], p[j + 1]);
			}
			if (s[j] == s[j+1] && p[j] < p[j+1]) {
				swap(t[j], t[j+1]);
				swap(s[j], s[j + 1]);
				swap(p[j], p[j + 1]);
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << t[i]+1 << endl;
		//cout << p[i] << endl;
	}

}

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

int main(){
  int a,b;
  cin >> a >> b;
  if(a % 3 == 0){
    cout << "Possible" << endl;
  }
  else if(b % 3 == 0){
    cout << "Possible" << endl;
  }
  else if((a+b) % 3 == 0){
    cout << "Possible" << endl;
  }
  else{
    cout << "Impossible" << endl;
  }
}

Measured memory_bytes: 256
Sa = str(input())
Sb = str(input())
Sc = str(input())
turn = "a"
while True:
    if turn == "a":
        if Sa == "Agari":
            print("A")
            exit()
        elif len(Sa) == 1:
            turn = Sa[0]
            Sa = "Agari"
        else:
            turn = Sa[0]
            Sa = Sa[1::]
    elif turn == "b":
        if Sb == "Agari":
            print("B")
            exit()
        elif len(Sb) == 1:
            turn = Sb[0]
            Sb = "Agari"
        else:
            turn = Sb[0]
            Sb = Sb[1::]
    else:
        if Sc == "Agari":
            print("C")
            exit()
        elif len(Sc) == 1:
            turn = Sc[0]
            Sc = "Agari"
        else:
            turn = Sc[0]
            Sc = Sc[1::]


Measured memory_bytes: 3064
N = int(input())
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A2.reverse()

C1 = [A1[0]]
for i in range(1, N):
    C1.append(C1[i-1]+A1[i])

C2 = [A2[0]]
for i in range(1, N):
    C2.append(C2[i-1]+A2[i])
C1.reverse()

ans = C1[0] + C2[0]
for i in range(1, N):
    ans = max(ans, C1[i]+C2[i])
print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int main(){
    string s;
    int k;
    cin>>k>>s;
    if(s.length()<k){
        cout<<s;
        return 0;
    }
    for(int i=0;i<k;i++){
        cout<<s[i];
    }
    if(s.length()>k){
        cout<<"...";
    }
}    

Measured memory_bytes: 3584
N = int(input())
A = list(map(int, input().split()))
money = 1000
stock = 0
for i in range(N - 1):
    if A[i] < A[i + 1] and money >= A[i]:
        stock += (money // A[i])
        money %= A[i]
    elif A[i] > A[i + 1]:
        money += stock * A[i]
        stock = 0
money += (stock * A[N - 1])
print(money)

Measured memory_bytes: 9068
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

int md = MOD;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}
 
inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}
 
inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % md);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (md)
  );
  return m;
}
 
inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}
 
inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

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

  int n;
  cin >> n;
  
  int a[n+1];
  int check[n] = {};
  REP(i,n+1){
    cin >> a[i];
    check[--a[i]]++;
  }
  
  int c,l = -1,r = -1;
  REP(i,n){
    if(check[i] == 2){
      c = i;
      break;
    }
  }
  
  REP(i,n+1){
    if(a[i] == c){
      if(l == -1){
        l = i;
      }
      else{
        r = i+1;
        break;
      }
    }
  }
  
  ll ans[n+1];
  ans[0] = n+1;
  FOR(i,1,n+1){
    ans[i] = mul(ans[i-1],mul(n+1-i,inv(i+1)));
  }
  
  ll cnt[n+1];
  cnt[0] = 1; // 長さ１のとき重複１
  FOR(i,1,n+1){
    if(n+1-r+l >= i){
      cnt[i] = mul(cnt[i-1],mul(n+1-r-i+1+l,inv(i)));
    }
    else cnt[i] = 0;
  }
  
  REP(i,n+1){
    int ANS = ans[i]-cnt[i];
    if(ANS < 0) ANS += MOD;
    cout << ANS <<endl;
  }

  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007

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

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

ll fact(ll n){
    if(n==0)
        return 1;
    else
        return n*fact(n-1);
}

ll cal(ll W[], ll V[], ll K, ll N){
    K++;
    ll dp[N][K]={},i,j;

    for(i=0;i<N;i++){
        for(j=0;j<K;j++){
            if(i==0){
                if(W[i]<=j)
                    dp[i][j] = V[i];
            }
            else{
                if(j-W[i]<0)
                    dp[i][j] = dp[i-1][j];
                else
                    dp[i][j] = max(V[i]+dp[i-1][j-W[i]],dp[i-1][j]);
            }
        }
    }
    /*for(i=0;i<N;i++){
        for(j=0;j<K;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<"\n";
    }*/
    return dp[N-1][K-1];

}

void solve(){

    ll N,K;
    cin>>N>>K;
    ll W[N],V[N],i;
    for(i=0;i<N;i++){
        cin>>W[i]>>V[i];
    }
    ll c = cal(W,V,K,N);
    cout<<c;

}

int main(){
    //freopen("D:\\codes\\1input.txt","r",stdin);
    //freopen("D:\\codes\\1output.txt","w",stdout);
    ll T=1;
    //cin>>T;
    for(ll t=1;t<=T;t++){

        //cout<<"Case #"<<t<<": ";
        solve();
        //cout<<"\n";
    }
}


Measured memory_bytes: 81672
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
def pri(x): print('\n'.join(map(str, x)))

N, K = map(int, input().split())

dum = list(range(N+1))

cnt = 0
minv = sum(dum[:K])
maxv = sum(dum[-K:])
for i in range(K, N+2):
    cnt += maxv-minv+1
    if cnt > MOD:
        cnt %= MOD
    minv += i
    maxv += N-i
print(cnt)



Measured memory_bytes: 18428
package main

import (
	"fmt"
)

func main() {
	var n, m, s int
	fmt.Scan(&n, &m)
	for k := 0; k <= n; k++ {
		v := ModCombination(n, k)
		v = v * ModPermutation(m, k) % Mod
		v = v * ModPermutation(m-k, n-k) % Mod
		v = v * ModPermutation(m-k, n-k) % Mod
		if k%2 == 1 {
			v = Mod - v
		}
		s = (s + v) % Mod
	}
	fmt.Println(s)
}

const Mod = int(1e9) + 7

func ModInverse(n int) int { return ModPow(n, Mod-2) }
func ModDiv(a, b int) int  { return a * ModInverse(b) }
func ModPow(a, b int) int {
	x := 1
	for b > 0 {
		if b&1 == 1 {
			x = x * a % Mod
		}
		a = a * a % Mod
		b >>= 1
	}
	return x
}
func ModFactorial(n int) int      { return fac[n] }
func ModPermutation(n, r int) int { return fac[n] * finv[n-r] % Mod }
func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 5 * 1e5
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for 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
	}
}


Measured memory_bytes: 14012
init = map(int, raw_input().split())
found = False
for loopnum in range(init[0]):
	scanline = map(int, raw_input().split())
	if scanline[1] <= init[1]: 
		if found == False:
			mincost = scanline[0]
			found = True
		else:
			if scanline[0] < mincost:
				mincost = scanline[0]

if found == False:
	print "TLE"
else:
	print mincost

Measured memory_bytes: 2568
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
    int N; cin >> N;
    vector<pair<int,int>> task;
    rep(i,N){
        int a,b; cin >> a >> b;
        task.emplace_back(b,a);
    }

    sort(task.begin(),task.end());
    int time = 0;
    bool is_ok = true;
    for(auto i : task){
        time += i.second;
        if(time > i.first){
            is_ok = false;
            break;
        }
    }

    cout << (is_ok? "Yes":"No") << endl;
}


Measured memory_bytes: 2420