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

using namespace std;

template<int MOD>
struct ModInt {
   using Mint = ModInt;
   int val;
   ModInt(int64_t __val = 0) { fix(__val % MOD + MOD); }
   Mint& fix(int __val) { val = __val; if (val >= MOD) val -= MOD; return *this; }
   explicit operator int() { return val; }
   Mint operator + (const Mint &mt) const { return Mint().fix(val + mt.val); }
   Mint operator - (const Mint &mt) const { return Mint().fix(val - mt.val + MOD); }
   Mint operator * (const Mint &mt) const { return Mint().fix(int64_t(val) * mt.val % MOD + MOD); }
   Mint& operator += (const Mint &mt) { return *this = *this + mt; }
   Mint& operator -= (const Mint &mt) { return *this = *this - mt; }
   Mint& operator *= (const Mint &mt) { return *this = *this * mt; }
   Mint pow(int y) const {
      Mint x = *this;
      Mint ans(1);
      for (; y > 0; y >>= 1, x *= x) {
         if (y & 1) ans *= x;
      }
      return ans;
   }
   Mint operator -() const { return Mint().fix(MOD - val); }
   Mint inv() const { return pow(MOD - 2); }
   Mint operator / (const Mint &mt) const { return *this * mt.inv(); }
   Mint& operator /= (const Mint &mt) const { return *this / mt; }
   friend ostream& operator<<(ostream& os, const Mint& mt) { return os << mt.val; }
};

using Mint = ModInt<1000000007>;

int main() {
   ios_base::sync_with_stdio(false); cin.tie(nullptr);
   int N; cin >> N; N /= 3;
   vector<int> A(3*N);
   vector<int> B(3*N);
   vector<int> invA(3*N);
   vector<int> invB(3*N);
   for (int i = 0; i < 3*N; ++i) cin >> A[i], invA[--A[i]] = i;
   for (int i = 0; i < 3*N; ++i) cin >> B[i], invB[--B[i]] = i;
   vector<vector<Mint>> ways(N+1, vector<Mint>(2*N+1));
   ways[0][0] = 1;
   for (int i = 0; i <= N; ++i) {
      for (int j = 2*i; j >= 0; --j) {
         if (i < N) ways[i+1][j+2] += ways[i][j];
         if (j) ways[i][j-1] += ways[i][j] * j;
      }
   }
   vector<vector<bool>> isGood(3*N, vector<bool>(3*N));
   vector<vector<int>> cnts(3*N, vector<int>(3*N));
   for (int i = 0; i < 3*N; ++i) {
      for (int j = 0; j < 3*N; ++j) {
         isGood[i][j] = (invB[A[i]] > j && invA[B[j]] > i);
         for (int z = 0; z < 3*N; ++z) if (invA[z] <= i || invB[z] <= j) cnts[i][j]++;
      }
   }
   vector<vector<Mint>> dp(3*N, vector<Mint>(3*N));
   for (int z = N-1; z >= 0; --z) {
      vector<vector<Mint>> ndp(3*N, vector<Mint>(3*N));
      for (int i = 0; i < 3*N; ++i) {
         for (int j = 0; j < 3*N; ++j) if (isGood[i][j]) {
            ndp[i][j] = 3*N - (N-1-z) * 3 - cnts[i][j];
            if (z < N-1) {
               if (i == 3*N-1 || j == 3*N-1) ndp[i][j] = 0;
               else ndp[i][j] *= dp[i+1][j+1];
            }
         }
      }
      dp.swap(ndp);
      for (int i = 3*N-1; i >= 0; --i) {
         for (int j = 3*N-1; j >= 0; --j) {
            if (i+1 < 3*N) dp[i][j] += dp[i+1][j];
            if (j+1 < 3*N) dp[i][j] += dp[i][j+1];
            if (i+1 < 3 * N && j+1 < 3*N) dp[i][j] -= dp[i+1][j+1];
         }
      }
   }
   cout << dp[0][0] * ways[N][0] << '\n';
   return 0;
}


Measured memory_bytes: 5332
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
typedef priority_queue<LL> PQ_DESC;
typedef priority_queue<LL, VL, greater<LL>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;
typedef priority_queue<VL> PQ_DESC_VL;
typedef priority_queue<VL, vector<VL>, greater<VL>> PQ_ASC_VL;
typedef priority_queue<PLL> PQ_DESC_PLL;
typedef priority_queue<PLL, vector<PLL>, greater<PLL>> PQ_ASC_PLL;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
//#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SORT_DESC(c) sort((c).rbegin(),(c).rend())
#define REV(c) reverse((c).begin(), (c).end())
#define SIZE(a) int((a).size())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ROF(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n) FOR(i,0,n)
#define PER(i,n) ROF(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF*(LL)INF;
const int MOD = 1e9+7;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

void Main()
{
    LL n;cin>>n;
    VL a(n);
    REP(i,n){
        cin>>a[i];
    }

    LL result = 0;
    LL now = a[0];

    FOR(i,1,n){
        result += now * a[i];
        result %= MOD;
        now += a[i];
        now %= MOD;
    }
    cout<<result<<endl;
    
	return;
}

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

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

