akhauriyash/Code-Regression huggingface dataset:
n,k=map(int,input().split())
p=list(map(lambda x : int(x) - 1, input().split()))
c=list(map(int,input().split()))
s=[0]*(n+1)
ans=-float("inf")
for i in range(n):
    x = i
    tmp = [-10 ** 9] * (n + 1)
    for j in range(1, n + 1):
        s[j] = s[j - 1] + c[p[x]]
        tmp[j] = max(tmp[j-1], s[j])
        x = p[x]
        if x == i:
            break
    if j >= k:
        ans = max(ans, tmp[k])
    elif s[j] < 0:
        ans = max(ans, tmp[j])
    else:
        m = k // j
        a = s[j] * (m - 1) + tmp[j]
        b = s[j] * m + tmp[k % j]
        ans = max(ans, a, b)
print(ans)
 

Measured memory_bytes: 75180
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7 ;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define input_from_file  freopen("input.txt", "r", stdin);
using namespace std::chrono; 

int main()
{
  // input_from_file 
  ll q;q=1;while(q--){
    ll a,b,c,k,x,val;cin>>a>>b>>c>>k;
    ll ans=0;
    while(a>=b){
      b=b*2;
      ans++;
    }
    while(b>=c){
      c=c*2;
      ans++;
    }
    // cout<<ans;
    if(ans<=k)  cout<<"Yes";
    else cout<<"No";
  }
  return 0;
}

Measured memory_bytes: 3608
r,c = map(int, tuple(input().split(' ')))
rc = [[int(s) for s in input().split(' ')] for _ in range(r)]
for row in rc: row.append(sum(row))
to = []
for col in range(c+1):
	su = 0
	for a in range(r): su += rc[a][col]
	to.append(su)
rc.append(to)
for row in rc: 
	ss = map(str, row)
	print(' '.join(ss))


Measured memory_bytes: 7784
import java.util.Scanner;

class Main{

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

      int n=sc.nextInt();
      
      for(int i=1;i<=n;i++){
       if(i%3==0) System.out.print(" "+i);
       else if(i%10==3) System.out.print(" "+i);
       else if(i/10==3) System.out.print(" "+i);
       else if(i/10%10==3) System.out.print(" "+i);
       else if(i/100==3) System.out.print(" "+i);
       else if(i/100%10==3) System.out.print(" "+i);
       else if(i/1000==3) System.out.print(" "+i);
       }
    	  
      System.out.print("\n");
      
}

}


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

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

typedef long long ll;
typedef long double ld;

using namespace std;

int k;
ll ans;

