akhauriyash/Code-Regression huggingface dataset:
// 2020-06-24 22:53:17
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

struct Line {
  int a, b, c;
  Line(int a_, int b_, int c_) : a(a_), b(b_), c(c_) {}
};

void answer() {
  int n, m;
  cin >> n >> m;
  vector<Line> vs, hs; // x1, x2, y / y1, y2, x
  map<int, int> mapX, mapY;
  mapX[0] = 0;
  mapY[0] = 0;
  rep(i, n) {
    int a, b, c;
    cin >> a >> b >> c; // x1, x2, y
    vs.emplace_back(Line(a, b, c));
    mapX[a] = mapX[b] = mapY[c] = 0;
  }
  rep(i, m) {
    int a, b, c;
    cin >> c >> a >> b; // x, y1, y2
    hs.emplace_back(Line(a, b, c));
    mapY[a] = mapY[b] = mapX[c] = 0;
  }
  vector<int> xs, ys;
  for(auto& mx : mapX) {
    mx.second = xs.size();
    xs.emplace_back(mx.first);
  }
  for(auto& my : mapY) {
    my.second = ys.size();
    ys.emplace_back(my.first);
  }
  int xsz = xs.size(), ysz = ys.size();
  vector<vector<int> > dist(xsz*2, vector<int>(ysz*2, 0));
  for(const auto& l : vs) {
    for(int x = mapX[l.a]; x <= mapX[l.b]; x++) {
      dist[x*2+0][mapY[l.c]*2] = -1;
      if(x < mapX[l.b]) dist[x*2+1][mapY[l.c]*2] = -1;
    }
  }
  for(const auto& l : hs) {
    for(int y = mapY[l.a]; y <= mapY[l.b]; y++) {
      dist[mapX[l.c]*2][y*2+0] = -1;
      if(y < mapY[l.b]) dist[mapX[l.c]*2][y*2+1] = -1;
    }
  }
  queue<pair<int, int> > que;
  que.emplace(make_pair(mapX[0]*2+1, mapY[0]*2+1));
  int dx[] = {0, 1, 0, -1};
  int dy[] = {1, 0, -1, 0};
  ll ans = 0;
  while(!que.empty()) {
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    if(dist[x][y] == -1) continue;
    if(dist[x][y] == 1) continue;
    dist[x][y] = 1;
    if(x % 2 && y % 2) {
      ans += abs(ll(xs[x/2]) - ll(xs[x/2+1])) * abs(ll(ys[y/2]) - ll(ys[y/2+1]));
    }
    rep(d, 4) {
      int nx = x + dx[d], ny = y + dy[d];
      if(dist[nx][ny] == -1) continue;
      if(dist[nx][ny] == 1) continue;
      if(nx == 0 || nx == xsz*2-1 || ny == 0 || ny == ysz*2-1) {
        cout << "INF\n";
        return;
      }
      que.push(make_pair(nx, ny));
    }
  }
  cout << ans << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 144456
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		int sum = 1;
		for (int i = 0; i < n; i++) {
			sum = Math.min(sum * 2, sum + k);
		}
		System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <vector>
int main(){
 int n;
 std::vector<int> shot(0);
 int a=1;
 std::vector<int> yeah(0);
 while(true){
  yeah.resize(a);
  std::cin>>n;
  if(n==0){
   break;
  }
  for(int i=1;i<=n/4;i++){
   shot.resize(i);
   std::cin>>shot[i-1];
   yeah[a-1]+=shot[i-1];
  }
  a++;
 }
 for(int i=0;i<a-1;i++){
  std::cout<<yeah[i]<<std::endl;
 }
}

Measured memory_bytes: 1220
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <set>

#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define MOD 1000000007

using namespace std;

int pow_mod(int a, int b, int p) {
	if (b == 0)return 1;
	else if (b % 2 == 0)return (pow_mod(a*a, b / 2, p) % p);
	else return (pow_mod(a, b - 1, p)*a%p);
}

int factorial_mod(int a, int p) {
	if (!a)return 1;
	else return a * factorial_mod(a - 1, p) % p;
}

int sum_digit(int N) {
	int ans = 0;
	for (; N != 0;) {
		ans += N % 10;
		N /= 10;
	}
	return ans;
}

string s;

int main(){
	cin >> s;
	int len = s.length();
	if (s[0] != 'A') {
		printf("WA");
		return 0;
	}
	int cnt = 0;
	bool flag = 0;
	for(int i=2;i<len-1;i++)if (s[i] == 'C')flag = true;
	rep(i, len)if ('A' <= s[i] && s[i] <= 'Z')cnt++;
	if (flag && (cnt == 2))printf("AC");
	else printf("WA");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,a,b) for( ll i = a; i < b ; i++ ) 
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define inter ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nuintptr)
	
using namespace std;


typedef int ll;
typedef long double ld;
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;

 
const int MAX = 2e5+10;
const ll inf = 1e9+10;

ll a[MAX],b[MAX];
ll n,k;




