akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = input()
    if "7" in n:
        print("Yes")
    else:
        print("No")
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 65444
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int n,m;
int stone[155][11][2];
int dp[155][11][76];
int num[155];
int main(){
	while(scanf("%d %d",&n,&m) && n){
		for(int i=1;i<=n;i++){
			scanf("%d",&num[i]);
			for(int g=1;g<=num[i];g++){
				scanf("%d %d",&stone[i][g][0],&stone[i][g][1]);
			}
		}
		for(int i=0;i<155;i++){
			for(int j=0;j<11;j++){
				for(int k=0;k<=m;k++){
					dp[i][j][k]=INF;
				}
			}
		}
		for(int j=1;j<=num[1];j++){
			for(int k=0;k<=m;k++){
				dp[1][j][k]=0;
			}
		}
		for(int j=1;j<=num[2];j++){
			for(int k=1;k<=m;k++){
				dp[2][j][k]=0;
			}
			for(int y=1;y<=num[1];y++){
				dp[2][j][0]=min(dp[2][j][0],dp[1][y][0]+abs(stone[1][y][0]-stone[2][j][0])*(stone[1][y][1]+stone[2][j][1]));
			}
		}
		int ans=INF;
		for(int i=3;i<=n;i++){
			for(int j=1;j<=num[i];j++){
				for(int k=0;k<=m;k++){
					for(int g=1;g<=num[i-1];g++){
						dp[i][j][k]=min(dp[i][j][k],dp[i-1][g][k]+abs(stone[i][j][0]-stone[i-1][g][0])*(stone[i][j][1]+stone[i-1][g][1]));
					}
					if(k!=0){
						for(int l=1;l<=num[i-2];l++){
							dp[i][j][k]=min(dp[i][j][k],dp[i-2][l][k-1]+abs(stone[i][j][0]-stone[i-2][l][0])*(stone[i][j][1]+stone[i-2][l][1]));
						}
					}
				}
			}
		}
		int res=INF;
		for(int j=1;j<=num[n];j++){
			for(int k=0;k<=m;k++){
			res=min(res,dp[n][j][k]);
			}
		}
		for(int j=1;j<=num[n-1];j++){
			for(int k=0;k<m;k++){
			res=min(res,dp[n-1][j][k]);
			}
		}
		printf("%d\n",res);
	}
}

Measured memory_bytes: 1708
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int a = sc.nextInt();
		int b = sc.nextInt();
		String u = sc.next();
		sc.close();

		if(u.equals(s)){
			a--;
		}else{
			b--;
		}
		System.out.println(a + " " + b);
	}
}


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

bool t[100010];
int memo[100010];
int n, m;
const int MOD = int(1e9 + 7);
int dp(int pos) {
    if (pos == n) return 1;
    if (pos > n || t[pos]) return 0;
    if (memo[pos] != -1) return memo[pos];
    int x = dp(pos + 1) % MOD;
    int y = dp(pos + 2) % MOD;
    return memo[pos] = (x + y) % MOD;
}


int main() {
    cin >> n >> m;
    for(int i = 0; i < m; i++) {
        int x;
        cin >> x;
        t[x] = true;
    }
    t[n + 1] = true;
    t[n + 2] = true;
    t[n + 3] = true;
    memset(memo, -1, sizeof(memo));
    int ans = dp(0) % MOD;
    ans = (ans + MOD) % MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 3840
# -*- coding: utf-8 -*-

n, m = map(int, input().split())
x = set(map(int, input().split()))

x = sorted(x)

dist = [0]*(m-1)
for i in range(m-1):
    dist[i] = x[i+1] - x[i]

dist = sorted(dist, reverse=True)

print(sum(dist[n-1:]))

Measured memory_bytes: 18960
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <bitset>
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)

using namespace std;
typedef long long ll;
const ll MOD=1e9+7;

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

    ll i,j,h;
    ll Q,M,K,P,A,B,C,N,X;

    long double x;

    string S;

    vector<ll>  aa;

    cin >>K>>S;

    if(S.size()<=K)cout<<S<<endl;
    else cout<<S.substr(0,K)+"..."<<endl;
    
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
   ll a,b;
   cin>>a>>b;
   ll arr[a];
   for(ll i=0;i<a;i++){
       cin>>arr[i];
   }
   sort(arr,arr+a,greater<int>());
   ll sum=0;
   for(ll i=b;i<a;i++){
       sum+=arr[i];
   }
   cout<<sum;
    
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;
// int n = 7;  int a[] = {4,2,5,3,5,8,3}; sort(a,a+n)
int main() {
    int a, b;
    cin >> a >> b;
    int g;
    int l;
    if(a >= b){
        g = a;
        l = b;
    } else{
        g = b;
        l = a;
    }
    for(int i = 0; i < g; i++){
        cout << l; 
    }
    return 0;
}

Measured memory_bytes: 3472
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <cmath>
#include <sstream>
#include <stack>
//#include <unordered_map>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<unsigned, unsigned> uu;
typedef pair<ll, ll> l4;


#define pb push_back
#define mp make_pair

