akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define PI acosl(-1)
using namespace std;

int main() {
  double ans,rad,deg,A,B;
  double H,M;
  cin >> A >> B >> H >> M;
  H = 30*H + 0.5*M;
  M *= 6;
  if(H > M){
    deg = H - M;
  }
  else{
    deg = M - H;
  }
  /*
  rad = cos((deg*PI)/180.0);
  ans = A*A + B*B - rad*2*A*B;
  cout << setprecision(20) << sqrt(ans) << endl;
  */
  rad = cosl((deg*M_PI)/180.0);
  ans = A*A + B*B - rad*2*A*B;
  cout << setprecision(20) << sqrtl(ans) << endl;
  return 0;
}


Measured memory_bytes: 4164
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl
#define INF 1000000;
#include <map>
#include <math.h>
 
using ll = long long;
using namespace std;

ll n, k;
const ll mod = 1000000007;



int main(){
    int y, m, d;
    char s1, s2;
    cin >> y >> s1 >> m >> s2 >> d;
    if(m<=4) out("Heisei");
    else out("TBD");
}

Measured memory_bytes: 256
/*
 *    author:  Gary Shih
 *    created: 2020-05-03 23:05:33
 */
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.setf(ios::fixed), cout.precision(9);
  int n;
  cin >> n;
  vector<double> p(n);
  for (int i = 0; i < n; ++i) cin >> p[i];
  vector<vector<double>> dp(n, vector<double>(n + 1));
  dp[0][0] = 1 - p[0];
  dp[0][1] = p[0];
  for (int i = 1; i < n; ++i) {
    for (int j = 0; j <= i + 1; ++j) {
      dp[i][j] = dp[i - 1][j] * (1 - p[i]);
      if (j > 0) dp[i][j] += dp[i - 1][j - 1] * p[i];
    }
  }
  double ans = 0;
  for (int i = n / 2 + 1; i <= n; ++i) ans += dp.back()[i];
  cout << ans << '\n';
}


Measured memory_bytes: 70656
#1. input
# map and zip, split()
N = int(input())
D, X = map(int, input().split())
A = [0]*N
for i in range(N):
    A[i] = int(input())


#2. count how many chocolates each member ate
choco_eaten = [0]*N
for i in range(N):
    day = 1
    while day <= D:
        choco_eaten[i] = choco_eaten[i] + 1
        day = day+A[i]


