akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
const int MAXN = 100000;
const int MOD = int(1E9) + 7;
int fct[MAXN + 5];
void init() {
	fct[0] = 1;
	for(int i=1;i<=MAXN;i++)
		fct[i] = 1LL*fct[i-1]*i%MOD;
}
int f[2*MAXN + 5], g[2*MAXN + 5], N;
char str[2*MAXN + 5];
int main() {
	init();
	scanf("%d%s", &N, str + 1), str[0] = 'W';
	for(int i=1;i<=2*N;i++)
		f[i] = (str[i] != str[i - 1]);
	for(int i=1;i<=2*N;i++) {
		if( f[i] )
			f[i] ^= 1, g[i] = 0;
		else
			f[i + 1] ^= 1, g[i] = 1;
	}
	int ans = 1, cnt = 0;
	for(int i=1;i<=2*N;i++) {
		if( g[i] == 0 ) cnt++;
		else {
			ans = 1LL*ans*cnt%MOD;
			cnt--;
		}
	}
	if( cnt ) printf("%d\n", 0);
	else printf("%lld\n", 1LL*ans*fct[N]%MOD);
}

Measured memory_bytes: 2304
#include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main(void){
	string a;
	int n,x;
	cin>>n;
	while(n--){
		cin>>a;
		sort(a.begin(),a.end());
		x=atoi(a.c_str());
		reverse(a.begin(),a.end());
		cout<<atoi(a.c_str())-x<<"\n";
	}
}

Measured memory_bytes: 1228
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

