akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define feach(it, v) for (vector<rec>::iterator it = (v).begin(); it != (v).end(); ++ it)
#define pb push_back
#define ri rd<int>
using namespace std;
typedef long long LL;
const int maxN = 3e5 + 7;
const LL INF = 1LL << 61;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

struct rec {
	LL v; int i;
};

int n, m;
LL a[2][maxN], s[2][maxN], f[2][maxN], g[2][maxN];
vector<rec> ask[2][maxN];
LL ans[maxN];

inline void Max(LL &x, LL y) {
	if (y > x) x = y;
}

inline LL eval(LL *f, LL *s, LL x) {
	return 2LL * (f[x] + s[x]) + x * x - x;
}

inline LL up(int x, int y, LL *f, LL *s) {
	return eval(f, s, y) - eval(f, s, x);
}

inline LL dw(int x, int y) {return y - x;}

void pre(int kd) {
	static int q[maxN];
	int h = 1, t = 0;
	q[++t] = 0;
	rep (i, 1, n) s[kd][i] = s[kd][i - 1] + a[kd][i];

	f[kd][0] = 0;
	rep (i, 1, n) {
		f[kd][i] = f[kd][i - 1];
		while (h < t && up(q[t - 1], q[t], f[kd], s[kd]) < 2LL * i * dw(q[t - 1], q[t])) -- t;
		int j = q[t];
		Max(f[kd][i], f[kd][j] + 1LL * (i - j) * (i - j + 1) / 2 - s[kd][i] + s[kd][j]);
		while (h < t && up(q[t - 1], q[t], f[kd], s[kd]) * dw(q[t], i) < up(q[t], i, f[kd], s[kd]) * dw(q[t - 1], q[t])) -- t;
		q[++t] = i;
	}
}

void gao(int kd, int l, int r, int mid) {
	static int q[maxN];
	int h = 1, t = 0;
	q[++t] = l - 1;

	rep (i, l, mid) {
		g[kd][i] = f[kd][i];
		while (h < t && up(q[t - 1], q[t], g[kd], s[kd]) * dw(q[t], i) < up(q[t], i, g[kd], s[kd]) * dw(q[t - 1], q[t])) -- t;
		q[++t] = i;
	}
	rep (i, mid + 1, r) {
		while (h < t && up(q[t - 1], q[t], g[kd], s[kd]) < 2LL * i * dw(q[t - 1], q[t])) -- t;
		int j = q[t];
		g[kd][i] = g[kd][j] + 1LL * (i - j) * (i - j + 1) / 2 - s[kd][i] + s[kd][j];
	}
	per (i, r, mid + 1) {
		g[kd][i] += f[kd ^ 1][n - i];
		if (i < r) Max(g[kd][i], g[kd][i + 1]);
		feach(it, ask[kd][i])
			Max(ans[it -> i], g[kd][i] + a[kd][i] - (it -> v));
	}
}

void solve(int l, int r) {
	int mid = (l + r) >> 1;
	if (l >= r) return; // only include i is always bad ( + 1 - a)
	solve(l, mid - 1);
	solve(mid + 1, r);
	gao(0, l, r, mid);
	gao(1, n - r + 1, n - l + 1, n - (mid + 1) + 1);
}

int main() {

	n = ri();
	rep (i, 1, n) a[0][i] = a[1][n + 1 - i] = ri();
	pre(0), pre(1);

	m = ri();
	rep (i, 1, m) {
		int p = ri(), v = ri();
		ask[0][p].pb((rec){v, i});
		ask[1][n - p + 1].pb((rec){v, i});
		ans[i] = f[0][p - 1] + f[1][n - p]; // i not included
	}

	solve(1, n);
	rep (i, 1, m) 
		printf("%lld\n", ans[i]);

	return 0;
}

Measured memory_bytes: 58240
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <queue>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define Set(i, v) memset(i, v, sizeof i)
#define pb push_back

using namespace std;

const int N = 60;
const int Mod = 1e9 + 7;

int n;
char S[2][N];

