akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <stdlib.h>
#include<string.h>
#include<math.h>
#define loop(i, l, r) for(i=l; i<r; i++)/*Instead of function, (for).*/
#define rep(i,r) for(i=0; i<r; i++)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long int lli;
/*Return Combination ,(nCr)*/
int combi(int n, int r)
{
	if(r==0 || r==n) return 1;
	else return combi(n-1,r) + combi(n-1,r-1);
}
/*Return gcd(a, b)*/
int gcd(int a, int b){
	if(b == 0) return a;
	else return gcd(b, a % b);
}
//qsort�֐��Ɏg��compare�֐�,(long long int, int, double�^)
int compare_lli(const void *a, const void *b)
{
    return *(lli*)a - *(lli*)b;
}
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int compare_double(const void *a, const void *b)
{
    return *(double*)a - *(double*)b;
}
/*qsort(data, 10, sizeof(int_lli_double), compare_int);*/
/*qsort(�z��, �v�f��, sizeof(�z��̌^), compare_�z��̌^);*/
int main(void)
{
	lli i, j, L, R, k, min=2019;
	scanf("%lld%lld", &L, &R);
	if(R-L+1 >= 2019){
		min = 0;
	}
	loop(i, L, R){
		loop(j, i+1, R+1){
			k = (i*j)%2019;
			if(k==0){
				printf("0");
				return 0;
			}
			if(k < min) min = k;
		}
	}
	printf("%lld", min);
	return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 17.11.2019 02:11:18       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int r, c, n;
  cin >> r >> c >> n;
  vector<pair<int, int>> x;
  while (n--) {
    int xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    int ka = 0, kb = 0;
    if (ya == 0) ka = xa; else
    if (xa == r) ka = r + ya; else
    if (ya == c) ka = r + c + (r - xa); else
    if (xa == 0) ka = r + c + r + (c - ya);
    else continue;
    if (yb == 0) kb = xb; else
    if (xb == r) kb = r + yb; else
    if (yb == c) kb = r + c + (r - xb); else
    if (xb == 0) kb = r + c + r + (c - yb);
    else continue;
    x.emplace_back(ka, n);
    x.emplace_back(kb, n);
  }
  sort(x.begin(), x.end());
  vector<int> st;
  for (auto& p : x) {
    int y = p.second;
    if (!st.empty() && st.back() == y) st.pop_back();
    else st.push_back(y);
  }
  cout << (st.empty() ? "YES" : "NO") << '\n';
  return 0;
}


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

import numpy as np

MOD = 10**9 + 7
N,K = map(int,read().split())

M = int(N**.5)

lower = np.zeros(M+1,np.int64)
upper = np.zeros(M+1,np.int64)
size = np.zeros(M+1,np.int64)
x = N//np.arange(1,M+1)
size[1:] = x; size[1:-1] -= x[1:]; size[M] = N//M - M

# 最初は1をひとつ持っておく
lower[1] += 1
for _ in range(K):
    prev_lower = lower
    prev_upper = upper
    prev_lower_cum = lower.cumsum() % MOD
    prev_upper_cum = upper[::-1].cumsum()[::-1] % MOD # 逆から累積しておく
    lower = np.zeros(M+1,np.int64)
    upper = np.zeros(M+1,np.int64)
    # 下→上
    upper += prev_lower_cum * size
    # 下→下
    lower[1:M+1] += prev_lower_cum[-1]
    # 上→下
    lower[1:M+1] += prev_upper_cum[1:M+1]
    lower %= MOD
    upper %= MOD

answer = (lower.sum() + upper.sum()) % MOD
print(answer)

Measured memory_bytes: 15088
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n;
ll d[65540],tac[65540];
ll a[20][20];
int main()
{
	cin >>n;
	for (int i=0;i<n;i++)
		for (int j=0;j<n;j++)
			cin >>a[i][j];
	for (int i=0;i<(1<<n);i++)
	{
		for (int j=0;j<n;j++)
		{
			if (!(i & (1<<j))) continue;
			for (int k=j+1;k<n;k++) if (i & (1<<k)) tac[i]+=a[j][k];
		}
	}
	for (int i=1;i<(1<<n);i++)
	{
		d[i]=tac[i];
		for (int j=i;j>0;j=(j-1)&i) d[i]=max(d[i],d[i^j]+tac[j]);
	}
	cout <<d[(1<<n)-1];
	return 0;
} 

Measured memory_bytes: 1280
use std::io::*;//Not mine.
use std::str::FromStr;
use std::collections::HashSet;
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main(){
    let mut set = HashSet::new();
    let n:i32 = read();
    for _i in 0..n {
        let a:i32 = read();
        set.insert(a);
    }
    println!("{}",set.len());
}

