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


int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
//    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

long long  factorial(long long n) {
    if (n > 0) {
        return n * factorial(n - 1);
    } else {
        return 1;
    }
}

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

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
//  int  a ,b, c, d, e, X, Y ,r;
  long long  a, b, c, d, e, X, Y;
  //  double  c;
//  int  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
  int  C[100003][100001]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p,q;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  int min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  int sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%lld%lld", &a, &b);

  for(i=0;i<b;i++){
    scanf("%lld", &c);
    sum=sum+c;
  }
  if(a<=sum)   printf("Yes\n");
  else   printf("No\n");
  
return 0;
}


Measured memory_bytes: 128
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let N = read int
    let S = (read string).ToCharArray()

    let bs = ['A'..'Z'] @ ['A'..'Z'] |> Array.ofList

    let f c =
        let i = Array.findIndex ((=) c) bs
        bs.[i + N]

    let ans = Array.map f S

    printfn "%s" (String.Join("", ans))
    0

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

int main() {
  int A, B, K;
  scanf("%d%d%d", &A, &B, &K);

  if (B - A + 1 <= 2 * K) {
    for (int i = 0; i < B - A + 1; i++) {
      printf("%d\n", A + i);
    }
    return 0;
  }

  for (int i = 0; i < K; i++) {
    printf("%d\n", A + i);
  }
  B = B - K + 1;
  for (int i = 0; i < K; i++) {
    printf("%d\n", B + i);
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from decimal import *

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	D = inputInt()
	C = inputList()
	S = []
	ans = []
	for i in range(D):
		s = inputList()
		S.append(s)

	minC = max(C)
	minCn = 0
	for i,val in enumerate(C):
		if val == minC:
			minCn = i+1

	for i,val in enumerate(S):
		tmp = max(val)
		mins = 0
		for j,vol in enumerate(val):
			if tmp == vol:
				mins = j+1
				break
		ans.append(minCn)

	for i in range(D):
		print(ans[i])

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


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

int k;

int main () {
	scanf("%d", &k);
	if (k == 1) printf("1\n1\n");
	else {
		int m = (k + 3) / 4, n = 2 * m;
		printf("%d\n", n);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (j & 1) printf("%d ", ((i + j) % n + n) >= k ? (i + j) % n + 1 : (i + j) % n + n + 1);
				else printf("%d ", (i + j) % n + 1);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

typedef struct {
    char name[10];
    int time;
} Process;

typedef struct {
    Process *que;
    int front;
    int rear;
    int size;
    int num;
} Que;

bool initQue(Que *q, int size) {
    if((q->que = malloc(size * sizeof(Process))) == NULL) {
        return false;
    }

    q->front = q->rear = q->num = 0;
    q->size = size;
    return true;
}

bool isEmptyQue(Que *q) {
    return q->num <= 0;
}

bool isFullQue(Que *q) {
    return q->num >= q->size;
}

int nextPtr(int ptr, int size) {
    return (ptr + 1) % size;
}

bool enQue(Que *q, Process *p) {
    if(isFullQue(q)) {
        return false;
    }

    q->que[q->rear] = *p;
    q->rear = nextPtr(q->rear, q->size);
    q->num++;

    return true;
}

bool deQue(Que *q, Process *p) {
    if(isEmptyQue(q)) {
        return false;
    }

    *p = q->que[q->front];
    q->front = nextPtr(q->front, q->size);
    q->num--;

    return true;
}

void terminateQue(Que *q) {
    free(q->que);
    q->front = q->rear = q->num = q->size = 0;
}

int main(void) {
    Que que;
    char buf[32];
    int n;
    int q;

    fgets(buf, sizeof(buf), stdin);
    sscanf(buf, "%d %d", &n, &q);

    initQue(&que, n);

    Process pBuf;
    for(int i = 0; i < n; i++) {
        fgets(buf, sizeof(buf), stdin);
        sscanf(buf, "%s %d", pBuf.name, &pBuf.time);
        enQue(&que, &pBuf);
    }
    
    int elapsedTime = 0;
    while(!isEmptyQue(&que)) {
        deQue(&que, &pBuf);
        int time = MIN(pBuf.time, q);
        elapsedTime += time;
        pBuf.time -= time;
        if(pBuf.time > 0) {
            enQue(&que, &pBuf);
        } else {
            printf("%s %d\n", pBuf.name, elapsedTime);
        }
    }

    terminateQue(&que);
    return 0;
}


Measured memory_bytes: 2284
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static class E {
		int i, j, w;
		E(int i, int j, int w) {
			this.i = i; this.j = j; this.w = w;
		}
	}
	int[] ds;
	int find(int i) {
		return ds[i] < 0 ? i : (ds[i] = find(ds[i]));
	}
	boolean join(int i, int j) {
		i = find(i);
		j = find(j);
		if (i == j)
			return false;
		if (ds[i] > ds[j])
			ds[i] = j;
		else {
			if (ds[i] == ds[j])
				ds[i]--;
			ds[j] = i;
		}
		return true;
	}
	void main() {
		int n = sc.nextInt();
		int[] xx = new int[n];
		int[] yy = new int[n];
		Integer[] ii = new Integer[n];
		Integer[] jj = new Integer[n];
		for (int i = 0; i < n; i++) {
			xx[i] = sc.nextInt();
			yy[i] = sc.nextInt();
			ii[i] = jj[i] = i;
		}
		Arrays.sort(ii, (i, j) -> xx[i] - xx[j]);
		Arrays.sort(jj, (i, j) -> yy[i] - yy[j]);
		int m = (n - 1) * 2;
		E[] ee = new E[m];
		m = 0;
		for (int h = 1; h < n; h++) {
			int i, j, w;
			i = ii[h - 1];
			j = ii[h];
			w = xx[j] - xx[i];
			ee[m++] = new E(i, j, w);
			i = jj[h - 1];
			j = jj[h];
			w = yy[j] - yy[i];
			ee[m++] = new E(i, j, w);
		}
		Arrays.sort(ee, (e, f) -> e.w - f.w);
		ds = new int[n]; Arrays.fill(ds, -1);
		long ans = 0;
		for (int h = 0; h < m; h++) {
			E e = ee[h];
			if (join(e.i, e.j))
				ans += e.w;
		}
		println(ans);
	}
}


Measured memory_bytes: 68292
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)

int keta(int a) {
	int ret = 0;
	while (a >= 10) {
		ret += a % 10;
		a /= 10;
	}
	return ret+a%10;
}

int main() {
	int n;
	cin >> n;
	cout << (n%keta(n) == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>

using namespace std;

int a,b,c,d;
int main(){
    scanf("%d %d %d",&a,&b,&c);
    cout<<(c<=a+b ?"Yes":"No")<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(N: int, A: int, B: int):
    print(min(N*A, B))
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(N, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {
    long long a, b;
    cin >> a >> b;
    if (a > b) {
        int tmp = a;
        a = b;
        b = tmp;
    }
    if (b%a == 0) {
        cout << b << endl;
    } else {
        long long insuu = 1;
        for (int i=2; i<a; i++) {
            if (a%i==0 && b%i==0) {
                a /= i;
                b /= i;
                insuu *= i;
                i--;
            }
        }
        cout << a * b * insuu << endl;
    }   
}

Measured memory_bytes: 256
n,k = map(int,input().split())
prob = 0
point = 0
for cube in range(1,n+1):
    if cube <= k-1:
        point = cube
        t = 0
        while True:
            point = point*2
            t += 1
            if point >= k:
                break
        prob += 1/n * ((1/2)**t)
    else:
        prob += 1/n
print(prob)

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

using namespace std;

int main() {
    vector<int> vt(4);
    for (int i = 0; i < 6; ++i) {
        int x;
        cin >> x;
        vt[x - 1]++;
    }

    if (*max_element(vt.begin(), vt.end()) <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Copyright 2019 yaito3014
#include "bits/stdc++.h"
using namespace std;

int main() {
  cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> A(N);
  for (auto& v : A)cin >> v;
  sort(begin(A), end(A));
  cout << (unique(begin(A), end(A)) == end(A) ? "YES" : "NO") << endl;
}

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

string change(string s){
    for(int i = s.size() - 1; i > 0; --i){
        swap(s[i],s[i - 1]);
    }

    return s;
}

int main(){
    string s,t;
    cin >> s >> t;

    int i = 0;

    while(i != s.size()){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }

        t = change(t);

        i++;
    }

    cout << "No" << endl;
}

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

using namespace std;

typedef long long int ll;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;

    ll cnt = 0;

    while(cnt < tx-sx)
    {
        cout << "R";
        cnt++;
    }

    cnt = 0;
    while(cnt < ty-sy)
    {
        cout << "U";
        cnt++;
    }

    cnt = 0;
    while(cnt < tx - sx)
    {
        cout << "L";
        cnt++;
    }

    cnt = 0;
    while(cnt < ty-sy+1)
    {
        cout << "D";
        cnt++;
    }

    cnt=0;
    while(cnt < tx-sx+1)
    {
        cout << "R";
        cnt++;
    }

    cnt = 0;
    while(cnt < ty-sy+1)
    {
        cout << "U";
        cnt++;
    }

    cout << "LU";

    cnt = 0;
    while(cnt < tx - sx+1)
    {
        cout << "L";
        cnt++;
    }

    cnt = 0;
    while(cnt < ty-sy+1)
    {
        cout << "D";
        cnt++;
    }

    cout << "R";

    cout << endl;


    return 0;
}

Measured memory_bytes: 256
R,C,K = map(int,input().split())
items = [[0]*(C+1) for _ in range(R+1)]
for i in range(K):
    r,c,v = map(int,input().split())
    items[r][c] = v

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for y in range(R+1):
    for x in range(C+1):
        for i in range(4):
            position = dp[i][y][x]
            if y+1 <= R:
                dp[0][y+1][x] = max(dp[0][y+1][x], position)
                dp[1][y+1][x] = max(dp[1][y+1][x], position+items[y+1][x])
            if x+1 <= C:
                dp[i][y][x+1] = max(dp[i][y][x+1], position)
                if i < 3:
                    dp[i+1][y][x+1] = max(dp[i+1][y][x+1], position+items[y][x+1])

ans = 0
for i in range(4):
    ans = max(ans, dp[i][-1][-1])
print(ans)

Measured memory_bytes: 429236
#define GODSPEED ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define f(i,x,n) for(i=x;i<n;i++)
#define rf(i,x,n) for(i=n;i>x;i--)
#define ll long long
#define GCD(a,b) __gcd(a,b)
#define adios return 0;

/*
SHERAJUL ARIFIN
Dept. of CSE,
IUT.
*/


#include <bits/stdc++.h>
using namespace std;

int main()
{
    GODSPEED;
    ll t,n,a,b,c,d,s=0,i,j,flag;
    cin>>t>>n;
    while(n--)
    {
        cin>>a;
        s+=a;
    }
    if(s>t) cout<<"-1\n";
    else cout<<t-s<<endl;




    adios;
}


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

using namespace std;
using llong = long long;
using ldbl = long double;
using P = pair<llong, llong>;

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

const llong inf = 1100100100100100ll;
const llong mod = 1e9+7;

int main(){
	llong H, W, N;
	llong sh, sw;
	string S, T;

	cin >> H >> W >> N;
	cin >> sh >> sw;
	cin >> S >> T;

	bool check = false;
	llong nh, nw;

	// U
	nh = sh;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'U') nh--;
		if (nh == 0)
			check = true;
		if (T[i] == 'D' && nh < H)
			nh++;
	}

	// D
	nh = sh;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'D') nh++;
		if (nh == H+1)
			check = true;
		if (T[i] == 'U' && nh > 1)
			nh--;
	}

	// L
	nw = sw;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L') nw--;
		if (nw == 0)
			check = true;
		if (T[i] == 'R' && nw < W)
			nw++;
	}

	// R
	nw = sw;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') nw++;
		if (nw == W+1)
			check = true;
		if (T[i] == 'L' && nw > 1)
			nw--;
	}

	if (check)
		cout << "NO" << endl;
	else
		cout << "YES" << endl;

	return 0;
}