int main(void) {
  string a, b;

  cin >> a >> b;

  int connected_int = stoi(a + b);


  bool is_square = false;
  for (int i = 1; i < 100110; i++) {
    if (i * i == connected_int) {
      is_square = true;
    }
  }

  if (is_square) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

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

int main()
{
    int h, n;
    cin >> h >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++)
    {
        cin >> as[i];
    }
    int sum = 0;
    for (auto &&i : as)
    {
        sum += i;
    }
    if (sum >= h)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	int i, j, n, y, b, r, t, max;
	double bank[50];
	
	while (scanf("%d", &n), n != 0){
		for (i = 0; i < 50; i++){
			bank[i] = 0;
		}
		
		scanf("%d", &y);
		
		for (i = 0; i < n; i++){
			scanf("%d %d %d", &b, &r, &t);
			
			if (t == 1){
				bank[b - 1] = 1 + y * r / 100.0;
			}
			
			else if (t == 2){
				bank[b - 1] = 1;
				
				for (j = 0; j < y; j++){
					bank[b - 1] *= (1 + r / 100.0);
				}
			}
		}
		
		for (i = 0, max = 0; i < 50; i++){
			if (bank[max] < bank[i]){
				max = i;
			}
		}
		
		printf("%d\n", max + 1);
	}
	
	return (0);
}

Measured memory_bytes: 600
#include "bits/stdc++.h"

using namespace std;