Measured memory_bytes: 4476
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        Integer[] x = new Integer[n];
        Integer[] y = new Integer[n];
        for (int i = 0; i < n; i++) {
            x[i] = Integer.parseInt(sc.next());
            y[i] = Integer.parseInt(sc.next());
        }
        sc.close();

        // 主処理
        double sum = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    double dx = Math.pow(Math.abs(x[i] - x[j]), 2);
                    double dy = Math.pow(Math.abs(y[i] - y[j]), 2);
                    double d = Math.sqrt(dx + dy);
                    sum += d;
                }
            }
        }
        double result = sum / n;

        // 出力
        System.out.println(result);
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);i++)
#define FD(i,b,a) for(int i=(b);i>=(a);i--)
#define len(a) int((a).size())
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int n;
    scanf("%d", &n);
    printf("%d\n", 48 - n);
}

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

namespace my_lib {
// 切り上げ除算
ll roundUp(ll a, ll b) { return (a + (b - 1)) / b; }
}  // namespace my_lib

int main() {
  ll h, w, n;
  cin >> h >> w >> n;
  ll _max = max(h, w);
  ll ans = my_lib::roundUp(n, _max);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;

namespace C
{
    class Program
    {
        static string[] GetStrAry(int n)
        {
            string[] strAry = new string[n];
            for(int i = 0; i < n;i++)
            {
                strAry[i] = Console.ReadLine();
            }
            return strAry;
        }
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int Count = 0;
            string[] Strings = GetStrAry(N);
            string Temp = "";
            Array.Sort(Strings);
            foreach(string s in Strings)
            {
                if(Temp != s)
                {
                    Temp = s;
                    Count++;
                }
            }
            Console.WriteLine(Count);
        }
    }
}

Measured memory_bytes: 38560
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;

int main()
 {
 	 long long int n,m,s=0,i,c=0;
 	 double p;
 	 cin>>n>>m;
 	 int a[n];
 	 for(i=0;i<n;i++)
 	 	cin>>a[i];
 	for(i=0;i<n;i++)
 		s=s+a[i];
 	p=(float)s/(float)(4*m);
 	for(i=0;i<n;i++)
 		{
 			if((float)a[i]>=p)
 				c++;
		 }
 //   cout<<p<<" "<<c<<endl;
	if(c>=m)	
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;  
 	return 0;
 }

Measured memory_bytes: 3616
// https://atcoder.jp/contests/

#include <bits/stdc++.h>
#define REP(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define REPR(i, n) for (int(i) = (n); (i) >= 0; (i)--)
#define FOR(i, m, n) for (int(i) = (m); (i) < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main()
{
  int P, Q, R, minimum;
  cin >> P >> Q >> R;

  minimum = min(P + Q, P + R);
  minimum = min(minimum, Q + R);

  cout << minimum << '\n';

  return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
is_up=False
is_even=True
pre_a=a[0]
cnt=1
for aa in a:
  if is_even and pre_a != aa:
    is_even=False
    is_up=pre_a < aa
  if not is_even:
    if (is_up and pre_a > aa) or (not is_up and pre_a < aa):
      is_even=True
      cnt+=1
  pre_a=aa
print(cnt)

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

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int N = in.nextInt();
            int[] T = new int[N];
            for (int i = 0; i < N; i++) {
                T[i] = in.nextInt();
            }
            int M = in.nextInt();
            int[] P = new int[M];
            int[] X = new int[M];
            for (int i = 0; i < M; i++) {
                P[i] = in.nextInt() - 1;
                X[i] = in.nextInt();
            }

            for (int i = 0; i < M; i++) {
                int[] times = Arrays.copyOf(T, N);
                times[P[i]] = X[i];

                int time = 0;
                for (int j = 0; j < N; j++) {
                    time += times[j];
                }

                System.out.println(time);
            }

        }
    }
}


Measured memory_bytes: 27664
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる


void pl(int z, int pre, vector<vector<int>> &p, vector<ll> &ans){
  vector<int> v={pre};
  if(p[z]==v) return;
  for(auto x : p[z]){
    if(x==pre) continue;
    ans[x]+=ans[z];
    pl(x,z,p,ans);
  }
  return;
}



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

  vector<vector<int>> p(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    p[a].pb(b);
    p[b].pb(a);
  }

  vector<ll> ans(n);
  rep(i,m){
    int p,x;
    cin>>p>>x;
    p--;
    ans[p]+=x;
  }

  int pre=-1;

  pl(0,pre,p,ans);

  rep(i,n){
    cout << ans[i];
    if(i!=n-1) cout << " ";
    else cout << endl;
  }

}

Measured memory_bytes: 36736
N = int(input())
A = list(map(int, input().split()))
dp = [[-1]*N for _ in range(N)]
for i in range(N):
    dp[i][i] = 0


def main(l, r):
    if dp[l][r] != -1:
        return dp[l][r]
    ret = 10**15
    for i in range(l, r):
        ret = min(ret, main(l, i)+main(i+1, r))
    ret += sum(A[l:r+1])
    dp[l][r] = ret
    return ret


print(main(0, N-1))

Measured memory_bytes: 44252
#include<iostream>
using namespace std;
int main() {
  int n,k;
  string s,str;
  char c;
  cin >> n >> k >> s;
  c=tolower(s[k-1]);
  for(int i=0; i<k-1; i++) {
    str.push_back(s[i]);
  }
  str.push_back(c);
  for(int i=k; i<n; i++) {
    str.push_back(s[i]);
  }
  cout << str << endl;
}


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