int main(){
	fastio;
	ll r;
	cin>>n>>k;
	f(i,1,n+1){
		cin>>a[i];
		b[max(1,i-a[i])]++;
		b[min(n,i+a[i]) +1]--;
	}
	f(i,1,n+1) b[i+1]+=b[i];
	f(x,0,min(k,500)){
		f(i,1,n+1) a[i] = b[i],b[i]=0;
		f(i,1,n+1){
			b[max(1,i-a[i])]++;
			b[min(n,i+a[i]) +1]--;
		}
		f(i,1,n+1)  b[i+1]+=b[i];
	}
	f(i,1,n+1){
		cout<<a[i]<<" ";
	}
	cout<<endl;
}	

Measured memory_bytes: 5220
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

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

const int INF = 1 << 24;
const int N = 4;

int main(void){
    for(string A, B; cin >> A >> B, A != "0";){
        int h = 0, b = 0;

        rep(i, N){
            int ind = B.find(A.at(i));
            if(ind == i) h ++;
            else if(~ind) b ++;
        }
        cout << h << " " << b << endl;
    }
 
    return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	int N;
	set<int> st;
	cin >> N;
	fore(i,0,N){
		int t;
		cin >> t;
		st.insert(t);
	}
	cout << st.size() << endl;
}

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

int main() {
    int X, Y;
    cin >> X >> Y;
    string ans = "No";
    for (int i=0; i<=X; i++) {
        for (int j=0; j<=X; j++) {
            if (i+j==X and 2*i+4*j==Y) {
                ans = "Yes";
                break;
            }
        }
    }
    cout << ans << endl;
}

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

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

const ll LINF = 1001002003004005006LL;
const int INF = 1001001001;

const int mod = 1000000007;

int dp[100100];

int main() {
    int n, k; cin >> n >> k;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    rep(i,n+1) dp[i] = INF;
    dp[0] = 0;
    rep(i,n) {
        for (int j = 1; j<=k; ++j) {
            dp[i+j] = min(dp[i]+abs(h[i+j]-h[i]), dp[i+j]);
        }
    }
    cout << dp[n-1] << endl; 
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
const ll MAX = 300010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD2;
        inv[i] = MOD2 - inv[MOD2%i] * (MOD2 / i) % MOD2;
        finv[i] = finv[i - 1] * inv[i] % MOD2;
    }
}

ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD2) % MOD2;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    COMinit();
    ll n,a,b,k;
    cin >> n >> a >> b >> k;
    ll ans = 0;
    rep(i,n+1){
        ll m = k-i*a;
        if (m >= 0 && m%b == 0){
            m /= b;
            if (m > n) continue;
            (ans += COM(n,i)*COM(n,m)%MOD2)%=MOD2;
        }
    }
    PRINT(ans);
}


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

        // String s[];
        // int t[];
        String s[] = new String[N];
        int t[] = new int[N];

        for (int i = 0; i < N; i++) {
            s[i] = sc.next();
            t[i] = sc.nextInt();
        }
        String X = sc.next();
        int result = 0;
        for (int j = 0; j < N; j++) {
            if (X.equals(s[j])) {
                result = j + 1;
                break;
            }
        }
        int sum = 0;
        for (int k = result; k < N; k++) {
            sum += t[k];
        }
        System.out.println(sum);
    }
}

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

