akhauriyash/Code-Regression huggingface dataset:
using System;

namespace ChokudaiScanner
{
    class MainClass
    {
        static void Main()
        {
            Scanner cin = new Scanner();

            int n = cin.NextInt();
            int m = cin.NextInt();
            int c = cin.NextInt();
            int sum = 0;
            int[] b = cin.ArrayInt(m);
            int[][] a = new int [n][];
            for(int i = 0; i < n; i++)
            {
                a[i] = cin.ArrayInt(m);
            }
            for(int i = 0; i < n; i++)
            {
                int x = 0;

                for (int j = 0; j < m; j++)
                {
                    x += a[i][j] * b[j];

                    if (j == m - 1)
                    {
                        if (x + c > 0)
                        {
                            sum++;
                        }
                    }
                }
            }
            Console.WriteLine(sum);
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string Next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            if (s.Length == 0) return Next();
            i = 0;
            return s[i++];
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }
        public int[] ArrayInt(int N, int add = 0)
        {
            int[] Array = new int[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextInt() + add;
            }
            return Array;
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public long[] ArrayLong(int N, long add = 0)
        {
            long[] Array = new long[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextLong() + add;
            }
            return Array;
        }

        public double NextDouble()
        {
            return double.Parse(Next());
        }


        public double[] ArrayDouble(int N, double add = 0)
        {
            double[] Array = new double[N];
            for (int i = 0; i < N; i++)
            {
                Array[i] = NextDouble() + add;
            }
            return Array;
        }
    }
}

Measured memory_bytes: 11220
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll N=2e5+5;
const ll MOD=1e9+7;
const ld pi=3.14159265359;
const ll INF=(1LL<<60);
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define X first
#define Y second
#define pb push_back
#define mp make_pair
#define setp setprecision
#define lwb lower_bound
#define SZ(a) (ll)a.size()

ll n,k,ans;

int main(){
	ios_base::sync_with_stdio(0);
	cin>>n>>k;
	for(ll b=k+1;b<=n;b++){
		ll tn=n,tmp=0;
		if(tn%b==0){
			ans+=(tn/b)*(b-k);
		}else if(tn%b>=k){
			ans+=tn%b-k+1;
			tn-=tn%b;
			ans+=(tn/b)*(b-k);
			if(k==0)ans--;
		}else{
			tn-=tn%b;
			ans+=(tn/b)*(b-k);
		}
	}
	cout<<ans<<"\n";
	return 0;
}


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

    jaldi