using ll = long long;
using P = pair<int, ll>;

void calc(ll l, ll r, vector<ll> const& a, vector<P>& v) {
    int size = r - l;
    for(int i=0; i<1<<size; ++i) {
        ll sum = 0;
        int cnt = 0;
        for(int j=0; j<size; ++j) {
            if(i >> j & 1) {
                cnt++;
                sum += a[j+l];
            }
        }
        v.push_back(P{cnt, sum});
    }
    sort(v.begin(), v.end());
}

int main() {
    ll N, K, L, R;
    cin >> N >> K >> L >> R;
    vector<ll> a(N);
    for(int i=0; i<N; ++i) {
        cin >> a[i];
    }
    vector<P> v1, v2;
    calc(0, N/2, a, v1);
    calc(N/2, N, a, v2);
    ll res = 0;
    for(int i=0; i<v1.size(); ++i) {
        ll l = lower_bound(v2.begin(), v2.end(), P{K-v1[i].first, L-v1[i].second}) - v2.begin(),
           r = upper_bound(v2.begin(), v2.end(), P{K-v1[i].first, R-v1[i].second}) - v2.begin();
        res += r - l;
    }
    cout << res << endl;
}


Measured memory_bytes: 43680
///بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم
///La ilaha illallahu muhammadur rosulullah
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
using namespace std;

long long int a[100000+5];
long long int dp[100000+5];
int main()
{
    fast;
    int n;
    cin>>n;
    for(int i=0; i<n ; i++)
        cin>>a[i];
    dp[1]=abs(a[1]-a[0]);

    for(int i=2; i<n ; i++)
    {
        dp[i] = min( abs(a[i]-a[i-1]) + dp[i-1],
                     abs(a[i]-a[i-2]) + dp[i-2] );
    }
    cout<<dp[n-1]<<endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void) {
        int n, m, i;
        scanf("%d %d",&n,&m);

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

        int select = 0, cnt = 0;

        for (i=0;i<n;i++) {
                if(A[i] * 4 * m >= sum) cnt++;
                if(cnt == m) {
                        select = 1;
                        break;
                }
        }
        if(select) printf("Yes\n");
        else printf("No\n");
        return 0;
}

Measured memory_bytes: 128
#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++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int H, W, K, ans = INT_MAX / 2;
    cin >> H >> W >> K;
    auto S = make_v<char>(H, W);
    rep(i, H) rep(j, W) cin >> S[i][j];
    vint cnt(H), cntc(H);
    rep(h, H)
    {
        int sum = 0;
        rep(w, W)
        {
            if (S[h][w] == '1')
                sum++;
        }
        cnt[h] = sum;
    }
    for (int bit = 0; bit < (1 << (H - 1)); bit++) //(bit & (1<<i)) == 1 ⇔ i番目の境界で切る
    {
        int tmp = 0;
        fill_v(cntc, 0);
        for (int w = 0; w < W; w++)
        {
            bool flag = true;
            int j = 0;
            auto prev = cntc;
            for (int i = 0; i < H; i++)
            {
                if (S[i][w] == '1')
                    cntc[j]++;
                if ((bit & (1 << i)))
                {
                    j++;
                }
            }
            for (int i = 0; i < H; i++)
            {
                if (cntc[i] > K)
                {
                    tmp++;
                    for (int l = 0; l < cntc.size(); l++)
                    {
                        cntc[l] -= prev[l];
                        if (cntc[l] > K)
                        {
                            tmp = INT_MAX / 2;
                        }
                    }
                }
            }
        }
        for (int i = 0; i < H; i++)
        {
            if (bit & (1 << i))
            {
                tmp++;
            }
        }
        chmin(ans, tmp);
    }
    cout << ans;
    return 0;
}

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

int main() {
  int N, A;
  cin >> N >> A;
  
  int X = N%500;
  if (X-A > 0)
  {
  
  cout << "No" << endl;
  
  }
  else 
  {
  
  cout << "Yes" << endl;
  
  }
}

Measured memory_bytes: 256
import re

s = input()

c0, c1 = 0, 0
for i in s:
    if i=='0':
        c0 += 1
    else:
        c1 += 1

print(min(c0, c1)*2)

"""TLE
def trans_word(text):
    replacements = {'01': '', '10': ''}
    return re.sub('({})'.format('|'.join(map(re.escape, replacements.keys()))), lambda m: replacements[m.group()], text)

ans = 0
flag = True

while flag:
    s_tmp = s
    s = trans_word(s)
    ans += (len(s_tmp) - len(s))
    flag = len(s_tmp) - len(s)

print(ans)
"""

Measured memory_bytes: 3316
#include <cstdio>

using namespace std;

