akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  double a,b;
  cin >> a >> b;
  ll ans=0;
  if(a==1||b==1){
    cout <<"1" <<endl;
    return 0;
  }
  double calc =floor(a/2)*b;
  ans = calc;
  if(fmod(a,2) != 0){
    ans += ceil(b/2);
  }
  cout << ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
struct Node{
  struct Node *right;
  struct Node *left;
  struct Node *p;
  int key;
};
struct Node *root,*NIL;
//#define NIL NULL

struct Node* find(struct Node *u,int k){
while(u != NIL && k != u->key){
  if(k < u->key) u=u->left;
  else u=u->right;
}
return u;
}
void insert(int k){
  struct Node *y = NIL;
  struct Node *x = root;
  struct Node *z = malloc(sizeof(struct Node)); 
  z->key = k;                                                                   
  z->left = NIL;                                                                
  z->right = NIL;
  while (x!= NIL){
    y=x;
    if(z->key<x->key)x=x->left;
    else x=x->right;
  }
    z->p=y;
    if(y==NIL)root=z;
else if(z->key < y->key){
    y->left=z;
  }else{
    y->right=z;
    }                                      
  }
void inorder(struct Node *u){
  if(u!=NIL){
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
  }
}
void preorder(struct Node *u){
if(u!=NIL){
	printf(" %d", u->key);
	preorder(u->left);
	preorder(u->right);
  }
}