    long long int n;
    cin>>n;
    if(n%2==0) {
        cout<<-1<<'\n';
    }
    else {
        long long int val = 7;
        int ans = 1;
        bool found = false;
        for (int i = 0; i <= 1e6; i++) {
            if(val%n == 0) {
                found=true;
                break;
            }
            val = val*10+7;
            val=val%n;
            ans++;
        }
        if(found)
            cout<<ans<<'\n';
        else
            cout<<-1<<'\n';
    }
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, greater_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	int n;
	cin >> n;
	vi a(n + 1, 0);
	for (int i = 2;i <= n;i++) {
		int x;
		cin >> x;
		a[x]++;
	}
	for (int i = 1;i <= n;i++)
		cout << a[i] << '\n';
}


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

  
int main (){
ll A, B, N, ans = 0;
  
cin >> A >> B >> N;

if( N < B ){
 ans = A * ( N % B ) - ((A * N) % B);
 ans = ans / B;
}
else{
 ans = A * (( B - 1 ) % B) - (A * ( B - 1 )) % B;
 ans = ans / B;
}
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll N;
    ll ans = 0;
    cin >> N;
    for(int i = 1; i <= N; i++){
        if(i%3 != 0 && i%5 != 0){
            ans += i;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3652
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(c-(a-b),0)<<endl;

	return 0;
}


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

int main()
{
    int a , b , c , dif ;
    cin >> a >> b >> c ;
    dif = a - b ;
    c -= dif ;
    if (c < 0){
        cout << 0 ;
    }
    else {
        cout << c ;
    }
    return 0;
}


Measured memory_bytes: 3460
def binary_search(array, target)
  num_of_elements = array.length
  left = 0
  right = num_of_elements-1
  while left <= right
    center = (left + right)/2
    if array[center] == target
      return true
    elsif array[center] < target
      left = center+1
    else
      right = center-1
    end
  end
end

n = gets.chomp.to_i
s = gets.chomp.split.map(&:to_i)
q = gets.chomp.to_i
t = gets.chomp.split.map(&:to_i)

sum_count = 0
for i in 0..(q-1)
  if binary_search(s, t[i]) == true
    sum_count += 1
  end
end

puts sum_count

Measured memory_bytes: 18052
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; ++i) cin >> S[i];
	function<bool(vector<int>)> solve = [&](vector<int> p) {
		if (p.size() == H) {
			vector<string> verti(W);
			for (int i = 0; i < W; ++i) {
				for (int j = 0; j < H; ++j) {
					verti[i] += S[p[j]][i];
				}
			}
			int cnt = 0;
			vector<bool> used(W);
			for (int i = 0; i < W; ++i) {
				if (used[i]) continue;
				string t = verti[i];
				reverse(t.begin(), t.end());
				for (int j = 0; j < W; ++j) {
					if (i != j && verti[j] == t && !used[j]) {
						used[i] = true;
						used[j] = true;
						cnt += 2;
						break;
					}
				}
			}
			if (W - cnt == 1) {
				for (int i = 0; i < W; ++i) {
					if (!used[i]) {
						string t = verti[i];
						reverse(t.begin(), t.end());
						if (t == verti[i]) ++cnt;
					}
				}
			}
			if (W == cnt) return true;
			return false;
		}
		int M = p.size();
		vector<bool> usedp(H);
		for (int i : p) usedp[i] = true;
		for (int i = 0; i < H; ++i) {
			if (usedp[i]) continue;
			bool ok = true;
			if (M >= 1 && M < H / 2 && p[M - 1] > i) ok = false;
			if (M > H - M - 1 && p[H - M - 1] > i) ok = false;
			if (ok) {
				p.push_back(i);
				if (solve(p)) return true;
				p.pop_back();
			}
		}
		return false;
	};
	bool ans = solve(vector<int>());
	cout << (ans ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair

const int MAX_N = 1e5+10;
ll N, K;
ll cnt[MAX_N];

ll powmod(ll x, ll y)
{
	ll res = 1;
	while(y){
		if(y&1) (res *= x)%=MOD;
		x = (x*x)%MOD;
		y>>=1;
	}
	return res;
}

void solve()
{
	ll ans = 0;
	for(ll g=K;g>=1;--g){
		cnt[g] = powmod(K/g, N);
		for(ll i=2*g;i<=K;i+=g){
			cnt[g] = (cnt[g]+MOD-cnt[i])%MOD;
		}
		(ans += g*cnt[g])%=MOD;
	}
	cout << ans << '\n';
}

int main()
{
	cin >> N >> K;
	solve();
    return 0;
}

Measured memory_bytes: 4364
H, W = map(int, input().split())
visited = [[True] * (W + 2)]
visited += [[True] + [x == '#' for x in list(input())] + [True] for _ in range(H)]
visited += [[True] * (W + 2)]
ans = -1
q = []
for i in range(1, H + 1):
    for j in range(1, W + 1):
        if visited[i][j]:
            q.append((i, j))

while q:
    tmp = []
    for h, w in q:
        if not visited[h - 1][w]:
            visited[h - 1][w] = True
            tmp.append((h - 1, w))
        if not visited[h + 1][w]:
            visited[h + 1][w] = True
            tmp.append((h + 1, w))
        if not visited[h][w - 1]:
            visited[h][w - 1] = True
            tmp.append((h, w - 1))
        if not visited[h][w + 1]:
            visited[h][w + 1] = True
            tmp.append((h, w + 1))
    q = tmp
    ans += 1
print(ans)


Measured memory_bytes: 111892
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }

int main(){
	while(1){
		int n,m,p; cin >>n>>m>>p;
		if(n==0)break;
		vector<int> x(n);
		cinf(n,x);
		if(x[m-1]==0)cout << 0 << endl;
		else{
			int sum=0;
			for(int i=0;i<n;i++){
				sum+=x[i];
			}
			cout << sum*(100-p)/x[m-1] << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3000
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  int m,n;
  cin >> m >>n;
  string a;
  cin >> a;
  int ac[n];
  ac[0] = 0;
  int dum;
  for(int i=0;i<m-1;i++){
    dum = (a.substr(i,2) == "AC") ? 1 : 0;
    ac[i+1] = ac[i] + dum; 
  }
  int st,en;
  for(int i=0;i<n;i++){
  	cin >> st >> en;
    cout << ac[en-1] - ac[st-1]<< endl;
  }
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <functional>
#include <queue>
#include <unordered_set>
#include <climits>

using namespace std;
typedef long long ll;

int main()
{
	int K,A,B;
	cin >> K >> A >> B;
	bool isOK = false;
	for(int i = 0; i <= B-A; i++){
		if((A+i) % K == 0){
			isOK = true;
		}
	}
	if(isOK){
		cout << "OK" << endl;
	}else{
		cout << "NG" << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3636
import java.util.*;
public class Main {
	public static void main(String[] args){
      	
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		
		for (int i = 0; i < 100; i++) {
			C= C-B;
			if (C<=0) {
				System.out.println("Yes");
				break;
			}
			A= A-D;
			if(A<=0){
				System.out.println("No");
				break;
			}
		}
		
		
      	sc.close();
    }
		
		
}


Measured memory_bytes: 27040
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include <string>
#include <numeric>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
map<int, int> mp;
map<int, int>mm;
#define ll long long
#define ld long double
#define PI 3.14159265358979l

int gcd(int a, int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}


int main() {
	int n;
	vector<int> b;
	cin >> n;
	rep(i, n) {
		int a;
		cin >> a;
		b.push_back(a);
	}
	stack<int> answer;
	while(!b.empty()) {
		bool c = false;
		for (int i = b.size() - 1; i >= 0; i--) {
			if (b[i] == i+1) {
				answer.push(b[i]);
				b.erase(b.begin() + i);
				goto ans;
			}
		}
		cout << -1 << endl;
		return 0;
	ans:;
	}
	rep(i, n) {
		cout << answer.top() << endl;
		answer.pop();
	}
	cin >> n;
	return 0;
}

Measured memory_bytes: 256
#
# abc065 c
#
import sys
from io import StringIO
import unittest
import math


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """2 2"""
        output = """8"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """3 2"""
        output = """12"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """1 8"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_4(self):
        input = """100000 100000"""
        output = """530123477"""
        self.assertIO(input, output)


def resolve():
    N, M = map(int, input().split())

    if abs(N-M) > 1:
        print("0")
    elif N == M:
        print(2*math.factorial(N)*math.factorial(M) % (10**9+7))
    else:
        print(math.factorial(N)*math.factorial(M) % (10**9+7))


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 18084
#include "stdio.h"
  
int main(void){
	int s;
	int ss[3];
	int cnt = 0;
	int i;

	scanf("%d", &s);

	ss[0]=s%10/1;
	ss[1]=s%100/10;
	ss[2]=s%1000/100;



	for(i=0;i<3;i++){
		if(ss[i]==1) cnt++;
	}


	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 128
from collections import deque

n, quantum = map(int, input().split())
que = deque()
elapsed_time = 0

for _ in range(n):
    name, time = input().split()
    process = {'name': name, 'time': int(time)}
    que.append(process)
    
while que:
    process = que.popleft()
    name = process['name']
    time = process['time']
    result_time = time - quantum
    if result_time > 0:
        elapsed_time += quantum
        process = {'name': name, 'time': result_time}
        que.append(process)
    else:
        elapsed_time += time
        print(f"{process['name']} {elapsed_time}")


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

//関数
    
    
    
    
//main関数
int main() {
    
    
    
    //入力
    int N;
    cin>>N;
    vector<int> a(N+1);
    for(int i=0;i<N;i++){
        cin>>a.at(i);
    }
    a.at(N)=-1;
    
    
    
    
    
    
    
    
    
    
    //計算
    vector<int> num(200);
    int old=-1,count=0;
    for(int i=0;i<=N;i++){
        if(old!=a.at(i)){
            num.at(count)++;
            
            count=1;
            old=a.at(i);
        }else{
            count++;
        }
    }
    
    int sum=0;
    for(int i=1;i<200;i++){
       // cout <<i<<" "<<num.at(i)<<endl;
        sum+=(num.at(i)*(i/2));
    }
    
    
    
    
    
    
    
    
    
    
    //出力
    cout <<sum<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

ll N;

int main() {
  cin >> N;
  ll ct, ca;
  cin >> ct >> ca;
  ll csum = ct + ca;

  rep(i, 0, N - 1) {
    ll t, a;
    cin >> t >> a;
    ll sum = t + a;
    if (csum % sum != 0) {
      csum = csum - csum % sum + sum;
    }

    ll nt = csum / sum * t;

    if (nt < ct) {
      ll diff = ct - nt;
      ll mul = (diff + t - 1) / t;
      csum += sum * mul;
    }

    ll na = csum / sum * a;
    if (na < ca) {
      ll diff = ca - na;
      ll mul = (diff + a - 1) / a;
      csum += sum * mul;
    }

    ct = csum / sum * t;
    ca = csum / sum * a;
  }
  cout << csum << endl;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b,n,t,sum=0,x;
vector <int> count(100005,0) ;
cin>>n;
for(int i=0;i<n;i++)
{
cin >> x;
count[x]++;
sum += x;
}
cin >>t;
while(t--)
{
cin >> a >> b;
sum-= a*count[a];
sum+= b*count[a];
count[b]+= count[a];
count[a] = 0;
cout <<sum <<endl ;
}

return 0;
}

Measured memory_bytes: 3716
#include <stdio.h>
#define NIL -1
#define MAX_N 30
typedef struct node_ {
    int p;
    int l;
    int r;
} Node;
 
Node T[MAX_N];
int D[MAX_N], H[MAX_N];
 
void setDepth(int u, int d) {
    if (u == NIL) return;
    D[u] = d;
    setDepth(T[u].l, d+1);
    setDepth(T[u].r, d+1);
}
 
int setHeight(int u) {
    int h1 = 0, h2 = 0;
    if (T[u].l != NIL) {
        h1 = setHeight(T[u].l) + 1;
    }
    if (T[u].r != NIL) {
        h2 = setHeight(T[u].r) + 1;
    }
 
    if (h1 >= h2) {
        return H[u] = h1;
    } else {
        return H[u] = h2;
    }
}
 
int getSibling(int u) {
    if (T[u].p == NIL) return NIL;
    if (T[T[u].p].l != u && T[T[u].p].l != NIL) {
        return T[T[u].p].l;
    }
    if (T[T[u].p].r != u && T[T[u].p].r != NIL) {
        return T[T[u].p].r;
    }
    return NIL;
}
 
void print(int u) {
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].p);
    printf("sibling = %d, ", getSibling(u));
 
    int deg = 0;
    if (T[u].l != NIL) deg++;
    if (T[u].r != NIL) deg++;
    printf("degree = %d, ", deg);
 
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
 
    if (T[u].p == NIL) {
        printf("root\n");
    } else if (T[u].l == NIL && T[u].r == NIL) {
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}
 
int main(void) {
    int i, n;
    scanf("%d", &n);
    for (i = 0; i < MAX_N; i++) {
        T[i].p = NIL;
        T[i].l = NIL;
        T[i].r = NIL;
    }
 
    for (i = 0; i < n; i++) {
        int id, left, right;
        scanf("%d %d %d", &id, &left, &right);
        T[id].l = left;
        T[id].r = right;
        if (left != NIL) T[left].p = id;
        if (right != NIL) T[right].p = id;
    }
 
    int r;
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) r = i;
    }
 
    setDepth(r, 0);
    setHeight(r);
 
    for (i = 0; i < n; i++) {
        print(i);
    }
 
    return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <ctype.h>
#include <string>
using namespace std;
 
 
int main(){
    int D,N;
    cin>>D>>N;
    int a=1;
    for(int i=0;i<D;i++)a*=100;
  if(N!=100)cout<<a*N<<endl;
  else cout<<a*101<<endl;

}

Measured memory_bytes: 256
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val v = in.readLine.split(" ").map(_.toInt)
  val c = in.readLine.split(" ").map(_.toInt)

  val ans = (0 until n).map(i => v(i) - c(i)).filter(_ > 0).sum
  println(ans)
}

Measured memory_bytes: 25396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T,class U> using P = pair<T,U>;
template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vec<T>>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
 
int main(){
    int a_sz, b_sz, m;
    cin >> a_sz >> b_sz >> m;
    int a[a_sz];
    int b[b_sz];
    int a_min=1e9+7;
    int b_min=1e9+7;
    rep(i, a_sz) {
        cin >> a[i];
        a_min = min(a_min, a[i]);
    }
    rep(i, b_sz) {
        cin >> b[i];
        b_min = min(b_min, b[i]);
    }
    int x[m], y[m], c[m];
    int ans = a_min + b_min;
    rep(i, m) {
        cin >> x[i] >> y[i] >> c[i];
        x[i]--, y[i]--;
        ans = min(ans, a[x[i]] + b[y[i]] - c[i]);
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 2176
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
@a = gets.chomp.split.map(&:to_i)
@edges = Array.new(n-1)
(n-1).times do
  x, y = gets.chomp.split.map(&:to_i)
  x -= 1
  y -= 1
  @edges[x] ||= []
  @edges[y] ||= []
  @edges[x].push y
  @edges[y].push x
end

dp = Array.new()
dp.push @a[0]
@visited = Set.new([0])
@ans = Array.new(n)
@ans[0] = 1

def dfs(index, dp)
  @edges[index].each do |v|
    next if @visited.include? v
    @visited.add v

    val = @a[v]
    if bi = dp.bsearch_index{|x| x >= val}
      preserve = dp[bi]
      dp[bi] = val
      @ans[v] = dp.size

      dfs(v, dp)
      dp[bi] = preserve
    else
      dp.push val
      @ans[v] = dp.size

      dfs(v, dp)
      dp.pop
    end
  end
end


dfs(0, dp)

@ans.each do |line|
  puts line
end

Measured memory_bytes: 254984
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int count = selectionSort(arr);
        printArray(arr);
        System.out.println(count);
    }

    static int selectionSort(int[] arr) {
        int n = arr.length;
        int counter = 0;
        for (int i = 0; i < n; i++) {
            int minJ = i;
            for (int j = i; j < n; j++) {
                if (arr[j] < arr[minJ]) {
                    minJ = j;
                }
            }
            if (minJ != i) {
                int tmp = arr[minJ];
                arr[minJ] = arr[i];
                arr[i] = tmp;
                counter++;
            }
        }
        return counter;
    }


    static void printArray(int[] arr) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length - 1; i++) {
            sb.append(arr[i]);
            sb.append(" ");
        }
        sb.append(arr[arr.length - 1]);
        System.out.println(sb.toString());
    }
}



Measured memory_bytes: 26240
import sys
input = sys.stdin.buffer.readline

H, W = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(H)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j] = min(C[i][j], C[i][k] + C[k][j])

answer = 0
for a in A:
    for aa in a:
        if aa != -1:
            answer += C[aa][1]

print(answer)

Measured memory_bytes: 39280
import System.Environment
import Data.Maybe
import Data.List
import Control.Exception

main :: IO ()
main = do
  isTest <- getEnv "TEST" `catch` (\(SomeException _) -> return "")
  if isTest == "1"
    then do
      testFile <- readFile "tests"
      putStrLn $ tests testFile
    else do
      input <- getContents
      putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve [x, _, y] | x > y  = ">"
                | x < y  = "<"
                | x == y = "="

tests :: String -> String
tests text = case testParse text of
  Right bodys -> unlines (fmap (\(i, body) -> test i body) (zip [1 ..] bodys))
  Left  msg   -> "Test file parse error:" ++ msg

test :: Int -> (String, String) -> String
test n (input, outputRight)
  | output == outputRight
  = header ++ "Passed"
  | otherwise
  = header
    ++ "Faild\n"
    ++ "Right:"
    ++ show outputRight
    ++ "\nOutput:"
    ++ show output
 where
  header = "test" ++ show n ++ ":"
  output = trim $ solve input

testParse :: String -> Either String [(String, String)]
testParse s = case lines s of
  (sp1:sp2:bodys) -> testBodysParse sp1 sp2 bodys
  _               -> Left "testParse"

testBodysParse
  :: String -> String -> [String] -> Either String [(String, String)]
testBodysParse sp1 sp2 = (traverse . testBodyParse) sp2 . (split sp1)

testBodyParse :: String -> [String] -> Either String (String, String)
testBodyParse sp body = case fmap (trim . unlines) (split sp body) of
  [input, output] -> Right (input, output)
  _               -> Left "testBodyParse"

split :: Eq a => a -> [a] -> [[a]]
split spratar = foldr f [[]]
 where
  f x (p:ps) | x == spratar = [] : p : ps
             | otherwise    = (x : p) : ps
  f _ _ = undefined

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

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

#define FOR(i, n) for(int i=1; i<=n; i++)
//#define kk
#define ff first
#define ss second
#define ll int
typedef pair<int, int> pi;

int arr[100001];
int dp[100001];

void solve(){
	int n;
	cin>>n;
	
	for(int i=1; i<=n; i++){
		cin>>arr[i];
	}
	
	dp[1]=0;
	dp[2]=abs(arr[2]-arr[1]);
	
	for(int i=3; i<=n; i++){
		dp[i]=min(dp[i-1]+abs(arr[i]-arr[i-1]), dp[i-2]+abs(arr[i]-arr[i-2]));
	}
	
	//FOR(i, n) cout<<dp[i]<<" ";
	//cout<<endl;
	
	cout<<dp[n]<<endl;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	#ifdef kk
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
    #endif
	
	int T=1;
	//cin>>T;
	
	while(T--){
		solve();
	}
}


Measured memory_bytes: 4388
import java.util.Scanner;

public class Main {
    private static final char BLACK = '#';
    private static final char WHITE = '.';

    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int length = scanner.nextInt();
        scanner.nextLine();
        final char[] chars = scanner.nextLine().toCharArray();

        int white = 0;
        int black = 0;
        for (int i = 0; i < length; i++) {
            if (chars[i] == WHITE) {
                white++;
            } else {
                black++;
            }
        }

        int result = Integer.MAX_VALUE;
        int kuroRuiseki = 0;
        for (int i = 0; i < length; i++) {
            if (chars[i] == BLACK) {
                kuroRuiseki++;
            }

            int kaeru = kuroRuiseki + length - i - 1 - (black - kuroRuiseki);

            if (kaeru >= 0 && result > kaeru) {
                result = kaeru;
            }
        }

        System.out.println(Math.min(Math.min(black, white), result));

    }
}


Measured memory_bytes: 29764
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	int A, B;
	cin >> A >> B;
	if (A <= 5) cout << 0 << endl;
	else if (A <= 12) cout << B / 2 << endl;
	else cout << B << endl;


	return 0;
}



