akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))


N = int(input())
A = LI()
Q = int(input())


move_dic = {}
revers_move_dic = {}
for i in range(1,10**5):
    revers_move_dic[i] = -1

BC = [() for i in range(Q)]
for q in range(Q):
    BC[q] = LI()


anss = []
A_collections = collections.Counter(A)

# print(A_collections)
ans = sum(A)
for q in range(Q):
    b,c = BC[q]

    if b in A_collections.keys():
        A_collections[c] += A_collections[b]
        ans += (c - b) * A_collections[b]
        A_collections[b] = 0
    print(ans)

    


Measured memory_bytes: 46204
fun main(args: Array<String>)
{
    val (w, h, x, y) = readLine()!!.split(" ").map{it.toDouble()}

    val flag = if (x == w/2 && y == h/2) 1 else 0
    println("${w * h / 2} $flag")
}


// Read an integer
// Usage: val a = readInt()
private fun readInt() = readLine()!!.toInt()

// Read N integers separated by " "
// Usage: val (a, b, c) = readNInts()
private fun readNInts() = readLine()!!.split(" ").map(String::toInt)

// Read a string
// Usage: val a = readString()
private fun readString() = readLine()!!


Measured memory_bytes: 37916
#include <stdio.h>
#include <stdlib.h>

int cmpnum(const void * n1, const void * n2) {
	if (*(long *)n1 > *(long *)n2)
	{
		return -1;
	}
	else if (*(long *)n1 < *(long *)n2)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long x[n],y[n],z[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld %ld %ld", &x[i], &y[i], &z[i]);
  }
  long value[8][n];
  for (long i = 0; i < n; i++) {
    value[0][i] = x[i]+y[i]+z[i];
    value[1][i] = x[i]+y[i]-z[i];
    value[2][i] = x[i]-y[i]+z[i];
    value[3][i] = x[i]-y[i]-z[i];
    value[4][i] = -x[i]+y[i]+z[i];
    value[5][i] = -x[i]+y[i]-z[i];
    value[6][i] = -x[i]-y[i]+z[i];
    value[7][i] = -x[i]-y[i]-z[i];
  }
  long max = 0;
  long sum;
  for (long i = 0; i < 8; i++) {
    qsort(value[i], n, sizeof(long), cmpnum);
    sum = 0;
    for (long j = 0; j < m; j++) {
      sum += value[i][j];
    }
    if (sum > max) {
      max = sum;
    }
  }
  printf("%ld\n", max);

  return 0;
}

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

const int INF = 1 << 29;

int main()
{
    int n,u,k,v,c;
    int V[101][101];
    fill((int*)V, (int*)(V + 101), INF);
    
    cin >> n;
    for(int i = 0; i < n; ++i){
        V[i][i] = 0;
    }
    
    for(int i = 0; i < n; ++i){
        cin >> u >> k;
        for(int j = 0; j < k; ++j){
            cin >> v >> c;
            V[u][v] = c;
        }
    }
    
    for(int k = 0; k < n; ++k){
        for(int i = 0; i < n; ++i){
            for(int j = 0; j < n; ++j){
                V[i][j] = min(V[i][j],V[i][k] + V[k][j]);
            }
        }
    }
    
    for(int i = 0; i < n; ++i){
        cout << i << ' ' << V[0][i] << endl;
    }
    
}

Measured memory_bytes: 1200
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	int Alice = 0;
	int Bob = 0;
	for (int i = 0; i < N; ++i)
	{
		i % 2 == 0 ? Alice += a[i] : Bob += a[i];
	}
	cout << Alice - Bob << endl;
    return 0;
}

Measured memory_bytes: 256
def solve(string):
    n, k = map(int, string.split())
    ans = 0
    for i in range(1, n + 1):
        tmp = i
        p = 1
        while i < k:
            i *= 2
            p /= 2
        ans += p

    return ans / n


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <set>

using namespace std;

template<typename T>inline T get(){T x;cin>>x;return x;}

int main()
{
    int n = get<int>();
    vector<int> p(n);
    for (int i = 0; i < n; i++) {
        p[i] = get<int>();
    }

    int ans = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((min(p[i-1],p[i])==p[i] || min(p[i],p[i+1])==p[i]) &&
            min(min(p[i-1],p[i]),p[i+1]) != p[i])
            ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<cmath>

using namespace std;

int main()
{
	int N, X;
	cin >> N >> X;
	int minG = 100000;

	for (int i = 0; i < N; i++)
	{
		int m;
		cin >> m;
		X -= m;
		if (minG > m)
			minG = m;
	}

	int ans = N;

	ans += X / minG;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
X = input()

cnt = X.count('1')
if cnt == 1:
    for x in X[:-1]:
        if x == '0':
            print(1)
        else:
            print(0)
    if X[-1] == '1':
        print(0)
    else:
        print(2)
    exit()

M = 0
for x in X:
    M <<= 1
    if x == '1':
        M += 1

def solve(n):
    ret = 1
    while n > 0:
        ret += 1
        n %= bin(n).count('1')
    return ret

ans = []
p = M % (cnt + 1)
m = M % (cnt - 1)

for i in range(N):
    if X[i] == '0':
        ans.append(solve((p + pow(2, N - i - 1, cnt + 1)) % (cnt + 1)))
    else:
        ans.append(solve((m - pow(2, N - i - 1, cnt - 1)) % (cnt - 1)))
print(*ans, sep='\n')


Measured memory_bytes: 14412
#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 x;
    cin >> x;
    if (x >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <functional>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<ll> A(N);

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

  }

  vector<ll> B(N);
  B[N-1] = A[N-1];

  for(int i = N-1;i > 0;i--){
    B[i-1] = B[i] + A[i-1];
  }


  for(int i = 0;i < N-1;i++){
    A[i+1] = A[i+1] + A[i];
  }

  
  ll ans = abs(A[0] - B[1]);

  for(int i = 0;i < N-1;i++){
    ans = min(ans,abs(A[i]-B[i+1]));
  }

  cout << ans << endl;

}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define f0(i,a,b) for(int i=a;i<b;i++)
#define f1(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mod 1000000007

int jump(vector<int>,int,int);

int main(){
    fast
    int n;
    cin>>n;
    vector<int> h;
    f0(i,0,n){
        int temp;
        cin>>temp;
        h.pb(temp);
    }

    int ans=jump(h,0,n);
    cout<<ans;
}

int jump(vector<int> h,int i,int n){
    vector<int> dp(2);
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    f0(i,2,n){
        dp.pb(min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1])));
    }
    return dp[n-1];
}