int main(){
	scanf("%d", &n);
	For(i, 0, 1) scanf("%s", S[i] + 1);
	long long ans = 1;
	For(i, 1, n){
		if(S[0][i] == S[1][i]){
			if(i == 1) ans = ans * 3 % Mod;
			else if(S[0][i - 1] == S[1][i - 1]) ans = ans * 2 % Mod;
		}
		else{
			if(i == 1) ans = ans * 6 % Mod;
			else if(S[0][i - 1] == S[1][i - 1]) ans = ans * 2 % Mod;
			else ans = ans * 3 % Mod;
			++i;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    bool down = true;
    int cnt = 0;
    bool l = false, r = false;
    for(int i=0;i<n;++i) {
      string s; cin >> s;
      if(s == "lu") {
        l = true;
      } else if(s == "ld") {
        l = false;
      } else if(s == "ru") {
        r = true;
      } else {
        r = false;
      }
      if(down && l && r) {
        down = false;
        cnt++;
      } else if(!down && !l && !r) {
        down = true;
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}



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

using namespace std;
/*                                   法一  搜索+判断   TLM
int n;
bool flag = true;
int arr[100005];
bool visit[100005];
int result[100005];

bool Judge(int arr[]) {
	for (int i = 0; i < sizeof(arr) - 1; ++i) {
		if (arr[i] * arr[i + 1] % 4 != 0) {
			return false;
		}
	}
	return true;
}

void DFS(int count) {
	if (flag == false)return;
	if (count == n) {
		if (Judge(result)) {
			if (flag) {
				cout << "Yes" << endl;
				flag = false;
				return;
			}
		}
	}
	for (int i = 0; i < n; ++i) {
		if (visit[i] == 0) {
			visit[i] = 1;
			result[count] = arr[i];
			DFS(count + 1);
			visit[i] = 0;
		}
	}
}


int main() {
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
	}
	DFS(0);
	if (flag) {
		cout << "No" << endl;
	}
	return 0;
}*/




int main() {
	int n;
	int a1 = 0, a2 = 0, a4 = 0,temp;
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> temp;
		if (temp % 4 == 0) a4++;
		else if (temp % 2 == 0) a2++;
		else a1++;
	}
	if (a2 == 0) {
		if (a1 > a4 + 1) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
			return 0;
		}
	}
	else {
		if (a1 > a4) {
			cout << "No" << endl;
			return 0;
		}
		else {
			cout << "Yes" << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 632
#include <bits/stdc++.h>
#define N 510
using namespace std;
typedef pair<int,int> P;
int h,w;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};
bool mp[N][N][4],used[N][N]={},gxy[N][N];;

bool check(int x,int y){
  bool f[2]={};
  for(int i=0;i<4;i++){
    int nx=x+dx[i],ny=y+dy[i];
    f[mp[y][x][i]]|=(nx==0||ny==0||nx==w+1||ny==h+1||used[ny][nx]);
  }
  return f[0]&&f[1];
}

bool bfs(){
  memset(used,0,sizeof(used));
  queue<P>Q; 
  for(int i=1;i<=h;i++)
    for(int j=1;j<=w;j++) 
      if(check(j,i))Q.push(P(j,i)),used[i][j]=1;
  
  while(!Q.empty()){
    P t=Q.front();Q.pop();
    int x=t.first,y=t.second;
    if(gxy[y][x])return 1;
    for(int i=0;i<4;i++){
      int nx=x+dx[i],ny=y+dy[i];
      if(nx==0||ny==0||nx==w+1||ny==h+1||used[ny][nx])continue;
      if(check(nx,ny))Q.push(P(nx,ny)),used[ny][nx]=1;
    }
  }
  return 0;
}

int main(){
  while(1){
    int sy,sx; 
    cin>>h>>w>>sy>>sx;
    if(!h&&!w&&!sy&&!sx)break;
    for(int i=1;i<=h+1;i++){
      for(int j=1,a;j<=w;j++)cin>>a,mp[i-1][j][2]=mp[i][j][0]=a;
      for(int j=1,a;j<=w+1&&i<h+1;j++)cin>>a,mp[i][j-1][1]=mp[i][j][3]=a;
    }
    
    memset(gxy,0,sizeof(gxy));
    int ans=0;
    for(int i=0;i<4;i++)
      if(!mp[sy][sx][i]){
	int nx=sx+dx[i],ny=sy+dy[i];
	gxy[ny][nx]=1;
	if(nx==0||ny==0||nx==w+1||ny==h+1)ans=1;
      }
    cout <<(ans||bfs()? "Yes":"No")<<endl;
  }
  return 0;

}

Measured memory_bytes: 4676
#include<iostream>
#include<string>
#include<algorithm>
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define REP(i,b) FOR(i,0,b)
using namespace std;

int main(void) {
	int a, b, c, p ;
	int count = 0;

	cin >> a >> b >> c;
	FOR(i, 1, b) {
		p = a*i;
		if (p%b == c) {
			count = 1;
			break;
		}
	}
	if (count == 0) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,x;//n=マスの合計 m=料金所の数(指定) x=最初にいるマス
    scanf("%d %d %d",&n,&m,&x);
    vector<bool> mas(n+1);

    for(int i=0;i<m;i++){
        int tmp=0;
        scanf("%d",&tmp);
        mas[tmp]=1;
    }

    int left=0,right=0,suml=0,sumr=0;
    for(int i=x-1;i>=0;i--){
        if(mas[i])
           suml++;
    }
    for(int i=x+1;i<=n;i++){
        if(mas[i])
            sumr++;
    }

    printf("%d\n",min(suml,sumr));
 }



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	string S;
	cin >> S;
	int X, Y;
	cin >> X >> Y;
	int N = S.size();
	vector< int > A;
	int k = 0;
	rep(i, N) {
		if (S[i] == 'T') {
			A.push_back(k);
			k = 0;
		} else {
			++k;
		}
	}
	A.push_back(k);
	X -= A[0];
	vector< int > DX, DY;
	for (int i = 1; i < A.size(); i++) {
		if (i % 2) {
			DY.push_back(A[i]);
		} else {
			DX.push_back(A[i]);
		}
	}
	//cout << DX << DY;
	vector< vector< int > > dpx(2, vector< int >(20000, 0)), dpy(2, vector< int >(20000, 0));
	vector< int > &nowx = dpx[0];
	vector< int > &nextx = dpx[1];
	nowx[10000] = 1;
	rep(i, DX.size()) {
		nextx.assign(20000, 0);
		rep(j, 20000) {
			if (nowx[j]) {

				nextx[j + DX[i]] = 1;
				nextx[j - DX[i]] = 1;
			}
		}
		swap(nowx, nextx);
	}
	vector< int > &nowy = dpy[0];
	vector< int > &nexty = dpy[1];
	nowy[10000] = 1;
	rep(i, DY.size()) {
		nexty.assign(20000, 0);
		rep(j, 20000) {
			if (nowy[j]) {

				nexty[j + DY[i]] = 1;
				nexty[j - DY[i]] = 1;
			}
		}
		swap(nowy, nexty);
	}
	string ans = (nowx[X + 10000] & nowy[Y + 10000]) ? "Yes" : "No";
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1248
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception{
		PrintWriter pw=new PrintWriter(System.out);
		MScanner sc = new MScanner(System.in);
		pw.println(sc.nextInt()<=sc.nextInt()?"unsafe":"safe");
		pw.flush();
	}
	static class MScanner {
		StringTokenizer st;
		BufferedReader br;
		public MScanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}
 
		public MScanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}
 
		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int[] intArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public long[] longArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public int[] intSortedArr(int n) throws IOException {
	        int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public long[] longSortedArr(int n) throws IOException {
	        long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        shuffle(in);
	        Arrays.sort(in);
	        return in;
		}
		public Integer[] IntegerArr(int n) throws IOException {
	        Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
	        return in;
		}
		public Long[] LongArr(int n) throws IOException {
	        Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
	        return in;
		}
		public String nextLine() throws IOException {
			return br.readLine();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public char nextChar() throws IOException {
			return next().charAt(0);
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public boolean ready() throws IOException {
			return br.ready();
		}
 
		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
	static void shuffle(int[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			int tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static void shuffle(long[]in) {
		for(int i=0;i<in.length;i++) {
			int idx=(int)(Math.random()*in.length);
			long tmp=in[i];
			in[i]=in[idx];
			in[idx]=tmp;
		}
	}
	static String arrToString(int[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(long[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Integer[]x) {
		return Arrays.toString(x);
	}
	static String arrToString(Long[]x) {
		return Arrays.toString(x);
	}
}

Measured memory_bytes: 32664
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
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;
}
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}

using Graph=vector<vector<int>>;
Graph G;

int main(){
  //input
  int n, w;
  cin >> n >> w;
  vector<int> weight(n);
  vector<ll> value(n);
  rep(i,n) cin >> weight[i] >> value[i];
  
  //initialization
  ll dp[110][100010]={0};
  
  //compute
  rep(i,n){
    for(int sum_w=0;sum_w<=w;sum_w++){
		if(sum_w-weight[i]>=0) dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w-weight[i]]+value[i]);
        dp[i+1][sum_w]=max(dp[i+1][sum_w],dp[i][sum_w]);
    }
  }
  
  //output
  cout << dp[n][w]<< endl;
  
  
}
    


Measured memory_bytes: 86144
currentPlace = []
array = []
height = 0
start = 0
abs_len = 0

def get_input():
    array = []
    N = []
    while True:
        try:
            str1,str2,str3 = input().split()
            int1,int2,int3 = int(str1),int(str2),int(str3)
            if int1 == 0 and int2 == 0 and int3 == 0:
                break
            yield [int1,int2,int3]
        except EOFError:
            break

if __name__ == '__main__':
    array_total = list(get_input())
    #print(array)
    while True:
        #print("start???{0}".format(start))
        height = array_total[start][1]
        who = array_total[start][2]
        array = array_total[start:start+height+1]
        #print(array)
        #print("height???{0}".format(height))

        #print("?????????{0}".format(array[start]))
        #??¢????????????????????????????????????
        currentPlace = [height,who]
        #print("??±???array???{0}".format(array))
        del array[0]
        array.sort(key = lambda x:x[0],reverse = True)
        #print(array)

        for i in range(len(array)):
            currentPlace[0] = int(array[i][0])
            #print("?????¨?????????{0}".format(currentPlace))
            #print(currentPlace)
            if (int(array[i][0]) == currentPlace[0]
            and (int(array[i][1]) == currentPlace[1]
            or int(array[i][2]) == currentPlace[1])):
                if int(array[i][1]) == currentPlace[1]:
                    currentPlace[1] = int(array[i][2])
                else:
                    currentPlace[1] = int(array[i][1])
                #print("?????¨?????????{0}????§????".format(currentPlace))

        print(currentPlace[1])
        #?¬??????¢???????????????????????????start?????£??\

        start = start + height + 1
        abs_len = abs_len + height + 1
        #print(abs_len)
        del array[:]

        if abs_len + 1 > len(array_total):
            break

Measured memory_bytes: 12488
n = int(input())
X = list(map(int, input().split()))
x_min = min(X)
x_max = max(X)

min_val = 10**6 + 1

for i in range(x_min, x_max + 1):
    min_val = min(min_val, sum(map(lambda x: (x-i)**2, X)))

print(min_val)

Measured memory_bytes: 8820
package main

import (
	"bufio"
	"fmt"
	"os"
	"reflect"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	n := nextInt()
	ts := nextInts(n)
	m := nextInt()

	for i := 0; i < m; i++ {
		p, x := nextInt()-1, nextInt()
		ans := 0
		for j := 0; j < n; j++ {
			if j != p {
				ans += ts[j]
			} else {
				ans += x
			}
		}
		fmt.Fprint(out, ans, "\n")
	}
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back

using namespace std;
using ll = long long int;
const int MOD = 1e9 + 7;
const int LOG = 22;
const int N = 1 << LOG;

ll dp[N];
int a[LOG][LOG];

ll func(int mask)
{
	if (mask == 0) return 1;
	auto &ret = dp[mask];
	if (ret != -1) return ret;

	int girl = __builtin_popcount(mask) - 1;
	ret = 0;
	for (int bit = 0; bit < LOG; ++bit)
	{
		if ((mask & (1 << bit)) and a[bit][girl])
		{
			ret += func(mask ^ (1 << bit));
			ret %= MOD;
		}
	}
	return ret;
}

void solve()
{
	int n; cin >> n;
	for (int i = 0; i < n; ++i)
	{
		for (int j = 0; j < n; ++j)
		{
			cin >> a[i][j];
		}
	}
	memset(dp, -1, sizeof dp);
	cout << func((1 << n) - 1);
}

//  ---------------------Template---------------------------
void InputSetup()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	#ifdef LOCAL
	freopen("in", "r", stdin);
	freopen("out", "w", stdout);
	#endif
}

int main(void)
{
	auto start = chrono::high_resolution_clock::now();

	InputSetup();
	solve();

	auto finish = chrono::high_resolution_clock::now();
	cerr << "Time elapsed: " << (chrono::duration<long double>(finish-start)).count() << "s\n";
}
//  ---------------------Template---------------------------

Measured memory_bytes: 33024
struct P{
	float t;
	int z;
}n[24],m[18];
M(float*a,float*b){
	return*a>*b?1:-1;
}
D(struct P*p){
	printf("%d %.2f\n",p->z,p->t);
}
main(i){
	for(i=0;i<24;i++)
		scanf("%d%f",&n[i].z,&n[i].t);
	for(i=0;i<3;i++){
		qsort(n+i*8,8,sizeof(*n),M);
		D(n+i*8);
		D(n+i*8+1);
		memcpy(m+i*6,n+i*8+2,sizeof(*n)*6);
	}
	qsort(m,18,sizeof(*n),M);
	D(m);
	D(m+1);
	exit(0);
}

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

int main() {
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if (a==0) {cout<<"1"<<endl;}
else if (b==0) {cout<<"2"<<endl;}
else if (c==0) {cout<<"3"<<endl;}
else if (d==0) {cout<<"4"<<endl;}
else {cout<<"5"<<endl;}
}


Measured memory_bytes: 3620
s = input()

so=""
se=""
for i in range(1, len(s), 2):
  so += s[i]
for i in range(0, len(s), 2):
  se += s[i]

print(len(s) - max(so.count("1") + se.count("0"), so.count("0") + se.count("1")))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1e5+5;

ll n,k,arr[N];

ll dp[N][2];

bool solve(ll kk, bool first){
    if(kk < arr[0] )    
        return !first;
        
    if(dp[kk][first] != -1) return dp[kk][first];
    
    bool ans = false;
    
    for(ll i=0;i<n;i++){
        if(arr[i] > kk) break;
        bool x = solve(kk-arr[i], !first);
        if(!first && !x){
            ans = false;
            break;
        }
        ans = ans || x;
    }
    
    return dp[kk][first] = ans;
}

int main() {
    scanf("%lld%lld",&n,&k);
    
    for(ll i=0;i<n;i++){
        scanf("%lld",arr+i);
    }
    
    memset(dp, -1, sizeof(dp));
    
    if(solve(k, 1)) printf("First");
    else printf("Second");
    
    return 0;
}

Measured memory_bytes: 13052
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    string s;
    cin >> s;
    int len = s.size();
    ll ans = 0;
    for (int i = 0; i < (1 << (len - 1)); i++) {
        ll x = s[0] - '0';
        for (int j = 0; j < len - 1; j++) {
            if (i & (1 << j)) {
                ans += x;
                x = s[j + 1] - '0';
            } else {
                x = x * 10 + (s[j + 1] - '0');
            }
        }
        ans += x;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <sstream>
#include <cstdio>
#include <utility>
//#include <bits/stdc++.h>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    if((int)s.size() < 4){
        puts("No");
    }
    else {
        string s1 = s.substr(0, 4);
        if(s1 == "YAKI")puts("Yes");
        else puts("No");
    }
    return 0;
}
//


Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {
  val n  = StdIn.readLine().toInt

  def solve(n: Int): Int = {
    var ans = 0
    (1 to n).foreach{ i =>
      if (i.toString().length % 2 != 0) ans = ans + 1
    }
    ans
  }

  println(solve(n))
}
  



Measured memory_bytes: 36468
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <math.h>
 
#define REP(i,n)for (int i=0;i<(n);i++)
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define ll long long
using namespace std;
typedef pair<int,int> P;

const int INF=1<<29;
int w,h;
int fld[20][20];
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int dfs(int x,int y,int times){
	if(times>10)return INF;
	int res=INF;
	REP(i,4){
		int xx,yy,t;
		for(t=1;;t++){
			xx=x+t*dx[i];
			yy=y+t*dy[i];
			if(xx<0||yy<0||xx>=w||yy>=h||fld[yy][xx]==1)break;
			if(fld[yy][xx]==3)return 1;
		}
		if(0<=xx && xx<w && 0<=yy && yy<h && fld[yy][xx]==1 && t>=2){
			fld[yy][xx]=0;
			res=min(res,1+dfs(xx-dx[i],yy-dy[i],times+1));
			fld[yy][xx]=1;
		}
	}
	return res;
}


int main(){
	while(1){
		cin>>w>>h;
		if(w==0&&h==0)break;
		int sx,sy;
		REP(i,h)REP(j,w){
			cin>>fld[i][j];
			if(fld[i][j]==2)sx=j,sy=i;
		}
		int ans=dfs(sx,sy,1);
		if(ans<INF)cout<<ans<<endl;
		else cout<<-1<<endl;
	}
}


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

namespace Math_Functions
{
    class Distance_II
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var x = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var y = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var abs = new double[n];
            for (int i = 0; i < n; i++)
                abs[i] = Math.Abs(x[i] - y[i]);

            Console.WriteLine(abs.Sum());
            Console.WriteLine(Math.Pow(abs.Select(s => s * s).Sum(), (double)1 / 2));
            Console.WriteLine(Math.Pow(abs.Select(s => s * s * s).Sum(), (double)1 / 3));
            Console.WriteLine(abs.Max());
        }
    }
}

Measured memory_bytes: 9932
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
    int n,m;
    cin>>n>>m;
    if(abs(n-m)>1){
        cout<<0<<endl;return 0;
    }
    int N=max(n,m);
    /*
    if(n==m)    n!*m!*2
    else        n!*m!
     */
    ll ans,kai=1,kai2=1;
    int c=N;
    while(c>0){
        kai=(kai*c)%mod;
        if(c!=N){
            kai2=(kai2*c)%mod;
        }
        c--;
    }
    if(n==m){
        ans=(kai*kai*2)%mod;
    }
    else{
        ans=(kai*kai2)%mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var NAB = IO_ShortCut.ReadSplitLong;
            var N = NAB[0];
            var A = NAB[1];
            var B = NAB[2];

            var a = N / (A + B);
            var b = N % (A + B);

            var ans = a * A;
            ans += A > b ? b : A;
            WriteLine(ans);
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

        #endregion
    }

    /// <summary>
    /// 正の数の四則演算のみ対応
    /// </summary>
    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算
        public static long Add(long a, long b) => (a * b) % M;
        // 引き算
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        public static long Multi(long a, long b) => (a * b) % M;
    }

    public class MathLib
    {
    }
}

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

using namespace std;

#define ll long long
#define mk make_pair

void PLAY()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    cout << fixed << setprecision(10);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

/*ll v[1000000];
ll len[1000000];
ll cnt = 0;
vector<vector<ll>> x;
ll dfs(ll n)
{
    //cout<<n<<" a"<<endl;
    vis[n] = 1;
    for (int i = 0; i < x[n].size(); i++)
    {
        ll lol = x[n][i];
        if (!vis[lol])
        {
            dfs(lol);
            cnt++;
        }
    }
    return cnt;
}
void seth(ll a, ll b)
{
    if (vis[a] == 2)
        return;
    vis[a] = 2;
    len[a] = b;
    for (int i = 0; i < x[a].size(); i++)
    {
        ll lol = x[a][i];
        if (vis[lol] != 2)
        {
            seth(lol, b);
        }
    }
    }*/

bool cmp(pair<ll, ll> &a, pair<ll, ll> &b)
{
    if (a.second != b.second)
    {
        return a.second < b.second;
    }
    return a.first < b.first;
}

const ll N = 1e5;
const ll mod = 1e18 + 9;

ll poww(ll b, ll p)
{
    if (p == 0)
        return 1;
    if (p % 2)
        return (poww(b, p - 1) * b) % mod;
    return (poww((b * b) % mod, p / 2)) % mod;
}

ll fact[N], infact[N];
ll ncr(ll n, ll r)
{
    return (((fact[n] * infact[r]) % mod) * infact[n - r]) % mod;
}

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

    ll n,m;
    cin>>n>>m;
    ll ans=0;
    if(m>=n)
    {
        cout<<"1"<<endl;
    }
    else
    {
        while(n>0)
        {
            n-=m;
            ans++;
        }
        cout<<ans<<endl;
    }
    

    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <stack>
#include <cstdlib>
#include <iostream>
using namespace std;
int main () {
  string word;
  stack<int> S;
  int m,n;
  while (cin >> word) { //??\??????????????????????????????
    if (word == "+") {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      S.push(m+n);
    }
    else if (word == "-") {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      S.push(n-m);
    }
    else if (word == "*") {
      m = S.top();
      S.pop();
      n = S.top();
      S.pop();
      S.push(m*n);
    }
    else {
      S.push(atoi(word.c_str()));
    }
  }
  cout << S.top() << endl;
}

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

using namespace std;

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))

typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;

#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))

int F()
{
	char ch;
	int x, a;
	while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
	if (ch == '-') ch = getchar(), a = -1;
	else a = 1;
	x = ch - '0';
	while (ch = getchar(), ch >= '0' && ch <= '9')
		x = (x << 1) + (x << 3) + ch - '0';
	return a * x;
}

int n, a[100010];

VI edge[100010];

int rd[100010];

void dfs(int u)
{
	VI p;
	for (auto v : edge[u])
	{
		dfs(v);
		p.pb(rd[v]);
	}
	sort(ALL(p));
	for (auto x : p)
		rd[u] = max(rd[u], x), ++rd[u];
}

int main()
{
	gi(n);
	for (int i = 2; i <= n; ++i) gi(a[i]), edge[a[i]].pb(i);
	dfs(1);
	printf("%d\n", rd[1]);
	return 0;
}

Measured memory_bytes: 14336
program prob2
    implicit none
    integer :: a,b,m,ans,i
    integer, allocatable :: va(:), vb(:), x(:), y(:), vc(:)

    read(*,*) a,b,m
    allocate(va(a))
    allocate(vb(b))
    allocate(x(m))
    allocate(y(m))
    allocate(vc(m))
    
    read(*,*) va
    read(*,*) vb
    do i = 1, m
        read(*,*) x(i), y(i), vc(i)
    end do
    ans = minval(va) + minval(vb)

    do i = 1, m
        if(va(x(i)) + vb(y(i)) - vc(i) < ans) then
            ans = va(x(i)) + vb(y(i)) - vc(i)
        end if
    end do

    write(*,'(i6)') ans



    stop