Measured memory_bytes: 256
n = int(input())
A = list(int(x) for x in input().split())
minimum = min(A)
maximum = max(A)

ANS = []
if abs(maximum) >= abs(minimum):  # すべてをプラスにして累積和
    index = A.index(maximum)
    for i in range(n):
        ANS.append((index, i))
        # A[i] += maximum
    for i in range(n - 1):
        ANS.append((i, i + 1))
        # A[i+1] += A[i]
else:  # 最小値がマイナスで絶対値がかなり大きい -> n回ですべてをマイナスにして累積和
    index = A.index(minimum)
    for i in range(n):
        ANS.append((index, i))
        # A[i] += minimum
    for i in reversed(range(1, n)):
        ANS.append((i, i - 1))
        # A[i-1] += A[i]

print(len(ANS))
for x, y in ANS:
    print(x + 1, y + 1)  # 1-index

# print(A)

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {
    int n;
    string s;
    cin >> n >> s;
    int flag = 0;
    int cnt = 0;

    REP(i, n-2)
    {
        string tmp = s.substr(i, 3);
        if(tmp == "ABC"){
            cnt++;
        }
    }

    ANS(cnt);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

int main() {
    vector<pair<int,int>> red, blue;
    int N;
    
    cin >> N;
    
    int x, y;
    rep( i, N) {
        cin >> x >> y;
        red.push_back({x,y});
    }
    
    rep( i, N) {
        cin >> x >> y;
        blue.push_back({x,y});
    }
    
    sort( red.begin(), red.end());
    sort( blue.begin(), blue.end());
    
    int ans = 0;
    rep(i,N) {
        int u = -1, maxy = -1;
        for ( int r = 0; r < red.size(); r++ ) {
            if ( red[r].first >= blue[i].first ) break;
            if ( red[r].second < blue[i].second && red[r].second >= maxy ) {
                u = r;
                maxy = red[r].second;
            }
        }
        if ( u != -1 ) {
            ans++;
            red.erase( red.begin()+u);
        }
    }
    cout1(ans);
}



Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
int i,c[277];
char s[1010];
int main() {
  scanf("%s",s);
  for (i=0; s[i]; i++) c[s[i]]=1;
  puts((c['N']==c['S'] && c['W']==c['E'])?"Yes":"No");
  return 0;
}


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



int main(){
   int n,a;
   cin >> n >> a;
   cout << n*n-a << endl;
   return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define N 2005
#define reg register
#define F(i,n) for(i=1;i<=n;++i)
#define R(i,n) for(i=n;i;--i)
int n,m,l[N][N],r[N][N],u[N][N];
char s[N][N],v[N][N];
inline void smin(int &a,int b){if(b<a)a=b;}
inline void smax(int &a,int b){if(b>a)a=b;}
int main() {
	reg int i,j,ans;
	scanf("%d%d",&n,&m);
	F(i,n) {
		scanf("%s",s[i]+1);
		F(j,m) s[i][j]=s[i][j]=='#'?1:0;
	}
	--n;--m;
	F(i,n) {
		F(j,m) {
			v[i][j]=s[i][j]^s[i+1][j]^s[i][j+1]^s[i+1][j+1];
		}
	}
	F(i,n) {
		F(j,m) {
			if(!v[i][j]) {
				u[i][j]=u[i-1][j]+1;
				l[i][j]=l[i][j-1]+1;
			}
		}
		R(j,m) {
			if(!v[i][j]) r[i][j]=r[i][j+1]+1;
		}
	}
	ans=(n>m?n:m)+1;
	F(i,n) {
		F(j,m) {
			if(u[i][j]>1) {
				smin(l[i][j],l[i-1][j]);
				smin(r[i][j],r[i-1][j]);
			}
			smax(ans,(l[i][j]+r[i][j])*(u[i][j]+1));
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 55040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int A[15],n,m,q,a[55],b[55],c[55],d[55],ans;
int main()
{
	cin>>n>>m>>q;
	for(int i=1;i<=q;i++)
	{
		cin>>a[i]>>b[i]>>c[i]>>d[i];
	}
	for(int i=1;i<=n;i++)A[i]=1;
	while(!A[0])
	{
		int res=0;
		for(int i=1;i<=q;i++)
		{
			if((A[b[i]]-A[a[i]])==c[i])res+=d[i];
		}
		ans=max(res,ans);
		for(int i=n;i>=0;i--)
		{
			if(A[i]<m)
			{
				A[i]++;
				for(int j=i+1;j<=n;j++)A[j]=A[i];
				break;
			}
		}	
	}
	cout<<ans;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<utility>
using namespace std;
#define maxn 100005
typedef pair<string,int> P;
int n,t;
string name;
int cost;
queue<P> q;
queue<P> ans;
int Time;
void Solve()
{
    while(!q.empty())
    {
        P p=q.front();
        P pp;
        if(p.second>t)
        {
            pp.first=p.first;
            pp.second=p.second-t;
            q.push(pp);
            q.pop();
            Time+=t;
        }
        else
        {
            Time+=p.second;
            ans.push(make_pair(p.first,Time));
            q.pop();
        }

    }
}
int main()
{
    P sp;
    while(cin>>n>>t)
    {
        Time=0;
        for(int i=0;i<n;i++)
        {
            cin>>name>>cost;
            q.push(make_pair(name,cost));
        }

        Solve();

        while(!ans.empty())
        {
            cout<<ans.front().first<<" "<<ans.front().second<<endl;
            ans.pop();
        }

    }
    return 0;
}

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

namespace IMissYou
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine();

            char[] array = new char[input.Count()];
            array = input.ToCharArray();

            string printOut = "";

            foreach(char x in array)
            {
                printOut += 'x';
            }
            Console.WriteLine(printOut);
                        
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;

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

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

int main() {
	string S;
	cin >> S;

	int max = 0;
	int ans = 0;

	for (int i = 0; i < (int)S.size(); i++) {
		for (int k = 0; S[i+k] != '\0'; k++) {
			if ((S[i + k] == 'A') || (S[i + k] == 'C') || (S[i + k] == 'G')
					|| (S[i + k] == 'T')) {
				ans++;
			} else {
				break;
			}
		}
		chmax(max, ans);
		ans = 0;
	}

	cout << max << endl;
}


Measured memory_bytes: 256
#!python3

def LI():
    return list(map(int, input().split()))

# input
H, W = LI()
N = int(input())
A = LI()


def main():
    l = []
    for i in range(N):
        for _ in range(A[i]):
            l.append(i + 1)
    
    for i in range(H):
        x = l[(i * W):(i * W + W)]
        if i % 2 == 1:
            x = x[::-1]
        print(*x)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3920
#include <iostream>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

template <class T>
using grid = vector<vector<T>>;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...);
}

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

ll sum(ll right) {
  return right * (right + 1) / 2;
}

ll sum(ll left, ll right) {
  return sum(right) - sum(left - 1);
}

ll MOD = 1000000000 + 7;

int main() {
  ll input(n, k);
  ll ans = 0;
  FOR(i, k, n + 1) {
    (ans += sum(n - (i - 1), n) - sum(i - 1) + 1) %= MOD;
  }
  print(ans);
}

Measured memory_bytes: 3644
#include<stdio.h>
#include<algorithm>
#include<string.h>
using namespace std;

int dp[1000][1000];//??°??????????????\??°
int d[1000];
int c[1000];

int main(){
	int n, m;
	memset(dp, -1, sizeof(dp));
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++)
		scanf("%d", &d[i]);
	for (int i = 0; i < m; i++)
		scanf("%d", &c[i]);
	for (int i = 1; i <= n; i++){
		for (int j = i; j <= m; j++){
			if (!~dp[i][j - 1])dp[i][j] = dp[i - 1][j - 1] + d[i - 1] * c[j - 1];
			else dp[i][j] = min(dp[i][j - 1], dp[i - 1][j - 1] + d[i - 1] * c[j - 1]);
		}
	}
	printf("%d\n", dp[n][m] + 1);
	return 0;
}

Measured memory_bytes: 6616
use proconio::input;
use std::cmp::min;

fn main() {
    input!{
        na:usize,nb:usize,m:usize,
        a:[i32;na],
        b:[i32;nb],
        xyz:[(usize,usize,i32);m]
    };

    let mut ans = a.iter().min().unwrap()+b.iter().min().unwrap();

    for (x,y,z) in xyz {
        ans = min(ans,a[x-1]+b[y-1]-z);
    }
    println!("{}",ans);
}



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

// https://atcoder.jp/contests/abc128/tasks/abc128_a

int solver(int apples,int chips){
    int result;

    result = ( apples * 3 + chips) / 2 ;
    return result;
}

int main(void){
    int answer ;
    int A,P;
    cin >> A >> P ;
    answer = solver(A,P);
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <queue>
#define rep(i,n) for (int i=0;i<(n);i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	
	int ans = 0;
	for (int i = 1;i <= n;i += 2) {
		int yaku = 0;
		for (int j = 1;j <= i;j++) {
			if (i % j == 0) {
				yaku++;
			}
		}
		if (yaku == 8) {
			ans++;
		}
	}

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


Measured memory_bytes: 3600
n = int(input())
s = [ i for i in input().split()]
flag = True
cnt = 0
while flag:
    flag = False
    for i in range(n-1):
        if int(s[i]) > int(s[i+1]):
            s[i],s[i+1] = s[i+1],s[i]
            flag = True
            cnt += 1
print(' '.join(s))
print(cnt)



Measured memory_bytes: 5604
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Long n = sc.nextLong();
		StringBuilder sb = new StringBuilder();
		while (n > 0) {
			n--;
			int t = (int) (n % 26);
			sb.insert(0, (char) (97 + t));
			n = n / 26;
		}
		System.out.println(sb.toString());
	}
}








Measured memory_bytes: 35700
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;$n:expr) => {
        (0..$n).map(|_| scan!()).collect::<Vec<_>>()
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let _ = scan!(usize);
    let vs = scan!(i64;;);
    let (mut num4, mut num2) = (0, 0);
    for v in vs.iter() {
        if v % 4 == 0 {
            num4 += 1
        } else if v % 2 == 0 {
            num2 += 1
        }
    }
    if 2 * num4 + 1 >= vs.len() || 2 * num4 + num2 >= vs.len() {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 6396
n, x = map(int, input().split())

h = [0] * (n + 1)
h[0] = 1
for i in range(n):
    h[i + 1] = h[i] * 2 + 3

def rec(n, x):
    if x == 0:
        return 0
    if n == 0:
        return 1
    if x * 2 > h[n]:
        return 2 ** n + rec(n - 1, x - 1 - h[n] // 2)
    return rec(n - 1, x - 1)

print(rec(n, x))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;

  cin >> n >> m;

  int T[n+1];
  int c[m];
  for(int j = 0;j < m;j++)cin >> c[j];

  for(int i = 0;i <= n;i++)T[i] = 50001;

  T[0] = 0;

  for(int i = 0;i < m;i++){
    for(int j = c[i];j <= n;j++){
      T[j] = min(T[j],T[j - c[i]]+1);
    }
  }

  cout << T[n] << endl;
}


  

Measured memory_bytes: 1356
#include <bits/stdc++.h>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



using namespace std;



vector <ll> ans(2010,0);

int main() {
  ll N; cin>>N;
  ll x,y; cin>>x>>y;
  for(int s = 1;s<N;s++){
    for(int g = s+1 ; g <= N; g++){ //s,gの最短距離取得
    ll dist1= g - s;
    ll dist2 = 10000;
    if(s <= x){
      dist2 = abs(x-s) + 1 + abs(y-g);
      ans[min(dist1,dist2)]++;
    } else if(x < s and s < y){
       dist2 = abs(x-s) + 1 + abs(y-g);
      ans[min(dist1,dist2)]++;


    } else {
       dist2 = abs(x-s) + 1 + abs(y-g);
      ans[min(dist1,dist2)]++;
    }

    }
  }

  for(int i=1;i<=N-1;i++) cout<<ans[i]<<endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void PRINT(T container, bool withSize) { if(withSize) cout<<container.size()<<endl; for(auto it : container) cout<<it<<" "; cout<<endl; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T> >;
typedef signed long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

int dp[405][405];
int adj[405][405];

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

    int H,W; cin>>H>>W;
    vector<string> grid = readVector<string>(H);

    FOR(i,H*W) {
        if(i%W != 0 && grid[i/W][i%W-1] == '.')
            adj[i][i-1] = 1;
        if(i%W != W-1 && grid[i/W][i%W+1] == '.')
            adj[i][i+1] = 1;
        if(i-W >= 0 && grid[i/W-1][i%W] == '.')
            adj[i][i-W] = 1;
        if(i/W+1 < H && grid[i/W+1][i%W] == '.')
            adj[i][i+W] = 1;
    }

    memset(dp, 0x3f, sizeof dp);
    FOR(i,H*W)
        dp[i][i] = 0;
    FOR(i,H*W)
        FOR(j,H*W)
            if(adj[i][j])
                dp[i][j]=1;

    FOR(k,400)
    FOR(i,400)
    FOR(j,400) {
        dp[i][j] |= MIN(dp[i][k] + dp[k][j]);
    }

    int ans = 0;
    FOR(i,H*W)
    FOR(j,H*W)
        if(grid[i/W][i%W] == '.' && grid[j/W][j%W]=='.')
            ans |= MAX(dp[i][j]);

    cout<<ans<<endl;

    return 0;
}



Measured memory_bytes: 1536
#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(void){
  ll k,a,b; cin >> k >> a >> b;
  ll ans;
  if(b-a<=2){
    ans = k+1;
  }else{
    k-=a-1;
    ans = a + (b-a)*(k/2) + k%2;
  }

  cout << ans << endl;
}


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

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

// h_iと、そのときの左のyと右のyを渡すと面積が返ってくる
double calc(int h, int y1, int y2) {
  if (y1 > h and y2 > h) {
    return fabs(0.5 * (y1 - h + y2 - h));
  }
  if (y1 <= h and y2 <= h) {
    return fabs(0.5 * (h - y1 + h - y2));
  }
  if (y1 <= h and h > y2) {
    double x = 1.0 * (h - y1) / (y2 - y1);
    return fabs(0.5 * ( x * (h - y1) + (1 - x) * (h - y2)));
  } else {
    double x = 1.0 * (h - y1) / (y2 - y1);
    return fabs(0.5 * ( x * (y1 - h) + (1 - x) * (h - y2) ));
  }

}

const double INF = 1e18;
double dp[155][333];

signed main() {
  int n;
  cin >> n;
  vector<int> h(n);
  for (int i = 0; i < n; i++) {
    cin >> h[i];
  }

  // DPテーブルを初期化
  for (int i = 0; i <= n; i++) {
    for (int y = 1; y <= 300; y++) {
      dp[i][y] = INF;
    }
  }
  dp[0][1] = 0;

  // DP
  for (int i = 0; i < n; i++) {
    for (int y1 = 1; y1 <= 300; y1++) { // 左のy
      for (int y2 = 1; y2 <= 300; y2++) { // 右のy
        chmin(dp[i+1][y2], dp[i][y1] + calc(h[i], y1, y2));
      }
    }
  }

  // 最後のyはどれが最適化を選ぶ
  double ans = 1e18;
  for (int i = 1; i <= 300; i++) {
    chmin(ans, dp[n][i]);
  }

  printf("%.10f\n", ans);

  return 0;
}


Measured memory_bytes: 3596