akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int k = sc.nextInt();
		int s = sc.nextInt();

		long ret = 0;
		for (int x = 0; x <= Math.min(k, s); x++) {
			for (int y = 0; y <= Math.min(k, s - x); y++) {
				if (s - x - y <= k) {
					ret++;
				}
			}
		}

		pr.println(ret);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9812
n, y = map(int, input().split())
for i in range(n + 1):
    for j in range(n - i + 1):
        if i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            exit()
print(-1, -1, -1)


Measured memory_bytes: 40684
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	string a, b, c;
	cin >> a >> b >> c;

	Int lena, lenb, lenc;
	lena = a.size();
	lenb = b.size();
	lenc = c.size();

	if (a[lena-1]==b[0]&&b[lenb-1]==c[0]) {
		cout << "YES" << "\n";
	}
	else {
		cout << "NO" << "\n";
	}
}


Measured memory_bytes: 256
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();


		Map<String,Long> map = new TreeMap<>();
		long cnt = 0;
		
		for(int i = 0; i < n; i++) {
			String s = stdIn.next();
			if(map.containsKey(s)) {
				map.put(s,map.get(s)+1);
				if(cnt < map.get(s)) {
					cnt = map.get(s);
				}
			}else {
				map.put(s,(long)1);
				if(cnt==0) {
					cnt=1;
				}
			}
		}

		for(String s: map.keySet()) {
			if(map.get(s)==cnt) {
				System.out.println(s);
			}
		}


	}

}


Measured memory_bytes: 83304
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            string s;
            int k,i,j;
            cin>>k;
            cin>>s;
            if(s.length()<=k)
            {
                cout<<s<<endl;
                return 0;
            }
            for(i=0;i<k;++i)
            {
                cout<<s[i];
            }
            cout<<"..."<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());
typedef long long ll;
const int mod = 1000000007;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

int main()
{
  int N;
  cin >> N;
  vector<long long> C(N);
  rep(i, N)
  {
    cin >> C[i];
  }
  vector<long long> CC;
  rep(i, N)
  {
    if (CC.size() == 0 || CC.back() != C[i])
      CC.push_back(C[i]);
  }

  vector<mint> dp(N + 1);
  map<long long, mint> count;
  dp[0] = 1;
  rep(i, CC.size())
  {
    dp[i + 1] += dp[i] + count[CC[i]];
    count[CC[i]] += dp[i];
  }

  mint ans = dp[CC.size()];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 20200
#include<iostream>
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    
    int N, X, Y; cin >> N >> X >> Y;
    X--;
    Y--;
    
    int d[N][N];
    int ans[N];
    
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            d[i][j] = j-i;
            d[j][i] = j-i;
        }
    }
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            chmin(d[i][j], d[i][X]+d[Y][j]+1);
            d[j][i] = d[i][j];
        }
    }
    for(int i=1; i<N; i++) ans[i] = 0;
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            ans[d[i][j]]++;
        }
    }
    /*
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cout << d[i][j] << " ";
        }
        cout << endl;
    }  
    */   
    for(int i=1; i<N; i++){
        cout << ans[i] << endl;
    } 
}

Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int N;
int arr[15];
int left_arr[15]={0},right_arr[15]={0};
bool flag;

void dfs(int l,int r){
    if(l>1&&left_arr[l-1]<left_arr[l-2]){
        return;
    }
    else if(r>1&&right_arr[r-1]<right_arr[r-2]){
        return;
    }

    if(l+r==10){
        flag=true;
        return;
    }


    left_arr[l]=arr[l+r];
    dfs(l+1,r);

    right_arr[r]=arr[l+r];
    dfs(l,r+1);


}

int main(){
    cin >> N;
    while(N>0){
        N--;

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

        flag=false;
        dfs(0,0);
        if(flag){
            cout<<"YES\n";
        }else{
            cout<<"NO\n";
        }


    }


    return 0;
}





Measured memory_bytes: 3084
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    double c = Math.toRadians(sc.nextInt());
    double s = 0.5 * a * b * Math.sin(c);
    double lengthC = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) - 2 * a * b * Math.cos(c));
    double l = a + b + lengthC;
    double h = b * Math.sin(c);
    System.out.println(s);
    System.out.println(l);
    System.out.println(h);
  }
}