Measured memory_bytes: 776
n=int(input())
h=list(map(int,input().split()))
 
h=h[::-1]
for i in range(1,n):
  if h[i]-h[i-1]>1:
    print("No")
    exit(0)
  elif h[i]-h[i-1]==1:
    h[i]-=1
print("Yes")


Measured memory_bytes: 14224
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
pair<ll, ll> reverse(pair<ll, ll> p){
    ll a = -1 * p.second, b = p.first;
    if(b < 0) {a *= -1; b *= -1;}
    return make_pair(a, b);
}
int main(){
    int n;
    cin >> n;
    map<pair<ll, ll>, int> mp;
    ll a_0 = 0, b_0 = 0, a_b_0 = 0;;
    for(int i = 0 ; i < n; i++){
        ll a, b;
        cin >> a >> b;
        if(a == 0 && b == 0) {a_b_0++; continue;}
        if(a == 0) {a_0++; continue;}
        if(b == 0) {b_0++; continue;}
        ll c = gcd(a, b);
        a /= c;
        b /= c;
        if(b < 0){a *= -1; b *= -1;}
        mp[make_pair(a, b)]++;
    }
    vector<ll> po(n + 1);
    po[0] = 1;
    for(int i = 1; i <= n; i++) po[i] = po[i - 1] * 2 % MOD;
    vector<ll> combination_for_each_pair;
    for(auto itr : mp){
        auto p = itr.first;
        int x = itr.second, y;
        auto itr2 = mp.find(reverse(p));
        if(itr2 != mp.end()){
            y = itr2->second;
            mp.erase(itr2);
            combination_for_each_pair.push_back((po[x] + po[y] - 1) % MOD);
        }else{
            combination_for_each_pair.push_back(po[x]);
        }
        mp.erase(itr.first);
    }
    if(a_0 == 0 && b_0 == 0);
    else if(a_0 == 0) combination_for_each_pair.push_back(po[b_0]);
    else if(b_0 == 0) combination_for_each_pair.push_back(po[a_0]);
    else combination_for_each_pair.push_back(po[a_0] + po[b_0] - 1);
    ll sum = 1;
    for(int i = 0; i < (int)combination_for_each_pair.size(); i++){
        sum = (sum * combination_for_each_pair[i]) % MOD;
    }
    sum = (sum + MOD + a_b_0 - 1) % MOD;
    cout << sum << "\n";
    /*for(int a : combination_for_each_pair){
        cout << a << " ";
    }
    cout <<  reverse(make_pair(2, -1)).first << " " << reverse(make_pair(2, -1)).second;*/
}