int n, cnt[3];
inline bool solve()
{
  if (cnt[2] == 0)
    return cnt[0] == 0 && cnt[1] != 1;
  if (cnt[1] != 0)
    cnt[0] += 1;
  return cnt[0]-1 <= cnt[2];
}
int main()
{
  memset(cnt, 0, sizeof(cnt));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    {
      int x;
      scanf("%d", &x);
      if (x%2 == 1)
	cnt[0] += 1;
      else if (x%4 == 2)
	cnt[1] += 1;
      else
	cnt[2] += 1;
    }
  puts(solve()?"Yes":"No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define endl "\n"
#define fr(i, n) for (int i = 0; i < n; i++)
#define frf(i, j, n) for (int i = j; i <= n; i++)
#define frd(i, n) for (int i = n; i >= 0; i--)
#define mp(i, j) make_pair(i, j)
#define pb(x) push_back(x)
using namespace std;
int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    ll t = ((h2 * 60) + m2) - ((h1 * 60 + m1) + k);
    cout<<t;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <stack>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, nuint_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set; 
#define int long long
#define MOD 1000000007
#define what_is(x) cerr << #x << " is " << x << endl;
#define loop(i,a,n) for(int i=a;i<n;i++)

#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, szof(x))
#define sortall(x) sort(aint(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
typedef pair<int, int> pt;
unordered_map<int, int> used;
 
int arr[200010],q;
vector<int> arr1(200010);

signed main() {
	
	fastio();
	//#define LOCAL_DEFINE
	#ifdef LOCAL_DEFINE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	//https://codeforces.com/contest/1084/problem/D
	int n;
	cin >> n;
	vector<int> as(n), rs(n), ls(n);
	for (int i = 0; i < n; i++)
	{
		cin >> as[i];
	}
	ls[0] = as[0];
	for (int i = 1; i < n; i++)
	{
		ls[i] = __gcd(ls[i-1], as[i]);
	}
	rs[n-1] = as[n-1];
	for (int i = n-2; i >= 0; i--)
	{
		rs[i] = __gcd(rs[i+1], as[i]);
	}
	int ans = max(ls[n-2], rs[1]);
	for (int i = 0; i < n-2; i++)
	{
		ans = max(ans, __gcd(ls[i], rs[i+2]));
	}
	cout << ans << endl;
	return  0;


}


Measured memory_bytes: 4224
n=int(input())
p=list(map(int,input().split()))
ans=0
for i in range(n-1):
  if p[i]==i+1:
    ans+=1
    x,y=p[i+1],p[i]
    p[i+1],p[i]=y,x
  if i==n-2:
    if p[-1]==n:
      ans+=1
print(ans)



Measured memory_bytes: 14008
#include <bits/stdc++.h>
#define m_k make_pair
#define inf 0x3f3f3f3f
using namespace std;
const int N=2*1e5+100;
int n,k,a[N],ans;
int main()
{
	scanf("%d%d",&k,&n);
	for (int i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	ans=k+a[1]-a[n];
	for (int i=2;i<=n;i++) ans=max(ans,a[i]-a[i-1]);
	printf("%d\n",k-ans);
}

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

using namespace std;

int H, W;
vector<string> A(1010);
vector<vector<int>> D(1010,vector<int>(1010,-1));

// int bfs(int i, int j) {
//     int ret = 5000;
//     queue<pair<int,int>> Q;
//     C[i][j] = 1;
//     Q.push(make_pair(i,j));
//     while (!Q.empty()) {
//         int m = Q.front().first, n = Q.front().second;
//         Q.pop();
//         if (A[m][n] == '#') ret = min(ret, abs(m-i)+abs(n-j));
//         if (m>0) if (!C[m-1][n] && A[m-1][n] != '#') {
//             Q.push(make_pair(m-1,n));
//             C[m-1][n] = 1;
//         }
//         if (m+1<H) if (!C[m+1][n] && A[m+1][n] != '#') {
//             Q.push(make_pair(m+1,n));
//             C[m+1][n] = 1;
//         }
//         if (n>0) if (!C[m][n-1] && A[m][n-1] != '#') {
//             Q.push(make_pair(m,n-1));
//             C[m][n-1] = 1;
//         }
//         if (n+1<W) if (!C[m][n+1] && A[m][n+1] != '#') {
//             Q.push(make_pair(m,n+1));
//             C[m][n+1] = 1;
//         }
//     }
//     // cout << "bfs(" << i << "," << j << "): " << ret << endl;
//     return ret;
// }

int main(void) {
    queue<pair<int,int>> Q;
    int dy[4] = {-1, 0,1,0};
    int dx[4] = { 0,-1,0,1};

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

    for (int i=0;i<H;i++) for (int j=0;j<W;j++) {
        if (A[i][j] == '#') {
            Q.push(make_pair(i,j));
            D[i][j] = 0;
        }
    }
    while (!Q.empty()) {
        int m = Q.front().first, n = Q.front().second;
        Q.pop();
        for (int i=0;i<4;i++) {
            int k = m+dy[i], l = n+dx[i];
            if (k>=0 && k<H && l>=0 && l<W && D[k][l] == -1) {
                Q.push(make_pair(k,l));
                D[k][l] = D[m][n] + 1;
            }
        }
    }

    int m=-1;
    for (int i=0;i<H;i++) for (int j=0;j<W;j++) {
        m = max(m,D[i][j]);
    }
    cout << m << endl;

    return 0;
}

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

int main(){
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll H,W;
	cin>>H>>W;
    string S[H];
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    vector<vector<ll>> mp(H+2,vector<ll>(W+2));
    for(int i=0;i<=H+1;i++){
        for(int j=0;j<=W+1;j++){
            if(i==0||j==0||i==H+1||j==W+1){
                mp[i][j]=1;
            }else{
                if(S[i-1][j-1]=='#') mp[i][j]=1;
            }
        }
    }
    // for(int i=0;i<=H+1;i++){
    //     for(int j=0;j<=W+1;j++){
    //         cout<<mp[i][j];
    //     }
    //     cout<<"\n";
    // }
    
    typedef pair<ll,ll> P;
    ll m=0,x,y,dx[]= {1,-1,0,0},dy[] = {0,0,1,-1},ans=0;
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(mp[i][j]!=0) continue;
            ll dist[25][25]= {};
            queue<P> qu;
            qu.push(P{i,j});
            dist[i][j]= 1;
            // cout<<i<<j<<"\n";
            while(!qu.empty()){
                tie(x,y)= qu.front();qu.pop();
                for(int k=0;k<4;k++){
                    int nx = x+dx[k],ny = y+dy[k];
                    if(dist[nx][ny]!=0||mp[nx][ny]!=0) continue;
                    dist[nx][ny]= dist[x][y]+1;
                    m = max(m,dist[nx][ny]);
                    qu.push(P{nx,ny});
                }
            }
            ans = max(ans,m-1);
        }
    }
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int N = sc.nextInt();

        System.out.println(solve(N) ? "Yes" : "No");

        sc.close();
    }

    static boolean solve(int N) {
        return String.valueOf(N).indexOf('9') >= 0;
    }
}