Measured memory_bytes: 26272
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args)
	{
		Scanner s=new Scanner(System.in);
		
		int n=s.nextInt();
		long d=2*s.nextInt();
		long a=s.nextInt();
		
		pair[] arr=new pair[n];
		
		for(int i=0;i<n;i++)
		{
			int pos=s.nextInt();
			int power=s.nextInt();
			
			pair p=new pair(pos,power);
			arr[i]=p;
		}
		
		Arrays.sort(arr,new comp());
		
		long[] diff=new long[n+1];
		diff[0]=arr[0].power;
		
		for(int i=1;i<n;i++)
		{
			diff[i]=arr[i].power-arr[i-1].power;
		}
		
		long ans=0;
		
		for(int i=0;i<n;i++)
		{
			if(diff[i]>0)
			{
				double left=diff[i];
				long moves=(long)Math.ceil(left/a);
				ans=ans+moves;
				diff[i]=diff[i]-moves*a;
				
				int index=bs(arr,arr[i].pos+d,n);
				diff[index]=diff[index]+moves*a;
			}
			
			diff[i+1]=diff[i+1]+diff[i];
			
		}
		
		System.out.println(ans);
		
	}
	
	public static int bs(pair[] arr,long range,int n)
	{
		int start=0;
		int end=n-1;
		
		int ans=-1;
		
		while(start<=end)
		{
			int mid=(start+end)/2;
			
			if(arr[mid].pos<=range)
			{
				ans=mid;
				start=mid+1;
			}
			else
			{
				end=mid-1;
			}
		}
		
		return ans+1;
	}
	
}

class pair
{
	int pos;
	long power;
	
	public pair(int pos,long power)
	{
		this.pos=pos;
		this.power=power;
	}
}

class comp implements Comparator<pair>
{
	public int compare(pair a,pair b)
	{
		return a.pos-b.pos;
	}
}

Measured memory_bytes: 112968
# coding: utf-8
"""Snuke's Coloring 2 (ABC Edit)

@author: hijiri.n
@modified: 11-19-2016

"""

def data(): return list(map(int, input().split()))


def solve(init, point):
    w, h, N = init
    rect = [0, w, 0, h]

    for p in point:
        x, y, a = p

        if [1, -1][a % 2] * ([x, y][a > 2] - rect[a - 1]) < 0:
            rect[a - 1] = [x, y][a > 2]

        if rect[1] <= rect[0] or rect[3] <= rect[2]:
            return 0
        
    return (rect[1] - rect[0]) * (rect[3] - rect[2])

# Input init & points data
i_in = data()
p_in = [data() for _ in range(i_in[-1])]
print(solve(i_in, p_in))

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
int main() {
  int n, m, t = 0;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    cin >> a[i];
    t += a[i];
  }
  if (n - t < 0) {
    cout << -1 << endl;
  } else {
    cout << n - t << endl;
  }
}

Measured memory_bytes: 3680
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>
#include <unordered_set>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define rep(i, n) for(int i = 0;i < n;i++)
const int INF = 1LL << 30;

int MOD = 1000000007;

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

    int n; cin >> n;

    std::vector<std::vector<int>> a(n, std::vector<int>(n-1));
    std::vector<int> progress(n, 0);

    rep(i,n) rep(j,n-1){cin >> a[i][j]; a[i][j]--;}

    int pair_num = 1;
    int cnt = 0;

    std::queue<int> possibility; rep(i,n) possibility.push(i); possibility.push(-1);

    std::unordered_set<int> played_game = {};

    while(possibility.size()>1){

        if(possibility.front() == -1){ cnt++; possibility.pop(); possibility.push(-1); played_game.clear();}

        //cout << "cnt: " << cnt << endl;
        int player1_id = possibility.front(); possibility.pop();
        int player2_id = a[player1_id][progress[player1_id]];

        if(progress[player1_id] == n-1 || progress[player2_id] == n-1) continue;

        if (player1_id==a[player2_id][progress[player2_id]] && played_game.find(player1_id) == played_game.end() && played_game.find(player2_id) == played_game.end()){
            pair_num++;
            progress[player1_id]++; played_game.emplace(player1_id);
            progress[player2_id]++; played_game.emplace(player2_id);
            //cout << "Progress made for " << player1_id << " and " << player2_id << endl;
            possibility.push(player1_id);
            possibility.push(player2_id);      
        }
        
        //cout << possibility.size() << endl;

    }

    bool is_complete = true;
    rep(i,n) if(progress[i]!=n-1) is_complete=false;

    if(is_complete) cout << cnt << endl;
    else cout << -1 << endl;


    return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<functional>
#include<algorithm>
#include<bitset>
#include<utility>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	string s;
	cin>>s;
	map<char,int>m;
	for(int i=0;i<s.length();i++)
		m[s[i]]++;
	for(map<char,int>::iterator it=m.begin();it!=m.end();it++)
		if(it->second!=2)
		{
			puts("No");
			return 0;
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
	int a = scan.nextInt();
    int b = scan.nextInt();
    if (a>b){
      System.out.println("safe");
    } else {
      System.out.println("unsafe");
    }
    scan.close();
  }
}

Measured memory_bytes: 35800
import std.stdio;
import std.c.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;
 