Measured memory_bytes: 1784
#include<bits/stdc++.h>
using namespace std;
long n,x[1000],y[1000];
vector<long>d;
main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[i]>>y[i];
		if(abs(x[i])+abs(y[i])&1^abs(x[0])+abs(y[0])&1){
			cout<<-1;
			return 0;
		}
	}
	for(int i=31;i--;)d.push_back(1<<i);
	if(abs(x[0])+abs(y[0])&1^1)d.push_back(1);
	cout<<d.size()<<" ";
	for(int i=0;i<d.size();i++)cout<<d[i]<<" ";
	for(int i=0;i<n;i++){
		long X=x[i],Y=y[i];
		string s=" ";
		for(int j=0;j<d.size();j++)s+=abs(X)>abs(Y)?X>0?X-=d[j],"R":(X+=d[j],"L"):Y>0?Y-=d[j],"U":(Y+=d[j],"D");
		cout<<s;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N,M;
    cin >> N >> M;
    vector<vector<ll>> G(N*3+10);
    ll u,v;
    rep(i,M){
        cin >> u >> v;
        u--;v--;
        G[u].push_back(v+N);
        G[u+N].push_back(v+N+N);
        G[u+N+N].push_back(v);
    }
    ll S,T;
    cin >> S >> T;
    S--;T--;
    queue<ll> que;
    que.push(S);
    vector<ll> memo(N*3+10, 1e18);
    memo[S] = 0;
    while(!que.empty()){
        ll a =  que.front();
        que.pop();
        for(auto& b:G[a]){
            if(memo[b] != 1e18) continue;
            memo[b] = memo[a] + 1;
            que.push(b);
        }
    }
    if(memo[T] == 1e18){
        cout << -1 << endl;
    }else{
        cout << memo[T]/3 << endl;
    }
}

Measured memory_bytes: 21896
N = int(input())
D, X = map(int, input().split())
A = [int(input()) for _ in range(N)]

cnt = N
for i, a in enumerate(A):
    n = 1
    while True:
        n += a
        if n > D:
            break
        else:
            cnt += 1

print(cnt+X)


Measured memory_bytes: 38512
#include <iostream>
#include <fstream>
#include <iomanip>
#include <math.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <string>
#include <string.h>
#include <sstream>
#include <ctime>

using namespace std;

#define eps 1e-12
#define pi 3.14159265358979323846
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define bgn begin
#define ll long long
#define ld long double
#define ull unsigned long long
#define ii pair<ll,ll>










const int N=1e5+10;
int n,k2,res;
char s[N];



void solve()
{
	cin>>(s+1);
	n=strlen(s+1);
	res=1;
	k2=n;
	for(int i=n-1;i>=1;i--)
	{
		if(s[i]!=s[i+1])k2=i;
		if(res+1>k2)break;
		res++;
	}
	cout<<res<<"\n";
}

