akhauriyash/Code-Regression huggingface dataset:
// 22
/****************************************************
https://searleser97.gitlab.io/algorithms/template.cpp
****************************************************/

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define fors(_, x, n, s) for (int _ = x; _ < n; _ += s)
#define forn(_, x, n) fors(_, x, n, 1)
#define rep(_, n) forn(_, 0, n)
#define forrs(_, x, n, s) for (int _ = x; _ > n; _ -= s)
#define forrn(_, x, n) forrs(_, x, n, 1)
#define rrep(_, n) forrn(_, n - 1, -1)
#define fi first
#define se second
#define pb push_back
#define pairii pair<int, int>
#define all(x) x.begin(), x.end()
#define cerr(s) cerr << "\033[48;5;196m\033[38;5;15m" << s << "\033[0m"
// typedef __int128_t lli;
typedef long long int li;
typedef long double ld;
// 12
void _main(int tc) {
  int n;
  cin >> n;
  vector<li> h(n);
  rep(i, n) cin >> h[i];
  vector<li> mem(n, -1);
  mem[n - 1] = 0;
  function<li(li)> fcost = [&](int pos) -> li {
    if (pos == n) return 0;
    if (pos == n - 2) return abs(h[pos] - h[pos + 1]);
    if (mem[pos] != -1) return mem[pos];
    return mem[pos] = min(abs(h[pos] - h[pos + 1]) + fcost(pos + 1), abs(h[pos] - h[pos + 2]) + fcost(pos + 2));
  };
  cout << fcost(0) << endl;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0); return 0;
  int tc;
  cin >> tc;
  rep(i, tc) _main(i + 1);
}

Measured memory_bytes: 6528
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
int main()
{
    int n;
    double pone=0;
    double ptwo=0;
    double pthree=0;
    double pfour=0;
    std::cin >> n;
    int lista[n]={0};
    int listb[n]={0};
    for(int i=0;i<n;i++){
        std::cin >> lista[i];
    }
    for(int j=0;j<n;j++){
        std::cin >> listb[j];
    }
    for(int k=0;k<n;k++){
        pone+=abs(lista[k]-listb[k]);
        ptwo+=abs(lista[k]-listb[k])*abs(lista[k]-listb[k]);
        pthree+=abs(lista[k]-listb[k])*abs(lista[k]-listb[k])*abs(lista[k]-listb[k]);
        if(pfour<abs(lista[k]-listb[k]))pfour=abs(lista[k]-listb[k]);
    }
    ptwo=sqrt(ptwo);
    pthree=cbrt(pthree);
    printf("%.8f\n",pone);
    printf("%.8f\n",ptwo);
    printf("%.8f\n",pthree);
    printf("%.8f\n",pfour);
 //   std::cout << pone << " " << ptwo << " " << pthree << " " << pfour << std::endl;
    return 0;
}

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    H,N=MI()
    A=[0]*N
    B=[0]*N
    
    for i in range(N):
        A[i],B[i]=MI()
        
    inf =10**20
    dp=[[inf]*(H+1)for _ in range(N+1)]
    # dp[i]はi番目の魔法まででhpをj減らす方法
    
    dp[0][0]=0
    
    for i in range(N):
        a=A[i]
        b=B[i]
        for j in range(H+1):
            if j-a>=0:
                dp[i+1][j]=min(dp[i+1][j],
                               dp[i][j],
                               dp[i+1][j-a]+b)
            else:
                dp[i+1][j]=min(dp[i+1][j],
                               dp[i][j],
                               dp[i+1][0]+b)
                
    print(dp[-1][-1])

main()