/*⠀⠀⠀⠀⠀⢀⣀⣀⣀    
⠀⠀⠀⠰⡿⠿⠛⠛⠻⠿⣷
⠀⠀⠀⠀⠀⠀⣀⣄⡀⠀⠀⠀⠀⢀⣀⣀⣤⣄⣀⡀
⠀⠀⠀⠀⠀⢸⣿⣿⣷⠀⠀⠀⠀⠛⠛⣿⣿⣿⡛⠿⠷
⠀⠀⠀⠀⠀⠘⠿⠿⠋⠀⠀⠀⠀⠀⠀⣿⣿⣿⠇
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠉⠁

⠀⠀⠀⠀⣿⣷⣄⠀⢶⣶⣷⣶⣶⣤⣀
⠀⠀⠀⠀⣿⣿⣿⠀⠀⠀⠀⠀⠈⠙⠻⠗
⠀⠀⠀⣰⣿⣿⣿⠀⠀⠀⠀⢀⣀⣠⣤⣴⣶⡄
⠀⣠⣾⣿⣿⣿⣥⣶⣶⣿⣿⣿⣿⣿⠿⠿⠛⠃
⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡄
⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡁
⠈⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁
⠀⠀⠛⢿⣿⣿⣿⣿⣿⣿⡿⠟
⠀⠀⠀⠀⠀⠉⠉⠉
*/

