akhauriyash/Code-Regression huggingface dataset:
from collections import deque
''' 
INF = float('inf')
MOD = 10 ** 9 + 7
'''
## ここは１つにまとめれる
# dy = (0, -1, 0, 1)
# dx = (1, 0, -1, 0)
d=[(1,0),(0,1),(-1,0),(0,-1)]

    
H,W=map(int,input().split())
M = []
Max_list = []
for i  in range(H):
    t = input()
    M.append(t)
dist = [[-1]*W for _ in range(H)]
q = deque()
for i in range(H):
    for j in range(W):
        dist = [[-1]*W for _ in range(H)]
        if M[i][j] == '.':
            Ma = 0
            q.append((i, j))
            dist[i][j] = 0
            while q:
                cx,cy = q.popleft()
                for nx,ny in d:
                    x ,y= cx+nx,cy+ny
                    ''' ここの処理がをnotにしてわかりやすく
                    if x<0 or y<0 or x>=H or y>=W or dist[x][y]>0:
                        continue
                    '''
                    if 0<= x < H and 0<= y < W:

                        if M[x][y] == "." and dist[x][y] == -1:
                            dist[x][y]=dist[cx][cy]+1
                            Ma = max(Ma,dist[x][y])
                            q.append((x,y))
            Max_list.append(Ma)

print(max(Max_list))

Measured memory_bytes: 3436
#include<stdio.h>
#define M 10001
int main(){
  double w;
  while(scanf("%lf",&w)!=EOF){
    if     (w>91.00)printf("heavy\n");
    else if(w>81.00)printf("light heavy\n");
    else if(w>75.00)printf("middle\n");
    else if(w>69.00)printf("light middle\n");
    else if(w>64.00)printf("welter\n");
    else if(w>60.00)printf("light welter\n");
    else if(w>57.00)printf("light\n");
    else if(w>54.00)printf("feather\n");
    else if(w>51.00)printf("bantam\n");
    else if(w>48.00)printf("fly\n");
    else            printf("light fly\n");
  }
  return 0;
}

Measured memory_bytes: 608
#include<stdio.h>

int main(){
  float xa1,ya1,xa2,ya2;
  float xb1,yb1,xb2,yb2;
  int f;

  while(scanf("%f%f%f%f%f%f%f%f",&xa1,&ya1,&xa2,&ya2,&xb1,&yb1,&xb2,&yb2)!=EOF){
    f=0;
    if(xa1<=xb1&&xb2<=xa2&&ya1<=yb1&&yb2<=ya2){
      f=1;
    }
    if(xb1<=xa1&&xa2<=xb2&&yb1<=ya1&&ya2<=yb2){
      f=1;
    }
    if(xb1<=xa1&&xa1<=xb2&&(ya1<=yb1&&yb1<=ya2||ya1<=yb2&&yb2<=ya2)){
      f=1;
    }
    if(xb1<=xa2&&xa2<=xb2&&(ya1<=yb1&&yb1<=ya2||ya1<=yb2&&yb2<=ya2)){
      f=1;
    }
    if(xa1<=xb1&&xb1<=xa2&&(yb1<=ya1&&ya1<=yb2||yb1<=ya2&&ya2<=yb2)){
      f=1;
    }
    if(xa1<=xb2&&xb2<=xa2&&(yb1<=ya1&&ya1<=yb2||yb1<=ya2&&ya2<=yb2)){
      f=1;
    }

    if(f==1)
      puts("YES");
    else 
      puts("NO");
  }
  return 0;
}

Measured memory_bytes: 608
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp;
    auto N = S.length;
    long min_n;
    auto ns = new long[](N+1);
    long x;
    foreach (i; 1..N+1) {
        if (S[i-1] == '<') {
            ns[i] = ++x;
        } else {
            x = 0;
        }
    }
    x = 0;
    foreach_reverse (i; 0..N) {
        if (S[i] == '>') {
            ns[i] = max(ns[i], ++x);
        } else {
            x = 0;
        }
    }
    writeln(0L.reduce!"a + b"(ns));
}

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

l = len(S)
ans = 0
if l == 1:
    ans = K//2
elif l == 2 : 
    if S[0]==S[1]:
        ans = K
    else:
        ans = 0
else:
    if S == S[0]*l:
        ans = (l*K)//2
    else:
        if S[0] == S[-1]:
            s = S[-1]
            for i,c in enumerate(S):
                if s!=c : break
            T = S[i:] + S[:i]
        else:
            T = S
        cntT = 0
        p = T[0]
        tmp_cnt = 1
        for c in T[1:]:
            if c == p:
                tmp_cnt +=1
            else:
                cntT += tmp_cnt // 2
                tmp_cnt = 1
            p = c
        cntT += tmp_cnt//2
        cntS = 0
        p = S[0]
        tmp_cnt = 1
        for c in S[1:]:
            if c == p:
                tmp_cnt +=1
            else:
                cntS += tmp_cnt // 2
                tmp_cnt = 1
            p = c
        cntS += tmp_cnt//2
        ans = cntT*(K-1) + cntS
print(ans)