const int ALPHABET = 26; // アルファベットの文字数
int main() {
	string s;
	int K;
	cin >> s >> K;
	vector<string> v;
	for (int i = 0;i < s.length();i ++) {
		for (int j = i, end = min(i + K, (int)s.length());j < end;j ++) {
			v.push_back(s.substr(i, j - i + 1));
		}
	}
	sort(v.begin(), v.end());
	if (K == 1) {
		cout << v[0];
		return 0;
	}
	for (int i = 1;i < v.end() - v.begin();i ++) {
		if (v[i] != v[i - 1]) K --;
		if (K == 1) {
			cout << v[i];
			return 0;
		}
	}
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

substringの個数なんて高々|s|Kしかないので全部見れば良い
*/

Measured memory_bytes: 1660
#include <iostream>
#include <cstring>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
using namespace std;

typedef long long LL;

typedef struct BigArray
{
	LL num;
	LL cnt;
}BigArray;
BigArray ba[100000+5];

int comp(const BigArray& a, const BigArray& b)
{
	return a.num < b.num;
}

int main()
{
	int N;
	LL K;
	while (cin >> N >> K)
	{
		LL a, b;
		for (int i=1; i<=N; ++i)
		{
			cin >> a >> b;
			ba[i].cnt = b;
			ba[i].num = a;
		}

		sort(ba+1, ba+N+1, comp);
		LL count_up = 0;
		LL res = 0;
		for (int i=1; i<=N; ++i) if (count_up < K)
		{
			count_up += ba[i].cnt;
			res = ba[i].num;
		}
		cout << res << endl;
	}

	return 0;
}




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

int main(){
  int n;
  cin >> n;
  int temp = n, sum = 0;
  while(temp > 0){
    sum += temp % 10;
    temp /= 10;
  }
  if(n % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
a=[0]+list(map(int,input().split()))
aa=[0,1]+[0 for i in range(n-1)]
i=1
flag=False
l=list()
while True:
    i=a[i]
    aa[i]+=1
    if aa[i]==2 and not(flag):
        flag=True
    k-=1
    if flag:
        l.append(i)
        if aa[i]==3:
            l=l[:-1]
            break
    if k==0:
        print(i)
        exit()
print(l[k%len(l)])

Measured memory_bytes: 32380
/**
  @file b.cpp
  @title B - Uneven Numbers
  @url https://atcoder.jp/contests/abc136/tasks/abc136_b
**/

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

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

int main() {
  int i;

  int N;
  cin >> N;

  int ans = 0;
  for (i = 1; i <= N; i++) {
    if ((to_string(i).size()) % 2 != 0) ans++;
  }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define cs const
#define pb push_back
#define ll long long 
#define pii pair<int,int>
#define fi first
#define se second
#define bg begin
cs int RLEN=(1<<20)|3;
inline char gc(){
	static char ibuf[RLEN],*ib,*ob;
	(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
	return (ib==ob)?EOF:*ib++;
}
inline int read(){
	char ch=gc();
	int res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;
}
inline ll readll(){
	char ch=gc();
	ll res=0;bool f=1;
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
	return f?res:-res;	
}
inline int readstring(char *s){
	char ch=gc();int l=0;
	while(isspace(ch))ch=gc();
	while(!isspace(ch)&&ch!=EOF)s[++l]=ch,ch=gc();
	return l;
}
inline char readchar(){
	char ch=gc();
	while(isspace(ch))ch=gc();return ch;
}
template<typename tp>inline void chemx(tp &a,tp b){a<b?a=b:0;}
template<typename tp>inline void chemn(tp &a,tp b){a<b?a=b:0;}
cs int mod=1e9+7;
inline int add(int a,int b){return (a+b>=mod)?(a+b-mod):(a+b);}
inline int dec(int a,int b){return (a<b)?(a-b+mod):(a-b);}
inline int mul(int a,int b){static ll r;r=(ll)a*b;return (r>=mod)?(r%mod):r;}
inline void Add(int &a,int b){a=(a+b>=mod)?(a+b-mod):(a+b);}
inline void Dec(int &a,int b){a=(a<b)?(a-b+mod):(a-b);}
inline void Mul(int &a,int b){static ll r;r=(ll)a*b;a=(r>=mod)?(r%mod):r;}
inline int ksm(int a,int b,int res=1){for(;b;b>>=1,Mul(a,a))(b&1)&&(Mul(res,a),1);return res;}
inline int Inv(int x){return ksm(x,mod-2);} 
cs int N=200005,iv2=Inv(2);
int n,a[N],cnt[N],pre[N],sm[N],is[N];
namespace bit{
	int tr1[N],tr2[N];
	#define lb(x) (x&(-x))
	void update(int p,int k){for(;p<=n;p+=lb(p))Add(tr1[p],k),tr2[p]++;}
	int query(int p,int res=0){for(;p>0;p-=lb(p))Add(res,tr1[p]);return res;}
	int query2(int p,int res=0){for(;p>0;p-=lb(p))Add(res,tr2[p]);return res;}
	void clear(){memset(tr1,0,sizeof(tr1)),memset(tr2,0,sizeof(tr2));}
	#undef lb
}
int main(){
	#ifdef Stargazer
	freopen("lx.in","r",stdin);
	#endif
	n=read();
	for(int i=1;i<=n;i++)a[i]=read(),cnt[a[i]]++;
	for(int i=n;i;i--)cnt[i]+=cnt[i+1];int all=1;
	for(int i=1;i<=n;i++)cnt[i]-=n-i,Mul(all,cnt[i]);
//	cout<<all<<'\n';
	sm[0]=1,pre[0]=1;
	for(int i=1;i<=n;i++){
		int vl=mul(cnt[i]-1,Inv(cnt[i]));
		if(!vl)pre[i]=i,sm[i]=sm[i-1];
		else pre[i]=pre[i-1],sm[i]=mul(sm[i-1],vl);
		is[i]=Inv(sm[i]);
	}int res=0;
	for(int i=1;i<=n;i++){
		Add(res,mul(sm[a[i]],mul(all,mul(iv2,dec(bit::query(a[i]),bit::query(pre[a[i]]-1))))));
		bit::update(a[i],is[a[i]]);
	}
	bit::clear();
	for(int i=n;i;i--){
		Dec(res,mul(sm[a[i]],mul(all,mul(iv2,dec(bit::query(a[i]-1),bit::query(pre[a[i]]-1))))));
		Add(res,mul(all,bit::query2(a[i]-1)));
		bit::update(a[i],is[a[i]]);
	}cout<<res<<'\n';return 0;
}

Measured memory_bytes: 6784
/* ex_9_2
   seira3 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define SIZE 100001

//リストのノード（スタック内の各データ）の定義
typedef struct node{
    char elem;
    struct node *next;
} node;

//プロトタイプ宣言 
void push(node **first, char elem);
char pop(node **first);

int main(void){
    //宣言
    char cube[SIZE], pre_cube; //入力を受け取る配列を一つ前の文字を格納する変数を宣言
    int i, count = 0, ans = 0; 
    node *first = NULL; //スタック

    scanf("%s",cube); //入力
    for(i=0;i<strlen(cube);i++){ //cubeの各要素を処理
        if(count==0){ //空ならpush
            push(&first,cube[i]);
            count++;
        }
        else{
            pre_cube = pop(&first);
            if(pre_cube == cube[i]){ //一個前と同じならばpush
                push(&first,pre_cube);
                push(&first,cube[i]);
                count++;
            }
            else{ //一個前と違うならばansに2を足す
                ans+=2;
                count--;
            }
        }
    }
    printf("%d\n",ans); //答えを出力
    return 0;
}
 
//スタックにデータを追加
void push(node **first, char elem){
    //追加する分の領域を確保
    node *new = calloc(1, sizeof(node));
    if(new == NULL) exit(1); //確保できなければ強制終了
    new->elem = elem;
    new->next = *first;
    *first = new;
}
 
//スタックからデータを取り出す
char pop(node **first){
    char elem;
    node *tmp = *first;
    if(tmp == NULL) exit(1); //空なら強制終了
    elem = tmp->elem;
    *first = tmp->next;
    //取り出したノードのメモリを解放
    free(tmp);
    return elem;
}

Measured memory_bytes: 4872
/* 実行時間1s制限の場合
  10^6 1,000,000   : 余裕をもって間に合う
  10^7 10,000,000  : おそらく間に合う
  10^8 100,000,000 : 非常にシンプルな処理でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}          // Least Commont Multiple オーバーフローしないように先に割る

const ll INF = LONG_MAX;
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; }

int main()
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    std::ifstream in("b.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    int n;
    cin >> n;

    struct st_t {
        int index;
        string name;
        int p;

        bool operator<(const st_t& another) const {
            if (name == another.name)
            {
                return p > another.p;
            }
            return name < another.name;
        }
    };

    vector<st_t> st(n);
    rep(i, n) {
        cin >> st[i].name >> st[i].p;
        st[i].index = i+1;
    }

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

    rep (i, n)
    {
        //cout << st[i].name << st[i].p << endl;
        cout << st[i].index << endl;
    }

    return 0;
}

/*
  - 1e9 : 10^9
  - vector
    vector<int> A(N);
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

void mainsolve(){

	ll n,m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> ss(n+1);
	rep(i,n) ss[i+1] = ss[i] + a[i];
	vector<ll> sitr(2*a[n-1]+1);
	rep(i,n) sitr[a[i]]++;
	rep(i,sitr.size()-1) sitr[i+1] += sitr[i];

	// x以上の幸福度を得られる握手がm通り以上あればtrue
	auto isOK = [&](ll x){
		ll cnt = 0;
		rep(i,n){
			// 左手は固定
			ll left = a[i];
			// ll j = lower_bound(a.begin(), a.end(), x-left) - a.begin();
			// cnt += n-j;
			cnt += n - sitr[max(0ll,x-left-1)];
		}
		return cnt >= m;
	};

	auto binsearch = [&](){
		ll ok = 2*a[0]-1;
		ll ng = 2*a[n-1]+1;
		ll mid = (ng+ok)/2;
		while(abs(ng-ok)>1){
			if(isOK(mid)) ok = mid;
			else ng = mid;
			mid = (ng+ok)/2;
		}
		return ok;
	};

	ll c = binsearch();
	ll res = 0;

	// c+1まではまとめて数える
	rep(i,n){
			// 左手は固定
			ll left = a[i];
			ll j = lower_bound(a.begin(), a.end(), c+1-left) - a.begin();
			if(j <= n-1){
				res += (n-j)*left;
				res += ss[n]-ss[j];
				m -= n-j;
			}
			
	}
	
	// 残りは全部c
	res += m*c;
	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)



int main (){
  int n;
  cin>>n;
  vector<int> a(9,0);
  int tmp;
  r(i,n){
    cin>>tmp;
    if(tmp<=399)a.at(0)++;
    else if(tmp>399 and tmp<800)a.at(1)++;
    else if(tmp>799 and tmp<1200)a.at(2)++;
    else if(tmp>1199 and tmp<1600)a.at(3)++;
    else if(tmp>1599 and tmp<2000)a.at(4)++;
    else if(tmp>1999 and tmp<2400)a.at(5)++;
    else if(tmp>2399 and tmp<2800)a.at(6)++;
    else if(tmp>2799 and tmp<3200)a.at(7)++;
    else a.at(8)++;
  }
  int cnt=0;
  r(i,8){
    if(a.at(i)!=0)cnt++;
    //cout<<cnt<<endl;
  }

  if(cnt==0)cout<<1<<" "<<a.at(8)<<endl;
  else if(a.at(8)!=0)cout<<cnt<<" "<<cnt+a.at(8)<<endl;
  else cout<<cnt<<" "<<cnt<<endl;

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for(ll &i:A)cin >> i;
    ll money=1000;
    ll beat=0;
    vector<bool> B(N);//BY(0),SE(0);
    for(ll i=0;i<N-1;i++){
        if((long double)A[i+1]/A[i]>1)B[i]=true;//BY.push_back(i);
        else B[i]=false;//SE.push_back(i);
        
    }
    for(ll i=0;i<N;i++){
        
        if(B[i]){
           /* while(money-A[i]>=0){
                beat++;
                money-=A[i];
            }*/
            beat+=money/A[i];
            money=money % A[i];
            
        }else{
            money+=beat*A[i];
            beat=0;
        }
        
    }
    
    cout << money << endl;
    
    
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const long long mod=1e9+7;
int i,i0,n,m,a[2005],b[2005];
long long dp[2005];
int main()
{
    scanf("%d %d",&n,&m);
    for(i=1;i<=n;i++)scanf("%d",&a[i]);
    for(i=1;i<=m;i++)
    {
        scanf("%d",&b[i]);
        long long sum=0;
        for(i0=1;i0<=n;i0++)
        {
            long long tmp=dp[i0];
            if(b[i]==a[i0])dp[i0]+=sum+1,dp[i0]%=mod;
            sum+=tmp,sum%=mod;
        }
    }
    long long ans=0;
    for(i=1;i<=n;i++)ans+=dp[i],ans%=mod;
    printf("%lld\n",ans+1);
    return 0;
}


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

int main()
{
    int n;
    cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;++i){
        cin>>v[i];
    }
    int avg = accumulate(v.begin(),v.end(),0)/v.size();
    int sum1=0;
    int sum2=0;
    for(int i=0;i<n;++i){
        sum1+=(v[i]-avg)*(v[i]-avg);
        sum2+=(v[i]-avg-1)*(v[i]-avg-1);
    }
    cout<<(sum1<sum2?sum1:sum2)<<endl;
}

Measured memory_bytes: 256
import sys
from math import factorial as f

input = sys.stdin.readline


def nCr(n, r):
    return f(n) // (f(n-r) * f(r))


def main():
    N, P = map(int, input().split())
    A = list(map(int, input().split()))

    r = [a % 2 for a in A]
    n_1 = sum(r)
    n_0 = N - n_1

    c_0 = 2**n_0
    if P == 0:
        c_1 = 0
        for i in range(0, n_1+1, 2):
            c_1 += nCr(n_1, i)
    elif P == 1:
        c_1 = 0
        for i in range(1, n_1+1, 2):
            c_1 += nCr(n_1, i)
    ans = c_0 * c_1
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
N, K = map(int, input().split())
A = list(map(int, input().split()))

S = []
for i in range(N):
    s = 0
    for a in A[i:]:
        s += a
        S.append(s)

def isOk(n):
    return sum([n & a == n for a in S]) >= K

ans = 0
for d in range(40)[:: -1]:
    if isOk(ans | (1 << d)):
        ans |= (1 << d)
print(ans)


Measured memory_bytes: 32744
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define endl "\n"
const int MAX= 100005 ;
const long long mod = 998244353;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,i;
    cin>>n;
    ll arr[n+1];
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    multiset<ll> ms;
    for(i=0;i<n;i++)
    {
        auto it= ms.lower_bound(arr[i]);
        if(it==ms.begin())
        {
            ms.insert(arr[i]);
        }
        else
        {
            it--;
            ms.erase(it);
            ms.insert(arr[i]);
        }
    }
    cout<<ms.size()<<endl;
    return 0;
}

Measured memory_bytes: 5760
n = input()
arr = []
for i in range(n):
    xi, yi, hi = map(int, raw_input().split())
    arr.append((xi, yi, hi))

for cx in range(101):
    for cy in range(101):
        for k in range(n):
            if arr[k][2] > 0:
                H = abs(arr[k][0]-cx)+abs(arr[k][1]-cy) + arr[k][2]
                break
        flag = 0
        for k in range(n):
            if arr[k][2] != max(H - abs(arr[k][0]-cx) - abs(arr[k][1]-cy), 0):
                flag = 1
                break
        if flag == 0:
            print cx, cy, H


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

int main(void) {
    
    int N,L,M,S; 
    cin>>N>>L;
    M=L;
    S=L;

    for(int i=1;i<N;i++){
        
        cin>>L;
        S=S+L;
        if(L>M){
            M=L;
        }
    }
        
    S=S-M;
    


    if(S>M){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }


return 0;
}


Measured memory_bytes: 256
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  
  int n;cin>>n;
  cout << (n-1)/2+1 << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (c <= b && c >= a)
		cout << "Yes" << "\n";
	else
		cout << "No" << "\n";
}

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

