akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl

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

    // input
    ll N;
    cin >> N;

    vector<pair<ll, ll> > A;

    FOR(i, 0, N){
        ll x, y;
        cin >> x >> y;

        A.push_back(make_pair(x, y));
    }
    sort(ALL(A));

    for(auto p : A){
        p2(p.first, p.second);
    }

    return 0;
}


Measured memory_bytes: 4944
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

ll beki(int a, int n){
    if(n == 0) return 1;
    ll ans = beki(a, n / 2);
    ans = ans * ans;
    if(n % 2 == 1) ans = ans * a;
    return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    int N;cin>>N;
    vi A(N-1); rep(i,N-1) cin >> A[i];
    vi cnt(N,0);
    rep(i,N-1) {
        cnt[A[i]-1]++;
    }
    rep(i,N) cout << cnt[i] << endl;
}

Measured memory_bytes: 4784
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define REP(i,l,r) for(int i=l;i<r;++i)
#define int long long
#ifdef DEBUG
#define dout cout
#else
std::stringstream dout;
#endif
using namespace std;
typedef pair<int,int> P;
//other libs

signed main(int argc, char * argv[]) {
	int n;
	map<int,int> mp;
	cin>>n;
	rep(i,n){
		int in;
		cin>>in;
		mp[in]++;
	}
	int ans=0;
	for(P it:mp){
		if(it.second%2)ans++;
	}
	cout<<ans<<endl;
}

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

