akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($arg:expr),*) => {
        #[cfg(debug_assertions)]
        $(writeln!(stderr(), "{} = {:?}", stringify!($arg), $arg).unwrap());*
    };
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

trait IteratorExt: Iterator + Sized {
    fn vec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

impl<T: Iterator> IteratorExt for T {}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, E) = read!(usize, u64);
    let X = read![[u64]];

    let mut Y = vec![0; N + 1];
    for i in 0..N {
        Y[i + 1] += Y[i] + X[i];
    }

    let mut mi = std::u64::MAX;

    for t in 1..N {
        let mut l = N - min(N, t);
        let mut u = 5_u64;
        let mut cost = E * t as u64;

        // 5
        cost += u * (Y[N] - Y[l]);

        // 5, 7, ..
        while l > 0 {
            let h = l - min(l, t);
            cost += u * (Y[l] - Y[h]);

            l = h;
            u += 2;
        }

        mi = min(mi, cost);
    }

    let mut cost = mi;
    cost += E * N as u64;

    println!("{}", cost)
}


Measured memory_bytes: 9392
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		no3();
	}

	static void no3() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			long y = sc.nextLong();
			long t = 0;
			for (int i = 0; i <= n; i++) {
				for (int j = 0; j <= n - i; j++) {
					t = 10000 * i + 5000 * j + 1000 * (n - i - j);
					if (t == y) {
						System.out.println(i + " " + j + " " + (n - i - j));
						return;
					}
				}
			}
			System.out.println("-1 -1 -1");
		}
	}

	static void no2() {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = 0;
			}

			int ans = 0;
			for (int i = 0; i < n; i++) {
				int flg = 0;
				int t = sc.nextInt();
				for (int j = 0; j < n; j++) {
					if (a[j] == t) {
						flg = 1;
						break;
					}
				}
				if (flg == 0) {
					ans++;
				}
				a[i] = t;
			}
			System.out.println(ans);
		}
	}

	static void no1() {
		try (Scanner sc = new Scanner(System.in)) {
			String str = sc.nextLine();
			System.out.println("2018/01/" + str.substring(8));
		}
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)

class Sushi{
public:
	lli kind;
	lli value;
};

Sushi make_sushi(lli t,lli d){
	Sushi s;
	s.kind=t;
	s.value=d;
	return s;
}

bool operator< (const Sushi &sushi1,const Sushi &sushi2){
	return sushi1.value>sushi2.value;
}