const int maxn = 100005;
typedef long long ll;
struct st{
    ll v, lazy;
}T[4*maxn];
ll A[maxn];

void lazy( int ini, int fin, int lv ){
    if( ini == fin )
        return;
    T[lv*2].lazy += T[lv].lazy;
    T[lv*2+1].lazy += T[lv].lazy;
    int mit = (ini+fin)/2;

    T[lv*2].v += T[lv].lazy * (mit-ini+1);
    T[lv*2+1].v += T[lv].lazy * (fin-mit);
    T[lv].lazy = 0;
}

void update( int ini, int fin, int lv, int a, int b, ll v ){
    if( ini > b || fin < a )return;
    if( T[lv].lazy )
        lazy(ini,fin,lv);
    if( ini >= a && fin <= b ){
        T[lv].v += (fin-ini+1)*v;
        T[lv].lazy = v;
        return;
    }
    int mit = (ini+fin)/2;
    update(ini,mit,lv*2,a,b,v);
    update(mit+1,fin,lv*2+1,a,b,v);
    T[lv].v = T[lv*2].v + T[lv*2+1].v;
}

ll query( int ini, int fin, int lv, int a, int b ){
    if( ini > b || fin < a )return 0;
    if( T[lv].lazy )
        lazy(ini,fin,lv);
    if( ini >= a && fin <= b )return T[lv].v;
    int mit = (ini+fin)/2;
    return query(ini,mit,lv*2,a,b) + query(mit+1,fin,lv*2+1,a,b);
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    #ifdef acm
    freopen("a.in","r",stdin);
    #endif // acm

    int N, Q;
    cin >> N >> Q;

    int q, a, b;
    ll x;
    while( Q-- ){
        cin >> q;
        if( q == 0 ){
            cin >> a >> b >> x;
            update(1, N, 1, a, b, x);
        }else{
            cin >> a >> b;
            cout << query(1, N, 1, a, b) << '\n';
        }
    }

    return 0;
}



