akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <iostream>
#include <climits>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <vector>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <utility>
#include <queue>
#include<bits/stdc++.h>

using namespace std;

/**templates**/
#define ll long long
#define LL long long
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define sd(x) scanf("%lf",&x)
#define ss(x) scanf("%s",x)
#define pi acos(-1.0)
#define pb push_back
#define inf 1LL<<62

int main()
{
    ll tst,a,b,m,n,res=0,ans=0,i,j,temp;
    bool ck=1;
    sl(n);
    sl(ans);
    a=ans/10000;
    b=ans/5000;
    for(i=a;i>=0;i--)
    {
        for(j=0;j<=b;j++)
        {
            temp=n-(i+j);
            if(temp<0)
                break;
            if((10000*i)+(5000*j)+(1000*temp)==ans)
                {
                    ck=0;
                    break;
                }

        }
        if(ck==0)
            break;
    }
    if(ck)
        printf("-1 -1 -1\n");
    else
        printf("%lld %lld %lld\n",i,j,temp);



    return 0;
}


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

int main(){
  ll n,ans=0;
  cin>>n;
  for(int k=1;k<=n;k++){
    ans+=k*floor(n/k)*floor(1+n/k)/2;
  }
  cout<<ans<<endl;
}


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

int main() {

    string a, b;
    cin >> a >> b;

    int aa, bb;
    cin >> aa >> bb;

    string c;
    cin >> c;

    if(c == a) cout << aa-1 << " " << bb << endl;
    else cout << aa << " " << bb-1 << endl;

    return 0;
}

Measured memory_bytes: 256
from fractions import Fraction

class Combination:
    '''計算量：階乗・逆元テーブルの作成O(N)
       nCkを求めるO(1)'''

    def __init__(self, n, MOD):
        self.fact = [1]
        for i in range(1, n + 1):
            self.fact.append(self.fact[-1] * i % MOD)
        self.inv_fact = [pow(self.fact[i] ,MOD - 2 ,MOD) for i in range(n + 1)]
        self.MOD = MOD

    def factorial(self, k):
        '''k!を求める'''
        return self.fact[k]

    def inverse_factorial(self, k):
        '''k!の逆元を求める'''
        return self.inv_fact[k]

    def combination(self, k, r):
        '''kCrを求める'''
        return (self.fact[k] * self.inv_fact[k - r] * self.inv_fact[r]) % self.MOD


b, w = map(int,input().split())
MOD = 10**9 + 7
comb = Combination(b+w, MOD)

#黒が(b+w-i)個残る確率 := pb
#白が(b+w-i)個残る確率 := pw
pb = [0]*(b+w+1)
pw = [0]*(b+w+1)

for i in range(b+w):
    if b+w-i > b:
        pb[b+w-i] = 0
        result_b = 0
    else:
        result_b = pb[b+w-i+1] + pow(pow(2, i, MOD), MOD-2, MOD) * comb.combination(i-1, w-1)
        result_b %= MOD
        pb[b+w-i] = result_b
        
    if b+w-i > w:
        pw[b+w-i] = 0
        result_w = 0
    else:
        result_w = pw[b+w-i+1] + pow(pow(2, i, MOD), MOD-2, MOD) * comb.combination(i-1, b-1)
        result_w %= MOD
        pw[b+w-i] = result_w
        
    ans = result_b + pow(2, MOD-2, MOD) * (1 - result_b - result_w)
    print(ans % MOD)

Measured memory_bytes: 108652
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

