akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>

#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long int ll;
const int INF = 1000000000;
const double PI = 3.1415926535897932;
const ll MOD = 1000000007;

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

    int cnt = 0;
    rep(i, n - 1) {
        if (s[i] != s[i + 1]) cnt++;
    }
    cout << cnt + 1 << endl;
    return 0;
}

Measured memory_bytes: 512
S = input()

try:
    first = int(S[:2])
except ValueError:
    first = -1

try:
    end = int(S[2:])
except ValueError:
    end = -1

def judgeYM(num):
    if num >= 1 and num <= 12:
        return "M"
    elif num >= 0 and num <=99:
        return "Y"
    else:
        return "N"

fj = judgeYM(first)
ej = judgeYM(end)

if fj == "N" or ej == "N":
    print("NA")
elif fj == "M" and ej == "M":
    print("AMBIGUOUS")
elif fj == "M":
    print("MMYY")
elif ej == "M":
    print("YYMM")
else:
    print("NA")

Measured memory_bytes: 3064
N = int(input())
ary=[]
ans=[]
for i in range(N):
    ary.append(list(map(int,(input().split()))))
    if 2 * max(ary[-1]) ** 2 == sum(ary[-1][j] ** 2 for j in range(3)):
        ans.append('YES')
    else:
        ans.append('NO')
print('\n'.join(ans))

Measured memory_bytes: 7744
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
//#define int long long

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

	map<int, int> mp;
	int N;
	cin >> N;

	for (int i = 0; i < N; i++)
	{
		int tmp;
		cin >> tmp;
		if (mp[tmp] == 1) {
			mp[tmp]--;
		}
		else {
			mp[tmp]++;
		}
	}
	int ans = 0;
	for (auto it = mp.begin();it != mp.end(); it++) {
		ans += it->second;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 4992
def ispari(s):
  a = 0
  b = len(s) - 1
  while a < b:
    if not s[a] == s[b]:
      return False
    a += 1
    b -= 1
  return True

S = input()
N = len(S)
S_1 = S[:(N - 1)// 2]
S_2 = S[(N+3)//2 -1:]
if ispari(S) and ispari(S_1) and ispari(S_2):
  ret = 'Yes'
else:
  ret = 'No'
print(ret)

Measured memory_bytes: 3064
#include<stdio.h>
 int main()
{
    int a;
    char s[11];
    scanf("%d",&a);
    scanf("%s",&s);
    if(a<3200)
    {
        printf("red\n");
    }
    else if(a>=3200)
    {
        printf("%s\n",s);
    }
}

Measured memory_bytes: 128
import sys

n = int(input())

if n % 10 == 7:
    print("Yes")
    sys.exit()
    
n_10 = n // 10
if n_10 % 10 == 7:
    print("Yes")
    sys.exit()

n_100 = n // 100
if n_100 % 10 == 7:
    print("Yes")
    sys.exit()

print("No")

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

ll num = 1000000007;

int main(){
	ll n, k;	cin >> n >> k;
	ll res = 0;
  	for(ll i = k; i <= n+1; i++){
    	ll mx = i*(2*n-i+1)/2;
      	ll mn = i*(i-1)/2;
      	res = (mx-mn+1+res)%num;
    }
  	cout << res << endl;
} 

Measured memory_bytes: 3592
//https://codeforces.com/gym/291121/problem/B

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

#define ll long long
#define pb push_back
#define vb vector<bool>
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll, ll>
#define MOD 1000000007
#define MAX_TIME 1e9
#define nl "\n"
#define sp " "
#define gcd __gcd
#define pf printf
#define sf scanf
#define se(a) a.begin(),a.end()
#define fill(a,n) for(int i = 0; i < n; i++)cin>>a[i]

ll solve(vi a,vi t,int index,int k){
    if(index >= a.size())return 0;
    int l1 = 0,l2 = 0;
    if(t[index] == 0 && index <= a.size() - k){
        
        for(int i = index; i < index+k; i++){
            l1 += a[i];
        }
        l1 = l1 + solve(a,t,index+k+1,0);
        l2 = solve(a,t,index+1,k);
    }
    else{
        l1 = a[index] + solve(a,t,index+1,k);
    }
    return max(l1,l2);
}

bool check_traingle(ll a,ll b,ll c){
    if(a+b>c && b+c>a && c+a>b && a!= b && b != c && c!= a)return true;
    return false;
}

int main()
{
    int n;
    cin>>n;
    vll a(n,0);
    fill(a,n);
    ll ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i+1; j < n; j++){
            for(int k = j+1; k < n;k++){
                if(check_traingle(a[i],a[j],a[k])){
                    ans++;
                    // cout<<i+1<<sp<<j+1<<sp<<k+1<<nl;
                }
            }
        }
    }
    cout<<ans<<nl;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

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

	    String a= gs();
	    String b= gs();
	    String c= gs();

        //System.out.print(aubstring(0,1));
        if (a.charAt(a.length()-1) == b.charAt(0) && b.charAt(b.length()-1) == c.charAt(0)) {
        	System.out.print("YES");
        }else{
        	System.out.print("NO");
        }

	   
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}
}

Measured memory_bytes: 35500
while True:
        n = input()
        if n == 0:
            break
        m = input()
        s = raw_input()
        graph = []
        for i in xrange(n):
            graph.append({"I":2*i+1,"O":0,"score":0})
            graph.append({"I":1,"O":2*(i+1),"score":0})
        graph.append({"I":2*n+1,"O":0,"score":0})
        graph.append({"I":1,"O":2*n,"score":1})
        cur,score = 0,0
        for c in s:
            cur = graph[cur][c]
            score += graph[cur]["score"]
        print score

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll n,k;
  cin >> n >> k;
  ll ans = n-k+1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n;
        cin>>n;
        cout<<(1000-n%1000)%1000;
   return 0;    
}