int n;
int solve(){
    int res = 0;
    vector<string> w(n); for(auto& in:w) cin >> in;
    vector<int> tanka = {5,7,5,7,7};
    for(int i = 0; i < w.size();i++){
        int I = 0;
        for(int j = i; j < w.size();j++){
           // cout << tanka << endl;
            if(w[j].length() < tanka[I]){
                tanka[I] -= w[j].length();
            }else if(w[j].length() == tanka[I]){
                tanka[I] = 0;
                I++;
                if(I == 5){
                    return i + 1;
                }
            }else{
                tanka = vector<int>{5,7,5,7,7};
                break;
            }
        }
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    while(cin >> n,n){
        cout << solve() << endl;
    }
    return 0;
}



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


signed main(){

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

    int n;
    cin >> n;
    vector<int> a(n),b(n),c(n);
    for(int i = 0;i < n;i ++){
        cin >> a.at(i);
    }
    for(int i = 0;i < n;i ++){
        cin >> b.at(i);
    }
    for(int i = 0;i < n;i ++){
        cin >> c.at(i);
    }

    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    a.push_back(10000000000000);
    c.push_back(10000000000000);

    int A=0,C=0;
    int ans = 0;

    for(int i = 0;i < n;i ++){
        while(a.at(A) < b.at(i)){
            A ++;
        }
        while(c.at(C) <= b.at(i)){
            C ++;
        }

        ans += A * (n-C);

    }

    cout << ans << endl;
}



Measured memory_bytes: 3456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int N; cin >> N;
    vector<int> a(N+2, 0);
    for(int i=1; i<=N; i++) cin >> a[i];


    set<int> se;
    for(int i=1; i<=N; i++) se.insert(a[i]);
    if(se.size() == 1){
        cout << 1 << endl;
        return 0;
    }

    int ans = 0;
    int tmp = 1;
    int id = 2;

    while(id <= N){
        while(a[id] == a[tmp]) id++;

        if(a[id] > a[tmp]){
            while(id+1 <= N && a[id+1] >= a[id]) id++;
            ans++;
            id++;
            tmp = id;
        }
        else if(a[id] < a[tmp]){
            while(id+1 <= N && a[id+1] <= a[id]) id++;
            ans++;
            id++;
            tmp = id;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 5376
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

A, B, C, K = inpl()
if A >= K:
    print(K)
    exit()
if A+B >= K:
    print(A)
    exit()

print(A - (K-A-B))

Measured memory_bytes: 10048
#include <iostream>
using namespace std;
int main(void){
    long long n,m,x=0,y=0,p=1e9+7;
    cin>>n>>m;
    for(long long i=1;i<=n;i++){
        long long z;
        cin>>z;
        if(i==1){
            x+=(1-n)*z;
        }else{
            x+=(2*i-n-1)*z;
        }
        x=(x+p*p)%p;
    }
    for(long long i=1;i<=m;i++){
        long long z;
        cin>>z;
        if(i==1){
            y+=(1-m)*z;
        }else{
            y+=(2*i-m-1)*z;
        }
        y=(y+p*p)%p;
    }
    cout<<(x*y)%p<<endl;
}


Measured memory_bytes: 256
/*
    -ensure correct output format
    -ensure printing required output
    -reread the problem statement
  */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;
bool compare(const pair<ll,ll> &a, const pair<ll,ll> &b)
{
    if(a.S==b.S)
        return a.F>b.F;

       return (a.S > b.S);
}
ll lcm(ll a,ll b)
{
    if(a==0 || b==0)return 0;

    return a/__gcd(a,b)*b;
}

void input(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)cin>>ara[i];
}
void print(ll ara[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<ara[i]<<" ";
    cout<<endl;
}


int main()
{

   fastread();

   ll i,j,n,m,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r,ans=0;

      bool flag=false;

      string str;

    cin>>a>>b>>c;

    c=c/a;

    cout<<c*b<<endl;



}



Measured memory_bytes: 3620
/*
ID: jerrywcy
LINK: https://atcoder.jp/contests/agc025/tasks/agc025_b
LANG: C++
STATUS:
*/
#include <bits/stdc++.h>

#define init(array,x) memset(array,x,sizeof(array))

using namespace std;

typedef long long ll;

const ll inf=0x3f3f3f3f;
const ll mod=998244353;

ll n,a,b,k;
ll f[3000010],g[3000010];
ll ans;

ll read(){
    ll f=1,x=0;
    char ss=getchar();
    while(ss<'0'||ss>'9'){if(ss=='-')f=-1;ss=getchar();}
    while(ss>='0'&&ss<='9'){x=x*10+ss-'0';ss=getchar();}
    return f*x;
}

ll pow(ll x,ll y){
    ll ret=1;
    while (y){
        if (y&1)ret=(ret*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
    return ret;
}

void getf(){
    f[1]=1;
    for (int i=2;i<=n;i++)f[i]=(f[i-1]*i)%mod;
    g[n]=pow(f[n],mod-2);
    for (int i=n-1;i>=1;i--)g[i]=(g[i+1]*(i+1))%mod;
    return ;
}

ll C(int x,int y){
    if (x<y)return 0;
    if (y==0 || y==x)return 1;
    return ((((f[x]*g[y])%mod)*g[x-y])%mod);
}

int main()
{
	ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
    n=read();a=read();b=read();k=read();
    getf();
    for (int i=0;i*a<=k;i++){
        if ((k-i*a)%b==0){
            int j=(k-i*a)/b;
            ans=(ans+(C(n,i)*C(n,j))%mod)%mod;
        }
    }
    printf("%lld\n",ans);

	return 0;
}


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

namespace AtCoderTutorial
{
    public class AtCoder176
    {
        public static void Main(string[] args)
        {
            long[] inputs = Console.ReadLine().Split(' ').Select(_ => long.Parse(_)).ToArray();
            long D = inputs[0];
            long T = inputs[1];
            long S = inputs[2];

            if(T * S >= D){
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}

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

signed main() {
  int n,t;
  cin >> n >> t;

  vector<pair<int,int>> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i].first >> a[i].second;
  }

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

  int ans = 0;
  vector<vector<int>> dp(n + 1, vector<int> (t + 1));
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < t; j++) {
      if(j - a[i].first >= 0) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j - a[i].first] + a[i].second);
      }
      dp[i][j] = max(dp[i][j], dp[i - 1][j]);
      if(j == t - 1) ans = max(ans, dp[i][j] + a[i+1].second);
    }
  }
  cout << ans << '\n';
}

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

int main() {
	int n, x; cin >> n >> x;
	int m[100];

	int donut = 0;
	int minv = 1000000;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		minv = min(minv, m[i]);
		x -= m[i];
	}

	while (x >= minv) {
		donut++;
		x -= minv;
	}

	cout << donut + n << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

string S = "abcdefghij";

vector<string> stdform(int N){
    if(N == 1) return {"a"};
    vector<string> res;

    vector<string> T = stdform(N-1);
    rep(i, T.size()){
        char maxc = 'a';
        rep(j, T[i].length()) maxc = max(T[i][j], maxc);

        rep(j, maxc-'a'+2){
            char next = 'a'+j;
            res.push_back(T[i]+next); 
        }
    }

    return res;
}


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

    vector<string> ans = stdform(N);

    rep(i, ans.size()){
        cout << ans[i] << endl;
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

int n,m;
string S,T;
ll dp[3001][3001];
string res;

ll dfs(int i,int j){
  if(i==n&&j==m)return 0;
  if(dp[i][j]!=-INF)return dp[i][j];
  if(i==n){
    return dp[i][j]=dfs(i,j+1);
  }else if(j==m){
    return dp[i][j]=dfs(i+1,j);
  }else{
    ll a=dfs(i+1,j+1)+(S[i]==T[j]?1:0);
    ll b=dfs(i+1,j);
    ll c=dfs(i,j+1);
    return dp[i][j]=max(a,max(b,c));
  }
}

void dfs2(int i,int j){
  if(i==n||j==m)return ;
  ll a=dfs(i+1,j+1)+(S[i]==T[j]?1:0);
  ll b=dfs(i+1,j);
  ll c=dfs(i,j+1);
  ll r=max(a,max(b,c));
  if(r==a){
    if(S[i]==T[j])res+=S[i];
    dfs2(i+1,j+1);
  }else if(r==b){
    dfs2(i+1,j);
  }else{
    dfs2(i,j+1);
  }
  return ;
}

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

  cin>>S>>T;
  n=S.size(); m=T.size();
  rep(i,n+1)rep(j,m+1)dp[i][j]=-INF;
  dfs(0,0);
  dfs2(0,0);
  cout<<res<<endl;

  return 0;
}


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

int dp[200000][13];

int main(){
	string s;cin>>s;
	dp[0][0]=1;
	rep(i,s.size())rep(j,13){
		if(s[i]=='?'){
			rep(k,10){
				(dp[i+1][(j*10+k)%13]+=dp[i][j])%=MOD;
			}
		}
		else{
			int d=s[i]-'0';
			(dp[i+1][(j*10+d)%13]+=dp[i][j])%=MOD;
		}
	}
	cout<<dp[s.size()][5]<<endl;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
using namespace std;
int main()
{


string s; cin >> s; int l=s.size();
sort(s.begin(),s.end());
    if(s[0]=='A' && s[l-1]=='B')
     cout <<"Yes"<<endl;
    else cout << "No";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
const long long mo=50000007;
const int maxn=200010;

int n,m,id[maxn],fa[maxn];
long long d[maxn],siz[maxn],ans,js[maxn];
int tot,nex[maxn*2],las[maxn*2],tov[maxn*2];
int hs[mo+10];

void con(int x,int y)
{
	tot++;
	tov[tot]=y;
	nex[tot]=las[x];
	las[x]=tot;
}

void insert(long long x,int id)
{
	long long i=x%mo;
	while (hs[i]!=0)
	{
		i++;
		if (i==mo) i=0;
	}
	hs[i]=id;
}

long long find(long long x)
{
	long long i=x%mo;
	while (hs[i]!=0 && d[hs[i]]!=x)
	{
		i++;
		if (i==mo) i=0;
	}
	return hs[i];
}

void qsort(int l,int r)
{
	int i=l;int j=r;
	long long m=d[(i+j)/2];
	while (i<=j)
	{
		while (d[i]>m) i++;
		while (d[j]<m) j--;
		if (i<=j)
		{
			swap(d[i],d[j]);
			swap(id[i],id[j]);
			i++;j--;
		}
	}
	if (l<j) qsort(l,j);
	if (r>i) qsort(i,r);
}

void dfs(int x,int ff)
{
	js[x]=js[ff]+1;
	for (int i=las[x];i;i=nex[i])
	{
		if (tov[i]!=ff)
		{
			dfs(tov[i],x);
			ans+=js[x];
		}
	}
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%lld",&d[i]);
		id[i]=i;
		siz[i]=1;
	}
	qsort(1,n);
	for (int i=1;i<=n;i++)
	{
		insert(d[i],i);
	}
	for (int i=1;i<n;i++)
	{
		long long op=d[i]-abs(n-2*siz[i]);
		long long oq=find(op);
		if (oq==0)
		{
			printf("-1\n");
			return 0;
		}
		else
		{
			fa[i]=oq;
			siz[oq]+=siz[i];
			con(i,oq);con(oq,i);
		}
	}
	dfs(n,0);
	if (ans!=d[n])
	{
		printf("-1\n");
		return 0;
	}
	else
	{
		for (int i=1;i<n;i++)
		{
			printf("%d %d\n",id[i],id[fa[i]]);
		}
	}
}

Measured memory_bytes: 208896
#include<bits/stdc++.h>
using namespace std;
long long x[100010],y[100010],z[100010];
int main(){

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

  long long a,b,c,cnt=0,ans=0,n;
  string s,v;
  char ad[5];

  cin>>s;
  if(s[0]=='A'){
    cout<<'T'<<'\n';
  }else if(s[0]=='T'){
    cout<<'A'<<'\n';
  }else if(s[0]=='G'){
    cout<<'C'<<'\n';
  }else if(s[0]=='C'){
    cout<<'G'<<'\n';
  }
}


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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;

const long long INF = 1LL << 60;

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

    cout << (A * B) / 2 << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = [int(_) for _ in input().split(' ')]

s1 = 0
s2 = sum(w)

answer = 10000
for i in range(n - 1):
    s1 += w[i]
    s2 -= w[i]
    if abs(s1 - s2) < answer:
        answer = abs(s1 - s2)
print(answer)


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

int main(){
    int n;
    cin >> n;
    if(n == 3){
        cout << 2 << endl;
    } else {
        int g = 0, k = 0;
        for(int i = 1; i <= n; i++){
            if(i % 2 == 0){
                g++;
            } else {
                k++;
            }
        }
        cout << g*k << endl;
    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)n; i++)
int main()
{
	string s, t;
	cin >> s >> t;
	int ans = 0;
	REP(i, 3)
	{
		if (s[i] == t[i])
		{
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> a(2*n);
    for(int i=0; i<2*n; i++){
        cin >> a[i];
    }
    int max=0;
    for(int i=0; i<n; i++){
        int sum = 0;
        int y=0;
        for(int j=0; j<n; j++){
            sum += a[y*n+j];
            if(i==j){
                y++;
                sum += a[y*n+j];
            } 
        }
        max = sum>max ? sum : max;
    }
    cout << max;
}


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

using namespace std;

#define REP(i,m) for(int i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define INF 1000000001
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define pb push_back
#define ll long long int
#define P pair<ll, ll>

int main() {
  int a, b, x;
  cin >> a >> b >> x;
  cout << ((a <= x && x <= (a+b)) ? "YES" : "NO") << endl;
  return 0;
}


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

//https://atcoder.jp/contests/m-solutions2019/tasks/m_solutions2019_d

const int nm = 1e4;

int n, c[nm], s = 0, num[nm], cursor;
vector<int> g[nm];

void dfs(int v, int p) {
	num[v] = c[cursor];
	cursor--;
	for (int nv : g[v]) {
		if (nv == p)
			continue;
		dfs(nv, v);
	}
}

int main() {
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(c, c + n);
	for (int i = 0; i < n - 1; i++)
		s += c[i];
	cursor = n - 1;
	dfs(0, 0);
	cout << s << endl;
	for (int i = 0; i < n; i++)
		cout << num[i] << (i < n - 1 ? " " : "\n");
}


Measured memory_bytes: 1408
import java.util.Scanner;
 
public class Main{
  public static void main(String[] args){
    Scanner scan=new Scanner(System.in);
    long A=scan.nextLong();
    long B=scan.nextLong();
    long K=scan.nextLong();
    
    if(A>K){
      A=A-K;
    }
    else if(A+B>K){ 
      B=B-K+A;
      A=0;
    }
    else{
      A=0;
      B=0;
    }
    System.out.println(A+" "+B);
  }
}

Measured memory_bytes: 23892
N = int(input())
A = list(map(int, input().split()))
B = []
for i in range(N):
    B.append([A[i]])
    B[i].append(i + 1)  # 出席番号をそれぞれ追加している
B = sorted(B)  # 人数でソート
ans = []
for ai in range(N):
    ans.append(B[ai][1])  # 人数順に出席番号で出力
print(" ".join(map(str, ans)))


Measured memory_bytes: 29932
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    int n;
    cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

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

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

  vector<int> p(n);
  for(int i=0;i<n;i++){
    cin>>p.at(i);
  }

  int ans = 0;
  for(int i=1;i<n-1;i++){
    if(p.at(i-1)<p.at(i) && p.at(i)<p.at(i+1)){
      ans += 1;
    }else if(p.at(i-1)>p.at(i) && p.at(i)>p.at(i+1)){
      ans += 1;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int n,p[100];
	int i,j,temp;
	int w[100],l[100],a[100];
	char t[100],m;

	scanf("%d",&n);
	while(n!=0){
		for(i=0;i<n;i++){
			w[i]=0;
			l[i]=0;
			scanf(" %c",&t[i]);
			a[i]=i;
			for(j=0;j<n-1;j++){
				scanf("%d",&p[j]);
				if(p[j]==0){
					w[i]++;
				}
				else if(p[j]==1){
					l[i]++;
				}
			}
		}
		for(i=0;i<n-1;i++){
			for(j=i+1;j<n;j++){
				if(w[i]<w[j]){
					temp=w[i];
					w[i]=w[j];
					w[j]=temp;
					temp=l[i];
					l[i]=l[j];
					l[j]=temp;
					m=t[i];
					t[i]=t[j];
					t[j]=m;
					temp=a[i];
					a[i]=a[j];
					a[j]=temp;
				}
				else if(w[i]==w[j]){
					if(l[i]>l[j]){
						temp=w[i];
						w[i]=w[j];
						w[j]=temp;
						temp=l[i];
						l[i]=l[j];
						l[j]=temp;
						m=t[i];
						t[i]=t[j];
						t[j]=m;
						temp=a[i];
						a[i]=a[j];
						a[j]=temp;
					}
					else if(l[i]==l[j] && a[i]>a[j]){
						temp=w[i];
						w[i]=w[j];
						w[j]=temp;
						temp=l[i];
						l[i]=l[j];
						l[j]=temp;
						m=t[i];
						t[i]=t[j];
						t[j]=m;
						temp=a[i];
						a[i]=a[j];
						a[j]=temp;
					}
				}
			}
		}
		for(i=0;i<n;i++){
			printf("%c\n",t[i]);
		}
		scanf("%d",&n);
	}
	return 0;
}

Measured memory_bytes: 1032
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
using namespace std;

typedef pair<int, int> pii;


int main(int argc, char* argv[]) {

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

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

	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] * 4 * m >= sum) {
			cnt++;
		}
	}

	if (cnt >= m) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}


}

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

#define vi vector<int>
#define pb push_back
#define ii pair<int, int>
#define x first
#define y second

int main() {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int r; cin >> r; cout << r * r;
	return 0;
}

Measured memory_bytes: 256
N=int(input())
ans=-10**9
s=["".join(list(input().split())) for i in range(N)]
t=[list(map(int,input().split())) for i in range(N)]
for j in range(1,1024):
    q=0
    for i in range(len(s)):
        q+=t[i][(bin(int(s[i],2)&j)).count("1")]
    ans=max(ans,q)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long int
int main()
{
   ll l,r;
   cin>>l>>r;
      if(r-l>2019)
        cout<<0;
      else
      {   ll ans=2020;
          for(ll i= l;i<r;i++)
          {
              for(ll j=i+1;j<=r;j++){
                ans=min(ans,(((i%2019)*(j%2019))%2019));
              }
          }
          cout<<ans;
      }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
#include<stdlib.h>
using namespace std;
typedef long long ll;
int n,m;
int a[110000];
ll K[810000],B[810000],ans,Ans=1ll<<60;

int Fabs(int x){
    return x>0?x:-x;
}

void modify(int v,int l,int r,int ql,int qr,int k,int b){
 //   printf("%d %d %d %d %d %d\n",l,r,ql,qr,k,b);
    if(qr<ql)return;
    if(l>=ql&&r<=qr){
        K[v]+=k;
        B[v]+=b;
        return;
    }int mid=(l+r)>>1;
    if(mid>=ql)modify(v<<1,l,mid,ql,qr,k,b);
    if(mid<qr)modify((v<<1)|1,mid+1,r,ql,qr,k,b);
}

ll query(int v,int l,int r,int pos){
    if(l==r)return (ll)K[v]*l+B[v];
    K[v<<1]+=K[v];
    K[(v<<1)|1]+=K[v];
    K[v]=0;
    B[v<<1]+=B[v];
    B[(v<<1)|1]+=B[v];
    B[v]=0;
    int mid=(l+r)>>1;
    if(mid>=pos)return query(v<<1,l,mid,pos);
    else return query((v<<1)|1,mid+1,r,pos);
}

int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }for(int i=1;i<n;i++){
        int dis;
        if(a[i+1]>a[i]){
            dis=a[i+1]-a[i];
            if(dis!=1){modify(1,1,m,a[i]+1,a[i+1],1,dis-1-a[i+1]);}
        }else{
            dis=m-a[i]+a[i+1];
            if(a[i]<m-1){modify(1,1,m,a[i]+2,m,1,-a[i]-1);}
            modify(1,1,m,1,a[i+1],1,dis-1-a[i+1]);
        }ans+=dis;
    }for(int i=1;i<=m;i++){
        Ans=min(Ans,ans-query(1,1,m,i));
    }printf("%lld\n",Ans);
}

