akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define Gene template< class
#define Rics printer& operator,
Gene c> struct rge{c b, e;};
Gene c> rge<c> range(c i, c j){ return {i, j};}
struct printer{
    ~printer(){cerr<<endl;}
    Gene c >Rics(c x){ cerr<<boolalpha<<x; return *this;}
    Rics(string x){cerr<<x;return *this;}
    Gene c, class d >Rics(pair<c, d> x){ return *this,"(",x.first,", ",x.second,")";}
    Gene ... d, Gene ...> class c >Rics(c<d...> x){ return *this, range(begin(x), end(x));}
    Gene c >Rics(rge<c> x){
        *this,"["; for(auto it = x.b; it != x.e; ++it)
            *this,(it==x.b?"":", "),*it; return *this,"]";}
};
#define debug() cerr<<"LINE "<<__LINE__<<" >> ", printer()
#define dbg(x) "[",#x,": ",(x),"] "
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int my_rand(int l, int r) {
    return uniform_int_distribution<int>(l, r) (rng);
}

const int N = 2005;
vector<int> g[N];
int n, K;
int ans = 1e9;
int cur;

void dfs(int u, int p, int d, int ex) {
    if(2*d + ex > K) cur++;
    for(int v : g[u]) {
        if(v == p) continue;
        dfs(v, u, d+1, ex);
    }
}

int main() {
//    freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> K;
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    for(int i = 1; i <= n; i++) {
        for(int v : g[i]) {
            cur = 0;
            dfs(i, v, 0, 1);
            dfs(v, i, 0, 1);
            debug(), dbg(i), dbg(v), dbg(cur);
            ans = min(ans, cur);
        }
    }
    for(int i = 1; i <= n; i++) {
        cur = 0;
        dfs(i, -1, 0, 0);
        debug(), dbg(i), dbg(cur);
        ans = min(ans, cur);
    }
    cout << ans << endl;
}





Measured memory_bytes: 3864
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = (B-1); I >= (A); --I)
const ll INF=1e18+7;
const ll MOD=1e9+7;

int express[509][509];


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	int ans = 0;
	for(int i=1;i<=n;i+=2){
		int m=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)m++;
		}
		if(m==8)ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const long MOD = 1000000007;
typedef pair<int, int> P;
typedef long long ll;