Measured memory_bytes: 3636
import numpy as np
N = int(input())
L = list(map(int,input().split()))
ans = 0
P = []
for i in range(N) :
    if L[i] % 2 == 0 :
        p = 2
    else :
        p = 1
    P.append(p)

ans = 3**N - np.prod(P)
print(ans)


Measured memory_bytes: 12424
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	long[] a, b;
	void Solve()
	{
		var I = GL;
		var N = (int)I[0];
		var X = I[1] - 1;
		a = new long[N + 1];
		b = new long[N + 1];
		a[0] = b[0] = 1;
		for (var n = 0; n < N; n++) { a[n + 1] = 2 * a[n] + 3; b[n + 1] = 2 * b[n] + 1; }
		WriteLine(Calc(N, X));
	}
	long Calc(int n, long x)
	{
		return x < 0 ? 0 : x >= a[n] - 1 ? b[n] : x < a[n - 1] + 1 ? Calc(n - 1, x - 1) : Calc(n - 1, x - a[n - 1] - 2) + b[n - 1] + 1;
	}
}


Measured memory_bytes: 13268
import java.util.Scanner;

 public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        int pivot = partition(a, 0, n - 1);

        for (int i = 0; i < n; i++) {
            if (i != 0)
                System.out.print(" ");
            if (i == pivot) {
                System.out.print("[" + a[i] + "]");
            } else {
                System.out.print(a[i]);
            }
        }
        
        System.out.println();
    }

    static int partition(int[] a, int p, int r) {
        int x = a[r];
        int i = p - 1;
        for (int j = p; j < r; j++) {
            if (a[j] <= x) {
                i++;
                swap(a, i, j);
            }
        }
        swap(a, i + 1, r);
        return i + 1;
    }

    private static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}


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

#+++++
		
def main():
	n, d = map(int, input().split())
	ll=lambda :list(map(int, input().split()))
	xl=[ll() for i in range(n)]
	
	lll= [x**2 for x in range(170)]
	cc=0
	for i, x in enumerate(xl):
		for y in xl[i+1:]:
			a=0
			for xv, yv in zip(x,y):
				a += (xv - yv)**2
			cc+=1 if a in lll else 0
		
	print(cc)
	
	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		
	ret = main()
	if ret is not None:
		print(ret)

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int n;
vector<double> x(50);
vector<double> y(50);

double searchy(double ly, double ry, double cx){
    double my1 = (ly*2+ry)/3.0;
    double my2 = (ly+ry*2)/3.0;

    double r1 = 0.0;
    double r2 = 0.0;
    for(int i = 0; i < n; i++){
        r1 = max(r1, sqrt((x[i]-cx)*(x[i]-cx)+(y[i]-my1)*(y[i]-my1)));
        r2 = max(r2, sqrt((x[i]-cx)*(x[i]-cx)+(y[i]-my2)*(y[i]-my2)));
    }

    if(abs(r1-r2) < 0.00000001){
        return r1;
    }

    if(r1 > r2){
        return searchy(my1, ry, cx);
    } else {
        return searchy(ly, my2, cx);
    }
}

double searchx(double lx, double rx){
    double mx1, mx2, r1, r2;

    for(int i = 0; i < 70; i++){
        mx1 = (lx*2+rx)/3.0;
        mx2 = (lx+rx*2)/3.0;

        r1 = searchy(0,1000,mx1);
        r2 = searchy(0,1000,mx2);

        if(r1 > r2){
            lx = mx1;
        } else {
            rx = mx2;
        }
    }

    return r1;
}

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> x[i] >> y[i];
    }

    double ans = searchx(0, 1000);
    cout << std::fixed << std::setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 3856
#include <iostream>
#include <vector>
#include <algorithm>
 
int main()
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);
 
  unsigned N = 0, K = 0;
  std::cin >> N;
  std::cin >> K;
  std::vector<int> vec(N, 0); 
  for (unsigned i = 0; i < N; ++i)
  {
    std::cin >> vec[i];
  }
 
  std::vector<int> cache(vec.size(), 0); 
  cache[0] = 0;
  cache[1] = abs(vec[1] - vec[0]);
  for (size_t i = 2; i < vec.size(); ++i)
  {
    cache[i] = 1<<30;
    for (int j = std::max<int>(0, i-K); j < i; ++j)
    {   
      cache[i] = std::min(cache[i], cache[j] + abs(vec[j] - vec[i]));
    }
  }
  std::cout << cache.back();
 
  return 0;
}

Measured memory_bytes: 1024
from collections import deque
import sys


def I(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))


INF = float('inf')


class Graph:
    def __init__(self, n, is_directed=False):
        self.graph = [[] for _ in range(n)]
        self.is_directed = is_directed

    def add_edge(self, u, v):
        """頂点uから頂点vに辺を作る
        無向グラフの場合、uからvの方向の辺のみを記録する
        """
        self.graph[u].append(v)
        if not self.is_directed:
            self.graph[v].append(u)

    def bfs(self, start):
        """幅優先探索を行い始点から各頂点までの距離の配列を返す
        """
        distances = [INF] * len(self.graph)
        queue = deque([start])
        distances[start] = 0
        ans = [0] * len(self.graph)

        while queue:
            now = queue.popleft()
            for to in self.graph[now]:
                if distances[to] != INF:
                    continue
                queue.append(to)
                ans[to] = now
                distances[to] = distances[now] + 1
        return distances, ans

    def dfs(self, start):
        """幅優先探索を行い始点から各頂点までの距離の配列を返す
        """
        distances = [INF] * len(self.graph)
        queue = deque([start])
        distances[start] = 0
        ans = [0] * len(self.graph)

        while queue:
            now = queue.pop()
            for to in self.graph[now]:
                if distances[to] != INF:
                    continue
                queue.append(to)
                # 前の頂点からこの頂点に対する道標を建てる
                ans[to] = now
                distances[to] = distances[now] + 1
        return distances, ans