Measured memory_bytes: 7264
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define ST first
#define ND second
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=1e6+7;

int ans=0;
int n,m,k,q;
int l,r;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>l>>r>>n;
    FORE(i,l,r){
        if(i%n==0)++ans;
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;

#define rep(i, a, b) for(int i=a; i<=b; i++)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) x.size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MOD = 998244353;

int n, k, l, r;
vector<pii> vec;
ll dp[200001];


struct segtree{
  int size;
  vector<ll> sums;

  void init(int n){
    size=1;
    while(size<n) size*=2;
    sums.assign(2*size, 0LL);
  }

  void build(vector<ll> &a, int x, int lx, int rx){
    if(rx-lx==1){
      if(lx<(int)a.size()) sums[x]=a[lx];
      return;
    }
    int m=(lx+rx)/2;
    build(a, 2*x+1, lx, m);
    build(a, 2*x+2, m, rx);
    sums[x]=sums[2*x+1]+sums[2*x+2];
  }

  void build(vector<ll> &a){
    build(a, 0, 0, size);
  }

  void set(int i, int v, int x, int lx, int rx){
    if(rx-lx==1){
      sums[x]=v; return;
    }
    int m=(lx+rx)/2;
    if(i<m){
      set(i, v, 2*x+1, lx, m);
    }
    else {
      set(i, v, 2*x+2, m, rx);
    }
    sums[x]=sums[2*x+1]+sums[2*x+2];
  }

  void set(int i, int v){
    set(i, v, 0, 0, size);
  }

  ll sum(int l, int r, int x, int lx, int rx){
    if(lx>=l && rx<=r) return sums[x];
    if(lx>=r || rx<=l) return 0;
    int m=(lx+rx)/2;
    ll s1=sum(l, r, 2*x+1, lx, m);
    ll s2=sum(l, r, 2*x+2, m, rx);
    return s1+s2;
  }

  ll sum(int l, int r){
    return sum(l, r, 0, 0, size);
  }
};

int main(){
  // freopen("input.txt", "r", stdin); 
  // freopen("output.txt", "w", stdout);
  cin.sync_with_stdio(0); cin.tie();
  cin.exceptions(cin.failbit);

  ll n, k, l, r;
  cin >> n >> k;
  vector<ll> dp(n+1);
  dp[n]=1;
  segtree st;
  st.init(n+1);
  st.build(dp);

  rep(i, 1, k){
    cin >> l >> r;
    vec.pb({l, r});
  }

  for(int i=n-1; i>=1; i--){
    ll ans=0;
    trav(s, vec){
      if(i+s.first<=n){
        ans=(ans+st.sum(i+s.first, min(n+1, (ll)i+s.second+1))%MOD)%MOD;
      }
    }
    ans%=MOD;
    dp[i]=ans;
    st.set(i, ans);
  }


  cout << dp[1];
}

Measured memory_bytes: 9052
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;

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

    int hour = A + B;

    if(hour >= 24)
    {
        hour -= 24;
    }

    cout << hour << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    rep(i,n){
        if(a[i] % 2 == 0){
            if(a[i] % 3 == 0 || a[i] % 5 == 0){

            }
            else{
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
    
    return 0;
}


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

using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    int num[n];
    for (int i = 0; i < n; ++i) {
        cin >> num[i];
    }
    for (int i = 1; i <= m; ++i) {
        int now = 0;
        while (now < n - 1) {
            if (num[now] % i > num[now + 1] % i) {
                swap(num[now], num[now + 1]);
            }
            ++now;
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << num[i] << '\n';
    }
}


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

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, pair<T1, T2> P)
{
    return s << '<' << P.first << ", " << P.second << '>';
}
template <class T>
ostream &operator<<(ostream &s, vector<T> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        if (i > 0)
        {
            s << " ";
        }
        s << P[i];
    }
    return s;
}
template <class T>
ostream &operator<<(ostream &s, vector<vector<T>> P)
{
    for (int i = 0; i < P.size(); ++i)
    {
        s << endl
          << P[i];
    }
    return s << endl;
}
template <class T>
ostream &operator<<(ostream &s, set<T> P)
{
    EACH(it, P) { s << "<" << *it << "> "; }
    return s << endl;
}
template <class T1, class T2>
ostream &operator<<(ostream &s, map<T1, T2> P)
{
    EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; }
    return s << endl;
}
typedef long long ll;