int main(){
    int N;
    cin >> N;
    ll A[N];
    ll m = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        m = max(m, A[i]);
    }

    ll bk = 0;
    while(m != 0){
        m = m / 2;
        bk++;
    }

    ll ans = 0;
    ll mul = 1;
    for(int i=0; i<bk; i++){
        ll n0 = 0;
        ll n1 = 0;
        for(int j=0; j<N; j++){
            if(((A[j]>>i) & 1) == 1) n1++;
            if(((A[j]>>i) & 1) == 0) n0++;
        }
        ll kumi = n0*mul%MOD;
        ans = ans + n1*kumi%MOD;
        ans = ans % MOD;
        mul = mul*2;
        mul = mul % MOD;
    }

    cout << ans << endl;

    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 PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    char X,Y;
    cin >> X>>Y;
    if(X>Y) cout << '>' << endl;
    else if(X<Y)cout << '<' << endl;
    else cout <<'='<<endl;



}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        s: chars,
    };
    let a = s[0].to_digit(10).unwrap() as i32;
    let b = s[1].to_digit(10).unwrap() as i32;
    let c = s[2].to_digit(10).unwrap() as i32;
    let d = s[3].to_digit(10).unwrap() as i32;

    let t = vec![true, false];

    for abp in &t{
        for bcp in &t{
            for cdp in &t{
                let mut tmp: i32 = a;
                if *abp{tmp+=b} else {tmp-=b}
                if *bcp{tmp+=c} else {tmp-=c}
                if *cdp{tmp+=d} else {tmp-=d}
                if tmp == 7 {
                    print!("{}", a);
                    print!("{}", if *abp {'+'} else {'-'});
                    print!("{}", b);
                    print!("{}", if *bcp {'+'} else {'-'});
                    print!("{}", c);
                    print!("{}", if *cdp {'+'} else {'-'});
                    print!("{}", d);
                    println!("=7");
                    return;
                }

            }
        }
    }
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,n) for(int i=1; i<=(n); i++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define abs(a) llabs(a)
#define re(s) reverse((s).begin(),(s).end())
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;

using namespace std;
signed main(){

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

    double w,h;
    int x,y;
    cin>>w>>h>>x>>y;

    cout<<setprecision(15)<<w*h/2<<' ';
    if(x+x==w && y+y==h) cout<<1<<'\n';
    else cout<<0<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
int main() {
    int n;
    cin >> n;
    vector <int> f(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        int x;
        cin >> x;
        ++f[x];
    }
    for (int i = 1; i <= n; ++i) {
        cout << f[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 4048
n,m,q=map(int,input().split())
s=[[0 for i in range(n+1)] for j in range(n+1)]

a=list()

for i in range(m):
  l,r=map(int,input().split())
  s[l][r] += 1

for i in range(1,n+1):
  for j in range(1,n+1):
    s[i][j] += s[i][j-1] 

for i in range(1,n+1):
  for j in range(1,n+1):
    s[j][i] += s[j-1][i]

for i in range(q):
  l,r=map(int,input().split())
  t = s[r][r] - s[l-1][r] - s[r][l-1] + s[l-1][l-1]
  a.append(t)

for i in range(q):
  print(a[i])


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

int main() {
    int n; cin >> n;
    for (int i = 0; i < 50000; i++) {
        int a = (i * 108) / 100;
        if (n == a) {
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
void pre(){}
void solve(){
    int s,w;cin>>s>>w;
    if(w>=s){
        cout<<"unsafe"<<"\n";
    }else{
        cout<<"safe"<<"\n";
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long int num = 1;
    //cin>>num;
    for(long long int i=0;i<num;i++){
	//cout<<"Case #"<<i+1<<": ";
       	solve();
    }   
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top,S[1000];

void push(int x)
{
	S[++top]=x;	
} 

int pop()
{
	top--;
	return S[top+1];
}

int main()
{
	int a,b;
	top=0;
	char s[100];
	while(scanf("%s",s)!=EOF){
		if(s[0]=='+')
		{
			a=pop();
			b=pop();
			push(a+b);
		}else if(s[0]=='-')
		{
			b=pop();
			a=pop();
			push(a-b);
		}
		else if(s[0]=='*')
		{
			a=pop();
			b=pop();
			push(a*b);
		}
		else{
			push(atoi(s));
		}
	}
	printf("%d\n",pop());
	return 0;
}


Measured memory_bytes: 2680
n=int(input())
a=[0]*n
b=[0]*n
c=[0]*n
for i in range(n):
    a[i],b[i],c[i]=list(map(int,input().split()))
dpa=[100000000]*n
dpb=[100000000]*n
dpc=[100000000]*n
dpa[0]=a[0]
dpb[0]=b[0]
dpc[0]=c[0]
for i in range(n-1):
    dpa[i+1]=max(dpb[i]+a[i+1],dpc[i]+a[i+1])
    dpb[i+1]=max(dpa[i]+b[i+1],dpc[i]+b[i+1])
    dpc[i+1]=max(dpa[i]+c[i+1],dpb[i]+c[i+1])


print(max(dpa[n-1],dpb[n-1],dpc[n-1]))

Measured memory_bytes: 52440
#include<stdio.h>
#include<stdlib.h>
int main()
{
    long long a,b,i,j=0;
    scanf("%lld %lld",&a,&b);
    for(i=0;i<=1000000000;i++)
    {
        if(abs(a-i)==abs(b-i))
        {
            j=i;
            break;
        }
    }
    if(j!=0)
        printf("%lld",j);
    else
        printf("IMPOSSIBLE");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)
#define ll long long

int main(void){
    int N;
    cin >> N;
    ll ans = 0; 
    vector<pair<int, int>> red, blue;
    int x,y;
    rep(i,N){
        cin >> x >> y;
        red.emplace_back(y, x);
    }
    rep(i,N){
        cin >> x >> y;
        blue.emplace_back(x, y);
    }
    sort(red.begin(), red.end(), greater<pair<int,int>>());
    sort(blue.begin(), blue.end());
    vec_rep(blue_itr,blue){
        pair<int, int> blue_point = *blue_itr;
        int blue_x = blue_point.first;
        int blue_y = blue_point.second;
        vec_rep(red_itr,red){
            pair<int, int> red_point = *red_itr;
            int red_x = red_point.second;
            int red_y = red_point.first;
            if(red_x >= blue_x || red_y >= blue_y)continue;
            ans++;
            red.erase(red_itr);
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int qmax(int &x,int y) {if (x<y) x=y;}
int qmin(int &x,int y) {if (x>y) x=y;}
ll read()
{
    char s;
    ll k=0,base=1;
    while((s=getchar())!='-'&&s!=EOF&&!(isdigit(s)));
    if(s=='-')base=-1,s=getchar();
    while(isdigit(s)){k=k*10+(s^'0');s=getchar();}
    return k*base;
}
inline void write(int x)
{
    static char cnt,num[15];cnt=0;
    if (!x)
    {
        putchar('0');
        return;
    }
    for (;x;x/=10) num[++cnt]=x%10;
    for (;cnt;putchar(num[cnt--]+48));
}
ll x,y;
int main()
{
	x=read();y=read();
	if (x%y==0)
	{
		printf("-1");
		return 0;
	} else
	{
		printf("%lld",x);
	}
	return 0;
} 

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

using namespace std;
int main()
{
  while(1){
    int n,m;
    cin>>n>>m;
    if((n==0) and (m==0)){
      return 0;
    }

    vector<int> list(n);
    for(int i=0;i<n;i++){
      cin>>list[i];
    }
  
    int sum[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if(i==j){
	  sum[i][j]=-1;
	}else{
	  sum[i][j]=list[i]+list[j];
	}
      }
    }
  
    int Out=-1;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
	if ((m>=sum[i][j])and(sum[i][j]>Out)) Out=sum[i][j];
      }
    }
  
    if(Out==-1){
      cout<<"NONE"<<endl;
    }else{
      cout<<Out<<endl;
    }
  }

  return 0;
}



Measured memory_bytes: 6968
#include<stdio.h>
#define M 200000
#define SNT 2000000000
typedef long long int llong;

int L[M / 2 + 2], R[M / 2 + 2];

llong merge(int*, int, int, int, int);
llong mergeSort(int*, int, int, int);

llong merge(int A[], int n, int left, int mid, int right){
  int i, j, k;
  int n1, n2;
  llong count = 0;
  n1 = mid - left;
  n2 = right - mid;
  for( i = 0 ; i < n1 ; i++){
    L[i] = A[left + i];
  }
  for( i = 0 ; i < n2 ; i++){
    R[i] = A[mid + i];
  }
  L[n1] = R[n2] = SNT;
  i = j = 0;
  for( k = left ; k < right ; k++){
    if( L[i] <= R[j] ){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++];
      count += n1 - i;
    }
  }
  return count;
}

llong mergeSort(int A[], int n, int left, int right){
  int mid;
  llong v1, v2, v3;
  if( left + 1 < right){
    mid = (left + right) / 2;
    v1 = mergeSort(A, n, left, mid);
    v2 = mergeSort(A, n, mid, right);
    v3 = merge(A, n, left, mid, right);
    return v1 + v2 + v3;
  }
  else return 0;
}

int main(){
  int A[M], n, i;
  llong ans;

  scanf("%d", &n);
  for( i = 0 ; i < n ; i++){
    scanf("%d", &A[i]);
  }

  ans = mergeSort(A, n, 0, n);
  printf("%lld\n", ans);

  return 0;
}



Measured memory_bytes: 3332
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;
#define N_MAX 8

int main(void){
    int N;
    float x[N_MAX], y[N_MAX];
    
    scanf("%d", &N);
    for(int i = 0; i < N; i++){
        int x_, y_;
        scanf("%d %d", &x_, &y_);
        x[i] = x_;
        y[i] = y_;
    }
    
    float dist_sum = 0;
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            dist_sum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
        }
    }
    
    printf("%lf", dist_sum / N * 2);
    
    return 0;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {

	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int ans = 0;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n; j += 2) {
				if (i <= n && j <= n) {
					ans++;
				}

			}
		}
		System.out.println(ans);

	}
}


Measured memory_bytes: 22996
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
typedef pair<int,int> pr;
int main() {
	// your code goes here
	int n,m;
	while(cin >> n >> m && n!=0){
		int win[101][101]={};
		int pic[50][50]={};
		int pt[50][50][4]={};
		int x=100,y=100;
		int fx[4]={},fy[4]={};
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
				cin >> win[i][j];
		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++){
				cin >> pic[i][j];
				pt[i][j][0]=pic[i][j];
				pt[m-i-1][m-j-1][1]=pic[i][j];
				pt[m-j-1][i][2]=pic[i][j];
				pt[j][m-i-1][3]=pic[i][j];
				
			}
		for(int k=0;k<4;k++)
			for(int i=0;i<m;i++)
				for(int j=0;j<m;j++)
					if(pt[i][j][k]!=-1){
						fx[k]=j;
						fy[k]=i;
						i=m;
						j=m;
					}
		for(int i=1;i<=n-m+1;i++)
			for(int j=1;j<=n-m+1;j++){
				for(int k=0;k<4;k++){
					for(int l=0;l<m;l++)
						for(int p=0;p<m;p++){
							if(pt[l][p][k]==-1 || pt[l][p][k]==win[i+l][j+p]){
								if(l==m-1 && p==m-1)
									if(y>i+fy[k]||(y>=i+fy[k] && x>=j+fx[k])){
										y=i+fy[k];
										x=j+fx[k];
									}
									
							}
							else{
								l=m;
								p=m;
							}
							
						}
				}
			}
		if(x==100 && y==100)
		cout << "NA" << endl;
		else
		cout << x <<" " <<  y << endl;
		
		
	}
	return 0;
}

Measured memory_bytes: 1260
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <iomanip>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	int n,m;cin>>n>>m;
	priority_queue<int> pq;
	loop(n,i,0){
		int x;cin>>x;
		pq.push(x);
	}
	while(m--){
		int x=pq.top();
		pq.pop();
		pq.push(x/2);
	}
	ll res=0;
	while(!pq.empty()){
		res+=pq.top();
		pq.pop();
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define re register 
string s;
int ans=1<<30;
int main()
{
    cin>>s;
    for(re int i=1;i<s.length();i++)
        if(s[i]!=s[i-1])
            ans=min(ans,max(i,int(s.length())-i)); 
    cout<<min(ans,int(s.length()))<<endl;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s, t;
	cin >> s >> t;
	ll n = s.size(), m = t.size();
	vector<vector<pair<ll, pll>>> dp(n, vector<pair<ll, pll>>(m, make_pair(0, pll(-1, -1))));
	REP(i, n) REP(j, m) {
		if(i == 0 && j == 0) {
			if(s[i] == t[j]) dp[i][j].first = 1;
			continue;
		}
		if(i && j) {
			if(s[i] == t[j]) {
				dp[i][j].first = dp[i - 1][j - 1].first + 1;
				dp[i][j].second = pll(i - 1, j - 1);
			} else {
				if(dp[i - 1][j].first > dp[i][j - 1].first) {
					dp[i][j].first = dp[i - 1][j].first;
					dp[i][j].second = pll(i - 1, j);
				} else {
					dp[i][j].first = dp[i][j - 1].first;
					dp[i][j].second = pll(i, j - 1);
				}
			}
		} else if(i) {
			if(s[i] == t[j]) {
				dp[i][j].first = 1;
			} else {
				dp[i][j].first = dp[i - 1][j].first;
				dp[i][j].second = pll(i - 1, j);
			}
		} else {
			if(s[i] == t[j]) {
				dp[i][j].first = 1;
			} else {
				dp[i][j].first = dp[i][j - 1].first;
				dp[i][j].second = pll(i, j - 1);

			}
		}
	}
	string ans = "";
	pll pos = pll(n - 1, m - 1);
	while(pos != pll(-1, -1)) {
		if(s[pos.first] == t[pos.second]) ans += s[pos.first];
		pos = dp[pos.first][pos.second].second;
	}
	reverse(ALL(ans));
	cout << ans << endl;
	return 0;
}

/* --------------------------------------- */


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

using namespace std;

#define range(i, m, n) for(int i = m; i < n; i++)
#define husk(i, m, n) for(int i = m; i > n; i--)

int n;

int main() {
  cin >> n;
  vector<int> t(n);
  vector<string> s(n);
  range(i, 0, n) {
    cin >> s[i] >> t[i];
  }
  string x;
  cin >> x;
  int pos = -1;
  range(i, 0, n) if(s[i] == x) pos = i;
  int res = 0;
  range(i, pos + 1, n) res += t[i];
  cout << res;
  return 0;
}


Measured memory_bytes: 256
/*
░░░░░░░░░░░░░░░░▄▄█▀▀██▄▄░░░░░░░
░░░░░░░░░░░░░▄█▀▀░░░░░░░▀█░░░░░░
░░░░░░░░░░░▄▀░░░░░░░░░░░░░█░░░░░
░░░░░░░░░▄█░░░░░░░░░░░░░░░█░░░░░
░░░░░░░██▀░░░░░░░▄▄▄░░▄░█▄█▄░░░░
░░░░░▄▀░░░░░░░░░░████░█▄██░▀▄░░░
░░░░█▀░░░░░░░░▄▄██▀░░█████░██░░░
░░░█▀░░░░░░░░░▀█░▀█▀█▀▀▄██▄█▀░░░
░░░██░░░░░░░░░░█░░█░█░░▀▀▄█▀░░░░
░░░░█░░░░░█░░░▀█░░░░▄░░░░░▄█░░░░
░░░░▀█░░░░███▄░█░░░░░░▄▄▄▄█▀█▄░░
░░░░░▀██░░█▄▀▀██░░░░░░░░▄▄█░░▀▄░
░░░░░░▀▀█▄░▀▄▄░▄░░░░░░░███▀░░▄██
░░░░░░░░░▀▀▀███▀█▄░░░░░█▀░▀░░░▀█
░░░░░░░░░░░░▄▀░░░▀█▄░░░░░▄▄░░▄█▀
░░░▄▄▄▀▀▀▀▀█▀░░░░░█▄▀▄▄▄▄▄▄█▀▀░░
░▄█░░░▄██▀░░░░░░░░░█▄░░░░░░░░░░░
█▀▀░▄█░░░░░░░░░░░░░░▀▀█▄░░░░░░░░
█░░░█░░░░░░░░░░░░░░░░░░█▄░░░░░░░
*/
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define x first
#define y second
#define pi pair <int, int>
#define vi vector <int>
//#define =1e9 =(int)1e9
const ll mod = 1000000007;
const ll nmax=3000001;
int n, k, dp[100002][2];

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
    cin>>n>>k;
    dp[0][0]=1;
    for(int i=1; i<=n; i++){
        int x;
        cin>>x;
        for(int i=1; i<=k; i++) dp[i][0]+=dp[i-1][0], dp[i][0]%=mod;
        for(int i=0; i<=k; i++) dp[i][1]=dp[i][0]-dp[max(i-x-1, 0)][0]*(i-x-1>=0)+mod, dp[i][1]%=mod;
        for(int i=0; i<=k; i++) dp[i][0]=dp[i][1];
    }
    cout<<dp[k][0];
}


Measured memory_bytes: 1024
import java.util.*;

public class Main{

public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int[] mountains = new int[10];

for(int i=0; i<10; i++){
mountains[i] = sc.nextInt();
}

Arrays.sort(mountains);
System.out.println(mountains[9]);
System.out.println(mountains[8]);
System.out.println(mountains[7]);
}


}

Measured memory_bytes: 26264
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>

using namespace std;

int main() {
  string s;
  vector<int> tmp;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    tmp.push_back(s[i] - 'a');
  }
  sort(tmp.begin(), tmp.end());
  if (tmp[0] == tmp[1] && tmp[1] != tmp[2] && tmp[2] == tmp[3])
    cout << "Yes" << endl;
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1LL << 60
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const long long MOD=1000000007;

// vector<p> cut(M); vector<vector<ll> > v(4);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()), sort(v.rbegin(), v.rend()); //sort
// char '' str ""
int main(void)
{
    str s;cin>>s;
    for(int i=0; i<s.size();i++){
      if(i%2==0) cout<<s[i];
    }

    cout<<endl;
    return 0;
}


Measured memory_bytes: 512
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
/*#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")*/

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define mp make_pair
#define what_is(x) cerr << #x << " is " << x << endl;

typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;


const int p = 1e9 + 7;


int mul(int a, int b) {
    return (1LL * a%p * b%p) % p;
}

int add(int a, int b) {
    int s = (a+b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int sub(int a, int b) {
    int s = (a-b);
    s = s%p;
    if (s<0) s+=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

vector<int> Z(vector<int> s)
{
    int n = s.size();
    vector<int> z(n);
    int L = 0, R = 0;
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R-L] == s[R]) R++;
            z[i] = R-L; R--;
        } else {
            int k = i-L;
            if (z[k] < R-i+1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R-L] == s[R]) R++;
                z[i] = R-L; R--;
            }
        }
    }
    return z;
}