int main()
{
	std::ios::sync_with_stdio(0);
	cin.tie(0);
#ifdef localProject
	freopen("in.txt","r",stdin);
#endif
	solve();
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
string negaternary(int value)
{
    string result;
    do
    {
        int remainder = value % -2;
        value = value / -2;
        if (remainder < 0)
        {
            remainder += 2;
            value += 1;
        }
        result = to_string(remainder) + result;
    } while (value != 0);
    return result;
}
int main(){
    long long int n;
    cin >> n;
    cout << negaternary(n) << endl;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc076/tasks/abc076_c
S = input()
T = input()

"""
アルゴリズム
Ｓの文字を一つずつずらしていって、Ｔが代入できるかどうかみる。
代入できるものなら代入してそのなかで辞書最小の文字列を保存する
全インデックスを試してみてできた文字列のなかで最小のものを出力
配列がなければＵＮ・・・を出力
"""
min_list = []

for i in range(len(S) - len(T) + 1):
    cut_s = S[i:i+len(T)]
    flg = True
    for s in range(len(cut_s)):
        if cut_s[s] == "?":
            continue
        if cut_s[s] == T[s]:
            continue
        else:
            flg = False
            break

    if flg:
        ano_s = S[:i] + T + S[i+len(T):]
        ano_s = ano_s.replace("?","a")
        min_list.append(ano_s)

# min_listの中で辞書順に最小のものを出力
if len(min_list) > 0:
    min_list.sort()
    print(min_list[0])
else:
    print("UNRESTORABLE")

Measured memory_bytes: 3064
import java.io.*;
import java.util.StringTokenizer;

class Rectangle {
	double x[] = new double[2];
	double y[] = new double[2];

	Rectangle(double x1,double y1,double x2,double y2) { //左下:(x0,y0) 右上:(x1,y1)
		x[0] = x1;
		y[0] = y1;
		x[1] = x2;
		y[1] = y2;
	}

	boolean hasIntersection(Rectangle r) {
		if (this.x[0]<=r.x[0]&&r.x[0]<=this.x[1]) {
			return checkY(r);
		} else if (r.x[0]<=this.x[0]&&this.x[0]<=r.x[1]) {
			return checkY(r);
		}
		return false;
	}

	boolean checkY(Rectangle r) {
		if (this.y[0]<=r.y[0]&&r.y[0]<=this.y[1]) return true;
		else if (this.y[0]<=r.y[1]&&r.y[1]<=this.y[1]) return true;
		else if (r.y[0]<=this.y[0]&&this.y[1]<=r.y[1]) return true;
		else return false;
	}
}

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf);
				double x[] = new double[4];
				double y[] = new double[4];
				for (int i=0;i<4;i++) {
					x[i] = Double.parseDouble(st.nextToken());
					y[i] = Double.parseDouble(st.nextToken());
				}
				Rectangle r[] = new Rectangle[2];
				r[0] = new Rectangle(x[0],y[0],x[1],y[1]);
				r[1] = new Rectangle(x[2],y[2],x[3],y[3]);
				if (r[0].hasIntersection(r[1])) System.out.println("YES");
				else System.out.println("NO");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16948
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update>
using namespace std; 
#define ll long long  
#define pb push_back
#define F first
#define S second
#define all(c)  c.begin(), c.end()
#define mp make_pair
#define endl "\n"
#define forn(i,n) for(int i = 0; i < int(n); ++i)
#define forni(i,a,b) for(int i=int(a) ; i<=int(b) ; ++i)
#define sz(z) (int)z.size()
#define lb lower_bound
#define ub upper_bound 
#define dbg cout << "yo" << endl  
#define N (ll)4e5+10
#define M (ll)1e6+10 

typedef pair<ll,ll> pll ;
typedef vector<pair<ll,ll>> vpll ;
typedef vector<ll> vll ;
typedef vector<char> vch ;
typedef vector<bool> vbl ;

ll mod = 998244353 ;
ll t[4*N] , a[N] ;
void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = a[tl];
    } else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = 0;
    }
}

void update(int v, int tl, int tr, int l, int r, int add) {
    if (l > r) return;

    if (l == tl && r == tr) {
        t[v] = (t[v]+add)%mod ;

    } else {
        int tm = (tl + tr) / 2;
        update(v*2, tl, tm, l, min(r, tm), add);
        update(v*2+1, tm+1, tr, max(l, tm+1), r, add);
    }
}

ll get(int v, int tl, int tr, int pos) {
    if (tl == tr)
        return t[v];
    int tm = (tl + tr) / 2;
    if (pos <= tm)
        return (t[v] + get(v*2, tl, tm, pos) )%mod ;
    else
        return (t[v] + get(v*2+1, tm+1, tr, pos) )%mod ;
}

int main(){
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif
    ios::sync_with_stdio(0);
    
    int n , k ;
    cin >> n >> k ;
    int l[k] , r[k] ;
    forn(i,k){
        cin >> l[i] >> r[i] ;
    }
    
    a[1]=1 ;
    build(1 , 1 , 2*n) ;
    for(int i=1 ; i<n ; i++){
          //cout << i << endl ;
         forn(j,k){
            //cout << i+l[j] << " " << i+r[j] << endl ;
            update(1, 1 , 2*n , i+l[j] , i+r[j] , get(1, 1 , 2*n , i) );
         }
    }

    ll ethan = get(1 , 1 , 2*n , n) ;

    cout << ethan ;

    

    return 0 ;
    
}