Measured memory_bytes: 21716
--http://www.nct9.ne.jp/m_hiroi/light/lua04.html

function member(x, ary)
    for i = 1, #ary do
        if x == ary[i] then return true end
    end
    return false
end
  
function permutations(fn, n, m, a)
    if #a == m then
       fn(a)
    else
        for x = 1, n do
            if not member(x, a) then
                table.insert(a, x)
                permutations(fn, n, m, a)
                table.remove(a)
            end
        end
    end
end

----------

local n,m,r=io.read("n","n","n")
local town={}
for i=1,r do
    town[i]=io.read("n")
end

local disttable={}
local INF=10^13
for i=1,n do
    disttable[i]={}
    for j=1,n do
        disttable[i][j]=(i==j and 0 or INF)
    end
end

for i=1,m do
    local a,b,c=io.read("n","n","n")
    disttable[a][b]=c
    disttable[b][a]=c
end

for k=1,n do
    for i=1,n do
        for j=1,n do
            disttable[i][j]=math.min(disttable[i][j],disttable[i][k]+disttable[k][j])
        end
    end
end

local distsum={}

permutations(
    function(list)
        local dist=0
        for i=1,#list-1 do
            local cur=town[list[i]]
            local nxt=town[list[i+1]]
            dist=dist+disttable[cur][nxt]
        end
        table.insert(distsum,dist)
    end, 
    r, 
    r, 
    {}
)

local totaldist=10^13
for i=1,#distsum do
    totaldist=math.min(totaldist,distsum[i])
end
print(totaldist)

Measured memory_bytes: 3424
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> v[200010];
map<pair<int, int>, bool> mp;
int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, N;
    cin >> H >> W >> N;
    int x[200010], y[200020];
    rep(i, N) cin >> x[i] >> y[i];
    rep(i, N) mp[{x[i], y[i]}] = true;
    rep(i, N) {
        v[y[i]].push_back(x[i]);
    }
    rep(i, W) v[i + 1].push_back(H + 1);
    rep(i, W) sort(v[i + 1].begin(), v[i + 1].end());
    // rep(i, W) {
    //     cout << i + 1 << ":";
    //     for(auto e: v[i + 1]) cout << e << " ";
    //     cout << endl;
    // }
    int ans = H;
    int X = 1, Y = 1;
    rep(i, H) {
        if (X == H) break;
        if (mp[{X, Y}]) break;
        ans = min(ans, *lower_bound(v[Y].begin(), v[Y].end(), X) - 1);
        
        X++;
        if (mp[{X, Y}]) break;
        if (mp[{X, Y + 1}]) continue;
        if (Y == W) continue;
        Y++;
        //cout << X << " " << Y << " " << *lower_bound(v[Y].begin(), v[Y].end(), X) << endl;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 45952
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

#define size_t int

using namespace std;
typedef long l;
typedef long long ll;

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

  int N,K,X,Y;
  std::cin >> N >> K >> X >> Y;
  std::cout << X*N*(N < K) + K*X*(!(N < K)) + (N-K)*Y*(N-K > 0)  << '\n';

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <set>
#include <sstream>
using namespace std;
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort(ALL(x))
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
const int INF = 1001001001;
const ll MOD = 1e9+7;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){std::fill((T*)array, (T*)(array+N),val);}

class CompareDist
{
public:
    bool operator()(PLL n1,PLL n2) {
				if(n1.first!=n2.first) return n1.first<n2.first;
				else return n1.second<n2.second;
    }
};


__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main(){
	int n; cin>>n;
  VL a(n); rep(i,n) cin>>a[i];
  VL cnt(n+1); rep(i,n+1) cnt[i]=0;
  if(a[0]!=0) return cout << 0 << endl,0;

  ll ans = 3;
  cnt[1] = 1;
  cnt[0] = 2;
  reps(i,n-1){
    ans *= cnt[a[i]];
    cnt[a[i]+1]++; cnt[a[i]]--;
    ans = (ans+MOD)%MOD;
    // cerr << ans << ' ';
  }
  cerr << endl;
  cout << ans << endl;




  return 0;
}


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