Measured memory_bytes: 8832
#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(){
    int N, A, B;
    cin >> N >> A >> B;
    cout << min(B, N * A) << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int N = sc.nextInt();
        int Q = sc.nextInt();
        String S = sc.next();

        int[] cumS = new int[N];
        cumS[0] = 0;
        for (int i = 1; i < N; i += 1) {
            char prevS = S.charAt(i - 1);
            char curS = S.charAt(i);
            if (prevS == 'A' && curS == 'C') {
                cumS[i] = cumS[i - 1] + 1;
            } else {
                cumS[i] = cumS[i - 1];
            }
        }

        int lq, rq, ansq;
        for (int q = 0; q < Q; q += 1) {
            lq = Integer.parseInt(sc.next());
            rq = Integer.parseInt(sc.next());
            ansq = cumS[rq - 1] - cumS[lq - 1];
            System.out.println(ansq);
        }
    }

}


Measured memory_bytes: 49912
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second 
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rep(i,a,b) for( ll i = a ; i < b ; i+=1 )
#define pp pair<ll,ll> 
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t = 1 ;
void solve()
{
    ll n , a , b , x , y , ans=0 ;
    cin >> n ;
    vector<ll> v(n+1) ;
    vector<pp> aa ;
    set<ll> seta ;
    rep( i , 1 , n + 1 ){
        cin >> v[i] ;
        aa.pb({-v[i],i});
    }
    sort(all(aa));
    rep(i,0,n){
        // find a , b , x , y
        seta.insert(aa[i].se);
        auto it = seta.find(aa[i].se) ;
        if( it != seta.begin() ){
            it--;
            b = *it ;
            if( it != seta.begin() ){
                it--;
                a = *it ;
            }
            else
                a = 0 ;
        }
        else{
            a = 0 ;
            b = 0 ;
        }
        it = seta.find(aa[i].se) ;
        it++;
        if(it!=seta.end())
        {
			x = *it ;
			it++;
			if(it!=seta.end())
				y = *it ;
			else
				y = n + 1 ;
		}
		else
			x = y = n+1 ;
        ans += ((b-a)*(x-aa[i].se)+(y-x)*(aa[i].se-b))*(-aa[i].fi) ;
    }
    cout << ans << "\n" ;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //cin >> t ;
    while(t--){
        solve();
    }
    return 0 ;
}


