akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

int n, A[50];

int solve(int p, int t){
  if ( p >= n )
    return 0;
  if ( A[p] == t )
    return 1;
  if ( solve(p+1,t) )
    return 1;
  if ( solve(p+1,t-A[p]) )
    return 1;
  return 0;
}

int main(){
  int k, M, i;
  scanf("%d",&n);
  for ( i = 0 ; i < n ; i++ )
    scanf("%d",&A[i]);
  scanf("%d",&k);
  for ( i = 0 ; i < k ; i++ ) {
    scanf("%d",&M);
    if ( solve(0,M) )
      printf("yes\n");
    else printf("no\n");
  }
  return 0;
}



Measured memory_bytes: 2112
from collections import Counter 
from collections import defaultdict
from collections import deque
from functools import reduce
import math
import itertools
import heapq
import numpy as np
import bisect
import sys
#import sympy
sys.setrecursionlimit(10**6)


def bfs(s,n,node):
    #頂点が探索済みかどうかのチェック配列
    check=[False for _ in range(n)]
    check[s]=True
    #次見る頂点を格納するキュー
    queue=deque([s])
    visited_num=1

    #問題固有の配列
    #color_check=[[True for _ in range(l)] for _ in range(n)]
    color=[-1 for _ in range(n)]
    color[s]=0
    
    while visited_num<n:
        #グラフが全連結ではない場合
        if len(queue)==0:
            #空配列を返す
            #現状までの計算済み配列を返してもいいと思う
            return color

        now_vertex=queue.popleft()
        #インデックスがない場合は
        for next_vertex in node[now_vertex]:


            if check[next_vertex]==True:
                continue

            queue.append(next_vertex)
            check[next_vertex]=True

            #問題固有の計算
            color[next_vertex]=color[now_vertex]+1
            visited_num+=1

    return color

#n=int(input())z
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
ceil=lambda x,y: (x+y-1)//y
input_list = lambda : list(map(int,input().split()))



#n=int(input())
n,m=input_list()
#a=input_list()
if n>9 or m>9:
    print(-1)
    exit()

print(n*m)

Measured memory_bytes: 12504
N, M, x, y = map(int,input().split())
X = list(map(int,input().split()))
Y = list(map(int,input().split()))

X.append(x)
Y.append(y)

X.sort(reverse=True)
Y.sort()

if Y[0] > X[0]:
    print('No War')
else:
    print('War')

Measured memory_bytes: 3064
a = []
for i in range(3):
  d, b, c = map(int, input().split())
  a.append(d)
  a.append(b)
  a.append(c)
for _ in range(int(input())):
  n = int(input())
  if(n in a):
    a[a.index(n)] = 0
retsu = [[0, 1, 2], [3, 4, 5], [6, 7, 8], [0, 3, 6], [1, 4, 7], [2, 5, 8], [0, 4, 8], [2, 4, 6]]
frag = False
for i in range(8):
  frag1 = True
  for s in range(3):
    if(a[retsu[i][s]] > 0):
      frag1 = False
  frag = frag1 or frag
if(frag):
  print("Yes")
else:
  print("No")


Measured memory_bytes: 9248
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {

        int n = sc.nextInt();
        int k = sc.nextInt();
        String s = sc.next();

        char[] ans = s.toCharArray();
        ans[k-1] = Character.toLowerCase(ans[k-1]);

        System.out.println(ans);
    }

}