Measured memory_bytes: 11792
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string s;
    cin>>s;
    int ans=0;
    vector <string> data(500);
    int count=0;
    for(int i=0;i<s.size();i++){
        string tmp = s.substr(0,i);
        if(i%2==0) {
            if(data[i/2]==tmp) ans=i;
            //cout<<i<<endl;
        }
        tmp+=tmp;
        data [count++]=tmp;
        //cout<<data[count-1]<<'*' <<i <<endl;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())

ans = 0
ls = ['3','5','7']
for x in ls:
    st = deque([])
    flag = False
    st.append((x, flag))
    while st:
        cur, f = st.pop()
        if f:
            ans += 1
        else:
            if '3' in set(list(cur)) and '5' in set(list(cur)) and '7' in set(list(cur)):
                # print(cur)
                f = True
                ans += 1
        for y in ls:
            if int(cur + y) <= N:
                st.append((cur+y, f))
print(ans)

Measured memory_bytes: 9460
#include<iostream>
#include<string>
#include<algorithm>
#include<numeric>
#include<cmath>
#include<vector>
#include<iomanip>
#include<map>
#include<set>
#include<utility>
#include<iterator>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
//#define t ll t;cin>>t;while(t--)
#define nn cout<<endl;
#define ff(a,n) for(ll i=a;i<n;i++)
#define cY cout<<"YES\n"
#define cN cout<<"NO\n"
#define cy cout<<"Yes\n"
#define cn cout<<"No\n"
#define sc second
#define fs first
#define c(a) cout<<a<<endl

void solve()
{
	ll x, y; cin>>x>>y;
	if(y%2==0&&y>=(x*2)&&y<=x*4)
	{
		cy; return;
	} 
	cn;
}

int main()
{
	solve();
}
/*




*/


Measured memory_bytes: 3616
H, W = map(int, input().split())
S = [['.' for _ in range(W+2)]]+[['.'] + list(input())+ ['.'] for _ in range(H)]+[['.' for _ in range(W+2)]]
S
Flag = True
for i in range(1,H+1):
    for j in range(1, W+1):
        if S[i][j]=='.':
            continue
        if S[i-1][j] == S[i+1][j] == S[i][j-1] == S[i][j+1] == '.':
            Flag = False
if Flag:
    print('Yes')
else:
    print('No')
    

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func scan(scanner *bufio.Scanner) int64 {

	scanner.Scan()
	n, err := strconv.ParseInt(scanner.Text(), 10, 64)

	if err != nil {
		panic(err)
	}

	return n
}

func main() {

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	n := scan(scanner)
	t := float64(scan(scanner))
	a := float64(scan(scanner))

	min_diff := math.Inf(1)
	best := n

	var i int64
	for i = 0; i < n; i++ {

		h := float64(scan(scanner))
		diff := math.Abs((t - 0.006*h) - a)

		if diff < min_diff {
			min_diff = diff
			best = i
		}
	}

	fmt.Println(best + 1)
}


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

string s;
int cnt[26];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  ll ans = 1;
  for (int i = 0; i < s.size(); i++) {
    ans += i - cnt[s[i]-'a'];
    cnt[s[i]-'a']++;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 720
import java.util.Scanner;

public class Main {

	static Main instance = new Main();

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		//入力値
		int numN = scan.nextInt();
		String str = scan.next();

		char[] array = str.toCharArray();

		for (int i = 0; i < array.length; i++) {
			if (array[i] +numN > 'Z') {
				array[i] = (char) ( array[i] +numN - 26);
			} else {
				array[i] = (char) ( array[i] +numN);
			}
		}

		for (int i = 0; i < array.length; i++) {
			System.out.print(array[i]);
		}
		System.out.println();
	}
}

Measured memory_bytes: 26580
#include <stdio.h>

int main() {
    int y, x;
    scanf("%d %d", &y, &x);
    int v[y][x], b[x], c[y];
    for (int i = 0; i < y; i++) {
        c[i] = 0;
    }

    //------------------------------------------
    for (int i = 0; i < y; i++) {
        for (int j = 0; j < x; j++) {
            scanf("%d", &v[i][j]);
        }
    }
    for (int i = 0; i < x; i++) {
        scanf("%d", &b[i]);
    }
    for (int i = 0; i < y; i++) {
        for (int j = 0; j < x; j++) {
            c[i] = c[i] + v[i][j] * b[j];
        }
    }
    for (int i = 0; i < y; i++) {
        printf("%d\n", c[i]);
    }
}



Measured memory_bytes: 2100
#include<iostream>
#include<cstring>

using namespace std;

bool map[21][21];

int main() {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        memset(map, 0, sizeof(map));

        for (int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            map[x][y] = true;
        }

        int m;
        cin >> m;
        int x = 10;
        int y = 10;
        int cnt = 0;
        if (map[10][10]) {
            map[10][10] = false;
            cnt++;
        }

        for (int i = 0; i < m; ++i) {
            char dir;
            int dist;
            cin >> dir >> dist;
            int dx = 0;
            int dy = 0;
            switch(dir) {
                case 'N':
                    dy = 1;
                break;
                case 'S':
                    dy = -1;
                break;
                case 'E':
                    dx = 1;
                break;
                case 'W':
                    dx = -1;
                break;
            }

            for (int k = 0; k < dist; ++k) {
                x += dx;
                y += dy;
                if (map[x][y]) {
                    map[x][y] = false;
                    cnt++;
                }
            }
        }

        cout << (cnt == n ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res)*m(a));
        a = m(m(a)*m(a));
        b >>= 1;
    }
    return res;
}
signed main(){
    fast();
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++)  cin >> a[i];
    sort(a.begin(), a.end());
    int ans = 0;
    for(int i=0; i<k; i++)  ans += a[i];
    cout << ans << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include <numeric>  
using namespace std;  
int arraySum(vector<int> &v)  
{ 
    int initial_sum  = 0;  
    return accumulate(v.begin(), v.end(), initial_sum); 
} 


int main()
{
  long long n,m,sum;
  vector<int> v;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
   int x;
   cin>>x;
   v.push_back(x); 
  }
  sum=arraySum(v);
  if(sum<=n)
    cout<<(n-sum);
  else cout<<"-1";
   return 0;


}

Measured memory_bytes: 3700
import java.util.*;

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

        int i = 0;
        int o = 0;
        String sub = "ABC";
        int n = sc.nextInt();
        String s = sc.next();


            while ((i = s.indexOf(sub, i)) != -1) {
                o++;
                i++;
            }


        System.out.println(o);
    }
}


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