Measured memory_bytes: 7280
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define sz(v) (ll((v).size()))
#define forn(i,n) for(ll i=0;i<(n);i++)
#define forr(i,n) for(ll i=(n)-1;i>=0;i--)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))


int main()
{
	ios_base::sync_with_stdio(false);

	ll n,m,k,ans=0;cin>>n>>m>>k;
	string s[n];
	forn(i,n)cin>>s[i];

	ll nx = (1<<n),mx = (1<<m);

	forn(ix,nx)forn(jx,mx){

		ll cnt=0;
		forn(i,n)forn(j,m){
			if(s[i][j]!='#')continue;
			if(ix&(1<<i))continue;
			if(jx&(1<<j))continue;
			cnt++;
		}
		if(cnt == k)ans++;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pi 3.141592653589793238
#define int long long
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int sz=(1<<18)+5;
multiset<int>s[sz];
int a[sz];

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

  #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout);
      }
  #endif  

  int n;
  cin>>n;
  for(int i=0;i<(1<<n);i++)
  {
    cin>>a[i];
    s[i].insert(a[i]);
  }
  int lim=(1<<n);
  for(int i=0;i<n;i++)
  {
    for(int mask=0;mask<lim;mask++)
    {
      if(mask&(1<<i))
      {
        for(auto j:s[mask^(1<<i)])
          s[mask].insert(j);
        while(s[mask].size()>2)
          s[mask].erase(s[mask].begin());
      }
    }
  }
  int mx=0;
  for(int i=1;i<lim;i++)
  {
    int ans=0;
    for(auto j:s[i])
      ans+=j;
    mx=max(mx,ans);
    cout<<mx<<'\n';
  }

}

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