using namespace std;
long long N,M;
struct Veb{
  long long A,B;
};

vector<Veb > v;

bool com(Veb v1, Veb v2) {
  if(v1.A < v2.A) return true;
  else return false;
}



int main() {
  long long a,b;
  ios::sync_with_stdio(false);
  cin >> N >> M;
  Veb tmp;
  for(int i = 0; i < N; i++) {
    cin >> a >> b;
    tmp.A = a;
    tmp.B = b;
    v.push_back(tmp);
  }
  sort(begin(v), end(v), com);

  long long s = 0;
  long long honsu = 0;
  int i = 0;
  for(i = 0; i < N; i++){
    s += v[i].A*v[i].B;
    honsu += v[i].B;
    if(honsu >= M){
      s -= v[i].A*v[i].B;
      honsu -= v[i].B;
      break;
    }
  }
  long long diff = M - honsu;
  s += diff*v[i].A;
  cout << s;
}


Measured memory_bytes: 2420
#include <iostream>
#include <queue>
using namespace std;
int main(){
  string sa,sb,sc;
  cin >> sa >> sb >> sc;
  queue<char> a,b,c;
  for(int i=0;i<sa.size();i++) a.push(sa[i]);
  for(int i=0;i<sb.size();i++) b.push(sb[i]);
  for(int i=0;i<sc.size();i++) c.push(sc[i]);

  char t = 'a';
  bool flag = true;
  while(flag){
    switch(t){
      case 'a':
        if(a.empty()){
          t = 'A';
          flag = false;
          break;
        }
        t = a.front();
        a.pop();
        break;
      case 'b':
        if(b.empty()){
          t = 'B';
          flag = false;
          break;
        }
        t = b.front();
        b.pop();
        break;
      case 'c':
        if(c.empty()){
          t = 'C';
          flag = false;
          break;
        }
        flag = !c.empty();
        t = c.front();
        c.pop();
        break;
    }
  }

  cout << t << "\n";
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  int N; cin >> N;
  ll A[N+1]; rep(i,N+1) cin >> A[i];
  if (N==0) {
    ll result = A[0]==1 ? 1 : -1;
    cout << result << endl; return 0;
  }
  else if (A[0]>=1) { cout << -1 << endl; return 0; }

  ll ma[N+1] = {}, mi[N+1] = {};
  per(i,N+1) {
    if (i==N) { ma[N] = A[N], mi[N] = A[N]; }
    else {
      mi[i] = (mi[i+1]+1)/2 + A[i];
      ma[i] = ma[i+1] + A[i];
    }
  }
  // debug(ma,ma+(N+1)); debug(mi,mi+(N+1));

  if (mi[0]!=1) { cout << -1 << endl; return 0; }
  ll result = 0, now = 1;
  rep(i,N) {
    result += now;
    // cout << result << " " << now << endl;
    now = min(ma[i+1], now*2-A[i]*2);
  }
  result += A[N];

  cout << result << endl;
  return 0;
}

Measured memory_bytes: 5968
// Author: Sayantanu
#include <bits/stdc++.h>

using namespace std;

#define ll long long int
const int mod = 1e9 + 7;
#define INF INT_MAX