contains
end program prob2

Measured memory_bytes: 2816
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int a[6][6];
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int N;
    cin>>N;
    vector<int> k(N);
    for(int &i:k)cin>>i;
    sort(k.begin(),k.end());
    reverse(k.begin(),k.end());
    int tot=0;
    tot+=k[0];
    bool p=0;
    int pos=0;
    for(int i=0;i<N-2;i++){
      if(!p)pos++;
      p=!p;
      tot+=k[pos];
    }
    cout<<tot;
}

Measured memory_bytes: 4796
// AtCoder Grand Contest 007
// A - Shik and Stone

#include <cstdio>
#include <cstring>
#define MAX_H 8
#define MAX_W 8
using namespace std;


int H, W;
bool visited[MAX_H + 1][MAX_W + 1];
int dx[2] = { 0, 1 };
int dy[2] = { 1, 0 };

int main() {

  char c;
  int x, y;
  int remain;

  scanf("%d%d", &H, &W);
  memset(visited, false, sizeof(visited));
  remain = 0;
  for (int j = 0; j < H; j++) {
    scanf("%*c");
    for (int i = 0; i < W; i++) {
      scanf("%c", &c);
      visited[j][i] = (c == '#');
      remain += (c == '#') ? 1 : 0;
    }
  }

  x = 0;
  y = 0;
  remain--;
  while (visited[y + dy[0]][x + dx[0]] != visited[y + dy[1]][x + dx[1]]) {
    if (visited[y + dy[0]][x + dx[0]]) {
      x += dx[0];
      y += dy[0];
    } else {
      x += dx[1];
      y += dy[1];
    }
    remain--;
  }

  if (x == W - 1 && y == H - 1 && remain == 0) {
    printf("Possible\n");
  } else {
    printf("Impossible\n");
  }

  return 0;

}




Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define LL long long
#define PI 3.14159265359
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

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

	if (A+B > C+D) {
		cout << "Left" << endl;
	}
	else if (A+B < C+D) {
		cout << "Right" << endl;
	}
	else {
		cout << "Balanced" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// Problem : A - Beginner
// Contest : AtCoder Beginner Contest 156
// URL : https://atcoder.jp/contests/abc156/tasks/abc156_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define mp(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
#define inf LLONG_MAX
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,r;cin>>n>>r;
if(n>=10)
{
	cout<<r;
}
else
cout<<r+100*(10-n);
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int a,b;
    char op;
    while(true){
        scanf("%d %c %d",&a,&op,&b);
        if(op == '?') break;
        switch(op){
        case '+':
            printf("%d\n",a+b);
            break;
        case '-':
            printf("%d\n",a-b);
            break;
        case '/':
            printf("%d\n",a/b);
            break;
        case '*':
            printf("%d\n",a*b);
            break;
        }
    }
}