int main() {
    int N;
    cin >> N;
    int size = pow(2, N);
    vector<int>S(size);
    for (int i = 0; i < size; ++i) {
        cin >> S[i];
    }

    multiset<int, greater<int>> se;
    for (int x: S) {
        se.insert(x);
    }

    // 貪欲でいい
    vector<int>current;
    current.reserve(size);
    current.push_back(*(se.begin()));
    se.erase(se.begin());

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < (1 << i); ++j) {
            auto iter = se.upper_bound(current[j]);
            if(iter != se.end()){
                current.push_back(*iter);
                se.erase(iter);
            } else{
                cout << "No" << "\n";
                return 0;
            }
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

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

int main(){
  int x, y;
  cin >> x >> y;
  
  for (int c = 0; c <= x; c++){
    int t = x - c;
    int foot = c*2 + t*4;
    
    if (foot == y){
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 3664
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
const ll nmax = 1e9 + 7;
const ll MOD = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  string S[N]; ll T[N];

  for (int i = 0; i < N; i++){
    cin >> S[i] >> T[i];
  }
  string X; cin >> X;

  ll ans = 0; bool flag = false;
  for (int i = 0; i < N; i++){
    if (flag == true){
      ans += T[i];
    }
    if (X == S[i]) flag = true;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
#define REP(a,b) for (int ii = a; ii <= (b); ++ii) 
#define mREP(a,b) for (int i = a; i == (b); --i)
#define mod 1e9 + 7
typedef long long ll;
using namespace std;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	/*
	　　　　　 　 _... ..._
	　　　　　 , ´⌒ ⌒ヽ
	　　　 　 ﾉｨ（ノﾉ）ﾉ）ﾉ）
	　　　 　 （（q|.ﾟ ヮﾟﾉ|ﾊ
	　　　　　　△ﾑ,8ﾑﾌつ
	　　　　　/(ﾝ_/＿ヽ＼
	　　　　 ～～i_ﾌ_ﾌ～´
	*/
	int n;
	cin >> n;
	vector<ll>a(n);
	ll temp = -1;
	bool sc = true;
	rep0(i, n - 1) {
		cin >> a[i];
	}
	rep0(j, n - 1) {
		if (temp > a[j]) {
			sc = false;
		}
		else if (temp < a[j]) {
			temp = a[j] - 1;
		}
		else {
			temp = a[j];
		}
	}
	cout << ((sc) ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 1024
n = int(input())
ac = 0
wa = 0
tle = 0
re = 0
for i in range(n):
  string = input()
  if string == 'AC':
    ac += 1
  elif string == 'WA':
    wa += 1
  elif string == 'TLE':
    tle += 1
  else:
    re += 1
print('AC x',ac)
print('WA x',wa)
print('TLE x',tle)
print('RE x',re)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 2147483600
#define long long long

int main(){
  int n;
  cin>>n;
  map<int, int> m;
  rep(i,n){
    int d;
    cin>>d;
    m[d]++;
  }
  int del=0;
  for(auto p : m){
    if(p.se>1) del+=p.se-1;
  }
  if(del%2==1) del++;
  cout<<n-del<<endl;

  return 0;
}


Measured memory_bytes: 4864
import java.util.Scanner;
public class Main{
	public static void main(String[]args){
	Scanner scan=new Scanner(System.in);
	int a=scan.nextInt();
	int b=scan.nextInt();
	int c=scan.nextInt();
	long d[][]=new long[a][b];
	long e[][]=new long[b][c];
	long ans[][]=new long[a][c];
	for(int i=0;i<a;i++) {
		for(int j=0;j<b;j++) {
			d[i][j]=scan.nextInt();
		}
	}
	for(int i=0;i<b;i++) {
		for(int j=0;j<c;j++) {
			e[i][j]=scan.nextInt();
		}
	}
	for(int i=0;i<a;i++) {
		for(int j=0;j<c;j++) {
			long C=0;
			for(int k=0;k<b;k++) {
				C+=d[i][k]*e[k][j];
			}
			ans[i][j]=C;
		}
	}for(int i=0;i<a;i++) {
		for(int j=0;j<c-1;j++) {
			System.out.print(ans[i][j]+" ");
		}
		System.out.println(ans[i][c-1]);
	}
	}
}


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

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

    vector<int> count(4,0);

    for(int i = 0; i < 6; i++){
        int a;
        cin >> a;
        a--;
        count[a]++;
    }

    int num = 0;

    for(int i = 0; i < 4; i++){
        if(count[i] == 1){
            num++;
        }
    }

    string result = "NO";
    if(num == 2) result = "YES";

    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, x int
	fmt.Scan(&n, &x)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}

	ans := 0
	for i := 1; i < n; i++ {
		for s := a[i-1] + a[i]; x < s; s = a[i-1] + a[i] {
			if a[i] != 0 {
				d := min(a[i], s-x)
				a[i] -= d
				ans += d
			} else {
				d := min(a[i-1], s-x)
				a[i-1] -= d
				ans += d
			}
		}
	}
	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 5504
n = 10 ** 2 + 1
a = {}
for x in range(1, n):
    for y in range(1, n):
        for z in range(1, n):
            f = x**2 + y ** 2 + z ** 2 + x*y + y*z + z*x
            a.setdefault(f, 0)
            a[f] += 1
N = int(input())
for i in range(1, N + 1):
    a.setdefault(i, 0)
    print(a[i])

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

int main()
{
    string S;
    cin >> S;
    if (S == "Sunny") {
        cout << "Cloudy" << endl;
    }
    else if (S == "Cloudy") {
        cout << "Rainy" << endl;
    }
    else {
        cout << "Sunny" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N, C = map(int, input().split())
f = [[0] * 100001 for _ in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    f[c-1][s-1:t] = [1] * (t-s+1)

print(max(map(sum, zip(*f))))

Measured memory_bytes: 26484
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: u128,
        a: [u128; n],
    }

    let mut cumulative_sum = vec![0u128; n as usize + 1];
    for i in 1..n + 1 {
        cumulative_sum[i as usize] = cumulative_sum[i as usize - 1] + a[i as usize - 1];
    }

    let mut ans: u128 = 0;
    for i in 0..n {
        ans += a[i as usize] * (cumulative_sum[n as usize] - cumulative_sum[i as usize + 1]);
        ans %= 1000000000 + 7;
    }

    println!("{}", ans);
}


Measured memory_bytes: 10372
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();
		int[] d = new int[n];
		for (int i = 0; i < n; i++)
			d[i] = in.nextInt();
		System.out.println(solve(n, d));
		in.close();
	}

	private static long solve(int n, int[] d) {
		if (d[0] != 0)
			return 0;
		Arrays.sort(d);
		if (d[1] != 1)
			return 0;
		int[] c = new int[n + 1];
		for (int i = 1; i < n; i++) {
			if (d[i] - d[i - 1] <= 1)
				c[d[i]]++;
			else
				return 0;
		}
		long r = 1;
		for (int i = 2; c[i] > 0; i++) {
			r *= pow(c[i - 1], c[i]);
			r %= 998244353;
		}
		return r;
	}

	private static long pow(int x, int e) {
		long r = 1;
		for (int i = 0; i < e; i++) {
			r *= x;
			r %= 998244353;
		}
		return r;
	}
}

Measured memory_bytes: 50492
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  string s; cin >> s;
  sort(all(s));

  cout << (s == "abc" ? "Yes" : "No") << endl;

  return 0;
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);


int main()
{
    int i = 0, j = 0, cs = 0, in;
    speed;
    ll n, k; cin>>n>>k;
    vll p(n), c(n);
    for(i = 0; i < n; i++){
        cin>>p[i];
        p[i]--;
    }
    for(i = 0; i < n; i++) cin>>c[i];
    ll ans = -LLONG_MAX;
    for(i = 0; i < n; i++){
        vll vis(n,-1), val(n,0);
        ll sum = 0, moves = 0, cur = i, x = -LLONG_MAX;
        while(moves < k && vis[cur] == -1){
            vis[cur] = moves, val[cur] = sum;
            moves++, sum += c[ p[cur] ], cur = p[cur];
            x = max(x, sum);
        }
        if(moves < k && sum - val[ cur ] > 0){
            ll y = (k - moves) / (moves-vis[cur]);
            sum += (y-1)*(sum-val[cur]);
            moves += (y-1)*(moves-vis[cur]);
        }
        x = max(x,sum);
        int inter = cur, f = 0;
        while(moves < k && f < 2){
            moves++, sum += c[ p[cur] ], cur = p[cur];
            x = max(x, sum);
            if(cur == inter) f++;
        }
        ans = max(ans,x);
    }
    cout << ans << endl;
    return 0;
}


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


#define MOD 1000000007

int N;
string s;
int memo[5001][5001];
int comb[5001][5001];
int pow2[5001];

int f(int n, int s, bool a) {
  if (a && memo[n][s] != -1) return memo[n][s];
  if (n == 0 && s != 0) return 0;
  if (n == 0 || n == s) return 1;
  if (n < s) return 0;
  int c = 0;
  if ((n-s) % 2 == 0) {
    int b = (n-s) / 2;
    c += (1LL * pow2[b] * comb[n][b]) % MOD;
  }
  if (a) {
    for (int i=1; i<=n; i+=2) {
      c += (1LL * f(i-1, 0, false) * f(n-i, s, true)) % MOD;
      c %= MOD;
    }
  }
  if (a) memo[n][s] = c;
  return c;
}

signed main() {
  cin >> N >> s;
  pow2[0] = 1;
  for (int i=1; i<=N; i++) {
    pow2[i] = (pow2[i-1] * 2) % MOD;
  }
  comb[0][0] = 1;
  for (int i=1; i<=N; i++) {
    comb[i][0] = 1;
    for (int j=1; j<=i; j++) {
      comb[i][j] = ((j>i-j?0:comb[i-1][j-1]) + comb[i-1][j]) % MOD;
    }
  }

  for (int i=0; i<=N; i++) {
    for (int j=0; j<=s.length(); j++) {
      memo[i][j] = -1;
    }
  }
  cout << f(N, s.length(), true) << "\n";
  return 0;
}


Measured memory_bytes: 194176
sx, sy, tx, ty = map(int, input().split())
vertical = ty - sy
side =  tx - sx
cycle1 = "U" * vertical + "R" * side + "D" * vertical + "L" * side
cycle2 = "L" + "U" * (vertical + 1) + "R" * (side + 1) + "D" + "R" + "D" * (vertical + 1) + "L" * (side + 1) + "U"
print(cycle1 + cycle2) 

Measured memory_bytes: 9148
package main

import (
	"bytes"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	if false {
		test()
	} else {
		solve(os.Stdin, os.Stdout)
	}
}

func solve(r io.Reader, w io.Writer) {
	var n int // number of participants
	var m int // number of languages
	fmt.Fscanln(r, &n, &m)
	// planet: paticipant -> lang -> bool
	planet := make(map[int]map[int]bool)
	for i := 0; i < n; i++ {
		planet[i] = make(map[int]bool)
		var langs int
		fmt.Fscan(r, &langs)
		for j := 0; j < langs; j++ {
			var lang int
			fmt.Fscan(r, &lang)
			planet[i][lang-1] = true
		}
	}

	if communicatable(planet, n, m) {
		fmt.Fprintln(w, "YES")
	} else {
		fmt.Fprintln(w, "NO")
	}
}

func communicatable(planet map[int]map[int]bool, n, m int) bool {
	g := make(map[int][]int)
	for p, langs := range planet {
		g[p] = make([]int, 0, len(langs))
		for l := range langs {
			langi := n + l
			g[p] = append(g[p], langi)
			g[langi] = append(g[langi], p)
		}
	}

	seen := make([]bool, n+m)
	q := []int{0}
	for len(q) > 0 {
		v := q[0]
		q = q[1:]
		if !seen[v] {
			seen[v] = true
			q = append(q, g[v]...)
		}
	}

	for i := 0; i < n; i++ {
		if !seen[i] {
			return false
		}
	}
	return true
}

func test() {
	tests := []struct {
		in   string
		want string
	}{
		{
			in: `4 6
3 1 2 3
2 4 2
2 4 6
1 6`,
			want: `YES
`,
		},
		{
			in: `4 4
2 1 2
2 1 2
1 3
2 4 3`,
			want: `NO
`,
		},
	}
	for i, tt := range tests {
		fmt.Printf("=== TEST %d\n", i)
		buf := new(bytes.Buffer)
		solve(strings.NewReader(tt.in), buf)
		if got := buf.String(); got != tt.want {
			fmt.Printf("%d: got %v, want %v\n", i, got, tt.want)
		}
	}
}


Measured memory_bytes: 45184
n=int(input())
path_color=[None]*(n-1)
tree_path=[[] for x in range(n)]
path_num_to_edges=[]
tree_edge_flag=set()
for i in range(n-1):
    ai,bi=[int(x) -1 for x in input().split()]
    tree_path[ai].append((bi,i))
    tree_path[bi].append((ai,i))
    path_num_to_edges.append((ai,bi))

path_color[0]=1
from collections import deque
d=deque()
for i in path_num_to_edges[0]:
    d.append(i)
while d:
    temp_edge=d.pop()
    if temp_edge in tree_edge_flag:
        continue
    tree_edge_flag.add(temp_edge)
    new_path_color=1
    for other_edge,path_num in tree_path[temp_edge]:
        if path_color[path_num]!=None:
            old_color=path_color[path_num]
            break
    for other_edge,path_num in tree_path[temp_edge]:
        if path_color[path_num]!=None:
            continue
        if new_path_color==old_color:
            new_path_color+=1
        path_color[path_num]=new_path_color
        new_path_color+=1
        d.append(other_edge)

print(max(path_color))
for i in path_color:
    print(i)

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

using namespace std;

#define PB push_back
#define f first
#define s second
#define what_is(x) cerr << #x << " is " << x << endl;

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

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    ll arr[n];
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    ll ct[n];
    ct[n-1] = 1;
    for(int i=0; i<n-1; i++)
    {
        ct[i] = 2;
    }
    sort(arr, arr+n);
    int st = n-1;
    int tot = n-1;
    ll ans = 0;
    while(tot--)
    {
        ans += arr[st];
        ct[st]--;
        if(ct[st] == 0)
            st--;
    }
    cout << ans;
    return 0;
}


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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
#define mp make_pair

int b[30],a[30][30];

int main(){
  int n,m,c;
  cin >> n >> m >> c;
  REP(i,m) cin >> b[i];
  REP(i,n) REP(j,m) cin >> a[i][j];
  int ans = 0;
  REP(i,n) {
    int k = c;
    REP(j,m) {
      k += a[i][j] * b[j];
    }
    ans += k > 0;
  }
  cout << ans <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>





using namespace std;





int main() 
{
    int i, a, b, c, n;
    cin >> a >> b >> c;
    n = 0;
     
     for( int i = a; i<= b; i++)
   {
     if (c % i == 0)
     n++;
    
   }
   cout << n << endl;
}


Measured memory_bytes: 3116
a, b, c = map(int , input().split())

yakusu = []

for i in range(1, c//2+1):
    if c%i == 0:
        yakusu.append(i)

yakusu.append(c)

cnt = 0
for i in range(len(yakusu)):
    x = yakusu[i]
    if a <= x and x <= b:
        cnt += 1

print(cnt)



Measured memory_bytes: 5600
import java.util.Scanner;

public class Main{

  static int[] parent;
  static int[] size;
  static int N,M;
  static int[] A,B;
  static long count;
  static long[] ans;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    M = sc.nextInt();
    A = new int[M];
    B = new int[M];
    ans = new long[M];
    for(int i=0;i<M;i++){
      A[i]=sc.nextInt();
      B[i]=sc.nextInt();
    }
    UnionFindTree(N);
    ans[0]=(long)N*(N-1)/2;
    for(int i=M-1;i>=1;i--){
      if (!same(A[i], B[i])) count+=(long)size[find(A[i])]*size[find(B[i])];
      ans[i] = count;
      union(A[i],B[i]);
    }
    if (M >= 2) {
      for(int j=1;j<M;j++){
        System.out.println((long)N*(N-1)/2-ans[j]);
      }
    }
    System.out.println((long)N*(N-1)/2);
  }

  static void UnionFindTree(int Size) {
    parent = new int[Size+1];
    size = new int[Size+1];

    for (int i = 1; i < Size+1; i++) {
      makeSet(i);
    }
  }

  public static void makeSet(int x) {
    parent[x] = x;
    size[x] = 1;
  }


  public static void union(int x, int y) {
    if(x==y){}
    else{
      final int xRoot = find(x);
      final int yRoot = find(y);


      if (xRoot != yRoot) {
        parent[yRoot] = xRoot;
        size[xRoot]+=size[yRoot];

      }
    }
  }


  public static int find(int x) {
    if (x != parent[x]) {
      parent[x] = find(parent[x]);
    }
    return parent[x];
  }


  public static boolean same(int x, int y) {
    return find(x) == find(y);
  }
}


Measured memory_bytes: 92900
#include<stdio.h>
int main()
{
  int x,a,b,c,i,j,k,n=0,sum;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);
  scanf("%d",&x);
  for(i=0;i<=a;i++)
    for(j=0;j<=b;j++)
      for(k=0;k<=c;k++){
        sum=500*i+100*j+50*k;
        if(sum==x)
          n++;
      }
  printf("%d",n);
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
namespace AtCoder
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }

        static readonly long Mod = 1000000000 + 7;
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var s = ReadLine();
            var from = new long[N];
            for (var i = 0; i < N; ++i)
                from[i] = 1;
            //i個目まで決まっているとする。このとき、i個目に残りN-(i-1)個からm番目のものを選んだとする
            for (var i = 0; i < N - 1; ++i)
            {
                //[0,i)個
                var sum = new long[N + 1];
                for (var k = 1; k <= N - i; ++k)
                    sum[k] = sum[k - 1] + from[k - 1];
                var to = new long[N];
                for (var m = 0; m < N - i; ++m)
                {
                    if (s[i] == '<')
                        to[m] = (to[m] + sum[m + 1]) % Mod;
                    else
                        to[m] = (to[m] + sum[N - i] - sum[m + 1] + Mod) % Mod;
                }
                from = to;
            }
            WriteLine(from[0]);
        }
    }
}

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

