akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x,y) fixed<<setprecision(y)<<x
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define gcd(x,y) __gcd(x,y)
#define mp make_pair
 
 
 
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string a,b;
    int i,j;
    cin>>a>>b;
 
    int n=a.length();
    int m=b.length();
 
    vector<vector<int>> dp(n+1,vector<int>(m+1));
    for(i=0;i<=n;i++) dp[i][0]=0;
    for(i=0;i<=m;i++) dp[0][i]=0;
 
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=m;j++)
    	{
    		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
    		if(a[i-1]==b[j-1]) dp[i][j]=max(dp[i][j],1+dp[i-1][j-1]);
    	}
    }

    string ans="";
 
    i=n;j=m;
    while(i>=1 && j>=1)
    {
    	if(a[i-1]==b[j-1]) {ans+=a[i-1]; i-=1; j-=1;}
    	else if(dp[i-1][j]>dp[i][j-1])  i-=1;
    	else j-=1;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
 
 
	return 0;
}

Measured memory_bytes: 73532
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;


template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}
 
template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}


//vector<pair<int,int>> pairs;  pairs[i] = make_pair(value, value);
//sort(a.begin(),a+index_number);

//cin>>  cout<<'\n'

/*
vector<int> vec(100,-1);全ての値に-1をセット
vector<std::vector<int>> vec{{ 1, 2, 3 },{ 4, 5, 6 }};
vec.size() vec[i].size()
vec.emplace_back(20);追加
*/

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

	int w,h,x,y;
	cin >> w >> h >> x >> y;

	float ans = w*h*0.5;
	int flag = 0;

	if(w%2 == 0 && h%2 == 0)
		if(x == w/2 && y == h/2)
			flag = 1;

	cout << ans << " " << flag <<endl;
    

    return 0;
}

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

struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> using iodef_rng_t = typename enable_if<decltype(declval<C>().begin(), true_type{})::value && !is_same<C, string>::value>::type;
template<class C, class = iodef_rng_t<C>> istream& operator>>(istream& in, C& c) { for (auto& v : c) { in >> v; } return in; }
template<class C, class = iodef_rng_t<C>> ostream& operator<<(ostream& out, const C& c) { int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
template<class T> void trace_(const char* s, const T& v) { cerr << s << "=" << v; }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { for (; *s != ','; ++s) { cerr << *s; } cerr << "=" << v << ","; trace_(++s, vs...); }
#define TRACE(...) (cerr << "\033[2m\033[33m", trace_(#__VA_ARGS__, __VA_ARGS__), cerr << "\033[0m\n")
#else
#define TRACE(...)
#endif

int N;
int ds[] = {7,5,3};
int ans = 0;

void dfs(int64_t n, bool f7, bool f5, bool f3) {
    for (int d : ds) {
        auto x = n * 10 + d;
        if (x <= N) {
            if ((f7 || d == 7) && (f5 || d == 5) && (f3 || d == 3)) {
                TRACE(x);
                ans++;
            }
            dfs(x, f7 || d == 7, f5 || d == 5, f3 || d == 3);
        }
    }
}

int main() {
    cin >> N;
    dfs(0, false, false, false);
    cout << ans << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int c = sc.nextInt();
		int[][] a = new int[r][c];
		int sum = 0;
		
		for(int ir = 0; ir < r; ir++) {
			for(int ic = 0; ic < c; ic++) {
				a[ir][ic] = sc.nextInt();
			}
		}
		
		for(int ir = 0; ir < r; ir++) {
			int rsum =0;
			for(int ic = 0; ic < c; ic++) {
				System.out.print(a[ir][ic] + " ");
				rsum += a[ir][ic];
				sum += a[ir][ic];
			}
			System.out.println(rsum);
		}
		
		for(int ic = 0; ic < c; ic++) {
			int csum = 0;
			for(int ir = 0; ir < r; ir++) {
				csum += a[ir][ic];
			}
			System.out.print(csum + " ");
		}
		System.out.println(sum);
	}
}



Measured memory_bytes: 41076
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline 




n,k = [int(i) for i in readline().split()]
a = [0]+[int(i) for i in readline().split()]

n += 1

INF = 10**18

K = n-k-1

dp = [[INF]*n for _ in range((K+1))]
dp[0][0] = 0



for i in range(1,n):
    ndp = [c[:] for c in dp]
    
    for l in range(min(i,K)):
        for now in range(0,i):
            ndp[l+1][i] = min(ndp[l+1][i], ndp[l][now]+max(0,a[i]-a[now]))
    
    dp = ndp
    #print(dp)    

#print(dp[-1])
print(min(dp[-1]))

        





Measured memory_bytes: 91996
#include <cstdio>
#define MAX 1000

int N, T;
int c[MAX], t[MAX];
int cmin = 1001;
int main(int argc, char const *argv[]) {
  scanf("%d %d\n", &N, &T);
  for (int i = 0; i < N; i++) {
    scanf("%d %d\n", &c[i], &t[i]);
    if(t[i] <= T && c[i] < cmin){
      cmin = c[i];
    }
  }
  if(cmin == 1001){
    printf("TLE\n");
  } else {
    printf("%d\n", cmin);
  }
  return 0;
}


Measured memory_bytes: 128
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def MI(N,num):
    if N<=0:
        return [[] for _ in range(num)]
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [LI() for _ in range(N)]
        return map(list, zip(*read_all))

#################

from bisect import bisect_left
from itertools import product,combinations

from operator import itemgetter
def index_sort(A):
    A_sort = sorted(enumerate(A),key=itemgetter(1))
    index = [a[0] for a in A_sort]
    sorted_A = [a[1] for a in A_sort]
    return index, sorted_A