long long solve(deque <int> v) {
	int last = v.front();
	int take = 0;
	int first = last;
	long long ans = 0;
	while(v.size() > 1) {
		if(take == 0) {
			ans += abs(v.front() - last);
			last = v.front();
			v.pop_front();
		} else {
			ans += abs(v.back() - last);
			last = v.back();
			v.pop_back();
		}
		take ^= 1;
	}
	ans += abs(first - v.back());
	return ans;
}

int main(int argc, char const *argv[])
{
	int n;
	scanf("%d", &n);
	deque <int> v;
	for(int i = 0; i < n; i++) {
		int x;
		scanf("%d", &x);
		v.push_back(x);
	}
	sort(v.begin(), v.end());
	long long ans = solve(v);
	reverse(v.begin(), v.end());
	ans = max(ans, solve(v));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 1128
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#define RG register
#define il inline
#define iter iterator
#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
const int N=300005;
int n,a[N],b[N],c[N],B[N],num=0;
ll f[N],ans=0,t[N];
void work()
{
   scanf("%d",&n);
   for(int i=1;i<=n;i++)scanf("%d",&a[i]),B[++num]=a[i];
   for(int i=1;i<=n;i++)scanf("%d",&b[i]),B[++num]=b[i];
   for(int i=1;i<=n;i++)scanf("%d",&c[i]),B[++num]=c[i];
   sort(B+1,B+num+1);
   int tot=unique(B+1,B+num+1)-B-1;
   for(int i=1;i<=n;i++)a[i]=lower_bound(B+1,B+tot+1,a[i])-B;
   for(int i=1;i<=n;i++)b[i]=lower_bound(B+1,B+tot+1,b[i])-B;
   for(int i=1;i<=n;i++)c[i]=lower_bound(B+1,B+tot+1,c[i])-B;

   for(int i=1;i<=n;i++)t[a[i]]++;
   for(int i=1;i<=tot;i++)t[i]+=t[i-1];
   for(int i=1;i<=n;i++)
      f[b[i]]+=t[b[i]-1];
   for(int i=1;i<=tot;i++)f[i]+=f[i-1];
   for(int i=1;i<=n;i++)
      ans+=f[c[i]-1];
   printf("%lld\n",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 8832
# -*- coding: utf-8 -*-

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=2**31-1

class SegTree:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_val: 区間[l, r)の値を得る
    """
 
    def __init__(self, n, func, init):
        """
        :param n: 要素数
        :param func: 値の操作に使う関数(min, maxなど)
        :param init: 要素の初期値
        """
        n += 1
        self.n = n
        self.func = func
        self.init = init
        # nより大きい2の冪数
        n2 = 1
        while n2 < n:
            n2 <<= 1
        self.n2 = n2
        self.tree = [self.init] * (n2 << 1)
 
    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.n2
        self.tree[i] = x
        while i > 1:
            self.tree[i >> 1] = x = self.func(x, self.tree[i ^ 1])
            i >>= 1
 
    def get_val(self, a, b):
        """
        [a, b)の値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        return self._get_val(a, b, 1, 0, self.n2)
 
    def _get_val(self, a, b, k, l, r):
        """
        [a, b)の値を得る内部関数
        :param k: 現在調べている区間のtree内index
        :param l, r: kが表す区間の左右端index [l, r)
        :return: kが表す区間と[a, b)の共通区間内での最小値。共通区間を持たない場合は初期値
        """
        # 範囲外なら初期値
        if r <= a or b <= l:
            return self.init
        # [a,b)が完全に[l,r)を包含するならtree[k]の値を採用
        if a <= l and r <= b:
            return self.tree[k]
        # 一部だけ範囲内なら2つに分けて再帰的に調査
        m = (l + r) // 2
        return self.func(
            self._get_val(a, b, k << 1, l, m),
            self._get_val(a, b, (k << 1) + 1, m, r)
        )

N,Q=MAP()
st=SegTree(N, min, INF)
for _ in range(Q):
    com,x,y=MAP()
    if com==0:
        st.update(x, y)
    else:
        print(st.get_val(x, y+1))



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

#define ll long long

ll M = 998244353;

ll powerm(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x)%M; y=y>>1; x=(x*x)%M;} return res%M; }
ll power(ll x,ll y){ ll res=1; while(y){ if(y&1) res=(res*x); y=y>>1; x=(x*x);} return res; }

const int N = 5e5 + 5;
ll fact[N], inv[N];
 
void pre(int n){fact[0] = inv[0] = 1;for(ll i=1;i<=n;i++){fact[i] = (fact[i-1]*i)%M;inv[i] = powerm(fact[i],M-2);}}
 
ll C(ll n,ll r){ll ans = ((fact[n]*inv[r])%M + M)%M;ans = ((ans*inv[n-r])%M + M)%M;return ans;}

int calcMEX(vector<int> v){
    map<int,int> m;
    for(auto x:v) m[x]++;
    for(int i=0;i<v.size();i++){
        if(m.find(i)==m.end()) return i;
    }
    return v.size();
}

int main(){
    ll t=1;
    // cin>>t;
    //cout<<t<<endl;
    while(t--){
        int n;
        cin>>n;
        map<string,int> m;
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            m[s]++;
        }
        cout<<"AC"<<" x "<<m["AC"]<<endl;
        cout<<"WA"<<" x "<<m["WA"]<<endl;
        cout<<"TLE"<<" x "<<m["TLE"]<<endl;
        cout<<"RE"<<" x "<<m["RE"]<<endl;


    }
}

Measured memory_bytes: 3632
#include <climits>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

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