int main(){
  long N;
  long a[100015],k;
  long count = 0;
  fill_n(a,100015,0);

  cin >> N;
  for(long i=1;i<=N;++i){
    cin >> k;
    if(k<=100000){
      a[k]++;
    }else{
      count++;
    }
  }
  for(long i=1;i<=N+1;++i){
    if(i<=a[i]){
      count += a[i]-i;
    }else{
      count += a[i];
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    intl a[n];
    rep(i,n){
        a[i] = m + i;
    }
    intl b = INF;
    intl idx = 0;
    rep(i,n){
        if(b > abs(a[i])){
            idx = i;
            b = abs(a[i]);
        }
    }
    intl ans = 0;
    rep(i,n){
        if(i == idx)continue;
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
string=input()
#print(s.index("Z")-s.index("A")+1)
tmp=None
a=[]
for i in range(len(string)):
    if string[i]=="A" and tmp is None:
        tmp=i
    if string[i]=="Z" and tmp is not None:
        a.append(i-tmp+1)
print(max(a))

Measured memory_bytes: 7528
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 100000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back


int n,ma,mb;
int dp[500][500][50];
int a[100],b[100],c[100];

signed main(){
  cin>>n>>ma>>mb;
  rep(i,500){
    rep(j,500){
      rep(k,50){
        dp[i][j][k]=inf;
      }
    }
  }
  rep(i,n){
    cin>>a[i]>>b[i]>>c[i];
  }

  dp[0][0][0]=0;

  rep(k,41){
    rep(i,410){
      rep(j,410){
        if(k>0)
          dp[i][j][k]=min(dp[i][j][k],dp[i][j][k-1]);
        dp[i+a[k]][j+b[k]][k+1]=min(dp[i+a[k]][j+b[k]][k+1],dp[i][j][k]+c[k]);
      }
    }
  }

  
  int ans = inf;
  rep(i,410){
    rep(j,410){
      if(ma*j==mb*i&&i!=0){
        ans = min(ans,dp[i][j][n]);
      }
    }
  }

  if(ans==inf){
    cout<<-1<<endl;
  }
  else
    cout<<ans<<endl;

}


Measured memory_bytes: 49024
#include <bits/stdc++.h>
#define REP(i, n) for(long long i=0; i<n; i++)
#define REPR(i, n) for(long long i=n-1; i>=0; i--)
#define FOR(i, m, n) for(long long i=m; i<=n; i++)
#define FORR(i, m, n) for(long long i=m; i>=n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
#define FIN ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
const ll mod = 1e9+7;
const ll inf = 1e15;
ll power(ll a,ll b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}


int main(){FIN
    string s,t;cin>>s>>t;
    vector<char> a(s.size()), b(t.size());
    REP(i,s.size()){
        a[i] = s[i];
    }
    REP(i,t.size()){
        b[i] = t[i];
    }
    VSORT(a); VSORTR(b);
    string ans = "No";
    bool same = true;
    REP(i,min(s.size(), t.size())){
        if (a[i] < b[i]){
            ans = "Yes";
            break;
        } 
        if (a[i] != b[i]) same = false;
    }
    if (same && t.size()>s.size()) ans = "Yes";
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3656
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
	"strings"
)

var mod int64 = 1000000007

func modPow2(num int64) int64 {
	if num == 0 {
		return 1
	}

	var rtn int64
	rtn = 1
	var i int64
	for i = 0; i < num; i++ {
		rtn = (rtn << 1) % mod
	}
	return rtn
}

func main() {
	N := getStdinInt64()
	hash1 := make(map[string]int64)
	hash2 := make(map[string]string)
	var zero int64 = 0
	var i int64
	for i = 0; i < N; i++ {
		list := getStdinIntArr64()
		A := list[0]
		B := list[1]
		if A == 0 && B == 0 {
			zero++
		} else if B == 0 {
			hash1["1/0"]++
			hash2["1/0"] = "0/1"
		} else if A == 0 {
			hash1["0/1"]++
			hash2["0/1"] = "1/0"
		} else {
			rat1 := big.NewRat(A, B)
			rat2 := big.NewRat(-B, A)
			hash1[fmt.Sprint(rat1)]++
			hash2[fmt.Sprint(rat1)] = fmt.Sprint(rat2)
		}
	}

	var ans int64 = 1
	for idx, val1 := range hash1 {
		if val1 == -1 {
			continue
		}
		var val2 int64 = hash1[hash2[idx]] // 仲の悪い相方
		var tmp1 int64 = (modPow2(val1) - 1) % mod
		var tmp2 int64 = (modPow2(val2) - 1) % mod
		var tmp3 int64 = 1
		hash1[idx] = -1 // 重複を避ける
		hash1[hash2[idx]] = -1
		ans = (ans * (tmp1 + tmp2 + tmp3)) % mod
	}
	ans = (ans + zero + mod - 1) % mod
	fmt.Printf("%d", ans)
	fmt.Printf("\n")
}

var sc = bufio.NewScanner(os.Stdin)

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
func getStdinInt64() int64 {
	sc.Scan()
	rtn, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return rtn
}
func getStdinIntArr64() []int64 {
	sc.Scan()
	str := sc.Text()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}


Measured memory_bytes: 107848
#include <iostream>
#include <string>

using std::string;

int main()
{
    while (true) {
        string in;
        std::cin >> in;

        if (in == "-") {
            break;
        }

        int shuffle_num;
        std::cin >> shuffle_num;

        int head = 0;
        while (shuffle_num--) {
            int cards_num;
            std::cin >> cards_num;

            head = (head + cards_num) % in.size();
        }

        string out = in.substr(head) + in.substr(0, head);
        std::cout << out << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1212
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		//文字取得
		String s = sc.next();
		String answer = "";
		sc.close();

		for(int i = 0; i < s.length(); i++) {
			char character = s.charAt(i);
			//System.out.println(character);

			if(character == '0' || character == '1') {
				answer += character;
			}else if(character == 'B') {
				if(answer.length() == 0) {
					//何もしない
				}else{
					//文字があったら削る
					answer = answer.substring(0, answer.length()-1);
				}
			}
		}

		System.out.println(answer);
	}

}


Measured memory_bytes: 21716
import java.util.Scanner;

public class Main {
    public static final int INFTY = 200000000;
    public static final int MOD   = 100000000;
    
    public static boolean check[];
    public static final int NUMBER = 2000;
    public static int FACTORS;
    public static int table[];
    
    public static void main(String[] args) {
        check = new boolean[NUMBER + 1];
        
        Scanner scanner = new Scanner(System.in);
        FACTORS = scanner.nextInt();
        
        table = new int[FACTORS];
        
        for(int k = 0; k < FACTORS; k++) {
            table[k] = scanner.nextInt();
        }
        
        recursive(0, 0);
        
        int queryNumber = scanner.nextInt();
        
        int tmpNum = 0;
        StringBuilder answer = new StringBuilder();
        
        for(int i = 0; i < queryNumber; i++) {
            tmpNum = scanner.nextInt();
            
            if(check[tmpNum]) {
                answer.append("yes\n");
            } else {
                answer.append("no\n");
            }
        }
        
        System.out.print(answer.toString());
    }
    
    public static void recursive(int key, int sum) {
        if(key == FACTORS) {
            check[sum] = true;
            return;
        }
        
        recursive(key + 1, sum);
        
        if(sum + table[key] <= NUMBER) {
            recursive(key + 1, sum + table[key]);
        }
    }
}


Measured memory_bytes: 26792
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

A=[a,b,c,d,e]
count=0
for i in range(5):
    for j in range(5):
        if abs(A[i]-A[j])>k:
            count+=1
if count==0:
    print('Yay!')
else:
    print(':(')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll X,Y,Z;
    cin >>X>>Y>>Z;
    
    cout << Z<<" " << X<<" "<<Y<< endl;


    return 0;
    

}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define st string
#define int unsigned long long
#define mii map<int,int>
#define low lower_bound
#define upp upper_bound
#define mod 1000000007 //10^9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
//efine sort(vec) sort(all(vec));
#define rever(vec) reverse(all(vec));
#define bisea binary_search
#define unsort(vec) sort(vec); rever(vec);
#define cend cout<<endl;
#define gcd __gcd
#define F first
#define S second
using namespace std;
signed main() {
	int n,k;
	cin>>n>>k;
	pair<int,int>A[114514];
	rep(i,n) {
		int a,b;
		cin>>a>>b;
		A[i].F=a;
		A[i].S=b;
	}
	sort(A,A+n);
	int cnt=0;
	rep(i,n) {
		int a,b;
		a=A[i].F;
		b=A[i].S;
		cnt+=b;
		if(k<=cnt) {
			cout<<a<<endl;
			break;
		}
	}
}


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


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

    string s;
    cin>>s;
    int n = s.size();
    int cnt = 0;
    int last = 0;
    int q = 0;
    bool end = true;
    reverse(s.begin(),s.end());
    for(int i=0;i<n;i++){
        if(s[i] == '?'){
            if(i!=0) end = false;
            q = i;
        }
        else{
            if(i <= 6 && i>=1){
                cnt += (s[i] - '0') * (i+1);
                cnt %= 11;
            }
            else if(i >=7 && i <= 11){
                cnt += (i-5) * (s[i] - '0');
                cnt %= 11;
            }
            else last = s[i] - '0';
        }
    }
    if(end){
        if(cnt <=1){
            cout << 0 << endl;
        }
        else cout << 11 - cnt << endl;
        return 0;
    }
    int ans = -1;
    if(last == 0){
        for(int i=0;i<10;i++){
            bool ok = false;
            if(q <= 6 && q>=1){
                if((cnt + i*(q+1))%11 <= 1) ok = 1;
            }
            else {
                if((cnt + i*(q-5))%11 <= 1) ok = 1;
            }
            if(ok){
                if(ans != -1){
                    cout << "MULTIPLE" << endl;
                    return 0;
                }
                ans = i;
            }
        }
    }
    else{
        for(int i=0;i<10;i++){
            bool ok = false;
            if(q<=6){
                if(11-(cnt + i*(q+1))%11 == last) ok = 1;
            }
            else {
                //cerr << q << endl;
                //cerr << i << " " << (cnt + i*(q-5))%11 << " " << last << endl;
                if(11-(cnt + i*(q-5))%11 == last) ok = 1;
            }
            if(ok){
                if(ans != -1){
                    cout << "MULTIPLE" << endl;
                    return 0;
                }
                ans = i;
            }
        }
    }
    cout << ans << endl;
}



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

using namespace std;

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  
  int rest = A-B;
  
  if(rest>C){
    cout << 0 << endl;
  }else{
    cout << C-rest << endl;
  }

  return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i
　　　　／　　　＼　 　 |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/












int N, M, C, B[20];
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> M >> C;
    rep(i, 0, M) cin >> B[i];

    int ans = 0;
    rep(i, 0, N) {
        int sm = C;
        rep(j, 0, M) {
            int a; cin >> a;
            sm += B[j] * a;
        }
        if (0 < sm) ans++;
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define cinsc ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOR(i,k,n)  for(int64 i=k;i<n;i++)
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
#define SQ(x) ((x)*(x))
const double pi=acos(-1.0);
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MPII;
typedef set<int> SETI;
typedef multiset<int> MSETI;
typedef long int int32;
typedef unsigned long int uint32;
typedef long long int int64;
typedef unsigned long long int  uint64;
 
//ONLINE_JUDGE   LOCAL
 
int64 powr(int64 x,int64 y,int64 p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0){   
        if (y & 1)  
            res = (res*x) % p;   
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
} 
 
void  in_o(){
#ifndef LOCAL
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif
	cinsc;
}
 


 
int main(){
	//in_o();
	string a,b;
	cin>>a>>b;
	int flag=0;
	if(a.length()>b.length())
		cout<<"GREATER"<<endl;
	else if(a.length()<b.length())
		cout<<"LESS"<<endl;
	else{
		int n=a.length();
		FOR(i,0,n){
			if(a[i]!=b[i]){
				if(a[i]>b[i])
					return cout<<"GREATER"<<endl,0;
				else if(a[i]<b[i])
					return cout<<"LESS"<<endl,0;
			}
			if(i==n-1)
				return cout<<"EQUAL"<<endl,0;				
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n); i >= 0; i--)
#define revrepr(i, a, b) for (int i = (a); i >= b; i--)
#define debug(x) cerr << #x << ": " << x << "\n"

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

const long long MOD = 1e9+7;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    cin >> a;

    vector<int> sum(n + 1);
    rep(i, n) sum.at(i + 1) = (sum.at(i) + a.at(i)) % m;

    map<int, ll> mp;
    mp[0] = 1;
    ll cnt = 0;
    rep(i, n) {
        cnt += mp[sum.at(i + 1)];
        mp[sum.at(i + 1)]++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 4992
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

bool is_prime(int n, int k = 2)
{
    if(n < k * k) { return true; }
    
    if(n % k == 0) { return false; }
    
    return is_prime(n, k + 1);
}

int main()
{
    vector<int> prime = {2};
    
    for(int i = 3; i < 101300; i += 2)
    {
        if(is_prime(i))
        {
            prime.push_back(i);
        }
    }
    
    int n, m;
    
    while(true)
    {
        scanf("%d", &n);
        scanf("%d", &m);
        
        if(n == -1 && m == -1) { break; }
        
        int ptr = distance(prime.begin(), lower_bound(prime.begin(), prime.end(), n + 1));
        
        vector<int> c;
        
        for(int i = ptr; i < ptr + m; i++)
        {
            for(int j = i; j < ptr + m; j++)
            {
                c.push_back(prime[i] + prime[j]);
            }
        }
        
        sort(c.begin(), c.end());
        
        printf("%d\n", c[m - 1]);
    }
    
    return 0;
}

Measured memory_bytes: 3360
import java.util.ArrayDeque

fun main(args: Array<String>){
    val (N, Q) = readLine()!!.split(" ").map(String::toInt)
    val neighbors = Array(N){ mutableListOf<Int>() }
    repeat(N - 1){
        val (A, B) = readLine()!!.split(" ").map(String::toInt)
        neighbors[A - 1].add(B - 1)
        neighbors[B - 1].add(A - 1)
    }
    
    val points = IntArray(N)
    repeat(Q) {
        val (P, X) = readLine()!!.split(" ").map(String::toInt)
        points[P - 1] += X
    }

    val queue = ArrayDeque(listOf(0))
    val visited = BooleanArray(N){ false }
    while(queue.isNotEmpty()){
        val cur = queue.poll()
        visited[cur] = true
        neighbors[cur].forEach {
            if(!visited[it]){
                points[it] += points[cur]
                queue.add(it)
            }
        }
    }
    println(points.joinToString(separator = " "))
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int t[n],x[n],y[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>t[i]>>x[i]>>y[i];
	}
	int f=1;
	if (t[0]>=abs(x[0])+abs(y[0])&&t[0]%2==(abs(x[0])+abs(y[0]))%2)
	{
		f=1;
	}
	else
	{
		f=0;
	}
	for (int i = 0; i < n-1; ++i)
	{
		if (t[i+1]-t[i]>=abs(x[i+1]-x[i])+abs(y[i+1]-y[i])&&(t[i+1]-t[i])%2==(abs(x[i+1]-x[i])+abs(y[i+1]-y[i]))%2)
		{
			continue;
		}
		f=0;
	}
	if (f)
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


Measured memory_bytes: 1408
// https://atcoder.jp/contests/abc106/tasks/abc106_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int_fast32_t i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int_fast32_t i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

// 約数の個数 (１の倍数＋２の倍数＋３の倍数＋...)
template <int N> struct calc_approx {
    int cnt[N + 1];

    constexpr calc_approx() : cnt() {
        for (int_fast64_t i = 1; i <= N; ++i) {
            for (int_fast64_t j = i; j <= N; j += i)
                cnt[j]++;
        }
    }
};
calc_approx<200000> approx;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int ans = 0;
    for (int i = 105; i <= N; i += 2) {
        ans += (approx.cnt[i] == 8);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5236
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int[] h = new int[n];
		for(int i = 0;i < n;i++){
			h[i] = saori.saori_hayami();
		}
		int[] dp = new int[n+1];
		dp[0] = 0;

		for(int i = 1;i < n;i++){
			if(i == 1){
				dp[i] = Math.abs(h[i] - h[i-1]);
				continue;
			}
			dp[i] = Math.min(Math.abs(h[i] - h[i-1]) + dp[i-1], Math.abs(h[i] - h[i-2]) + dp[i-2]);
		}

		System.out.println(dp[n-1]);
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

Measured memory_bytes: 22740
/**
*   Russian Flag
**/

#include<bits/stdc++.h>
using namespace std;

int n = 0;
int m = 0;
char flag[70][70] = {0};

int solve()
{
  int cnt = 0;
  int ans = 1001001001;
  for (int i = 0; i < n - 2; i++)
  {
    for (int j = i + 1; j < n - 1; j++)
    {
      cnt = 0;
      for (int l = 0; l < m; l++)
      {
        for (int w = 0; w <= i; w++)   if (flag[w][l] != 'W') cnt++;
        for (int b = i+1; b <= j; b++) if (flag[b][l] != 'B') cnt++;
        for (int r = j+1; r < n; r++) if (flag[r][l] != 'R') cnt++;
      }
      //printf("[debug]{i: %d, j: %d, w: 0-%d, b: %d-%d, r: %d-%d, cnt: %d}\n", i, j, i, i+1, j, j+1, n-1, cnt);
      ans = min(ans, cnt);
      //printf("[debug]ans = %d\n", ans);
    }
  }
  return ans;
}

int main()
{
  cin >> n >> m;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < m; j++)
    {
      cin >> flag[i][j];
    }
  }
  printf("%d\n", solve());
  return 0;
}



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

int main() {
  string a;
  cin >> a;
  if(a[0] == a[1] && a[1] == a[2])cout << "Yes" << endl;
  else if (a[1] == a[2] && a[2] == a[3])cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

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

  int k = 0;
  for (int i = 1; i * (i - 1) <= 2 * n; i++) {
    if(i * (i - 1) == 2 * n) {
      k = i;
      break;
    }
  }
  if(k == 0) {
    cout << "No" << '\n';
    return 0;
  }
  vector<vector<int>> answer (k);

  int base = 0;
  int limit = k - 1;
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    answer[base].push_back(i);
    answer[base + cnt + 1].push_back(i);
    cnt++;
    if(cnt == limit) {
      cnt = 0;
      limit--;
      base++;
    }
  }

  cout << "Yes" << '\n';
  cout << k << '\n';
  for (int i = 0; i < k; i++) {
    cout << (k - 1) << " ";
    for (auto it : answer[i]) {
      cout << it << " ";
    }
    cout << '\n';
  }
  return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

bool isOk(string s)
{
	bool ret = true;
	int n = s.length();
	for(int i = 0; i < n / 2; ++i)
	{
		ret = ret & (s[i] == s[n - i - 1]);
	}
	// cout << "in " << s << " " << ret << endl;
	return ret;
}

void solve()
{
	string s;
	cin >> s;
	int n = s.length();
	bool ans = true;
	ans = 	isOk(s) & 
			isOk(s.substr(0, (n - 1) / 2)) & 
			isOk(s.substr( (n + 3) / 2 - 1));

	cout << ( ans ? "Yes" : "No") << endl;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

(t, p, r) = map(int, raw_input().split())
while t!=0:
    pena = [0]*t
    pub = [[False]*p for i in range(t)]
    mis = [[0]*p for i in range(t)]
    num = [0]*t
    for i in range(r):
        (tid, pid, time, mes) = raw_input().split()
        tid = int(tid)-1
        pid = int(pid)-1
        time = int(time)
        if pub == True:
            continue
        if mes == "CORRECT":
            pub[tid][pid] = True
            pena[tid] += mis[tid][pid]*1200+time
            num[tid] += 1
        else:
            mis[tid][pid] += 1
    order = []
    for i in range(t):
        order.append([-num[i], pena[i], i])
    order.sort()
    for i in range(t):
        print order[i][2]+1, -order[i][0], order[i][1]

    (t, p, r) = map(int, raw_input().split())










    

Measured memory_bytes: 4292
while True:
  a,op,b = map(str, input().split())
  a = int(a)
  b = int(b)
  if op == '?': 
    break
  if op == '+':
    print(a+b)
  if op == '-':
    print(a-b)
  if op == '*':
    print(a*b)
  if op == '/':
    print(a//b)


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;

#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define eb emplace_back

set<int> ms;
double sum[200005], val[1005];
int main(){
    for(int i=1;i<=1000;i++){
        for(int j=1;j<=i;j++) val[i] += 1.0/i*j;
    }
    int k, n, p;
    cin >> n >> k;
    for(int i=1;i<=n;i++){
        cin >> p;
        sum[i] = val[p];
        sum[i] += sum[i-1];
    }
    double ans = 0;
    for(int i=k;i<=n;i++){
        ans = max(ans, sum[i]-sum[i-k]);
    }
    printf("%.10lf\n", ans);
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stack>
#define stack std::stack
stack<char> s;
int main()
{
	char temp;
	while(~scanf("%c",&temp))
	{
		if(temp!='S'&&temp!='T')continue;
		if(temp=='S') s.push(temp);
		else
		{
			if(s.empty()) s.push(temp);
			else if(s.top()=='S') s.pop();
			else s.push(temp);
		}
	}
	printf("%d",s.size());
}

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

typedef long long  LL;

using namespace std;

int main(){
	
	LL N,C;
	cin >> N >> C;
	
	vector<LL> vecl(N+1);
	vecl.at(0) = 0;
	vector<LL> lmax(N+1,0);
	vector<LL> lini(N+1,0);
	
	vector<LL> vecr(N+1);
	vecr.at(0) = 0;
	vector<LL> rmax(N+1,0);
	vector<LL> rini(N+1,0);
	
	vector<vector<LL>> vec = vector<vector<LL>>(N+2, vector<LL>(2,0));
	
	vec.at(N+1).at(0) = C;
	vec.at(N+1).at(1) = 0;
	
	for(LL i=1; i<N+1; i++){
		cin >> vec.at(i).at(0) >> vec.at(i).at(1);
	}
	
	for(LL i=1; i<N+1; i++){
		vecl.at(i) = vecl.at(i-1) + vec.at(i).at(1) - (vec.at(i).at(0) - vec.at(i-1).at(0)) ;
		if(lmax.at(i-1) < vecl.at(i)) lmax.at(i) = vecl.at(i);
		else lmax.at(i) = lmax.at(i-1);
		if(lini.at(i-1) < vecl.at(i) - vec.at(i).at(0)) lini.at(i) = vecl.at(i) - vec.at(i).at(0);
		else lini.at(i) = lini.at(i-1);
		
	}
	
	for(int i=1; i<N+1; i++){
		vecr.at(i) = vecr.at(i-1) + vec.at(N+1-i).at(1) - (C - vec.at(N+1-i).at(0)) + (C - vec.at(N+2-i).at(0));
		if(rmax.at(i-1) < vecr.at(i)) rmax.at(i) = vecr.at(i);
		else rmax.at(i) = rmax.at(i-1);
		if(rini.at(i-1) < vecr.at(i) - (C - vec.at(N+1-i).at(0))) rini.at(i) = vecr.at(i) - (C - vec.at(N+1-i).at(0));
		else rini.at(i) = rini.at(i-1);
		
		
	}
	
	
	
	LL res = 0;
	
	//cout << "rmax = " << rmax << " rini = " << rini << endl;
	//cout << "lmax = " << lmax << " lini = " << lini << endl;
	
	
	
	/*
	for(LL i=0; i<N+1; i++){
		cout<< " i = " << i<< endl;
		cout<< "lmax = " << lmax.at(i)<< " lini = " << lini.at(i) << endl;
		cout<< "rmax = " << rmax.at(i)<< " rini = " << rini.at(i) << endl;
		
	}*/
		
	
	
	for(LL i=0; i<N+1; i++){
		if (res <= rmax.at(i)) res = rmax.at(i);
		if(res <= rini.at(i) + lmax.at(N-i))res = rini.at(i) + lmax.at(N-i);
		if(res <= lini.at(i) + rmax.at(N-i))res = lini.at(i) + rmax.at(N-i);
		if(res <= lmax.at(i))res = lmax.at(i);
		
	}
	cout << res << endl;
	
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

int main(){
    fcin;
    int n;
    cin >> n;
    vector<int> a(n);
    for(int& i : a) cin >> i;

    int ans = INF;
    for(int i = 1; i <= 100; i++){
        int cost = 0;
        for(int j : a) cost += ((j - i) * (j - i));
        ans = min(ans, cost);
    }
    cout << ans << endl;
    return 0;
}



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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pll> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

vector<vector<int> > rotate(vector<vector<int> > &v) {
	int h = v.size(), w = v[0].size();
	
	vector<vector<int> > tmp(w, vector<int>(h));
	REP(i, h) REP(j, w) tmp[j][h - 1 - i] = v[i][j];
	
	return tmp;
}

int main() {
	int n, m;
	while (cin >> n >> m, n || m) {
		vector<vector<int> > w(n, vector<int>(n)), p(m, vector<int>(m));
		
		REP(i, n) REP(j, n) scanf("%d", &w[i][j]);
		REP(i, m) REP(j, m) scanf("%d", &p[i][j]);
		
		pii ans(INF, 0);
		REP(t, 4) {
			REP(y, n - m + 1) REP(x, n - m + 1) {
				bool ok = true;
				REP(i, m) if (ok) REP(j, m) if (ok) {
					int xx = x + j, yy = y + i;
					if (p[i][j] == -1) continue;
					if (w[yy][xx] != p[i][j]) ok = false;
				}
				if (ok) {
					int dx = -1, dy;
					REP(i, m) REP(j, m) {
						if (dx == -1 && p[i][j] != -1) {
							dx = j, dy = i;
						}
					}
					chmin(ans, pii(y + dy, x + dx));
				}
				
			}
			p = rotate(p);
		}
		
		if (ans == pii(INF, 0)) puts("NA");
		else {
			printf("%d %d\n", ans.se + 1, ans.fi + 1);
		}
	}
	
	return 0;
}

Measured memory_bytes: 3304
#import math  
import fractions
from functools import reduce

N = int(input())
T = []
for i in range(N):
    T.append(int(input()))

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
ans = lcm_list(T)

print(ans)

Measured memory_bytes: 5052
n=int(input())
A=list(map(int,input().split()))
q=int(input())
m=list(map(int,input().split()))

def solve(x,y):
    global n
    global A
    if y==0:
        return True
    if x>=n:
        return False
    if sum(A[x:])<y:
        return False
    return solve(x+1,y) or solve(x+1,y-A[x])
for i in m:
    if solve(0,i):
        print("yes")
    else:
        print("no")


Measured memory_bytes: 5620
import java.util.*;
import java.math.*;
public class Main {
    static final int MOD = 1_000_000_007; // 10^9+7
    //static final int MAX = 2_147_483_646; // intの最大値
    static final int INF = 1_000_000_000; // 10^9
    static final int MAX = 10_000_000;
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int[][] dp = new int[n][n];
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                if(i>=j)continue;
                dp[i][j] = Math.min(j-i,dp[i][j-1]+1);
                if(i > x-1&&j > x-1)dp[i][j] = Math.min(dp[i][j], dp[x-1][i]+dp[x-1][j]);
                if(i<x&&j==y-1)dp[i][j]-=y-x-1;
            }
        }
        for(int i = n-1;i >=0;i--){
            for(int j = n-2;j >= 0;j--){
                if(dp[i][j] > dp[i][j+1]+1)dp[i][j] = dp[i][j+1]+1;
            }
        }
        int[] ans = new int[n];
        for(int i = 0;i < n;i++){
            for(int j = 0;j < n;j++){
                ans[dp[i][j]]++;
            }
        }
        for(int i = 1;i< n;i++){
            System.out.println(ans[i]);
        }

    }       
}






Measured memory_bytes: 52564
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
 

  int a,b,c;
  cin>>a>>b>>c;

  bool flg=false;
  for(int i=1;i<=100;i++)
  if( (a*i)%b==c ){
    flg=true;
  }

  if(flg)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;

	return 0;
}

Measured memory_bytes: 3640
#include<stdio.h>
#define N 5000000

typedef struct
{
  int l,r,key;
}H;

H B[N];

void maxHeapify(int);
void BMH();

int n;

int main()
{
  int i,j;
  scanf("%d",&n);
  B[0].key = 0;
  for(i=1;i<=n;i++)
  {
    scanf("%d",&B[i].key);
    B[i].l = B[i].r = 0;
  }

  BMH();

  for(i=1;i<=n;i++)
  {
    printf(" %d",B[i].key);
  }
  printf("\n");

  return 0;
}

void maxHeapify(int i)
{
  int left=0,right=0,largest,temp;
  left = 2*i;
  right = 2*i+1;

  if(left <= n && B[left].key > B[i].key)
    largest = left;
  else
    largest = i;

  if(right <= n && B[right].key > B[largest].key)
    largest = right;

  if(largest != i)
  {
    temp = B[i].key;
    B[i].key = B[largest].key;
    B[largest].key = temp;
    maxHeapify(largest);
  }
}

void BMH()
{
  int i;
  for(i=n/2;i>=1;i--)maxHeapify(i);
}



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

int main() {
  int N,W;
  cin >> N >> W;
  vector<long long> w(N);
  vector<long long> v(N);
  for(int i=0;i<N;i++){
    cin >> w[i] >> v[i];
  }
  long long dp[N+1][W+1];
  for(int i=0;i<=W;i++){
    dp[0][i]=0;
  }
  for(int i=0;i<=N;i++){
    dp[i][0]=0;
  }
  for(int i=0;i<N;i++){
    for(int j=1;j<=W;j++){
      if(j<w[i]){
        dp[i+1][j]=dp[i][j];
      }else{
        dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      }
    }
  }
  cout << dp[N][W];
}
  

Measured memory_bytes: 79104
//Dragon_warrior7(IITK)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define deb(x) cout << #x << " " << x << "\n"
#define pll pair<ll, ll> 
#define vll vector<ll> 
#define rub cout << "\n------------------------------------\n"
void read(vector<ll> &v)
{
	for (int i = 0; i < v.size(); i++)
		cin >> v[i];
}

void print(vector<ll> v)
{
	for (int i = 0; i < v.size(); i++)
		cout << v[i] << " ";
}
ll n,m,a,b,temp,x,y;
string str;
set<ll> s;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	ll k;
	cin>>k;
	cin>>a;
	vll v;
	for(int i=0;i<k;i++)
	v.pb(a);
	if(a>(n-k))
	{
	    for(int i=0;i<n-k;i++)
	    {
	       v.pb(1); 
	    }
	}
	 else
	    {
	        for(int i=0;i<n-k;i++)
	        v.pb(1000000000);
	    }
	    print(v);
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <limits>
#include <string>
#include <vector>

using namespace std;

const long long INF = 1LL << 60;

//各桁の和を出力
long long Sum(long long n) {
  long long m = 0;
  while (n) {
    m += n % 10;
    n /= 10;
  }
  return m;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void Comuse() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; 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;
  }
}

#define comuse Comuse()
// nCk(comuseを使え)
long long combi(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// pCk(comuseを使え)
long long perm(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] % MOD) % MOD;
}

//最小公倍数(aとbの)
long long lcm(long long a, long long b) {
  long long n;
  n = a / __gcd(a, b) * b;
  return n;
}

// auto A = div(n)
vector<long long> div(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) {
        ret.push_back(n / i);
      }
    }
  }
  sort(ret.begin(), ret.end());
  return ret;
}