Measured memory_bytes: 154832
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    for (int i = 0; i < N; i++) {
      ans += (sc.nextInt() - 1);
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 24564
while s = gets.chomp
  break if s == "0"

  res = 0
  one_n = 0

  s.split(" ").map{|e|
    e.to_i
  }.each{|e|
    if e == 1 then
      one_n += 1
    elsif e >= 10 && e <= 13
      res += 10
    else
      res += e
    end
  }

  f = false
  for i in 0..one_n #i: 1をそのまま使う数
    if res + i + 11*(one_n-i) <= 21 then
      res += i + 11*(one_n-i)
      f = true
      break
    end
  end

  if f
    puts res
  else
    puts 0
  end
end

Measured memory_bytes: 2392
#include "bits/stdc++.h"
using namespace std;
long long a[2][1000001];
char b[1000001];
int main()
{
	int n, q;
	scanf("%d\n", &n);
	for(int i = 1; i <= n; ++i)
	{
		scanf("%c", &b[i]);
		switch(b[i])
		{
			case 'D':
				a[0][i] = 1;
				break;
			case 'M':
				a[1][i] = 1;
				break;
		}
		for(int j = 0; j < 2; ++j) 
		{
			a[j][i] += a[j][i - 1]; 
		}
	}
	scanf("%d", &q);
	for(int i = 0, j; i < q; ++i)
	{
		scanf("%d", &j);
		long long total = 0, dm = 0;
		for(int k = 1; k <= n; k++)
		{
			if(k - j >= 1) 
			{
				if(b[k - j] == 'D')
				{
					dm -= a[1][k - 1] - a[1][k - j - 1];
				}
			}
			switch(b[k])
			{
				case 'M':
					dm += a[0][k] - a[0][max(0, k - j)]; 
					break;
				case 'C':
					total += dm;
					break;
			}
		}
		printf("%lld\n", total);
	}
}

Measured memory_bytes: 16896
n, m, c = map(int, input().split())
B = list(map(int, input().split()))

ans = 0
for _ in range(n):
    A = list(map(int, input().split()))
    cnt = c
    for i in range(m):
        cnt += A[i] * B[i]
          
    if cnt > 0: 
        ans += 1

print(ans)

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

static const int MAX = 1000000+10;
static const int INF = 1<<30;

int main(){
    vector<int> dp(MAX,INF);
    vector<int> odd(MAX,INF);
    dp[0] = odd[0] = 0;
    for(int i=1; ; i++){
        int cur = i*(i+1)*(i+2)/6;
        if(cur > MAX) break;
        for(int j=cur; j<MAX; j++){
            dp[j] = min(dp[j],dp[j-cur]+1);
            if(cur % 2 != 0) odd[j] = min(odd[j],odd[j-cur]+1);
        }
    }

    int N;
    
    while(cin>>N){
        if(N == 0) break;
        cout<<dp[N]<<" "<<odd[N]<<endl;
    }

    return 0;
}


Measured memory_bytes: 10564
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#define N 200001
#define MAX 1000

struct Node{
    int key;
    struct Node *right,*left,*parent;
};

struct Node *root,*NI;
struct Node *find(struct Node *u,int k){
    while(u != NI && k != u->key){
        if(k < u->key){u=u->left;}
        else{u=u->right;}
    }
    return u;
}

void insert(int k){
    struct Node *y=NI;
    struct Node *x=root;
    struct Node *z;

    z=(struct Node *)malloc(sizeof(struct Node));
    z->key=k;
    z->left=NI;
    z->right=NI;
    while(x != NI){
        y=x;
        if(z->key < x->key){  x=x->left;}
        else{x=x->right;}
    }
    z->parent=y;
    if(y==NI){root=z;}
    else{
        if(z->key < y->key){y->left=z;}
        else{y->right=z;}
    }
}

void inorder(struct Node *u){
    if(u==NI){return;}
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}
void preorder(struct Node *u){
    if(u==NI){return;}
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}
int main(void){
    int j,i,x;
    char line[7];
    scanf("%d",&j);
    for(i=0;i<j;i++){
        scanf("%s",line);
        if(!strcmp(line,"insert")){
            scanf("%d",&x);
            insert(x);
        }
        else if(!strcmp(line,"print")){
            inorder(root);
            puts("");
            preorder(root);
            puts("");
        }
        else{
            scanf("%d",&x);
            struct Node *temp=find(root,x);
            if(temp != NI){puts("yes");}
            else {puts("no");}
        }
    }
    return 0;
}



Measured memory_bytes: 20488
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <cstdint>
#include <cctype>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

using ll =  long long;
using Pll = pair<ll, ll>;
using Pii = pair<int, int>;

constexpr int INF = 1 << 30;
constexpr ll LINF = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr long double EPS = 1e-10;
constexpr int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};
constexpr int N_MAX = 200000;

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(n);
    vector<ll> cnt(N_MAX+1);
    for(int i=0;i<n;++i) {
        cin >> a[i];
        ++cnt[a[i]];
    }

    ll ans = 0;
    for(int i=1;i<=N_MAX;++i) {
        ans += cnt[i] * (cnt[i]-1) / 2;
    }

    for(int i=0;i<n;++i) {
        cout << ans - (cnt[a[i]]-1) << endl;
    }
}


Measured memory_bytes: 4992
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;

long long n;
long long a[1000];

long long dfs(long long b){
  
  if(b==0){
   
    return 2;
  }
  if(b==1){
   
    return 1;
  }
  
  if(a[b]!=0){
    return a[b];
  }
  
  
  return a[b] = dfs(b-2)+dfs(b-1);
  
}

int main() {

 
   cin >> n;
  
   cout << dfs(n) << endl;

  
  return 0;
}

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

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;

const int N = 1e6 + 5;

/***************************************************************************/

int P[N];
set<int> S;

void print(int b) {
	if(b) cout<<"Yes\n";
	else cout<<"No\n";
	exit(0);
}

int main() {

	boost;
	int N; cin>>N;
	for(int i=1; i<=N; i++) {
		cin>>P[i];
		if(P[i] % 2 != i % 2) print(0);
	}

	int p = 1;

	while(p <= N) {
		int at = p;
		S.clear();
		S.insert(P[p]);
		int last = 0;

		while(at <= p) {
			while(S.find(at) == S.end()) {
				if(p+2 > N or P[p+1] != p+1) print(0);
				if(P[p] > at) {
					if(P[p] < last) print(0);
					last = P[p];
				}
				p += 2;
				S.insert(P[p]);
			}
			at += 2;
		}
		p++;
	}

	print(1);
	
	return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
#define INF 1000000007
#define MAX_N 200
using namespace std;

int d[MAX_N + 1][MAX_N + 1];

void warshall_floyd(int n) {
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }
}