Measured memory_bytes: 21588
/*
* @Author: wxyww
* @Date: 2020-03-23 07:30:09
* @Last Modified time: 2020-03-23 08:24:37
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstring>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
#define int ll
const int N = 1010,mod = 1e9 + 7;
ll read() {
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,h[N];
int qm(int x,int y) {
	int ret = 1;
	for(;y;y >>= 1,x = 1ll * x * x % mod)
		if(y & 1) ret = 1ll * ret * x % mod;
	return ret;
}
#define pi pair<ll,ll>

pi solve(int l,int r,int lim) {
	int mn = 1e9,cnt = 0;pi ret;
	for(int i = l;i <= r;++i) {
		if(h[i] < mn) {
			mn = h[i];cnt = 1;
		}
		else if(h[i] == mn) cnt++;
	}
	if(cnt == r - l + 1) {
		ret.first = (qm(2,r - l + 1) - 2 + mod) % mod;
		ret.second = qm(2,mn - lim - 1);
		return ret;
	}
	int len = r - l + 1,s0 = 1,s1 = 1,lst = 0;
	for(int i = l;i <= r + 1;++i) {
		if(!lst && h[i] > mn) lst = i;
		else if(lst && (h[i] <= mn || i > r)) {
			len -= i - lst;
			pi tmp = solve(lst,i - 1,mn);
			s0 = 1ll * s0 * (tmp.first + 4ll * tmp.second % mod) % mod;
			s1 = 1ll * s1 * (2ll * tmp.second % mod) % mod;
			lst = 0;
		}
	}
	s0 = (s0 - s1 + mod) % mod;
	ret.first = 1ll * s0 * qm(2,len) % mod;
	ret.first += 1ll * s1 * (qm(2,len) - 2 + mod) % mod;
	ret.second = s1 * qm(2,mn - lim - 1) % mod;
	return ret;
}

 main() {
	n = read();
	for(int i = 1;i <= n;++i) h[i] = read();
	for(int i = 1;i <= 100000;++i) 
	if(n == 1) {
		printf("%d\n",qm(2,h[1]));
		return 0;
	}
	int ans = 1;
	for(int i = 1;i <= n;++i) {
		if(h[i] > h[i - 1] && h[i] > h[i + 1]) {
			ans = 1ll * ans * qm(2,h[i] - max(h[i - 1],h[i + 1])) % mod;
			h[i] = max(h[i - 1],h[i + 1]);
		}
	}

	pi ret = solve(1,n,0);
	printf("%lld",1ll * ans * (ret.first + ret.second + ret.second) % mod);

	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
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)*} }; }
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)*} };}
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Functions
fn gets(e:&Vec<u32>, n:u32) -> u32{
    return e.iter().filter(|x| **x > n-2).collect::<Vec<&u32>>().len() as u32;
}

// Main
fn main(){
    input!{
        N: usize,
    }
    // N! を素因数分解してvecに格納
    let mut e = vec![0; 101];
    for i in 2..N+1{
        let mut p = i;
        for j in 2..N+1{
            while p%j == 0{
                e[j] += 1;
                p /= j;
            }
        }
    }
    let mut ans = 0;
    // 約数が75個になるパターンは以下の4つ
    // 1. e1^74
    ans += gets(&e,75);
    // 2. e1^24 + e2^2
    ans += gets(&e,25) * (gets(&e,3)-1);
    // 3. e1^14 + e2^4
    ans += gets(&e,15) * (gets(&e,5)-1);
    // 4. e1^4 + e2^4 + e3^2
    ans += gets(&e,5) * (gets(&e,5)-1) * (gets(&e,3)-2)/2;

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


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

int main(){
  int n;
  map<int, int> mp;
  while (cin >> n){
    mp[n]++;
  }
  int maxnum = 1;
  for (auto m:mp) {
    maxnum = max(m.second, maxnum);
  }
  for (auto m:mp) {
    if (maxnum == m.second)
    cout << m.first << endl;
  }
}


Measured memory_bytes: 3076
class Goto(Exception):pass
while True:
    n=int(input())
    if n==0:
        break
    state=[[True for j in range(21)]for k in range(21)]
    for j in range(n):
        cor=[int(num)for num in input().split(' ')]
        state[cor[0]][cor[1]]=False
    m=int(input())
    now=[10,10]
    d=[[0,1],[1,0],[0,-1],[-1,0]]
    for i in range(m):
        com=input().split(' ')
        t=int(com[1])
        if com[0]=='N':
            for j in range(t):
                now[0]+=d[0][0]
                now[1]+=d[0][1]
                state[now[0]][now[1]]=True
        elif com[0]=='E':
            for j in range(t):
                now[0]+=d[1][0]
                now[1]+=d[1][1]
                state[now[0]][now[1]]=True
        elif com[0]=='S':
            for j in range(t):
                now[0]+=d[2][0]
                now[1]+=d[2][1]
                state[now[0]][now[1]]=True
        else:
            for j in range(t):
                now[0]+=d[3][0]
                now[1]+=d[3][1]
                state[now[0]][now[1]]=True
    try:
        for a in state:
            for s in a:
                if s==False:
                    print("No")
                    raise Goto()
        print("Yes")
    except Goto:pass

Measured memory_bytes: 7688
//http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2676345#1
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
#include<fstream>
#include<cstring>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define P pair<int,int>
#define ll __int64
int m,n;
int x[400],y[400];
int x2[1111],y2[1111];
set<P>table;

bool sserch(int i,int j){
	int dx=x2[j]-x[i],dy=y2[j]-y[i];
	int nx,ny;
	for(int i=0;i<n;i++){
		nx=x[i]+dx;
		ny=y[i]+dy;
		if(table.find(mp(nx,ny))==table.end())return 0;
	}
	return 1;
}
int main(){

while(cin>>n,n){
table.clear();
memset(x,0,sizeof x);
memset(y,0,sizeof y);
memset(x2,0,sizeof x2);
memset(y2,0,sizeof y2);

rep(i,n)cin>>x[i]>>y[i];
cin>>m;
rep(i,m){
cin>>x2[i]>>y2[i];
table.insert(mp(x2[i],y2[i]));

}


int ax,ay;

	rep(j,m){
		if(sserch(0,j)){//図1のiと図2のjを視点にして探索
			ax=x2[j]-x[0];
			ay=y2[j]-y[0];
			cout<<ax<<" "<<ay<<endl;
		}
}
}

	return 0;
}


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

int main(void) {
  long n, x, ans = 0;

  cin >> n >> x;

  vector<long> a(n);

  for(long i = 0; i < n; i++) {
    cin >> a.at(i);
  }

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

  if(x < a.at(0)) {
    cout << 0 << endl;
    return 0;
  }

  while(x > 0) {
    x = x - a.at(ans);
    ans++;
    if(ans == n && x > 0) {
      ans--;
      cout << ans << endl;
      return 0;
    } else if(x == 0) {
      cout << ans << endl;
      return 0;
    }
  }

  ans--;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
for(int i=1;i<=n;++i){
    int a;
cin>>a;
sum+=a;
}
if(sum&1) cout<<"NO"<<endl;
   else cout<<"YES"<<endl;
    return 0;
}

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

int main() {
    int i[12] = {1,2,1,3,1,3,1,1,3,1,3,1};
    int x,y;
    cin >> x >> y;
    x--; y--;
    if(i[x] == i[y]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<long long int> v(n, 0);
    for (int i = 1; i < n; i++) {
        for (int j = 1; j * i < n; j++) {
            v[j * i]++;
        }
    }
    
    cout << accumulate(v.begin(), v.end(), (long long int)0) << endl;
}






Measured memory_bytes: 11096
#include <bits/stdc++.h>    
#include <unordered_map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define pb  push_back
#define show(x) cerr<<(#x)<<" : "<<x<<endl;
#define ll  long long
#define ld  long double
#define fill(a,val) memset(a,val,sizeof(a))
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define endl "\n"
#define fo(i,n) for(int i=0;i<n;i++)
#define foo(i,x,n) for(int i=x;i<n;i++)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define w(x) int x;cin>>x;while(x--)
#define display(a,n) {fo(i,n) {cout<<a[i]<<" ";}cout<<endl;}
#define fil(a,n,val) {fo(i,n) a[i]=val; }
const ll MOD   = 1000*1000*1000+7;
const ll MOD2  = 998244353;
const ll N = 1000*1000+5;
const double PI  = 3.14159265;
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
ll search(vl arr, ll l, ll r, ll x){if (r >= l) {ll mid = l + (r - l) / 2;if (arr[mid] == x)return mid;if (arr[mid] > x)return search(arr, l, mid - 1, x);return search(arr, mid + 1, r, x);} return -1;}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll lcm(ll a , ll b){return (a*b)/ gcd(a,b);}
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){ if (y & 1) res = (res*x) % p; y = y>>1;x = (x*x) % p; } return res; }
ll modInverse(ll n, ll p){return power(n, p-2, p);}
const int maxn=3e5+5;

int dp[maxn]={0};

int main(){
	fastio();
	int n;
	cin>>n;
	int a[n+1];
	foo(i,1,n+1) cin>>a[i];

	foo(i,2,n+1){
		if(i==2){
			dp[i]+=abs(a[i]-a[i-1]);
			continue;
		}
		dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]), dp[i-1]+abs(a[i]-a[i-1]));
	}

	cout<<dp[n]<<endl;

}

Measured memory_bytes: 4440
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define repe(i,n) for(int i=0;i<n;i++)
#define repa(i,j,n) for(int i=j;i<n;i++)
//#define v.all() v.begin(),v.end()
#define repr(i,n) for(int i=n;i>=0;i--)
#define int long long int
#define vi vector<int>
#define vpi vector<pair<int,int>>
int gcd(int a,int b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
vi primef(int n){
	vi a,ref;
	a.push_back(1);
	while(n%2==0) {
		a.push_back(2);
		n/=2;
	}
	for(int i=3;i<=sqrt(n);i+=2){
		while(n%i==0){
			a.push_back(i);

			n/=i;
		}
	}
	if(n>2) a.push_back(n);
	sort(a.begin(), a.end());
	ref.push_back(a[0]);
	for(int i=1;i<a.size();i++){
		if(a[i]!=a[i-1]) {
			ref.push_back(a[i]);
		}
	}
	return ref;
}
int powe(int a,int b){
	int ans=0;
	while(a>=b){
		b*=2;
		ans++;
	}
	return ans;
}
signed  main(){
	int t=1;
	//cin>>t;
	while(t--) {
		int n,k;
		int mod=10e17;
		cin>>n>>k;
		vi a(n);
		rep(i,n) cin>>a[i];
		vi grade;
		int gt=1;
		rep(i,k){
			gt*=a[i];
			gt%=mod;
		}
		grade.push_back(gt);
		for(int i=k;i<n;i++){
			if(a[i]>a[i-k]) cout<<"Yes"<<endl;
			else cout<<"No"<<endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 4804
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline



def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    cnt = 0
    for i in range(1, N + 1):
        s = str(i)
        if(len(s) % 2 == 1):
            cnt += 1
    print cnt

if __name__ == '__main__':
    main()


Measured memory_bytes: 6000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;


main(){
    int n;cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int count=0;
    for(int i=0;i<n;i+=2){
        if(a[i]&1) count++;
    }
    cout<<count;
}

Measured memory_bytes: 3648
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    a, b = LI()
    if a + b == 15:
        print("+")
        return
    if a * b == 15:
        print("*")
        return
    print("x")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 39408
import java.util.Scanner;

public class Main {

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

        int N = sc.nextInt();
        int[] W = new int[N];
        int[] P = new int[N];
        for (int i=0; i<N; i++) {
            W[i] = sc.nextInt();
        }

        System.out.println(solve(N, W));
    }

    private static int solve(int N, int[] W) {
        int min = Integer.MAX_VALUE;
        int S1 = 0;
        int S2 = 0;
        for (int i=0; i<N; i++) {
            S2 += W[i];
        }

        for (int t=0; t<N; t++) {
            S1 += W[t];
            S2 -= W[t];

            min = Math.min(min, Math.abs(S1 - S2));
        }

        return min;
    }
}


Measured memory_bytes: 22868
from itertools import combinations_with_replacement

def resolve():
    N, M, Q = map(int, input().split())
    A = [list(map(int, input().split())) for _ in range(Q)]
    cmb_A = list(combinations_with_replacement(range(1,M+1), N))

    ans = 0
    for cmb in cmb_A:
        tot = 0
        for x in A:
            a,b,c,d = x
            a -= 1
            b -= 1
            if cmb[b]-cmb[a] == c:
                tot += d
        ans = max(ans, tot)
    print(ans)

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 21488
//#include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define fast_io()                \
    ios::sync_with_stdio(false); \
    std::cin.tie(0);
#define mod 998244353
typedef long long ll;
typedef long double ld;
using namespace std;

int main()
{
    fast_io();
    string s;
    cin >> s;
    ll ans = 0;
    for (auto i : s)
        ans += i - 48;
    if (ans % 9)
        cout << "No";
    else
        cout << "Yes";
    return 0;
}


Measured memory_bytes: 3368
#include<stdio.h>
int main(void){
    int W,H;
    int x,y,r;
    scanf("%d%d%d%d%d",&W,&H,&x,&y,&r);
    if((0<=x-r)&&(x+r<=W)&&(0<=y-r)&&(y+r<=H)){
        printf("Yes\n");
    }
    else    printf("No\n");
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	int ans = 1e9*3;
	for (int i = 0;i<N;++i) {
		int a, b;
		cin >> a >> b;
		ans = min(ans,a+b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main(){
	
	int i, n, k, cnt;
	
	double tmp, p = 0;
	
	scanf("%d %d", &n, &k);
	
	for(i = 1; i <= n; i++){
		if(i >= k){
			p += 1 / (double)n;
		}else{
			tmp = log2(k / (double)i);
			if(tmp == (int)tmp)
				cnt = (int)tmp;
			else
				cnt = (int)tmp + 1;
			
			p += 1 / (n * pow(2, cnt));
		}
	}
	printf("%.12f", p);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>  
using namespace std;
char s[200005];
int f[1<<26];
int main(){
	scanf("%s",&s);
	int n=strlen(s),td;
	for (int i=1;i<(1<<26);i++) f[i]=1000000000;
	for (int i=0,zt=0;i<n;i++){
		zt^=(1<<(s[i]-'a'));
		td=f[zt]+1;
		for (int j=0;j<26;j++) td=min(td,f[zt^(1<<j)]+1);
		f[zt]=min(f[zt],td);
	}
	printf("%d",td);
}

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

int main() {
	
	ios_base::sync_with_stdio(0);
	
	int n,k;
	cin >> n >> k;
	
	vector<int> v(n);
	for(int i=0; i<n; ++i)
	cin >> v[i];
	
	vector<int> dp(n,INT_MAX);
	
	dp[0] = 0;
	
	for(int i=0; i<n; ++i) {
		for(int j=i+1; j<=i+k && j<n; ++j) 
		dp[j] = min(dp[j],dp[i]+abs(v[i]-v[j]));
	}
	
	cout << dp[n-1] << endl;
	
	return 0;
	
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int MOD = 1000000007;
int dp[3005][3005][2];
int N,M;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void update(int &x,int y) {
    x = inc(x,y);
}
void Solve() {
    read(N);read(M);
    for(int i = 0 ; i <= N ; ++i) dp[0][i][0] = 1;
    for(int i = 0 ; i < M ; ++i) {
	for(int j = 0 ; j <= N ; ++j) {
	    for(int k = 0 ; k <= 1 ; ++k) {
		if(!dp[i][j][k]) continue;
		if(j >= 1) {
		    int t = 0;
		    if(j == 1) t = 1;
		    update(dp[i + 1][j - 1][k | t],dp[i][j][k]);
		    update(dp[i + 1][j][k | t],dp[i][j][k]);
		}
		if(j <= N - 1) {
		    int t = 0;
		    if(j == 0) t = 1;
		    update(dp[i + 1][j + 1][k | t],dp[i][j][k]);
		    update(dp[i + 1][j][k | t],dp[i][j][k]);
		}
	    }
	}
    }
    int ans = 0;
    for(int j = 0 ; j <= N ; ++j) update(ans,dp[M][j][1]);
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
}


Measured memory_bytes: 70656
//By UditDesai
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define memreset(a) memset(a,0,sizeof(a))
#define testcase(t) int t;cin>>t;while(t--)
#define trav(i,v) for(auto &i: v)
#define forn(i,e) for(int i=0;i<e;++i)
#define forsn(i,s,e) for(int i=s;i<e;++i)
#define rforn(i,s) for(int i=s;i>=0;--i)
#define rforsn(i,s,e) for(int i=s;i>=e;--i)
#define bitcount(a) __builtin_popcount(a) // set bits (add ll)
#define nl cout<<'\n'
#define sp <<' '<<
#define sz(a) (int)(a.size())
#define check(x) cout << #x << " : " << (x) << endl
#define show(a) for(auto i:a) cout<<i<<" ";cout<<endl//By UditDesai
#define getcurrtime() cerr<<"Time = "<<((double)clock()/CLOCKS_PER_SEC)<<endl
#define dbgarr(v,s,e) cerr<<#v<<" = "; forsn(i,s,e) cerr<<v[i]<<", "; cerr<<endl
#define inputfile freopen("input.txt", "r", stdin)
#define outputfile freopen("output.txt", "w", stdout)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int N=2e5+5,MOD=1e9+7;
const ld EPS = 1e-9;
 
 
int main()
{
	fastio;
	ll n,i,j,w;
	cin>>n>>w;
	ll a[n+1],v[n+1];
	a[0]=0,v[0]=0;
	forsn(i,1,n+1) cin>>a[i]>>v[i];	
	ll dp[n+1][w+1];
	for(i=0;i<=n;i++) for(j=0;j<=w;j++) dp[i][j] = 0;
	for(i=a[1];i<=w;i++) dp[1][i] = v[1];
	
	for(i=2;i<=n;i++)
	{
		for(j=0;j<=w;j++)
		{
			dp[i][j] = dp[i-1][j];
			if(j>=a[i])
			{
				dp[i][j] = max(dp[i-1][j], dp[i-1][j-a[i]] + v[i]);
			}
			//cout<<i sp j sp dp[i][j];nl;
		}
	}
	
	ll ans = -1;
	for(i=0;i<=w;i++) ans = max(ans,dp[n][i]);
	cout<<ans;
	return 0;
}


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


int main() {
	
	int N;
	int64_t T, A;
	T =1, A = 1;
	cin >> N;
	vector<int> t(N), a(N);
	for (int i=0; i<N; i++)
		cin >> t.at(i) >> a.at(i);
	for (int i=0; i<N; i++){
		int64_t j;
		j = max ( (T + t.at(i) - 1)/t.at(i), (A + a.at(i) - 1) /a.at(i));
		T = t.at(i)*j, A = a.at(i)*j;
	}
	cout << T + A << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {

	int H,W,i,j;


	while(1){

		scanf("%d %d",&H,&W);

		if(H==0&&W==0) break;

		for(i=1;i<=H;i++){

			for(j=1;j<=W;j++){
				if(i==1||i==H)
					putchar('#');

				else if(j==1||j==W)
					putchar('#');
				else
					putchar('.');

				
			}

			putchar('\n');

		}

		putchar('\n');

	}

	return 0;


}


Measured memory_bytes: 2040
def main():
    n = int(input())
    l = list(map(int, input().split()))
    
    l.sort()
    
    x = 0
    for i in range(n):
        x += min(l[2*i], l[2*i+1])
        
    print(x)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define getbit(n, i) (((n) & (1LL << (i))) != 0) 
#define setbit0(n, i) ((n) & (~(1LL << (i)))) 
#define setbit1(n, i) ((n) | (1LL << (i))) 
#define togglebit(n, i) ((n) ^ (1LL << (i))) 
#define lastone(n) ((n) & (-(n))) 
char gap = 32;
template<typename T> 
ostream& operator<<(ostream &os, const vector<T> &v) { 
    os << '{'; 
    for (const auto &x : v) os << gap << x;
        return os << '}'; 
}
template<typename A, typename B> 
ostream& operator<<(ostream &os, const pair<A, B> &p) {
        return os << '(' << p.first << gap << p.second << ')';
}

template <class T>
void read(T &x) {
    char c;
    for (c = getchar(); c < '0' || c > '9'; c = getchar())
        ;
    for (x = 0; c <= '9' && c >= '0'; c = getchar()) x = x * 10 + (c & 15);
}
#define ll long long 
#define lll __int128_t
#define pb push_back
#define mp make_pair
typedef pair < int,int> ii;
typedef vector<ii> vii;
typedef vector<ll>vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll hashPrime = 1610612741;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll x, n, i, j, k, l;
    cin >> x >> n;
    vector<ll> data(1000,0);
    for (i = 1; i <= n;i++){
        cin >> k;
        data[k] = 1;
    }
    ll mindis = 1e9;
    ll minnum;
    for (i = -2; i <= 105;i++){
        if(i<0||data[i]==0){
            if(abs(x-i)<mindis){
                mindis = abs(x - i);
                minnum = i;
            }
        }
    }
    cout << minnum;
    return 0;
}

Measured memory_bytes: 3664
#include <stdio.h>
int main(void){
   int i, j,H,W;
   while(scanf("%d %d",&H,&W)!=EOF){
    if(H==0&&W==0){
        break;
    }
    for ( i = 0; i < H; i++ ){
    for ( j = 0; j < W; j++ ){
        if((j+i)%2){
            printf(".");
        } else {
            printf("#");
        }
    }
    printf("\n");
}
    printf("\n");
}
 return(0);// Your code here!
    
}


Measured memory_bytes: 2140
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	double a,b,c,d; cin >> a >> b >> c >> d;
	printf("%.8f\n",sqrt((a-c)*(a-c)+(b-d)*(b-d)));
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i += 2) {
        int divs = 0;
        for(int j = 1; j <= n; j++) {
            divs += i % j == 0;
        }
        ans += divs == 8;
    }
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

bool f(vector<ll> &a) {
  int N = (int)a.size();
  if (*max_element(ALL(a)) < N)
    return false;
  REP(i, N) a[i]++;
  *max_element(ALL(a)) -= (N+1);
  return true;
}

void rev(vector<ll> &a) {
  int N = (int)a.size();
  REP(i, N) a[i]--;
  *min_element(ALL(a)) += (N+1);
}

void print(const vector<ll> &a) {
  int N = (int)a.size();
  cout << N << endl;
  REP(i, N) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

int main2() {
  ll K; cin >> K;
  int N = 50;
  vector<ll> a(N, N-1);
  REP(i, N) a[i] += K/N;
  REP(_, K % N) {
    rev(a);
  }

  print(a);

  // if (K <= 100) {
    // ll count = 0;
    // while (f(a)) {
      // count++;
      // print(a);
    // }
    // cout << "check=" << count << endl;
  // }
  
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


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

using namespace std;

#define forn(i, s, f) for(int i = (s); i <= (f); ++i)
#define for1(i, f, s) for(int i = (f); i >= (s); --i)
#define fora(i, x) for (auto i : x)
#define show(x) cout << #x << " = " << x << " ";
#define skip continue;
#define pb push_back
#define _1 first
#define _2 second

typedef long long ll;

const int N3 = 1e3 + 5;
const int N4 = 1e4 + 5;
const int N5 = 1e5 + 5;
const int N6 = 1e6 + 5;
const int N7 = 1e7 + 5;
const int N8 = 1e8 + 5;
const int N9 = 1e9 + 5;
const int mod = N9 + 2;

#define int ll

int n, res, a[N5], b[N5], x;

main()
{
    cin >> n;
    forn (i, 1, n)
    {
        cin >> a[i] >> b[i];
    }
    for1 (i, n, 1)
    {
        a[i] += res;
        res += ((a[i] + b[i] - 1) / b[i]) * b[i] - a[i];
    }
    cout << res;
}


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

int main() {
	int n;
	cin >> n;
	string c;
	cin >> c;
	vector<int> w(n + 1), r(n + 1);
	rep(i, n) {
		if (c[i] == 'W') w[i + 1] = w[i] + 1;
		else w[i + 1] = w[i];
		if (c[i] == 'R') r[i + 1] = r[i] + 1;
		else r[i + 1] = r[i];
	}
	int mn = 1e8;
	rep(i, n + 1) {
		int wn = w[i] - w[0];
		int rn = r[n] - r[i];
		mn = min(mn, max(wn, rn));
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int dx[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dy[] = {0, 1, 1, 1, 0, -1, -1, -1};

const int INF = 1<<30;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> x(n, 0);
    rep(i,n) cin >> x[i];
    int ans = INF;
    rep(i,n){
        if (i + k - 1 == n) break;
        int l = i;
        int r = i+k-1;
        int t1 = abs(x[l]) + abs(x[r] - x[l]);
        int t2 = abs(x[r]) + abs(x[r] - x[l]);
        ans = min(ans, min(t1, t2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3724
'use strict';
var data = '';
process.stdin.on('end', function() {
    var inputs = data.toString().trim().split('\n');
    var params = inputs[1].split(' ').map(Number);
    var sum = params.reduce(function(a,b) {
      return a + b;
    });
    var min = params[0];
    var max = params[0];
    for (var i = 0; i < params.length; i++) {
      min = Math.min(min,params[i]);
      max = Math.max(max,params[i]);
    }
  
    console.log(min, max, sum);
  
});
  
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  data += chunk;
});

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

#define N 26

int main() {
    using namespace std;
    string str;
    cin >> str;
    int i, a[N] = {};
    for(i=0; i<str.size(); ++i) {
        ++a[str[i]-'a'];
    }
    for(i=0; i<N; ++i) {
        if(a[i] == 0) {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }

    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);
  rep(i, N) {
    cin >> A[i];
  }
  rep(i, N) {
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  long long ans = 1;
  rep(i, N) {
    if (A[i] <= 1000000000000000000 / ans) {
      ans = ans * A[i];
    }
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4052
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x,it) for(auto it = x.begin();it!=x.end();++it)
#define fpresent(x,c) ((c).find(x) != (c).end())  //set,map
#define present(c,x) (find(all(c),x) != (c).end()) //vector
#define pb push_back 
#define mp make_pair
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

int main()
{
    // freopen("input.in","r",stdin);
    // freopen("output.in","w",stdout);
    fastio;
    cin.tie(NULL);
    ll n,m,i,j,k,ans=0;
    cin>>n>>k;

    vector<ll> h(n), dp(n, M);

    dp[0] = 0;
    for(i=0;i<n;i++)
        cin>>h[i];

    for(i=1;i<n;i++){
        for(j=1;j<=k;j++){
            dp[i] = min(dp[i], dp[max(0LL, i-j)] + abs(h[i] - h[max(0LL, i-j)]));
        }
    }

    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1792
s = input()

wordCount = 1
i = 1
prevWord = s[0]
nextWord = ''
while i < len(s):
  nextWord += s[i]
  i += 1
  if prevWord == nextWord:
    continue
  else:
    prevWord = nextWord
    nextWord = ''
    wordCount += 1

print(wordCount)

Measured memory_bytes: 41692
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }

ll mod = 1000000007;
ll modsize;

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

ll modpow(ll a, ll b) {
	ll ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = ans * a%mod;
		a = a * a%mod;
		b >>= 1;
	}
	return ans;
}

vector<ll> fac(modsize + 5);
vector<ll> inv(modsize + 5);
vector<ll> facinv(modsize + 5);

void modcalc() {
	fac[0] = fac[1] = 1; inv[1] = 1;
	facinv[0] = facinv[1] = 1;
	for (int i = 2; i < modsize; i++) {
		fac[i] = fac[i - 1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod / i) % mod;
		facinv[i] = facinv[i - 1] * inv[i] % mod;
	}
}

ll modcomb(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[k] % mod * facinv[n - k] % mod;
}

ll modperm(ll n, ll k) {
	if (n < 0 || k < 0 || n < k) return 0;
	return fac[n] * facinv[n - k] % mod;
}

ll modhom(ll n, ll k) {
	if (n < 0 || k < 0) return 0;
	if (n == 0 && k == 0) return 1;
	return modcomb(n + k - 1, k);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	//modcalc();

	int h, w, t;
	cin >> h >> w >> t;
	int ht = gcd(h, t); int wt = gcd(w, t);
	int c = ht * wt % (mod - 1);
	int cnt = (modpow(2, h / ht) + modpow(2, w / wt) - 1) % mod;
	int g = gcd(h / ht, w / wt);
	cnt += modpow(2, g) - 2;
	if (cnt < 0) cnt += mod;
	cout << modpow(cnt, c) << endl;
}


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

int main ()
{
    int a, b, c;
    int sq = 0, dy = 0;

    while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
        if (a == b && a*a + b*b == c*c) {
        } else if (a != b && a*a + b*b == c*c) {
            sq++;
        } else if (a != b && a*a + b*b != c*c) {
        } else {
            dy++;
        }
    }
    cout << sq << endl << dy << endl;

    return 0;
}

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

int main(){
  int i,j,n,ans=0;
  cin >> n;
  int a[2][n];
    for(j=0;j<n;j++){
      cin >> a[0][j];
      a[0][j]+=ans;
      ans=a[0][j];
    }
    cin >> a[1][0];
    a[1][0]+=a[0][0];
    for(i=1;i<n;i++){
      cin >> a[1][i];
      ans = max(a[0][i],a[1][i-1]);
      a[1][i]+=ans;
    }
    /*for(i=0;i<2;i++){
      for(j=0;j<n;j++){
        cout << a[i][j] << " ";
      }
      cout << endl;
    }*/
    cout << a[1][n-1] << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from collections import deque