int main() {
    int n;
    scanf("%d\n", &n);
    char c[n];
    int ans = 3 * 10 * 10 * 10 * 10 * 10;
    int de[ans];
    int dw[ans];

    for (int i = 1; i <= n; i++) {
        scanf("%c", &c[i]);
        if (c[i] == 'E') {
            de[i] = de[i - 1] + 1; 
            dw[i] = dw[i - 1];
        } else {
            dw[i] = dw[i - 1] + 1; 
            de[i] = de[i - 1];
        }
    }
    for (int i = 1; i <= n; i++) {
        int tmp = 0;
        tmp = dw[i - 1] + de[n] - de[i];
        if (tmp <= ans) ans = tmp;
    }
    printf("%d\n", ans);
    return 0;
}



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

using namespace std;

const int N = 3*1e3 + 7;

double f[N][2][N], a[N];
int n;

int main()
{
    //freopen("I.inp","r",stdin);
    //freopen("I.out","w",stdout);

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

    f[1][1][1] = a[1];
    f[1][0][0] = (1 - a[1]);

    for(int i = 2; i <= n; i++)
    {
        for(int k = 0; k <= i; k++)
        {
            if(k > 0) f[i][1][k] += a[i]*(f[i - 1][1][k - 1] + f[i - 1][0][k - 1]);
            if(k < i) f[i][0][k] += (1 - a[i])*(f[i - 1][1][k] + f[i - 1][0][k]);
        }
    }

    double ans = 0;
    for(int k = n / 2 + 1; k <= n; k++)
    {
        ans += f[n][1][k] + f[n][0][k];
    }

    cout << setprecision(9) << fixed << ans;
}


Measured memory_bytes: 139904
#include <iostream>
#include <map>
#include <string>
#include <algorithm>
#include <vector>
#define ll long long

int main()
{
    int x;
    std::cin >> x;

    if(x == 0) {
        std::cout << "1" << std::endl;
    }
    else {
        std::cout << "0" << std::endl;
    }
}

Measured memory_bytes: 3636
/*
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
typedef mp::cpp_int mint; //*/
#include <bits/stdc++.h>
#define  re(i,j,n) for(li i=(j);i<(n);i++)
#define  rep(i,n) re(i,0,(n))
#define  red(i,n) for(li i=n-1;i>=0;i--)
#define  all(a) begin(a),end(a)
#define  pb(a) push_back(a)
using namespace std;
typedef long int li;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<string> vs;


int main()
{
    ull a,b,x;
    cin>>a>>b>>x;
    cout<<b/x-(a!=0)*(a-1)/x+(a==0)<<endl;
    return 0;
}

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

