akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<queue>
#include<utility>
#include<string>

using namespace std;

queue<string> tasksname;
queue<int> taskst;

int main()
{
	cin.tie(0);
	ios::ios_base::sync_with_stdio(false);
	int taskam, q, time = 0;
	cin >> taskam >> q;
	for (int i = 0; i < taskam; ++i) {
		string name;
		int thistask;
		cin >> name >> thistask;
		if (thistask <= q) {
			time += thistask;
			cout << name << " " << time << endl;
			continue;
		}
		time += q;
		tasksname.emplace(name);
		taskst.emplace(thistask - q);
	}
	while (!tasksname.empty()) {
		int tmpt = taskst.front();
		string tmpname = tasksname.front();
		tasksname.pop();
		taskst.pop();
		int n = tmpt - q;
		if (n > 0) {
			tasksname.emplace(tmpname);
			taskst.emplace(n);
			time += q;
		}
		else {
			time += tmpt;
			cout << tmpname << " " << time << endl;
		}
	}
}

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

int32_t main()
{



    IOS

    


    int n;
    cin >> n;

    vector<int> v(n);
    map<int,int> mp;


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

    int ans =0;

    for(int i = 0; i< n; i++)
    {
      ans += mp[i-v[i]];
    }

    cout << ans;







    
    return 0;
}



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

