akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
//#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
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;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
int a, b, c;
int main(void) {
    cin >> a >> b >> c;
    (b - a == c - b ? cout << "YES" << endl : cout << "NO" << endl);
    return 0;
}

Measured memory_bytes: 3584
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

let cnt = 0;

const merge = (arr, left, mid, right) => {
    const n1 = mid - left;
    const n2 = right - mid;
    const L = [];
    const R = [];

    for (let i = 0; i < n1; i++) {
        L[i] = arr[left + i];
    }
    for (let i = 0; i < n2; i++) {
        R[i] = arr[mid + i];
    }

    L[n1] = 1/0;
    R[n2] = 1/0;

    let i = 0;
    let j = 0;
    for (let k = left; k < right; k++) {
        if (L[i] <= R[j]) {
            arr[k] = L[i];
            i++;
        } else {
            arr[k] = R[j];
            j++;
            cnt += n1-i;
        }
    }
};

const msort = (arr, left, right) => {
    if (left + 1 < right) {
        const mid = Math.floor((left + right) / 2);
        msort(arr, left, mid);
        msort(arr, mid, right);
        merge(arr, left, mid, right);
    }
};

const data = line[1].split(' ').map(Number);
msort(data, 0, data.length);
console.log(cnt);



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

int digit_sum(int x) {
  if (x == 0)
    return 0;
  return x % 10 + digit_sum(x / 10);
}