//library//
ll mod_fact(ll a, ll mod){
    ll ans = 1;
    while(a > 1){
        ans = ans * a % mod;
        a--;
    }
    return ans; 
}
ll mod_pow(ll a, ll b, ll mod){
    ll ans = 1;
    while(b > 0){
        if(b & 1) ans = ans * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ans;
}
ll mod_inv(ll a, ll mod){
    return mod_pow(a, mod - 2, mod);
}
ll gcd(ll a, ll b){
    while(a % b){
        return gcd(b, a % b);
    }
    return b;
}
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

Measured memory_bytes: 19256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] c = str.toCharArray();
        
        int n = c.length;
        for (int i = 0; i < n-1; i++) {
            if (c[i] == 'P' && c[i+1] == '?') {
                c[i+1] = 'D';
            }
        }
        for (int i = 0; i < n-1; i++) {
            if (c[i] == '?' && c[i+1] == 'D') {
                c[i] = 'P';
            }
        }
        for (int i = 0; i < n-1; i++) {
            if (c[i] == '?' && c[i+1] == '?') {
                c[i] = 'P';
                c[i+1] = 'D';
            }
        }
        
        for (int i = 0; i < n; i++) {
            if (c[i] == '?') c[i] = 'D';
        }
        
        for (int i = 0; i < n; i++) {
            System.out.print(c[i]);
        }
        System.out.println();
    }
}


Measured memory_bytes: 58260
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		int N; input_returnner(int N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(int N) { return std::move(input_returnner(N)); }
}

void solve();
/// ---template---

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

signed main(void) {
	SETUP;
	solve();
	return 0;
}

void solve() {
	int N, X; cin >> N >> X;
	vector<int> A = in(N);

	ll res = 0;
	FOR(i, 1, N) {
		int sum = A[i] + A[i - 1];
		if (sum > X) {
			int diff = min(A[i], sum - X);
			A[i] -= diff;
			res += diff;
		}
	}
	res += max(A[0] + A[1] - X, 0);
	cout << res << endl;
}

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

void z_algorithm(int *s,int *z,int n){
    int c=0;
    for(int i=1;i<n;i++){
        if(i+z[i-c]<c+z[c]){
            z[i]=z[i-c];
        }else{
            int j=max(0,c+z[c]-i);
            while(i+j<n&&s[j]==s[i+j])j++;
            z[i]=j;
            c=i;
        }
    }
    z[0]=n;
}

int n;
int a[200005],pa[200005];
int b[200005],pb[200005];
int s[600005],z[600005];

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>n;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;i++)cin>>b[i];
    a[n]=a[0];
    b[n]=b[0];
    for(int i=0;i<n;i++){
        pa[i]=a[i]^a[i+1];
        pb[i]=b[i]^b[i+1];
    }
    memcpy(s,pb,n<<2);
    memcpy(s+n,pa,n<<2);
    memcpy(s+n+n,pa,n<<2);
    z_algorithm(s,z,n*3);
    for(int i=n;i<n*2;i++){
        if(z[i]>=n){
            cout<<i-n<<' '<<(a[i-n]^b[0])<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 11264
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long H = sc.nextLong();
    int W = sc.nextInt();
    long s;
    if(H == 1 || W == 1) {
      s = 1;
    } else if(H * W  % 2 == 0) {
      s = H * W / 2;
    } else {
      s = (H * W + 1) / 2;
    }
    System.out.println(s);
  }
}


Measured memory_bytes: 23764
#include <cstdio>
#include <cctype>
#include <algorithm>
#define repu(i,x,y) for (int i=x; i<=y; ++i)
using namespace std;

int n,h,deg[410],cnt;
bool flag[410];
struct edge
{
    int v;
    edge *nxt;
} pool[100100],*tp=pool,*fst[410];

int getint()
{
    char ch;
    while (!isdigit(ch=getchar()));
    int x=ch-'0';
    for (; isdigit(ch=getchar()); x=x*10+ch-'0');
    return x;
}

void addedge(int u,int v)
{
    *tp=(edge){v,fst[u]},fst[u]=tp++;
    ++deg[u],--deg[v];
}