//(aのn乗をmodで割ったあまり)
long long modpow(long long a, long long n, long long mod) {
  long long ans = 1;
  while (n > 0) {
    if (n & 1) {
      ans = ans * a % mod;
    }

    a = a * a % mod;

    n >>= 1;
  }

  return ans;
}

void solve();

const int MAX_N = 131072;
// segment tree
int NN;
int seg[MAX_N * 2 - 1];
void seguse() {
  for (int i = 0; i < 2 * NN - 1; i++) {
    seg[i] = INT_MAX;
  }
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;
  solve();
}

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

int N, M;

void solve() {
  cin >> N >> M;
  cout << N * (N - 1) / 2 + M * (M - 1) / 2 << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int count = sc.nextInt();
        for (int i = 0; i < count; i++) {
            String op = sc.next();
            if (op.equals("replace")) {
                StringBuilder sb1 = new StringBuilder();
                sb1.append(str).replace(sc.nextInt(), sc.nextInt() + 1, sc.next());
                str = sb1.toString();
            } else if (op.equals("reverse")) {
                StringBuilder sb1 = new StringBuilder();
                StringBuilder sb2 = new StringBuilder();
                int a = sc.nextInt(), b = sc.nextInt() + 1;
                sb2.append(str).replace(a, b, sb1.append(str.substring(a, b)).reverse().toString());
                str = sb2.toString();
            } else {
                System.out.println(str.substring(sc.nextInt(), sc.nextInt() + 1));
            }
        }
    }
}