int n, t, h[1000];
double ta[1000] = {}, a;
pair<double, int> mu = {};

int main(){
	cin >> n >> t >> a;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
		ta[i] = max(a, t - h[i] * 0.006) - min(a, t - h[i] * 0.006);
	}
	mu.first = ta[0];
	mu.second = 1;
	for (int i = 1; i < n; i++) {
		if (mu.first > ta[i]) {
			mu.first = ta[i];
			mu.second = i + 1;
		}
	}
	cout << mu.second << endl;
	return 0;
}

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

#include <iostream>
#include <algorithm>

#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <cstring>
#include <string>
#include <utility>
#include <array>
#include <complex>
#include <valarray>

#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <chrono>
#include <random>
#include <numeric>


using namespace std;
#define int long long

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const double EPS = 1e-12;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod
#define inside(y, x, h, w) (0 <= (y) && (y) < (h) && 0 <= (x) && (x) < (w)) ? true : false

string a;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a;
    if (a[0] == a[1] && a[1] == a[2]) {
        cout << "Yes" << endl;
    }
    else if (a[1] == a[2] && a[2] == a[3]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int A, B;
  while (cin >> A >> B) {
    int res = (1 ^ 2 ^ 3) ^ A ^ B;
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().doIt();
	}
	void doIt() {
		solveA();
	}
	void solveA() {
		int N = sc.nextInt();
		String ans = "Christmas";
		for(int i = N; i < 25; i++) {
			ans += " Eve";
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 20820
N, A, B = map(int, input().split())
s = input()
 
x, y = 0, 0
for i, p in enumerate(s):
    if p=="a":
        if x < A+B:
            print("Yes")
            x+=1
        else:
            print("No")
    elif p=="b":
        if x < A+B and y < B:
            print("Yes")
            x+=1
            y+=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4016
#include <cstdio>
#include <cstring>

using namespace std;
const int MOD(1000000007);
const int Max_N(20);
const int Max_M(25);
typedef long long int LL;

constexpr int Mult(int a, int b)
{
	return a * 1LL * b % MOD;
}

constexpr int Add(int a, int b)
{
	return a + b >= MOD ? a + b - MOD : a + b;
}

constexpr int Sub(int a, int b)
{
	return a - b < 0 ? a - b + MOD : a - b;
}

inline int lowbit(int x)
{
	return x & -x;
}

/*
按照编号从小到大的顺序考虑每条路径，每条路径必须在上一条路径的右边。设F[i][S]表示考虑到第i条路径，第i条路径是S的方案数
转移考虑第i + 1条的路径是什么。设第i条路径是S1，第i + 1条路径是S2，需要满足对于任意前缀，S1的1的个数 <= S2的1的个数
这个条件等价于：每一个S1中的1都可以找到S2中在其位置之前的1匹配。可以理解成hall定理的逆命题 
考虑dp这个过程，设G[h][S]表示考虑到第h层，S2[1 ~ h] = S[1 ~ h]，S1[h + 1 ~ N]中没被匹配的1 = S[h + 1 ~ N]
每次转移考虑S2[h + 1]是什么。分情况讨论：
(1)S2[h + 1] = 0，需要保证S1中不能有无法被匹配的1
(2)S2[h + 1] = 1，那么贪心把S1中没有被匹配的最靠前的1与其匹配
G直接转移即可，F的转移也就很方便了
*/

int N, M, K, F[1 << (Max_N - 1)], G[2][1 << (Max_N - 1)], X[Max_M][Max_N];

int main()
{
	scanf("%d%d%d", &N, &M, &K), --N, memset(X, -1, sizeof(X));
	for (int a, b;K--;)
		scanf("%d%d", &a, &b), scanf("%d", &X[a][b - 1]);
	F[0] = 1;
	for (int i = 1;i <= M;++i)
	{
		memset(G[1], 0, sizeof(G[1]));
		for (int S = 0;S < (1 << N);++S)
			G[1][S] = F[S];
		for (int b = 0, now = 1, lst = 0;b <= N - 1;++b)
		{
			now ^= 1, lst ^= 1, memset(G[now], 0, sizeof(G[now]));
			for (int S = 0, S0;S < (1 << N);++S)
				for (int c = 0;c <= 1;++c)
				{
					if (X[i][b] != -1 && X[i][b] != c)
						continue;
					S0 = S;
					if (c)
						S0 = S0 - lowbit(S0 - (S0 & ((1 << b) - 1)));
					if (S0 & (1 << b))
						continue;
					S0 |= (c * (1 << b));
					G[now][S0] = Add(G[now][S0], G[lst][S]);
				}
		}
		for (int S = 0;S < (1 << N);++S)
			F[S] = G[(N - 1) & 1][S];
	}
	int Ans(0);
	for (int S = 0;S < (1 << N);++S)
		Ans = Add(Ans, F[S]);
	printf("%d", Ans);
	return 0;
}

Measured memory_bytes: 6400
var b=[String:Int]()
for _ in 0..<Int(readLine()!)!{
    let s=readLine()!
    b[s]=(b[s] ?? 0)+1
}
var r=[String:Int]()
for _ in 0..<Int(readLine()!)!{
    let t=readLine()!
    r[t]=(r[t] ?? 0)+1
}
var ans=0
for (s,_) in b{
    ans=max(b[s]!-(r[s] ?? 0),ans)
}
print(ans)

Measured memory_bytes: 5872
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <string>

using namespace std;

#define N 3
#define N2 9

const int dx[4] { -1, 0, 1, 0 };
const int dy[4] { 0, -1, 0, 1 };
const char dir[4] { 'u', 'l', 'd', 'r' };

struct Puzzle {
	int f[N2], space;
	string path;
	bool operator <(const Puzzle p) const {
		for (int i = 0; i < N2; ++i) {
			if (f[i] == p.f[i])
				continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};

bool isResolved(Puzzle p) {
	for (int i = 0; i < N2; ++i) {
		if (p.f[i] != i + 1)
			return false;
	}
	return true;
}

string bfs(Puzzle p) {
	queue<Puzzle> Q;
	p.path = "";
	Q.push(p);
	map<Puzzle, bool> M;
	M[p] = true;
	Puzzle u, v;
	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (isResolved(u))
			return u.path;
		int sx = u.space / N;
		int sy = u.space % N;
		for (int r = 0; r < 4; ++r) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)
				continue;
			v = u;
			swap(v.f[u.space], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if (!M[v]) {
				M[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "";
}

int main() {
	Puzzle p;
	for (int i = 0; i < N2; ++i) {
		scanf("%d", &p.f[i]);
		if (p.f[i] == 0) {
			p.f[i] = N2;
			p.space = i;
		}
	}
	string ans = bfs(p);
	cout << ans.size() << endl;

	return 0;
}

Measured memory_bytes: 30620
#include <iostream>
#include <cmath>
#define NMAX 100000
#define inf 2000000000

using namespace std;

int n, k, v[NMAX+10], dp[NMAX+10];

int main()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> v[i], dp[i] = inf;
    dp[1] = 0;
    for(int i=2; i<=n; i++)
        for(int j=i-1; j>=max(1, i-k); j--) dp[i] = min(dp[i], dp[j] + (int)abs(v[i] - v[j]));
    cout << dp[n] << '\n';
    return 0;
}


Measured memory_bytes: 1024
n = int(input())

def fib_loop(n):
	F = [-1] * (n + 1)
	F[0], F[1] = 1, 1
	for i in range(2, n + 1):
		F[i] = F[i - 1] + F[i - 2]
	return F[n]

print(fib_loop(n))


Measured memory_bytes: 5600
#include<iostream>
using namespace std;
int main(){
int W,H,x,y,r;
cin>>W>>H>>x>>y>>r;
if((x-r)>=0 && (x+r)<=W && (y-r)>=0 && (y+r)<=H){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}}

Measured memory_bytes: 1160
N=int(input())
Students=list(map(int,input().split()))


d={}

for i in range(N):
    d[i+1]=Students[i]

d_2 = sorted(d.items(),key=lambda x: x[1])

ans=[]
for k in d_2:
    ans.append(k[0])

print(*ans)

Measured memory_bytes: 27064
import java.io.InputStream;
import java.io.PrintStream;
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int n = Integer.parseInt(sc.next());
    BigInteger border = BigInteger.valueOf(10).pow(18);
    long a[] = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = Long.parseLong(sc.next());
      if (a[i] == 0) {
        pw.println(0);
        return;
      }
    }
    BigInteger ans = BigInteger.valueOf(1);
    for (int i = 0; i < n; i++) {
      ans = ans.multiply(BigInteger.valueOf(a[i]));
      if (ans.compareTo(border) > 0) {
        pw.println(-1);
        return;
      }
    }
    pw.println(ans);
  }
}


Measured memory_bytes: 59184
import java.util.Scanner;
import java.util.Arrays;
class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		final int cnt = scan.nextInt();
		
		for(int i = 0; i < cnt; i++) {
			Integer[] tri = new Integer[3];
			
			tri[0] = scan.nextInt();
			tri[1] = scan.nextInt();
			tri[2] = scan.nextInt();
			
			Arrays.sort(tri);
			
			tri[0] *= tri[0];
			tri[1] *= tri[1];
			tri[2] *= tri[2];
			
			if((tri[0] + tri[1]) == tri[2]) {
				System.out.println("YES");
			}
			
			else {
				System.out.println("NO");
			}
		}
	}
	
}

Measured memory_bytes: 23348
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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


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

    int N, m; cin >> N >> m;
    vector<int> check(N + 1, true);
    rep(i, m) {
        int a; cin >> a;
        check[a] = false;
    }

    vector<ll> dp(N + 1);
    dp[0] = 1;
    for(int now = 0; now < N; now++) {
        for(int next = now + 1; next <= min(N, now + 2); next++){
            if(check[next]){
                dp[next] += dp[now];
                dp[next] %= MOD;
            }
        }
    }

    COUT(dp[N]);
}

