akhauriyash/Code-Regression huggingface dataset:
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll MOD=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  int N,K,A[100000];
  cin>>N>>K;
  for (int i(0);i<N;i++) cin>>A[i];
  cout << (N-1+K-2)/(K-1) << endl;
  return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
string s;
main(){
	cin>>s;
	if (s.length()>3){
		if (s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I') puts("Yes");
		else puts("No");

	}
	else puts("No");


}


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

using namespace std;

long long x[100000], y[100000];

long long tri[100001];

long long MOD = 1000000000 + 7;

int main()
{
	int N, M;
	scanf("%d%d", &N, &M);

	tri[0] = 0;
	for (int i = 1; i <= 100000; i++) {
		tri[i] = (tri[i-1] + i) % MOD;
	}

	for (int i = 0; i < N; i++) {
		scanf("%lld", &x[i]);
	}
	for (int i = 0; i < M; i++) {
		scanf("%lld", &y[i]);
	}
	long long xlen = 0, ylen = 0;
	for (int i = 0; i < N - 1; i++) {
		long long len = x[i + 1] - x[i];
		int iti = min(i, N - i - 2);
		xlen += len * ((((long long)N - 1) * (iti + 1) - (long long)tri[iti] * 2) % MOD) % MOD;
		xlen %= MOD;
	}
	for (int i = 0; i < M - 1; i++) {
		long long len = y[i + 1] - y[i];
		int iti = min(i, M - i - 2);
		ylen += len * ((((long long)M - 1) * (iti + 1) - (long long)tri[iti] * 2) % MOD) % MOD;
		ylen %= MOD;
	}
	printf("%lld\n", (xlen * ylen) % MOD);


	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <iomanip>
using namespace std;
#define rep(i, N) for (ll i = 0; i < (N); i++)
typedef long long ll;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
}

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

int main() {
  ll n;
  cin >> n;
  ll rt = sqrt(n);
  ll ans = n - 1;  // (1,n)
  for (ll i = 2; i <= rt; i++) {
    if (n % i) continue;
    ll I = i;
    ll J = n / i;
    ll dist = I + J - 2;
    ans = min(ans, dist);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int a;
    cin>>a;
    int ans=a+(a*a)+(a*a*a);
    cout<<ans<<endl;
}


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

vector<int> root;
vector<int> Rank;
vector<int> u_size;

int find(int x){
    if (root[x] == x) return x;
    root[x] = find(root[x]);
    return root[x];
}

bool check(int x, int y){
    return find(x) == find(y);
}

void Union(int x, int y){
    x = find(x); y = find(y);
    if (check(x, y)){
        return;
    }
    if (Rank[x] >= Rank[y]) 
    {
        u_size[x] += u_size[y];
        u_size[y] = 0;
        root[y] = x;
    }
    else 
    {
        u_size[y] += u_size[x];
        u_size[x] = 0;
        root[x] = y;
    }
    if (Rank[x] == Rank[y]) Rank[x]++;
}

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> set_root(n);
    for (int i = 0; i < n; i++) set_root[i] = i;
    root = set_root;
    vector<int> set_Rank(n, 0);
    Rank = set_Rank;
    vector<int> set_u_size(n, 1);
    u_size = set_u_size;
    vector<int> friend_cnt(n, 0);
    int u, v;
    for (int i = 0; i < m; i++){
        cin >> u >> v;
        u--; v--;
        friend_cnt[u]++;
        friend_cnt[v]++;
        Union(u, v);
    }
    for (int i = 0; i < k; i++)
    {
        cin >> u >> v;
        u--; v--;
        if (check(u, v)) friend_cnt[u]++, friend_cnt[v]++;
    }
    for (int i = 0; i < n; i++){
        cout << u_size[find(i)] - friend_cnt[i] - 1;
        if (i != n - 1) cout << " ";
    }
    cout << endl;
}

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


int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  for(int i=0;i<n;++i){
    string s;
    cin >> s;
    mp[s]++;
  }
  vector<string> ss;
  int ma=0;
  for(auto p : mp){
    if(ma<p.second){
      ss.clear();
      vector<string>().swap(ss);
      ss.push_back(p.first);
      ma=p.second;
    }else if(ma==p.second){
      ss.push_back(p.first);
    }
  }
  for(int i=0;i<ss.size();++i){
    cout << ss[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 26996
using namespace std;

#include <bits/stdc++.h>

int main(){
    int N;
    cin >> N;
    int a[N+7];
    int b[N];
    for ( int i = 0; i < N + 1; i ++ ){
        cin >> a[i];
    }
    for ( int i = 0; i < N; i ++ ){
        cin >> b[i];
    }
    long long ans = 0;
    for ( int i = 0; i < N; i ++ ){
        int p = min ( a[i], b[i] );
        ans += p;
        b[i] -= p;
        int k = min ( b[i], a[i + 1] );
        ans += k;
        a[i + 1] -= k;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
        int x[100];
        int a;
        int i,j,k,l,n,m,o;
        int count = 0;

        for(i=0;;i++){
                scanf("%d",&x[i]);
                if(x[i] == 0)
                        break;
        }
        for(j=0; j<i; j++){
                a = 1000 - x[j];
                if(a / 500){
                        a = a - 500;
                        count++;
                }
                if(a / 100){
                        int num = a / 100;
                        a = a - num*100;
                        count += num;
                }
                if(a / 50){
                        int num = a / 50;
                        a = a - num*50;
                        count += num;
                }
                if(a / 10){
                        int num = a / 10;
                        a = a - num*10;
                        count += num;
                }

                if(a / 5){
                        int num = a / 5;
                        a = a - num*5;
                        count += num;
                }
                if(a / 1){
                        int num = a / 1;
                        a = a - num*1;
                        count += num;
 
                }
                printf("%d\n",count);
                count = 0;
        }
 
        return 0;
}

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

int main(void){
  int n, A[100];
  cin >> n;
  for(int i=0; i < n; i++){
    cin >> A[i];
  }
  for(int i=1; i < n; i++){
    int key = A[i];
    int j = i - 1;
    for(int k = 0; k < n; k++){
      cout << A[k];
      if(k != n-1){
        cout << " ";
      }
    }
    cout << endl;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
  }
  for(int i=0; i < n; i++){
    cout << A[i];
    if(i != n-1){
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 1160
import sys
import heapq as h

input=sys.stdin.readline

N=int(input())
hen=[[] for i in range(0,N)]
for i in range(0,N-1):
    a,b=map(int,input().split())
    hen[a-1].append(b-1)
    hen[b-1].append(a-1)
mod=10**9+7

subtreesize=[1 for i in range(0,N)]
flag=[0 for i in range(0,N)]
q=[]
for i in range(1,N):
    if len(hen[i])==1:
        q.append(i)
        flag[i]=0

h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in hen[x]:
            if p!=0:
                if flag[p]!=len(hen[p])-1:
                    subtreesize[p]+=subtreesize[x]
                    flag[p]+=1
                    if flag[p]==len(hen[p])-1:
                        h.heappush(sub,p)
            else:
                subtreesize[p]+=subtreesize[x]
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break

ans=[0 for i in range(0,N)]
flag=[0 for i in range(0,N)]
q=[]
for i in range(1,N):
    if len(hen[i])==1:
        q.append(i)
        flag[i]=0

h.heapify(q)
sub=[]
h.heapify(sub)
while q!=[]:
    while q!=[]:
        x=h.heappop(q)
        for p in hen[x]:
            if p!=0:
                if flag[p]!=len(hen[p])-1:
                    ans[p]=(ans[p]+ans[x]-pow(2,subtreesize[x],mod)+1)%mod
                    flag[p]+=1
                    if flag[p]==len(hen[p])-1:
                        ans[p]=(ans[p]+pow(2,N-1,mod)-pow(2,N-subtreesize[p],mod))%mod
                        h.heappush(sub,p)
            else:
                ans[p]=(ans[p]+ans[x]-pow(2,subtreesize[x],mod)+1)%mod
        #何らかの操作
        #ここでsubキューに次に使うものを格納
        if q==[]:
            q=sub
            sub=[]
            h.heapify(sub)
            break


ans[0]=(ans[0]+pow(2,N-1,mod)-1)%mod
print((ans[0]*pow(2,(N*(mod-2)),mod))%mod)

Measured memory_bytes: 109048
// problem: "https://atcoder.jp/contests/abc147/tasks/abc147_b"

#include<bits/stdc++.h>

using namespace std;

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

    int i,j,c;
    c = 0;
    i = 0;
    j = s.size()-1;

    while(i < j)
    {
        if(s[i] != s[j])
            c++;

        i++;
        j--;
    }

    cout<<c;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;

int calc_digit(long long num) {
  int cnt = 0;
  while(num > 0) {
    num /= 10;
    cnt++;
  }
  return cnt;
}

int main() {
  long long N;
  cin >> N;
  int res = 100;
  for (long long a=1 ; a<=(int)sqrt(N) ; a++) {
    if (N%a == 0) {
      long long b = N/a;
      int f = max(calc_digit(a), calc_digit(b));
      res = min(res, f);
    }
  }
  cout << res << endl;
}


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

int main(){
int W,H, x,y,r;
cin>>W>>H>>x>>y>>r;
if(x-r>=0 && y-r>=0 && x+r<=W && y+r<=H){
cout<<"Yes"<<endl;
}
else{
cout<<"No"<<endl;
}
return 0;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s,t;
    cin >> s >> t;
    reverse(all(t));
    fp(s == t,"YES","NO");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	bool flg = false;
	for(int i = 0; i < 3; i++){
		char c;
		cin >> c;
		if(c == '7') flg = true;
	}
	if(flg)cout << "Yes";
	else cout << "No";
	
	cout << endl;
}

Measured memory_bytes: 3632
using System.Linq;
using System;
using System.IO;
using System.Collections.Generic;
using static System.Console;

class Program
{
  static void Main(string[] args) =>
    new Program().solve();

  private void solve()
  {
    var st = ReadLine().Split(' ');
    WriteLine(String.Join("",st.Reverse()));
  }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
const int maxn = 101,maxm = 51;
int P[maxn],T[maxn],V[maxn];
long long C[maxm][maxm];
double rst[maxn][maxm];
double tim[maxn][maxm];
const double eps = 1e-11;
//#define LOCAL
int main()
{
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif
    int n,m,l; scanf("%d%d%d",&n,&m,&l);
    C[0][0] = 1;
    for(int i = 1; i < maxm; i++){
        C[i][i] = C[i][0] = 1;
        for(int j = 1; j < i; j++){
            C[i][j] = C[i-1][j] + C[i-1][j-1];
        }
        //cout<<C[i][i/2]<<endl;
    }
    for(int i = 0; i < n; i++){
        scanf("%d%d%d",P+i,T+i,V+i);
    }
    int rt = 0;
    for(int i = 0; i < n; i++){
        double p = P[i]/100., t0 = l*1./V[i];
        for(int j = 0; j <= m; j++){
            rst[i][j] = C[m][j]*(pow(p,j))*(pow(1-p,m-j));
            tim[i][j] = t0+j*T[i];
        }
        //for(int j = 1; j <= m; j++){
       //     rst[i][j] += rst[i][j-1];
      //  }
    }
    for(int i = 0; i < n; i++){
        double ans = 0;
        for(int j = 0; j <= m; j++){
            double t = tim[i][j], wn = 1;
            for(int k = 0; k < n; k++){
                if(k == i) continue;
                double twn = 0;
                for(int j2 = m; j2 >= 0; j2--){
                    if(tim[k][j2] <= t) break;
                    twn += rst[k][j2];
                }
                wn *= twn;
            }
            ans += wn*rst[i][j];
        }
        printf("%lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1392
#include <stdio.h>

int main(void)
{
	/*?????°??£?¨?*/
	int r,c,i,j,sum;
	int data[101][101];
	
	/*??\???*/
	scanf("%d %d",&r,&c);
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d",&data[i][j]);
		}
	}
	
	/*??????*/
	for(i=0;i<r;i++){
		sum=0;
		for(j=0;j<c;j++){
			sum+=data[i][j];
		}
		data[i][c]=sum;
	}
	for(i=0;i<=c;i++){
		sum=0;
		for(j=0;j<r;j++){
			sum+=data[j][i];
		}
		data[r][i]=sum;
	}
	
	/*??????*/
	for(i=0;i<=r;i++){
		for(j=0;j<=c;j++){
			if(j) printf(" ");
			printf("%d",data[i][j]);
		}
		printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2044
$_=<>;
$C=y/C//;
$c=y/?//;
$%=1e9+7;
@3=(1,map$.=$.*3%$%,1..1e5);
$x=0;
/A/?++$A:!/C/?($x+=($A*$3[$a]+$a*$3[$a-1])%$%*(($C*$3[$c-=/\?/]+$c*$3[$c-1])%$%))%=$%:--$C,$a+=/\?/ for/./g;
print$x


Measured memory_bytes: 24960
#include<bits/stdc++.h>
using namespace std;
#define MAX 1000000007
int main(){
    int n;
    long long k; cin >> n >> k;
    pair<int, long long> p[n];
    for(int i = 0; i < n; i++){
        int a,b; cin >> a >> b;
        p[i] = make_pair(a,b);
    }
    sort(p,p+n);
    for(int i = 0; i < n; i++){
        if(p[i].second < k){
            k -= p[i].second;
        }else{
            cout << p[i].first << endl;
            return 0;
        }
    }
}

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

int main() {
    long long int t,n,i,j,k,l;
    long long int a[100001];
    char s[100001];
    scanf("%lld",&n);
    for(i=0;i<n;i++)
    {
        printf("ACL");
    }
	
	return 0;
}


Measured memory_bytes: 3828
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	const int MAXN=200005;
	typedef long long LL;
	int n,A[MAXN];
	void work()
	{
		while(scanf("%d",&n)!=EOF)
		{
			for(int i=1;i<=n;i++) scanf("%d",&A[i]);
			LL ans=0;int mx=A[1];
			for(int i=2;i<=n;i++)
			{
				if(mx>=A[i]) ans+=mx-A[i];
				else mx=A[i];
			}
			cout<<ans<<endl;
		}
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

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

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

const ll INF=1e18;
const int MOD=1e9+7;

int main(){
    int N; cin >> N;
    P len[N];
    for(int i=0;i<N;i++){
        ll x,l; cin >> x >> l;
        len[i]={x+l,x-l};
    }
    sort(len,len+N);
    ll cur=-INF;
    int ans=0;
    for(int i=0;i<N;i++){
        if(cur<=len[i].second){
            cur=len[i].first;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5176
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>
#include <ios>
#include <iomanip>

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

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTAG(a,n) sort(a,a+n,greater<>())
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;
typedef tuple<ll,ll,ll> Tl;

int atcoder(){
    //入力
    string s;
    cin >> s;
  if(s=="a" || s=="i" || s=="u" || s=="e" || s=="o") cout << "vowel" <<ENT;
  else cout << "consonant" <<ENT;
    return 0;
}

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


Measured memory_bytes: 256
# coding: utf-8
require "set"
s = gets.chop
k = gets.to_i

set = Set.new()

#部分文字列
0.step(s.length-1){|ii|
  len = ii + 5

  if (len >= s.length-1 )
    len = s.length-1
  end
  
  ii.step(len){|jj|
#    p s[ii..jj]
    set.add(s[ii..jj])
  }
}

#配列に変更
arr = []
set.each{|val|
  arr << val
}

#ソート
arr.sort!

#p arr
print arr[k-1] + "\n"


Measured memory_bytes: 4856
using System;
using System.Linq;

namespace AGC041
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(x => ulong.Parse(x)).ToArray();
            var N = input[0];
            var A = input[1];
            var B = input[2];

            ulong ans;
            if ((B - A) % 2 == 0)
                ans = (B - A) / 2;
            else
                ans = Math.Min(A - 1, N - B) + 1 + (B - A - 1) / 2;

            Console.WriteLine(ans);
        }
    }
}

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

typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ar array
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll mod = 1e9 + 7;
const ll inf = 2e9 + 5;
double PI = 3.14159265358979323846;

const int N = 1e5 + 5;
vvi dp(N, vi(3, 0));

void solve() {

    int n;
    cin >> n;
    int a[n], b[n], c[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + a[i];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + b[i];
        dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + c[i];
    }

    cout << max({dp[n-1][0], dp[n-1][1], dp[n-1][2]}) << endl;


}

int32_t main()
{
    IOS
    // int T; cin >> T; while (T--)
    solve();
    return 0;
}


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

using namespace std;

int main()
{
    int n, m, ans = 0;
    vector<int> l, r;
    cin >> n >> m;
    int upmin = n, lowmax = 0;

    l.resize(m+1);
    r.resize(m+1);
    for (int i = 1 ; i <= m; ++i) {
        cin >> l[i] >> r[i];
        if (l[i] > lowmax) lowmax = l[i];
        if (r[i] < upmin) upmin = r[i];
    }
    cout << max(upmin-lowmax+1, 0) << endl;
    return 0;
}

Measured memory_bytes: 1024
S = input()
len_S = len(S)

s = 0
for i in range(1<<(len_S-1)):
    t = S[0]
    for j in range(len_S-1):
        if (i>>j)%2:
            t += "+"
        t += S[j+1]
    s += eval(t)

print(s)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<int> x(m),y(m),a(n,1);
  vector<bool> p(n);
  int red=0;
  for(int i=0;i<m;i++){
    cin >> x[i] >> y[i];
  }
  p[0]=true;
  for(int i=0;i<m;i++){
    if(red==x[i]-1){
      red=y[i]-1;
    }
    if(p[x[i]-1]){
      p[y[i]-1]=true;
      if(a[x[i]-1]==1){
        p[x[i]-1]=false;
      }
    }
    a[x[i]-1]--;
    a[y[i]-1]++;
  }
  p[red]=true;
  int cnt=0;
  for(int i=0;i<n;i++){
    if(p[i]){
      cnt++;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1408
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N, X;
    cin >> N >> X;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    vector<int> L(N);
    rep(i,N) cin >> L.at(i);
    int c = 0;
    int D = 0;
    while (D <= X) {
        if (c >= N) {
            cout << N + 1 << endl;
            return 0;
        }
        D = D + L[c++];
    }
    cout << c << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 10000000000000007
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int h, w, ta;
char a[10][10];

signed main() {
	cin >> h >> w;
	rep(i, h) {
		rep(j, w) {
			cin >> a[i][j];
			if (a[i][j] == '#')ta++;
		}
	}
	if (ta == h + w - 1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	ggr
}

Measured memory_bytes: 256
from itertools import combinations
from bisect import bisect_left, bisect_right

N = int(input()) #2*10**3
L_list = [int(e) for e in input().split()]
index_list = [i for i in range(N)]

L_list.sort(reverse=False)
#print(L_list)

ans = 0

for i in range(0,N-1):
    for j in range(i+1,N):
        a = L_list[i]
        b = L_list[j]
        
        #a < b+c ∴a-b < c
        #b < c+a ∴b-a < c
        if a-b > 0:
            low_limit = a-b
        else:
            low_limit = b-a
        index_left = bisect_right(L_list, low_limit) #log(2*10**6)≒6.3

        #c < a+b
        index_right = bisect_left(L_list, a+b) #log(2*10**6)
        
        #print(a,b,low_limit,a+b)
        #print(L_list[index_left:index_right])
        
        OK_c = index_right - index_left
        
        if index_left <= i <= index_right:
            OK_c -= 1
        if index_left <= j <= index_right:
            OK_c -= 1
            
        #print(OK_c)
        ans += OK_c
    
print(ans//3)

Measured memory_bytes: 49628
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim M As Integer = NextInt()
        Dim X As Integer = NextInt()
        Dim Y As Integer = NextInt()

        Dim A As Integer = Integer.MinValue
        For i As Integer = 0 To N - 1
            A = Math.Max(A, NextInt())
        Next

        Dim B As Integer = Integer.MaxValue
        For i As Integer = 0 To M - 1
            B = Math.Min(B, NextInt())
        Next

        If A < B And A < Y And X < B Then Write("No ")
        WriteLine("War")
    End Sub

    Function B2I(ok As Boolean) As Integer
        If ok Then Return 1
        Return 0
    End Function

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


Measured memory_bytes: 19920
#include<bits/stdc++.h>
using namespace std;
#define NL            "\n"
#define _SAD()        ios::sync_with_stdio(0),cin.tie(0), cout.tie(0);
#define SZ(s)         s.size()
#define SRT(x,y)      sort(x,x+y)
#define REV(a,b)      reverse(a,a+b)
#define VSRT(x)       sort(x.begin(),x.end())
#define VREV(x)       reverse(x.begin(),x.end())
int main()
{
    _SAD()
    string s,k,p="+",e="=",ss="7",m="-";
    cin>>s;
    int x,y,z,a;
    a=s[0]-'0';
    x=s[1]-'0';
    y=s[2]-'0';
    z=s[3]-'0';
    if(a+x+y+z==7)
    {
        k+=s[0]+p+s[1]+p+s[2]+p+s[3]+e+ss;
        cout<<k<<NL;
    }
    else if(a-x-y-z==7)
    {
        k+=s[0]+m+s[1]+m+s[2]+m+s[3]+e+ss;
        cout<<k<<NL;
    }
    else if(a+x+y-z==7)
    {
        k+=s[0]+p+s[1]+p+s[2]+m+s[3]+e+ss;
        cout<<k<<NL;
    }
    else if(a+x-y+z==7)
    {
        k+=s[0]+p+s[1]+m+s[2]+p+s[3]+e+ss;
        cout<<k<<NL;
    }
    else if(a-x+y+z==7)
    {
         k+=s[0]+m+s[1]+p+s[2]+p+s[3]+e+ss;
         cout<<k<<NL;
    }
    else if(a-x-y+z==7)
    {
         k+=s[0]+m+s[1]+m+s[2]+p+s[3]+e+ss;
         cout<<k<<NL;
    }
    else if(a-x+y-z==7)
    {
         k+=s[0]+m+s[1]+p+s[2]+m+s[3]+e+ss;
         cout<<k<<NL;
    }
    else if(a+x-y-z==7)
    {
         k+=s[0]+p+s[1]+m+s[2]+m+s[3]+e+ss;
         cout<<k<<NL;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define x             first
#define y             second
#define sz(v)         (int)v.size()
#define all(x)        (x).begin(),(x).end()
#define PI            3.14159265358979
#define N             200005

const int mod=1e9+7;
int solve(){
    int n,ans=0; cin>>n;
    int pw[65];
    pw[0]=1;
    for(int i=1; i<=60; i++) pw[i]=(pw[i-1]*2)%mod;
    int a[n]; for(int i=0; i<n; i++) cin>>a[i];
    for(int j=0; j<=60; j++){
        int s=0;
        for(int i=0; i<n; i++){
            if(a[i]%2) s++;
            a[i]/=2;
        }
        ans=(ans+(((s*(n-s))%mod)*pw[j])%mod)%mod;
    }
    cout<<ans;
    return 0;
}

signed main() {
    ios::sync_with_stdio(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    // cin>>t;
    while(t--) solve();
    return 0;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int MAXN = 10 + 5;

char s[MAXN],t[MAXN];

int main(void)
{
	scanf("%s%s",s+1,t+1);
	for(int i=1; s[i]; ++i)
		if(s[i] != t[i])
		{
			printf("No\n");
			return 0;
		}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 1616
#include <stdio.h>

int main(){
    char num[4], i;
    scanf("%s", &num[i]);
    if(num[0]==num[1]&&num[1]==num[2]){
        printf("Yes\n");
    }else if(num[1]==num[2]&&num[2]==num[3]){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
//#define LOCAL_DEBUG

#include <fstream>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;


int main() {
#ifdef LOCAL_DEBUG
	freopen("input.txt","r", stdin);
#endif

	ll x; cin >> x;
	ll point = 0;
	ll cnt = x / 11 * 2;
	x %= 11;

	while (point < x) {
		if (cnt % 2 == 0)
			point += 6;
		else
			point += 5;

		cnt++;

	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
// 1_abc143_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
#define MOD (1000000007)
typedef long long ll;

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

    int a, b;
    cin >> a >> b;
    if(2 * b >= a) cout << 0 << endl;
    else cout << a - 2 * b << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int M = in.nextInt();

		System.out.println(48 - M);

	}

}


Measured memory_bytes: 21460
import sys

for line in sys.stdin:
    n = int(line)
    num = 0
    for a in range(0, 10):
        for b in range(0, 10):
            for c in range(0, 10):
                for d in range(0, 10):
                    if a+b+c+d == n:
                        num += 1

    print(num)

Measured memory_bytes: 7612
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int n=5,dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int a[n][n],d[n],m,ans;
bool check(int x,int y){return x>=0&&x<n&&y>=0&&y<n;}

void solve() {
  int b[n][n];
  rep(i,n)rep(j,n)b[j][n-i-1]=a[i][j];
  int c=1,e=0;
  while(1) {
    bool f=0,u[n][n];
    memset(u,0,sizeof(u));
    rep(i,n)rep(j,n) {
      if(!b[i][j]) continue;
      for(int k=2;k<4;k++) {
        int x=i,y=j,z=b[i][j],t=1;
        while(1) {
          x+=dx[k],y+=dy[k];
          if(!check(x,y)||z!=b[x][y])break;
          t++;
        }
        if(t>=3) {
          f=1,x=i,y=j,u[x][y]=1;
          while(1) {
            x+=dx[k],y+=dy[k];
            if(!check(x,y)||z!=b[x][y])break;
            u[x][y]=1;
          }
        }
      }
    }
    if(!f) break;
    rep(i,n){
      rep(j,n){
        if(!u[i][j])continue;
        e+=d[b[i][j]-1]*c;
        b[i][j]=0;
      }
      fill(remove(b[i],b[i]+n,0),b[i]+n,0);
    }
    c++;
  }
  ans=max(ans,e);
}

void dfs(int nx,int ny,int k) {
  if(k>m) return;
  solve();
  rep(i,4){
    int x=nx+dx[i],y=ny+dy[i];
    if(!check(x,y)) continue;
    swap(a[x][y],a[nx][ny]);
    dfs(x,y,k+1);
    swap(a[x][y],a[nx][ny]);
  }
}   

int main() {
  while(cin>>m&&m!=-1) {
    rep(i,n)rep(j,n)cin>>a[i][j];
    rep(i,n)cin>>d[i];
    ans=0;
    rep(i,n)rep(j,n)dfs(i,j,0);
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 1164
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int n,k,x[100],ans=0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++){
    scanf("%d",&x[i]);
    ans+=2*(min(x[i],k-x[i]));
  }
  printf("%d\n",ans);
}

Measured memory_bytes: 128
#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

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

signed main() {
	ll n, a, color[9] = {0}, cnt = 0;
  cin >> n;
  rep(i, n) {
    cin >> a;
    if (a < 3200) color[a / 400]++;
    else color[8]++;
  }
  rep(i, 8) if (color[i]) cnt++;
  if (!cnt) cout << 1 << " " << color[8] << endl;
  else cout << cnt << " " << cnt + color[8] << endl;
}

Measured memory_bytes: 256
import sys

Nstr = sys.stdin.readline().strip()

if Nstr[-1] in ("2", "4", "5", "7", "9"):
    print("hon")
elif Nstr[-1] in ("0", "1", "6", "8"):
    print("pon")
elif Nstr[-1] == "3":
    print("bon")

Measured memory_bytes: 9108
#include <iostream>
#include <math.h>

using namespace std;

int main(void)
{
	int a,b,c;
    long long k;
	cin >> a>>b>>c>>k;

    if(abs(a-b) < pow(10.0, 18.0)){
        if(k%2==0){
            cout << a-b << endl;
        }
        else{
            cout <<b-a <<endl;
        }
    }
    else{
        cout << "Unfair" << endl;
    }


	return 0;
}

Measured memory_bytes: 256
N=int(input())
V=list(map(int,input().split()))
C=list(map(int,input().split()))
sa=[]
for i in range(N):
    sa.append(V[i]-C[i])
sa_sort=sorted(sa,reverse=True)
ans=0
for i in range(N):
    if sa_sort[i]>0:
        ans=ans+sa_sort[i]
    else:
        break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std; 
string s;
int ans,num,a[150],x=1;
int main(){
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
    	if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') num++;
    	else ans=max(num,ans),num=0,a[x++]=num;
	}
	if(num+a[1]>ans) ans=num+a[1];
	cout<<ans;
	return 0;
} 

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

int main(){
	int n, r = 0, l = 0;
	cin >> n;
	string k;
	cin >> k;
	for(int i = 0; i < n; i++){
		if(k[i] == ')'){
			if(l > 0){
				l--;
			}else{
				r++;
			}
		}else if(k[i] == '('){
			l++;
		}
	}
	string right;
	for(int i = 0; i < r; i++){
		right.insert(0, "(");
	}
	string left;
	for(int i = 0; i < l; i++){
		left.insert(0, ")");
	}
	cout << right + k + left << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define min(a, b) ((a)>(b) ? (b) : (a))
#define abs(a) ((a)<0 ? -(a) : (a))

int tens(int d){
  int r = 1;
  while(d--){
    r *= 10;
  }
  return r;
}

int main(){
  int ans = 1000000;
  char s[12];  scanf("%s", s);
  int length = strlen(s);
  for(int i=0; i<length-2; i++){
    int num = 0;
    for(int j=0; j<3; j++){
      int tonum;
      for(int k=0; k<=9; k++){
	if(s[i+j] == '0'+k){
	  tonum = k;
	  break;
	}
      }
      num = num + tonum * tens(2 - j);
    }
    ans = min(ans, abs(num - 753));
  }
  printf("%d\n", ans);
      
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<vector>

using namespace std;
typedef long long ll;

ll ans,mx,sum,mn=1e8;
int main(){
	ll n,k;
	cin>>n>>k;
	vector< pair<ll,ll> > v;
	for(ll i=0; i<n; i++){
		ll a,b;
		cin>>a>>b;
		v.push_back(make_pair(a,b));
		
	}
	sort(v.begin(),v.end());
	for(ll i=0; i<n; i++){
		ans+=v[i].second;
		if(ans>=k){
			cout<<v[i].first<<endl;
			break;
		}
	}
}


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

int main() {

	int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;
	int sum = 0;
	if (h2 < h1) {
		h2 += 24;
	}		
	sum += (60 * h2 + m2) - (60 * h1 + m1) - k;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string a, b, c;
	cin >> a >> b >> c;
	char A = a[0] - 32, B = b[0] - 32, C = c[0] - 32;
	cout << A << B << C << endl;
	return 0;
}


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

int main(){
  int n;
  cin>>n;
  int sum=0;
  vector<int> d(n);
  for(int i=0;i<n;i++) cin>>d[i];
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      sum+=d[i]*d[j];
    }
  }
  cout<<sum<<endl;
}
    

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

#define endl ("\n")
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x)
#define println(x) cout << (x) << endl

template<typename Type>
Type gcd(const Type a,const Type b){return(b==0)?a:gcd(b,a%b);}
template<typename Type>
Type lcm(const Type a,const Type b){return(a/gcd(a,b))*b;}

template<typename Type>
void sort(vector<Type>& v){
	sort(all(v));
}

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

	int maxDist=K-(A[N-1]-A[0]);
	for(int i=0;i<N-1;i++){
		maxDist = max(maxDist, A[i+1]-A[i]);
	}
	cout << (K-maxDist);
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

const int N = 100000;
int n, k;
int h[N];

int32_t main() {

    cin >> n >> k;
    for(int i = 0; i < n; ++i) cin >> h[i];
    sort(h, h+n);
    
    int ans = 10000000000;
    for(int i = 0; i+k-1 < n; ++i) {
        int cand = h[i+k-1] - h[i];
        ans = min(ans, cand);
    }

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


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int m[105];

int main()
{
	int N, X;
	cin >> N >> X;
	REP(i, N)
	{
		cin >> m[i];
		X -= m[i];
	}

	sort(m, m + N);
	cout << N + X / m[0] << endl;
	return 0;
}

Measured memory_bytes: 256
#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 h, w, k; cin >> h >> w >> k;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    for (int i=0;i<(1<<h);i++) {
        vector<int> yoko(h, 0);
        for (int bit=0;bit<h;bit++) {
            if ((i>>bit)&1) {
                yoko[bit] = 1;
            }
        }

        for (int j=0;j<(1<<w);j++) {
            vector<int> tate(w, 0);
            for (int bit2=0;bit2<w;bit2++) {
                if ((j>>bit2)&1) {
                    tate[bit2] = 1;
                }
            }
            int cnt = 0;
            for (int x=0;x<h;x++) {
                for (int y=0;y<w;y++) {
                    if (s[x][y]=='#'&&yoko[x]==0&&tate[y]==0) {
                        cnt++;
                    }
                }
            }

            if (cnt == k) ans++;
        }
    }
    cout << ans;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) { return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b) { return a/gcd(a,b)*b;}

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define INF 1001001001

int main() {
  int n, m;
  cin >> n >> m;
  long a, b;
  vector< pair<int, int> > keys;
  rep(i, m) {
    cin >> a >> b;
    int s = 0;
    rep(j, b) {
      int c;
      cin >> c;
      c--;
      s |= 1 << c;
    }
    keys.emplace_back(s, a);
  }

  vector<int> dp(1<<n, INF);
  dp[0] = 0;
  rep(i, 1<<n) {
    rep(j, m) {
      int t = i | keys[j].first;
      int cost = dp[i] + keys[j].second;
      dp[t] = min(dp[t], cost);
    }
  }
  int ans = dp.back();
  if (ans == INF) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){

int a[1000];
int n;

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

int j;
for(j=n-1;j>-1;j=j-1)
    {cout<<a[j];
              if(j>0){cout<<" ";}
              if(j==0){cout<<endl;}
    }
}


Measured memory_bytes: 3072
S = input()
before = S[:2]
after = S[2:]
a = int(after)
b = int(before)

a_flg = False
b_flg = False
if 1 <= a and a <= 12:
  a_flg = True
if 1 <= b and b <= 12:
  b_flg = True

if b_flg and a_flg:
  print('AMBIGUOUS')
elif b_flg and not a_flg:
  print('MMYY')
elif not b_flg and a_flg:
  print('YYMM')
else:
  print('NA')

Measured memory_bytes: 3064
import java.util.Scanner;

/**
 * 
 * @author hiranoi
 *
 *         ?????????????????§??????????????????????????°??£?????? ???????????????????\?????????? 10 ???????????????????????????????????¨??????????????????????????¨???????????????
 *         ???????\???????????????±????????¨??? 5% ???????????????????????????????????????????????? 1,000 ?????????????????????????????????
 * 
 *         ??´??° n ?????\?????????n??±???????????????????????????????????????????????°?????????????????????????????????
 *
 */
public class Main {
    static final int DEBT = 100000;
    static final double PER = 1.05;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int week = Integer.parseInt(sc.nextLine());
        System.out.println(calcDebt(week));
    }

    private static int calcDebt(int week) {
        double nowDebt = DEBT; // ??¨??????????????????
        for (int i = 0; i < week; i++) {
            nowDebt = nowDebt * PER;
            nowDebt = (int) Math.ceil((double) nowDebt / 1000) * 1000;
        }
        return (int) nowDebt;
    }
}

Measured memory_bytes: 25960
#include <bits/stdc++.h>
#include <boost/functional/hash.hpp>

#define debug 0
#define esc(ret) cout << (ret) << endl,quick_exit(0)
#define fcout(d) cout << fixed << setprecision(d)
#define repU(i,s,t) for(int i = (int)(s); i <= (int)(t); ++i)
#define repD(i,s,t) for(int i = (int)(s); i >= (int)(t); --i)
#define rep(i,n) repU(i,0,(n) - 1)
#define rep1(i,n) repU(i,1,(n))
#define all(v) begin(v),end(v)
#define vct vector
#define prique priority_queue
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define ins insert
#define era erase
#define fir first
#define sec second
#define qceil(n,d) ((n) > 0 ? ((n) - 1) / (d) + 1 : (n) / (d))
#define parity(a,b) (a & 1 ^ b & 1 ^ 1)

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<db,int> pdi;
typedef tuple<int,int,int> tiii;

namespace std {
	template <> struct hash<pii> {
		size_t operator()(pii &x) { return boost::hash_value(x); }
	};
	template <> struct hash<tiii> {
		size_t operator()(tiii &x) { return boost::hash_value(x); }
	};
}

const int dir[][2] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int mod = 1e9 + 7;
const int inf32 = (1 << 30) - 1;
const ll inf64 = (1LL << 62) - 1;


ll N,M,Q,K,L,H,W,D;
string S;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	cin >> N >> K;
	vct<ll> neg,pos(1,0);
	int n = 0,p = 0;
	rep(i,N){
	    int a; cin >> a;
	    if(a > 0) pos.pub(a),p++;
	    if(a < 0) neg.pub(-a),n++;
	    if(!a) --K;
	}
	neg.pub(0);
	reverse(all(neg));
	if(!K) esc(0);
	ll ans = inf64;
	rep(i,K + 1){
	    if(p >= i && n >= K - i) ans = min(ans,pos[i] * 2 + neg[K - i]);
	   if(p >= i && n >= K - i) ans = min(ans,pos[i] + 2 * neg[K - i]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1656
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;

int main(){
    int a,b,c;cin>>a>>b>>c;
    int x=101;
    int y=0;
    x=min(a,b);
    x=min(x,c);
    y=max(a,b);
    y=max(y,c);
    cout<<y-x<<endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:128777216")

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>

#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>

#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <string.h>

#include <memory.h>
#include <cassert>
#include <time.h>
#include <functional>

using namespace std;

#define forn(i,n) for (int i = 0; i < (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define forab(i,a,b) for (int i = (int)(a); i <= (int)(b); i++)
#define forabd(i, b, a) for (int i = (int)(b); i >= (int)(a); i--)
#define forit(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)

#define _(a, val) memset (a, val, sizeof (a))
#define sz(a) (int)((a).size())
#define pb push_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()

typedef long long lint;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vii;

const lint LINF = 1000000000000000000LL;
const int INF = 1000000000;
const long double eps = 1e-9;
const long double PI = 3.1415926535897932384626433832795l;

#ifdef MY_DEBUG
#define dbgx( x ) { cerr << #x << " = " << x << endl; }
#define dbg( ... ) { fprintf(stderr, __VA_ARGS__); fflush(stderr); }
#else
#define dbgx( x ) {  } 
#define dbg( ... ) {  } 
#endif

void prepare(string s) {
#ifdef MY_DEBUG
  freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#else
  //freopen("input.txt", "r", stdin);
  //freopen ("output.txt", "w", stdout);
#endif
}

int n;
int a[105][2];
int b[105][2];

int g[105][105];
int mt[105];
int used[105];

bool dfs(int v) {
  if (used[v])
	  return false;
  used[v] = 1;
  forn(i, n) {
	if (g[v][i]) {
		if (mt[i] == -1 || dfs(mt[i])) {
			mt[i] = v;
			return true;
		}
	}
  }
  return false;
}

void read() {
  scanf("%d", &n);
  forn(i, n) {
    scanf("%d %d", &a[i][0], &a[i][1]);
  }
  forn(i, n) {
    scanf("%d %d", &b[i][0], &b[i][1]);
  }
}

void solve() {
  forn(i, n) {
    forn(j, n) {
      if (a[i][0] < b[j][0] && a[i][1] < b[j][1]) {
        g[i][j] = 1;
      } else {
        g[i][j] = 0;
      }
    }
  }
  _(mt, -1);
  int ans = 0;
  forn(i, n) {
    _(used, 0);	  
    if (dfs(i)) {
	ans++;
    }
  }
  printf("%d\n", ans);
}

int main() {
  prepare("");

  read();
  solve();
  dbg("Clock = %.3f\n", clock() / (double)CLOCKS_PER_SEC);
  return 0;
}

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

int main()
{
  int N = 0, tmp = 0;
  cin >> N;
  
  vector<int> nums;
  
  for(int i = 0; i < N; i++)
  {
    cin >> tmp;
    nums.push_back(tmp);
  }
  
  sort(nums.begin(), nums.end(), greater<int>() );
  
  int sum = 0;
  for(int i = 1; i < N; i++)
  {
    sum += nums[i];
  }
  
  if(nums[0] < sum)
  {
    cout << "Yes";
  }
  else
  {
    cout << "No";
  }
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
int n, k;
int g[12];
int memo[2048][12];
vector<int> c[12];
int solve(int i, int j){
  int res = 0, m = 0;
  if(memo[i][j]) return memo[i][j];
  if(i >= k || j > 10) return 0;
  for(int l = 0;l < g[j]; l++){
    m += c[j][l] + 2 * l;
    if(i + l + 1 > k) break;
    res = max(res, solve(i + l + 1, j + 1) + m);
  }
  res = max(res, solve(i, j + 1));
  return memo[i][j] = res;
}
int main(void){
  int C, G;
  scanf("%d %d", &n, &k);
  for(int i = 0;i < n; i++){
    scanf("%d %d", &C, &G);
    c[G].push_back(C);
    g[G]++;
  }
  for(int i = 1;i <= 10; i++){
    sort(c[i].begin(), c[i].end());
    reverse(c[i].begin(), c[i].end());
  }
  
  printf("%d\n", solve(0, 1));
}


Measured memory_bytes: 1160