long long dp[1010][1010];
char grid[1010][1010];
int main()
{
    int mod = 1e9 + 7;
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> grid[i][j];
        }
    }
    dp[0][0] = 1;
    bool flag1 = true;
    for (int i = 0; i < w; i++)
    {   if(grid[0][i]=='.' && flag1==true)
            dp[0][i] = 1;
        else{
            dp[0][i] = 0;
            flag1 = false;

        }
    }
    bool flag2 = true;
    for (int i = 0; i < h; i++)
    {
        if (grid[i][0] == '.' && flag2 == true)
            dp[i][0] = 1;
        else
        {
            dp[i][0] = 0;
            flag2 = false;
        }
    }

    for (int i = 0; i < h-1; i++)
    {
        for (int j = 0; j < w-1; j++)
        {
            if(grid[i+1][j+1]=='.'){
            dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1];
            dp[i + 1][j + 1] %= mod;
            }
            else dp[i + 1][j + 1] = 0;
        }
        
    }
   /*  for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << dp[i][j] << endl;
            ;
        }
    }*/

    cout << dp[h - 1][w - 1]%mod << endl;
    
    
    


    return 0;
}

Measured memory_bytes: 9088
import java.util.Scanner;


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

        int n = in.nextInt();
        int l = in.nextInt();
        int[] a = new int[n];
        int index = -1;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
        }

        for (int i = 0; i < n-1; i++) {
            if(a[i]+a[i+1]>=l){
                index = i+1;
                break;
            } 
        }

        if(index == -1){
            System.out.println("Impossible");
        }else{
          	System.out.println("Possible");
            for (int i = 1; i < index; i++) {
                System.out.println(i);
            }
            for(int i = n-1; i >= index; i--){
                System.out.println(i);
            }
        }
    }
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    vll a(n);
    rep(i,n) cin>>a[i];
    sort(rall(a));
    ll maxi = -1, ans;
    FOR(i,1,n-1){
        ll c = min(a[0]-a[i],a[i]);
        if (maxi<c){
            maxi = c;
            ans = i;
        }
    }
    cout<<a[0]<<" "<<a[ans]<<endl;
    return 0;
}