int		main()
{
	char	name[101];
	char	last[101];
	char	**names;
	int		*time;
	int	N;
	// int	seconds;
	int	duration;
	int	i, r;

	i = 0;
	duration = 0;
	r = scanf("%d\n", &N);
	names = (char **)malloc(sizeof(char *) * (N + 1));
	time = (int *)malloc(sizeof(int) * (N + 1));
	if (r != 1 || !time || !names) //if malloc error or scan error
		return (0);
	while(i < N)
	{
		names[i] = (char *)malloc(sizeof(char) * 101);
		if (names[i])
			r = scanf("%s %d\n", names[i], &time[i]);
		if (r != 2 || !names[i])
			return (0);
		i++;
	}
	r = scanf("%s\n", last);
	i = 0;
	while (i < N)
	{
		if (!strcmp(names[i], last))
			break ;
		i++;
	}
	i++;
	while (i < N)
	{
		duration += time[i];
		i++;
	}
	printf("%d\n", duration);
	return (0);
}


Measured memory_bytes: 128
<?php
$n = 6;
$n -= int();
$n -= int();
echo $n;
function str(){
  return trim(fgets(STDIN));
}
function ints(){
  return array_map("intval", explode(" ", trim(fgets(STDIN))));
}
function int(){
  return intval(trim(fgets(STDIN)));
}
function o(...$val){
    if(count($val)==1)$val = array_shift($val);
    $trace = debug_backtrace();
    echo $trace[0]['line'].")";
    if(is_array($val)){
        if(count($val) == 0){
            echo "empty array";
        }elseif(!is_array(current($val))){
            echo "array:";
            echo implode(" ", $val)."\n";
        }else{
            echo "array:array\n";
            foreach($val as $row){
                echo implode(" ", $row)."\n";
            }
        }
    }else{
        echo $val."\n";
    }
}

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
int n,m;
long long para[1200][4],f[1200],res,cand;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>para[i][1]>>para[i][2]>>para[i][3];
	}
	for(int i=0;i<8;i++){
		for(int k=1;k<=n;k++)
			f[k]=0;
		int t=i;
		for(int j=1;j<=3;j++){
			for(int k=1;k<=n;k++)
				f[k]+=(para[k][j]*(t%2==0?1:-1));
			t/=2;
		}
		sort(f+1,f+n+1);
		reverse(f+1,f+n+1);
		cand=0;
		for(int j=1;j<=m;j++){
			cand+=f[j];
		}
		res=max(res,cand);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
// Template
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <cmath>
#include <complex>
#define rep(i, x) for (int i = 0; i < (x); ++i)
#define rng(i, x, y) for (int i = (x); i < (y); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T &x, const T &y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T &x, const T &y) {if (x < y) {x = y; return 1;} return 0;}
void solve();
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    solve();
    return 0;
}