int main() {
    //code
    int n;
    cin>>n;
    int dp[n][3];
    int a,b,c;
    cin>>a>>b>>c;
    dp[0][0] = a;
    dp[0][1] = b;
    dp[0][2] = c;
    for(int i=1;i<n;i++){
        cin>>a>>b>>c;
        dp[i][0] = a + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c + max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
    return 0;
}

Measured memory_bytes: 4772
#include <iostream>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
using namespace std;


int main() {

	int n, m;

	cin >> n >> m;
	vector<int> a(m);
	int ans = 0;
	for (int i = 0; i < m; i++) {
		cin >> a.at(i);
		ans += a.at(i);
	}

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



}

Measured memory_bytes: 3616
#include <iostream>

using namespace std;

#ifndef ONLINE_JUDGE
  #include <fstream>
  #define cin fin
  #define cout fout
  ifstream fin ("test.in");
  ofstream fout ("test.out");
#endif

int p[10];
int n, m, q;
int a[60], b[60], c[60], d[60];

int f (int i, int fn) {
  if (i == n) {
    int ans = 0;
    //for (int j = 0; j < n; j++)
      //cout << p[j] << ' ';
    for (int j = 0; j < q; j++) {
      if (p[b[j]] - p[a[j]] == c[j])
        ans += d[j];
    }
    //cout << ans << endl;
    return ans;
  }
  int ans = 0;
  for (int j = fn; j <= m; j++) {
    p[i] = j;
    ans = max (ans, f(i + 1, j));
  }
  return ans;
}

int main() {
  cin >> n >> m >> q;
  for (int i = 0; i < q; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  for (int i = 0; i < q; i++) {
    a[i]--; b[i]--;
  }
  cout << f (0, 1) << endl;
  return 0;
}


Measured memory_bytes: 3188
n,m=map(int,input().split())
l=[]
for i in range(m):
  a,b=map(int,input().split())
  l.append([a,b])
for i in range(10**n):
  x=str(i)
  if len(x)<n:pass
  else:
    c=0
    for i in range(m):
      if x[l[i][0]-1]==str(l[i][1]):
        c+=1
    if c==m:
      print(x)
      quit()
print(-1)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
char ch[110][210];
int pn[110];
char ans[2010];
long long num[2010];
int N,M;long long K;
int st['z'+1][110][210];
int tp['z'+1][110];
long long oo;
long long S[110][210];
int main()
{
    int i,j,k,o;oo=1;for(i=0;i<18;i++)oo*=10;oo+=1;
    scanf("%d%d%lld",&N,&M,&K);
    for(i=0;i<N;i++)
    {
        scanf("%s",ch[i]);
        pn[i]=strlen(ch[i]);
    }

    for(i=0;i<N;i++)
    {
        for(j=0;j<pn[i];j++)
        {
            st[ch[i][j]][i][tp[ch[i][j]][i]++]=j;
        }
    }

    num[0]=1;
    for(i=1;i<=M;i++)
    {
        for(j=0;j<N;j++)
        {
            if(i>=pn[j]) num[i]+=num[i-pn[j]];
            if(num[i]>oo) num[i]=oo;
        }
    }
    long long s=0;
    long long last=1;
    int t;
    for(i=0;i<M;i++)
    {
        for(j='a';j<='z';j++)
        {
            s=0;
            for(k=0;k<N;k++)
            {
                for(o=0;o<tp[j][k];o++)
                {
                    t=st[j][k][o];
                    if(t>0)
                    {
                        if(ch[k][t-1]==ans[i-1]&&M-i>=pn[k]-t)
                        {
                            //cout<<S[k][t-1]<<"   "<<num[M-i-(pn[k]-t)]<<endl;
                            if((double)S[k][t-1]*(double)(num[M-i-(pn[k]-t)])>(double)(oo+oo/10)) s=oo;
                            else
                            {
                                s+=S[k][t-1]*num[M-i-(pn[k]-t)];
                                if(s>oo) s=oo;
                            }
                        }
                    }
                    else
                    {
                        if(M-i>=pn[k]-t)
                        {
                            if((double)last*(double)(num[M-i-(pn[k]-t)])>(double)(oo+oo/10)) s=oo;
                            else
                            {
                                s+=last*num[M-i-(pn[k]-t)];
                                if(s>oo) s=oo;
                            }
                        }
                    }
                }
            }
            //cout<<s<<endl;
            if(K>s) K-=s;
            else break;
        }
       //cout<<K<<"  "<<ans[i]<<endl;
        if(j>'z')
        {
            printf("-\n");
            return 0;
        }
        ans[i]=j;
        for(k=0;k<N;k++)
        {
            for(o=pn[k]-1;o>0;o--)
            {
                if(i>0&&ch[k][o]==j&&ch[k][o-1]==ans[i-1])
                {
                    S[k][o]=S[k][o-1];
                }
                else S[k][o]=0;
            }
        }
        for(k=0;k<N;k++)
        {
            if(ch[k][0]==j) S[k][0]=last;
            else S[k][0]=0;
        }
        last=0;
        for(k=0;k<N;k++)
        {
            if(ch[k][pn[k]-1]==j)
            {
                last+=S[k][pn[k]-1];
                if(last>oo) last=oo;
            }
        }

    }
    ans[M]=0;
    printf("%s\n",ans);
    return 0;
}

Measured memory_bytes: 4476
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 1e9 + 7;
const int N = 5e5 + 5;
int n,m,k,s;
int a[N];

int main(){
    scanf("%d%d%d",&n,&k,&s);
    rep(i,1,k) a[i]=s;
    rep(i,k+1,n){
        if(s>5) a[i]=s-1;
        else a[i]=s+1;
    }
    rep(i,1,n) printf("%d%c",a[i],i==n?'\n':' ');
    return 0;
}
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

#define MAX_N 100
#define MAX_W 10000

void solve();

int N, W;
int v[MAX_N + 1], w[MAX_N + 1];
int dp[MAX_N + 1][MAX_W + 1];

int main() {

    cin >> N >> W;

    //??????0
    v[0] = 0;
    w[0] = 0;

    //??????1~
    for (int i = 1; i <= N; i++) {
        cin >> v[i] >> w[i];
    }

    solve();
    cout << dp[N][W] << endl;

    return 0;
}

void solve(){
    for (int i = 1; i <= N; i++) {          //??????1??????????????????
        for (int j = 0; j <= W; j++) {
            /* ????????? */
	  if(w[i]<=j){//??\?????´???
	    dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+v[i]);
	  }else{
	    dp[i][j]=dp[i-1][j];
	  }
	 // cout <<"dp["<<i<<"]["<<j<<"]="<< dp[i][j]<<endl;
        }
    }
}

Measured memory_bytes: 7008
import java.util.Scanner;

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

        while (true) {
            int a = scanner.nextInt();
            String op = scanner.next();
            int b = scanner.nextInt();

            int res = 0;
            switch (op) {
            case "?":
                return;
            case "+":
                res = a + b;
                break;
            case "-":
                res = a - b;

                break;
            case "*":
                res = a * b;

                break;
            case "/":
                res = a / b;

                break;
            }
            String s = String.format("%d", res);
            System.out.println(s);
        }

    }
}


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

using namespace std;
const int N = 100000;