Measured memory_bytes: 1024
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, k, a[MAXN], b[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m >> k;
    FOR(i,1,n) cin >> a[i];
    FOR(i,1,m) cin >> b[i];
    int res = 0;
    int vt = 0;
    ll cntB = 0;
    FOR(i,1,m) {
        if (cntB + b[i] <= k) {
            cntB += b[i];
            vt = i;
        } else break;
    }
    res = vt;
    ll cntA = 0;
    FOR(i,1,n) {
        cntA += a[i];
        if (cntA > k) break;
        while (cntA + cntB > k) {
            cntB -= b[vt];
            vt--;
        }
        res = max(res, i + vt);
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 5220
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N;
    cin >> N;
    int C;
    cin >> C;
    vector<vector<int> > televi(100002, vector<int>(C + 1));
    rep(i,100002){
        rep(j,C + 1){
            televi[i][j] = 0;
        }
    }
    rep(i,N){
        int s,t,c;
        cin >> s >> t >> c;
        televi[s][c]++;
        televi[t + 1][c]--;
    }
    rep(i,100001){
        rep(j,C + 1){
            televi[i + 1][j] += televi[i][j];
        }
    }
    vector<int> sametime(100002, 0);
    rep(i,100002){
        rep(j,C + 1){
            if (televi[i][j] >= 1) sametime[i]++;
        }
    }
    int ans = 0;
    rep(i,100002){
        ans = max(ans, sametime[i]);
    }
    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define nl '\n'
#define pi 2.0*acos(0.0)
#define mod 1e9+7
#define FOR(i,j,n)    for(ll i=j;i<n;i++)
#define RFOR(i,j,n)    for(ll i=j;i>=n;i--)
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;

int main(){
    ll n,ans = 0;
    scanf("%lld", &n);
    FOR(i,1,n+1){
        if(i % 3 == 0 || i % 5 == 0) continue;
        else ans += i;
    }
    cout<< ans <<nl;
}


Measured memory_bytes: 3716
#include <cstdio>
#include<stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;


//h配列の要素を順番に出力
void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
        if(i>0) printf(" ");
        cout << A[i];
    }
    printf("\n");
}