def main():
    N,M = map(int,input().split())
    G = [[] for _ in range(N)]
    for _ in range(M):
        a,b = map(int,input().split())
        a -= 1
        b -= 1
        G[a].append(b)
        G[b].append(a)
    
    dist = [-1] * N
    before = [-1] * N
    dist[0] = 0
    q = deque([0])
    while q:
        v = q.popleft()
        for e in G[v]:
            if dist[e] >= 0:
                continue
            dist[e] = dist[v] + 1
            before[e] = v + 1
            q.append(e)
    flag = True
    for i in range(N):
        if dist[i] < 0:
            flag = False
            break

    if flag:
        print('Yes')
        print('\n'.join(map(str,before[1:])))
    else:
        print('No')
if __name__ == '__main__':
    main()



Measured memory_bytes: 45484
N = int(input())
S = input()
WPrefix = [0]
RSuffix = [0]
for elem in S:
    if elem == "R":
        RSuffix[0] += 1
for elem in S:
    if elem == "R":
        RSuffix.append(RSuffix[-1] - 1)
        WPrefix.append(WPrefix[-1])
    else:
        RSuffix.append(RSuffix[-1])
        WPrefix.append(WPrefix[-1] + 1)
minSwap = len(S)
for index in range(len(RSuffix)):
    if max(RSuffix[index],WPrefix[index]) < minSwap:
        minSwap = max(RSuffix[index],WPrefix[index])