// Main Code
void solve() {
    int h, w, k, x1, y1, x2, y2;
    cin >> h >> w >> k >> x1 >> y1 >> x2 >> y2;
    --x1; --y1; --x2; --y2;
    vector<vector<char>> c(h, vector<char>(w, '.'));
    rep(i, h) rep(j, w) cin >> c[i][j];
    
    auto f = [h, w](int x, int y, int m) -> int {return x * w + y + m * h * w;};
    auto g = [h, w](int z) -> tuple<int, int, int> {return tuple<int, int, int>(z % (h * w) / w, z % (h * w) % w, z / (h * w));};
    const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    
    vector<ll> dist(h * w * 4, INF);
    vector<bool> used(h * w * 4, false);
    priority_queue<pair<ll, int>> pq;
    rep(i, 4) {
        dist[f(x1, y1, i)] = 0;
        pq.push(pair<int, int>(0, f(x1, y1, i)));
    }
    while (!pq.empty()) {
        auto [x, y, m] = g(pq.top().second);
        pq.pop();
        if (used[f(x, y, m)]) continue;
        rep(i, 4) {
            if (x + dx[i] < 0 || x + dx[i] >= h || y + dy[i] < 0 || y + dy[i] >= w) continue;
            if (c[x + dx[i]][y + dy[i]] == '@') continue;
            if (i == m) {
                if (chmin(dist[f(x + dx[i], y + dy[i], m)], dist[f(x, y, m)] + 1)) {
                    pq.push(pair<ll, int>(-dist[f(x + dx[i], y + dy[i], i)], f(x + dx[i], y + dy[i], i)));
                }
            } else {
                ll dis = dist[f(x, y, m)];
                dis = (dis + k - 1) / k * k;
                ++dis;
                if (chmin(dist[f(x + dx[i], y + dy[i], i)], dis)) {
                    pq.push(pair<ll, int>(-dist[f(x + dx[i], y + dy[i], i)], f(x + dx[i], y + dy[i], i)));
                }
            }
        }
        used[f(x, y, m)] = true;
    }
    
    ll res = INF;
    rep(i, 4) chmin(res, (dist[f(x2, y2, i)] + k - 1) / k * k);
    if (res == INF) cout << -1 << "\n";
    else cout << res / k << "\n";
    return;
}