Measured memory_bytes: 1408
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
//typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1,1,1,-1,-1};
int dy[]={1,0,-1,0,1,-1,1,-1};
int main(){
	int n;cin>>n;
	string s;cin>>s;
	auto it=s.find("xx");
	if(it+1)cout<<it+1<<endl;
	else cout<<n<<endl;
}













Measured memory_bytes: 3344
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)x.size()
#define f first
#define s second
#define MAXN 710

ll fw[MAXN];

int M[MAXN][MAXN];
int N,E,a,b;
int L;
vi A,B;
bool D[MAXN];
int leftsize = 0;
int rightsize = 0;
vi V;
void solve(int x){
	cout<<x*(x-1)/2+(N-x)*(N-x-1)/2;
	exit(0);
}
int k[MAXN*2][2];

int main(){
	cin>>N>>E;
	L=N;
	for (int i=0;i<E;++i){
		cin>>a>>b;
		M[a][b] = M[b][a] = 1;
	}
	while(SZ(A) + SZ(B) < N){
		if(SZ(A) == 0){
			for (int i=1;i<=N;++i)if (!D[i]){
				for (int j=1;j<=N;++j)if(!D[j] && i!=j){
					if (!M[i][j]){
						A.pb(i);
						B.pb(j);
						D[i] = D[j] = 1;
						break;
					}
				}
				if(SZ(A))break;
			}
			if(SZ(A))L-=2;
		}
		if (SZ(A) == 0){
			for (int i=0;i<L;++i)V.pb(1);
			break;
		}
		int T = SZ(A) + SZ(B);
		for (int i=1;i<=N;++i)if (!D[i]){
			// cout<<"Try "<<i<<'\n';
			// Check if can insert into left
			bool canleft = 1;
			bool canright = 1;
			for (auto x:A)if (!M[i][x])canleft=0;
			for (auto x:B)if (!M[i][x])canright=0;
			if (!canleft && !canright){
				cout<<-1;
				return 0;
			}
			if (canleft && canright){
				continue;
			}
			if (canleft && !canright){
				D[i]=1;
				A.pb(i);
				break;
			}
			if(canright && !canleft){
				D[i]=1;
				B.pb(i);
				break;
			}
			assert(0);
		}
		if(SZ(A) + SZ(B) == T){
			// Nothing was added
			V.pb(abs(SZ(A) - SZ(B)));
			A.clear();
			B.clear();
		}else L--;
	}
	if(SZ(A))V.pb(abs(SZ(A) - SZ(B)));
	// for(auto i:V)cout<<i<<' ';cout<<'\n';
	// return 0;
	k[MAXN][1] = 1;
	for (int i=0;i<SZ(V);++i){
		int t=V[i];
		for (int j=0;j<2*MAXN;++j){
			k[j][i%2]=0;
			int cur = j-t;
			if(cur>0) if (k[cur][1-i%2])k[j][i%2] = 1;
			cur = j+t;
			if(cur<2*MAXN)if(k[cur][1-i%2])k[j][i%2] = 1;
		}
		// for (int j=-10;j<=10;++j)cout<<k[j+MAXN][i%2]<<' ';cout<<'\n';
	}
	int mindist = MAXN;
	for (int i=0;i<2*MAXN;++i){
		if (k[i][1-SZ(V)%2])mindist = min(mindist, abs(i-MAXN));
	}
	// cout<<N<<' '<<mindist<<' ';
	solve((N-mindist)/2);
}