def main():
    n, m = LI()
    g = Graph(n)
    for _ in range(m):
        a, b = LI()
        a, b = a - 1, b - 1
        g.add_edge(a, b)

    bfs_res, ans = g.bfs(0)
    for d in bfs_res:
        if d == INF:
            print('No')
            return

    print('Yes')
    print(*map(lambda x: x + 1, ans[1:]), sep='\n')


if __name__ == '__main__':
    main()


Measured memory_bytes: 39320
n, k = map(int,input().split())
a = list(map(int,input().split()))
mod = 10**9 + 7

plus = []
minus = []

for i in a:
	if i >= 0:
		plus.append(i)
	else:
		minus.append(i)

plus.sort(key = lambda x:-x)
minus.sort()

#print(plus, minus)

"""
貪欲チックに求める
numplus … 前からnumplus番目まで掛け合わせる
numminus … 前からnumminus番目まで掛け合わせる

入力例2に合わせるのは場合分けが必要だが, minusは2個単位で管理する.
"""

numplus = k
numminus = 0

"""
kがplusを超える場合, うまく処理ができないのでリスト参照できる範囲まで下げる.
"""
while numplus > len(plus):
	numplus -= 2
	numminus += 2

#print(numplus, numminus)

while numplus-2 >= 0 and numminus+1 < len(minus):
	if plus[numplus-1] * plus[numplus-2] <= minus[numminus] * minus[numminus+1]:
		numplus -= 2
		numminus += 2
	else:
		break

#print(numplus, numminus)

ans = 1

if numplus >= 0 and numminus >= 0 and numminus <= len(minus):
	for i in range(numplus):
		ans = ans * plus[i] % mod
	for i in range(numminus):
		ans = ans * minus[i] % mod
else:
	"""
	これは, ansが負になる場合や, minusが1個だけの場合, minusしかない場合, plusしかない場合に使える.
	"""
	#print("ここに来ました！")
	tmp = sorted(a, key=lambda x:-x)
	for i in range(k):
		ans = ans * tmp[i]%mod

print(ans)

Measured memory_bytes: 30844
#include<stdio.h>
#include<string.h>
int main()
{
    int N,i,sum=0;
    scanf("%d",&N);
    int V[N],C[N];
    for(i=0;i<N;i++){
        scanf("%d",&V[i]);
    }
    for(i=0;i<N;i++){
        scanf("%d",&C[i]);
    }

    for(i=0;i<N;i++){
        if(V[i]>C[i])
            sum+=V[i]-C[i];
    }
    printf("%d\n",sum);
return 0;
}


Measured memory_bytes: 128
N, K = map(int, input().split())
A = list(map(int, input().split()))

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = max(A)
ng = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2

    cnt = 0
    for a in A:
        l = (a + mid - 1) // mid
        cnt += l - 1
    if cnt <= K:
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 93876
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt();
    if(n%10==3){
      System.out.println("bon");
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
      System.out.println("pon");
    }else{
      System.out.println("hon");
    }
  }
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 100000 + 10;

template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

int n;
vector<LL> vec;
map<int, bool> mp;

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    scanf("%d", &n);
    for(int i = 1; i <= n; ++i) { 
        LL x = read<int>();
        if(mp[x]) {
            mp.erase(x);
            vec.pb(x);
        }else mp[x] = true;
    }

    sort(vec.begin(), vec.end(), greater<LL>());

    if(vec.size() > 1) 
        printf("%lld\n", vec[0] * vec[1]);
    else printf("0\n");

    return 0;
}


Measured memory_bytes: 4992
n = input()
op_cnt = len(n) - 1  # すき間の個数
for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt  # あらかじめ ["-", "-", "-"] というリストを作っておく
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - 1 - j] = "+"  # フラグが立っていた箇所を "+" で上書き

    formula = ""
    for p_n, p_o in zip(n, op + [""]):  # 少々モヤッとする
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        break

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

int main(void)
{
    using namespace std;
    int m, f, r;
    while(true) {
        scanf("%d %d %d", &m, &f, &r);
        if (m == -1 && f == -1 && r == -1) {
            break;
        } else if (m == -1 || f == -1) {
            printf("F\n");
        } else if ((m + f) >= 80) {
            printf("A\n");
        } else if ((m + f) >= 65) {
            printf("B\n");
        } else if ((m + f) >= 50) {
            printf("C\n");
        } else if ((m + f) >= 30) {
            if (r >= 50) {
                printf("C\n");
            } else {
                printf("D\n");
            }
        } else {
            printf("F\n");
        }
    }
}


Measured memory_bytes: 3140
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, t[102] = {}, p, x, z = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> t[i], z += t[i];
    cin >> m;
    while (m--) {
        cin >> p >> x;
        cout << z + x - t[p] << '\n';
    }
}


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

using LL = long long;
int n;
vector<LL> a, s;