#3. output
print(X + sum(choco_eaten))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int a[102];
int main()
{
    ios::sync_with_stdio(false);
    long long a,b,c;
    cin>>a>>b>>c;
    a=abs(a);
    long long d=a/c;
    if (b>=d)
    {
        b-=d;
        if (b%2==0)
            cout<<a%c<<endl;
        else
            cout<<c-a%c<<endl;
    }
    else
        cout<<a-b*c<<endl;
    return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <utility>
#include <vector>
using namespace std;
using ll = long long;
using Pos = pair<int, int>;
inline ll distance(const Pos& a, const Pos& b) {
  return abs(a.first - b.first) + abs(a.second - b.second);
}
ll INF = 100100100100;
int main() {
  int N, M;
  cin >> N >> M;
  vector<Pos> ps(N);
  for(int i = 0; i < N; ++i) {
    cin >> ps[i].first >> ps[i].second;
  }
  vector<Pos> as(M);
  for(int i = 0; i < M; ++i) {
    cin >> as[i].first >> as[i].second;
  }
  auto pos_no = [&as](const Pos& p) {
    int mind = INF;
    int idx = 0;
    for(int i = 0; i < as.size(); ++i) {
      auto d = distance(p, as[i]);
      if(d < mind) {
        mind = d;
        idx = i;
      }
    }
    return idx + 1;
  };
  for(auto p : ps) {
    cout << pos_no(p) << endl;
  }

  return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int ans = n;
    if(n % 2 == 1) ans *= 2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;

int main(){
	double x, h, ans;
	while (cin >> x >> h) {
		if (x == 0 && h == 0) { break; }
		x *= 10000;
		h *= 10000;
		ans = pow(x, 2) + 2 * x * sqrt(pow(h,2)+pow(x/2,2));
		cout << fixed << setprecision(6) << ans / 100000000 << endl;
	}
	return 0;
}

Measured memory_bytes: 3192
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def main():
    H, W = NMI()
    C = NLI()
    D = NLI()
    C = [x-1 for x in C]
    D = [x-1 for x in D]
    grid = [SI() for _ in range(H)]

    que = deque()
    cost = [[10**10]*W for _ in range(H)]
    cost[C[0]][C[1]] = 0
    que.append(C)
    while que:
        now = que.popleft()
        now_cost = cost[now[0]][now[1]]

        for i in range(-2, 3):
            if now[0] + i < 0 or now[0] + i >= H:
                continue
            for j in range(-2, 3):
                if now[1]+j < 0 or now[1]+j >= W:
                    continue
                if i == j == 0:
                    continue
                goto = [now[0]+i, now[1]+j]
                goto_cost = cost[goto[0]][goto[1]]
                if grid[goto[0]][goto[1]] == "#":
                    continue

                dist = abs(goto[0]-now[0]) + abs(goto[1]-now[1])
                if dist == 1:
                    if now_cost < goto_cost:
                        cost[goto[0]][goto[1]] = now_cost
                        que.appendleft(goto)
                else:
                    if now_cost + 1 < goto_cost:
                        cost[goto[0]][goto[1]] = now_cost + 1
                        que.append(goto)

    ans = cost[D[0]][D[1]]
    print(ans if ans < 10**10 else -1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 125252
#include<iostream>
#include<algorithm>
#define MAXN 100003
using namespace std;
int dp[MAXN][3], n, a[MAXN][3];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i][0] >> a[i][1] >> a[i][2];
	}
	dp[0][0] = a[0][0];
	dp[0][1] = a[0][1];
	dp[0][2] = a[0][2];
	    for(int i=1;i<n;i++)                               
	{
		dp[i][0] = a[i][0] + max(dp[i-1][1], dp[i-1][2]);
		dp[i][1] = a[i][1] + max(dp[i-1][0], dp[i-1][2]);
		dp[i][2] = a[i][2] + max(dp[i-1][0], dp[i-1][1]);
	}
	cout << max(dp[n-1][0], max(dp[n-1][1], dp[n-1][2]))<<endl;
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
#if 1
#define gc() getchar_unlocked()
#else
#define gc() getchar()
#endif
 
int in()
{
    int n = 0, c = gc();
    do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
    return n;
}
 
#define INF 0x10101010
#define MAX_V 102
int  hi[MAX_V], *to[MAX_V];
int  q[MAX_V][2]; int top, end;
int  dist[MAX_V];
 
void bfs(int u)
{
    int i, v, d;
 
    q[0][0] = u, q[0][1] = 0, dist[u] = 0, top = 0, end = 1;
    while (top != end) {
        u = q[top][0], d = q[top++][1];
        if (dist[u] < d) continue;
        for (i = 0; i < hi[u]; i++) {
            v = to[u][i];
            if (dist[v] > d+1) {
                dist[v] = d+1, q[end][0] = v, q[end++][1] = d+1;
            }
        }
    }
}
 
int main()
{
    int n, i, j, k, u;
 
    n = in();
    memset(dist, INF, n<<2);
    for (i = 0; i < n; i++) {
        u = in()-1;
        hi[u] = k = in();
        to[u] = malloc(k<<2);
        for (j = 0; j < k; j++) to[u][j] = in()-1;
    }
 
    bfs(0);
    for (i = 0; i < n; i++) {
        if (dist[i] == INF) dist[i] = -1;
        printf("%d %d\n", i+1, dist[i]);
    }
    return 0;
}



Measured memory_bytes: 2092
#include<iostream>
#include<cstring>

using namespace std;

long long dp[1001][10001];
int a[1001];
int b[1001];
int c[1001][1001];
int N,M;
long long T;
const int INF = 1e9;

long long solve(int i, long long j){
    if(dp[i][j] > 0) return dp[i][j];
    
    long long res;
    long long temp=0;
    if(i == M){
        if((j&T) == T){
            res = 0;
        }
        else {
            res = INF;
        }
    }
    else if( (j&T) == T ){
        res = solve(i+1,j);
    }
    else{
        for (int x=0;x<b[i];x++){
              temp |= (1 << (c[i][x]-1));
        }
        res = min(solve(i+1, j ),solve(i+1, j|temp) + a[i]);
    }
    //cout << "temp:" << " bits:" << temp << endl;

    //cout << "i:=" << i<< " j:=" << j << " j&T:=" << (j&T)  << " T=" << T << " res:=" << res << endl;
    
    return dp[i][j] = res;
}
    

int main() {
    long long out;
    cin >> N >> M;
    T = (1<<N)-1;
    //cout <<"T:"<< T << endl;
    for(int i=0; i<M;i++){
        cin >> a[i] >> b[i];
        for (int j=0;j<b[i];j++) cin >> c[i][j];
    }
    
    //memset(dp, -1, sizeof(dp));
    
    out = solve(0,0);
    if (out == INF) out=-1;
    cout << out;
    
    return 0;
}



Measured memory_bytes: 82304
#include <stdio.h>

int main(void)
{
	int a,b,i;
	char str[200000]={};
	scanf("%s",str);



	for(i=0;i<200000;i++)
		if(str[i]=='A'){
			a=i; 
			break;
		}

	for(i=200000-1;i>0;i--)
		if(str[i]=='Z'){
			b=i;
			break;
		}

	printf("%d\n",b-a+1);
	return 0;
}

Measured memory_bytes: 384
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  inputs = input.split("\n");

  var tmp = inputs[0].split(" ");

  var n = parseInt( tmp[0], 10 );
  var m = parseInt( tmp[1], 10 );

  var max_l = 0;
  var min_r = n;

  for ( var i=1; i<=m; i++){
    var tmp = inputs[i].split(" ");
    
    var l = parseInt( tmp[0], 10 );
    var r = parseInt( tmp[1], 10 );

    max_l = l > max_l ? l : max_l;
    min_r = r < min_r ? r : min_r;
  }

  if ( max_l > min_r ){
    console.log('%d', 0);
  } else {
    console.log('%d', min_r - max_l + 1);
  }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 28976
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
   string s;
  cin>>s;
  ll n=s.length();
  ll count=0;
   for(int i=0;i<n/2;i++)
   {
     if(s[i]==s[n-i-1])
       continue;
     else
       count++;
   }
  cout<<count<<endl;
   return 0;
}

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