int dfs(int r[], int n, int start, short bit_set) {
    if (n == 0)
        return 0;
    int i = 0, ret = INF;
    short b = bit_set;
    while (b > 0) {
        if (b & 1)
            ret = min(ret, d[start][r[i]] + dfs(r, n - 1, r[i], bit_set ^ (1 << i)));
        i++;
        b >>= 1;
    }
    return ret;
}

int main() {
    int N, M, R;
    cin >> N >> M >> R;
    int r[R];
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            d[i][j] = INF;
        }
    }
    for (int i = 0; i < R; i++) {
        cin >> r[i];
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd(N);
    int ans = INF;
    for (int i = 0; i < R; i++) {
        ans = min(ans, dfs(r, R - 1, r[i], ((1 << R) - 1) ^ (1 << i)));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
#define precout(val) cout << std::fixed << std::setprecision(20) << val;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const double pi = 3.141592653589793;

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

  ll ans = 0;
  ll n; cin >> n;

  for(ll i = 1; i * i < n; ++i) {
    if((n - i) % i == 0 && (n - i) / i > i) {
      ans += (n - i) / i;
    }
  }

  cout << ans << endl;
}

// N = mr + r
// N = (m + 1)r


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

using namespace std;



int main(){
  int n;
  cin >> n;
  if(n<=9) cout << n << endl;
  else if(n<=99) cout << "9" << endl;
  else if(n<=999) cout << n-90 << endl;
  else if(n<=9999) cout << "909" << endl;
  else if(n<=99999) cout << n-9090 << endl;
  else cout << 100000-9090-1 << endl;

  return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(){
    char s[100000] = {'\0'};
    scanf("%s",s);
    int i = 0;
    int sum = 0;
    char d = s[i];
    while(i < strlen(s)){
        d = s[i];
        i++;
        if(s[i] != d) sum++;
    }
    sum--;
    printf("%d\n",sum);
    return EXIT_SUCCESS;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+3;
vector<int> g[N];
int used[N],cnt;
int main(){
	ios::sync_with_stdio(false);
  	cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)cout<<"x";
}

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

int main() {

    int n;
    int a[100000], v[100003] = {0};

    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        v[a[i]]++, v[a[i] + 1]++, v[a[i] + 2]++;
    }
    cout << *max_element(v, v + 100003) << endl;
}


Measured memory_bytes: 1024
n=int(input())
a=[int(x) for x in input().split()]


dp=[]
dp.append(0)
dp.append(abs(a[1]-a[0]))
for i in range(2,n):
    dp.append(min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1])))
    
    
        

print(dp[n-1])    
        


Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
long long fact(long long a){
   long long result=1;
   for(int i=1;i<=a;i++){
      result*=i;
      result=result%mod;
   }
   return result;
}
int main(void){
   int N,M;
   cin>>N>>M;
   if(abs(N-M)>=2){
      cout<<0<<endl;
   }else if(abs(N-M)==1){
      cout<<fact(N)*fact(M)%mod<<endl;
   }else{
      cout<<fact(N)*fact(M)*2%mod<<endl;
   }
   return 0;
}

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

typedef long long ll;
constexpr ll MOD = ll(1e9+7);

int main(){
    ll n, ans = 1, d = 0;  // d = ロボットiを最初にゴールさせるために必要な先にゴールさせるロボット数
    cin >> n;
    vector<ll> x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    for(ll i=0;i<n;i++){
        ans *= i-d+1;
        ans %= MOD;
        // 後ろのロボットを先にゴールさせるためにはi番目のロボットは少なくともi*2+1にいる必要がある
        d = max(d, ((i*2+1-x[i])+1)/2);
    }
    cout << ans << endl;
    return 0;
}

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++)
        cin >> h[i];
    sort(all(h));
    int sum = 0;
    for(int i = 0; i + k < n; i++)
        sum += h[i];
    cout << sum << endl;
}

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

Measured memory_bytes: 4776
N, M, Q = map(int, input().split())
a = []
for _ in range(Q):
    a.append(list(map(int, input().split())))

vs = [j for j in range(1, M + 1)]

temp = []
for v in vs:
    temp.append([v])

use = []
while True:
    hoge = []
    for i in temp:
        index = vs.index(i[-1])
        for v in vs[index:]:
            hoge.append(i + [v])
    temp = hoge
    if len(hoge[0]) == N:
        use = hoge
        break

ans = 0
for u in use:
    t = 0
    for v in a:
        if u[v[1] -1] - u[v[0] -1] == v[2]:
            t += v[3]
    ans = max(ans, t)

print(ans)

Measured memory_bytes: 30616
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int r = scanner.nextInt();
		int card[] = new int[50];
		while (n > 0 && r > 0) {
			for (int i = 0; i < n; i++) {
				card[i] = n - i;
			}
			for (int r0 = 0; r0 < r; r0++) {
				int p = scanner.nextInt() - 1;
				int c = scanner.nextInt();
				int move[] = new int[c];
				for (int i = 0; i < c; i++) {
					move[i] = card[p+i];
				}
				for (int i = p-1; i >= 0; i--) {
					card[c+i] = card[i];
				}
				for (int i = 0; i < c; i++) {
					card[i] = move[i];
				}
			}
			System.out.println(card[0]);
			n = scanner.nextInt();
			r = scanner.nextInt();
		}
	}
}