mt19937 rnd(time(0));
/*
struct Line {
    mutable ll k, m, p;
    bool operator<(const Line& o) const { return k < o.k; }
    bool operator<(ll x) const { return p < x; }
};

struct CHT : multiset<Line, less<>> {
    // (for doubles, use inf = 1/.0, div(a,b) = a/b)
    const ll inf = LLONG_MAX;
    ll div(ll a, ll b) { // floored division
        return a / b - ((a ^ b) < 0 && a % b); }
    bool isect(iterator x, iterator y) {
        if (y == end()) { x->p = inf; return false; }
        if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
        else x->p = div(y->m - x->m, x->k - y->k);
        return x->p >= y->p;
    }
    void add(ll k, ll m) {
        auto z = insert({k, m, 0}), y = z++, x = y;
        while (isect(y, z)) z = erase(z);
        if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
        while ((y = x) != begin() && (--x)->p >= y->p)
            isect(x, erase(y));
    }
    ll query(ll x) {
        assert(!empty());
        auto l = *lower_bound(x);
        return l.k * x + l.m;
    }
};
*/

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);

    int n;
    cin>>n;
    int maxx = 0;
    vector<int> a(n);
    for (int i = 0; i<n; i++) {cin>>a[i]; maxx = max(maxx, a[i]);}
    int cnt = 0;
    int idx = -1;
    for (int i = 0; i<n; i++) if (a[i] == maxx) {cnt++; idx = i;}
    if (cnt>=2) {for(int i = 0; i<n; i++) cout<<maxx<<endl; return 0;}
    int maxx1 = 0;
    for (int i = 0; i<n; i++) if (i!=idx) maxx1 = max(maxx1, a[i]);
    for (int i = 0; i<n; i++) if (i==idx) cout<<maxx1<<endl; else cout<<maxx<<endl;
}