Measured memory_bytes: 38256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  int64_t A, B, K;
  cin >> A >> B >> K;
  if(K <= A){
    cout << A - K << " " << B << endl;
  }
  else if(K <= A + B){
    cout << 0 << " " << B - (K - A) << endl;
  }
  else{
    cout << 0 << " " << 0 << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	if (a+b==15) cout<<"+"<<endl;
	else if (a*b==15) cout<<"*"<<endl;
	else cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

hop_before = []
hop_to = []

hop_dict = {}

for i in range(M) :
    a, b = map(int, input().split())
    
    if a == 1 :
        if b in hop_dict.keys() :
            hop_dict[b] += 1
        else :
            hop_dict[b] = 1
    if b == N :
        if a in hop_dict.keys() :
            hop_dict[a] += 1
        else :
            hop_dict[a] = 1
        
possible = False
for i in hop_dict.keys() :
    if hop_dict[i] >= 2 :
        print("POSSIBLE")
        possible = True
        break
        
if possible == False :
    print("IMPOSSIBLE")

Measured memory_bytes: 27084
n=int(input())
a=list(map(int,input().split()))
m=1000
bef=a[0]
up=[]
k=0
for i in a[1:]:
  if i>bef:
    up.append(1)
  else:
    up.append(0)
  bef=i
bef=up[0]
if bef:
  k=m//a[0]
  m=m%a[0]  

for i in range(1,n-1):
  if up[i]<bef:    
    m+=k*a[i]
    k=0
  elif up[i]>bef:
    k=m//a[i]
    m=m%a[i]
  bef=up[i]
m+=k*a[-1]
print(m)

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

int main() {
  int a, b;
  cin >> a >> b;
  int counter = 0;

  for(int i=a;i<=b;i++) {
    string intstr = to_string(i);
    string reversed = intstr;
    reverse(reversed.begin(), reversed.end());
    if(intstr == reversed) {
      counter++;
    }
  }

  cout << counter;
  return 0;
}


Measured memory_bytes: 256
#n = (int(i) for i in input().split())  
n = int(input())
if n == 100000:
    print(9 + 900 + 90000)
elif n >= 10000:
    print(9 + 900 + n - 9999)
elif n >= 1000:
    print(9 + 900)
elif n >= 100:
    print(9 + n - 99)
elif n >= 10:
    print(9)
else:
    print(n)



Measured memory_bytes: 2940
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

vector<int> bfs(int node, vector<string> &a) {
    int n = a.size();
    vector<int> d(n, n+1);
    vector<int> color(n, -1);
    d[node] = 0;
    color[node] = 0;

    queue<int> q;
    q.push(node);

    while(!q.empty()) {
        int node = q.front();
        q.pop();
        rep(i, n) {
            if (a[node][i] == '1') {
                if (d[i] >= n) {
                    d[i] = d[node] + 1;
                    color[i] = 1 - color[node];
                    q.push(i);
                }
                if (color[i] != 1 - color[node]) {
                    return vector<int> ();
                }
            }
        }
    }
    return d;
}

int main() {
    int n;
    cin >> n;
    vector<string> mat(n);
    rep(i, n) {
        cin >> mat[i];
    }
    int ans = -1;
    rep(i, n) {
        auto d = bfs(i, mat);
        if (d.empty()) {
            cout << -1 << endl;
            return 0;
        }
        ans = max(ans, *max_element(d.begin(), d.end()));
    }
    cout << ans + 1 << endl;
    return 0;
}


Measured memory_bytes: 3664
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

ll k,mn,mx,a[100005],t;

int32_t main(){
    ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();
    cin >> k;
    for(int i=1;i<=k;i++) cin >> a[i];
    mn=2; mx=2;
    for(int i=k;i>=1;i--){
        if(mn%a[i]) mn+=a[i]-mn%a[i];
        mx-=mx%a[i];
        if(mn>mx){
            cout << -1;
            return 0;
        }
        mx+=a[i]-1;
    }
    cout << mn << ' ' << mx << '\n';
}


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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    ll N,M;
    cin >>N >> M;
    vector<ll> H(N);

    for(ll i = 0; i < N; i++){
        cin >> H[i];
    }
    vector<vector<ll>> m(N);
    for(ll i = 0;i < M; i++){
        ll A,B;
        cin >> A >> B;
        m[A-1].push_back(H[B-1]);
        m[B-1].push_back(H[A-1]);
    }
    ll count = 0;
    for(ll i = 0; i < N; i++){
        bool over = false;
//         if(m[i].size() == 0) count++;
//         cout << "展望" << i << " " << H[i] << endl; 
        for(ll j = 0; j < m[i].size(); j++){
//             cout << "比較" << m[i][j] << endl;
            if(H[i] <= m[i][j]){
//                 cout << "Over" << endl;
                over = true;
            }
        }
        if(over == false){
            count++;
//             cout << "プラス" << endl;
        }
    }

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



Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
    int N, M;
    cin >> N >> M;

    vector<int> a(M), b(M), c(M);
    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i]>> c[i];
        --a[i], --b[i];
    }

    const int inf = 1e18;
    vector<int> dist(N, -inf);
    vector<int> f(N);
    dist[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) {
            if (dist[a[j]] == -inf) continue;
            if (dist[a[j]] + c[j] <= dist[b[j]]) continue;
            dist[b[j]] = dist[a[j]] + c[j];
            if (i == N - 1 && b[j] == N - 1) return cout << "inf" << endl, 0;
        }
    }
    cout << dist[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
import sys


def input(): return sys.stdin.readline().strip()


def solve():
    pass


def main():
    A, B = map(int, input().split())
    ans = 0
    total = 1
    while total < B:
        total += A-1
        ans += 1

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
main :: IO ()
main = do
  [q,h,s,d] <- map read.words <$> getLine :: IO [Int]
  n <- read <$> getLine :: IO Int
  let minEven = minimum [8*q,4*h,2*s,d]
      minOdd = minimum [4*q,2*h,s]
  print $ (n`div`2)*minEven + if odd n then minOdd else 0


Measured memory_bytes: 508
S=input()
Q=input()
#rev -1:False 0:True
L=''
R=''
rev=-1
for i in range(int(Q)):
  tmp=input().split()
  if tmp[0]=='1':
    rev = abs(rev)-1
  else:
    if rev+int(tmp[1])==1:
      R = R + tmp[2]
    else:
      L = L + tmp[2]
if rev==-1:
  print(L[::-1]+S+R)
else:
  print(R[::-1]+S[::-1]+L)

Measured memory_bytes: 4340
#include<cstdio> 
using namespace std;
typedef long long ll;
const int N=100100;
int i,j,k,n,m,ch,ff,En,nm;
ll now,ans;
int a[N],h[N];
struct edge { int val,n;} E[N<<1];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void R(ll &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void W(ll x) {
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void E_add(int x,int val) {
	E[++En].val=val;E[En].n=h[x];h[x]=En;
}
ll Js(int x) {
	int i,t1,t2;
	ll ans=0;
	for (i=1;i<n;i++) {
		if (a[i]<=a[i+1]) t1=a[i+1]-a[i];
		else t1=m-a[i]+a[i+1];
		if (x<=a[i+1]) t2=a[i+1]-x+1;
		else t2=m-x+a[i+1]+1;
		if (t1<t2) ans+=t1;
		else ans+=t2;
	}
	return ans;
}
int dis(int x,int y) {
	if (x<=y) return y-x;
	return m-x+y;
}
int main() {
	R(n);R(m);
	for (i=1;i<=n;i++) R(a[i]);
	for (i=1;i<n;i++) {
		if (a[i]==a[i+1]) continue;
		E_add(a[i]%m+1,-1);
		E_add(a[i+1],dis(a[i],a[i+1])-1);
		if (a[i]>a[i+1]) {
			if (a[i]<m) nm++;
			now+=a[i+1];
		}
		else now+=a[i+1]-a[i];
	}
	ans=now;
	for (i=1;i<=m;i++) {
		if (now<ans) ans=now;
		for (k=h[i];k;k=E[k].n) {
			if (E[k].val==-1) nm++;
			else now+=E[k].val,nm--;
		}
		now-=nm;
	}
	W(ans);puts("");
}

Measured memory_bytes: 2560
N = int(input()) 
A = str(input()) 
B = str(input()) 
C = str(input()) 

a = list(A)    
b = list(B)
c = list(C)

count = 0
for i in range(0,N):
    if a[i] == b[i] and a[i] == c[i]:
        count += 0
    elif a[i] == b[i] or a[i] == c[i] or b[i] == c[i]:
        count += 1
    else:
        count += 2

print(count)

Measured memory_bytes: 3064
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

S = input()
N = len(S)
K = getN()

lista = set()
for i in range(N):
    for j in range(i, min(N, i + K)):
        lista.add(S[i:j + 1])
lista = sorted(list(lista))
print(lista[K - 1])

Measured memory_bytes: 39920
#include <iostream>

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
int gcd3(int a, int b, int c) {
    return gcd(gcd(a, b), c);
}

int main(){
    int K;
    long long int sum = 0;
    cin >> K;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                sum += gcd3(i, j, k);
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] num=new int[n];

            for (int i=0;i<n;i++)
            {
                num[i] = int.Parse(Console.ReadLine());
            }

            shellSort(num, n);
        }

        static void shellSort(int [] num, int n)
        {
            int cnt = 0;
            int m = 0;
            List<int> G = new List<int>();

            for(int i=1;i<=n;i*=4)
            {
                G.Add(i);
            }
            G.Reverse();
            m = G.Count();

            Console.WriteLine(m);

            for (int i=0;i<m;i++)
            {
                insertionSort(num, n, G[i], ref cnt);
                Console.Write((i==0?"":" ")+G[i]);
            }
            Console.WriteLine();
            Console.WriteLine(cnt);
            for(int j=0; j<n;j++)
            {
                Console.WriteLine(num[j]);
            }
        }

        static void insertionSort(int[] num, int n, int g, ref int cnt)
        {
            for(int i=g;i<n;i++)
            {
                int key = num[i];
                int j = i - g;
                while(j>=0&&num[j]>key)
                {
                    num[j + g] = num[j];
                    j = j - g;
                    cnt++;
                }
                num[j + g] = key;
            }
        }
    }
}