Measured memory_bytes: 37644
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		//int n = sc.nextInt();
		//int m = sc.nextInt();
		//int k = sc.nextInt();
		long count=0;
		int[] array = new int[3];
		Arrays.sort(array);

		for(int i=0;i<3;i++) {
			if(s.substring(i,i+1).equals(s.substring(i+1,i+2))) {
				count=1;
				break;
			}
		}
		if(count==0) {
			System.out.println("Good");
		}else {
			System.out.println("Bad");
		}

		//System.out.println(array[0]+array[1]);
	}
}




Measured memory_bytes: 23636
import sys

n, k, *v = map(int, sys.stdin.read().split())

def main():
    m = min(n, k)
    res = 0
    for i in range(m+1):
        for j in range((m-i)+1):
            l = v[:i]
            r = v[-j:] if j > 0 else []
            take = l + r
            s = sum(take)
            neg = [t for t in take if t < 0]
            neg.sort()
            s -= sum(neg[:(k-(i+j))])
            res = max(res, s)
    return res
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>

using namespace std;

int mireday(int, int, int);

int main()
{
	int n;
	int y[100], m[100], d[100];

	scanf("%d", &n);

	for (int i = 0; i < n; i++) {

		scanf("%d %d %d", &y[i], &m[i], &d[i]);

		cout << mireday(1000,1,1) - mireday(y[i], m[i], d[i])<<endl;

	}

	return 0;
}

int mireday(int y, int m, int d)
{
	int suuti = 0;

	suuti += (y - 1) / 3 * 200 + ((y - 1) - ((y - 1) / 3)) * 195;
	if ((y % 3) == 0) {
		suuti += ((m - 1) * 20);
	}
	else {
		suuti += (((m - 1) / 2) * 19) + (((m - 1) - ((m - 1) / 2)) * 20);
	}
	suuti += d;

	return suuti;
}


Measured memory_bytes: 3164
a, b, h, m = *gets.split(' ').map(&:to_i)

h_angle = h * 30 + m * 30 / 60.0
m_angle = m * 6.0
angle = (h_angle - m_angle).abs
angle = 360 - angle if 180 < angle
radian = (angle / 180) * Math::PI

def sq(n); n * n; end

puts Math.sqrt(sq(Math.sin(radian) * a) + sq(b - Math.cos(radian) * a))


Measured memory_bytes: 14788
#include <stdio.h>

int dp[16];
bool u[16][16];

int main()
{
while(1)
{
 int a,b;
 scanf("%d%d",&a,&b);
if(a == 0)
{
break;
}
 for(int i = 0; i < b; i++)
 {
  for(int ii = 0; ii < a; ii++)
  {
   u[i][ii] = true;
  }
 }
 int n;
 scanf("%d",&n);
 for(int i = 0; i < n; i++)
 {
  int x,y;
  scanf("%d%d",&x,&y);
  u[y - 1][x - 1] = false;
 }
 for(int i = 0; i < a; i++)
 {
  dp[i] = 0;
 }
 dp[0] = 1;
 for(int i = 0; i < b; i++)
 {
  int now = 0;
  for(int ii = 0; ii < a; ii++)
  {
   if(u[i][ii])
   {
    now += dp[ii];
    dp[ii] = now;
   }
   else
   {
    dp[ii] = 0;
    now = 0;
   }
  }
 }
 printf("%d\n",dp[a - 1]);
}
 return 0;
}

Measured memory_bytes: 1028
def solve(n, a)
  min = 100
  max = -100

  a.each do |i|
    min = i if i < min
    max = i if i > max
  end

  min_cost = Float::INFINITY
  (min..max).each do |i|
    cost = a.reduce(0) {|a, e| a + (e - i)**2 }
    min_cost = cost if cost < min_cost
  end

  min_cost
end

def main
  stdin = STDIN.gets
  n = stdin
  stdin = STDIN.gets
  a = stdin.split(/\s/).map!(&:to_i)

  puts solve(n, a)
end

main

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(ll i = 0; i<n; i++)
#define rep_s(i, start, n) for(ll i= start;  i<n; i++)
#define rep_down(i, n) for(ll i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(ll i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()
#define print(ans) cout << ans << endl;
#define MOD 1000000007
string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
for (iterator = hash.begin(); iterator != hash.end(); iterator++)
{
// ここで、要素毎の操作を行います。
std::pair<std::string, CMyClass> element = *iterator;

}
*/
/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll keta_num(ll num){
  ll total = 0;
  while(num){
    num /= 10;
    total++;
  }
}


ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

ll gcd(ll a, ll b){
  ll tmp;
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }

  ll r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
  return b;
}