int main() {
  int n;
  cin >> n;
  int ret = INF;
  for (int a = 1; a + a <= n; a++) {
    ret = min(digit_sum(a) + digit_sum(n - a), ret);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
// ARC089
// C - March

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const string MONTH = "MARCH";
const int M = MONTH.length();
const int K = 3;

int N;
vector<int> cnt(M);

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < M; j++) {
            if (s[0] == MONTH[j]) {
                cnt[j]++;
                break;
            }
        }
    }

    ll ans = 0;
    int comb = (1 << K) - 1;
    while (comb < (1 << M)) {
        ll prd = 1;
        for (int j = 0; j < M; j++) {
            if (comb & (1 << j)) {
                prd *= cnt[j];
            }
        }
        ans += prd;

        int x = comb & -comb, y = comb + x;
        comb = (((comb & ~y) / x) >> 1) | y;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*Hey, What's up?*/

#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
string s;
int main()
{
    fastio;
    long long a=0,b=0,c,d,e,f=0,l,g,m,n,k,i,j,t,p,q;
    cin>>n>>a>>b;
    n*=a;
    if(n>b)swap(n,b);
    cout<<n<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "cmath"
#include "vector"
using namespace std;

int n, k;
vector <int> h;
vector <long long> cost;

long long solve(int x) {
    if (cost[x] != -1) {
        return cost[x];
    }

    if (x == 1) {
        cost[x] = 0;
    }
    else {
        cost[x] = 1e18;
        for (int i=x-1; (x - i) <= k && i >= 1; i--) {
            long long jump_i = solve(i) + abs(h[x] - h[i]);
            cost[x] = min(cost[x], jump_i);
        }
    }

    return cost[x];
}

int main() {
    cin >> n >> k;
    h.resize(n + 1);
    cost.resize(n + 1, -1LL);
    for (int i=1; i<=n; i++) cin >> h[i];
    solve(n);
    cout << cost[n] << '\n';
}


Measured memory_bytes: 6144
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    string S;
    cin>>S;
    int C=0;
    int D=0;
    for(int i=0;i<3;i++){
        if(S[i]=='A'){
            C++;
        }
        else if(S[i]=='B'){
            D++;
        }
    }
    if(C!=0&&D!=0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

}


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

int main() {
    ll N, K;
    cin >> N >> K;
    ll ans;

    if (N > K) N = N - (N / K) * K;
    ans = min(N, K - N);
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 300005;
const int MM = 1000000007;

int N, M;
pii D[MX], E[MX];

int dist(int x, int y){
	if(x <= y) return y-x;
	else return M+y-x;
}

int main()
{
	scanf("%d%d", &N, &M);
	for(int i = 1; i <= N; i++) scanf("%d", &D[i].first);
	for(int i = 1; i <= N; i++) D[i].second = D[i+1].first;
	N--;
	
	vector<pii> Ev;
	int sz = 0;
	for(int i = 1; i <= N; i++){
		if( D[i].first < D[i].second ){
			E[++sz] = D[i];
			E[++sz] = pii(D[i].first + M, D[i].second + M);
		}
		else{
			E[++sz] = pii(D[i].first - M, D[i].second);
			E[++sz] = pii(D[i].first, D[i].second + M);
		}
	}
	for(int i = 1; i <= sz; i++){
		Ev.emplace_back(E[i].first, +i);
		Ev.emplace_back(E[i].second, -i);
	}
	sort(Ev.begin(), Ev.end());

	ll total = 0, cnt = 0, sum = 0, ans = 0;
	for(int i = 1; i <= N; i++) total += dist(D[i].first, D[i].second);
	ans = total;
	for(int i = 0, j = 0; i < Ev.size(); i = j){
//		printf("%d : %lld %lld %lld\n", Ev[i].first, total, sum, cnt);
		ans = min(ans, total + sum - cnt * Ev[i].first + cnt);
		for(; j < Ev.size() && Ev[j].first == Ev[i].first; j++){
			int ad = abs(Ev[j].second);
			if(Ev[j].second < 0){
				cnt--;
				sum -= E[ad].second;
				total += dist(E[ad].first, E[ad].second);
			}
			else{
				cnt++;
				sum += E[ad].second;
				total -= dist(E[ad].first, E[ad].second);
			}
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 9584
#include <iostream>
#include <string>
#include <numeric>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <random>

using namespace std;
 
int main()
{
	string str;
	cin >> str;

	bool S = false;
	bool N = false;
	bool E = false;
	bool W = false;
 
	for (auto c : str)
	{
		if (c == 'S') S = true;
		if (c == 'N') N = true;
		if (c == 'E') E = true;
		if (c == 'W') W = true;
	}

	if (((S == true && N == false) || (S == false && N == true)) || ((E == true && W == false) || (E == false && W == true))) cout << "No" << endl;
	else cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] num = new int[3];
		for(int i = 0; i < num.length; i++) {
			num[i] = scan.nextInt();
		}
		for(int i = 0; i < num.length; i++) {
			for(int j = i + 1; j < num.length; j++) {
				if(num[i] > num[j]) {
					int tmp = num[i];
					num[i] = num[j];
					num[j] = tmp;
				}
			}
		}
		for(int i = 0; i < num.length; i++) {
			if(i != 0) System.out.print(" ");
			System.out.print(num[i]);
		}
		System.out.println();
	}
}


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

int main()
{
  int A[3][3], N, b;
  bool bingo = false;
  cin >> A[0][0] >> A[0][1] >> A[0][2];
  cin >> A[1][0] >> A[1][1] >> A[1][2];
  cin >> A[2][0] >> A[2][1] >> A[2][2];
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> b;
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < 3; k++)
      {
        if (A[j][k] == b)
        {
          A[j][k] = -1;
        }
      }
    }
  }
  for (int i = 0; i < 3; i++)
  {
    if (A[i][0] == -1 && A[i][1] == -1 && A[i][2] == -1)
    {
      bingo = true;
    }
  }
  for (int i = 0; i < 3; i++)
  {
    if (A[0][i] == -1 && A[1][i] == -1 && A[2][i] == -1)
    {
      bingo = true;
    }
  }
  if (A[0][0] == -1 && A[1][1] == -1 && A[2][2] == -1)
  {
    bingo = true;
  }
  if (A[0][2] == -1 && A[1][1] == -1 && A[2][0] == -1)
  {
    bingo = true;
  }

  if (bingo)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <ctime>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;



int main(void)
{
    ll n, a, b;
    cin >> n >> a >> b;
    ll x = min(n%(a+b), a);
    ll ans = (ll)(n/(a+b)*a + x);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input = input.split(" ");

  var A = parseInt(input[0]);
  var B = parseInt(input[1]);

  if (A <= 8 && B <= 8) {
    console.log('Yay!');
  } else {
    console.log(':(');
  }
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
from collections import deque
s = input()
q = int(input())
op = [input().split() for _ in range(q)]


flag = True
ans = deque(s)

for i in op:
    if i[0] == "1":
        flag = not flag
    else:
        if i[1] == "1":
            if flag:
                ans.appendleft(i[2])
            else:
                ans.append(i[2])
        else:
            if flag:
                ans.append(i[2])
            else:
                ans.appendleft(i[2])

if flag:
    while(ans):
        t = ans.popleft()
        print(t, end='')
else:
    while(ans):
        t = ans.pop()
        print(t, end='')

Measured memory_bytes: 121816
#include <iostream>
#include <vector>

using namespace std;

void MaximalValue() 
{
  int n;
  int res = 0;
  cin >> n;
  vector<int> b(n);
  for (int i = 0; i < n - 1; i++) cin >> b[i];
  int next = b[0];
  for (int i = 0; i < n-1; i++) {
    if (b[i] < next) next = b[i];
    res += next;
    next = b[i];
  }
  res += next;
  cout << res << endl;
}

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

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int A=scan.nextInt(),B=scan.nextInt();
        if(24 <= A+B){
            System.out.println(A+B - 24);
        }else{
        System.out.println(A+B);
        }
    }
}

Measured memory_bytes: 21844
n =int(input())
count = 0

def make753(s):
    global count
    if int(s) > n:
        return 0
    if all(s.count(i) > 0 for i in '753'):
        count += 1
    for i in '753':
        make753(s + i)
    return count
           
print(make753('0'))

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  if(a<=0&&b>=0) {
    cout << "Zero" << endl;
  }
  else if(a>0) {
    cout << "Positive" << endl;
  }
  else if(b<0) {
    if(abs(b-a)%2==0) {
      cout << "Negative" << endl;
    }
    else {
      cout << "Positive" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	string n; cin>>n;
	if (n[0]=='9'||n[1]=='9') cout<<"Yes";
	else cout<<"No"<<endl;	
	return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    int n; cin >> n;
    vector<lint> l(n);
    rep(i, n) cin >> l[i];

    lint ans = 0;
    for(int i = 0; i < n-2; i++) for(int j = i+1; j < n-1; j++) for(int k = j+1; k < n; k++){
        if(l[i]==l[j] || l[j]==l[k] || l[k]==l[i]) continue;
        if(abs(l[i]-l[j]) < l[k] && l[k] < l[i]+l[j]){
            ans++;
        }
    }
    out(ans);
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
//using ll=long long;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279; //円周率
/*---------------------便利な関数--------------------------------------*/
int fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}

int gcd(int a, int b) {        //最大公約数
    if (b == 0) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) {      //最小公倍数
    return a * b / gcd(a, b);
}

int keta(int n) {        //桁数を求める
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}

int ketasum(int n) {    //各桁の和
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
//最小化問題(DP)
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
//最大化問題(DP)
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
/*-------------ここまで---------------------------------------------*/

/*signed*/int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    s[k-1] += 32;
    cout << (string)s << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<string.h>

int main()
{
    char s[7];

    scanf("%s", s);

    if(strcmp(s, "Sunny") == 0){
        printf("Cloudy");
    }
    else{
        if(strcmp(s, "Cloudy") == 0){
            printf("Rainy");
        }
        else{
            printf("Sunny");
        }
    }

    return 0;
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head &head, Tail&... tail) { cin >> head; input(tail...); }

inline void print() { cout << "\n"; }
template <class Head, class... Tail>
inline void print(Head &&head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<< (ostream &out, const vector<T> &vec) {
    static constexpr const char *delim[] = { " ", "" };
    for (const auto &e : vec) out << e << delim[&e == &vec.back()];
    return out;
}
// }}} End Header

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

    var(int, N);
    set<int> S;

    rep(i, N) {
        var(int, e);
        S.insert(e);
    }

    print((int(S.size()) == N) ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 9600
#include <iostream>

using namespace std;

int main(void)
{
    int a, b;

    cin >> a >> b;

    if((a+b)%2==0){
        cout << (a+b)/2 << endl;
    }
    else{
        cout << (a+b)/2+1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=200000+50;
int n;
int a[maxn];
int f[maxn];
int vis[maxn];
int tot;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        if(vis[a[i]]) f[vis[a[i]]]++;
        else
        {
            vis[a[i]]=++tot;
            f[vis[a[i]]]++;
        }    
    }   
    long long ans=0;
    for(int i=1;i<=tot;i++)
    {
        long long b=f[i];
        ans+=b*(b-1);
    }

    for(int i=1;i<=n;i++)
    {
        long long b=f[vis[a[i]]];
        cout<<ans/2-b+1<<'\n';
    }
    return 0;

}

Measured memory_bytes: 3712
import kotlin.*


fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val s = sc.nextCharArray()
        // 選ぶ区間 順番は関係ない

        // 区間の端の候補
        // 01の境目

        // 01の境目 遠いほうの端までの距離のmin

        var ans = s.size
        for (i in 0 until s.size - 1) {
            if (s[i] != s[i + 1]) {
                val left = i + 1
                val right = s.size - (i + 1)
                ans = Math.min(ans, Math.max(left, right))
            }
        }

        println(ans)
    }
}

class MyScanner {
    private var ptr = 0
    private var l = listOf<String>()

    fun next(): String {
        while (l.size <= ptr) {
            l = readLine()!!.split(' ')
            ptr = 0
        }
        return l[ptr++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun list(): List<String> {
        ptr = l.size
        return readLine()!!.split(' ')
    }

    fun intList() = list().map { s -> s.toInt() }
    fun longList() = list().map { s -> s.toLong() }
    fun doubleList() = list().map { s -> s.toDouble() }

    fun array() = list().toTypedArray()
    fun intArray() = intList().toIntArray()
    fun longArray() = longList().toLongArray()
    fun doubleArray() = doubleList().toDoubleArray()
}


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

using namespace std;
using ll = long long;

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

    int n, r;

    cin >> n >> r;

    printf("%d\n", n < 10 ? r + 100 * (10 - n) : r);

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.9f\n",*********);
#include<vector>//文字列.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char(小文字-32=大文字) to_string,string,char
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap
#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(s,n) rep(i,n)cin>>s[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//標準=昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define str string
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

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

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int SED(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}//stringのほうが効率よくないか？

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */


int main(void) {
	rapid_pleaseAC_fast;

	double a;
	cin >> a;

	printf("%.15f\n", a * a * a / 27);

	please AC;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc =new  Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int k=sc.nextInt();
		if(b-k+1<=a+k-1) {
			for(int i=a;i<=b;i++) {
				System.out.println(i);
			}
		}else {
			for(int i=a;i<=b&&i<a+k;i++){
				System.out.println(i);
			}
			for(int i=b-k+1;i<=b;i++) {
				System.out.println(i);
			}
		}
	}
}

Measured memory_bytes: 23124
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

namespace CSharp
{
    static class Program
    {
        static void Main(string[] args)
        {
            ReadString();
            double[] V = ReadIntArray().OrderBy(x => x).Select(x => (double)x).ToArray();
            for (int i = 0; i < V.Length - 1; i++)
            {
                V[i + 1] = (V[i] + V[i + 1]) / 2;
            }

            double ans = V[V.Length - 1];
            Console.WriteLine(ans);
        }

        #region Helpers

        static int[] ReadIntArray() => Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
        static long[] ReadLongArray() => Console.ReadLine().Split().Select(s => long.Parse(s)).ToArray();

        static int[] ReadLineIntArray(int count) => Enumerable.Repeat(0, count).Select(_ => int.Parse(Console.ReadLine())).ToArray();
        static long[] ReadLineLongArray(int count) => Enumerable.Repeat(0, count).Select(_ => long.Parse(Console.ReadLine())).ToArray();

        static string ReadString() => Console.ReadLine();
        static int ReadInt() => int.Parse(Console.ReadLine());
        static long ReadLong() => long.Parse(Console.ReadLine());

        static void ReadInt(out int first)
        {
            var array = ReadIntArray();
            first = array[0];
        }

        static void ReadInt(out int first, out int second)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
        }

        static void ReadInt(out int first, out int second, out int third)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadInt(out int first, out int second, out int third, out int fourth)
        {
            var array = ReadIntArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        static void ReadLong(out long first)
        {
            var array = ReadLongArray();
            first = array[0];
        }

        static void ReadLong(out long first, out long second)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
        }

        static void ReadLong(out long first, out long second, out long third)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
        }

        static void ReadLong(out long first, out long second, out long third, out long fourth)
        {
            var array = ReadLongArray();
            first = array[0];
            second = array[1];
            third = array[2];
            fourth = array[3];
        }

        #endregion
    }
}

Measured memory_bytes: 13396
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = (int)(n-1); i >= 0; i--)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;cin>>n;
  vector<int>a(n+1,0);
  rep(i,n)cin>>a[i];
  sort(all(a),greater<int>());
  int f=-1;//1:first
  rep(i,n){
  //if(a[0]==1)f=(n-1)%2;
    //if(a[i]==i+1&&a[i+1]<i+1){
      //f=0;
    //}
    if(a[i]>=i+1&&a[i+1]<i+1){//case1
      if((a[i]-1-i)%2){
        f=1;
      }
      else f=0;
      break;
    }
    if(a[i]>i+1&&a[i+1]==i+1){//case2
      //cout<<"skdfjlksd"<<endl;
      int j=i+1;
      while(a[i+1]==a[j+1])j++;
      int x=(j-(i+1))%2;
      int y=(a[i]-1-(i+1))%2;
      if(x&y){
        f=0;
      }
      else {
        f=1;
      }

      break;
    }
    if(a[i]==i+1&&a[i+1]==i+1){//case3
      int j=i+1;
      while(a[i+1]==a[j+1])j++;
      if((j-(i))%2){
        f=1;
      }
      else {
        f=0;
      }
      break;
    }
  }
  //if(f==-1)cout<<"fdSecond"<<endl;
  if(f==1){
    cout<<"First"<<endl;
  }
  else if(f==0){
    cout<<"Second"<<endl;
  }
  return 0;

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(std::unique(all(x)), x.end());
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;
const double PI=acos(-1);
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}


