akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);

int N, H, W;
int a[10000];
int m[100][100];

int main() {
	cin >> H >> W;
	cin >> N;
	rep(i, N) cin >> a[i];

    int i = 0;
	for(int y = 0; y < H; y++){
		if(y % 2 == 0){
			for(int x = 0; x < W; x++){
				m[y][x] = i;
				a[i]--;
				if(a[i]==0) i++;
			}
		}
		else{
			for(int x = W-1; x >= 0; x--){
				m[y][x] = i;
				a[i]--;
				if(a[i]==0) i++;
			}
		}
	}

	rep(y, H) {
		rep(x, W){
			cout << m[y][x]+1;
			if(x < W-1) cout << " ";
			else cout << endl;
		}
	}
}

Measured memory_bytes: 384
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      	int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();      
      	
      
      	if(a <= b && a <= c && c <= b){
          System.out.println("Yes");
          return;
        }else if(b <= a && b <= c && c <= a){
          System.out.println("Yes");
          return;          
        }
      
          System.out.println("No");
      
    }
}

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

int main(){
 int D; cin >>D;
cout << "Christmas" << " ";
int E; E = 25 - D;
if(E == 0){
        cout << endl;
        }
else{
    for(int i = 0; i < E; i++){
        
       cout << "Eve" << " ";
    }
cout << endl;
    return 0;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
int main ( void ) {
 
	int n, m;
	std::cin >> n >> m;
 
	std::vector < std::string > data( n );
	for ( std::string& str : data ) {
		std::cin >> str;
	}
 
	sort ( data.begin(), data.end() );
	for ( const std::string& str : data ) {
		std::cout << str;
	}
	std::cout << std::endl;
 
	return 0;
}

Measured memory_bytes: 3660
#include<stdio.h>
#include<stdbool.h>
bool p[] = {[2 ... 1<<20] true};
int X;
int main(){
	for(int i=2; i<1<<20; i++){
		if(p[i]){
			for(int j=2*i; j<1<<20; j+=i){
				p[j] = false;
			}
		}
	}
	scanf("%d", &X);
	while(!p[X++]);
	printf("%d\n", --X);
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define Graph vector<vector<ll>>
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
 
int main(){
	ll n,x,y;cin>>n>>x>>y;
	x--;y--;
	Graph G(n);

	rep(i,n-1){
		G[i].push_back(i+1);
		G[i+1].push_back(i);
	}

	G[x].push_back(y);
	G[y].push_back(x);

	vector<ll> ans(n,0);
	queue<ll> que;
	rep(i,n){
		que.push(i);

		vector<ll> dist(n,0);
		vector<bool> visit(n,false);

		while(que.size()!=0){
			ll now=que.front();
			que.pop();
			visit[now]=true;

			for(auto next:G[now]){
				if(visit[next]==true) continue;

				visit[next]=true;
				que.push(next);
				dist[next]=dist[now]+1;
			}
		}

		rep(j,n){
			ans[dist[j]]++;
		}
	}

	rep(i,n){
		if(i!=0) cout<<ans[i]/2<<endl;
	}

	return 0;
}

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

int main(){
	int x,N;
	cin>>N;
	x=N;
	int fx=0;
	
	while(N>0){
		fx+=N%10;
		N/=10;
	}
	
	if(x%fx==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	
	return 0;
}

Measured memory_bytes: 256
<?php
  $a = str_split(trim(fgets(STDIN)));
if($a[0]==$a[1] && $a[1]==$a[2]){
  echo 'Yes';
}elseif($a[2]==$a[3] && $a[1]==$a[2]){
  echo 'Yes';
}else{
  echo 'No';
}

Measured memory_bytes: 3576
// ABC061_C
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <tuple>  // std::tuple std::get
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define REPN(i, n) for (ll i=1; i <= n; i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0LL)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
#define zero_pad(num) setfill('0') << std::right << setw(num)
#define space_pad(num) setfill(' ') << std::right << setw(num)

typedef long long ll;

const ll MOD7 = 1000000007;  // 1 000 000 007
const ll MOD9 = 1000000009;  // 1 000 000 009

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

    // input
    ll N, K, a, b;
    cin >> N >> K;
    vector<ll> num(100000+1, 0);
    REP(i, N) {
        cin >> a >> b;
        num[a] += b;
    }
    
    // 各数が何個あるかの累積和
    vector<ll> partial;
    COPY(num, partial);  // copy vec to partial
    partial_sum(num.begin(), num.end(), partial.begin());
    
    // K 個以上となる最小のインデックスを求める
    auto iter = lower_bound(partial.begin(), partial.end(), K);
    cout << IDX(partial, iter) << "\n";
    
    return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
typedef long long ll;
const int mod = 1e9+7;
ll powe(int a, int b) {
	if(b == 0) return 1;
	ll ret = powe(a, b/2)%mod;
	ret = ((ret%mod)*(ret%mod))%mod;
	if(b % 2 == 1) {
		ret = ((ret%mod)*(a%mod))%mod;
	}
	return ret%mod;
}
int main() {
	int n;
	cin >> n;
	if(n == 1) {
		cout<<0;
		return 0;
	} else if(n == 2) {
		cout<<2;
		return 0;
	}
	ll x = powe(10,n)%mod;
	ll a = (2*powe(9,n))%mod;
	ll b = powe(8,n)%mod;
	ll ans = x - a + b;
	if(ans <= 0) ans += mod;
	cout<<ans%mod;
}


Measured memory_bytes: 3640
#include<stdio.h>
#include<math.h>

int main(){
  int N; 
  scanf("%d",&N);
  char str[N];
  scanf("%s",&str);
  
  int cnt = 0;
  if(N % 2 == 1){
    printf("No");
    cnt = 1;  
  }
  else{
  	for(int i = 0;i < N/2 ; i++){
  	  if(strncmp(&str[i],&str[i+N/2],1)!=0){
			printf("No");
        	cnt = 1;
       		break;
  	   } 
     }
  }
  if(cnt != 1)
	  printf("Yes");

  return 0;
}

Measured memory_bytes: 128
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val m = sc.nextInt()
    val t = (1..n).map { Pair(sc.nextLong(), sc.nextLong()) }.sortedBy { it.first }

    var ans = 0L
    var sumB = 0L
    for (i in t.indices) {
        val add = Math.min(t[i].second, m - sumB)
        sumB += add
        ans += add * t[i].first
    }
    println(ans)
}

Measured memory_bytes: 118648
#include <bits/stdc++.h>
#define H ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
using namespace std;
const ll  mod = 998244353;


int main()
{
    H
    int x, y ,z , k;
    cin >> x >> y >> z >> k;
    ll a[x], b[y], c[z];
    vector<ll> v, ans;
    for (int i = 0; i < x; i++) cin >> a[i];
    for (int i = 0; i < y; i++) cin >> b[i];
    for (int i = 0; i < z; i++) cin >> c[i];
    for (int i = 0; i < x; i++){
        for (int j = 0; j < y; j++){
            v.push_back(a[i] + b[j]);
        }

    }
    sort(v.rbegin(), v.rend());
    for (int i = 0; i < min(k, (int)v.size()); i++){
        for (int j = 0; j < z; j++){
            ans.push_back(v[i] + c[j]);
        }
    }
    sort(ans.rbegin(), ans.rend());
    for (int i = 0; i < k; i++){
        cout << ans[i] << '\n';
    }

    return 0 ;
}


Measured memory_bytes: 43236
A = input()
B = input()
C = input()

d = {'a':A, 'b':B, 'c':C}
ind =  {'a':0, 'b':0, 'c':0}
leng = {'a':len(A), 'b':len(B), 'c':len(C)}

turn = 'a'

while True:
    if ind[turn] == leng[turn]:
        break
    next_turn = d[turn][ind[turn]]
    ind[turn] += 1
    turn = next_turn
    
print(turn.upper())

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

int main() {
  
  while (1) {

    int n, nmin, nmax, x;
    vector<int> vc;

    cin >> n >> nmin >> nmax;
    if (n == 0 && nmin == 0 && nmax == 0) break;

    for (int i = 0; i < n; i++) {
      cin >> x;
      vc.push_back(x);
    }

    sort(vc.begin(), vc.end());
    reverse(vc.begin(), vc.end());

    int gap = 0;
    int ans = 0;

    for (int i = nmin - 1; i < nmax; i++) { 
      int tmp = vc[i] - vc[i + 1];
      if (tmp >= gap) {
        gap = tmp;
        ans = i + 1;
      }
    }

    cout << ans << endl;
  }
}



Measured memory_bytes: 3136
import sys
from fractions import gcd
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    N = ii()
    A = list(mi())

    L = [0]*N
    R = [0]*N
    L[1] = A[0]
    R[N-2] = A[N-1]

    M = [0]*N

    for i in range(N-2):
        L[i+2] = gcd(L[i+1], A[i+1])
    for i in range(N-2, 0, -1):
        R[i-1] = gcd(R[i], A[i])

    for i in range(N):
        if L[i] == 0:
            M[i] = R[i]
        elif R[i] == 0:
            M[i] = L[i]
        else:
            M[i] = gcd(R[i], L[i])
    
    print(max(M))



if __name__ == '__main__':
    main()


Measured memory_bytes: 96800
S=input()
ans=0
i=0
while i < len(S):
  #print(i)
  if i==0:
    pre=S[i]
    ans+=1
  else:
    if pre==S[i]:
      if i==len(S)-1:
        break
      else:
        pre=S[i]+S[i+1]
        i+=1
        ans+=1
    else:
      pre=S[i]
      ans+=1
  i+=1
  #print(pre)
print(ans)

Measured memory_bytes: 3500
S = input()

if S[0] == S[-1]:
    C1 = True
else:
    C1 = False

if len(S) % 2 == 1:
    C2 = True
else:
    C2 = False

if C1 ^ C2 == 0:
    print('Second')
else:
    print('First')


Measured memory_bytes: 3316
from collections import deque

def bfs():
    flag = False
    d = [[float('inf')] * W for i in range(H)]
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]

    que = deque([])
    que.append((0, 0))
    d[0][0] = 0

    while que:
        p = que.popleft()
        if p[0]==H-1 and p[1]==W-1:
            flag = True
            break

        for i in range(4):
            nx = p[1] + dx[i]
            ny = p[0] + dy[i]

            if 0<=nx<W and 0<=ny<H and maze[ny][nx]!='#' and d[ny][nx]==float("inf"):
                que.append((ny, nx))
                d[ny][nx] = d[p[0]][p[1]] + 1

    if flag==False:
        return False

    return d[H-1][W-1]

def notcount(H, W, maze):
    cnt = 0

    for i in range(H):
        for j in range(W):
            if maze[i][j]=='#':
                cnt += 1

    return cnt

H, W = map(int, input().split())
maze = [list(input()) for i in range(H)]
if bfs()==False:
    print(-1)
else:
    s = (H * W - notcount(H, W, maze)) - (bfs() + 1)
    #bfs()
    print(s)


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

int main(void){
	int a,b,c;
	int count = 0;

	cin >> a >> b >> c ;

	for ( int i = a ; i <= b ; i++ ) {
		if ( c % i == 0 ) count++;
	}

	cout << count << endl;
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string str; cin >> str;
  set<int> s = {'A', 'C', 'G', 'T'};
  int ans = 0, cnt = 0;
  for (auto &i : str) {
    if (s.count(i)) cnt++; else cnt = 0;
    ans = max(ans, cnt);
  }
  cout << ans << '\n';
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
string s[1003];
int dp[1003][1003];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)cin>>s[i];
	for(int i=0;i<m&&s[0][i]=='.';i++)dp[0][i]=1;
	for(int i=0;i<n&&s[i][0]=='.';i++)dp[i][0]=1;
	for(int i=1;i<n;i++)
		for(int j=1;j<m;j++)
			if(s[i][j]!='#')
				dp[i][j]=(dp[i-1][j]+dp[i][j-1])%1000000007;
	cout<<dp[n-1][m-1];
}


Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


bool isPrime(ll n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    for (ll  i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

int main()
{
    ll n,i,j;
    cin>>n;
    ll arr[n];

    unordered_map<ll,ll>mp;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }

    ll ans=0;
    for(i=0;i<n;i++)
    {
        mp[arr[i]]--;
        if(mp[arr[i]]==0)
        {
            mp.erase(arr[i]);
        }
        ll x = arr[i];
        ll flag=0;

        for(j=1;j<=sqrt(x);j++)
        {
            if(x%j==0)
            {
                ll p = x/j , q = j;
                if(mp.find(p)!=mp.end() || mp.find(q)!=mp.end())
                {
                    flag=1;
                    break;
                }
            }
        }
        if(flag==0)
        {
            ans++;
        }
        mp[arr[i]]++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12952
h=int(input())
if h==1:
    print(1)
else:
    num=1
    while 2**num<=h:
        num+=1
    #print(num) #グループのチェック
    ans=1
    num2=1
    for i in range(num-1):
        ans+=(2**num2)
        num2+=1
    print(ans)

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

int  i,j,k,h,w,a,b,c,d,x,y,z,ret;
int main(void){
	cin>>a>>b>>c;
	cout<<a*b*c/max({a,b,c})/2;
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
 class Main {
 public static void main(String[] args) throws IOException {
 BufferedReader br;
 br=new BufferedReader(new InputStreamReader(System.in));
String target=br.readLine();
//Scanner sc = new Scanner(br);
String[] moji = target.split(" ", 0);
int maisu = Integer.parseInt(moji[0]); 
int high = Integer.parseInt(moji[1]);
int wid = Integer.parseInt(moji[2]);
//List<String> kumi = new ArrayList<>();
int count = 0;
for (int i = 0 ; i < maisu ; i++){
      String line = br.readLine();
String[] awase = line.split(" ", 0);
int tate = Integer.parseInt(awase[0]); 
int yoko = Integer.parseInt(awase[1]);
if( tate >= high && yoko >= wid) {count++;}


    }
System.out.println(count);
 }
}

Measured memory_bytes: 22996
N,M = map(int,input().split())
L = [[] for _ in range(M)]
for i in range(M):
  L[i] = list(map(int,input().split()))
  L[i].remove(L[i][0])
P = list(map(int,input().split()))
Cand = []
for i in range(2**N):
  res = []
  for j in range(N):
    if ((i>>j) & 1):
      res.append(1)
    else:
      res.append(0)
  Cand.append(res) 
res = 0
for i in range(2**N):
    key = 0
    loop = 0
    for j in range(M):
        loop = 1
        if P[j] == 0:
            Even_counter = 0
            for el in L[j]:
                if Cand[i][el-1] == 1:
                    Even_counter += 1
            if Even_counter % 2 != 0:
                key = 1
                break
        if P[j] == 1:
            Od_counter = 0
            for el in L[j]:
                if Cand[i][el-1] == 1:
                    Od_counter += 1
            if Od_counter % 2 != 1:
                key = 1
                break           
        if key == 0 and j == M-1 and loop == 1:
            res += 1    
print(res)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = (n) - 1; i >= 0; i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define devec(a,n) { cout << #a << " = "; rep(_,n) cout << a[_] << ' '; cout << '\n'; }
#define all(ar) ar.begin(), ar.end()
#define rall(ar) ar.rbegin(), ar.rend()
#define sz(x) ((long long)x.size())
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define mp make_pair
#define ff first
#define ss second
#define MOD 1000000007
 
auto clk=clock();
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll INF = 1e18L+5;
const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};
 
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vi;
typedef vector<int> vint;
typedef vector<string> vs;
typedef vector<vi> vvi;

ll gcd(ll a, ll b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void solve(){
    int n;
    cin>>n;
    int d[n][2];
    rep(i,n)cin>>d[i][0]>>d[i][1];
    fr(i,2,n-1){
        if(d[i][0]==d[i][1]&&d[i-1][0]==d[i-1][1]&&d[i-2][0]==d[i-2][1]){
            cout<<"Yes\n";
            return;
        }
    }
    cout<<"No\n";
}
 
int main (){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout<<setprecision(11);
 
    ll t = 1;
    // cin>>t;
    while(t--){
        solve();
    }
 
    // cout<<endl<<endl<<"Time elapsed: "<<((double)(clock()-clk)/CLOCKS_PER_SEC)*1000<<"ms"<<endl;
    return 0;
}

Measured memory_bytes: 3656
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

used = 0
rainbow = 0
for ai in a:
    for i in range(8):
        if ai < 400 * (i + 1):
            used = used | (2 ** i)
            break
        else: continue
    else: rainbow += 1

ans = 0
for i in range(8):
    if used & (2 ** i) > 0: ans += 1

print(max(1, ans), ans + rainbow) # oh...

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
#include <map>
#include <unordered_map>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <limits.h>
#include <tgmath.h>

using namespace std;

typedef uint16_t ui16;
typedef uint32_t ui32;
typedef uint64_t ui64;
typedef int16_t i16;
typedef int32_t i32;
typedef int64_t i64;
typedef long double ld;
typedef pair<int, int> pr;

//template<typename T> inline T abs(T a) { return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a) { return a * a; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) {for (int i = 0; i < v.size(); ++i) cout << v[i] << " "; cout << endl; return cout; }
void print() { cout << endl; }
template<typename T, typename... Ts> void print(T x, Ts... xs) { cout << x << " "; print(xs...); };
template<typename T> void read(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cin >> v[i]; };

int main() {
    ui32 N, K;
    cin >> N >> K;
    vector<int> h(N + 1, 0);
    for (int i = 1; i <= N; ++i) {
        cin >> h[i];
    }

    vector<int> dp(N + 1);
    dp[0] = 0;
    dp[1] = 0;

    for (int i = 2; i <= N; ++i) {
        dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
        for (int k = 2; k <= K; ++k) {
            if (i > k) {
                dp[i] = min(dp[i], dp[i - k] + abs(h[i] - h[i - k]));
            }
        }
    }

    cout << dp[N];

    return 0;
}













Measured memory_bytes: 1024
n = int(input())
l = list(map(int, input().split()))
res = 'YES'
count = 0
for i in range( n):
	if l[i] >  i + 1:
		p = l[i] - 1
		if l[p] == i + 1:
			l[i] = i
			l[p] = p + 1
			count += 1
			if count > 1:
				res = 'NO'
		else:
			res = 'NO'

print(res)
	

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define mp         make_pair
#define x first
#define y second

typedef pair<int,int> pii;

enum{N=0,E=1,S=2,W=3};
enum{RIGHT=1,LEFT=3,FRONT=0};
bool vis[200][200][4];
bool cango[200][200][4];


void setH(pii a1,pii a2,int r,bool fg){
  if (a1 > a2)swap(a1,a2);
  int i=a1.y;
  REP(j,a1.x,a2.x){
    if (i-1>=0)cango[i-1][j][N]=fg;
    if (i<r)cango[i][j][S]=fg;
  }
}

void setV(pii a1,pii a2,int c,bool fg){
  if (a1 > a2)swap(a1,a2);
  int j=a1.x;
  REP(i,a1.y,a2.y){
    if (j-1>=0)cango[i][j-1][E]=fg;
    if (j<c)cango[i][j][W]=fg;
  }
}

int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int solve(int x,int y,int dir,int gx,int gy,int r,int c){
  int cnt=1;
  while(true){
    //cout << y <<" " << x <<" " << dir << endl;
    if (x<0||y<0||x==c||y==r||vis[y][x][dir])return -1;
    vis[y][x][dir]=true;
    if (x==gx && y == gy)return cnt;
    if (!cango[y][x][(dir+LEFT)%4]){
      dir=(dir+LEFT)%4;
      x+=dx[dir];
      y+=dy[dir];
      cnt++;
    }else if (cango[y][x][(dir+LEFT)%4] && !cango[y][x][dir]){
      x+=dx[dir];
      y+=dy[dir];
      cnt++;
    }else if (cango[y][x][(dir+LEFT)%4] && cango[y][x][dir]){
      dir=(dir+1)%4;
    }
  }
  return -1;
}


main(){
  int c,r,n;
  while(cin>>c>>r>>n &&c){
    rep(i,r)rep(j,c)rep(k,4)cango[i][j][k]=vis[i][j][k]=false;
    rep(i,n){
      pii a1,a2;
      cin>>a1.x>>a1.y>>a2.x>>a2.y;
      if (a1.x == a2.x)setV(a1,a2,c,true);
      else if (a1.y == a2.y)setH(a1,a2,r,true);
    }
    setV(mp(0,0),mp(0,r),c,true);
    setH(mp(0,0),mp(c,0),r,true);
    setH(mp(0,r),mp(c,r),r,true);
    setV(mp(c,0),mp(c,r),c,true);

    int sy,sx,dir;
    pii a1,a2;
    cin>>a1.x>>a1.y>>a2.x>>a2.y;
    if (a1 > a2)swap(a1,a2);
    if (a1.x==a2.x){
      setV(a1,a2,c,false);
      if (a1.x == 0)sx=a1.x,dir=E;
      else if (a1.x==c)sx=a1.x-1,dir=W;
      sy=a1.y;
    }else if (a1.y==a2.y){
      setH(a1,a2,r,false);
      if (a1.y == 0)sy=a1.y,dir=N;
      else if (a1.y == r)sy=a1.y-1,dir=S;
      sx=a1.x;
    }
    int gy,gx;
    cin>>gx>>gy;

//     rep(i,r){
//       rep(j,c){
//      cout << i <<" " << j <<" ";
//      rep(k,4)cout << cango[i][j][k];
//      cout << endl;
//       }
//     }
    int ans =solve(sx,sy,dir,gx,gy,r,c);
    //cout << sy <<" " << sx <<" " << dir << endl;
    if (ans == -1)cout <<"Impossible"<<endl;
    else cout << ans << endl;
  }
  return false;
}


/*
0 0 0101
0 1 0011
0 2 0110
1 0 0101
1 1 1101
1 2 0101
2 0 1001
2 1 1010
2 2 1100
0 0 0
1 0 0
2 0 0
2 0 1
2 1 1
2 2 1
3 2 0
Impossible
0 0 0101
0 1
2 2 1
3 2 0
Impossible
 */

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

int modSubtract(int a, int b){
  if(a>b) return a-b;
  else return b-a;
}  

int path(int h[], int n){
  int dp[n];
  if(n==2) return modSubtract(h[1], h[0]);
  dp[0]=0, dp[1] = modSubtract(h[1], h[0]);
  for(int i=2; i<n; i++){
    dp[i] = min(dp[i-1]+modSubtract(h[i], h[i-1]) , dp[i-2]+modSubtract(h[i], h[i-2]));
  }
  return dp[n-1];
}

int main(){
  int n;
  cin>>n;
  int h[n];
  for(int i=0; i<n; i++){
    cin>>h[i];
  }
  int val = path(h,n);
  cout<<val<<endl;
}

Measured memory_bytes: 4388
// I'm a f*cking looser
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fasino ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
#define input(A) for(auto &i:A) cin>>i;
signed main()
{
    fasino
    string A;
    cin>>A;
    int K = A.size();
    string J(A.begin(), A.begin()+(K-1)/2), G(min(A.begin(),A.begin()+((K+3)/2)-1), A.end());
    string revA(A.rbegin(),A.rend());
    string revJ(J.rbegin(),J.rend());
    string revG(G.rbegin(),G.rend());
    if(revA==A and revG==G and revJ == J) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3600
N, K = map(int, input().split())

cnt = {}
for _ in range(N):
    a, b = map(int, input().split())
    if a not in cnt:
        cnt[a] = b
    else:
        cnt[a] += b

cnt = [[k, v] for k, v in cnt.items()]
cnt.sort()

s = 0
ans = 0
for k, v in cnt:
    s += v
    if s < K:
        continue
    else:
        ans = k
        break

print(ans)


Measured memory_bytes: 58712
#include <bits/stdc++.h>
#define lli long long int
#define MOD 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define repf(i, n) for(int i=1; i<(int)(n+1); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
using namespace std;

// 半公倍数の個数を計算
lli hcm(vi &a, lli n, lli m){
    // a1,...,anを全て奇数になるまで割る
    while(a[0]%2 == 0){
        rep(i, n){
            if(a[i]%2 != 0) return 0;
            a[i] /= 2;
        }
        m = floor(m/2.0);
    }
    rep(i, n) if(a[i]%2 == 0) return 0;

    // a1,...,anの最小公倍数の計算
    lli lcm = 1;
    rep(i, n){
        lli gcd = __gcd(lcm, a[i]);
        lcm = (lcm * a[i]) / gcd;
        if(lcm > m) return 0;
    }
    return (m/lcm+1) / 2;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, m;
    cin >> n >> m;
    vi a(n);
    rep(i, n) cin >> a[i], a[i] /= 2;
    cout << hcm(a, n, m) << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	for(int i=m/n;i>=1;i--)
	{
		if(m%i==0)
		{
			int t=m/i;
			if(t>=n)
			{
				cout<<i<<endl;
				break;
			}
		}
	}
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#define ll long long

signed main() {
	int N, Q; cin >> N >> Q;
	fenwick_tree<long long>fw(N);
	for (int i = 0; i < N; i++) {
		long long a; cin >> a;
		fw.add(i, a);
	}
	for (int _ = 0; _ < Q; _++) {
		int t; cin >> t;
		if (t == 0) {
			int p; long long x; cin >> p >> x;
			fw.add(p, x);
		}
		else {
			int l, r; cin >> l >> r;
			cout << fw.sum(l, r) << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 8196
def main():
    MOD = 10 ** 9 + 7

    S = input()
    z, a, b, c = 1, 0, 0, 0

    for x in S:
        if x == 'C':
            c = (c + b) % MOD
        elif x == 'B':
            b = (b + a) % MOD
        elif x == 'A':
            a = (a + z) % MOD
        elif x == '?':
            z, a, b, c = z * 3 % MOD, (a * 3 + z) % MOD, (b * 3 + a) % MOD, (c * 3 + b) % MOD
    print(c)


if __name__ == '__main__':
    main()


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define IMP cout << "IMPOSSIBLE" << endl
#define Imp cout << "Impossible" << endl
#define imp cout << "impossible" << endl
#define M1 cout << "-1" << endl
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using vpint = vector<pint>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    string s, t;
    cin >> s >> t;
    int a, b;
    cin >> a >> b;
    string u = in();
    if (s == u)
        --a;
    else if (t == u)
        --b;
    cout << a << " " << b << endl;
}

signed main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 256
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

def solve():
    s = input()
    t = input()
    hoge = 10000
    let = len(t)
    les = len(s)
    ans = 10000
    for i in range(les-let+1):
        hoge = s[i:i+let]
        piyo = 0
        for j, k in zip(hoge,t):
            if j != k:
                piyo += 1
        if piyo < ans:
            ans = piyo
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


Measured memory_bytes: 10380
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
    os<<endl;
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, map<T,S> const&M){
    for(auto e:M){
        os<<e;
    }
    os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;



int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N,K;
    cin >> N >> K;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    map<int,int> cnt;

    int l = 0, ans = N+1;
    REP(r,N){
        if(A[r]<=K) cnt[A[r]]++;
        if(cnt.size()!=K) continue;
        while(A[l]>K or cnt[A[l]]>=2 ){ if(A[l]<=K) cnt[A[l]]--; l++;}
        chmin(ans, r-l+1);
    }

    if(ans==N+1) cout << 0 << bn;
    else cout << ans << endl;
}



Measured memory_bytes: 7896
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
using namespace std;

void solve(){
  int n; cin >> n;
  int a[n]; for(int i = 0; i < n; i++) cin >> a[i];
  double sum = 0;
  for(int i = 0; i < n; i++) sum += 1.0/a[i];
  cout << fixed << setprecision(6) << 1 / sum << endl;
  return;
}

int main(){
  solve();
  return 0;
}


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

using namespace std;

#define all(v)				((v).begin()), ((v).end())
#define allr(v)				((v).rbegin()), ((v).rend())
#define sz(v)				((int)((v).size()))
#define ll long long
#define pb					push_back
#define fIO ios_base::sync_with_stdio(0);cin.tie(0);

const ll oo = 1e8;
const double pi = 3.1415926535897;


const double EPS = (1e-7);
int dcmp(double x, double y) {	return fabs(x-y) <= EPS ? 0 : x < y ? -1 : 1;	}


typedef vector<int>                vi;
typedef vector<pair<int,int>>      vii;
typedef vector<ll>                 vll;
typedef vector<double>             vd;
typedef vector< vi >               vvi;
typedef vector< vd >               vvd;
typedef vector<string>             vs;
typedef pair<int, int>             pii;

/**
    * PLEASEEE READDD PROBLEEEM CARFULLY ****
    * Always check for OVERFLOW ll vs int
    * Always check for array bounds
    * Check for function return
    * READ OUTPUT SECTION AGAIN!!!
**/

struct edge{
    int from, to, w;

    edge(){}
    edge(int x, int y, int we): from(x), to(y), w(we){}

    bool operator < (const edge &rhs) const{
        return w > rhs.w;
    }

};

int main(){
    fIO
//    freopen("", "r", stdin);
//    freopen("", "w", stdout);


    int n;
    string s;

    cin >> n >> s;

    s = "x" + s;
    unordered_map<char, vi> loc;
    /**
        n! / (n - r)! r!

        n! / (n - 3)! 6

        (n - 3)! * n * (n - 1) * (n - 2) / (n - 3)! 6

        n * (n - 1) * (n - 2) / 6
    **/
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        loc[s[i]].pb(i);

        for(int j = 1; j < i; j++) {
            if(s[j] == s[i]) continue;

            set<char> chrs = {'R', 'G', 'B'};
            chrs.erase(s[i]);
            chrs.erase(s[j]);

            char rem = *chrs.begin();

            if(sz(loc[rem]) == 0) continue;


            int bad = 2 * j - i;

            auto it = lower_bound(all(loc[rem]), j);

            if( (*it > j && it != loc[rem].begin()) || (it == loc[rem].end())) it--;
            if(*loc[rem].begin() > j) continue;
            ll currAns = it - loc[rem].begin() + 1;
            //cout << i << " " << j << " " << sz(loc[rem]) << "\n";

            it++;
            auto bd = lower_bound(loc[rem].begin(), it, bad);

            if(bad > 0 && *bd == bad) currAns--;

            ans += currAns;
        }
    }

    cout << ans;
}








Measured memory_bytes: 3668
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int getketa(ll n) {
  int res = 0;
  while (n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

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

  int ans = getketa(n);
  for (ll i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      ans = min(ans, getketa(n / i));
    }
  }
  cout << ans << endl;



  
  return 0;
}

Measured memory_bytes: 256
// Areas on the Cross-Section Diagram
// 問題URL: http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_3_D&lang=jp
// 中央*右
// 
// 最初は配列で高さの値を管理すること考えましたが、それ以降よく分からなかったので、参考文献[2]の解説115pと以下を参考に実装しました。
// 横向きに面積を計算するという発想が浮かばず、勉強になりました。
// https://mtdtx9.hatenablog.com/entry/2017/04/24/230941

#include <iostream>
#include <stack>
#include <vector>
#include <algorithm>

using namespace std;

int area_sum = 0;
char buff;

stack<int> stck1;
stack<pair<int, int > > stck2;

int main(){
    int id = 0;

    while(cin >> buff){
    if (buff=='\\'){
            stck1.push(id);
    } else if(buff=='/' && !stck1.empty()){ //空の場合はtop, popの操作をしてはいけない
            int id_p = stck1.top(); //対応する'\'のidを取得
            stck1.pop(); 
            // printf("(%d, %d)\n",id_p, id);
            int area = id - id_p; //'\'と'/'のペアで追加される面積
            area_sum += area; //面積の総和
            while(!stck2.empty() && stck2.top().first > id_p){ //下層に面積があったら加算して消去
                area += stck2.top().second; stck2.pop();
            }
            stck2.push(make_pair(id_p, area));
        } 
    id++;
    }

    cout << area_sum << endl;

    vector<int> ans_area;
    while(!stck2.empty()){ //stck2には逆順に格納されているのでvectorに面積を入れ直し
        ans_area.push_back(stck2.top().second); stck2.pop();
    }
    reverse(ans_area.begin(),ans_area.end()); //reverseでひっくり返す

    cout << ans_area.size();
    for(auto itr = ans_area.begin(); itr != ans_area.end(); itr++){
        cout << " " << *itr;
    }
    cout << endl;
}





Measured memory_bytes: 3212
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M;
	cin >> N >> M;
	long long ans = 1900 * M + 100 * (N - M);
	for (int i = 0; i < M; i++) {
		ans *= 2;
	}
	cout << ans << endl;
 }

Measured memory_bytes: 256
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
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);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
bool isprime(int n) { //素数判定
    if(n==1)return false;
    if(n==2)return true;
    for(int i = 2;i<=sqrt(n);i++) {
        if(n%i==0) return false;
    }
    return true;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int n,m,x,y;cin >> n >> m >> x >> y;
    int ma = -110,mi = inf;
    rep(i, n) {
        int a;cin >> a;
        chmax(ma,a);
    }
    rep(i, m) {
        int a;cin >> a;
        chmin(mi,a);
    }
    if(mi<=ma||mi<x+1||ma>=y)cout << "War\n";
    else cout << "No War\n";

    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset

typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
#define fbo find_by_order
#define ook order_of_key

char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 122)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 122)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 122)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
bool isect (int l1, int r1, int l2, int r2){
    pii p1,p2;
    p1 = mp(l1,r1); p2 = mp(l2,r2);
    if(p1>p2)swap(p1,p2);
    if(p2.fi <= p1.se)return true;
    else return false;
}
ll quickpow (ll num1, ll num2, ll MOD){
    if(num2==0)return 1;
    else if(num2==1)return num1;
    else{
        ll temp = quickpow (num1,num2/2,MOD); ll res = ((temp%MOD) * (temp%MOD))%MOD;
        if(num2%2==1) res = ((res%MOD)*(num1%MOD))%MOD; return res;
    }
}
ll invmod (ll num, ll MOD){return quickpow (num,MOD-2,MOD);}
ll gcd (ll num1, ll num2){
    if(num1 < num2) swap(num1,num2); ll num3 = num1 % num2 ;
    while(num3 > 0){ num1 = num2; num2 = num3; num3 = num1 % num2;}
    return num2;
}
ll lcm (ll num1 , ll num2){return (ll) (num1/__gcd(num1,num2))*num2;}
// end of Template

int main(){

//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    str a,b; int na, nb;
    cin>>a>>b;
    cin>>na>>nb;
    str q; cin>>q;
    if(q == a) na--;
    else nb--;

    cout<<na<<" "<<nb<<newl;
}


Measured memory_bytes: 256
//ABC126-C
//Reference: editorial answer
#include<iostream>
#include<iomanip>
using namespace std;

#define rep(i, a, b) for(int i=(a); i<=(b); i++)
int main(){
  int N,K;
  double result=0;
  cin >>N>>K;
  
  rep(i,1,N){
    double prob_temp = 1./N;
    int current_temp = i;
    while(current_temp<K){
      current_temp *=2;
      prob_temp /=2.;
    }
    result += prob_temp;
  }
  cout<<setprecision(12)<<result<<endl;
}


Measured memory_bytes: 256
// Example program
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    int count = 0;
    int n = a < b ? a : b;
    int ans = -1;
    for (int i = n; i >= 1; --i) {
        if (a % i == 0 && b % i == 0) {
            ++count;    
        }
        if (count == k) {
            ans = i;
            break;
        }
        
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;
    int num = 0;
    while (b<=a) {
        b *= 2;
        num++;
    }
    while (c<=b) {
        c *= 2;
        num++;
    }

    string ans = "No";
    if (num<=k) ans = "Yes";
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll N;cin>>N;
    ll ans=0;
    REPS(i,N){
        if((i)%3==0||(i)%5==0)continue;
        ans+=i;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 3640
x,y = map(int,input().split())

if x*2 == y:
  print('Yes')
  exit()

if x*4 == y:
  print('Yes')
  exit()

for i in range(1,x+1):
  if (x-i)*2 + i*4 == y:
    print('Yes')
    exit()
  if (x-i)*4 + i*2 == y:
    print('Yes')
    exit()

print('No')

Measured memory_bytes: 61808
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
long long n, t, pos = 1, m, a, b, c, ans, hs[MAXN];
string str1, str2;
int main(void)
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		if (t == pos)
		{
			pos++;
		}
	}
	cout << (((n - pos + 1) == n) ? -1 : (n - pos + 1)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
string s, t, u;
int a, b;
int main(){
	cin >> s >> t >> a >> b >> u;
	if(s == u) a--;
	else b--;
	cout << a << " " << b << "\n";
}

Measured memory_bytes: 256