akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

long A[100010];

int main() {
  long N, X, M; cin >> N >> X >> M;
  set<int> a_set;
  a_set.insert(A[0] = X);
  int l = 1;
  for (int i = 1; i <= M; i++) {
    A[i] = A[i-1]*A[i-1]%M;
    if (a_set.find(A[i]) != a_set.end()) {
      break;
    }
    a_set.insert(A[i]);
    l++;
  }
  int j = find(A, A+l, A[l]) - A;
  long sum1 = 0, sum2 = 0;
  for (int i = 0; i < min(N, (long)j); i++) sum1 += A[i];
  if (N > j) {
    for (int i = j; i < l; i++) sum2 += A[i];
    sum2 *= (N-j)/(l-j);
    for (int i = 0; i < (N-j)%(l-j); i++) sum2 += A[i+j];
  }
  cout<<sum1+sum2 << endl;
}

Measured memory_bytes: 6328
import math

def main():
    n = int(input())
    s = input()
    ans = solve(n, s)
    print(ans)


def solve(n, s):
    ans = 0
    for i in range(n - 1):
        tmp = Z(s[i:])
        t = [min(tmp[j], j)for j in range(n - i)]
        ans = max(ans, max(t))
        #print(tmp)
    return ans

def Z(s):
    l = len(s)
    ans = [l for _ in range(l)]

    i, j = 1, 0
    while i < l:
        while i + j < l and s[j] == s[i + j] :
            j += 1
        ans[i] = j

        if j == 0:
            i += 1
            continue

        k = 1
        while k < j and k + ans[k] < j:
            ans[i + k] = ans[k]
            k += 1
        i += k
        j -= k
    return ans

if __name__ == '__main__':
    main()

Measured memory_bytes: 65884
///Bismillahir Rahmanir Rahim
#include "bits/stdc++.h"

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=100005;
vector<int>vec;
map<int,int>cnt;
int ses=0;
 main()

{
    fast
    int n;
    cin>>n;
    f(i,1,n)
    {
        int x;
        cin>>x;
        cnt[x]++;
    }
    for(auto x:cnt)
    {
        if(x.si>=2)vec.pb(x.fi);
        if(x.si>=4)ses=max(ses,(x.fi*x.fi));
    }
    sort(vec.begin(),vec.end());
    if(vec.size()<2)
    {
        cout<<ses<<endl;
        return 0;
    }
    int a=vec.back();
    vec.pop_back();
    int b=vec.back();
    ses=max(ses,a*b);
    cout<<ses<<endl;
    return 0;

}





































Measured memory_bytes: 9752
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    String S = sc.next();
    String T = sc.next();
    char[] S2 = S.toCharArray();
    char[] T2 = T.toCharArray();
    boolean check2 = false;
    for(int i=S2.length-1; i>=0; i--){
      int k = i;
      int j = T2.length-1;
      boolean check = false;
      if(check2 == true){
        if(S2[i] == '?') S2[i] = 'a';
        continue;
      }
      while(j >= 0 && k >= 0 && (S2[k] == T2[j] || S2[k] == '?')){
        if(j == 0){
          check = true;
          check2 = true;
          j = T2.length-1;
          while(j >= 0){
            S2[i] = T2[j];
            j--;
            i--;
          }
          i++;
        }
        j--;
        k--;
      }
      if(check == false){
        if(S2[i] == '?') S2[i] = 'a';
      }
    }
    if(check2 == true) out.println(S2);
    else out.println("UNRESTORABLE");
    
      
       
  }

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

Measured memory_bytes: 22868
#include<iostream>

using namespace std;

int main() {
	int n;
	char s;
	int fl = 0;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> s;
		if (s == 'Y') {
			fl = 1;
		}
	}
	if (fl == 0) {
		cout << "Three" << endl;
		return 0;
	}
	else
	{
		cout << "Four" << endl;
		return 0;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
using namespace std;

//繰り返し
#define REP(i, m, n) for(int i=(int)m; i<(int)n; ++i)
#define rep(i, n) REP(i, 0, n)
#define RREP(i, m, n) for(int i=(int)m; i>=(int)n; --i)
#define rrep(i, m) RREP(i, m, 0)

//簡略化
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> P;

//定義
const int INF = 1e9+7;
const ll LINF = 1e18;
const ll MOD = 1e9+7;

//最大最小
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) {if(a>b) a=b;}
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) {if(a<b) a=b;}