//挿入ソート
void insertion_sort(int array[],int N){

    for(int i=1; i<N ;i++){
        
        int key=array[i];
        int j=i-1;

        while(j>=0 && array[j]>key){
            array[j+1]=array[j];
            j--;
        }

        array[j+1]=key;
        trace(array,N);
    }    
}


int main(){
    int N;
    int A[100];

    cin >> N;

    for(int i=0 ; i<N ; i++) cin >> A[i];

    trace(A,N);
    insertion_sort(A,N);

    return 0;
}


Measured memory_bytes: 3108
#include<iostream>//ACRush代码 http://agc018.contest.atcoder.jp/submissions/1445316
#include<cmath>//题源 http://agc018.contest.atcoder.jp/tasks/agc018_b
#include<string.h>
using namespace std;//本题贪心，多个数组标示法
template<class T>inline bool ckmin(T&a, T b) { return b < a ? (a = b, 1) : 0; }
template<class T>inline bool ckmax(T&a, T b) { return b > a ? (a = b, 1) : 0; }
int n, m;
int a[350][350], head[350];
bool cksp[350]; //check第i项运动是否已去除
int main()
{
	int i,j;
	while (cin >> n >> m&&n&&m) {
		for (i = 1; i <= n; i++)for (j = 1; j <= m; j++)cin >> a[i][j];
		int ret = 1000000000;//全部判断中第ret项运动人数最多
		//memset(cksp, true, sizeof(cksp));
		for (i = 1; i <=m; i++)cksp[i] = true;
		//memset(head, 1, sizeof(head));//memset()设置int型时只能设成0and-1，设成1就会错，他本来就是用来设char【】的
		for (i = 1; i <= n; i++)head[i] = 1;
		while (1) {
			int spn[350]; //代表当前第i项运动喜欢的人数
			//memset(spn, 0, sizeof(spn));
			for (i = 1; i <=m; i++)spn[i] = 0;
			for (i = 1; i <= n; i++)++spn[a[i][head[i]]];
			int num = 1;//本次第num项运动人数最多
			for(i=1;i<=m;i++)if (spn[i] > spn[num])num = i;
			ckmin(ret, spn[num]);
			cksp[num] = false;
			bool ok = true;
			for (i = 1; i <= n; i++) {
				for (; head[i] <= m && !cksp[a[i][head[i]]]; head[i]++);
				if(head[i] > m) ok = false;
			}
			if (!ok)break;
		}
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
main()
{
    vector <int> P(101,0);
    vector <int> X(101,0);
    int N,M,T[101],sum=0,t,x;
   cin>>N;
   for(int i=1;i<=N;i++)
   {
       cin>>T[i];
       sum+=T[i];
   }
   cin>>M;
   int tmp=sum;
   for(int i=1;i<=M;i++)
   {
       cin>>t>>x;
       X[i]=t;
       P[t]=x;
       sum-=(T[X[i]]-P[X[i]]);
       cout<<sum<<endl;
       sum=tmp;
   }


}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

bool dp[81][81][25600];

void solve() {
  int h, w;
  cin >> h >> w;
  vector<vi32> a(h, vi32(w));
  vector<vi32> b(h, vi32(w));
  cin >> a >> b;
  dp[0][0][12800 + (a[0][0] - b[0][0])] = true;
  dp[0][0][12800 + (b[0][0] - a[0][0])] = true;
  rep(i, h) rep(j, w) repc(k, 25600) {
    if (!dp[i][j][k]) continue;
    if (i < h - 1) {
      dp[i+1][j][k + (a[i+1][j] - b[i+1][j])] = true;
      dp[i+1][j][k - (a[i+1][j] - b[i+1][j])] = true;
    }
    if (j < w - 1) {
      dp[i][j+1][k + (a[i][j+1] - b[i][j+1])] = true;
      dp[i][j+1][k - (a[i][j+1] - b[i][j+1])] = true;
    }
  }
  int ans = 1e9;
  repc(k, 25600) if(dp[h-1][w-1][k]) {
    amin(ans, abs(k - 12800));
  }
  cout << ans << endl;
}


Measured memory_bytes: 162944