LL gao(int id) {
  LL ret = 1E18, tmp = 1E18;
  int lo = 1, hi = id, s1 = 1, s2 = 1;
  while(lo <= hi) {
    int mid = (lo + hi) >> 1;
    if(tmp == 1E18 || tmp > (LL)abs(s[id]-s[mid]-s[mid])) {
      tmp = (LL)abs(s[id]-s[mid]-s[mid]);
      s1 = mid;
    }
    if(s[id]-s[mid]<s[mid]) hi = mid - 1;
    else lo = mid + 1;
  }
  lo = id + 1, hi = n, tmp = 1E18;
  while(lo <= hi) {
    int mid = (lo + hi) >> 1;
    if(tmp == 1E18 || tmp > (LL)abs(s[n]-s[mid]-(s[mid]-s[id]))) {
      tmp = (LL)abs(s[n]-s[mid]-(s[mid]-s[id]));
      s2 = mid;
    }
    if(s[n]-s[mid]<s[mid]-s[id]) hi = mid - 1;
    else lo = mid + 1;
  }
  LL L = min({s[s1], s[id]-s[s1], s[s2]-s[id], s[n]-s[s2]});
  LL R = max({s[s1], s[id]-s[s1], s[s2]-s[id], s[n]-s[s2]});
  ret = min(ret, R-L);
  return ret;
}

signed main() {
  // freopen("in", "r", stdin);
  while(cin >> n) {
    a.resize(n+1); s.resize(n+1);
    for(int i = 1; i <= n; i++) {
      cin >> a[i];
      s[i] = s[i-1] + a[i];
    }
    LL ret = 1E18;
    for(int i = 1; i <= n; i++) {
      ret = min(ret, gao(i));
    }
    cout << ret << endl;
  }
  return 0;
}

Measured memory_bytes: 3328
#define _CRT_NONSTDC_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <array>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>
#include <map>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
const int INTMAX = numeric_limits<int>::max();
const int INTMIN = numeric_limits<int>::min();
const ll LLMAX = numeric_limits<long long>::max();
const ll LLMIN = numeric_limits<long long>::min();
const int MOD = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }

bool solve() {

	int n;
	cin >> n;
	vector<int> a(n + 1);
	vector<int> b(n + 1);
	for (int i = 1; i <= n; i++) cin >> a[i];
	int ball = 0;

	int d = 2;
	for (int i = n; i >= 1; i--) {
		int sum = 0;
		for (int j = i; j <= n; j += i) {
			sum += b[j];
		}
		if (sum % 2 != a[i]) {
			if (b[i] == 0) b[i] = 1;
			else b[i] = 0;
		}

	}

	
	for (int i = 1; i <= n; i++)
		if (b[i]) ball++;
	cout << ball << endl;
	for (int i = 1; i <= n; i++) {
		if (b[i]) cout << i << ' ';
	}
		

	return true;
}

signed main() {
	solve();

	return 0;
}