int main() {
	vector<int>X(5);
	for (int n = 0; n< 5; ++n) {
		cin >> X[n];
	}
	for (int n = 0; n < 5; ++n) {
		if (0 == X[n]) {
			cout << n + 1 << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <unordered_map>

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

    std::unordered_map<long, int> mp;
    long a, ans = 0, sum = 0;
    ++mp[0];
    for (int i = 0; i < n; ++i) {
        scanf("%ld", &a);
        sum += a;
        ans += mp[sum];
        ++mp[sum];
    }
    printf("%ld\n", ans);
}
/*
累積和が等しい2点間の、連続する部分列の和は０になる。
ある累積和がn個存在するとき、n個の中から2点を選ぶ組み合わせはnC2通り。

累積和１が３回現れる場合。
1回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 0 <- 初回の累積和はカウントされない
    ++mp[sum];  // mp[1] = 1

2回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 1 <- 累積和１が２回出たのでansがカウントされる。2C2=1通り
    ++mp[sum];  // mp[1] = 2 <- 累積和１が２点に存在する

3回目：
    sum += a;  // sum = 1
    ans += mp[sum];  // mp[1] = 2 <- 累積和１が３回出たのでansがカウントされる。3C2=3通り
    ++mp[sum];  // mp[1] = 3 <- 累積和１が３点に存在する
*/


Measured memory_bytes: 8520
#include <iostream>

int main() {

	int N = 0;
	int b[99] = { 0, };
	int ans[99] = { 0, };
	int ansC = 0;
	std::cin >> N;

	for (int i = 0; i < N; i++)
		std::cin >> b[i];



	for (int i = N; i > 0; i--) {

		for (int j = i; j > 0; j--) {

			if (j == b[j-1]) {

				ans[ansC++] = j;

				for (int k = j; k < N ; k++) {
					b[k-1] = b[k];
				}
			
				break;
			}

		}

	}


	if (ansC == N) {
		for (int i = ansC; i > 0; i--)
			std::cout << ans[i-1] << std::endl;
	}
	else {
		std::cout << -1 << std::endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int n = s.length();
		int n1 = n / 2;
		String s1 = s.substring( 0 , n1);
		String s2 = s.substring(n1 + 1);
		int i=0;
		int j = n-1;
		boolean c1 = true;
		while(i < j){
		    if(s.charAt(i) != s.charAt(j)){
		        c1 = false;
		        break;
		    }
		    i++;
		    j--;
		}
		i =0;
		j = s1.length()-1;
		boolean c2 = true;
        while(i < j){
		    if(s1.charAt(i) != s1.charAt(j)){
		        c2 = false;
		        break;
		    }
		    i++;
		    j--;
		}
		i = 0;
		j = s2.length()-1 ;
		boolean c3 = true;
        while(i < j){
		    if(s2.charAt(i) != s2.charAt(j)){
		        c3 = false;
		        break;
		    }
		    i++;
		    j--;
		}
		if(c1&&c2&&c3){
		    System.out.println("Yes");
		}else{
		    System.out.println("No");
		}
	}
}


Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;
typedef long long ll;

int m[2010][2010];
int N,X,Y;
int c[2010];

int main(){
    cin >> N >> X >> Y;
    for(int i=0;i<N;i++) c[i] = 0;
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            c[min(j-i,abs(X-i-1) + abs(Y-1-j)+ 1)]++;
        }
    }
    for(int i=1;i<N;i++){
        cout << c[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#define N 200000
#define MOD 1000000007
using namespace std;
typedef long long LL;
LL fac[N+1];
LL fac_inv[N+1];
LL mod_pow(LL base, LL exp)
{
	if(exp==0) return 1;
	if(exp&1) return (base*mod_pow(base,exp-1))%MOD;
	else return mod_pow((base*base)%MOD,exp/2);
}
LL C(LL n, LL k)
{
	if(k < 0 || n < k) return 0;
	LL num = fac[n];
	LL den = (fac_inv[k]*fac_inv[n-k])%MOD;
	return (num*den)%MOD;
}
LL paths(LL h, LL w)
{
	return C(h-1+w-1,h-1);
}
int main()
{
	fac[0] = 1;
	for(LL n = 1; n <= N; n++)
		fac[n] = (fac[n-1]*n)%MOD;
		
	fac_inv[N] = mod_pow(fac[N],MOD-2);
	for(LL n = N-1; n >= 0; n--)
		fac_inv[n] = (fac_inv[n+1]*(n+1))%MOD;
		
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	LL h, w, a, b; cin >> h >> w >> a >> b;
	
	LL ans = 0;
	for(LL i = h-a, j = b+1; i > 0 && j <= w; i--, j++)
		ans = (ans+paths(i,j)*paths(h-i+1,w-j+1))%MOD;
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 3328
def solve():
    from bisect import bisect_right, bisect, bisect_left
    x = int(input())
    n = 100100
    primes = set(range(2, n + 1))
    for i in range(2, int(n ** 0.5 + 1)):
        if i not in primes:
            i += 1
        else:
            ran = range(i * 2, n + 1, i)
            primes.difference_update(ran)
    primes = list(primes)
    y = bisect_left(primes, x)
    print(primes[y])
    
    
solve()


Measured memory_bytes: 20640
n = int(input())
ls = list(map(int,input().split()))
di = [0]*n
di[0] = sum(ls)//2 - sum(ls[1::2])
for i in range(1,n):
    di[i] = ls[i-1] - di[i-1]
di = list(map(lambda x:2*x,di))
print(*di)

Measured memory_bytes: 20788
# 整数の入力
N = int(input())
A = [int(a) for a in input().split()]
Q = int(input())
process = []
proc_append = process.append
hash = [0]*100001
for i in range(Q):
    proc_append(tuple(input().split()))
    process[i] = tuple(map(int,process[i]))

goukei = sum(A)

for i in A:
	hash[i] += 1

for b,c in process:
	if hash[b] != 0:
		goukei += (c-b)*hash[b]
		hash[c] += hash[b]
		hash[b] = 0
	print(goukei)

Measured memory_bytes: 28124
#include<bits/stdc++.h>
 
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
#define int  long long
#define pb push_back
#define pii pair<int,int>
#define fr(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define ccM 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
long double pi = 3.14159265358979323;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
int max(int b,int a){if(b>a)return b;else return a;}
int min(int b,int a){if(b<a)return b;else return a;}
int Abs(int b){return max(b,-b);}
bool sortbysec(const pair<string,int> &a, const pair<string,int> &b){if(a.first==b.first)return a.second<b.second; return a.first<b.first;}

int32_t main()
{
	int a,b;
	cin>>a>>b;
	int d=(a*b)/__gcd(a,b);
	cout<<d<<endl;	
	
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

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

        switch (s) {
            case "A":
                System.out.println("T");
                break;
            case "T":
                System.out.println("A");
                break;
            case "C":
                System.out.println("G");
                break;
            case "G":
                System.out.println("C");
                break;
        }


    }
}


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

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(0); cin.tie(NULL);
    int n;
    cin >> n;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    const int INF = 1e5+9;
    int dp[n];
    dp[0] = 0;
    dp[1]=abs(a[1]-a[0]);
    
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1]; 
    //return 0;
}   

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

const int INF = 1<<28;

int main() {
  for(int n, d; cin >> n >> d && (n|d);) {
    vector<vector<int> > c(n);
    for(int i = 0; i < n; ++i) {
      int m; cin >> m;
      c[i].resize(m);
      for(int j = 0; j < m; ++j) cin >> c[i][j];
    }
    vector<int> sum(n);
    for(int i = 0; i < n; ++i) {
      sum[i] = accumulate(c[i].begin(), c[i].end(), 0);
    }
    while(1) {
      bool update = false;
      for(int i = 0; i < n; ++i) {
        if(c[i].empty()) continue;
        sum[i] -= c[i].back();
        if(*max_element(sum.begin(), sum.end())
           - *min_element(sum.begin(), sum.end()) <= d) {
          c[i].pop_back();
          update = true;
        } else {
          sum[i] += c[i].back();
        }
      }
      if(!update) break;
    }
    if(accumulate(sum.begin(), sum.end(), 0)) {
      cout << "No" << endl;
    } else {
      cout << "Yes" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
const int mod = 998244353;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<int> l(k), r(k);
    rep(i, k) scanf("%d%d", &l[i], &r[i]);

    vector<mint> dp(n + 1); //dp[i]はiに行く場合の数
    vector<mint> dpsum(n + 1);

    dp[1] = 1; //dp
    dpsum[1] = 1; //累積和

    // もらうdpで考える。
    // 1は初期化でやってるので、2マス目から
    for (int i = 2; i <= n; ++i) {
        rep(j, k) {
            int li = i - r[j]; //足す区間の左端
            int ri = i - l[j]; //足す区間の右端
            if (ri < 0) continue; //右端がマイナスの場合実行しない
            li = max(li, 1);  //左端がマイナスにならないように
            dp[i] += dpsum[ri] - dpsum[li - 1];  // dpsum[li - 1]は区間外の部分;
        }
        dpsum[i] = dpsum[i - 1] + dp[i]; //dpsum累積和を更新
    }

    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 6428
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    int n, k;
    cin >> n >> k;
    int result = 1;
    for (int i = 0; i < n; i++) {
        if (result * 2 < result + k)
            result *= 2;
        else
            result += k;
    }
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
s = list(input())
ans = 0

for i in range(len(s)):
    if s[0] == '0':
        if i % 2 == 0:
            if s[i] != '0':
                ans += 1
        else:
            if s[i] != '1':
                ans += 1
    else:
        if i % 2 == 0:
            if s[i] != '1':
                ans += 1
        else:
            if s[i] != '0':
                ans += 1
            
print(ans)

Measured memory_bytes: 3956
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<numeric>
#include<map>
#include<unordered_map>
#include<queue>
#include<deque>
 
using namespace std;
using ll=long long;
#define rep(i,n)  for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()
 
int main(){
    ll n, k;
    cin >> n >> k;
    ll r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;
    rep(i, n){
        if(t[i] == 'r')t[i] = 'p';
        else if(t[i] == 's')t[i] = 'r';
        else t[i] = 's';
    }

    ll ans = 0;
    char taka[n];
    rep(i, n){
        if(i < k){
            if(t[i] == 'r')ans += r, taka[i] = 'r';
            else if(t[i] == 's')ans += s, taka[i] = 's';
            else ans += p, taka[i] = 'p';
        } 
        else if(t[i] != taka[i-k]){
            if(t[i] == 'r')ans += r, taka[i] = 'r';
            else if(t[i] == 's')ans += s, taka[i] = 's';
            else ans += p, taka[i] = 'p';
        }
        else if(i+k < n){
            if(t[i] == 'r'){
                if(t[i+k] == 's')taka[i] = 'p';
                else taka[i] = 's';
            }
            else if(t[i] == 's'){
                if(t[i+k] == 'r')taka[i] = 'p';
                else taka[i] = 'r';
            }
            else {
                if(t[i+k] == 's')taka[i] = 'r';
                else taka[i] = 's';
            }
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int arr[11],arr2[11];
int mem[11][100005*2];
int n,m;

int go(int ind,int res)
{
	if(res<=0) return 0;
	if(ind>n) return (1<<30);
	if(mem[ind][res]!=-1) return mem[ind][res];
	mem[ind][res]=(1<<30);
	for(int i=0;i<=arr[ind];i++)
	{
		mem[ind][res]=min(mem[ind][res],i+go(ind+1,res-i*ind-(i==arr[ind]?arr2[ind]:0)));
	}
	return mem[ind][res];
}

int main()
{
	cin >> n >> m;
	for(int i=1;i<=n;i++) {cin >> arr[i] >> arr2[i]; arr2[i]/=100;}
	memset(mem,-1,sizeof mem);
	cout << go(1,m/100) << endl;
	return 0;
}

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

#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef long long int ll;

using namespace std;

ll f(ll n, ll p) { return (n % p == 0 ? n / p : n / p + 1); }
int main() {
  ll N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;
  ll ans = max(f(N, A), f(N, B));
  ans = max(ans, f(N, C));
  ans = max(ans, f(N, D));
  ans = max(ans, f(N, E));
  cout << ans + 4 << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void) {
	int suma, sumb, tmp;
	int i;

	suma = 0;
	for(i = 0; i < 4; i++) {
		cin >> tmp;
		suma += tmp;
	}
	sumb = 0;
	for(i = 0; i < 4; i++) {
		cin >> tmp;
		sumb += tmp;
	}

	cout << max(suma, sumb) << endl;

	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;

const int N = 200010;
const int mod = 998244353;

char s[N];
int n, fl, ans, tmp;
int vis[N], f[N][3], h[N][3][3];

void brute_force()
{
    int tmp = 0;
    FOR(i, 1, n) tmp = tmp * 10 + s[i] - 'a' + 1;
    if (vis[tmp]) return; else ++ans, vis[tmp] = 1;

    FOR(i, 1, n - 1) if (s[i] != s[i + 1])
    {
        char t1 = s[i], t2 = s[i + 1], t3 = 'a' + 'b' + 'c' - t1 - t2;
        s[i] = s[i + 1] = t3; brute_force();
        s[i] = t1, s[i + 1] = t2;
    }
}

int main()
{
    scanf("%s", s + 1); n = strlen(s + 1);

    FOR(i, 2, n) if (s[i] != s[1]) fl = 1;
    if (!fl) {puts("1"); return 0;}

    if (n <= 3) {brute_force(); printf("%d\n", ans); return 0;}

    FOR(i, 2, n) if (s[i] == s[i - 1]) fl = 0;
    if (fl) ans = 1;

    FOR(i, 1, n) tmp += s[i] - 'a'; tmp %= 3;

    f[0][0] = 1;
    FOR(i, 0, n - 1) FOR(j, 0, 2) FOR(k, 0, 2)
        (f[i + 1][(j + k) % 3] += f[i][j]) %= mod;
    (ans += f[n][tmp]) %= mod;

    FOR(i, 0, 2) h[1][i][i] = 1;
    FOR(i, 1, n - 1) FOR(j, 0, 2) FOR(k, 0, 2) FOR(l, 0, 2)
        if (l != k) (h[i + 1][(j + l) % 3][l] += h[i][j][k]) %= mod;
    FOR(i, 0, 2) (ans += mod - h[n][tmp][i]) %= mod;

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 10496
N, M = [int(n) for n in input().split()]

def main():
    ps = [[] for _ in range(N)]

    for m in range(M):
        p, y = [int(n) for n in input().split()]
        pref = ps[p - 1]
        pref.append([m, y])

    result = []

    for i, pref in enumerate(ps):
        pref.sort(key=lambda p: p[1])
        for j, p in enumerate(pref):
            result.append([p[0], '{:06}{:06}'.format(i + 1, j + 1)])

    result.sort(key=lambda x: x[0])

    ans = '\n'.join(map(lambda p: p[1], result))
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 51028
//52行目から編集
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <cassert>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

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

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    double l;cin >> l;
    l = l / (double)3;
    cout << l*l*l << '\n';
    return 0;
}


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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

// void c_p_c()
// {
// 	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
// }

int main(){
	//c_p_c();
	ll n; cin >> n;
	ll ans = 0;
	ans += (n/500)*1000;
	n = n%500;
	ans += (n/5)*5;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  string ans = (b - a == c - b) ? "YES" : "NO";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3520
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pl = pair<ll, int>;


void Main() {
	int n;
	cin >> n;
  if(n%10 == 3) puts("bon");
  else if(n%10 == 0 | n%10 == 1 | n%10 == 6 |n%10 == 8) puts("pon");
  else puts("hon");
	return;
}

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


Measured memory_bytes: 3644
import java.util.*;
import java.math.*;

public class Main {

  static int k;

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    k = sc.nextInt();
    ArrayList<Long> list = new ArrayList<Long>();
    for (long i = 1; i < 10; i++) {
      list.add(i);
    }
    int c = 0;
    while (list.size() < k) {
      long a = list.get(c);
      if (a%10 != 0) list.add((a*10) + (a%10)-1);
      list.add((a*10) + (a%10));
      if (a%10 != 9) list.add((a*10) + (a%10)+1);
      c++;
    }
    System.out.println(list.get(k-1));
  }

}


Measured memory_bytes: 25940
#include <iostream>

using namespace std;

int main()
{

  int N,X,cnt=0,sum=0;
  int a[105];
  cin>>N>>X;
  for (int i = 0; i < N; i++)
      cin>>a[i];
  int mins=a[0];
  for (int j=1;j<N;j++)
      if (a[j]<mins)
          mins=a[j];
  for (int r=0; r<N; r++)
  {
      sum+=a[r];
      cnt++;
  }
  cnt=cnt+(X-sum)/mins;
  cout<<cnt<<endl;
    return 0;
}






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

using namespace std;

int N;
string s, t;

int main(void) {

	cin >> N;

	cin >> s >> t;

	int ans = 2*N;

	for (int q = 0; q < N; q++) {
		bool sign = true;
		for (int i = q; i < N; i++) {
			if (s[i] != t[i-q]) { sign = false; }
		}
		if (sign) { ans = min(ans, q + N); }
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    private static Scanner scn = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String sa = scn.next();
        String sb = scn.next();
        String sc = scn.next();
        int la = sa.length();
        int lb = sb.length();
        int lc = sc.length();
        int a = 0;
        int b = 0;
        int c = 0;
        int n = 0;
        while (true) {
            char t = ' ';
            if (n==0) {
                if (a==la) {
                    System.out.println("A");
                    return;
                }
                t = sa.charAt(a++);
            } else if (n==1) {
                if (b==lb) {
                    System.out.println("B");
                    return;
                }
                t = sb.charAt(b++);
            } else if (n==2) {
                if (c==lc) {
                    System.out.println("C");
                    return;
                }
                t = sc.charAt(c++);
            }
            if (t=='a') {
                n = 0;
            } else if (t=='b') {
                n = 1;
            } else if (t=='c') {
                n = 2;
            }
        }
    }
}


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

long ans;
long M, N, K;
long X, Y;
long H, W;
// vector<long> A, B, C;
// vector<long> P;
vector<string> C;

int main(void) {

    cin >> H >> W >> K;
    for (long i = 0; i < H; i++) {
        string s; cin >> s;
        C.push_back(s);
    }

    
    for (long i = 0; i < (1 << H); i++) {
        for (long j = 0; j < (1 << W); j++) {
            long counter = 0;
            for (long h = 0; h < H; h++) {
                for (long w = 0; w < W; w++) {
                    if ((i & (1 << h)) | (j & (1 << w))) continue;
                    if (C[h][w] == '#') counter++;
                }
            }
            if (counter == K) {
                ans++;
            }
        }
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 3624
import math

def isPutNum(board, x, y, n):
    for i in range(9):
        if board[x][i] == n:
            return False
    for i in range(9):
        if board[i][y] == n:
            return False
    xx = math.floor(x / 3)
    yy = math.floor(y / 3)
    for i in range(3):
        for j in range(3):
            if board[xx*3 + i][yy*3 + j] == n:
                return False
    return True

N = int(input())
table = [[0 for i in range(9)] for j in range(9)]
for l in range(N):
    if l > 0:
        print("")

    for i in range(9):
        table[i] = [int(j) for j in input().split()]

    for i in range(9):
        for j in range(9):
            tmp = table[i][j]
            table[i][j] = 0
            if isPutNum(table, i, j, tmp):
                print(" ", end="")
            else:
                print("*", end="")
            table[i][j] = tmp
            print(table[i][j], end="")
        print("")


Measured memory_bytes: 5696
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
ll n,h,w;
int main()
{
    gbtb;
    cin>>n>>h>>w;
    ll ans=(n-h+1)*(n-w+1);
    cout<<ans<<endl;
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}



Measured memory_bytes: 256
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <cassert>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, b, a) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    vector h_s(n, vector(3, 0));
    rep(i, n)
    {
        cin >> h_s[i][0] >> h_s[i][1] >> h_s[i][2];
    }

    // i日後の幸福度
    vector<int> dp(3), dptmp(3);

    dp = {0, 0, 0};

    rep(i, n)
    {
        // dptmp = dp;

        rep(j, 3)
        {
            dptmp[j] = max(dp[(j + 1) % 3] + h_s[i][(j + 1) % 3], dp[(j + 2) % 3] + h_s[i][(j + 2) % 3]);
        }

        swap(dp, dptmp);
    }

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

    return 0;
}


Measured memory_bytes: 8716
from collections import deque

class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N, K = map(int, input().split())
MOD = 10**9 + 7
edges = [[] for _ in range(N)]

for _ in range(N - 1):
    fr, to = map(int, input().split())
    fr -= 1
    to -= 1
    edges[fr].append(to)
    edges[to].append(fr)

comb = Combination(N + K + 100)

chCnt = [0] * N
que = deque([(0, -1)])
while que:
    now, pr = que.popleft()
    chCnt[now] = len(edges[now]) - 1
    for to in edges[now]:
        if to != pr:
            que.append((to, now))
chCnt[0] += 1

ans = K
que = deque([(0, -1)])
while que:
    now, pr = que.popleft()

    if pr == -1:
        ans *= comb.npr(K - 1, chCnt[now])
    else:
        ans *= comb.npr(K - 2, chCnt[now])

    ans %= MOD
    for to in edges[now]:
        if to != pr:
            que.append((to, now))

print(ans % MOD)


Measured memory_bytes: 55248
#include <stdio.h>
int main(void){
    int x;
    scanf("%d",&x);
    if(x%7==0){
        printf("thu\n");
    }if(x%7==1){
        printf("fri\n");
    }if(x%7==2){
        printf("sat\n");
    }if(x%7==3){
        printf("sun\n");
    }if(x%7==4){
        printf("mon\n");
    }if(x%7==5){
        printf("tue\n");
    }if(x%7==6){
        printf("wed\n");
    }
    return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        
        if      (a == b) System.out.println("a == b");
        else if (a < b)  System.out.println("a < b");
        else             System.out.println("a > b");
    }
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define ull unsigned long long
#define mk make_pair
#define pb push_back
#define eps 1e-12
#define MAXN 200009
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k;
	cin>>n>>k;
	if(k>((n-1)*(n-2))/2)
	{
		cout<<-1<<endl;
	}
	else
	{
		cout<<((n*(n-1))/2)-k<<endl;
		int a[n+1][n+1];
		for(int i=1;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				a[i][j]=1;
			}
		}
		for(int i=1;i<=n-2;i++)
		{
			for(int j=i+1;j<n;j++)
			{
				if(k)
				{
					a[i][j]=0;
					k--;
				}
			}
		}
		for(int i=1;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
			{
				if(a[i][j])
				{
					cout<<i<<" "<<j<<endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
int main(void){
    long long int N;
    cin>>N;
    string S[N];
    long long int count=1;
    for(int i=0;i<N;i++){
        string s;
        cin>>S[i];
    }
    sort(S,S+N);
    for(int i=1;i<N;i++){
        if(S[i]!=S[i-1]){
            count++;
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 9884
#include <iostream>

using namespace std;

int main() {
  int N;
  cin >> N;
  long long L[87] = {2,1};
  for(int i = 2; i <= N; i++) {
    L[i] = L[i - 2] + L[i - 1];
  }
  cout << L[N] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

int main(void) {
  int m = 0;
  int f = 0;
  int r = 0;

  std::cin >> m >> f >> r;

  while(!((m < 0) && (f < 0) && (r < 0))) {
    int total = m + f;
    char grade = 'F';

    if ((m < 0) || (f < 0))  {
      grade = 'F';
    }  else if (total >= 80) {
      grade = 'A';
    } else if((total >= 65) && (total < 80)) {
      grade = 'B';
    } else if((total >= 50) && (total < 65)) {
      grade = 'C';
    } else if((total >= 30) && (total < 50)) {
      if (r >= 50) {
	grade = 'C';
      } else {
	grade = 'D';
      }
    } else {
      grade = 'F';
    }
    
    std::cout << grade << std::endl;
    
    std::cin >> m >> f >> r;
  }
  

  return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int a[100], b[100];

int main()
{
	int n;
	cin >> n;

	int j = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			b[j] = a[i];
			j++;
		}
	}


	for (int i = 0; i < j; i++) {
		if (b[i] % 3 != 0 && b[i] % 5 != 0) {
		cout << "DENIED";
		return 0;
		}
	}

	cout << "APPROVED";
}

Measured memory_bytes: 3624
#include <stdio.h>

int ball(int *w,int x,int y,int z){
  int a=0;
  if(z==9 && (w[0]>x || w[0] >y)) a=1;
  else {
    if(w[0]>x) a+=ball(w+1,w[0],y,z+1);
    if(w[0]>y) a+=ball(w+1,x,w[0],z+1);
  }
  return a;
}

int main(){
  int a,b[10],i,j;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    for(j=0;j<10;j++){
      scanf("%d",b+j);
    }
    if(ball(b,0,0,0)==0) printf("NO\n"); else printf("YES\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
////////////////////////////////////////////////////////////////////////
const ll INF = (ll)1e9;
const ll MAX_N = 1000, MAX_M = 1000000;
////////////////////////////////////////////////////////////////////////
ll dist[MAX_N][MAX_N];
ll N, M;

void init_dist() {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dist[i][j] = (i == j) ? 0 : INF;
    }
  }
}

void Warshall_Floyd() {
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }
}
////////////////////////////////////////////////////////////////////////

int a[MAX_M], b[MAX_M], c[MAX_M];

void abc051c() {
  init_dist();
  for (int i = 0; i < M; i++) {
    dist[a[i]][b[i]] = dist[b[i]][a[i]] = c[i];
  }

  Warshall_Floyd();

  ll res = M;
  for (int i = 0; i < M; i++) {
    bool used = false;
    for (int j = 0; j < N; j++) {
      if (dist[j][a[i]] == dist[j][b[i]] + c[i]) {
        used = true;
        break;
      }
    }
    if (used) {
      res--;
    }
  }
  cout << res << "\n";
  return;
}

int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  abc051c();
  return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4000 + 10;
int a[maxn][maxn];
char op[10];
int n, k, m;
int sum(int x, int y) 
{
	int xl = x < 1 ? 1 : x, yl = y < 1 ? 1 : y;
	int xr = x + k - 1 > m ? m : x + k - 1, yr = y + k - 1 > m ? m : y + k - 1;
	int ret = a[xr][yr] - a[xl - 1][yr] - a[xr][yl - 1] + a[xl - 1][yl - 1];
	return ret;
}
int solve1(int x, int y)
{
	return sum(x, y) + sum(x - k, y - k) + sum(x - k, y + k) + sum(x + k, y - k) + sum(x + k, y + k);
}
int solve2(int x, int y)
{
	return sum(x - k, y) + sum(x + k, y) + sum(x, y - k) + sum(x, y + k);
}
int main()
{
	scanf("%d%d", &n, &k);
	m = k << 1;
	for(int i = 1; i <= n; ++i) 
	{
		int x, y;
		scanf("%d%d%s", &x, &y, op);
		if(op[0] == 'W') y += k;
		x = (x % m + m) % m + 1;
		y = (y % m + m) % m + 1;
		++a[x][y];
	}
	for(int i = 1; i <= m; ++i)
		for(int j = 1; j <= m; ++j)
			a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
	int ans = 0;
	for(int i = 1; i <= k; ++i)
		for(int j = 1; j <= k; ++j)
		{
			ans = max(ans, solve1(i, j));
			ans = max(ans, solve2(i, j));
		}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 27436
import math

D, G = map(int, input().split())
G = G // 100

N = [0] * D
score = [0] * D

for i in range(D):
    N[i], b = map(int, input().split())
    score[i] = (i + 1)*N[i] + (b // 100)

ans = G

for d in range(1 << D):
    g = G
    c = 0
    idx = -1
    for i in range(D):
        if (d >> i) & 1:
            g -= score[i]
            c += N[i]
        else:
            idx = i
    if g > 0 and g - (idx + 1) * (N[idx] - 1) <= 0:
        tmp_c = math.ceil(g / (idx + 1))
        if tmp_c <= N[idx]:
            c += tmp_c
            g -= tmp_c * (idx + 1)
    
    if g <= 0:
        ans = min(ans, c)
print(ans)

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


#define base 1000000007LL
#define ll long long
// unsigned long long int t = 10000000000000000003ULL;
#define ulint unsigned long long int
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-15
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())
#define cprint(n) printf("%.6lf + %.6lfi\n", (n).real(), (n).imag())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)


using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;



struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const int M=1e5+7;
const int MM=4*M;
const ll MOD=base;
const int MAX=1e9;


inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
inline ll inverse(ll n, ll p=MOD){return power(n,p-2);}
ll search(ll a[], ll N, ll x){ ll l = 0, r = N - 1; while (l <= r){ ll mid = (l + r) / 2; if (x == a[mid]){ return 1; } else if (x < a[mid]){ r = mid - 1; } else if (x > a[mid]){ l = mid + 1; } } return -1; }

ll a, b;

int main(){
    ios::sync_with_stdio(0);
	cin >> a >> b;
	ll res = a * b;
	for (int i = 1; i <= 3; i++){
		if((res * i) % 2 == 1){
			cout << "Yes"; return 0;
		}
	}    
	cout << "No";
    return 0;
}





Measured memory_bytes: 256
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
*/

#include <cstdio>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>
#include <regex>
#include <functional>
#include <complex>
#include <list>
#include <cassert>
#include <iomanip>
#include <set>
#include <stack>
#include <bitset>
/*多倍長整数/cpp_intで宣言
#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
*/

//pragma gcc target ("avx2")
//#pragma gcc optimization ("o3")
//#pragma gcc optimization ("unroll-loops")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printim(a) printf(a ? "possible\n" : "imposible\n")
#define printdb(a) printf("%.50lf\n", a) //少数出力
#define printLdb(a) printf("%.50Lf\n", a) //少数出力
#define printdbd(a) printf("%.16lf\n", a) //少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str()) //string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2LL) //等差数列の和、初項,末項,項数
#define pb push_back
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0L)*2.0L*PI)
#define rad_to_deg(rad) (((rad)/2.0L/PI)*360.0L)
#define Please return
#define AC 0
#define manhattan_dist(a, b, c, d) (abs(a - c) + abs(b - d)) /*(a, b) から (c, d) のマンハッタン距離 */
#define inf numeric_limits<double>::infinity();
#define linf numeric_limits<long double>::infinity()


using ll = long long;

constexpr int INF = 1073741823;
constexpr int MINF = -1073741823;
constexpr ll LINF = ll(4661686018427387903);
constexpr ll MOD = 1000000007;
constexpr long double eps = 1e-9;
const long double PI = acosl(-1.0L);

using namespace std;

void scans(string& str) {
	char c;
	str = "";
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);
	while (c != '\n' && c != -1 && c != ' ') {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

ll LSB(ll n) { return (n & (-n)); }

/*-----------------------------------------ここからコード-----------------------------------------*/



int main() {

	int n;
	scanf("%d", &n);
	vector<int> dp(n);
	fill(all(dp), INF);
	int a;
	rep(i, n) {
		scanf("%d", &a);
		auto ite = lower_bound(all(dp), a);
		if (ite != dp.end())*ite = a;
	}
	printf("%d\n", distance(dp.begin(), lower_bound(all(dp), INF)));

	Please AC;
}



Measured memory_bytes: 3228
import sys
from collections import deque
input = sys.stdin.readline

N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = input().strip()
D = deque(T)
D.appendleft('none')
T = list(D)

score = 0
count = 0
before = 'a'

for i in range(1, K+1):
    for j in range(i, N+1, K):
        now = T[j]
        if now == before:
            count += 1
        else:
            if now == 'r':
                score += P
            elif now == 's':
                score += R
            elif now == 'p':
                score += S
            if count >= 2:
                if before == 'r':
                    score += P*((count-1)//2)
                elif before == 's':
                    score += R*((count-1)//2)
                elif before == 'p':
                    score += S*((count-1)//2)
            count = 1
        before = now
    if count >= 2:
        if now == 'r':
            score += P*((count-1)//2)
        elif now == 's':
            score += R*((count-1)//2)
        elif now == 'p':
            score += S*((count-1)//2)
    before = 'a'
        
print(score)


Measured memory_bytes: 4980
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int a[1001];
    int n,m,p;
    while(cin>>n>>m>>p&&!(n==0&&m==0&&p==0)){
        int sum=0;
        m--;
        for(int i = 0; i < n; i++){
            cin>>a[i];
            sum+=a[i];
        }
        sum=sum*(100-p);
        if(a[m]==0)
            cout<<0<<endl;
        else{
            cout<<sum/a[m]<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 0