struct artist {
	int e, s;
	artist(int e, int s):e(e), s(s) {}
};

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

	for(int l, n, m, x; cin >> l >> n >> m >> x, x;) {
		vector<artist> sec(1, artist(0, 0));
		for(int i = 0; i < n; ++i) {
			string name;
			int e, s;
			cin >> name >> e >> s;
			sec.push_back(artist(e, s));
		}

		vector<artist> std;
		for(int i = 0; i < m; ++i) {
			string name;
			int e, s;
			cin >> name >> e >> s;
			std.push_back(artist(e, s));
		}

		vector<vector<int> > dp(m + 1, vector<int>(l + 1, INT_MIN));
		vector<int> result(l + 1, INT_MIN);
		for(int i = 0; i <= n; ++i)
			for(int j = i + 1; j <= n; ++j)
				if(sec[i].e + sec[j].e <= l)
					chmax(dp[0][sec[i].e + sec[j].e], sec[i].s + sec[j].s);

		for(int i =0; i < m; ++i) {
			vector<vector<int> > tmp = dp;
			for(int j = max(0, x - m + i); j < m; ++j)
				for(int k = 0; k + std[i].e <= l; ++k)
					chmax(tmp[j + 1][k + std[i].e], dp[j][k] + std[i].s);

			dp.swap(tmp);
		}

		int ans = 0;
		for(int i = x; i <= m; ++i)
			for(int j = 0; j <= l; ++j)
				chmax(ans, dp[i][j]);

		cout << ans << endl;
	}


	return EXIT_SUCCESS;
}

Measured memory_bytes: 2020
#include <iostream>

using namespace std;

int main() {

  int c1,c2,c3;

  int dealed[10];
  int res;
  int count;

  while(cin >> c1 >> c2 >> c3) {
    
    for(int i=1;i<=10;i++) {

      if(i==c1 || i==c2 || i== c3) dealed[i]=1;

      else dealed[i]=0;

    }  

    res=20-(c1+c2);
    count=0;

    for(int i=1;i<=10;i++) {

      if(dealed[i]==0 && i<=res) count++;

    }

    if(count>=4) cout << "YES" << endl;

    else cout << "NO" << endl;

  }

  return 0;

}

	

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>

using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;

vector<vector<int> > calcNext(const string &S) {
    int n = (int)S.size();
    vector<vector<int> > res(n+1, vector<int>(10, n));
    for (int i = n-1; i >= 0; --i) {
        for (int j = 0; j < 10; ++j) res[i][j] = res[i+1][j];
        res[i][S[i]-'0'] = i;
    }
    return res;
}

int main(){
    ll A,B;
    cin >> A >> B;
    ll X = A*B;
    if(A<B){
        ll tmp = A;
        A = B;
        B = tmp;
    }
    ll r = A%B;
    while(r!=0){
        A = B;
        B = r;
        r = A % B;
    }
    cout << X/B << endl;
    return 0;
}


Measured memory_bytes: 256
S = input()
mkR = []
mkL = [-1]
Ans = [0] * len(S)

for i in range(len(S)-1):
  if S[i:i+2] == "RL":
    mkR.append(i)
  elif S[i:i+2] == "LR":
    mkL.append(i)
    
mkL.append(len(S)-1)

for i, R in enumerate(mkR):
  Ans[R] = (R-mkL[i]-1) // 2 + (mkL[i+1]-R) // 2 + 1
  Ans[R+1] = (R-mkL[i]) // 2 + (mkL[i+1]-R-1) // 2 + 1

for i in range(len(S)-1):
  print(Ans[i], end=" ")
print(Ans[-1])

Measured memory_bytes: 51676
#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    if (n % 2 != 0) {
        OUT("No");
        return 0;
    } else {
        for (int i = 0; i < n / 2; i++) {
            if (s[i] != s[i + n / 2]) {
                OUT("No");
                return 0;
            }
        }
    }
    OUT("Yes");
}


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

long min(long a,long b){
    if (a<b)return a;
    else return b;
}

int main(void) {
	int n,W,ans;
	long w,v,dp[105][100005];
	scanf("%d%d",&n,&W);
	for (int i=0;i<=n;i++){
	    for (int j=0;j<100005;j++){
	        dp[i][j] = 10000000000;
	    }
	}
	
	scanf("%lld%lld",&w,&v);
	dp[1][v]=w;
	dp[1][0]=0;

	for (int i=2;i<=n;i++){
	    scanf("%lld%lld",&w,&v);
	    for (int j=0;j<=100005;j++){
	        if(j>=v) {
	            dp[i][j] = min(dp[i-1][j-v]+w,dp[i-1][j]);
	        }else {
	            dp[i][j]=dp[i-1][j];
	        }
	    }
	}

    for (int i=100004;i>=0;i--){
        for (int j=0;j<=n;j++){
            if (dp[j][i] <= W) {
                ans = i;
                printf("%d\n",ans);
                return 0;
            }
        }
    }
}

Measured memory_bytes: 81152
#include <stdio.h>

int main(){
  int min, max, input, i = 0;
  int ans = 0;
  scanf("%d %d %d", &min, &max, &input);

  for(i=min;i<=max;i++){
    if(input%i ==0) {ans++;}
  }

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

  return 0;

}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int main()
{
    double x1, y1, x2, y2;

    scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
    
    printf("%lf\n", sqrt(pow((x2-x1),2)+pow((y2-y1),2)));

    return 0;
}

Measured memory_bytes: 2752
#include<stdio.h>