void main() {
    int N, M, P;
    alias Tuple!(int, int) Pair;
    Pair[] Pos;

    bool input() {
        Pos = [];
        readf("%d %d %d\n", &N, &M, &P);
        if (N == 0 && M == 0 && P == 0) return false;
        for (int i = 0; i < P; i++) {
            int x, y; readf("%d %d\n", &x, &y);
            x--; y--;
            Pos ~= Pair(x, y);
        }
        return true;
    }

    void solve() {
        int[][][] F = new int[][][](N, N, N);

        void dump() {
            for (int z = 0; z < N; z++) {
                for (int x = 0; x < N; x++) {
                    for (int y = 0; y < N; y++) {
                        printf("%d ", F[x][y][z]);
                    }
                    printf("\n");
                }
                printf("\n");
            }
            printf("\n");
        }

        int Check() {
            const dx = [1, 0, 0, 1,  1, 1,  1, 0,  0, 1,  1,  1,  1],
                  dy = [0, 1, 0, 1, -1, 0,  0, 1,  1, 1, -1,  1, -1],
                  dz = [0, 0, 1, 0,  0, 1, -1, 1, -1, 1,  1, -1, -1];
            // 0 => Draw, 1 => Black, 2 => White
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    for (int k = 0; k < N; k++) {
                        int X = F[i][j][k];
                        if (X == 0) continue;
                        for (int a = 0; a < 13; a++) {
                            int Count = 0;
                            int x = i, y = j, z = k;
                            while (0 <= x && x < N &&
                                   0 <= y && y < N &&
                                   0 <= z && z < N && F[x][y][z] == X) {
                                Count++;
                                x += dx[a];
                                y += dy[a];
                                z += dz[a];
                            }
                            if (Count >= M) {
                                return X;
                            }
                        }
                    }
                }
            }
            return 0;
        }

        for (int i = 0; i < P; i++) {
            int bw = i % 2 + 1; // 1 => Black, 2 => White
            int x = Pos[i][0], y = Pos[i][1];
            for (int j = 0; ; j++) {
                if (F[x][y][j] == 0) {
                    F[x][y][j] = bw;
                    break;
                }
            }
            int Winner = Check();
            if (Winner == 1) {
                printf("Black %d\n", i + 1);
                return;
            } else if (Winner == 2) {
                printf("White %d\n", i + 1);
                return;
            }
        }
        printf("Draw\n");
    }

    while (input()) solve();
}

Measured memory_bytes: 2112
#include<bits/stdc++.h>
using namespace std;
int ar[1000100] , dp[100010] , n , z ;
int frog(int i)
{
  //  cout<<i<<endl ;
    if(i+1 > n)
    {
  //      cout<<i<<endl ;
         return 0 ;
    }
  //  if(dp[i] != -1) return dp[i] ;
 //   cout<<"1"<<endl ;
    int a = 0 , b = 0 , k = 0 , l = 0 ;
    if(dp[i]!=-1)return dp[i] ;
    a = abs(ar[i]-ar[i+1]) ;
    k = frog(i+1)+a ;
  //  cout<<"1"<<endl ;
    if(i+2<=n)
    {
        b = abs(ar[i]-ar[i+2]) ;
        l = frog(i+2)+b ;
    }
    else l = 1000000 ;
    dp[i] = min(k,l) ;
//    cout<<i<<" "<<k<<" "<<l<<endl ;
    return dp[i] = min(k,l) ;
}
int main()
{
    memset(dp,-1,sizeof(dp)) ;
    cin>>n ;
    for(int i = 1 ; i <= n ;i++)
    {
        cin>>ar[i] ;
    }
    int k = frog(1) ;
  //  for(int i = 1 ; i <= n ; i++) cout<<dp[i]<<" " ;
    cout<<k<<endl ;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}


int vis[N];
int diff[N];
unordered_map<int,vec> fr,en;
void dfs(int u, int cnt) {
    if(vis[u] != 0) {
        return;
    }
    vis[u] = cnt;
    for(auto it : fr[u]) {
        if(vis[it] == 0) {
            dfs(it,cnt);
        }
    }
}


void test_case() {

    
   
        int n, m, k;
        cin>>n>>m>>k;


        

        rep(i,m) {
            int a,b;
            cin>>a>>b;

            fr[a].pb(b);
            fr[b].pb(a);
        }

        
        int cnt = 1;
        for(int i=1; i<=n; i++) {
            if(vis[i] == 0) {
                dfs(i,cnt);
                cnt++;
            }
        }

        unordered_map<int,int > temp;

        for(int i=1; i<=n; i++) {
            //  cout<<vis[i]<<" ";
            if(vis[i] != 0)
                temp[vis[i]]++;
        }

        // cout<<endl;

        rep(i,k) {
            int a,b;
            cin>>a>>b;

            if(vis[a] == vis[b]) {
                diff[a]--;
                diff[b]--;
            }

        
        }



        for(int i=1; i<=n; i++) {
            // cout<<temp[vis[i]]<<" ";
            //  cout<<fr[i].size()<<" ";
            int ans = temp[vis[i]] - 1 - fr[i].size() + diff[i];
            cout<<max(0,ans)<<" ";;
        }

            cout<<endl;



    



}


int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);

    //    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);


    int t = 1;
   //  cin >> t;
    while(t--)
    {   
        test_case();
    }
}


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