ll fibonacchi(ll num){
  ll f0 = 0, f1 = 1, f2;
  ll count = 0;
  while(count<num){
    f2 = f0+f1;
    f0 = f1;
    f1 = f2;
    count++;
  }
  return f2;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, E, F, G, K,L, W, H, P, Q, R, V, X, Y;
  string S, T;
  ll r;
  cin >>r;
  cout << r*2.0*3.14159 << endl;



}


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
const int N=1e9+7;
int32_t main()
{
    IOS;
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int ans=0;
    for(int i=1;i<n;i++)
    {
        if(arr[i]<arr[i-1])
        {
            ans=ans+abs(arr[i]-arr[i-1]);
            arr[i]=arr[i-1];
        }
    }
    cout<<ans;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
bool dp[100005];
int n,k;
int main(){
    cin>>n>>k;
    vector<int>a(n+1);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<=k;i++){
        for(int j=0;j<n;j++){
            if(a[j]<=i&&!dp[i-a[j]]) dp[i]=true;
        }
    }
    cout<<(dp[k]==true?"First":"Second");
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll h, w;
  cin >> h >> w;

  vector<vector<char>> s(h, vector<char>(w));
  for (ll i = 0; i < h; ++i) {
    string tmp;
    cin >> tmp;
    for (ll j = 0; j < tmp.size(); ++j) {
      s[i][j] = tmp[j];
    }
  }

  vector<vector<ll>> seen(h, vector<ll>(w, -1));
  queue<Pll> q;
  q.push(mkp(0, 0));
  seen[0][0] = 0;
  while (!q.empty()) {
    auto pos = q.front();
    q.pop();

    ll y = pos.first;
    ll x = pos.second;
    if (y == h-1 && x == w-1) break;

    vector<ll> dy = {1, -1, 0, 0};
    vector<ll> dx = {0, 0, 1, -1};
    for (ll i = 0; i < 4; ++i) {
      ll ny = y + dy[i];
      ll nx = x + dx[i];
      if (ny < 0 || ny >= h) continue;
      if (nx < 0 || nx >= w) continue;
      if (s[ny][nx] == '#') continue;
      if (seen[ny][nx] >= 0) continue;

      seen[ny][nx] = seen[y][x] + 1;
      q.push(mkp(ny, nx));
    }
  }

  if (seen[h-1][w-1] == -1) {
    cout << -1 << endl;
    return 0;
  }

  vector<vector<ll>> mark(h, vector<ll>(w, false));
  q = queue<Pll>();
  q.push(mkp(h-1, w-1));
  mark[h-1][w-1] = 1;
  while (!q.empty()) {
    auto pos = q.front();
    q.pop();

    ll y = pos.first;
    ll x = pos.second;
    if (y == 0 && x == 0) break;

    vector<ll> dy = {1, -1, 0, 0};
    vector<ll> dx = {0, 0, 1, -1};
    for (ll i = 0; i < 4; ++i) {
      ll ny = y + dy[i];
      ll nx = x + dx[i];
      if (ny < 0 || ny >= h) continue;
      if (nx < 0 || nx >= w) continue;
      if (mark[ny][nx] == 1) continue;
      if (seen[ny][nx] == seen[y][x]-1) {
        mark[ny][nx] = 1;
        q.push(mkp(ny, nx));
        break;
      }
    }
  }

  ll ans = 0;
  for (ll i = 0; i < h; ++i) {
    for (ll j = 0; j < w; ++j) {
      if (s[i][j] == '#') continue;
      if (mark[i][j] == 1) continue;
      ++ans;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(obj) obj.begin(),obj.end()
#define pb(obj) push_back(obj)
#define REP(i,N) for(int i=0;i<N;i++)
typedef long long ll;
const ll MOD=1000000007;
int main(){
	cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin>>N;
    vector<int>B(N-1);
    REP(i,N-1)cin>>B[i];
    int sum=B[0]+B[N-2];

    for(int i=1;i<=N-2;i++){
        sum+=min(B[i-1],B[i]);
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main ()
{
  int x , y ,z;
  cin >> x >> y >> z;
if (x==y && y==z &&x==z)
{
  cout << "No";
}else if (x!=y&&y!=z&&x!=z)
{
  cout << "No";
}else
{
  cout << "Yes";
}
  
}

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

int main(){
  string S_tmp,T;cin>>S_tmp>>T;
  vll a;
  vector<string> v;
  rep(i,S_tmp.size()-T.size()+1){
    bool flag=true;
    rep(j,T.size()){
      if(S_tmp[i+j]=='?' || S_tmp[i+j]==T[j]) continue;
      else{
        flag=false;
        break;
      }
    }
    if(flag) a.push_back(i);
  }
  rep(i,a.size()){
    string s=S_tmp;
    rep(j,T.size()){
      s[a[i]+j]=T[j];
    }
    rep(i,s.size()){
      if(s[i]=='?') s[i]='a';
    }
    v.push_back(s);
  }
  sort(all(v));
  if(v.size()!=0) cout<<v[0]<<endl;
  else cout<<"UNRESTORABLE"<<endl;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);  
	
	int n, m;
	cin >> n >> m;
	vector<vector<int>> d(n , vector<int>(n, 1e9));
	for(int i = 0; i < n; i++) {
		d[i][i] = 0;
	}
	vector<pair<pair<int, int>, int>> e(m);
	for(int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		d[a][b] = d[b][a] = c;
		e[i].first.first = a;
		e[i].first.second = b;
		e[i].second = c;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < n; k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	int cnt = 0;
	for(int i = 0; i < m; i++) {
		int x = e[i].first.first;
		int y = e[i].first.second;
		int z = e[i].second;
		cnt += d[x][y] != z;
	}
	cout << cnt << endl;
	return 0;	
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#include <stdexcept>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
typedef long long ll;
int ceil(int a,int b){// a以上でｂの倍数の最小値を出力//
    return (a+b-1)/b*b;
}
int stoii(string s){ //stoi関数の代用//
    return atoi(s.c_str());
}
int main(void){
    string s;
    cin>>s;
    int a=0,z=0;
    rep(i,s.size()) {
        if(s[i]=='A'){
            a=i;
            break;
        }
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='Z'){
            z=i;
            break;
        }
    }
    cout<<z-a+1<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#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, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    ll n, m;
    cin >> n >> m;
    vll c(m);
    REP(i, m) cin >> c[i];
    vll dp(n + 1, 500000);
    REP(i, m) dp[c[i]] = 1;
    REP(i, n + 1){
        REP(j, m){
            if(i + c[j] <= n) dp[i + c[j]] = min(dp[i + c[j]], dp[i] + 1);
        }
    }
    cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 3132
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main() {
	// your code goes here
	ll n,p;
	cin>>n>>p;
	string s;
	cin>>s;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		a[i]=s[i]-'0';
	}
	map<ll,ll> m;
	m[0]=1;
	ll out=0;
	ll t=0;
	ll ten=1;
	if(p!=2 && p!=5)
	{
	for(ll i=n-1;i>-1;i--)
	{
		t=((t)+(a[i]*ten)%p)%p;
		t=t%p;
		out+=m[t];
		m[t]++;
		ten=(ten*10)%p;
	}
	cout<<out;
	}
	else
	{
		ll out=0;
		for(ll i=0;i<n;i++)
		{
			if(a[i]%p==0)
			{
				out+=i+1;
			}
			
		}
		cout<<out;
	}
	return 0;
}

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

signed main() {
  int N, T;
  cin >> N >> T;
  
  int ans = 0;
  vector<int> time(N);
  for( int i = 0; i < N; i++ ){
    cin >> time.at(i);
  }
  for( int i = 1; i < N; i++ ){
    ans += min(T, time.at(i)-time.at(i-1));
  }
  ans += T;
  cout << ans << endl;  
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll X;
    cin >> X;
    ll a;
    if (X < 600) a = 8;
    else if(X < 800)
        a = 7;
    else if(X < 1000)
        a = 6;
    else if(X<1200)
        a = 5;
    else if(X<1400)
        a = 4;
    else if(X<1600)
        a = 3;
    else if(X<1800)
        a = 2;
    else
        a = 1;
    cout << a << endl;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <stdint.h>
#include <algorithm>
#include <vector>


using namespace std;

int main() {
	string s;
	
	cin >> s;
	
	if(s.at(0) == s.at(1) && s.at(1) == s.at(2) && s.at(2) == s.at(3)){
		cout << "No" << endl;
		return 0;
	}
	
	if((s.at(0)==s.at(1) && s.at(2)==s.at(3)) || (s.at(0)==s.at(2) && s.at(1)==s.at(3)) || (s.at(0)==s.at(3) && s.at(2)==s.at(1)) ){
		cout << "Yes" << endl;
		
	} else {
		cout << "No" << endl;
	}
	


	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include "bits/stdc++.h" // define macro "/D__MAI"

using namespace std;
typedef long long int ll;

#define xprintf(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define debugv(v) {printf("L%d %s => ",__LINE__,#v);for(auto e:v){cout<<e<<" ";}cout<<endl;}
#define debugm(m) {printf("L%d %s is..\n",__LINE__,#m);for(auto v:m){for(auto e:v){cout<<e<<" ";}cout<<endl;}}
#define debuga(m,w) {printf("L%d %s is => ",__LINE__,#m);for(int x=0;x<(w);x++){cout<<(m)[x]<<" ";}cout<<endl;}
#define debugaa(m,w,h) {printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[x][y]<<" ";}cout<<endl;}}
#define debugaar(m,w,h) {printf("L%d %s is..\n",__LINE__,#m);for(int y=0;y<(h);y++){for(int x=0;x<(w);x++){cout<<(m)[y][x]<<" ";}cout<<endl;}}
#define ALL(v) (v).begin(),(v).end()
#define repeat(l) for(auto cnt=0;cnt<(l);++cnt)
#define iterate(b,e) for(auto cnt=(b);cnt!=(e);++cnt)
#define MD 1000000007ll
#define PI 3.1415926535897932384626433832795
template<typename T1, typename T2>
ostream& operator <<(ostream &o, const pair<T1, T2> p) { o << "(" << p.first << ":" << p.second << ")"; return o; }

mt19937 mt(8901016);
inline int rand_int(int l, int h) {
    return uniform_int_distribution<>(l, h)(mt);
}

#ifdef __MAI
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#endif
#ifdef __VSCC
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
namespace {
#define isvisiablechar(c) (0x21<=(c)&&(c)<=0x7E)
    class MaiScanner {
    public:
        template<typename T> void input_integer(T& var) {
            var = 0;
            T sign = 1;
            int cc = getchar_unlocked();
            for (; cc<'0' || '9'<cc; cc = getchar_unlocked())
                if (cc == '-') sign = -1;
            for (; '0' <= cc&&cc <= '9'; cc = getchar_unlocked())
                var = (var << 3) + (var << 1) + cc - '0';
            var = var*sign;
        }
        inline int c() { return getchar_unlocked(); }
        inline MaiScanner& operator>>(int& var) {
            input_integer<int>(var);
            return *this;
        }
        inline MaiScanner& operator>>(long long& var) {
            input_integer<long long>(var);
            return *this;
        }
        inline MaiScanner& operator>>(string& var) {
            int cc = getchar_unlocked();
            for (; !isvisiablechar(cc); cc = getchar_unlocked());
            for (; isvisiablechar(cc); cc = getchar_unlocked())
                var.push_back(cc);
        }
        template<typename IT> void in(IT begin, IT end) {
            for (auto it = begin; it != end; ++it) *this >> *it;
        }
    };
}
MaiScanner scanner;


ll m, n, kei;

ll aa[200010];
//ll imos[200010];

int main() {

    scanner >> n;

    ll allsum = 0;
    repeat(n) {
        scanner >> aa[cnt];
        allsum += aa[cnt];
    }

    ll sum = 0;
    ll best = 5e17;
    for (int i = 0; i < n-1; ++i) {
        sum += aa[i];

        ll a = sum;
        ll b = allsum - sum;
        best = min(best, abs(a - b));
    }
    cout << best << endl;

    return 0;
}

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

int n, m;

bool isOn(int *ms, int sw, int p) {
    // cout << "sw1 ";
    // for (int i = 0; i < n; i++) {
    //     cout << ms[i] << " ";
    // }
    // cout << endl;

    // cout << "sw2 " << sw << endl;

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (ms[i] && ((sw >> i) & 0x01)) {
            cnt++;
        }
    }

    // cout << "cnt " << cnt << endl;
    // cout << "p " << p << endl;

    return (cnt % 2) == p;
}

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

    int k;
    int ms[10][10] = {};

    for (int i = 0; i < m; i++) {
        cin >> k;

        int s;
        for (int j = 0; j < k; j++) {
            cin >> s;
            ms[i][s - 1] = 1;
        }
    }

    int p[m];
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for (int i = 0; i < (int)pow(2, n); i++) {
        bool allOn = true;
        for (int j = 0; j < m; j++) {
            // cout << "====== denkyu" << j << endl;
            if (!isOn(ms[j], i, p[j])) {
                allOn = false;
                break;
            }
        }

        if (allOn) {
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
    int n;
    int s[2];
    int check[2] = {0};

    cin >> n;

    for(int i = 0; i < 2; i++){
        s[1 - i] = n % 100;
        n /= 100;
    }

    if(1 <= s[0] && s[0] <= 12){
        check[0] = true;
    }
    if(1 <= s[1] && s[1] <= 12){
        check[1] = true;
    }

    if(check[0] == true && check[1] == true){
        cout << "AMBIGUOUS\n";
    }
    else{
        if(check[0] == true){
            cout << "MMYY\n";
        }
        else{
            if(check[1] == true){
                cout << "YYMM\n";
            }
            else{
                cout << "NA\n";
            }
        }
    }
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> vec;
    int d;
    for (int i = 0; i < M; ++i) {
        cin >> d;
        vec.push_back(d);
    }
    int sum=0;
    for (int x : vec) {
        sum += x;
    }
    if (sum>N){
        cout << -1;
    }
    else {
        cout << N - sum;
    }
    return 0;
}


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

int main() {
  int N; cin >> N;  // 生徒数
  map<int,int> A;   // 出席済人数,出席番号

  int wk_int; // 入力値を一旦入れる。
  rep(i,N){
    cin >> wk_int;
    A[wk_int] = i+1;
  }

  for(auto M:A){
    cout << M.second << " ";
  }
  cout << endl;
}

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

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

int main() {
	long long a,b,c,d,e,a1=0,b1=0,p,q;
	cin>>a>>b>>c>>d;
	e=c*d/gcd(c,d);
	p=(a-1)/c;
	q=b/c;
	a1=q-p;
//	cout<<a1<<endl;
	p=(a-1)/d;
	q=b/d;
	a1+=q-p;
//	cout<<a1<<gcd(c,d)<<endl;
	p=(a-1)/e;
	q=b/e;
	a1-=(q-p);
	cout<<b-a-a1+1<<endl;
	
	
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144*2LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll
void solve() {
	while (true) {
		int n, m, k;
		cin >> n >> k >> m;
		if (n == 0) return;
		int right[20000] = {};
		int left[20000] = {};
		for (int i = 0; i < n; ++i) {
			left[i] = i - 1;
			right[i] = i + 1;
		}
		left[0] = n - 1;
		right[n - 1] = 0;
		m--;
		REP(i, n) {
			right[left[m]] = right[m];
			left[right[m]] = left[m];
			REP(q, k) {
				m = right[m];
			}
		}
		cout << m + 1 << endl;
	}
}
#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3428
#include<bits/stdc++.h>
using namespace std;
long long int wt[103],val[103],dp[103][100003],n;
long long int rec(long long int i,long long int v)
{
    if(i>n)
        return 0;
    if(dp[i][v]!=-1)
        return dp[i][v];
   return dp[i][v]=min(dp[i][v],min(rec(i+1,v),(wt[i]+rec(i+1,v+val[i]))));
}
int main()
{
    long long int w,i,max1=0,j;
    cin>>n>>w;
    long long int val[n+1],wt[n+1];
    for(i=1;i<=n;i++)
    {
        cin>>wt[i]>>val[i];
    }
    for(i=0;i<=101;i++)
    {
        for(j=0;j<=100001;j++)
        {
            if(j==0)
            dp[i][j]=0;
            else
            dp[i][j]=1e14;
        }
    }
    for(j=1;j<=n;j++)
    {
        for(i=0;i<=100000;i++)
        {
            if(i>=val[j])
            dp[j][i]=min(dp[j-1][i],dp[j-1][i-val[j]]+wt[j]);
            else
            dp[j][i]=dp[j-1][i];
        }
    }
    for(i=1;i<=100000;i++)
    {
        
        if(dp[n][i]<=w)
        {
            max1=i;
        }
    }
    cout<<max1;
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7;
int quick_pow(int a,int p)
{
	if(p==0)
	{
		return 1;
	}
	int sqr=quick_pow(a,p/2);
	if(p%2)
	{
		return sqr*sqr%mod*a%mod;
	}
	else
	{
		return sqr*sqr%mod;
	}
}
int fac[2010],inv[2010];
void init()
{
	fac[0]=inv[0]=1;
	for(int i=1;i<2010;i++)
	{
		fac[i]=fac[i-1]*i%mod;
		inv[i]=quick_pow(fac[i],mod-2)%mod;
	}
}
int C(int n,int m)
{
	return fac[n]*inv[m]%mod*inv[n-m]%mod;
}
signed main()
{
	int s;
	cin>>s;
	init();
	int ans=0;
	for(int i=1;i<=s/3;i++)
	{
		ans=(ans+C(s-2*i-1,i-1))%mod;
	}
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 3660
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int N=200005;
long long s;
int main()
{
	scanf("%lld",&s);
	long long x1,y1,x2,y2,x3,y3;
	x1=0,y1=0;
	x2=y3=ceil(sqrt(s));
	long long t=x2*y3-s;
	if(t==0) y2=x3=0;
	for(long long i=1;i<=sqrt(t);i++)
		if(t%i==0)
		{
			if(i<=1e9&&t/i<=1e9) y2=i,x3=t/i;
		}
	printf("%lld %lld %lld %lld %lld %lld",x1,y1,x2,y2,x3,y3);
	return 0;
}

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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long int ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n,k; cin >> n >> k;
    string s; cin >> s;

    vl a;
    if(s[0] != '1')a.push_back(0);
    for(int i=0;i<n;){
        int j = i;
        while(j < n && s[i] == s[j])j++;
        a.push_back(j - i);
        i = j;
    }
    if(s[n-1] != '1')a.push_back(0);
    //debug(a);
    
    vl sums(a.size()+1);
    ll m = sums.size();
    rep(i,m)sums[i+1] = sums[i] + a[i];
    ll res = 0;
    for(int i = 0;i<m;i+=2){
        int j = i + 2*k+1;
        if(j >= m)j = m-1;
        res = max(res,sums[j] - sums[i]);
    }
    out(res);
}


Measured memory_bytes: 2116
// AtCoder165 C

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <math.h>
#include <assert.h>
#include <string.h>
#include <memory.h>
#include <malloc.h>
#include <stdlib.h>

// qsortで用いる比較用関数．*a<*bならaが先になる．
int compare(const void* a, const void* b) {
    return *(int*)a - *(int*)b;
}

int main() {
    int i,j;
    int n;
    int m,c;
    int* a;
    int* b;
    int cnt = 0,sum;
    
    scanf("%d %d %d", &n, &m, &c);
    b = (int*)malloc(sizeof(int) * m);
    a = (int*)malloc(sizeof(int) * m);

    for(i=0;i<m;i++){
        scanf("%d", b + i);
    }

    for(i=0;i<n;i++){
        sum = 0;
        for(j=0;j<m;j++){
            scanf("%d", a + j);
            sum += *(b+j) *  *(a+j);
        }
        if(sum > -c) cnt++;
    }
    printf("%d", cnt);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N, M;
    cin >> N >> M;
    vector<ll> v[N];
    ll po, yo;
    for(ll i = 0; i < M; i++){
        ll a, b;
        cin >> a >> b;
        v[--a].push_back(--b);
        v[b].push_back(a);
        po = a;
        yo = b;
    }
    bool used[N] = {};
    deque<ll> ans;
    ans.push_back(po);
    ans.push_back(yo);
    used[po] = used[yo] = 1;
    while(1){
        bool success = 1;
        for(ll next: v[po]){
            if(used[next]) continue;
            used[next] = 1;
            ans.push_front(next);
            success = 0;
            po = next;
            break;
        }
        for(ll next: v[yo]){
            if(used[next]) continue;
            used[next] = 1;
            ans.push_back(next);
            success = 0;
            yo = next;
            break;
        }
        if(success) break;
    }
    cout << ans.size() << endl;
    while(ans.size()){
        ll tmp = ans.front();
        ans.pop_front();
        cout << tmp + 1 << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 7168