print(minSwap)


Measured memory_bytes: 95668
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

H, W = rl()
M = []
for i in range(H):
    row = rs()
    M.append(row)

import collections
def get_dist(i, j):
    visited = {}
    queue = collections.deque()
    queue.append((i,j,0)) 
    max_l = 0
    while queue:
        i, j, l = queue.popleft()
        if (i,j) in visited: continue
        max_l = max(max_l, l)
        visited[(i,j)] = 1
        for di, dj in [(1,0), (-1,0), (0,1), (0,-1)]:
            ni, nj = i+di, j+dj
            if 0 <= ni < H and 0 <= nj < W and M[ni][nj] != '#':
                queue.append((ni,nj,l+1))
    return max_l

max_move = 0
for i in range(H):
    for j in range(W):
        if M[i][j] == '#': continue
        d = get_dist(i, j)
        max_move = max(max_move, d)
print(max_move)


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

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

	vector<int> h(n);
	vector<int> idou;

	rep(i, n) {
		cin >> h[i];
	}

	int idoulen = 0;
	idou.push_back(0);
	rep(i, n-1) {
		if (h[i] >= h[i + 1]) {
			idou[idoulen] += 1;
		} else {
			idoulen += 1;
			idou.push_back(0);
		};
	}

	sort(idou.begin(), idou.end());
	cout << idou[idoulen] << endl;
	return 0;
}

