akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
	String [] page;
	int n;
	//0830 start
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			page = new String[n];
			for(int i = 0 ; i < n; i++){
				page[i] = sc.next();
			}
			for(int i = 0; i < m; i++){
				String arg1 = sc.next();
				String arg2 = sc.next();
				String newa = fix(arg1);
				String newb = fix(arg2);
//				//debug
//				System.out.println("newa = " + newa);
//				System.out.println("newb = " + newb);
				
				if(newa == null || newb == null){
					System.out.println("not found");
				}
				else{
					String newaa = fix2(newa);
					String newbb = fix2(newb);
					boolean cand1 = (find(newa) || find(newaa));
					boolean cand2 = (find(newb) || find(newbb));
					if(cand1 && cand2){
						if(newa.equals(newb) || newa.equals(newbb) || newaa.equals(newb) || newaa.equals(newbb)){
							System.out.println("yes");
						}
						else{
							System.out.println("no");
						}
					}
					else{
						System.out.println("not found");
					}
				}
			}
		}
	}

	private String fix2(String newb) {
		if(newb.endsWith("/")){
			return newb + "index.html";
		}
		return newb + "/index.html";
	}

	private String fix(String arg) {
		
		String [] a = arg.split("/");
		ArrayList<String> work = new ArrayList<String>();
		for(int i = 0; i < a.length; i++){
			work.add(a[i]);
		}
		//debug
//		System.out.println(Arrays.toString(a));
//		System.out.println("a = " + work.toString());
		
		for(int i = 1; i < work.size(); i++){
			if(work.get(i).equals(".")){
				work.remove(i);
				i--;
			}
		}
		//debug
		//System.out.println(work.toString());
		
		for(int i = 1; i < work.size(); i++){
			if(work.get(i).equals("..")){
				StringBuilder sb = new StringBuilder("/");
				for(int j = 1; j < i; j++){
					sb.append(work.get(j) + "/");
				}
				boolean flg = false;
				for(int j = 0; j < n; j++){
//					//debug
//					System.out.println("test = " + page[j] + " " + sb.toString());
//					System.out.println("test2 = " + page[j].matches(sb.toString() + ".*"));
					if(page[j].matches(sb.toString() + ".*")){
						flg = true;
						break;
					}
				}
				if(! flg){
					return null;
				}
				work.remove(i);
				work.remove(i-1);
				i--;i--;
			}
		}
		StringBuilder res = new StringBuilder();
		for(int i = 0 ; i < work.size(); i++){
			res.append("/" + work.get(i));
		};
		//System.out.println(res.toString());
		if(arg.endsWith("/")){
			res.append("/");
		}
		if(res.length() > 0){
			return res.substring(1);
		}
		return res.toString();
	}

	private boolean find(String s) {
		for(int i = 0; i < n; i++){
			if(s.equals(page[i])) return true;
		}
		return false;
	}

	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define sort(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	int ans = 0;
	ff(i, 0, n) {
		int a;
		cin >> a;
		if (a >= k)ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi w(n);
    rep(i,n)cin>>w[i];
    Rep(i,1,n)w[i]+=w[i-1];
    int ans=inf;
    rep(i,n-1){
        ans=min(ans,abs(w[i]-(w[n-1]-w[i])));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int siz=1e6;
const long inf=1e9;
int main(){
	int X,N; cin>>X>>N;
	int cnt[102] = {}; int p;
	rep(i,0,N){ cin>>p; cnt[p]++; }
	int a = X,b = X;
	while(cnt[a]) a--;
	while(cnt[b]) b++;
	if(X-a <= b-X) cout<<a<<endl;
	else cout<<b<<endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
#define endn "\n"
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


////////////////////////////////////////////////////////////////////
vector<int> divisor(int n){
  vector<int> ret;
  for(int i = 1;i*i <= n;i++){
    if(n % i == 0){
      ret.push_back(i);
      if(n/i != i)ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}
map<int, int> prime_factor(int n){
  map<int, int> ret;
  for(int i = 2;i*i <= n;i++){
    while(n % i == 0){
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1){
    ret[n] = 1;
  }
  return ret;
}
////////////////////////////////////////////////////////////////////

int k;queue<int> que;
signed main(){
  cin>>k;
  repd(i,1,10)que.push(i);
  int x;
  rep(i,k){
    x = que.front();que.pop();
    int y = 10*x+(x%10);
    if(y % 10 != 0)que.push(y-1);
    que.push(y);
    if(y % 10 != 9)que.push(y+1);
  }
  cout << x << endl;
}


Measured memory_bytes: 1792
// Problem : A - Circle
// Contest : AtCoder - AtCoder Beginner Contest 145
// URL : https://atcoder.jp/contests/abc145/tasks/abc145_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int r;
    cin>>r;
    cout<<r*r<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3556
using System;

namespace abc165
{
    class Program
    {
        static void Main()
        {
            var k = int.Parse(Console.ReadLine());
            var ab = Console.ReadLine().Split(' ');
            var a = int.Parse(ab[0]);
            var b = int.Parse(ab[1]);
            for (var i = a; i <= b; ++i)
            {
                if (i % k == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");
        }
    }
}


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

using namespace std;

#define ll long long
#define MAX 100

int main()
{
    ll n, g;
    scanf("%lld %lld", &n, &g);
    vector<ll> V;
    pair<ll, ll> p[MAX];
    for(ll i=1; i<=n; i++){
        scanf("%lld %lld", &p[i].first, &p[i].second);
        V.push_back(i);
    }
    ll mins = INT_MAX;
    vector<ll> st = V;
    while(1){
        ll ans = 0;
        ll tot = g;
        for(ll i=0; i<V.size(); i++){
            ll x = V[i];
            ll cnt = p[x].first, bonus = p[x].second;
            ll needed = tot/(x*100);
            if(tot%(x*100) != 0) needed++;
            if(needed <= cnt){
                ans += needed;
                break;
            }
            else {
                ans += cnt;
                tot -= (cnt*x*100+bonus);
                if(tot <= 0) break;
            }
        }
        mins = min(mins, ans);
        next_permutation(V.begin(), V.end());
        if(V == st) break;
    }
    cout << mins;
}


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

s = 0
c = 0
m = abs(a[0])
for i in range(n):
  t = abs(a[i])
  s += t
  if m > t:
    m = t
  if a[i] < 0:
    c += 1

if c % 2 == 1:
  s -= m * 2

print(s)


Measured memory_bytes: 14332
import java.util.*;

class Main{
  static Scanner sc = new Scanner(System.in);
  public static void main(String[] args){
    String s = sc.next();
    String t=sc.next();
    int sum=0;
    for(int i=0;i<3;i++){
      if(s.charAt(i)==t.charAt(i)){
        sum++;
      }
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 22996
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
qx = [list(map(int, input().split())) for i in range(q)]

ans = 0

for i in combinations_with_replacement(range(1, m + 1), n):
    s = 0
    for a, b, c, d in qx:
        s += d if (i[b-1] - i[a-1] == c) else 0
    ans = max(ans, s)

print(ans)


Measured memory_bytes: 9136
#include<iostream>
#include<string>
const int LEN = 100005;
using namespace std;

struct p
{
    string name;
    int q;
};

p Q[LEN];
int head, tail;

void enqueue(p x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

p dequeue(){
    p x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int main(){
    int elap = 0, c;
    int n, q; cin >> n >> q;
    p u;
    for (int i = 0; i < n; i++)
    {
        cin >> Q[i].name >> Q[i].q;
    }
    
    head = 0; tail = n;
    while (head != tail)
    {
        u = dequeue();
        c = min(q, u.q);
        u.q -= c;
        elap += c;
        if (u.q > 0)
        {
            enqueue(u);
        }

        else
        {
            cout << u.name << " " << elap << endl;
        }

    }
    
}


Measured memory_bytes: 6920
M = 1000000007
N = int(input())
S = [input() for i in range(2)]

ans = 1
l = 1
i = 0
while i < N:
    if S[0][i] == S[1][i]:
        if i == 0:
            ans = ans * 3 % M
        else:
            if l == 1:
                ans = ans * 2 % M
        l = 1
        i += 1
    else:
        if i == 0:
            ans = ans * 6 % M
        else:
            if l == 1:
                ans = ans * 2 % M
            else:
                ans = ans * 3 % M
        l = 2
        i += 2

print(ans)


Measured memory_bytes: 3064
def main():
    V, E = map(int, input().split())
    G = [[float("INF")] * V for _ in range(V)]
    for i in range(V):
        G[i][i] = 0
    for _ in range(E):
        s, t, d = map(int, input().split())
        G[s][t] = d

    for k in range(V):
        for i in range(V):
            for j in range(V):
                G[i][j] = min(G[i][j], G[i][k] + G[k][j]) 

    for i in range(V):
        if G[i][i] < 0:
            print("NEGATIVE CYCLE")
            return

        for j in range(V):
            if G[i][j] == float("INF"):
                G[i][j] = "INF"
    for g in G:
        print(*g)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6284
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define int long long 

int32_t main() {
	int n;
	cin >> n;
	vector<int> height(n);
	for(int i = 0; i < n; i++)
		cin >> height[i];

	int maxDec = 0;
	int curCount = 0;
	for(int i = 1; i < n; i++)
	{
		if(height[i - 1] >= height[i])
			curCount++;
		else
		{
			maxDec = max(curCount, maxDec);
			curCount = 0;
		}
	}
	maxDec = max(curCount, maxDec);

	cout << maxDec << endl;
}

Measured memory_bytes: 1024
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)


const double pi = std::acos(-1.0);

using type = std::complex<long double>;

std::vector<type> fft(std::vector<type> v, bool inv = false) {
  ll const n = v.size();
  double theta = 2 * pi / n * (inv ? -1 : 1);
  for (ll m = n; m >= 2; m >>= 1) {
    ll mh = m >> 1;
    type theta_i(0, theta);
    for (ll i = 0; i < mh; i++) {
      type w = std::exp((type)i * theta_i);
      for (ll j = i; j < n; j += m) {
        type x = v[j] - v[j + mh];
        v[j] = v[j] + v[j + mh];
        v[j + mh] = w * x;
      }
    }
    theta *= 2;
  }
  ll i = 0;
  for (ll j = 1; j < n - 1; j++) {
    for (ll k = n >> 1; k > (i ^= k); k >>= 1)
      ;
    if (j < i) std::swap(v[i], v[j]);
  }
  if (inv) {
    for (auto &x : v) x /= n;
  }
  return v;
}

std::vector<long long> convolution(std::vector<type> x, std::vector<type> y) {
  ll sz = 1;
  ll t = x.size() + y.size() - 1;
  while (sz < t) {
    sz <<= 1;
  }
  x.resize(sz);
  y.resize(sz);
  x = fft(std::move(x));
  y = fft(std::move(y));
  for (ll i = 0; i < sz; i++) {
    x[i] *= y[i];
  }
  x = fft(std::move(x), true);
  vector<long long> res(sz);
  for(ll i=0; i<sz; i++) res[i] = (long long)(x[i].real() + 0.5);
  return res;
}



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    vector<type> a(1e5+1),b(1e5+1);
    FOR(i,0,n){
        ll in;
        cin>>in;
        a[in]+=1; b[in]+=1;
    }
    vector<ll> v = convolution(a,b);
    ll cnt=0;
    ll res = 0;
    FORr(i,0,v.size()){
        if(cnt >= k)break;
        res += min(v[i],k-cnt)*i;
        cnt += min(v[i],k-cnt);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 26056
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0)
#define END return EXIT_SUCCESS
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR(I,0,N)
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP(I,N) cin>>V[I]
#define INS2(I,N,V1,V2) REP(I,N) cin>>V1[I]>>V2[I];
#define INS3(I,N,V1,V2,V3) REP(I,N) cin>>V1[I]>>V2[I]>>V3[I];
#define OUT(P) cout<<P<<endl
#define OUT2(P1,P2) cout<<P1<<" "<<P2<<endl
#define OUT3(P1,P2,P3) cout<<P1<<" "<<P2<<" "<<P3<<endl
#define OUTS(I,N,V) REP(I,N) cout<<V[i]<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
typedef unsigned long ul;
typedef unsigned int ui;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

long N,K,i;
vector<long> D;
string M;
bool flag;

inline void solve(){
  IN2(N,K);
  D.resize(K);
  INS(i,K,D);
  M=to_string(N);
  while(1){
    flag=true;
    REP(i,K){
      if(M.find(to_string(D[i]))!=string::npos){
        flag=false;
        break;
      }
    }
    if(flag){
      OUT(M);
      return;
    }
    N++;
    M=to_string(N);
  }
}

int main(int argc,char**argv){
  BEGIN;
  solve();
  END;
}


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

public class Main {
	public static void main(String[] args) throws Exception {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			int n = Integer.parseInt(br.readLine());
			Map<String, Integer> map = new HashMap<>();
			int max = 0;
			for (int i = 0; i < n; i++) {
				String s = br.readLine();
				int val = map.containsKey(s) ? map.get(s) + 1 : 1;
				map.put(s, val);
				max = Math.max(max, val);
			}
			List<String> list = new ArrayList<>();
			for (String key : map.keySet()) if (map.get(key) == max) list.add(key);
			Collections.sort(list);
//			PrintWriter out = new PrintWriter(System.out);
//			for (String s : list) System.out.println(s);
//			out.flush();
			StringBuilder ans = new StringBuilder();
			for (String s : list) ans.append(s + "\n");
			System.out.println(new String(ans));
		}
	}
}

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

int main(void){
    
    ll n, ans=1;
    
    cin >> n;
    
    vector<ll> d(n, 9999);
    
    for(ll i=0; i<=n-1; i++){
        
        cin >> d.at(i);
        
    }
    
    sort(d.begin(), d.end());
    
    if(n==1){
        
        cout << "1" << endl;
        return 0;
        
    }
    
    for(ll i=0; i<=n-2; i++){
        
        if(d.at(i)!=d.at(i+1)){
            
            ans += 1;
            
        }
        
    }
    
    cout << ans << endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

  ll H, W, k;
  cin >> H >> W >> k;
  vector<string> a(H);
  rep(h, 0, H) cin >> a[h];
  
  vector<Vl> ans(H, Vl(W));
  ll color = 1;
  bool f = true;
  rep(h, 0, H) {
    rep(w, 0, W){
      if(a[h][w] == '#') {
        color++;
        if(f == true){
        color--;
        f = false;
        }
      }
    
      ans[h][w] = color;
      if(w == W-1){
        color++;
        f = true;
      }
    }
    bool ff = true;
    rep(ww, 0, W) if(a[h][ww] == '#') ff = false;
    if(ff) color--;
  }
  
  int t = 300;
  while(t--){
    
  rep(h, 0, H-1){
    bool fla = true;
    rep(w, 0, W) if(a[h][w] != '.') fla = false;
    if(fla){
      rep(w, 0, W) ans[h][w] = ans[h+1][w];
    }
  }
  bool fla = true;
  rep(w, 0, W) if(a[H-1][w] != '.') fla = false;
  if(fla){
    rep(w, 0, W) ans[H-1][w] = ans[H-2][w];
  }

  

  }

  int l = 300;
  while(l--){
    for(int h = H-1; h >= 1; h--){
    bool fla = true;
    rep(w, 0, W) if(a[h][w] != '.') fla = false;
    if(fla){
      rep(w, 0, W) ans[h][w] = ans[h-1][w];
    }
  }
  }


  rep(h, 0, H){
    rep(w, 0, W){
      if(w) cout << " ";
      cout << ans[h][w];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 1664
#include <stdio.h>

int main(){
	int n,i=1;
	scanf ("%d",&n);
	int ary[n];
	for (;i<=n;i++){
		scanf ("%d",&ary[i]);
	}
	i=i-1;
	for (;i>=1;i--){
		printf ("%d",ary[i]);
		if (i!=1){
			printf (" ");
		}
	}
	printf ("\n");

	return 0;
}

Measured memory_bytes: 600
#include<iostream>
using namespace std;
int main()
{
    int n, m;
    cin >> n >> m;
  
/* s - - s - s => 偶数ならON
   - s - s s s => 奇数ならON
   という問題は,和積ともにXOR演算のもとで
   [[1 0 0 1 0 1],
   [0 1 0 1 1 1]]  dot [ x1 x2 x3 x4 x5 ] = [0 1]
   の解の個数を求めるのと同じ
   その個数は2^(自由変数の個数)となる
*/
   
    int k, s;
    int sw[10]; // LSB:p_i それ以外:s_ij
    for (int i = 0; i < m; i++) {
      sw[i] = 0;
      cin >> k;
      for (int j = 0; j < k; j++) {
        cin >> s;
        sw[i] |= 1 << s;
      }
    }
    int p;
    for (int i = 0; i < m; i++) {
      cin >> p;
      sw[i] |= p;
    }
  
    int pv = 0; // ピボット数
    int pv_index, tmp;
    int not_resolve = 0;
    for (int mask = 1<<n; mask != 1; mask >>= 1) {
      pv_index = -1;
//for (int i = 0; i < m; i++) cout << hex << sw[i] << endl; cout << "p" << pv_index; cout << endl;
      for (int j = pv; j < m; j++) {
        if (sw[j] & mask) {
          if (pv_index == -1) pv_index = j;
          else {
            sw[j] ^= sw[pv_index];
            if (sw[j] == 1) {
              not_resolve = 1;
              break;
            }
          }
        }
      }
      if (pv_index != -1) {
        tmp = sw[pv];
        sw[pv] = sw[pv_index];
        sw[pv_index] = tmp;
        pv++;
      }
      if (not_resolve) break;
    }

    int result;
    if (not_resolve) result = 0;
    else {
      result = 1;
      for (int i = pv; i < n; i++) result *= 2;
    }
  
    cout << result << endl;
    return 0;
}

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

using namespace std;

#define INF 2000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

long long dp[55][55][2550];
int main()
{
	int n, a;
	cin >> n >> a;
	int x[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	for (int i = 0; i < 52; i++) {
		for (int j = 0; j < 52; j++) {
			for (int k = 0; k < 2550; k++) {
				dp[i][j][k]=0;
			}
		}
	}

	dp[0][0][0]=1;
//	dp[0][1][x[0]]=1;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < 2500; k++) {
				if (dp[i][j][k]) {
					dp[i+1][j][k] += dp[i][j][k];
					dp[i+1][j+1][k+x[i]] += dp[i][j][k];
				}
			}
		}
	}

	ll ans = 0;
	for (int i = 1; i <= n; i++) {
		ans += dp[n][i][i*a];
	}
	cout << ans << endl;

}


Measured memory_bytes: 57600
import java.util.*;
public class Main 
{
	public static void main(String[] args) 
	{
		Scanner stdIn = new Scanner(System.in);
		while(stdIn.hasNext())
		{
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			if(n == 0 && m == 0)
			{
				break;
			}
			List<Integer> list = new ArrayList<Integer>();
			for(int i = 0; i < n; ++i)
			{
				int price = stdIn.nextInt();
				list.add(price);
			}
			Collections.sort(list);
			int count = 1;
			int sum = 0;
			for(int i = list.size() - 1; i >= 0; --i)
			{
				if(count == m)
				{
					count = 1;
					continue;
				}
				sum += list.get(i);
				++count;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int h[n];

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

    sort(h,h+n);
    long long int sum=0;

    if(n>k)
    {
         for(int i=0;i<n-k;i++)
         {
             sum+=h[i];
         }
         cout<<sum<<endl;
    }

    else
    {
        cout<<0<<endl;
    }

    exit(0);

}


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

int main(){
    int n;
    cin >> n;
    int a[n];
    rep(i, n) { 
        int b;
        cin >> b;
        a[i] = b - 1;
    }
    int count = 0;
    rep(i, n) {
        if(a[a[i]] == i)
            count++;
    }
    cout << count / 2 << endl;
    return 0;
}

Measured memory_bytes: 640
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
string s;
int w;
int main(){
	cin>>s;
	cin>>w;
	for(int i=0;i<s.size();i+=w){
		cout<<s[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
	char al[110];
	int n,a[30],b[30],ans=0;
	memset(a,0,sizeof(a));
	memset(b,0,sizeof(b));
	cin>>n;
	scanf("%s",&al);
	for(int i=0;i<n;i++) a[al[i]-'a'+1]++;
	b[al[0]-'a'+1]++;
	a[al[0]-'a'+1]--;
	if(a[al[0]-'a'+1]) ans=1;
	for(int i=1;i<n;i++){
		b[al[i]-'a'+1]++;
		a[al[i]-'a'+1]--;
		int k=0;
		for(int j=1;j<=26;j++) if((b[j])&&a[j]) k++;
		ans=max(ans,k);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<map>
using namespace std;
// 1 [2] 3 [4] 5 [6] 7 [8] 9 [10] 11 [12] 13 [14] 15 [16] 17 [18] 19 [20]
// 1     2     3     4     5       6       7       8       9      10
int make[10];
long long sum = 0;
char str[25];
void makeit(int n) {
	if (str[2 * n] == '+')
		str[2 * n] = 0;
	else
		str[2 * n] = '+';
}
void ans(int x, int n) {
	if (x == n) {
		long long s = 0, tmp = 0, k = 1;
		for (int i = 20; i >= 1; i--)
		{
			if (isdigit(str[i])) {
				tmp += (str[i] - '0') * k;
				k *= 10;
			}
			else if(str[i] == '+') {
				k = 1;
				s += tmp;
				tmp = 0;
			}
		}
		s += tmp;
		sum += s;
		return;
	}
	makeit(n + 1);
	ans(x, n + 1);
	makeit(n + 1);
	ans(x, n + 1);
}

int main() {
	char t[11];
	cin >> t;
	int len = strlen(t);
	for (int i = 0; i < len; i++)
	{
		str[(i + 1) * 2 - 1] = t[i];
	}
	ans(len - 1, 0);
	cout << sum << endl;
	return 0;
}


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

int main(){
    int n,ans=0;cin>>n;
    vector<int> l(n),r(n);
    for(int i=0;i<n;i++){
        cin>>l.at(i)>>r.at(i);
        ans+=(r.at(i)-l.at(i)+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
class Tree:
    __slots__ = ['id', 'p', 'sibling', 'degree', 'depth', 'height', 'type', 'c']
    def __init__(self, id):
        self.id = id
        self.p = -1
        self.sibling = -1
        self.degree = 0
        self.depth = 0
        self.height = 0
        self.type = "leaf"
        self.c = []
    def __str__(self):
        return f"node {self.id}: parent = {self.p}, sibling = {self.sibling}, degree = {self.degree}, depth = {self.depth}, height = {self.height}, {self.type}"
def solve():
    n = int(input())
    tree = tuple(Tree(i) for i in range(n))
    for _ in range(n):
        id, *c = map(int, readline().replace("-1", "").split())
        if c != []:
            tree[id].type = "internal node"
            tree[id].c = c
            for j in c:
                tree[j].p = id
            len_c = len(c)
            tree[id].degree = len_c
            if len_c == 2:
                tree[c[0]].sibling = c[1]
                tree[c[1]].sibling = c[0]
    root = 0
    while tree[root].p != -1:
        root = tree[root].p
    tree[root].type = "root"
    def depth_height_check(id, d):
        d += 1
        height = 0
        for i in tree[id].c:
            tree[i].depth = d
            if tree[i].type != "leaf":
                tree[i].height = depth_height_check(i, d) + 1
                height = max(height, tree[i].height)
        return height
    tree[root].height = depth_height_check(root, 0) + 1 if n > 1 else 0
    print("\n".join(map(str, tree)))
solve()



Measured memory_bytes: 5632
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n;
	int i,j;
	int ans=0;
	
	//データの読み込み
	scanf("%d",&n);
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	for(i=0;i<15;i++){
		for(j=0;j<25;j++){
			if(7*i+4*j==n){
				ans=1;
			}
		}
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	if(ans==1){
		printf("Yes");
	}else{
		printf("No");
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
N, M = map(int, input().split())
H = list(map(int, input().split()))
D = {i: [] for i in range(N)}
for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] > H[B-1]:
        D[B-1].append(A-1)
    elif H[A-1] < H[B-1]:
        D[A-1].append(B-1)
    elif H[A-1] == H[B-1]:
        D[B-1].append(A-1)
        D[A-1].append(B-1)
cnt = 0
for i in range(N):
    if D[i] == []:
        cnt += 1
print(cnt)

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int N = 1e5 + 5;
int a, b, c, x, y;

int main() {
    cin >> a >> b >> c >> x >> y;
    if (c * 2 <= a + b) {
        int ans = 0;
        int m = min(x, y);
        x -= m;
        y -= m;
        ans += m * 2 * c;
        ans += min(c * 2, a) * x;
        ans += min(c * 2, b) * y;
        cout << ans << endl;
    } else {
        cout << a * x + b * y << endl;
    }
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
ll a, b, n;
ll f(ll x) { return floor(1.0 * a * x / b) - a * floor(1.0 * x / b); }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cin >> a >> b >> n;
  cout << f(min(n, b - 1)) << endl;
}

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

int main()
{
    string A, B;
    cin >> A >> B;
    while (A.size() <= 100)
        A.insert(0, "0");
    while (B.size() <= 100)
        B.insert(0, "0");
    if (B < A)
        cout << "GREATER" << endl;
    else if (A == B)
        cout << "EQUAL" << endl;
    else
        cout << "LESS" << endl;
    return 0;
}

Measured memory_bytes: 256
l=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
s = int (input())
print(l[s-1])

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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

int digit_sum(i64 x){
    int res=0;
    while(x){
        res+=x%10;
        x/=10;
    }
    return res;
}

i64 shift(i64 x,int k){
    rep(i,0,k) x/=10;
    return x;
}

void solve(){
    i64 N;
    cin >> N;

    int ans=digit_sum(N);
    auto s=to_string(N);
    for(int i=0; i<s.size(); ++i){
        if(s[i]=='0') continue;
        ans=max(ans,int(9*(s.size()-i-1)+digit_sum(shift(N,s.size()-i))+s[i]-'0'-1));
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

void printVec(vector<int> vec){
    rep(i,vec.size()){
        cout << vec.at(i);
        if(i < vec.size()-1) cout << " ";
    }
    cout <<  endl;
}

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int n,q,query,x,t;
    cin >> n >> q;
    vector<vector<int>> vec(n);

    rep(i,q){
        cin >> query >> t;
        if(query == 0){
            cin >> x;
            vec[t].push_back(x);
        }else if(query==1){
            printVec(vec[t]);
        }else{
            vector<int> v;
            vec[t] = v;
        }
    }   
}


Measured memory_bytes: 6780
func gcd(_ x: Int, _ y: Int) -> Int {
    if y == 0 { return x }
    return gcd(y, x % y)
}

let K = Int(readLine()!)!
var res: Int = 0

for a in 1...K {
    for b in 1...K {
        for c in 1...K {
            res += gcd(gcd(a, b), c)
        }
    }
}
print(res)

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

int main() {
  int h, w;
  cin >> h >> w;
  string a[h];
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }
  int right = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w - 1; j++) {
      if (a[i][j] == '#' && a[i][j + 1] == '#') {
        right++;
      }
    }
  }
  int down = 0;
  for (int i = 0; i < h - 1; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#' && a[i + 1][j] == '#') {
        down++;
      }
    }
  }
  cout << (right == w - 1 && down == h - 1 ? "Possible" : "Impossible") << endl;
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

int main(){

    int n;
    cin >> n;
    ll ans = 1;
    for(int i = 0; i < n; i++){
        ans *= (i+1);
        ans %= MOD;
    }
    cout << ans << endl;
    
    return 0;
}

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





int main() {


  int N,M;
  cin>>N>>M;
  
  vector<int> vec(2*M);
  
  for (int i=0;i<2*M;i++){
    cin>>vec.at(i);
  }
  
  for (int i=1;i<N+1;i++){
    int number=0;
    for (int j=0;j<2*M;j++){
      if (vec.at(j)==i){
        number+=1;
      }
      
    }
    cout<<number<<endl;
  }

    
  
  
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
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;
}
const long long INF = 1LL << 60;

int main()
{
    int n;
    cin >> n;
    int v[n], c[n];
    int ans = 0;
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
    rep(i, n)
    {
        ans += v[i] > c[i] ? v[i] - c[i] : 0;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 1000000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;


ll n,m,l;

int main() {
    //read,write;
    cin >> n >> m >> l;
    ll a[n+5][m+5],b[m+5][l+5],ans[n+5][l+5];
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++) ans[i][j]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++) cin >> a[i][j];
    }

    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++) cin >> b[i][j];
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            for(int k=0;k<m;k++){
                ans[i][j]+=a[i][k]*b[k][j];
            }
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<l-1;j++){
            cout << ans[i][j] << " ";
        }
        cout << ans[i][l-1] << endl;
    }
 

    return 0;
}



Measured memory_bytes: 3352
let i_inp_list : unit -> int list = fun () ->
  let inp_split = Str.split (Str.regexp " ") (input_line stdin) in
  List.map (fun x -> int_of_string x) (inp_split)
  
let () =
  let (n, k) = Scanf.sscanf (input_line stdin) "%d %d" (fun a b -> (a, b)) in
  let l = i_inp_list () in
  let ans = List.fold_right (fun h num -> num + (if h >= k then 1 else 0)) l 0
  in
  print_int ans;
  print_newline ()


Measured memory_bytes: 13824
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<map>
#include<cstring>
#include<iomanip> //cout << fixed << setprecision(15) << x << endl;

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 6;
const ll MOD = 1e9 + 7;
const ll LLINF = 1LL<<60;
#define P pair<int, int>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
/* -- template -- */

int main() {
    ll N, K; cin >> N >> K;
    ll cntK2 = 0, cnt0 = 0;
    for(int i = 1; i <= N; ++i) {
        if(i % K == K / 2) ++cntK2;
        if(i % K == 0) ++cnt0;
    }
    ll ans = ((K%2 == 0) ? cntK2 * cntK2 * cntK2 : 0) + cnt0 * cnt0 * cnt0;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

map<string,int>M,A;
char C[]={'A','C','T','G'};

set<string>ng;

bool NG(string s){
    if(s[0]=='A'&&s[1]=='G'&&s[2]=='C')return 1;
    if(s[1]=='A'&&s[2]=='G'&&s[3]=='C')return 1;
    return 0;
}

void dfs(string s){
    if(s.size()==4){
        M[s]++;

        int F=0;
        if(NG(s))F++;
        r(i,3){
            string t=s;
            swap(t[i],t[i+1]);
            if(NG(t))F++;
        }
        if(F)ng.insert(s);
    }
    else{
        r(i,4){
            string t=s;
            t+=C[i];
            dfs(t);
        }
    }
}

signed main(){
    int n;
    cin>>n;
    if(n==3){
        cout<<61<<endl;
        return 0;
    }
    dfs("");
    n-=4;
    r(i,n){
        A.clear();
        for(auto &e:M){
            if(ng.count(e.F))continue;
            r(j,4){
                string t=e.F;
                t.erase(t.begin());
                t+=C[j];
                A[t]+=e.S;
                A[t]%=1000000007;
            }
        }
        M=A;
    }
    int sum=0;
    for(auto &e:M){
        if(ng.count(e.F))continue;
        sum+=e.S;
        sum%=1000000007;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
import math


def triangle(a, b, angle):
    """returns (area, circumference, height) of a triangle

    a, b: sides of a trianble
    anble: interior angle of a, b (deg)

    >>> s, l, h = triangle(4, 3, 90)
    >>> print('{:.5f} {:.5f} {:.5f}'.format(s, l, h))
    6.00000 12.00000 3.00000
    >>> s, l, h = triangle(1, 1, 60)
    >>> print('{:.5f} {:.5f} {:.5f}'.format(s, l, h))
    0.43301 3.00000 0.86603
    """
    rad = math.radians(angle)
    h = b * math.sin(rad)
    c = math.sqrt(h**2 + (a - b*math.cos(rad))**2)

    return ((a * h) / 2, a + b + c, h)


def run():
    a, b, C = [int(i) for i in input().split()]
    (area, length, height) = triangle(a, b, C)

    print(area)
    print(length)
    print(height)


if __name__ == '__main__':
    run()



Measured memory_bytes: 5732
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
#define fi first
#define se second
//#define mp make_pair
#define pb push_back
typedef pair<int,int> P;
#define REP(i,x,y) for(int i=x;i<=y;i++)
#define abs(x) ((x)>0?(x):-(x))
const int maxn = 100205, inf = 0x3f3f3f3f;
int n;
char s[maxn];
int main(){
	cin>>s>>n;
	int m=strlen(s);
	for(int i=0;i<m;i++){
		if((i)%n==0) {
			cout<<s[i];
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define rep(i, n) repl(i, 0, n)
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18 + 10;
const int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
const int dy[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);

	int n;
	cin >> n;
	string s[n];
	int t[n];
	rep(i, n) cin >> s[i] >> t[i];
	int ans = 0;
	string x;
	cin >> x;
	bool flag = 0;
	rep(i, n) {
		if (flag)
			ans += t[i];
		else if (x == s[i])
			flag = 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
n = int(input())
a = list(map(lambda x: int(x) - 1, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

total = 0
i = -10
for a_i in a:
    if a_i == i + 1:
        total += c[i]
    total += b[a_i]
    i = a_i
print(total)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
2
80 70
)");
#define cin input
#endif

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

	int c[512][512] = {};

	REP(i, m)
	{
		int l, r;
		cin >> l >> r;
		--l, --r;
		++c[l][r];
	}

	REP(i, n)
	{
		FOR(j, i + 1, n)
			c[i][j] += c[i][j - 1];
	}

	REP(i, q)
	{
		int p, q;
		cin >> p >> q;
		--p, --q;
		int r = 0;
		FOR(j, p, q + 1)
			r += c[j][q];
		cout << r << endl;
	}

	return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define per(i,r,l) for(int i=r;i>=l;i--)
#define fi first
#define se second
#define lc T[p].l
#define rc T[p].r
#define mid (l+r>>1)
#define lson lc,l,mid
#define rson rc,mid+1,r
#define sum T[p].val
#define pii pair<int,int>
const int MX=1e6+7;
const int mod=998244353;
const double pi=3.1415926535897932384;
double isp=1e-13;
using namespace std;
ll qpow(ll a,ll b,ll MOD=mod){for(ll ans=1;;a=a*a%MOD,b>>=1){if(b&1)ans=ans*a%MOD;if(!b)return ans;}}
ll inv(ll a,ll MOD=mod){return qpow(a,MOD-2,MOD);}//要求MOD为质数
ll exgcd(ll a,ll b,ll &x,ll &y){if(b==0){x=1,y=0;return a;}ll ret=exgcd(b,a%b,y,x);y-=a/b*x;return ret;}
ll getInv(int a,int mod){ll x,y;ll d=exgcd(a,mod,x,y);return d==1?(x%mod+mod)%mod:-1;}//求a在mod下的逆元，不存在逆元返回-1，不要求MOD为质数
ll mx[MX],a[10];
void solve()
{
    int n;
    cin>>n;
    if(n>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}
int main()
{
  ios::sync_with_stdio(0),cin.tie(0);
  int t;
 // cin>>t;
  t=1;
  while(t--)
  {
      solve();
  }
}


Measured memory_bytes: 3608
while 1:
    n = int(input())
    if n == 0:
        break

    alist = []
    for _ in range(n):
        a = int(input())
        alist.append(a)

    cnt = 0
    for i in range(len(alist)):
        for j in range(len(alist)-1, i, -1):
            if alist[j] < alist[j-1]:
                alist[j], alist[j-1] = alist[j-1], alist[j]
                cnt += 1

    print(cnt)



Measured memory_bytes: 5604
#include <bits/stdc++.h>
#define int long long
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? LLONG_MAX : INT_MAX;
const int MOD = 1000000007;
const long double EPS = 1e-8;

signed main() {
	int n;
	string s;
	cin >> n >> s;
	rep (i, 2) {
		string ans = i ? "S" : "W";
		string tmp = ans;
		rep (j, 2) {
			ans = tmp;
			ans += j ? "S" : "W";
			/*
			*/
			range (k, 1, s.size()) {
				if (s[k] == 'o') {
					if (ans[k] == 'S')
						ans += ans[k - 1] == 'S' ? "S" : "W";
					else
						ans += ans[k - 1] == 'S' ? "W" : "S";
				}
				else {
					if (ans[k] == 'S')
						ans += ans[k - 1] == 'S' ? "W" : "S";
					else
						ans += ans[k - 1] == 'S' ? "S" : "W";
				}
			}
			if (s[0] == 'o') {
				if (ans[1] == 'S') {
					if (ans[0] == 'S') ans.insert(ans.begin(), 'S');
					else ans.insert(ans.begin(), 'W');
				}
				else {
					if (ans[0] == 'S') ans.insert(ans.begin(), 'W');
					else ans.insert(ans.begin(), 'S');
				}
			} else {
				if (ans[1] == 'S') {
					if (ans[0] == 'S') ans.insert(ans.begin(), 'W');
					else ans.insert(ans.begin(), 'S');
				}
				else {
					if (ans[0] == 'S') ans.insert(ans.begin(), 'S');
					else ans.insert(ans.begin(), 'W');
				}
			}

			if (ans[0] == ans[ans.size() - 2] && ans[1] == ans[ans.size() - 1]) {
				ans.pop_back();
				ans.erase(ans.begin());
				cout << ans << endl;
				return 0;
			}
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,sum,diff;
  char op;
  cin>>a>>op>>b;
  if(op=='+')
  {
    sum=a+b;
    cout<<sum<<endl;
  }
 
  else
  {
    diff=a-b;
    cout<<diff<<endl;
  }
    
  return 0;
  
}

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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 2e5 + 5;

typedef pair<int,int>   ii;

int f[N];
int h[N];

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

    int n;  cin >> n;
    int k;  cin >> k;

    fill(f + 2,f + 2 + n,1e9 + 7);

    for(int i = 1 ; i <= n ; ++i)   {
        cin >> h[i];

        for(int j = 1 ; j <= k ; ++j)   {
            if (j >= i) break;

            int nxt = f[i - j] + abs(h[i - j] - h[i]);

            if (f[i] > nxt)
                f[i] = nxt;
        }
    }
    cout << f[n] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main () {
  int64_t N, A, B;
  cin >> N >> A >> B;
  int64_t i = (A + B) * (N / (A + B));
  int64_t ans = A * (N / (A + B));
  if ((i + A) < N) {
    ans += A;
  }
  else {
    ans += (N - i);
  }
  cout << ans << endl; 
}

Measured memory_bytes: 3620
from sys import stdin
from itertools import accumulate
import bisect

n = int(stdin.readline().rstrip())
a = list(map(int,stdin.readline().rstrip().split()))
b = list(map(int,stdin.readline().rstrip().split()))

pra = []
mai = 0
kosuu = 0
atari = 0

for i in range(n):
    if a[i]-b[i] < 0:
        mai += b[i]-a[i]
        kosuu += 1
        continue
    elif a[i]-b[i] > 0:
        pra.append(a[i]-b[i])
    atari += 1

if sum(pra) < mai:
    print(-1)
    exit()
if atari == n:
    print(0)
    exit()
pra.sort(reverse=True)

pra = list(accumulate(pra))
print(bisect.bisect(pra,mai)+kosuu+1)

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

priority_queue<int>q;

struct node{string s;};

priority_queue<string,vector<string>,greater<string> >ans;

char ch[5500];

map<string,int>mark;
bool f[2000];


int main(){
	
	int i,j,l,x,k;
	string A;
	scanf("%s",ch);
	for(i=0;ch[i];i++)
		if(!f[ch[i]]){
			q.push(-ch[i]);
			f[ch[i]]=true;
		}
	scanf("%d",&k);
	if(k==1){
		printf("%c",-q.top());
		return 0;
	}
	while(k&&!q.empty()){
		//printf("%d\n",k);
		x=-q.top();
		q.pop();
		for(i=0;ch[i];i++)
			if(ch[i]==x){
				A.clear();
				for(j=i;ch[j]&&i+5>=j;j++){
					A+=ch[j];
					ans.push(A);
				}
			}
		while(k&&!ans.empty()){
			//printf("big=%d\n",ans.size());
		//	cout<<ans.top()<<endl;
			A=ans.top();
			if(mark.find(A)==mark.end()){
				mark[A]=1;
				k--;
			//	cout<<A<<endl;
			}
			if(k)ans.pop();
		/*	if(k==1)k=0;
			printf("?=%d ",k);
			cout<<ans.top()<<' '<<A<<endl;*/
		}
		//if(k==1)break;
	}
	cout<<ans.top();
	return 0;
}		


Measured memory_bytes: 1916