akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}
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;
}

signed main() {
    INIT;
    cin >> X;
    int n = 0;
    while (n * (n + 1) / 2 < X) {
        n++;
    }
    cout << n << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    ll N;
    cin >> N;
    ll ans = (N * (N - 1)) / 2;
    cout << ans << endl;
    return 0;
}

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

ll dp[1000000];
long long N=0,W=0,V=0,wi[1000000],vi[1000000];

int main(){

	cin >> N >> W;
	for(int i = 1;i<=N;i++){
		cin >> wi[i] >> vi[i];
		V += vi[i];
	}

	for(int i = 1;i<=V;i++){
		dp[i] = INT_MAX;
	}
	dp[0] = 0;
	
	for(int item = 1;item<=N;item++){
		int w = wi[item], v = vi[item];
		for(int i = V;i>=v;i--){
			dp[i] = min(dp[i],dp[i - v] + w);
		}
	}

	for(int i = V;i>=0;i--){
		if(dp[i] <= W){
			cout << i << endl;
			break;
		}
	}

	return 0;

}

Measured memory_bytes: 6400
#include<iostream>
#include<vector>
#include<algorithm>
#include <tuple>
#include <utility>
#include<string>
#include <cmath>
#define ll long long
using namespace std;

vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}

int main(){
    ll X,B,tmp;
    cin >> X;
    vector<ll> C = divisor(X);
    for(ll A = 0; A< X; A++){
        for(ll i = 0; i < C.size(); i++){
            B = A - C[i];
            tmp = pow(A,5) -pow(B,5);
            if(tmp == X){
                cout << A <<" "<< B << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4216
#include<iostream>
#include<vector>
#include<algorithm>
#include<unordered_set>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<string>
#include<cmath>
#include<climits>
using namespace std;

int main() {
    int n;
    cin>>n;
    vector<double> p(n);
    for(int i=0;i<n;i++)    cin>>p[i];
    vector<vector<double>> dp(n+1, vector<double> (n+1,0));
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++) {
        for(int j=0;j<=i;j++) {
            if(j==0) 
                dp[i][j] = dp[i-1][j]*(1-p[i-1]);
            else 
                dp[i][j] = dp[i-1][j]*(1-p[i-1]) + dp[i-1][j-1]*p[i-1];
        }
    }
    double res=0.0;
    for(int i=n/2+1;i<=n;i++)    
        res += dp[n][i];
    printf("%0.10lf",res);
}


Measured memory_bytes: 73748
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;

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

	int N; cin >> N;

	if (N % 2 == 0) {
		cout << N << endl;
	}else {
		cout << 2 * N << endl;	
	}
	return 0;
}


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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int n;
long long s[N];
long long b[N];
long long a[N];

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        cin >> n;
        for(int i = 0; i <= n; i++){
                cin >> b[i];
        }
        for(int i = n; i >= 0; i--){
                s[i] = s[i + 1] + b[i];
        }
        a[0] = 1;
        long long res = 0;
        for(int i = 0; i <= n; i++){
                a[i] = min(a[i], s[i]);
                if(b[i] > a[i]){
                        cout << -1 << "\n";
                        return 0;
                }
                a[i + 1] = (a[i] - b[i]) * 2;
                res += a[i];
        }
        cout << res << "\n";
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  if(M == 0)
  {
    if(N == 3)
      cout << 100 << endl;
    else
      cout << 10 * (N - 1) << endl;
    return 0;
  }
  string ans(N, '0');
  vector<bool> changed(N, false);
  int s, c;
  for(int i = 0; i < M; i++)
  {
    cin >> s >> c;
    s = s - 1;
    if(changed.at(s) && (int(ans.at(s) - '0') != c))
    {
      cout << -1 << endl;
      return 0;
    }
    else if(!changed.at(s))
    {
      ans.at(s) = char('0' + c); 
      changed.at(s) = true;
    }
  }
  if(N > 1)
  { 
    if(!changed.at(0))
      ans.at(0) = '1';
    else if(ans.at(0) == '0')
    {
      cout << -1 << endl;
      return 0;
    }
  }
  int res = 0;
  for(int i = 0; i < N; i++)
    res = res * 10 + int(ans.at(i) - '0');
  cout << res << endl;
}


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

int main(){
  long a,b,c,d;
  cin >> a >> b >> c >>d;
  long ans = max(a*c,max(a*d,max(b*c,b*d)));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <time.h>
#include <string>
#include <iomanip>

using namespace std;

int main(){
  int a,b;
  double d;
  cin>>a>>b;
  d = double(a)/b;
  cout<<fixed<<setprecision(10)<<d<<endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
x = [int(i) for i in input().split()]
 
 
import statistics
a = statistics.median(sorted(x)[0:len(x)-1])
b = statistics.median(sorted(x)[1:len(x)])
for i in x:
    if i > a:
        print(a)
    else:
        print(b)

Measured memory_bytes: 26772
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll x,n;
  cin >> x >> n;
  ll p[n];
  for(int i=0;i<n;i++){
    cin >> p[i];
  }

  ll q;

  for(ll i=0;i<105;i++){
    q=0;
    for(int j=0;j<n;j++){
      if(x-i==p[j]){
        q++;
      }
    }
    if(q==0){
      cout << x-i << endl;
      break;
    }
    q=0;
    for(int j=0;j<n;j++){  
      if(x+i==p[j]){
        q++;
      }
    }
    if(q==0){
      cout << x+i << endl;
      break;
    }
  }

}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
inline long long mod(long long n,long long m){return(n%m+m)%m;}
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int n;
long long a[3010];
// dp[l][r]:=[l,r]が残っているときのx-y
long long dp[3010][3010];
long long dfs(int l,int r,int who){
    // cout<<l<<" "<<r<<" "<<who<<endl;
    if(dp[l][r]!=LINF) return dp[l][r];
    if(l==r){
        if(who==0) dp[l][r]=a[l];
        else dp[l][r]=-a[l];
        return dp[l][r];
    }
    long long ret;
    if(who==0){
        ret=-LINF;
        ret=max(ret,dfs(l+1,r,(who+1)%2)+a[l]);
        ret=max(ret,dfs(l,r-1,(who+1)%2)+a[r]);
    }else{
        ret=LINF;
        ret=min(ret,dfs(l+1,r,(who+1)%2)-a[l]);
        ret=min(ret,dfs(l,r-1,(who+1)%2)-a[r]);
    }
    dp[l][r]=ret;
    return ret;
}
int main(){
    cin>>n;
    rep(i,n) cin>>a[i];
    rep(i,3010)rep(j,3010) dp[i][j]=LINF;
    cout<<dfs(0,n-1,0)<<endl;
    // rep(i,n) cout<<dp[i][i]<<endl;
    return 0;
}


Measured memory_bytes: 71296
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9+7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
unsigned day;
if(dow < dow1) dow += 7;
day = dow - dow1;
day += 7 * n - 6;
return day;
}
unsigned DayToWeekNumber(unsigned day)
{
  return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
  return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main(){
  int N; cin>>N;
  vector<int>A(N);
  rep(i,N){
    cin>>A[i];
    if(A[i]%2==0){
      if(A[i]%3!=0&&A[i]%5!=0){
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }
  cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 3624
def rev (s):
    _re=''.join(list(reversed(s)))
    return _re

name = ['dream','dreamer','eraser','erase']
S = input()
S_re = rev(S)
i=0
can = True
while i < len(S_re):
    for div in name:
        can2 = False
        if len(S_re[i:]) >= len(div):
           if S_re[i:i+len(div)]==rev(div) :
                i+=len(div)
                can2 = True
                break
    if not can2 :
        can = False
        break


if can :
    print('YES')
else :
    print('NO')



Measured memory_bytes: 4084
import sys
def line():return sys.stdin.readline().strip()

S = line()
L = list(S)
ans = 0
for i in range(1 << (len(S) - 1)):
    A = ""    
    for j in range(len(S)):
        A+=L[j]
        if i & (1 << j):
            A+="+"
    ans+=eval(A)
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n = sc.nextInt();
		int[] p=new int[n];
		for(int i = 0; i<n; i++){
			p[i]=sc.nextInt()-1;
		}
		int ans=0;
		for(int i = 0; i<n-1; i++){
			if(p[i]==i){
				p[i+1]=p[i];
				ans++;
			}
		}
		if(p[n-1]==n-1){
			ans++;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 49584
def read_values():
    return map(int, input().split())


def read_list():
    return list(read_values())


def main():
    H, W = read_values()
    S = [input() for _ in range(H)]
    X = [[0 for _ in range(W)] for __ in range(H)]
    Y = [[0 for _ in range(W)] for __ in range(H)]

    for h in range(H):
        for w in range(W):
            if S[h][w] == ".":
                X[h][w] = 1 if w == 0 else X[h][w - 1] + 1
                Y[h][w] = 1 if h == 0 else Y[h - 1][w] + 1

    res = 0
    for h in range(H - 1, -1, -1):
        for w in range(W - 1, -1, -1):
            if S[h][w] == "#":
                continue
            if w != W - 1:
                X[h][w] = max(X[h][w + 1], X[h][w]) 
            if h != H - 1:
                Y[h][w] = max(Y[h + 1][w], Y[h][w])
            res = max(res, X[h][w] + Y[h][w] - 1)
    print(res)

        
if __name__ == "__main__":
    main()



Measured memory_bytes: 128728
#include <iostream>

using namespace std;

int str_size;
char str[100 + 1];

//種類数
int count(int y_start_index)
{
	int flag_x['z' + 1] = { 0 };
	int flag_y['z' + 1] = { 0 };

	for ( int i = 0; i < str_size; i++ )
	{
		if ( i < y_start_index )
		{
			flag_x[str[i]] = 1;
		}
		else
		{
			flag_y[str[i]] = 1;
		}
	}

	int ret = 0;

	for ( int i = (int)'a'; i <= (int)'z'; i++ )
	{
		if ( flag_x[i] && flag_y[i] )
		{
			ret++;
		}
	}

	return ret;
}

int main()
{
	cin >> str_size >> str;

	int ans = 0;

	for ( int i = 1; i < str_size - 1; i++ )
	{
		int c = count(i);
		if ( c > ans ) ans = c;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int buf, city[4];
	REP(i,4){
		city[i]=0;
	}
	REP(i,6){
		cin >> buf;
		city[buf-1]++;
	}
	int o1=0,o2=0;
	REP(i,4){
		if(city[i]==1){
			o1++;
		}
		if(city[i]==2){
			o2++;
		}
	}

	if(o1==2 && o2 == 2){
		println("YES");
	}else{
		println("NO");
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    final static long mod = 1000000007;
    //
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        boolean[][] connection = new boolean[m][10];
        for(int i = 0; i < m; i++){
            int k = sc.nextInt();
            for(int j = 0; j < k; j++){
                connection[i][sc.nextInt() - 1] = true;
            }
        }
        int[] nums = new int[m];
        for(int i = 0; i < m; i++) nums[i] = sc.nextInt();
        int cnt = 0;
        for(int i = 0; i < (1 << n); i++){
            int on = 0;
            boolean[] swi = new boolean[10];
            for(int j = 0; j < 10; j++){
                if((i >> j & 1) == 1){
                    swi[j] = true;
                }
            }
            for(int j = 0; j < m; j++){
                int on_cnt = 0;
                for(int k = 0; k < 10; k++){
                    if(swi[k] && connection[j][k]) on_cnt++;
                }
                if(on_cnt % 2 == nums[j]) on++;
            }
            if(on == m) cnt++;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 23892
#include<stdio.h>
main(){
  int C[3];
  int A[10]={1,2,3,4,5,6,7,8,9,10};
  int sum,i;

  while(scanf("%d %d %d",&C[0],&C[1],&C[2])!=EOF){

    sum=0;
    
    for(i=0;i<10;i++){
      if( !(C[0]==A[i] || C[1]==A[i] || C[2]==A[i]) ){
	if(C[0]+C[1]+A[i]<=20){
	  sum++;
	}
      }
    }
    
    
    if(sum>3){
      puts("YES");
    }
    else puts("NO");
    
  }
  
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int mod = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct Edge{
    ll to, weight;
    Edge(ll t, ll w) : to(t), weight(w){}
};
using graph = vector<vector<ll>>;
using Graph = vector<vector<Edge>>;


ll gcd(ll a,ll b){
    if(b == 0){
        return a;
    }else{
        return gcd(b, a%b);
    }
}

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s, t;
    cin>>s>>t;
    string ans = "Yes";
    vector<ll> a(26, INF), b(26, INF);
    for(ll i=0;i<s.size();++i){
        if(a[s[i]-'a'] == INF and b[t[i]-'a'] == INF){
            a[s[i]-'a'] = t[i]-'a';
            b[t[i]-'a'] = s[i]-'a';
        }else{
            if(a[s[i]-'a'] != t[i]-'a' or b[t[i]-'a'] != s[i]-'a'){
                ans = "No";
                break;
            }
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 776
// E - Simple String Queries
// Segment Tree version
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using vi = vector<int>;

// Segment Tree (sum)
template<class T> struct SegmentTree{//(0_origin)
private:
	#define LEFT(i) (2*(i)+1)
	#define RIGHT(i) (2*(i)+2)
	int n;//最下段データ数
	T node;//セグ木
	int calc_func(int left, int right){return left + right;}//sum
	int bottom_up(int i){return calc_func(node[LEFT(i)], node[RIGHT(i)]);}
public:
	SegmentTree(const T &v){// 配列 v をセグ木にする
		int size = v.size();
		for(n=1; n<size; n<<=1);//最下段データ数
		node.resize(2*n-1, 0);//セグ木領域確保
		for(int i=0; i<size; ++i) node[n-1 + i] = v[i];//最下段設定
		for(int i=n-2; i>=0; --i) node[i] = bottom_up(i);
	}
	void update(int i, int val){
		i += n-1;//最下段のindex
		if(node[i] == val) return;
		node[i] = val;//最下段更新
		while(i){i = (i-1)/2; node[i] = bottom_up(i);}
	}
	int calc(int a, int b, int k=0, int l=0, int r=-1){// calc[a,b), k:self index, segT[l,r)
		if(r<0) r = n;//first time [l,r)=[0,n)
		if(r<=a || b<=l) return 0;//unmatch: !(l<b & a<r)
		if(a<=l && r<=b) return node[k];//match: calc[l,r)
		return calc_func(calc(a, b, LEFT(k), l, (l+r)/2), calc(a, b, RIGHT(k), (l+r)/2, r));//calc_func(left,right)
	}
};

using SEGT = SegmentTree<vi>;
using VSEG = vector<SEGT>;

int main(){
	int N,Q; string S; cin>>N>>S>>Q;

	VSEG segT;
	rep(i,26){
		vi a(N); rep(j,N) if(S[j] == i+'a') a[j] = 1;
		segT.push_back(SEGT(a));
	}

	while(Q--){
		int t; cin>>t;
		if(t-1){//type2 out
			int l,r; cin>>l>>r; --l;
			int ans = 0;
			rep(i,26) if(segT[i].calc(l, r)) ans++;//[l,r)
			printf("%d\n",ans);
		}
		else{//type1 update
			int i; cin>>i; --i;
			segT[S[i]-'a'].update(i, 0);//del
			cin>>S[i];
			segT[S[i]-'a'].update(i, 1);//add
		}
	}
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll
#define INF 100000000

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

bool isprime[55556];

signed main() {
	ll n;
  cin >> n;
  rep(i, 55556) isprime[i] = true;
  isprime[0] = isprime[1] = false;
  for(int i = 2; i < sqrt(55556); i++) {
    if(isprime[i]) {
      ll j = i + i;
      while(j <= 55555) {
        isprime[j] = false;
        j += i;
      }
    }
  }
  vector<int> v[5];
  rep(i, 55556) if (isprime[i]) v[i % 5].pb(i);
  rep(i, n) {
    if (i) cout << " ";
    cout << v[1][i];
  }
  cout << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>

using namespace std;

int main(void){
	int n,i;
	vector<int> intv;

	while(cin >> n){
		intv.push_back(n);
		if(intv.size() == 5) break;
	}

	//cout << "input ended" << endl;

	sort(intv.begin(), intv.end());
	
	/*
	for(i=intv.size();i>1;i--){
		cout << intv[i-1] << " ";
	}

	cout << intv[0] << endl;
	*/
	
	vector<int>::iterator it = intv.end() - 1;
	while(it != intv.begin()){
		cout << *it << " ";
		--it;
	}

	cout << *it << endl;

	return 0;
}

Measured memory_bytes: 576
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
using namespace std;



int main(){
  long long N, K;
  vector<int> a(100000), b(100000);
  vector<pair<long long, long long>> arr(100001);
  cin >> N >> K;

  for(long long i=0; i < N; i++){
    cin >> arr[i].first >> arr[i].second;
  }
  auto it = arr.begin();
  for(long long  i = 0; i < N; i++)
    ++it;
  sort(arr.begin(), it);

  bool flag = true;
  long long  sum=0;
  for(long long  i = 0; flag; i++){
    sum+=arr[i].second;
    if(sum >= K){
      cout << arr[i].first <<endl;
      flag = false;
    }
  }

  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char> > a(h,vector<char>(w));
  rep(i,h) rep(j,w) cin >> a[i][j];
  vector<int> r,c;
  rep(i,h){
    bool flag = true;
    rep(j,w) flag &= a[i][j] == '.';
    if(flag) r.push_back(i);
  }
  rep(j,w){
    bool flag = true;
    rep(i,h) flag &= a[i][j] == '.';
    if(flag) c.push_back(j);
  }
  rep(i,h){
    bool fa = false;
    for(buf:r) if(buf == i) fa = true;
    if(fa) continue;
    rep(j,w){
      bool fb = false;
      for(buf:c) if(buf == j) fb = true;
      if(fb) continue;
      cout << a[i][j];
    }
    cout << endl;
  }
}



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

using namespace std;

const long long int MOD = 1e9 + 7;
long long int mypow(long long int x,long long int n)
{
	long long int res = 1;
	while(n > 0)
	{
		if(n%2==1)
		{
			res = ((res%MOD) * (x%MOD)%MOD);
			res%=MOD;
		}
		x = ((x%MOD)*(x%MOD)%MOD);
		x%=MOD;
		n/=2;
	}
	return res;
}
long long int dp[100001];

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

	int n,k;

	cin >> n;
	k = 3;
	
	long long int res = 0;
	
	for(int i=n;i>=1;i--)
	{
		dp[i] = mypow(n/i,k);
		for(int j=2*i;j<=n;j+=i)
		{
			dp[i] -= dp[j];
			if(dp[i] < 0)
			{
				dp[i] += MOD;
			}
		}
		res = ((res%MOD) + ((i%MOD)*(dp[i]%MOD)%MOD)%MOD);
		res%=MOD;
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, x;
    int ans = 1;
    int now = 0;
    cin >> n >> x;
    int a[n];
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        if(now + a[i] > x)
            break;
        else {
            now += a[i];
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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



int main(){
  int x;
  cin >> x;
  int n = 100005;
  
  vector<bool> a(n);
  rep(i,n) a[i] = 1;

    rep(i,n){
      if(i == 0 || i == 1) continue;
      for(int j = i*2; j < n; j += i) {
      if(i < 4) continue;
      a[j] = 0;
    }
  }
  
  rep(i,n){
    if(i < x) continue;
    if(a[i] == 1){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3644
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>
#include <queue>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;


int main() {
	vector<vector<pair<int, int>>> adjlist(100000, vector < pair<int, int>>());
	int N, a, b, c, i;
	cin >> N>>a;
	if (N >= 13)
		cout << a << endl;
	else if (N <= 5)
		cout << 0 << endl;
	else
	cout << a/2<< endl;
	return 0;

}



Measured memory_bytes: 3068
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

vector<int> G[100010];
int a[100010], ans[100010];
P b[100010];

int dfs(int u, int prev){
	if(G[u].size() == 1 && prev != -1)return 1;
	int res = 1;
	rep(i,G[u].size()){
		int to = G[u][i];
		if(to == prev)continue;
		chmin(res, dfs(to, u));
		
		if(b[to].se == inf)continue;
		int l = b[to].fi-1, r = b[to].se+1;
		b[u] = P(max(b[u].fi, l), min(b[u].se, r));
		if(b[u].fi > b[u].se || (r-b[u].se)%2)return 0;
	}
	return res;
}

void dfs2(int u, int prev){
	if(u != 1){
		int m = ans[prev];
		if(b[u].fi <= m-1 && m-1 <= b[u].se)ans[u] = m-1;
		if(b[u].fi <= m+1 && m+1 <= b[u].se)ans[u] = m+1;
		if(G[u].size() == 1)return;
	}
	rep(i,G[u].size())if(G[u][i] != prev)dfs2(G[u][i], u);
	return;
}

signed main(){
	int n, k;
	fill(a, a+100010, -1);
	fill(b, b+100010, P(-inf, inf));
	scanf("%lld", &n);
	rep(i,n-1){
		int x, y;
		scanf("%lld%lld", &x, &y);
		G[x].pb(y);G[y].pb(x);
	}
	scanf("%lld", &k);
	rep(i,k){
		int x, y;
		scanf("%lld%lld", &x, &y);
		a[x] = y;b[x] = P(y, y);
	}
	
	int f = dfs(1, -1);
	if(f == 0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	if(b[1].fi != -inf)ans[1] = b[1].fi;
	dfs2(1, -1);
	//rrep(i,n)printf("%lld %lld\n", b[i].fi, b[i].se);
	rrep(i,n)printf("%lld\n", ans[i]);
	return 0;
}




Measured memory_bytes: 17280
N,K=gets.split.map &:to_i
p=gets.split.map{|i|(i.to_f+1)/2.0}
a=[0]
N.times do |i|
  a[i+1]=a[i]+p[i]
end
s=0
0.upto(N-K) do |i|
  r=a[i+K]-a[i]
  s=r if s<r
end
puts s

Measured memory_bytes: 16588
#include <iostream>
#include <vector>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int gcd(int a, int b) {
    int r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}

signed main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    int c = B / C - (A - 1) / C;
    int d = B / D - (A - 1) / D;
    int cd = B / (C * D / gcd(C, D)) - (A - 1) / (C * D / gcd(C, D));
    cout << B - A + 1 - (c + d - cd) << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

    ll N; cin >> N;
    ll a[200005];
    for (int i = 1;i <= N;i++){
        cin >> a[i];
    }

    ll ans[200005];
    memset(ans,-1,N+1);
    ll tmp = 0;

    for (int i = N;i >= 1;i--){
        ll sum = 0;
        for (int j = i*2;j <= N;j += i){
            sum += ans[j];
        }
        if(sum%2 != a[i]){ ans[i] = 1; tmp++;}
        else ans[i] = 0;
    }

    cout << tmp << endl;
    for (int i = 1;i <= N;i++){
        if(ans[i]) cout << i << " ";
    }
    cout << endl;

    return 0;

}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int n,m;
struct Query {
    int l,r,d;
    Query(int l,int r,int d):l(l),r(r),d(d){}
};
vector<pair<int,int> > adj[100001];
vector<Query> q;
int x[100001];
bool check[100001];
void dfs(int cur){
    check[cur] = true;
    for(int i=0;i<adj[cur].size();i++){
        int nxt = adj[cur][i].first;
        int v = adj[cur][i].second;
        if(!check[nxt]){
            x[nxt] = x[cur]+v;
            dfs(nxt);
        }
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n >> m;
    for(int i=0;i<m;i++){
        int l,r,d;
        cin >> l >> r >> d;
        q.push_back(Query(l,r,d));
        adj[l].push_back(make_pair(r,d));
        adj[r].push_back(make_pair(l,-d));
    }
    for(int i=1;i<=n;i++){
        if(!check[i]){
            dfs(i);
        }
    }
    for(int i=0;i<q.size();i++){
        Query y = q[i];
        if((x[y.r]-x[y.l])!=y.d){
            cout << "No" << '\n';
            return 0;
        }
    }
    cout << "Yes" << '\n';
    return 0;
}


Measured memory_bytes: 15024
#include <iostream>
using namespace std;
int main(void){
  int n;
  int t;
  int a[110]={};
  cin >> n;
  int cnt=0;
  for(int i=0; i<n; i++){
    cin >> t;
    if(a[t]==0){a[t]=1;cnt++;}
    else a[t]++;
  }

  cout << cnt << endl;

  return 0;
}


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

using namespace std;

typedef long long	ll;

const int N = int(1e5 + 10);
vector< ll > a1, a2;
ll a[N];

ll get(vector< ll >&a){
	int n = a.size();
	ll sum = 0LL;
		
	for(int i = 1 ; i < n ; i++){
		sum += abs(a[i] - a[i - 1]);
	}
	
	return sum;
}

int main(){
	int n;	
	
	scanf("%d", &n);
	
	for(int i = 0 ; i < n ; i++){
		scanf("%lld", &a[i]);
	}
	
	sort(a, a + n);
	
	int p = 0, i = 0, j = n - 1;
	
	while(i <= j){
		if(a1.size() == 0){
			a1.push_back(a[j]);
			j--;
		}else{
			int tp = a1[a1.size() - 1];
			int bt = a1[0];
			
			ll mx1 = 0, mx2 = 0;
			
			mx1 = abs(bt - a[i]);
			mx2 = abs(tp - a[i]);
			
			ll mxx1 = 0, mxx2 = 0;
			
			mxx1 = abs(bt - a[j]);
			mxx2 = abs(tp - a[j]);
			
			if(max(mx1, mx2) > max(mxx1, mxx2)){
				if(mx1 < mx2){
					a1.push_back(a[i]);
				}else{
					a1.insert(a1.begin(), a[i]);
				}
				
				i++;
			}else{
				if(mxx1 < mxx2){
					a1.push_back(a[j]);
				}else{
					a1.insert(a1.begin(), a[j]);
				}
				
				j--;
			}
		}
	}
		
	printf("%lld\n", get(a1));
	
	return 0;
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define emb emplace_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define N  99999
#define f first 
#define em emplace
#define s second
using lint=long long int;

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

 
#define fori(n) for(int i=0; i<int(n); i++)
 
#define cins(s) string s; cin>>s;
#define cini(i) lint i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define z 1000000007 


void solve(){
  
  cini(n);
  vector<int>dp(3);


  for(int i=0;i<n;i++){
     vector<int>v(3);

     for(int j=0;j<3;j++){
           cin>>v[j];
            int m=0;
           for(int k=0;k<3;k++){

              if(j!=k){
                m=max(dp[k],m);
              }
           }
           v[j]+=m;
     }
    
    dp=v;
  }
     
     int a=max({dp[1],dp[2],dp[0]});
     cout<<a<<endl;




}
 
 
int main()
{ 
  fast;

  



  solve();
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100020],n,x;
int f[100020];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	memset(f,0x3f,sizeof f);
	for(int i=0;i<n;i++)
	{
		int p=lower_bound(f,f+n,a[i])-f;
		f[p]=a[i];
	}
	int ans1= lower_bound(f, f + n, 0x3f3f3f3f) - f;
	reverse(a,a+n);
	memset(f,0x3f,sizeof f);
		for(int i=0;i<n;i++)
	{
		int p=upper_bound(f,f+n,a[i])-f;
		f[p]=a[i];
	}
    int ans2= lower_bound(f, f + n, 0x3f3f3f3f) - f;
	cout<<ans2<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	static int[][] a;
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			a = new int[30][30];
			int x=0, y=0;
			boolean flag = false;
			for(int i = 5; i < 5+8;i++){
				String str = cin.next();
				for(int j = 5; j < 5+8;j++){
					a[i][j]=str.charAt(j-5)-'0';
					if(a[i][j]==1&&!flag){
						flag=true;
						x=i;y=j;
					}
				}
			}
			// A
			if(a[x][y]+a[x][y+1]+a[x+1][y]+a[x+1][y+1]==4){
				System.out.println("A");
				continue;
			}
			
			//B
			if(a[x][y]+a[x+1][y]+a[x+2][y]+a[x+3][y]==4){
				System.out.println("B");
				continue;
			}
			
			//C
			if(a[x][y]+a[x][y+1]+a[x][y+2]+a[x][y+3]==4){
				System.out.println("C");
				continue;
			}
			
			//D
			if(a[x][y]+a[x+1][y]+a[x+1][y-1]+a[x+2][y-1]==4){
				System.out.println("D");
				continue;
			}
			
			//E
			if(a[x][y]+a[x][y+1]+a[x+1][y+1]+a[x+1][y+2]==4){
				System.out.println("E");
				continue;
			}
			
			//F
			if(a[x][y]+a[x+1][y]+a[x+1][y+1]+a[x+2][y+1]==4){
				System.out.println("F");
				continue;
			}
			
			//G
			if(a[x][y]+a[x][y+1]+a[x+1][y-1]+a[x+1][y]==4){
				System.out.println("G");
				continue;
			}
		}
	}

}

Measured memory_bytes: 12000
#include<stdio.h>
#define MAX 150
int graph[MAX][MAX];
int d[MAX],f[MAX];
int time=0,n;

void DFS(int);
 
int main(){
  int u,k,v;
  int i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&u);
    scanf("%d",&k);
    for(j=0;j<k;j++){
      scanf("%d",&v);
      graph[u-1][v-1]=1;
    }
  }
  for(i=0;i<n;i++){
    if(d[i]==0) DFS(i);
  }
 
  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }
  return 0;
}

void DFS(i){
  int j;
  time++;
  d[i]=time;
  for(j=0;j<n;j++){
    if(graph[i][j]!=0 && d[j]==0){
      DFS(j);
    }
  }
  time++;
  f[i]=time;
}

Measured memory_bytes: 656
using System;

public static class Program
{
    private struct Point
    {
        public double X;
        public double Y;

        public static double Distance(Point p, Point q)
        {
            var dx = p.X - q.X;
            var dy = p.Y - q.Y;
            return Math.Sqrt(dx * dx + dy * dy);
        }
    }

    public static void Main()
    {
        Point[] points = ReadInput();
        double result = OptBitonicTraverse(points);
        OutputResult(result);
    }

    static Point[] ReadInput()
    {
        var pointCount = Convert.ToInt32(Console.ReadLine());
        var ret = new Point[pointCount];
        for (int i = 0; i < pointCount; i++)
        {
            var segments = Console.ReadLine().Split(' ');
            ret[i] = new Point { X = Convert.ToDouble(segments[0]), Y = Convert.ToDouble(segments[1]) };
        }
        return ret;
    }

    static void OutputResult(double result)
    {
        Console.WriteLine(result);
    }

    static double OptBitonicTraverse(Point[] points)
    {
        var n = points.Length;
        if (n == 0 || n == 1)
        {
            return 0.0;
        }

        var d = new double[n, n];
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                d[i, j] = Point.Distance(points[i], points[j]);
            }
        }

        var b = new double[n, n];
        b[0, 1] = d[0, 1];
        for (int j = 2; j < n; j++)
        {
            b[j - 1, j] = double.PositiveInfinity;
            for (int k = 0; k < j - 1; k++)
            {
                var newValue = b[k, j - 1] + d[k, j];
                if (newValue < b[j - 1, j])
                {
                    b[j - 1, j] = newValue;
                }
            }

            for (int i = 0; i < j - 1; i++)
            {
                b[i, j] = b[i, j - 1] + d[j - 1, j];
            }
        }

        b[n - 1, n - 1] = b[n - 2, n - 1] + d[n - 2, n - 1];
        return b[n - 1, n - 1];
    }
}


Measured memory_bytes: 21416
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 2e5 + 10;
bool can[N];
int pref[N], suf[N];
int lef[N], rig[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n, k, c;
    cin >> n >> k >> c;
    for (int i = 1; i <= n; i++) {
        char ch;
        cin >> ch;
        can[i] = ch == 'o';
    }
    int ptr = 0;
    for (int i = 1; i <= n; i++) {
        if (can[i]) {
            ptr = i;
            break;
        }
    }
    if (ptr == 0) {
        return 0;
    }
    for (int i = ptr; i <= n; i++) {
        if (can[i] && i - ptr - 1 >= c) {
            ptr = i;
        }
        pref[i] = pref[i - 1] + (i == ptr);
        lef[i] = ptr;
    }
    ptr = n + 1;
    for (int i = n; i >= 1; i--) {
        if (can[i]) {
            ptr = i;
            break;
        }
    }
    for (int i = ptr; i >= 1; i--) {
        if (can[i] && ptr - i - 1 >= c) {
            ptr = i;
        }
        suf[i] = suf[i + 1] + (i == ptr);
        rig[i] = ptr;
    }
    for (int i = 1; i <= n; i++) {
        if (lef[i - 1]) {
            if (pref[lef[i - 1]] + suf[max(i + 1, lef[i - 1] + c + 1)] < k) {
                cout << i << "\n";
            }
        }
        else {
            if (suf[i + 1] < k) {
                cout << i << "\n";
            }
        }
    }

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4864
#include<bits/stdc++.h>
using namespace std;
struct P{
	int y;
	int x;
	int ans;

};

void print(const P & p){
	cout<<p.y<<","<<p.x<<","<<p.ans<<endl;
}

queue<P> que;
P sg[10]={};
int def(char tebl[][1000],int nezu,int h,int w,int n){
	while(que.size()){
		P p=que.front();
		
		//printf("%d %d %d %d %d\n",nezu, p.y, p.x, p.ans, que.size());
		
		que.pop();
		if(p.y>0&&tebl[p.y-1][p.x]=='.'){//up
			que.push(P{p.y-1,p.x,p.ans+1});
			tebl[p.y-1][p.x]='$';
		}
		if(p.y+1<h&&tebl[p.y+1][p.x]=='.'){//down
			que.push(P{p.y+1,p.x,p.ans+1});
			tebl[p.y+1][p.x]='$';
		}
		if(p.x>0&&tebl[p.y][p.x-1]=='.'){//left
			que.push( P{p.y,p.x-1,p.ans+1});
			tebl[p.y][p.x-1]='$';
		}
		if(p.x+1<w&&tebl[p.y][p.x+1]=='.'){//right
			que.push(P{p.y,p.x+1,p.ans+1});
			tebl[p.y][p.x+1]='$';
		}
		if(p.y==sg[nezu].y&&p.x==sg[nezu].x){//リセット
			if(n==nezu){
				return p.ans;
			}
			nezu++;
			for(int l=0;l<h;l++){
				for(int m=0;m<w;m++){
					if(tebl[l][m]=='$'){
						tebl[l][m]='.';
					}
				}
			}
			while(que.size()){
				que.pop();
			}
			que.push(P{p.y,p.x,p.ans});
			tebl[p.y][p.x]='$';
		}
	}
	return 0;
}





int main(){
	int n,h,w,k;
	static char tebl[1000][1000]={};
	cin>>h>>w>>n;
	for(int p=0;p<h;p++){
		for(int m=0;m<w;m++){
			cin>>tebl[p][m];
			if(tebl[p][m]=='S'){
				que.push(P{p,m,0});
				tebl[p][m]='$';
			}
			if(tebl[p][m]>='1'&&tebl[p][m]<='9'){
				sg[tebl[p][m]-'1'+1]=(P{p,m,0});
				tebl[p][m]='.';
			}
		}
	}
	cout<<def(tebl,1,h,w,n)<<endl;
}


Measured memory_bytes: 4064
// D - Preparing Boxes

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const int MOD = 1e9 + 7;

int a[200001];
int b[200001];
vector<int> ans;

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

	for (int i=1; i<=N; i++) {
		cin >> a[i];
	}

	for (int i=N; i>=1; i--) {
		int sum = a[i];
		for (int j=2; i*j<=N; j++) {
			sum += b[i*j];
		}

		if (sum % 2 == 1) {
			b[i] = 1;
			ans.push_back(i);
		} else {
			b[i] = 0;
		}
	}

	int M = ans.size();

	cout << M << endl;

	if (M > 0) {
		for (int i=0; i<M; i++) {
			if (i > 0) cout << " ";
			cout << ans[i];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3064
N, M = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda t: t[0])
ans = 0

for A, B in AB:
    if M-B>=0:
        ans += A*B
        M -= B
    else:
        ans += A*M
        break

print(ans)

Measured memory_bytes: 61528
N=int(input())
A=list(map(int,input().split()))
A = sorted(A, reverse=True)
tate=0
yoko=0

for i in range(N-1):
    if A[i]==A[i+1]:
        tate=A[i]
        A.remove(A[i+1])
        A.remove(A[i])
        break

for i in range(len(A)-1):
    if A[i]==A[i+1]:
        yoko=A[i]
        break

print(tate*yoko)

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

int main ()
{
    while (1)
    {
        int n, m;
        std::cin >> n >> m;
        
        if (n == 0 and m == 0) break;
        
        int a[1100];
        for (int i = 0; i < n; i++) 
        {
            std::cin >> a[i];
        }
        
        int max = 0;
        for (int i = 0; i < n-1; i++) 
        {
            for (int j = i+1; j < n; j++) 
            {
                int temp;
                temp = a[i] + a[j];
                
                if (temp > max and temp <= m)
                {
                    max = temp;
                }
            }
        }
        
        if (max == 0) std::cout << "NONE" << std::endl;
        else          std::cout << max << std::endl;
    }
    
    return 0;
}


Measured memory_bytes: 3048
#include<iostream>
#define rep(x,y,z) for(int x = y;x<z;x++)
using namespace std;
int main(){
    int N;
    cin >> N;
    long long int max;
    cin >> max;
    long long int step = 0;
    rep(i,1,N){
        long long int x;
        cin >> x;
        long long int margin = max-x;
        if(margin > 0){
            step += margin;
        }else{
            max = x;
        }
    }
    cout << step;
    cout << endl;
    return 0;

}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, a, ans = 0;
  cin >> N;
  vector<ll> cnt(100001);
  for(ll i = 0; i < N; i++) {
    cin >> a;
    if(a > 100000) ans++;
    else cnt.at(a)++;
  }
  for(ll i = 1; i <= 100000; i++) {
    if(cnt.at(i) >= i) ans += cnt.at(i) - i;
    else ans += cnt.at(i);
  }
  cout << ans << endl;
}

Measured memory_bytes: 4032
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using namespace std;



// int main() {
//     int n;
//     cin >> n;
//     vector<int>a(n);
//     rep(i,n) {
//         cin >> a[i];
//     }
//     int sum = 1;
//     sort(a.begin(),a.end());
//     reverse(a.begin(),a.end());
//     for(int i = 1; i < n; i++) {
//         if(n == 1)break;
//         if(a[i] == a[i-1])continue;
//         sum++;
//     }
//     cout << sum << endl;
// }
//バケット法
// int main() {
//     int n;
//     cin >> n;
//     vector<int>a(n);
//     rep(i,n) cin >> a[i];
//     vector<int>num(110);
//     //バケットを作る
//     rep(i,n){
//         num[a[i]]++;
//     }
//     int ans = 0;
//     for(int i = 0;i <=100; i++){
//         if(num[i]) ans++;
//     }
//     cout << ans << endl;
// }
//連想配列を使う
int main() {
    int n;
    cin >> n;
    vector<int>a(n);
    rep(i,n) cin >> a[i];
    set<int>s;
    rep(i,n) {
        s.insert(a[i]);
    }
    cout << s.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55556;
int isp[maxn];
vector<int> good;
void init(){
	for(int i = 2; i < maxn; i++){
      if(!isp[i]){
        for(int j = 2 * i; j < maxn; j += i) isp[j] = 1;
      }
    }
  for(int i = 2; i < maxn; i++) if(!isp[i]){
    if(i%5 == 1) good.push_back(i);
  }
}
int main(){
  init();
  int n; cin >> n;
  assert(good.size() >= n);
  for(int i = 0; i < n; i++) cout << good[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 512
while True:
    h,w = map(int, input().split())
    if h == 0 and w == 0:
        break
    for i in range(h):
        for j in range(w):
            if(i % 2 == j % 2):
                print("#", end="")
            else:
                print(".", end="")
        print("")
    print("")


Measured memory_bytes: 7016
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



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

    int r,g,b;
    cin>>r>>g>>b;
    int ans=100*r+10*g+b;
    if(ans%4==0)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <string.h>

using namespace std;

int main() {
    int count = 1;
    while (true) {
        int limit;
        cin >> limit;
        if (limit == 0)break;
        int n;
        cin >> n;

        vector<int> dp(limit + 1, -1145141919);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
            char s[15];
            cin >> s;
            int v = stoi(strtok(s, ","));
            int w = stoi(strtok(NULL, ","));
            for (int j = limit; j >= 0; j--) {
                if (j + w > limit)continue;
                dp[j + w] = max(dp[j + w], dp[j] + v);
            }
        }

        int maxvalue = 0;
        int minweight = 0;
        for (int i = 0; i <= limit; i++) {
            if (maxvalue < dp[i]) {
                maxvalue = dp[i];
                minweight = i;
            }
        }

        cout << "Case " << count << ":" << endl;
        cout << maxvalue << endl;
        cout << minweight << endl;
        count++;
    }
    return 0;
}


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

int main(){
  string s;
  cin>>s;
  int ans =0;
  REP(i,s.length()){
    if(s[i] == '1'){
	ans++;
    }
  }
  cout<<ans<<endl;

return 0;
}

Measured memory_bytes: 256
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *					# ll = deepcopy(l)
from heapq import *					# heappush(hp,x)
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from bisect import *				# bisect_left(arr,x,start,end)  => start and end parameters are temporary
from sys import stdin				# bisect_left return leftmost position where x should be inserted to keep sorted
from sys import maxsize				# minn = -maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *				# pre = [0] + list(accumulate(l))
from decimal import Decimal 		# a = Decimal(a)	# use this for math questions
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''
4
RGRBG

[0,2]
[1,4]
[3,5]
'''

def solve(s):
	n = len(s)
	r,g,b = s.count('R'),s.count('G'),s.count('B')
	sub = 0
	for i in range(n):
		for j in range(i+1,n):
			k = 2*j - i
			if(k >= n):
				break
			if(len(set([s[i],s[j],s[k]])) == 3):
				sub += 1
	return r*g*b - sub


N = int(stdin.readline())
l = input()
ans = solve(l)
print(ans)



Measured memory_bytes: 10940
#include <cstdio>
using namespace std;
bool vis[100005];
int h[100005],n,m,a,b,c;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%d",h+i);
	}
	for(int i=1;i<=m;++i){
		scanf("%d%d",&a,&b);
		if(h[a]>=h[b])vis[b]=true;
		if(h[a]<=h[b])vis[a]=true; 
	}
	for(int i=1;i<=n;++i){
		if(!vis[i]){
			++c;
		} 
	}
	printf("%d\n",c);
	return 0;
}


Measured memory_bytes: 2176