Measured memory_bytes: 2732
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		if(n==1)
			System.out.println("Hello World");
		else{
			int a = sc.nextInt();
			int b = sc.nextInt();
			
			System.out.println(a+b);
		}
		
	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <boost/math/constants/constants.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0;i < n;i++)
#define FOR(i, n, m) for(int i=n; i<m; ++i)

int main(){
  ll N;
  cin >> N;
  ll L[1000];
  rep(i,N) cin >> L[i];
  
  ll sum=0;
  sort(L, L+N);
  rep(i,N-1) sum+=L[i];
  
  if(sum>L[N-1]) cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

int main () {
    string s; cin >> s;
    if(s[0] == s[1]|| s[1] == s[2]|| s[2] == s[3]){
        cout << "Bad" << endl;
    }else{
        cout << " Good" << endl; 
    }
    
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<pair<pair<string, int>, int>> p(N);
    for (int i = 0; i < N; ++i) {
        string a;
        int b;
        cin >> a >> b;
        p.at(i) = make_pair(make_pair(a, -b), i+1);
    }
    sort(p.begin(), p.end());

    for (int i = 0; i < N; ++i) {
        cout << p.at(i).second << endl;
    }
}

Measured memory_bytes: 256
n=int(input())
s=list(map(int,input().split()))
x={}
for i in range(n):
    if s[i] in x:
        x[s[i]]+=1
    else:
        x[s[i]]=1
ans=0
for i in x:
    a=x[i]
    if a<i:
        ans+=a
    elif a>i:
        ans+=(a-i)
print(ans)


Measured memory_bytes: 18160
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
// IN THE NAME OF GOD
#include <bits/stdc++.h>

#define ff first
#define endl '\n'
#define ss second
#define ll long long
#define pb push_back
#define ld long double
#define pii pair <int, int>
#define pll pair <long long, long long>

using namespace std;
string s;
int main(){
  //ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(s[i] == '9') s[i] = '1';
    else if(s[i] == '1') s[i] = '9';
  }
  cout << s;
}
//programmer: a_h_k_81
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //


Measured memory_bytes: 256
"use strict"
const create = () => {
    const input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
    const res = {
        "list": input, "index": 0, "max": input.length,
        "hasNext": function() {return this.index < this.max},
        "next": function() { if (!this.hasNext()) {throw "ArrayIndexOutOfBoundsException";}else{return this.list[this.index++];}}
    };
    return res;
}
const o = create();
const next = () => o.next()
const nextInt = () => parseInt(o.next())
const nextStrArray = () => o.next().split(" ")
const nextIntArray = () => o.next().split(" ").map(el => parseInt(el))
const nextCharArray = () => o.next().split("")
const hasNext = () => o.hasNext()
const myout = (...x) => console.log(...x)

const maxTime = (x) => Math.ceil(x/10)*10
const remainTime = (x) => maxTime(x) - x

const Main = () => {
    let total = 0
    let a = nextInt()
    let b = nextInt()
    let c = nextInt()
    let d = nextInt()
    let e = nextInt()
    total = maxTime(a) + maxTime(b) + maxTime(c) + maxTime(d) + maxTime(e) 
    total -= Math.max(remainTime(a), remainTime(b), remainTime(c), remainTime(d), remainTime(e))
    console.log(total)
}
Main()




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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

int main()
{
    while ( true ) {
        int n;
        scanf("%d", &n );

        if ( n == 0 ) break;

        int h[ n + 1 ];
        int kh [ n + 1 ];
        int temp;

        for ( int i = 0; i <= n; ++i ) {
            scanf("%d", &h[i] );
            if ( i != 0 ) kh[i] = h[i] - h[ i - 1 ];
        }

        if ( kh[1] != kh[2] && kh[2] == kh[n] ) {
            printf("%d\n", h[0] );
        } else if ( kh[n] != kh[ n - 1 ] && kh[1] == kh[ n - 1 ] ) {
            printf("%d\n", h[n] );
        } else {
            for ( int i = 0; i < n; ++i ) {
                temp = ( h[n] - h[0] ) / ( n - 1 );
                if ( h[i] + temp != h[ i + 1 ] ) {
                    printf("%d\n", h[ i + 1 ] );
                    break;
                }
            }
        }
    }
    return 0;
}

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

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