Measured memory_bytes: 2432
#include<iostream>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define c(n) cout<<n<<endl;
signed main(){
	string s;
	cin>>s;
	int n=s.size();
	int ans=0;
	rep(i,n){
		if(s[i]!=s[n-i-1]){
			ans++;
		}
	}
	c(ans/2)
}			

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#define SIZE 2005
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define mp make_pair
#define ll long long
using namespace std;
void io() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); }
ll n, m, k, top;
char s[SIZE][SIZE];
int nx[SIZE][SIZE], ny[SIZE][SIZE];

int getx(int x, int y) {
	int cnt = 0, ed = y - 1;
	rep(i, y, m) {
		if (s[x][i] == '#') break;
		++cnt, ++ed;
	}
	rep(i, y, ed) nx[x][i] = cnt;
	return cnt;
}

int gety(int x, int y) {
	int cnt = 0, ed = x - 1;
	rep(i, x, n) {
		if (s[i][y] == '#') break;
		++cnt, ++ed;
	}
	rep(i, x, ed) ny[i][y] = cnt;
	return cnt;
}

int main() {
	io(); cin >> n >> m;
	rep(i, 1, n) {
		rep(j, 1, m) {
			cin >> s[i][j];
		}
	}
	int ans = 0;
	rep(i, 1, n) {
		rep(j, 1, m) {
			if (s[i][j] == '#') continue;
			int tmp = 0;
			if (nx[i][j]) tmp += nx[i][j];
			else tmp += getx(i, j);
			if (ny[i][j]) tmp += ny[i][j];
			else tmp += gety(i, j);
			ans = max(ans, tmp);
		}
	}
	cout << ans - 1;
}