//GCD&LCM
ll gcd(ll x, ll y) {
  if(y==0) return x;
  else return gcd(y, x%y);
}

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

//--------------------------

int main() {

  ll A, B, C, D, c, d, l;
  cin >> A >> B >> C >> D;

  c = B/C-(A-1)/C;
  d = B/D-(A-1)/D;
  l = B/lcm(C, D)-(A-1)/lcm(C, D);

  cout << (B-A+1)-(c+d-l) << endl;

  return 0;
}

/*
4, 6, 8
6, 9
*/


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

int n,m,ac,wa;

signed main(){
  cin>>n>>m;
  vector<int> v(n,0);
  for(int i=0;i<m;i++){
    int p;string s;cin>>p>>s;p--;
    if(~v[p]){
      if(s=="AC"){
        ac++;
        wa+=v[p];
        v[p]=-1;
      }
      else v[p]++;
    }
  }
  cout<<ac<<" "<<wa<<endl;
}


Measured memory_bytes: 640
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);

//    2つの文字列を入力してもらう
    String s = scanner.next();
    String t = scanner.next();

//    tから最後の１文字を切り離した文字列を抽出
    int tLength = t.length();
    String T = t.substring( 0 , tLength - 1);

//    最初に入力してもらった文字列と先ほど抽出した文字列を比較する
    if( s.equals(T)) {
        System.out.println("Yes");
    }else {
        System.out.println("No");
    }

    scanner.close();
  }
}

Measured memory_bytes: 35768
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    int k = Integer.parseInt(sc.next());
    int n = Integer.parseInt(sc.next());
    int a[] = new int[n];
    int maxDistance = 0;
    for (int i = 0; i < n; i++) {
      a[i] = Integer.parseInt(sc.next());
    }
    for (int i = 0; i < n - 1; i++) {
      maxDistance = Math.max(a[i + 1] - a[i], maxDistance);
    }
    maxDistance = Math.max(a[0] + (k - a[n - 1]), maxDistance);
    pw.println(k - maxDistance);
  }
}


Measured memory_bytes: 57044
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define PPC(x) __builtin_popcount((x))
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
using namespace std;

vector <pair <int, int> > p;
long long res;
int limit;

void go(int d, int prev, long long sum)
{
	if (d == p.size() or prev == limit)
	{
		res = max(res, sum);
		return;
	}
	
	int i = (d == p.size() - 1 ? limit : prev);
	for (; i<=limit; i++)
		go(d+1, i, sum + 1ll*(i-prev) / p[d].first * p[d].second + (i-prev) % p[d].first);
} 

int main()
{
	long long n;
	scanf ("%lld", &n);
	
	pair <int, int> T[3];
	FOR(i, 0, 3)
		scanf ("%d", &T[i].first);
	FOR(i, 0, 3)
		scanf ("%d", &T[i].second);
		
	FOR(i, 0, 3)
		if (T[i].first < T[i].second)
			p.pb(T[i]);
	limit = n;
	go(0, 0, 0);	
	n = max(n, res);
	
	p.resize(0);
	FOR(i, 0, 3)
		if (T[i].second < T[i].first)
			p.pb({T[i].second, T[i].first});
	res = 0;
	limit = n;

	go(0, 0, 0);	
	n = max(n, res);
	
	printf("%lld\n", n);	
	return 0;
}


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

#define _USE_MATH_DEFINES
#define pb  push_back

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF = 999999999;
const ll atcoder = 1000000007;
const int dx[4] = { 1 , 0 , -1 ,0 };
const int dy[4] = { 0 , 1 , 0 , -1 };

int main() {

	string s;

	cin >> s;

	
	for (int i = 0; i < s.length() - 8; i++) {
		cout << s[i];
	}

	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;

void input() {
  ;
  ;
  cin >> S;
}
void solve() {
  int n = S.size();
  rep(i, 1, n) cout << "x";
  cout << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
long[] a = new long[n];
int count = 0;
for(int i = 0;i < n;i++){
a[i] = sc.nextLong();
while(a[i]%2 == 0){
count++;
a[i] /= 2;
}
}
System.out.println(count);
}}

Measured memory_bytes: 34756
;; #!/usr/bin/env sbcl --script

(declaim (optimize (speed 3) (safety 0) (debug 0)))