Measured memory_bytes: 2432
/*
Date: 2017/01/15 19:44:55 Sunday
*/
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define rep(i,a,n) for(int i=(a);i<=(n);++i)
#define dep(i,a,n) for(int i=(a);i>=(n);--i)
#define eps 1e-8
#define pi 3.1415926535897
#define sqr(x) ((x)*(x))
#define MAX(a,b) a=max(a,b)
#define MIN(a,b) a=min(a,b)
#define SZ(x) ((int)(x).size())
#define CPY(a,b) memcpy(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define POSIN(x,y) (1<=(x)&&(x)<=n&&1<=(y)&&(y)<=m)
#define all(x) (x).begin(),(x).end()
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
#define buli(x) (__builtin_popcountll(x))
#define bur0(x) (__builtin_ctzll(x))
#define bul2(x) (63-__builtin_clzll(x))
#define pw(x) ((ll(1))<<(x))
#define upmo(a,b) (((a)=((a)+(b))%mo)<0?(a)+=mo:(a))
#define mmo(a,b) (((a)=1ll*(a)*(b)%mo)<0?(a)+=mo:(a))
#define y0 y0z
#define y1 y1z
#define yn ynz
#define j0 j0z
#define j1 j1z
#define jn jnz
#define tm tmz
#ifdef LOCAL
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define debug(...) 
#endif
typedef long long ll;
typedef double lf;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<lf,lf> pff;
typedef complex<double> CD;
const int inf=0x3f3f3f3f;
const int mo=1000000007;
inline void gn(long long&x){
	int sg=1;char c;while(((c=getchar())<'0'||c>'9')&&c!='-');c=='-'?(sg=-1,x=0):(x=c-'0');
	while((c=getchar())>='0'&&c<='9')x=x*10+c-'0';x*=sg;
}
inline void gn(int&x){long long t;gn(t);x=t;}
inline void gn(unsigned long long&x){long long t;gn(t);x=t;}
inline void gn(double&x){double t;scanf("%lf",&t);x=t;}
inline void gn(long double&x){double t;scanf("%lf",&t);x=t;}
template<class T1,class T2>inline void gn(T1&r,T2&s){gn(r),gn(s);}
template<class T1,class T2,class T3>inline void gn(T1&r,T2&s,T3&t){gn(r),gn(s),gn(t);}
template<class T1,class T2,class T3,class T4>inline void gn(T1&r,T2&s,T3&t,T4&u){gn(r),gn(s),gn(t),gn(u);}
inline void gs(char *s){scanf("%s",s);}
inline void gc(char &c){while((c=getchar())>126 || c<33);}
inline void pc(char c){putchar(c);}
const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll powmod(ll a,ll b,ll mo) {ll res=1;a%=mo;for(;b;b>>=1){if(b&1)res=res*a%mo;a=a*a%mo;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
//*******************************************

const int N=1111,M=111111;
int l,m,n,t,A,B,C,D;
ll dp[N][N],CC[N][N];
ll jc[N],inv[N];
int main(){
#ifdef LOCAL
	freopen("C.in","r",stdin);//freopen("C.out","w",stdout);
#endif
	scanf("%d%d%d%d%d",&n,&A,&B,&C,&D);
	jc[0]=1;
	rep(i,1,1010)jc[i]=jc[i-1]*i%mo;
	rep(i,0,1010)inv[i]=powmod(jc[i],mo-2);
	CC[0][0]=1;
	rep(i,1,1010){
		CC[i][0]=1;
		rep(j,1,i)CC[i][j]=(CC[i-1][j]+CC[i-1][j-1])%mo;
	}
	dp[A-1][0]=1;
	rep(i,A,B){
		rep(j,0,n)if(j==0||j>=C&&j<=D){
			dep(k,n-j*i,0){
				ll q=dp[i-1][k]*CC[n-k][i*j]%mo;
				q=q*jc[i*j]%mo*powmod(inv[i],j)%mo*inv[j]%mo;
				dp[i][k+j*i]=(dp[i][k+j*i]+q)%mo;
			}
		}
		//rep(j,0,n)printf("%d %d %d\n",i,j,dp[i][j]);
	}
	cout<<dp[B][n]<<endl;
	return 0;
}

Measured memory_bytes: 16256
def q69(w):
    word_count = {}
    for i in w:
        if i in word_count:
            word_count[i] += 1
        else:
            word_count[i] = 1

    for i in word_count.values():
        if i % 2 != 0:
            return 'No'
        
    return 'Yes'
            
w = list(input())
print(q69(w))


Measured memory_bytes: 2940
//Bismillahir rahmanir rahim
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll n,W;
ll weight[105],value[105];
ll dp[105][100005];
ll solve(ll pos,ll w)
{
    if(w>W) return -1e18;
    if(pos==n) return 0;
    ll &ret=dp[pos][w];
    if(ret!=-1) return ret;
    ret=0;
    ret=max(ret,solve(pos+1,w+weight[pos])+value[pos]);
    ret=max(ret,solve(pos+1,w));
    return ret;
}
int main()
{
    scanf("%lld %lld",&n,&W);
    for(ll i=0;i<n;i++){
        ll w,v;
        scanf("%lld %lld",&weight[i],&value[i]);
    }
    memset(dp,-1,sizeof(dp));
    ll ans=solve(0,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 82432
import java.util.*;
import java.io.*;
import java.lang.*;

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

        int n = sc.nextInt();

        int[] arr = new int[n];

        long ans = 0;

        for (int i = 0; i<n; i++){
            arr[i] = sc.nextInt();
        }

        for (int i = 1; i<n; i++){
            if (arr[i] < arr[i-1]){
                ans += (arr[i-1]-arr[i]);
                arr[i] = arr[i-1];
            }
        }
        System.out.println(ans);
    }
}

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

int main(){
    string s,t;
    cin>>s>>t;
    int ans=1e9;
    rep(i,s.size()-t.size()+1){
        int cnt=0;
        rep(j,t.size()){
            if(s[i+j]!=t[j]){
                       cnt++;
                   }
        }
        ans=min(ans,cnt);
    }
    cout<<ans;
   
    
    }


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


def main():
    s = input()[::-1]
    mod = 10 ** 9 + 7

    # DPテーブル（あまりが0～12となる組み合わせを管理）を用意
    n = 13
    dp = [0 for _ in range(n)]
    dp[0] = 1

    # 桁数の初期化
    digit = 1

    # 1文字ずつ見る
    for si in s:
        # 更新用のテーブルnext_dp[n]を用意
        next_dp = [0 for _ in range(n)]

        if si == '?':
            # '?'の取りうる範囲
            for q in range(10):
                # XXX: next_dpの括弧内の理解がかなり怪しい
                # digit - 1桁のときの結果を使って，
                # それぞれのあまりについて組み合わせの数を更新
                for j in range(n):
                    next_dp[(q * digit + j) % n] += dp[j]
                    next_dp[(q * digit + j) % n] %= mod
        else:
            q = int(si)

            for j in range(n):
                next_dp[(q * digit + j) % n] += dp[j]
                next_dp[(q * digit + j) % n] %= mod

        # DPテーブルを上書き
        dp = next_dp

        # 桁数を1つ増やす
        digit *= 10
        digit %= n

    # dp[5]が答え
    print(dp[5])


if __name__ == '__main__':
    main()


Measured memory_bytes: 44012
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --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 SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(v) for (auto itr = v.begin(), itr != v.end(); ++itr)
#define LB(v, x) lower_bound(v.begin(), v.end(), x) - v.begin()
#define UB(v, x) upper_bound(v.begin(), v.end(), x) - v.begin()
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class Zp {
    const int p = 1000000007;
    ll r;
    void set(ll x) {
        while (x < 0) x += p;
        r = x % p;
    }

public:
    Zp(ll x) { set(x); }
    Zp() { set(0); }

    Zp operator-() const { return Zp(-r); }
    Zp &operator=(ll y) {
        set(y);
        return *this;
    }
    Zp &operator=(const Zp &y) { return *this = y.r; }

    Zp &operator+=(ll y) {
        set(r + y);
        return *this;
    }
    Zp &operator-=(ll y) { return *this += -y; }
    Zp &operator*=(ll y) {
        set(r * y);
        return *this;
    }
    Zp &operator/=(ll y) { return *this *= inv(y); }
    Zp operator+(ll y) const { return Zp(r + y); }
    Zp operator-(ll y) const { return *this + (-y); }
    Zp operator*(ll y) const { return Zp(r * y); }
    Zp operator/(ll y) const { return *this * inv(y); }

    Zp &operator+=(const Zp &y) { return *this += y.r; }
    Zp &operator-=(const Zp &y) { return *this -= y.r; }
    Zp &operator*=(const Zp &y) { return *this *= y.r; }
    Zp &operator/=(const Zp &y) { return *this /= y.r; }
    Zp operator+(const Zp &y) const { return *this + y.r; }
    Zp operator-(const Zp &y) const { return *this - y.r; }
    Zp operator*(const Zp &y) const { return *this * y.r; }
    Zp operator/(const Zp &y) const { return *this / y.r; }

    Zp pow(int n) const {
        if (n == 0) return 1;
        if (n % 2) return *this * pow(n - 1);
        Zp tmp = pow(n / 2);
        return tmp * tmp;
    }
    Zp inv(int x) const { return Zp(x).pow(p - 2); }
    Zp inv() const { return inv(r); }

    ll get() const { return r; }

    friend istream &operator>>(istream &istr, Zp &x) {
        istr >> x.r;
        x.set(x.r);
        return istr;
    }
    friend ostream &operator<<(ostream &ostr, const Zp &x) {
        ostr << x.r;
        return ostr;
    }
};
class Comb {
    vector<Zp> fact, ifact;

public:
    Comb(int N) : fact(N + 1), ifact(N + 1) {
        fact[0] = 1;
        REP(i, N) fact[i + 1] = fact[i] * (i + 1);
        ifact[N] = fact[N].inv();
        REPR(i, N) ifact[i] = ifact[i + 1] * (i + 1);
    }
    Zp operator()(int n, int k) const {
        return fact[n] * ifact[n - k] * ifact[k];
    }
    Zp f(int k) const { return fact[k]; }
    Zp invf(int k) const { return ifact[k]; }
};

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

    ll N, K;
    cin >> N >> K;
    vector<int> sum(N + 1);
    Zp res = 0;
    FOR(i, K, N + 2) { res += i * (N - i + 1) + 1; }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3992
a, b = map(int, input().split())

from math import ceil

a1 = ceil(a / 0.08)
a2 = ceil((a+1) / 0.08)
b1 = ceil(b / 0.1)
b2 = ceil((b+1) / 0.1)

m = min([a1,b1])

if m == a1:
    if b1 in range(a1,a2):
        ans = b1
        print(ans)
    else:
        print('-1')

else:
    if a1 in range(b1,b2):
        ans = a1
        print(ans)
    else:
        print('-1')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  map<ll, ll> cnt;
  ll A;
  rep(i, N){
    cin >> A;
    cnt[A]++;
  }

  ll odd = 0, even = 0;
  for(auto itr = cnt.begin(); itr != cnt.end(); itr++){
    if((itr->second) % 2) odd++;
    else even++;
  }

  odd += 2 * (even / 2);

  cout << odd << endl;
  
  return 0;
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,k,n,m,o,p,l;
    char str[1001][1001];
    while(~scanf("%d %d",&n,&m))
    {
        getchar();
        for(i=1;i<=n;i++)
        {
            scanf("%s",str[i]);
            getchar();
        }
        for(i=1;i<=n;i++)
        {
            printf("%s\n",str[i]);
            printf("%s\n",str[i]);
        }
    }
    return 0;
}


Measured memory_bytes: 1764
#include<stdio.h>
#include<stdlib.h>

int main(void){

  int N;

  long long int S=0;
  
  scanf("%d\n",&N);
  
  for(int i=0;i<N;i++){
  
    S=i+S;
  
  }

  printf("%lld\n",S);

  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int k;
	cin>>k;
	ll num=0;
	map<ll,bool> m;
	for(int i=1;;i++){
		num=num*10+7;
		num=num%k;
		if(num==0){
			cout<<i;
			break;
		}
		else if(m[num]){
			cout<<-1;
			break;
		}
		else{
			m[num]=1;
		}
	} 
	re 0;
}

Measured memory_bytes: 66092
#include <iostream>

using namespace std;

int main()
{
    cout.precision( 6 );
    cout.setf( ios::fixed, ios::floatfield );

    int a, b;
    while( cin >> a >> b ) {
        cout << static_cast<double>( a * b ) / 3.305785 << endl;
    }
}

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

int main()
{
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  vector<int> a(n),b(m);
  for(int i = 0;i < n;i++) cin >> a[i];
  for(int i = 0;i < m;i++) cin >> b[i];
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());

  bool flag = false;
  for(int i = x + 1;i <= y;i++){
    if(a[n-1] < i && b[0] >= i) flag = true;
  }
  if(flag) cout << "No War" << endl;
  else cout << "War" << endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio> 
using namespace std;
static const int INFTY = (1<<21);
int n, M[100][100];
int color[100],d[100],p[100];

void dijkstra()
{
    for (int i = 0; i < n; i++)
    {
        d[i] = INFTY;
        p[i] = -1;
        color[i] = 0;
    } 
    
    d[0] = 0;

    while (true)
    { 
        int mincost = INFTY;
        int u = -1;
        for (int i = 0; i < n; i++)
        {
            if (color[i] != 2 && d[i] < mincost )
            { 
                mincost = d[i];
                u = i;
            }         
        } 
        if (mincost == INFTY) break;
        color[u] = 2;
        for (int v = 0; v < n; v++)
        {
            if (color[v] != 2 && d[u] + M[u][v] < d[v])
            { 
                d[v] = d[u] + M[u][v];
                p[v] = u;
                color[v] = 1;
            }  
        } 
    } 

}

int main()
{
    //freopen("in3.txt","r",stdin);
    int u,k,v,c;
    cin>>n;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            M[i][j] = INFTY; 
        }  
    } 
    for (int i = 0; i < n; i++)
    {
        cin>>u>>k;
        for (int j = 0; j < k; j++)
        {
            cin>>v>>c; 
            M[u][v] = c; 
        } 
    } 
    
    dijkstra();

    for (int i = 0; i < n; i++)
    {
        cout<<i<<" "<<d[i]<<endl; 
    } 
    
    return 0;
}