Measured memory_bytes: 35584
#include <stdio.h>

int main()
{
	int r;
	int g;
	int b;
	int num;

	scanf("%d %d %d", &r, &g, &b);

	if (r < 0 || r > 9) {
		goto end;
	} else if (g < 0 || g > 9) {
		goto end;
	} else if (b < 0 || b > 9) {
		goto end;
	}

	num = r * 100 + g * 10 + b;

	if (num % 4 == 0) {
		printf("YES\n");
	} else {
		printf("NO\n");
	}
end:
	return 0;
}


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

using lli=long long int;
	void solve(){
		int N,i,j,p,q;
		string word;
		cin>>word;
		N=word.size();
		for(i=0;i<N;i++){
			if(word[i]=='?')word[i]='D';
		}
		cout<<word;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 3756
#include<stdio.h>
int main(void){
	int n, h[3]={-1,-1,-1};
	int i, j, k;
	for(i=0;i<10;i++){
		scanf("%d", &n);
		for(j=0;j<3;j++){
			if(h[j] < n){
				for(k=2;k>j;k--){
					h[k] = h[k-1];
				}
				h[j]=n;
				break;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n", h[i]);
	}
	return 0;
}

Measured memory_bytes: 600
use proconio::input;

fn main() {
    input! {
        n: i32,
        m: i32,
        a: [i32;m]
    }
    let mut ans = n;
    for x in a.iter() {
        ans = ans-x;
    }
    if ans < 0 {println!("-1")}else{    println!("{}", ans)}
}

Measured memory_bytes: 2192
#include<unordered_map>
#include<iostream>
#include<algorithm>
#include<utility>
#include<climits>
#include<fstream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<cmath>
#include<list>
#include<map>
#include<set>
#define inf 0x7f7f7f
#define p(x) (x)*(x)
#define PI 3.14159265358979
using namespace std;

typedef vector<vector<int> > vtype;
typedef long long ll;

int main()
{
	//ios::sync_with_stdio(false);
	int a[3] = {0};
	cin >> a[0] >> a[1] >> a[2];
	if(count(a, a+3, a[1]) == 2 || count(a, a+3, a[0]) == 2 ||count(a, a+3, a[2]) == 2)
		cout << "Yes" << endl;
	else
		cout <<"No" << endl; 
    return 0;
}















Measured memory_bytes: 256
/*
         ██╗ ██████╗ ██╗███╗   ██╗    ██╗   ██╗███████╗
         ██║██╔═══██╗██║████╗  ██║    ██║   ██║██╔════╝
         ██║██║   ██║██║██╔██╗ ██║    ██║   ██║███████╗
    ██   ██║██║   ██║██║██║╚██╗██║    ██║   ██║╚════██║
    ╚█████╔╝╚██████╔╝██║██║ ╚████║    ╚██████╔╝███████║
     ╚════╝  ╚═════╝ ╚═╝╚═╝  ╚═══╝     ╚═════╝ ╚══════╝
*/
//password:+BdCHpO8dQvpo5fnV3/u
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 5e5 + 5;
const int inf = 0x3f3f3f3f;



int main() {
    ll n;
    cin>>n;
    map<int,int>ma,mb;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)
    cin>>a[i],ma[i+a[i]]++,mb[i-a[i]]++;
    ll ans=0;
    for(auto it:ma){
        ans+=(ll)it.second*mb[it.first];
    }    
    cout<<ans;
    return 0;
}

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

int main(){
    int s;  cin>>s;
    int m,u;
    m=s/100;
    u=s%100;
    if(m<=12&&m>0){
        if(u<=12&&u>0){
        cout<<"AMBIGUOUS"<<endl;
        }else{cout<<"MMYY"<<endl;
        }
    }else if(u<=12&&u>0){
        cout<<"YYMM"<<endl;
        }else{cout<<"NA"<<endl;
        }
    }


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

#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define snd sd.ft
#define td sd.sd
#define debug(x) cout<<"### x is: "<<x<<"###"<<endl
#define all(a) a.begin(),a.end()

#define ninf -1000000000
#define pinf 1000000000

typedef long long int ll;
const ll MOD= 1e9+7;
typedef vector<pair<ll,ll> > vecpair;
typedef vector<pair<ll, pair<ll,ll> > > vecpair3;
typedef pair<ll, ll> pi;

//double mei ye line cout << fixed << setprecision(10); kam mei le

ll power(ll a, ll b) {ll ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=MOD) ret%=MOD;if(a>=MOD) a%=MOD;b>>=1;}return ret;}