N,K = LI()
x,y = MI(N,2)

index,_ = index_sort(x)
x2 = [x[i] for i in index]
y2 = [y[i] for i in index]

A = list(product(combinations(range(N),2),repeat=2))
ans = float('inf')
for a in A:
    xmin = min(x[a[0][0]],x[a[0][1]])
    xmax = max(x[a[0][0]],x[a[0][1]])
    ymin = min(y[a[1][0]],y[a[1][1]])
    ymax = max(y[a[1][0]],y[a[1][1]])
    S = (xmax-xmin)*(ymax-ymin)
    if S >= ans:
        continue
    l = bisect_left(x2,xmin)
    r = bisect_left(x2,xmax)
    num = 0
    for i in range(l,r+1):
        if ymin <= y2[i] <= ymax:
            num += 1
    if num >= K:
        ans = S

print(ans)

Measured memory_bytes: 137892
#include <cstdio>
#include <stdio.h>
#include <string>
#include <string.h>
#include <algorithm>
#include <vector>
#include <iostream>
using namespace std;
 
typedef vector<int> vi;
typedef long long ll;
typedef vector<ll> vl;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#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(a) (a).begin(),a.end()
#define MAXE(a) *max_element(ALL(a))
#define MINE(a) *min_element(ALL(a))


int main(){
  string a;
  cin >> a;
  int N = a.length();
  int b[N];
  REP(i,N)b[i]=0; 
  //jがn^i回後にいる場所
  int dp[20][N];
  REP(j,N){
    if(a[j]=='R') dp[0][j] = j+1;
    else dp[0][j] = j-1;
  }
  REP(i,19) REP(j,N) {
    dp[i+1][j] = dp[i][dp[i][j]];
  }
  REP(i,N){
    int x = dp[19][i];
    b[x]++;
  }
  REP(i,N)cout << b[i] << " ";
  cout << endl;
}


Measured memory_bytes: 8832
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int ans = 0;
		
		for(int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == '+') {
				ans++;
			} else {
				ans--;
			}
		}
		System.out.println(ans);
	}
}


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

using namespace std;
const int mod = 1e9 + 7;
const long long INF = 1e18;
#define PI 3.141592653589793
#define REP(i, n) for(long long i = 0;i < n;i++)
bool A[2000000];

int main()
{
  long long N,T;
  long long A,B=-1e9,count=0;
  cin>>N>>T;
  for(int i=0;i<N;i++){
    cin>>A;
    if(A-B<T)count+=A-B;
    else count+=T;
    B=A;
  }
  cout<<count;
  return 0;
}




Measured memory_bytes: 3628
#include<stdio.h>

int main()
{
	int i,j,h, w, flag;
	char s[101][102];

	scanf("%d%d", &h, &w);

	for (i = 0; i < h; i++)
		scanf("%s", s[i]);

	flag = 1;

	for (i = 0; i < h; i++)
	{
		for (j = 0; j < w; j++)
		{
			if (s[i][j] == '#'&&s[i - 1][j]!='#' && s[i + 1][j] != '#'&&s[i][j - 1] != '#'&&s[i][j + 1] != '#')
			{
				flag = 0;
				break;
			}
		}
	}

	if (flag == 1)
		printf("Yes\n");
	else
		printf("No\n");

	return 0;
}

Measured memory_bytes: 128
N,M = map(int,input().split())
sc = {}
flag = False
for i in range(M):
    s,c = map(int,input().split())
    if N!=1 and s==1 and c == 0:
        flag =True
        break
    elif s not in sc:
        sc[s] = c
    else:
        if sc[s] != c:
            flag = True
            break
if flag:
    print(-1)
elif N == 1 and M == 0:
    print(0)
else:
    if N == 1:
        print(sc[1])
    else:
        ans = [0 for i in range(N)]
        ans[0] = 1

        for s,c in sc.items():
            ans[s-1] = c
        print(*ans,sep='')
        print()


Measured memory_bytes: 3064
//Replacing
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <map>
#include <stdio.h>
#include <string.h>
#include <initializer_list>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <queue>
#include <set>
using namespace std;
const int INF = 1 << 29;
int main ()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> digit(100001,0);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        digit[A[i]]++;
    }
    unsigned long long sum = 0;
    for (int j = 0; j < N; j++) {
            sum += A[j];
    }

    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int B,C;
        cin >> B >> C;

        int diff = C - B;
        sum = sum + digit[B] * diff;
        digit[C] = digit[C] + digit[B];
        digit[B] = 0;
        
        cout << sum << endl;
    }

    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<iomanip>
#include<algorithm>
using namespace std;

vector<int> G[1<<18];
double dp [1<<18];
double dp2 [1<<18];

double dfs(int u,int p) {
    int cnt = 0;
    double ans = 0;
    for(int i = 0; i < G[u].size(); i ++) {
        if (G[u][i] == p) continue;
        ans += dfs(G[u][i], u) + 1;
        cnt ++;
    }
    return dp[u] = cnt ? ans / cnt : 1;
}

void dfs2(int u, int p, double a) {
    double ans=0;
    for(int i=0;i<G[u].size();i++)
    {
        if(G[u][i]==p)ans+=a;
        else ans+=dp[G[u][i]];
    }
    dp2[u] = ans/G[u].size();
    for(int i=0;i<G[u].size();i++)
    {
        if(G[u][i]==p)continue;
        dfs2(G[u][i],u, 1+(ans-dp[G[u][i]])/max(1,(int)G[u].size()-1));
    }
}