signed main(){

	lli k,n;
	cin>>n>>k;

	vector<Sushi> v;

	REP(i,0,n){
		lli t,d;
		cin>>t>>d;
		v.push_back(make_sushi(t,d));
	}

	sort(v.begin(),v.end());
	
	priority_queue<Sushi> q;

	lli sum=0;
	set<lli> s;
	lli kindD[100010]={0};
	REP(i,0,k){
		q.push(v[i]);
		sum += v[i].value;
		s.insert(v[i].kind);
		kindD[v[i].kind]++;
	}

	lli ans=sum + (s.size()*s.size());

	lli now=k;
	while(q.size() && now<n){
		lli topKind  = q.top().kind;
		lli topValue = q.top().value;
		q.pop();
		if(kindD[topKind]==1)continue;

		/*入れ替えを行う*/
		sum -= topValue;
		sum += v[now].value;
		s.insert(v[now].kind);
		q.push(v[now]);
		kindD[v[now].kind]++;
		ans = max((unsigned lli)ans, sum+(s.size()*s.size()));
		now++;
	}


	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 8432
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
int N,M;
ll A[100010],B[100010],Y[100010];
ll X[100010];
vector<vector<pair<int,ll>>> v(100010);
vector<pair<ll,int>> edges;
int p[100010] = {0},r[100010] = {0};
ll s[100010] = {0};
void init(int N){
	for(int i=0;i<=N;++i){
		p[i] = i;
		s[i] = X[i];
	}
}
 
int root(int a){
	if(p[a] == a) return a;
	return (p[a] = root(p[a]));
}
 
bool is_same_set(int a,int b){
	return root(a) == root(b);
}
 
void unite(int a, int b){
	a = root(a);
	b = root(b);
	if(a==b) return;
	if(r[a]<r[b]){
		p[a] = b;
		s[b] += s[a];
		s[a] = s[b];
	}else{
		p[b] = a;
		s[a] += s[b];
		s[b] = s[a];
		if(r[a] == r[b]) r[a]++;
	}
}

int visited[100010] = {},ans = 0;
void dfs(int n,int c){
	for(auto& a:v[n]){
		int b = a.first;ll id = a.second;
		if(visited[id]==0 && Y[id]<=c){
			visited[id] = 1; ans++;
			dfs(b,c);
		}
	}
}

int main(){
	cin >> N >> M;
	for(int i=1;i<=N;i++){
		cin >> X[i];
	}
	init(N);
	for(int i=1;i<=M;i++){
		cin >> A[i] >> B[i] >> Y[i];
		v[A[i]].push_back({B[i],i});
		v[B[i]].push_back({A[i],i});
		edges.push_back({Y[i],i});
	}
	sort(edges.begin(),edges.end());
	stack<int> S;
	for(auto& a:edges){
		int id = a.second;
		unite(A[id],B[id]);
		if(s[root(A[id])]>=Y[id]) S.push(id);
	}
	while(!S.empty()){
		int a = S.top(); S.pop();
		if(visited[a]==0) dfs(A[a],Y[a]);
	}
	cout << M-ans << endl;
}

Measured memory_bytes: 19184
#include<stdio.h>
#define swap(x, y) {int z; z=y; y=x; x=z;}
int main()
{
	int a, b;
	while(scanf("%d %d", &a, &b))
	{
		if(a==0 && b==0)
		{
			break;
		}
		if(a>b)
		{
			swap(a, b);
		}
		printf("%d %d\n", a, b);
	}
	return 0;
}


Measured memory_bytes: 2036
(n,),aa,bb = [list(map(int, s.split())) for s in open(0)]

up = down = 0

for i in range(n):
    a = aa[i]
    b = bb[i]
    if a > b:
        down += a-b
    if b > a:
        d,m = divmod(b-a,2)
        up += d+m
        down += m

diff = sum(bb) - sum(aa)

if up <= diff and down <= diff:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 74192
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

template <class T>
class SegTree {
    using F = function<T(T, T)>;
    int n;
    vector<T> data;
    const F f;
    const T e;

public:
    SegTree(const vector<T>& as, const F f, const T& e) : f(f), e(e) {
        n = 1;
        while (n < as.size()) n <<= 1;
        data.assign(2 * n, e);
        for (int i = 0; i < as.size(); i++) {
            data[n + i] = as[i];
        }
        for (int i = n - 1; i > 0; i--) {
            data[i] = f(data[2 * i], data[2 * i + 1]);
        }
    }

    void update(int k, const T& x) {
        k += n;
        data[k] = x;
        while (k >>= 1) {
            data[k] = f(data[2 * k], data[2 * k + 1]);
        }
    }

    T query(int a, int b) {
        T L = e, R = e;
        for (a += n, b += n; a < b; a >>= 1, b >>= 1) {
            if (a & 1) {
                L = f(L, data[a++]);
            }
            if (b & 1) {
                R = f(data[--b], R);
            }
        }
        return f(L, R);
    }
};

using ii = pair<int, int>;
struct range {
    int l, r;
    ii mi;
    bool even;
    bool operator<(const range& rhs) const {
        return mi.first > rhs.mi.first;
    }
};

void printvec(vi& x, int size = 0) {
    if (x.size() == 0) {
        cout << endl;
        return;
    }
    cout << x.front();
    for (int i = 1; i < (size == 0 ? x.size() : size); i++) {
        cout << " " << x[i];
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    vector<ii> es, os;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (i % 2 == 0) {
            es.emplace_back(p, i);
        } else {
            os.emplace_back(p, i);
        }
    }
    SegTree<ii> et(es, [](ii a, ii b) {return min(a, b);}, ii(1e9, 0));
    SegTree<ii> ot(os, [](ii a, ii b) {return min(a, b);}, ii(1e9, 0));
    priority_queue<range> er;
    range orr = {-1, -1, ii(-1, -1), true};
    er.push({0, n, et.query(0, n / 2), true});
    vi ans;
    while (er.size() || orr.l != -1) {
        if (orr.l != -1) {
            ans.push_back(orr.mi.first);
            if (orr.mi.second != orr.l) {
                er.push({orr.l, orr.mi.second, (orr.even ? et : ot).query((orr.l + orr.even) / 2, (orr.mi.second + orr.even) / 2), orr.even});
            }
            if (orr.mi.second + 1 != orr.r) {
                er.push({orr.mi.second + 1, orr.r, (!orr.even ? et : ot).query((orr.mi.second + 1 + !orr.even) / 2, (orr.r + !orr.even) / 2), !orr.even});
            }
            orr = {-1, -1, ii(-1, -1), true};
            continue;
        }
        
        range rem = er.top();
        ans.push_back(rem.mi.first);
        if (rem.l != rem.mi.second) {
            er.push({rem.l, rem.mi.second, (rem.even ? et : ot).query((rem.l + rem.even) / 2, (rem.mi.second + rem.even) / 2), rem.even});
        }
        orr = {rem.mi.second + 1, rem.r, (!rem.even ? et : ot).query((rem.mi.second + 1 + !rem.even) / 2, (rem.r + !rem.even) / 2), !rem.even};
        er.pop();
    }
    
    printvec(ans);
}


Measured memory_bytes: 10468
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let m = 60;
    let mut a: Vec<usize> = (0..n).map(|_| it.next().unwrap().parse().unwrap()).collect();
    let xor = a.iter().fold(0, |s, a| s ^ a);
    let mut ans = xor;
    a = a.into_iter().map(|a| a & !xor).collect();
    let mut v = 0;
    for i in (0..m).rev() {
        if (xor >> i) & 1 == 1 {
            continue;
        }
        let p = *a.iter().max().unwrap();
        if v ^ p > v {
            v ^= p;
        }
        for j in 0..n {
            if (a[j] ^ p) < a[j] {
                a[j] ^= p;
            }
        }
    }
    ans += 2 * v;
    println!("{}", ans);

}