Measured memory_bytes: 3104
s = input()
n = len(s)

from itertools import product

ans = 0
# 後ろから切っていく
for i in product([0, 1], repeat=n-1):
    ss = s
    num = 0
    for j in range(n-1):
        if i[j] == 1:
            num += int(ss[n-j-1:])
            ss = ss[:n-j-1]
    num += int(ss)
    ans += num

print(ans)

Measured memory_bytes: 67804
#include <iostream>
#include <cstdio>
#include <bitset>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <limits>

using namespace std;
using ll=long long;
using vint=vector<int>;
using pint=pair<int,int>;

const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

#define rep(i,n) for(int i=0;i<int(n);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,i,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

bool judge(int c[3][3]){
	if(c[0][0] - c[0][1] != c[1][0] - c[1][1])
		return false;
	if(c[1][0] - c[1][1] != c[2][0] - c[2][1])
		return false;

	if(c[0][1] - c[0][2] != c[1][1] - c[1][2])
		return false;
	if(c[1][1] - c[1][2] != c[2][1] - c[2][2])
		return false;

	if(c[0][0] - c[1][0] != c[0][1] - c[1][1])
		return false;
	if(c[0][1] - c[1][1] != c[0][2] - c[1][2])
		return false;

	if(c[1][0] - c[2][0] != c[1][1] - c[2][1])
		return false;
	if(c[1][1] - c[2][1] != c[1][2] - c[2][2])
		return false;
	return true;
}