int main() {
  string str;
  cin >> str;
  
  vector<string> vecStr(str.size());
  vector<int> vecInt(str.size(),0);
  
  int cnt = 0;
  for(int i = 0; i < str.size(); i++){
    if(cnt == 0){
      vecStr.at(i) = str.at(i);
      vecInt.at(i) += 1;
      cnt++;
      continue;
    }
    
    for(int j = 0; j < cnt; j++){
     if(vecStr.at(j) == ""s + str.at(i)){
       //一致発見
       vecInt.at(j) += 1;
     }else{
      if(j == cnt-1){
       // 不一致の場合、リストの最後に追加
        vecStr.at(j+1) = str.at(i);
        vecInt.at(j+1) += 1;
      }
     }
    }
  }
  bool check = true;
  for(int k = 0; k < vecInt.size(); k++){
    if( vecInt.at(k) % 2 == 1) check = false;
  }
    
  if(check == true){
    cout << "Yes"; 
  }else{
    cout << "No"; 
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 998244353;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd_calc(T a, T b){ if(b){ return gcd_calc(b, a % b); }else{ return a; }}
template<class T> T gcd(T a, T b){ if(a < b) swap(a, b); return gcd_calc(a, b); }
template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
inline int at(int x, int k){ return (x >> k) & 1; }
random_device rnd;

string day[7] =  {"Sunny", "Cloudy", "Rainy"};

int main(){
    string S;
    cin >> S;
    sort(all(S));
    Yes(S[0] == S[1] && S[2] == S[3] && S[1] != S[2]);
}


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

using namespace std;

const int N = 1000 + 10;

int a[N];

int main()
{
	int res, n, k, i;
	cin>>n>>k;
	for (i=0; i<n; i++) cin>>a[i];
	sort(a, a + n);
	res = 0;
	for (i=0; i<k; i++) res += a[i];
	cout<<res<<endl;
	return 0;
}

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

static const int MAX=100;

int selectionSort(int A[],int N){
  int minj;
  int sw=0;
  bool flag=0;

  for(int i=0;i<N;i++){
    minj=i;
    flag=0;
    for(int j=i+1;j<N;j++){
      if(A[minj]>A[j]){
	minj=j;
	flag=1;
      }
    }
    if(flag)
      sw++;
    swap(A[i],A[minj]);
  }
    return sw;
}

int main(void){
  int A[MAX],N;
  int sw;

  cin>>N;
  for(int i=0;i<N;i++)cin>>A[i];

  sw=selectionSort(A,N);

  for(int i=0;i<N;i++){
    if(i)
      cout<<" ";
    cout<<A[i];
  }
  cout<<endl<<sw<<endl;

  return 0;
}

  
  

    

Measured memory_bytes: 3088
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MEM(a,b) memset(a,b,sizeof(a))
#define MP(a,b) make_pair(a,b)
#define PB push_back
#define lp (p << 1)
#define rp (p << 1|1)

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const int mod = (int)(1e9 + 7);

char s[100010];

int main(){
	scanf("%s",s + 1);
	int len = strlen(s + 1);
	int ans = 0,l = 1,r = len;
	while(l < r){
		if(s[l] == s[r]){
			l++;
			r--;
		}
		else if(s[l] == 'x'){
			ans++;
			l++;
		}
		else if(s[r] == 'x'){
			ans++;
			r--;
		}
		else{
			ans = -1;
			break;
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int N;
    cin >> N;
    cout << (N >= 1000 ? "ABD" : "ABC") << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<map>
#include<deque>
#include<math.h>
using namespace std;
#define ll long long
ll mp[100][100];
ll visited[100][100];
void dfs(ll w,ll h,ll i,ll j){
    ll a,b;
    visited[i][j]=1;
    for(a=i-1;a<=i+1;a++){
        for(b=j-1;b<=j+1;b++){
            if(a>=0&&a<h&&b>=0&&b<w&&mp[a][b]==1&&visited[a][b]==0)dfs(w,h,a,b);
        }
    }
    return ;
}

int main(){
    while(true){
        ll w,h;
        cin >> w >> h;
        if(w==0&&h==0) return 0;
        ll i,j;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                cin >> mp[i][j];
                visited[i][j]=0;
            }
        }
        ll ans =0;
        for(i=0;i<h;i++){
            for(j=0;j<w;j++){
                if(mp[i][j]==1&&visited[i][j]==0){
                    ans++;
                    dfs(w,h,i,j);
                }
            }
        }
        cout << ans <<endl;
    }
}


Measured memory_bytes: 3344
def examB():
    N = I()
    A = SI(); B = SI(); C = SI()
    ans = 2*N
    for i in range(N):
        cur = 0
        if A[i]==B[i]:
            cur +=1
        if B[i]==C[i]:
            cur +=1
        if C[i]==A[i]:
            cur +=1
        ans -=min(2,cur)
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examB()


Measured memory_bytes: 38384
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n, a, b;
ll mn = 4e18;
ll sum;
bool v = false;

int main()
{
    scanf("%lld", &n);
    while(n--)
    {
        scanf("%lld%lld", &a, &b);
        sum += a;
        if(a > b)
        {
            v = true;
            mn = min(mn, b);
        }
    }
    printf("%lld\n", (sum - mn) * v);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define rep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
	char s[13];
	cin >> s;
	int count = 0;
	rep(i, 0, 13) {
		if(i!=4) cout << s[count++];
		else cout << " ";
	}
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const K = parseInt(args[0][1], 10)
	console.log(N % K)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 7372
#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 <stdio.h>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,a,n) for(ll i =(a);i<(n);++i)
#define urep(i,a,n) for(ll i = (a);i>=(n);--i)
#define all(x) (x).begin(),(x).end()
#define INF 1e18
const int mod = 1e9 + 7;
typedef long long ll;
using namespace std;
ll dx[4] = { 1,-1,0,0 };
ll dy[4] = { 0,0,1,-1 };
ll N,M,X,Y,A,B,C,Q,K,R,W,H,P,L;
string S,T;
ll ans;
ll x[101010];
ll y[101010];
ll a[101010];
ll b[101010];
ll c[101010];
ll t[101010];
ll p[101010];
ll n[101010];
ll l[101010];
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	else return gcd(b, a%b);
}
struct Edge{
	ll to,cost;
	 Edge(ll to, ll cost) : to(to), cost(cost) {}
};
typedef vector<vector<Edge> > AdjList;
AdjList graph;
vector<ll> dist;

struct UnionFind {
    vector<ll> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
	vector<ll> size;
    UnionFind(ll N) : par(N),size(N) { //最初は全てが根であるとして初期化
        for(ll i = 0; i < N; i++) par[i] = i;
		for(ll i = 0; i < N; i++) size[i] = 1;
    }

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

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

    }

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

int main() {
	cin>>S;
	ans=0;
	ll pos=INF;
	rep(i,0,S.size()){
		if(S[i]=='B'){
			pos=i;
			break;
		}
	}
	rep(i,pos+1,S.size()){
		if(S[i]=='W'){
			ans+=i-pos;
			pos++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 640
def main():
    #from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = list(map(int, input().split()))
    #a = [input().split() for i in range(n)]
    #a = [int(input()) for i in range(n)]
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0
    a,b,c=map(int,input().split())
    if c-a-b < 0:
        print('No')
        return 0
    if 4*a*b < (c-a-b)**2:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
N, K = map(int, input().split())

okashi_sunuke = [0] * N
for i in range(K):
    d = int(input())
    a_list = list(map(int, input().split()))
    for a in a_list:
        okashi_sunuke[a-1] = 1

count = 0
for i in range(N):
    if okashi_sunuke[i] == 0:
        count += 1
print(count)

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

int main() {
	long long n;cin>>n;
	vector<int> a(n),s(n),l(n+1);
	l[0]=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		s[i]=a[i];
	}
	sort(s.begin(),s.end());
	int right=n-1;
	int left=0;
	while(right!=left){
		int j=(right+left+1)/2;
		int num=s[j];
//		cout<<i<<' '<<num<<endl;
		for(int i=0;i<n;i++){
			if(a[i]>=num){
				l[i+1]=1;
			}else{
				l[i+1]=-1;
			}
		}
		for(int i=1;i<=n;i++)l[i]+=l[i-1];
//		for(int i=0;i<=n;i++)cout<<l[i]<<' ';
//		cout<<endl;
		long long count;
		long long t=0;
		vector<long long> bit(2*n+2,0);
		for(int i=0;i<n+1;i++){
			int first=l[i]+n+1;
//			int k=0;
			for(int x=first;x<=2*n+1;x+=x&-x){
				bit[x]++;
//				cout<<x;
//				if(k<10){
//					k++;
//				}else{
//					break;
//				}
			}
			long long sum=0;
//			cout<<'A';
			for(int x=first;x>=1;x-=x&-x)sum+=bit[x];
			t+=i+1-sum;
		}
		count=n*(n+1)/2-t;
//		cout<<i<<' '<<count<<endl;
		if(count>=(n*(n+1)/2+1)/2){
			left=j;
		}else{
			right=j-1;
		}
	}
	cout<<s[left]<<endl;
	return 0;
}

Measured memory_bytes: 3044
#include<bits/stdc++.h>
using namespace std;
int n;
int existnuma(int p[], int a){
    for(int i = 0; i < n; i++){
        if(p[i] == a) return 1;
    }
    return 0;
}

int main(){
    int x, p[110];
    cin >> x >> n;
    if(n == 0){
        cout << x << endl;
        return 0;
    }

    for(int i = 0; i < n; i++) cin >> p[i];

    if(existnuma(p, x) == 0){
        cout << x << endl;
        return 0;
    }

    for(int i = 1; i < 100; i++){
        if(existnuma(p, x - i) == 0){
            cout << x - i << endl;
            return 0;
        }
        if(existnuma(p, x + i) == 0){
            cout << x + i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
 
int main(){
	int n;
    cin>>n;
    // int a[n],b[n];
    // int amax_index=0;

    // for(int i=0;i<n;i++){
    //     cin>>a[i]>>b[i];
    //     if(i!=0){
    //         if(a[i-1]<a[i]){
    //             amax_index=i;
    //         }
    //     }
    // }
    int a,b;
    int amax;
    int ans;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        if(amax<a){
            amax=a;
            ans=a+b;
        }
    }

    // int ans=a[amax_index];
    // while(b[amax_index]!=0){
    //     b[amax_index]--;
    //     ans++;
    // }
	
    
	
    // cout << ans+b[amax_index] << endl;
     cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)
#define pb push_back
#define deb(x) cout<<#x<<" "<<x<<endl;
#define deb2(x, y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define deb3(x, y, z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
const int mod = 1e9 + 7;
template<class T, class U> inline void add_self(T &a, U b){a += b;if (a >= mod) a -= mod;if (a < 0) a += mod;}
template<class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void max_self(T &x, U y) { if (y > x) x = y; }

template <typename T>void print(T v, bool show_index = false){int w = 2;if(show_index){for(int i=0; i<v.size(); i++)cout<<setw(w)<<i<<" ";cout<<endl;}for(auto i= v.begin(); i!=v.end(); i++)cout<<setw(w)<<*i<<" ";cout<<endl;}
template <typename T>void print_vv(T v){if(v.size()==0) {cout<<"Empty"<<endl; return;} int w = 3;cout<<setw(w)<<" ";for(int j=0; j<v[0].size(); j++)cout<<setw(w)<<j<<" ";cout<<endl;for(auto i= 0; i<v.size(); i++){cout<<i<<" {";for(auto j = 0; j!=v[i].size(); j++){cout<<setw(w)<<v[i][j]<<",";}cout<<"},"<<endl;}cout<<endl;}
template <class T, class U> void print_m(map<T,U> m, int w=3){if(m.empty()){cout<<"Empty"<<endl; return;}for(auto x: m)cout<<"("<<x.first<<": "<<x.second<<"),"<<endl;cout<<endl;}

int main(){
    int k, n;
    while(cin>>k>>n){
        vi a(n);
        forn(i,n) cin>>a[i];
        // print(a);


        vi dists;
        forn(i,n-1)
            dists.push_back(a[i+1]-a[i]);
        
        dists.push_back(k - a[n-1] + a[0]);
        // print(dists);

        int mx = *max_element(all(dists));
        ll out = accumulate(all(dists),ll(0));
        // deb(out);
        cout<<out - mx<<endl;
        // cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 2168
#include <stdio.h>

int main() {
	int n {};
  	scanf("%d", &n);
  
  	long long total {};
  	for(int i=0; i<=n; i++) {
    	if(i%3 != 0 && i%5 != 0) {
        	total += i;
        }
    }
  
  	printf("%lld\n", total);
  	return 0;
}

Measured memory_bytes: 1732
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
map<long long,int>xyj;
vector<long long>Ve;
int main()
{
	int N;
	scanf("%d",&N);
	while(N--)
	{
		int num;
		scanf("%d",&num);
		xyj[num]++;
		if(xyj[num]==2)
		{
			xyj[num]-=2;
			Ve.push_back(num);
		}
		
		
	}
	sort(Ve.begin(),Ve.end());
	if(Ve.size()<2)
			printf("%d",0);
		else
			printf("%lld",Ve[Ve.size()-1]*Ve[Ve.size()-2]);
		printf("\n");
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

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

    string str;
    str = s.substr(0, 4);
    str += s.substr(5, 2);
    str += s.substr(8, 2);

    cout << ((str <= "20190430") ? "Heisei" : "TBD") << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 * main.cpp
 *
 *  Created on: 2017/10/22
 *      Author: sep
 */

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

inline int main001();
inline int main002();
inline int main003();
inline int main004();

int main() {

	main002();

	return 0;
}

inline int main002() {

	int num;
	int i;
	int *a;
	int odd = 0;

	cin >> num;

	a = new int[num];

	for (i = 0; i < num; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0)
			odd++;
	}

	cout << pow(3, num) - pow(2, odd);

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,w;long long weight[101],value[101];
long long dp[101][100001];
long long dpe(int i,int remw)
{
    if(i==n)return 0;

long long &ret=dp[i][remw];
  if(~ret)return ret;

 ret=dpe(i+1,remw);
  if(remw>=weight[i])
      ret=max(ret,value[i]+dpe(i+1,remw-weight[i]));

  return ret;
}



int main()
{

  cin>>n>>w;
memset(dp,-1,sizeof(dp));
for(int i=0;i<n;i++)
    cin>>weight[i]>>value[i];

cout<<dpe(0,w)<<endl;

    return 0;
}

Measured memory_bytes: 82464
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var r = Enumerable.Range(0, 13);
		var d = Enumerable.Range(0, 10).Select(i =>
		{
			var m = new int[13, 13];
			foreach (var j in r) m[(10 * j + i) % 13, j] = 1;
			return new { i, m };
		})
		.ToDictionary(_ => _.i.ToString()[0], _ => _.m);

		var m_ = new int[13, 13];
		foreach (var p in r.SelectMany(i => r.Select(j => new { i, j }))) m_[p.i, p.j] = d.Values.Sum(m => m[p.i, p.j]);
		d['?'] = m_;

		var x = new long[13];
		x[0] = 1;
		x = Console.ReadLine().Aggregate(x, (v, c) => r.Select(i => r.Sum(j => d[c][i, j] * v[j]) % 1000000007).ToArray());
		Console.WriteLine(x[5]);
	}
}


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

int main(){
  char a[3][3]={};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> a[i][j];
      if(i==j)
        cout << a[i][j] ;
    }
  }
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
S = [int(input()) for _ in range(N)]

score = {0}
for s in S:
    tmp = set()
    for i in score:
        tmp.add(s+i)  
    score |= tmp
for i in range(10,10010,10):
    if i in score:               
        score.remove(i)
print(max(score))


Measured memory_bytes: 4656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

int max_N = 100005;


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

void addDivs(set<int> &st, int t){
	for(int i = 1; i * i <= t; i++){
		if(t % i == 0){
			st.insert(i);
			st.insert(t / i);
		}
	}
}

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

	int N;
	cin >> N;

	vector<int> A(N, 0);
	rep(i, N) cin >> A[i];

	set<int> st;
	addDivs(st, A[0]);
	addDivs(st, A[1]);

	int ans = 1;

	for(int x : st){
		int cnt = 1;
		bool chk = true;
		for(int i = 0; i < N; i++){
			if(A[i] % x != 0){
				if(cnt == 1){
					cnt--;
				}else{
					chk = false;
					break;
				}
			}
		}

		if(chk){
			ans = max(ans, x);
		}
	}

	cout << ans << endl;
}


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

int main()
{
  string s;
  cin >> s;
  int q;
  cin >> q;
  
  deque<char> deq;
  for(auto c : s) deq.push_back(c);
  bool rev = false;
  rep(i,q)
  {
    int t;
    cin >> t;
    if(t == 1) rev = !rev;
    else if(t == 2)
    {
      int f;
      char c;
      cin >> f >> c;
      f--;
      if(f ^ rev) deq.push_back(c);
      else deq.push_front(c);
    }
  }
  
  if(rev) reverse(deq.begin(), deq.end());
  rep(i,deq.size()) cout << deq[i]; cout << endl;
  
  return 0;
}

Measured memory_bytes: 896
from collections import defaultdict

n = int(input())
A = list(map(int, input().split()))

Count = {x:0 for x in range(0, n)}

mod = 10**9+7
ans = 1

for i in range(n):
    now = A[i]
    if now == 0:
        ans = (3 - Count[0]) * ans % mod
        Count[0] += 1
        continue
    ans = (Count[now-1] - Count[now]) *ans  % mod
    Count[now] += 1

print(ans)
# print(Count)

Measured memory_bytes: 20960
from collections import Counter

n = int(input())
s = [input() for _ in range(n)]

counter = Counter(s)
count = counter.most_common()
most = count[0][1]

c = []

for i in range(len(count)):
    if most == count[i][1]:
        c.append(count[i][0])

c.sort()
print(*c, sep='\n')

Measured memory_bytes: 50192
#include <bits/stdc++.h>
using namespace std;
    #define fio ios_base::sync_with_stdio(false), cin.tie(NULL)
    #define ll long long
    #define int long long 
    #define ull unsigned long long 
    #define ld long double
    #define sb __builtin_popcount
    #define vi vector<int>
    #define vc vector<char>
    #define ii pair<int, int>
    #define pq priority_queue<ii, vector<ii>, greater<ii>>
    #define vii vector<ii>
    #define sz(a) int((a).size())
    #define f(a, b) for (int i = a; i < b; i++)
    #define fr(a, b) for (int i = a - 1; i >= b; i--)
    #define tr(x, m) for (auto x : m)
    #define in(a, b) (b.find(a) != string::npos)
    #define minin(a) *min_element(all(a))
    #define maxin(a) *max_element(all(a))
    #define X first
    #define Y second
    #define fill(a, x) memset(a, x, sizeof(a))
    #define pb push_back
    #define pf push_front
    #define mp make_pair
    #define all(v) v.begin(), v.end()
    #define rall(v) reverse(v.begin(), v.end())
    #define unq(v) v.erase(unique(all(v)), v.end())
    #define el "\n"
    #define mx3(a, b, c) max(max(a, b), c)
    #define mn3(a, b, c) min(min(a, b), c)
    #define S(v) accumulate(all(v), (ll)0)
    #define SP(n) cout.precision(n)
    const ld PI = atan(1.0) * 4.0;
    const ll MOD = 1e9 + 7;
    const ll INF = 1e18;
    const ld EPS = 0.0000001;



        int32_t main() {
            fio;
            SP(10);
            int n,m,x;
            cin>>n>>m;
            int sm=0;
            for(int i=0;i<m;i++){
                cin>>x;
                sm+=x;
            }
            if(sm>n)cout<<-1<<el;
            else cout<<n-sm<<el;
            return 0;
        }


Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>
#include <queue>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;

int main(){

    int N;
    cin >> N;
    
    vector<int> v(N);
    for(int i = 0; i < N; i++) cin >> v[i];

    vector<int> ans;
    while(v.size() != 0){
        //cout << v.size() << endl;
        bool f = true;
        for(int i = v.size() - 1; i >= 0; i--){
            //cout << i << v[i] << endl;
            if(i + 1 == v[i]){
                ans.push_back(v[i]);
                v.erase(v.begin() + i);
                f = false;
                break ;
            } 
        }
        if(f){
            cout << -1 << endl;
            return 0;
        }
    }

    for(int i = ans.size() - 1; i >= 0; i--){
        cout << ans[i] << endl;
    }

}

Measured memory_bytes: 256
#人生終わり
#解説解答
n,a,b,c = map(int,input().split())
if a + b + c == 0:
  print('No')
  exit()
elif a + b + c == 1:
  ans = []
  for _ in range(n):
    q = input()
    if q == 'AB':
      if a + b == 0:
        print('No')
        exit()
      a,b = b,a
      if a:
        ans.append('A')
      else:
        ans.append('B')
    elif q == 'BC':
      if b + c == 0:
        print('No')
        exit()
      b,c = c,b
      if b:
        ans.append('B')
      else:
        ans.append('C')
    else:
      if c + a == 0:
        print('No')
        exit()
      c,a = a,c
      if a:
        ans.append('A')
      else:
        ans.append('C')
  print('Yes')
  for x in ans:
    print(x)
  exit()
p = []
for _ in range(n):
  p.append(input())
if a + b == 0 and p[0] == 'AB':
    print('No')
    exit()
if b + c == 0 and p[0] == 'BC':
    print('No')
    exit()
if a + c == 0 and p[0] == 'AC':
    print('No')
    exit()
print('Yes')
for i in range(n):
  if p[i] == 'AB':
    if a == 0:
      a += 1
      b -= 1
      print('A')
    elif b == 0:
      a -= 1
      b += 1
      print('B')
    elif i != n-1:
      if p[i+1] == 'BC':
        a -= 1
        b += 1
        print('B')
      else:
        a += 1
        b -= 1
        print('A')
    else:
      a += 1
      b -= 1
      print('A')
  elif p[i] == 'BC':
    if b == 0:
      b += 1
      c -= 1
      print('B')
    elif c == 0:
      b -= 1
      c += 1
      print('C')
    elif i != n-1:
      if p[i+1] == 'AC':
        b -= 1
        c += 1
        print('C')
      else:
        b += 1
        c -= 1
        print('B')
    else:
      b += 1
      c -= 1
      print('B')
  else:
    if a == 0:
      a += 1
      c -= 1
      print('A')
    elif c == 0:
      a -= 1
      c += 1
      print('C')
    elif i != n-1:
      if p[i+1] == 'BC':
        a -= 1
        c += 1
        print('C')
      else:
        a += 1
        c -= 1
        print('A')
    else:
      a += 1
      c -= 1
      print('A')

Measured memory_bytes: 83304
#include <bits/stdc++.h>
#define int long long

using namespace std;

int32_t main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        int res = 0;
        for (int j = 1; j <= i; j++) {
            if (i % j == 0) res++;
        }
        if (i % 2 && res == 8) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
// Standard Deviation
// 標準偏差を求めるプログラム
// ITP1_10_C

package main

import (
	"fmt"
	"math"
)

func average(scores [1000]int, num int) float64 {
	s := 0.0

	for i := 0; i < num; i++ {
		s += float64(scores[i])
	}

	return s / float64(num)
}

func bunsan(scores [1000]int, avg float64, num int) float64 {
	d := 0.0

	for i := 0; i < num; i++ {
		d += math.Pow(float64(scores[i])-avg, 2)
	}

	return d / float64(num)
}

func main() {
	var n int
	var scores [1000]int
	var avg float64
	var ss float64

	for {
		fmt.Scanf("%d", &n)
		if n == 0 {
			break
		}

		// 得点データ読み込み
		for i := 0; i < n; i++ {
			fmt.Scanf("%d", &scores[i])
		}

		avg = average(scores, n)

		ss = bunsan(scores, avg, n)
		fmt.Printf("%.5f\n", math.Sqrt(ss))
	}
}


Measured memory_bytes: 1300