akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner scn = new Scanner(System.in);
		long num1 = scn.nextInt();
		long num2 = scn.nextInt();
		System.out.println(CommonMultipleNum.cmn(num1,num2));
	}
}
class CommonMultipleNum{
	static long cmn(long num1,long num2){
		//総当たり戦。頑張る。
		long tmp;
		long num3 = num1;
		num3 *= num2;//3点交換
		while((tmp= num1%num2)!=0){
			num1 = num2;
			num2 = tmp;
		}
		return (long)(num3/num2);//キャスト(voidとは)
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll;
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define count2way(v, x) high2way(v, x) - low2way(v, x)
#define lower(v, x) low2way(v, x) - v.begin()       //1番左が0、もし見つから無いならｎを出力
#define higher(v, x) high2way(v, x) - v.begin() - 1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout << a << endl
#define putout2(a, b) \
  putout(a);          \
  putout(b)
#define putout3(a, b, c) \
  putout(a);             \
  putout(b);             \
  putout(c)
#define putout4(a, b, c, d) \
  putout(a);                \
  putout(b);                \
  putout(c);                \
  putout(d)
#define putout5(a, b, c, d, e) \
  putout(a);                   \
  putout(b);                   \
  putout(c);                   \
  putout(d);                   \
  putout(e)
#define Gput(a, b) G[a].push_back(b)
#define cin1(a) cin >> a
#define cin2(a, b) cin >> a >> b
#define cin3(a, b, c) cin >> a >> b >> c
#define cin4(a, b, c, d) cin >> a >> b >> c >> d
#define cin5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
  if (c >= '0' && c <= '9')
  {
    return c - '0';
  }
  return 0;
}
ll lcm(ll x, ll y)
{
  ll z = gcd(x, y);
  return x * y / z;
}

ll primejudge(ll n)
{
  if (n < 2)
    return 0;
  else if (n == 2)
    return 1;
  else if (n % 2 == 0)
    return 0;
  double sqrtn = sqrt(n);
  Loop(i, 3, sqrtn + 1)
  {
    if (n % i == 0)
    {
      return 0;
    }
    i++;
  }
  return 1;
}

vector<bool> seen;
vec first;
vec last;
void dfs(const Graph &G, ll v, ll &time)
{
  if (!(seen[v]))
  {
    seen[v] = true;
    first[v] = time++;
    for (auto next_v : G[v])
    {
      if (seen[next_v])
        continue;
      dfs(G, next_v, time);
    }
    last[v] = time++;
  }
}
int main()
{
  ll n;
  cin >> n;
  Graph G(n);
  loop(i, n)
  {
    ll u, k;
    cin >> u >> k;
    while (k--)
    {
      ll x;
      cin >> x;
      Gput(u - 1, x - 1);
    }
  }
  vec id(n);
  loop(i, n) id[i] = i + 1;
  seen.assign(n, false); // 全頂点を「未訪問」に初期化
  first.resize(n);
  last.resize(n);
  ll time = 1;
  loop(i, n) dfs(G, i, time);
  loop(i, n)
  {
    cout << id[i] << " " << first[i] << " " << last[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3172
from collections import Counter

N = int(input())
b = [int(ai)%4 for ai in input().split()]

c = Counter(b)
n1 = c[1] + c[3]
n2 = c[2]
n4 = c[0]

if (n2 == 0 or n1 <= n4) and (n2 != 0 or n1 <= n4+1):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11436
#include<iostream>
#include<string>
using namespace std;
int n,m;
int mp[21][21];
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
int nx,ny;
void f(char c,int a){
  int ar=0;
  switch(c){
  case 'N':
    ar=0;
    break;
  case 'E':
    ar=1;
    break;
  case 'W':
    ar=2;
    break;
  default:
    ar=3;
  }
  for(int i=0;i<a;i++){
    nx+=dx[ar];ny+=dy[ar];
    mp[nx][ny]=0;
  }
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<21;i++){
      for(int j=0;j<21;j++){
        mp[i][j]=0;
      }
    }
    nx=10;ny=10;
    for(int i=0;i<n;i++){
      int x,y;
      cin>>x>>y;
      mp[x][y]=1;
      if(x==10&&y==10)mp[x][y]=0;
    }
    cin>>m;
    for(int i=0;i<m;i++){
      char ch;int a;
      cin>>ch>>a;
      f(ch,a);
    }
    int flg=0;
    for(int i=0;i<21;i++){
      for(int j=0;j<21;j++){
        if(mp[i][j]==1){
          flg=1;break;
        }
      }
    }
    if(flg){
      cout<<"No"<<endl;
    }else{
      cout<<"Yes"<<endl;
    }
  }
}

Measured memory_bytes: 1152
# -*- coding: utf-8 -*-

N = int(input())
As = list(map(int, input().split()))

results = []

ans = 0
sum_a = 0
flg = 1

for a in As:
    if flg == 1:
        if 1 <= sum_a + a:
            sum_a += a
        else:
            a_ = 1 - sum_a
            ans += 1 - sum_a - a
            sum_a = 1
        #print(a,sum_a,ans)
    else:
        if sum_a + a <= -1:
            sum_a += a
        else:
            a_ = -1 - sum_a
            ans += +1 + sum_a + a
            sum_a = -1
        #print(a,sum_a,ans)
    flg *= -1

results.append(ans)

ans = 0
sum_a = 0
flg = -1

for a in As:
    if flg == 1:
        if 1 <= sum_a + a:
            sum_a += a
        else:
            a_ = 1 - sum_a
            ans += 1 - sum_a - a
            sum_a = 1
        #print(a,sum_a,ans)
    else:
        if sum_a + a <= -1:
            sum_a += a
        else:
            a_ = -1 - sum_a
            ans += +1 + sum_a + a
            sum_a = -1
        #print(a,sum_a,ans)
    flg *= -1

results.append(ans)

print(min(results))

Measured memory_bytes: 14468
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if b%a == 0:
        print(a+b)
    else:
        print(b-a)
    return

#B
def B():
    n,m = LI()
    d = defaultdict(int)
    for i in range(n):
        l = LI()
        for j in range(1,len(l)):
            d[l[j]] += 1
    ans = 0
    for i in d.values():
        if i == n:
            ans += 1
    print(ans)
    return

#C
def C():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a,a)
    n = I()
    a = LI()
    g = a[0]
    for i in range(1,n):
        g = gcd(g,a[i])
    print(g)
    return

#D
def D():
    n,m = LI()
    a = LI()
    f = [0,2,5,5,4,5,6,3,7,6]
    dp = [None for i in range(n+1)]
    dp[0] = []
    for j in a:
        for i in range(n+1):
            if i-f[j] >= 0 and dp[i-f[j]] != None:
                if dp[i] == None:
                    dp[i] = dp[i-f[j]]+[j]
                    dp[i].sort(reverse = True)
                elif len(dp[i]) < len(dp[i-f[j]])+1:
                    dp[i] = dp[i-f[j]]+[j]
                    dp[i].sort(reverse = True)
                elif len(dp[i]) == len(dp[i-f[j]])+1:
                    d = dp[i-f[j]]+[j]
                    d.sort(reverse = True)
                    if dp[i] < d:
                        dp[i] = d
    ans = 0
    k = pow(10,len(dp[n])-1)
    for i in range(len(dp[n])):
        ans += k*dp[n][i]
        k //= 10
    print(ans)
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    D()


Measured memory_bytes: 476168
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    b = IR(n)
    b.sort()
    a = deque(b)
    q = deque([a.pop()])
    n -= 1
    for i in range(n):
        if i&1:
            ai = a.pop()
        else:
            ai = a.popleft()
        x = q[0]
        y = q[-1]
        if abs(x-ai) < abs(y-ai):
            q.append(ai)
        else:
            q.appendleft(ai)
    ans = 0
    for i in range(n):
        ans += abs(q[i+1]-q[i])
    a = deque(b)
    q = deque([a.popleft()])
    for i in range(n):
        if i&1:
            ai = a.popleft()
        else:
            ai = a.pop()
        x = q[0]
        y = q[-1]
        if abs(x-ai) < abs(y-ai):
            q.append(ai)
        else:
            q.appendleft(ai)
    ans2 = 0
    for i in range(n):
        ans2 += abs(q[i+1]-q[i])
    a = deque(b)
    q = deque([a.pop()])
    for i in range(n):
        if i&2:
            ai = a.pop()
        else:
            ai = a.popleft()
        x = q[0]
        y = q[-1]
        if abs(x-ai) < abs(y-ai):
            q.append(ai)
        else:
            q.appendleft(ai)
    ans3 = 0
    for i in range(n):
        ans3 += abs(q[i+1]-q[i])
    a = deque(b)
    q = deque([a.popleft()])
    for i in range(n):
        if i&2:
            ai = a.popleft()
        else:
            ai = a.pop()
        x = q[0]
        y = q[-1]
        if abs(x-ai) < abs(y-ai):
            q.append(ai)
        else:
            q.appendleft(ai)
    ans4 = 0
    for i in range(n):
        ans4 += abs(q[i+1]-q[i])
    print(max(ans,ans2,ans3,ans4))
    return


#Solve
if __name__ == "__main__":
    solve()


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

int n;
int dst[110][110];
int M = 1001001001; // dekai kazu

int main(){
	cin >> n;
	for(int i=0; i<=n; i++){
		for(int j=0; j<=n; j++){
			dst[i][j] = M;
			if(i==j) dst[i][j] = 0;
		}
	}
	for(int i=0; i<n; i++){
		int r, k;
		cin >> r >> k;
		for(int j=0; j<k; j++){
			int t;
			cin >> t;
			dst[r][t] = 1;
		}
	}
	for(int k=1; k<=n; k++){
		for(int i=1; i<=n; i++){
			for(int j=1; j<=n; j++){
				if(dst[i][k]+dst[k][j] < dst[i][j]){
					dst[i][j] = dst[i][k]+dst[k][j];
				}
			}
		}
	}

	int p;
	cin >> p;
	for(int i=0; i<p; i++){
		int s, d, v;
		cin >> s >> d >> v;
		if(dst[s][d] < v){
			cout << dst[s][d]+1 << endl;
		}else{
			cout << "NA" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
const int N=305;
int n,K,P,f[N][N],sum[N][N],C[N][N];
int main(){
	cin>>n>>K>>P;
	C[0][0]=1;
	rep(i,1,N-1){
		C[i][0]=1;
		rep(j,1,i)C[i][j]=(C[i-1][j-1]+C[i-1][j])%P;
	}
	rep(i,0,K)f[1][i]=1;
	rep(i,2,n+1){
		per(j,K,0)sum[i-1][j]=(sum[i-1][j+1]+f[i-1][j])%P;
		rep(j,0,K)rep(a,1,i-1){
			f[i][j]=(f[i][j]+1LL*C[i-2][a-1]*f[i-a][j]%P*sum[a][j+1])%P;
		}
	}
	printf("%d\n",f[n+1][0]);
	return 0;
}

Measured memory_bytes: 4812
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int N=2e5+5;
int n,m,a[N],b[N],res[N];
vector<ii> v[N];
int main(){
	ios::sync_with_stdio(false);cin.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		v[a[i]].push_back(ii(b[i],i));
	}
	for(int i=1;i<=n;i++)	sort(v[i].begin(),v[i].end());
	for(int i=1;i<=n;i++)	for(int j=0;j<int(v[i].size());j++)	res[v[i][j].second]=j+1;
	for(int i=1;i<=m;i++)	printf("%06d%06d\n",a[i],res[i]);
	
	return 0;
}

Measured memory_bytes: 11136
s = input()
l = len(s)
N = int(s)
ans = 0
for i1, a in enumerate(" 357"):
    if l<9 and i1>0: break
    for i2, b in enumerate(" 357"):
        if l<8 and i2>0: break
        for i3, c in enumerate(" 357"):
            if l<7 and i3>0: break
            for i4, d in enumerate(" 357"):
                if l<6 and i4>0: break
                for i5, e in enumerate(" 357"):
                    if l<5 and i5>0: break
                    for i6, f in enumerate(" 357"):
                        if l<4 and i6>0: break
                        for g in " 357":
                            for h in " 357":
                                for i in " 357":
                                    for j in "357":
                                        try:
                                            s = a+b+c+d+e+f+g+h+i+j
                                            n = int(s)
                                            if N >= n and "3" in s and "5" in s and "7" in s:
                                                ans += 1
                                        except ValueError:
                                            pass
print(ans)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 準備
            List<ClsSmp> lstGrp = new List<ClsSmp>()
            {
                new ClsSmp() {iN = 0001, iX = 0399, iC = 0 },
                new ClsSmp() {iN = 0400, iX = 0799, iC = 0 },
                new ClsSmp() {iN = 0800, iX = 1199, iC = 0 },
                new ClsSmp() {iN = 1200, iX = 1599, iC = 0 },
                new ClsSmp() {iN = 1600, iX = 1999, iC = 0 },
                new ClsSmp() {iN = 2000, iX = 2399, iC = 0 },
                new ClsSmp() {iN = 2400, iX = 2799, iC = 0 },
                new ClsSmp() {iN = 2800, iX = 3199, iC = 0 },
                new ClsSmp() {iN = 3200, iX = 9999, iC = 0 },
            };

            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            sS = Console.ReadLine().Trim().Split(' ');
            List<int> lstInp = new List<int>();
            for (int i = 0; i < sS.Length; i++) { lstInp.Add(int.Parse(sS[i])); }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            for (int i = 0; i < lstInp.Count; i++)
            {
                for (int j = 0; j < lstGrp.Count; j++)
                {
                    if (lstGrp[j].iN <= lstInp[i] && lstInp[i] <= lstGrp[j].iX) { lstGrp[j].iC += 1; break; }
                }
            }
            int iMin = 0;
            int iMax = 0;
            for (int j = 0; j < lstGrp.Count - 1; j++)
            {
                if (lstGrp[j].iC > 0) { iMin += 1; }
            }
            if (iMin == 0 && lstGrp[lstGrp.Count - 1].iC > 0) { iMin = 1; iMax = lstGrp[lstGrp.Count - 1].iC; }
            else
            {
                iMax = iMin + lstGrp[lstGrp.Count - 1].iC;
            }

            //出力
            Console.WriteLine("{0}", iMin.ToString() + " " + iMax.ToString());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }
        private class ClsSmp
        {
            public int iN { get; set; } = 0;
            public int iX { get; set; } = 0;
            public int iC { get; set; } = 0;
        }

}


Measured memory_bytes: 11348
#include<stdio.h>
#include<string.h>
void a(char *s){
    int l=strlen(s),i;
    for(i = 0;i<l/2;i++){
      char t=s[i];
      s[i] = s[l - i -1];
      s[l-1-i]=t;
    }
}
char T[4][8]={"dream","dreamer","erase","eraser"};
int main(){
    int i =0,c,l;
    char s[100001];
    for(i=0;i<4;i++)a(T[i]);
    scanf("%s",s);
    l = strlen(s);
    a(s);
    for(;c<l;){
      int k=-1;
  	  for(i = 0;i < 4;i++){
        if(!strncmp(s+c,T[i],strlen(T[i]))){
          k = strlen(T[i]);
          break;
        }
      }
      if(k < 0){
        puts("NO");
        return 0;
      }
      c += k;
    }
    puts("YES");
    return 0; 
}


Measured memory_bytes: 256
n, k = list(map(int, input().split()))
if n % 2 == 1:
    if k + n // 2 + k + 2 * n - 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        large = large[n // 2:] + large[:n // 2]
        total = list(range(k + 2 * n, k + 3 * n))
        total = total[::2] + total[1::2]
        for a, b, c in zip(small, large, total):
            print(a, b, c)
else:
    # print(k + (n - 1) // 2, k + 2 * n - 1, k + 3 * n - 1)
    if k + (n - 1) // 2 + k + 2 * n - 1 + 1 > k + 3 * n - 1:
        print(-1)
    else:
        small = list(range(k, k + n))
        large = list(range(k + n, k + 2 * n))
        total = list(range(k + 2 * n, k + 3 * n))
        for a, b, c in zip(small[:n // 2], large[n // 2:], total[::2]):
            print(a, b, c)
        for a, b, c in zip(small[n // 2:], large[:n // 2], total[1::2]):
            print(a, b, c)


Measured memory_bytes: 18516
#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
    int N; cin >> N;
    vector<long long> a(N);
    for (int i = 0; i < N; ++i) cin >> a[i];

    // 累積和と連想配列
    vector<long long> s(N+1, 0);
    map<long long, long long> nums;
    for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i];
    for (int i = 0; i < N+1; ++i) nums[s[i]]++;

    // 集計処理
    long long res = 0;
    for (auto it : nums) {
        long long num = it.second; // it.first が it.second 個ある
        res += num * (num - 1) / 2;
    }
    cout << res << endl;
}   

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

#define BR "\n"
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

int main() {
  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  fcout << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << BR;
  return 0;
}


Measured memory_bytes: 3260
// D - 11
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

// void v_print(vi &v){for(auto e:v){printf("%d,",e);}puts("");}//

#define MAX 100000+10
ll fac[MAX]; // 累乗 n!
ll inv[MAX]; // 逆元 1/n
ll finv[MAX]; // 逆元の累乗 (n^-1)! = (1/n)!

void init(int n, int p){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	rp(i, 2, n+1){
		fac[i] = fac[i-1] * i % p;
		inv[i] = p - inv[p%i] * (p/i) % p;
		finv[i] = finv[i-1] * inv[i] % p;
	}
}

ll nCk_mod(int n, int k, int m){
	if(n<k || n<0 || k<0) return 0;
	return fac[n] * (finv[n-k] * finv[k] % m) % m;
}

void solve(int N, vi &A){
	int d = 0;
	vi exist(N+1, -1);
	rp(i, 0, N+1){
		if(exist[A[i]] >= 0){
			d = i - exist[A[i]];
			break;
		}
		exist[A[i]] = i;
	}
	int MOD = 1000000007;
	init(N+1+5, MOD);
	rp(k, 1, N+2){
		ll ans = (nCk_mod(N+1, k, MOD) - nCk_mod(N-d, k-1, MOD)) % MOD;
		if(ans < 0) ans += MOD;
		cout<< ans <<endl;
	}
}

int main(){
	int N; cin>>N;
	vi A(N+1);
	rp(i, 0, N+1) cin>>A[i];
	solve(N, A);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define fi first
#define se second
#define inf (INT_MAX/2-1)
#define infl (1LL<<60)
#define vi vector<int>
#define pb push_back
#define sz(a) (int)(a).size()
#define all(a) begin(a),end(a)
#define y0 y5656
#define y1 y7878
#define aaa system("pause");
#define dbg(x) cerr<<(#x)<<": "<<(x)<<'\n',aaa
#define dbga(x,n) cerr<<(#x)<<"[]: ";for(int _=0;_<n;_++)cerr<<x[_]<<' ';cerr<<'\n',aaa
#define dbgs(x) cerr<<(#x)<<"[stl]: ";for(int _:x)cerr<<_<<' ';cerr<<'\n',aaa
#define dbgp(x) cerr<<(#x)<<": "<<x.fi<<' '<<x.se<<'\n',aaa
#define maxn 400

using namespace std;

ll d[maxn+5][maxn+5];///cost minim unire i..j
bool viz[maxn+5][maxn+5];
ll v[maxn+5], s[maxn+5];

ll Dp (int l, int r) {///<---ll nu int
  if (l >= r) return 0;
  if (l+1 == r) return v[l]+v[r];
  if (viz[l][r]) return d[l][r];
  viz[l][r] = 1;
  d[l][r] = infl;
  for (int z = l; z <= r-1; z++) d[l][r] = min(d[l][r], Dp(l, z) + Dp(z+1, r));
  d[l][r] += s[r] - s[l-1];
  return d[l][r];
}

int main () {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n; cin >> n;
  int i, j, z;
  for (i = 1; i <= n; i++) cin >> v[i];
  for (i = 1; i <= n; i++) s[i] = s[i-1] + v[i];
  cout << Dp(1,n);
  return 0;
}


Measured memory_bytes: 1664
N = int(input())
S = input()
w = '.'
b = '#'

c = S.count(w)
c_min = c

for i in range(N):
    if S[i] == b:
        c += 1
    else:
        c += -1
    if c < c_min:
        c_min = c

print(c_min)


Measured memory_bytes: 3500
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
ans = [[0] * (w + 2) for i in range(h + 2)]

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i - 1][j - 1] == "#":
            ans[i - 1][j - 1] += 1
            ans[i - 1][j] += 1
            ans[i - 1][j + 1] += 1
            ans[i][j - 1] += 1
            ans[i][j + 1] += 1
            ans[i + 1][j - 1] += 1
            ans[i + 1][j] += 1
            ans[i + 1][j + 1] += 1

del ans[0]
del ans[-1]
for i in range(h):
    del ans[i][0]
    del ans[i][-1]
for i, _ in enumerate(s):
    tmp = ""
    for j, word in enumerate(_):
        if word == "#":
            tmp += "#"
        else:
            tmp += str(ans[i][j])
    print(tmp, end="\n")


Measured memory_bytes: 9168
n, y = map(int, input().split())
for a in range(n+1):
  for b in range(n+1):
    c = n - a - b
    if c < 0:
      continue
    if 10000*a + 5000*b + 1000*c == y:
      print(a, b, c)
      exit()
else:
  print(-1, -1, -1)
    

Measured memory_bytes: 40940
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner in=new Scanner(System.in);
        int n=in.nextInt();
        int m=in.nextInt();
        int sum=0,t_value=0,check=0;
        int ar[]=new int[n];
        for (int i = 0; i <n; i++) {
            ar[i]=in.nextInt();
            sum=sum+ar[i];
        }
        t_value=sum/(4*m);
        int count=0;
        for (int i = 0; i <n; i++) {
                    if(ar[i]*(4*m) >= sum){
            count++;
        }
        }
        if(count>=m){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23636
from bisect import bisect_right
N = int(input())
A = list(int(input()) for _ in range(N))
INF = 10 ** 9 + 1

dp = [INF]
for a in A:
    if -a >= dp[-1]:
        dp.append(-a)
    else:
        j = bisect_right(dp, -a)
        dp[j] = -a

print(len(dp))


Measured memory_bytes: 55896
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int i,j,n,m,t,k,a,b,r=0,l;
    double d;
    char s[262144];
    scanf("%d%d%d",&n,&a,&b);
    //l=strlen(s);
    //for(i=1;i<=n;i++){scanf("%d",&a[i]);}
    if(zt(a,b)%2){printf("Borys\n");}else{printf("Alice\n");}
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
    int a[100][100],b[100][100];
    long c[100][100]={{0}};
    int n,m,l,i,j,k;

    scanf("%d%d%d",&n,&m,&l);

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

    for(i=0;i<m;i++) {
        for(j=0;j<l;j++)
            scanf("%d",&b[i][j]);
    }
    
    for(i=0;i<n;i++) {
        for(j=0;j<l;j++) {
            for(k=0;k<m;k++)
                c[i][j]+=a[i][k]*b[k][j];   
        }
    }
    
    for(i=0;i<n;i++) {
        for(j=0;j<l-1;j++)
            printf("%ld ", c[i][j]);
        printf("%ld\n",c[i][l-1]);
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int ans = 0;

    rep(i, 1000) {
        int s3 = i % 10;
        int s2 = (i / 10) % 10;
        int s1 = (i / 100) % 10 ;

        bool f1 = false;
        bool f2 = false;
        bool f3 = false;
        rep(k, N) {
            int s = S[k] - '0';
            if (!f1 && s == s1) {
                f1 = true;
            } else if (f1 && !f2 && s == s2) {
                f2 = true;
            } else if (f1 && f2 && !f3 && s == s3) {
                f3 = 1;
            }
        }
        if (f1 && f2 && f3) ans++;
    }
    cout << ans << endl;
}

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

int main(){
string a;
string b;
string c;
int flag=0;


cin>>a>>b>>c;

if(a[(int)(a.length())-1]==b[0]){
    if(b[(int)(b.length())-1]==c[0]){
        cout<<"YES";
    }
    else{
    cout<<"NO";
    }
}
else{
    cout<<"NO";
}

}

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

using namespace std;
long long a,b,POW;
int main()
{
 cin>>a>>b;
 for(int i=b;i>0;i/=10)
 {
    POW++; 
 }
 a*=pow(10,POW);
 a+=b;
 if(floor(sqrt(a))!=sqrt(a))cout<<"No"<<endl;
 else cout<<"Yes"<<endl;
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int A, B, C, i, flag = 0;
	scanf("%d %d %d", &A, &B, &C);
	for (i = A; i <= A * B; i++) {
		if (i % A == 0 && i % B == C) {
			flag = 1;
		}
	}
	if (flag)
		printf("YES");
	else
		printf("NO");
	return 0;
}

Measured memory_bytes: 128
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: i64 = s.trim().parse().unwrap();
    let mut ans: i64 = 0;
    for i in 1..=n {
        if i % 3 != 0 && i % 5 != 0 {
            ans += i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2172
N = int(input())
S = []

for n in range(N):
    tmp = list(input())
    tmp.sort()
    s = "".join(tmp)
    S.append(s)

S.sort()

ans = 0
count = 0

for i in range(N - 1):
    if S[i] == S[i+1]:
        count += 1
        ans += count
    else:
        count = 0

print(ans)


Measured memory_bytes: 10612
def main():
    N, M = map(int, input().split())
    A = [[0, 0] for _ in range(N)]
    for i in range(N):
        A[i][0], A[i][1] = map(int, input().split())
    
    cnt = 0
    money = 0

    A.sort(key=lambda x:(x[0], x[1]))
    for i in range(N):
        money += A[i][0]*A[i][1]
        cnt += A[i][1]
        if(cnt >= M):
            break
    if(cnt == M):
        print(money)
    else:
        print(money-(cnt-M)*A[i][0])
    
main()

Measured memory_bytes: 27556
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,X,Y,x[200005],y[200005],f[200005][18],d[200005],wi[200005],D[200005],ans;
vector<int> v[200005];
void dfs(int x,int y){
    f[x][0]=y,d[x]=d[y]+1;
    for(int i=0;i<17;++i)f[x][i+1]=f[f[x][i]][i];
    for(int i=0;i<v[x].size();++i)if(v[x][i]!=y)dfs(v[x][i],x);
}
int lca(int x,int y){
    if(d[x]<d[y])swap(x,y);
    for(int i=17;i>=0;--i)if(d[f[x][i]]>=d[y])x=f[x][i];
    if(x==y) return x;
    for(int i=17;i>=0;--i)if(f[x][i]!=f[y][i])x=f[x][i],y=f[y][i];
    return f[x][0];
}
void dfs2(int x,int y){
    D[x]=D[y]+1;
    if(D[x]>d[x]) return;
    if(D[x]==d[x]){
        ans=max(ans,d[x]*2);
        return;
    }
    if(wi[x])ans=orz;
    else ans=max(ans,d[x]*2);
    for(int i=0;i<v[x].size();++i)if(v[x][i]!=y)dfs2(v[x][i],x);
}
int main(){
    scanf("%d%d%d",&n,&X,&Y);
    for(int i=1;i<n;++i)scanf("%d%d",x+i,y+i);
    for(int i=1;i<n;++i){
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].pb(y),v[y].pb(x);
    }
    d[0]=-1;
    dfs(Y,0);
    for(int i=1;i<=n;++i)v[i].clear();
    for(int i=1;i<n;++i){
        int o=d[x[i]]+d[y[i]]-d[lca(x[i],y[i])]*2;
        if(o>2)wi[x[i]]=wi[y[i]]=1;
        else v[x[i]].pb(y[i]),v[y[i]].pb(x[i]);
    }
    D[0]=-1;
    dfs2(X,0);
    if(ans==orz)puts("-1");
    else printf("%d\n",ans);
    //system("pause");
    return 0;
}


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

using namespace std;
int main() {
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  int maxX = -101;
  int minY = 101;
  for (int i = 0; i < n; i++) {
    int x1;
    cin >> x1;
    maxX = max(maxX, x1);
  }
  for (int i = 0; i < m; i++) {
    int y1;
    cin >> y1;
    minY = min(minY, y1);
  }

  if (x < y && x < minY && maxX < y && maxX < minY)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
namespace Sample
{
  class Sample
  {
      static void Main()
      {
       string str = Console.ReadLine();
       string[] arr =  str.Split(' ');
       int x = int.Parse(arr[0]);
       int y = int.Parse(arr[1]);
       Console.WriteLine("{0}", x - y + 1);
        
      }
  }
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void)
{
	int a, b, c;
	int sikaku, hisi;
	
	sikaku = hisi = 0;
	
	while (scanf("%d,%d,%d", &a, &b, &c) != EOF){
		
		if (c * c == a * a + b * b){
			sikaku++;
		}
		else if (a == b){
			hisi++;
		}
		//printf("%d %d\n", sikaku, hisi);
	}
	
	printf("%d\n%d\n", sikaku, hisi);
	
	return (0);
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int a, b, n; cin >> a >> b >> n;
	vi sum(1010);
	rep(i, n){
		int x, y; cin >> x >> y;
		sum[x]++;
		sum[y]--;
	}
	rep(i, 1001) sum[i + 1] += sum[i];
	for(int i = a; i < b; i++) if(sum[i]){
		cout << 1 << endl;
		return 0;
	}
	cout << 0 << endl;
	
	return 0;
}


Measured memory_bytes: 3164
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

#define INF 1<<29
#define pb push_back

using namespace std;

int main(void){

  int n,m,p,a,b,d[31][31],x,y,z;
  double dp[1<<9][31];
  vector<int>t;

  while(cin >> n >> m >> p >> a >> b,n|m|p|a|b){
    t.clear();

    for(int i=0;i<31;i++)
      for(int j=0;j<31;j++)d[i][j]=-1;

    for(int i=0;i<n;i++){
      int in;
      cin >> in;
      t.push_back(in);
      d[i][i]=0;
    }

    for(int i=0;i<p;i++){
      cin >> x >> y >> z;
      d[x-1][y-1]=d[y-1][x-1]=z;
    }

    for(int i=0;i<(1<<9);i++)
      for(int j=0;j<31;j++)dp[i][j]=INF;

    dp[(1<<n)-1][a-1]=0;
    double res=INF;

    for(int S=(1<<n)-1;S>=0;S--){
      res=min(res,dp[S][b-1]);
      for(int v=0;v<m;v++){
	for(int i=0;i<n;i++){
	  if(S>>i & 1){
	    for(int u=0;u<m;u++){
	      if(d[v][u]>=0){
		dp[S & ~(1<<i)][u]=min(dp[S & ~(1<<i)][u],dp[S][v]+(double)d[v][u]/t[i]);
	      }
	    }
	  }
	}
      }
    }
    if(res==INF)printf("Impossible\n");
    else printf("%.3f\n",res);
  }
  return 0;
}

Measured memory_bytes: 1368
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    int rem = n%10;
    if(rem == 2 || rem == 4 || rem == 5 || rem == 7 || rem == 9)
        cout << "hon";
    else if(rem == 0 || rem == 1 || rem == 6 || rem == 8)
        cout << "pon";
    else
        cout << "bon";
}

Measured memory_bytes: 3592
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF 0x6fffffff
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,h,i,j,k,l,m,n,x,y;
	ll		ans = 0;
	string	s;
	cin >> n;
	for(i=1;i<=(ll)sqrt(n);i++) {
		if (n%i!=0) continue;
		m = n/i - 1;
		if (m==0) continue;
		if (n/m == n%m)	ans += m;
		//if (i<n/3) break;
	}

	cout << ans << endl;
	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 = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        String ans = "";
        for(int i=0; i<n; i++) {
            ans += s.substring(i, i+1);
            ans += t.substring(i, i+1);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 39052
X, N = map(int, input().split())
if N == 0:
    print(X)
    exit()

p = list(map(int, input().split()))
pp = set(p)
numlist = [i for i in range(-1000, 1000)]
numlistt = set(numlist)
newlist = numlistt - pp
newlistt = list(newlist)
absn = 1000
ans = 1000
 
for i in newlistt:
    if absn > abs(X-i):
        ans = i
        absn = abs(X-i)
    elif absn == abs(X-i) and i < ans:
        ans = i
        absn = abs(X-i)

print(ans)

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

int main(){
  ll N, M;
  cin >> N >> M;
  if(abs(N-M) > 1){
    cout << "0" << endl;
    return 0;
  }
  ll ans = 1;
  if(M == N){
    for(int i = 1; i <= M; i++){
      ans = ans*i % mod;
      ans = ans*i % mod;
    }
    ans = ans*2 % mod;
  }
  else{
    for(int i = 1; i <= M; i++)  ans = ans*i % mod;
    for(int i = 1; i <= N; i++)  ans = ans*i % mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(p) cerr<<"["<<p.FI<<", "<<p.SE<<"]";


typedef long long ll;
typedef pair<ll, ll> P;

int dp[3300][3300];
int main()
{
  string s, t;
  cin >> s >> t;
  REP(i, s.size()) {
    REP(j, t.size()) {
      if (s[i] == t[j]) dp[i + 1][j + 1] = dp[i][j] + 1;
      else dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
    }
  }

  int i = s.size(), j = t.size();
  string ans = "";
  while (i > 0 && j > 0) {
    if (s[i - 1] == t[j - 1]) {
      ans += s[i - 1];
      i--;
      j--;
    } else {
      if (dp[i - 1][j] >= dp[i][j - 1]) i--;
      else j--;
    }
  }
  reverse(ALL(ans));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 39168
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <utility>
#include <fstream>

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a, T b) { a = abs(a), b = abs(b); while (b > 0) { tie(a, b) = make_pair(b, a % b); } return a; }
//mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;

int main()
{

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

	int n; cin >> n;
	string s; cin >> s;
	s.erase(unique(s.begin(), s.end()), s.end());
	cout << s.size() << "\n";
	return 0;
}

Measured memory_bytes: 3760
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int mx = 0;
int n;
struct Edge {
    int to, id;
};
vector<vector<Edge>> g;
vi ans;

void dfs(int v, int c=0, int p=-1) {
    int nxt = 1;
    for (Edge e : g[v]) {
        int u = e.to;
        if (u == p) continue;
        if (nxt == c) nxt++;
        ans[e.id] = nxt;
        dfs(u, nxt, v);
        chmax(mx, nxt);
        nxt++;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n;
    g.resize(n);
    rep(i, n-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].pb(Edge{b, i});
        g[b].pb(Edge{a, i});
    }
    ans.resize(n);
    dfs(0);
    cout << mx << endl;
    rep(i, n-1) cout << ans[i] << endl; 
}

Measured memory_bytes: 8320
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 cnt = 0;
        int i = 1;
        while(n >= i) {
            if (String.valueOf(i).length() % 2 == 1) {
                cnt++;
            }
            i++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 26068
#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)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

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

    int n;
    cin >> n;
    vvi o(n, vi(10));
    vvi p(n, vi(11));
    REP(i, n) REP(j, 10) cin >> o[i][j];
    REP(i, n) REP(j, 11) cin >> p[i][j];

    ll ans = -1e9;
    FOR(i, 1, 1 << 10) {
        vi a(n);
        ll score = 0;
        REP(j, 10) {
            if(i >> j & 1) {
                REP(k, n) {
                    if(o[k][j]) a[k]++;
                }
            }
        }
        REP(j, n) {
            score += p[j][a[j]];
        }
        ans = max(ans, score);
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"

#define MOD 1e9+7
#define PI acos(-1.0)
#define ll long long
#define INF 1000000001

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

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  string s; cin>>s;
  int s_long=s.size();

  for(int i=0; i<s_long; i+=2) {
    cout<<s[i];
  }
  cout<<"\n";
  return 0;
}


Measured memory_bytes: 592
#include<iostream>

using namespace std;

int main() {
  int w,s,c;
  cin >> w >> s >> c;
  int i = 0;
  i = 0;
  for(i = 0; i < 120;) {
    if(c < (w + s) * i) {
      c += 60;
    }
    else if(  c <= (w + s) * i + w) break;
    else i++;
  }
  if(i >= 120) cout << "-1" << endl;
  else         cout << c << endl;

  
  return 0;
}

Measured memory_bytes: 1160
x, y, z, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

a.sort()
a.reverse()
b.sort()
b.reverse()
c.sort(reverse=True)
ans = []

for n in range(len(a)):
    for m in range(len(b)):
        if (n+1)*(m+1) > k:
            break
        for l in range(len(c)):
            if (n+1)*(m+1)*(l+1) > k:
                break
            ans.append(a[n]+b[m]+c[l])

ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

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

int main(){
  string s;
  cin >> s;
  int ans = 0,n = 0;
  int l = s.size();
  for(int i=0;i<l;i++){
    if(s[i]=='A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
      n++;
    }
    else{
      n = 0;
    }
    if(n > ans)ans=n;
  }
  cout << ans << endl;
}


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

int main(){
	int n, m, p, ans;
	while(1){
		cin >> n >> m >> p;
		if(n == 0 && m == 0 && p == 0) break;

		ans = 0;
		int a;
		for(int i = 1; i <= n; i++){
			int x;
			cin >> x;
			ans += x;
			if(i == m) a = x;
		}

		if(a == 0){
			ans = 0;
		}else{
			ans = ans * (100-p) / a;
		}

		cout << ans << endl;
	}

	return 0;
}

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

int main(){
	int n;
	cin>>n;
	
	int a[n+1];
	int err=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		if(a[i]!=i){
			err++;
		}
	}
	if(err==2 || err==0) cout<<"YES";
	else cout<<"NO";
	return 0;
}

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

#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i,a) for (auto i = rbegin(a); i != rend(a); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using namespace std;
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-10;
ll mod = static_cast<ll>(1e9 + 7);
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr void mins(T& a, Args... args) { a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr void maxs(T& a, Args... args) { a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int n, k, c;
string s;
vector<vector<int>> v;
void solve() {
    cin >> n >> k >> c >> s;
    int r = 0;
    rep(i, n) {
        if (r > 0) {
            --r;
            if (s[i] == 'o') v.back().emplace_back(i);
            continue;
        }
        if (s[i] == 'o') {
            r = c;
            v.emplace_back();
            v.back().emplace_back(i);
        }
    }
    vector<int> ans;
    if (sz(v) == k) {
        int b = n + c + 1;
        repd(i, sz(v)) {
            if (sz(v[i]) == 1) ans.push_back(v[i][0]);
            else if (i != sz(v) - 1 && v[i][1] + c >= b) ans.push_back(v[i][0]);
            repd(j, sz(v[i])) if (v[i][j] + c < b) { b = v[i][j]; break; }
        }
    }
    repd(i, sz(ans)) cout << ans[i] + 1 << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 15808