void solve(){
	int c[3][3];
	rep(i,3)
		rep(j,3)
			cin >> c[i][j];
	if(judge(c))
		cout << "Yes";
	else
		cout << "No";
	cout << endl;

}

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

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n,k;
  cin >> n >> k;
  cout << (n%k?1:0) << endl;
  return 0;
}


Measured memory_bytes: 764
#include <iostream>

using namespace std;

void func(int ans[], int p[], int c[], int d, int g, int num, int total,
          int idx, bool flg[]) {
  if (total >= g) {
    ans[0] = min(ans[0], num);
    return;
  }

  for (int i = idx; i < d; i++) {
    num += p[i];
    total += 100 * (i + 1) * p[i] + c[i];
    flg[i] = true;
    func(ans, p, c, d, g, num, total, i + 1, flg);
    num -= p[i];
    total -= 100 * (i + 1) * p[i] + c[i];
    flg[i] = false;
  }

  for (int i = d - 1; i >= 0; i--) {
    if (!flg[i]) {
      for (int j = 1; j < p[i]; j++) {
        num += 1;
        total += 100 * (i + 1);
        if (total >= g) {
          ans[0] = min(ans[0], num);
          return;
        }
      }
      num -= p[i] - 1;
      total -= 100 * (i + 1) * (p[i] - 1);
      break;
    }
  }
}

int main() {
  int d, g;
  cin >> d >> g;

  int p[d];
  int c[d];
  int ans[1];
  ans[0] = 0;
  bool flg[d];
  for (int i = 0; i < d; i++) {
    cin >> p[i] >> c[i];
    ans[0] += p[i];
    flg[i] = false;
  }

  func(ans, p, c, d, g, 0, 0, 0, flg);

  cout << ans[0] << endl;

  return 0;
}


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

int main() {
	int e;
	cin >> e;
	if (e == 25) cout << "Christmas" << endl;
		if (e == 24) cout << "Christmas Eve" << endl;
		if (e == 23)cout << "Christmas Eve Eve" << endl;
		if (e == 22)cout << "Christmas Eve Eve Eve" << endl;
	return 0;
}

Measured memory_bytes: 256
#最大値の最小値を求める問題は二分探索
#求めるものを変数と見て丸太の最大値がxだとすると
#丸太の長さは全てx以下である必要があるため切るべき回数がわかる
#それがk回以下ならokだしそれがk回を超えていたらだめ
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
ng=0
ok=max(a)

def check(x):
  num=0
  for i in range(n):
    if a[i]%x==0:
      num=num+a[i]//x-1
    else:
      num=num+a[i]//x
  return num<=k

while ok-ng>1:
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)



Measured memory_bytes: 30732
#include<stdio.h>

int addEachPlace(int N){
    int ans = 0;
    while(N>0){
        ans += N % 10;
        N /= 10;
    }
    return ans;
}

int main(){
    int N=0, A=0, B=0,sum=0;

    scanf("%d",&N);
    scanf("%d",&A);
    scanf("%d",&B);

for(int i=1;i<=N;i++){
    int temp = addEachPlace(i);
    if(A<=temp && B>=temp){
        sum += i;
    }
}

printf("%d\n",sum);
}

Measured memory_bytes: 128
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>

using namespace std;

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();}

typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EACH(t,i,c) for(t::iretator i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,n-1)

const double EPS = 1e-10;

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

vvi field(1002, vi(1002, 0));
vvi cost(1002, vi(1002, 0));