int main() {
    int n ,k,d,s,sum = 0;
    cin >> n >> k;
    vector<int> sun(n);
    for(int i = 0 ; i < k ;++i){
        cin >> d;
        for(int j = 0 ; j < d ; ++j){
            cin >> s;
            sun.at(s-1)++;
            }
        }
    for(int i = 0 ; i < n ;++i){
        if(sun.at(i) == 0){
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            cout << i << 'x' << j << '=' << i * j << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1116
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> n = new ArrayList<>();
		
		while(sc.hasNext()) {
			n.add(sc.nextInt());
		}

		int i = 0;
		while(i < n.size()) {
			int cnt = 0;
			for(int a = 0; a < 10; a++) {
				for(int b = 0; b < 10; b++) {
					for(int c = 0; c < 10; c++) {
						for(int d = 0; d < 10; d++) {
							if(a + b + c + d == n.get(i)) {
								cnt++;
							}
						}
					}
				}
			}
			System.out.println(cnt);
			i++;
		}
	}
}

Measured memory_bytes: 26720
#include<iostream>
#include<cstdio>
using namespace std;
char s[110];//定义char数组
int n,p,ma;//ma存储最高高度，p存储当前高度
int main()
{
    scanf("%d%s",&n,s+1);//读入字符串的长度和字符串.
    for(int i=1;i<=n;++i)
    {
        if(s[i]=='I') ++p;//判断如果是'I'，高度++.
        else --p;//否则高度--
        ma=max(ma,p);//每次选取最大值.
    }
    printf("%d\n",ma);//输出答案.
    return 0;//结束.
}

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

int k;

int main() {
	cin >> k;

	int even = k / 2;
	int odd = k / 2;
	if( (k % 2) == 1 ) {
		odd++;
	}	
	int ans = even * odd;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    long H; // N, K;
    cin >> H;
    
    long X = 0;

   
    long i = 0;
    //cout << 2^0 << endl;
    while( H != 0){
        H /= 2;
        X += pow(2,i);
        i++;
    }
    cout << X<< endl;
return 0;
}

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

using namespace std;

int main()
{
    long long n, k, counter=0;
    cin >> n >> k;
    long long arr[n];
    for(int i = 0;i < n;i++){
        cin >> arr[i];
    }
    sort(arr,arr + n);
    if(k >= n)
        cout << 0 << endl;
    else{
        for(int i = 0;i < (n - k);i++){
            counter += arr[i];
        }
        cout << counter << endl;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(int X = 0; X < N; X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<ll> march(5,0);

    rep(i,n){
        string tmp;
        cin >> tmp;

        if(tmp[0] == 'M'){
            march[0]++;
        }else if(tmp[0] == 'A'){
            march[1]++;
        }else if(tmp[0] == 'R'){
            march[2]++;
        }else if(tmp[0] == 'C'){
            march[3]++;
        }else if(tmp[0] == 'H'){
            march[4]++;
        }
    }

    ll ans = 0;

    for(int i = 0; i < 3; i++){
        for(int j = i + 1; j < 4; j++){
            for(int k = j + 1; k < 5; k++){
                ans = ans + march[i] * march[j] * march[k];
            }
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

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

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

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

ll n;
vector<ll> vi;

int main() {
	cin >> n;
	vi.resize(n);
	REP(i, n)cin >> vi[i];
	sort(ALL(vi));
	ll num = 0, sum = 0;
	REP(i, n - 1) {
		//cout << sum << " " << num << endl;
		//cout << 2 * (vi[i] + sum) << " " << vi[i + 1] << endl;
		if (2 * (vi[i] + sum) < vi[i + 1]) {
			num = i + 1;
		}
		sum += vi[i];
	}
	cout << n - num << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

#define INF 1e9
#define LLINF 1e18
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

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


int main() {
    int x, n;
    int ans;
    bool minus = false;
    cin >> x >> n;
    vector<int> p(n);
    vector<bool> a(102, true);
    rep(i, n) {
        cin >> p.at(i);
        a.at(p.at(i)) = false;
    }
    if (a.at(x)) {
        cout << x << endl;
        return 0;
    }
    for (int i = 1; i <= 102 - x; i++) {
        if (a.at(x + i)) {
            ans = i;
            goto next;
        }
    }
    next:
    for (int i = -1; i >= -x; i--) {
        if (a.at(x + i) && ans >= -1 * i) {
            ans = -1 * i;
            minus = true;
            goto last;
        }
    }
    last:
    if (minus) ans *= -1;
    cout << ans + x << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cstdlib>
using namespace std;

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

	int n, d;
	cin >> n >> d;
	d = 2 * d + 1;
	int ans = n / d;
	if (n%d) ans++;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#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>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(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 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;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

int main() {
	int N, M;
	cin >> N >> M;
	vi count(M + 1, 0);
	REP(i, N) {
		int K, A;
		cin >> K;
		REP(j, K) {
			cin >> A;
			count[A]++;
		}
	}

	int ans = 0;
	FOR(i, 1, M) {
		if (count[i] == N) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    char[] s = scanner.next().toCharArray();

    int left = 0;
    int tmp = 0;
    for(char ch : s) {
      if (ch == '(') tmp--;
      else tmp++;
      left = Math.max(left, tmp);
    }
    int right = 0;
    tmp = 0;
    for (int i = N - 1; i >= 0; i--) {
      char ch = s[i];
      if (ch == ')') tmp--;
      else tmp++;
      right = Math.max(right, tmp);
    }

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < left; i++) sb.append('(');
    sb.append(s);
    for (int i = 0; i < right; i++) sb.append(')');
    System.out.println(sb.toString());
  }
}

Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  
  if (e - a > f) {
    cout << ":(" << endl;
  } else {
    cout << "Yay!" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define N 100000
#define L 10
#define TRUE 1
#define FALSE 0
int head,tail;
int Q[N];

void initialize();
void enqueue();

int main(){
  int i,j,n,q,a;
  char name[N][L];
  int sumtime=0;
  char temp[L];
  
  scanf("%d%d",&n,&q);
  
  initialize();
  
  for(i=0;i<n;i++){
    scanf("%s%d",name[i],&Q[i]);
    tail++;
  }


  while(isEmpty()!= 1){
    if(Q[head]-q>0){
      strcpy(name[tail],name[head]);
      sumtime += q;
      Q[head]-= q;
      a = dequeue(Q[head]);
      enqueue(a);

    }
    else{
      sumtime += Q[head];
      a = dequeue(Q[head]);
      printf("%s %d\n",name[head-1],sumtime);
    }
    
  }

  return 0;
}

  
void initialize(){
  head = tail = 0;
}

int isEmpty(){
  if(head == tail){
    return TRUE;
  }
  else return FALSE;
}


void enqueue(int x){
  
  Q[tail] = x;
  if(tail+1 == N){
    tail = 0;
  }
  else{
    tail++;
  }
}

int dequeue(){
  int x;
  x = Q[head];
  if((head +1) == N){
    head = 0;
  }
  else {
    head++;
  }
  return x;
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()
#define endl "\n"

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;

void solve() {
    int N;
    cin >> N;
    string s;
    cin >> s;
    stack<int> red_pos;
    int play = 0;
    REP(i,s.size()) if(s[i] == 'R') red_pos.push(i);
    REP(i,s.size()) {
        if(s[i] == 'W') {
            // 先に赤は無い
            if(red_pos.empty()) {
                cout << play << endl;
                return;
            }
            int pos = red_pos.top(); red_pos.pop();
            // あったけどその赤はindexが通過済み
            if (pos < i) {
                cout << play << endl;
                return;
            }
            // 交換を行う
            play++;
        }
    }
    cout << play << endl;
}

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

Measured memory_bytes: 4456
from collections import defaultdict

def main():
    n = int(input())
    V = [int(e) for e in input().split()]

    De, Do = defaultdict(int), defaultdict(int)
    for i in range(0, n, 2):
        De[V[i]] += 1

    for i in range(1, n + 1, 2):
        Do[V[i]] += 1

    Des = sorted(De.items(), key=lambda x: -x[1])
    Dos = sorted(Do.items(), key=lambda x: -x[1])

    Des.append((-1, 0))
    Dos.append((-1, 0))

    ans = n - Des[0][1] - Dos[0][1]

    if Des[0][0] == Dos[0][0]:
        ans += min(Des[0][1] - Des[1][1], Dos[0][1] - Dos[1][1])

    print(ans)

if __name__ == "__main__":
    main()


Measured memory_bytes: 66284
#include <iostream>
#include <string>

using namespace std;

int main() {
	int a, b;
	string s[100];
	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (i < 50)s[i].push_back('.');
			else s[i].push_back('#');
		}
	}
	cin >> a >> b;
	for (int i = 0; i < b - 1; i++) {
		s[i / 50 * 2][i * 2 % 100] = '#';
	}
	for (int i = 0; i < a - 1; i++) {
		s[99 - (i / 50 * 2)][i * 2 % 100] = '.';
	}
	cout << 100 << " " << 100 << "\n";
	for (int i = 0; i < 100; i++) {
		cout << s[i] << "\n";
	}
	cout << endl;
	return 0;
}

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

typedef long long ll;
const long long LINF = 1LL << 60;
const long long LMINF = 1LL << 63;
const int INF = 1 << 30;

#define REP(i,n) for(int i = 0;i < n;++i)
#define REPS(i,x) for(int i = 1;i <= (int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i >= 0;i--)
#define RREPS(i,x) for(int i=((int)(x));i > 0;i--)
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << ": " << x << "\n"

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



int main(){

    int n;
    cin >> n;
    vector<int> x(n);
    REP(i,n)cin >> x[i];

    int L = x[0];
    int R = x[0];

    REP(i,n){
        chmin(L,x[i]);
        chmax(R,x[i]);
    }
    int ans = INF;
    
    for(int i = L;i <= R;i++){
        int cost = 0;
        REP(j,n)cost+=(x[j] - i)*(x[j] - i);
        chmin(ans,cost); 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<map>
#include<queue>
typedef long long L;
typedef std::map<L,int>M;
M m;
L S(L l,int a,int b)
{
	L c=(l>>(a*4))&15;
	l&=~(15LL<<(a*4));
	L d=(l>>(b*4))&15;
	l&=~(15LL<<(b*4));
	return l|(c<<(b*4))|(d<<(a*4));
}

struct I{int operator()(L l,int x)
{
	if(m.find(l)!=m.end())return -2;
	m[l]=x;
	return -1;
}};
struct E
{
	M inm;
	int operator()(L l,int x)
	{
		M::iterator ite=m.find(l);
		if(ite!=m.end())return ite->second+x;
		else if(inm.find(l)!=inm.end())return -2;
		inm[l]=x;
		return -1;
	}
};
template<class T>
int F(L init,T func)
{
	const int di[13][4]={
		{3},
		{3,6},
		{1,2,4,7},
		{3,8},
		{6},
		{2,5,7,10},
		{3,6,8,11},
		{4,7,9,12},
		{8},
		{6,11},
		{7,10,12,13},
		{8,11},
		{11}};
	M::iterator ite;
	std::queue<L>q;
	q.push(init);
	q.push(-1);
	int i,j,k;
	for(int x=0;x<=10;)
	{
		L l=q.front();
		q.pop();
		if(l<0)
		{
			q.push(l);
			++x;
			continue;
		}
		int res=func(l,x);
		if(res==-2)
			continue;
		if(res>=0)
			return res;
		int a[2];
		for(i=j=0;i<13;++i)
			if( !(l&(15LL<<(i*4))) )
				a[j++]=i;
		for(k=0;k<2;++k)
			for(i=0;i<4;++i)
			{
				int c=di[a[k]][i];
				if(c)
				{
					L t=S(l,a[k],c-1);
					q.push(t);
				}
				else break;
			}
	}
	return -1;
}
int main()
{
	F(0xBA9876543210LL,I());
	for(;;)
	{
		L l=0,x;
		for(int i=0;i<13;++i)
		{
			if(scanf("%lld",&x),x<0)return 0;
			l|=(x<<(i*4));
		}
		x=F(l,E());
		x<0?puts("NA"):printf("%lld\n",x);
	}
}

Measured memory_bytes: 2384
import sys

input = sys.stdin.readline

def main():
    N, K, Q = map(int, input().split())
    A = [0]*N
    for _ in range(Q):
        a = int(input())
        A[a-1] += 1
    
    for i in range(N):
        ans = K - (Q - A[i])
        if ans > 0:
            print('Yes')
        else:
            print('No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 4680
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>

int main() {
	int n, m;
	cin >> n >> m;
	vector<int>a(n);
	int sum(0);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	double b;
	b = double(sum) / (4 * double(m));
	int c(0);
	//cout << b << endl;
	rep(i, n) {
		if (a[i] >= b) {
			++c;
			
		}
	}
	if (c >= m) {
		cout << "Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    store = list()
    for i in range(N):
        A, B = map(int, input().split())
        store.append([A, B])
    store.sort(key = lambda x : x[0])
    cost = 0
    drink = 0
    for i in range(N):
        if drink < M:
            if drink + store[i][1] < M:
                drink += store[i][1]
                cost += store[i][0] * store[i][1]
            else:
                cost += store[i][0] * (M - drink)
                drink += M - drink
        else:
            break
    print(cost)
if __name__ == "__main__":
    main()

Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
int main(){
    int n;
    std::cin >> n;
    std::vector<int> x(n),y(n);
    rep(i,n)std::cin >> x[i]>>y[i];
    std::vector<int> p(n);
    rep(i,n)p[i]=i;
    dou d=0;
    do{
        rep(i,n-1)d+=sqrt(powl(abs(x[p[i]]-x[p[i+1]]),2)
            +powl(abs(y[p[i]]-y[p[i+1]]),2));
        
    }while(next_permutation(all(p)));
    rep(i,n)d/=(i+1);
    std::cout <<keta(10)<< d << std::endl;
    
}

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

int main() {
  ll n,k;
  cin>>n>>k;
  ll ans=0;
  rep(i,n){
    ll h;
    cin>>h;
    if(h>=k)ans++;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int N, M;
    vector<int> answer;
    while (cin >> N >> M && N != 0)
    {
        vector<int> h(N + 1, 0), w(M + 1, 0);
        int square = 0;
        map<int, int> length;
        for (int i = 0; i < N; i++)
        {
            cin >> h.at(i + 1);
            h.at(i + 1) += h.at(i);
        }
        for (int i = 0; i < M; i++)
        {
            cin >> w.at(i + 1);
            w.at(i + 1) += w.at(i);
        }
        for (int i = 0; i < N + 1; i++)
        {
            for (int j = 0; j < M + 1; j++)
            {
                length[h.at(i) - w.at(j)]++;
            }
        }
        for (auto x = length.begin(); x != length.end(); x++)
        {
            //cout << x->first << " " << x->second << endl;
            square += (x->second * (x->second - 1)) / 2;
        }
        answer.push_back(square);
    }
    for (int i = 0; i < answer.size(); i++)
    {
        cout << answer.at(i) << endl;
    }
    return 0;
}



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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,A,B,C,D,E;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>A>>B>>C>>D>>E;
	A=min({A,B,C,D,E});
	N=(N+A-1)/A;
	cout<<4+N<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
import static java.lang.Math.abs;
import java.util.Scanner;


/**
 *
 * @author must
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        
        for (int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int sum=0;
        for (int i=0;i<N-1;i++){
            sum+=abs(A[i+1]-A[i]);
        }
        sum+=abs(A[0]) + abs(A[N-1]);
        
        for(int k=0;k<N;k++){
            int delyen=0;
            int addyen=0;
            if(k==0){
                delyen = abs(A[k]) + abs(A[k+1]-A[k]);
                addyen = abs(A[k+1]);
            }else if(k==N-1){
                delyen = abs(A[k]) + abs(A[k]-A[k-1]);
                addyen = abs(A[k-1]);
            }else{
                delyen = abs(A[k+1]-A[k]) + abs(A[k]-A[k-1]);
                addyen = abs(A[k+1]-A[k-1]);                
            }
            int sum1 = sum - delyen + addyen;
            System.out.println(sum1);
        }
        

     }
    
}


Measured memory_bytes: 63376
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <functional>
#include <map>
#include <set>
#include <stack>
#include <deque>
#include <queue>

//#define INF 1000000000;
#define MOD 1000000007;
#define LIMIT 1000000000000000000;
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
    string a, b; cin >> a >> b;
    string ans = "D";
    if (a == b) {
        ans = "H";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    int t[n][3];
    REP(i, n - 1)
    {
        cin >> t[i][0] >> t[i][1] >> t[i][2];
    }
    REP(i, n - 1)
    {
        int ct = 0;
        rep(j, i, n - 1)
        {
            if (ct <= t[j][1])
            {
                ct = t[j][1] + t[j][0];
            }
            else
            {
                int diff = ct - t[j][1];
                //int add = diff / t[j][2];
                int add = (diff + t[j][2] - 1) / t[j][2];
                ct = t[j][0] + t[j][1] + add * t[j][2];
            }
        }
        cout << ct << endl;
    }
    cout << "0" << endl;
}


Measured memory_bytes: 256
/*
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_11_B    "Depth First Search"?????¨??????
????????????1.5h????§£????????±???????????¢?´¢
?°??????????????????????????????????????????????????§£???????????£????????§???????????¨??????
*/
#include <iostream>
using namespace std;
int a[100][100]={},f[100]={},d[100]={},T[200]={};//a[i][j]???i????§??????¨??????j??????????°????????????????T[i]?????????i???????????????????????????
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		int u,k;
		cin>>u>>k;
		for(int j=0;j<k;j++){
			cin>>a[u][j];
		}
	}
	T[1]=1;//????????????????????????
	f[1]=1;
	int s=1;//s?????¨????????¨???????????????????????????????????????
	for(int time=2;time<=2*n;time++){
		for(int j=0;j<100;j++){
			if(a[T[time-1]][j]==0){//?????????????????????????????????????????????????????????????????????
				d[T[time-1]]=time;
				if(f[T[time-1]]==s){//???????????¨?????¢?´¢???????????£??????
					for(int i=1;i<n;i++){
						if(f[i]==0){//??°????????¨?????????i
							T[time+1]=i;
							time++;
							f[i]=time;
							break;
						}
					}
					s=time;//s?????´??°
				}else{
					T[time]=T[f[T[time-1]]-1];//T[time]??????????????\?????????????????????????????????
				}
				break;
			}
			else if(f[a[T[time-1]][j]]==0){//?????£????????¨???????????????????????????
				f[a[T[time-1]][j]]=time;
				T[time]=a[T[time-1]][j];
				break;
			}
		}
	}
	for(int i=1;i<=n;i++){
		cout<<i<<" "<<f[i]<<" "<<d[i]<<endl;
	}
}

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

int search(string s[]) {
  int count = 0;
  int t = 0;
  for (int i = 0; ; i++) {
    if (s[i].size() > 5) continue;
    int start = i;
    for (int j = i; ; j++) {
      t += s[j].size();
      if (count == 0 || count == 2) {
	if (t == 5) {
	  count++;
	  t = 0;
	} else if (t > 5) {
	  count = 0;
	  t = 0;
	  break;
	} 
      } else {
	if (t == 7) {
	  count++;
	  if (count == 5) return start;
	  t = 0;
	} else if (t > 7) {
	  count = 0;
	  t = 0;
	  break;
	}
      }
    }
  }
}


int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    string s[n];
    for (int i = 0; i < n; i++)
      cin >> s[i];
    
    int ans = search(s);
    cout << ans + 1 << endl;
  }
}

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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;

typedef pair<ll,int>pa;

int p[10],pp[10],ppp[10],a[10];
pa sum1,sum2,sum3; ///len,v
ll ans;


bool getbit1(int x)
{
     for(int i=0;i<8;i++){
        if(x & (1<<i)) {
            if(p[i+1]) return false;
             p[i+1]=1;
             sum1.first+=a[i+1];
             sum1.second++;
        }
     }
     return true;
}

bool getbit2(int x)
{
     for(int i=0;i<8;i++){
        if(x & (1<<i)) {
            if(pp[i+1]) return false;
             pp[i+1]=1;
             sum2.first+=a[i+1];
             sum2.second++;
        }
     }
     return true;
}

bool getbit3(int x)
{
    for(int i=0;i<8;i++){
        if(x & (1<<i)) {
            if(ppp[i+1]) return false;
             ppp[i+1]=1;
             sum3.first+=a[i+1];
             sum3.second++;
        }
     }
     return true;
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    ans=1e9;
    int n,A,b,c;
    cin>>n>>A>>b>>c;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }

    for(int i=1;i<(1<<n);i++){
        memset(p,0,sizeof p);
        sum1.first=0,sum1.second=0;
        if(!getbit1(i)) continue;

        for(int j=1;j<(1<<n);j++){
            sum2.first=0,sum2.second=0;
             memcpy(pp,p,sizeof p);
             if(!getbit2(j)) continue;

             for(int r=1;r<(1<<n);r++){
                sum3.first=0,sum3.second=0;
                memcpy(ppp,pp,sizeof pp);
                if(!getbit3(r)) continue;
                ans=min(ans,sum1.second*10+sum2.second*10+sum3.second*10-30+abs(sum1.first-A)+abs(sum2.first-b)+abs(sum3.first-c));
             }
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3604
from collections import deque
N = int(input())
a = list(map(int,input().split()))
a = deque(a)
count = 0
k = 1
for i in range(N):
    if a[0] != k:
        a.popleft()
        count += 1
    else:
        a.popleft()
        k += 1
if k == 1:
    print(-1)
else:
    print(count)



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

int main(void){
  string S;
  unsigned long K;
  cin >> S >> K;

  // 1以外の文字は半無限に長くなる
  // 先頭から1の数を数えれば良さそう?
  int count1 = 0;
  int i;
  for (i = 0; i < S.size(); i++){
    if(S[i] =='1'){
      count1++;
    }else{
      break;
    }
  }

  if(count1>=K){
    cout << 1<<endl;
  }else{
    cout << S[i] << endl;
  }
}


Measured memory_bytes: 256