akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

typedef vector <vector<int>> Graph;

// 強連結成分分解ライブラリ
class StronglyConnectedComponent {
public:
  Graph G;
  Graph rG;
  Graph cG;
  vector<int> vs;
  vector<bool> used;
  vector<int> componentId;
  int componentCount;
  int V;

  StronglyConnectedComponent(int V) {
    this->V = V;
    used = vector<bool>(V);
    componentId = vector<int>(V);
    G = Graph(V);
    rG = Graph(V);
  }

  void add_edge(int from, int to) {
    assert(0 <= from && from < V);
    assert(0 <= to && to < V);

    G[from].push_back(to);
    rG[to].push_back(from);
  }

  void run() {
    fill(used.begin(), used.end(), false);
    componentCount = 0;
    vs.clear();

    for (int v = 0; v < V; ++v) {
      if (used[v]) continue;

      dfs(v);
    }

    fill(used.begin(), used.end(), false);

    for (int i = vs.size() - 1; i >= 0; --i) {
      int v = vs[i];
      if (used[v]) continue;

      cG.push_back(vector<int>());
      rdfs(v, componentCount++);
    }
  }

private:
  void dfs(int v) {
    used[v] = true;

    for (int i = 0; i < (int) G[v].size(); ++i) {
      int u = G[v][i];

      if (used[u]) continue;

      dfs(u);
    }

    vs.push_back(v);
  }

  void rdfs(int v, int k) {
    used[v] = true;
    componentId[v] = k;
    cG[k].push_back(v);

    for (int i = 0; i < (int) rG[v].size(); ++i) {
      int u = rG[v][i];

      if (used[u]) continue;

      rdfs(u, k);
    }
  }
};

const int MAX_V = 2010;
int N, D;
bool answer[MAX_V];
StronglyConnectedComponent scc(MAX_V);

void add_clause(int i, bool f, int j, bool g) {
  assert(0 <= i && i < N);
  assert(0 <= j && j < N);
  scc.add_edge(2 * i + (f ? 0 : 1), 2 * j + (g ? 1 : 0));
  scc.add_edge(2 * j + (g ? 0 : 1), 2 * i + (f ? 1 : 0));
}

bool satisfiable() {
  scc.run();
  memset(answer, false, sizeof(answer));

  for (int i = 0; i < N; ++i) {
    if (scc.componentId[2 * i] == scc.componentId[2 * i + 1]) return false;
    answer[i] = scc.componentId[2 * i] < scc.componentId[2 * i + 1];
  }

  return true;
}

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

  int X[N];
  int Y[N];

  int x, y;
  for (int i = 0; i < N; ++i) {
    cin >> x >> y;
    X[i] = x;
    Y[i] = y;
  }

  for (int i = 0; i < N; ++i) {
    int x1 = X[i];
    int y1 = Y[i];

    for (int j = i + 1; j < N; ++j) {
      if (i == j) continue;

      int x2 = X[j];
      int y2 = Y[j];

      if (abs(x1 - x2) < D) {
        add_clause(i, false, j, false);
      }

      if (abs(x1 - y2) < D) {
        add_clause(i, false, j, true);
      }

      if (abs(y1 - x2) < D) {
        add_clause(i, true, j, false);
      }

      if (abs(y1 - y2) < D) {
        add_clause(i, true, j, true);
      }
    }
  }

  if (satisfiable()) {
    cout << "Yes" << endl;

    for (int i = 0; i < N; ++i) {
      if (answer[i]) {
        cout << X[i] << endl;
      } else {
        cout << Y[i] << endl;
      }
    }
  } else {
    cout << "No" << endl;
    return 0;
  }

  return 0;
}


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

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k; vector <int> a(n);
	for(int &x: a) {
		cin >> x;
	}
	sort(a.begin(), a.end()); 
	a.resize(k);
	int ans = 0;
	for(int x: a) {
		ans += x;
	}

	cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using namespace std;