int main()
{
    int n;
    cin>>n;
    int u,v;
    for(int i = 1; i < n; i ++) {
        cin >> u >> v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, 0);
    dfs2(1, 0, 0);
    for(int i = 1; i <= n; i ++) {
        cout << setprecision(12) << dp2[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 21376
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

struct Combination{
    vector<ll> fac,finv,inv;
    Combination(int mx){init(mx);}
    void init(int mx){
        fac.resize(mx+1);
        finv.resize(mx+1);
        inv.resize(mx+1);
        fac[0]=fac[1]=1;
        finv[0]=finv[1]=1;
        inv[1]=1;
        for(int i=2;i<=mx;i++){
            fac[i]=fac[i-1]*i%mod;
            inv[i]=mod-inv[mod%i]*(mod/i)%mod;
            finv[i]=finv[i-1]*inv[i]%mod;
        }
    }
    ll operator()(int n,int k){
        if(n<k)return 0;
        return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
    }
};

int main(){
    int n,k;
    cin>>n>>k;
    ll a[n];
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    Combination comb(n);
    ll ans=0;
    rep(i,n){
        ans+=comb(i,k-1)*a[i];
        ans-=comb(n-1-i,k-1)*a[i];
        ans%=mod;
    }
    ans=(ans+mod)%mod;
    cout<<ans<<endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <set>
#include <cctype>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <algorithm>
#include <ctime>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <limits>
#include <cmath>
#include <typeinfo>

using namespace std;

int main() { 
	string s, t;
	cin >> s >> t;
	for(int i = 0; i < t.length(); i++) {
		cout << t[i];
	}
	for(int i = 0; i < s.length(); i++) {
		cout << s[i];
	}

  	return 0;
    
}


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

#define int long long

#define MOD 1000000007

int f(int a){
    if(a == 1){
        return 1;
    }
    return (a*f(a-1)) % MOD;
}

signed main(){
    int n, m;
    cin >> n >> m;

    int tmp = f(n)*f(m) % MOD;
    if(n == m){
        cout << (tmp * 2) % MOD << endl;
    }else if(abs(n-m) == 1){
        cout << tmp << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}



Measured memory_bytes: 1792
#ABC-125-C
N = int(input())
A = list(map(int, input().split())) #[0, 1, 2, ..., N-2, N-1]
L = [0] * N #L[0]とL[N-1]は0から変わらない。N=5なら実行終了時にL=[*0*,a,b,c,*0*]となる。
R = [0] * N #R[0]とR[N-1]は0から変わらない。N=5なら実行終了時にR=[*0*,f,e,d,A[4]]となる。

def gcd(x, y):
    while y:
        x, y = y, x%y
    return x

ans_gcd = -1

#Lから埋める
L[0] = A[0]
check_gcd = L[0]
for i in range(1, N-1): #N=5のときはi=1~3を実施して最終的にL=[0,a,b,c,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    L[i] = check_gcd

#Rを埋める
R[-1] = A[-1]
check_gcd = R[-1]
for i in reversed(range(1, N-1)):#N=5のときはi=3~1を実施して最終的にR=[0,f,e,d,0]となる。
    check_gcd = gcd(check_gcd, A[i])
    R[i] = check_gcd

#端以外を書き換えの対象とした場合の最大公約数のMaxを探す。
for i in range(1, N-1):
    m = gcd(L[i-1], R[i+1])
    ans_gcd = max(ans_gcd, m)

#端と比べて最終的な答えを出す。N>2のときは数字が低い方を消すだけ。
if N > 2:
    ans_gcd = max(ans_gcd, gcd(A[-2], L[N-3]), gcd(A[1], R[2]))
else:
    ans_gcd = max(A)

print(ans_gcd)

Measured memory_bytes: 14584
#include <bits/stdc++.h>
using namespace std;
#define rep for(int i = 0;i<n;i++)
#define ll long long
 
//const int INF = 1e8;
const int MOD = 1000000007;
typedef pair<int,int>P;
int dx[4] = {1,0,-1,0};int dy[4] = {0,1,0,-1};
queue<P> que;

int main(){
    int n;cin >> n;
    int a[n];int first = 0;int second = 0;
    rep{
        int ai;cin >> ai;
        if(ai >= first){
            second = first;
            first = ai;
        }else if(ai >= second){
            second = ai;
        }
        a[i] = ai;
    }
    rep{
        if(a[i]== first){
            cout << second << endl;
        }else{
            cout << first << endl;
        }
    }
}

Measured memory_bytes: 2432
#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <map>
#include <string.h>
 
using namespace std;

int gcd(int a,int b){
  if(b==0) return a;
  else gcd(b,a%b);
  }
 
int main(){
  
  int a,b;
 
  while(cin>>a>>b){
    
    if(a>=b) cout<<gcd(a,b)<<' '<<a/gcd(a,b)*b<<endl;
    else cout<<gcd(a,b)<<' '<<b/gcd(a,b)*a<<endl;
    
    }
      
}

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

#define ln '\n'
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define FORR(i, a, b) for(int i = (a); i >= (int)(b); --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<P> VP;
typedef vector<PL> VPL;
typedef vector<string> VS;

const int MOD = (int)1e9 + 7;


class BIT {
private:
    VL _bit;
    int _n_max;

public:
    BIT(int n): _n_max(n) {
        _bit.resize(_n_max + 1, 0);
    }

    void add(int i, ll x) {  // 1-indexed
        for(int j = i; j <= _n_max; j += j & -j) 
            _bit.at(j) = (_bit.at(j) + x) % MOD;
    }

    ll sum(int i) {  // 1-indexed, sum of [1, i]
        ll res = 0;
        for(int j = i; j > 0; j -= j & -j) 
            res = (res + _bit.at(j)) % MOD;
        return res;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VI a(n);
    REP(i, n) cin >> a.at(i);
    vector<BIT> bit(n + 1, BIT(k + 1));
    bit.at(0).add(0 + 1, 1);
    FOR(i, 1, n)FOR(j, 0, k) {
        ll sum = bit.at(i - 1).sum(j + 1) 
            - bit.at(i - 1).sum(max(j - a.at(i - 1), 0));
        bit.at(i).add(j + 1, (sum + MOD) % MOD);
    }

    cout << (bit.at(n).sum(k + 1) - bit.at(n).sum(k) + MOD) % MOD << ln;
    return 0;
}


Measured memory_bytes: 80256
from collections import Counter
N,M=map(int,input().split())
A=list(map(int,input().split()))
cum=[0]*(N+1)
for i in range(N):
    cum[i+1]=cum[i]+A[i]
for i in range(N+1):
    cum[i]=cum[i]%M
c=Counter(cum)
ans=0
for x,y in c.items():
    ans+=y*(y-1)//2
print(ans)

Measured memory_bytes: 62576
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
using namespace std;
int x1,ya,x2,y2;
typedef pair<int, int> P;

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

  cin >> x1 >> ya >> x2 >> y2;
  P direction = make_pair(x2-x1, y2-ya);
  int x3 = x2 - direction.second;
  int y3 = y2 + direction.first;
  int x4 = x1 - direction.second;
  int y4 = ya + direction.first;

  cout << x3 << ' '<< y3 << ' ' << x4 << ' ' << y4 << "\n";
  
  return 0;
}

Measured memory_bytes: 256
def check(s):
    n = len(s)
    for i in range(n//2):
        if s[i] != s[-(i+1)]:
            return False
    return True

def Main(S):
    N = len(S)
    a = S[:(N-1)//2]
    b = S[(N+2)//2:]
    return "Yes" if check(S) and check(a) and check(b) else "No"

def main():
    S = str(input())
    print(Main(S))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import sys
n, m = map(int, input().split())
n_list = [list(input()) for i in range(n)]
m_list = [list(input()) for i in range(m)]

def bunkatu(x, y):
    global n_list
    lis = []
    for i in range(y, y + m):
        lis.append(n_list[i][x: x + m])
    return lis

for j in range(n - m + 1):
    for i in range(n - m + 1):
        tmp = bunkatu(i, j)
        if m_list == tmp:
            print('Yes')
            sys.exit(0)
print('No')

Measured memory_bytes: 3064
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>
using namespace std;

typedef long long lint;

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        vector<int> score(n);
        int sum = 0, ma = 0, mi = 1500;
        for(int i = 0 ; i < n ; i++){
            cin >> score[i];
            sum += score[i];
            ma = max(ma, score[i]);
            mi = min(mi, score[i]);
        }
        sum -= (ma + mi);
        cout << sum / (n - 2) << endl;
    }
    return 0;
}


Measured memory_bytes: 3048
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define fi first
// #define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

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; }

struct Timer{
    chrono::system_clock::time_point start, end;
    Timer(){ start = chrono::system_clock::now(); }
    ~Timer(){
        end = chrono::system_clock::now();
        auto msec = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cerr<<"time : "<<msec<<" ms"<<endl;
    }
};


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // Timer TM;
    
    ll a,b;
    cin>>a>>b;
    if(b%a==0) cout<<a+b<<endl;
    else cout<<b-a<<endl;
    return 0;
}


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

int main() {
  string a;
  cin >> a;
  int N = a.size();
  vector<string> b(N);
  for (int i = 0; i < N; i++) {
    b.at(i) = a.at(i);
  }
  int c = 0;
  for (int i = 0; i < N; i++) {
    c += stoi(b.at(i));
  }
  if (c % 9 == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 9664
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	
	static class Lan implements Comparable<Lan>{
		int a, dis;
		Lan(int a,int dis){
			this.a=a;
			this.dis=dis;
		}
		public int compareTo(Lan l) {
			return this.dis-l.dis;
		}
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			while(sc.hasNext()) {
				int n=sc.nextInt();
				if(n==0) break;
				int m=sc.nextInt();
				PriorityQueue<Lan> pq=new PriorityQueue<Lan>();
				boolean [] visit=new boolean[n];
				int[][] lon=new int[n][n];
				int[] distance = new int[n];
				int INF=10000000;
				Arrays.fill(distance, INF);
				for(int i=0; i<m; i++) {
					String s=sc.next();
					String[] tokens=s.split(",");
					int a=Integer.parseInt(tokens[0]);
					int b=Integer.parseInt(tokens[1]);
					int d=Integer.parseInt(tokens[2]);
					lon[a][b]=lon[b][a]=d;
				}
				pq.add(new Lan(0, 0));
				int ans=0;
				while(!pq.isEmpty()) {
					Lan lan=pq.poll();
					if(visit[lan.a]) continue;
					//System.out.println(lan.a+" "+lan.dis);
					visit[lan.a]=true;
					if(lan.dis>0)ans+=lan.dis/100-1;
					boolean tf=true;
					for(int i=0; i<n; i++) {
						if(lon[lan.a][i]>0) {
							pq.add(new Lan(i, lon[lan.a][i]));
						}
					}
				}
				System.out.println(ans);
				
			}
			

		}
	}
}


Measured memory_bytes: 40228
// D.

#include <iostream>
#include <algorithm>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <map>

using namespace std;

struct UnionFind {
	std::vector<int> _parent;
	std::vector<int> _size;
	UnionFind(int size) : _parent(size, -1), _size(size, 1) { }
	void unite(int a, int b) {
		int ra = root(a), rb = root(b); if (ra == rb) { return; }
		if (_size[ra] >= _size[rb]) { _parent[rb] = ra, _size[ra] += _size[rb]; } else { _parent[ra] = rb, _size[rb] += _size[ra]; }
	}
	int root(int a) {
		int p = _parent[a];
		if (p < 0) { return a; }
		while (_parent[p] >= 0) { p = _parent[p]; }
		return _parent[a] = p;
	}
	int size(int a) { return _size[root(a)]; }
};

int main(int argc, char *argv[]) {
	int N, K, L;
	cin >> N >> K >> L;
	UnionFind road(N), rail(N);
	for (int i = 0; i != K; ++i) {
		int p, q;
		cin >> p >> q;
		road.unite(p - 1, q - 1);
	}
	for (int i = 0; i != L; ++i) {
		int r, s;
		cin >> r >> s;
		rail.unite(r - 1, s - 1);
	}
	map<pair<int, int>, int> m;
	for (int i = 0; i != N; ++i) {
		pair<int, int> key = make_pair(road.root(i), rail.root(i));
		m[key] += 1;
	}
	for (int i = 0; i != N; ++i) {
		pair<int, int> key = make_pair(road.root(i), rail.root(i));
		cout << (i ? " " : "") << m[key];
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 15104
import sys
txt=input()
n=int(input())
for i in range(n):
    x=input().split()
    if x[0]=='print':
        print(txt[int(x[1]):int(x[2])+1])
    elif x[0]=='replace':
        txt=txt[:int(x[1])]+x[3]+txt[int(x[2])+1:]
    else:
        txt=txt[:int(x[1])]+''.join(reversed(txt[int(x[1]):int(x[2])+1]))+txt[int(x[2])+1:]



Measured memory_bytes: 5616
from math import ceil as c,floor as f
a,b=map(int,input().split())
ah,bh=a+.99,b+.99
a1,a2=c(a/.08),f(ah/.08)
b1,b2=c(b/.1),f(bh/.1)
if a2<b1 or b2<a1: print(-1)
else:
    if b1<=a1<=b2: print(a1)
    elif a1<=b1<=a2: print(b1)
    elif b1<=a2<=b2: print(a2)
    elif a1<=b2<=a2: print(b2)



Measured memory_bytes: 62212
using System;
namespace AtCoder
{
    static class Solver
    {
        static IO io = new IO();
 
        public static void Solve()
        {
            io.ReadSplit();
            int A = io.Int();
            int B = io.Int();
            int C = io.Int();
 
            int count = 0;
            if ((A == B) && (A == C))
            {
                if (A % 2 == 0)
                {
                    count = -1;
                }
                else
                {
                    count = 0;
                }
            }
            else
            {
                count = Count(A, B, C);
            }
 
            io.WriteLine(count.ToString());
        }
 
        private static int Count(int A, int B, int C)
        {
            int count = 0;
            while (true)
            {
                if ((A % 2 == 0) && (B % 2 == 0) && (C % 2 == 0))
                {
                    count += 1;
                    A /= 2;
                    B /= 2;
                    C /= 2;
                }
                else if ((A % 2 == 1) && (B % 2 == 1) && (C % 2 == 1))
                {
                    count += 1;
                    return count;
                }
                else
                {
                    return count;
                }
            }
        }
    }
}
namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver.Solve();
        }
    }
    class IO
    {
        private string[] _Inputs;
        private int _Index;
        public void Read()
        {
            _Inputs = new string[1];
            _Inputs[0] = Console.ReadLine();
            _Index = 0;
        }
        public void ReadSplit()
        {
            _Inputs = Console.ReadLine().Split(' ');
            _Index = 0;
        }
        public string String()
        {
            return _Inputs[_Index++];
        }
        public string[] String(int xCount)
        {
            string[] rv = new string[xCount];
            Array.Copy(_Inputs, _Index, rv, 0, xCount);
            _Index += xCount;
            return rv;
        }
        public int Int()
        {
            return int.Parse(_Inputs[_Index++]);
        }
        public int[] Int(int xCount)
        {
            int[] rv = new int[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = int.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public long Long()
        {
            return long.Parse(_Inputs[_Index++]);
        }
        public long[] Long(int xCount)
        {
            long[] rv = new long[xCount];
            for (int i = 0; i < xCount; ++i)
            {
                rv[i] = long.Parse(_Inputs[_Index++]);
            }
            return rv;
        }
        public void Write(string xStr)
        {
            Console.Write(xStr);
        }
        public void WriteLine(string xStr)
        {
            Console.WriteLine(xStr);
        }
    }
}

Measured memory_bytes: 11092
#include <iostream>

long pow(long x, long y){
	if(y==0){
		return 1;
	}else if (y==1) {
		return x;
	}else if(y%2 == 0){
		long z = pow(x,y/2)%1000000007;
		return z*z%1000000007;

	}else{
		long z = pow(x,y/2)%1000000007;
		return (z*z%1000000007)*x%1000000007;
	}
}

int main(){
	long x , y;
	std::cin>>x>>y;
	std::cout<<pow(x,y)<<std::endl;
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define int long long
#define pb push_back
#define pll pair<long long,long long>
using namespace std;
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    int x=n/500;
    int sum=x*1000;
    int k=n%500;
    k=k/5;
    sum+=(k*5);
    cout<<sum;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
using namespace std;
int num[100001];
int leng;
int main() {
	cin >> leng;
	for (int i = 0;i < leng;i++) {
		cin >> num[i];
	}
	int count = 0;
	int NEW = 1000;
	int jud = NEW;
	int p = 0;
	while (p < leng) {
      if (jud == 0) {
			if (num[p] > num[p - 1]) {
				jud = 1;
			}
			else if (num[p] < num[p - 1]) {
				jud = -1;
			}
			else if (num[p] == num[p - 1]) {
				jud = 0;
			}
		}
		else if (jud == 1) {
			if (num[p] < num[p - 1]) {
				jud = NEW;	
			}
		}
		else if (jud == -1) {
			if (num[p - 1] < num[p]) {
				jud = NEW;
			}
		}
		if (jud == NEW) {
			count++;
			if (p!=0) {
				jud = 0;
			}
			else {
				jud = 0;
			}
		}
		p++;
	}
	cout << count << endl;
}

Measured memory_bytes: 640
import math

def main():
    N,K = map(int, input().split())
    prob = 0
    for a in range(N):
        power = math.ceil(max(0,math.log2(K)-math.log2(a+1)))
        prob += ((0.5)**power)
    print(prob/N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
s = input()
len_s = len(s)
mod = 10 ** 9 + 7
dp = [[0] * 13 for i in range(len_s)]
if s[-1] == '?':
    for i in range(10):
        dp[0][i] = 1
else:
    dp[0][int(s[-1])] = 1

digits = 1
for i in range(1, len_s):
    digits = (digits * 10)%13
    for j in range(13):

        if dp[i - 1][j] > 0:
            if s[-(i + 1)] != '?':
                add = int(s[-(i + 1)]) * digits
                dp[i][(j + add)%13] = (dp[i][(j + add)%13] + dp[i - 1][j])%mod
            else:
                for k in range(10):
                    # k:先頭に加える数字
                    add = k * digits
                    dp[i][(j + add) % 13] = (dp[i][(j + add) % 13] + dp[i - 1][j]) % mod

print(dp[-1][5] % mod)

Measured memory_bytes: 61916
X, K, D = map(int, input().split())
X = abs(X)

sho = X // D
yo = X % D

if sho > K:
    print(X - K * D)
elif sho == K:
    print(yo)
else:
    if (K - sho) % 2 == 0:
        print(yo)
    else:
        print(abs(yo - D))


Measured memory_bytes: 61684
N=int(input())
List=[list(input().split()) for i in range(N)]
LList=[]
for i in range(N):
    if List[i][1]=="JPY":
      LList.append(float(List[i][0]))
    else :
      LList.append(float(List[i][0])*380000.0)
print(sum(LList))

Measured memory_bytes: 3060
#include <stdio.h>
int main(void){
	int n,s;
	char calc[2];
	scanf("%d",&s);
	while(1){
		scanf("%s",calc);
		if(calc[0]=='=')
			break;
		scanf("%d",&n);
		switch(calc[0]){
			case '+':s+=n; break;
			case '-':s-=n; break;
			case '*':s*=n; break;
			default :s/=n; break;
		}
	}
	printf("%d\n",s);
	return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int count = 0;
  
  for (int i = 0; i < 3; i++) {
    if (S.at(i) == T.at(i)){
      count++;
    }
  }
  cout << count << endl;
}



Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int count = 0;
        for (int i = 1; i <= N; i++) {
            int num = sc.nextInt();
            if (i % 2 == 1 && num % 2 == 1) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 35724
//
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define MOD 1000000007
#define PI 3.14159265
#define EPS 1e-9
#define Pi acos(-1.0)
typedef pair<int, int> ii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
#define forr(i,a,b) for(int i=(a); i<(b); i++)
#define clean(arr,val) memset(arr,val,sizeof(arr))
#define forn(i,n) forr(i,0,n)
#define PB push_back
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vpll;

/*CODE START HERE*/

int n, ans, aux;
int arr[205];

int main(){
    ios::sync_with_stdio(0);
    cin >> n;
    forn(i,n){
        cin >> arr[i];
    }
    ans = INF;
    forn(i,n){
        aux = 0;
        while(arr[i]%2==0){
            aux++;
            arr[i]/=2; 
        }
        ans = min(ans,aux);
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
N,M = map(int,input().split())
#P = [list(map(int,input().split())) for i in range(M)]
D = [[] for i in range(N)]
#print(P.sort())
for i in range(M):
    p,y = map(int,input().split())
    D[p-1].append((y,i))
    

#D = [[(32,0),(12,2)],[(63,1)]]
#print(D)
submit = [0]*M
for i,d in enumerate(D):
    #print(d)
    d.sort()
    #print(i,d)
    for k, (y,j) in enumerate(d):
        #print(k,y,j)
        submit[j] = str(i+1).zfill(6)+str(k+1).zfill(6)
        
#print(submit)
print(*submit,sep = '\n')

Measured memory_bytes: 40336
#include <iostream>
#include <algorithm>
using namespace std;
int insertionSort(int a[],int n)
{
	for(int i=0;i<n;i++)
	{
		int j=i-1;
		int min=a[i];
		while(a[j]>min&&j>=0)
		{
			a[j+1]=a[j]; 
			j--;	
		}
		a[j+1]=min;
	}
 } 
int main()
{
	int x[10];
	for(int i=0;i<10;i++)
		cin>>x[i];
	insertionSort(x,10);	
	for(int i=9;i>=7;i--)
	cout << x[i] << endl;	
	return 0;
}


Measured memory_bytes: 3072
#レート 1-399：灰色
    #レート 400-799：茶色
    #レート 800-1199：緑色
    #レート 1200-1599：水色
    #レート 1600-1999：青色
    #レート 2000-2399：黄色
    #レート 2400-2799：橙色
    #レート 2800-3199：赤色

import numpy as np
n = input()
a = np.array(list(map(int, input().split())))
a = a // 400
b = set()
sa = 0
ans = 0
for i in a:
    if i >= 8:
        sa+=1
    else:
        b.add(i)

print(len(b) if len(b) != 0 else 1, len(b)+sa)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef unsigned long long ll;

ll N, n, M, K;

int main(){
    cin >> N >> M;
    vector<pair<ll,ll>> v;
    REP(i,N){
        ll a ; cin >>a;
        v.push_back( make_pair(a, 1) );
    }
    REP(i,M){
        ll a, b; cin >> a >> b;
        v.push_back(make_pair(b,a));
    }
    sort(v.begin(), v.end(), std::greater<>());
    ll card = 0, iter = 0, ans = 0;
    while(card < N){
      	ans += min(v[iter].second, N-card)*v[iter].first;
        card += v[iter].second;
      	++iter;
    }
    cout << ans;
}

Measured memory_bytes: 6512
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;

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

    cout << "ABC" << N << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        var n = int.Parse(Console.ReadLine());
        //int[] n = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var ans = 0;
        if (n <= 599) ans = 8;
        else if (600 <= n && n <= 799) ans = 7;
        else if (800 <= n && n <= 999) ans = 6;
        else if (1000 <= n && n <= 1199) ans = 5;
        else if (1200 <= n && n <= 1399) ans = 4;
        else if (1400 <= n && n <= 1599) ans = 3;
        else if (1600 <= n && n <= 1799) ans = 2;
        else if (1800 <= n) ans = 1;

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 27480
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int n, m;
int a[100020];
bool used[100020];
vector<int> G[100020];
int bestvalue;
int bestindex;
LL ans;
void dfs(int x) {
	used[x] = true;
	if (bestvalue > a[x]) {
		bestvalue = a[x];
		bestindex = x;
	}
	for (int i = 0; i < G[x].size();i++) {
		if (!used[G[x][i]]) {
			dfs(G[x][i]);
		}
	}
}

int main() {
	cin >> n >> m;
	REP(i, n)cin >> a[i];
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	int count = 0;
	for (int i = 0; i < n; i++) {
		if (!used[i]) {
			bestvalue = INF;
			bestindex = -1;
			dfs(i);
			count++;
			ans += bestvalue;
			a[bestindex] = INF;
		}
	}
	sort(a, a + n);
	if (count == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < count - 2; i++) {
		if (a[i] == INF) {
			cout << "Impossible" << endl;
			return 0;
		}
		ans += a[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 6272
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
using namespace std;
#define ll signed long long

int main() {
  vector<pair<ll, int> > apple;
  int X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  for (int i = 0; i < A; ++i) {
    ll t;
    cin >> t;
    apple.push_back(make_pair(t, 0));
  }
  for (int i = 0; i < B; ++i) {
    ll t;
    cin >> t;
    apple.push_back(make_pair(t, 1));
  }
  for (int i = 0; i < C; ++i) {
    ll t;
    cin >> t;
    apple.push_back(make_pair(t, 2));
  }

  ll x = 0, y = 0;
  sort(apple.begin(), apple.end());
  reverse(apple.begin(), apple.end());
  ll i = 0, cnt = 0;
  ll ans = 0;
  while (cnt < X + Y) {
    ll v = apple[i].first;
    ll c = apple[i].second;
    ++i;
    if (c == 0 && x < X) {
      ++x;
      ++cnt;
      ans += v;
    } else if (c == 1 && y < Y) {
      ++y;
      ++cnt;
      ans += v;
    } else if (c == 2) {
      ++cnt;
      ans += v;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 10476
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

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


unsigned long long int a[50][6];
vector<unsigned long long int>x,y,d;

int main(){

	int N,K;
	unsigned long long int x1,y1,d1,x2,y2,d2;
	cin >> N >> K;
	rep(i,N){
		cin >> x1 >> y1 >> d1 >> x2 >> y2 >> d2;
		a[i][0]=x1; a[i][1]=y1; a[i][2]=d1; a[i][3]=x2; a[i][4]=y2; a[i][5]=d2;
		x.push_back(x1); x.push_back(x2);
		y.push_back(y1); y.push_back(y2);
		d.push_back(d1); d.push_back(d2);
	}

	sort(x.begin(),x.end());
	vector<unsigned long long int>:: iterator itx=unique(x.begin(),x.end());
	x.erase(itx,x.end());

	sort(y.begin(),y.end());
	vector<unsigned long long int>:: iterator ity=unique(y.begin(),y.end());
	y.erase(ity,y.end());

	sort(d.begin(),d.end());
	vector<unsigned long long int>:: iterator itd=unique(d.begin(),d.end());
	d.erase(itd,d.end());

	unsigned long long int V=0;
	rep(i,x.size()-1){
		rep(j,y.size()-1){
			rep(k,d.size()-1){
				int t=0;
				double x0=(x[i]+x[i+1])/2.0,y0=(y[j]+y[j+1])/2.0,d0=(d[k]+d[k+1])/2.0;

				rep(l,N){
				if(a[l][0]<=x0 && x0<=a[l][3] && a[l][1]<=y0 && y0<=a[l][4] && a[l][2]<=d0 && d0<=a[l][5])
					t++;
				if(t>=K){ V+=(x[i+1]-x[i])*(y[j+1]-y[j])*(d[k+1]-d[k]); break;}
				}
			}
		}
	}

	cout << V << endl;

	return 0;
}

Measured memory_bytes: 1228
#include <iostream>
using namespace std;
int main(void){
    int a,b;
    char op;
    
    cin >> a >> op >> b;
    while(true){
        if (op == '?'){
            break;
        }
        else if (op == '+'){
            cout << (a+b) << endl;
         }  
        else if (op == '-'){
            cout << (a-b) << endl;
        }
        else if (op == '*'){
            cout << a*b << endl;
        }
        else if (op == '/'){
            cout << a/b << endl;
        }
    cin >> a >> op >> b;
    }
    return 0;
}



Measured memory_bytes: 3080
my ($N,$M,$K) = split(/ /,<>);
my $s = <>; chomp $s;
my @DBA = split(/ /,$s);
my $t = <>; chomp $t;
my @DBB = split(/ /,$t);

my @TA;
my $A=0;
$TA[0]=0;
for(my $i=0;$i<=$#DBA;$i++){
    $TA[$i+1] = $TA[$i] + $DBA[$i];
    if($TA[$i+1] >$K ){last;}
    $A++;
}
my @TB;
$TB[0]=0;
my $j=0;
my $ans= $A;
for(my $i=0;$i<=$#DBB;$i++){
    $TB[$i+1] = $TB[$i] + $DBB[$i];
    if($TB[$i+1] >$K ){ last;}
    while( $TA[$A-$j] + $TB[$i+1] > $K){
        $j++;
    }
    if($ans < ($A-$j+$i+1) ){ $ans = ($A-$j+$i+1);}
}
print "$ans";

Measured memory_bytes: 60536
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) FOR(i,0,n)



ll fast_pow(ll x,ll n,ll mod){
    if (n==0) return 1;
    ll res=fast_pow(x*x %mod,n/2,mod);
    if (n&1) res=res*x%mod;
    return res;
}

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;




int main(){
    int N;
    cin>>N;
    int x,y,basex,basey;
    ll h;
    ll baseh=0;
    //入力の格納用
    vector<tuple<int,int,ll>> vec;
    rep(i,N){
        cin>>x>>y>>h;
        vec.emplace_back(x,y,h);
        if (baseh==0 && h!=0){
            basex=x,basey=y,baseh=h;
            //cout<<basex<<','<<basey<<','<<baseh<<endl;        
            
        }
    }
    //答え候補となる各点での高さを計算する
    vector<tuple<int,int,ll>> ans_memo;
    FOR(i,0,101){
        FOR(j,0,101){
            h=baseh+abs(i-basex)+abs(j-basey);
            ans_memo.emplace_back(i,j,h);
        }
    } 
    int ansx,ansy; ll ansh;
    for (auto a1:ans_memo){
        bool check=true;
        ansx=get<0>(a1); ansy=get<1>(a1); ansh=get<2>(a1);
        
        for (auto a2:vec){
            x=get<0>(a2);y=get<1>(a2);h=get<2>(a2);
            if (h!=max((ll)0,ansh-abs(ansx-x)-abs(ansy-y))){
                check=false;
                break;
            }
        }
        //if (ansx==2 && ansy==2) cout<<ansh<<endl;
        if (check==true){
            cout<<ansx<<' '<<ansy<<' '<<ansh<<endl;
        }
    }
    
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

int main() {
	string s;
	cin >> s;
	int l = stoi(s.substr(0, 2));
	int r = stoi(s.substr(2, 2));
	if (l == 0 && r == 0) {
		cout << "NA" << endl;
		return 0;
	}
	bool lm = false;
	bool rm = false;
	if (l <= 12 && l != 0) {
		lm = true;
	}
	if (r <= 12 && r != 0) {
		rm = true;
	}
	if (lm && rm) {
		cout << "AMBIGUOUS" << endl;
		return 0;
	}
	if (lm) {
		cout << "MMYY" << endl;
		return 0;
	}
	if (rm) {
		cout << "YYMM" << endl;
		return 0;
	}
	cout << "NA" << endl;
	return 0;
}



Measured memory_bytes: 256
h,w=map(int,input().split())
C=[]
for i in range(10):
    C.append(list(map(int,input().split())))
A=[]
for i in range(h):
    A.append(list(map(int,input().split())))

for k in range(10):
    for i in range(10):
        for j in range(10):
            C[i][j]=min(C[i][j],C[i][k]+C[k][j])
cnt=0
for i in range(h):
    for j in range(w):
        if A[i][j]==-1 or A[i][j]==1:
            continue
        cnt+=C[A[i][j]][1]
print(cnt)

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

public class Main {

  Scanner sc;

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  int a, n;
  int p, q;

  int dfs(int last, int sa, int sn, double sm) {
    if (sn > n) {
      return 0;
    }

    int cnt = 0;
    if (Math.abs(sm - (double) p / q) < 1e-9) {
      ++cnt;
    }
    if ((sm - (double) p / q) > 1e-9) {
      return 0;
    }
    for (int i = last; i <= a / sa; ++i) {
      cnt += dfs(i, sa * i, sn + 1, sm + 1.0 / i);
    }
    return cnt;
  }

  void run() {
    for (; ; ) {
      p = ni();
      q = ni();
      a = ni();
      n = ni();

      if (p == 0) {
        break;
      }

      System.out.println(dfs(1, 1, 0, 0));
    }
  }

  void debug(Object... os) {
    System.err.println(Arrays.deepToString(os));
  }
}

Measured memory_bytes: 31092