Measured memory_bytes: 29408
#include<iostream>
#include<cstdio>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstring>
#include<algorithm>

#define L(x) (x<<1)
#define R(x) (x<<1|1)
#define ll long long
using namespace std;

const int M=1e5+100,inf=1e8;
const double z=1e-6;

int q[M],top;

int main()
{
    ios::sync_with_stdio(false);
    int n,tem;
    cin>>n>>q[0];
    top=0;
    bool flag=true;
    for(int i=1;i<n;i++)
    {
        cin>>tem;
        if(flag&&tem-1>=q[top])q[++top]=tem-1;
        else if(flag&&tem>=q[top])q[++top]=tem;
        else flag=false;
    }
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 640
<?php
$pattern = strtolower(trim(fgets(STDIN)));
$count = 0;

while (true) {
  $text = trim(fgets(STDIN));
  if ($text == "END_OF_TEXT") break;
  $text = explode(" ", strtolower($text));

  foreach ($text as $word)
    if ($word == $pattern) $count++;
}

echo $count . "\n";



Measured memory_bytes: 9244
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// House Moving
// 2012/09/20
public class Main{
	Scanner sc=new Scanner(System.in);

	long INF=1L<<60;

	int n;
	int[] x;

	void run(){
		n=sc.nextInt();
		x=new int[n];
		for(int i=0; i<n; i++){
			x[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		SegTree seg=new SegTree(n);
		for(int i=0; i<n; i++){
			seg.update(x[i], seg.query(0, x[i]+1)+x[i]);
		}
		println((long)n*(n+1)/2-seg.query(0, n+1)+"");
	}

	class SegTree{
		int N;
		long[] a;

		SegTree(int n){
			N=Integer.highestOneBit(n)<<1;
			a=new long[N<<1];
		}

		void update(int k, long x){
			a[N+k]=x;
			for(int i=(N+k)>>1; i>0; i>>=1){
				a[i]=max(a[2*i], a[2*i+1]);
			}
		}

		// [s, t)
		long query(int s, int t){
			return query(s, t, 1, 0, N);
		}

		long query(int s, int t, int k, int l, int r){
			if(r<=s||l>=t){
				return 0;
			}else if(s<=l&&r<=t){
				return a[k];
			}else{
				return max(query(s, t, k*2, l, (l+r)>>1),
						query(s, t, k*2+1, (l+r)>>1, r));
			}
		}
	}

	class Scanner{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in){
			br=new BufferedReader(new InputStreamReader(in));
			eat("");
		}

		void eat(String s){
			st=new StringTokenizer(s);
		}

		String nextLine(){
			try{
				return br.readLine();
			}catch(IOException e){
				throw new IOError(e);
			}
		}

		boolean hasNext(){
			while(!st.hasMoreTokens()){
				String s=nextLine();
				if(s==null)
					return false;
				eat(s);
			}
			return true;
		}

		String next(){
			hasNext();
			return st.nextToken();
		}

		int nextInt(){
			return Integer.parseInt(next());
		}
	}

	void println(String s){
		System.out.println(s);
	}

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

Measured memory_bytes: 15000
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 0; i < 3; i++){
		if((n%10) == 7){
			cout << "Yes\n";
			return 0;
		}
		n /= 10;
	}
	cout << "No\n";
	return 0;
}


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

int n = 0;
char str[3]; 

int main(){
  int i;
  cin>> str;
  for(i=0;i<4;++i){
    if(str[i] == '+') ++n;
    else if(str[i] == '-') --n;
  }
  cout<< n <<endl;
  return 0;
}
  

Measured memory_bytes: 256