int main(void){
    int a,b,i=0,sw=0;
    cin >> a >> b;
    string s;
    cin >> s;
    for(i=0;i<a;i++){
      if(s[i] == '-')
        sw=1;
    }
    if(s[a] != '-')
      sw=1;
    for(i=a+1;i<a+b+1;i++){
      if(s[i] == '-')
        sw=1;
    }
    if(sw==0)
      cout << "Yes\n";
    else
      cout << "No\n";
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

struct DATA{
  int x;
  int isFound;
};

vector<int> Operation(vector<int>);

int main(){
  int i, n, a, count;
  vector<int> before, after;

  while(1){
    cin >> n;
    if(n == 0) break;

    for(i=0; i<n; ++i){
      cin >> a;
      before.push_back(a);
    }

    count = 0;
    while(1){
      after = Operation(before);
      if(after == before) break;
      before = after;
      ++count;
    }

    cout << count << endl;
    for(i=0; i<after.size()-1; ++i)
      cout << after[i] << " ";
    cout << after[after.size()-1] << endl;

    before.clear();
    after.clear();
  }
  return 0;
}

vector<int> Operation(vector<int> before){
  int i, j, count;
  vector<int> list, after;
  DATA onedata;
  vector<DATA> data;

  for(i=0; i<before.size(); ++i){
    onedata.x = before[i];
    onedata.isFound = 0;
    data.push_back(onedata);
  }

  i = 0;
  while(1){
    count = 0;
    list.clear();
    for(j=i; j<data.size(); ++j){
      if(data[j].isFound == 0 && data[i].x == data[j].x){
        data[j].isFound = 1;
        list.push_back(j);
        ++count;
      }
    }

    for(j=0; j<list.size(); ++j)
      data[list[j]].x = count;

    j = 1;
    while(1){
      if(i+j == data.size() || data[i+j].isFound == 0){
        i += j;
        break;
      }      
      ++j;
    }
    if(i == data.size()) break;
  }

  for(i=0; i<data.size(); ++i)
    after.push_back(data[i].x); 

  return after;

}

Measured memory_bytes: 0
#include<stdio.h>

	int main(){
		
		int i,n,x[10],v,w,a,b,c;
		a=0;
		b=0;
		c=0;
		
		for(i=0;i<10;i++){
			x[i]=0;
		}
		
		
		for(i=0;i<10;i++){
			scanf("%d",&n);
			x[i]=n;
		}
		
		for(i=0;i<10;i++){
			if(a<x[i]){
				a=x[i];
				v=i;
			}
		}
		
		for(i=0;i<10;i++){
			if(i!=v){
				if(b<x[i]){
					b=x[i];
					w=i;
				}
			}
		}
		
		for(i=0;i<10;i++){
			if(i!=v){
				if(i!=w){
					if(c<x[i]){
						c=x[i];
					}
				}
			}
		}
		
		printf("%d\n%d\n%d\n",a,b,c);
		
	return 0;
}

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

// int rec(vector<vector<int>> happ , int i, int j){
//     if(j == 3 && i == happ.size()) return 0;

//     if(j > 3 && i > happ.size()) return INT_MIN;

//     int a = happ[i][j] + rec(happ ,i+1)
// }

int main()
{
    int n;
    cin >> n;
    vector<vector<int>> happ(n + 1, vector<int>(3, 0));

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            cin >> happ[i][j];
        }
    }
    vector<vector<int>> dp(n + 1, vector<int>(3, 0));

    for (int i = 0; i < 3; i++)
    {
        dp[0][i] = max(happ[0][0], max(happ[0][1], happ[0][2]));
    }

    for (int i = 1; i < n; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            if (j == 0)
                dp[i][j] = happ[i][j] + max(dp[i - 1][j + 1], dp[i - 1][j + 2]);
            if (j == 1)
                dp[i][j] = happ[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j + 1]);
            if (j == 2)
                dp[i][j] = happ[i][j] + max(dp[i - 1][j - 1], dp[i - 1][j - 2]);
        }
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
    return 0;
}

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

int main() {
	int n,found;
	cin >> n;
	string s;
	cin >> s;
	
	if(s.size() > n) {
		s = s.substr(0, n) + "...";
		cout << s << endl;
	} else {
		cout << s << endl;
	}

	
	return 0;
}

Measured memory_bytes: 3512
#include <bits/stdc++.h>
#define N 50001
using namespace std;
typedef long long ll;

int main(){
  while(1){
    ll r,c,q;
    cin>>r>>c>>q;
    if(!r&&!c&&!q)return 0;

    ll A[N],B[N],O[N];
    for(int i=0;i<q;i++)cin>>A[i]>>B[i]>>O[i];
    
    ll ans=0,cnt[2]={},rc[]={r,c},used[2][N]={};
    for(int i=q-1;i>=0;i--){
      bool f=A[i];
      if(used[f][B[i]]++)continue;
      cnt[f]++;
      ans+=(rc[!f]-cnt[!f])*O[i];
    }
    cout <<ans<<endl;
  }
  
  return 0;
}

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