Measured memory_bytes: 3220
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashSet;

fn divisors(N: i64) -> HashSet<i64> {
    let mut ds = vec![];
    let mut d = 1;
    while d * d <= N {
        if N % d == 0 {
            ds.push(d);
            ds.push(N / d);
        }
        d += 1;
    }
    let uniq: HashSet<i64> = ds.into_iter().collect();
    uniq
}

fn main() {
    let q: usize = read();
    let mut a: Vec<(usize, usize)> = vec![];
    for _ in 0..q {
        let l: usize = read();
        let r: usize = read();
        a.push((l, r));
    }

    let mut current = 0;
    let maxnum = 100_005;
    let mut memo = vec![0; maxnum];
    for i in 0..maxnum - 1 {
        let a = divisors(i as i64);
        let b = divisors(((i + 1) / 2) as i64);

        if a.len() == 2 && b.len() == 2 {
            current += 1;
        }

        memo[i] = current;
    }

    for i in 0..q {
        let ai = a[i];
        println!("{}", memo[ai.1] - memo[ai.0 - 1])
    }
}


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

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

    vector<ll> A(N);
    ll ans = 0;
    ll sum = 0;
    ll seki = 0;
    ll mod = 1000000007;

    for (ll i=0; i<N; i++){
        cin >>A.at(i);
    }

    for (ll i=0; i<N; i++){
        sum += A.at(i);
    }

    for (ll i=0; i<N-1; i++){
        sum -= A.at(i); 
        seki = A.at(i) * (sum % mod) % mod;
        ans = (ans + seki) % mod;

    }
    cout << ans << endl;
}

Measured memory_bytes: 4824
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {
	vi arr(2);
	for(int &i:arr){cin>>i;if(i<0||i>9){cout<<-1;return;}}
	cout<<arr[0]*arr[1];
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define endl '\n'
#define ff first
#define ss second
#define rev(a) a.rbegin(),a.rend()
#define all(a) a.begin(),a.end()
#define pi pair<int,int>
#define vii vector<pi>
#define size(a)  (int)(a.size())
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define debug(...) cerr<<" ["<<#__VA_ARGS__<<": "<<(__VA_ARGS__)<<"] ";
#define debugv(...) for(int i=0; i<size(__VA_ARGS__); i++) cerr<<" ["<<#__VA_ARGS__<<i<<": "<<(__VA_ARGS__)[i]<<"] ";
const int mod = 1e8;
const int inf = 1e9+5;
const int inf64 = 1e18+5;
//           -------"Where is your Pen and Paper?"-------
void solve(){
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);  
    #endif
    */
    int test;
    //cin>>test;
    test=1;
    //int cse=1;
    while(test--){
         //cout<<"Case #"<<cse<<": ";
         solve();
         cout<<endl;
         //cse++;
    }
    return 0;
}

Measured memory_bytes: 3652