void dfs(int x)
{
    if (flag[x])
        return;
    flag[x]=1;
    for (edge *i=fst[x]; i; i=i->nxt)
        ++cnt,dfs(i->v);
}

bool check()
{
    repu(i,1,n)
    {
        int a=getint(),b=getint(),c=getint(),d=getint();
        int u=c?c:h+a,v=d?h+d:b;
        addedge(u,v);
    }
    repu(i,1,h*2)
    {
        if (deg[i]>0)
            if (i>h)
                dfs(i);
            else
                return 0;
        if (deg[i]<0 && i>h)
            return 0;
    }
    return cnt==n;
}

int main()
{
    scanf("%d%d",&n,&h);
    puts(check()?"YES":"NO");
    return 0;
}

Measured memory_bytes: 1792
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = breads >>= print . solve
    where
        solve [a, b, c]
            | a == b = c
            | b == c = a
            | otherwise = b

breads :: IO [Int]
breads = unfoldr uff <$> B.getLine
    where
        uff b = check <$> B.readInt b
        check (a, b)
            | B.null b = (a, b)
            | otherwise = (a, B.tail b)


Measured memory_bytes: 380
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N = int(input())
    P = list(map(int, input().split()))
    count = 0
    for i in range(N-2):
        a = sorted(P[i:i+3])
        if a[1] == P[i+1]:
            count += 1 
    print(count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5588
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    vector<int> ans(N);
    while(M--) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        ans[a]++;
        ans[b]++;
    }
    for(auto e: ans) {
        cout << e << endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(auto &i:a) cin >> i ;
	ll cnt = 0 ;
	ll sum = 0 ;
	ll mn = INF ;
	ll zero = 0 ;
	for(int i=0;i<n;i++){
		if(a.at(i)<0) cnt++ ;
		if(a.at(i)==0) zero++ ;
		sum += abs(a.at(i)) ;
		mn = min(mn,abs(a.at(i))) ;
	}
	cout << sum-2*mn*(zero==0&&cnt&1) << endl ;
}


Measured memory_bytes: 4024
N = int(input())
P = [int(input()) for _ in range(N)]


"""
t, t+1, t+2,... のように、差が１かつ単調増加で並んでいる部分列の最大長さが動かさないでいい数。
なので、２が１より右にあるか、３が２より右にあるか、...を、見ていき、t+1がtの右にない時点である部分列は終わり。
その最大長さを要素数から引いたものが答え

"""
idxs = [0] * (N+1)
for i in range(N):
    idxs[P[i]] = i # それぞれの数字の場所を記録

cnt = 1
max_len = 1
for i, j in zip(idxs[1:], idxs[2:]):
    if i < j:
        cnt += 1
        max_len = max(cnt, max_len)
    else:
        cnt = 1

print(N - max_len)


Measured memory_bytes: 22060
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

int main(){
	long long n, m, ans = 0;
	cin >> n >> m;
	vector<long long> a(n), b(n + 1);
	for(int i = 0; i < n; i++){
		cin >> a[i];
		b[i + 1] = b[i] + a[i];
	}
	map<long long, long long> mp;
	for(int i = 0; i < n + 1; i++){
		mp[b[i] % m]++;
	}
	for(auto i : mp){
		long long t = i.second;
		ans += t * (t - 1) / 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 5760
K = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[K-1])

Measured memory_bytes: 3060
import copy
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
l = []
l1 = []
key = 0
p = 0
q = 0
for i in range(n):
    count = a[i]
    for j in range(a[i]):
        l1.append(i+1)
        if q == w-1:
            if key % 2 == 0:
                l.append(l1)
            else:
                l1.reverse()
                l.append(l1)
            l1 = []
            q = 0
            key = key + 1
        else:
            q = q + 1
for i in l:
    print(*i)

Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define il inline
#define ri register int
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define mid ((l+r)>>1)
#define MAXN 100050
#define MAXM
#define mod
#define INF (1<<30)
#define eps (1e-6)
#define rep(i, x, y) for(ri i = x; i <= y; ++i)
#define repd(i, x, y) for(ri i = x; i >= y; --i)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
template <typename T> inline bool chkmin(T &x, T y) {return x > y ? x = y, 1 : 0;}
template <typename T> inline bool chkmax(T &x, T y) {return x < y ? x = y, 1 : 0;}
il void read(int &qwq) {
	char ch = getchar(); int f = 1; qwq = 0;
	while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
	while(ch >= '0' && ch <= '9') qwq = qwq*10+ch-'0', ch = getchar();
	qwq *= f;
}
//default codes end here
int n, m, val[MAXN], fa[MAXN], ok[MAXN], good[MAXN], vis[MAXN], ans;
ll sum[MAXN];
struct node {
	int u, v, w;
	bool operator < (const node &x) const {
		return w < x.w;
	}
} E[MAXN];
vector <node> adj[MAXN];
int get(int u) {
	return u == fa[u] ? u : fa[u] = get(fa[u]);
}
void merge(int u, int v) {
	u = get(u), v = get(v);
	if(u != v) fa[v] = u, sum[u] += sum[v];
}
void search(int u, int w) {
	vis[u] = 1;
	for(auto pa: adj[u]) {
		if(pa.w <= w) {
			ok[pa.u] = 1;
			if(!vis[pa.v]) search(pa.v, w);
		}
	}
	
}
int main() {
	int u, v, w;
	read(n), read(m);
	rep(i, 1, n) read(val[i]), fa[i] = i, sum[i] = val[i];
	rep(i, 1, m) read(u), read(v), read(w), E[i] = node {u, v, w};
	sort(E+1, E+m+1);
	rep(i, 1, m) {
		merge(E[i].u, E[i].v);
		adj[E[i].u].pb(node {i, E[i].v, E[i].w}), adj[E[i].v].pb(node {i, E[i].u, E[i].w});
		if(sum[get(E[i].u)] >= E[i].w) good[i] = 1;
//		cout<<sum[get(E[i].u)]<<' '<<E[i].w<<endl;
	}
	repd(i, m, 1) {
		if(ok[i]) ++ans;
		else if(good[i]) ++ans, search(E[i].u, E[i].w);
	}
	cout<<m-ans<<endl;
	return 0;
}

Measured memory_bytes: 12672
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int S = sc.nextInt();
		
		int h = (int)Math.floor(S / 3600);
		int m = (int)Math.floor((S - h * 3600) / 60);
		int s = S - (h * 3600 + m * 60);
		
		System.out.println(h + ":" + m + ":" + s);
		
		sc.close();
	}

}



