akhauriyash/Code-Regression huggingface dataset:
n, m, x, y = map(int, input().split())
lx = list(map(int, input().split()))
ly = list(map(int, input().split()))
lx.append(x)
ly.append(y)
lx.sort()
ly.sort()

if lx[-1] < ly[0]:
        print('No War')
else:
    print('War')

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
int N,M;
int D[100100],pos[100100];
vector<int> g[200100];
queue<int> q;
int root;
int d[100100];
int used[100100];
ll rec(int v){
	if(sz(g[v])==0){
		if(used[v]!=-1){
			if(d[used[v]]==1)return 0ll;
			else return 100000ll;
		}else{
			return 1ll;
		}
	}else{
		ll sum = 0,mx = -1;;
		for(int i=0;i<3;i++){
			ll r = rec(g[v][i]);
			sum += r;
			mx = max(mx,r);
		}
		return sum-mx;
	}
}
bool check(int x){
	int cnt = 0;
	for(int i=0;i<N;i++){
		if(D[i]>=x){
			d[i]=1;
			if(i>=M)cnt++;
		}else d[i]=0;
	}
	ll req = rec(root);
	return req <= cnt;
}
int main(){
	scanf("%d %d",&N,&M);
	memset(used,-1,sizeof(used));
	for(int i=0;i<N;i++){
		if(i<M){
			scanf("%d %d",&D[i],&pos[i]);
			pos[i]--;
			used[pos[i]]=i;
		}else{
			scanf("%d",&D[i]);
		}
	}
	for(int i=0;i<N;i++)q.push(i);
	int cnt = N;
	while(q.size()>2){
		for(int i=0;i<3;i++){
			int f = q.front();
			q.pop();
			g[cnt].pb(f);
		}
		q.push(cnt++);
	}
	root = cnt-1;
	int l = 0,r = INF;
	while(r-l>1){
		int mid = (l+r)/2;
		if(check(mid))l = mid;
		else r = mid;
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 9064
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;

int main(){
	string N;
	cin>>N;
	int number = atoi(N.c_str());
	string hundred_st = N.substr(0, 1);
	string ten_st = N.substr(1, 1);
	string one_st = N.substr(2, 1);
	int hundred = atoi(hundred_st.c_str());
	int ten = atoi(ten_st.c_str());
	int one = atoi(one_st.c_str());
	
	int result;
	int sanka = hundred*111;
	if(number <= sanka){
		result = sanka;
	}	else{
		result = (hundred + 1)*111;
	}
	cout<<result;
	return 0;
}


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

int main() {
    int64_t N,M,K;
    cin >> N >> M >> K;
    
    vector<int64_t> A(N),B(M);
    for ( int64_t i = 0; i < N; ++i){
        cin >> A[i];
    }
    for ( int64_t i = 0; i < M; ++i){
        cin >> B[i];
    }
    
    int64_t totaltime = 0;
    int64_t Bnum = 0;
    for ( int64_t i = 0; i < N; ++i){
        if ( totaltime + A[i] > K ) break;
        totaltime = totaltime + A[i];
        Bnum = Bnum + 1;
    }
    
    int64_t maxBnum = Bnum;
    int64_t Mini = 0;
    for ( int64_t i = Bnum-1; i >= 0; --i){
        for ( int64_t j = Mini; j < M; ++j){
            if ( totaltime + B[j] > K ) {
                Mini = j;
                break;
            }
            totaltime = totaltime + B[j];
            Bnum = Bnum + 1;
        }
        //maxBnum = max(maxBnum,Bnum);
        if ( Bnum > maxBnum ) maxBnum = Bnum;
        Bnum = Bnum - 1;
        totaltime = totaltime - A[i];
    }
    for ( int64_t j = Mini; j < M; ++j){
        if ( totaltime + B[j] > K ) {
            Mini = j;
            break;
        }
        totaltime = totaltime + B[j];
        Bnum = Bnum + 1;
    }
    //maxBnum = max(maxBnum,Bnum);
    if ( Bnum > maxBnum ) maxBnum = Bnum;
    
    cout << maxBnum << endl;
    
    return 0;
}

Measured memory_bytes: 6360
#ifdef _DEBUG
#define _CRT_SECURE_NO_WARNINGS
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define MGN 8
#define LINF (LONG_MAX/2)
using namespace std;
typedef long long ll; typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vvi;
typedef vector<ll> vl; typedef vector<vl> vvl;
typedef vector<double> vd; typedef vector<string> vs;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
typedef vector<bool> vb; typedef vector<vb> vvb;
template <typename T>
using keyVal = pair<string, T>;
template<typename T>
bool val_greater(const keyVal<T>& left, const keyVal<T>& right) {
    return left.second > right.second;
}
vs split(string str, char sep) {
    vs v; stringstream ss(str); string t;
    while (getline(ss, t, sep)) v.push_back(t);
    return v;}
vs re_search_g(string s, regex re) {
    vs ret; smatch mc; auto it = s.cbegin();
    while (regex_search(it, s.cend(), mc, re)) {
        ret.push_back(mc[0]);
        it += mc.position(0) + mc.length();}
    return ret;}
#endif

void init_global_C() {}

int main_C() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N; cin >> N;
    vi s(N); REP(i, N) cin >> s[i];

    vi o;
    int sum = 0;
    REP(i,N){
        sum += s[i];
        if (s[i] % 10 != 0) o.push_back(s[i]);
    }

    sort(o.begin(), o.end());

    if (sum % 10 == 0) {
        if (o.size() > 0) sum -= o[0];
        else sum = 0;
    }

    int ans = sum;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
def factorization(n):
    arr = []
    temp = n
    for i in range(1, int(-(-n**0.5//1))+1):
        if temp%i==0:
            arr.append([i, temp//i])
    return arr

def main():
  X = int(input())
  Y = factorization(X)
  flg = 0
  for con in Y:
    N = con[0]
    M = con[1]
    for i in range((N//2) + 1, (10**9)+1):
      A = i
      B = i - N
      K = (A**4) + ((A**3)*B) + ((A**2)*(B**2)) + (A*(B**3)) + (B**4)
      if K > M:
        break
      elif K == M:
        print('{} {}'.format(A, B))
        flg = 1
        break
    if flg == 1:
      break
main()

Measured memory_bytes: 63804
//
// Created by Wangzhe on 2019/10/19.
//

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll maxn = 1e5 + 10, INF = 1e18;

int a[maxn];

int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int res = 0;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int sum = a[i] + a[j];
            int r = lower_bound(a, a + n, sum) - a;

            res += r - j - 1 > 0 ? r - j - 1: 0;
//            cout << r <<  ' ' << res << endl;
        }
    }
    cout << res << endl;


    return 0;
}

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

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

    int sum = 0;

    for (int i = 0; i < n.size(); i++)
    {
        sum += (int)(n.at(i) - '0');
    }

    string ans = "No";
    if (sum % 9 == 0)
    {
        ans = "Yes";
    }

    cout << ans << endl;
}


Measured memory_bytes: 3748
N=int(input())
S=input()

B=[0]
for i in range(N):
    if S[i]=="#":
        B.append(B[-1]+1)
    else:
        B.append(B[-1])

MAXB=B[-1]
ANS=10**10

for i in range(N+1):
    l=B[i]
    r=(N-i)-(MAXB-B[i])
    #print(i,l,r)
    

    ANS=min(ANS,l+r)

print(ANS)

Measured memory_bytes: 11140
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.round
import kotlin.math.sqrt

fun main(){
    val (a, b, h, m) = readLine()!!.split(" ").map { it.toDouble() }
    var kakudo:Double = 0.toDouble()
    val mKaku = 0.0333333333333 * m
    val hKaku = 0.1666666666667 * h + (0.00277777777778 * m)
    if (mKaku > hKaku){
        if (mKaku - hKaku <= 1){
            kakudo = mKaku - hKaku
        } else {
            kakudo = 2 - (mKaku - hKaku)
        }
    } else {
        if (hKaku - mKaku <= 1){
            kakudo = hKaku - mKaku
        } else {
            kakudo = 2 - (hKaku - mKaku)
        }
    }
    val ans = (a * a) + (b * b) - (2 * a * b * (cos(kakudo * PI)))
    val anS = sqrt(ans)
    println(anS)
    
}


Measured memory_bytes: 36576
use std::io::{self, Stdin};
use std::str::{self, FromStr};
use std::error::Error;

fn exec() {
    let mut sc = Scanner::new();
    let (h, w, y, x): (usize, usize, usize, usize) = (sc.ne(), sc.ne(), sc.ne(), sc.ne());
    if h % y == 0 && w % x == 0 {
        println!("No");
        std::process::exit(0);
    }
    println!("Yes");
    let base: i64 = 1000;
    for i in 1..h + 1 {
        for j in 1..w + 1 {
            let p = if i % y == 0 && j % x == 0 {
                ((x * y) as i64 - 1) * -base - 1
            } else {
                base
            };
            print!("{} ", p);
        }
        println!("");
    }
}

fn main() {
    const STACK: usize = 16 * 1024 * 1024;
    let _ = std::thread::Builder::new()
        .stack_size(STACK)
        .spawn(|| { exec(); })
        .unwrap()
        .join()
        .unwrap();
}

#[allow(dead_code)]
struct Scanner {
    stdin: Stdin,
    id: usize,
    buf: Vec<u8>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner {
            stdin: io::stdin(),
            id: 0,
            buf: Vec::new(),
        }
    }
    fn next_line(&mut self) -> Option<String> {
        let mut res = String::new();
        match self.stdin.read_line(&mut res) {
            Ok(0) => None,
            Ok(_) => Some(res),
            Err(why) => panic!("error in read_line: {}", why.description()),
        }
    }
    fn next<T: FromStr>(&mut self) -> Option<T> {
        while self.buf.len() == 0 {
            self.buf = match self.next_line() {
                Some(r) => {
                    self.id = 0;
                    r.trim().as_bytes().to_owned()
                }
                None => return None,
            };
        }
        let l = self.id;
        assert!(self.buf[l] != b' ');
        let n = self.buf.len();
        let mut r = l;
        while r < n && self.buf[r] != b' ' {
            r += 1;
        }
        let res = match str::from_utf8(&self.buf[l..r])
                  .ok()
                  .unwrap()
                  .parse::<T>() {
            Ok(s) => Some(s),
            Err(_) => {
                panic!("parse error, {:?}",
                       String::from_utf8(self.buf[l..r].to_owned()))
            }
        };
        while r < n && self.buf[r] == b' ' {
            r += 1;
        }
        if r == n {
            self.buf.clear();
        } else {
            self.id = r;
        }
        res
    }
    fn ne<T: FromStr>(&mut self) -> T {
        self.next::<T>().unwrap()
    }
}


Measured memory_bytes: 9852
gets
score = 0
base = [0, 0, 0]
out_count = 0
readlines.map(&:chomp).each{|cmd|
  case cmd
  when 'HIT'
    base.unshift(1)
    score += base.pop
  when 'OUT'
    out_count += 1

    if out_count == 3
      puts score
      score = 0
      base = [0, 0, 0]
      out_count = 0
    end
  when 'HOMERUN'
    score += base.inject(&:+) + 1
    base = [0, 0, 0]
  end
}

Measured memory_bytes: 8600
//
// Created by yamunaku on 2020/09/20.
//

#include <bits/stdc++.h>
//#include <atcoder/all>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main() {
    //CFS;
    int n, k;
    cin >> n >> k;
    vl a(n + 2);
    a[0] = -LINF, a[n + 1] = LINF;
    repl(i, 1, n + 1) cin >> a[i];
    int lg = 0;
    int tmp = 1;
    while (tmp < n + 2) tmp *= 2, lg++;
    mti fl(lg, vi(n + 2)), fr(lg, vi(n + 2));
    mtl sl(lg, vl(n + 2)), sr(lg, vl(n + 2));
    fl[0][0] = fr[0][0] = 0;
    fl[0][n + 1] = fr[0][n + 1] = n + 1;
    sl[0][0] = sr[0][0] = 0;
    sl[0][n + 1] = sr[0][n + 1] = 0;
    repl(i, 1, n + 1) {
        fl[0][i] = lower_bound(all(a), a[i] + k) - a.begin();
        fr[0][i] = upper_bound(all(a), a[i] - k) - a.begin() - 1;
        sl[0][i] = i;
        sr[0][i] = i + 1;
    }
    repl(t, 1, lg) {
        fl[t][0] = fr[t][0] = 0;
        fl[t][n + 1] = fr[t][n + 1] = n + 1;
        sl[t][0] = sr[t][0] = 0;
        sl[t][n + 1] = sr[t][n + 1] = 0;
        repl(i, 1, n + 1) {
            fl[t][i] = fl[t - 1][fl[t - 1][i]];
            fr[t][i] = fr[t - 1][fr[t - 1][i]];
            sl[t][i] = sl[t - 1][i] + sl[t - 1][fl[t - 1][i]];
            sr[t][i] = sr[t - 1][i] + sr[t - 1][fr[t - 1][i]];
        }
    }
    int q;
    cin >> q;
    rep(t, q) {
        int l, r;
        cin >> l >> r;
        int tl = l, tr = r;
        ll sum = 0;
        per(i, lg) {
            if (fl[i][tl] <= r) {
                sum -= sl[i][tl];
                tl = fl[i][tl];
            }
            if (fr[i][tr] >= l) {
                sum += sr[i][tr];
                tr = fr[i][tr];
            }
        }
        sum -= tl;
        sum += tr+1;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 91652
#include <stdio.h>
#include <stdlib.h>
int N;
long int ans;
int A[200001];
int main(void) {
    A[0] = 0;
    scanf("%d", &N);
    for(int k = 1; k <= N; k++){
        scanf("%d", &A[k]);
        if(A[k] < A[k-1]){
            ans += (A[k-1] - A[k]);
            A[k] = A[k-1];
        }
    }
    printf("%ld", ans);
    return 0;
}

Measured memory_bytes: 2484
from collections import defaultdict

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

#処理内容
def main():
	N = int(input())
	D = defaultdict(int)
	a = sorted(getlist())
	if N == 2:
		if a[0] != 1 or a[1] != 1:
			print("Impossible")
		else:
			print("Possible")
	else:
		for i in range(N):
			D[a[i]] += 1
		if a[-1] % 2 != 0:
			if a[0] * 2 - 1 != a[-1]:
				print("Impossible")
			else:
				judge = "Possible"
				if D[a[0]] != 2:
					judge = "Impossible"
				for i in range(a[0], a[-1] + 1):
					if D[i] < 2:
						judge = "Impossible"
						break
				print(judge)
		else:
			judge = "Possible"
			if a[0] * 2 != a[-1]:
				print("Impossible")
			else:
				judge = "Possible"
				if D[a[0]] != 1:
					judge = "Impossible"
				for i in range(a[0] + 1, a[-1] + 1):
					if D[i] < 2:
						judge = "Impossible"
						break
				print(judge)

if __name__ == '__main__':
	main()

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

const int MOD = 1e9 + 7;

inline int mod_add(int a, int b, int m = MOD) {
    int sum = a + b;
    return sum >= m ? sum - m : sum;
}

inline int mod_sub(int a, int b, int m = MOD) {
    int diff = a - b;
    return diff < 0 ? diff + m : diff;
}

int N, K;

int main() {
    scanf("%d %d", &N, &K);
    vector<int> dp(K + 1, 0);
    dp[0] = 1;

    for (int i = 0; i < N; i++) {
        int a;
        scanf("%d", &a);
        int sum = 0;

        for (int x = K; x > K - a; x--)
            sum = mod_add(sum, dp[x]);

        for (int c = K; c >= 0; c--) {
            if (c - a >= 0)
                sum = mod_add(sum, dp[c - a]);

            int new_sum = mod_sub(sum, dp[c]);
            dp[c] = sum;
            sum = new_sum;
        }
    }

    printf("%d\n", dp[K]);
}


Measured memory_bytes: 640
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, string
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**7)
inf = float('inf')
mod = 10**9+7
ans = inf ;count = 0 ;pro = 1

s = input()
t = s[::-1]
for i in range(len(s)):
    if s[i] != t[i]:
        count += 1
print(count//2)


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

using namespace std;

int main() {
  int k, x;
  cin >> k >> x;

  for (int i = x - k + 1; i <= k + x - 1; i++) {
    cout << i << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
const int N=200005;
vector<int> vec[N];
int n;
int tmp,tmp1;
void dfs (int x,int fa,int dep)
{
	if (dep>tmp1)	{tmp=x;tmp1=dep;}
	int siz=vec[x].size();
	for (int u=0;u<siz;u++)
	{
		int y=vec[x][u];
		if (y==fa) continue;
		dfs(y,x,dep+1);
	}
}
int main()
{
	scanf("%d",&n);
	for (int u=1;u<n;u++)
	{
		int x,y;
		scanf("%d%d",&x,&y);
		vec[x].push_back(y);vec[y].push_back(x);
	}
	tmp1=0;dfs(1,0,1);
	tmp1=0;dfs(tmp,0,1);
	if (tmp1%3==2) printf("Second\n");
	else printf("First\n");
	return 0;
}

Measured memory_bytes: 23680
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {
	private static final int MOD = 1000000007;

	public static void main(String[] args) throws Exception {
		java.util.Scanner sc = new java.util.Scanner(System.in);
		int N = sc.nextInt();
		double[] x = new double[N];
		String[] y = new String[N];
		for (int i = 0; i < N; i++) {
			x[i] = sc.nextDouble();
			y[i] = sc.next();
		}

		double sum = 0;
		for (int i = 0; i < N; i++) {
			if (y[i].equals("JPY")) {
				sum += x[i];
			} else {
				sum += x[i] * 380000;
			}
		}

		System.out.println(sum);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 23636
#include <cstdio>
#include <unordered_set>
#include <vector>

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

  std::vector<int> a(n);
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);
  int xor_sum = 0;
  for (int i = 0; i < n; i++)
    xor_sum ^= a[i];
  std::unordered_set<int> s;
  for (int i = 0; i < n; i++)
    s.insert(a[i] ^ (a[i] - 1));
  int ans = 0;
  for (int bit = 29; bit >= 0; bit--) {
    if (((1 << bit) & xor_sum) == 0) {
      continue;
    }
    int x = (1 << (bit + 1)) - 1;

    if (s.find(x) != s.end()) {
      xor_sum ^= x;
      ans += 1;
    }
  }

  if (xor_sum != 0) {
    printf("-1\n");
  } else {
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define MAX 510000
#define Rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)

using namespace std;
typedef long long int  ll;
typedef pair<int, int> P;

//cout << fixed << setprecision(10);//
//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}


//inversemod//
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll 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;
	}
}

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

//LARGE n

ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	
	   k/=i;
	
	}

	return k;
}


////////////////////////////////////////////////////////////////////



int main() {
ll n,k;
cin>>n>>k;

if(k==1){cout<<0<<endl;
return 0;}

ll a[n+1];
for(int i=1;i<=n;i++){
	cin>>a[i];
	a[i]--;
}
a[0]=0;
rep(i, n){
	a[i]=a[i-1]+a[i];
	a[i]%=k;
}


set <ll> ks;
for(int i=0;i<=n;i++){
ks.insert(a[i]);
}

ll m=ks.size();
ll ans=0;

map<ll, ll> mp;

ll num=-1;
for(auto itr=ks.begin(); itr!=ks.end();++itr){
ll s=*itr;
if(!mp.count(s)){
	++num;
	mp[s]=num;
}

}


queue<ll> que[m];
ll fin[n+1];

for(ll i=0;i<=n;i++){
	ll c=mp[a[i]];

que[c].push(i+k-1);
fin[i]=c;
ans+=que[c].size()-1;

if(i>=k-1){
	ll u=fin[i-k+1];
	que[u].pop();
}



}



cout<<ans<<endl;
return 0;






}





Measured memory_bytes: 159616
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp;

const INF: isize = std::isize::MAX;

fn calc(s: &[isize], l: usize, m: usize, r: usize) -> isize {
    let p = s[l];
    let q = s[m] - s[l];
    let rr = s[r] - s[m];
    let n = s[s.len()-1] - s[r];
    let max = cmp::max(cmp::max(p, q), cmp::max(rr, n));
    let min = cmp::min(cmp::min(p, q), cmp::min(rr, n));
    // println!("l={} i={} r={} {:?} | {:?} | {:?} | {:?} {}", l, m, r, &s[0..l+1], &s[l+1..m+1], &s[m+1..r+1], &s[r+1..], max-min);
    assert!(l > 0);
    assert!(l < m);
    assert!(m < r);
    assert!(r < s.len());
    max - min
}

fn main() {
    input!{
        n: usize,
        aa: [isize; n],
    }
    let mut s = vec![0; n+1];
    for i in 0..aa.len() {
        s[i+1] = aa[i] + s[i];
    }
    let mut f = vec![0; n+1];
    let mut g = vec![0; n+1];

    let mut ans = INF;
    for i in 2..n-1 {
        // f
        let mut j = f[i-1];
        let b = s[j];
        let c = s[i] - s[j];
        let mut dmin = (b - c).abs();
        while j < i-1 {
            let b = s[j+1];
            let c = s[i] - b;
            if dmin < (b - c).abs() { break; }
            dmin = (b - c).abs();
            j = j + 1;
        }
        f[i] = j;

        // g
        let mut j = cmp::max(g[i-1], i+1);
        let b = s[j] - s[i];
        let c = s[n] - s[j];
        let mut dmin = (b - c).abs();
        while j < n {
            let b = s[j+1] - s[i];
            let c = s[n] - s[j+1];
            if dmin < (b - c).abs() { break; }
            dmin = (b - c).abs();
            j = j + 1;
        }
        g[i] = j;
        ans = cmp::min(calc(&s, f[i], i, g[i]), ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 12540
{
  const main = (input: string) => {
    const r = reader(input)
    const [H, W, K] = r.ns()
    const s: (number | string)[][] = r.lines.map(line => line.split(''))
    const a = [...s]

    let fillMaster = 0
    for (let y = 0; y < H; y++) {
      let fill = 0
      for (let x = 0; x < W; x++) {
        if (s[y][x] === '#') {
          fill += 1
        }
        if (fill > 0) {
          s[y][x] = fill + fillMaster
        } else {
          s[y][x] = 0
        }
      }
      if (fill === 0) {
        continue
      }
      for (let x = 0; x < W && s[y][x] === 0; x++) {
        s[y][x] = fillMaster + 1
      }
      fillMaster += fill
    }
    for (let y = 1; y < H; y++) {
      if (s[y][0] !== 0) {
        continue
      }
      s[y] = s[y - 1]
    }
    for (let y = H - 2; y >= 0; y--) {
      if (s[y][0] !== 0) {
        continue
      }
      s[y] = s[y + 1]
    }
    console.log(s.map(cs => cs.join(' ')).join('\n'))
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  main(require('fs').readFileSync('/dev/stdin', 'utf8'))
}


Measured memory_bytes: 22604
inputs = STDIN.gets.chomp.split(' ').map(&:to_i)

R = inputs[0]
G = inputs[1]
B = inputs[2]
N = inputs[3]

count = 0

n_r = N / R
n_g = N / G
n_b = N / B

(0..n_r).each do |r|
  rr = R * r

  if rr == N
    count += 1
    next
  end

  (0..n_g).each do |g|
    gg = G * g

    next if (rr+gg) > N

    if (rr + gg) == N
      count += 1
      next
    end

    rg = rr + gg

    count += 1 if (N - rg) % B == 0
  end
end

puts count

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


int main() {
int N;
cin>>N;
long ans=0;
for(int i=1;i<=N;i+=2){
  int tmp=i;
  int d3=0;
  while(tmp%3==0){
    d3++;
    tmp/=3;
  }
  int d5=0;
  while(tmp%5==0){
    d5++;
    tmp/=5;
  }
  int d7=0;
  while(tmp%7==0){
    d7++;
    tmp/=7;
  }
  int d11=0;
  while(tmp%11==0){
    d11++;
    tmp/=11;
  }
  int d13=0;
  while(tmp%13==0){
    d13++;
    tmp/=13;
  }
  int num=(d3+1)*(d5+1)*(d7+1)*(d11+1)*(d13+1);
  if(num==8) {
    ans++;
  //  cout<<i<<endl;
  }
}
cout<<ans<<endl;
}


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

#define ll long long
#define fi first
#define se second
#define inf 1e15

#define N 300005

vector<int>row[N];

multiset<int>Noofbombsincolumnsset;

int bombsineachcolumn[N];

void upd(int pos,int delta){
    
    Noofbombsincolumnsset.erase(Noofbombsincolumnsset.find(bombsineachcolumn[pos]));
    
    bombsineachcolumn[pos]+=delta;
    
    Noofbombsincolumnsset.insert(bombsineachcolumn[pos]);
    
}
int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
	int t=1;
//	cin>>t;
	while(t--){
	    
	    int n,m,k;
	    cin>>n>>m>>k;
	    
	    for(int i=0;i<m;i++){
	        Noofbombsincolumnsset.insert(0);
	        bombsineachcolumn[i]=0;
	    }
	    for(int i=0;i<k;i++){
	        int x,y;
	        cin>>x>>y;
	        x--;y--;
	        row[x].push_back(y);
	        //add
	        upd(y,1);
	    }
	    int ans=0;
	    
	    for(int i=0;i<n;i++){
	        
	        int cnt=row[i].size();
	        
	        for(auto y:row[i]){
	            //remove
	            upd(y,-1);
	        }
	        
	        cnt+= *Noofbombsincolumnsset.rbegin();
	        
	        ans=max(ans,cnt);
	        
	        for(auto y:row[i]){
	            //add
	            upd(y,1);
	        }
	        
	    }
	    
	    cout<<ans<<"\n";
	    
	    
	}
	return 0;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define REPV(iter, v) for(auto (iter)=(v).begin(); (iter)!=(v).end();++(iter))
#define ALL(v) (v).begin(),(v).end()

#define MOD 1000000007

using namespace std;

typedef long long ll;

bool isOK(ll num, ll d)
{
    vector<ll> digit(d);
    bool flag = true;
    REP(i, d)
    {
        ll p = num;
        digit[i] = (p >> i) & 1; 
    }
    REP(i, d - 1)
    {
        if (digit[i] == 1)
        {
            if (digit[i + 1] == 1)
            {
                flag = false;
                break;
            }
        }
    }

    return flag;
}

int main()
{
    ll H, W, K;
    cin >> H >> W >> K;
    vector<ll> down(W, 0), right(W, 0), left(W, 0);
    REP(i, 1 << (W - 1))
    {
        if (isOK(i, W - 1))
        {
            REP(j, W)
            {
                ll num = i;
                if (j < W - 1 && (num >> j) & 1)
                {
                    right[j]++;
                }
                else if (j - 1 >= 0 && (num >> (j - 1)) & 1)
                {
                    left[j]++;
                }
                else
                {
                    down[j]++;
                }
            }
        }
    }

    ll dp[H + 1][W + 1];
    REP(i, H + 1)
    {
        REP(j, W + 1)
        {
            dp[i][j] = 0;
        }
    }
    dp[0][1] = 1;
    for (ll h = 1; h <= H; ++h)
    {
        for (ll w = 1; w <= W; ++w)
        {
           
            dp[h][w] = (dp[h - 1][w] * down[w - 1]) % MOD;
            if (w + 1 <= W)
            {
                dp[h][w] += (dp[h - 1][w + 1] * left[w]) % MOD;
                dp[h][w] = dp[h][w] % MOD;
            }
            if (w - 1 >= 1)
            {
                dp[h][w] += (dp[h - 1][w - 1] * right[w - 2]) % MOD;
                dp[h][w] = dp[h][w] % MOD;
            }
        }
    }

    cout << dp[H][K] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int n, a, b; cin >> n >> a >> b;
    vector<int> cur(3, 0);
    rep(i, n){
        int p; cin >> p;
        if(p <= a) cur[0]++;
        else if(a < p and p <= b) cur[1]++;
        else cur[2]++;
    }
    cout << *min_element(cur.begin(), cur.end()) << endl;
}

Measured memory_bytes: 3588
package main

import "fmt"

func main() {
	var x, ans int
	fmt.Scan(&x)
	a := x / 11 * 2
	b := x % 11
	switch b {
	case 0:
		ans = a
	case 1:
		ans = a + 1
	case 2:
		ans = a + 1
	case 3:
		ans = a + 1
	case 4:
		ans = a + 1
	case 5:
		ans = a + 1
	case 6:
		ans = a + 1
	case 7:
		ans = a + 2
	case 8:
		ans = a + 2
	case 9:
		ans = a + 2
	case 10:
		ans = a + 2
	}
	fmt.Println(ans)
}


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

int main() {
	// your code goes here
	long long int n;
	cin>>n;
	long long int hash[200001] = {0};
	for(int i=1; i<n; i++){
	    int x;
	    cin>>x;
	    hash[x]++;
	}
	for(int i=1; i<=n; i++){
	    cout<<hash[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 5184
#include<iostream>
using namespace std;
int main()
{
	int n,s=0,m;
	cin>>n;
	if(n%500==0)
	s=s+n*2;
	else
	{
		 m=n%500;
		
	s=(n-m)*2;
	if(m%5==0)
	{
		s+=m;
	}
	else
	s=s+(m-(m%5));
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include<iostream>

#include<stdio.h>

using namespace std;

int main(){

	int a, b; 

	char op;

	while(1){

	 	cin >> a >> op >> b;

		if ( op == '?') break;

		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;

			}

	}

	return 0;

}

Measured memory_bytes: 1164
import Data.List
main = do
    n <- read <$> getLine :: IO Int
    a <- reverse.sort.map read.words <$> getLine
    let alice = sum.step $ a
          where
            step (x:_:xs) = x:step xs
            step l = l
        total = sum a
    putStrLn.show $ 2*alice - total


Measured memory_bytes: 1020
//https://onlinejudge.u-aizu.ac.jp/problems/ALDS1_4_D
//p137.cpp

#include<iostream>
using namespace std;
#define MAX 100000
typedef long long llong;
int n,k;
llong T[MAX];

int check(llong P){
	int i = 0;
	for(int j = 0 ; j<k ; j++){
		llong s = 0;
		while( s + T[i] <= P){
			s += T[i];
			i++;
			if(i == n)return n;
		}
	}
	return i;
}

int solve(){
	llong left = 0;
	llong right = 100000 * 10000;
	llong mid;
	while (right - left > 1){
		mid = (left + right)/2;
		int v = check(mid);
		if(v >= n)right = mid;
		else left = mid;
	}

	return right;
}

int main(){
	cin >> n >> k;
	for(int i = 0 ; i < n ; i++ )cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}



Measured memory_bytes: 3888
/**
	Language: C++
	Author  : 21
**/

#include <bits/stdc++.h>

using namespace std;

#define FastIO() ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define Debug(v) cerr << '\n' << #v << ":\t" << v << '\n'

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

int main() {
	FastIO();
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll sum = 0;
	if (a < k) {
		sum += a;
		k -= a;
		if (b < k) {
			sum += 0;
			k -= b;
			sum += -k;
		} else {

		}
	} else {
		sum = k;
	}
	cout << sum << '\n';
	return 0;
}


Measured memory_bytes: 3648
// abco54c: One-stroke Path
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;

#define rep(i,n) for(int i=0;i<(n);i++)
#define oute(x) cout<<(x)<<endl

struct vertex{vi v; bool visit;};
using graph = vector<vertex>;

int dfs(graph &g, int p, int distance, int count){
  if(distance==g.size()-1) return count+1;
  g[p].visit = true;
  for(int c:g[p].v)
    if(!g[c].visit) count = dfs(g,c,distance+1,count);
  g[p].visit = false;
  return count;
}

int main(){
  int n,m; cin>>n>>m;
  graph g(n);
  rep(i,m){
    int a,b; cin>>a>>b;
    g[--a].v.push_back(--b);
    g[b].v.push_back(a);
  }
  oute(dfs(g,0,0,0));
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
using namespace std;

int main(){
	int n, l;
	cin >> n >> l;
	vector<string> s(n);
	string ans = "";
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
	}
	sort(s.begin(), s.end());
	for (int i = 0; i < n; ++i) {
		ans += s[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int long long
using namespace std;
using P=pair<int,int>;
using Graph=vector<vector<int>>;
using ll=long long;


ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
bool root(string s){
    int n=s.length();
    if(n==2){
        if(s[0]==s[1]){
            return true;
        }
        else return false;
    }
    if(n==3){
        if(s[0]==s[2]){
            return true;
        }
        else return false;
    }
 
    return false;
}
 
 
//深さ優先
vector<int> seen;
vector<ll> h;
 
//普通の深さ優先探索seenを返す感じ
void dfs(const Graph &G,int v){
    seen[v] = 0; //v探索済み
 
    P good=make_pair(v,h[v]);
    for(auto next_v :G[v]){
        if(seen[next_v]!=-1) continue;//もう探索していた
        if(h[next_v]>good.second){
            good=make_pair(next_v,h[next_v]);
        }
        dfs(G,next_v);
    }
 
    if(!(h[v]==good.second && v==good.first)){
        seen[good.first]=1;
    }
}
 
signed main(){
    /*
    int n,m;
    cin>>n>>m;
 
    h.assign(n,0);
    rep(i,0,n) cin>>h[i];
 
    Graph G(n);
    rep(i,0,m){
        int a,b; cin>>a>>b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
 
    seen.assign(n,-1);
 
    rep(i,0,n){
        if(seen[i]==-1){
            dfs(G,i);
        }
    }
 
    int sum=accumulate(all(seen),0);
 
    cout<<sum<<endl;*/
 
    int n;
    cin>>n;
    set<int> se;
    int a[n];
    rep(i,0,n){
        int ai;
        cin>>ai;
        a[i]=ai-1;
        //se.insert(i);
    }

    int ans=0;

    for(int i=0;i<n;i++){
        if(a[a[i]]==i){
            if(se.count(i)==0){
            ans++;
            se.insert(i);
            se.insert(a[i]);
            }
        }
    }
    

    cout<<ans<<endl;
}   

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

int main() {
    ll N; cin >> N;
    ll sr = ll(sqrt(N));
    for (ll i=sr; i>0; i--) {
        if (N % i == 0) {
            ll j = N / i;
            cout << i + j - 2<< endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i,n) for(int i = 0;i < n; i++)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e18;

#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int dp[5050];
int ndp[5][5000*5050];

signed main(){
	IOS();
	int N;
	cin>>N;
	int ga,gb,sa,sb,ba,bb;
	cin>>ga>>sa>>ba>>gb>>sb>>bb;
	rep(i,0,N+1){
		chmax(dp[i+1],dp[i]+1);
		rep(j,0,N+1){
			if(i+j>N)continue;
			chmax(dp[i+j],dp[i]+j/ga*gb);
			chmax(dp[i+j],dp[i]+j/sa*sb);
			chmax(dp[i+j],dp[i]+j/ba*bb);
		}
	}
	int ma = 0;
	rep(i,0,N+1)chmax(ma,N-i+dp[i]);
	vector<int>w(4),v(4);
	w[0]=gb;
	v[0]=ga;
	w[1]=sb;
	v[1]=sa;
	w[2]=bb;
	v[2]=ba;
	w[3]=v[3]=1;
	rep(i,0,v.size()){
		rep(j,0,ma+1){
			if(j<w[i]){
				ndp[i+1][j] = ndp[i][j];
			}else{
				chmax(ndp[i+1][j],max(ndp[i][j],ndp[i+1][j-w[i]]+v[i]));
			}
		}
	}
	cout<<ndp[4][ma]<<endl;
}

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

int a[200010];
int ans[200010];

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


Measured memory_bytes: 5136
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
int MOD=1000000007;
int main() {
	int count=0;
    string S;
	cin >> S;
	if(S[0]==S[1]) count+=1;
	if(S[1]==S[2]) count+=2;
	if(S[2]==S[3]) count+=1;
	if(count==0) cout << "Good" << endl;
	else cout << "Bad" << endl;
}


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

int main() {
  int N;
  cin >> N;
  set<string> S;
  for (int i = 0; i < N; i++) {
    string str;
    cin >> str;
    S.insert(str);
  }

  cout << S.size() << endl;
  return 0;
}

Measured memory_bytes: 19256
//Author: master19
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ff first 
#define ss second 
#define pb push_back
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000007LL // fixed...
#define modd 1000000007LL // Can be changed for global use
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define Yes cout << "Yes\n"
#define No cout << "No\n"
#define all(arr) arr.begin(),arr.end()
#define x(arr) arr.begin(),arr.end()
#define ulli unsigned long long int
#define assign(x,val) memset(x,val,sizeof(x))
#define prec(val, dig) fixed << setprecision(dig) << val
#define Sort(arr) sort(arr.begin(), arr.end())
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define crap ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define get(arr, num) vector < ll > arr(num); for(int i=0; i<num; i++)cin >> arr[i];
#define get_set(arr, num, st, type) set < type > st; for(int i=0; i<num; i++) st.insert(arr[i]);
#define put(arr, num) for(int i=0; i<num; i++)cout << arr[i] << " "; cout << endl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > new_ds; 
ll lets_do_it();
// pi xy[] = {{-1, 0}, {1, 0} , {0, -1}, {0, 1}};
// pi dig[] = {{-1, -1}, {-1, 1}, {1, 1}, {1, -1}};
// bool isValid(ll x, ll y, ll row, ll col){
//     return ((x>=0) && (y >=0)  && (x < row) && (y < col));
// }
int main(int argc, const char** argv) {
    crap;
    ll test = 1;
    // cin >> test;
    for(int loop=0; loop<test; loop++){
        // cout << "Case #" << (loop+1) << ": "; 
        lets_do_it();
    }
    return 0;
}
ll lets_do_it(){
    // Your code goes by here !!
    ll num;
    cin >> num;
    get(arr, num);
    ll value = 0;
    for(int i=0; i<num; i++)
        value ^= arr[i];
    for(int i=0; i<num; i++){
        value = arr[i]^value;
        cout << value << " ";
        value = arr[i] ^value;
    }





























    return 0;
}


Measured memory_bytes: 4752
N, A, B = [int(x) for x in input().split()]

if N == 1:
    ans = 1 if A == B else 0
else:
    if B >= A:
        ans = ((N - 1) * B + A) - ((N - 1) * A + B) + 1
    else:
        ans = 0

print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  double n,t,a;
  cin >> n >> t >> a;
  vector<double> h(n);
  rep(i,n){
    double x;
    cin >> x;
    h.at(i) = t - x * 0.006;
  }
  double mini = 1e9;
  int id;
  rep(i,n) {
    if(mini > abs(a - h.at(i))){
      mini = abs(a - h.at(i));
      id = i + 1;
    }
  }
  cout << id << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
typedef pair<int, int> P;
struct UF{
  vector<int> data;
  vector<int> weight;
  UF(int N) : data(N, -1), weight(N, 0) {}
  void uni(int x, int y, int w){
    P px = root(x), py = root(y);
    if(px.first != py.first){
      if(data[px.first] > data[px.first]){
        swap(px, py);
        w *= -1;
      }
      data[px.first] += data[py.first];
      data[py.first] = px.first;
      weight[py.first] = px.second - py.second + w;
    }
  }
  P root(int x){
    if(data[x] < 0) return P(x, 0);
    P p = root(data[x]);
    data[x] = p.first;
    weight[x] += p.second;
    return P(data[x], weight[x]);
  }
};

int main(){
  int N, M;
  while(cin>>N>>M && N){
    UF uf(N);
    string s; int x, y, z;
    REP(i, M){
      cin>>s;
      if(s == "!"){
        scanf("%d %d %d", &x, &y, &z);
        x--; y--;
        uf.uni(x, y, z);
      }else{
        scanf("%d %d", &x, &y);
        x--; y--;
        P px = uf.root(x);
        P py = uf.root(y);
        if(px.first == py.first){
          printf("%d\n", py.second - px.second);
        }else{
          printf("UNKNOWN\n");
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 2780
import math

N = int(input())
P = []

for k in range(2,55555):
    f = 1
    for l in range(2,int(math.sqrt(k))+1):
        if k%l==0:
            f = 0
    if f and k%5==1:
        P.append(k)
    if len(P)>=N:
        break

print(" ".join(map(str,P)))

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

int main() {
  int N,K,a;
  cin >> N >> K;
  a = 1;
  for(int i=0;i < N;i++){
    if(a*2 < a+K){
      a=a*2;
    }else{
      a=a+K;
    }
  }
  cout << a << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <cassert>

using namespace std;


bool solve(){
	int n;
	while(cin>>n){
		vector<int> a;
		int k = 0;
		int end_num;
		while(n){
			if(n%2) end_num = k;
			a.push_back(n%2);
			n /= 2;
			k++;
		}
		int num = 1;
		for(int i=0;i<k;i++){
			if(a[i]){
				cout<< num;
				if(i != k-1) cout<< " ";
			}
			num *= 2;
		}
		cout<< endl;
	}
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();
	
	return 0;
}

 

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

int main() {
  long long n, m;
  cin >> n >> m;
  
  long long ans = 0;
  if(n * 2 >= m) ans = m / 2;
  else ans = (n * 2 + m) / 4;
  cout << ans << endl;
}

Measured memory_bytes: 3640