Measured memory_bytes: 1276
num1, num2, num3 = input().split(" ")
numList = [int(num1),int(num2),int(num3)]
numList.sort(reverse=True)
maxNum = numList[0]
midNum = numList[1]
minNum = numList[2]

count = 0

if midNum % 2 == 0 and minNum % 2 == 0:
    count += (midNum - minNum) // 2
    count += (maxNum - midNum)
elif midNum % 2 == 1 and minNum % 2 == 1:
    if maxNum % 2 == 0:
        maxNum += 2
        midNum += 2
        midNum += 2
        count += (midNum - minNum) // 2
        count += (maxNum - midNum)
        count += 2
    else:
        count += (midNum - minNum) // 2
        count += (maxNum - midNum)
else:
    if midNum % 2 == 0:
        maxNum += 1
        minNum += 1
        count += (midNum - minNum) // 2
        count += (maxNum - midNum)
        count += 1
    else:
        maxNum += 1
        midNum += 1
        count += (midNum - minNum) // 2
        count += (maxNum - midNum)
        count += 1
print(count)



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

struct node
{
	int f,t;
} t[1000000];

long long a[1000000],size[1000000],id[1000000],hh[1000000],h,tot;
map<long long,int>mp;

void add(long long x,long long y)
{
	t[++h].f=hh[x];
	t[h].t=y;
	hh[x]=h;
}