Measured memory_bytes: 16748
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int n,ch;
	cin>>n;
	string tmp;
	vector<string> s;
	vector<string> k;
	for(int i=0;i<n;i++){
		cin>>tmp;
		s.push_back(tmp);
		k.push_back(tmp);
	}	
	sort(k.begin(),k.end());
	for(int i=1;i<n;i++){
		if(k[i]==k[i-1]){
			cout<<"No"<<endl;
			return 0;
		}
		int p;
		p=s[i-1].length();
		if(s[i-1][p-1]!=s[i][0]){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int min = sc.nextInt();
		int max = sc.nextInt();
		int divide = sc.nextInt();
		sc.close();

		int count = 0;
		for(int i=min; i<=max; i++) {
			if(divide % i == 0) count++;
		}

		System.out.println(count);

	}

}



Measured memory_bytes: 26380
import sys
input = sys.stdin.readline

def main():
    n, c, k = input_list()
    arrivals = []
    for _ in range(n):
        arrivals.append(int(input()))
    arrivals.sort()
    count = 0
    limit = 0
    ans = 0
    for i, a in enumerate(arrivals):
        if limit and limit < a:
            limit = 0
            count = 0
            ans += 1
        if not limit:
            limit = a + k
        if a <= limit:
            count += 1
        if count == c:
            ans += 1
            count = 0
            limit = 0
    if count > 0:
        ans += 1
    print(ans)

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


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 77360
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		
		Queue<String> que = new ArrayDeque<>();
		que.offer("3");
		que.offer("5");
		que.offer("7");
		int cnt = 0; 
		while (true) {
			String str = que.poll();
			if (Long.valueOf(str) > n) break;
			if (str.indexOf("3") != -1 && str.indexOf("5") != -1 && str.indexOf("7") != -1) {
				cnt++;
			}
			String str3 = str + "3";  String str5 = str + "5";  String str7 = str + "7";
			que.offer(str3);  que.offer(str5); que.offer(str7);
			
		}
		out.println(cnt);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}