(deftype int32 () '(signed-byte 32))

(defun main ()
  (let* ((n (read))
         (k (read))
         (a (make-array n :element-type 'int32))
         (dp (make-array n :element-type 'int32 :initial-element (+ (expt 10 9) 100))))
    ;; (let ((stream (make-string-input-stream (read-line))))
    ;;   (loop for i from 0
    ;;      for j = (read stream nil) until (null j)
    ;;      do (setf (aref a i) j))
    (loop for i of-type int32 from 0 below n do (setf (aref a i) (read)))
    (setf (aref dp 0) 0)
    (loop for i of-type int32 from 0 below n do
      (loop with from-val of-type int32 = (aref dp i)
         for j of-type int32 from (1+ i) to (+ i k)
         while (< j n)
         do
           (let ((nval (+ from-val (abs (- (aref a i) (aref a j))))))
             (setf (aref dp j) (min (aref dp j) nval)))))
    (format t "~a~%" (aref dp (- n 1)))))

(main)


Measured memory_bytes: 59748
// finish date: 2018/01/21
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    cin >> N;
    int n = N;
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    if (N % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int N;
	cin >> N;
	int zoro = 0;
	for (int i = 0; i < N; i++) {
		int j, k;
		cin >> j >> k;
		if (j == k) {
			zoro++;
		}
		else {
			zoro = 0;
		}
		if (zoro == 3) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;


	return 0;
}

Measured memory_bytes: 3636
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
#define PI 3.1415926535
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 25e7;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

const int X = 2505;

const int INF = 1e18;

signed main()
{
    Start();
    int n, m, s;
    cin >> n >> m >> s;
    if (s >= X)
        s = X - 1;
    int vs = n * X;
    vector <vector <pii>> g(vs);
    for (int i = 0; i < m; ++i)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b, --u, --v;
        for (int t = a; t < X; ++t)
            g[u * X + t].pb(v * X + t - a, b), g[v * X + t].pb(u * X + t - a, b);
    }
    for (int i = 0; i < n; ++ i)
    {
        int c, d;
        cin >> c >> d;
        for (int t = 0; t + c < X; ++t)
            g[i * X + t].pb(i * X + t + c, d);
    }
    vector <int> d(vs, INF);
    d[s] = 0;
    set <pii> q;
    q.emplace(0, s);
    while (!q.empty())
    {
        int v = q.begin()->second;
        q.erase(q.begin());
        for (auto &para : g[v])
        {
            int to = para.first, w = para.second;
            if (d[to] > d[v] + w)
            {
                q.erase(mp(d[to], to));
                d[to] = d[v] + w;
                q.emplace(d[to], to);
            }
        }
    }
    for (int v = 1; v < n; ++v)
    {
        int mn = INF;
        for (int x = 0; x < X; ++x)
            mn = min(mn, d[v * X + x]);
        cout << mn << endl;
    }
    return 0;
}



Measured memory_bytes: 25064
#include<iostream>
using namespace std;
int n,m;
int switch_bit[105]={0};
int p[105];
int rec(int bit,int num,int pos);
int main(){
  
  cin>>n>>m;
  for(int i=0;i<m;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      switch_bit[i]|=1<<(s-1);
    }
  }

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

  int sum=0;
  for(int i=0;i<=n;i++){
    sum+=rec(0,i,0);
  }
  cout<<sum<<endl;
  return(0);
}

int rec(int bit,int num,int pos){
  if(num==0){
    bool success=true;
    for(int i=0;i<m&&success;i++){
      int check=bit&switch_bit[i];
      int cnt=0;
      while(check>0){
	cnt++;
	check-=(-check&check);
      }
      if(cnt%2!=p[i]){
	success=false;
      }
    }
    if(success){
      return(1);
    }
    return(0);
  }

  int res=0;
  if(pos<n){
    res+=rec(bit|(1<<pos),num-1,pos+1);
    res+=rec(bit,num,pos+1);
  }
  return(res);
}


Measured memory_bytes: 384
#include<iostream>
#include<vector>
using namespace std;
class union_find{
private:
    vector<int>parent;
    vector<int>rank;
    int cnt;
public:   
    union_find(int vertex_num)
    {
        parent.resize(vertex_num);
        rank.resize(vertex_num);
        cnt = vertex_num;
        for(int i = 0; i < vertex_num; ++i){
            parent[i] = i;
            rank[i] = 0;
        }
    }
    int get_root(int n)
    {
        if(parent[n] == n){
            return n;
        }else{
            return get_root(parent[n]);
        }
    }
    bool is_same(int a, int b)
    {
        return get_root(a) == get_root(b);
    }
    void unite(int a, int b)
    {
        int root_a=get_root(a),root_b=get_root(b);
        if(root_a == root_b) return;
        if(rank[root_a] < rank[root_b]){
            parent[root_a] = root_b;
        }else if(rank[root_a] > rank[root_b]){
            parent[root_b] = root_a;
        }else{
            parent[root_a] = root_b;
            ++rank[root_b];
        }
    }
    int get_cnt()
    {
        return cnt;
    }
};

int main()
{
    int n, m;
    cin >> n >> m;
    int ans = m;
    vector<vector<int>>a(m,vector<int>(2));
    for(int i = 0; i < m; ++i){
        cin >> a[i][0] >> a[i][1];
        a[i][0]--;
        a[i][1]--;
    }
    for(int i = 0; i < m; ++i){
        union_find uf(n);
        for(int j = (i % m), k = 0;k < m-1; j = ((j + 1) % m), k++){
            uf.unite(a[j][0], a[j][1]);//１組抜かしてそのcntを調べたい
        }
        int cnt_vertex = 0;
        for(int j = 0; j < n; j++){
            if(uf.is_same(j, 0)) cnt_vertex++;
        }
        if(cnt_vertex == n) ans--;
    }
    cout << ans << endl;   
    return 0;
}

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

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> fromcount(N,0);
  map<int, set<int>> bond;
  for (int i=0; i<N+M-1; i++){
    int A, B;
    cin >> A >> B;
    A--; B--;
    fromcount[B]++;
    bond[A].insert(B);
  }
  int root = -1;
  for (int i=0; i<N; i++){
    if (fromcount[i]==0) {
      root = i;
      break;
    }
  }
  vector<int> ans(N, 0);
  ans[root] = -1;
  queue<int> q;
  q.push(root);
  while (!q.empty()){
    int check = q.front();
    q.pop();
    for (auto k: bond[check]){
      fromcount[k]--;
      if (fromcount[k]==0){
        q.push(k);
        ans[k] = check;
      }
    }
  }
  for (int i=0; i<N; i++){
    cout << ans[i]+1 << endl;
  }
}


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

typedef long long ll;
#define int ll
#define db(x) cout<<#x<<" = "<<x<<"\n";
#define FIN ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ALL(a) a.begin(),a.end()
#define mset(a,b) memset(a,b,sizeof(a));


 main() 
{
	FIN;
	int n;
	cin>>n;
	
	string res;

    char tmp;

    while(n)
    {

        n -= 1;

        tmp = 'a' + n % 26;

        res = tmp + res;

        n /= 26;

    }

    cout<< res<<endl;


}

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

int main()
{
    char a,b;
    while( scanf(" %c %c",&a,&b)!=EOF)
    {
        if(a=='D'&&b=='H')
            printf("D\n");
        else  if(a=='H'&&b=='D')
            printf("D\n");
        else  if(a=='H'&&b=='H')
            printf("H\n");
        else
            printf("H\n");
    }


    return 0;
}

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

#define all(x) x.begin(),x.end()
#define pb(x) emplace_back(x)
#define forn(i,N) for(int i=0;i<N;i++)

using namespace std;
using ll=long long int;
using ld=long double;
using vi=vector<int>;
using vll=vector<ll>;
using vd=vector<double>;

int main() {
//freopen("input.txt","rt",stdin);
ios::sync_with_stdio(false);
cin.tie(nullptr);

int a,b,c;
cin>>a>>b>>c;
cout<<(a+b+c>=22 ? "bust" : "win")<<endl;
return 0;
}


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

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    vector<vector<int>> RGB(3, vector<int>());
    map<int, int> Bmap;
    rep(i, N) {
        if (S[i] == 'R') {
            RGB[0].push_back(i);
        } else if (S[i] == 'G') {
            RGB[1].push_back(i);
        } else if (S[i] == 'B') {
            RGB[2].push_back(i);
            Bmap[i] = 1;
        }
    }
    ll Rc  = RGB[0].size();
    ll Gc  = RGB[1].size();
    ll Bc  = RGB[2].size();
    ll ans = (Rc * Gc * Bc);

    ll count = 0;
    rep(i,N){
        char X = S[i];
        for(int j=1;i+j*2<N;++j){
            char Y = S[i+j];
            char Z = S[i+j*2];
            if(X != Y && X!=Z && Y!=Z) ++count;
        }
    }
    cout << ans-count << endl;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<pair<int, int>> a(26);
    for(int i=0; i<26; i++) a[i] = make_pair(0, i);
    for(int i=0; i<n; i++){
        if(i%2 == 0){
            a[s[i]-'a'].first++;
        }
    }
    sort(a.begin(), a.end(), greater<pair<int, int>>());

    int ans = 0;
    int tmp = 0, now = a[0].first;
    for(int i=0; i<=26; i++){
        if(i < 26 && now == a[i].first){
            tmp++;
        }else{
            if(now > 0) ans += 2*tmp;
            if(now > 1) ans += 2;
            if(now > 1 && tmp > 1) ans += 2;
            tmp = 1;
            if(i < 26) now = a[i].first;
        }
    }
    cout << ans-1 << endl;
}





Measured memory_bytes: 3224
import java.util.*;
import java.text.*;

class Main {
    public static void main(String[]args)throws Exception {
        Scanner sc = new Scanner(System.in);
        for(;;) {
            int n = sc.nextInt();
            int x = sc.nextInt();
            int c = 0;
            if(n == 0 && x == 0) break;
            for(int i = 1; i <= n; i++) {
                for(int j = i + 1; j <= n; j++) {
                    for(int k = j + 1; k <= n; k++) {
                        if(i + j + k == x) c++;
                    }
                }
            }
            System.out.println(c);
        }
    }
}

Measured memory_bytes: 19588
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
//#define all(v) ((v).begin(),(v).end())
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> v(k,0);
    rep(i,1,n+1){
        v[i%k]++;
    }
    ll ans=0;
    if(v[0]){
        ans+=(v[0]*v[0]*v[0]);
    }
    if(k%2==0){
        ans+=(v[k/2]*v[k/2]*v[k/2]);
    }
    cout<<ans<<endl;



    
}


Measured memory_bytes: 1792
# B - Two Anagrams
s = list(input())
t = list(input())

# sを可能な限り辞書順で小さくする
s = sorted(s)
s = "".join(s)

# tを可能な限り辞書順で大きくする
t = sorted(t, reverse=True)
t = "".join(t)

# 一文字ずつ文字コードで比較する
ans = ""
N = min(len(s),len(t))
for i in range(N):
    if ord(s[i]) == ord(t[i]):
        pass
    elif ord(s[i]) < ord(t[i]):
        ans = "Yes"
        break
    else:
        ans = "No"
        break
else: #調べた文字が全部一緒だった場合、文字列の長さで比較
    if len(s) < len(t):
        ans = "Yes"
    else:
        ans = "No"

# 出力
print(ans)


Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)


int main(){
  int N;
  cin >> N;
  ll a[N];
  multiset<ll> s;
  set<ll> t;
  rep(i,N){
    cin >> a[i];
    t.insert(a[i]);
    s.insert(a[i]);
  }
  ll l=0;
  ll sm=0;
  for(auto i : t){
    if(i>sm){
      if(s.count(i)==2 || s.count(i)==3){
	if(i>l){
	  sm=l;
	  l=i;
	}
	else sm =i;
      }
      else if(s.count(i) >3){
	if(i>l) sm= l =i;
	else sm=i;
      }
    }
  }

  
  cout << sm*l << endl;
  
  return 0;

}


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

int main(){
    string S;
    cin >> S;

    string ans = "Good";

    for(int i = 0; i < 3; i++) {
        if(S[i] == S[i+1])ans = "Bad";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int a, b;
    scanf("%d%d", &a, &b);

    if (a == 1) a += 13;
    if (b == 1) b += 13;

    if (a < b) printf("Bob\n");
    else if (a > b) printf("Alice\n");
    else printf("Draw\n");

    return (0);
}


Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int N = 1e6;
int A[105][105];
string s[105];

int main() {
    ios_base::sync_with_stdio(0);
    int a,b,n,h,w,T,cas=0;
    cin>>h>>w;
    for(int i=1;i<=h;++i) {
        cin>>s[i];
        s[i]="."+s[i];
    }
    for(int j=0;j<=w;++j) s[0] += '.';

    for(int i=1;i<=h;++i) {
        for(int j=1;j<=w;++j) {
            if(i==1) A[i][j] = A[i][j-1] + (s[i][j]=='#' && s[i][j-1]=='.');
            else if(j==1) A[i][j] = A[i-1][j] + (s[i][j]=='#' && s[i-1][j]=='.');
            else {
                if(s[i][j]=='#') {
                    int x = min(A[i-1][j]+(s[i-1][j]=='.'), A[i][j-1]+(s[i][j-1]=='.'));
                    A[i][j] = x;
                }
                else A[i][j] = min(A[i-1][j], A[i][j-1]);
            }
        }
    }
    cout<<A[h][w];
    return 0;
}

Measured memory_bytes: 384
using System;

class A
{
	static void Main()
	{
		var h = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
		int l = h[0] + h[1], r = h[2] + h[3];
		Console.WriteLine(l > r ? "Left" : l == r ? "Balanced" : "Right");
	}
}


Measured memory_bytes: 27296
n = int(input())
list = []

for i in range(n):
    a,b = map(int,input().split())
    list.append([b,a])

list = sorted(list)

tpast = 0
flag = 0

for i in range(n):
    b,a = list[i][0],list[i][1]
    if tpast+a > b:
        flag = 1
        break
    else:
        tpast = tpast+a

if flag == 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 37272
#include<cstdio>
#include<cstring>
using namespace std;
int main(){
    int W,H,N;
    int x,y,type;
    while(~scanf("%d%d%d",&W,&H,&N)){
        int xl=0,xr=W,yl=0,yr=H;
        for(int i=0;i<N;i++){
            scanf("%d%d%d",&x,&y,&type);
            if(type==1&&xl<x){
                xl=x;
            }
            if(type==2&&xr>x){
                xr=x;
            }
            if(type==3&&yl<y){
                yl=y;
            }
            if(type==4&&yr>y){
                yr=y;
            }
        }
        if(yr-yl>0&&xr-xl>0){
            printf("%d\n",(yr-yl)*(xr-xl));
        }
        else{
            printf("0\n");
        }
    }
    return 0;
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;

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

    if(A <= C && C <= B) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    int X, t; cin >> X >> t;
    cout << max(0, X-t) << endl;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>
#include <unordered_map>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

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

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

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

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

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

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

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

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

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

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

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

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

int main(void){
  ll N, M, A, B, C, D, E, F, K,W, H, P, Q, R, X, Y;
  ll ans;
  string S, T;
  cin >> A >> P;
  cout << (A*3+P)/2<<endl;


}


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

struct node {
  int key;
  struct node *right;
  struct node *left;
  struct node *parent;
};

typedef struct node* Nodepointer;
Nodepointer nil, root;

Nodepointer find(Nodepointer u, int k){
  while( u != nil && k != u->key ){
    if( k < u->key ) u = u->left;
    else u = u->right;
  }
  return u;
}

void insert(int k){
  Nodepointer x, y, z;
  y = nil;
  x = root;

  z = (Nodepointer)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(Nodepointer u){
  if( u == nil ) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}

void preorder(Nodepointer u){
  if( u == nil ) return;
  printf(" %d", u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n, i, x;
  char com[7];

  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ ){
    scanf("%s",com);
    if( com[0] == 'f' ){
      scanf("%d", &x);
      Nodepointer t = find(root, x);
      if( t != nil ) printf("yes\n");
      else printf("no\n");
    }
    else if( strcmp("insert",com) == 0 ){
      scanf("%d", &x);
      insert(x);
    }
    else if( strcmp("print",com) == 0 ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



Measured memory_bytes: 20480
//↓template↓

#include "bits/stdc++.h"
using namespace std;
#define Would
#define you
#define all(n)  n.begin(),n.end()
#define rall(n) n.rbegin(),n.rend()
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
const double pi = acos(-1);
const ll SIZE = 1 << 17;
int dx[] = { 1,0,-1,0 }, dy[] = { 0,1,0,-1 }, alp[30];
ll fac[200005], finv[200005], inv[200005];
vector<ll>dij;
struct edge { ll to, cost; };
vector<vector<edge> >G;

ll mod_pow(ll a, ll b) {
	ll res = 1, mul = a;
	for (int i = 0; i < 31; ++i) {
		if (b >> i & 1) {
			res *= mul;
			res %= MOD;
		}
		mul = (mul * mul) % MOD;
	}
	return res;
}

void addedge(int from, int to, int cost) {
	G[from].push_back({ to,cost });
	G[to].push_back({ from,cost });
}


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) {
	for (auto &e : t) fill_v(e, v);
}

template<typename T>
void outp(vector<T>v) {
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i];
		if (i != v.size() - 1) { cout << " "; }
	}
}

//↑template↑



int main() {

	string h;
	cin >> h;
	sort(all(h));
	if (h[0] == h[1] && h[1] != h[2] && h[2] == h[3]) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }




}

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int a;
  int b;
  scanf("%d %d" ,&a , &b);
  if (a < b){
    printf("a < b\n");  
  }else if (a == b){
    printf("a == b\n");
  }else if (a > b) {
    printf("a > b\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//#include<math.h>
//#include<queue>
#include<algorithm>
//#include<iostream>
//#include<assert.h>
using namespace std;

int a,b,c;
#define maxn 2000011
int qa[maxn],qb[maxn],qc[maxn],dis[222][222][222],head,tail;
int main()
{
	scanf("%d%d%d",&a,&b,&c);
	head=0; tail=1;
	for (int i=0;i<=200;i++)
		for (int j=0;j<=200;j++)
			for (int k=0;k<=200;k++)
				dis[i][j][k]=0x3f3f3f3f;
	qa[0]=a; qb[0]=b; qc[0]=c; dis[a][b][c]=0;
	if (a==b && b==c) {puts("0"); return 0;}
	while (head!=tail)
	{
		int na=qa[head],nb=qb[head],nc=qc[head]; head++;
		int xa,xb,xc;
		
		xa=na+1; xb=nb+1; xc=nc; 
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
		
		xa=na; xb=nb+1; xc=nc+1;
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
		
		xa=na+1; xb=nb; xc=nc+1;
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
		
		xa=na+2; xb=nb; xc=nc;
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
		
		xa=na; xb=nb+2; xc=nc;
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
		
		xa=na; xb=nb; xc=nc+2;
		if (dis[xa][xb][xc]==0x3f3f3f3f)
		{
			if (xa==xb && xb==xc) {printf("%d\n",dis[na][nb][nc]+1); return 0;}
			qa[tail]=xa; qb[tail]=xb; qc[tail]=xc; tail++; dis[xa][xb][xc]=dis[na][nb][nc]+1;
		}
	}
	
	return 0;
}

Measured memory_bytes: 47104
#include <iostream>
using namespace std;
int main(void){
    int N = 1;
    int primes[1300] = {0};
    int i, j;
    bool isprime;
    int input;
    int count = 0;
    
    primes[0] = 2;
    
    for(i = primes[N - 1] + 1; i < 10000; i++){
        isprime = true;
        for(j = 0; j < N; j++){
            if(!(i % primes[j])){
                isprime = false;
                break;
            }
        }
        if(isprime){
            primes[N] = i;
            N++;
        }
    }
    
//    cout << N << endl;
//    for(i = 0; i < N; i++) cout << primes[i] << " ";
    
    cin >> input;
    while(cin >> input){
//        cout << input;
        isprime = true;
        for(j = 0; j < N; j++){
            if((primes[j] < input) && !(input % primes[j])){
                isprime = false;
            }
        }
        if(isprime) count++;
    }
    
    cout << count << endl;
    return 0;
}

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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

ld d[8][8];

int main(){
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    rep(i, n) rep(j, n) {
        ld d1 = sqrtl((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        d[i][j] = d1;
        d[j][i] = d1;
    }
    ld sum = 0.0;
    int count = 0;
    vi p(n);
    rep(i, n) p[i] = i;
    do {
        ld dist = 0.0;
        rep(i, n-1) dist += d[p[i]][p[i+1]];
        sum += dist;
        ++count;
    } while (next_permutation(all(p)));
    sum /= count;
    printf("%Lf\n", sum);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int m, t, p, r;
    while (cin >> m >> t >> p >> r && m){
        vector<pair<P, int> > a(t);
        REP(i,t) a[i].second = -(i+1);
        int w[50][10] = {};
        while (r--){
            int x, y, z, j;
            cin >> z >> x >> y >> j;
            x--;
            y--;
            if (j != 0){
                w[x][y]++;
            }else{
                a[x].first.first--;
                a[x].first.second += z + 20 * w[x][y];
            }
        }
        sort(a.begin(), a.end());
        cout << -a[0].second;
        FOR(i,1,t-1){
            if (a[i].first == a[i-1].first) cout << "=";
            else cout << ",";
            cout << -a[i].second;
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3016
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();

		int ans = Integer.MAX_VALUE;
		for (int i = 1; i < n; i++) {
			int a = i;
			int b = n - i;
			int sum = 0;
			while (a > 0) {
				sum += a % 10;
				a /= 10;
			}
			while (b > 0) {
				sum += b % 10;
				b /= 10;
			}
			ans = Math.min(ans, sum);
		}
		System.out.println(ans);
	}
}


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

int main(){
  int n, x, y;
  cin >> n;
  for(int i=1; n >= i; i++){
    if(i == 0){
      x += 800;
    }else if((i % 15) == 0){
      x += 600;
    }else{
      x += 800;
    }
  }
  //int result = x - y;
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;
typedef long long LL;

int main()
{
    int a,b,c,x,y;
    while(scanf("%d%d%d%d%d",&a,&b,&c,&x,&y)==5){
        LL ans=0;
        if(a+b>2*c){
            if(x>=y){
                ans+=y*c*2;
                if(a>=c*2){
                    ans+=(x-y)*c*2;
                }
                else ans+=(x-y)*a;
            }
            else{
                ans+=x*c*2;
                if(b>=c*2){
                    ans+=(y-x)*c*2;
                }
                else ans+=(y-x)*b;
            }
        }
        else{
            ans+=a*x+y*b;
        }
        printf("%lld\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    ll n; cin >> n;
    vector<string> v;
    ll res = 0;
    ll a_end_num = 0;
    ll b_start_a_end_num = 0;
    ll b_start_num = 0;
    REP(i, n) {
        string tmp; cin >> tmp;
        v.push_back(tmp);

        FOR(j, 0, tmp.size()-2) {
            if (tmp[j] == 'A' && tmp[j+1] == 'B') {
                res++;
            }
        }

        if ((tmp.substr(tmp.size()-1, 1) == "A") && (tmp.substr(0, 1) == "B")) {
            b_start_a_end_num++;
        } else if (tmp.substr(tmp.size()-1, 1) == "A") {
            a_end_num++;
        } else if (tmp.substr(0, 1) == "B") {
            b_start_num++;
        }
    }
    // sort(ALL(v));
    // Aおわり、Bはじまり、Aおわり、Bはじまり、を繰り返せるだけ繰り返してインクリメント。2で割ったのをresに追加
    // 最初はbaがあってもaから消化。つぎはbaがあるかぎりba。なくなったらa
    // REP(i, n) {
    //     cout << v[i] << endl;
    // }
    bool before_a = false;
    // cout << res << endl;
    // cout << a_end_num << " " << b_start_num << " " << a_end_b_start_num << endl;
    FOR(i, 0, 12345) {
        if (i == 0) {
            // 1つめの文字列だけ処理が特殊になるので分岐
            if (a_end_num > 0) {
                a_end_num--;
                before_a = true;
            } else if (b_start_a_end_num > 0) {
                b_start_a_end_num--;
                before_a = true;
            } else {
                // Aおわりがないと以降ABを作れないので抜ける
                break;
            }
        } else if (before_a) {
            // 直前がAで終わっている場合はBを付けに行く。なおかつ次につなげるためにA終わりのものから優先して取得
            if (b_start_a_end_num > 0) {
                res++;
                b_start_a_end_num--;
                before_a = true;
            } else if (b_start_num > 0) {
                res++;
                b_start_num--;
                before_a = false;
            } else {
                before_a = false;
            }
        } else if (a_end_num > 0) {
            // before_aでなくても、Aで終わることができるなら追加
            a_end_num--;
            before_a = true;
        } else {
            break;
        }
        // cout << a_end_num << " " << b_start_num << " " << a_end_b_start_num << endl;
    }
    // cout << a_end_num << " " << b_start_num << " " << a_end_b_start_num << endl;
    cout << res << endl;
    return 0;
}

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

#define MOD 1000000007

string S[1003];
int dp[1003][1003];

int main() {

    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    
    int H, W;
    cin >> H >> W;
    
    for(int i=1; i<=H; i++)
    {
        cin >> S[i];
        S[i] = "*" + S[i];
    }
    
    for(int i=1; i<=H; i++)
        for(int j=1; j<=W; j++)
        {
            if(S[i][j] == '#')
                continue;
            if(i == 1 && j == 1)
            {
                dp[i][j] = 1;
                continue;
            }
            
            dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % MOD;
        }
    
    cout << dp[H][W] << "\n";
    return 0;
}

Measured memory_bytes: 5248
n,m=map(int,input().split())
S=[list(map(int,input().split()))[1:] for i in range(m)]
P=list(map(int,input().split()))
cnt=0
for i in range(2**n):
    pattern=format(i,"b").zfill(n)
    point=0
    for j in range(m):
        swi=0
        for k in S[j]:
            if pattern[k-1]=="1":
                swi +=1
        if swi%2==P[j]:
            point +=1
    if point==m:
        cnt +=1

print(cnt)

Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int main() {
	int a, b, c; cin >> a >> b >> c;
	if (b - a == c - b)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 3568