int main(){
  int width_window, width_curtain;
  scanf("%d %d", &width_window, &width_curtain);
  
  int width_not_hidden;
  width_not_hidden = (width_window < width_curtain*2) ? 0 : width_window - width_curtain*2;
  printf("%d", width_not_hidden);
}

Measured memory_bytes: 128
n = int(input())
a = list(map(int,input().split()))
inc = False
dec = False
new = [a[0]]
for i in a[1:]:
  if i < new[-1]:
    if not dec:
      new.append(i)
      dec = True
      inc = False
    else:
      new[-1] = i
  elif i > new[-1]:
    if not inc:
      new.append(i)
      inc = True
      dec = False
    else:
      new[-1] = i
new = [0]+new+[0]
n = len(new)
money = 1000
stocks = 0
for i in range(1,n-1):
  if new[i-1] < new[i] > new[i+1]:
    money += stocks * new[i]
    stocks = 0
  else:
    has_peek_up = False
    for j in range(i+1,n):
      if new[j-1] < new[j] > new[j+1]:
        has_peek_up = True
        break
    if has_peek_up:
      stocks = money//new[i]
      money = money%new[i]
print(money)

Measured memory_bytes: 9252
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>
#define vii vector<vi>
#define vs vector<string>
#define vss vector<vs>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define repr(i, a, n) for (int i = (n); i >= (a); --i)
using namespace std;
const int INF(1 << 30);
const ll LLINF(1LL << 55LL);
const int pi = 3.1415926536;
const int MOD = 1000000007;
const int MAX = 510000;
 
void Main() {
  string s;
  cin >> s;
  string ans;
  for (int i = 0; i < s.size(); i += 2) {
    ans += s[i];
  }
  cout<<ans<<endl;
}
 
int main() {
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  std::cout << std::fixed << std::setprecision(15);  // 小数を10進数表示
  Main();
}

Measured memory_bytes: 592
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main() {
  int n;
  long long c;
  cin >> n >> c;

  vector<long long> x(n + 1), v(n + 1);
  vector<long long> s(n + 1);

  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> v[i];
    s[i] = s[i - 1] + v[i];
  }

  long long ans = 0;
  for (int i = 0; i <= n; i++) {
    ans = max(ans, s[i] - x[i]);
  }
  for (int i = 1; i <= n; i++) {
    ans = max(ans, s[n] - s[i - 1] - (c - x[i]));
  }
  
  multiset<long long> st;
  multiset<long long> st2;
  for (int j = 1; j <= n; j++) {
    long long v0 = -s[j - 1] - (c - x[j]);
    long long v1 = -s[j - 1] - (c - x[j]) * 2;
    st.insert(v0);
    st2.insert(v1);
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, s[i] + s[n] - x[i] * 2 + *st.rbegin());
    ans = max(ans, s[i] + s[n] - x[i] + *st2.rbegin());
    long long v0 = -s[i] - (c - x[i + 1]);
    long long v1 = -s[i] - (c - x[i + 1]) * 2;
    st.erase(st.find(v0));
    st2.erase(st2.find(v1));
  }

  cout << ans << endl;
}

Measured memory_bytes: 12032
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

vector<ll>relation[20], money(20, 1);

int main() {
	string s;
	cin >> s;
	rep(i, 3) {
		if (s[i] == '7') {
			puts("Yes");
			return 0;
		}
	}
	puts("No");
	return 0;
}


Measured memory_bytes: 3628
import numpy as np
H, W = map(int, input().split())
a = ['']*H
for i in range(H):
  a[i] = input()

h_flag = [0]*H
w_flag = [0]*W
for iHeight in range(H):
  for jWidth in range(W):
    if a[iHeight][jWidth] == '#':
      h_flag[iHeight] = 1
      w_flag[jWidth] = 1

for iHeight in range(H):
  if h_flag[iHeight] == 1:
    for jWidth in range(W):
      if w_flag[jWidth] == 1:
        print(a[iHeight][jWidth], end='')
    print()

Measured memory_bytes: 26472
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<28;
const ll INF=1ll<<50;
const double pi=acos(-1);
const double eps=1e-10;
const ll mod=1e9+7;
const vi emp;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,-0};
const int DX[8]={-1,-1,-1,0,0,1,1,1},DY[8]={1,0,-1,1,-1,1,0,-1};

char c;

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

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#define mod 998244853 
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n, m, x;
    cin >> n >> m;
    long long int a[n+1];
    for(int i = 0; i <= n; i++)
        a[i]=0;
    for(int i = 0; i < m; i++)
    {
        cin >> x;
        a[x]=-1;
    }
        a[n]=1;
        if(a[n-1]!=-1)
        {
            a[n-1]=1;
        }
    for(int i = n-2; i >= 0; i--)
    {
        if(a[i]!=-1)
        {
            if(a[i+1]!=-1)
            {
                a[i]+=a[i+1];
            }
            if(a[i+2]!=-1)
            {
                a[i]+=a[i+2];
            }
            a[i]%=1000000007;
        }
    }
    cout << a[0]%1000000007 << '\n';
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main() {
  int X, Y;
  cin >> X >> Y;

  for(int i = 0; i <= X; i++) {
    if(i * 2 + (X - i) * 4 == Y) { cout << "Yes"; return 0; }
  }

  cout << "No";
  return 0;
  }

Measured memory_bytes: 3568
#include<iostream>

using namespace std;