Measured memory_bytes: 26336
#include <stdio.h>
#include <math.h>
#include <string.h>
int main(void) {
	
	char s[100000];
	scanf("%s", s);
	char b[100000];
	int count = 0;
	int a = strlen(s);
	for (int i = 0; i < a; i += 2) {
		b[count] = s[i];
		count++;
	}
	for (int i = 0; i < count; i++) {
		printf("%c", b[i]);
	}
	return 0;

}

Measured memory_bytes: 384
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_4_C
 */
#include <iostream>
#include <string>
#include <set>

using namespace std;

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

    set<string> dict;
    for (int i = 0; i < n; i++) {
        string line;
        getline(cin, line);

        if (line[0] == 'f') {
            auto found = dict.find(line.substr(5));
            cout << (found == dict.end() ? "no" : "yes") << endl;
        } else {
            dict.insert(line.substr(7));
        }
    }

    return 0;
}

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

int main() {
  int a, b, c;
  int k;
  cin >> a >> b >> c;
  cin >> k;

  int b_tmp = b;
  int c_tmp = c;
  int count = 0;
  
  while(b_tmp <= a){
    b_tmp = b_tmp * 2;
    count++;
  }

  while(c_tmp <= b_tmp){
    c_tmp = c_tmp * 2;
    count++;
  }

  if(count <= k){
    cout << "Yes" <<endl;
  }else{
    cout << "No" <<endl;
  }
  
}

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

int N;
int sum;

bool check(string num_str) {
	bool three = false, five = false, seven = false;
	for (int i = 0; i < num_str.length(); i++) {
		if (num_str[i] == '3') three = true;
		if (num_str[i] == '5') five = true;
		if (num_str[i] == '7') seven = true;
	}
	bool f = three && five && seven;
	if (!f)
		return true;

	int num = atoi(num_str.c_str());
	if (num <= N) {
		sum++;
		return true;
	} 
	return false;
}

void dfs(int level, string str) {
	if (level >= 10) {
		return;
	} else {
		if (str != "") {
			if (str.length() >= 3 && !check(str)) {
				return;
			}
		}
		dfs(level+1, "3"+str);
		dfs(level+1, "5"+str);
		dfs(level+1, "7"+str);
	}
}

