akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <stack>
#include <stdio.h>

#define BUF_SIZE 20008

using namespace std;

stack<int> ST;

void calcS(){

}

int main(){

	char buf[BUF_SIZE];
	int heightTable[BUF_SIZE],maxHeightTable[BUF_SIZE],height = 0,maxHeight = 0,i;

	fgets(buf,BUF_SIZE,stdin);

	char current,history = 's';

	for(i = 0;;i++){
		current = buf[i];
		if(history == '/'){
			height += 1;
		}else if(history == '\\'){
			height -= 1;
		}else{
			//Do nothing
		}
		heightTable[i] = height;
		if(i == 0){
			if(buf[0] == '\\'){
				maxHeightTable[i] = 0;
			}else{
				maxHeightTable[i] = -1;
			}

		}else{
			maxHeightTable[i] = maxHeightTable[i-1];
		}

		if(maxHeight <= height && ((history == '/' && current == '\\')
				|| (history == '_' && current == '\\') || (history == '/' && current== '\n'))){
			maxHeightTable[i] = i;
			maxHeight = height;
		}
		history = current;

		if(current ==  '\n'){
			break;
		}
	}


	int total = 0,left = 0,baseHeight = 0,S = 0,tmp,joutei = 0,katei = 0,k = 0,pool_count = 0;

	for(; i > 0; ){

		if(maxHeightTable[i-1] == -1){
				break;
		}else{

			if(buf[i-1] == '/'){
				tmp = 0;
				if(maxHeightTable[i] == i || heightTable[i] > heightTable[maxHeightTable[i-1]]){
					left = maxHeightTable[i-1];
					baseHeight = heightTable[left];
					k = left;
					while(true){
						joutei = 10*(baseHeight - heightTable[k]);
						katei = 10*(baseHeight - heightTable[k+1]);
						tmp += (joutei+katei)/2;
						if(baseHeight ==  heightTable[k+1]){
							break;
						}
						k++;
					}
					S = tmp/10;
					if( S!= 0){
						total += S;
						ST.push(S);
						pool_count++;
					}
					i = left;
				}else{
					for(k = i-1; k >= 0; k--){
						if(heightTable[k] == heightTable[i]){
							break;
						}
					}
					left = k;
					baseHeight = heightTable[left];
					while(true){
							joutei = 10*(baseHeight - heightTable[k]);
							katei = 10*(baseHeight - heightTable[k+1]);
							tmp += (joutei+katei)/2;
							if(baseHeight ==  heightTable[k+1]){
								break;
							}
							k += 1;
					}
					S = tmp/10;
					if( S!= 0){
						total += S;
						ST.push(S);
						pool_count++;
					}
					i = left;
				}
			}else{
				i--;
			}
		}
	}

	printf("%d\n",total);
	printf("%d",pool_count);
	while(!ST.empty()){
		printf(" %d",ST.top());
		ST.pop();
	}
	printf("\n");
}


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    string s;
    cin >> s;

    for (char & i : s) {
        int ch = i - 'A';
        ch += n;
        ch %= 26;
        i = ch + 'A';
    }
    cout << s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<char> A(n);
            REP(i, n) cin >> A[i];
            if(n == 1) cout << A[0] << " " << 1 << endl;
            else{
                vector<pair<int, char>> B(0);
                bool ok = false;
                pair<char, int> ans;
                REP(i, n){
                    bool fd = false;
                    REP(j, B.size()){
                        if(A[i] == B[j].second){
                            B[j].first++;
                            fd = true;
                            break;
                        }
                    }
                    if(fd != true){
                        B.push_back(make_pair(1, A[i]));
                    }
                    whole(sort, B, greater<>());
                    if(B.size() >= 2 and B[0].first > B[1].first + (n - (i + 1))){
                        ok = true;
                        ans = make_pair(B[0].second, i + 1);
                        break;
                    }
                    else if(B.size() == 1 and B[0].first > n / 2){
                        ok = true;
                        ans = make_pair(B[0].second, i + 1);
                        break;
                    }
                }
                if(ok) cout << ans.first << " " << ans.second << endl;
                else{
                    if(B[0].first == B[1].first) cout << "TIE" << endl;
                    else cout << B[0].second << " " << n << endl;
                }
            }       
        }
    }
}


Measured memory_bytes: 3072
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
S = input()

es = [0] * (N + 1)
ws = [0] * (N + 1)

for i, c in enumerate(S):
    if c == 'E':
        es[i + 1] = es[i] + 1
        ws[i + 1] = ws[i]
    elif c == 'W':
        ws[i + 1] = ws[i] + 1
        es[i + 1] = es[i]
    
ans = INF
for i in range(N):
    cnt = ws[i] + (es[N] - es[i + 1])
    ans = min(ans, cnt)
print(ans)


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

double Temp (int T_Normal,int Height){
  double T;
  T = T_Normal - 0.006*Height;
  return T;
}

  
int main() {
  //入れ物の宣言
  int N ; //データの数
  int T_Normal ; //平均気温
  int T_Stand ; //基準温度
  int Num = 0 ; //ベストな番地(0を代入）
  vector<int> height(1500); //各地点の標高
  
  //データ入力部
  cin >> N ;
  cin >> T_Normal;
  cin >> T_Stand ;
  
  for (int i = 0;i < N; i++){
    cin >> height.at(i);
  }
  
  //一番基準の温度に近いところを検索
   
  for (int i =1 ; i < N;i++){
    if (abs(T_Stand - Temp(T_Normal,height.at(Num))) > abs(T_Stand - Temp(T_Normal,height.at(i)))){
      Num = i;
    }
  }
   
 cout << Num + 1 << endl;
}

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

