akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;

// 各桁の和を計算する関数
int SumDigi(int x) {
  int sum = 0;
  while (x > 0) { // n が 0 になるまで
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

int main() {
  int n,a,b;
  cin >> n >> a >> b;
  int ans = 0;
  rep(i, n+1){
    int sumD = SumDigi(i);
    if (sumD >= a && sumD <= b){
      ans += i;
    }
  } 
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    N, M = i2nn()
    A = i2nn()
    BC = ii2nnn(M)
    # 元のカード列Aを単調増加にする
    A.sort()
    # 書き換え後の値C[1:M]を単調減少にする
    BC.sort(key=lambda v: v[1])
    BC.reverse()
    # 貪欲法的に書き換える
    i = 0
    j = 0
    k = 0
    while i < N and j < M:
        b, c = BC[j]
        while i < N and k < b:
            A[i] = max(A[i], c)
            i += 1
            k += 1
        j += 1
        k = 0
    n = sum(A)
    print(n)

main()


Measured memory_bytes: 88148
N = int(raw_input())

def dfs(depth, l, r):
    if depth == 10:
        return True

    if l < A[depth] and dfs(depth+1, A[depth], r):
        return True
    if r < A[depth] and dfs(depth+1, l, A[depth]):
        return True

    return False

for c in range(N):
    A = map(int, raw_input().split(" "))
    if dfs(0, 0, 0):
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4220
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 pair<int,int> P;

int main(){
  int a,b,t;
  cin >> a >> b >> t;
  cout << t/a*b << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int W,a,b; cin >> W >> a >> b;
  if(a+W<b) cout << b-(a+W) << endl;
  else if(b+W<a) cout << a-(b+W) << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 3624
package main

import (
	"fmt"
)

func main() {
	var N int
	var S string
	fmt.Scan(&N)
	fmt.Scan(&S)

	cnt := 0
	for i := 0; i < 1000; i++ {
		t := fmt.Sprintf("%03d", i)
		j := 0
		for _, st := range S {
			if string(st) == string(t[j]) {
				j++
				if j == 3 {
					cnt++
					break
				}
			}
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 896
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

		final int n = sc.nextInt();
		
		int[][][] people = new int[4][3][10];
		
		for(int i = 0; i < n; i++){
			final int b = sc.nextInt() - 1;
			final int f = sc.nextInt() - 1;
			final int r = sc.nextInt() - 1;
			final int v = sc.nextInt();	
			
			people[b][f][r] += v;
		}
		
		for(int i = 0; i < 4; i++){
			for(int j = 0; j < 3; j++){
				for(int k = 0; k < 10; k++){
					System.out.print(" " + people[i][j][k]);
				}
				System.out.println();
			}
			
			if(i != 3){
				System.out.println("####################");
			}
		}
		
	}

}

Measured memory_bytes: 21068
#include <iostream>
#include <queue>
#include <vector>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
	int n;
	cin >> n;
	for( int t = 0; t < n; t++ ){
		//priority_queue<int, vector<int> > max;
		//priority_queue<int, vector<int>, greater<int> > min;
		string num;
		cin >> num;
		sort(num.begin(), num.end());
		int max = 0, min = 0;
		for( int i = 0; i < num.size(); i++ ){
			min += (int)(num[i]-'0') * pow(10.0, (double)(num.size()-i-1));
		}
		sort(num.begin(), num.end(), greater<int>());
		for( int i = 0; i < num.size(); i++ ){
			max += (int)(num[i]-'0') * pow(10.0, (double)(num.size()-i-1));
		}
		cout << max-min << endl;
	}
}

Measured memory_bytes: 1268
#include<iostream>
#include<cstdio>
using namespace std;

inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}

inline void write(int x){
	if(x<0)x=-x,putchar('-');
	if(x>9)write(x/10);putchar(x%10+'0');
}

inline void writeln(int x){
	write(x);puts("");
}

int n,m,l,r,vi,fa[100005],v[200005];

inline int get(int x){
	if(x==fa[x])return x;
	int f=get(fa[x]);
	v[x]+=v[fa[x]];
	return fa[x]=f;
}

int main(){
	n=read();m=read();
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=m;i++){
		l=read();r=read();vi=read();
		int li=get(l),ri=get(r);
		if(li!=ri){
			v[ri]=vi-v[r]+v[l];
			fa[ri]=li;
		}else{
			if(v[r]-v[l]!=vi){
				cout<<"No\n";
				return 0;
			}
		}
	}
	cout<<"Yes\n";
	return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define EPS 1e-9
#define INF 1070000000LL
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(__typeof((X).begin()) it=(X).begin();it!=(X).end();it++)
#define ite iterator
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define pb push_back
#define sec second
#define sz(x) ((int)x.size())

using namespace std;

typedef istringstream iss;
typedef long long ll;
typedef pair<int,int> pi;
typedef stringstream sst;
typedef vector<int> vi;

int N,M;
int row[5010],dia[5010];
vector<int> v;

#define tri(y,x,t) ((y)<<15|(x)<<2|(t))

int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cin>>N>>M;
	int A,B,X;
	rep(i,M){
		cin>>A>>B>>X;
		X++;
		v.pb(tri(A,B,0));
		v.pb(tri(A+X,B,1));
		v.pb(tri(A  ,B+1,3));
		v.pb(tri(A+X,B+X+1,2));
	}
	v.pb(INF);
	sort(v.begin(),v.end());
	int ans=0,sum,cur=0;
	rep2(y,1,N+2){
		sum=0;
		rep2(x,1,y+2){
			while((v[cur]>>2)==(y<<13|x)){
				switch(v[cur]&3){
					case 0: row[x]++;break;
					case 1: row[x]--;break;
					case 2: dia[y-x+1]++;break;
					case 3: dia[y-x+1]--;break;
				}
				cur++;
			}
			sum+=row[x]+dia[y-x+1];
			ans+=sum>0;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 11244
/*input
2
1 2
3
1 100
2 100
100 1000
*/

#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() {
  int n;
  cin >> n;
  vector<int> cnt(1e5+5);
  ll ans = 0;
  rep(i, n) {
    int a;
    cin >> a;
    cnt[a]++;
    ans += a;
  }

  int q;
  cin >> q;
  rep(i, q) {
    int b, c;
    cin >> b >> c;
    ans += (ll)cnt[b]*(c-b);
    cout << ans << endl;
    cnt[c] += cnt[b];
    cnt[b] = 0;
  }
}

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

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

int main() {
    int n;
    cin >> n;
    int x1=0;
    int y1=0;
    int t1=0;
    int x2=0;
    int y2=0;
    int t2=0;
    rep(i,n){
        cin >> t2 >> x2 >> y2;
        int td = t2-t1;
        int xd = abs(x2-x1);
        int yd = abs(y2-y1);
        if(td%2 == (xd+yd)%2 && td >= xd+yd){
            x2 = x1;
            y2 = y1;
            t2 = t1;
        }else{
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
int main(void){
    string ymd,buf;
    cin>>ymd;
    auto v = std::vector<std::string>();
    stringstream ss{ymd};
    while (getline(ss, buf, '/')) {
      v.push_back(buf);
    }
    auto vv = vector<int>();
    for (int i = 0;i<3;i++){
        vv.push_back(stoi(v[i]));
    }
    if (vv[0]<2019){
        cout<<"Heisei"<<endl;
    }
    else if (vv[0]==2019 and vv[1]<=4){
        cout<<"Heisei"<<endl;
    }
    else{
        cout<<"TBD";
    }
}


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

int n;
int a[100];

void printArray(){
    for(int i = 0; i < n; i++){
        cout << a[i];
        if(i != n-1) cout << " ";
    }
    cout << endl;
}

void insertionSort(){
    int v,j;
    printArray();
    for(int i = 1; i < n; i++){
        v = a[i];
        j = i - 1;
        while(j >= 0 && a[j] > v){
            a[j+1] = a[j];
            j--;
        }
        a[j+1] = v;
        printArray();
    }
}

void bubbleSort(){
    int cnt = 0;
    int flag = 1;
    while(flag){
        flag = 0;
        for(int j = n-1; j > 0; j--){
            if(a[j] < a[j-1]){
                swap(a[j],a[j-1]);
                flag = 1;
                cnt++;
            }
        }
    }
    printArray();
    cout << cnt << endl;
}

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

    //insertionSort();
    bubbleSort();

    return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#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 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;

int main(){
    Init();
    string s; cin >> s;
    ll sum = 0;
    rep(i, s.size()) sum += s[i]-'0';
    (sum%9 == 0) ? Yes() : No();
}

Measured memory_bytes: 3732
import scala.io.Source

object Main extends App {
  val primes = sieve(Stream.from(2))

  def sieve(st: Stream[Int]): Stream[Int] = {
    val x = st.head
    x #:: sieve(st.tail.filter(_ % x != 0))
  }

  val lines: Iterator[String] = Source.stdin.getLines()
  val n = lines.next.toInt
  println(primes.filter(_ % 5 == 1).take(n).mkString(" "))
}


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

int main() {
  int N, M, a = 1, simeva = 0, eva = 0;
  
  cin >> N;
  
  vector<string> blue(N);
  vector<int> bluecou(N);
  
  for (int i = 0; i < N; i++) {
    cin >> blue.at(i);
  }
  
  cin >> M;
  
  vector<string> red(M);
  vector<int> redcou(M);
  
  for (int i = 0; i < M; i++) {
    cin >> red.at(i);
  }
  
  
  for (int i = 0; i < N; i++) {
    
    for (int j = 0; j < N; j++) {
      if (blue.at(i) == blue.at(j)) bluecou.at(i)++;
    }
    
  }
  
  for (int i = 0; i < M; i++) {
    
    for (int j = 0; j < M; j++) {
      if (red.at(i) == red.at(j)) redcou.at(i)++;
    }
  }
  
  
  for (int i = 0; i < N; i++) {
    
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j)) {
        simeva = bluecou.at(i) - redcou.at(j);
        break;
      }
      else simeva = bluecou.at(i);
    }
    
    if (eva < simeva) eva = simeva;
    simeva = 0;
    
  }
  cout << eva << endl;
}


Measured memory_bytes: 256
S = input()
len_s = len(S)
_1 = S[:(len_s-1)//2]
_2 = S[(len_s+2)//2:]

S_rev = ''.join(list(reversed(S)))
_1_rev = ''.join(list(reversed(_1)))
_2_rev = ''.join(list(reversed(_2)))


if S == S_rev:
  if _1_rev == _1:
    if _2_rev == _2:
      print('Yes')
      exit()

print('No')

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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  if (a==b && b==c && a==c){
    cout << 1 << endl;
  }
  else if (a!=b && b!=c && a!=c){
    cout << 3 << endl;
  }
  else {
    cout << 2 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int a[11][11];

int main()
{
	int n,d;
	int i,j,k;
	scanf("%d%d",&n,&d);
	for (i=1;i<=n;i++)
	for (j=1;j<=d;j++)
	scanf("%d",&a[i][j]);
	int res=0;
	for (i=1;i<=n;i++)
	for (j=i+1;j<=n;j++) {
		int s=0;
		for (k=1;k<=d;k++)
		s+=(a[i][k]-a[j][k])*(a[i][k]-a[j][k]);
		int r=(int)sqrt((double)s);
		if (r*r==s) res++; 
	}
	printf("%d",res);
	return 0;
}

Measured memory_bytes: 128
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


def extgcd(a, b):
    if b:
        d, y, x = extgcd(b, a % b)
        y -= (a // b) * x
        return d, x, y
    return a, 1, 0


# V = [(X_i, Y_i), ...]: X_i (mod Y_i)
def remainder(V):
    x = 0; d = 1
    for X, Y in V:
        g, a, b = extgcd(d, Y)
        x, d = (Y*b*x + d*a*X) // g, d*(Y // g)
        x %= d
    return x, d


N = I()


def prime_factorization(n):
    ANS = {}
    for i in range(2,int(n**.5)+1):
        if n % i == 0:
            r = 0  # nがiで何回割り切れるか
            while n % i == 0:
                n //= i
                r += 1
            ANS[i] = r
    if n != 1:
        ANS[n] = 1
    return ANS


prime = prime_factorization(N)
if not 2 in list(prime.keys()):
    prime[2] = 1
else:
    prime[2] += 1

A = list(prime.keys())
B = list(prime.values())
l = len(A)


ans = 2*N
from itertools import product

for a in list(product([-1,0],repeat=l)):
    for i in range(l):
        if a[i] != 0:
            break
    else:
        continue

    V = [(a[i],A[i]**B[i]) for i in range(l)]
    x,d = remainder(V)
    ans = min(ans,x)

print(ans)


Measured memory_bytes: 72800
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(n: int, S: "List[str]"):
    ret = ''
    counts = [[0] * n for _ in range(26)]
    for i, s in enumerate(S):
        for c in s:
            counts[ord(c) - ord('a')][i] += 1
    #print(counts)
    for i, cnt in enumerate(counts):
        ret += ''.join([chr(ord('a') + i) for _ in range(min(cnt))])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    n = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(n) ]  # type: "List[str]"
    solve(n, S)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
n = int(input())
m = int(input())
target = list(map(int, input().split()))
score = [0] * n

for t in target:
    vote = list(map(int, input().split()))
    cnt = 0
    for i, v in enumerate(vote):
        if t == v:
            score[i] += 1
        else:
            cnt += 1
    score[t-1] += cnt

for s in score:
    print(s)



Measured memory_bytes: 5620
N = int(input())

# [出席番号, 登校順]のリスト
A = [[i, int(a)] for (i, a) in zip(range(1, N+1), input().split())]

# 登校順でソート
A.sort(key = lambda x:x[1])

print(' '.join(map(str, [row[0] for row in A])))

Measured memory_bytes: 77100
using System;
using System.Linq;
using static System.Console;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var d = ReadIntArray();
        Array.Sort(d);
        WriteLine(d[2]*10+d[1]+d[0]);
    }
}



Measured memory_bytes: 13396
s = input()
t = input()

my_d = dict()

for i, ch in enumerate(s):
    if ch not in my_d:
        if t[i] in my_d.values():
            print('No')
            exit()
        else:
            my_d[ch] = t[i]
    else:
        if my_d[ch] != t[i]:
            print('No')
            exit()

print('Yes')


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> ac(n);
    vector<int> sum(n + 1, 0);
    rep(i, n) {
        if(i != n) {
            if(s[i] == 'A' && s[i + 1] == 'C') {
                ac[i]++;
                i++;
            }
        }
    }
    rep(i, n) {
        sum[i + 1] += sum[i] + ac[i];
    }
    /*cout << endl;
    rep(i, n) cout << ac[i] << ' ';
    cout << endl;
    rep(i, n + 1) cout << sum[i] << ' ';
    cout << endl;
    //確認済*/
    vector<vector<int>> l(q, vector<int>(2));
    rep(i, q) {
        rep(j, 2) cin >> l[i][j];
    }
    rep(i, q) {
        cout << sum[l[i][1] - 1] - sum[l[i][0] - 1] << endl;
    }

}

Measured memory_bytes: 9564
#include<iostream>
#include<iomanip>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;
 
int main(){
    double n, x, y;cin >> n;
    vector<double> xi;
    vector<double> yi;
    double D = 0.0;
    for(int i = 0; i < n; i++){
        cin >> x;
        xi.push_back(x);
    }
    for(int i = 0; i < n; i++){
        cin >> y;
        yi.push_back(y);
    }
    //p=1
    for(int i = 0; i < n; i++){
    D = abs(xi[i] - yi[i]) + D;
    }
    cout << fixed << D << endl;
    //p=2
    D=0.0;
    for(int i = 0; i < n; i++){
    D = pow(abs(xi[i] - yi[i]), 2.0) + D;
    }
    cout << fixed << sqrt(D) << endl;
    //p=3
    D = 0.0;
    for(int i = 0; i < n; i++){
    D = pow(abs(xi[i] - yi[i]), 3.0) + D;
    }
    cout << fixed << pow(D, 1.0 / 3.0) << endl;
    //p=mugen
    D = 0.0;
    for(int i = 0; i < n; i++){
        D = max(D, abs(xi[i] - yi[i]));
    }
    cout << fixed << D << endl;
    return 0;
}
        
        

Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int dp[101][100001];
int a[200];

int main(){
	int n,K;scanf("%d%d",&n,&K);
	rep(i,n)scanf("%d",&a[i]);
	dp[0][0]=1;
	rep(i,n){
		int sum=0;
		for(int j=0;j<=K;j++){
			(sum+=dp[i][j])%=MOD;
			dp[i+1][j]=sum;
			if(j>=a[i]){
				sum=(sum+MOD-dp[i][j-a[i]])%MOD;
			}
		}
	}
	cout<<dp[n][K]<<endl;
}

Measured memory_bytes: 39296
#include<stdio.h>
#define N 101
int main(){
  int M[N][N];
  int n,u,k,v,i,j;
  scanf("%d",&n);
  for(i =0;i<=n;i++){
    for(j =0;j<=n;j++) M[i][j] = 0;
  }
  for(i = 0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j =0;j<k;j++){
      scanf("%d",&v);
      M[u][v] = 1;
    }
  }
  for(i =1;i<=n;i++){
    for(j = 1;j<=n;j++){
      if(j == n){
        if(M[i][j] != 0){
          printf("1");
        }else printf("0");
        break;
        }
        if(M[i][j] != 0){
          printf("1 ");
        }else printf("0 ");
      }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while (!(line = br.readLine()).equals("0")) {

			int n = Integer.parseInt(line);
			int[] prog, freq;
			prog = new int[n];
			freq = new int[n];

			line = br.readLine();
			StringTokenizer st = new StringTokenizer(line);

			for (int i = 0; i < n; i++) {
				prog[i] = Integer.parseInt(st.nextToken());
			}

			// 出現頻度操作
			int op = 0;
			while (true) {

				// 数え上げ
				boolean[] chk = new boolean[n];

				for (int i = 0; i < n; i++) {
					if (!chk[i]) {
						int f = 1, t = 1;
						int[] idx = new int[n];
						chk[i] = true;
						idx[0] = i;
						for (int j = 0; j < n; j++) {
							if (!chk[j] && prog[i] == prog[j]) {
								chk[j] = true;
								f++;
								idx[t] = j;
								t++;
							}
						}
						for (int j = 0; j < t; j++) {
							freq[idx[j]] = f;
						}
					}
				}
				//
				if (!Arrays.equals(prog, freq)) {
					prog = Arrays.copyOf(freq, n);
					op++;
				} else {
					prog = freq;
					break;
				}
			}
			System.out.println(op);
			if (n > 1) {
				System.out.print(freq[0]);
				for (int i = 1; i < n - 1; i++) {
					System.out.print(" " + freq[i]);
				}
				System.out.println(" " + freq[n - 1]);
			} else {
				System.out.println(freq[0]);
			}
		}
	}
}

Measured memory_bytes: 20812
N = int(input())
L = list(map(int,input().split()))
cnt = 0

for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            if len(set([L[i], L[j], L[k]])) == 3 and 2 * max([L[i], L[j], L[k]]) < sum([L[i], L[j], L[k]]):
                cnt += 1
print(cnt)

Measured memory_bytes: 9144
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
#define MAX_M 100000
#define vec vector<int>
#define vecst vector<string>
#define vecch vector<char>
#define vecf vector<float>
#define vecvec vector<vector<int>>
using ll=int long long;
const int INF = 1e9;
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

int main(){
  string s;
  cin>>s;
  int n,ans=0;
  cin>>n;
  for(int e=0;e<n;e++){
    string q;
    cin>>q;
    for(int i=0;i<q.size();i++){
      bool st=true;
      for(int j=0;j<s.size();j++){
        if(i+j>=q.size()){
          if(s[j]!=q[j+i-q.size()]){
            st=false;
            break;
          }
        }
        else{
          if(s[j]!=q[i+j]){
            st=false;
            break;
          }
        }
      }
      if(st){
        ans++;
        break;
      }
    }
  }
  cout<<ans<<endl;
}




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


int main()
{
map<int,int>mp;
vector<int>v;
int n;
cin >> n;
for(int i=0; i<n; i++)
{
    int x ;
    cin >> x;
    if(!mp[x])
        v.push_back(x);
    mp[x]++;
}
cout << v.size() << endl;

}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define ll long long
#define dbg(x) cout<<#x<<"="<<x
#define nl cout<<"\n"
#define frn(i,n) for(int i = 0;i < n;i++)
#define fr(i,a,b) for(int i = a;i < b;i++)
#define pb push_back
#define trav(x,c) for(auto &x:c)
using namespace std;

int toint(string s) {
  int ans = 0;
  for(char x: s) ans = ans*10 + (x - '0');
  return ans;
}

int sum(int x) {
  int s = 0;
  while(x) {
    s += x%10;
    x /= 10;
  }
  return s;
} 

int main() {
  int n,k;
  cin>>n>>k;
  priority_queue<int> pq;
  frn(i,n){ 
    int x;
    cin>>x;
    pq.push(x);
  }
  int ans = 0;
  frn(i,k) {
    ans += pq.top();
    pq.pop();
  }
  cout<<ans;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;
/*
Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}
*/
Node treeSearch(Node u, int k){
  Node ret = NIL;
  if (u->key==k) return u;
  else if (u->key>k) {
    if (u->left!=NIL) {
      return treeSearch(u->left, k);
    }
  } else if (u->right!=NIL)
    return treeSearch(u->right, k);

  return ret;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x!=NIL) {
    y = x;
    if (z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if (y==NIL)
    root = z;
  else if (z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void inorder(Node u){
  if (u->left!=NIL) inorder(u->left);
  printf(" %d", u->key);
  if (u->right!=NIL) inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if (u->left!=NIL) preorder(u->left);
  if (u->right!=NIL) preorder(u->right);
}

void print()
{
  if (root==NIL) return;
  preorder(root);
  printf("\n");
  inorder(root);
  printf("\n");
}
int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);
  
  for (i = 0; i < n; i++){
    scanf("%s", com);
    switch (com[0]) {
    case 'f':
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
      break;
    case 'i':
      scanf("%d", &x);
      insert(x);
      break;
    case 'p':
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
      break;
      /*
    case 'd':
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
      */
    }
  }
  return 0;
}


Measured memory_bytes: 20508
#include<stdio.h>

int main()
{
	int i = 0;
	char password[20];
	int check = 0b0000;
	
	scanf("%s", password);
	
	do{
		if(password[i]>='0'&&password[i]<='9')	check |= 0b0001;
		if(password[i]>='a'&&password[i]<='z')	check |= 0b0010;
		if(password[i]>='A'&&password[i]<='Z')	check |= 0b0100;
		i++;
	}while(password[i] != '\0');
	
	if(i >= 6)	check |= 0b1000;
	
	puts((check == 0b1111) ? ("VALID") : ("INVALID"));
	
	return 0;
}

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

const int MAXN=4000;

long long len[MAXN][MAXN];
pair<int, int> pre[MAXN][MAXN]; 

int main(){
	string s,t;
	cin >> s >> t;
	for(int i = 1; i <= s.length(); i++){
		for(int j = 1; j <= t.length(); j++){
			if(s[i - 1] == t[j - 1]){
				len[i][j] = len[i - 1][j - 1] + (s[i - 1] == t[j - 1]);
				pre[i][j] = {i - 1, j - 1};
			}if(len[i][j] < len[i][j - 1]){
				len[i][j] = len[i][j - 1];
				pre[i][j] = {i, j - 1};
			}if(len[i][j] < len[i - 1][j]){
				len[i][j] = len[i - 1][j];
				pre[i][j] = {i - 1, j};
			}
			
			/*len[i][j]=max({len[i - 1][j - 1] + (s[i - 1] == t[j - 1]),
			               len[i][j - 1],
			               len[i - 1][j]});*/
		}
	}//cout<<len[s.length()][t.length()];
	string _ans="";
	//if(s[s.length() - 1] == t[t.length() - 1]) _ans+=s[s.length() - 1];
	
	pair<int, int>now={s.length(), t.length()};
	
	while(now.first != 0 || now.second != 0){
		if(pre[now.first][now.second].first == now.first - 1 && 
		pre[now.first][now.second].second == now.second - 1 && s[now.first - 1] == t[now.second - 1]){
			_ans+=s[now.first-1];
			//cout<<"* ";
		}//cout<<now.first << ","<<now.second<<","<<pre[now.first][now.second].first<<pre[now.first][now.second].second<<"\n";
		now={pre[now.first][now.second].first, pre[now.first][now.second].second} ;
		
	}string ans="";
	for(int i=_ans.length()-1; i>=0; i--){
		ans+=_ans[i];
	}
	cout << ans << "\n";
	
	//未完成:回朔 
}














Measured memory_bytes: 188416
#include <iostream>

using namespace std;

int main()
{
    int a , b , c , d ;
    cin >> a >> b >> c >> d;
    int area1 = a*b , area2 = c*d ;
    if (area1 >= area2)
        cout << area1 ;
    else
        cout << area2 ;
 return 0 ;
}


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

int main()
{
  int n, i, push;
  int fill=0;
  vector<int> a;
  vector<int> b;
  vector<int> c;
  
  cin >> n;
  
  for(i=0;i<n;i++)
  {
    cin >> push;
    a.push_back(push);
  }
  
  for(i=0;i<n;i++)
  { 
    cin >> push;
    b.push_back(push);
  }
  
  for(i=0;i<n-1;i++)
  { 
    cin >> push;
    c.push_back(push);
  }
  
  fill = b[a[0]-1];
  
  for(i=1;i<n;i++)
  {
    fill += b[a[i]-1];
    if(a[i] == a[i-1]+1)
    {
      fill = fill + c[a[i]-2];
    }
  }
  
  cout << fill << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint k, a, b;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> k >> a >> b;
	
	if(b-a+1 >= k){
		cout << "OK" << endl;
		return 0;
	}
	for(int i = a; i <= b; i++){
		if(i%k == 0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	int n,t,i;
	char a[100],b[100],x[100],y[100];
	scanf("%d",&n);
	for(int o=0;o<n;o++){
		t=0;
		scanf("%s %s",a,b);
		for(i=0;a[i]!='\0';i++){}
		for(int j=0;j<i;j++){
			x[j]=a[i-j-1];
		}
		for(;i<100;i++){
			x[i]='0';
		}
		for(i=0;b[i]!='\0';i++){}
		for(int j=0;j<i;j++){
			y[j]=b[i-j-1];
		}
		for(;i<100;i++){
			y[i]='0';
		}
		for(i=0;i<99;i++){
			x[i]+=y[i]-'0';
			if(x[i]>'9'){
				x[i]-=10;
				x[i+1]+=1;
			}
		}
		for(i=99;i>=0;i--){
			if(x[i]!='0' || t){
				t=1;
				if(i>79){
					printf("overflow");
					break;
				}
				printf("%c",x[i]);
			}
		}
		if(!t)printf("0");
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2560
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void){
  int n,i,cnt=1;
  char s[200000][11];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s",s[i]);
  }
  
  qsort(s,n,11,strcmp);
  
  for(i=0;i<n-1;i++){
    if(strcmp(s[i],s[i+1]) != 0){
      cnt++;
    }
  }
  printf("%d",cnt);
  return 0;
}

Measured memory_bytes: 5724
n,p = map(int,input().split())
s = input()
num = 0
s1 = [0]*(n+1)
ans = 0
if p == 2 or p == 5:
	for i in range(len(s)):
		if int(s[i])%p == 0:
			ans += i+1	
	print(ans)
	exit()
ans = 0
arr = [0]*p
s = s[::-1]
z = 1
for i in range(n):
	s1[i+1] = s1[i] + int(s[i])*z
	z = z * 10 %p
	s1[i+1] %=p
	arr[s1[i]] += 1
arr[s1[n]]+=1
#print(s1)
for i in range(p):
	ans += arr[i] * (arr[i] - 1) // 2
print(ans)


Measured memory_bytes: 11024
#include <iostream>
#include <string>
#include <vector>
#include <stack>
using namespace std;

int main() {
	int x=0,y=100;
	stack<int> hor;
	char key;
	int S = 0, sum=0;
	int i = 0, tmp = 0;
	vector<pair<int, int> > p; //p(S,x)
	while (cin >> key) {
		x++;
		if (key == '\\') {
			hor.push(x);
		}else if(key == '/' && !hor.empty()) {
			tmp = hor.top();
			hor.pop();
			S = x - tmp;
			sum += S;
			while (!(p.empty()) && p.back().second > tmp) {
				S += p.back().first;
				p.pop_back();
			}
			p.push_back(make_pair(S, tmp));
		}
	}
	cout << sum << endl;
	cout << p.size() ;
	for (int i = 0; i < p.size(); i++) cout << ' ' << p[i].first;
	cout << endl;
}


Measured memory_bytes: 3248
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
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...));
}
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 ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++) {
        cin >> p.at(i);
    }
    vector<int> a(N), b(N);
    int M = 30000;
    for (int i = 0; i < N; i++) {
        a[i] = (i * M + 1);
    }
    for (int i = 0; i < N; i++) {
        a[p[i] - 1] += i;
    }
    for (int i = 0; i < N; i++) {
        b[i] = (N - i - 1) * M + 1;
    }
    for (int i = 0; i < N; i++) {
        cout << a[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;
    for (int i = 0; i < N; i++) {
        cout << b[i];
        if (i != N - 1) cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 896
#include<iostream>
#include<vector>
#include<algorithm>

struct P{
    int x, y;
};
 
std::vector<P> creature[7];//0は始点, 6は終点となっている
const int INF = 1 << 24;
//dp[ゲットしたパチモンの匹数][さっきつかまえた種族][さっきつかまえたパチモンの番号]: 最小手数
int dp[5][5][1000];
 
int rec(int i, int t, int n){
	if(dp[i][t][n] >= 0){
		return dp[i][t][n];
	}
 
	if(i == 4){
		int x_diff = abs(creature[6][0].x - creature[t][n].x),
			y_diff = abs(creature[6][0].y - creature[t][n].y);
		return x_diff + y_diff;
	}

	//t+1へ行こう
	int res = INF, prev_res;
	for(int v=0;v<creature[t+1].size();v++){
		int x_diff = abs(creature[t+1][v].x - creature[t][n].x),
			y_diff = abs(creature[t+1][v].y - creature[t][n].y);
		res = std::min(res, rec(i+1, t+1, v) + x_diff + y_diff);
	}

	return dp[i][t][n] = res;
}
 
int main(){
	int w, h;
	while(std::cin >> w >> h, w){
		for(int i=0;i<7;i++)creature[i].clear();
 
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char c;
				std::cin >> c;
				if(c == 'S'){
					creature[0].push_back({j, i});
				}else if(c == 'G'){
					creature[6].push_back({j, i});
				}else if('1' <= c && c <= '5'){
					creature[c-'0'].push_back({j, i});
				}
			}
		}
 
		int res = INF, type;
		for(int i=1;i<=5;i++){
			for(int S=0;S<5;S++){
				for(int t=0;t<5;t++){
					for(int n=0;n<1000;n++){
						dp[S][t][n] = -1;
					}
				}
			}

			std::rotate(creature+1, creature+2, creature+6);

			if(rec(0, 0, 0) < res){
				res = rec(0, 0, 0);
				type = i;
			}
		}
 
		if(res == INF){
			std::cout << "NA" << std::endl;
		}else{
			std::cout << type << " " << res << std::endl;
		}
	}
}

Measured memory_bytes: 1360
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
// #include<C:\Users\J\Desktop\AC\athead.h>
#define showa(v) for(int iii = 0; iii < v.size(); iii++){ cout << v[iii] << " ";} cout << endl;
#define show(iiii) cout << iiii << endl; 
#define shows(iiiii) cout << iiiii << " ";
#include<iostream>
#include<string>
#include<vector>
// #include<stdio.h>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <set>
#include <deque>
#include <numeric>
#include<tuple>
#include <utility>
#include <map>
#include <cassert>
#include<unordered_set>
using namespace std;

 
int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> a(n, vector<int>(m));
    vector<int> suma(m, 0);
    rep(i,n){
        cin >> c[i];
        rep(j,m){
            cin >> a[i][j];         
            suma[j] += a[i][j];
        }
    }

    rep(j,m){
        if(suma[j] < x){
            cout << -1 << endl;
            return 0;
        }
    }
    vector<vector<int>> pool;
    vector<long long int> sumcs;
    vector<bool> use;
    long long int minc = 0;
    for (int bit = 0; bit < (1<<n); ++bit) {
            // vector<int> S;
            int sumc = 0;
            vector<int> Si;
            for (int i = 0; i < n; ++i) {
                if (bit & (1<<i)) { // 列挙に i が含まれるか
                    // S.push_back(a[i][j]);
                    Si.push_back(i);
                    sumc+=c[i];
                }
            }
            pool.push_back(Si);
            sumcs.push_back(sumc);
            use.push_back(true);
            if(sumc > minc){
                minc = sumc;
            }
        }

    rep(j,m){
        vector<int> buf(n);
        rep(i,n) buf[i] = a[i][j];
        rep(k, pool.size()){
            if(use[k]){
                int summ = 0;
                rep(kk, pool[k].size()){
                    summ += a[pool[k][kk]][j];
                }
                if(summ < x) use[k] = false;
            }          
        }
    }
    
    rep(k, use.size()){
        if(use[k]){
            if(minc > sumcs[k]){
                minc = sumcs[k];
            }
        }
    }
    cout << minc << endl;



}

Measured memory_bytes: 3896
#include <iostream>
#define ll long long
using namespace std;

int main() {
	ll o1,o2;
	char c;
	cin>>o1;
	cin>>c;
	cin>>o2;
	if(c=='+')
	    cout<<o1+o2;
	else
	    cout<<o1-o2;
	return 0;
}

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


int main(){
        long x;
        cin >>x;
        long ans = x / 11;
        ans *= 2;
        long n = x % 11;
        if(n == 0) {

        }else if(n <= 6) {
                ans++;
        }else{
                ans += 2;
        }
        cout << ans << endl;
}


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

int main () {
  int N,M,K;
  cin >> N >> M >> K;
  
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      if (i*M + j*N - i*j*2 == K){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}
  

Measured memory_bytes: 3512
IDENTIFICATION DIVISION.
       PROGRAM-ID. test1.
       ENVIRONMENT DIVISION.
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       01 INP PIC X(100).
       01 A PIC 99999999.
       01 B PIC 99999999.
       01 C PIC 9999999999.
       01 REN PIC 9999999999.
       01 RE PIC ZZZZZZZZZZ9.
       01 temp1 PIC 9999999.
       01 temp2 PIC 9999999.
       01 temp3 PIC 9999999.
       01 N PIC 9999999.
       PROCEDURE DIVISION.
       MAIN.
       	ACCEPT INP.
      	PERFORM VARYING temp1 FROM 1 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	SUBTRACT 1 FROM temp1.
      	MOVE INP(1:temp1) TO A.
      	ADD 2 TO temp1.
      	PERFORM VARYING temp2 FROM temp1 BY 1 UNTIL INP(temp2:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp2 - temp1.
      	MOVE INP(temp1:N) TO B.
      	ADD 1 TO temp2.
      	PERFORM VARYING temp1 FROM temp2 BY 1 UNTIL INP(temp1:1)=SPACE
      	END-PERFORM.
      	COMPUTE N=temp1 - temp2.
      	MOVE INP(temp2:N) TO C.
      	ADD 1 TO A.
      	MOVE 0 TO REN.
      	PERFORM VARYING N FROM 1 BY 1 UNTIL N = A
      		MOVE 0 TO temp1
      		MOVE N TO temp2
      		PERFORM MOD
      		IF temp1 >= B AND temp1 <= C THEN
      			ADD N TO REN
      		END-IF
      	END-PERFORM.
      	MOVE REN TO RE.
      	DISPLAY RE.
        STOP RUN.

      MOD SECTION.
      	PERFORM 5 TIMES
      		COMPUTE temp3 = temp2 / 10
      		COMPUTE temp1 = temp1 + temp2 - temp3 * 10
      		COMPUTE temp2 = temp3
      	END-PERFORM.
      EXIT.



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

int main() {
  long long a;
  cin>>a;
  string b;
  cin>>b;
  long long lb = 0;
  for (int i=0; i<b.length(); i++) {
    if (b[i] == '.') {
      continue;
    }
    lb = lb * 10 + b[i] - '0';
  }
  long long ans = a * lb;
  cout<<ans / 100<<endl;
}

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

int main()
{
	long long X, K, D;
	cin >> X >> K >> D;

	X = abs( X );
	long long n = X / D;
	long long ans = X - K * D;
	if( K <= n ) {
	}
	else {
		ans = X - n * D;
		if( (K - n) % 2 ) ans = min( abs( ans + D ), abs( ans - D ) );
	}

	cout << ans << endl;
}


Measured memory_bytes: 3624
S = input()
if len(S) % 2 == 0:
    former = S[:len(S) // 2]
    latter = S[len(S) // 2:]
else:
    former = S[:len(S) // 2]
    latter = S[len(S) // 2 + 1:]

count = 0
for c_former, c_latter in zip(former, latter[::-1]):
    if c_former != c_latter:
        count += 1
print(count)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  	long long n,x,m;
  	map<long long,long long>rec;
	cin>>n>>x>>m;
	vector<long long>s{0};
	long long ans=-1;
	for(int i=0;i<n&&x;++i){
		if(rec.find(x)!=rec.end()){
			long long hn=(n-rec[x])/(i-rec[x]);
			long long res=n-rec[x]-(i-rec[x])*hn;
			ans=hn*(s[i]-s[rec[x]])+s[rec[x]+res];
			break;
		}
		s.push_back(s[s.size()-1]+x); 
		rec[x]=i;
		x=(x*x)%m;
	}
	if(ans==-1){
		ans=s[s.size()-1];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6744
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(in) in.begin(),in.end()
#define int long long
typedef pair<int,int> pii;
signed main(){
    int n,t,q;
    cin >> n >> t >> q;
    vector<pii> l,r;
    vector<int> in(n),d(n);
    rep(i,n){
        cin >> in[i] >> d[i];
        if(d[i] == 1){
            r.push_back(pii(in[i],i));
        }else{
            l.push_back(pii(in[i],i));
        }
    }
    sort(all(l));
    sort(all(r));
    //rep(i,l.size())cout << " " << l[i].first;cout << endl;
    //rep(i,r.size())cout << " " << r[i].first;cout << endl;
    rep(i,q){
        int qq;
        cin >> qq;
        qq--;
        if(d[qq] == 1){
            //lの中からin[qq]以上の最小ind1をさがす
            int tmp1 = upper_bound(all(l), pii(in[qq],-1)) - l.begin();
            if(tmp1 == l.size()){
                cout << in[qq] + t << endl;
                continue;
            }
            int ind1 = l[tmp1].second;
            //rの中からin[ind1]以下の最大ind2をさがす
            int tmp2 = lower_bound(all(r), pii(in[ind1],-1)) - r.begin() - 1;
            int ind2 = r[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(in[qq] + t > x){
                cout << x << endl;
            }else{
                cout << in[qq] + t << endl;
            }
        }else{
            int tmp1 = lower_bound(all(r),pii(in[qq],-1)) - r.begin() - 1;
            if(tmp1 < 0){
                cout << in[qq] - t << endl;
                continue;
            }
            int ind1 = r[tmp1].second;
            int tmp2 = upper_bound(all(l), pii(in[ind1],-1)) - l.begin();
            int ind2 = l[tmp2].second;
            int x = (in[ind1] + in[ind2])/2;
            //cout << ind1 << " " << ind2 << " " << x << endl;
            if(x > in[qq] - t){
                cout << x << endl;
            }else{
                cout << in[qq] - t << endl;
            }
        }

    }
}



Measured memory_bytes: 6720
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] != s[2] && s[2] == s[3])
    cout << "Yes";
  else if(s[0] == s[2] && s[0] != s[1] && s[1] == s[3])
    cout << "Yes";
  else if(s[0] == s[3] && s[0] != s[1] && s[1] == s[2])
    cout << "Yes";
  else
    cout << "No";
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

int main()
{
	fast;
	ll n;
	cin >> n;
	string ans;
	while (n)
	{
		n--;
		ans = char('a' + n % 26) + ans;
		n /= 26;
	}
	cout << ans;
}

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

struct Graph
{
    int N;
    vector<vector<int>> red_neighbors, blue_neighbors;

    Graph(const int N) : N(N), red_neighbors(N), blue_neighbors(N) {}

    void add_red_edge(const int a, const int b)
    {
        red_neighbors[a].push_back(b);
        red_neighbors[b].push_back(a);
    }

    void add_blue_edge(const int a, const int b)
    {
        blue_neighbors[a].push_back(b);
        blue_neighbors[b].push_back(a);
    }

    int solve(const int X, const int Y) const
    {
        auto blue_distances = vector<int>(N);
        auto blue_parents = vector<int>(N);
        const function<void(int, int)> blue_dfs = [&](const int v, const int parent)
        {
            for (const auto w : blue_neighbors[v]) if (w != parent)
            {
                blue_distances[w] = blue_distances[v]+1;
                blue_parents[w] = v;
                blue_dfs(w, v);
            }
        };
        blue_parents[Y] = Y;
        blue_dfs(Y, -1);

        auto red_distances = vector<int>(N, -1);
        auto win = false;
        const function<void(int, int)> red_dfs = [&](const int v, const int parent)
        {
            if (red_distances[v] >= blue_distances[v]) return;
            for (const auto w : red_neighbors[v]) if (w != parent)
            {
                auto close = blue_parents[v] == w || blue_parents[w] == v;
                close |= blue_parents[blue_parents[v]] == w;
                close |= blue_parents[blue_parents[w]] == v;
                close |= blue_parents[v] == blue_parents[w];

                if (!close) win = true;
                else
                {
                    red_distances[w] = red_distances[v]+1;
                    red_dfs(w, v);
                }
            }
        };
        red_distances[X] = 0;
        red_dfs(X, -1);

        if (win) return -1;
        else
        {
            auto result = 0;
            for (auto v = 0; v < N; v++) if (red_distances[v] != -1)
                result = max(result, 2*blue_distances[v]);
            return result;
        }
    }
};

int main()
{
    int N, X, Y; cin >> N >> X >> Y;
    X--; Y--;

    auto graph = Graph(N);

    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        graph.add_red_edge(a, b);
    }

    for (auto i = 0; i < N-1; i++)
    {
        int a, b; cin >> a >> b;
        a--; b--;
        graph.add_blue_edge(a, b);
    }

    cout << graph.solve(X, Y) << endl;
}


Measured memory_bytes: 38652
from bisect import bisect_left

N = int(input())
L = list(map(int,input().split()))
L.sort()
 
result = 0

for i,a in enumerate(L[:N-2]):
    i += 1
    for j,b in enumerate(L[i:N-1]):
        j += i + 1
        n = bisect_left(L,a+b) - j
        result += n
print(result)

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main(void)
{
  double a,b,C,c;
  double S,L,h;
  double d; //??????
  double si,co;
  double pai = 3.1415926;
  
  scanf("%lf%lf%lf",&a,&b,&C);

  c = C / 180 *pai;
  si = sin(c);
  co = cos(c);
  h = b * si;
  d = sqrt((a*a)+(b*b)-(2*a*b*co));
  L = a+b+d;
  S = (a * h) / 2;

  printf("%f\n%f\n%f\n",S,L,h);
  
  return(0);
}

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

int main(){ 
    int n;
    cin>>n;
    int b=0;
    int c=0;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        b=max(b,a[i]);
    }
    for(int i=0;i<n;i++){
        c+=a[i];
    }
    cout<<c-b/2;
    return 0;
}


Measured memory_bytes: 256
# vim: fileencoding=utf-8


def main():
    l = list()
    for i in range(3):
        l.append(list(map(int, input().split())))

    for a1 in range(0, l[0][0] + 1):
        b1 = l[0][0] - a1
        b2 = l[0][1] - a1
        b3 = l[0][2] - a1
        a2 = l[1][0] - b1
        a3 = l[2][0] - b1
        if b1 < 0:
            continue
        if b2 < 0:
            continue
        if b3 < 0:
            continue
        if a2 < 0:
            continue
        if a3 < 0:
            continue
        if (
            l[1][1] == b2 + a2
            and l[1][2] == b3 + a2
            and l[2][1] == b2 + a3
            and l[2][2] == b3 + a3
        ):
            print("Yes")
            return
    print("No")


if __name__ == "__main__":
    main()


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

int main() {
  int n;cin>>n;
  vector<ll> vec(5);
  string t="MARCH";
  rep(i,n){
    string s;cin>>s;
    rep(j,5){
      if(s[0]==t[j])vec[j]++;
    }
  }
  ll ans=0;
  rep(i,3)for(int j=i+1;j<4;j++)for(int k=j+1;k<5;k++){
    ans+=vec[i]*vec[j]*vec[k];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3604