Measured memory_bytes: 34388
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll N,C,K,ans=0,cnt=1;
  cin>>N>>C>>K;
  vector<ll> T;
  REP(i,N){
    ll a;
    cin>>a;
    T.PB(a);
  }
  T.PB(INF);
  SORT(T);
  
  ll W=0LL;
  while(W<N){
    ll P=T.at(W);;
    cnt=1;
    while(P+K>=T.at(W+1) && cnt<C){
      W++;
      cnt++;
    }
    ans++;
    W++;
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    // TODO 自動生成されたメソッド・スタブ
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int h = sc.nextInt();

    int area = (a + b) * h / 2;
    System.out.println(area);
  }
}


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

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 0x3f3f3f3f;
const ll LINF = 1ll << 55;
const ll MOD = 1e9 + 7;
const ll MAXN = 400 + 5;
const ll MAXK = 1e5 + 10;

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

int main() {
    ll N;
    cin >> N;
    vll A(N);
    vll B(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> B[i];
    }
    vll a(N);
    vll b(N);
    ll ans = 0;
    for (int i = 0; i < 40; ++i) {
        ll T2 = 1ll << (i + 1);
        ll T = 1ll << i;
        for (int j = 0; j < N; ++j) {
            a[j] = A[j] % T2;
            b[j] = B[j] % T2;
        }
        sort(b.begin(), b.end());
        ll cnt = 0;
        for (ll& x : a) {
            ll k1 = lower_bound(b.begin(), b.end(), T - x) - b.begin();
            ll k2 = lower_bound(b.begin(), b.end(), 2 * T - x) - b.begin();
            ll k3 = lower_bound(b.begin(), b.end(), 3 * T - x) - b.begin();
            cnt += k2 - k1 + N - k3;
        }
        if (cnt % 2 == 1) {
            ans += T;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int s;
    cin >> s;
    int fir = s/100;
    int sec = s%100;
    if (fir > 0 && fir < 13){
        if (sec > 0 && sec < 13){
            cout << "AMBIGUOUS" << endl;
        }else{
            cout << "MMYY" << endl;
        }
    }else{
        if (sec > 0 && sec < 13){
            cout << "YYMM" << endl;
        }else{
            cout << "NA" << endl;
        }
    }
}

Measured memory_bytes: 256
n, k = map(int, input().split())
lst = list(map(int, input().split()))

if n**(1/2) <= k:
    lst = [n for _ in range(n)]
    print(*lst)
else:
    for _ in range(k):
        ans = 0
        dp = [0] * (n + 1)
        for _ in range(n):  
            mx = max(0,_ - lst[_])
            mn = min(n, _ + lst[_] +1)
            dp[mx] += 1
            dp[mn] -= 1
        
        for _ in range(n):
            ans = ans + dp[_]
            lst[_] = ans

    print(*lst[:n])

Measured memory_bytes: 160812
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <limits>

using namespace std;

int helper(const vector<int>& v, const vector<int>& c, int idx) {
	if (idx >= v.size()) {
		return 0;
	}
	int next_max = helper(v, c, idx + 1);
	return max(next_max + v[idx] - c[idx], next_max);
}

int main (int argc, char* argv[]) {
	int n;
	cin >> n;
	vector<int> v(n);
	vector<int> c(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i];
	}
	for (int i = 0; i < n; i++) {
		cin >> c[i];
	}
	cout << helper(v, c, 0) << endl;
}


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

struct UnionFind {
  UnionFind(int n = 0): par(n, -1){}
  int root(int x){
    return par[x] < 0 ? x : par[x] = root(par[x]);
  }
  void unite(int x, int y){
    if ((x = root(x)) == (y = root(y))) return;
    par[y] = x;
  }
private:
  vector<int> par;
};

int n, q;
int p[100000];
string t[100000];
int v[100000];
int m[100000];

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

  while (cin >> n >> q, n){
    memset(m, 0, sizeof(m));
    m[0]++;
    UnionFind uf(n);
    for (int i = 1; i < n; i++){
      cin >> p[i], p[i]--;
    }
    for (int i = 0; i < q; i++){
      cin >> t[i] >> v[i], v[i]--;
      if (t[i] == "M") m[v[i]]++;
    }
    for (int i = 0; i < n; i++){
      if (!m[i]){
        uf.unite(p[i], i);
      }
    }
    long long s = 0;
    for (int i = q - 1; i >= 0; i--){
      if (t[i] == "M"){
        if (!--m[v[i]]){
          uf.unite(p[v[i]], v[i]);
        }
      }
      else s += uf.root(v[i]) + 1;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 10128
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,c; cin >> n >> c;
	vector<vector<pair<int,int>>> v(c);
	for(int i=0;i<n;i++){
		int s,t,x; cin >> s >> t >> x;
		s--; t--;
		x--;
		v[x].push_back(make_pair(s,t));
	}
	vector<pair<int,int>>nv;
	for(int i=0;i<c;i++){
		sort(v[i].begin(),v[i].end());
		for(int j=0;j<v[i].size();j++){
			int d=0;
			while(j+d+1<v[i].size()&&v[i][j+d].second==v[i][j+d+1].first)d++;
			nv.push_back(make_pair(v[i][j].first,v[i][j+d].second));
			j+=d;
		}
	}
	sort(nv.begin(),nv.end());
	int ans=0;
	int crnt=0;
	vector<int> ed(100005,0);
	int iv=0;
	for(int i=0;i<100004;i++){
		while(iv<nv.size()&&nv[iv].first==i){
			crnt++;
			ans=max(ans,crnt);
			ed[nv[iv].second]++;
			iv++;
		}
		crnt-=ed[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 2676
// In The Name Of God
#include<bits/stdc++.h>
#define err(i) cerr << #i << " : " << i << "\n"
#define pb push_back
#define ll long long

using namespace std;

const int N = 1e5+22 ;

int a,b,c;

int main()
{
	cin>>a>>b>>c;
	if(a==b && b==c)
	{
		if(a&1) cout<<0;
		else cout<<-1;
	}
	else
	{
		for(int i=0;i<=N;i++)
		{
			if(a&1 || b&1 || c&1) return cout<<i,0;
			int tmp=a,tmp2=b;
			a=b/2+c/2;
			b=tmp/2+c/2;
			c=tmp/2+tmp2/2;
		}	
	}	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<char>> vect(h,vector<char>(w));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++) cin>>vect[i][j];
  }
  vector<vector<long int>> dp(h,vector<long int>(w));
  dp[0][0]=1;
  for(int i=1;i<h;i++){
    if(vect[i][0]=='.') dp[i][0]=dp[i-1][0];
    else dp[i][0]=0;
  }
  for(int j=1;j<w;j++){
    if(vect[0][j]=='.') dp[0][j]=dp[0][j-1];
    else dp[0][j]=0;
  }
  for(int i=1;i<h;i++){
    for(int j=1;j<w;j++){
      if(vect[i][j]=='.'){
        if(vect[i-1][j]=='#' && vect[i][j-1]=='#') dp[i][j]=0;
        else if(vect[i-1][j]=='#' && vect[i][j-1]=='.') dp[i][j]=dp[i][j-1];
        else if(vect[i-1][j]=='.' && vect[i][j-1]=='#') dp[i][j]=dp[i-1][j];
        else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
      }
      else dp[i][j]=0;
    }
  }
  cout<<dp[h-1][w-1];
  return 0;
}
        
    
  

Measured memory_bytes: 9088
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define RREP(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}


int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N; cin >> N;
    vpl T(N);
    REP(i, N){
        ll a, b; cin >> a >> b;
        T[i] = {b, a};
    }
    sort(T.begin(), T.end());
    ll now = 0;
    
    bool ok = true;
    REP(i, N){
        now += T[i].ss;
        if(now > T[i].ff){
            ok = false;
        }
    }
    cout << (ok ? "Yes" : "No") << endstr;
    return 0;
}


Measured memory_bytes: 3328
loop do
n,x = gets.split.map(&:to_i)


if n==0 && x==0 then
exit

else

count = 0
for i in 3..n
for j in 2..(i-1)
for k in 1..(j-1)

if i+j+k == x then
count += 1
end

end
end
end

puts count


end


end


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

int R;
int B;
char S[ 110 ];

int main()
{
int i;
char C;

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

	cin >> i;
	cin >> S;

	i = 0;
	while( ( C = S[ i ] ) != '\0' )
	{
		i++;
		if( C == 'R' )
			R++;
		else
			B++;
	}

	if( R > B )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <list>
#include <utility>
#include <queue>
#include <memory>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std; 

int
main(int argc, char const *argv[])
{
    uint64_t t, i, j, min, res;
    cin >> t;

    vector<uint64_t> hs;
    for (uint64_t i = 0; i < t; ++i) {
	uint64_t v;
	cin >> v;
	hs.push_back(v);
    }

    min = 0;
    res = 0;

    for (auto h = hs.begin(); h != hs.end(); ++h) {
	if (*h >= min) {
	    ++res;
	    min = *h;
	}
    }

    cout << res << endl;

    return 0;
}


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

#define  quick  ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define s(x) sort(x.begin(),x.end())
#define sr(x) sort(x.begin(),x.end(),greater<ll>())
#define v1 vector<ll>
#define p1 pair<ll,ll>
#define m1 map<ll,ll>
#define ff first
#define ss second
#define ee '\n';
#define pb push_back
#define all(v) v.begin(),v.end()
#define f(i,x,y) for(i=x;i<y;i++)
#define mp make_pair
#define yes cout<<"YES"<<endl
#define no  cout<<"NO"<<endl


void solve()
{
       ll i,n;
       cin>>n;
       p1 a[n];
       f(i,0,n)
       {
              cin>>a[i].ff>>a[i].ss;
       }
       f(i,0,n-2)
       {
                 if(a[i].ff==a[i].ss && a[i+1].ff==a[i+1].ss && a[i+2].ff==a[i+2].ss)
                 {
                           cout<<"Yes";
                           return;
                 }
       }
       cout<<"No";
       return;
}

 int32_t main()
 {
    quick;
    ll t=1;
    //cin>>t;
    while(t--)
    {
       solve();
    }
    return 0;
 }

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define sz(x) int(x.size())

using namespace std;

typedef pair<int, int> P;

int main(int argc, const char * argv[]) {
    // input from txt
    
    /////////
    //write//
    /////////
    
    int n;
    cin >> n;
    vector<vector<int> > A(n, vector<int>(n-1));
    rep(i, n){
        rep(j, n-1){
            cin >> A[i][j];
            A[i][j]--;
        }
        reverse(A[i].begin(), A[i].end());
    }
    
    vector<P> q;
    auto check = [&](int i){
        if(A[i].empty())return;
        int j = A[i].back();
        if(A[j].empty())return;
        if(A[j].back() == i){
            if(i > j)swap(i, j);
            q.push_back(P(i, j));
        }
    };
    
    rep(i, n)check(i);
    
    int day = 0;
    while(!q.empty()){
        day++;
        sort(q.begin(), q.end());
        q.erase(unique(q.begin(), q.end()), q.end());
        vector<P> prevQ;
        swap(q, prevQ);
        for(P p: prevQ){
            int i=p.first; int j=p.second;
            A[i].pop_back();
            A[j].pop_back();
        }
        for(P p: prevQ){
            int i=p.first; int j=p.second;
            check(i);
            check(j);
        }
    }
    
    rep(i, n){
        if(A[i].size() != 0){
            cout << "-1" << endl;
            return 0;
        }
    }
    
    cout << day << endl;
    
    return 0;
}


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

using namespace std;

int a[105][2];
long long f[105][100005];

int main() {
	int n, w;
	scanf("%d %d", &n, &w);
	int sum = 0;
	for (int i = 0; i < n; i++) {
		scanf("%d %d", &a[i][0], &a[i][1]);
		sum += a[i][1];
	}
	for (int i = 0; i <= n; i++) {
		for (int j = 1; j <= sum; j++) {
			f[i][j] = 1e9;
		}
	}
	f[0][0] = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= sum; j++) {
			if (j - a[i - 1][1] >= 0) {
				f[i][j] = min(f[i - 1][j], a[i - 1][0] + f[i - 1][j - a[i - 1][1]]);
			} else {
				f[i][j] = f[i - 1][j];
			}
		}
	}
	int ans = 0;
	for (int j = 1; j <= sum; j++) {
		if (f[n][j] <= 1ll * w) {
			ans = max(ans, j);
		}
	}
	printf("%d\n", ans);
	return 0; 
}

Measured memory_bytes: 80128
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/agc031/tasks/agc031_b

//参考：
//https://www.hamayanhamayan.com/entry/2019/03/17/003754

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL N;
LL C[200000];

LL ans = 0;

void solve(){
	//dp[i]:i番目の石まで塗り替えが終わっている場合の組合せ
	vector<LL> dp(N+1,0);
	dp[0] = 1;
	//(1)i+1番目の石には何もしない
	//(2)i+1番目以前の石で色がcのものと組合せて塗り替える
	//という選択が考えられる。
	//前者の操作は普通にdp[i + 1] += dp[i]である。

	//今までに何回色iが出てきたかをsm[i]とする
	vector<LL> sm(200001,0);
	for(int i=0;i<N;i++){
		if(i>=1){
			if(C[i]==C[i-1]){
				dp[i+1] = dp[i];
				continue;
			}
		}
		dp[i+1] = (dp[i] + sm[C[i]])%mod;
		sm[C[i]] = (sm[C[i]] + dp[i])%mod;
	}
	ans = dp[N];
}
 
int main(){
    cin >> N;
    for(int i=0;i<N;i++) cin >> C[i];
 
    solve();

    cout << ans << endl;
    return 0;
}

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

int main(){

    int n;cin>>n;
    vector<int>arr(n);
    for(int i=0; i < n ; i++) cin>>arr[i];
    long long sum[n+1];
    sum[0] = 0;
    for(int i=1;i <= n;i++)sum[i] = sum[i-1] + arr[i-1];
    const int mod = 1000000007;
    int64_t ans = 0;
    for(int i=1;i<=n;i++){
        ans += ((sum[i]%mod)*(arr[i]%mod))%mod;
        if(ans >= mod)ans %= mod;
    }
    cout<<ans<<"\n";
}

Measured memory_bytes: 5624
import sys
from collections import defaultdict as dd
from collections import deque
from fractions import Fraction as f
from copy import *
from bisect import *	
from heapq import *
from math import *
from itertools import permutations 
 
def eprint(*args):
    print(*args, file=sys.stderr)
zz=1
 
#sys.setrecursionlimit(10**6)
if zz:
	input=sys.stdin.readline
else:	
	sys.stdin=open('input.txt', 'r')
	sys.stdout=open('all.txt','w')
def li():
	return [int(x) for x in input().split()]
def gi():	
	return [x for x in input().split()]
def fi():
	return int(input())
def si():
	return list(input().rstrip())	
def mi():
	return 	map(int,input().split())	
def gh():
	sys.stdout.flush()
def graph(n,m):
	for i in range(m):
		x,y=mi()
		a[x].append(y)
		a[y].append(x)
def bo(i):
	return ord(i)-ord('a')
		


tt=1



while tt>0:
	tt-=1
	s=si()
	t=si()
	n=len(s)
	m=len(t)
	dp=[[0 for i in range(m+1)] for j in range(n+1)]
	for i in range(1,n+1):
		for j in range(1,m+1):
			#print(i,j,s[i-1],t[j-1])
			if i==1 and j==1:
					dp[i][j]=int(s[i-1]==t[j-1])
			elif i==1:
				
					dp[i][j]=max([dp[i][j],dp[i][j-1],int(s[i-1]==t[j-1])])
			elif j==1:
				dp[i][j]=max([dp[i][j],dp[i-1][j],int(s[i-1]==t[j-1])])
			else:
				dp[i][j]=max([dp[i][j],dp[i-1][j-1]+int(s[i-1]==t[j-1]),dp[i][j-1],\
					dp[i-1][j]])	
	i=n
	j=m
	ans=""
	tle=0
	#for ii in dp[:n+1]:
	#	print(*ii[:m+1])
	while i>0 or j>0:
		if dp[i][j]==0:
			break
		if i>0 and dp[i-1][j]==dp[i][j]:
			i-=1
		elif j>0 and dp[i][j-1]==dp[i][j]:
			j-=1		
		elif i>0 and j>0 and dp[i][j]-dp[i-1][j-1]==1:
			ans+=s[i-1]
			i-=1
			j-=1
		
		else:
			if i>0 and j>0:
				if dp[i-1][j]>dp[i][j-1]:
					i-=1
				else:
					j-=1	
				
			elif j>0:	
				j-=1
			else:
				i-=1	
		tle+=1
		#print(ans,i,j,tle)
		if tle>n+m:
			break
	if dp[i][j]>0:
		ans+=s[0]			
	print(ans[::-1])		

						


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

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

    if (b - a == c - b)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 3612
//?????¨????????????, UnionFind, ?????????. [Q v?????????]??§???????????°???????????????????????¨, ?????°????????????marked???1????????¨???????????¨?????????.
#include <iostream>
#define int long long
using namespace std;

class UF {
	int par[100001];
public:
	void init(int n) { for (int i = 0; i < n; i++) par[i] = i; }
	int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); }
	void marge(int x, int y) { x = root(x); y = root(y); par[x] = y; }
};

