akhauriyash/Code-Regression huggingface dataset:
##a = int(stdin.readline().rstrip())
##b, c = [int(x) for x in stdin.readline().rstrip().split()]
##s = stdin.readline().rstrip()
##a = list(set(b))  重複を削除
##a = list(map(int,[int(x) for x in stdin.readline().rstrip().split()])) a[0, 1, 2, ...]
##a = [[0] * 2 for _ in range(n)]  a[0,0]
##v = [s[i: i+2] for i in range(0, len(s), 2)]
##  s="12345678" を v=["12","34","56","78"] にするイメージ
##s = "".join(list)リストを文字列に変換[""]は区切り文字
##a.sort(key=itemgetter(1))リストをソートできるよ(from operator import itemgetterが必要)
##sort_p = sorted(p) 昇順ソート

# -*- coding: utf-8 -*-
from sys import stdin
from operator import itemgetter
from collections import deque, Counter
import math
import pprint
from functools import reduce
import numpy as np
import random
import bisect
import copy
# stdin = open("sample.txt")


MOD = int(1e9+7)
INF = float('inf')
alpha = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]

def keta(kazu): # 入力されたintを桁ごとに分解，リストで出力
    kazu_str = str(kazu)
    kazu_list = [int(kazu_str[i]) for i in range(0, len(kazu_str))]
    return kazu_list

def gcd(*numbers): # 最小公倍数
    return reduce(math.gcd, numbers)

def combination(m,n): # mCn
    
    if n > m:
        return 'すまん'
    return math.factorial(m) // (math.factorial(m-n) * math.factorial(n))

def pow_k(x,n):  # (x**n)の計算の高速化
    if n == 0:
        return 1
    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2
    return K * x