int cmp(int x,int y)
{
	return a[x]>a[y];
}

void dfs(int x,int y,int z)
{
	tot+=z;
	for(int i=hh[x];i;i=t[i].f)
	{
		int j=t[i].t;
		if(j==y) 
			continue;
		dfs(j,x,z+1);
	}
}

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) 
	{
		scanf("%lld",a+i);
		mp[a[i]]=i;
		size[i]=1;
		id[i]=i;
	}
	sort(id+1,id+1+n,cmp);
	for(int i=1;i<n;i++)
	{
		long long x=id[i],y=a[x]-(n-size[x])+size[x];
		if(!mp[y]||y>=a[x]) 
		{
			printf("-1\n");
			return 0;
		}
		y=mp[y];
		add(x,y);
		add(y,x);
		size[y]+=size[x];
	}
	dfs(id[n],0,0);
	if(tot!=a[id[n]]) 
	{
		printf("-1\n");
		return 0;
	}
	for(int i=1;i<=n;i++)
		for(int j=hh[i];j;j=t[j].f)
			if(t[j].t>i) 
				printf("%d %d\n",i,t[j].t);
	return 0;
}


Measured memory_bytes: 25088
#!/usr/bin/env python3

# from numba import njit

# from collections import Counter
# from itertools import accumulate
# import numpy as np
# from heapq import heappop,heappush
# from bisect import bisect_left