using namespace std;

#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

signed main () {
  cin.tie(0);
  cout << setprecision(10);

  int n, W; cin >> n >> W;
  vi w(n), v(n);
  int su = 0;
  REP(i, n) {
    cin >> w[i] >> v[i];
    su += v[i];
  }

  vvi dp(n);
  REP(i, n) {
    dp[i].resize(su+1, INT_MAX);
  }

  dp[0][0] = 0;
  dp[0][v[0]] = w[0];

  FOR(i, 1, n) {
    REP(j, su+1) {
      dp[i][j] = dp[i-1][j];
    }
    FOR(j, v[i], su+1) {
      dp[i][j] = min(dp[i][j], dp[i-1][j - v[i]] + w[i]);
    }
  }
        
  RREP(i, su) {
    if(dp[n-1][i] <= W) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 78592
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#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>

using namespace std;

int main() {
    int A,B,C;
    cin>>A>>B>>C;

    int D;
    D=max(A,B);

    int E;

    for(int i=0;C>i*D;i++){

      E++;
    }


    cout<<E<<endl;
}



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

int main() {
  int n;
  cin >> n;
  map<int, int> a;
  for(int i = 0; i < n; i++){
    int now;
    cin >> now;
    a[now]++;
  }
  
  int ans = 0;
  for(auto now : a){
    int dis = now.second - now.first;
    if(dis == 0) continue;
    if(dis < 0) ans += now.second;
    else ans += dis;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 7884
#include <cstdint>
#include <cstdio>

int main() {
  intmax_t x;
  scanf("%jd", &x);

  intmax_t y = 100;
  for (int i = 1; true; ++i) {
    y += y / 100;
    if (y >= x) return !printf("%d\n", i);
  }
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair < ll, ll > PLL;
#define rep(i,n) for (int i = 0; i < (n); ++i)
int main() {
    string s;
    cin >> s;
    map<char, bool> mp;
    rep(i, s.length()) {
        mp[s[i]] = true;
    }
    int ans = 1e8;
    vector<int> len;
    for ( auto tmp_s : mp ) {
        char tmp_char = tmp_s.first;
        int cnt = 0;
        len.clear();
        rep(j, s.length()) {
            if ( tmp_char == s[j] ) {
                len.push_back(cnt);
                cnt = 0;
            }
            else if ( j == s.length() - 1 ) {
                len.push_back(cnt + 1);
            }
            else {
                ++cnt;
            }
        }
        int max_len = 0;
        rep(j, len.size()) {
            max_len = max(max_len, len[j]);
        }
        ans = min(ans, max_len);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int a[3], b[3];
  for(int i = 0; i < 3; i++) cin >> a[i] >> b[i];

  bool graph[4][4];
  for(int i = 0; i < 4; i++){
    fill(graph[i], graph[i] + 4, false);
  }

  for(int i = 0; i < 3; i++){
    graph[a[i] - 1][b[i] - 1] = graph[b[i] - 1][a[i] - 1] = true;
  }

  bool ans = false;
  int p[4] = {0, 1, 2, 3};
  do{
    if(graph[p[0]][p[1]] && graph[p[1]][p[2]] && 
        graph[p[2]][p[3]]){
      ans = true;
      break;
    }
  }while(next_permutation(p, p + 4));

  if(ans) cout << "YES" << endl;
  else cout << "NO" << endl;

  return 0;
}


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

#define ld long double
#define ll long long
#define ull unsigned long long
#define F first
#define S second
#define nl endl
#define pii pair <ll, ll>
#define pb push_back
#define mp make_pair
#define pi 3.14159265358979323846264
#define y1 abacaba
#define fn "abc"
#define sz(a) (int)(a).size()
#define all(a) (a).begin(), (a).end()
#define chill_wave ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pressF freopen("flusha.in", "r", stdin); freopen("flusha.out", "w", stdout);

using namespace std;

const long long MXN = 1e6 + 1;
const long long MAXN = 1e2 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;

inline void JUDGE(bool ok = 0) { chill_wave if(ok) { pressF; } }

//int dx[]= {1,0,-1,0}; int dy[]= {0,1,0,-1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1}; int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int dx[]={2,1,-1,-2,-2,-1,1,2}; int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction
//int dx[]={-1,-1,+0,+1,+1,+0}; int dy[]={-1,+1,+2,+1,-1,-2}; //Hexagonal Direction

ll n, a, b;

int main () {

    JUDGE();

    cin >> n >> a >> b;
    if(b < a) {
        cout << 0;
    } else if(n == 1) {
        if(a == b) {
            cout << 1;
        } else {
            cout << 0;
        }
    } else {
        cout << (b - a) * (n - 2) + 1;
    }
    return 0;
}



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

ll n, ans;

int main() {
  cin >> n;
  vector<ll> a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vector<ll> s(n, 0);
  for (int i = n-2; i >= 0; i--) {
    s[i] = s[i+1] + a[i+1];
    s[i] %= 1000000007;
  }
  ans = 0;
  rep (i, n) {
    ans += (a[i] * s[i]) % 1000000007;
    ans %= 1000000007;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 6324
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,k,p[N],ret;
VI s[N];
int dfs(int u) {
	int r=0;
	for (auto v:s[u]) {
		int c=dfs(v);
		if (c==k-1&&u!=1) ret++,c=0;
		else r=max(r,c+1);
	}
	return r;
}
int main() {
	scanf("%d%d",&n,&k);
	rep(i,1,n+1) scanf("%d",p+i);
	if (p[1]!=1) {
		p[1]=1; ret++;
	}
	rep(i,2,n+1) s[p[i]].pb(i);
	dfs(1);
	printf("%d\n",ret);
}


Measured memory_bytes: 10752
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String args[])throws IOException
   {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer tk;
     tk=new StringTokenizer(br.readLine());
    int n=Integer.parseInt(tk.nextToken());
    int k=Integer.parseInt(tk.nextToken());
    tk=new StringTokenizer(br.readLine());
    int a[]=new int[n];
    for(int i=0;i<n;i++)
    {
      a[i]=Integer.parseInt(tk.nextToken());
     }
    if(n<=2)
    {
      System.out.println(Math.abs(a[1]-a[0]));
      System.exit(0);
    }
    int prev[]=new int[n];
    prev[0]=0;
    prev[1]=Math.abs(a[1]-a[0]);
    int minCost=Integer.MAX_VALUE;
    for(int i=2;i<n;i++)
    {
      minCost=Integer.MAX_VALUE;
      for(int j=Math.max(0,i-k);j<i;j++)
      {
         if(prev[j]+Math.abs(a[i]-a[j])<=minCost)
         {
           minCost=prev[j]+Math.abs(a[i]-a[j]);
         }
         prev[i]=minCost;
        
      }
      
      
    }
    System.out.println(prev[n-1]);
    
    
    
    
  }
  
}
 

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

int main(){
    bool judge;
    int N;
    string S;
    cin >> N;
    cin >> S;

    if(N%2 != 0){
        judge = false;
        //cout << "1" << endl;
    }else{
        string former = S.substr(0, (N/2));
        //cout << former << endl;
        string later = S.substr(N/2, N-1);
        //cout << later << endl;
        if(former == later){
            judge = true;
            //cout << "2" << endl;
        }else{
            judge = false;
            //cout << "3" << endl;
        }
    }
    if(judge){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			String str = sc.nextLine();
			if (str.equals("0")) break;
			int sum = 0;
			for (int i = 0; i < str.length(); ++i) {
				sum += Character.getNumericValue(str.charAt(i));
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 26564
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll x;
    cin >> x;

    ll tmp = x/11;

    x -= 11*tmp;

    if (x == 0) {
        cout << tmp*2 << endl;
    } else if (x <= 6) {
        cout << tmp*2 + 1 << endl;
    } else {
        cout << tmp*2 + 2 << endl;
    }


    return 0;
}

Measured memory_bytes: 3616
#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()
{
    vector<int> x(5);
    int cnt = 0;
    rep(i, 5) {
        cin >> x[i];
        cnt += 1;
        if (x[i] == 0) {
            cout << cnt << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3596
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;*/
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
typedef long long ll;
typedef pair<ll, ll> Pa;

/*
template <std::int_fast64_t Modulus> class modint {
	using u64 = std::int_fast64_t;
public:
	u64 a;
	constexpr modint(const u64 x = 0) noexcept : a(x% Modulus) {}
	constexpr u64& value() noexcept { return a; }
	constexpr const u64& value() const noexcept { return a; }
	constexpr modint operator+(const modint rhs) const noexcept {
		return modint(*this) += rhs;
	}
	constexpr modint operator-(const modint rhs) const noexcept {
		return modint(*this) -= rhs;
	}
	constexpr modint operator*(const modint rhs) const noexcept {
		return modint(*this) *= rhs;
	}
	constexpr modint operator/(const modint rhs) const noexcept {
		return modint(*this) /= rhs;
	}
	constexpr modint& operator+=(const modint rhs) noexcept {
		a += rhs.a;
		if (a >= Modulus) {
			a -= Modulus;
		}
		return *this;
	}
	constexpr modint& operator-=(const modint rhs) noexcept {
		if (a < rhs.a) {
			a += Modulus;
		}
		a -= rhs.a;
		return *this;
	}
	constexpr modint& operator*=(const modint rhs) noexcept {
		a = a * rhs.a % Modulus;
		return *this;
	}
	constexpr modint& operator/=(modint rhs) noexcept {
		u64 exp = Modulus - 2;
		while (exp) {
			if (exp % 2) {
				*this *= rhs;
			}
			rhs *= rhs;
			exp /= 2;
		}
		return *this;
	}
};
#pragma endregion

typedef modint<MOD> m;
m func[400001];
void funcinit(int N)
{
	func[0] = 1;
	for (int i = 1; i <= N; i++)
	{
		func[i] = func[i - 1] * i;
	}
}
m comb(m n, m r)
{
	if (n.a <= 0 || n.a < r.a)
	{
		return 0;
	}
	return func[n.a] / (func[r.a] * func[(n - r).a]);
}*/

ll dp[101][100001];
ll w[100], v[100];
int main() {
	cin >> N >> W;
	rep(i, N) {
		cin >> w[i] >> v[i];
	}
	rep(i, 101) {
		rep(j, 100001) {
			dp[i][j] = W + 1;
		}
	}
	rep(i, 101) {
		dp[i][0] = 0;
	}
	ll mv = 0;
	rep(i, N) {
		rep(j, 100001) {
			dp[i + 1][j] = dp[i][j];
		}
		rep(j, 100001) {
			if (w[i] + dp[i][j] <= W) dp[i + 1][v[i] + j] = min(dp[i + 1][v[i] + j], dp[i][j] + w[i]);
		}
	}
	rep(i, N) {
		ll inst_mv = 0;
		rep(j, 100001) {
			if (dp[i + 1][j] != W+1) inst_mv = j;
		}
		mv = max(mv, inst_mv);
	}
	cout << mv;
}


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 2e3 + 5;

int n, m;
char c[N][N];
int a[N][N], l[N][N], u[N][N], r[N][N], d[N][N];


int32_t main()
{
	IOS;
	cin >> n >> m;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
		{
			cin >> c[i][j];
			if(c[i][j] == '.')
				a[i][j] = 1;
		}
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(!a[i][j])
				l[i][j] = 0;
			else
				l[i][j] = 1 + l[i][j - 1];
		}
	}
	for(int i = 1; i <= n; i++)
	{
		for(int j = m; j >= 1; j--)
		{
			if(!a[i][j])
				r[i][j] = 0;
			else
				r[i][j] = 1 + r[i][j + 1];
		}
	}
	for(int j = 1; j <= m; j++)
	{
		for(int i = 1; i <= n; i++)
		{
			if(!a[i][j])
				u[i][j] = 0;
			else
				u[i][j] = 1 + u[i - 1][j];
		}
	}
	for(int j = 1; j <= m; j++)
	{
		for(int i = n; i >= 1; i--)
		{
			if(!a[i][j])
				d[i][j] = 0;
			else
				d[i][j] = 1 + d[i + 1][j];
		}
	}
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		for(int j = 1; j <= m; j++)
		{
			if(a[i][j])
			{
				ans = max(ans, l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3);
			}
		}
	}
	cout << ans;
	return 0;
}


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

int main() {
    int n;
    int ac,wa,tle,re;
    ac=wa=tle=re=0;
    cin >> n;
    string s[100000];
    for(int i=0;i<n;i++){
        cin >> s[i];
        if(s[i] == "AC"){
            ac++;
        }else if(s[i]=="WA"){
            wa++;
        }else if(s[i]=="TLE"){
            tle++;
        }else if(s[i]=="RE"){
            re++;
        }  
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ii = pair<int,int>;
using ll = long long;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int n;
  cin >> n;
  string s = to_string(n);
  char c = s[s.size()-1];
  if (c == '2' || c == '4' || c == '5' || c == '7' || c == '9') {
    cout << "hon" << '\n';
  } else if (c == '0' || c == '1' || c == '6' || c == '8') {
    cout << "pon" << '\n';
  } else {
    cout << "bon" << '\n';
  }
  return 0;
}


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

int dp[110][101010];
// dp[i][w]は、i(0-index)番目までの品物で、重さがwになる時の価値の最大値を示す

void chmax(int &a, int b){ if( a < b){ swap(a,b);} return;}

int main(){
  
  for(int i = 0; i < 110; i++){
    for(int j = 0; j < 101010; j++){ dp[i][j] = 0;}}
  
  int N,W; cin >> N >> W;
   
  vector<int> v(N); vector<int> w(N);
  
  for(int i = 0; i < N; i++){ 
    cin >> v[i] >> w[i];}
  
  for(int i = 0; i < N; i++){ 
    if( w[i] <= W){ dp[i][w[i]] = v[i];}}
  // 少なくともi番目自身のみを選んだ時の価値v[i]以上(w[i]がW以下ならば）
  
  for(int i = 0; i < N-1; i++){
    for(int b = 0; b <= W; b++){
        chmax(dp[i+1][b], dp[i][b]); // i+1番目を選ばないとき
      if( b+w[i+1] <= W){ 
        chmax(dp[i+1][b+w[i+1]], dp[i][b]+v[i+1]);
      }
    }
  }
  
  int res = 0;
  
  for(int b = 0; b <= W; b++){
    chmax(res, dp[N-1][b]);}
  
  cout << res << endl; return 0;}
                       
            
                       
                   
  
  
  
  
 


Measured memory_bytes: 46512
<?php
while ($line = fgets(STDIN)) {
  list($a, $op, $b) = explode(' ', $line);
  if ($op == '?') break;

  switch ($op) {
    case '+': $c = $a + $b; break;
    case '-': $c = $a - $b; break;
    case '*': $c = $a * $b; break;
    case '/': $c = (int)($a / $b); break;
  }
  echo $c . "\n";
}

Measured memory_bytes: 15336
#include<bits/stdc++.h>
#include<fstream>
#define vi vector<int>
#define vii vector<vi>
#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define per(i, a, b) for (long long i = (a); i > (b); i--)
#define pb push_back
#define sz(v) (int)v.size()
#define CIN                       \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
using namespace std;
int main(){
	CIN;
	ll n,a,b;
	cin >> n  >>  a >> b;
	cout << min(n*a,b);
}

Measured memory_bytes: 256
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

use std::cmp;
use std::collections::{HashSet, BinaryHeap};
use std::io::{Write, BufWriter, stdout};
fn main() {
    input! {
        Q: usize,
        query: [(usize, usize); Q],
    }

    let like2017_countsum = eratosthenes_variant(100_000);
    let stdout = stdout();
    let mut out = BufWriter::with_capacity(9*Q, stdout.lock());
    for &(l, r) in query.iter() {
        let ans: usize = like2017_countsum[r] - like2017_countsum[l-1];
        writeln!(out, "{}", ans).unwrap();
    }
}

fn eratosthenes_variant(max: usize) -> Vec<usize> {
    let search_bound = (max as f64).sqrt().ceil() as usize;
    let mut like2017_countsum = vec![0; max+1];
    let mut is_primes = vec![true; max+1];
    is_primes[0] = false;
    is_primes[1] = false;

    let mut count = 0;
    for candidate in 2..max+1 {
        if is_primes[candidate] {
            let prime = candidate;
            if prime <= search_bound {
                let mut no_prime = prime*prime;
                while no_prime <= max {
                    is_primes[no_prime] = false;
                    no_prime += prime;
                }
            }
            if is_primes[(prime+1)/2] { count += 1; }
        }
        like2017_countsum[candidate] = count;
    }

    like2017_countsum
}


Measured memory_bytes: 8828
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

ll root(ll pa, ll node, ll cost, vvi &c, vi &minmp){
    if(node == 1){
        chmin(minmp[pa], cost);
        return cost;
    }
    ll mincost = INFLL;
    for(ll i=0; i<10; i++){
        // 自分自身なら飛ばす
        if(i == node) continue;
        // 現在の最小値より小さい変更先があるなら試してみる
        if(cost + c[node][i] < minmp[pa]){
            chmin(mincost, root(pa, i, cost+c[node][i], c, minmp));
        }
    }
    return mincost;
}

int main(){
    Init();
    ll h, w; cin >> h >> w;
    vvi c(10, vi(10, 0));
    vi minmp(10);

    // i -> jへの移動に必要な魔力を入力
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
            // 0~9から直接1に変更するのに必要な魔力を入れておく
            if(j==1) minmp[i] = c[i][j];
        }
    }

    // 0~9の各数値を1に変更するのに必要な最小値を求める
    for(ll i=0; i<10; i++){
        // 1は自明（mp=0）なので飛ばす
        if(i == 1) continue;
        root(i, i, 0, c, minmp);
    }

    // h*wで1と-1を除く数字を1にする魔力の総和を求める
    ll total = 0;
    rep(i, h){
        rep(j, w){
            ll tmp; cin >> tmp;
            if(tmp != 1 && tmp != (-1)) total += minmp[tmp];
        }
    }
    cout << total << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(usize, usize);

    let mut graph = vec![vec![1 << 60; n + 1]; n + 1];
    for i in 0..n + 1 {
        graph[i][i] = 0;
    }

    let mut edges = vec![];
    for _ in 0..m {
        let (a, b, c) = scan!(usize, usize, usize);
        graph[a][b] = c;
        graph[b][a] = c;
        edges.push((a, b, c));
    }

    for k in 1..n + 1 {
        for i in 1..n + 1 {
            for j in 1..n + 1 {
                if graph[i][k] + graph[k][j] < graph[i][j] {
                    graph[i][j] = graph[i][k] + graph[k][j];
                }
            }
        }
    }

    let mut ans = 0;
    for edge in edges {
        let (a, b, c) = edge;
        let mut shortest = false;
        for s in 1..n + 1 {
            for t in 1..n + 1 {
                if graph[s][t] == graph[s][a] + c + graph[b][t] {
                    shortest = true;
                }
            }
        }
        if shortest {
            ans += 1;
        }
    }
    println!("{}", m - ans)
}


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

#define nl '\n'

using namespace std;

typedef long long ll;

void solve() {
  int N;
  cin >> N;

  cout << (1000 - N%1000) % 1000;
}

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

  // int t;
  // cin >> t;
  // while (t--) {
  solve();
  cout << nl;
  // }

  return 0;
}

Measured memory_bytes: 3504
#include <iostream>
#include <math.h>
using namespace std;
int main(){
	while (1){
		int n;
		int sum = 0;
		cin >> n;
		if (n == 0) break;
		int s;
		int max = -1;
		int min = 9999;
		for (int i = 0; i < n; i++){
			cin >> s;
			sum += s;
			if (s >= max) max = s;
			if (s <= min) min = s;
		}
		int ans = floor((sum - max - min) / (n - 2));
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
//#include <function>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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


int main() {

  int N;
  cin >> N;
  string ss;
  vector<int> vec(N);

  cin >> ss;
  int ww = 0;
  REP(i, N) {
    if (i == 0) {
      if (ss[i] == '.') vec[i] = 1;
      else vec[i] = 0;
    }else {
      if (ss[i] == '.') vec[i] = vec[i - 1] + 1;
      else vec[i] = vec[i - 1];
    }
    if (ss[i] == '.') ww++;
  }
  int min_tmp = ww;
  int tmp;
  REP(i, N){
    if (ss[i] == '.'){
      tmp = i - (vec[i] - 1) + (vec[N - 1] - vec[i]);
      min_tmp = min(min_tmp, tmp);
    }
  }


  //REP(i, N) cout << vec[i];

  cout << min_tmp << endl;
  return 0;
}


Measured memory_bytes: 1412
#include <iostream>
#include <math.h>
#include <algorithm>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::sort;

int main()
{
  string w;

  cin >> w;

  if(w.length() == 1) {
    cout << "No" << endl;
    return 0;
  }

  sort(w.begin(), w.end());

  char prev = w[0];

  for(int i = 1; i < w.length(); i++) {
    // odd
    if(i % 2 != 0 && prev != w[i]) {
      cout << "No" << endl;
      return 0;
    } else {
      prev = w[i];
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

#define DEBUG(x) cout << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<pair<T, T> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;

	int a;
	int odds = 0, evens = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a;
		if (a & 1) {
			++odds;
		} else {
			++evens;
		}
	}

	int left_odd = 0, left_even = 0;
	if (odds & 1) {
		++evens;
		left_odd = 1;
	} else {
		left_odd = 0;
		++evens;
	}

	if (evens > 0) {
		left_even = 1;
	}

	if (left_odd + left_even == 1) {
		cout << "YES\n";
	} else {
		cout << "NO\n";
	}

	return 0;

}

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



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

    //同じ種類の数をmapに保存する。
    map<int64_t,int64_t> ball_map;
    vector<int> ball(n);
    for(int i=0;i<n;i++){
        int wk;
        cin>>wk;
        ball.at(i)=wk;
        if(ball_map.count(wk))
            ball_map.at(wk)++;
        else
            ball_map[wk]=1;
    }

    //mapの2以上の要素についてnC2=n*(n-1)/2を計算してその和をとる。
    int64_t sum=0;
    for (auto p : ball_map) {
        auto key = p.first;
        auto value = p.second;
        if(value>=2)
            sum+=value*(value-1)/2;
    }

    //k番目の要素をmapで探して、sumからnC2を引く。n-1C2を計算してsumに足す。
    for(int i=0;i<n;i++){
        int64_t wk,wk2;
        wk=ball.at(i);
        wk2=ball_map.at(wk);
        if(wk2>=2)
            cout<<sum-wk2*(wk2-1)/2+(wk2-1)*(wk2-2)/2<<endl;
        else
            cout<<sum<<endl;
    }

    return 0;
}

Measured memory_bytes: 11008
#include <bits/stdc++.h>
 
using namespace std;
 
const long long MOD=1e9+7;
const double PI=3.14159265359;



int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    long long ans=0;
    for(int i=0; i<n; i++){
        int l,r;
        cin>>l>>r;
        ans+=(r-l+1);
    }
    cout<<ans;
    
   
   
    
    return 0;
    
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    string s, t;
    cin >> s >> t;
    cout << t << s << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define PI  3.14159265358979323846
#define M   1000000007
ll fast(ll n,ll a,ll m)
{
    if(n==0)
        return 1;
    else if(n==1)
        return a;
    else
    {
        ll r=fast(n/2,a,m);
        if(n%2==0)
        {
            return (((r%m)*(r%m))%m);
        }
        else
        {
            return (((((r%m)*a)%m)*r)%m);
        }
    }
}
int tree[26][1000010];
void build(int n,string s)
{
    int i,j;
    for(i=0;i<n;i++)
    {
        tree[s[i]-'a'][n+i]=1;
    }
    for(j=0;j<26;j++)
    {
        for(i=n-1;i>0;i--)
        {
          tree[j][i]=tree[j][i<<1]+tree[j][i<<1|1];
        }
    }

}
void upd(int pos,char val,int n,string s)
{
    char t=s[pos];
    pos+=n;
    tree[t-'a'][pos]--;
    tree[val-'a'][pos]++;
    for(int p=pos;p>1;p>>=1)
    {
        tree[t-'a'][p>>1]=tree[t-'a'][p]+tree[t-'a'][p^1];
    }
    for(int p=pos;p>1;p>>=1)
    {
        tree[val-'a'][p>>1]=tree[val-'a'][p]+tree[val-'a'][p^1];
    }
}
int Query(int l,int r,int n)
{
    int res=0;
    int u=l,v=r,j;
    for(j=0;j<26;j++)
    {
        int cnt=0;
        for(u+=n,v+=n;u<v;u>>=1,v>>=1)
        {
            if(u&1)
                cnt+=tree[j][u++];
            if(v&1)
                cnt+=tree[j][--v];
        }
        if(cnt!=0)
            res++;

        u=l;
        v=r;
    }
    return res;
}
int main()
{
    memset(tree,0,sizeof(tree));
    int n,i;
    cin>>n;
    string S;
    cin>>S;
    build(n,S);
    int Q;
    cin>>Q;
    int a,b,c;
    char l;
    while(Q--)
    {
        cin>>a;
        if(a==1)
        {
            cin>>b>>l;
            b--;
            upd(b,l,n,S);
            S[b]=l;
        }
        else
        {
            cin>>b>>c;
            b--;
            cout<<Query(b,c,n)<<"\n";
        }
    }

}


Measured memory_bytes: 102916
import sys
from collections import Counter

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):

    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    A = il()
    A_p, A_n = [0] * N, [0] * N
    for i in range(N):
        A_p[i] = A[i] + 1
        A_n[i] = A[i] - 1
    c = Counter(A + A_p + A_n)
    m = max(c.values())
    return m


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 30016
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())
    s = input()
    x = 1

    sn = [ord(c) - 96 + x for c in s]

    lmax = n // 2
    m1 = 10 ** 9 + 7
    m2 = 2 ** 61 - 1

    ans = 0

    ng = n + 1
    ok = 0

    while abs(ng - ok) > 1:
        l = (ng + ok) // 2
        found = False

        appeared = set()
        diff = pow(m1, l - 1, m2)

        h_init = 0

        for i in range(l):
            h_init += sn[i] * pow(m1, l - 1 - i, m2)
            h_init %= m2

        hashlist = [0] * n
        hashlist[l - 1] = h_init
        h = h_init

        for i in range(l, n):
            h -= sn[i - l] * diff
            h *= m1
            h += sn[i]
            h %= m2
            hashlist[i] = h
            if i - l >= 0:
                appeared.add(hashlist[i - l])
            if h in appeared:
                found = True
                break

        if found:
            ok = l
        else:
            ng = l

    print(ok)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define rfore(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);--i)
#define rrep(i,n) rfore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
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 cnt[505][505];
void solve(){
    ll n,m,q;cin>>n>>m>>q;
    rep(i,m){
        ll l,r;cin>>l>>r;
        cnt[l][r]++;
    }
    rep(i,n)rep(j,n){
        cnt[i+1][j+1]+=cnt[i+1][j];
    }
    rep(i,n)rep(j,n){
        cnt[i+1][j+1]+=cnt[i][j+1];
    }
    rep(i,q){
        ll p,qq;cin>>p>>qq;
        ll ans=cnt[qq][qq]-cnt[qq][p-1]-cnt[p-1][qq]+cnt[p-1][p-1];
        cout<<ans<<endl;
    }
}

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


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

#define vint vector<int>
#define vvint vector<vint>
#define sint stack<int>
#define qint queue<int>
#define rep(i, n) for(int i=0;i<(int)(n);i++) // 繰り返し処理
#define all(x) (x).begin(),(x).end() // 全体 こんな感じで使う→sort(all(a));
#define ct(a) cout << a << endl
#define iceil(a,b) (a+(b-1))/b //int ceil : 繰り上げの割り算 通常のceilではceil((7.0/2.0))のようにしなければならなかった。
#define ld long double
#define ll long long
vint CinLine(int N){vint v(N);for(int i=0;i<N;i++){cin >> v.at(i);}return v;}//cin line 連続でvectorに格納
void CoutLine(vint v){for(int i=0;i<v.size()-1;i++){cout<<v.at(i)<<" ";}cout << v.at(v.size()-1)<<endl;}

bool IsOver(ll ans, ll a, ll lim){
    if(a > lim/ans){
        return true;
    }else{
        return false;
    }
}
void Main(){
    ll limit = pow(10,18);
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0; i<n;i++){
        cin >> a[i];
        if(a[i] == 0){
            ct(0);
            return;
        }
    }
    ll ans = 1;
    for(ll i = 0; i < n; i++){
        if(IsOver(ans,a[i], limit)){
            ct(-1);
            return;
        }else {
            ans *= a[i];
        }
    }
    if ( ans > limit ){
        ct(-1);
    }else{
        ct(ans);
    }
    return;
}

int main() {
    Main();
}

/*
 *  int a,b;
    cin >> a >> b;
    ct(a*b);
int main() {
    ll maxv = pow(10,18);
    int n;
    cin >> n;
    ll ans;
    bool over = false;
    bool zero = false;
    cin >> ans;
    if(ans == 0){
        zero = true;
    }
    rep(i,n-1){
        ll a;
        cin >> a;
        if(a == 0){
            zero = true;
            break;
        }else if(!over) {
            ll c = ans * a;
            ll d = c / ans;
            if (a != d) {
                over = true;
            }

            ans *= a;
            if (ans > maxv) {
                over = true;
            }
        }
    }
    if(zero) {
        ct(0);
    }else if(over){
        ct(-1);
    }else{
        ct(ans);
    }
}

 * */

Measured memory_bytes: 4052