struct subset // disjoint set use subsets.claer and subsets.resize............
{
	int parent,sz;
};
vector< subset> subsets;
int find( int i)
{
    if (subsets[i].parent != i)
        subsets[i].parent = find(subsets[i].parent);

    return subsets[i].parent;
}
void uniona(int x, int y){
	if( x == y)
	return ;
    int xroot = find( x);
    int yroot = find( y);
    if (subsets[xroot].sz < subsets[yroot].sz){
        subsets[xroot].parent = yroot;
        subsets[yroot].sz += subsets[xroot].sz;
    }
    else{
        subsets[yroot].parent = xroot;
        subsets[xroot].sz += subsets[yroot].sz;
    }
}
//..............................

string s,t;
int l1,l2;
int dp[3005][3005];

int solve(int i,int j)
{
	if(i==l1||j==l2)
		return 0;
	if(dp[i][j]!=-1)
		return dp[i][j];
	if(s[i]==t[j])
		dp[i][j]=1+solve(i+1,j+1);
	else
		dp[i][j]=max(solve(i+1,j),solve(i,j+1));
		return dp[i][j];
}

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

	cin >> s >> t;
	l1=s.size();
	l2=t.size();
	for(int i=0;i<3005;i++)
	{
		for(int j=0;j<3005;j++)
		{
			dp[i][j]=-1;
		}
	}
	int k=solve(0,0);
	for(int i=0;i<l1;i++)
	{
		cout << "\n";
		for(int j=0;j<l2;j++)
		{
			//cout << dp[i][j] << " ";
		}
	}
	string ss;
	int p=-1;
	for(int i=0;i<l1;i++)
	{
		for(int j=p+1;j<l2;j++)
		{
			if(s[i]==t[j]&&dp[i][j]==k)
			{
				ss+=s[i];
				p=j;
				k--;
				break;
			}
		}
	}
	cout << ss;

	return 0;
}


Measured memory_bytes: 35968
///
// File:  1126.cpp
// Author: ymiyamoto
//
// Created on Sun Dec 10 00:54:34 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
bool bigger(string str1, string str2)
{
  if (str1.size() == str2.size()) {
    return str1 < str2;
  } else {
    return str1.size() < str2.size();
  }
}

string wfs(vector<string> matrix, vector<vector<string>> &memo, uint32_t i, uint32_t j)
{
  if (i < matrix.size() && j < matrix[0].size() && memo[i][j] != "") return memo[i][j];

  if (i >= matrix.size() || j >= matrix[0].size() || !isdigit(matrix[i][j]))
    return "";
  else {
    string s1 = wfs(matrix, memo, i + 1, j);
    string s2 = wfs(matrix, memo, i, j + 1);
    return memo[i][j] = matrix[i][j] + (bigger(s1, s2) ? s2 : s1);
  }
}

int32_t main()
{
  while (true) {
    uint32_t W, H;
    cin >> W >> H;
    if (W == 0 && H == 0) break;
    vector<string> matrix;
    for (uint32_t i = 0; i < H; i++) {
      string line;
      cin >> line;
      matrix.push_back(line);
    }

    string number = "";
    vector<vector<string>> memo(H, vector<string>(W, ""));
    for (int32_t i = matrix.size() - 1; i >= 0; i--) {
      for (int32_t j = matrix[0].size() - 1; j >= 0; j--) {
        if (matrix[i][j] == '0') continue;
        string num = wfs(matrix, memo, i, j);
        if (bigger(number, num)) {
          number = num;
        }
      }
    }
    cout << number << endl;
  }

  return 0;
}

Measured memory_bytes: 3112
#include <iostream>
#include <string>
#include <algorithm>
#include <cassert>
#include <limits>
#include <numeric>
#include <type_traits>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <functional>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <complex>
#include <climits>
#include <time.h>

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)

const double PI = 3.14159265358979;
/******変数定義start******/
ll sx, sy, tx, ty;
/*******変数定義end*******/

ll solve(){
    cin >> sx >> sy >> tx >> ty;
    REP(i, tx-sx){
        cout << "R";
    }
    REP(i, ty-sy){
        cout << "U";
    }
    REP(i, tx-sx){
        cout << "L";
    }
    REP(i, ty-sy){
        cout << "D";
    }
    cout << "D";
    REP(i, tx-sx+1){
        cout << "R";
    }
    REP(i, ty-sy+1){
        cout << "U";
    }
    cout << "L";
    cout << "U";
    REP(i, tx-sx+1){
        cout << "L";
    }
    REP(i, ty-sy+1){
        cout << "D";
    }
    cout << "R";
    
    return 0;
}