YEAR = 2019
INF = 10**8

def calcMod(x,y):
  return x*y % YEAR

# @njit
def solve(l,r):
  ans = INF
  if r - l > YEAR:
    r = l + YEAR
  for i in range(l,r):
    for j in range(i+1,r+1):
      ans = min(ans,calcMod(i,j))

  return ans



def main():
  L,R = map(int,input().split())
  print(solve(L,R))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9136
#pragma GCC optimize(2)
#include<bits/stdc++.h> 
using namespace std;
#define ll long long
#define endl "\n"
const int MAX=1e6+7;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
	ll n,ans=0;cin>>n;
	for(ll i=1;i<=n;i++){
		ans+=n/i;
		if(n/i*i==n)ans--;
	}
	cout<<ans;
   return 0;
} 

Measured memory_bytes: 3680
def multi(a, b) :
    if a == 0 :
        return 0
    elif a == 1 :
        if b == 0 :
            return 0
        else :
            return 1
    else :
        return b

def add(a, b) :
    if a == 0 :
        return b
    elif a == 1 :
        if b == 2 :
            return 2
        else :
            return 1
    else :
        return 2

def minus(a) :
    return (2 - a)

def calc(l) : # '('、')'のない計算式
    l = list(l)
    
    #'-'を計算
    i = len(l)-1
    while True :
        if i < 0 :
            break
        if l[i] == '-' :
            print
            l[i] = str(minus(int(l[i+1])))
            del l[i+1]
        i -= 1 
        
    #'*'を計算
    i = 0
    while True :
        if i >= len(l) :
            break
        if l[i] == '*' :
            l[i-1] = str(multi(int(l[i-1]), int(l[i+1])))
            del l[i:i+2]
        else :
            i += 1
    
    #'+'を計算
    i = 0
    while True :
        if i >= len(l) :
            break
        if l[i] == '+' :
            l[i-1] = str(add(int(l[i-1]), int(l[i+1])))
            del l[i:i+2]
        else :
            i += 1
    return ''.join(l)
    

        
            