Measured memory_bytes: 40140
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	string s;
	while (cin >> s, s != "#") {
		int cnt = 0;
		int c = 0, p = 1;
		vector<int>v;
		while (cnt < s.size()) {
			if (s[cnt] == 'n') {
				v.push_back(-1);
				cnt += 5;
			}
			else {
				v.push_back(1);
				cnt += 4;
			}
		}
		for (int i = v.size() - 1; i >= 0; i--) {
			p <<= 1;
			c <<= 1;
			c += v[i];
			c = max(c, 0);
		}
		c *= 90;
		p >>= 1;
		while (c % 2 == 0 && p % 2 == 0) {
			c >>= 1;
			p >>= 1;

		}
		if (p > 1) {
			cout << c << "/" << p << endl;
		}
		else {
			cout << c << endl;
		}
	}
}


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

using namespace std;

#define forn(i, n) for (int i = 0; i < int(n); i++)
typedef long long LL;

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5])
	cout << "Yes";
	else
	cout << "No";
	return 0;
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	vector<pair<int, int>> v;
	rep(i, n) {
		v.push_back(make_pair(a[i], i));
	}
	sort(v.begin(), v.end());

	for (auto u : v)
		cout << u.second + 1 << " ";
	cout << endl;
	return 0;
}


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

int main() {
        int n;
        scanf("%d", &n);
        int c = 0;
        long long ans = 0;
        int mi = 1e9 + 6;
        vector<int> a(n);
        rep(i, n) {
                scanf("%d", &a[i]);
                c += a[i] < 0;
                ans += abs(a[i]);
                mi = min(mi, abs(a[i]));
        }
        if (c % 2 == 0) {
                printf("%lld\n", ans);
        } else {
                printf("%lld\n", ans - 2 * mi);
        }
        return 0;
}


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

int gcd(long long a, long long b) {
  if(a < b) return gcd(b, a);
     if (b == 0) return a;
    else return gcd(b, a % b);
}
  
int main(){
  int N,K;
  cin>>N>>K;
  int A[N];
  cin>>A[0];
  int GCD=A[0];
  int amax=A[0];
  for(int i=1;i<N;i++){
    cin>>A[i];
    GCD=gcd(GCD,A[i]);
    amax=max(amax,A[i]);
  }
  
  //cout<<GCD<<" "<<amax<<endl;
  if(K%GCD==0 && K<=amax){
    cout<<"POSSIBLE"<<endl;
    return 0;
  }
  cout<<"IMPOSSIBLE"<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const ll INFL = (1LL << 62);
const ll MOD = 1000000007;
template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T gcd(T a, T b) {
    return b ? gcd(b, a % b) : a;
}
template <class T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}
template <class T>
ll mod_pow(ll a, ll n, T mod) {
    mod = (ll)mod;
    ll res = 1, p = a % mod;
    while (n) {
        if (n & 1) res = res * p % mod;
        p = p * p % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    unordered_map<int, int> count;
    rep(i, N) {
        int a;
        cin >> a;
        A[i] = a;
        count[a]++;
    }
    int count_even_pair = 0;
    set<int> nums(all(A));
    for (auto& a : nums) {
        if (!(count[a] & 1)) count_even_pair++;
    }
    if (count_even_pair & 1) {
        cout << (int)count.size() - 1 << endl;
    } else
        cout << count.size() << endl;

    return 0;
}

Measured memory_bytes: 9508
#include<bits/stdc++.h>
using namespace std;
int n,t[9];
int main()
{
    scanf("%d",&n);
    if(n==3)printf("2 5 63");
    else
    {
        if(n&1)
            t[0]=6,t[1]=2,t[2]=10,t[3]=3,t[4]=9,t[5]=4,t[6]=8,t[7]=12;
        else
            t[0]=2,t[1]=10,t[2]=3,t[3]=9,t[4]=4,t[5]=8,t[6]=6,t[7]=12;
        for(int i=0; i<min(n,8); i++)printf("%d ",t[i]);
        for(int i=8; i<n; i++)t[i%8]=t[i%8]+12,printf("%d ",t[i%8]);
    }
    return 0;
}


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

int main(){
  int n, ans = 0;
  cin >> n;
  map<string, int> s;
  string word;
  for(int i = 0; i < n; i++){
    cin >> word;
    if(s.count(word)) continue;
    else{
      s[word] = 1;
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 19180
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    using namespace __gnu_pbds;
    using namespace std;
     
    typedef long long ll;
    typedef tree<int,null_type,less<int>,rb_tree_tag,
    		tree_order_statistics_node_update> indexed_set;
     
    #define br printf("\n")
     
    string solve(ll num) {
    	ll ch = 26;
    	ll len = 0;
    	while (num > ch) {
    		num -= ch;
    		ch *= 26;
    		len++;
    	} len += 1;
    	num--;
    	string str = "";
    	while (len--) {
    		ll rem = num % 26;
    		num /= 26;
    		str += (char)(rem + 'a');
    	}
    	reverse(str.begin(), str.end());
    	return str;
    }
    		
     
    int main () {
    	ios::sync_with_stdio(1);
    	cin.tie(0);
     
    //	freopen("input.txt", "r", stdin);
    //	freopen("output.txt", "w", stdout);
     
    	ll num;
    	cin >> num;
    	cout << solve(num) << '\n';
    	return 0;
    }

Measured memory_bytes: 3476
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define veci vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vec>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))


using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x:vec) is >> x;
    return is;
}
const ll mod=1e9+7;