#define HAS_TEST_CASE 0  // Do you forget to complete this?

namespace registerGen
{
typedef long long ll;

const int N=1e6;

int n,m,a[N+10];
char str[N+10];
bool vis[N+10];

inline void main()
{
	int k;
	scanf("%d",&k);
	if(!(k%2))return puts("-1"),void();
	int ans=0,now=0;
	while(1)
	{
		now=(now*10+7)%k;
		if(vis[now])return puts("-1"),void();
		vis[now]=1;
		ans++;
		if(now==0)break;
	}
	printf("%d\n",ans);
}
}

int main()
{
#ifndef ONLINE_JUDGE
///	freopen("tmp.out","w",stdout);
#endif
	int T=1;
#if HAS_TEST_CASE
	scanf("%d",&T);
#endif
	while(T--)registerGen::main();
	return 0;
}


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

int main() {
  int N;
    cin >> N;
    int a = N%10;
    int b = (N%100-a)/10;
    int c = (N%1000-10*b-a)/100;
    int d = (N-100*c-10*b-a)/1000;
  if ((a==b && b==c) || (b==c && c==d) ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
    
    
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        long A = sc.nextLong();
        String op = sc.next();
        long B = sc.nextLong();
        
        System.out.println(op.equals("+") ? A+B: A-B);
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

using EDGE = vector<unordered_map<ll, ll>>;

void dfs(ll node, ll dist, vector<ll>& colors, const EDGE& edges)
{
    if (colors[node] != -1) {
        return;
    }

    colors[node] = (dist % 2 == 0) ? 1 : 0;

    for (auto um : edges[node]) {
        dfs(um.first, dist + um.second, colors, edges);
    }
}

void main_()
{
    ll N;
    cin >> N;
    EDGE edges(N + 1, unordered_map<ll, ll>());
    for (ll i = 0; i < N - 1; i++) {
        ll u, v, w;
        cin >> u >> v >> w;
        edges[u][v] = w;
        edges[v][u] = w;
    }

    vector<ll> colors(N + 1, -1);
    dfs(1, 0, colors, edges);

    copy(begin(colors) + 1, end(colors), ostream_iterator<ll>(cout, "\n"));
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 18688
import math

x = int(input())

for num in range(x, 100003+1):
    cnt = 0
    # 素数を見つける割り算は半分でいい
    for i in range(2, int(math.sqrt(num))+1):
        if num % i == 0:
            cnt += 1
    if cnt == 0:
        print(num)
        break

Measured memory_bytes: 3060
(N, M), P, *E = $<.map{|ln|ln.split.map(&:to_i)}

P.unshift(0)
IP = [0]*(N+1)
P.each_with_index{|p,i| IP[p]=i }

G = *0..N
ID = lambda{|i|
	next i == G[i] ? i : G[i] = ID[G[i]]
}
E.each{|xy|
	a,b = xy.map(&ID)
	G[a] = G[b] = [a,b].min
}

p (1..N).count{|i|
	P[i] == i or ID[i] == ID[IP[i]]
}


Measured memory_bytes: 16252
int main(){
    int m,f,r;
    for(;;){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1&&f==-1&&r==-1)break;
        if (m==-1 || f==-1) printf("F\n");
        else if (m+f>=80) printf("A\n");
        else if (m+f>=65) printf("B\n");
        else if (m+f>=50) printf("C\n");
        else if (m+f>=30 && r>=50) printf("C\n");
        else if (m+f>=30) printf("D\n");
        else if (m+f<30)  printf("F\n");
    }
    return 0;   
}
         
         
         
          
        
      
     
   



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define per(i,b,a) for (int i=b;i>=a;i--)
#define mes(a,b)  memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
typedef long long ll;
const int N = 200005;

int n, a[N], ans;
int main()
{
    int  flag=-1, flag2=-1;
    scanf("%d", &n);
    rep(i,1,n) {
        scanf("%d", &a[i]);
        if(flag==-1) ans++, flag=0;
        else if(flag2==-1) {
            if(a[i]>a[i-1]) flag2=0;
            else if(a[i]<a[i-1]) flag2=1;
        }
        else if(flag2==0) {
            if(a[i]<a[i-1]) flag2=-1, ans++;
        }
        else if(flag2==1) {
            if(a[i]>a[i-1]) flag2=-1, ans++;
        }
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
struct UnionFind {
private:
    ll N;
    vector<ll> parent;
    vector<ll> num;
    vector<ll> diff_weight;
    vector<ll> rank;

public:
    UnionFind(ll n){
        N = n;
        rep(i,0,N) parent.push_back(i);
        rep(i,0,N) num.push_back(1);
        rep(i,0,N) diff_weight.push_back(0);
        rep(i,0,N) rank.push_back(0);
    }
    ll root(ll x){
        if(x == parent[x]){
            return x;
        }else{
            ll r = root(parent[x]);
            diff_weight[x] += diff_weight[parent[x]];
            return parent[x] = r;
        }
    }
    void unite(ll a, ll b, ll w = 0){
        w += weight(a); w -= weight(b);
        a = root(a); b = root(b);
        if(a == b) return;
        // if(rank[a] < rank[b]) swap(a,b), w = -w;
        // if(rank[a] == rank[b]) ++rank[a];
        parent[b] = a;
        ll sum = num[a] + num[b];
        num[a] = sum;
        num[b] = sum;
        diff_weight[b] = w;
    }
    // void merge(ll a, ll b, ll w){
    //     w += weight(a); w -= weight(b);
    //     a = root(a); b = root(b);
    //     if(a == b) return;
    //     // if(rank[a] < rank[b]) swap(a,b), w = -w;
    //     // if(rank[a] == rank[b]) ++rank[a];
    //     parent[b] = a;
    //     ll sum = num[a] + num[b];
    //     num[a] = sum;
    //     num[b] = sum;
    //     diff_weight[b] = w;
    // }
    bool same(ll a, ll b){ return root(a) == root(b);}
    ll sz(ll x){ return num[x];}

    ll weight(ll x){
        root(x);
        return diff_weight[x];
    }

    ll diff(ll a, ll b){
        return weight(b) - weight(a);
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    UnionFind uf(100010);
    ll N,M;
    cin >> N >> M;
    ll L[200010], R[200010], D[200010];
    rep(i,0,M){
        cin >> L[i] >> R[i] >> D[i];
        L[i]--; R[i]--;
    }
    bool ok = true;
    rep(i,0,M){
        if(not uf.same(L[i], R[i])){
            uf.unite(L[i], R[i], D[i]);
        }else{
            ll diff = uf.diff(L[i],R[i]);
            if(diff != D[i]){
                ok = false;
            }
        }
    }
    if(ok){
        print("Yes");
    }else{
        print("No");
    }
    
}

Measured memory_bytes: 8180
//To debug :  g++ -g file.cpp -o code
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

double dp[301][301][301];
ll n;

double fun(double,double,double);

int main()
{

	FAST

	int i,j,k,v;

	rep(i,0,301)
		rep(j,0,301)
			rep(k,0,301)
				dp[i][j][k]=-1;


	double a=0,b=0,c=0;

	cin>>n;

	rep(i,0,n)
	{
		cin>>v;
		if(v==3)
			++a;
		else if(v==2)
			++b;
		else if(v==1)
			++c;
	}

	
cout<<setprecision(9)<<fixed<<1 + (c/(a+b+c))*fun(a,b,c-1) + (b/(a+b+c))*fun(a,b-1,c+1) + (a/(a+b+c))*fun(a-1,b+1,c);

	return 0;
}

double fun(double a,double b,double c)
{

	int A=a,B=b,C=c;

	if(a==0 && b==0 && c==0)
			return 0;
	else if(a<0 || b<0 || c<0)
			return 0;
	else if(dp[A][B][C]!=-1)
			return dp[A][B][C];
	else
	{
		dp[A][B][C] = n/(a+b+c) + (c/(a+b+c))*fun(a,b,c-1) + (b/(a+b+c))*fun(a,b-1,c+1) + (a/(a+b+c))*fun(a-1,b+1,c);

		return dp[A][B][C];
	}
	
}

Measured memory_bytes: 213376
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class FManySlimes {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n,S;
        in>>n;
        multiset<int> s;
        fr(_,1<<n) in>>S,s.insert(S);
        vector<int> now;
        auto t=s.end();
        --t;
        now.emplace_back(*t);
        s.erase(t);
        fr(_,n){
            int q=now.size();
            fr(j,q){
                auto it=s.lower_bound(now[j]);
                if(it==s.begin()){
                    out<<"No"<<endl;
                    return;
                }
                --it;
                now.emplace_back(*it);
                s.erase(it);
            }
        }
        out<<"Yes"<<endl;
    }
};

int main() {
    FManySlimes solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(a) (a).begin(),(a).end()
#define CHMIN(a, b) a = min((a),(b))
#define CHMAX(a, b) a = max((a),(b))
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main() {
    string n;
    cin >> n;

    auto ans = "No";
    for (int i = 0; i < 2; ++i) {
        if (n[i] == '9') {
            ans = "Yes";
        }
    }
    cout << ans << endl;
    return 0;
}

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

ll n,a,b;
int main () {
  cin >> n >> a >> b;
  if(b < a || (n == 1 && a != b)) {
    cout << 0 << endl;
  } else {
    cout << (n - 2) * (b - a) + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cctype>
#include <utility>
#include <algorithm>
using namespace std;

#define gcu getchar_unlocked
#define pcu putchar_unlocked
#define _T template <typename T>
#define _HT template <typename H, typename... T>
#define _il inline
#define _in _il int in
#define _sc _il bool scan
_T T in(int c){T n=0;bool m=false;
	while (isspace(c)) {c = gcu();}
	if(c=='-')m=true,c=gcu();
	do{n=10*n+(c-'0'),c=gcu();}while(c>='0');return m?-n:n;} //&&c<='9'
_in() {return in<int>(gcu());}
_T T scan(T &n){int c=gcu();return c==EOF?false:(n=in<T>(c),true);}
_sc(char &c){c=gcu();gcu();return c!=EOF;}
#ifdef _GLIBCXX_STRING
_sc(string &s){int c;s="";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#endif
_HT _sc(H &h, T&&... t){return scan(h)&&scan(t...);}
#define _vo _il void out
#define _vl _il void outl
_vo(bool b) {pcu('0'+b);}
_vo(const char *s){while(*s)pcu(*s++);}
_vo(char c){pcu(c);}
#ifdef _GLIBCXX_STRING
_vo(string s){for(char c:s)pcu(c);}
#endif
_T _vo(T n){static char buf[20];char *p=buf;
	if(n<0)pcu('-'),n*=-1;if(!n)*p++='0';else while(n)*p++=n%10+'0',n/=10;
	while (p!=buf)pcu(*--p);}
_vl(){out('\n');}
#ifdef _GLIBCXX_VECTOR
_T _vo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);outl();}
#endif
_HT _vo(H&& h, T&&... t){out(h);out(move(t)...);}
template <typename... T> _vl(T&&... t){out(move(t)...);outl();}

#define binds a, b, c, d, p

int main() {
	int binds;
	scan(binds);
	outl(min(p * a, max((p - c) * d, 0) + b));
}


Measured memory_bytes: 2608
#include<iostream>
#include<vector>
using namespace std;
typedef long long int ll;
static const int MAX_C = 200000;
static const ll MOD = 1000000007;
 
int N;
vector<int> C;
vector<ll> memo, memo2;
 
int main(){
	cin >> N;
	C.resize(N + 1);
	for(int i = 1; i < N + 1; i++) cin >> C[i];
	memo.resize(N + 1);
	memo2.resize(MAX_C + 1);
	memo[0] = 1;
	for(int i = 1; i < N + 1; i++){
		if(C[i] == C[i - 1]){
			memo[i] = memo[i - 1];
			continue;
		}
		memo2[C[i]] += memo[i - 1];
		memo2[C[i]] %= MOD;
		memo[i] = memo2[C[i]];
	}
	cout << memo[N] << endl;
	return 0;
}

Measured memory_bytes: 4096
import java.util.*;

public class Main {
  public static void main(String[] args) {
    try (Scanner sc = new Scanner(System.in)) {
      Queue<Prosess> queue = new ArrayDeque<>();
      int N = sc.nextInt();
      int q = sc.nextInt();
      int time = 0;

      for (int i = 0; i < N; i++) {
        queue.offer(new Prosess(sc.next(), sc.nextInt()));
      }

      while (queue.size() != 0) {
        Prosess p = queue.poll();
        if (p.time > q) {
          // クオンタムだけ処理
          queue.offer(new Prosess(p.name, p.time - q));
          time += q;
        } else {
          // 処理が終わっていれば、名前とここまでかかった時間を表示して終わり
          time += p.time;
          System.out.println(p.name + " " + time);
        }

      }
    }
  }
}

class Prosess {
  String name;
  int time;

  Prosess(String name, int time) {
    this.name = name;
    this.time = time;
  }
}


Measured memory_bytes: 74376
import sys
A,B = map(int,input().split())
if not ( 0 <= A <= 100 ): sys.exit()
if not ( 2 <= B <= 1000 ): sys.exit()
if not ( B % 2 == 0 ): sys.exit()

if A <= 5: print(0)
if 6 <= A <= 12: print(B//2)
if A >= 13: print(B)
 

Measured memory_bytes: 9080
def main():
    h, w, k = map(int, input().split())
    cake = [list(input()) for _ in range(h)]
    answer = [[0 for _ in range(w)] for _ in range(h)]
    count = 0
    for i in range(h):
        is_exits_strawberry = False
        for j in range(w):
            if cake[i][j] == "#":
                is_exits_strawberry = True
                count += 1
            if is_exits_strawberry:
                answer[i][j] = count
    for i in range(h):
        if answer[i][-1] == 0:
            continue
        for j in range(-1, -w - 1, -1):
            if answer[i][j] == 0:
                answer[i][j] = answer[i][j + 1]
    for i in range(-2, -h - 1, -1):
        if answer[i][0] == 0:
            answer[i] = answer[i + 1]
    for i in range(1, h):
        if answer[i][0] == 0:
            answer[i] = answer[i - 1]
    for ans in answer:
        print(" ".join(map(str, ans)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 7924
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef double db;
ll n;
vector<P> v;//first ???????????? second: 0or1
ll x;
int main()
{while(1){
	cin>>n;
	if(!n) return 0;
	v.clear();
	for(ll i=1;i<=n;i++){
		cin>>x;
		if(i==1||(i%2==1 && v[v.size()-1].second!=x)){//??°??????
			v.push_back(P(i,x));
		}
		else if(i%2==0&&v[v.size()-1].second!=x){//???????¶????
			if(v.size()==1){
				v[0].second=x;
			}
			else{
				v.erase(v.end()-1);
			}
		}
	}
	ll ans=0;
	for(ll i=0;i<v.size();i++){
		if(v[i].second==0) ans+=(i==v.size()-1?n+1:v[i+1].first)-v[i].first;
	}
	cout<<ans<<endl;
}}

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

int main() {
    int n, x;
    int count = 0;
    while(1){
        cin >> n >> x;
        if(n == 0 && x == 0){
            break;
        }
        for(int i = 1; i <= n; i++){
            for(int j = i + 1; j <= n; j++ ){
                for(int k = j + 1; k <= n ; k++){
                    if(i + j + k == x){
                        count++;
                    }    
                }
            }
        }
        cout << count << endl;
        count = 0;
    }
	return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<vector>
#include<algorithm>
#include<iterator>
#include<string>
#include<queue>

using namespace std;

typedef pair<int,int> P;//firstは最短距離,secondは頂点の番号

struct edge{
    int to,cost,index;
};

const int MAX_V=100;//問題の制約用
const int INF=9999999;
int V;//使う頂点数
vector<edge> G[MAX_V];//グラフ
int d[MAX_V];//距離を詰める
int IsUsed[1000];

void dijkstra(int s){//始点sからの最短距離を求める。
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d,d+V,INF);
    d[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.top(); que.pop();
        int v = p.second;
        if(d[v]<p.first) continue;//それが最短距離でなければ無視
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to] > d[v] + e.cost){
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to],e.to));
            }else if(d[e.to]==d[v]-e.cost){
                IsUsed[e.index]++;
            }
        }
    }
}

int main(){
    int N,M;
    cin>>N>>M;
    V=N;
    for(int i=0;i<M;i++){
        int A,B,C;
        cin>>A>>B>>C;
        A--; B--;
        edge e;
        e.to=B;
        e.cost=C;
        e.index=i;
        G[A].push_back(e);
        e.to=A;
        G[B].push_back(e);
    }
    for(int i=0;i<M;i++){
        IsUsed[i]=0;
    }
    for(int i=0;i<N;i++){
        dijkstra(i);
    }
    int ans=0;
    for(int i=0;i<M;i++){
        if(!IsUsed[i]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

int main(){
    long a, b, c;
    cin >> a >> b >> c;
    string ans;
    if(a + b - c >= 0){
        ans = "No";
    }
    else if(a * a + b * b + c * c - 2 * c * a - 2 * a * b - 2 * b * c > 0){
        ans = "Yes";
    }
    else{
        ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		
		int maxL = 0;
		int minR = 100_009;
		
		for (int i = 0; i < m; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			maxL = Math.max(maxL, l);
			minR = Math.min(minR, r);
		}
		
		int dif = minR - maxL;
		int ans = Math.max(dif + 1, 0);
		
		System.out.println(ans);
		

	}
}


Measured memory_bytes: 63184
#include <iostream>
using namespace std;
const int N_MAX = 100000;

long long gcd(long long a, long long b) {
	if (a < 0) a = -a;
	if (b < 0) b = -b;
	while (a != 0) {
		long long tmp = b % a;
		b = a;
		a = tmp;
	}
	return b;
}

long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}

int factor2(long long x) {
	int i = 0;
	while (x % 2 == 0) {
		x /= 2;
		i++;
	}
	return i;
}

int main() {
	long long n, m, a[N_MAX], f;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		a[i] /= 2;
		if (i == 0) f = factor2(a[i]);
		else if (f != factor2(a[i])) {
			cout << 0 << endl;
			return 0;
		}
	}
	long long l = 1;
	for (int i = 0; i < n; i++) {
		l = lcm(l, a[i]);
		if (l > m) {
			cout << 0 << endl;
			return 0;
		}
	}
	long long ans = m / l / 2;
	if ((m/l)%2 == 1) ans++;
	cout << ans << endl;
	return 0;
}

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

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

    ll n;
    cin >> n;
    //ll a[n];
    ll a;
    int four = 0;
    int odd = 0;
    int two = 0;
    rep(i, n){
        cin >> a;
        if(a%2) ++odd;
        else{
            if(a%4==0) ++four;
            else ++two;
        }
    }
    if(two){
        if(odd <= four) puts("Yes");
        else puts("No");
    }
    else{
        if(odd <= four+1) puts("Yes");
        else puts("No");
    }





}

Measured memory_bytes: 764
#include <iostream>
#include <string>
using namespace std;
int main(void){
    int N,M,ans=0;
    cin>>N;
    string s[N];
    for(int i=0;i<N;i++){
        cin>>s[i];
    }
    cin>>M;
    string t[M];
    for(int i=0;i<M;i++){
        cin>>t[i];
    }
    for(int i=0;i<N;i++){
        int x=0;
        for(int j=0;j<N;j++){
            if(s[i]==s[j]){
                x++;
            }
        }
        for(int j=0;j<M;j++){
            if(s[i]==t[j]){
                x--;
            }
        }
        if(x>ans){
        ans=x;
    }
    }
    cout<<ans<<endl;
    
}


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

int main(void)
{
	vector <int> square;
	int dp[350] = {0};
	for (int i = 1; i <= 17; i++){
		square.push_back(i*i);
	}
	
	dp[0] = 1;
	for (int i = 0; i < 17; i++){
		for (int j = square[i]; j <= 300; j++){
			if (square[i] <= j) dp[j] += dp[j - square[i]];
		}
	}
	int n;
	while (cin >> n, n){
		cout << dp[n] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

#define MAX 300
#define MIN 1

int main(void)
{
	int height, width;
	
	while(1)
	{
		if( scanf("%d %d", &height, &width)==2 )
		{
			if((height==0) && (width==0))
			{
				break;
			}
			else if((height>=MIN) && (height<=MAX) &&
				(width>=MIN) && (width<=MAX))
			{
				for(int i=0; i<height; i++)
				{
					for(int j=0; j<width; j++)
					{
						printf("%c", '#');
					}
					printf("\n");
				}
				printf("\n");
			}
			else
			{
				return -1;
			}
		}
		else
		{
			return -1;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=(a);i<(b);i++)
#define fore(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
#define F first
#define S second
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;
void amin(ll &a, ll b){ a=min(a,b); }
void amax(ll &a, ll b){ a=max(a,b); }
void YES(){cout<<"YES\n";} void NO(){cout<<"NO\n";}
void SD(int t=0){ cout<<"PASSED "<<t<<endl; }
const ll INF = ll(1e18);
const int MOD = 998244353;

const bool DEBUG = 0;
const int MAXN = 100005;

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n; cin>>n;
	ii a[n];
	forn(i,0,n) cin>>a[i].F>>a[i].S;
	forn(i,0,n-2)
	{
		bool ok=1;
		forn(j,i,i+3)
		{
			if(a[j].F!=a[j].S) ok=0;
		}
		if(ok){ cout<<"Yes\n"; return 0; }
	}
	cout<<"No\n";
	
	return 0;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
const int maxn=1e5+100;
const int mod=1e9+7;
const int inf=123456789;
const int p=1e4;
using namespace std;
int n,m,k,ar[maxn],br[maxn],sum,s;
char str[maxn];
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>m;
    s=0;
    vector<int>v;
    for(int i=0;i<m;i++){
        cin>>k>>str;
        if(ar[k])continue;
        if(str[0]=='A'&&ar[k]==0){
            ar[k]=1;
            v.push_back(k);
        }else{
            br[k]++;
        }
    }
    for(int i:v){
        s+=br[i];
    }
    cout<<v.size()<<" "<<s<<'\n';
    return 0;
}


Measured memory_bytes: 1276
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
  Name:- OMHARI 
  Institution:- UNIVERSIT OF CALCUTTA(INFORMATION TECHNOLOGY)
  Email:- omharicu@gmail.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#include<bits/stdc++.h>
using namespace std; 

#define F               first
#define S               second
#define ull             unsigned long long
#define ll              long long
#define db              long double
#define ST              string
#define pb              push_back
#define mp              make_pair
#define el              "\n"
#define vll             vector <ll>
#define vi              vector <int>
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define vec(v)          vector <v>
#define all(v)          (v.begin(), v.end()) 
#define rall(v)         (v.rbegin(), v.rend()) 
#define is_sort(v)      is_sorted all(v)
#define max_of(v)       *max_element all(v)
#define min_of(v)       *min_element all(v)
#define itos(s)         to_string(s)
#define cntone(x)       __builtin_popcountll(x)
#define cntzro(x)       __builtin_clz(x)
#define clr(x,y) 		memset(x, y, sizeof(x))
#define For(i, a, b)    for(int i=a; i<b; i++)
#define Forr(i, a, b)   for(int i=a; i>=b; i--)
const ll mod = 1e9+7;

bool comp(pll &a, pll &b)
{
    ll len1, len2;
    len1=a.F+a.S;
    len2=b.F+b.S;

    return len1<len2;
}
bool com(pll &a, pll &b)
{
    ll len1, len2;
    len1=abs(a.F-a.S);
    len2=abs(b.F-b.S);
    

    return len1<len2;
}

void solve()
{
    int n;
    cin>>n;
    vll v(n), vv(n);

    For(i, 0, n)
    {
        ll x, y;
        cin>>x>>y;
        v[i]=x+y;
        vv[i]=(x-y);
    }

    sort all(v);
    sort all(vv);

    cout<<max(v[n-1]-v[0], vv[n-1]-vv[0]);
}

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

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    /***************-Code starts from here-***************/
    // int t;
    // cin>>t;
    // while(t--)
    solve();
    return 0; 
} 

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

int clacTime(string s){
  int st = toInt(s.substr(0,2)) * 10000;
  st += toInt(s.substr(3,2)) * 100;
  st += toInt(s.substr(6,2));
  return st;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while(true){
      cin >> n;
      if(n == 0) break;
      string s,e;
      VLL arr(300000,0);
      rep(i,n){
        cin >> s >> e;
        int st = clacTime(s);
        int et = clacTime(e);
        arr[st] ++;
        arr[et]--;
      }

      rep(i,arr.size()-1){
        arr[i+1] += arr[i];
      }

      ll ans = 0;
      rep(i,arr.size()){
        ans = max(arr[i],ans);
      }
      cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 5532
lis = [int(x) for x in input().split()]
res = 0

lis.sort()
lis_dif = [x-lis[0] for x in lis]
res += (lis_dif[2]//2)*2 - (lis_dif[1]//2)
lis_bi = [x%2 for x in lis_dif]
res += lis_bi.count(1)

print(res)

Measured memory_bytes: 3188
use std::cmp;
use proconio::input;

fn main() {
  input! {
    n : usize,
    a: [i64; n]
  }
  let mut dp = vec![vec![0; n + 1]; n + 1];
  for (i, &item) in a.iter().enumerate() {
    dp[i][i] = item;
  }
  
  for i in (1..n) {
    for j in (0..(n - i)) {
      dp[j][j + i] = cmp::max(dp[j+i][j+i] - dp[j][j + i - 1], dp[j][j] - dp[j + 1][j + i]);
    }
  }
    
    println!("{}", dp[0][n - 1]);
}



Measured memory_bytes: 72556
N = int(input())
Pi = list(map(int, input().split()))
sortedPi = sorted(Pi)
wrongPiCnt = 0
for i in range(N):
    if Pi[i] - sortedPi[i] != 0:
        wrongPiCnt +=1
if wrongPiCnt > 2:print('NO')
else:print('YES')

Measured memory_bytes: 2940
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <map>
#include <functional>
#include <set>

#define rep(i, n) for(int i = 0; i < (n); i++)
#define MAX(a, b) (((a) < (b)) ? (b) : (a))
#define MIN(a, b) (((a) < (b)) ? (a) : (b))

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pint;
const ll inf = (1LL << 60);
const ll mod = 1000000007;
ll max(ll a, ll b) {
	if (a < b)
		return b;
	else
		return a;

}
ll min(ll a, ll b) {
	if (a < b)
		return a;
	else
		return b;

}





int main() {
	
	ll N;
	cin >> N;
	vector<ll> A(N), B(N);

	rep(i, N) {
		cin >> A[i];
		B[i] = A[i];
	}
	sort(A.begin(), A.end());

	reverse(A.begin(), A.end());


	if (A[0] == A[1]) {
		rep(i, N) {

			cout << A[0] << endl;
		}

	}

	else {
		rep(i, N) {
			if (B[i] == A[0])
				cout << A[1] << endl;
			else
				cout << A[0] << endl;
		}
	}




	return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int rever(int n)
{

int t=n,r,num=0;

while(t>=1)

{

r=t%10;

t=t/10;

num=num*10+r;

}

return num;

}
int isPalindrome(int num)
{
int n=rever(num);

if(n==num)

return 1;

else

return 0;

}


int main()
{

ll n,k,c;
cin>>n>>k>>c;
if(n+k>=c) cout<<"Yes";
else cout<<"No";
return 0;

}



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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

template <class T1, class T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T1, class T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll N, M;
    cin >> N >>M;
    ll ans = 0;
    rep(i, M)
    {
        ll num;
        cin >> num;
        ans += num;
    }

    ans = N -ans;
    if (ans < 0)
    {
        cout << -1 << endl;
    }else
    {
        cout << ans << endl;
    }

}

Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<cmath>
#include<stdio.h>
#include<map>
#include<set>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
    //freopen("/Users/shitian/Downloads/2546-in5.txt","r",stdin);
    int m,n;
    cin>>m>>n;
    int c[101][101];
    for(int i=0;i<m;i++)
        for(int j=0;j<n;j++){
            cin>>c[i][j];
        }
    int all=0;
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            if(i>0)
                c[i][j]=(c[i][j]+1)%2;
        }
        int maxA=0;
        for(int mi=0;mi<n;mi++){
            int curA=0;
            for(int l=0;l<mi;l++){
                if(l==0){
                    curA+=c[i][l];
                } else {
                    curA+=(c[i][l]+1)%2;
                }
            }
            //cout<<"- curA: "<<curA<<endl;
            for(int r=n-1;r>mi;r--){
                if(r==n-1){
                    curA+=c[i][r];
                } else {
                    curA+=(c[i][r]+1)%2;
                }
            }
            //cout<<"-- curA: "<<curA<<endl;
            if((mi>0&&mi<n-1)||(n<2)){
                curA+=c[i][mi];
            } else {
                curA+=(c[i][mi]+1)%2;
            }
            //cout<<"--- curA: "<<curA<<endl;
            maxA = max(maxA, curA);
        }
        all += maxA;
    }
    cout<<all<<endl;
}

Measured memory_bytes: 1200
#   2???????????????????????????????????????????????????????????°??????


#   ??????????????¢????????????????????????
#   top = 1 front = 2 right = 3 left = 4 back = 5 bottom = 6
class Dice:
    def __init__(self, nums):
        self.face = nums

    #   2->1->5->6
    def __turnSouth__(self):
        temp = self.face[0]
        self.face[0] = self.face[4]
        self.face[4] = self.face[5]
        self.face[5] = self.face[1]
        self.face[1] = temp
        return self

    #   4->1->3->6
    def __turnEast__(self):
        temp = self.face[0]
        self.face[0] = self.face[2]
        self.face[2] = self.face[5]
        self.face[5] = self.face[3]
        self.face[3] = temp
        return self

    #   3->1->4->6
    def __turnWest__(self):
        temp = self.face[0]
        self.face[0] = self.face[3]
        self.face[3] = self.face[5]
        self.face[5] = self.face[2]
        self.face[2] = temp
        return self

    #   5->1->2->6
    def __turnNorth__(self):
        temp = self.face[0]
        self.face[0] = self.face[1]
        self.face[1] = self.face[5]
        self.face[5] = self.face[4]
        self.face[4] = temp

    #   2->3->5->4
    def __turnRight__(self):
        temp = self.face[1]
        self.face[1] = self.face[2]
        self.face[2] = self.face[4]
        self.face[4] = self.face[3]
        self.face[3] = temp
        return self

    #   2->4->5->3
    def __turnLeft__(self):
        temp = self.face[1]
        self.face[1] = self.face[3]
        self.face[3] = self.face[4]
        self.face[4] = self.face[2]
        self.face[2] = temp
        return self

    def equals(self, another):
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.__turnRight__()
            another.__turnNorth__()
        #   ?????¢??????????????????????????????
        for i in range(0, 4):
            if self.face[0] == another.face[0]:
                #   ??£??¢???????????????????????¢????????????????????¢
                for j in range(0, 4):
                    if self.face[1] == another.face[1]:
                        if self.face == another.face:
                            return True
                    another.__turnRight__()
            another.__turnEast__()
        return False

#   Dice?????????
Dice1 = Dice(input().split())
Dice2 = Dice(input().split())

if Dice1.equals(Dice2):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 7704
import java.util.*;
class Main
{
  public static void main(String args[])
  {
    int K;
    Scanner in=new Scanner(System.in);
    K=in.nextInt();
    String S=in.next();
    int l=S.length();
    if(l<=K)
      System.out.println(S);
    else
    {
      String p=S.substring(0,K);
      p=p+"...";
      System.out.println(p);
    }
  }
        
}

Measured memory_bytes: 38716
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int A = in.nextInt();
			int B = in.nextInt();
			int K = in.nextInt();
			int count = 0;
			ArrayList<Integer> list = new ArrayList<>();
			for(int i = 1; i < 10000; i++) {
				if(A % i == 0 && B % i == 0) {
					list.add(i);
				}
			}
			Collections.sort(list, Comparator.reverseOrder());
			out.println(list.get(K - 1));
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public char nextChar() {
			return next().charAt(0);
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}

	}
}


Measured memory_bytes: 23380
n = gets.chomp.to_i

n.times do
  h, m = gets.chomp.split(':').map(&:to_f)
  diff = (h * 30 + m * 0.5 - m * 6).abs
  diff = 360 - diff if diff > 180
  if diff < 30
    puts :alert
  elsif diff < 90
    puts :warning
  else
    puts :safe
  end
end

Measured memory_bytes: 8804
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	char c;
	cin>>c;
	if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'){
		cout<<"vowel"<<endl;
	}
	else{
		cout<<"consonant"<<endl;
	}
}

Measured memory_bytes: 256
// 解説前
#include <iostream>

int solve_A() {
  char S[3];
  std::cin.read(S, 3);

  std::cin.get();  // 改行を読み飛ばす
  
  char T[3];
  std::cin.read(T, 3);

  size_t result = 0;
  for (size_t i = 0; i < 3; ++i) {
    if (S[i] == T[i]) result++;
  }

  std::cout << result;
  return 0;
}

int main() {
  return solve_A();
}


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int open = 0; // 対応していない開き括弧の数（後ろに足さなきゃいけない閉じ括弧の数）
  int close = 0; // 対応していない閉じ括弧の数（前に足さなきゃいけない開き括弧の数）
  for (int i = 0; i < N; i++) {
    if (S[i] == '(') {
      open++;
    } else {
      if (open > 0) {
        open--;
      } else {
        close++;
      }
    }
  }
  for (int i = 0; i < close; i++) cout << '(';
  cout << S;
  for (int i = 0; i < open; i++) cout << ')';
  cout << endl;
  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

ll v[500019][2];

int main() {

    string S;
    cin >> S;

    string tS;

    ll idx = 0;
    ll cn = 0;
    for(ll i = 0; i < S.length(); i++){
        if(S[i] == 'x'){
            cn++;
        }else{
            v[idx][0] = cn;
            v[idx+1][0] = S[i];
            cn = 0;
            idx+=2;
        }
    }
    if(S.back() == 'x') v[idx][0] = cn;

    idx = 0;
    cn = 0;
    for(ll i = S.length()-1; i >= 0; i--){
        if(S[i] == 'x'){
            cn++;
        }else{
            v[idx][1] = cn;
            v[idx+1][1] = S[i];
            cn = 0;
            idx+=2;
        }
    }
    if(S.front() == 'x') v[idx][1] = cn;

    ll ans = 0;
    for(ll i = 0; i <= 400000; i++){
        if(i % 2 == 1 && v[i][0] != v[i][1]){
            cout << -1 << endl;
            return 0;
        }else{
            ans += abs(v[i][0]-v[i][1]);
        }
    }

    cout << ans / 2 << endl;

}

Measured memory_bytes: 4608
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.hasNextLine();
		String[] stones = sc.next().split("");
		int redscnt = 0;
		int whitecnt = 0;
		for (int i = 0; i < n; i++) {
			if (stones[i].equals("R")) {
				redscnt++;
			} else {
				whitecnt++;
			}
		}
		
		int min = 0;
		int whiteleft = 0;				// 左辺の白（移動対象）
		int rednow = redscnt;		// 右辺の赤（移動対象）
		for (int i = 0; i <= n; i++) {
			// i = 仕切り位置
			if ( i != 0) {
				if (stones[i-1].equals("W")) {
					// 仕切りの左辺の「白」
					whiteleft++;
				} else {
					// 右辺の「赤」
					rednow--;
				}
			}
			// 多い方の分の移動回数になる
			int max = Math.max(whiteleft, rednow);
			// 最小なら移動回数を更新
			if (i == 0 || max < min) {
				min = max;
			}
		}
		System.out.println(min);
		
	}
}


Measured memory_bytes: 54324
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
//bool compare_map(string s1, string s2){
//  //for(int i=0;i<mp1.size();i++){
//    for(int i=0; i<s1.length(); i++){
//        if(s1[i] != s2[i])
//            return false;
//    }
//    //cout << s1 << " vs " <<  s2 << endl;
//    return true;
//}
int main(){
    int N;
    cin >> N;
    ll count = 0;
    map<string,int> mp;
    rep(i,N){
        string s;
        cin >> s;
        sort(s.begin(), s.end());
        //cout << s << endl;
        mp[s]++;
        //if(i==0){
        //    s_vec.push_back(s);
        //}
        //else{
        //    for(int i=0;i < s_vec.size();i++){
        //        if(compare_map(s, s_vec[i])){
        //            count +=1;
        //            break;
        //        }
        //        //else{
        //        //    s_vec.push_back(s);
        //        //}
        //        if(i== s_vec.size()-1)
        //            s_vec.push_back(s);

        //    }
        //}
    }
    for(auto& p : mp){
        ll a = p.second;
        count += static_cast<ll>(a*(a-1)/2);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 11136