Measured memory_bytes: 2176
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int x = in.nextInt();
        int ans = 0;
        while (x >= 500) {
            x -= 500;
            ans += 1000;
        }
        while (x >= 5) {
            x -= 5;
            ans += 5;
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>

int main(){
  int H, N;
  scanf("%d",&H);
  scanf("%d",&N);
  std::vector<int > A(N), B(N);
  for (int i=0; i<N; i++){
    scanf("%d",&A[i]);
    scanf("%d",&B[i]);
  }
  std::vector<std::vector<int > > dp(N+1, std::vector<int > (H+1, 200000000));
  dp[0][0] = 0;
  for (int i=1; i<=N; i++){
    //printf("i=%d\n",i);
    dp[i][0]=0;
    for (int j=1; j<=H; j++){
      //printf("j=%d\n",j);
      if (j<A[i-1]){
        dp[i][j] = B[i-1]*((j+A[i-1]-1)/A[i-1]);
        //printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
      } else {
        dp[i][j] = std::min(dp[i-1][j-A[i-1]]+B[i-1], B[i-1]*((j+A[i-1]-1)/A[i-1]));
        dp[i][j] = std::min(dp[i][j-A[i-1]]+B[i-1], dp[i][j]);
        //printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
      }
      dp[i][j] = std::min(dp[i][j], dp[i-1][j]);
    }
  }
  /*for (int i=0; i<=N; i++){
    for (int j=0; j<=H; j++){
      std::cout << dp[i][j] << " ";
    }
    std::cout << std::endl;
    }*/
  //  printf("N=%d, H=%d\n",N,H);
  printf("%d\n",dp[N][H]);
  return 0;
}


Measured memory_bytes: 41344
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.IO;
using System.Text;
using System.Diagnostics;

class Program
{
    static void Main()
    {
        string s = Console.ReadLine();
        string target = "";
        foreach (char p in new char[] { '+', '-'})
        {
            foreach (char q in new char[] { '+', '-' })
            {
                foreach (char r in new char[] { '+', '-' })
                {
                    target = s[0].ToString() + p.ToString() + s[1].ToString() + q.ToString() + s[2].ToString() + r.ToString() + s[3].ToString();
                    if(Calc(target) == 7)
                    {
                        Console.WriteLine(target + "=7");
                        return;
                    }
                }
            }
        }
    }

    static public int Calc(string s)
    {
        int ans = int.Parse(s[0].ToString());
        for(int i = 0; i < s.Length / 2; i++)
        {
            if(s[2 * i + 1] == '+')
            {
                ans += int.Parse(s[2 * (i + 1)].ToString());
            }
            else
            {
                ans -= int.Parse(s[2 * (i + 1)].ToString());
            }
        }
        return ans;
    }
}

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

const double EPS = 1e-8;
const double INF = 1e12;

//point
typedef complex<double> P;
namespace std {
	bool operator < (const P& a, const P& b) {
		return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
	}
}
double cross(const P& a, const P& b) {
	return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
	return real(conj(a)*b);
}
// line
struct L : public vector<P> {
	L(const P& a, const P& b) {
		push_back(a); push_back(b);
	}
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;								  // a--c--b on line
}

bool intersectLL(const L &l, const L &m) {
  return abs(cross(l[1]-l[0], m[1]-m[0])) > EPS || // non-parallel
         abs(cross(l[1]-l[0], m[0]-l[0])) < EPS;   // same line
}
bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}
bool intersectLP(const L &l, const P &p) {
  return abs(cross(l[1]-p, l[0]-p)) < EPS;
}
bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