int main() {
	int n, k, a;
	vector<int> v(10, 0);
	
	cin >> n >> k;
	
	for (int i = 0; i < k; i++) {
		cin >> a;
		v[a] = !v[a];
	}
	
	for (int i = n; i < N; i++) {
		int c = i;
		bool f = false;
		
		while (c > 0) {
			f = !v[c % 10];
			if (!f) break;
			c /= 10;
		}
		
		if (f) {
			cout << i << endl;
			return 0;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define pb push_back
#define mxe max_element
#define mne min_element
#define bg begin()
#define nd end()
 
void swap(int &a,int &b)
{
    int t=a;
    a=b;
    b=t;
    return ;
}

string func(ll n)
{
    string s="abcdefghijklmnopqrstuvwxyz";
    string res="";
    
    if(n%26==0)
    {
        string k=func(n-1);
        res=k.substr(0,k.size()-1);
        res+=(char)(k.back()+1);
        return res;
    }
    
    if(n>26)
    {
        while(n>26)
        {
            ll rem=n/26;
            n=n%26;
            if(rem>=26)
            while(rem>=26)
            {
                res+=func(rem);
                rem=0;
            }
            else
            {
                if(rem==0)
                res+='z';
                else res+=s[rem-1];
            }
        }
    }
    if(n<=26 && n>0)
    {
        // cout<<s[n-1]<<"\n";
        res+=s[n-1];
    }
    return res;
}




int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll t,n;
    ll k;
    cin>>n;
    
    cout<<func(n)<<"\n";
    return 0;
}








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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const ld eps = 1e-9;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int a, b; cin >> a >> b;
  if(b == 1) cout << 0 << endl;
  else cout << (b-2) / (a-1) + 1 << endl;

  
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main() {
	long long N, M, K; cin >> N >> M >> K;
	vector<long long>A(N + 1, 0), B(M + 1, 0);
	for (long long i = 1; i <= N; i++) {
		cin >> A.at(i);
		A.at(i) += A.at(i - 1);
	}
	for (long long i = 1; i <= M; i++) {
		cin >> B.at(i);
		B.at(i) += B.at(i - 1);
	}
	long long ans = 0, num = 0;
	for (long long i = 0; i <= N; i++) {
		if (A.at(i) <= K) {
			num = i;
		}
		else break;
		auto ite = upper_bound(B.begin(), B.end(), K - A.at(i));
		num += (ite - B.begin()) - 1;
		ans = max(ans, num);
	}
	cout << ans << endl;
}


Measured memory_bytes: 6424
#include<stdio.h>

int main(){
  int n,k,h[100001],count=0;
  scanf("%d %d",&n,&k);
  for(int i=0;i<n;i++)
    {
      scanf("%d", &h[i]);
    }
  for(int i=0;i<n;i++)
    {
      if(h[i]>=k)
	{
	  count++; 
	}
    }
  printf("%d\n",count);
  return 0;
}


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

#define mod      1e9+7;
#define INF      1e9+9;
#define ps(x,y)  fixed<<setprecision(y)<<x
# define PI 3.14159265358979323846264338327950 L
typedef long long ll;
typedef unsigned long long ull;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;
	int r=0,w=0;
	for(int i=0;i<n;i++){
		if(s[i]=='W')
			w++;
		else
			r++;
	}
	w=0;
	for(int i=0;i<r;i++){
		if(s[i]=='W')
			w++;
	}
	cout<<w<<endl;
	return 0;
}

Measured memory_bytes: 3732
import sys
input=sys.stdin.readline

def main():
    n,k=map(int,input().split())
    H=[0]+list(map(int,input().split()))
    DP=[[10**12]*(n-k+1) for _ in range(n+1)]
    DP[0][0]=0
    for x in range(1,n+1):
        for y in range(1,n-k+1):
            for i in range(x):
                DP[x][y]=min(DP[x][y],DP[i][y-1]+max(0,H[x]-H[i]))
    print(min(DP[i][-1] for i in range(n+1)))

if __name__=='__main__':
    main()

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

char str[300100],t[300100];
int n;

int check(int l) {
    for(int i=0;i<n;i++) t[i]=str[i];
    int v=0;
    for(int i=0;i<n;i++) {
        if(i+l<=n && (t[i]^v)==1) {
            v^=1;
        }
        t[i]^=v;
    } 
    for(int i=0;i<l;i++) if(t[i]!=t[0]) return 0;
    return 1;
}
int main() {
    scanf("%s",str);
    n=strlen(str);
    for(int i=0;i<n;i++) str[i]-='0';

    int lo=(n+1)/2,up=n+1;
    while(up-lo>1) {
        int md=(lo+up)>>1;
        int f=check(md);
        reverse(str,str+n);
        f|=check(md);
        if(f) lo=md;
        else up=md;
    }
    printf("%d\n",lo);
    return 0;
}


Measured memory_bytes: 384
if __name__ == '__main__':
    input()
    a = list(map(int, input().split()))
    count = 0
    for i in range(0, len(a) - 2):
        old = a[i:i + 3]
        new = sorted(old)
        if old[1] == new[1]:
            count += 1
    print(count)


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

typedef complex<double> P;

#define EPS (1e-10)

double cross(P a, P b){
	return (a.real() * b.imag() - a.imag() * b.real());
}

int is_intersect(P a1, P a2, P b1, P b2){
	return (cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS) &&
		(cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS);
}

int main(void){
	double x,y;
	P p[4],o;

	while(1){
		for(int i=0;i<4;i++){
			if(!(cin>>x>>y)) return 0;
			p[i] = P(x,y);
		}

		o = P((p[0].real() + p[1].real() + p[2].real()) / 3,
					(p[0].imag() + p[1].imag() + p[2].imag()) / 3);

		if(is_intersect(p[0],p[1],p[3],o) ||
			 is_intersect(p[1],p[2],p[3],o) ||
			 is_intersect(p[2],p[0],p[3],o)){
			cout<<"NO\n";
		}
		else{
			cout<<"YES\n";
		}
	}
}

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

typedef pair<int,int>P;
typedef pair<int,P>PP;


int dx[]={1,-1,0,0,0,0};
int dy[]={0,0,1,-1,0,0};
int dz[]={0,0,0,0,1,-1};

set<PP> st;

signed main(){
  int A,B,C,n;
  cin>>A>>B>>C>>n;

  int sum = A*B*2 + A*C*2 + B*C*2;
  while(n--){
    int x,y,z;
    cin>>x>>y>>z;
    for(int i=0;i<6;i++){
      int nx = x + dx[i];
      int ny = y + dy[i];
      int nz = z + dz[i];
      if(nx<0||ny<0||nz<0 || nx>=A||ny>=B||nz>=C) sum--;
      else if(st.count(PP(nx,P(ny,nz))))sum--;
      else sum++;
    }
    st.insert(PP(x,P(y,z)));
  }

  cout<< sum <<endl;
}



Measured memory_bytes: 3160
#include <iostream>
#include <string>

int main() {
  std::string S;
  std::cin >> S;

  int cnt = 0;
  int ans = 0;

  for (auto c: S) {
    if (c == '0') {
      if (cnt > 0) ans++;
      cnt--;
    } else if (c == '1') {
      if (cnt < 0) ans++;
      cnt++;
    }
  }

  std::cout << (ans * 2) << std::endl;

  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

/**
 * https://abc066.contest.atcoder.jp/tasks/abc066_a
 */
public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i=0; i<3; i++) a[i] = sc.nextInt();
		sc.close();
		
		Arrays.sort(a);
		System.out.println(a[0]+a[1]);

	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define FOR(i,s,n) for(int i=s;i<n;i++)
#define ROF(i,n,e) for(int i=n;i>e;i--)
#define mod 1e9+7
#define MAX 1000005    //10^5+5
#define MAXQ 200005    //2*10^5+5
#define pi pair<int,int>
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(it,container) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ll long long
#define f first
#define s second
#define sz(container) container.size()
typedef pair<int,int> pii;
typedef pair<int,pii> node;

inline ll modExp(ll a,ll b,ll m=mod){
	ll res=1;
	a%=m;
	while(b>=1){
		if(b%2!=0){
			res=(res%m*a%m)%m;
		}
		a=(a%m*a%m)%m;
		b=b/2;
	}
	return res;
}

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    long long a,b,k;
    cin>>a>>b>>k;
    ll val=min(a,k);
    a-=val;
    k-=val;
    if(k==0){
    	cout<<a<<" "<<b<<"\n";
    }else{
    	b-=min(b,k);
    	cout<<a<<" "<<b<<"\n";
    }
    return 0;    
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<vector>
#define inf 2147483647
#define rep(i,a,b) for(int i=a;i<b;i++)
#define  rr read()
#define ll long long
#define repb(i,a,b) for(int i=a;i<=b;i++)
#define CloseIo   ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
using namespace std;
int read()
{
    char ch = getchar();
	int x = 0, f = 1;
    while(ch < '0' || ch > '9') {if(ch == '-') f = -1; ch = getchar();}
    while('0' <= ch && ch <= '9') {x = x * 10 + ch - '0'; ch = getchar();}
    return x * f;
}
int main()
{
     int n,k;
	 cin>>n>>k;
	 string s;
	 cin>>s;
	 for(int i=0;i<n;i++)
	 {
	 	 if(i+1==k)
	 	 printf("%c",s[i]+32);
	 	 else
	 	 printf("%c",s[i]);
	  } 
}




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

const int X=0x80808080;

int n,a[50],b[50],c[50];
int memo[51][51][51];
int Solve(int song,int rest, int level1)
{
	if(n<=song)
		return 0;
	int &ref = memo[song][rest][level1];
	if(ref != X)
		return ref;
	for(int i=0; i<=min(8,rest); ++i)
	{
		ref = max(ref, c[song] + Solve(song+1,rest-i,i));
		for(int j=0; j<=min(8-i,level1); ++j)
			if(i+j)
				ref = max(ref, i*a[song]+j*b[song] + Solve(song+1,rest-i,i));
		for(int j=1; j<=min(8,level1); ++j)
			ref = max(ref, j*b[song] + Solve(song+1,rest-i,i));
		if(i)
			ref = max(ref, a[song] + Solve(song+1,rest-i,i));
	}
	return ref;
}

int main()
{
	int m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)
		scanf("%d%d%d",a+i,b+i,c+i);

	memset(memo,X,sizeof(memo));
	printf("%d\n",Solve(0,m,0));
	return 0;
}