def fact(n): # nの素因数分解の結果を辞書で出力 fuct(24) → {2: 3, 3: 1}
    arr = {}
    temp = n
    for i in range(2,int(n**0.5)+1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr[i] = cnt
    if temp != 1:
        arr[temp] = 1
    if arr == {}:
        arr[n] = 1
    return arr
    
def main():
   N,X,T = [int(x) for x in stdin.readline().rstrip().split()]
   if N % X != 0:
       print(((N//X)+1)*T)
   else:
       print((N//X)*T)

                
main()

Measured memory_bytes: 27252
// 2020-09-02 23:55:59
// clang-format off
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

// clang-format on
const int inf = 1e9;
int n, a[3], l[8], m[8], s[3], ans;
int calc() {
  int res = 0;
  memset(s, 0, sizeof s);
  rep(i, n) if (m[i] < 3) {
    s[m[i]] += l[i];
    res += 10;
  }
  res -= 30;
  sort(s, s + 3, greater<int>());
  if (s[2] == 0) res += inf;
  rep(i, 3) res += abs(a[i] - s[i]);
  return res;
}
void dfs(int i) {
  if (i == n) {
    chmin(ans, calc());
    return;
  }
  rep(j, 4) {
    m[i] = j;
    dfs(i + 1);
  }
}
void answer() {
  cin >> n;
  rep(i, 3) cin >> a[i];
  rep(i, n) cin >> l[i];
  ans = inf;
  dfs(0);
  cout << ans << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 3584
S = input()

max_leng = 0
i = 0
while i < len(S):
  count = 0
  while S[i] == 'A' or S[i] == 'C' or S[i] == 'G'or S[i] == 'T':
    count += 1
    i += 1
    if i == len(S):
      break
  if max_leng < count:
    max_leng = count
  i += 1
print(max_leng)
    
  
  

Measured memory_bytes: 8984
D,G = map(int,input().split())
P = []
C = []
for i in range(D) :
    p,c = map(int,input().split())
    P.append(p)
    C.append(c)

ans = float("inf")
for i in range(1 << D) :
    ct = 0
    score = 0
    for j in range(D) :
        if i >> j&1 :
            score += C[j]
            score += P[j] * (j+1) * 100
            ct += P[j]
    for j in range(D-1, -1, -1) :
        if i >> j&1 :
            continue
        if score >= G :
            break
        g = (j+1)*100
        got = (G-score+g-1)//g
        score += min(got, P[j])*g
        ct += min(got, P[j])
    ans = min(ans, ct)
print(ans)


Measured memory_bytes: 3064
#include<iostream>
using namespace std

;

int main(){

int W,H,x,y,r,s1,s2;

cin>>W>>H>>x>>y>>r;

if (x-r>=0 && x+r<=W){

s1=0;

} else{

s1=1;

}

if (y-r>=0 && y+r<=H){

s2=0;} else{

s2=1;

}


if (s1==0 && s2==0){

cout<<"Yes"<<"\n";

} else{

cout<<"No"<<"\n";

}

return 0;

}

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

int main() {
	string S;
	cin >> S;
	int s[4];
	for (int i = 0; i < 4; i++) {
		s[i] = S[i] - '0';
		//cout << S[i] << " ";
	}
	//cout << endl<<(1<<3)<<endl;
	int i = 0;
	for (; i < (1 << 3); i++) {
		int sum = s[0];
		for (int j = 0; j < 3; j++) {
			if (i & (1 << j)) {
				sum += s[j + 1];
				
			}
			else {
				sum -= s[j + 1];
				
			}
		}
		///cout << sum<<endl;
		if (sum == 7) {
			break;
		}
	}
	char pm[3];
	for (int j = 0; j < 3; j++) {
		if (i & (1 << j)) {
			pm[j] = '+';
		}
		else {
			pm[j] = '-';
		}
	}
	cout << s[0] << pm[0] << s[1] << pm[1] << s[2] << pm[2] << s[3] << "=7";
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
    int i,j;
    int x,y,s;
 
    int p; 
    int max = 0;
 
    while(1){
        scanf("%d %d %d",&x,&y,&s);
        if(x == 0 && y == 0 && s == 0)break;
 
        for(i=1;i<1000;i++){
            for(j=1;j<1000;j++){
                if(i*(100+x)/100 + j*(100+x)/100 == s){
                    p = i*(100+y)/100 + j*(100+y)/100;
                    //printf("%d %d %lf %lf %d %lf %lf %d\n",i,j,i*x,j*x,(int)(i*x)+(int)(j*x),(i*y),(j*y),p);
                    if(max < p){
                        max = p;
                    }
                }
            }
        }
 
        printf("%d\n",max);
        max = 0;
 
    }
 
    return 0;
}


Measured memory_bytes: 2100
import sys
import math
import decimal

def input():
    return sys.stdin.readline()[:-1]

X, N = map(int, input().split())
P = list(map(int, input().split()))

for i in range(0,101):
    up = X + i
    down = X - i
    if down not in P:
        print(down)
        break
    elif up not in P:
        print(up)
        break
        


Measured memory_bytes: 76972
fun main(args: Array<String>) {
  val n = readLine()!!.toString()
  val lastN = n.substring(n.length - 1)
  val hon = arrayOf("2", "4", "5", "7", "9")
  val pon = arrayOf("0", "1", "6", "8")
  
  hon.forEach { if (it == lastN) { println("hon") } }
  pon.forEach { if (it == lastN) { println("pon") } }
  if (lastN == "3") { println("bon") }
}

Measured memory_bytes: 34412
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr int INF = 2e9;

unsigned int randxor() {
  static unsigned int x=123456789,y=362436069,z=521288629,w=88675123;
  unsigned int t;
  t=(x^(x<<11));x=y;y=z;z=w; return( w=(w^(w>>19))^(t^(t>>8)) );
}




int main() {
  int D;
  cin >> D;
  vector<int> c(26);
  rep(i,26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  vector<int> last_day(26, 0);
  vector<int> t(D);
  rep(i,D) rep(j,26) cin >> s[i][j];

  int score = 0;
  int res = 0;
  auto Scoring = [&](int d, int id, int oid) {
    if (oid != -1) score -= s[d - 1][oid];
    score += s[d - 1][id];
    last_day[id] = d;
    for (int i = 0; i < 26; i++) score -= c[i] * (d - last_day[i]); 
    res = max((int)1e6 + score, 0);
  };

  auto init = [&](){
    while (res < 10000000) {
      for (int i = 0; i < D; i++) {
        int q = randxor() % 26;
        t[i] = q;
        Scoring(i + 1, q, -1);
      }
    }
  };
  
  //計算  
  init();
  /*
  rep(p, 40000000) {

    int d = randxor() % D;
    int change_q = randxor() % 26;    
    int old_q = t[d];
    t[d] = change_q;
    int old_res = res;
    int old_score = score;
    Scoring(d + 1, change_q, old_q);
    if (res < old_res) {
      t[d] = old_q;
      res = old_res;
      score = old_score;
    }
  }

  //cout << res << endl;
  */
  rep(i,D) cout << t[i] + 1 << endl;
  return 0;
} 

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

long long dp[51][51][2501];

int main()
{
  	ios_base::sync_with_stdio(false);
  	cin.tie(NULL);
  	cout.tie(NULL);
	int n, a;
	cin >> n >> a;
	vector<int> x(n+1);
	for(int i=1; i<=n; i++) cin >> x[i];
	for(int i=0; i<=n; i++) dp[i][0][0] = 1;
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=i; j++)
		{
			for(int k=1; k<=n*a; k++)
			{
				if(k < x[i]) dp[i][j][k] = dp[i-1][j][k];
				else dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-x[i]];
			}
		}
	}
	long long ans = 0;
	for(int i=1; i<=n; i++) ans += dp[n][i][i*a];
	cout << ans << "\n"; 
	return 0;
}

Measured memory_bytes: 49024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c,n) for(int i=c;i<n;i++)
 
int main() {
  string s,t;
  cin>>s>>t;
  int n=s.length();

  if(s==t.substr(0,n)){cout<<"Yes"<<endl;}
  else{cout<<"No"<<endl;}
  return 0;
}


Measured memory_bytes: 3624
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int min = scan.nextInt();
		int max = scan.nextInt();
		int n = scan.nextInt();
		
		if ((max - min) / 2 >= n) {
			for (int i = 0; i < n; i++) {
				System.out.println(min + i);
			}
			for (int i = 0; i < n; i++) {
				System.out.println(max - n + 1 + i);
			}
		} else {
			for (int i = min; i <= max; i++) {
				System.out.println(i);
			}
		}
		
	}
}

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

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

//改造
typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    int N;
    vector<ll> A;
    ll K;

    bool check(ll m) {
        vector<ll> B(N);
        for (int i = 0; i < N; ++i) {
            B[i] = A[i] % m;
        }

        ll bsum = accumulate(all(B), 0ll);
        ll k = bsum / m;
        sort(all(B));
        reverse(all(B));
        ll val = 0;
        for (int i = 0; i < k; ++i) {
            val += (m - B[i]);
        }
        return val <= K;
    }

    void solve() {
        cin >> N;
        cin >> K;
        A.resize(N);
        for (int i = 0; i < N; ++i) {
            cin >> A[i];
        }

        ll sumA = accumulate(all(A), 0ll);

        ll ans = 1;

        for (int i = 1; i * i <= sumA; ++i) {
            if (sumA % i == 0) {
                if (check(i)) {
                    chmax(ans, i);
                }
                if (check(sumA / i)) {
                    chmax(ans, sumA / i);
                }
            }
        }
        cout << ans << endl;

    }
};


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

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n-1);
    rep(i,n) cin>>a[i];
    rep(i,n) a[i]--;
    rep(i,n) cin>>b[i];
    rep(i,n-1) cin>>c[i];
    int sum = 0;
    rep(i,n){
        sum+=b[a[i]];
        if(i!=n-1){
            if(a[i]+1==a[i+1]){
                //cout<<i<<"is correct"<<endl;
                sum+=c[a[i]];
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b;
	while(1){
		scanf("%d %d",&a,&b);
		if((a|b)==0){
			break;
		}
		if(a<b){
			printf("%d %d\n",a,b);
		}
		else{
			printf("%d %d\n",b,a);
		}
	}
	return 0;
}



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

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

Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if l[i]!=l[j] and l[j]!=l[k] and l[k]!=l[i] and l[k]-l[j]<l[i]:
                cnt +=1

print(cnt)

Measured memory_bytes: 9136
N = int(input())

A = [int(x) - 1 for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

ans = 0
flag = False
temp = A[0]

for i in range(1, N):
    ans += B[temp]
    if temp == A[i] - 1:
        ans += C[temp]
    temp = A[i]
ans += B[temp]
print(ans)

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
int pr(int n)
{
 for(int i=2;i*i<=n;i++)
      {
          if(n%i==0)
          return 0;
      }
      return 1;
}
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
      int n;
      cin>>n;
      for(int i=n;i<=1000000;i++)
      {
          if(pr(i)==1)
          {
              cout<<i;
              break;
          }
      }
    }
    
}
// 🍪 🍪 🍪


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

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

using namespace std;

int main(){
	int h,w,n; scanf("%d%d%d",&h,&w,&n);
	vector<pair<int,int>> p(n);
	rep(i,n){
		int y,x; scanf("%d%d",&y,&x); y--; x--;
		p[i]={y,x};
	}

	sort(p.begin(),p.end());

	vector Y(w,vector<int>());
	for(auto [y,x]:p) Y[x].emplace_back(y);
	rep(x,w) Y[x].emplace_back(h);

	int ans=h,y=0,x=0;
	while(1){
		ans=min(ans,*upper_bound(Y[x].begin(),Y[x].end(),y));
		if(y==h-1 || binary_search(p.begin(),p.end(),make_pair(y+1,x))){
			break;
		}
		y++;
		if(x<w-1 && !binary_search(p.begin(),p.end(),make_pair(y,x+1))){
			x++;
		}
	}
	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 15948
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  int flag = 0;
  int d = a;
  for(int i=0;i<10000;i++){
    if(d % b ==c) flag=1;
    d += a;
//    cout << d << endl;
  }
  if(flag==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int read()
{
	char ch=getchar();int f=0;
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();}
	return f;
}
struct data
{
	long double x;
	long double y;
	int id;
	long double num;
}h[14];
int cmp(data x,data y)
{
	return x.x<y.x;
}
int main()
{
	long double a,b,c,d;
	cin>>a>>b>>c>>d;h[1].x=a/0.25,h[2].x=b/0.5,h[3].x=c,h[4].x=d/2;
	h[1].y=a,h[2].y=b,h[3].y=c,h[4].y=d;
	h[1].num=0.25,h[2].num=0.5,h[3].num=1,h[4].num=2;
	for(int i=1;i<=4;i++)
	h[i].id=i;
	sort(h+1,h+5,cmp);
	long double n;
	cin>>n;
	if(h[1].id==4)
	{
		int s=n;
		if(s%2)
		{
			printf("%.0Lf",(s/(int)h[1].num)*h[1].y+(1/h[2].num)*h[2].y);
		}
		else
		{
			printf("%.0Lf",(n/h[1].num)*(h[1].y));
		}
	}
	else
	{
		printf("%.0Lf",(n/h[1].num)*h[1].y);
	}
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <queue>
#include <cstring>
using namespace std;

vector<int> m(100001, -1);

int f(int x) {
	if (x == 0) return 0;
	if (m[x] != -1)return m[x];
	int res = x;

	for (int i = 1; i <= x; i *= 6)res = min(res, f(x - i) + 1);
	for (int i = 9; i <= x; i *= 9)res = min(res, f(x - i) + 1);
	return m[x] = res;
}

int main() {
	int N; cin >> N;
	cout << f(N) << endl;
}



Measured memory_bytes: 5376
#include <stdio.h>
#include <limits.h>
#include <math.h>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x);
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 100000000;
typedef double D;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={-1, 0, 1, 0}, dy[4]={0, -1, 0, 1};
using namespace std;
typedef pair<int, int> P;

/** Problem2232 : Ennichi **/
int main()
{
	int H, W, N;
	cin>>H>>W>>N;
	
	char field[H][W];
	rep(i, H) {
		cin>>field[i];
	}
	
	bool flg = false;
	rep(oy, H) {
		rep(ox, W-1) {
			char field2[H][W];
			memcpy(field2, field, sizeof(field));
			swap(field2[oy][ox], field2[oy][ox+1]);
			
			for (int y=H-2; y>=0; y--) {
				for (int x=0; x<W; x++) {
					int ty = y;
					while (ty<H-1 && field2[ty+1][x] == '.') {
						swap(field2[ty][x], field2[ty+1][x]);
						ty++;
					}
				}
			}
			
			while (1) {
				bool update = false;
				bool del[H][W]; memset(del, 0, sizeof(del));
				
				rep(y, H) {
					rep(x, W) {
						char base = field2[y][x];
						int cntH=1;
						
						if (base == '.') continue;
						
						for (int i=x+1; i<W; i++) {
							if (base == field2[y][i])
								cntH++;
							else
								break;
						}
						
						int cntV=1;
						for (int i=y+1; i<H; i++) {
							if (base == field2[i][x])
								cntV++;
							else
								break;
						}
						
						if (cntH>=N) {
							update = true;
							for (int i=0; i<cntH; i++) {
								del[y][x+i] = true;
							}
						}
						
						if (cntV>=N) {
							update = true;
							for (int i=0; i<cntV; i++) {
								del[y+i][x] = true;
							}
						}
					}
				}
				
				rep(y, H) {
					rep(x, W) {
						if (del[y][x])
							field2[y][x] = '.';
					}
				}
				
				if (!update) break;
				
				for (int y=H-2; y>=0; y--) {
					for (int x=0; x<W; x++) {
						int ty = y;
						while (ty<H-1 && field2[ty+1][x] == '.') {
							swap(field2[ty][x], field2[ty+1][x]);
							ty++;
						}
					}
				}
			}
			
			for (int y=0; y<H; y++) {
				for (int x=0; x<W; x++) {
					if (field2[y][x] != '.')
						goto end;
				}
			}
			flg = true;
		end:;
		}
	}
	
	cout << (flg?"YES":"NO") << endl;
}

Measured memory_bytes: 1176
#include <iostream>
#include <cstring>
#include <climits>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <map>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	if(n%10 == 9 || n/10 == 9){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}



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

const int N = 403;

int n;
int a[N], pref[N];
int dp[N][N];

int recur(int i, int j)
{
    if(i == j)
        return 0;
    
    if(dp[i][j] != -1)
        return dp[i][j];

    int ans = 1e18;

    for(int k = i; k <= j - 1; k ++)
        ans = min(ans, recur(i, k) + recur(k + 1, j) + pref[j] - pref[i - 1]);

    return dp[i][j] = ans;
}

int32_t main()
{
    cin >> n;

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

    memset(dp, -1, sizeof(dp));
    cout << recur(1, n);

    return 0;
}


Measured memory_bytes: 1536
def main():
    n, *s = map(int, open(0).read().split())
    s.sort()
    x = [i for i in s if i % 10 != 0]
    t = sum(s)
    if t % 10 != 0:
        ans = t
    elif len(x) > 0:
        ans = t - x[0]
    else:
        ans = 0

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    int k;cin>>k;
    int m=0;
    int prev=1;
    const int inf=1e7;
    for(int i=0;i<inf;i++)
    {
        if(i!=0)
        {
            prev*=10;
            prev%=k;
        }
    	m+=(prev*7)%k;
    	m%=k;
    	if(m==0)
    	{
    		cout<<i+1<<endl;
    		return 0;
    	}
    }
    cout<<-1<<endl;

    return 0;
}

Measured memory_bytes: 3608
# -*- coding: utf-8 -*-
A = int(input())
B = int(input())
C = int(input())
X = int(input())

_500 = 500
_100 = 100
_50 = 50

count = 0

if A > 0:
    for a in range(A+1):
        for b in range(B+1):
            for c in range(C+1):
                if X - (a*_500 + b*_100 + c*_50) == 0:
                    count = count + 1
else:
    if B > 0:
        for b in range(B+1):
            for c in range(C+1):
                if X - (b*_100 + c*_50) == 0:
                    count = count + 1
    else:
        for c in range(C+1):
            if X - (c*_50) == 0:
                count = count + 1

print(count)


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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.1415926535
#define lb lower_bound
#define ub upper_bound
#define bs binary_search

ll power(ll x,ll y,int p)
{
    ll res=1;
    x=x%p;
    while (y > 0)
    {
        if (y & 1)  res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}

ll fact[100000+5];
vector<int> v[100000+5];
ll ans=0;
int vis[100000+5]={0};
int n,k;


void bfs(int r)
{
    vis[r]=1;
    queue <int> q;
    q.push(r);
    while(!q.empty())
    {
        int x=q.front();
        q.pop();
        ll c=0;
        ffor(i,0,(int)v[x].size())
        {
            if(vis[v[x][i]]!=1)
            {
                /* perform operations */
                vis[v[x][i]]=1;
                q.push(v[x][i]);
                c++;
            }
        }
        if(x==1)
        {
            if(k-1<c)
            {
                ans=0;
                return;
            }
            ll p=fact[k-1];
           // p=(p*power(fact[c],mod-2,mod))%mod;
            p=(p*power(fact[k-1-c],mod-2,mod))%mod;
            ans=(ans*p)%mod;
        }
        else
        {
            if(k-2<c)
            {
                ans=0;
                return;
            }
            ll p=fact[k-2];
           // p=(p*power(fact[c],mod-2,mod))%mod;
            p=(p*power(fact[k-2-c],mod-2,mod))%mod;
            ans=(ans*p)%mod;
        }
    }
}

void factt()
{
    fact[0]=1;
    ffor(i,1,100000+5) fact[i]=(i*fact[i-1])%mod;
}

int main()
{
    factt();
    cin>>n>>k;
    ans=k;
    ffor(i,0,n-1)
    {
        int x,y;
        cin>>x>>y;
        v[x].pb(y);
        v[y].pb(x);
    }
    bfs(1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 7672
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b;
  string str;
  cin >> a >> b;
  cin >> str;
  bool x;
  
  if(str.at(a) != '-'){
    cout << "No" << endl;
    return 0;
   }
  
  str.erase(str.begin()+a);
 
  for(int i = 0; i < a+b; i++){
    x = (str.at(i) == '0') || (str.at(i) == '1') || (str.at(i) == '2') || (str.at(i) == '3') || (str.at(i) == '4') || (str.at(i) == '5') || (str.at(i) == '6') || (str.at(i) == '7') || (str.at(i) == '8') || (str.at(i) == '9');
    if(x){
    }else{
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(int argc, const char * argv[]) {
    int i;
    long int j;
    char s[1201];
    char a[27]="abcdefghijklmnopqrstuvwxyz";
    char A[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    long int len;
    gets(s);
    len=strlen(s);
    for(j=0;j<len;j++){
        for(i=0;i<26;i++){
            if(s[j]==a[i]){
                s[j]=A[i];
            }else if(s[j]==A[i]){
                s[j]=a[i];
            }
        }
        printf("%c",s[j]);
    }
    printf("\n");
    return 0;
}

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

int main() {
    int N, M;

    cin >> N;
    vector<string> s_N(N);
    rep2(i, 0, N) cin >> s_N.at(i);

    cin >> M;
    vector<string> s_M(M);
    rep2(i, 0, M) cin >> s_M.at(i);

    vector<string> list(N);
    list.at(0) = s_N.at(0);

    int check, index = 1;

    rep2(i, 1, N){
        check = 0;

        rep2(j, 1, list.size()){
            if(s_N.at(i) == list.at(j)){
                check = 1;
                break;
            }
        }

        if(check == 0){
            list.at(index) = s_N.at(i);
            index++;
        }
    }


    int score, max_score = 0;
    rep2(i, 0, index){
        score = 0;
        rep2(j, 0, N){
            if(list.at(i) == s_N.at(j)) score++;
        }
        rep2(j, 0, M){
            if(list.at(i) == s_M.at(j)) score--;
        }

        if(max_score < score) max_score = score;
    }

    cout << max_score << endl;
}


Measured memory_bytes: 3632
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		String s = fs.next();
		String t = fs.next();
		int min = Integer.MAX_VALUE;
		
		for(int i = 0;i<=s.length()-t.length();i++) {
			String k = s.substring(i,i+t.length());
			int count =0;
			for(int j =0 ;j<t.length();j++) {
				if(t.charAt(j)!=k.charAt(j)) count++;
				
			}
			
			if(min>count) min = count;
			
		}
		
		System.out.println(min);
		
		
		
	}
	
	

	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


class node{
	int data;
	node next;

	node(int data){
		this.data=data;
	}
}

class Methods{
	node head;
	int size =0 ;
	void insert(int data) {
		node n = new node(data);
		size++;
		if(head==null) {
			head= n;
		}
		else {
			node k = head;
			while(k.next!=null) {
				k=k.next;
			}
			
			k.next=n;
		}
		
	}

	void print() {
		node n = head;
		while(n.next!=null) {
			System.out.print(n.data+" ");
			n=n.next;
		}
		System.out.println(n.data);
		
	}
	
	void isLoop(int x) {
		
		System.out.println(size - x +1);
		
		node n = head;
		
		while(n.next!=null && x-->2 ) {
			n=n.next;
		}
		
		n.next=n.next.next;
		
	}
	
	
}




Measured memory_bytes: 33296
#include<stdio.h>
int main(void)
{
	int A, B, K;
	int count = 0;
	int countl = 0;
	scanf("%d%d%d", &A, &B, &K);
	if (B - A <= K) {
		for (int i = A; i <= B; i++) {
			printf("%d\n", i);
		}
	}
	else {
		for (int i = A; i <= B; i++) {
			printf("%d\n", i);
			count++;
			if (count == K)
				break;
		}
		if (K > 2) {
			for (int i = B - K + 1; i <= B; i++) {
				if (count+A-1 < i)
					printf("%d\n", i);
			}
		}
		else {
			for (int i = B - K+1; i <= B; i++) {
				if (count+A-1 < i)
					printf("%d\n", i);
			}
		}
	}

	return 0;
}

Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, k, q;
ll bit[ohara];

ll sum(ll i) {
  ll s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}

void add(ll i, ll x) {
  while (i <= n) {
    bit[i] += x;
    i += i & -i;
  }
}

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

  cin >> n;
  rep(i, n) cin >> a[i];
  rep(i, n) {
    ll cost = sum(a[i]);
    if (cost == 0) ans++;
    add(a[i], 1);
  }
  Cout(ans);
  return 0;
}

Measured memory_bytes: 5888
import math

N = int(input())

box = []
for i in range(1, int(math.sqrt(N) + 1)):
    if N % i == 0:
        box.append(int(N / i)) 

a = box[-1]
b = int(N / a)

kkk = (a-1) + (b-1)

print(kkk)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B);
    int mina = INF;
    rep(i, A) {
        cin >> a[i];
        mina = min(mina, a[i]);
    }
    int minb = INF;
    rep(i, B) {
        cin >> b[i];
        minb = min(minb, b[i]);
    }

    int res = mina + minb;
    vector<pair<P, int>> v;
    rep(i, M) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        res = min(res, a[x] + b[y] - c);
    }


    cout << res << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

int main() {
  int A,B,C; cin >> A >> B >> C;
  if (A+B+C >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}

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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    u32 N;
    cin >> N;
    map<string, u32> D;
    for (u32 i = 0; i < N; i++) {
        string s;
        cin >> s;
        if (D.count(s) == 0) {
            D.insert(make_pair(s, 1));
        } else D[s]++;
    }
    Vec<pair<string, u32>> P;
    map<string, u32>::iterator it;
    u32 max = 0;
    for (it = D.begin(); it != D.end(); it++) {
        P.push_back(make_pair(it->first, it->second));
        if (max < it->second) max = it->second;
    }
    for (u32 i = 0; i < P.size(); i++) {
        if (P[i].second == max)
            cout << P[i].first << endl;
    }
}


Measured memory_bytes: 28016
import java.util.*;

public class Main {
    static int[] a;
    static boolean res;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        a = new int[4];
        
        for(int i = 0; i < 4; i++) a[i] = sc.nextInt();
        
        dfs("");
        
        System.out.println(res ? "YES" : "NO");
        
    }
    
    public static void dfs(String current){
        if(res){
            return;
        }
        
        if(current.length() == 4){
            if(current.equals("1974")){
                res = true;
            }
            return;
        }
        
        dfs(current + a[0]);
        dfs(current + a[1]);
        dfs(current + a[2]);
        dfs(current + a[3]);
        
    }
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

//関数内に大きな配列はNG
ll dp[110][100100] = {0};

int main() {

    ll N, W; cin >> N >> W;

    vector<ll> w(N);
    vector<ll> v(N);
    for (ll i = 0; i < N; ++i) {
        cin >> w[i] >> v[i];
    }

    for (ll i = 0; i < N; ++i) {
        for (ll j = 0; j <= W; ++j) {
            if (j + w[i] <= W) {
                dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i]);
            }

            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    ll ans = 0;

    for (ll i = 0; i <= W; ++i) {
        ans = max(ans, dp[N][i]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 79360
A,B,C=map(int,input().split())

x=C%(A*7+B)
y =C//(A*7+B)

if (C//A)<7:
    if C%A==0:
        print(C//A)
    else:
        print(C//A+1)
        
elif x==0:
    print(y*7)
else:
    z=x%A
    w=x//A
    if w>(A*7):
        print(y*7+7)
    elif w==7 and z<=B:
        print(y*7+7)
    elif z==0:
        print(y*7+w)
    else:
        print(y*7+w+1)


Measured memory_bytes: 5596
import java.util.*;
        public class Main{
          public static void main(String args[]){
            Scanner sc = new Scanner(System.in);
            
            int a = sc.nextInt();
            int b = sc.nextInt();
            int x = 0;
            
            if(a-b == 0){
              System.out.println(1);
            }else{
            x = a-b;
            System.out.println(x+1);
            }
         }
        }

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define F first
#define S second

signed main(){
  int n,m,c,s=0;
  cin>>n>>m>>c;
  int a[m],b[m];
  r(i,m)cin>>b[i];
  while(n--){
    r(i,m)cin>>a[i];
    int p=c;
    r(i,m)p+=a[i]*b[i];
    if(p>0)s++;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 256
w,h=map(int, input().split())
a=[int(input())for i in range(w)]
b=[int(input())for i in range(h)]
from heapq import heappop,heappush
q=[]
w+=1
h+=1
for i in a:
  heappush(q,(i,0))
for i in b:
  heappush(q,(i,1))
ans=0
while q:
  c,t=heappop(q)
  if t==0:
    ans+=h*c
    w-=1
  else:
    ans+=w*c
    h-=1
print(ans)

Measured memory_bytes: 86744
// template ver2.02

// include
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>

using namespace std;

// conversion
inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

// typedef
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

// util
#define MP make_pair
#define EACH(i, c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define CLR(a) memset((a), 0 , sizeof(a))
template<class T, class C> inline bool in(T e, C c) {return c.find(e) != c.end();}
template<class T> inline bool in(T x, T a, T b) {return a <= x && x < b;}

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = (b) - 1; i >= (a); --i)
#define RREP(i, n) RFOR(i, 0, n)

// IO
#define PRA(a, n) cout << a[0]; FOR(itr, 1, n) {cout << " " << a[itr];} cout << endl;
#define PRF(x, w) cout << setprecision((w)); cout << setiosflags(ios::fixed); cout << (x) << endl;

// constant
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = (int)1e9;
const int DI[] = {0, 1, 0, -1};
const int DJ[] = {1, 0, -1, 0};

// debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DUMPA(a, n) cerr << #a << " = {" << a[0]; FOR(itr, 1, n) { cout << ", " << a[itr]; } cerr << "}" << endl;
#define DUMPAA(a, n, m) REP(itr, n) {REP(jtr, m) {cout << a[itr][jtr] << " ";} cout << endl;}

// template end

const int N_MAX = 1000;
const int M_MAX = 100;

int n, m;
int r[N_MAX][M_MAX];

void init()
{
}

void solve()
{
    vector<pii> dp;
    REP(j, m) {
        int s = 0;
        REP(i, n) s += r[i][j];
        dp.push_back(MP(-s, j + 1));
    }
    sort(dp.begin(), dp.end());
    cout << dp[0].second;
    FOR(i, 1, m) cout << ' ' << dp[i].second;
    cout << endl;
}

int main()
{
    init();
    while (cin >> n >> m, n) {
        REP(i, n) REP(j, m) cin >> r[i][j];
        solve();
    }
    return 0;
}


Measured memory_bytes: 1588
#include <iostream>

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

ll n;
string s;
ll dp[30][30]; // ith use #j chars
ll cnt[30];

void solve() {
  for (int i=0;i<n;i++) {
    cnt[s[i] - 'a' + 1]++;
  }
  for (int i=0;i<26;i++) {
    for (int j=1;j<=26;j++) {
      dp[i+1][j] = (dp[i][j] + dp[i][j-1] * cnt[i+1]) % MOD;
      if (j==1) {
        dp[i+1][j] = (dp[i+1][j] + cnt[i+1]) % MOD;
      }
    }
  }
  ll sum = 0;
  for (int i=1;i<=26;i++) {
    sum = (sum + dp[26][i]) % MOD;
  }
  cout << sum << endl;
}

int main() {
  cin >> n;
  cin >> s;
  solve();
}


Measured memory_bytes: 512
// you can use includes, for example:
#include <iostream>
#include <vector>
#include <algorithm>
#include <memory>
#include <unordered_map>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <sstream>
#include <set>
#include <cassert>
#include <map>

using namespace std;

constexpr int64_t kMod = 1e9 + 7;
constexpr int64_t kMaxN = 1e6 + 1;

int64_t din[kMaxN][2];
std::vector<int> gen;
int total = 0;

void Print() {
  for (auto& el : gen) {
    cout << el << " ";
  }
  cout << endl;
}

bool Check(int n) {

  auto check_seg = [&](int l, int r) {
    int cur = gen[l];
    for (int i = l; i <= r; i++) {
      if (gen[i] != cur) {
        return false;
      }
    }
    return true;
  };

  for (int i = 0; i < n - 1; i++) {
    if (!check_seg(i + 1, min(i + gen[i], n - 1))) {
      return false;
    }
  }
  Print();
  return true;
}

void Gen(int i, int n) {
  if (i == n) {
    total += Check(n);
  } else {
    for (int j = 1; j <= n; j++) {
      gen.push_back(j);
      Gen(i + 1, n);
      gen.pop_back();
    }
  }
}

void Test(int n) {
  total = 0;
  Gen(0, n);
  cout << "Correct answer " << total << endl;
}

int main(void) {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
//  Test(n);

  din[1][0] = 1;
  din[1][1] = 1;
  for (int i = 2; i <= n; i++) {
    din[i][0] = din[i - 1][0];
    din[i][0] += din[i - 2][1];
    din[i][0] %= kMod;
    din[i][1] = (din[i - 1][1] + din[i - 1][0]) % kMod;
  }


  auto calc = [&](int rem) {
    if (rem == 0) {
      return static_cast<int64_t>(1LL);
    }
    if (rem == 1) {
      return static_cast<int64_t>(n - 1LL);
    }
    int64_t sum = 0;
    sum += (n - 1) * 1ll * (n - 1);
    sum += n - (rem) + 1;
    sum %= kMod;
    return static_cast<int64_t>(sum);
  };

//  cout << "Din " <<  din[4] << endl;


  int64_t ans = 0;
  for (int i = 0; i <= n; i++) {
    ans += ((i == 0 ? 1LL : din[i][0]) * 1ll * calc(n - i));
//    cout << i << " " << ans << endl;
    ans %= kMod;
  }
  cout << ans << endl;
}


Measured memory_bytes: 15872
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
total=0

for i in range(N):
    if i<N-1:
        if A[i+1]==A[i]+1:
            total+=C[A[i]-1]
    total+=B[A[i]-1]
    

print(total)

Measured memory_bytes: 3064