int main() {
    int n,m;
    string s;
    cin>>n>>m>>s;
    reverse(all(s));
    vector<int> ok;
    rep(i,n+1) {
        if(s[i]=='0') ok.push_back(i);
    }
    
    vector<int> ans;
    int pos=0;
    while(pos<n) {
        auto itr=lower_bound(all(ok),pos+m+1);
        itr--;
        int x=*itr-pos;
        if(x<=0) {
            cout<<-1<<endl;
            return 0;
        }
        ans.push_back(x);
        pos+=x;
    }
    
    rrep(i,sz(ans)) cout<<ans[i]<<endl;
}



Measured memory_bytes: 1592
from collections import deque

def solve():
    ret = 0
    stack = deque()
    stack.append([1, {1}])
    while stack:
        node, used = stack.popleft()
        if len(used) == N:
            ret += 1
            continue

        for n in neighbors[node]:
            if n in used:
                continue
            stack.append([n, used | {n}])

    print(ret)

if __name__ == "__main__":
    N, M = map(int, input().split())
    neighbors = [[] for _ in range(N + 1)]
    for _ in range(M):
        a, b = map(int, input().split())
        neighbors[a].append(b)
        neighbors[b].append(a)
    solve()

Measured memory_bytes: 44784
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,1,0,-1};
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    double L;cin>>L;
    CST(10)<<L*L*L/27<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N - 1);
    rep(i, N) { cin >> A[i]; }
    rep(i, N) { cin >> B[i]; }
    rep(i, N - 1) { cin >> C[i]; }
    int sum = 0;
    int prev = -1;
    rep(i, N)
    {
        sum += B[A[i] - 1];
        if (prev == A[i] - 1) {
            sum += C[prev - 1];
        }
        prev = A[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
function Main(input) {
  input=input.split("\n");
  const S=input[0]
  var max=0;
  var zantei=0;
  for(var i=0;i<S.length;i++){
    if(S[i]==='S'){
      if(max<zantei){
        max=zantei;
      }
      zantei=0;
    }else{
      zantei++;
    }
  }
  if(max<zantei){
    max=zantei;
  }
  console.log(max);
  
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


Measured memory_bytes: 29636
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define Mod 1000000007
#define ll long long
#define dd double
#define pb push_back
#define ff first
#define ss second
#define Mp make_pair
#define INF (ll)(1e17+5)
#define NN (ll)(1e6+5)
int mod(string s,int a) 
{ 
    int ans=0; 
    for (int i=0;i<s.length();i++) 
         ans=(ans*10+(int)s[i]-'0')%a; 
    return ans; 
}
ll min(ll x,ll y){if(x<y) return x;return y;}
ll max(ll x,ll y){if(x>y) return x;return y;}
ll power(ll x,unsigned ll y) 
{ 
    if (y==0) 
        return 1; 
    else if (y%2==0) 
        return power(x,y/2)*power(x,y/2); 
    else
        return x*power(x,y/2)*power(x,y/2); 
}
ll hcf(ll a,ll b) 
{ 
    if(b==0) 
        return a; 
    return hcf(b,a%b);  
}
int main()
{
   fio;
   /*#ifndef ONLINE_JUDGE 
    	freopen("input.txt", "r", stdin); 
    	freopen("output.txt", "w", stdout); 
    	freopen("error.txt", "w", stderr); 
   #endif*/
   ll TT=1;
   //cin>>TT;
   while(TT--)
   {    
       ll n,a,b,ans;
       cin>>n>>a>>b;
       ans=(n/(a+b))*a;
       ans+=min((n%(a+b)),a);
       cout<<ans<<"\n";
   }
}

Measured memory_bytes: 256
/*  
    |\_/|
    |* *|
    \_+_/
*/
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  string str;

  cin>>str;

  string temp="CODEFESTIVAL2016";

  int cnt=0;
  
  for(int i=0;i<str.length();i++){

    if(str[i]!=temp[i]){
      cnt++;
    }
  }

  cout<<cnt<<endl;
  
  return 0;
  
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("inp.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif

    int h,w,k;
    cin>>h>>w>>k;

    string s[h];
    for(int i=0;i<h;++i) {
        cin>>s[i];
    }

    int total = 0;
    for(int i=0;i<h;++i) {
        for(int j=0;j<w;++j) {
            if(s[i][j] == '#') ++total;
        }
    }

    int cc1 = 0;

    bitset<10> bh(0);
    
    int ans = 0;
    while(cc1 < 100) {
        int r = bh.to_ulong();
        cc1 += 1;

        bitset<10> bw(0);
        int cc2 = 0;

        while(cc2 < 100) {

            int c = bw.to_ulong();
            cc2 += 1;

            int temp = 0;
            for(int i=0;i<h;++i) {
                if(bh[i] == 1) {
                    for(int j=0;j<w;++j) {
                        if(s[i][j] == '#') ++temp;
                    }
                }
            }
            for(int i=0;i<w;++i) {
                if(bw[i] == 1) {
                    for(int j=0;j<h;++j) {
                        if(s[j][i] == '#') ++temp;
                    }
                }
            }
            for(int i=0;i<h;++i) {
                if(bh[i] == 1) {
                    for(int j=0;j<w;++j) {
                        if(bw[j] == 1) {
                            if(s[i][j] == '#') --temp;
                        }
                    }
                }
            }

            if(total - temp == k) ++ans;
            // cout<<temp<<"\n";


            int ff = 1;
            for(int i=0;i<w;++i) {
                if(bw[i] == 0) {
                    ff = 0;
                    break;
                }
            }
            if(ff) break;

            c += 1;
            bw = c;
        }


        int f = 1;
        for(int i=0;i<h;++i) {
            if(bh[i] == 0) {
                f = 0;
                break;
            }
        }
        if(f) break;
        r += 1;
        bh = r;
    }
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3672
num_li = list(input())
for i in range(2**3):
    li = ['+']*3
    q = num_li[0]
    for j in range(3):
        if ((i>>j) & 1):
            li[j] = '-'
        q += li[j] + num_li[j+1]
    if eval(q) == 7:
        print('{}=7'.format(q))
        break

Measured memory_bytes: 8956
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

// [1,x) で必要な文字数
ll calc(ll x)
{
    string s = to_string(x);
    ll n = s.length();
    ll res = 0;
    for (ll i = 1; i <= n - 1; i++)
    {
        res += 9 * i * pow(10, i - 1);
    }
    res += n * (x - pow(10, n - 1));
    return res;
}

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

    // N 桁目から K 文字
    ll N, K;
    while (cin >> N >> K, N || K)
    {
        string s = "0";
        for (int i = 1; i <= 9999; i++)
        {
            s += to_string(i);
        }
        if (N + K - 1 < (int)s.length())
        {
            cout << s.substr(N, K) << endl;
            continue;
            ;
        }
        ll low = 1, high = 1e9;
        for (int i = 0; i < 50; i++)
        {
            ll mid = (low + high) / 2;
            if (calc(mid) >= N)
            {
                high = mid;
            }
            else
            {
                low = mid;
            }
        }
        string res = "0";
        for (int i = low; i <= low + 100; i++)
        {
            res += to_string(i);
        }
        cout << res.substr(N - calc(low), K) << endl;
    }
}



Measured memory_bytes: 3524
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(0..2*N).to_a
f=a I[1..N]
l,r=1,N+1
9.times{
m=(l+r)/2
f==a(I[m,N])?l=m:r=m
}
x=I[r,N-1]
y=I-[0]-I[l,N+1]
1.upto(2*N){|i|
s+=a([i]+(x.index(i)?y:x))[0]
}
puts s

Measured memory_bytes: 2508
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <math.h>
#include <map>
#include<cmath>
#include<queue>

typedef long long ll;
using namespace std;
#define mod 10007

int main(void){
  int n;cin >> n;
  string s;cin >> s;
  int ans=0;
  for(int i=0;i<n;i++){
    if(s[i]!=s[i+1]){
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    string s;
    io.read(s);
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '1') ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n;
    while(cin>>n,n){
        int next=3,now=0,ans=0;
        string s;
        msi p={{"lu",1},{"ld",-1},{"ru",2},{"rd",-2}};
        rep(i,n){
            cin>>s;
            now+=p[s];
            if(now==next){
                ans++;
                next^=3;
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3144
#include <stdio.h>

int N;
#define MAX 100
int a[MAX][MAX];

int main(){
  int i,j,count,num,head;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&head);
    scanf("%d",&count);
  if(count == 0)continue;
  else for(j=0;j<count;j++){
      scanf("%d",&num);
      a[head-1][num-1] = 1;
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(j==N-1){
        printf("%d\n",a[i][j]); break;
      }
      else printf("%d ",a[i][j]);
    }
    
  }
return 0;

}

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

int main(){
  int n,m,i,cur,ans;
  cin >> n;
  vector<int> p(n);
  for(i=0; i<n; i++){
    cin >> p[i];
  }
  cur=n+1; ans=0;
  for(i=0; i<n; i++){
    if(cur>p[i]){
      ans++; cur=p[i];
    }
  }
  cout << ans;
}

Measured memory_bytes: 1024
// ITP1_7_B
import java.util.Scanner;

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

    // Cacl roop
    while(true){
      // Input
      String[] row = scanner.nextLine().split(" ");
      int n = Integer.parseInt(row[0]);
      int x = Integer.parseInt(row[1]);
      // Stop condition
      if(n==0 && x==0){
        break;
      }

      // Calculation
      int answer = 0;
      for(int i=1; i<=n-2; i++){
        for(int j=i+1; j<=n-1; j++){
          int tmp = i + j;
          int k = x - tmp;

          if(k<=i || k<=j){
            continue;
          }

          if(k>=1 && k<=n){
            answer += 1;
          }
        }
      }
      // Output
      System.out.println(answer);
    }
  }
}



Measured memory_bytes: 26280
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <bits/stdc++.h>

using namespace std;

int main()
{   long long w,h,n,z,x,c,a,b,i,j,k,y,cnt=0;
    string s;
    cin>>s;
    for(i=1;i<s.length();i++)
    { 
      if(s[i]!=s[i-1]){cnt++;}  
    } 
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define SZ(i) int(i.size())
#ifdef tmd
#define IOS()
#define debug(...) fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y){cerr<<x<<", ";_do(y...);}
#else
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define debug(...)
#endif

const int MAXN = 1003;
const int MAXC = 5003;
const int iNF = 0x3f3f3f3f;

int n, p[MAXN], x[MAXN], dp[MAXN][2];
vector<int> edg[MAXN];
int mn[2][MAXC];

void ckmin (int &cu, const int &va) {
    if (cu > va) {
        cu = va;
    }
}

void dfs (int nd) {
    for (auto v : edg[nd]) {
        dfs(v);
    }
    int sz = SZ(edg[nd]);

    memset(mn, iNF, sizeof(mn));
    mn[0][0] = 0;
    REP1 (i, sz) { // black
        int v = edg[nd][i-1];
        for (int j=0; j<MAXC; j++) {
            mn[i&1][j] = iNF;
            if (dp[v][0] != iNF && j >= x[v]) {
                ckmin(mn[i&1][j], mn[i&1^1][j-x[v]] + dp[v][0]);
            }
            if (dp[v][1] != iNF && j >= dp[v][1]) {
                ckmin(mn[i&1][j], mn[i&1^1][j-dp[v][1]] + x[v]);
            }
        }
    }

    dp[nd][0] = iNF;
    REP (i, x[nd]+1) {
        dp[nd][0] = min(dp[nd][0], mn[sz&1][i]);
    }


    memset(mn, iNF, sizeof(mn));
    mn[0][0] = 0;
    REP1 (i, sz) { // white
        int v = edg[nd][i-1];
        for (int j=0; j<MAXC; j++) {
            mn[i&1][j] = iNF;
            if (dp[v][1] != iNF && j >= x[v]) {
                ckmin(mn[i&1][j], mn[i&1^1][j-x[v]] + dp[v][1]);
            }
            if (dp[v][0] != iNF && j >= dp[v][0]) {
                ckmin(mn[i&1][j], mn[i&1^1][j-dp[v][0]] + x[v]);
            }
        }
    }

    dp[nd][1] = iNF;
    REP (i, x[nd]+1) {
        dp[nd][1] = min(dp[nd][1], mn[sz&1][i]);
    }
}

/*********************GoodLuck***********************/
int main () {
    IOS();

    cin >> n;
    for (int i=2; i<=n; i++) {
        cin >> p[i];
        edg[p[i]].emplace_back(i);
    }

    REP1 (i, n) {
        cin >> x[i];
    }

    dfs(1);

    REP1 (i, n) {
        debug(dp[i][0], dp[i][1]);
    }

    cout << (min(dp[1][1], dp[1][0]) == iNF ? "IMPOSSIBLE" : "POSSIBLE") << endl;

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


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

  ll sum = 0;
  ll keta = 0;
  rep(i, M) {
    ll d, c; cin >> d >> c;
    sum += d*c;
    keta += c;
  }

  ll ans = keta + (sum-1)/9 - 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384