Measured memory_bytes: 1556
#include<stdio.h>
#define MAX 2000000
#define NMAX 10001



int main(){
int n,i,j,x,last;
int A[MAX];
int B[MAX];
int C[NMAX]={0};
int m=-1;

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


for(i=0;i<n;i++)C[A[i]]++;
last=0;

for(i=0;i<=m;i++){
 if(C[i]>0){
   x=C[i];
   for(j=0;j<x;j++){B[last]=i;last++;}
 }
}





for(i=0;i<n-1;i++)printf("%d ",B[i]);
printf("%d\n",B[n-1]);

return 0;
}


Measured memory_bytes: 17464
#include <iostream>
#include <stdio.h>
using namespace std;
int main(){
    char s;
    bool a[26]={};
    while(scanf("%c",&s)!=EOF){
        if(a[(int)s-97]==1){
            cout<<"no"<<endl;
            return 0;
        }
        else a[(int)s-97]=1;
    }
    cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
K, S = map(int, input().split())
x, y, z = 0, 0, 0
c = 0
for i in range(K + 1):
    if S - i > 2 * K:
        continue
    for j in range(K + 1):
        if i + j > S:
            break
        elif S - i - j > K:
            continue
        c += 1
print(c)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int S=a*b;
		int C=(a+b)*2;
		System.out.println(S+" "+C);
		
	}

}