int bfs(pii start, pii goal) {
	REP(i, 1002) {
		REP(j, 1002) {
			cost[i][j] = 10000;
		}
	}
	cost[start.first][start.second] = 0;

	queue<pii> Q;
	Q.push(start);

	while(!Q.empty()) {
		pii p = Q.front();
		Q.pop();
		if(p == goal) {
			break;
		}
		REP(i, 4) {
			int ny = p.first + dy[i], nx = p.second + dx[i];
			if(field[ny][nx] && cost[ny][nx]==10000) {
				Q.push(pii(ny, nx));
				cost[ny][nx] = cost[p.first][p.second]+1;
			}
		}
	}

	return cost[goal.first][goal.second];
}

int main() {
	int H, W, N;
	cin >> H >> W >> N;

	vector<pii> point(N+1);

	string str;
	REP(i, H) {
		cin >> str;
		REP(j, W) {
			switch(str[j]) {
			case 'S':
				point[0].first = i+1;
				point[0].second = j+1;
				field[i+1][j+1] = 1;
				break;
			case '1': case '2': case '3': case '4': case '5':
			case '6': case '7': case '8': case '9':
				point[str[j]-'0'].first = i+1;
				point[str[j]-'0'].second = j+1;
				field[i+1][j+1] = 1;
				break;
			case 'X':
				field[i+1][j+1] = 0;
				break;
			case '.':
				field[i+1][j+1] = 1;
				break;
			}
		}
	}

	int ans = 0;
	REP(i, N) {
		ans += bfs(point[i], point[i+1]);
	}

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

Measured memory_bytes: 8928
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define MAXINF 1000000005
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repc(it, x) for(auto it = (x).begin(); it != (x).end(); ++it)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rrepc(it, x) for(auto it = (x).rbegin(); it != (x).rend(); ++it)
#define all(x) (x).begin(), (x).end()

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h;
    cin >> h;
    ll ans = 0, count = 0;
    while(h > 1) {
        h /= 2;
        ans += 1 * (pow(2, count++));
    }
    ans += 1 * (pow(2, count));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from heapq import heappush, heappushpop, heapify
from fractions import gcd

N = int(readline())
m = map(int,read().split())
AB = sorted(zip(m,m),key=lambda x:(x[1],x[0]))
A,B = zip(*AB)

dp2 = [0]*N # T_B - T_A
for i in range(N-1,0,-1):
    a = A[i]; b = B[i]
    if a<b:
        dp2[i-1] = dp2[i]+(b-a)
    else:
        dp2[i-1] = dp2[i]

def F(n):
    opt_num = -1
    opt_den = 1
    q = list(-x for x in A[:n])
    heapify(q)
    S = -sum(q)
    for i in range(n,N):
        a = A[i]; b = B[i]
        x = S+a-dp2[i]
        if 0<=x<=b:
            den = b
            num = (n+1)*den-x
            if opt_num*den < opt_den*num:
                opt_num = num; opt_den = den
        x = a
        y = -heappushpop(q,-x)
        S += x-y
    return opt_num, opt_den

opt_num = 0; opt_den = 1
left = -1 # 値がある
right = N+10 # むり
while left+1 < right:
    mid = (left+right)//2
    num,den = F(mid)
    if num==-1:
        right=mid
    else:
        left=mid
        if opt_num*den < opt_den*num:
            opt_num = num; opt_den = den

opt_den *= N
g = gcd(opt_num,opt_den)
opt_num//=g; opt_den//=g
print(opt_num,opt_den)

Measured memory_bytes: 123072
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	a = a+b;
	if(a<10) cout<<a<<endl;
	else
		cout<<"error"<<endl;
	return 0;
}

Measured memory_bytes: 256
let () =
    try
        while true do
            let x, y   = Scanf.scanf "%d %d\n" (fun x y -> x, y) in
            let total  = x + y in
            let digits = (String.length (string_of_int total)) in
            Printf.printf "%d\n" digits
        done
    with
        End_of_file -> ()

Measured memory_bytes: 2448
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
vector<int>G[maxn];
int x[maxn],y[maxn],w[maxn];
int col[maxn], n;
void dfs(int u,int fa,int dis){
    col[u] = dis % 2;
    for (int i=0,sz = G[u].size();i<sz;i++){
        int ed = G[u][i];
        int v = (x[ed] == u ? y[ed] : x[ed]);
        if (v == fa) continue;
        dfs(v,u,dis+w[ed]);
    }
}
int main(){
    scanf("%d",&n);
    for (int i=1;i<n;i++){
        int u,v;
        scanf("%d%d%d",&u,&v,&w[i]);
        w[i] &= 1;
        x[i] = u; y[i] = v;
        G[u].push_back(i);
        G[v].push_back(i);
    }
    memset(col,-1,sizeof(col));
    dfs(1,1,0);
    for (int i=1;i<=n;i++) printf("%d\n",col[i]);
    return 0;
}


Measured memory_bytes: 10240
N, M = map(int, input().split())
A = [input() for i in range(N)]
B = [input() for i in range(M)]

ans = 'No'
for i in range((N-M+1)**2):
    y = i % (N-M+1)
    x = i // (N-M+1)
    check = True
    for j in range(M**2):
        v = j % M
        h = j // M
        if A[y+v][x+h] != B[v][h]:
            check = False
        if not check:
            break
    if check:
        ans = 'Yes'
        break

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(){
    int len;
    char s[210];
    scanf("%s",s);
    len = strlen(s);
    for(int i=2;i<=len;i+=2){
     bool no_match=false;
        for(int j=0;j<(len-i)/2;j++){
            if(s[j]!=s[(len-i)/2+j]){
               no_match=true;
               break;
            }
        }
        if(!no_match){
            printf("%d\n",len-i);
            return 0;
        }
       
    }
   return 0;
}

Measured memory_bytes: 128