int main() {
	int a, b; cin >> a >> b;
	for (int c = 0; c < a; c++) {
		string d; cin >> d;
		cout << d << endl << d << endl;
	}
}

Measured memory_bytes: 256
n,m = map(int,input().split())
ls = []
for _ in range(m):
  tmp = list(map(int,input().split()))[1:]
  lls = []
  for i in range(1,n+1):
    lls += [int(i in tmp)]
  ls += [lls]
p = list(map(int,input().split()))
count = 0
yyy = [0]*n
while True:
  if yyy[-1] == 2:
    break
  dd = 0
  for mi in range(m):
    c = 0
    for ni in range(n):
      c += ls[mi][ni] * yyy[ni]
    d = c%2
    dd += 1-int(d==p[mi])
  if dd == 0:
    count += 1
  yyy[0] += 1
  for j in range(0,n-1):
    if yyy[j] == 2:
      yyy[j] = 0
      yyy[j+1] += 1
print(count)

Measured memory_bytes: 3064
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a=in.nextInt();
		int b=in.nextInt();
		int c=in.nextInt();
		if(a+b+c>=22)
		{
			System.out.println("bust");
		}
		else
		{
			System.out.println("win");
		}
	}
}


Measured memory_bytes: 35604
#include<stdio.h>

int main(){
  int p,q,r;
  scanf("%d %d %d",&p,&q,&r);
  int a;/*aとbは三つの数字の小さい二つ*/
if(p>=q&&p>=r){
  a =q+r;
}
  if(q>=p&&q>=r){
    a = p+r;
  }
  if(r>=p&&r>=q){
    a = p+q;
  }
  printf("%d",a);
}

Measured memory_bytes: 128
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  [n, m] <- getIntList

  d <- VM.new n
  VM.set d (0::Int)

  replicateM_ m $ do
    [a, b] <- getIntList
    x <- VM.read d (a-1)
    VM.write d (a-1) (x+1)
    y <- VM.read d (b-1)
    VM.write d (b-1) (y+1)

  d' <- V.freeze d

  putStrLn $ if V.and $ V.map (\x -> x `mod` 2 == 0) d'
             then "YES"
             else "NO"

Measured memory_bytes: 2556
N=int(input())
for i in range(1):
  if N%10==3:
    print("bon")
    break
  if N%10==0:
    print("pon")
    break
  if N%10==1:
    print("pon")
    break
  if N%10==6:
    print("pon")
    break
  if N%10==8:
    print("pon")
    break
  print("hon")

Measured memory_bytes: 9204
n=int(input())
r={}


for i in range(n):
  a,b=map(str,input().split())
  r[a.ljust(10,"*")+str((100-int(b))).zfill(3)]=i
  