fn main() {
    run();
}


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

bool search(vector<int> *pl,vector<int> land,int current,int end,int n){
  if(current == end && n==2)
    return true;
  for(auto itr = land.begin();itr!=land.end();itr++){
    if(search(pl,pl[*itr],*itr,end,n+1))
      return true;
  }
  return false;
}

int main(){
  int n,m,a,b;
  cin >> n>>m;
  vector<int> land[n];
  for(int i=0;i<m;i++){
    cin >> a>>b;
    land[a-1].push_back(b-1);
  }
  int start = 0,end = n-1;

  if(search(land,land[start],start,end,0))
    cout << "POSSIBLE" << endl;
  else
    cout << "IMPOSSIBLE" << endl;

}


Measured memory_bytes: 8824
#include <stdio.h>

#define SQ(x) ((x) * (x))

typedef struct {
    double x;
    double y;
} POINT;

int dist(POINT a, POINT b)
{
    if (SQ(a.x - b.x) + SQ(a.y - b.y) > 1){
        return (0);
    }
    return (1);
}

int max(int a, int b)
{
    if (a > b){
        return (a);
    }
    return (b);
}

int main(void)
{
    POINT seal[100], l[100][100];
    int n;
    int count, ans;
    int i, j, k;
    
    while (1){
        scanf("%d", &n);
        
        if (!n){
            break;
        }
        
        for (i = 0; i < n; i++){
            scanf("%lf%*c%lf", &seal[i].x, &seal[i].y);
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                l[i][j].x = seal[i].x / 2.00 + seal[j].x / 2.00;
                l[i][j].y = seal[i].y / 2.00 + seal[j].y / 2.00;
            }
        }
        
        ans = 0;
        for (i = 0; i < n; i++){
            for (j = 0; j < n; j++){
                count = 0;
                for (k = 0; k < n; k++){
                    if (dist(seal[k], l[i][j])){
                        count++;
                    }
                }
                ans = max(ans, count);
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 0
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(A: "List[List[int]]", N: int, b: "List[int]"):
    for i in range(N):
        n = b[i]
        for j in range(3):
            for k in range(3):
                if A[j][k] == n:
                    A[j][k] = 0
    if A[0][0] == A[0][1] == A[0][2]:
        print(YES)
    elif A[1][0] == A[1][1] == A[1][2]:
        print(YES)
    elif A[2][0] == A[2][1] == A[2][2]:
        print(YES)
    elif A[0][0] == A[1][0] == A[2][0]:
        print(YES)
    elif A[0][1] == A[1][1] == A[2][1]:
        print(YES)
    elif A[0][2] == A[1][2] == A[2][2]:
        print(YES)
    elif A[0][0] == A[1][1] == A[2][2]:
        print(YES)
    elif A[0][2] == A[1][1] == A[2][0]:
        print(YES)
    else:
        print(NO)

    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = [[int(next(tokens)) for _ in range(3)] for _ in range(3)]  # type: "List[List[int]]"
    N = int(next(tokens))  # type: int
    b = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(A, N, b)

if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  int A=0;
  for(int a=1; a<=N; a++){
      for(int b=1; b<=N; b++){
           for(int c=1; c<=N; c++){
             int j =1;
         for(int i=1; i<=min(a,min(b,c)); i++){
          
           if (a%i==0&&b%i==0&&c%i==0){
             j=i;
            
           }
           if(i==min(a,min(b,c)))  A+=j;
         }    
          
  }
  }    
  }
  cout <<A;
}


Measured memory_bytes: 3612
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
D = LIST()
d_s = set(D)
moto = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
amari = d_s & moto
l = list(str(N))
l = map(int, l)

# for i in range(len(l)):
i = N
while 1:
    
    l = list(str(i))
    l = list(map(int, l))
    l_s = set(l)
    s_intersection = d_s & l_s
    
    if len(s_intersection) == 0:
        print(i)
        exit()
    i += 1
    # if d_s.isdisjoint(l_s):
    #     print(i)
    #     exit()






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

int main() {
  int a, b;
  char op;

  while (1){
    cin>>a>>op>>b;
    if( op == '+' ) cout<<a+b<<endl;
    else if( op == '-' ) cout<<a-b<<endl;
    else if( op == '*' ) cout<<a*b<<endl;
    else if( op == '/' ) cout<<a/b<<endl;
    else break;
  }

  return 0;
}


Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#define lli long long int

using namespace std;

lli a[16][16];

lli func(bool vis[16][16][16][16], int x, int y, int s, int t)
{
	if(x == s && y == t){
		return 1;
	}
	if(a[x][y] > 0){
		return a[x][y];
	}
	
	lli r = 0;
	if(x+1 <= s && vis[x][y][x+1][y]){
		r += func(vis, x+1, y, s, t);
	}
	if(y+1 <= t && vis[x][y][x][y+1]){
		r += func(vis, x, y+1, s, t);
	}
	a[x][y] = r;
	
	return r;
}

int main()
{
	int n, s, t, x1, y1, x2, y2, v, p;
	bool vis[16][16][16][16];
	
	cin >> n;
	while(n--){
		cin >> s >> t;
		cin >> p;
		fill(&vis[0][0][0][0], &vis[15][15][15][15], true);
		fill(&a[0][0], &a[15][15], 0);
		while(p--){
			cin >> x1 >> y1 >> x2 >> y2;
			vis[x1][y1][x2][y2] = vis[x2][y2][x1][y1] = false;
		}
		
		lli r = func(vis, 0, 0, s, t);
		if(r == 0){
			cout << "Miserable Hokusai!" << endl;
		} else {
			cout << r << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  int x;
  cin >> x;
  int count = x/100;
  int num = x%100;
  if(num > count*5) {
    cout << 0 << endl;
  }else {
    cout << 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



int main() {
	int c, a, b;
	cin >> c >> a >> b;
	cout << c * a / 2 << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,N-1,0)
#define RREPS(i,n) RFOR(i,N,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
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 int INF=1e18;
const int MOD=1e9+7;
const int MAX=2e6+1000;
int fac[MAX],finv[MAX],inv[MAX];

void COMinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

int COM(int n,int k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int powMOD(int n,int r){
    if(r==0)return 1;
    if(r%2==0)return powMOD(n,r/2)*powMOD(n,r/2)%MOD;
    if(r%2==1)return powMOD(n,r-1)*n%MOD;
}

signed main(){
    COMinit();
    int A,B,C,D;cin>>A>>B>>C>>D;
    int ans=0;
    for(int i=A+1;i<=C+1;i++){
        ans+=COM(i+D,D)-COM(i+B-1,B-1); 
        ans%=MOD;
    }
  	while(ans<0)ans+=MOD;
    cout<<ans<<endl;
}

Measured memory_bytes: 50460
#include <bits/stdc++.h>
using namespace std;
#define int long long
int MOD = (int)1e9 + 7;
int INF = (int)2e18;
// Comment out below and program paste

// #include "UnionFind.hpp"
// #include "power.hpp"

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S;
    cin >> S;
    int N = S.length();
    string A = "", B = "";
    for (int i = 0; i < N; i++) {
        if (i % 2 == 0) {
            A += '0';
            B += '1';
        } else {
            A += '1';
            B += '0';
        }
    }
    int ans1 = 0, ans2 = 0;
    for (int i = 0; i < N; i++) {
        if (S[i] != A[i]) ++ans1;
        if (S[i] != B[i]) ++ans2;
    }
    cout << min(ans1, ans2) << endl;
}


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

using namespace std;

int main(){

    int N;
    long long cnt = 0;
    long long ans = 0;

    cin >> N;

    for(long long a = 1;a<=N-1;a++){
        cnt = (N-1)/a;
        ans += cnt;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3420
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
	int i,j,n,m;
	char input[2];
	char *a;
	char *b;
	while(1)
	{
		scanf("%d",&n);
		if(n == 0)return 0;
		a = (char*)malloc(sizeof(char)*n*2);
		if(a == NULL) exit(EXIT_FAILURE);
		b = (char*)malloc(sizeof(char)*n*2);
		if(b == NULL) exit(EXIT_FAILURE);
		for(i=0;i<n;i++)
		{
				scanf("%s %s",a+(2*i),b+(2*i));
		}
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s",input);
			for(j=0;j<n;j++)
			{
				if(*(a+(2*j)) == input[0])
				{
					input[0] = *(b+(2*j));
					break;
				}
				
			}
			printf("%c",input[0]);
		}
		printf("\n");
		free(a);
		free(b);
	}
	return 0;
}

Measured memory_bytes: 576
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define endl "\n"
#define pi 3.14159265358979323846264338327950288
#define MOD 1000000007
#define INF -100000000000000
#define ordered_set tree<pair< ll int ,ll  int>, null_type,less<pair<ll int, ll int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
using namespace std;
#define lld long double
using namespace __gnu_pbds;
int main()
{
    fast;
    ll int n,ww;
    cin>>n>>ww;
    ll int i,j;
    ll int w[n],v[n];
    for(i=0;i<n;i++)
    {
    	cin>>w[i]>>v[i];
    }
    ll int dp[n+1][ww+1];
    for(i=0;i<=n;i++)
    {
    	for(j=0;j<=ww;j++)
    	{
    		if(i==0)
    			dp[i][j]=0;
    		else if(w[i-1]>j)
    			dp[i][j]=dp[i-1][j];
    		else 
    			dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
    	}
    }
    cout<<dp[n][ww]<<endl;
}

Measured memory_bytes: 82460
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>

#define DIV 1000000007
using namespace std;

int main() {
    int N, Y;
    cin >> N >> Y;
   
    int flag = 0;
    for (int yuki = 0; yuki <= N; yuki++) {
        for (int higu = 0; higu <= N-yuki; higu++) {
            int nogu = (Y - 10000 * yuki - 5000 * higu)/1000;
            if (nogu == N - yuki-higu) {
                cout << yuki << " " << higu << " " << nogu << endl;
                flag = 1;
                break;
            }
        }
        if (flag)
            break;
    }
    if(!flag)
    cout << "-1 -1 -1" << endl;
}

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

using namespace std;

int main(){
    int a,b;
    char ope;
    while(true){
        cin >> a >> ope >> b;
        if(ope=='+') cout << a + b << "\n";
        else if(ope=='-') cout << a-b << "\n";
        else if(ope=='*') cout << a*b << "\n";
        else if(ope=='/') cout << a/b << "\n";
        else if(ope=='?') break; 
    }  
    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <math.h>

#define INPUT_FROM_FILE (0)

#if INPUT_FROM_FILE
#include <fstream>
#endif

#if INPUT_FROM_FILE
#define IS ifs
#else
#define IS std::cin
#endif

bool is_prime(int num){
	bool ret = true;
	int max = int(sqrt(num)) + 1;

	if(num == 2){
	}
	else if(num % 2 == 0){
		ret = false;
	}
	else{
		for(int i = 3; i < max; i+=2){
			if(num % i == 0){
				ret = false;
				break;
			}
		}
	}

	return ret;
}

int main(int argc, char **argv){
#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
#endif
	int n = 0;
	int num_primes = 0;

	IS >> n;

	for(int i = 0; i < n; i++){
		int num = 0;

		IS >> num;
		if(is_prime(num)){
			num_primes++;
		}
	}

	std::cout << num_primes << std::endl;
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Okay_Bye return 0
#define fo(i,n) for(auto i=0;i<n;i++)
#define f1(i,a,n) for(auto i=a;i<n;i++)
#define pn printf("\n")
#define Yes printf("YES\n")
#define No printf("NO\n")
#define pb push_back

int cs=1;
const int N=1e5+7;
int a[N],b[N],c[N],n,dp[3][N];
int fu(int i,int s){
    if(i>n-1)return 0;
    if(dp[s-1][i]!=-1)return dp[s-1][i];
    int x;
    if(s==1){
        x = a[i]+max(fu(i+1,2),fu(i+1,3));
    }if(s==2){
        x = b[i]+max(fu(i+1,1),fu(i+1,3));
    }if(s==3){
        x = c[i]+max(fu(i+1,2),fu(i+1,1));
    }
    return dp[s-1][i]=x;
}
void solve(){
    cin>>n;
    fo(i,n){
        cin>>a[i]>>b[i]>>c[i];
    }
    memset(dp,-1,sizeof dp);
    cout<<max(fu(0,1),max(fu(0,2),fu(0,3)))<<endl;
}

signed main()
{
	int t=1;
	//cin>>t;
	while(t--)solve();
	Okay_Bye;
}

Measured memory_bytes: 9600
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

N, M = gets_i_list
h_list = gets_i_list

ans_list = Array.new(N + 1, true)
ans_list[0] = false

M.times do
  a, b = gets_i_list
  ha = h_list[a-1]
  hb = h_list[b-1]
  if ha == hb
    ans_list[a] = false
    ans_list[b] = false
  elsif ha >= hb
    ans_list[b] = false
  else ha <= hb
    ans_list[a] = false
  end
end
puts ans_list.count(true)

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

using ull = unsigned long long;

static const int MOD = 1e9 + 7;
static const int MAX = 1000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void CombiInit(int max)
{
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < max; i++)
  {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long Combi(int n, int k)
{
  if (n < k)
    return 0;
  if (n < 0 || k < 0)
    return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
  int X, Y;
  cin >> X >> Y;
  if ((X + Y) % 3 != 0)
  {
    cout << 0 << endl;
    return 0;
  }
  int n = 2 * X - Y;
  int m = 2 * Y - X;
  if (n < 0 || m < 0)
  {
    cout << 0 << endl;
    return 0;
  }

  n /= 3;
  m /= 3;
  // どちらかが0の場合は1通りしかない
  if (n == 0 || m == 0)
  {
    cout << 1 << endl;
    return 0;
  }

  CombiInit(m + n + 10);

  cout << Combi(m + n, m) << endl;

  return 0;
}

Measured memory_bytes: 22784
N, x_ini=map(int,input().split())
a=list(map(int, input().split()))
x = x_ini
count =0

for i in range(N):
	for j in range(i,0,-1):
		if a[j-1] > a[j]:
			temp = a[j-1]
			a[j-1] = a[j]
			a[j]=temp
			
while x > 0:
	x -= a[count]
	count += 1
	if N==count:
		break
if x==0:
	print(count)
else:
	print(count-1)

Measured memory_bytes: 3064
n,*a=map(int,open(0).read().split())
m=6**8
c=[0]*m
p=[1,1]+c[:]
for i in range(m):
  if p[i]<1:
    for j in range(i,m,i):p[j]=i
for a in a:
  s={a}
  while a!=p[a]:
    s|={p[a]}
    a//=p[a]
    s|={a}
  for i in s:c[i]+=1
print(('not','psaeitr'[max(c[2:])>1::2]+'wise')[max(c[2:])<n],'coprime')

Measured memory_bytes: 234532
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
	char suit;
	int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[],int n,int left,int mid,int right){
 int i,j,k;
	int n1=mid-left; 
	int n2=right-mid;
	for(i=0;i<n1;i++)L[i]=A[left+i];
	for(i=0;i<n2;i++)R[i]=A[mid+i];
	L[n1].value=R[n2].value=SENTINEL;
	i=j=0;
	for(k=left;k<right;k++){
		if(L[i].value<=R[j].value){
		A[k]=L[i++];
		}else{
		A[k]=R[j++];
		}
	}
}

void mergeSort(struct Card A[],int n,int left,int right){
	int mid;
	if(left+1<right){
		mid=(left+right)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int partition(struct Card A[],int n,int p,int r){
 int i,j;
	struct Card t,x;
  x=A[r];
  i=p-1;
	for(j=p;j<r;j++){
		if(A[j].value<=x.value){
		 i++;
		 t=A[i]; A[i]=A[j]; A[j]=t;
		}
	}
t=A[i+1]; A[i+1]=A[r]; A[r]=t;
return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){

	int q;
	if(p<r){
	
		q=partition(A,n,p,r);
		quickSort(A,n,p,q-1);
		quickSort(A,n,q+1,r);
	}
}

int main(){
	int n,i,v;
	struct Card A[MAX],B[MAX];
	char S[10];
	int stable=1;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%s %d",S,&v);
		A[i].suit=B[i].suit=S[0];
		A[i].value=B[i].value=v;
		}
	
	mergeSort(A,n,0,n);
	quickSort(B,n,0,n-1);
	
	for(i=0;i<n;i++){
		if(A[i].suit!=B[i].suit)stable=0;
	}
	
	if(stable==1)printf("Stable\n");
	else printf("Not stable\n");
	for(i=0;i<n;i++){
		printf("%c %d\n",B[i].suit,B[i].value);
	}
	return 0;
}




Measured memory_bytes: 4112
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 6/11/2018
 
 14:35-15:15 give up
 15:30-16:00 read editorials
 18:45-19:04 pause
 
 Editorials:
  - https://youtu.be/6ZP8JyGsQBs?t=1094
  - http://agc007.contest.atcoder.jp/data/agc/007/editorial.pdf
 
 Summary:
  - bucket or inversion... => bucket
 
 */

// $ g++ -std=c++11 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
// 14:35-15:15 give up
const int MAX_N=2e4+1;
int N;
LL P[MAX_N];
LL A[MAX_N],B[MAX_N];

LL BU=MAX_N+10;
void test() {
  int prev=-1e9;
  REP(i,N) {
    if(i>0) assert(A[i]>A[i-1]&&B[i]<B[i-1]);
    LL a=A[P[i]],b=B[P[i]],x=a+b;
    assert(1<=a&&a<=1e9);
    assert(1<=b&&b<=1e9);
    assert(prev<x);
    prev=x;
  }
}

void solve() {
  
  /*
  REP(i,N) A[i]=i*BU+1,B[N-i-1]=i*BU+1;
  REP(i,N) A[P[i]]+=i;
  */
  
  int i,j,k,l,r,x,y; string s;
  
  REP(i,N) {
    A[i]=30000*(i+1);
    B[i]=30000*(N+1-i);
  }
  REP(i,N) {
    A[P[i]]+=i;
    B[P[i]]+=i;
  }
   
  test();
  REP(i,N) cout<<A[i]<<(i==(N-1)?"\n":" ");
  REP(i,N) cout<<B[i]<<(i==(N-1)?"\n":" ");
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>N;
  REP(i,N) {
    int x;
    cin>>x;
    --x;
    //P[x]=i;
    P[i]=x;
  }
    
  solve();
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
int n;
int a[MAXN], FMax[MAXN], SMax[MAXN];
int main()
{
    scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
    FMax[1] = a[1]; SMax[1] = 0;
    for(int i = 2; i <= n; i++)
    {
        if(a[i] >= FMax[i-1]) FMax[i] = a[i], SMax[i] = FMax[i-1];
        else
            if(a[i] > SMax[i-1]) FMax[i] = FMax[i-1], SMax[i] = a[i];
            else
                FMax[i] = FMax[i-1], SMax[i] = SMax[i-1];
    }
    for(int i = 1; i <= n; i++) printf("%d\n", (FMax[n] == a[i]) ? SMax[n] : FMax[n]);
//    system("pause");
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元使ったnCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元によりr!で割ると同値
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io
    
    string s;
    cin>>s;
    if(s[0]==s[1] && s[1]==s[2]) cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1[1];
  int n=-1,o=0;
  cin >> s1[0];
  for(int i=0;i<s1[0].size();i++){
    if(s1[0][i] == 'A' && n == -1){
      n = i;
    } 
    if(s1[0][i] == 'Z'){
      o = i;
    }
  }

  cout << o-n+1 << endl;

  return 0;
}


Measured memory_bytes: 640
/* 
 * Project: AtCoder Beginners Contest 095 A - Something on It
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/02
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

char s[3];

void solve() {

    int price = 700;
    for (int i=0;i<sizeof(s)/sizeof(char);i++) {
        if (s[i] == 'o') {
            price += 100;
        }
    }
    printf("%d\n", price);

}

int main() {

    scanf("%s", s);

    solve();

}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int N, K;
    cin >> N >> K;
    vector<ll> p(N);
    for (int i = 0; i < N; ++i) cin >> p[i], ++p[i];

    vector<ll> s(N+1, 0);
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + p[i];

    ll res = 0;
    for (int i = 0; i+K <= N; ++i) res = max(res, s[i+K] - s[i]); 
    cout << fixed << setprecision(10) << (double)(res)/2 << endl;
    return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 28;

// ====================================================================

int main() {
  string s;
  cin >> s;
  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'x') count++;
  }
  if (count < 8)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static final int MOD = 1000000007;

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

		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());

		int n = Math.max(a, b);
		int m = Math.min(a, b);
		long ans = 1;

		if (Math.abs(n - m) <= 1) {
			ans = power(n, ans);
			ans = power(m, ans);
		} else {
			ans = 0;
		}

		if (a == b) {
			ans *= 2;
			ans %= MOD;
		}

		System.out.println(ans);
		sc.close();
	}

	public static long power(int x, long ans) {
		long res = ans;
		for (int i = 1; i <= x; i++) {
			res *= i;
			res %= MOD;
		}
		return res;
	}
}

Measured memory_bytes: 21716
#include <cstdio>
#include <vector>
using namespace std;

int n;
int arr[200000][2];
vector<int> v[200001];
int dpt[200001];

void depth(int now, int d, int p)
{
	dpt[now] = d;

	for (int i = 0; i < v[now].size(); i++)
		if (v[now][i] != p)
			depth(v[now][i], d + 1, now);
}

int main()
{
	scanf("%d", &n);

	for (int i = 0; i < n - 1; i++)
	{
		scanf("%d %d", &arr[i][0], &arr[i][1]);
		v[arr[i][0]].push_back(arr[i][1]);
		v[arr[i][1]].push_back(arr[i][0]);
	}

	depth(1, 0, -1);
	
	int md = 1;

	for (int i = 2; i <= n; i++)
		if (dpt[md] < dpt[i])
			md = i;

	depth(md, 0, -1);

	int md2 = 1;

	for (int i = 2; i <= n; i++)
		if (dpt[md2] < dpt[i])
			md2 = i;

	int ans = dpt[md2] + 1;

	if (ans <= 3)
	{
		if (ans == 2)
			printf("Second");
		else
			printf("First");
	}
	else
	{
		if (ans % 3 == 2)
			printf("Second");
		else
			printf("First");
	}


	return 0;
}

Measured memory_bytes: 25984
//#include "bits/stdc++.h"

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

const int MAX = 1000010;

int dp1[3010][3010], dp2[3010][3010];

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

	int N, T;
	int A[3010], B[3010];

	cin >> N >> T;
	rep(i, 0, N)
	{
		cin >> A[i] >> B[i];
	}

	rep(i, 0, N)
	{
		rrep(j, 0, T)
		{
			dp1[i + 1][j] = dp1[i][j];
			if (j - A[i] >= 0)
			{
				chmax(dp1[i + 1][j], dp1[i][j - A[i]] + B[i]);
			}
		}
	}
	rrep(i, 0, N)
	{
		rrep(j, 0, T)
		{
			dp2[i][j] = dp2[i + 1][j];
			if (j - A[i] >= 0)
			{
				chmax(dp2[i][j], dp2[i + 1][j - A[i]] + B[i]);
			}
		}
	}

	int ans = 0;
	rep(i, 0, N)
	{
		if (i == 0)
		{
			chmax(ans, B[i] + dp2[1][T - 1]);
		}
		else if (i == N - 1)
		{
			chmax(ans, B[i] + dp1[N - 1][T - 1]);
		}
		else
		{
			rep(j, 0, T)
			{
				chmax(ans, B[i] + dp1[i][j] + dp2[i + 1][T - 1 - j]);
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 141696
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,m,c,ans=0,val=0;cin>>n>>m>>c;
  lvector a(m,0),b(m,0);
  rep(i,m) cin>>b[i];
  rep(i,n) {
    val=c;
    rep(i,m) cin>>a[i];
    rep(i,m) val+=a[i]*b[i];
    if(val>0) ans++;
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    h,w = map(int, input().split())
    a = [list(map(int, input().split())) for _ in range(h)]
    b = [list(map(int, input().split())) for _ in range(h)]
    c = [[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            c[i][j] = abs(a[i][j] -b[i][j])

    mid = 6400
    dp = [[0]*w for _ in range(h)]
    dp[0][0] = (1<<(mid+c[0][0])) | (1<<(mid-c[0][0]))
    for x in range(h):
        for y in range(w):
            for dx, dy in [[0, 1], [1, 0]]:
                nx = x + dx
                ny = y + dy
                if 0<=nx<h and 0<=ny<w:
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]<<c[nx][ny])
                    dp[nx][ny] = dp[nx][ny] | (dp[x][y]>>c[nx][ny])
    
    for i in range(mid+1):
        if (dp[-1][-1]>>i) & 1:
            res = mid - i

    print(res)

if __name__ == '__main__':
    main()

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    string s;
    cin >> s;
    print(s[0] == '7' or s[1] == '7' or s[2] == '7' ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 3632
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])

x,y,z = 0,0,0
for _ in range(int(input())):
    a,b,c = ilele()
    if x == y == z == 0:
        x,y,z = a,b,c
    else:
        d = a + max(y,z)
        e = b + max(x,z)
        f = c + max(x,y)
        x,y,z = d,e,f
print(max(x,y,z))
    

Measured memory_bytes: 91552
#include <bits/stdc++.h>
#define ll long long
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
string a; int ans;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>a;
	for(int i=0;i<a.size()-1;i++)
	if(a[i]!=a[i+1])ans++;
	printf("%d\n",ans); 
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

int main()
{
    //freopen("FORM.inp", "r", stdin);
    //freopen("FORM.out", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, k;
    cin >> n >> k;
    long long a[n+1], dp[n+1];
    for(int i = 1; i <= n; i++) cin >> a[i], dp[i] = LONG_MAX;
    dp[1] = 0;
    dp[2] = abs(a[1] - a[2]);
    for(int i = 3; i <= n; i++)
    {
        for(int j = 1; j <= k && j < i; j++)
        dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
    }
    cout << dp[n];


}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
const int maxm=1e2+10;
int a[maxn];
bool dp[maxn];
int n;
int k;
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
     cin>>n>>k;
     for(int i=0;i<n;i++){
     	cin>>a[i];
	 }
	 dp[0]=1;
	 for(int i=1;i<=k;i++){
	 	dp[i]=0;
	 	for(int j=0;j<n;j++){
	 		if(i-a[j]>=0){
	 			dp[i]|=dp[i-a[j]];
			 }
		 }
		 dp[i]^=1;
	 }
	 if(dp[k]){
	 	cout<<"Second";
	 }
	 else{
	 	cout<<"First";
	 }
	 }

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
    
using namespace std;    
typedef long long ll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){

    int n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    sort(all(v));

    ll minDiff = abs(v.back() - v[0]);
    ll minNum = v[0];
    for(int i = 0; i < n; i++){
        if(minDiff > abs( (v.back()+1 ) / 2 - v[i]) ){
            minDiff = abs( (v.back()+1) / 2 - v[i]);
            minNum = v[i];
        }
    }
    cout << v.back() << " " << minNum << endl;

}

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

int main() {
  int n,k,x,y,ans=0;
  cin >> n >> k >> x >> y;
  for (int i=0 ; i<n ;i++) {
    if (i < k) ans += x;
    else ans += y;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    long long int n,i,min,k;
    char a[300005];
    while(scanf("%lld",&n)==1)
    {
        min=0;
        scanf("%s",a);
        for(i=1;i<n;i++)
        {
            if(a[i]=='E')
                min++;
        }
        k=min;
        for(i=1;i<n;i++)
        {
            if(a[i]=='E'&&a[i-1]=='E')
                k--;
            if(a[i]=='W'&&a[i-1]=='W')
                k++;
            min=min>k?k:min;
        }
        printf("%lld\n",min);
    }
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char * argv[])
{
	unsigned int k = 0;
	unsigned int t = 0;
	while (cin >> k >> t) {
		unsigned int max = 0;
		unsigned int others = 0;
		unsigned int value = 0;
		for (unsigned int i = 0;i < t; ++i) {
			cin >> value;

			if (value > max) {
				others += max;
				max = value;
			}
			else {
				others += value;
			}
		}
		if (others > max) {
			cout << 0 << endl;
		}
		else {
			cout << max - others - 1 << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	int N;
	cin >> N;

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

	int lighton_num = 0;
	int memory;
	int push_count = 0;

	while(1){
		if(check_count[lighton_num] != 0){
			cout << -1 << endl;
			break;
		}else{
		if(lighton_num == 1){
			cout << push_count << endl;
			break;
		}else{
			memory = lighton_num;
			lighton_num = a[memory]-1;
			check_count[memory]++;
			push_count++;
		}
		}
	}
	return 0;
}



Measured memory_bytes: 1152
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define mp make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define rep(i,n) for(int i=0;i<n;i++)
#define INF (1<<30)
#define LLINF (1LL<<60)
#define MOD 998244353
#define PI 3.14159265358979
typedef long long ll;
using namespace std;

int n,m,shirube[100005]={};
vector<int> edge[100005];
bool isvisited[100005]={};//false:not visited, true:visited
queue< pair<int,int> > check;//first:num of visit edge, second:where is this from

void bfs(){
    while(!check.empty()){
        pair<int,int> t=check.front(); check.pop();
        rep(i,edge[t.first].size()){
            if(!isvisited[edge[t.first][i]]){
                check.push(mp(edge[t.first][i],t.first));
                shirube[edge[t.first][i]]=t.first;
                isvisited[edge[t.first][i]]=true;
            }
        }
    }
}

int main(){
    cin>>n>>m;
    rep(i,m){
        int a,b;
        cin>>a>>b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    check.push(mp(1,0));
    isvisited[1]=true;
    bfs();
    
    bool t=true;
    for(int i=2;i<=n;i++){
        if(shirube[i]==0) t=false;
    }
    if(!t) No;
    else{
        Yes;
        for(int i=2;i<=n;i++){
            cout<<shirube[i]<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 10804