int main(){

    //clock_t start = clock();
    cout << std::fixed << std::setprecision(10);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll end = solve();
    /*
    clock_t end = clock();
    const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
    printf("time %lf[ms]\n", time);
    */
    return end;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<map>
#include<random>

using namespace std;


int N;
long long a[2000];
long long dp[2][2000][2000];
bool ate[2000] = {};

long long solve(int t, int r, int l) {
	if (ate[r] == true && ate[l] == true) return 0;

	if (dp[t][r][l] != -1) return dp[t][r][l];

	/*
	if (r == l) {
		ate[r] = true; 
		dp[t][r][l] = a[r] + solve(1, (r - 1) % N, (l + 1) % N);
		ate[r] = false; 

		return dp[t][r][l];
	}
	*/

	if (t == 0) {
		long long tmp1, tmp2;

		if (ate[r] != true) {
			ate[r] = true;
			tmp1 = a[r] + solve(1, (r - 1+N) % N, l);
			ate[r] = false;
		}

		if (ate[l] != true) {
			ate[l] = true;
			tmp2 = a[l] + solve(1, r, (l + 1) % N);
			ate[l] = false;
		}

		long long tmp = max(tmp1, tmp2);
		dp[t][r][l] = max(dp[t][r][l], tmp);
		return tmp;
	}
	else {

		long long tmp;
		if (a[r] < a[l] && ate[l] != true) {
			ate[l] = true;
			tmp = solve(0, r, (l + 1) % N);
			ate[l] = false;
		}
		else if (ate[r] != true){
			ate[r] = true;
			tmp = solve(0, (r - 1+N) % N, l);
			ate[r] = false;
		}

		dp[t][r][l] = max(dp[t][r][l], tmp);
		return tmp;
	}

	if (dp[t][r][l] != -1) {
		return dp[t][r][l];
	}
	else {
		return 0;
	}
}

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

		for (int j = 0; j < N; j++) {
			dp[0][i][j] = -1;
			dp[1][i][j] = -1;
		}
	}

	long long ans = 0;
	for (int i = 0; i < N; i++) {
		ate[i] = true;
		ans = max(ans, a[i] + solve(1, (i-1+N)%N, (i + 1) % N));
		ate[i] = false;
	}

	cout << ans << endl;


	return 0;
}


Measured memory_bytes: 65724
#include<bits/stdc++.h>
using namespace std;
string lcs(string x, string y, int n, int m){
    int t[n+1][m+1];
    for(int i=0; i<n+1; i++){
        for(int j=0; j<m+1; j++){
            if(i==0||j==0)
            t[i][j]=0;
            else if(x[i-1]==y[j-1])
            t[i][j]=1+t[i-1][j-1];
            else
            t[i][j]=max(t[i-1][j], t[i][j-1]);
        }
    }
    int i=n; int j=m;
    string s;
    while(i>0&&j>0){
        if(x[i-1]==y[j-1])
        {
            s=s+x[i-1];
            i--;j--;
        }
        else{
     if(t[i-1][j]>t[i][j-1])
        i--;
        else
        j--;
    }
    }
    reverse(s.begin(), s.end());
    return s;
}
int main(){
  string x,y;
  int n,m;
  cin>>x>>y;
  n=x.size();
  m=y.size();
  cout<<lcs(x,y,n,m);
  return 0;
}

Measured memory_bytes: 38784
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << endl; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

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

  int n, m, x;
  cin >> n >> m >> x;
  vi c(n);
  vector<vi> a(n, vi(m));
  REP(i, n) {
    cin >> c[i];
    REP(j, m) { cin >> a[i][j]; }
  }

  int ans = 1e9;
  REP(s, (1 << n)) {
    int tans = 0;
    vi rikai(m, 0);
    REP(i, n) {
      if ((s >> i) % 2 == 0)
        continue;
      tans += c[i];
      REP(j, m) { rikai[j] += a[i][j]; }
    }
    bool ok = true;
    REP(j, m) {
      if (rikai[j] < x)
        ok = false;
    }
    if (ok)
      chmin(ans, tans);
  }

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


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

using namespace std;