Measured memory_bytes: 26204
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;

namespace Atcoder_Answer
{
    class Program
    {
        const Int32 mod = 1000000007;

        static void Main(string[] args)
        {
            string[] Reader = ReadLine().Split(' ');
            int S = int.Parse(Reader[0]);
            int W = int.Parse(Reader[1]);

            if (W >= S) WriteLine("unsafe");
            else WriteLine("safe");
        }
    }

    public static class Extension
    {
        #region 拡張:bool
        #region キャスト関連
        public static int ToInt(this bool Bool)
        {
            if (Bool) return 1;
            else return 0;
        }

        public static string ToString(this bool Bool, string TrueStr, string FalseStr)
        {
            if (Bool) return TrueStr;
            else return FalseStr;
        }
        #endregion
        #endregion

        #region 拡張:int
        #region キャスト関連
        public static char ToAlphaBets(this int Base) => (char)Base;
        #endregion
        #endregion

        #region 拡張:char
        #region 変換関連
        public static char NextAlpha(this char Char) => (char)((Char) + 1); //次の文字を取得
        #endregion
        #endregion

        #region 拡張:int[]
        public static long Sum(this int[] Array)
        {
            int Ret = 0;
            for (int loop = 0; loop < Array.Length; loop++) Ret += Array[loop];
            return Ret;
        }
        #endregion

        #region 拡張: string
        public static string Multi(this string THIS, int Value)
        {
            string RetValue = "";

            for (int loop = 0; loop < Value; loop++) RetValue += THIS;

            return RetValue;
        }
        #endregion

        #region 拡張: List<string>
        public static string Sum(this List<string> THIS, string Split)
        {
            string RetValue = "";

            for (int loop = 0; loop < THIS.Count; loop++)
            {
                RetValue += THIS[loop];
            }

            return RetValue;
        }
        #endregion
    }
}


Measured memory_bytes: 17920
S = input()
gap_arr = []
for i in [int(S[i]+S[i+1]+S[i+2]) for i in range(len(S)-2)]:
    if 753 >= i : gap_arr.append(753-i)
    else : gap_arr.append(i-753)
gap_arr.sort()
print(gap_arr[0])

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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}


struct dsu {
        vector<int> par, rk;
        dsu(int n) {
                par.resize(n + 1);
                rk.resize(n + 1);
                for (int i = 1; i <= n; i++) {
                        par[i] = i;
                        rk[i] = 1;
                }
        }

        int find(int x) {
                while (x != par[x]) x = par[x];
                return x;
        }

        void unite(int a, int b) {
                a = find(a), b = find(b);
                if (a != b) {
                        if (rk[a] < rk[b]) swap(a, b);
                        par[b] = a;
                        rk[a] += rk[b];
                }
        }
};



void _main() {
        int n, m; cin >> n >> m;
        dsu d(n);
        while (m--) {
                int x, y, z; cin >> x >> y >> z;
                d.unite(d.find(x), d.find(y));
        }


        int cnt = 0;
        set<int> s;
        for (int i = 1; i <= n; i++) {
                s.emplace(d.find(i));
        }

        cout << sz(s);
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 8712
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#ifdef _DEBUG_
	#define debug(...) printf(__VA_ARGS__)
#else
	#define debug(...) (void)0
#endif
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;

const int MAXS = 2e5 + 100;
char s[MAXS * 2], in[MAXS];

int cnt[250];

int main() {
	scanf("%s", in);
	for (int i = 0; in[i]; i++)
		cnt[in[i]]++;
	ll len = strlen(in);
	ll ans = len * (len - 1) / 2 + 1;
	for (int i = 0; i < 250; i++)
		ans -= 1ll * cnt[i] * (cnt[i] - 1) / 2;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int c[100009];
long long bigmod(long long x,long long n,long long p)
{
    long long res=1;
    x=x%p;
    while(n!=0)
    {
        if(n%2!=0)
        {
            res=(res*x)%p;
        }
        n=n/2;
        x=(x*x)%p;
    }
    return res;
}
int main()
{
    int n,i,j,first;
    scanf("%d",&n);
    int a[n+10];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        c[a[i]]++;
    }
    if(n%2==0)
    {
        first=1;
        for(i=first;i<n;i=i+2)
        {
        if(c[i]!=2)
        {
            printf("0\n");
            return 0;
        }
        }
    }
    else
    {
        first=0;
        if(c[first]!=1)
        {
           printf("0\n");
           return 0;
        }

        for(i=first+2;i<n;i=i+2)
        {
            if(c[i]!=2)
            {
                printf("0");
                return 0;
            }
        }
    }
    int x=n/2;
    long long p=1000000007;
    long long ans=bigmod(2,x,p);
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 1024