public class AtCoder_156_B
{
    public static void Main()
    {
        //var exStdIn = new System.IO.StreamReader( "input.txt" );
        //System.Console.SetIn( exStdIn );

        int[] line1 = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        int n = line1[0];
        int k = line1[1];

        int ans = 1;
        int th = k;
        while (n >= th)
        {
            ans++;
            th *= k;
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
const ll MOD = 1e9 + 7;
#define x first
#define y second
#define all(x) x.begin(),x.end()
#define mem(a,b) memset(a,b,sizeof(a))
#define rep(c,a,b) for(ll c=a;c<b;c++)
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define min_heap priority_queue<pll,vector<pll>,greater<pll> >
#define pld pair<pll,ll>
ll dx4[]={-1,1,0,0};
ll dy4[]={0,0,-1,1};
ll dx8[]={-1,-1,-1,0,1,1,1,0};
ll dy8[]={-1,0,1,1,1,0,-1,-1};
bool isvalid(ll x,ll y,ll n,ll m)
{
	return (x>=0 and y>=0 and x<n and y<m);
}
bool isprime[1000];
vector<ll> prime;
void sievetoprime(ll n)
{
	mem(isprime,true);
	for(ll p=2;p*p<=n;p++)
	{
		if(isprime[p]==true)
		{
			for(ll i=p*p;i<=n;i+=p)
				isprime[i]=false;
		}
	}
}
ll cnt(ll a[])
{

}
void solve()
{	
	ll n,a,b;
	cin>>n>>a>>b;
	if((b-a)%2==0)
	{
		cout<<(b-a)/2;
	}
	else
	{
		ll cnt=0;
		ll x=min((a-1),(n-b));
		if(x==(a-1))
		{
			cnt=x;
			b=1+(b-a);
			a=1;
			cnt++;
			b--;
			cnt+=(b-a)/2;
		}
		else
		{
			cnt=x;
			a=n-(b-a);
			b=n;
			cnt++;
			a++;
			cnt+=(b-a)/2;
		}
		cout<<cnt;
	}
}	
int main()
{
	IOS
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
road = {}

for idx in range(n):
    road[idx] = []

for idx in range(m):
    a, b = map(int, input().split())
    road[a - 1].append(b - 1)
    road[b - 1].append(a - 1)

visited = [-1 for i in range(n)]

from collections import deque
def bfs(road):
    global visited
    queue = deque([0])
    visited[0] = 0
    while queue:
        x = queue.popleft()
        for r in road[x]:
            if visited[r] == -1:
                visited[r] = x
                queue.append(r)

bfs(road)
if (-1) in visited:
    print('No')
else:
    print('Yes')
    for x in visited[1:]:
        print(x + 1)


Measured memory_bytes: 42464
from heapq import *
def find(A,x) -> int:
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    A[y] = bx
    A[by] = bx

N = int( input())
X = [(0,0)]*N
Y = [(0,0)]*N
E = [(0,0)]*N
for i in range(N):
    x, y = map( int, input().split())
    X[i] = (x,i)
    Y[i] = (y,i)
    E[i] = (x,y)
X.sort()
Y.sort()
H = []
heapify(H)
for i in range(N-1):
    x1, j1 = X[i]
    x2, j2 = X[i+1]
    y1, k1 = Y[i]
    y2, k2 = Y[i+1]
    heappush(H,(x2-x1, j1, j2))
    heappush(H, (y2-y1, k1, k2))
ans = 0
V = [ i for i in range(N)]
while H:
    w,s,t = heappop(H)
    if find(V,s) != find(V,t):
        union(V,s,t)
        ans += w
print(ans)

Measured memory_bytes: 61056
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL -1
using namespace std;
const int64_t MOD = 1e9 + 7;

int main() {
	int H, W, N;
	cin >> H >> W >> N;

	vector<vector<int>> v(H, vector<int>(W));
	vector<int> C(N);
	for (int i = 0; i < N; i++) cin >> C.at(i);

	int x, y;
	x = 0;
	y = 0;
	for (int i = 0; i < N; ) {
		if (C.at(i) == 0) {
			i++;
			continue;
		}
		while (C.at(i)) {
			//cout << x << ' ' << y << endl;
			v.at(x).at(y) = i + 1;
			if (x % 2) y--;
			else y++;

			if (y < 0) {
				x++;
				y = 0;
			}
			else if (y == W) {
				x++;
				y = W - 1;
			}

			C.at(i)--;
		}

		if (x >= H) break;
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << v.at(i).at(j);
			if (j == W - 1) cout << endl;
			else cout << ' ';
		}
	}
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define moder 1000000007
#define int long long
#define double long double
#define ll long long
#define INF LLONG_MAX/3
#define P pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
#define ggr getchar();getchar();return 0;
using namespace std;
string s,t;
int dp[3010][3010];
signed main(){
    cin>>s>>t;
    rep(i,s.size()){
        rep(j,t.size()){
            if(s[i]==t[j]){
                if(i)dp[i][j]=dp[i-1][j];
                if(j)dp[i][j]=max(dp[i][j],dp[i][j-1]);
                if(i&&j)dp[i][j]=max(dp[i][j],dp[i-1][j-1]+1);
                dp[i][j]=max(dp[i][j],(ll)1);
            }
            else{
                if(i)dp[i][j]=dp[i-1][j];
                if(j)dp[i][j]=max(dp[i][j],dp[i][j-1]);
            }
        }
    }
    int a=s.size()-1,b=t.size()-1;
    string ans;
    while(a||b){
        if(s[a]==t[b]&&dp[a][b]==dp[max((ll)0,a-1)][max((ll)0,b-1)]+1){
            ans+=s[a];
            a--;b--;
            a=max((ll)0,a);
            b=max((ll)0,b);
            continue;
        }
        if(a&&dp[a][b]==dp[a-1][b]){
            a--;
            continue;
        }
        if(b&&dp[a][b]==dp[a][b-1]){
            b--;
            continue;
        }
    }
    if(dp[a][b])ans+=s[0];
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    ggr;
}

Measured memory_bytes: 70784
const lines=readlines(open("/dev/fd/0"))
state=0
input()=lines[global state+=1]
int(s::String)=parse(Int,s)
intSub(s::SubString{String})=parse(Int,s)
intLine(s::Array{SubString{String},1})=map(intSub,s)
function main()
    const INF=2^60
    a,b,q=input()|>split|>intLine
    s=Array{Int}(a+2)
    s[1],s[a+2]=-INF,INF
    for i in 2:a+1
        s[i]=int(input())
    end
    t=Array{Int}(b+2)
    t[1],t[b+2]=-INF,INF
    for i in 2:b+1
        t[i]=int(input())
    end
    for _ in 1:q
        x=int(input())
        m=INF
        i=searchsortedlast(s,x)
        j=searchsortedlast(t,x)
        for v in view(s,i:i+1)
            for w in view(t,j:j+1)
                m=min(m,abs(x-v)+abs(v-w),abs(x-w)+abs(w-v))
            end
        end
        println(m)
    end
end
main()

Measured memory_bytes: 174828
import collections
import math
# math.gcd(a,b)
k = int(input())
cnts = collections.defaultdict(int)
for i in range(1, k+1):
    for j in range(1, k+1):
        cnts[math.gcd(i,j)] += 1
ans = 0
for i in range(1, k+1):
    for key in cnts.keys():
        ans += math.gcd(i, key)*cnts[key]
print(ans)


Measured memory_bytes: 9480
<?php

fscanf(STDIN, "%s", $s);
fscanf(STDIN, "%s", $sb);
$s = str_split($s);
$sb = str_split($sb);

foreach($s as $key => $value){
    if($value != $sb[$key]){
        echo "No";
        exit;
    }
}
if(count($s) + 1 === count($sb)){
    echo "Yes";
}else{
    echo "No";
}

Measured memory_bytes: 16156
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
template <typename T, typename U> using P = pair<T, U>;
using ll = int64_t;
using PLL = P<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace __init {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
#include "../debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

int main() {
    ll A, P;
    cin >> A >> P;
    ll sum = A * 3 + P;
    cout << sum / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000000000;
int H, W;
int dh[] = {1, 0, -1, 0};
int dw[] = {0, 1, 0, -1};
int d[25][25];
char c[25][25];

int dfs(int sh, int sw) {
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) d[i][j] = INF; 
    }
    queue<P> que;
    que.push({sh, sw});
    d[sh][sw] = 0; 

    while (!que.empty()) {
        P p = que.front(); que.pop();
        for (int i = 0; i < 4; i++) {
            int nh = p.first + dh[i], nw = p.second + dw[i];
            if (0 <= nh && 0 <= nw && nh < H && nw < W && c[nh][nw] == '.' && d[nh][nw] == INF) {
                que.push({nh, nw});
                d[nh][nw] = d[p.first][p.second] + 1;
            }
        }
    }
}

int main() {
    cin >> H >> W;
    for (int i = 0; i < H; i++) cin >> c[i];

    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (c[i][j] == '.') {
                int M = 0;
                dfs(i, j);
                for (int k = 0; k < H; k++) {
                    for (int l = 0; l < W; l++) {
                        if (d[k][l] != INF) {
                            M = max(M, d[k][l]);
                        }
                    }
                }
                ans = max(ans, M);
            }
        }
    }
    cout << ans << endl;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

vector<ll> v;

void brute(int i, int last, ll cur){
    if(i == 0) return;

    v.pb(cur);

    if(last > 0) brute(i-1, last-1, cur * 10 + last - 1);
    brute(i-1, last, cur * 10 + last);
    if(last < 9) brute(i-1, last+1, cur * 10 + last + 1);
};


int main(){
    fcin;
  
    int k;
    cin >> k;

    for(int i = 1; i <= 9; i++){
        brute(12, i, i);
    }

    nth_element(v.begin(), v.begin() + k - 1, v.end());
    cout << v[k-1] << endl;

    return 0;
}



Measured memory_bytes: 18664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        private const int MODULO = 1000000007;
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static IEnumerable<int> Make(int s, int N)
        {
            int sum = 0;
            var list = new List<int>();
            for (int i = s; i <= 30000 && list.Count < N; ++i)
            {
                if (i % 2 == 0 || i % 3 == 0)
                {
                    if (list.Count < N - 1 || (sum + i) % 6 == 0)
                    {
                        list.Add(i);
                        sum += i;
                    }
                }
            }
            return (list.Count == N) ? list : null;
        }
        static IEnumerable<int> Solve(int N)
        {
            if (N == 3)
            {
                return new[] { 2, 5, 63 };
            }
            else
            {
                return Make(2, N) ?? Make(3, N) ?? Make(4, N);
            }
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            Console.WriteLine(string.Join(" ", Solve(N)));
        }
    }
}


Measured memory_bytes: 14048
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v[1000010];
int pr[1000010],cnt[1000010] = {};
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int i,j,n; cin >> n;
    for(i=1;i<=1000000;i++) pr[i] = -1;
    for(i=2;i<=1000000;i++){
        if(pr[i]!=-1) continue;
        for(j=i;j<=1000000;j+=i){
            if(pr[j]==-1) pr[j] = i;
        }
    }
    for(i=0;i<n;i++){
        int a; cin >> a;
        while(a!=1){
            v[i].push_back(pr[a]);
            a /= pr[a];
        }
    }
    for(i=0;i<n;i++){
        sort(v[i].begin(),v[i].end());
        v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
        for(int x:v[i]) cnt[x]++;
    }
    int mx = 0;
    for(i=1;i<=1000000;i++){
        mx = max(mx,cnt[i]);
    }
    if(mx==n){
        cout << "not coprime" << endl;
        return 0;
    }
    if(mx>1){
        cout << "setwise coprime" << endl;
        return 0;
    }
    cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 109088
def is_palindrome(s):
    if len(s) > 1:
        i = 0
        n = len(s)-1
        while s[i] == s[n]:
            i += 1
            n -= 1
            if i >= n:
                break
        else:
            return False
        return True
    else:
        return True

s = input()
n = len(s)

if is_palindrome(s) and is_palindrome(s[0:(n-1)//2]) and is_palindrome(s[(n+3)//2-1:]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  int n;
  cin>>n;
  vector<int> list(n);
  rep(i,n){
    int d1,d2;
    cin>>d1>>d2;
    if(d1==d2) list[i]++;
  }
  rep(i,n-2){
    if(list[i]==1&&list[i+1]==1&&list[i+2]==1){
      cout<<"Yes";
      return 0;
    }
  }
  cout<<"No";
return 0;
}

Measured memory_bytes: 3608
def ordinary_number(n, pli):

    ans = 0

    for i in range(1, n-1):
        if pli[i-1] != pli[i] != pli[i+1]:
            if pli[i-1] + pli[i] + pli[i+1] - max(pli[i-1], pli[i], pli[i+1]) - min(pli[i-1], pli[i], pli[i+1]) == pli[i]:
                ans += 1

    return ans

def main():
    n = int(input())
    pli = list(map(int, input().split()))
    print(ordinary_number(n, pli))

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
/*
confirm 0LL and 1LL
confirm cornercases such as 0
confirm times of cin < 10^6
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using VecVec = vector<Vec>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll (i) = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll (i) = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll (i) = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll (i) = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T& b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T& b){if(a > b){a = b; return true;} return false;}
template <typename T>
void co(const T n){cout << n << endl;}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void coVec(const Vec &v){for(ll i : v) cosp(i); cout << endl;}
ll in(){ll x; cin >> x; return x;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
const ll INF = 1e9+1;
const ll LINF = 1e18+1;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-11;

int main(void){
	sonic();
	ll n, m;
	cin >> n >> m;
	Vec x(n), y(m);
	rep(i, n) cin >> x[i];
	rep(i, m) cin >> y[i];

	ll sumx = 0;
	rep(i, n){
		sumx += x[i]*(i*2-(n-1));
		sumx %= MOD;
	}
	ll sumy = 0;
	rep(i, m){
		sumy += y[i]*(i*2-(m-1));
		sumy %= MOD;
	}
	co(sumx*sumy%MOD);

	return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n), b(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i)
        cin >> b[i];
    ll x = 0, y = 0;
    int odp = 0;
    vector<ll> r;
    for (int i = 0; i < n; ++i)
    {
        if (a[i] < b[i])
        {
            x += b[i] - a[i];
            ++odp;
        }
        if (a[i] > b[i])
        {
            y += a[i] - b[i];
            r.push_back(a[i] - b[i]);
        }
    }
    if (x <= y)
    {
        sort(r.begin(), r.end());
        reverse(r.begin(), r.end());
        for (int i = 0; x > 0; ++i)
        {
            x -= r[i];
            ++odp;
        }
        cout << odp;
    }
    else
        cout << "-1";
    return 0;
}


Measured memory_bytes: 2428
n = int(input())

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


def solve(cnt,A,N):
    sumA=A[0]
    for i in range(1, N):
        if sumA>0:
            if sumA+A[i]>=0:
                r = A[i]
                A[i]=-sumA-1
                cnt+=abs(r-A[i])
        else:
            if sumA+A[i]<=0:
                r = A[i]
                A[i]=-sumA+1
                cnt+=abs(r-A[i])

        sumA+=A[i]
    return cnt

cnt1=0
if b[0]<=0:
    ini=b[0]
    b[0]=1
    cnt1=abs(1-ini)


ans1=solve(cnt1,b,n)
cnt2=0
if a[0]>=0:
    ini=a[0]
    a[0]=-1
    cnt2=abs(-1-ini)


ans2=solve(cnt2,a,n)

print(min(ans1,ans2))


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

int main()
{
  int N;
  cin >> N;

  map<string, long long> count;
    // 答えは 32bit 整数型(int)に収まらない
    // 可能性があるので, long long を使う

  for (int i = 0; i < N; ++i)
  {
    string s; cin >> s;
    sort(s.begin(), s.end());
    count[s] += 1;
  }

  long long ans = 0;

  for (auto it = count.begin(); it != count.end(); it++)
  {
    long long n = it->second;
    ans += n * (n - 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 11136
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=2e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
char str[MAXN*4];
int main()
{

    scanf("%s",str+MAXN);
        int x=MAXN;
        int y=MAXN+strlen(str+MAXN);
        int q;scanf("%d",&q);
        int k=0;
        while(q--)
        {
            int o;o=read();
            if(o==1){if(k==0)k=1;else k=0;}
            else {
                int f;
                char ch[3];
                cin>>f>>ch;
                if(k==1)
                {
                    if(f==1)f=2;
                    else f=1;
                }
                if(f==1)
                {
                    str[--x]=ch[0];
                }
                else
                {
                    str[y++]=ch[0];
                }
            }
        }
        if(k!=0)for(int i=y-1;i>=x;i--)cout<<str[i];
        else for(int i=x;i<y;i++)cout<<str[i];
        cout<<endl;
    return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
int A[200000], B[200000];
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N;
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  int ans = 0;
  for (int k=29; k>=0; k--) {
    rep(i, N) if ((A[i]>>(k+1))&1) A[i] -= 1<<(k+1);
    rep(i, N) if ((B[i]>>(k+1))&1) B[i] -= 1<<(k+1);
    sort(A, A+N);
    sort(B, B+N);
    vector<int> sum = {1<<k, 1<<(k+1), (1<<k)+(1<<(k+1)) };
    int parity = 0;
    for (int X : sum) {
      int r = N;
      rep(i, N) {
        while (r > 0 && A[i]+B[r-1] >= X) r--;
        parity ^= (N-r)&1;
      }
    }
    if (parity) ans ^= 1<<k;
  }
  cout<<ans<<"\n";
  return 0;
}


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

int main() {
  string s;
  cin >>s;
  for(int i=0; i<19; i++){
    if(s.at(i)==','){
      cout <<' ';
    }
    else{
      cout <<s.at(i);
    }
  }
  cout <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int dp[n+2];
  memset(dp,0,sizeof dp);
  dp[0]=0;
  dp[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++){
    dp[i]=min(dp[i-1]+abs(a[i-1]-a[i]),dp[i-2]+abs(a[i-2]-a[i]));
  }
  cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1024
#!/usr/bin/env python3
import bisect
import collections
import sys

sys.setrecursionlimit(1000000)
ACMOD = 1000000007
INF = 1 << 62

YES = "YES"  # type: str
NO = "NO"  # type: str


def solve(A: int, V: int, B: int, W: int, T: int):
    oni = - abs(B - A)
    kodomo = 0
    if W * T <= V * T + oni:
        print(YES)
    else:
        print(NO)

    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    V = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    T = int(next(tokens))  # type: int
    solve(A, V, B, W, T)


if __name__ == '__main__':
    main()


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

using namespace std;

#define all(v) begin(v), end(v)
#define inf 1<<25

struct PrimalDual {
  struct edge {
    int to, cap, cost, rev;
    edge(){}
    edge(int to, int cap, int cost, int rev)
      :to(to), cap(cap), cost(cost), rev(rev){}
  };
  vector< vector<edge> > graph;
  vector<int> h, mincost, prevv, preve;
  PrimalDual(){}
  PrimalDual(int V):graph(V), h(V), mincost(V), prevv(V), preve(V){}
  void add_edge(int from, int to, int cap, int cost) {
    graph[from].emplace_back(to, cap, cost, graph[to].size());
    graph[to].emplace_back(from, 0, -cost, graph[from].size()-1);
  }
  int min_cost_flow(int s, int t, int f) {
    fill(all(h), 0);
    fill(all(prevv), -1);
    fill(all(preve), -1);
    typedef pair<int, int> P;
    int res = 0;
    while(f > 0) {
      fill(all(mincost), inf);
      priority_queue<P, vector<P>, greater<P> > que;
      que.emplace(0, s);
      mincost[s] = 0;
      while(que.size()) {
	P p = que.top(); que.pop();
	int v = p.second;
	if(mincost[v] < p.first) continue;
	for(int i = 0; i < graph[v].size(); i++) {
	  edge&e = graph[v][i];
	  int cost = mincost[v] + e.cost + h[v] - h[e.to];
	  if(e.cap > 0 && cost < mincost[e.to]) {
	    mincost[e.to] = cost;
	    que.emplace(cost, e.to);
	    prevv[e.to] = v;
	    preve[e.to] = i;
	  }
	}
      }
      if(mincost[t] < 0) return -1;
      for(int v = 0; v < graph.size(); v++) h[v] += mincost[v];
      int d = f;
      for(int v = t; v != s; v = prevv[v])
	d = min(d, graph[prevv[v]][preve[v]].cap);
      f -= d;
      res += d * h[t];
      for(int v = t; v != s; v = prevv[v]) {
	edge& e = graph[prevv[v]][preve[v]];
	e.cap -= d;
	graph[e.to][e.rev].cap += d;
      }
    }
    return res;
  }
};

int N, M, K;
int a[101];
int b[101][101];
int T[101];

int main() {
  cin >> N >> M >> K;
  for(int i = 0; i < N; i++) cin >> a[i];
  for(int i = 0; i < M; i++) {
    for(int j = 0; j < N; j++) cin >> b[i][j];
  }
  for(int i = 0; i < M; i++) cin >> T[i];
  int dummy = N + M, s = dummy + 1, s2 = s + 1, t = s2 + 1, V = t + 1;
  PrimalDual graph(V);
  graph.add_edge(s, s2, N-K, 0);
  graph.add_edge(s, dummy, N, 0);
  for(int i = 0; i < M; i++) {
    graph.add_edge(s2, i, T[i], 0);
    for(int j = 0; j < N; j++) {
      graph.add_edge(i, M+j, 1, 100-b[i][j]);
    }
  }
  for(int i = 0; i < N; i++) {
    graph.add_edge(dummy, M+i, 1, 100-a[i]);
    graph.add_edge(M+i, t, 1, 0);
  }
  cout << 100*N-graph.min_cost_flow(s, t, N) << endl;
  return 0;
}

Measured memory_bytes: 3300
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>

#define CH(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)

using namespace std;

int dp[(1<<17)], INF = 100000000;

int main() {
  while(1){
    int N, t[20][20];
    cin>>N;
    if(N==0) break;
    REP(i,0,N){
      REP(j,0,N+1){
        cin>>t[i][j];
      }
    }

    REP(i,0,(1<<N)){
      dp[i] = INF;
    }
    dp[0] = 0;

    REP(mask,0,(1<<N)){
      int minCost[16];
      //Calculate current minimum cost of each stage
      REP(i,0,N){
        minCost[i] = t[i][0];
        REP(j,0,N){
          if(i == j) continue;
          if(mask & (1<<j)) minCost[i] = min(minCost[i],t[i][j+1]);
        }
      }
      //Determination of the next stage
      REP(i,0,N){
        if(mask & (1<<i)) continue;
        dp[mask | (1<<i)] = min(dp[mask | (1<<i)], dp[mask] + minCost[i]);
      }
    }
    cout<<dp[(1<<N)-1]<<endl;
  }

  return 0;
}

Measured memory_bytes: 3252
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,n) for(int i = (s); i < (n); i++)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  vector<vector<int> > s;
  vector<int> k(m);
  rep(i, 0, m) {
    cin >> k[i];
    vector<int> kk(k[i]);
    rep(j, 0, k[i])  cin >> kk[j];
    s.push_back(kk);
  }
  vector<int> p(m);
  rep(i, 0, m) cin >> p[i];
  
  int ans = 0;
  for(int bit = 0; bit < (1 << n); bit++) {
    int cnt = 0;
    rep(i, 0, m) {
      int on = 0;
      rep(j, 0, k[i]) {
        if(bit & (1 << s[i][j]-1)) on++;
      }
      if(on % 2 == p[i]) cnt++;  
    }
    if(cnt == m) ans++;
  } 
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
	using namespace std;
	#define xxx ios::sync_with_stdio(),cin.tie(0),cout.tie(0)
	#define rep(i,n) for(int i=0;i<n;i++)
	#define int long long
	int powerof(int x, int n){
		int ans=0;
		while(x!=0){
			if(x%n==0) {x/=n;ans++;}
			else{
				return ans;
			}
		}
	}
	
	
	signed main(){
		int test=1;
		//cin>>test;
		while(test--){
			int n;
			cin>>n;
			if(n%1000)cout<<1000-n%1000<<endl;
			else cout<<0<<endl;
		}
		return 0;
	}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int main(){
	ll a,b;
	cin>>a>>b;

	ll x=a*b;

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

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

	ll ans=x/b;
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let mut ans = 0;
    let mut min = n + 1;
    for _ in 0..n {
        let p: usize = scan(tokens);
        if p < min {
            ans += 1;
        }
        min = std::cmp::min(min, p);
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
def is_prime(n):
    p = 3
    while p * p <= n:
        if n % p == 0:
            return False
        else:
            p += 2
    return True


x = int(input())
if x == 2:
    print(x)
else:
    if x % 2 == 0:
        x += 1
    while True:
        if is_prime(x):
            print(x)
            break
        x += 2

Measured memory_bytes: 3060
k, n = map(int, input().split())
a = list(map(int, input().split()))
distance = [0]*n
distance[n-1] = k - a[n-1] + a[0]
for i in range(n-1):
    distance[i] = a[i+1] - a[i]
print(sum(distance) - max(distance))

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

using namespace std;

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

  string S;
  cin >> S;

  cerr << S << endl;

  vector<bitset<10>> T(N + 1);
  T[N] = bitset<10>(0);
  for (int64_t n = N; n > 0; --n) {
    T[n - 1] = T[n];
    T[n - 1].set(S[n - 1] - '0');
  }

  vector<bitset<100>> U(N + 1);
  U[N] = U[N - 1] = bitset<100>(0);
  for (int64_t n = N - 1; n > 0; --n) {
    U[n - 1] = U[n];

    uint64_t j = S[n] - '0';
    for (uint64_t i = 0; i < 10; ++i) {
      if (T[n + 1].test(i)) {
        U[n - 1].set(j * 10 + i);
      }
    }
  }

  bitset<1000> V(0);
  for (int64_t n = 0; n < N; ++n){
    uint64_t j = S[n] - '0';
    for (uint64_t i = 0; i < 100; ++i) {
      if (U[n].test(i)) {
        V.set(j * 100 + i);
      }
    }
  }

  cout << V.count() << endl;

  return 0;
}

Measured memory_bytes: 1024
// In the Name of Allah
// Ya Ali!
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(x) x.begin() , x.end()

const ll maxn = 2e5 + 10;
const ll mod = 1e9 + 7;
const ll INF = 1e18 ;

ll h , w , n , dp[ maxn ] , fac[ 2*maxn ] , inv[ 2*maxn ];
vector < pair <ll , ll> > block ;

ll poww( ll a , ll b)
{
  if( b == 0 )return 1 ;
  ll x = poww( a , b/2 )%mod ;
  if( b & 1) return (((x*x)%mod)*a)%mod ;
  else return (x*x)%mod ;
}

ll c( ll nn , ll rr)
{
  return (((fac[nn] * inv[rr])%mod)*inv[nn-rr])%mod ;
}

signed main()
{
 ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

 cin >> h >> w >> n ;
 for(int i = 1 ; i <= n ; i ++){
    ll r , c ;
    cin >> r >> c;
    block.pb({ r , c }) ;
 }
 block.pb({ h , w }) ;
 sort(all(block));

 fac[ 0 ] = 1;
 inv[ 0 ] = 1;
 for(int i = 1 ; i <= h+w ; i ++){
     fac[ i ] = ( fac[i-1] * i)%mod ;
     inv[ i ] = poww(fac[ i ] , mod-2)%mod ;
 }

 for(int i = 0 ; i <= n ; i ++){
   ll r1 = block[ i ].F , c1 = block[ i ].S ;
   dp[ i ] = c(r1-1+c1-1 , r1-1)%mod ;

   for(int j = i-1 ; j >= 0 ; j --){
    ll r2 = block[ j ].F , c2 = block[ j ].S ;
    ll dis1 = r1-r2 , dis2 = c1-c2;
    if(dis1 < 0 || dis2 < 0)continue;
    ll va = (dp[ j ] * (c(dis1+dis2 , dis1)%mod))%mod ;
    dp[ i ] = (dp[ i ] - va + mod)%mod ;
   }
 }

 cout << dp[n] ;

    return 0;
}


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

using namespace std;

#define int long long

void solve() {
    string s;
    cin >> s;
    if (s[1] == 'B') cout << "ARC";
    else cout << "ABC";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>

void calc(char);
void push(int);
int pop(void);

int stack[100];

main(){

  int i, END_OF_INPUT;
  char str[9];

  stack[0]=0;

  while(1){

    for(END_OF_INPUT=0,i=0; ;i++){
      scanf("%c",&str[i]);
      if(str[i] == ' '){
	str[i]='\0';
	break;
      }
      if(str[i] == '\n'){
	str[i]='\0';
	END_OF_INPUT=1;
	break;
      }
    }

    if('0' <= str[0] && str[0] <= '9')
      push(atoi(str));
    else
      calc(str[0]);

    if(END_OF_INPUT) break;

  }

  printf("%d\n",pop());

  return 0;

}

void calc(char exp){

  int op1, op2, ans;

  op2 = pop();
  op1 = pop();
  
  if(exp=='+')ans = op1 + op2;
  if(exp=='-')ans = op1 - op2;
  if(exp=='*')ans = op1 * op2;

  push(ans);

}

void push(int v){
  stack[++stack[0]] = v;
}

int pop(){
  return stack[stack[0]--];
}

Measured memory_bytes: 0
l=[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 24, 25, 27, 28, 30, 32, 35, 36, 40, 42, 45, 48, 49, 54, 56, 63, 64, 72, 81]
print('Yes' if int(input()) in l else 'No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
    string S;cin>>S;
    int a=0,b=0;char temp[2]={'0','1'};
    for(int i=0;i<S.size();i++){
        if(S.at(i)==temp[i%2]){
            a++;
        }else{
            b++;
        }
    }cout<<min(a,b)<<endl;
}

Measured memory_bytes: 512
// #pragma GCC optimize("O3", "unroll-loops")
// #pragma GCC target("avx2")

#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;

typedef long long int ll;
#define endl '\n'
#define ld long double
#define all(a) a.begin(),a.end()
#define int long long
#define pb push_back
#define pii pair <int, int>
#define ff first
#define ss second
#define sz(v) (int)v.size() 
#define UB upper_bound
#define LB lower_bound
#define OST tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>

const int INF = 1e15 + 0;
const int mod = 1e9 + 7;
//const int mod = 998244353;

void solve() {
  int n, k; cin >> n >> k;
  k++;
  int data[n+5], vis[n+5] = {0};
  data[0] = 1;
  for(int i = 1; i <= n; i++) {
    cin >> data[i];
  }
  vector <int> v, cyc;
  int cur = 0, st = 1;
  while(1) {
     cur = data[cur];
     if(vis[cur]) {
      st = cur; break;
     }
     v.pb(cur);
     vis[cur] = 1;
  }
  
  memset(vis, 0, sizeof(vis));
  data[0] = st; cur = 0;
  while(1) {
     cur = data[cur];
     if(vis[cur]) break;
     cyc.pb(cur);
     vis[cur] = 1;
  }
  if(k <= sz(v)) {
    cout << v[k-1] << '\n';
  }
  else {
    k -= sz(v);
    k %= (sz(cyc));
    if(k == 0) k = sz(cyc);
    cout << cyc[k-1] << '\n';
  }
}

signed main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif
    int t = 1; // cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }
}    


Measured memory_bytes: 10788
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

vector<vector<int> > g;   // to
vector<int> vis;
ll ans;

void dfs( int root, int curr, int flag, long ret[3] )
{
    assert(vis[curr]==0);
    vis[curr]=flag;

    int siz=(int)g[curr].size();
    int i;
    for(i=0; i<siz; i++) {
        int next=g[curr][i];
        if(vis[next]) {
            if(vis[next]!=3-flag) ret[2]=1;
            continue;
        }
        dfs( root, next, 3-flag, ret );
    }

    if(flag==1) ret[0]++;
    if(flag==2) ret[1]++;

    if(root==curr) {
        //printf("ret=%d %d %d\n", ret[0], ret[1], ret[2]);
        if(ret[2]) ans += (ret[0]+ret[1])*(ret[0]+ret[1]-1)/2;
        else       ans += ret[0]*ret[1];
    }

    return;
}

int main(int argc, char* argv[])
{
    int n, m;
    scanf("%d%d", &n, &m);

    g.resize(n);
    vis.resize(n);
    int i;
    for(i=0; i<m; i++) {
        int a, b;
        scanf("%d%d", &a, &b);
        g[a-1].push_back(b-1);
        g[b-1].push_back(a-1);
    }

    ans=0;
    for(i=0; i<n; i++) {
        if(!vis[i]) {
            long ret[3]={0, 0, 0};   // num of 0/1, flag
            dfs(i, i, 1, ret);
        }
    }
    printf("%lld\n", ans-m);

    return 0;
}


Measured memory_bytes: 7424
d, g = gets.strip.split.map(&:to_i)
pc = readlines.map {|line| line.strip.split.map(&:to_i) }.map.with_index {|(p, c), i| [p, 100*(i+1), c, 100*(i+1)*p+c] }

result = 10**4
(2**d).times do |i|
  digits = ("%0#{d}b" % i).split('').map(&:to_i)

  parts, full = digits.map.with_index {|d, i| [d,i] }.partition {|e| e.first.zero? }.map {|arr| arr.map(&:last) }

  pp = pc.map.with_index {|c_pc, i| full.include?(i) ? c_pc.last : 0 }.inject(0, :+)
  r = pc.map.with_index {|c_pc, i| full.include?(i) ? c_pc.first : 0 }.inject(0, :+)

  if pp < g
    diff = parts.map {|part|
      c_pc = pc[part]
      need = ((g-pp)/c_pc[1].to_f).ceil.to_i
      need >= c_pc.first ? nil : need
    }.compact.min
    next if diff.nil?

    r += diff
  end

  result = [result, r].min
end

p result


Measured memory_bytes: 1916
n = int(input())

dp = [-1] * 100
dp[0] = 2
dp[1] = 1

def f(x):
  if x == 0:
    return dp[0]
  
  if x == 1:
    return dp[1]

  if dp[x] == -1:
    dp[x] = f(x-1) + f(x-2)
    return dp[x]
  else:
    return dp[x]

print(f(n))


Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int A[100010];
int cnt[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	ll ans = 1;
	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			ans *= 3 - cnt[A[0]];
		}
		else {
			ans *= cnt[A[i] - 1] - cnt[A[i]];
		}
		cnt[A[i]]++;
		ans %= mod;
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
x=[]
y=[]


for i in range (10):
    A=int(input())
    x.append(A)
x1=sorted(x,reverse=True)

for j in range (10):
    B=int(input())
    y.append(B)
y1=sorted(y,reverse=True)
   
   
sum1=x1[0]+x1[1]+x1[2]
sum2=y1[0]+y1[1]+y1[2]

print(sum1,sum2)



Measured memory_bytes: 5600
fun main(args: Array<String>) {
    val s = readLine()!!
    val a = s.take(2)
    val b = s.drop(2)
    when {
        check(a) && check(b) -> println("AMBIGUOUS")
        check(a) && !check(b) -> println("MMYY")
        !check(a) && check(b) -> println("YYMM")
        !check(a) && !check(b) -> println("NA")
    }

}

fun check(s:String) = s in "01".."12"

Measured memory_bytes: 33860
#include<cstdio>
#include<vector>
using namespace std;
#define N 100005
int n, m, x, y, q[N], c[N], i, j, k;//c[i]=j表示第i号房间指示第j个房号 
vector<int> ac[N];//图的存储 
int main()
{
	scanf("%d%d", &n, &m);
	for(i=1; i<=m; i++){
		scanf("%d%d", &x, &y);
		ac[x].push_back(y);
		ac[y].push_back(x);
	}
	q[1] = 1;
	for(i=j=1; i<=j; i++){
		for(k=0; k<ac[q[i]].size(); k++){
			if(c[ac[q[i]][k]] == 0){//与i相连的第k个房间有没有走过 
				q[++j] =  ac[q[i]][k];
				c[ac[q[i]][k]] = q[i];//入队的肯定是当前从1到目前这个点的最短路径 
			} 
			
		}
	}
	for(i=2; i<=n; i++){
		if(c[i] == 0){
			printf("No");
			return 0;
		} 
	}	
	printf("Yes\n");
	for(i=2; i<=n; i++){
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 10232
#include <stdio.h>

int main(void)
{
	int a,b,c,d,x[101],y[101],i;
	
	scanf("%d %d %d %d",&a,&b,&c,&d);
	
	int xmax=c,ymin=d;
	
	for(i=0;i<a;i++){
		scanf("%d",&x[i]);
		if(xmax<x[i])xmax=x[i];
	}
	
	for(i=0;i<b;i++){
		scanf("%d",&y[i]);
		if(ymin>y[i])ymin=y[i];
	}
	
	if(xmax<ymin)printf("No War\n");
	else printf("War\n");
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
		 String s = sc.nextLine();
		 int n = s.length();
		 String s1 = s.substring(0, (n-1)/2);
		 String s2 = s.substring((n+1)/2, n);
        if(isKai(s) && isKai(s1) && isKai(s2)){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
    }
	
	public static boolean isKai(String s){
		return s.equals(new StringBuilder(s).reverse().toString());
	}
}






Measured memory_bytes: 23764
def sign(x):
  if x<0:
    return -1
  elif x>0:
    return 1
  else:
    return 0
n = int(input())
a = list(map(int,input().split()))
a_sum_pn = 0
a_sum_np = 0
ans_pn = 0
ans_np = 0
flag = 1
for i in range(n):
  a_sum_pn += a[i]
  a_sum_np += a[i]
  if sign(a_sum_pn) != flag:
    ans_pn += abs(flag-a_sum_pn)
    a_sum_pn = flag
  if sign(a_sum_np) != -flag:
    ans_np += abs(-flag-a_sum_np)
    a_sum_np = -flag
  flag *= -1
print(min(ans_pn,ans_np))


Measured memory_bytes: 63216
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
	int a,b,mato[1000];
	vector<int> nums;
	while(scanf("%d%d",&a,&b),a,b){
		int res=0;
		nums.clear();
		for(int i=0;i<a;i++)scanf("%d",mato+i);
		for(int i=0;i<=a;i++)
			for(int j=0;j<=a;j++)
				nums.push_back(mato[i]*!!(i-a)+mato[j]*!!(j-a));
				
		sort(nums.begin(),nums.end());
		vector<int>::iterator it=nums.begin();
		while(it!=nums.end() && b>=*it){
			vector<int>::iterator itt=upper_bound(nums.begin(),nums.end(),b-*it);
			res=max(res,*it+++*--itt);
		}
		printf("%d\n",res);
	}
	return 0;
}

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

bool check(string s) {
    
    int n=s.size(),flag=0;
    
    for(int i=0;i<n;i++){
        if(s[i]!=s[n-i-1]){
            flag = 1;
            break;
        }
    }
    if(flag)
    return false;
    else
    return true;
    
}
int main() 
{ 
    string s;
    cin>>s;
     if (check(s)==false){
  	cout<<"No"<<endl;
  	return 0;
  }
   string k="";
   
    int n = s.length(); 
    char arr[n + 1]; 
    strcpy(arr, s.c_str()); 
  
    for (int i = 0; i < (n-1)/2; i++) {
    	k += arr[i];
    }
  if (check(k)==false){
  	cout<<"No"<<endl;
  	return 0;
  }
  string j="";
      for (int i = ((n+3)/2)-1; i < n; i++) {
    	j += arr[i];
    }
    if(check(j)==true){
    	cout<<"Yes"<<endl;
    }
    else{
    	cout<<"No"<<endl;
    }
    return 0; 
} 

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

int main() {
  int n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  long long h = 0;
  for(int i = 1; i < n; i++) {
    if(a.at(i) < a.at(i-1)) {
      h += a.at(i-1) - a.at(i);
      a.at(i) = a.at(i-1);
    }
  }
  cout << h << endl;
}

Measured memory_bytes: 4836
import java.util.HashMap;
import java.util.Scanner;

public class Main {
	private static Scanner scan;

	public static void main(String[] args) {
		scan = new Scanner(System.in);
		String line = scan.nextLine();
		String[] words = line.split(" ");
		int i;
		HashMap<String,Integer> map = new HashMap<String, Integer>();
		for(i=0;i<words.length;i++){
			if(map.containsKey(words[i])) map.put(words[i],map.get(words[i])+1);
			else map.put(words[i],1);
		}
		int temp=0;
		for(i=0;i<map.size();i++){
			if(map.get(words[i]) > temp) temp = map.get(words[i]);
		}
		for(i=0;i<map.size();i++){
			if(map.get(words[i]) == temp){
				System.out.print(words[i]+" ");
				break;
			}
		}
		String longestWord = "";
		for(i=0;i<words.length;i++){
			if(longestWord.length()<words[i].length()) longestWord = words[i];
		}
		System.out.println(longestWord);
	}
}

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

double theta = acos(-1) / 3;

struct Point
{
	double x;
	double y;
};

void Curve(Point *A, int a)
{
	Point pa = A[a], pb = A[a + 4];
	Point v;
	
	v.x = (pb.x - pa.x) / 3;
	v.y = (pb.y - pa.y) / 3;
	
	A[a + 1].x = A[a].x + v.x;
	A[a + 1].y = A[a].y + v.y;
	
	A[a + 2].x = A[a + 1].x + v.x * cos(theta) - v.y * sin(theta);
	A[a + 2].y = A[a + 1].y + v.x * sin(theta) + v.y * cos(theta);
	
	A[a + 3].x = A[a].x + v.x * 2;
	A[a + 3].y = A[a].y + v.y * 2;
}

void Koch(Point *A, int n)
{
	int len = (1 << (2 * n)) + 1;
	for(int i = len - 1; i > 0; i -= 4)
	{
		A[i] = A[i / 4];
	}
	
	for(int i = 0; i < len; i += 4)
	{
		Curve(A, i);
	}
}

int main()
{
	int N;
	cin >> N;
	
	Point A[5000];
	A[0].x = 0;
	A[0].y = 0;
	A[1].x = 100;
	A[1].y = 0;

	for(int i = 1; i <= N; ++i)
	{
		Koch(A, i);
	}
	
	int len = (1 << (2 * N)) + 1;
	for(int i = 0; i < len; ++i)
	{
		cout << fixed << setprecision(6) << A[i].x << " " << fixed << setprecision(6) << A[i].y << endl;
	}

    return 0;
}



Measured memory_bytes: 3480
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int inputCount = int.Parse(Reader.ReadLine());

        long numA = 1;
        long numB = 1;

        for (int i = 0; i < inputCount; i++)
        {
            int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            long bai = (long)Math.Ceiling(Math.Max((decimal)numA / inpt[0], (decimal)numB / inpt[1]));
            numA = inpt[0] * bai;
            numB = inpt[1] * bai;
        }
        Console.WriteLine((numA + numB).ToString("#########################################0"));



    }


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


3
2 3
1 1
3 2


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 3288
#include <stdio.h>

int main()
{   
	double a =0,b = 0,t = 0;
	int total = 0;
	 
	scanf("%lf %lf",&a,&b);
	t = (a+b)/2;
	t = t + 0.9; 
	total = (double)(int)t;
	printf("%d  ",total);
	
	
	return 0;
}


Measured memory_bytes: 128