int n, q;
int parent[100000];
pair<char, int> query[100000];
int markCount[100000];
UF uf;

void init(int n) {
	for (int i = 0; i < n; i++) { markCount[i] = 0; }
	uf.init(n);
}

signed main() {
	int i;
	
	while (cin >> n >> q) {
		if (!n) break;
		init(n);
		
		for (i = 1; i < n; i++) {
			cin >> parent[i];
			parent[i]--;
		}
		for (i = 0; i < q; i++) {
			cin >> query[i].first >> query[i].second;
			query[i].second--;
			if (query[i].first == 'M') {
				markCount[query[i].second]++;
			}
		}
		for (i = 1; i < n; i++) {
			if (!markCount[i]) {
				uf.marge(i, parent[i]);
			}
		}
		
		int ans = 0;
		for (i = q - 1; i >= 0; i--) {
			int v = query[i].second;
			if (query[i].first == 'M') {
				markCount[v]--;
				if (markCount[v] == 0) uf.marge(v, parent[v]);
			}
			else {
				ans += uf.root(v) + 1;
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 6992
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n;
while(1){
cin>>n;
if(n==0)return 0;
V<string> s(n);
for(int i=0;i<n;i++)cin>>s[i];
int l=0,r=0,u=0,d=1,ans=0;
for(int i=0;i<n;i++){
    if(s[i]=="lu")l=1;
    if(s[i]=="ru")r=1;
    if(s[i]=="ld")l=0;
    if(s[i]=="rd")r=0;
    if(u){
        if(l==0&&r==0){
            ans++;
        u=0;d=1;
        }
    }
    if(d){
         if(l==1&&r==1){
            ans++;
        u=1;d=0;
        }
    }
}
cout<<ans<<endl;
}
}


Measured memory_bytes: 3156
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int a;
signed main()
{
	cin>>a;
	rep(i,10){
		rep(j,10){
			if(i*j==a){
				cout<<"Yes";
				return 0;
			}
		}
	}
	cout<<"No";
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

string S;

int main() {
	cin >> S;

	int red = 0, blue = 0;
	for (unsigned int i = 0; i < S.length(); i++) {
		if (S[i] == '0')red++;
		else blue++;
	}
	cout << min(red, blue) * 2 << endl;
}

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

const int max_n = 1000000;
int prime[max_n];
bool is_prime[max_n+1];

int sieve(int n)
{
	int p = 0;
	for(int i=0;i<=n;i++){
		is_prime[i] = true;
	}
	is_prime[0] = is_prime[1] = false;
	for(int i=2;i<=n;i++){
		if(is_prime[i]){
			prime[p++] = i;
			for(int j=2*i;j<=n;j+=i)
				is_prime[j] = false;
		}
	}
	return p;
}

int main()
{
	int n;
	while(cin >> n)
		cout << sieve(n) << endl;
	return 0;
}

Measured memory_bytes: 2152
S = str(input())

akibalst = []
for i in range(2):
    if i == 0:
        a1 = 'A'
    else:
        a1 = ''
    for j in range(2):
        if j == 0:
            a2 = 'A'
        else:
            a2 = ''
        for k in range(2):
            if k == 0:
                a3 = 'A'
            else:
                a3 = ''
            for l in range(2):
                if l == 0:
                    a4 = 'A'
                else:
                    a4 = ''

                tmp = a1 + 'KIH' + a2 + 'B' + a3 + 'R' + a4
                akibalst.append(tmp)
#print(akibalst)
if S in akibalst:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    long long int sum = 0;
    for(int i  =0;i<n+1;i++){
    if(i % 5 !=0 && i % 3 !=0){
        sum+=i;
    }
    }
  printf("%lld", sum);
  return 0;
}

Measured memory_bytes: 1728
def is_integer_num(n):
    if isinstance(n, int):
        return True
    if isinstance(n, float):
        return n.is_integer()
    return False
  
n = int(input())

flag=0
for i in range(1, 10):
    m = n/i
    if is_integer_num(m) and m<10:
        flag = 1
        print("Yes")
        break
if flag == 0:
    print("No")

Measured memory_bytes: 3060
_,a,b,*H=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
	m=(l+r)//2
	if-sum(min(0,(h-m*b)//(b-a))for h in H)>m:l=m
	else:r=m
print(r)

Measured memory_bytes: 14092
n = int(input())
l = list(input())

ans = 100000000
east = 0
west = 0
for i in range(1, n):
    if l[i] == 'E':
        east+=1
ans = east

if l[0] == 'E':
    east+=1

for i in range(1, n):
    if l[i-1] == 'W':
        west+=1
    elif l[i-1] == 'E':
        east-=1
    if l[i] == 'E':
        ans = min(ans, west + east-1)
    else:
        ans = min(ans, west + east)
print(ans)


Measured memory_bytes: 11424
#include <bits/stdc++.h>
 
using namespace std;
 
int main(int argc,char* argv[]){
  int N,p,max=0,count=0;
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> p;
    if(max < p) max = p;
    count += p;
  }
  cout << count-max/2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

  int n,v,i,j,k;

  scanf("%d",&n);
  
  int A[n];

  for(i=0; i<n ; i++){
    scanf("%d",&A[i]);
  }

  for(k=0; k<n; k++){
    printf("%d",A[k]);
    if(k != n -1)printf(" ");
  }
  printf("\n");


  for(i = 1; i <= n-1; i++){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v){
      A[j + 1] = A[j];
      j--;
      A[j+1] = v;
    }
    
    for(k=0; k<n; k++){
      printf("%d",A[k]);
      if(k != n -1)printf(" ");
    }
    printf("\n");
    
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

ll n;
int ans;

void dfs(ll a, int flag){
	if(a>n){
		return;
	}
	if(flag==7){
		++ans;
	}
	dfs(a*10+3, flag | 1);
	dfs(a*10+5, flag | 1<<1);
	dfs(a*10+7, flag | 1<<2);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	dfs(0, 0);
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        int[] fib = new int[n+1];
        fib[0] = 1;
        if(n >= 1) fib[1] = 1;
        for(int i = 2; i <= n; i++){
            fib[i] = fib[i-2] + fib[i-1];
        }
        
        System.out.println(fib[n]);
    }
}


Measured memory_bytes: 26316