int main(){
  int n, i, x, z;
  char com[20];
  scanf("%d", &n);
 for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if(com[0]== 'f'){
      scanf("%d", &x);
      struct Node *t =find(root,x);
      if(t == NIL)printf("no\n");
      else printf("yes\n");
    }
    else if ( com[0] == 'i' ){
      scanf("%d", &z);
      insert(z);
    } else {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}




Measured memory_bytes: 25168
#include <bits/stdc++.h>
using namespace std;
int a[105],b[105];
int main()
{
	int n,s=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		b[a[i]]=1;
	}
	for(int i=1;i<=100;i++)
	{
		s+=b[i];
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char s[10];

int main(){
	cin>>s+1;
	sort(s+1,s+5);
	if(s[1]==s[2]&&s[3]==s[4]&&s[2]!=s[3]) cout<<"Yes";
	else cout<<"No";
	
	return 0;
}

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

using namespace std;

int main() {
	long long int n, z, w;
	cin >> n >> z >> w;
	vector<long long int> a(n);
	for (long long int i = 0; i < n; i++) {
		cin >> a[i];
	}
	if (n == 1) {
		cout << abs(a[0] - w) << endl;
	}
	else {
		cout << max(abs(a[n - 1] - w), abs(a[n - 2] - a[n - 1])) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
vector<int> par; //oya
vector<int> rnk; //ki no hu ka sa
// n要素で初期化
void init(int n){
    par.resize(n);rnk.resize(n);
    FOR(i, 0, n){par[i] = i;rnk[i] = 0;}
}
//木の根を求める
int find(int x){
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
}
//xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);y = find(y);
    if(x == y) return;
    if(rnk[x] < rnk[y])par[x] = y;
    else{par[y] = x;if(rnk[x] == rnk[y]) rnk[x]++;}
    return;
}
bool isSame(int x, int y){return find(x) == find(y);}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N,M;cin>>N>>M;
  init(N+1);
  int p[N];
  FOR(i,0,N)cin>>p[i];
  FOR(i,0,M){
    int a,b;cin>>a>>b;
    unite(a,b);
  }
  int ans=0;
  FOR(i,1,N+1){
    if(isSame(p[i-1],i)||p[i-1]==i){
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1408
s = input()
p = input()

check = False

for i in range(len(s)):
  is_ans = True
  for k in range(len(p)):
    if s[(i+k)%(len(s))] != p[k]:
      is_ans = False
      break

  if is_ans:
    check = True
    break

if check:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 5564
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

string s[350];
int ans[350][350];

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    rep(i, h) cin >> s[i];
    int y = 0, now = 1;
    rep(y, h){
        int cnt = 0;
        bool flag = true;
        rep(x, w) flag &= (s[y][x] == '.');
        if (flag) continue;

        rep(x, w){
            if (s[y][x] == '#') {
                cnt++;
                if (cnt >= 2) now++;
            }
            ans[y][x] = now;
        }
        if (!flag) now++;
    }

    for(int y = 1; y < h; y++){
        bool zflag = true;
        rep(x, w) zflag &= (s[y][x] == '.');
        if (zflag){
            rep(x, w) ans[y][x] = ans[y-1][x];
        }
    }

    for(int y = h-2; y >= 0; y--){
        bool zflag = true;
        rep(x, w) zflag &= (s[y][x] == '.');
        if (zflag){
            rep(x, w) ans[y][x] = ans[y+1][x];
        }
    }

    rep(y, h){
        rep(x, w) cout << ans[y][x] << " ";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[200010],aa[200010],b[200010];
int n;

int bs(int x){
	//x以上の値をもつa[i]の最小のindex
	if(aa[0]>=x)return 0;
	int l=0,r=n;//a[l]<x<=a[r]
	while(r-l>1){
		int m=(l+r)/2;
		if(aa[m]<x)l=m;
		else r=m;
	}
	return r;
}

int main(){
	scanf("%d",&n);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)scanf("%lld",b+i);
	
	ll ans=0;
	rep(k,0,29){
		ll mod=1LL<<(k+1);
		ll cnt=0;
		rep(i,0,n)aa[i]=a[i]%mod;
		sortup(aa,n);
		rep(i,0,n){
			ll bb=b[i]%mod;
			if(bb&(mod/2)){
				//[mod-bb,mod-bb+mod/2)が0
				int l=bs(mod*2/2-bb),r=bs(mod*3/2-bb);
				cnt+=n-(r-l);
			}else{
				//[mod/2-bb,mod-bb)が1
				int l=bs(mod*1/2-bb),r=bs(mod*2/2-bb);
				cnt+=r-l;
			}
		}
		if(cnt%2)ans|=1LL<<k;
	}
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6388
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

vector<int> dijkstra(int s, vector<vector<P>> &G){
    int n = G.size();
    vector<int> dist(n, inf);
    priority_queue<P, vector<P>, greater<P>> que;
    dist[s] = 0;
    que.emplace(0, s);

    while(que.size()){
        int ccost, cv;
        tie(ccost, cv) = que.top(); que.pop();

        if(dist[cv] < ccost) continue;

        for(auto nxt : G[cv]){
            int nv, ncost;
            tie(nv, ncost) = nxt;
            
            if(dist[cv] + ncost < dist[nv]){
                dist[nv] = dist[cv] + ncost;
                que.emplace(dist[nv], nv);
            }
        }
    }

    return dist;
}

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

    int v, e, r; cin>>v>>e>>r;
    vector<vector<P>> G(v);
    for(int i=0; i<e; i++){
        int s, t, d; cin>>s>>t>>d;
        G[s].emplace_back(t, d);
    }

    auto dist = dijkstra(r, G);

    for(int i=0; i<v; i++){
        if(dist[i] == inf) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 12928
/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
I'm working for the day I will surpass you
https://www.a2oj.com/Ladder16.html
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class Main
   {
      public static void main(String omkar[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));  
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         LinkedList<Integer>[] edges = new LinkedList[N+1];
         for(int i=1; i <= N; i++)
            edges[i] = new LinkedList<Integer>();
         for(int i=0; i < M; i++)
         {
            st = new StringTokenizer(infile.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            edges[a].add(b);
         }
         int[] dp = new int[N+1];
         Arrays.fill(dp, -1);
         for(int i=1; i <= N; i++)
            if(dp[i] == -1)
               dfs(i, dp, edges);
         int res = 0;
         for(int x: dp)
            res = Math.max(res, x);
         System.out.println(res);
      }
      public static int dfs(int curr, int[] dp, LinkedList<Integer>[] edges)
      {
         if(dp[curr] >= 0)
            return dp[curr];
         int res = 0;
         for(int next: edges[curr])
            res = Math.max(res, 1+dfs(next, dp, edges));
         return dp[curr] = res;
      }
   }

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

ifstream in ("test.in" );
ofstream out("test.out");

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n, k;
    cin >> n >> k;
    
    int mxm = 0, gcd = 0;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        
        if (i == 1)
            mxm = gcd = x;
        else {
            mxm = max(mxm, x);
            gcd = __gcd(gcd, x);
        }
    }
    
    if (k <= mxm && k % gcd == 0)
        cout << "POSSIBLE";
    else
        cout << "IMPOSSIBLE";
    
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A1=[int(i) for i in input().split(" ")]
A2=[int(i) for i in input().split(" ")]

total=sum(A2)+A1[0]
maximum=total
for i in range(N-1):
    total+=A1[i+1]
    total-=A2[i]
    maximum=max(maximum,total)
print(maximum)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	int a,b,c[11];
	cin>>a>>b>>c[0];
	for(int i=1;i<11;++i)
	{
		c[i] = a * c[i-1] - b;
		cout<<c[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int x = stdIn.nextInt();
        int y = stdIn.nextInt();
        int z = stdIn.nextInt();
        
        
        System.out.println(z + " " + x + " " + y);
    }
}


Measured memory_bytes: 23764
k=int(input())
ans=[0]*50
if k<50:
    for i in range(k):
        ans[i]=50-i
else:
    for i in range(50):
        ans[i]=50-i
    k-=50
    for i in range(50):
        ans[i]+=k//50
    for i in range(k%50):
        ans[i]+=1
print(50)
print(*ans)

Measured memory_bytes: 9208
#include<stdio.h>
    int main()
    {
    	int N,K,i;
    	int min;
    	min = 1;
    	scanf("%d %d",&N,&K);
    	for(i = 0;i < N;i++)
    		{
    			if(min<K)
    				min = min * 2;
    				else if(min > K || min == K)
    					min = min + K;
    			}
    	printf("%d",min);
    	return 0;
    }

Measured memory_bytes: 128
//Author - Rahil Malhotra
#include <bits/stdc++.h>
using namespace std;
 
template <typename T> void print(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void print(T t, Args... args) { cout<<t<<" "; print(args...); }
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

void start() {
	#ifndef ONLINE_JUDGE 
		freopen("in", "r", stdin); 
		freopen("out", "w", stdout); 
	#endif
}

int n,t;
vector< pair<int,int> >v;
int cache[3004][3004];

int dp(int pos,int time) {
    if(pos == n || time >= t) {
        return 0;
    }

    int &ans = cache[pos][time];
    if(ans != -1) {
        return ans;
    }

    ans = dp(pos+1, time);
    ans = max(ans, v[pos].second + dp(pos+1, time + v[pos].first));
    return ans;

}

int32_t main() {
    IOS;
    start();

    cin >> n >> t;
    for(int i = 0; i < n; i++) {
        int a,b;
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(), v.end());
    memset(cache, -1, sizeof(cache));
    print(dp(0,0));
}   

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

int main() {

        int n;

        std::cin >> n;

        std::vector<int> v(n);
        std::vector<int> c(n);

        for (auto& vi : v) {
                std::cin >> vi;
        }
        for (auto& ci : c) {
                std::cin >> ci;
        }

        int result = 0;

        for (std::size_t i = 0; i < n; ++i) {
                if (v[i] - c[i] > 0) {
                        result += (v[i] - c[i]);
                }
        }

        std::cout << result << std::endl;

        return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main(void)
{
	int q;
	double x;

	while (1) {
		scanf("%d", &q);
		if (q == -1)break;

		x = q / 2.0;
		while (fabs(pow(x, 3) - q) >= 0.00001*q)
			x = x - (pow(x, 3) - q) / (3.0 * pow(x, 2));

		printf("%lf\n", x);
	}
	return 0;
}

Measured memory_bytes: 708
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    [n, k] <- map read.words <$> getLine :: IO [Int]
    xs <- U.unfoldrN n (B.readInt.B.dropWhile isSpace) <$> B.getLine
    print $ solve n k xs

solve :: Int -> Int -> U.Vector Int -> Int
solve n k xs = go 0 sums 40
  where
    sums :: U.Vector Int
    sums = U.concatMap (U.scanl1' (+) . flip U.drop xs) $ U.generate n id

    go !res !acc i
        | i < 0 = res
        | U.length (U.filter (`testBit` i) acc) >= k = go (setBit res i) (U.filter (`testBit` i) acc) (i - 1)
        | otherwise = go res acc (i - 1)



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

int main()
{
    int n;
    cin >> n;
    vector<long long> S(n);
    for (int i=0; i<n; i++) cin >> S[i];
    sort(S.begin(), S.end());
    int q;
    cin >> q;
    vector<long long> T(q);
    for (int i=0; i<q; i++) cin >> T[i];
    sort(T.begin(), T.end());
    
    int ans = 0;
    // Tの要素の小さい方から調べていく
    for (int i=0; i<q; i++)
    {
        //cout << T[i] << endl;
        int floor_id, roof_id;
        floor_id = 0;
        roof_id = n;
        while (true)
        {
            
            if (T[i] > S[(floor_id+roof_id)/2]) floor_id = (floor_id + roof_id)/2;
            else if (T[i] < S[(floor_id+roof_id)/2]) roof_id = (floor_id + roof_id)/2;
            else
            {
                ans++;
                //cout << T[i] << endl;
                break;
            }

            if (roof_id - floor_id <= 1)
            {
                if (T[i]==S[floor_id])
                {
                    ans++;
                    //cout << T[i] << endl;
                    break;
                }
                else break;
            }
        }

    }

    cout << ans << endl;
}


Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<(int)c;i++)
#define print(var) cout<<var<<endl;
#define DEBUG(var) cerr<<var<<endl;
// puts("str");

const int inf = 1000000000;//10^9

int main (){

  string S;
  string A;
  int it=0;

  cin >>S;
  rep(i,S.size()){
    if(S[i]=='B'){
      if(A.size()){
        A.pop_back();
      }
    }else{
      A.push_back(S[i]);
    }
  }
print(A);




  return 0;

}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, C, D[30][30] = {}, c[3][30] ={};
    cin >> N >> C;
    REP(i, C) REP(j, C) cin >> D[i][j];
    REP(i, N) REP(j, N) {
        int tmp;
        cin >> tmp;
        c[(i + j) % 3][tmp - 1]++;
    }
    ll ans = 1000000000000;
    REP(i, C) REP(j, C) REP(k, C) {
        if (i == j || j == k || k == i) continue;
        ll cost = 0;
        REP(col, C) {
            cost += D[col][i] * c[0][col];
            cost += D[col][j] * c[1][col];
            cost += D[col][k] * c[2][col];
        }
        ans = min(ans, cost);
    }

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

Measured memory_bytes: 256
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <time.h>
#include <functional>

//#include "All.h"

using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    REP(i, b) tmp *= a;
    return tmp;
}

int N;
vector<int> A;
vector<int> B;
bool chk;
int ans = 0;

//vector<ll> res;

int main() {
    
    //B.reserve(200010);
    cin >> N;
    A.reserve(N);
    REP(i, N) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    sort(A.begin(), A.end());

    

    REP(j, N) {
        ll M = A[j];
        if (j > 0) A[j] = A[j - 1];
        else A[j] = -1;
        chk = true;
        for (ll i = 1; i * i <= M; ++i) {
            if (M % i == 0) {
                //res.emplace_back(i);
                if (binary_search(A.begin(), A.end(), i)) chk = false;
                if (i != M / i) {
                    //res.emplace_back(N / i)
                    if (binary_search(A.begin(), A.end(), M / i)) chk = false;
                };
            }
        }
        A[j] = M;
        //trueなら割り切れるものなし、falseならあり
        if (chk) ans++;
    }
    cout << ans << endl;
    //REP(i, B.size()) {
    //    cout << B[i] << endl;
    //}
}


Measured memory_bytes: 3996
#include<stdio.h>
int main (void){
int num,i,count,sum;
char number[1001];
char*str;
while(1){
    scanf("%s",number);
    i = 0;
    sum= 0;
    str = &number;
    count = (int)strlen(str);
    if(number[0]=='0'){
        if(count == 1){
            break;
        }
    }
    while(i<count){
        num = number[i]-'0';
        sum = sum +num;
        i++;
    }
    printf("%d\n",sum);
}
return 0;
}

Measured memory_bytes: 536
if __name__ == "__main__":
    # week = ["MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"]
    week = ["SUN", "SAT", "FRI", "THU", "WED",  "TUE", "MON"]

    S = input()
    count = 0 

    for i in week:
        if S != i:
            count += 1
        elif S == i:
            if count == 0:
                count = 7
            print(count)
            exit(0)    


Measured memory_bytes: 2940
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

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

int main() {

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

	int N;
	cin >> N;

	vector<string> S(N);
	for (int i = 0; i < N; i++) cin >> S[i];

	vector<pair<int, int>> l, r;
	for (int i = 0; i < N; i++) {
		int sum = 0, m = 0;;
		for (const auto &c : S[i]) {
			sum += (c == '(') - (c == ')');
			chmin(m, sum);
		}
		if (sum > 0) l.emplace_back(m, sum);
		else r.emplace_back(m - sum, -sum);
	}

	sort(l.begin(), l.end(), greater<>());
	sort(r.begin(), r.end(), greater<>());
	DMP(l, r);

	auto check = [](auto &vec) {
		int sum = 0;
		for (int i = 0; i < vec.size(); i++) {
			if (sum + vec[i].first < 0) return -1;
			sum += vec[i].second;
		}
		return sum;
	};

	if (int res = check(l); res == check(r) && res != -1) cout << "Yes" << "\n";
	else cout << "No" << "\n";

	return 0;
}

Measured memory_bytes: 42508
#include<bits/stdc++.h>
#define ll long long int
#define endl "\n"
#define mod 1000000007
#define ff first
#define ss second
#define pb push_back
using namespace std;

string func(string s, string t){
	string ans;
	int n = s.size(), m = t.size();
	ll dp[n + 1][m + 1];
	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= m; ++j)
		{
			if (i == 0 or j == 0)
			{
				dp[i][j] = 0;
			}
			else if (s[i - 1] == t[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	// for (int i = 0; i <= n; ++i)
	// {
	// 	for (int j = 0; j <= m; ++j)
	// 	{
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	int row = n;
	for (int i = m; i > 0; --i)
	{
		if (dp[row][i] != dp[row][i - 1])
		{
			for (int j = row; j > 0; --j)
			{
				if (dp[j][i] != dp[j - 1][i])
				{
					//cout<<j<<endl;
					ans.pb(s[j - 1]);
					row = j - 1;
					break;
				}
			}
		}
	}
	reverse(ans.begin(), ans.end());
	return ans;
}

void solve(int test){
	string s,t;
	cin>>s>>t;
	string ans;
	ans = func(s, t);
	cout<<ans<<endl;
	//cout<<3232;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t=1,k;
	//cin>>t;
	k = t;
	while(t--){
		solve(k - t);
	}
	cerr<<"Timpe elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " mps\n" ;
	return 0;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    rep(i, 0, N) {
        int cnt = 0;
        rep(j, 0, N + 1) {
            if(i + j == N) break;
            if(S[j] == S[i + j]) cnt++;
            else cnt = 0;
            if(j - i >= 0 && cnt >= i) cnt -= S[j - i] == S[i + j - i];
            if(cnt < 0) cnt = 0;
            ans = max(ans, cnt);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import sys
N,*W = map(str,open(0).read().split())
N = int(N)
for i in range(N-1):
    if list(W[i])[-1] != list(W[i+1])[0]:
        print("No")
        sys.exit()
if len(W) != len(set(W)):
    print("No")
    sys.exit()
print("Yes")

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
ll f(ll a) {
  ll b = a &  3ll;
  ll c = a & ~3ll;
  if (b == 2) b = 3;
  else if (b == 3) b = 0;
  if (a % 2) c = 0;
  return b | c;
}
int main() {
  ios::sync_with_stdio(false);
  ll A, B;
  cin >> A >> B;
  ll ret = f(B) ^ f(max(A-1,0ll));
  cout << ret << endl;
}

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  if(n%2==0)cout << n << " " << n <<  " " << n/2 << endl;
  else{
   rep(i, 1, 3501){
     rep(j, 1, 3501){
       if(4*i*j-n*(i+j)<=0)continue;
       if((n*i*j)%(4*i*j-n*(i+j))==0){
         ll ans = (n*i*j)/(4*i*j-n*(i+j));
         cout << i << " " << j <<  " " << ans << endl;
         return 0;
       }
     }
   }
  } 
}

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

using namespace std;

const int MX = 300;

char s[MX][MX + 1];

int main() {
	int n;
	ignore = scanf("%d", &n);
	for (int i = 0; i < n; i++) ignore = scanf("%s", s[i]);
	
	int ans = 0;
	for (int d = 1 - n; d < n; d++) {
		bool ok = true;
		for (int x = 0; x < n; x++)
			for (int y = 0; y < n; y++)
				ok = ok && s[x][y] == s[(y - d + n) % n][(x + d + n) % n];
		
		if (ok) ans += n - abs(d);
	}
	
	printf("%d\n", ans);
	
	return 0;
}


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

int main() {
    int N, Y;
    cin >> N >> Y;
    int res10000 = -1, res5000 = -1, res1000 = -1;
    for (int a = 0; a <= N; ++a){
        for (int b = 0; b + a <= N; ++b){
            int c = N - a - b;
            int total = 10000*a + 5000*b + 1000*c;
            if(total == Y) {
                res10000 = a;
                res5000 = b;
                res1000 = c;
            }
        }
    }
    //答えを出力
    cout << res10000 << " " << res5000 << " " << res1000 << endl;

}

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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 2147483647
using namespace std;



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

	int  a, b, c;
	cin >> a >> b >> c;
	cout<<min(min(a + b, a + c), b + c)<<endl;


	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main extends App { 
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt()
  val array = (for (i <- 0 until N) yield sc.nextInt()).toArray
  val flags = Array.fill[Int](K+1)(0)

  def solver(l:Int, r:Int, len:Int):Int = {
    def isFilled:Boolean = flags(0) == K
    def inRange(x:Int):Boolean = 1 <= x && x <= K

    if (r >= N && !isFilled) if (len < N+1) len else 0
    else if (isFilled) {
      val i = array(l)
      if (inRange(i)) {
        flags(i) -= 1
        if (flags(i) == 0) flags(0) -= 1 
        solver(l+1, r, len min (r -l))
      }
      else solver(l+1, r, len)
    }
    else {
      val i = array(r)
      if (inRange(i)) {
        if (flags(i) == 0) flags(0) += 1 
        flags(i) += 1
      }
      solver(l, r+1, len)
    }
  }

  println(solver(0, 0, N+1))

}


Measured memory_bytes: 131972
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k=0,c;
string s,d;
cin>>s;
c=s.size();
while((--c)>0)s[c]=tolower(s[c]);
while(cin>>d){
  if(d=="END_OF_TEXT")break;
c=d.size();
while((--c)>-1)d[c]=tolower(d[c]);
  if(s==d)k++;
}
cout<<k<<endl;
}

Measured memory_bytes: 3104
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N, R; cin >> N >> R;
    if (N < 10){
        cout << R + (10 - N) * 100 << endl;
    }
    else{
        cout << R << endl;
    }
}

Measured memory_bytes: 3568
#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <string> 
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <iomanip>
  
using namespace std;

#define pi 3.141592653589793

int main()
{
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int w, h;
		cin >> w >> h;
		int wheretree[101][101] = {};
		int x, y;
		for(int i = 0; i < n; i++){
			cin >> x >> y;
			wheretree[x][y] = 1;
		}
		int result[101][101] = {};
		for(int i = 1; i < w + 1; i++){
			for(int j = 1; j < h + 1; j++){
				result[i][j] = result[i - 1][j] + result[i][j - 1] - result[i - 1][j - 1] + wheretree[i][j];
			}
		}
		int ans = 0;
		int s, t;
		cin >> s >> t;
		for(int i = 0; i < w; i++){
			for(int j = 0; j < h; j++){
				for(int k = i + 1; k < w + 1; k++){
					for(int l = j + 1; l < h + 1; l++){
						if(k - i == s && l - j == t){
							ans = max(ans, result[k][l] - result[i][l] - result[k][j] + result[i][j]);
						}
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include<bits/stdc++.h>
using namespace std;
#define ll long long
template<class T> void chmax(T& x, T y) {if(x < y) x = y;} 
int N;
int tp;
bool used[200010];
vector<int> G[200010];

int dfs(int n, int& di){
    used[n] = true;

    vector<int> res = {0, 0};
    for(auto& u : G[n]){
        if(!used[u]){
            res.push_back(dfs(u, di));
        }
    }
    sort(res.rbegin(), res.rend());
    chmax(di, res[0] + res[1] + 1);
    return res[0] + 1;
}

int main(){
    cin >> N;
    for(int i = 1; i < N; i++){
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    int di = 0;
    dfs(1, di);
    cout << (di % 3 != 2 ? "First" : "Second")  << endl;
    return 0;
}

Measured memory_bytes: 38400
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;

int main() {
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	if (k % 2 == 0) cout << a - b << endl;
	else cout << b - a << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

const int INF = (1 << 31) - 1;

//?????¶???????????°???????????¨(RMQ & RUQ)??????????????¨??????????°????
struct SegTree {
    int N;
    vector<int> dat, lazy;
    SegTree() {}
    SegTree(int n) {
        N = 1;
        while(N < n) N *= 2;
        dat.resize(2 * N, INF);//change!!
        lazy.resize(2 * N, -1);//change!!
    }
    //?????¶??????
    void lazy_evaluate(int k, int l, int r){
        if(lazy[k] != -1){//?????¶????????????
            dat[k] = lazy[k];
            if(k < N - 1){//k????????§???????????????????????¬
                lazy[k * 2 + 1] = lazy[k];
                lazy[k * 2 + 2] = lazy[k];
            }
            lazy[k] = -1;
        }
    }
    int marge(int x, int y){
        return min(x, y);//change!!
    }
    //replace x [a, b)
    void update(int a, int b, int x){ update(a, b, 0, 0, N, x); }
    void update(int a, int b, int k, int l, int r, int x){
        lazy_evaluate(k, l, r);        
        if(r <= a || b <= l) return;
        if(a <= l && r <= b){
            lazy[k] = x;
            lazy_evaluate(k, l, r);
        }else{
            int m = (l + r) / 2;
            update(a, b, k * 2 + 1, l, m, x);
            update(a, b, k * 2 + 2, m, r, x);
            dat[k] = marge(dat[k * 2 + 1], dat[k * 2 + 2]);
        }
    }
    // min [a, b)
    int query(int a, int b){ return query(a, b, 0, 0, N); }
    int query(int a, int b, int k, int l, int r) {
        lazy_evaluate(k, l, r);
        if(r <= a or b <= l) return INF;//change!!
        if(a <= l and r <= b) return dat[k];
        int m = (l + r) / 2;
        int x = query(a, b, k * 2 + 1, l, m);
        int y = query(a, b, k * 2 + 2, m, r);
        return marge(x, y);
    }
};


signed main(){
    int n, q;
    cin >> n >> q;
    SegTree sg(n);
    rep(i, 0, q){
        int k, s, t, x;
        cin >> k;
        if(k == 0){
            cin >> s >> t >> x;
            sg.update(s, t + 1, x);
        }else{
            cin >> s >> t;
            cout << sg.query(s, t + 1) << endl;
            //  rep(j, 0, n){
            //     cout << sg.dat[sg.N - 1 +  j] << " ";
            // }
            // rep(j, 0, sg.N * 2){
            //     cout << sg.dat[j] << " ";
            // }
            // cout << endl;
        }
    }
}

Measured memory_bytes: 7004
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
   int a,b;
   cin>>a>>b;
   int count=1;
   int x=b-a;
   int y=a-1;
   if(b==1){
     cout<<0;
   }
   else if(b<=a){
     cout<<1;
   }
   else{
     if(x%y==0){
     count+=(x/y);
     }
     else{
     count+=((x/y)+1);
     }
     cout<<count;
   }
     
   
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

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

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

    vector<int> v(3);
    REP(i, 3) {
        std::cin >> v[i];
    }

    SORT(v);

    std::cout << (v[0] * v[1]) / 2 << std::endl;

    return 0;
}


Measured memory_bytes: 256
#[cfg(debug_assertions)]
include! {"./debug.rs"}

#[cfg(not(debug_assertions))]
macro_rules! debug {
    ($($arg:expr),*) => {};
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
#[allow(deprecated)]
fn rl() -> String {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

////////////////////////////////////////////////////////////////////////////////

fn gcd(x: usize, y: usize) -> usize {
    if y == 0 {
        x
    } else if x == 0 {
        y
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let n = read!(usize);
    let a = read!([usize]);
    let mut l = vec![0; n + 1];
    let mut r = vec![0; n + 1];

    for i in 0..n {
        l[i + 1] = gcd(l[i], a[i]);
    }
    for i in (0..n).rev() {
        r[i] = gcd(r[i + 1], a[i]);
    }

    debug!(l, r);

    let ans = (0..n).map(|i| gcd(l[i], r[i + 1])).max().unwrap();
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
int main() {
    vector<vector<int>> bg(3, vector<int>(3, 0));
    vector<vector<int>> ans(3, vector<int>(3, 0));
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            cin >> bg[i][j];
        }
    }
    int n;
    cin >> n;
    for(int k = 0; k < n; k++) {
        int b;
        cin >> b;
        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                ans[i][j] = ans[i][j] ^ (bg[i][j] == b);
            }
        }
    }
    int res = 0;
    for(int i = 0; i < 3; i++) {
        int tmp = 0;
        for(int j = 0; j < 3; j++) {
            tmp += ans[i][j];
        }
        res += (tmp == 3);
    }
    for(int i = 0; i < 3; i++) {
        int tmp = 0;
        for(int j = 0; j < 3; j++) {
            tmp += ans[j][i];
        }
        res += (tmp == 3);
    }
    int t1 = 0;
    for(int i = 0; i < 3; i++) {
        t1 += ans[i][i];
        // cout << ans[i][i] << endl;
    }
    res += (t1 == 3);
    int t2 = 0;
    for(int i = 0; i < 3; i++) {
        t2 += ans[i][2 - i];
    }
    res += (t2 == 3);
    if(res > 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n;
    cin >> n;
    cout << 2*n*M_PI << endl;
    return 0;
}


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

#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{int x,y,t;};
struct Edge{int to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=1010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(int from,int to,int cost){E[from-1].pb({to-1,cost});}
};
int main(){
  int n,k;cin>>n>>k;
  vector<int>stone(n);
  for(int i=0;i<n;i++)cin>>stone[i];
  int dp[2*k+10]={};
  dp[0]=0;
  for(int i=0;i<k;i++){
    for(int j=0;j<n;j++)
      if(dp[i]==0)
      dp[i+stone[j]]=(dp[i]+1)%2;
  }
  if(dp[k]%2)
    cout<<"First"<<endl;
  else
    cout<<"Second"<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm> 
// などの必要なインクルードファイルすべて（3章の各標準ライブラリの説明でそれぞれ書いています）
using namespace std;

int main(void){
  int N;
  cin >> N;
  int ans = 0;
  int count;
  for (int i = 1; i <= N; i+=2){
    count = 0;
    for (int j = 1; j <= i; j++){
      if (i%j==0) count++;
    }
    if (count == 8) ans++;
  }
  
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
A = rl()

b = [0] * 60

def count(a, b):
	i = len(b)-1
	while a:
		b[i] += a % 2
		a //= 2
		i -= 1
	return i+1

def sum_xor(a, b, l, left):
	i = len(b)-1
	e = 1
	s = 0
	while a or left <= i:
		if a % 2 == 0:
			s = (s + b[i] * e) % mod
		else:
			s = (s + (l-(b[i])) * e) % mod
		a //= 2
		e = e * 2 % mod
		i -= 1
	return s

ans = 0
min_left = 60
for i in range(N):
	if i > 0:
		ans = (ans + sum_xor(A[i], b, i, min_left)) % mod
	left = count(A[i], b)
	min_left = min(min_left, left)
print(ans)

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

int main()
{
  int k,s;
  int ans=0;
  cin>>k>>s;
  for(int i=0;i<=k;i++){
    for(int j=0;j<=k;j++){
      if (s-i-j>=0 && s-i-j <= k){
        ans++;
      }
    }
  }
  cout<< ans <<endl;
}


Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        long[][] a = new long[n][2];
        int number = 0;
        long ans = 0;
        for(int i =0; i < n; i++){
            a[i][0] = sc.nextLong();
            a[i][1] = sc.nextLong();
        }
        //ここまで値を格納するフェーズ
        //値段の安い順を考慮して並べ替えるが、値段が重複してる部分を消さないようにする
        Arrays.sort(a,(x,y)->Long.compare(x[0], y[0]));
        //安い店から買っていく処理        
        for(int i = 0; i < n; i++){
            if(number + a[i][1] < m){
                ans += a[i][0] * a[i][1];
			    number += a[i][1];
            }else{
                ans += a[i][0] * (m - number);
				break;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 94092
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M = map(int, input().split())
    edge = []
    for _ in range(M):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        edge.append((a, b))

    adj = [list() for _ in range(N)]
    for a, b in edge:
        adj[a].append(b)
        adj[b].append(a)

    ans = 0
    for a, b in edge:
        visit = [False for _ in range(N)]
        que = queue.Queue()
        que.put(0)
        while not que.empty():
            c = que.get()
            visit[c] = True
            for n in adj[c]:
                if (c == a and n == b) or (c == b and n == a):
                    continue
                if not visit[n]:
                    que.put(n)
        if sum(visit) != N:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45800
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

bool flag[4];
int hand[5];
int ans[5];

void solve() {
  for(int i = 0 ; i < 5 ; i++) {
    if(hand[i] == 1) flag[1] = true; //O[
    if(hand[i] == 2) flag[2] = true; //`L
    if(hand[i] == 3) flag[3] = true; //p[
  }
}

int main() { 
  while(cin >> hand[0], hand[0]) {
    for(int i = 1 ; i < 5 ; i++) cin >> hand[i];
    for(int i = 1 ; i < 4 ; i++) flag[i] = false;
    solve();
    
    for(int i = 0 ; i < 5 ; i++) { 
      if(flag[1] == true && flag[2] == true && flag[3] == false) {
	if(hand[i] == 1) ans[i] = 1;
	if(hand[i] == 2) ans[i] = 2;
      }	      
      else if(flag[1] == false && flag[2] == true && flag[3] == true) {
	if(hand[i] == 2) ans[i] = 1;
	if(hand[i] == 3) ans[i] = 2;
      }	      
      else if(flag[1] == true && flag[2] == false && flag[3] == true) {
	if(hand[i] == 3) ans[i] = 1;
	if(hand[i] == 1) ans[i] = 2;
      }
      else ans[i] = 3;
    }

    for(int i = 0 ; i < 5 ; i++) {
      cout << ans[i] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
import Data.Char

main :: IO()
main = do
  xs <- map (read . (:"")) <$> getLine
  xrs <- return $ reverse xs
  putStrLn $ extract $ filter eq7 $ showPattern $ enumeratePattern xrs

type Result = Int
type Expr = String
data Calc = Calc Expr Result deriving(Show)

extract :: [Calc] -> String
extract ((Calc e r):xs) = e ++ "=7"

eq7 :: Calc -> Bool
eq7 (Calc e r) = r == 7

showPattern :: [Calc] -> [Calc]
showPattern xs = map f xs
  where
    f (Calc e r) = Calc (reverse e) r

enumeratePattern :: [Int] -> [Calc]
enumeratePattern [x] = [Calc (show x) x]
enumeratePattern (x:xs) =  ys >>= f
   where
     ys = enumeratePattern xs
     d = intToDigit x
     f :: Calc -> [Calc]
     f (Calc y r') = [ Calc (d:'+':y) (r'+x), Calc (d:'-':y) (r'-x) ]


Measured memory_bytes: 508
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
using namespace std;
int i, j;
const int num = 100002;
const int numm = 1 + num / 2;
const int INF = 1000000001;
struct Card {
	int numc;
	char pic;
};
Card A[num], B[num];
inline int partition(int p, int r) {
	int base = A[r].numc;
	int q = p - 1;
	for (i = p; i < r; i++) {
		if (A[i].numc <= base)
			swap(A[++q], A[i]);
	}
	swap(A[++q], A[r]);
	return q;
}
inline void quickSort(int p, int r) {
	if (r > p) {
		int a = partition(p, r);
		quickSort(p, a - 1);
		quickSort(a + 1, r);
	}
}
inline void merge(int left, int mid, int right) {
	int n1 = mid - left, n2 = right - mid;
	Card I[numm], J[numm];
	for (i = 0; i < n1; i++)
		I[i] = B[left + i];
	for (i = 0; i < n2; i++)
		J[i] = B[mid + i];
	int a = 0, b = 0;
	I[n1].numc = J[n2].numc = INF;
	for (i = left; i < right; i++) {
		if (I[a].numc <= J[b].numc)
			B[i] = I[a++];
		else B[i] = J[b++];
	}
}
inline void mergeSort(int left, int right) {
	if (right > left + 1) {
		int mid = (left + right) / 2;
		mergeSort(left, mid);
		mergeSort(mid, right);
		merge(left, mid, right);
	}
}
int main() {
	int n, v, sta = 1;
	char c[2];
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%s%d", c, &v);
		A[i].numc = B[i].numc = v;
		A[i].pic = B[i].pic = c[0];
	}
	quickSort(0, n - 1);
	mergeSort(0, n);
	for (i = 0; i < n - 1; i++) {
		if (A[i].pic != B[i].pic)
			sta = 0;
	}
	if (sta) cout << "Stable" << endl;
	else cout << "Not stable" << endl;
	for (i = 0; i < n; i++) {
		printf("%c %d\n", A[i].pic, A[i].numc);

	}
	return 0;
}

Measured memory_bytes: 5476
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  ll n, k;
  cin >> n >> k;
  map<ll, ll> m;
  ll a, b;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    m[a] += b;
  }
  for (auto x : m) {
    k -= x.second;
    if (k <= 0) {
      cout << x.first << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 4224
#include<stdio.h>
int main(void){
int d,t,s;
while(1){
scanf("%d",&d);
if(1<=d&&d<=10000)break;
}
while(1){
scanf("%d",&t);
if(1<=t&&t<=10000)break;
}
while(1){
scanf("%d",&s);
if(1<=s&&s<=10000)break;
}
if(d<=t*s){
printf("Yes");
}else printf("No");
return 0;
}

Measured memory_bytes: 1732
n,m = map(int,input().split())
a = list(map(int,input().split()))
import heapq
q = [0]*n
for i in range(n):
    q[i] = -a[i]
heapq.heapify(q) 
for i in range(m):
    x = heapq.heappop(q) 
    heapq.heappush(q,-(-x//2))
ans = 0
for i in range(n):
    x = heapq.heappop(q)
    ans += x
print(-ans)

Measured memory_bytes: 19952
def main():
	H, W = map(int, input().split())
	STAGE = [input() for _ in range(H)]

	dp = [[0] * W for _ in range(H)]
	dp[0][0] = 1

	MOD = 10 ** 9 + 7

	for y in range(H):
		for x in range(W):
			if y + 1 < H and STAGE[y + 1][x] == ".":
				dp[y + 1][x] += dp[y][x] % MOD
			if x + 1 < W and STAGE[y][x + 1] == ".":
				dp[y][x + 1] += dp[y][x] % MOD

	print(dp[-1][-1] % MOD)

main()


Measured memory_bytes: 43692