c=list(r.keys())
c.sort()
#print(r)
for i in c:
  print(r[i]+1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
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; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define FOR(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstr vector<string>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
const long long dx[4]={1,0,-1,0};
const long long dy[4]={0,1,0,-1};
const long long INF = 1e12;
const long long MOD = 1e9+7;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    map<int,int> map;
    rep(i,n){
        int a; cin >> a;
        map[a]++;
    }
    int res=0;
    for(auto m:map){
        if(m.F>m.S){
            res+=m.S;
        }else if(m.F<m.S){
            res+=m.S-m.F;
        }
    }
    cout<<res<<endl;
}

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

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	for(int i = 1;i <= b;i++){
		if(a * i % b == c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
using namespace std;
int n;
string s;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	cin>>n>>s;
	int left=0;
	int right=0;
	int cntl=0;
	int cntr=0;
	for(int i=s.size()-1;i>=0;i--){
		if(s[i]=='('){
			if(right==0){
				cntr++;
			}
			else if(right>0){
				right--;
			}
		}
		if(s[i]==')')right++;
	}
	for(int i=0;i<s.size();i++){
		if(s[i]==')'){
			if(left==0){
				cntl++;
			}
			else if(left>0){
				left--;
			}
		}
		if(s[i]=='(')left++;
	}
	for(int i=0;i<cntl;i++)s='('+s;
	for(int j=0;j<cntr;j++)s=s+')';
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def solve(sc: => Scanner): Unit = {
    val M = sc.nextInt
    if (M != 0) {
      val X = Array.fill[Int](10000)(0)
      X(0) = 1
      for (_ <- 0 until M) {
        val A, B = sc.nextInt
        for (j <- 0 to 10000 - A - 1) (for (i <- 1 to B) (if (10000 - A * i - 1 - j >= 0) (X(10000 - 1 - j) += X(10000 - A * i - 1 - j))))
      }
      val N = sc.nextInt
      for (_ <- 0 until N) {
        println(X(sc.nextInt))
      }
      solve(sc)
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 51232
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    ll k = min(x, y);
    ll ans = 0;
    if(a+b < 2*c){
        ans += (a+b)*k;
    }else{
        ans += 2*c*k;
    }
    x -= k; y -= k;
    if(x>0){
        if(a < 2*c) ans += a*x;
        else ans += 2*c*x;
    }else if(y>0){
        if(b < 2*c) ans += b*y;
        else ans += 2*c*y;
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3420
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef int ftype;
 
#define pb push_back 
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define fori(i, n) for (int i = 0; i < (int)(n); ++i)
#define forn(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n); i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define RETURN(x) do{cout << x << '\n'; return 0;}while(0)
#define FIRSTWIN do{cout << "Monocarp\n"; return 0;}while(0)
#define SECONDWIN do{cout << "Bicarp\n"; return 0;}while(0)

const int MAXN = 2e5+4;
const int MOD = 1e9+7;
const int INF = 1e9+1;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a,b;
    cin >> a >> b;
    if(a < 1 || a > 9) RETURN(-1);
    if(b < 1 || b > 9) RETURN(-1);
    cout << a*b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

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

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	ll N;
	cin >> N;
	vector<ll> ym(N+1, 1);
	ym.at(0) = 0;

	ll ans = 1;
	for (ll i = 2; i <= N; ++i)
	{
		for (ll j = i; j <= N; j += i)
		{
			ym.at(j)++; 
		}
		ans += i * ym.at(i);
	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 81412
#include <iostream>
#include <vector>

using namespace std;

int calc(vector<int> n, const vector<int> &P, const vector<int> &C, const int G, const int h=0) {
	if(h >= G) {
		int out = 0;
		for(auto x: n) out += x;
		return out;
	}
	int D = n.size();
	int res = INT_MAX;
	for(int i = 0; i < D; i++) {
		if(n[i] == P[i]) continue;
		if(P[i] * 100 * (i + 1) + C[i] + h > G) {
			int j = 0;
			for(; j < P[i]; j++) {
				if(j * 100 * (i + 1) + h >= G) break;
			}
			n[i] = j;
		} else {
			n[i] = P[i];
		}
		int hh = n[i] * 100 * (i + 1);
		if(n[i] == P[i]) hh += C[i];
		res = min(res, calc(n, P, C, G, h + hh));
		n[i] = 0;
	}
	return res;
}
int main() {
	int D, G;
	cin >> D >> G;

	vector<int> C(D);
	vector<int> P(D);

	for(int i = 0; i < D; i++) {
		cin >> P[i] >> C[i];
	}
	auto n = vector<int>(D, 0);
	cout << calc(n, P, C, G) << endl;
}


Measured memory_bytes: 256
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll n,m,k,ans = 0;
    sfffl(n,m,k);
    vll a(n+1),b(m+1),sumofa(n+5,0),sumofb(n+5,0);
    for(ll i=1;i<=n;i++)
    {
        sfl(a[i]);
        a[i]+=a[i-1];
    }
    for(ll i=1;i<=m;i++)
    {
        sfl(b[i]);
        b[i]+=b[i-1];
    }
    debug(a,b);
    for(ll i=0;i<=n;i++)
    {
        if(k-a[i]<0) continue;
        if(k-a[i]==0)
        {
            ans = max(ans,i);
            continue;
        }
        ll temp = upper_bound(all(b),k-a[i])-b.begin();
        temp--;
        ans = max(ans,i+temp);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 9500
# Solved by QBnewb
# Discretization
# off-line

q = int(input())
s = []
rs = [] # for discretization

# download the input
for i in range(q):
    s.append(list(map(int, input().split())))
    if s[i][0] == 3:
        rs.append(s[i][1])
        rs.append(s[i][2])
    else:
        rs.append(s[i][1])

rs.append(10**9 + 1)
rs = sorted(list(set(rs)))
index = {rs[i]:i for i in range(len(rs))} # discretization
used = [False for i in range(len(rs) + 1)] # tag the elements in set
cnt = 0
for i in range(q):
    op, x = s[i][0], s[i][1]
    idx = index[x]
    if op == 0:
        if not used[idx]:
            cnt += 1
        used[idx] = True
        print(cnt)
    elif op == 1:
        print(+used[idx])
    elif op == 2:
        if used[idx]:
            cnt -= 1
        used[idx] = False
    else:
        l = idx
        r = index[s[i][2]]
        for j in range(l, r+1):
            if used[j]:
                print(rs[j])


Measured memory_bytes: 62688
/*
          Life before Death
          Strength before Weakness
          Journey before Destination
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    #define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define rep(i,a,n) for(ll i=a;i<n;i++)
    #define per(i,n,a) for (ll i=n;i>a;i--)
    #define te ll t; std::cin >> t; while(t--)
    #define SZ 100011
    //#define M_PI  3.141592653589793238462643383279502884L
    /*------Just DO IT--------------------------------------*/

    ll dp[SZ];

    ll solve(){
      ll n;
      cin>>n;
      ll a[n+1];
      rep(i,1,n+1) cin>>a[i];
      dp[2] = abs(a[2]-a[1]);
      rep(i,3,n+1) {
      dp[i] = min( dp[i-1] + abs(a[i-1] - a[i]), dp[i-2] + abs(a[i-2]-a[i]));
      //cout<<abs(a[i-1] - a[i])<<" "<<abs(a[i-2] - a[i])<<endl;
      }cout<<dp[n]<<endl;
    } 
    
   int main() {
       fastio
       solve();
    }

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<utility>
#include<algorithm>
#include<queue>
#include<cmath>
#include<iomanip>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

ll n, m, x, ans;

void isSkill(vll tmp, vvll a) {//今回の組の計算
    bool flag = true;
    vll now(m+1, 0);
    ll money = 0;
    for(ll num : tmp){//今回の組の理解度を算出
        FOR(i, 1, m){
            now[i] += a[num][i];
        }
        money += a[num][0];
    }
    FOR(i, 1, m){//今回の組がいけているか判断
        if (now[i] < x){
            flag = false;
            break;
        }
    }
    if(flag) ans = min(ans, money);

    while (tmp.back() < n) {
        tmp.back()++;//後ろの値を1大きくした場合
        isSkill(tmp, a);
        tmp.back()--;//後ろに1大きい値を入れた場合
        tmp.push_back(tmp.back()+1);
        isSkill(tmp, a);
    }
    return;
}

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> x;
    ans = inf;
    vvll a(n+1, vll(m+1, 0));
    FOR(i, 1, n){
        REP(j, m+1){
            cin >> a[i][j];
        }
    }
    vll t = {1};
    isSkill(t, a);
    if(ans == inf){
        ans = -1;
    }

    cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include<algorithm>

int main() {
	int a, b, c, d, e, f;
	std::cin >> a >> b >> c >> d >> e >> f;
	int kamoku1 = a + b + c + d - std::min({ a,b,c,d });
	int kamoku2 = e + f - std::min(e, f);
	std::cout << kamoku1 + kamoku2 << std::endl;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int d, g;
    cin >> d >> g;
    vector<int> p(d), c(d);
    for (int i = 0; i < d; i++) {
        cin >> p[i] >> c[i];
    }

    vector<int> dp(1001, 0);
    for (int i = 0; i < d; i++) {
        for (int k = 1000; k > 0; k--) {
            for (int j = 1; j <= p[i]; j++) {
                if (k >= j) dp[k] = max(dp[k], dp[k - j] + 100 * (i + 1) * j + (j == p[i]) * c[i]);
            }
        }
    }

    for (int i = 0; i <= 1000; i++) {
        if (dp[i] >= g) {
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define rep(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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; }

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

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

  puts(regex_match(s, regex("(dream|dreamer|erase|eraser)*")) ? "YES" : "NO");
}

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

int main(){
    string s; cin >> s;
    string a = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'B' && a.size()){
            a.erase(a.begin()+a.size()-1);
            continue;
        }else if(s[i] != 'B') a += s[i];
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
n, h = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
bs = []
maxa = 0
for a, b in ab:
    if a < b:
        bs.append(b)
    maxa = max(a, maxa)
bs = list(reversed(sorted(bs)))
d = 0
for b in bs:
    if h <= d:
        break
    elif maxa < b:
        d += b
        ans += 1
    else:
        break
if d < h:
    ans += (h - d + maxa - 1) // maxa
print(ans)

Measured memory_bytes: 18852
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        char[] c = s.toCharArray();
        char tmp = c[0];
        boolean f = false;
        for(char tc : c){
            if(tc != tmp)f=true;
            tmp = tc;
        }
        if(f){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 21844
import static java.lang.Integer.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
		st = new StringTokenizer(br.readLine());
		int N = parseInt(st.nextToken());
		TreeSet<Integer> ts = new TreeSet<Integer>();


		st = new StringTokenizer(br.readLine());
		for(int i=0;i<N;i++) {
			ts.add(parseInt(st.nextToken()));
		}

		while(true) {
			if(ts.size() == 1) {
				break;
			}
			int newLast = ts.last() % ts.first();
			ts.remove(ts.last());

			if(newLast !=0) {
				ts.add(newLast);
			}


		}

		System.out.println(ts.first());
	}
}


Measured memory_bytes: 43364
#include<iostream>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<stack>
#include<queue>
#include<sstream>
#include<bitset>
#include<cstdio>
using namespace std;
void fast()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
}
bool IsPrime(int num)
{
	if(num==1)
		return false;
	for(int i=2;i*i<=num;i++)
		if(num%i==0)
			return false;
	return true;
}
vector<int>v;
int main()
{
	//in_out_txt();
	fast();
	v.resize(100005);
	int cnt=0;
	for(int i=1;i<=100000;i++)
	{
		if(IsPrime(i) && IsPrime((i+1)/2))
			v[i]=++cnt;
		else
			v[i]=cnt;
	}
	int q;
	cin>>q;
	while(q--)
	{
		int l,r;
		cin>>l>>r;
		cout<<v[r]-v[l-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

bool comp(string a, string b) {
    if (a.size() > b.size()) return 1;
    else if (b.size() > a.size()) return 0;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] > b[i]) return 1;
        else if (b[i] > a[i]) return 0;
    }
    return 1;
}

int main(void){
    int w, h;
    while (cin>>w>>h && w) {
        vector<vector<char> > g(h, vector<char>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                cin >> g[i][j];
            }
        }
        
        vector<vector<string> > dp(h, vector<string>(w));
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (g[i][j] >= '0' && g[i][j] <= '9') dp[i][j] = g[i][j];
            }
        }
        
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (g[i][j] < '0' || g[i][j] > '9') continue;
                string a, b, c;
                a = dp[i][j];
                if (a == "0") continue;
                
                if (j+1 < w && g[i][j+1] >= '0' && g[i][j+1] <= '9') {
                    string b = a + g[i][j+1];
                    if (comp(b,a) && comp(b, dp[i][j+1])) dp[i][j+1] = b;
                }
                
                if (i+1 < h && g[i+1][j] >= '0' && g[i+1][j] <= '9') {
                    string c = a + g[i+1][j];
                    if (comp(c,a) && comp(c, dp[i+1][j])) dp[i+1][j] = c;
                }
            }
        }
        
        string ans;
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (comp(dp[i][j], ans)) {
                    ans = dp[i][j];
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3300
#include <limits.h>
#include <iostream>
#include <vector>

void insertionSort(std::vector<int> &data, int dataLength);

int main(void)
{
    int dataLength = 0;         // データ数
    // データ数を入力
    std::cin >> dataLength;

    std::vector<int> data(dataLength);   // ソートデータ

    for (int i = 0; i < dataLength; i++) {
        std::cin >> data[i];
    }

    std::cout << data[0];
    for (int k = 1; k < dataLength; k++) {
        std::cout << " " << data[k];
    }
    std::cout << "\n";
    insertionSort(data, dataLength);

    return 0;
}

void insertionSort(std::vector<int> &data, int dataLength)
{
    for (int i = 1; i < dataLength; i++) {
        int v = data[i];

        int j = i - 1;
        while (j >= 0 && data[j] > v) {
            data[j + 1] = data[j];
            j--;
        }
        data[j + 1] = v;

        std::cout << data[0];
        for (int k = 1; k < dataLength; k++) {
            std::cout << " " << data[k];
        }
        std::cout << "\n";
    }
    return;
}


Measured memory_bytes: 3088
#include <algorithm>
#include <stdio.h>
#define sqr(x) ((x)*(x))

using namespace std;

int main(void)
{ 
  int n;
  int x[100];
  
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &x[i]);
  
  sort(x, x+n);
  
  int dmin = 1000000;
  
  for (int p = x[0]; p <= x[n-1]; p++) {
    int d = 0;
    for (int j = 0; j < n; j++)
      d += sqr(x[j] - p);
    if (dmin > d)
      dmin = d;
    else
      break;
  }
  
  printf("%d", dmin);
  
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define FOR(i,x,y) for(int i=x;i<y;i++)
using namespace std;

bool BeautifulString(string s,char c){
  int ans = 0;
  FOR(i,0,s.size())if(s[i] == c)ans++;
  return ans%2;
}

int main(){
  string w,alphabet="abcdefghijklmnopqrstuvwxyz";
  cin >> w;
  bool flag = 1;
  FOR(i,0,alphabet.size())if(BeautifulString(w,alphabet[i]))flag = 0;
  flag ? cout << "Yes" << endl : cout << "No" << endl;
}


Measured memory_bytes: 256
n=int(input())
s=input()
ctl=[]
ctr=[]
for i in range(26):
  ctl.append(0)
  ctr.append(0)
for i in range(n):
  ctr[ord(s[i])-ord('a')]+=1
ans=0
for i in range(n-1):
  ctr[ord(s[i])-ord('a')]-=1
  ctl[ord(s[i])-ord('a')]+=1
  ans1=0
  for j in range(26):
    if(ctl[j]>0 and ctr[j]>0):
      ans1+=1
  ans=max([ans, ans1])
print(ans)

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

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

    int cnt = 0;
    for (int i = 0; i <= A; ++i) {
         for (int j = 0; j <= B; ++j) {
             for (int k = 0; k <= C; ++k) {
                 int total = (500*i + 100*j + 50*k);
                 if ( total == X) ++cnt; 
             }
         }
     }
     cout << cnt << endl;

}

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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;
const ll dx[] = {1, -1, 0, 0};
const ll dy[] = {0, 0, 1, -1};

ll N;
VL X, SX;

int main() {
    cin >> N;
    REP(i, N) {
        CINT(x);
        X.emplace_back(x);
        SX.emplace_back(x);
    }
    sort(All(SX));
    ll med1 = SX[N / 2 - 1], med2 = SX[N / 2];
    REP(i, N) {
        if(X[i] >= med2) {
            cout << med1 << "\n";
        } else {
            cout << med2 << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 5860
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int A, B; cin >> A >> B;
	A--; B--;
	cout << (B+A-1)/A << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343


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

    int[] a = new int[5];

    for (int i = 0; i < 5; i++) {
      a[i] = sc.nextInt();
    }
    
    int k = sc.nextInt();
    
    String result = ant(a, k);
      
    // 出力
    System.out.println(result);
  }
  
  private static String ant(int[] a, int k) {
    
    for (int i = 0; i < a.length - 1; i++) {
      for (int j = i + 1; j < a.length; j++) {
        if (a[j] - a[i] > k) {
          return ":(";
        }
      }
    }
    return "Yay!";
  }
}

Measured memory_bytes: 22996
#include<cstdio>
int main(){
  int n,a,b=4280;
  
  scanf("%d",&n);
  
  while(n != -1){
    a = 1150;
    if(n > 30) a += 2650+160*(n-30);
    else if(n > 20) a += 1250+140*(n-20);
    else if(n > 10) a += 125*(n-10);
    printf("%d\n",b-a);
    scanf("%d",&n);
  }
  return (0);
}

Measured memory_bytes: 2552
#include <stdio.h>
 
using namespace std;
 
void outPut(int Array[],char mark){
    for(int i = 1; i <= 13; i++){
        if(Array[i] == 0) printf("%c %d\n",mark,i);
    }
}
 
int main(){
    char mark[2];
    int n,S[14],H[14],C[14],D[14],tmp;
    for(int i = 0; i < 14; i++) S[i] = H[i] = C[i] = D[i] = 0;
    scanf("%d",&n);
 
    for(int i = 0; i < n; i++){
        scanf("%s %d",mark,&tmp);
        switch(mark[0]){
        case 'S':
            S[tmp] = 1;
            break;
        case 'H':
            H[tmp] = 1;
            break;
        case 'C':
            C[tmp] = 1;
            break;
        case 'D':
            D[tmp] = 1;
            break;
        }
    }
    outPut(S,'S');
    outPut(H,'H');
    outPut(C,'C');
    outPut(D,'D');
}


Measured memory_bytes: 2700
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Restaurant> list = new ArrayList<Restaurant>();
        int N = sc.nextInt();
        for (int i = 1; i <= N; i++) {
        String name = sc.next();
        int point = sc.nextInt();
        list.add(new Restaurant(name, point, i));
        }
        Collections.sort(list);
        for (Restaurant res: list) {
        System.out.println(res.i);
      }
    }
}

class Restaurant implements Comparable<Restaurant> {
  String name;
  int point;
  int i;
  
  public Restaurant(String name, int point, int i) {
    this.name = name;
    this.point = point;
    this.i = i;
  }
 
 @Override
  public int compareTo(Restaurant obj) {
    int ans = name.compareTo(obj.name);
    if (ans != 0){
         return ans;
    }
    //同じときは、点数で降順にする
    return Integer.compare(point, obj.point)*-1;
  }
}

Measured memory_bytes: 35892
#include <stdio.h>
void dfsv(int, int);
int array[100][100],col[100],found[100],fin[100],time;
int main(){
  int num,i,j,id,nextnum,next;
  scanf("%d",&num);
  for(i=0;i<num;i++){
    for(j=0;j<num;j++){
      array[i][j]=0;
    }
  }
  for(i=0;i<num;i++){
    scanf("%d%d",&id,&nextnum);
    for(j=0;j<nextnum;j++){
      scanf("%d",&next);
      array[id-1][next-1]=1;
    }
  }
  for(i=0;i<num;i++) col[i]=0;
  time=0;
  for(i=0;i<num;i++){
    if(col[i]==0) dfsv(i,num);
  }
  for(i=0;i<num;i++) printf("%d %d %d\n",i+1,found[i],fin[i]);
  
  return 0;
}

void dfsv(int val, int num){
  int i;
  col[val]=1;
  time++;
  found[val]=time;  /*first visit*/
  for(i=0;i<num;i++){
    if(array[val][i]!=1) continue;
    if(col[i]==0) dfsv(i,num);
  }
  col[val]=2;
  time++;
  fin[val]=time; /*finish visit*/
}



Measured memory_bytes: 2112
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#define my_abs(x) ((x) < 0 ? -(x) : (x))
#define pb push_back
typedef long long ll; 
char str[1000005]; 
int main()
{
	// freopen("B.in", "r", stdin); 
	int w; 
	scanf("%s%d", str, &w); 
	int n = strlen(str); 
	for (int i = 0; i < n; i += w)
		putchar(str[i]); 
	puts("");
	return 0; 
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define fin(ans) cout<<(ans)<<endl
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p,q)
#define pb(n) push_back(n)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(a.begin(),a.end())
#define Rort(a) sort(a.rbegin(),a.rend())
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;}
const int P = 1000000007;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;



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

    string s;
    cin>>s;
    if(s=="Sunny")fin("Cloudy");
    else if(s=="Cloudy")fin("Rainy");
    else fin("Sunny");
    


//////////////////////////////////////////////////////
return 0;}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

string f(int n) {
  string ret;
  rep(i, n) {
    ret += '.';
  }
  return ret;
}

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

  int h, w, k;
  cin >> h >> w >> k;
  vector<string> s(h);
  rep(i, h) {
    cin >> s[i];
  }

  vector<vi> ans(h, vi(w, -1));
  int cnt = 0;
  rep(i, h) {
    if (s[i] == f(w)) {
      continue;
    }
    cnt++;
    bool f = true;
    rep(j, w) {
      if (s[i][j] == '#') {
        if (!f) {
          cnt++;
        }
        f = false;
      }
      ans[i][j] = cnt;
    }
  }

//  rep(i, h) {
//    rep(j, w) {
//      cout << ans[i][j] << " ";
//    }
//    cout << endl;
//  }

  rep(i, h) {
    if (i == 0 && ans[i][0] == -1) {
      rep(j, h) {
        if (ans[j][0] != -1) {
          rep(k, w) {
            ans[i][k] = ans[j][k];
          }
          break;
        }
      }
    } else if (ans[i][0] == -1) {
      cerr << i << endl;
      for (int j = i-1; j >= 0; j--) {
        if (ans[j][0] != -1) {
          rep(k, w) {
            ans[i][k] = ans[j][k];
          }
          break;
        }
      }
    }
    rep(j, w) {
      cout << ans[i][j] << " ";
    }
    cout << endl;
  }
}


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

int main(){
	int D; cin>> D;
  	
  	if(D==25){
      cout<<"Christmas"<<endl;
    }else if(D==24){
      cout<<"Christmas Eve"<<endl;
    }else if(D==23){
      cout<<"Christmas Eve Eve"<<endl;
    }else if(D==22){
      cout<<"Christmas Eve Eve Eve"<<endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

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

  if (s.size() > k) {
    for (int i = 0; i < k; i++) {
      cout << s[i];
    }
    cout << "..." << endl;
  } else {
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3592