int main() {
	cin >> N;
	dfs(0, "");
	cout << sum << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007
#define INF 1001001001

int n, a[15], x[15][15][2], ans = 0;

main(){
    scanf("%d", &n);
    for(int i=0; i<n; i++){
        scanf("%d", &a[i]);
        for(int j=0; j<a[i]; j++){
            scanf("%d%d", &x[i][j][0], &x[i][j][1]);
            x[i][j][0]--;
        }
    }
    for(int i = 0; i< (1<<n); i++){
        int cnt = 0;
        for(int j=0; j<n; j++){
            if(i & (1<<j)){
                for(int k=0; k<a[j]; k++){
                    if(((i>>x[j][k][0])&1) != x[j][k][1]){
                        cnt = -INF;
                        break;
                    }
                }
                cnt++;
            }
        }
        ans = max(ans, cnt);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
/*
My heart’s beating faster
I know what I’m after
 
I’ve been standing here my whole life
Everything I’ve seen twice
Now it’s time I realized
It’s spinning back around now
On this road I’m crawlin’
Save me 'cause I’m fallin’
Now I can’t seem to breathe right
'Cause I keep runnin' runnin' runnin' runnin'
Runnin' runnin' runnin' runnin'
Runnin' from my heart
*/
 
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define nt _int128
#define fir first
#define sec second
#define slow_as_snail ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define debug(x) cout<<x<<"\n";
#define debugged cout<<"debugged\n";
#define inf 0x3f3f3f3f
#define rall(v) v.rbegin(),v.rend()
#define all(v) v.begin(),v.end() 
 
const ll mod = 1000000007;
#define mx 10000005
const ll mxi = 100005;

int main()
{
    slow_as_snail;
    vector<pair<ll,ll>> vpr;
    ll t;
    cin>>t;
    for(int i=0;i<t;i++)
    {
        ll x,y;
        cin>>x>>y;
        vpr.pb({y,x});
    }
    sort(all(vpr));
    ll sm = 0;
    ll sm1 = 0;
    ll fl = 1;
    for(int i=0;i<t;i++)
    {
        sm += vpr[i].sec;
        if(sm>vpr[i].fir)
        {
            fl = 0;
            break;
        }
    }
    if(!fl)
    {
        cout<<"No";
    }
    else
    {
        cout<<"Yes";
    }
}

Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<int> data, tmp;

void calc(int s, int t){
  if(s >= t){
    if(tmp.size() > 1 && tmp[0] == 0) return;
    vector<int> ans(t);
    for(int i=0;i<(t+1)/2;i++) ans[i] = ans[t-1-i] = tmp[i];
    int res = 0;
    for(int i=0;i<t;i++){
      res *= 10;
      res += ans[i];
    }
    data.push_back(res);
  }else{
    for(int i=0;i<10;i++){
      tmp.push_back(i);
      calc(s + 2, t);
      tmp.pop_back();
    }
  }
}

main(){
  for(int i=1;i<=5;i++) calc(0, i);  
  sort(data.begin(), data.end());
  int n;
  cin >> n;
  int p = distance(data.begin(), lower_bound(data.begin(), data.end(), n));
  if(data[p] == n) cout << n << endl;
  else cout << (data[p] - n < n - data[p-1] ? data[p] : data[p-1]) << endl;
}

Measured memory_bytes: 1240
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll a[200100];
vector<ll> sum(200100);
ll cnt[200100];
map<ll, ll> mll;

int main() {
	cin >> n;
	FOR(i, 1, 200100)cnt[i] = cnt[i - 1] + i;
	rep(i, n) {
		cin >> a[i];
		if (i == 0)sum[i] = a[i];
		else sum[i] = sum[i - 1] + a[i];
		mll[sum[i]]++;
	}
	ll ans = 0;
	for (auto it = mll.begin(); it != mll.end(); it++) {
		if (it->first == 0)ans += cnt[it->second];
		else ans += cnt[it->second - 1];
	}
	cout << ans << endl;
}

Measured memory_bytes: 17408
#!/usr/bin/env python3
import sys
N,K = list(map(int, input().split()))
dup = [N]
N = N % K
M = N
while True:
    N = abs(N-K)
    if ( N < M ):
        M = N
    if N in dup:
        break
    else:
        dup.append(N)

print(M)



Measured memory_bytes: 3060
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element? {
        return self.maxElement()
    }
    func min() -> Element? {
        return self.minElement()
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
//    func enumerated() -> [(Int, Element)] {
//        return self.enumerate()
//    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/

//func gcd(x: Int, _ y: Int) -> Int {
//    if y == 0 {
//        return x
//    } else {
//        return gcd(y, x%y)
//    }
//}

/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (H, W) = (input[0], input[1])
var board = [[String]]()
for _ in 0..<H {
    board += [readLine()!.toArray()]
}
var ans = "Yes"
loop: for i in 0..<H {
    for j in 0..<W {
        if board[i][j] == "#" {
            if board[max(i-1,0)][j] == "." && board[min(i+1,H-1)][j] == "." && board[i][max(j-1,0)] == "." && board[i][min(j+1,W-1)] == "." {
                ans = "No"
                break loop
            }
        }
    }
}
print(ans)


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q>
ostream& operator << (ostream& os, pair<P, Q> p)
{
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

const int N = 2000 + 10;
int n;

vector<lli> a1;
lli memo1[N];

lli rec2(int other) ;

lli rec1(int other)
{
  if (other == a1.size() - 1) {
    return +(1LL << 60);
  }

  lli& ret = memo1[other];
  if (ret != -1) return ret;

  lli best = labs(a1[other] - a1.back());
  for (int i = other + 1; i < a1.size(); ++i) {
    best = max(best, rec2(i));
  }

  return ret = best;
}

vector<lli> a2;
lli memo2[N];

lli rec2(int other)
{
  if (other == a2.size() - 1) {
    return -(1LL << 60);
  }

  lli& ret = memo2[other];
  if (ret != -1) return ret;

  lli best = labs(a2[other] - a2.back());
  for (int i = other + 1; i < a1.size(); ++i) {
    best = min(best, rec1(i));
  }

  return ret = best;
}

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli z, w;
  while (cin >> n >> z >> w) {
    fill(memo1, memo1 + N, -1);
    fill(memo2, memo2 + N, -1);
    a1.resize(n + 1);
    a2.resize(n + 1);
    a1[0] = w;
    a2[0] = z;
    for (int i = 0; i < n; ++i) {
      int a;
      cin >> a;
      a1[i + 1] = a2[i + 1] = a;
    }
    cout << rec1(0) << endl;
  }

  return 0;
}


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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define PB push_back

typedef pair<int, char> pic;
typedef vector<pic> vp;

int main() {
	int n;
	cin >> n;
	while (n--) {
		vp v;
		string str;
		cin >> str;
		
		v.PB(pic(0, str[0]));
		
		int tmp = 0;
		for(int i = 1; i < str.size(); i += 3) {
			if (str.substr(i, 2) == "<-") {
				tmp--;
				v.PB(pic(tmp, str[i + 2])); 
			}
			else {
				tmp++;
				v.PB(pic(tmp, str[i + 2]));
			}
		}
		sort(v.begin(), v.end());
		v.erase(unique(v.begin(), v.end()), v.end());
		
		REP(i, v.size())
			printf("%c", v[i].second);
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<vector>
#define MAXN 100000
using namespace std;
typedef pair<int,int> PII;
queue<PII> que;
set<int> st[MAXN+5];
map<PII,int> mp;
int N,setfa[MAXN+5];
vector<int> vec;
PII Work(int x,int y)
{
	if(x>y)
		swap(x,y);
	return PII(x,y);
}
void AddEdge(int u,int v)
{
	st[u].insert(v);
	st[v].insert(u);
	mp[Work(u,v)]++;
	if(mp[Work(u,v)]==2)
		que.push(Work(u,v));
}
void Init()
{
	for(int i=0;i<=MAXN;i++)
		setfa[i]=i;
}
int Findfa(int x)
{
	if(x==setfa[x])
		return x;
	return setfa[x]=Findfa(setfa[x]);
}
void Union(int x,int y)
{
	int fx=Findfa(x),fy=Findfa(y);
	if(fx==fy)
		return;
	setfa[fx]=fy;
}
int main()
{
//	freopen("bluered.in","r",stdin);
//	freopen("bluered.out","w",stdout);
	Init();
	scanf("%d",&N);
	int u,v;
	for(int i=1;i<=2*N-2;i++)
	{
		scanf("%d %d",&u,&v);
		AddEdge(u,v);
	}
	set<int>::iterator it;
	for(int i=1;i<=N-1;i++)
	{
		int spu,spv;
		while(true)
		{
			if(que.empty()==true)
			{
				printf("NO\n");
				exit(0);
			}
			u=Findfa(que.front().first);
			v=Findfa(que.front().second);
			que.pop();
			if(Findfa(u)==Findfa(v))
				continue;
			spu=u,spv=v;
			break;
		}
		if(st[spu].size()>st[spv].size())
			swap(spu,spv);
		Union(spu,spv);
		mp.erase(Work(spu,spv));
		st[spv].erase(spu);
		vec.clear();
		for(it=st[spu].begin();it!=st[spu].end();it++)
			vec.push_back(*it);
		for(int i=0;i<vec.size();i++)
		{
			int poi=vec[i];
			poi=Findfa(poi);
			if(poi==spv)
				continue;
			mp.erase(Work(spu,poi));
			st[poi].erase(spu);
			st[spu].erase(poi);
			AddEdge(poi,spv);
		}
	}
	printf("YES\n");
	return 0;
}

Measured memory_bytes: 36736
S = input()
K = int(input())

X = []
b = S[0]
cnt = 1
for i in range(1, len(S)):
    s = S[i]
    if b == s:
        cnt += 1
    else:
        X.append([b, cnt])
        cnt = 1
        b = s
X.append([b, cnt])

if len(X) == 1:
    print(X[0][1] * K // 2)
elif X[0][0] == X[-1][0]:
    result = 0
    s = X.pop(0)
    e = X.pop()
    result = sum(x[1] // 2 for x in X) * K + s[1] // 2 + e[1] // 2 + ((s[1] + e[1]) // 2) * (K - 1)
    print(result)
else:
    print(sum(x[1] // 2 for x in X) * K)



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

if x >= 0 and y >= 0:
    if y > x:
        print(y-x)
    else:
        print(x+1)
elif x >= 0 and y < 0:
    if abs(y) < x:
        print(1+x-abs(y))
    else:
        print(1+abs(y)-x)
elif x < 0 and y >= 0:
    if abs(x) == y:
        print(1)
    elif abs(x) < y:
        print(1+y-abs(x))
    else:
        t1 = abs(x)+y
        t2 = abs(x)-y+1
        print(min(t1,t2))
else:
    if x < y:
        print(abs(x)-abs(y))
    else:
        print(1+abs(y)-abs(x)+1)

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

signed main(){
  int N, K;
  cin >> N >> K;
  int d[110];
  int A[110][110];
  bool snuke[110];
  rep(i,K){
    cin >> d[i];
    rep(j,d[i]){cin >> A[i][j];snuke[A[i][j]] = true;}
  }
  int ans = 0;
  for(int i = 1;i <= N;i++){
    if(!snuke[i])ans++;
  }
  cout << ans;
}


Measured memory_bytes: 3728