def main(l) :
    l = list(l)
    while '(' in l :
        for i in range(len(l)) :
            if l[i] == '(' :
                start = i
            elif l[i] == ')' :
                A = ''.join(l[start+1:i])
                del l[start:i+1]
                l.insert(start, calc(A))
                break
    if len(l) != 1 :
        l = calc(l)
    return ''.join(l)

while True :
    input_l = input()
    if input_l == '.' :
        break
    
    cnt = 0
    for p in ['0', '1', '2'] :
        for q in ['0', '1', '2'] :
            for r in ['0', '1', '2'] :
                l = input_l
                if 'P' in l :
                    l = l.replace('P', p)
                if 'Q' in l :
                    l = l.replace('Q', q)
                if 'R' in l :
                    l = l.replace('R', r)
                if main(l) == '2' :
                    cnt += 1
    print(cnt)
    



Measured memory_bytes: 5624
#!/usr/bin python3
# -*- coding: utf-8 -*-

#######################################################################
# ナップサック
# 重さ：Wー10**5くらい
# 価値：N*max_Viー10**11くらい
# dp[w]:wの重さで可能な最大の価値
#   dp[w]とdp[w-wi]+vi(i番目のアイテムをとる場合)との大きいほうで更新
#######################################################################

n, t = map(int, input().split())
dp = [0] * (t+1)
itm = [list(map(int, input().split())) for _ in range(n)]
itm.sort()
for w_ , v_ in itm:
    for i in range(1,t+1):
        dp[max(0,i-w_)] = max(dp[max(0,i-w_)], dp[i] + v_)
print(dp[0])


Measured memory_bytes: 74968
s = list(input())
s.pop()
if len(s) % 2 !=0:
    s.pop()

while len(s) != 0 :
    if len(s)%2 == 0 and s[:len(s)//2]==s[len(s)//2:]:
        print(len(s))
        break
    else:
        s.pop()

Measured memory_bytes: 3060
#include <algorithm>/*{{{*/
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define FOR(i, b, e) for (typeof(b) i = (b); assert((i) <= (e)), i != (e); ++i)
#define SZ(a) ((int)a.size())
#define PB(e) push_back(e)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(),(v).rend())
#define F first
#define S second
#define MP(a, b) make_pair(a, b)
#define BIT(n) (1ULL << (n))

static const double PI (3.14159265358979323846);
static const double EPS (1e-10);

using namespace std;
typedef long long int LL;
typedef pair<int,int> P;/*}}}*/

#define MAX_N 100
#define INF (LONG_MAX / 10)
int n, m, s, g1, g2;
LL dist[MAX_N][MAX_N];
int main(int argc, char const* argv[])
{
	while(cin >> n >> m >> s >> g1 >> g2, n || m || s || g1 || g2) {
		--s; --g1; --g2;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (i == j) {
					dist[i][j] = 0;
				} else {
					dist[i][j] = INF;
				}
			}
		}
		for (int i = 0; i < m; i++) {
			int a, b, c; cin >> a >> b >> c; --a; --b;
			dist[a][b] = c;
		}
		for (int k = 0; k < n; k++) {
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < n; j++) {
					dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
				}
			}
		}

		LL ans = INF;
		for (int div = 0; div < n; div++) { // where to divide
			LL cost = dist[s][div] + dist[div][g1] + dist[div][g2];
			ans = min(ans, cost);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 944