int main()
{
    ll h,w,k;
    cin >> h >> w >> k;
    vector<vector<char>> s(h,vector<char>(w));
    
    vector<ll> a(h,0);
    rep(i,h){
        bool flag=false;
        rep(j,w){
            cin >> s[i][j];
            if(s[i][j]=='#'){
                flag=true;
            }
        }
        if(!flag) a[i]=1;
    }
    ll color=1;
    ll count=0;
    vector<vector<ll>> ans(h,vector<ll>(w));
    rep(i,h){
        if(a[i]==1) continue;
        else count++;
        ll cnt=0; //その行でいちごを数えたかどうか
        rep(j,w){
            if(s[i][j]=='.'){
                ans[i][j]=color;
            }
            else{
                if(cnt==0) ans[i][j]=color;
                else ans[i][j]=++color;
                cnt++;
            }
        }
        color++;
    }
    ll number=1;
    map<ll,ll> m;
    vector<ll> t(h);
    rep(i,h){
        if(a[i]==1){
            t[i]=number;
        }
        else{
            t[i]=number;
            m[number]=i;
            number=min(number+1,count);
        }
    }
    rep(i,h){
        rep(j,w){
            if(a[i]==1){
                ll p=m[t[i]];
                cout << ans[p][j] << " ";
            }
            else{
                cout << ans[i][j] << " ";
            }
        }
        cout << endl;
    }
    return 0;
} 

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

int main() {
	int n;
  	cin >> n;
  
  	char s[n];
  	rep(i,n)cin>>s[i];
  
  	int ans=n;
  
  	for(int i=1;i<n;i++){
    	if(s[i]==s[i-1]){
        	ans--;
        }
    }
  
  cout<<ans<<endl;
}

Measured memory_bytes: 3716
int main()
{
    int N,C,A,i,o;
    scanf("%d",&N);
    C=0;
    A=0;
for(i=1;N>=i;i++)
{
    if(i%2!=0)
    {
        for(o=1;i>=o;o++)
        {
            if(i%o==0)
            {
                C++;
            }
        }
        if(C==8)
        {
            A++;
        }
        C=0;
    }
}

printf("%d",A);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <utility>

using namespace std;

#define pb push_back
#define ft first
#define sd second
#define mpr make_pair
#define all(x) begin((x)), end((x))
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int (i) = 0; (i) < (n); ++(i))
#define max3(a, b, c) max((a), max((b), (c)))
#define max4(a, b, c, d) max(max((a), (b)), max((c), (d)))
#define min3(a, b, c) min((a), min((b), (c)))
#define min4(a, b, c, d) min(min((a), (b)), min((c), (d)))
#define isz(x) (int)(x).size()

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;

/* <------------------------------------------------------------------------------------> */

deque<int> q;

void solve()
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i)
    {
        int a;
        scanf("%d", &a);
        if (n & 1)
        {
            if (i & 1) q.push_back(a);
            else q.push_front(a);
        }
        else
        {
            if (i & 1) q.push_front(a);
            else q.push_back(a);
        }
    }
    while (!q.empty())
    {
        printf("%d ", q.back());
        q.pop_back();
    }
    puts("");
}

/* <------------------------------------------------------------------------------------> */

// #define LOCAL
// #define FILE_NAME

int main()
{
    #if defined LOCAL
        freopen("input.txt", "r", stdin);
    #elif defined FILE_NAME
        freopen(FILE_NAME".in", "r", stdin);
        freopen(FILE_NAME".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3072