int main(){
  int a, b, c ,d;
  cin >> a >> b >> c >> d;
  if(a+b>c+d){
    cout << "Left" << endl;
  }
  else if(a+b==c+d){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,sum=0,a=0;
	string s;
	cin>>n;
	cin>>s;
	for(int i=0;i<n;i++){
		if(s[i]=='I'){
	
		sum=sum+1;
		if(sum>a)
		a++;
	
		}
	else {
	
	sum=sum-1;
	if(sum>a)
		a++;	
		
		
	}
	
	
	
	
}

cout<<a;}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextFloat64() float64 {
	sc.Scan()
	i, e := strconv.ParseFloat(sc.Text(), 64)
	if e != nil {
		panic(e)
	}
	return i
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	const mod = 1000000000 + 7

	sc.Buffer(nil, 100000000)

	n := nextInt()

	xs := make([]int, n)
	for i := 0; i < n; i++ {
		xs[i] = nextInt()
	}

	min := 100000000
	for p := 1; p <= 100; p++ {
		total := 0
		for _, x := range xs {
			total += (x - p) * (x - p)
		}
		if total < min {
			min = total
		}
	}
	fmt.Println(min)
}


Measured memory_bytes: 1780
#include <stdio.h>
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
	
    int a, b, c, k, n, s, i;

    scanf("%d %d %d", &a, &b, &c);
    scanf("%d", &k);
    s = a + b + c;
    n = max(a, max(b, c));
    s = s - n;
    for(i = 0; i < k; i++) n = n * 2;
    printf("%d\n", s+n);

	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			int[] score = new int[n];
			for (int i = 0; i < n; i++) {
				score[i] = sc.nextInt();
			}
			Arrays.sort(score);
			int sum = 0;
			for (int i = 1; i < n - 1; i++) {
				sum += score[i];
			}
			int ave = sum / (n - 2);
			System.out.println(ave);
		}
	}
}

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

int n;
vector<int> adj[200005];
int dist[200005];

int dfs(int x,int par){
    for(int i=0;i<(int)adj[x].size();i++){
        if(adj[x][i]==par){
            continue;
        }
        dist[adj[x][i]]=dist[x]+1;
        dfs(adj[x][i],x);
    }
}

int main(){
    scanf("%d",&n);
    int a,b;
    for(int i=0;i<n-1;i++){
        scanf("%d%d",&a,&b); a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    dfs(0,-1);
    int maxi=0;
    for(int i=1;i<n;i++){
        if(dist[maxi]<dist[i])maxi=i;
    }
    memset(dist,0,sizeof(dist));
    dfs(maxi,-1);
    int diameter=0;
    for(int i=0;i<n;i++)diameter=max(diameter,dist[i]);
    bool dp[diameter+5];
    dp[0]=1; dp[1]=0;
    for(int i=2;i<=diameter;i++){
        if(dp[i-1]&&dp[i-2]){
            dp[i]=0;
        }else{
            dp[i]=1;
        }
    }
    if(dp[diameter])printf("First");
    else printf("Second");
}


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

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++)
    {
        cin >> l[i];
    }
    sort(l.begin(), l.end());
    reverse(l.begin(), l.end());
    int total = 0;
    for (int i = 0; i < k; i++)
    {
        total += l[i];
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 3528
import java.util.Scanner;

/**
 * We Love Golf.
 */
public class Main {
    public static void main(String[] args) {
        var scanner = new Scanner(System.in);
        var k = Integer.parseInt(scanner.next());
        var a = Integer.parseInt(scanner.next());
        var b = Integer.parseInt(scanner.next());

        System.out.println(k * (b / k) >= a ? "OK" : "NG");
    }
}


Measured memory_bytes: 35668
#include <cstdio>
#define MOD 1000000007
int sum[4005], dp[4005][4005];
int main()
{
	// freopen("AGC009-E.in", "r", stdin);
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	dp[0][0] = 1;
	for (int i = 1; i < n + m; i++)
	{
		for (int j = 0; j <= m; j++)
		{
			sum[j] = ((j ? sum[j - 1] : 0) + dp[i - 1][j]) % MOD;
			dp[i][j] = (sum[j] - (j >= k ? sum[j - k] : 0) + MOD) % MOD;
		}
	}
	int ans = 0;
	while (m > 0)
	{
		(ans += dp[(n + m - 1) / (k - 1)][m]) %= MOD;
		m -= k - 1;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 61952
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll n,k; cin >> n >> k;
  int flag,ans=0;
  rep(i,n){
    int x; cin >> x;
    if(x==1) flag = i;
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,c=0,k=0;
  string a;
  cin>>n;
  while(n--){
    cin>>a;
    if(a=="A")c++;
    else c--;
    if(c<0)k++;
  }
  cout<<((k||c)?"NO":"YES")<<endl;
}

Measured memory_bytes: 3164
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int Q = sc.nextInt();
        int[][] train = new int[n+1][n+1];
        for(int i = 0; i < m; i++){
            int L = sc.nextInt();
            int R = sc.nextInt();
            train[L][R]++;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                train[i][j] += train[i][j-1];
            }
        }
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                train[i][j] += train[i-1][j];
            }
        }
        for(int i = 0; i < Q; i++){
            int p = sc.nextInt();
            int q = sc.nextInt();
            System.out.println(train[q][q] - train[p-1][q] - train[q][p-1] + train[p-1][p-1]);
        }
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

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


Measured memory_bytes: 58484