int main()
{
    int x[5], k;

    cin >> x[0] >> x[1] >> x[2] >> x[3] >> x[4] >> k;

    bool is_ok = true;
    for (int i = 0; i < 5; i++)
        for (int j = 0; j < 5; j++)
        {
            if (abs(x[i] - x[j]) > k)
            {
                is_ok = false;
                break;
            }
            if (!is_ok)
            {
                break;
            }
        }
    if (is_ok)
        cout << "Yay!" << endl;
    else
        cout << ":(" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	vi is_prime(100000,1);
	is_prime[0]=is_prime[1]=0;
	rep(i,is_prime.size()){
		if(!is_prime[i])
			continue;
		for(int j=i+i;j<is_prime.size();j+=i)
			is_prime[j]=0;
	}
	
	for(int n;cin>>n,n;){
		int res=0;
		for(int i=2;i+i<=n;i++)
			if(is_prime[i] && is_prime[n-i])
				res++;
		cout<<res<<endl;
	}
	
	return 0;
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const ll MOD=1e9+7;

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


int main(){
    int N; cin >> N;
    vi x(N), y(N);
    pii mx1={0, 0}, mx2={0, 0};
    pii mn1={LINF, 0}, mn2={LINF, 0};
    for(int i=0; i<N; i++){
        cin >> x[i] >> y[i];
        if(mx1.first < x[i]+y[i]){
            mx1={x[i]+y[i], i};
        }
        if(mx2.first < x[i]-y[i]){
            mx2={x[i]-y[i], i};
        }
        if(mn1.first > x[i]+y[i]){
            mn1={x[i]+y[i], i};
        }
        if(mn2.first > x[i]-y[i]){
            mn2={x[i]-y[i], i};
        }
    }

    ll ans=0;
    for(int i=0; i<N; i++){
        ll a=x[i]+y[i], b=x[i]-y[i];
        int id=mx1.second;
        ll c=x[id]+y[id], d=x[id]-y[id];
        ll dist=max(a-c, max(-a+c, max(b-d, -b+d)));
        id=mx2.second;
        c=x[id]+y[id], d=x[id]-y[id];
        chmax(dist, max(a-c, max(-a+c, max(b-d, -b+d))));
        id=mn1.second;
        c=x[id]+y[id], d=x[id]-y[id];
        chmax(dist, max(a-c, max(-a+c, max(b-d, -b+d))));
        id=mn2.second;
        c=x[id]+y[id], d=x[id]-y[id];
        chmax(dist, max(a-c, max(-a+c, max(b-d, -b+d))));
        chmax(ans, dist);
    }
    cout << ans << endl;
    return 0;
}

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

#define FASTIO ios::sync_with_stdio(NULL); cin.tie(NULL);
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define compination(x) ((x*(x-1))/2)
#define all(x) x.begin() , x.end()
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vch vector  <char>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define vss vector  <string>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define PI  3.141592654
#define OO (ll)1e18
using namespace std;
void ONLINE__JUDGE();

pii swapii( pii pr ){ return { pr.S , pr.F }; }
int dx[] = { 0  , 0  , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 , 0  , 0  , -1 , +1 , +1 , -1 };

const int mod = 7901;
const int MAX = 1e3 + 9;

ll x , y;
char arr[MAX][MAX];
bool ok[MAX][MAX];
queue < pii > q;

bool isOk( ll i , ll j )
{
    return i >= 0 && i < x && j >= 0 && j < y;
}

int main()
{
    cin >> x >> y;
    for ( int i = 0; i < x; ++i )
        for ( int j = 0; j < y; ++j )
        {
            cin >> arr[i][j];
            if ( arr[i][j] == '#' ) q.push( { i , j } ) , ok[i][j] = 1;
        }


    ll cnt = 0;
    while ( q.size() > 0 )
    {
        ll sz = q.size();
        while ( sz-- )
        {
            pii point = q.front(); q.pop();
            for ( int i = 0; i < 4; ++i )
            {
                ll a = point.F + dx[i];
                ll b = point.S + dy[i];
                if ( isOk( a , b ) && !ok[a][b] )
                {
                    ok[a][b] = 1; q.push( {a , b} );
                }
            }
        }
        if ( q.size() ) cnt++;
    }
    cout << cnt;
    return 0;
}

Measured memory_bytes: 18612
fun main(args: Array<String>) = IO().exec {
    val s = string()
    println(if (s.length == 2) s else s.reversed())
}

// region template
operator fun Int.iterator() = 0.until(this).iterator()

class IO {
    val printable = 33..126
    val buffer = ByteArray(1024)
    var ptr = 0
    var buflen = 0
    val out = java.io.PrintWriter(System.out)
    fun hasNextByte(): Boolean = if (ptr < buflen) true else {
        ptr = 0
        buflen = System.`in`.read(buffer)
        buflen > 0
    }

    fun readByte(): Byte = if (hasNextByte()) buffer[ptr++] else -1
    fun hasNext(): Boolean {
        while (hasNextByte() && buffer[ptr] !in printable) ptr++
        return hasNextByte()
    }

    fun string(): String {
        if (!hasNext()) throw java.util.NoSuchElementException()
        val sb = StringBuilder()
        var b = readByte()
        while (b in printable) {
            sb.appendCodePoint(b.toInt())
            b = readByte()
        }
        return sb.toString()
    }

    fun long(): Long {
        if (!hasNext()) throw java.util.NoSuchElementException()
        var n = 0L
        var minus = false
        var b = readByte()
        if (b == '-'.toByte()) {
            minus = true
            b = readByte()
        }
        if (b !in '0'.toByte()..'9'.toByte()) {
            throw NumberFormatException()
        }
        while (true) {
            if (b in '0'.toByte()..'9'.toByte()) {
                n *= 10
                n += b - '0'.toByte()
            } else if (b == (-1).toByte() || b !in printable) {
                return if (minus) -n else n
            } else {
                throw NumberFormatException()
            }
            b = readByte()
        }
    }

    fun int(): Int {
        val nl = long()
        if (nl !in Integer.MIN_VALUE..Integer.MAX_VALUE) throw NumberFormatException()
        return nl.toInt()
    }

    fun double(): Double = string().toDouble()
    fun print(obj: Any) = out.print(obj)
    fun print(i: Int) = out.print(i)
    fun print(l: Long) = out.print(l)
    fun println(obj: Any) = out.println(obj)
    fun println(i: Int) = out.println(i)
    fun println(l: Long) = out.println(l)
    inline fun exec(block: IO.() -> Unit) {
        block()
        out.flush()
    }
}
// endregion

Measured memory_bytes: 31268
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int MOD = 1000000007;

int row(int n) {
  if (n == 1) {
    return 2;
  } else if (n == 2) {
    return 3;
  } else {
    return row(n-1) + row(n-2);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  vector<int> bar(8, 0); // 1-based
  for (int i = 1; i <= 7; ++i) {
    bar[i] = row(i);
  }

  int h, w, k; cin >> h >> w >> k;

  vector<int> left(w+2, 0), center(w+2, 0), right(w+2, 0); // 1-based
  int temp[4];
  for (int i= 1; i <= w; ++i) {
    temp[0] = bar[max(w-2-i, 0)];
    temp[1] = bar[max(w-1-i, 0)];
    temp[2] = bar[max(i-2, 0)];
    temp[3] = bar[max(i-3, 0)];
    left[i] = max({temp[1], temp[3], temp[1] * temp[3], 1});
    center[i] = max({temp[2], temp[1], temp[2] * temp[1], 1});
    right[i] = max({temp[2], temp[0], temp[2] * temp[0], 1});
  }
  left[1] = 0;
  right[w] = 0;

  vector<vector<long long> > dp(h+1, vector<long long>(w+2, 0)); // 1-based
  dp[0][1] = 1;
  for (int i = 1; i < h+1; ++i) {
    for (int j = 1; j <= w; ++j) {
      dp[i][j] = (right[j-1] * dp[i-1][j-1]) % MOD + (center[j] * dp[i-1][j]) % MOD + (left[j+1] * dp[i-1][j+1]) % MOD;
      dp[i][j] %= MOD;
    }
  }
  cout << dp[h][k] << "\n";
  return 0;
}


Measured memory_bytes: 256