P projection(const L &l, const P &p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}
P reflection(const L &l, const P &p) {
	return p + (double)2 * (projection(l, p) - p);
}
double distanceLP(const L &l, const P &p) {
	return abs(p - projection(l, p));
}
double distanceLL(const L &l, const L &m) {
	return intersectLL(l, m) ? 0 : distanceLP(l, m[0]);
}
double distanceLS(const L &l, const L &s) {
	if (intersectLS(l, s)) return 0;
	return min(distanceLP(l, s[0]), distanceLP(l, s[1]));
}
double distanceSP(const L &s, const P &p) {
	const P r = projection(s, p);
	if (intersectSP(s, r)) return abs(r - p);
	return min(abs(s[0] - p), abs(s[1] - p));
}
double distanceSS(const L &s, const L &t) {
	if (intersectSS(s, t)) return 0;
		return min({distanceSP(s, t[0]), distanceSP(s, t[1]), distanceSP(t, s[0]), distanceSP(t, s[1])});
}
P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

int main() {
	int q;
	cin >> q;
	for(int i=0; i<q; ++i) {
		double x[4], y[4];
		for(int j=0; j<4; ++j) cin >> x[j] >> y[j];
		L l1(P{x[0], y[0]}, P{x[1], y[1]}), l2(P{x[2], y[2]}, P{x[3], y[3]}); 
		if(intersectSS(l1, l2)) cout << 1 << endl;
		else cout << 0 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3280
using System;
using System.Linq;

class U
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n].Select(_ => Console.ReadLine().Split().Select(int.Parse).ToArray()).ToArray();
		var p2 = Enumerable.Range(0, n + 1).Select(i => 1 << i).ToArray();

		var s = new long[p2[n]];
		for (int i = 0; i < n; i++)
			for (int j = i + 1; j < n; j++)
				for (int f = 0; f < p2[n]; f++)
					if ((f & p2[i]) > 0 && (f & p2[j]) > 0)
						s[f] += a[i][j];

		var dp = (long[])s.Clone();
		for (int f = 0; f < p2[n]; f++)
			for (int g = f; g > 0; g = f & (g - 1))
				dp[f] = Math.Max(dp[f], dp[f - g] + s[g]);
		Console.WriteLine(dp[p2[n] - 1]);
	}
}