int main()
{
	cin >> k;
	for (int i = 1; i <= k; i++)
	{
		for (int j = 1; j <= k; j++)
		{
			for (int l = 1; l <= k; l++)
				ans += gcd(i, gcd(j, l));
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3636
#3問目 CODE FESTIVAL 2016 qual C B問題 -K個のケーキ
KT = map(int, input().split())
A = [int(s) for s in input().split()]
Max_i = 0
Max = 0
withoutMaxSum = 0
#二回連続で食べる可能性のあるケーキは一番個数の多いケーキのみ
#一番個数の多いケーキの個数 - その他のケーキの個数の総和 - 1が前日と同じケーキを食べる日数
#0以下になったら確実に被らずに食べられる
#1以上になったら確実に被る -> max(0, Max - withoutMaxSum)
for i in range(len(A)):
    if(Max < A[i]):
        Max = A[i]
        Max_i = i
for i in range(len(A)):
    if(i != Max_i):
        withoutMaxSum += A[i]
print(max(0, Max-withoutMaxSum-1))

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

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

  for (int i = 0; i < k; i ++) {
    if (s.at(i) != '1') {
      cout << s.at(i) << endl;
      return 0;
    }
  }

  cout << 1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;

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

    int n;
    cin>>n;
    int cnt = 0;
    rep(i, n) {
        int a;
        cin>>a;
        if (a % 2 == 1) cnt++;
    }
    if (cnt % 2 == 1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    d = [int(input()) for _ in range(n)]
    s_d = sorted(d)
    max = s_d[-1]
    for di in d:
        if di == s_d[-1]:
            print(s_d[-2])
        else:
            print(max)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 56304
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

int main(){
    vector<int> A(3,0);
    cin>>A[0]>>A[1]>>A[2];
    sort(ALL(A));
    if(A[0]==A[1] and A[1]==A[2]){
        cout<<"Yes";
        return 0;
    }
    cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const LL mod = 1e9 + 7;
const int N = 200005;

vector<int> G[N];
int sz[N];
LL ans[N];
LL now = 1;
LL pow_mod(LL x, LL n) {
    LL res = 1;
    while (n) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}
void dfs1(int u, int fa) {
    sz[u] = 1;
    for (auto v : G[u]) {
        if (v == fa) continue;
        dfs1(v, u);
        sz[u] += sz[v];
    }
}
int n;
void dfs2(int u, int fa) {
    ans[u] = pow_mod(now, mod - 2);
    for (auto v : G[u]) {
        if (v == fa) continue;
        now = now * pow_mod(sz[v], mod - 2) % mod * (n - sz[v]) % mod;
        dfs2(v, u);
        now = now * pow_mod(n - sz[v], mod - 2) % mod * sz[v] % mod;
    }
}
int main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs1(1, 0);
    for (int i = 1; i <= n; i++) {
        now = now * sz[i] % mod;
    }
    dfs2(1, 0);
    LL wc = 1;
    for (int i = 1; i <= n; i++) wc = wc * i % mod;
    for (int i = 1; i <= n; i++) {
        printf("%lld\n", ans[i] * wc % mod);
    }
    return 0;
}


Measured memory_bytes: 16244
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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

int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

static const double EPS = 1e-8;

class Data{
public:
	string mName;
	int mC,mV,mD,mL;
	Data(string _n,int _c,int _v,int _d,int _l){
		mName = _n;
		mC = _c;
		mV = _v;
		mD = _d;
		mL = _l;
	}
};

int dp[301][3];

int main(){
	int N,M;

	string line;
	stringstream ss;
	while(getline(cin,line)){
		ss << line;
		ss >> N >> M;
		ss.clear();

		vector<Data> idols;
		for(int i=0;i<N;i++){
			
			getline(cin,line);
			string name = line;

			getline(cin,line);
			ss << line;

			int C,V,D,L;
			ss >> C >> V >> D >> L;
			ss.clear();

			idols.push_back(Data(name,C,V,D,L));
		}


		memset(dp,0,sizeof(dp));

		for(int i=0;i<=M;i++){
			for(int j=0;j<idols.size();j++){
				for(int k=0;k<=300;k++){
					if(i-idols[j].mC*k < 0) break;
					dp[i][0] = max(dp[i-idols[j].mC*k][0] + idols[j].mV*k,dp[i][0]);
					dp[i][1] = max(dp[i-idols[j].mC*k][1] + idols[j].mD*k,dp[i][1]);
					dp[i][2] = max(dp[i-idols[j].mC*k][2] + idols[j].mL*k,dp[i][2]);
				}
			}
		}

		int maxv = 0;
		for(int i=0;i<=M;i++){
			for(int j=0;j<3;j++){
				maxv = max(dp[i][j],maxv);
			}
		}
		printf("%d\n",maxv);

	}
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int h, w, n;
  cin >> h >> w >> n;
  vvi y(w, vi(1, h));
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    y[b].push_back(a);
  }
  for (int i = 0; i < w; ++i) {
    sort(y[i].begin(), y[i].end());
    y[i].resize(unique(y[i].begin(), y[i].end()) - y[i].begin());
  }
  int res = h, pos = 0, cur = 0;
  for (int i = 0; i < w && pos < h; ++i) {
    int it = lower_bound(y[i].begin(), y[i].end(), pos) - y[i].begin();
    res = min(res, cur + (y[i][it] - pos));
    ++pos;
    ++cur;
    if (i + 1 < w) while (pos < h && binary_search(y[i+1].begin(), y[i+1].end(), pos)) {
      ++pos;
      ++cur;
    }
  }
  cout << res << endl;
  return 0;
}

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

int main(){
    string s; cin >> s;
    int n = 0; n = s.length();

    vector<ll> ans(n, 0);

    ll rl_left = 0, rl_right = 0;
    for(int i=0; i<n; i++){
        if(s[i]=='R' && s[i+1]=='L'){
            ans[i]=1; ans[i+1]=1;
            for(int j=i-1; j>=0; j--){
                if(s[j]=='L'){
                    break;
                }else if(s[j]=='R'){
                    if((j - i)%2==0){
                        ans[i]++;
                    }else{
                        ans[i+1]++;
                    }
                }
            }
            for(int k=i+2; k<n; k++){
                if(s[k]=='R'){
                    break;
                }else if(s[k]=='L'){
                    if((k-(i+1))%2==0){
                        ans[i+1]++;
                    }else{
                        ans[i]++;
                    }
                }   
            }
        }
    }

    for(int i=0; i<n; i++){
        printf("%d ", ans[i]);
    }
    printf("\n");
    return 0;
}

Measured memory_bytes: 4316
// #include "bits/stdc++.h"
// using namespace std;
// const int nmax = 1e6 + 10;
// const int INF = 0x3f3f3f3f;
// typedef long long ll;
// typedef double db;
// int a,b,c,d;
// int main() {
// 	scanf("%d %d %d %d",&a,&b,&c,&d);
// 	if((abs(a-b) <= d && abs(b-c) <=d)  || abs(a-c) <= d) puts("Yes");
// 	else puts("No");
// 	return 0;
// }

#include "bits/stdc++.h"
using namespace std;
const int nmax = 1e6 + 10;
const int INF = 0x3f3f3f3f;
typedef long long ll;
typedef double db;
int x;
bool table[1005];
int pow(int x, int times){
	int ans = x;
	times --;
	while(times){
		ans *= x;
		times --;
	}
	return ans;
}
int main() {
	int m = 1;
	int tag = 0;
	table[1] = 1;
	for(int i = 2;i<=1000;++i){
		int times = 2;
		while((int)pow(i,times) <= 1000){
			table[pow(i,times)] = 1;
			times ++;
		}
	}
	scanf("%d",&x);
	for(int i = x;i>=1;--i){
		if(table[i]) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
import sys

x,y = map(int,input().split())
MOD = 10**9+7
N = 10**6
if (x+y)%3 != 0:
    print(0)
    sys.exit()
else:
    m = (2*x-y)//3
    n = (2*y-x)//3
    if n < 0 or m < 0:
        print(0)
        sys.exit()
    else:
        A = [1,1]
        B = [1,1]
        Inv = [0,1]
        for i in range(2,N+1):
            A.append((A[-1]*i)%MOD)
            Inv.append((-Inv[MOD%i]*(MOD//i))%MOD)
            B.append((B[-1]*Inv[-1])%MOD)
print(A[m+n]*B[m]*B[n]%MOD)

Measured memory_bytes: 123768
<?php
$input = explode(" ", trim(fgets(STDIN)));
$n = $input[0];
$a = $input[1];
$b = $input[2];
$cnt = 0;
for($i=0; $i<$n; $i++){
    $ti = trim(fgets(STDIN));
    if($ti<$a || $ti>=$b){
        $cnt++;
    }
}
echo $cnt,PHP_EOL;
?>

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

#define all(v) v.begin(), v.end()
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

int main() {
    string a, b, c; cin >> a >> b >> c;
    queue<char> qa, qb, qc;
    for(int i = 0; i < a.size(); i++) qa.push(a[i]);
    for(int i = 0; i < b.size(); i++) qb.push(b[i]);
    for(int i = 0; i < c.size(); i++) qc.push(c[i]);

    char next = 'a', ans = 'D';
    int an = a.size(), bn = b.size(), cn = c.size();
    while(1){
        if(next == 'a'){
            if(an == 0){
                ans = 'A';
                break;
            }
            next = qa.front();
            qa.pop();
            an--;
        }
        if(next == 'b'){
            if(bn == 0){
                ans = 'B';
                break;
            }
            next = qb.front();
            qb.pop();
            bn--;
        }
        if(next == 'c'){
            if(cn == 0){
                ans = 'C';
                break;
            }
            next = qc.front();
            qc.pop();
            cn--;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

dist :: [Double] -> [Int]
dist xs = [h1, h2, h3, h4, h5, h6]
  where h1 = length $ filter (< 165.0) xs
        h2 = length $ filter (\x -> x < 170.0 && x >= 165.0) xs
        h3 = length $ filter (\x -> x < 175.0 && x >= 170.0) xs
        h4 = length $ filter (\x -> x < 180.0 && x >= 175.0) xs
        h5 = length $ filter (\x -> x < 185.0 && x >= 180.0) xs
        h6 = length $ filter (> 185.0) xs

duplicate :: [Int] -> String -> Int -> [String]
duplicate [] _ _ = []
duplicate (x:xs) c n = (show n ++ ":" ++ concat (replicate x c)) : duplicate xs c (n + 1)

solver ::[Double] -> [String]
solver xs =
  let ys = dist xs
  in
      duplicate ys "*" 1


main :: IO()
main = do
  n <- (read :: String -> Int) <$> getLine
  heights <- map (read :: String -> Double) <$> replicateM n getLine
  mapM_ putStrLn $ solver heights

Measured memory_bytes: 4292
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	vector<long int>v(n);
	for(int i=0;i<n;i++)
	{
		cin>>v[i];
	}
	vector<long int>dp(n,INT_MAX);
	dp[0]=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<=i+k;j++)
		{
			if(j<n)
			dp[j]=min(dp[j],dp[i]+abs(v[i]-v[j]));
		}
	}
	cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 4860
import itertools
import sys

input = sys.stdin.readline

n, m, q = map(int, input().split())
ls = [[0] * n for _ in range(n)]
for _ in range(m):
    l, r = map(int, input().split())
    ls[l - 1][r - l] += 1
for i in range(n):
    ls[i] = list(itertools.accumulate(ls[i]))
for _ in range(q):
    l, r = map(int, input().split())
    l -= 1
    r -= 1
    res = 0
    for i in range(r - l + 1):
        res += ls[l + i][r - l - i]
    print(res)

Measured memory_bytes: 60380
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main(){
  int A[3][3];
  for(int i=0; i<3; i++){
    for(int j=0;j<3;j++) cin >> A[i][j];
  }

  int N;
  cin >> N;

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

  int flag[3][3]={};
  for(int k=0;k<N;k++){
    for(int i=0; i<3; i++){
      for(int j=0;j<3;j++){
	if(A[i][j]==b[k]){
	  flag[i][j]=1;
	  break;
	}
      }
    }
  }

  string ans="No";
  for(int i=0;i<3;i++){
    if(flag[i][0]==1 && flag[i][1]==1 && flag[i][2]){
      ans="Yes";
      break;
    }
    if(flag[0][i]==1 && flag[1][i]==1 && flag[2][i]){
      ans="Yes";
      break;
    }
  }
  if(flag[0][0]==1 && flag[1][1]==1 && flag[2][2]) ans="Yes";
  if(flag[0][2]==1 && flag[1][1]==1 && flag[2][0]) ans="Yes";

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


Measured memory_bytes: 256
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = pair<ll,ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long MAX = 100000;
const long MOD = 1000000007;



int main(){
    long double L;cin>>L;
    long double res = pow(L/3,3);
    printf("%.10Lf\n",res);

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define vi vector<int>
#define pb push_back
#define P pair<int,int>
#define PP pair<P,int>
#define fi first
#define se second
#define INF (1<<30)
#define MOD 1000000007
#define all(a) (a).begin(),(a).end()
 
 
signed main(){
    string t;
    cin>>t;
    set<char> se;
    for(int i=0;i<t.length();i++){
        if(se.find(t[i])!=se.end()){
            cout<<"no"<<endl;
            return 0;
        }
        se.insert(t[i]);
    }
    cout<<"yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N;
	std::vector<std::string> W;
	std::cin >> N;
	W.resize(N);
	for (auto& w : W)
		std::cin >> w;
	
	std::unordered_set<std::string> chk;
	chk.insert(W[0]);
	for (int i = 1; i < W.size(); ++i) {
		const auto& prev = W[i-1];
		const auto& cur = W[i];
		if (prev[prev.size()-1] != cur[0]) {
			std::cout << "No\n";
			return 0;
		}
		if (!chk.insert(cur).second) {
			std::cout << "No\n";
			return 0;
		}
	}
	std::cout << "Yes\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int maxtime(int n) {
  n = (n+9)/10*10;
  return n;
}
int remtime(int n){
  n = maxtime(n) - n;
  return n;
}
int main() {
  int A,B,C,D,E;
  cin >> A >> B >> C >> D >> E;
  int sum = maxtime(A) + maxtime(B) + maxtime(C) + maxtime(D) + maxtime(E);
  sum -= max({remtime(A), remtime(B), remtime(C), remtime(D), remtime(E)});
  cout << sum << endl;
}

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

typedef long long ll;

int main() {
  string S;
  cin >> S;
  ll first = 0, last = 0;
  int c = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'B') {
      first += i;
      c++;
    }
  }
  for (int i = 0; i < c; i++) {
    last += S.size() -1 - i;
  }
  cout << last - first << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define PI acos(-1)
#define sz 100010
#define RUN_FAST ios::sync_with_stdio(false);
using namespace std;

int main()
{
    RUN_FAST; cin.tie(nullptr);
    int i, j, n, val, cnt;
    bool flag;
    int arr[3][3];
    for (i=0; i<3; i++)
        for (j=0; j<3; j++) cin >> arr[i][j];

    cin >> n;
    while (n--) {
        cin >> val;
        flag=false;
        for (i=0; i<3; i++) {
            for (j=0; j<3; j++) {
                if (arr[i][j]==val) {
                    arr[i][j]=0;
                    flag=true;
                    break;
                }
            }
            if (flag) break;
        }
    }
    if (!arr[0][0] && !arr[0][1] && !arr[0][2]) cout << "Yes";
    else if (!arr[1][0] && !arr[1][1] && !arr[1][2]) cout << "Yes";
    else if (!arr[2][0] && !arr[2][1] && !arr[2][2]) cout << "Yes";

    else if (!arr[0][0] && !arr[1][0] && !arr[2][0]) cout << "Yes";
    else if (!arr[0][1] && !arr[1][1] && !arr[2][1]) cout << "Yes";
    else if (!arr[0][2] && !arr[1][2] && !arr[2][2]) cout << "Yes";

    else if (!arr[0][0] && !arr[1][1] && !arr[2][2]) cout << "Yes";
    else if (!arr[0][2] && !arr[1][1] && !arr[2][0]) cout << "Yes";

    else cout << "No";
    cout << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int r,g,b;
	cin >> r >> g >>b;
	int ans = 100*r + 10*g + b;
	if (ans % 4 == 0){
		cout << "YES" <<endl;
	}
	else{
		cout<< "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long n = in.nextLong(), j = in.nextLong();
		//System.out.println(((2*n-k+1)*k/2 - (k-1)*k/2) % 1000000007);
		long s = 0;
		for (long k = j; k <= n+1; k++) {
			s = (s + (2*n-k+1)*k/2 - (k-1)*k/2 + 1) % 1000000007;
			//System.out.println(s);
		}
		System.out.println(s);
	}
}


Measured memory_bytes: 27232
from functools import reduce
from operator import xor
n = int(input())
A = list(map(int, input().split()))


total = []
it = iter(A)
for x, y in zip(it, it):
    total.append(x ^ y)

total = reduce(xor, total)

ans = []
for a in A:
    ans.append(total ^ a)
print(*ans)


Measured memory_bytes: 31976
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		int m = scanner.nextInt();
		int a =0;
		for(int i=0 ; i<m ; i++) {
			a = scanner.nextInt();
			if(a <= n) {
				n -= a;
			}else {
				n = -1;
				break;
			}
		}

		System.out.println(n);

		scanner.close();




	}

}


Measured memory_bytes: 45976
n, k = map(int, input().split())
a = list(map(int, input().split()))


from collections import Counter
c = Counter(a)
keys = list(c.keys())
keys.sort()
tmp1 = 0
tmpsum = 0
for key in keys:
    tmp1 += c[key] * tmpsum
    tmpsum += c[key]

tmp2 = 0
counter = [0] * 2000
for _a in reversed(a):
    if _a > 1:
        tmp2 += sum(counter[:_a-1])
    counter[_a-1] += 1

print((tmp1 * (k-1) * k // 2 + tmp2 * k) % (10 ** 9 + 7))


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

using namespace std;

int main()
{
    int l;
    cin >> l;
    int n = 32 - __builtin_clz(l);
    int m = (n - 1) * 2 + __builtin_popcount(l) - 1;
    cout << n << " " << m << endl;
    for (int i = 1; i < n; i++)
    {
        if (l % 2 == 1)
        {
            l--;
            cout << i << " " << n << " " << l << endl;
        }
        cout << i << " " << i + 1 << " " << l / 2 << endl;
        cout << i << " " << i + 1 << " " << 0 << endl;
        l /= 2;
    }
    return 0;
}


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

int main() {
    int n; cin >> n;
    vector<pair<pair<string, int>, int>> d(n);
    for(int i = 0; i < n; ++i) {
        string s;
        int p;
        cin >> s >> p;
        d[i] = make_pair(make_pair(s, -p), i);
    }
    sort(d.begin(), d.end());
    for(int i = 0; i < n; ++i) cout << d[i].second + 1 << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<queue>
#define maxn 510
using namespace std;
int n,x,y,cnt=0,ans=0;
int dis[maxn*maxn],head[maxn*maxn];
int dx[5]={-1,0,0,1},dy[5]={0,-1,1,0};
bool vis[maxn*maxn];
queue<int>q;
struct Edge{
	int v,w,nxt;
}e[10*maxn*maxn];
void addEdge(int u,int v,int w){
	//cout<<"add "<<u<<" "<<v<<" "<<w<<endl;
	e[++cnt].v=v;
	e[cnt].w=w;
	e[cnt].nxt=head[u];
	head[u]=cnt;
}
int id(int x,int y){
	return (x-1)*n+y;
}
void setup(){
	for(register int i=1;i<=n*n;i++)dis[i]=1e9;
	vis[0]=1;
	q.push(0);
}
void calc(){
	while(!q.empty()){
		int u=q.front();q.pop();vis[u]=0;
		for(register int i=head[u];i;i=e[i].nxt){
			int v=e[i].v;
			if(dis[v]>dis[u]+e[i].w){
				dis[v]=dis[u]+e[i].w;
				if(!vis[v]){
					vis[v]=1;
					q.push(v);
				}
			}
		}
	}
}
int main(){
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<=n;j++){
			if(i==1||i==n||j==1||j==n)addEdge(0,id(i,j),0);
			for(register int k=0;k<4;k++){
				x=i+dx[k];y=j+dy[k];
				//cout<<i<<" "<<j<<" "<<x<<" "<<y<<endl;
				if(x<0||x>n||y<0||y>n)continue;
				else addEdge(id(i,j),id(x,y),1);
			}
		}
	}
	setup();
	calc();
	for(register int i=1;i<=n*n;i++){
		scanf("%d",&x);
		//cout<<"   dis["<<x<<"]="<<dis[x]<<endl;
		ans+=dis[x];
		for(register int j=head[x];j;j=e[j].nxt){
			e[j].w=0;
			int v=e[j].v;
			//cout<<"v="<<v<<endl;
			if(dis[v]>dis[x]){
				dis[v]=dis[x];
				vis[v]=1;
				q.push(v);
				//cout<<"q.push "<<v<<endl;
			}
		}
		calc();
		//for(register int j=1;j<=n*n;j++)cout<<"re["<<j<<"]="<<dis[j]<<endl;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 17688
def resolve():
    n = int(input())
    a = [0] + list(map(int, input().split())) + [0]
    total = sum([abs(a[i] - a[i + 1]) for i in range(n + 1)])
    for i in range(1, n + 1):
        print(total + abs(a[i + 1] - a[i - 1]) - abs(a[i] - a[i - 1]) - abs(a[i] - a[i + 1]))


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 65772
#include<iostream>
#include <algorithm>
#include <string>
#include<math.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int main() {
    int a, b;
  cin>>a>>b;
    cout << (a % 500<=b?"Yes":"No") << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
from numba import njit
 
MOD = 10**9 + 7
 
N = int(readline())
S = np.array(list(read().rstrip()), np.int8)
 
R = np.sum(S == ord('R'))
B = np.sum(S == ord('B'))
G = np.sum(S == ord('G'))
 
@njit
def f(S):
    N = len(S)
    ret = 0
    for i in range(N):
        for j in range(i + 1, N):
            k = j + j - i
            if k >= N:
                break
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                ret += 1
    return ret
 
answer = R * B * G - f(S)
print(answer)

Measured memory_bytes: 109668
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

int main(){
    string s;cin >> s;
    int ans = 0;
    rep(i,s.size()){
        ans += s[i] - '0';
    }
    cout << ((ans%9==0) ? "Yes" : "No") << endl;
    
}

Measured memory_bytes: 3744
#include <cstring>
#include <cmath>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int mmap[3][3];

int main()
{
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
			scanf("%d",&mmap[i][j]);
	}
	int sum1,sum2,sum3,sum4;
	sum1=mmap[0][0]+mmap[1][1]+mmap[2][2];
	sum2=mmap[2][0]+mmap[1][1]+mmap[0][2];
	sum3=mmap[0][1]+mmap[1][2]+mmap[2][0];
	sum4=mmap[1][0]+mmap[2][1]+mmap[0][2];
	if(sum1==sum2&&sum2==sum3&&sum3==sum4)
		printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 2*1e9
#define N 410000
using namespace std;
main(){
    ll q,h,s,d,n;
    cin>>q>>h>>s>>d>>n;
    ll m=min({8*q,4*h,2*s,d});
    ll mm=min({4*q,2*h,s});
    cout<<m*(n/2)+mm*(n%2);
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> Pll;
typedef pair<P,P> PP;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define repr(i,a,n) for(ll i = n-1;i >= a;i--)
#define LINF (ll)1e17
#define INF (int)1e9
#define MOD (ll)1e9+7
#define sMOD 1e5
#define fs first
#define sc second

ll gcd(ll a,ll b){
	if(!b) return a;
	return gcd(b,a%b);
	
}

ll lcm(ll a,ll b){
	return a * b / gcd(a,b);
}





signed main(){
	ll n,ans = 0,memo = 0;
	cin >> n;

	ll a[n+1] = {};
	rep(i,0,n+1) cin >> a[i];

	ll b[n] = {};

	rep(i,0,n) cin >> b[i];

	rep(i,0,n){
		ans += min(a[i],b[i]);
		b[i] = max((ll)0,b[i]-a[i]);

		ans += min(a[i+1],b[i]);
		a[i+1] = max((ll)0,a[i+1]-b[i]);
	}

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

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>

#include <bits/stdc++.h>


using namespace std;

#define INPUT_INT(valName) int valName; cin >> valName
#define INPUT_LLINT(valName) long long int valName; cin >> valName;
#define INPUT_STR(valName) string valName; cin >> valName;
#define INPUT_LINE(valName) string valName; getline(cin,s);
#define INPUT_VECTOR_INT(valName, N) vector<int> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }
#define INPUT_VECTOR_DOUBLE(valName, N) vector<double> valName(N); for(int i=0; i < N; ++i) { cin >> valName[i]; }

#define OUTPUT(A) cout << (A) << endl;
#define OUTPUT2(A, B) cout << (A) << " " << (B) << endl;
#define OUTPUT3(A, B, C) cout << (A) << " " << (B) << " " << (C) << endl;

#define REP(valName, N) for(int valName = 0; valName < N; ++valName)

vector<string> split(const string& str, char delimiter) {
	vector<string> ret;
	string tmp = "";
	for (auto c : str) {
		if (c != delimiter) {
			tmp.push_back(c);
		} else {
			ret.push_back(tmp);
			tmp = "";
		}
	}
	ret.push_back(tmp);
	return ret;
}

template <typename T> void sortAsc(vector<T>& v) { sort(v.begin(), v.end(), less<T>()); }
template <typename T> void sortDesc(vector<T>& v) { sort(v.begin(), v.end(), greater<T>()); }

template <typename T> void insert(vector<T>& dest, const vector<T>& src) { copy(src.begin(), src.end(), back_inserter(dest)); }

template <long long int MOD> long long int mod_inv(long long int a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}

template <long long int MOD> long long int mod_add(long long int a, long long int b) {
	return (a + b) % MOD;
}

template <long long int MOD> long long int mod_sum(long long int a, long long int b) {
	return (a - b) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b) {
	return (a % MOD) * (b % MOD) % MOD;
}

template <long long int MOD> long long int mod_mul(long long int a, long long int b, long long int c) {
	return mod_mul<MOD>(a, mod_mul<MOD>(b, c));
}

template <long long int MOD> long long int mod_div(long long int a, long long int b) {
	return (a % MOD) * mod_inv<MOD>(b) % MOD;
}


//------------------------------------------------------------------------------------------------------------------------------


int main() {

	INPUT_INT(A);
	INPUT_INT(B);

	int n = ((B - 1) + (A-2) ) / (A - 1);

	OUTPUT(n);

	return 0;
}

Measured memory_bytes: 256
s = [0]*2
t = [0]*2
s[0],s[1],t[0],t[1] = map(int,input().split())
ans = 'R'*(t[0]-s[0])+'U'*(t[1]-s[1])+'L'*(t[0]-s[0])+'D'*(t[1]-s[1])+\
'D'+'R'*(t[0]-s[0]+1)+'U'*(t[1]-s[1]+1)+'L'+'U'+'L'*(t[0]-s[0]+1)+'D'*(t[1]-s[1]+1)+'R'
print(ans)


Measured memory_bytes: 3064
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
use std::collections::HashMap;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, m) = (line[0], line[1]);
    let m: u64 = m as u64;
    let a: Vec<u64> = read_as_vec();

    /*
    let mut b: Vec<u64> = vec![0];
    let mut sum = 0;
    for elem in a{
        sum += elem;
        b.push(sum);
    }

    let mut mod_hash = HashMap::new();

    let mut ans = 0;
    for elem in b{
        let x = mod_hash.entry(elem%m).or_insert(0);
        ans += *x;
        *x += 1;
    }
    println!("{}", ans);
     */
    let mut sum = vec![0; n + 1];
    for i in 0..n {
        sum[i + 1] = (sum[i] + a[i]) % m;
    }

    let mut map = std::collections::HashMap::new();
    let mut ans = 0i64;
    for i in 0..n + 1 {
        let x = map.entry(sum[i]).or_insert(0);
        ans += *x;
        *x += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 14588
#include<iostream>
#include<algorithm>
#include<climits>
#include<cstring>
#include<cstdio>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
int n;
double p[3010];
double dp[3010][3010];
int main(){
  scan(n);
  rep(i,n){
    scan(p[i]);
  }
  memset(dp,0,sizeof(dp));
  dp[0][0]=1;
  rep1(i,n){
    rep(j,n+1){
      if(j==0){
	dp[i][j]=dp[i-1][j]*(1-p[i-1]);
      }
      else{
	dp[i][j]=dp[i-1][j]*(1-p[i-1])+dp[i-1][j-1]*p[i-1];	
      }
    }
  }
  double ans=0;
  for(int i=(n+1)/2;i<=n;i++){
    ans+=dp[n][i];
  }
  printf("%.10f\n",ans);

  
  return 0;
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define orep(i, n) for(int i = 1; i < (int)(n); ++i)
#define rrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

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

    if ("SAT" == s) cout << 1 << endl;
    if ("FRI" == s) cout << 2 << endl;
    if ("THU" == s) cout << 3 << endl;
    if ("WED" == s) cout << 4 << endl;
    if ("TUE" == s) cout << 5 << endl;
    if ("MON" == s) cout << 6 << endl;
    if ("SUN" == s) cout << 7 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N, ma, mb;
    cin >> N >> ma >> mb;

    vc<array<ll, 3>> A(N);
    rep(i, N) cin >> A[i][0] >> A[i][1] >> A[i][2];

    vvc<ll> C(401, vl(401, INF));
    C[0][0] = 0;

    ll sa = 0, sb = 0;
    rep(k, N){
        auto [a, b, c] = A[k];
        repr(i, sa + 1){
            repr(j, sb + 1){
                if(i+a<=400 and j+b<=400){
                    chmin(C[i + a][j + b], C[i][j] + c);
                }
            }
        }
        sa += a, sb += b;
    }

    ll ans = INF;
    repe(i, 1, 401){
        if (i * ma > 400 or i * mb > 400) break;
        chmin(ans, C[i * ma][i * mb]);
    }

    cout << (ans==INF?-1:ans) << endl;
}   

Measured memory_bytes: 4496
#include <stdio.h>

int H, W;
char a[100][100];
int tmp = 0, ans = 2500;

int main(void){
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; ++i){
		scanf("%s", &a[i]);
	}

	for (int i = 1; i <= H - 2; ++i) {
		for (int j = 1; j <= H - 1; ++j) {
			for (int x = 1; x <= H; ++x) {
				for (int y = 1; y <= W; ++y) {
					if (x <= i) {
						if (a[x - 1][y - 1] != 'W') {
							tmp++;
						}
					}
					else if (x <= j) {
						if (a[x - 1][y - 1] != 'B') {
							tmp++;
						}
					}
					else {
						if (a[x - 1][y - 1] != 'R') {
							tmp++;
						}
					}
				}
			}
			if (ans > tmp) { ans = tmp; }
			tmp = 0;
		}
	}

	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define repi(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define SIZE_OF_ARRAY(array)    (sizeof(array)/sizeof(array[0]))
typedef long long ll;
using namespace std;
int main(){
  ll h;
  cin >> h;
  ll ans = 0;
  while(h>1){
    h/=2;
    ans++;
  }
  ll sum = pow(2,ans);
  sum = sum+(sum-1);
  cout << sum << endl;
  return 0;
  
}

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

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

    cout << sum << endl;
}

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

using namespace std;
using ll = long long;
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
 
template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

// GF(2)の行列
template<int width=64>
struct matrix {
    int h, w;
    vector<bitset<width>> dat;
    matrix() {}
    matrix(int h) : h(h), w(width), dat(h) {}

    matrix& operator+=(const matrix& r) {
        assert(h==r.h && w==r.w);
        REP(i, h) dat[i] ^= r.dat[i];
        return *this;
    }
    matrix& operator-=(const matrix& r) {
        assert(h==r.h && w==r.w);
        REP(i, h) dat[i] ^= r.dat[i];
        return *this;
    }
    matrix& operator*=(const matrix& r) {
        assert(w==r.h);
        matrix ret(h, w);
        REP(i, h) REP(j, r.w) REP(k, w) {
            ret.dat[i][j] ^= dat[i][k] & r.dat[k][j];
        }
        return (*this) = ret;
    }
    matrix operator+(const matrix& r) { return matrix(*this) += r; }
    matrix operator-(const matrix& r) { return matrix(*this) -= r; }
    matrix operator*(const matrix& r) { return matrix(*this) *= r; }
    bool operator==(const matrix& a) { return dat==a.dat; }
    bool operator!=(const matrix& a) { return dat!=a.dat; }

    friend matrix pow(matrix p, ll n) {
        matrix ret(p.h, p.w);
        REP(i, p.h) ret.dat[i][i] = 1;
        while(n > 0) {
            if(n&1) {ret *= p; n--;}
            else {p *= p; n >>= 1;}
        }
        return ret;
    }
    // 階段行列を求める O(HW^2)
    friend int gauss_jordan(matrix &a) {
        int rank = 0;
        // bitset[i] = (下からi桁目が0/1)
        for(ll i=a.w-1; i>=0; --i) {
            int pivot = -1;
            FOR(j, rank, a.h) if(a.dat[j][i] != 0) { pivot = j; break; }
            if(pivot == -1) continue;
            swap(a.dat[rank], a.dat[pivot]);
            REP(j, a.h) if(j != rank && a.dat[j][i] != 0) {
                a.dat[j] ^= a.dat[rank];
            }
            rank++;
        }
        return rank;
    }

    friend ostream &operator<<(ostream& os, matrix a) {
        REP(i, a.h) {
            REP(j, a.w) os << a.dat[i][j] << " ";
            os << endl;
        }
        return os;
    }
};

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

    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    ll all = 0;
    REP(i, n) all ^= a[i];

    matrix<64> mat(n);
    REP(i, n) mat.dat[i] = bitset<64>(a[i]&~all);
    gauss_jordan(mat);

    ll v = 0;
    REP(i, n) {
        ll tmp = mat.dat[i].to_ulong();
        chmax(v, v^tmp);
    }

    cout << 2*v + all << endl;

    return 0;
}

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

int main() {
  int n, t;
  cin >> n >> t;
  int ans=10009;
  for (int i = 0; i < n; i++) {
    int cost, time;
    cin >> cost >> time;
    if (time<=t) ans = min(ans, cost);
  }
  if (ans == 10009) cout << "TLE";
  else cout << ans;
  cout << endl;
}

Measured memory_bytes: 256
m,r,s=10**9+7,1,t=i=0;f=->a,b{b>0?a**b[0]*f[a*a%m,b/2]%m:1};b=(1..gets.to_i).map{|j|t+=f[j,m-2]};gets.split.map{|a|s+=a.to_i*(b[i]+b[-i+=1]-1);r=r*i%m};p s*r%m

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

int main() {
    int N;
    string S;
    cin >> N >> S;

    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        int pass[3] = {i / 100, (i / 10) % 10, i % 10};
        int idx = 0;
        for (int j = 0; j < N; j++) {
            if (S[j] == ('0' + pass[idx])) idx++;
            if (idx == 3) {
                ans++;
                break;
            }
        }
    }

    cout << ans << endl;
}

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

#define say(obj) (cout << obj << endl)
#define endline (cout << endl)
#define all(container) container.begin(), container.end()
#define sortall(container) (sort(container.begin(), container.end()))
#define yn(cond) ((cond) ? (cout << "yes" << endl) : (cout << "no" << endl))
#define Yn(cond) ((cond) ? (cout << "Yes" << endl) : (cout << "No" << endl))
#define YN(cond) ((cond) ? (cout << "YES" << endl) : (cout << "NO" << endl))

typedef long long       ll;

typedef vector<int>     vi;
typedef vector<ll>      vll;
typedef vector<double>  vd;
typedef vector<bool>    vb;
typedef vector<char>    vc;
typedef vector<string>  vs;
typedef pair<int, int>  pii;
typedef pair<ll, ll>    pll;
typedef vector<vi>		vvi;
typedef vector<vll>		vvll;
typedef vector<vd>		vvd;
typedef vector<vb>		vvb;
typedef vector<vc>		vvc;
typedef vector<vs>		vvs;
typedef vector<pii>     vpii;
typedef vector<pll>     vpll;

typedef struct edge_ {
	ll to, cost;
	edge_(ll to, ll cost) : to(to), cost(cost) {}
} edge;

typedef struct point_ {
	ll x, y;
	point_(ll x = 0, ll y = 0) : x(x), y(y) {}
} point;

template <typename T>
using mat2d = vector<vector<T>>;

constexpr double	PI = 3.14159265358979323846;
constexpr int		INF = (int)1e7;
constexpr ll		MOD = (ll)1e9 + 7;
constexpr double	EPS = 1e-7;
constexpr int		dy4[4] = { 0, 1, 0, -1 };
constexpr int		dx4[4] = { 1, 0, -1, 0 };
constexpr int		dy8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };
constexpr int		dx8[8] = { 1, 1, 0, -1, -1, -1, 0, 1 };

template <typename T>
istream& operator >> (istream& is, vector<T>& vec) {
	for (T& x : vec) is >> x;
	return is;
}

template <typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
	for (const T& x : vec) os << x << " ";
	return os;
}

template <typename T>
ostream& operator << (ostream& os, const vector<vector<T>>& mat) {
	for (const vector<T>& m : mat) os << m << endl;
	return os;
}

template <typename S, typename T>
istream& operator >> (istream& is, pair<S, T>& p) {
	is >> p.first >> p.second;
	return is;
}

istream& operator >> (istream& is, point& p) {
	is >> p.x >> p.y;
	return is;
}

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

template <typename T>
ostream& operator << (ostream& os, const set<T>& s) {
	for (const T& x : s) os << x << " ";
	return os;
}

ostream& operator << (ostream& os, const edge e) {
	os << "{to: " << e.to << ", cost: " << e.cost << "}";
	return os;
}

ostream& operator << (ostream& os, const point& p) {
	os << "(" << p.x << " " << p.y << ")";
	return os;
}

/******************************************************************************/
/**********************         Don't make WA !!         **********************/
/******************************************************************************/


int main()
{
	ll N, M;
	cin >> N >> M;
	ll ans = 0;

	if (N * 2 <= M) {
		ans += N;
		M -= 2 * N;
		N -= N;
	}
	else {
		ans = M / 2;
		N -= M / 2;
		M -= M / 2 * 2;
	}

	if (M > 3) {
		ans += M / 4;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val dx = listOf(1, 0, -1, 0)
    val dy = listOf(0, 1, 0, -1)
    val (H, W) = listOfInt()
    val maze = Array<String>(H) { next() }
    var ans = 0
    for (sh in 0 until H) {
        for (sw in 0 until W) {
            if (maze[sh][sw] == '#') continue
            var Q = Queue<Triple<Int, Int, Int>>()
            var visit = Array<IntArray>(H) { IntArray(W) { -1 } }
            Q.enqueue(Triple(sh, sw, 0))
            visit[sh][sw] = 0
            while (!Q.isEmpty()) {
                val (h, w, k) = Q.dequeue()!!
                val nk = k + 1
                for (n in 0 .. 3) {
                    val nh = h + dx[n]
                    val nw = w + dy[n]
                    if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue
                    if (maze[nh][nw] == '#') continue
                    if (visit[nh][nw] != -1) continue
                    Q.enqueue(Triple(nh, nw, nk))
                    visit[nh][nw] = nk
                    ans = Math.max(ans, nk)
                }
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfInt(delta: Int = 0) = listOfString().map { Integer.parseInt(it) + delta }
class Queue<T> {
    val elements = mutableListOf<T>()
    fun isEmpty() = elements.isEmpty()
    fun enqueue(item: T) = elements.add(item)
    fun dequeue() = if (!isEmpty()) elements.removeAt(0) else null
}

Measured memory_bytes: 40660
n,w=map(int, input().split())
g=[0]
v=[0]
for i in range(n):
    G,V=map(int, input().split())
    g.append(G)
    v.append(V)

dp=[[10**10]*(10**5+10) for i in range(n+1)]
dp[0][0]=0

for i in range(1,n+1):
    for j in range(10**5+10):
        if j-v[i]>=0:dp[i][j]=min(dp[i-1][j],dp[i-1][j-v[i]]+g[i])
        else:dp[i][j]=dp[i-1][j]

for i in range(10**5+9,0,-1):
    if dp[n][i]<=w:
        print(i)
        exit()

Measured memory_bytes: 147176
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		
		// 入出力高速化 java.io.* とthrows IOExceptionを忘れずに
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] in = br.readLine().split(" ");
		int A = Integer.parseInt(in[0]);
		int B = Integer.parseInt(in[1]);
		int C = Integer.parseInt(in[2]);
		
		String ans = "NO";
		for(int i=1; i<A+B; i++) {
			if(i*A%B == C)
				ans = "YES";
		}
				
		System.out.println(ans);	
	}
}

Measured memory_bytes: 32784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    rep(i, 0, n) cout << s[i] << t[i];
    cout << endl;
}


Measured memory_bytes: 256