Measured memory_bytes: 14304
import sys
sys.setrecursionlimit(10000000)
MOD = 998244353
INF = 10 ** 18

import numpy as np
def main():
    N,S = map(int,input().split())
    A = list(map(int,input().split()))
    
    before = np.zeros(S + 1,np.int64)
    before[0] = 1
    ans = 0
    for a in A:
        now = np.zeros(S + 1,np.int64)
        now += before
        now[a:] += before[:-a]
        ans += now[S]
        ans %= MOD
        now[0] += 1
        now = np.mod(now,MOD)
        before = now
    print(ans)
if __name__ == '__main__':
    main()



Measured memory_bytes: 14412
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define all(v) v.begin(), v.end()
bool chmin(ll & a, ll  b) { if (b < a) { a = b; return 1; } return 0; }
bool chmax(ll & a, ll b) { if (b > a) { a = b; return 1; } return 0; }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
const ll MAX_N=500010;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans;
    vector<pair<vl,ll>> A;
int main() {
    cin>>n;

    A.push_back({{0},1});

    rep(i,n-1){
        vector<pair<vl,ll>> B;
        for(pair<vl,ll> t:A){
            x=t.second;
            rep(j,x+1){
                vl C=t.first;
                C.push_back(j);
                B.push_back({C,max(x,j+1)});
            }
        }
        A=B;
    }

    rep(i,A.size()){
        rep(j,n){
            cout<<(char('a'+(A[i].first)[j]));
        }
        cout<<endl;
    }

}

Measured memory_bytes: 31960
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {

	static Scanner scan = new Scanner(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {
		int w = si(), n = si();
		int[] ary = new int[w];
		for (int i = 0; i < w; i++)
			ary[i]=i+1;
		for (int i = 0; i < n; i++) {
			String[] cons = scan.next().split(",");
			int p = Integer.parseInt(cons[0])-1, q = Integer.parseInt(cons[1])-1;
			int tmp = ary[p];
			ary[p] = ary[q];
			ary[q] = tmp;
		}
		for (int i = 0; i < w ; i++)
			out.println(ary[i]);
		out.flush();
	}

	static int si() {
		return Integer.parseInt(scan.next());
	}
}

Measured memory_bytes: 15352