akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>

int K, S;

int main()
{
	scanf("%d%d", &K, &S);
	int i, j;
	long long res = 0;
	for(i=0; i<=K; i++){
		for(j=0; j<=K; j++){
			if(S-i-j<=K && S-i-j>=0)
				res ++;
		}
	}
	printf("%lld\n", res);
	return 0;
}

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

const int N = 200005;
const int md = 1e9 + 7;

int fact[N], inv[N];

int pw(int a, int b) {
	int res = 1;
	while(b) {
		if (b & 1) res = 1LL * res * a % md; a = 1LL * a * a % md;
		b >>= 1;
	}
	return res;
}

int C(int n, int k) {
	if (n == k) return 1;
	if (n < 0 || k < 0 || n < k) return 0;
	return 1LL * fact[n] * (1LL * inv[k] * inv[n-k] % md) % md;
}

int calc(int a, int b) {
	return C(a + b - 2, a - 1);
}

int h, w, a, b;

int main() {
	scanf("%d %d", &h, &w);
	scanf("%d %d", &a, &b);
	fact[0] = 1; for (int i = 1; i < N; ++i) fact[i] = 1LL * fact[i-1] * i % md;
	for (int i = 0; i < N; ++i) inv[i] = pw(fact[i], md - 2);

	int ans = 0;
	for (int i = 1; i <= h - a; ++i) {
		int j = h + 1 - i;
		ans = (ans + 1LL * calc(i, b) * calc(j, w - b)) % md;
	}
	cout << ans << '\n';
}

Measured memory_bytes: 1792
n,m,x,y = map(int,input().split())
li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))

a = max(li1)
b = min(li2)

war = "War"

for i in range(a+1,b+1):
    if x < i <= y:
        war = "No War"
        break

print(war)


Measured memory_bytes: 3060
import os
import sys
from collections import Counter

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


N = int(sys.stdin.buffer.readline())
S = [sys.stdin.buffer.readline().decode().rstrip() for _ in range(N)]

counts = Counter(S)
_, m = counts.most_common(1)[0]
ans = []
for s, cnt in counts.items():
    if cnt == m:
        ans.append(s)
ans.sort()
print(*ans, sep='\n')


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

int main() {
  int N, max=0, c=0, k;
  cin >> N;
  vector<int> moti(N);
  
  for(int i=0;i<N;i++){
    cin >> moti.at(i);
  }
  
  for(int i=0;i<N;i++){
    max=0;
    for(int j=0;j<N;j++){
      if(i==0){
        if(max < moti.at(j))
          max = moti.at(j);
      }else{
        if(max < moti.at(j) && moti.at(j) < k)
          max = moti.at(j);
      }
    }
    k=max;
    if(max > 0)
      c++;
  }
  cout << c << endl;
      
      
}


Measured memory_bytes: 3552
#include <stdio.h>
int main() {
	int x, y, z, s;
	scanf("%d %d %d",&x,&y,&z);
	for(int i=x;i<=y;i++)
		{
			if(z % i==0)
				s++;	
		}
	printf("%d\n",s);
return 0;
} 


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

    }
}

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

using namespace std;

char m[100][100];

int ans[100][100];

int main()
{
	int h, w; cin >> h >> w;

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

	memset(ans, -1, sizeof(ans));

	for (int i = 0; i < h; ++i) {
		for (int j = w - 1; j >= 0; --j) {
			for (int k = j; k >= 0; --k) {
				if (m[i][k] == 'c') {
					ans[i][j] = j - k;
					break;
				}
			}
		}
	}

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) printf(j == 0 ? "%d" : " %d", ans[i][j]);
		printf("\n");
	}
}

Measured memory_bytes: 1232
# 入力
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

x1, y1, x2, y2 = li()

x3, y3, x4, y4 = x2-(y2-y1), y2+(x2-x1), x1-(y2-y1), y1+(x2-x1)

print(x3,y3,x4,y4)

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


void solve(long long A, long long B){
    if(1<=A && A<=9){
        if(1<=B && B<=9){
            cout<<A*B<<endl;
            return;
        }
    }
    cout<<-1<<endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
import math
N, K = map(int,input().split())
logs = list(map(int,input().split()))
a = 0
b = max(logs)
b_memo = set()
count=0
flg =0
while b-a > 1:
    c = (a+b)//2
    times = []
    for i in logs:
        times.append(math.ceil(i/c)-1)
    if sum(times) > K:
        a = c
    else:
        b = c

print(b)

Measured memory_bytes: 219872
#include <bits/stdc++.h>
using namespace std;
struct zb
{
    int x, y;
};
int n, m, ans = 0;
const int dx[4]{1, -1, 0, 0}, dy[4]{0, 0, 1, -1};
int d[25][25];
char a[25][25];
bool vis[25][25];
queue<zb> q;
int main()
{
    memset(a, 0x3f, sizeof(a));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> a[i][j];
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            if (a[i][j] == '#')
                continue;
            memset(d, 0, sizeof(d));
            memset(vis, 0, sizeof(vis));
            q.push((zb){i, j});
            vis[i][j] = 1;
            while (!q.empty())
            {
                zb now = q.front();
                q.pop();
                for (int k = 0; k < 4; k++)
                {
                    int nx = now.x + dx[k], ny = now.y + dy[k];
                    if (nx > n || ny > m || nx <= 0 || ny <= 0 || a[nx][ny] == '#' || vis[nx][ny])
                        continue;

                    vis[nx][ny] = 1;
                    d[nx][ny] = d[now.x][now.y] + 1;
                    ans = max(d[nx][ny], ans);
                    q.push((zb){nx, ny});
                }
            }
        }

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

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

int N, K;
int A[200010];
int max_=-1;

int main(){
  cin >> K >> N;
  for(int i = 0; i < N; ++i) cin >> A[i];
  A[N] = A[0] + K;
  for(int i = 0; i < N; ++i){
    int res = A[i+1]-A[i];
    if(res > max_){
       max_ = res;
    }
  }
  cout << K - max_;
  return 0;
}

Measured memory_bytes: 1024
#line 1 "/home/parallels/kyopro/cplib/template.cpp"
#include<bits/stdc++.h>
using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;

void lyn(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}

#line 1 "/home/parallels/kyopro/cplib/debug.cpp"
#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
	return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}
#line 1 "/home/parallels/kyopro/cplib/modint.cpp"
template<int mod = 1000000007> struct modint{
  long long x; 
  modint(long long x=0):x((x%mod+mod)%mod){}
  modint operator-() const { return modint(-x);}
  modint& operator+=(const modint a) { if ((x += a.x) >= mod) x -= mod; return *this; }
  modint& operator-=(const modint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; }
  modint& operator*=(const modint a) { (x *= a.x) %= mod; return *this;}
  modint operator+(const modint a) const { return modint(*this) += a;}
  modint operator-(const modint a) const { return modint(*this) -= a;}
  modint operator*(const modint a) const { return modint(*this) *= a;}
  modint pow(long long t) const {
    if (!t) return 1; modint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a;
  }
  // for prime mod
  modint inv() const { return pow(mod-2);}
  modint& operator/=(const modint a) { return *this *= a.inv();}
  modint operator/(const modint a) const { return modint(*this) /= a;}
};
template<int mod = 1000000007>
istream& operator>>(istream& is, modint<mod>& a) { return is >> a.x;}
template<int mod = 1000000007>
ostream& operator<<(ostream& os, const modint<mod>& a) { return os << a.x;}

#line 3 "main.cpp"
using mint = modint<(int)(1e9+7)>;
int main(int argc, char const* argv[])
{
  lyn();
  
  mint sum = 0;
  int n;cin >> n;
  vector<ll> a(n);
  cin >> a;

  vector<mint> cum(n+1,0);
  REP(i,n)cum[i+1] = cum[i] + a[i];

  mint ans = 0;

  REP(i,n){
    ans += (mint)a[i] * (cum[n] - cum[i+1]);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6364
fun main(args: Array<String>) {
    readInteger()
    calc(0, readLine()!!).let(::println)

}

fun calc(count: Int, s: String): Int {
    if (s.length < 3) {
        return count
    }

    return calc(calcNextCount(count, s), s.substring(1))
}

fun calcNextCount(count: Int, s: String) = if (s.startsWith("ABC")) count + 1 else count

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 33688
a1=input("").split(" ")
a2=input("").split(" ")
a3=input("").split(" ")
lista=[]
listmp=[]
for k in range(3):
    listmp+=[int(a1[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
    listmp+=[int(a2[k])]
lista+=[listmp]
listmp=[]
for k in range(3):
    listmp+=[int(a3[k])]
lista+=[listmp]
n=int(input(""))
listn=[]
for i in range(n):
    t=int(input(""))
    listn+=[t]
for i in range(3):
    for k in range(3):
        if(lista[i][k] in listn):
            lista[i][k]=0
p=0
for i in range(3):
    s=0
    for k in range(3):
        s+=lista[i][k]

    if(s==0):
            p=1
for i in range(3):
    s=0
    for k in range(3):
        s+=lista[k][i]

    if(s==0):
            p=1
s=0
for i in range(3):
    s+=lista[i][i]
if(s==0):
    p=1
s=0
for i in range(3):
    s+=lista[i][2-i]
if(s==0):
    p=1
if(p==1):
    print("Yes")
else:
    print("No")
    
    

    


Measured memory_bytes: 9256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

string S;
 
string ans = "Yes";

void solve(){
    if(S[2]!=S[3]) ans="No";
    if(S[4]!=S[5]) ans="No";
}
 
int main(){
    cin >> S;
 
    solve();
 
    cout << ans << endl;
    return 0;
}

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

map<pair<int, int>, int> s;
long long x[10];

void add(int i, int j) {
  pair<int, int> u = make_pair(i, j);
  if (s.find(u) != s.end()) s[u]++;
  else s.insert(make_pair(u, 1));
}

int main(){
  long long h, w, n; cin >> h >> w >> n;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    for (int x = -1; x <= 1; x++) {
      for (int y = -1; y <= 1; y++) {
        if (a+x <= 0 || b+y <= 0 || a+x >= h-1 || b+y >= w-1) continue;
        add(a+x, b+y);
      }
    }
  }
  long long sum = 0;
  for (map<pair<int, int>, int>::iterator it = s.begin(); it != s.end(); it++) {
    sum++;
    x[it->second]++;
  }
  x[0] = (h-2) * (w-2) - sum;
  for (int i = 0; i < 10; i++) {
    cout << x[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 56448
# 初期入力
N = int(input())
#B = list(map(int, input().split()))
B = [10**5] + list(map(int,input().split())) + [10**5]
#
A =[0]*(N+1)
A[0]=B[0]
for i in range(N):
    A[i+1] =B[i]
    A[i] =min(B[i],B[i-1])
    #if 0<i:
     #   A[i] =min(A[i-1],b) 

print(sum(A[1:]))

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

int N;
vector<int> G[100100];
bool v[100100];

bool bfs() {
    queue<int> f;
    queue<int> s;
    f.push(0);
    s.push(N - 1);
    v[0] = v[N - 1] = true;

    int fennec = 0;
    int sunuke = 0;

    bool check = true;
    while (check) {
        int Nf = f.size();
        int Ns = s.size();

        check = false;

        for (int i = 0; i < Nf; i++) {
            int k = f.front();
            f.pop();
            fennec++;
            for (int j = 0; j < G[k].size(); j++) {
                int to = G[k][j];
                if (!v[to]) {
                    f.push(to);
                    v[to] = true;
                    check = true;
                }
            }
        }

        for (int i = 0; i < Ns; i++) {
            int k = s.front();
            s.pop();
            sunuke++;
            for (int j = 0; j < G[k].size(); j++) {
                int to = G[k][j];
                if (!v[to]) {
                    s.push(to);
                    v[to] = true;
                    check = true;
                }
            }
        }
    }

    return fennec > sunuke;
}

int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    if (bfs()) {
        cout << "Fennec" << endl;
    } else {
        cout << "Snuke" << endl;
    }
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #pragma GCC optimize("unroll-loops,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
// using namespace __gnu_pbds;
using namespace std;
 
// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef long double ld;
typedef pair<long long ,long long> ii; 	
//typedef complex<long double> com;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin >> n;
	unordered_map <ll,bool> mapp;
	for (int z=0;z<n;z++){
		ll temp;
		cin >> temp;
		if (mapp[temp]){
			cout << "NO" << endl;
			return 0;
		}
		mapp[temp] = true;
	}
	cout << "YES" << endl;
} 
 


Measured memory_bytes: 8520
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

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

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

  string S, T;
  cin >> S;
  cin >> T;

  ll l = lcm(N, M);
  ll ds = l/N;
  ll dt = l/M;
  ll d = lcm(ds, dt);

  for(ll i = 0; i*d <= l-1; i++){
    if(S[i*d/ds] != T[i*d/dt]) {
      cout << -1 << endl;
      return 0;
    }
  }

  cout << l << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void){
	
	char s[4];
	
	int sum = 700;
			
	scanf("%s",s);	
	
	for(int i = 0;i < 3;i++){
		
		if(s[i] == 'o')
			sum += 100;
			
	}
	
	printf("%d",sum);
	
	return 0;
	
}
	

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int main(){

	int a, b, h;
	cin >> a >> b >> h;

	cout << ( a + b ) * h / 2 << endl;

	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main(){
    int n,q;
    string s;
    cin>>n>>q>>s;
    int l=s.size();
    vector<int> ac={-1};
    bool A = false;
    for(int i=0; i<l; i++){
        if(A){
            if(s.at(i)=='C') ac.push_back(i-1);
        }
        if(s.at(i)=='A') A=true;
        else A=false;
    }
    ac.push_back(l);
    int k =ac.size();
    for(int i=0; i<q; i++){
        int l,r;
        cin>>l>>r;
        r--;
        l--;
        int ok=0;
        int ng=k;
        while(ng-ok>1){
            if( ac.at((ng+ok)/2) >=l ){
                ng = (ng+ok)/2;
            }
            else ok=(ng+ok)/2;
        }
        int L = ng;
        ok=0;
        ng=k;
        while(ng-ok>1){
            if( ac.at((ng+ok)/2)+1 >r ){
                ng = (ng+ok)/2;
            }
            else ok=(ng+ok)/2;
        }
        int R =ok;
        cout<<R-L+1<<endl;
    }
}

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

#define MOD 1000000007
typedef pair<int,int> pi;
typedef long long ll;

int main()
{
   int n;
   string s;
   cin>>n>>s;
   if(n%2!=0)
   {
       cout<<"No";
   }
   else
   {
       int mid = n/2;
       bool flag = true;
       for(int i=0, j=mid; i<=mid-1 && j<=n-1; i++, j++)
       {
           //cout<<i<<" "<<s[i]<<" "<<j<<" "<<s[j]<<endl;
           if(s[i] != s[j])
           {
               flag = false;
               break;
           }
       }
       if(flag)
        cout<<"Yes";
       else
        cout<<"No";
   }
}



Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN


int main(void){
	bool ok=true;
	ll n,m,a[100010],b[100010],visit[100010]={};
	cin>>n>>m;
	rep(i,m){
		cin>>a[i]>>b[i];
		visit[a[i]]++;
		visit[b[i]]++;
	}
	reg(i,1,n){
		if(visit[i]%2==1)ok=false;
	}
	cout<<(ok?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 2560
def DFS(num):
    global ans,color
    color[num]="black"
    if "white" not in color[1:]:
        ans +=1
    for i in MAP[num]:
        if color[i]=="white":
            DFS(i)
    color[num]="white"


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

MAP=[[] for _ in range(n+1)]
for a,b in AB:
    MAP[a].append(b)
    MAP[b].append(a)

color=["white" for _ in range(n+1)]
ans=0
DFS(1)
print(ans)

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long

int main() {
    fastio;
    int n, x;
    cin >> n >> x;
    int* a = new int[n];

    for (int i = 0; i< n; ++i) cin >> a[i];

    sort(a, a + n);
    int count = 0;
    while (x >= 0) {
        x -= a[count++];
        if (count == n) break;
    }
    if (x != 0) count--;
    cout << count;
    return 0;
}

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

int selection(vector<int> &);

int main(int argc, char const *argv[])
{
    int n = 0;
    cin >> n;

    vector<int> a(n, 0);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }

    int cnt = selection(a);

    for (int i = 0; i < n - 1; i++)
    {
        cout << a[i] << " ";
    }
    cout << a[n - 1] << endl
         << cnt << endl;

    return 0;
}

int selection(vector<int> &a)
{
    int cnt = 0;
    for (int i = 0; i < (int) a.size(); i++)
    {
        int min_i = i;
        for (int j = i + 1; j < (int) a.size(); j++) {
            if (a[j] < a[min_i]) {
                min_i = j;
            }
        }
        if (a[i] > a[min_i]) {
            int temp = a[i];
            a[i] = a[min_i];
            a[min_i] = temp;
            cnt++;
        }
    }
    return cnt;
}



Measured memory_bytes: 3112
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
using namespace std;

long long int a[111111];
long long int kuro[111111];
long long int b[111111];
int main(void){
  int N,K,x,i,j,k;
  long long int res,tmp,zero;
  zero=res=tmp=0;
  scanf("%d %d",&N,&K);

  for(i=0;i<=N;i++){
    a[i]=kuro[i]=b[i]=0;
  }
  for(i=1;i<=N;i++){
    scanf("%lld",&a[i]);
  }
  for(i=1;i<=K;i++){
    kuro[1]+=a[i];
  }
  for(i=2;i<=N-K+1;i++){
    kuro[i]=kuro[i-1]+a[i+K-1]-a[i-1];
  }

  b[1]=max(zero,a[1]);
  for(i=2;i<=N;i++){
    b[i]=b[i-1]+max(zero,a[i]);
  }
  for(i=1;i<=N-K+1;i++){
    tmp=kuro[i]+b[i-1]+(b[N]-b[i+K-1]);
    res=max(res,tmp);
  }
  for(i=1;i<=N-K+1;i++){
    tmp=b[i-1]+(b[N]-b[i+K-1]);
    res=max(res,tmp);
  }

  printf("%lld\n",res);

  return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int main() {
 int u[100],d[100],dp[101][101],i,j,k,n;
 cin >> n;
 for (i=0;i<100;i++) for (j=0;j<100;j++) dp[i][j]=999999999;
 for (i=0;i<n;i++) { cin >> u[i] >> d[i]; dp[0][i]=0;} 
 for (i=1;i<n;i++)
	 for (j=0;j<n-i;j++)
		 for (k=0;k<i;k++) dp[i][j]=min(dp[i][j],dp[k][j]+dp[i-k-1][j+k+1]+u[j]*d[j+k]*u[j+k+1]*d[j+i]) ; 
 cout << dp[n-1][0] << endl;
 return 0;
 }

Measured memory_bytes: 1200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_Coffee_160
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string s = Console.ReadLine();

            string s3 = s.Substring(2, 1);
            string s4 = s.Substring(3, 1);
            string s5 = s.Substring(4, 1);
            string s6 = s.Substring(5, 1);

            string result;

            if ( s3 == s4 && s5 == s6)
            {
                result = "Yes";
            }
            else
            {
                result = "No";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25756
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  ll d,n;
  cin>>d>>n;
  if(n==100)n++;
  ll a=1;
  for(int i=0;i<d;i++)a*=100;
  cout<<a*n<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
#define sz(s) (int)(s.size())
#define vecprint(v) rep(i,0,v.size()-1)cout << v[i] << " ";cout << endl;
#define arrprint(v,n) rep(i,0,n-1)cout << v[i] << " ";cout << endl;
#define matprint(v,n,m) rep(i,0,n-1){rep(j,0,m-1){cout << v[i][j] << " ";}cout << endl;}
using namespace std;
const int mod=1000000007;
const int INF=1001001001;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n;
    cin >> n;
    set<int> s;
    rep(i,0,n-1){
        int a;
        cin >> a;
        auto itr = s.find(a);
        if(itr != s.end()){
            puts("NO");
            return 0;
        }
        s.insert(a);
    }
    puts("YES");

    // cout << ans << endl;
//  printf("%.10f\n",ans);

    return 0;
}

Measured memory_bytes: 9600
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	N := nextInt()
	X := nextInt()
	Y := nextInt()
	g := make([][]int, N+1)
	for i := 0; i < N+1; i++ {
		g[i] = make([]int, N+1)
	}
	for i := 0; i < N+1; i++ {
		for j := 0; j < N+1; j++ {
			g[i][j] = abs(i - j)
		}
	}
	for i := 0; i < N+1-1; i++ {
		g[i][i+1] = 1
		g[i+1][i] = 1
	}
	g[X][Y] = 1
	g[Y][X] = 1
	// for k := 0; k < N+1; k++ {
	// 	for i := 0; i < N+1; i++ {
	// 		for j := 0; j < N+1; j++ {
	// 			g[i][j] = min(g[i][j], g[i][k]+g[k][j])
	// 		}
	// 	}
	// }
	lens := make([]int, 2001)
	for i := 1; i < N+1-1; i++ {
		for j := i + 1; j < N+1; j++ {
			length := g[i][j]
			length = min(length, g[i][X]+g[Y][j]+1)
			length = min(length, g[i][Y]+g[Y][j]+1)
			lens[length]++
		}
	}
	for i := 1; i < N; i++ {
		fmt.Println(lens[i])
	}
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 33920
<?php
$N = fgets(STDIN);
$S = fgets(STDIN);

$count = 0;
for ($i = 0; $i < $N; $i ++) {
    if ($i === 0) {
        $count ++;
        continue;
    }
    if (substr($S, $i - 1, 1) !== substr($S, $i, 1)) {
        $count ++;
    }
}
echo $count;


Measured memory_bytes: 3700
/****************************************************************************************************
                                        SUBMITTED BY-

                                               aish_07

****************************************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define ll long long
#define sl set<ll>
#define vs vector<string>
#define pb push_back
#define vl vector<ll>
#define vi vector<int>
#define PI  3.14159265
#define mod 998244353
int main()
{
    int n,m;
    cin>>n>>m;
    int a[m];
    for(int i=0;i<m;i++)
        cin>>a[i];

    sort(a,a+m);

    if(n>=m)
        cout<<"0\n";
    else
    {
        ll k=0;
        int b[m-1];
        for(int i=0;i<m-1;i++)
        {
            b[i]=a[i+1]-a[i];
        }
        sort(b,b+m-1);
        for(int i=0;i<m-n;i++)
            k+=b[i];
        cout<<k<<"\n";
    }
    return 0;
}


Measured memory_bytes: 4360
N = int(input())
A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
C = 0
c = 0
for i in range(N):
    c = sum(A1[:i + 1]) + sum(A2[i:])
    C = max(C, c)
print(C)    

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

int main() {
  int a;
  string n;
  cin>>a>>n;
  int red=0;
  int blue=0;
  
  for(int i=0;i<a;i++){
    if(n.at(i)=='R'){
      red++;
    }
    else{
      blue++;
    }
  }
  
  if(red>blue){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
import collections
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n=I()
As=(LI())
Bs=(LI())
ans=0
#print(As)
#print(Bs)
for i in range(n):
    ans+=min(As[n-i]+As[n-1-i],Bs[n-1-i])
    As[n-i-1]=max(As[n-i-1]-max(0,Bs[n-1-i]-As[n-i]),0)
    #print(As)
    #print(ans)
print(ans)

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

int main(){
    ll n;
    cin >> n;
    ll count = 0, a = 1;
    vector<string> s(n);
    rep(i,n){
        cin >> s[i];
    }
    rep(i,n){
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());
    s.push_back("a");
    for(int i = 1; i <= n; i++){
        if(s[i] != s[i-1]){
            if(a >= 2){
                count += a*(a-1)/2;
            }
            a = 0;
        }
        a++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>

using namespace std;
int main()
{
    int n;cin>>n;
    int ans=0;
    for(int i=1;i<=n;++i){
        if(i%2==0)continue;
        int cnt=0;
        for(int j=1;j<=i;++j){
            if(i%j==0)++cnt;
            if(cnt>8)break;
        }
        if(cnt==8)++ans;
    }
    
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int sand, time, ans;
  char str[32];
  
  fgets(str,sizeof(str),stdin);
  sscanf(str,"%d%d",&sand,&time);
  
  ans = sand - time;
  
  if(ans>0)
  {
    printf("%d",ans);
  }else
  {
    puts("0");
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void depot(int x)
{
     int y;

     while(0<1){
	  
	  if(scanf("%d", &y)==EOF) return;     
     
	  if(y==0){
	       printf("%d\n", x);
	       return;
	  }
	  
	  else depot(y);
     }
}

int main(void)
{
     depot(0);		

     return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main(){
    char a[4],b[4];
    int tedad=0;
    cin>>a;
    cin>>b;
    if(a[0]==b[0]){
        tedad++;
    }
    if(a[1]==b[1]){
        tedad++;
    }
    if(a[2]==b[2]){
        tedad++;
    }
    cout<<tedad;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>

#define FASTIO ios::sync_with_stdio(NULL); cin.tie(NULL);
#define show(x) cerr << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define vss vector  <string>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define PI  3.141592654
#define OO (ll)1e18
using namespace std;
void ONLINE__JUDGE();

pii swapii( pii pr ){ return { pr.S , pr.F }; }
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 200 + 9;

ll x , k; vpi a , b; vii v;

int main()
{
    FASTIO //ONLINE__JUDGE();

    cin >> x >> k; a.pb({1 , 2});
    for ( int i = 3; i <= x; ++i )
        a.pb({2 , i}) , b.pb({1 , i}) , v.pb(i);

    for ( int i = 0; i < SZ(v); ++i )
        for ( int j = i+1; j < SZ(v); ++j ) b.pb({ v[i] , v[j] });

    ll cnt = SZ(v); cnt *= (cnt-1); cnt /= 2; cnt += SZ(v);
    if ( cnt < k ) cout << -1;
    else
    {
        k = cnt-k;
        while ( k-- ) a.pb(b.back()) , b.pop_back();

        cout << SZ(a) << "\n";
        for ( auto i : a ) cout << i.F << " " << i.S << "\n";
    }
    return 0;
}



Measured memory_bytes: 512
def dfs(A, chk):
    if a[A[-1][0]][A[-1][1]] == ".":
        return
    elif A[-1] == [h, w]:
        if len(A) == cnt and chk == 0:
            print("Possible")
        else:
            print("Impossible")
        exit()

    for v in [[1, 0], [0, 1], [0, -1], [-1, 0]]:
        tmp = [A[-1][0] + v[0], A[-1][1] + v[1]]
        if tmp not in A:
            A.append(tmp)
            if v in [[0, -1], [-1, 0]]:
                dfs(A, chk + 1)
            else:
                dfs(A, chk)                
            A.pop()

h, w = map(int, input().split())
a = [["."]*w]
a.extend([list("." + input() + ".") for x in range(h)])
a.append(["."]*w)
cnt = 0
for i in range(1,h+1):
    cnt += a[i].count("#")
dfs([[1, 1]], 0)


Measured memory_bytes: 9252
/*
ID:dyx_6661
TASK:
LANG:
*/
#include<cstdio>
#include<cstring>
#include<cmath>
#include<queue>
#include<stack>
#include<algorithm>
#include<deque>
#include<set>
#include<map>
#include<vector>
#include<iostream>
using namespace std;
typedef long long int ll;
typedef double db;
typedef string str;
typedef pair<int,int> pa;
typedef vector<int> vec;

int n;
db a[105];

int main(){
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%lf",&a[i]);
	sort(a+1,a+1+n);
	db cnt=1.0*a[1];
	for(int i=2;i<=n;i++){
		cnt=(cnt+1.0*a[i])/2; 
	}
	printf("%lf",cnt);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define F first
#define S second
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
using ll = long long;
using pi = pair<int,int>;
const ll MOD=1e+9+7;
struct mint{
  ll x;
  mint(ll x=0):x(x%MOD){}
  mint& operator+=(const mint a){
    if((x+=a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x += MOD-a.x)>=MOD) x-=MOD;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=MOD;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a = pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }
  
  //for prime mod
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint a){
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

const int NMAX=3000010; // we can calculate nCk until n is equal to NMAX
mint fact[NMAX],infac[NMAX];
void Make_Fact(){
  fact[0]=fact[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    fact[i]=fact[i-1]*(mint)i;
  }
}
void Make_InvFact(){
  infac[0]=infac[1]=1;
  for(int i=2;i<=NMAX-1;++i){
    infac[i]=infac[i-1]/(mint)i;
  }
}
mint Comb(int n,int k){
  if(n<0||k<0||n-k<0) return 0;
  return fact[n]*infac[k]*infac[n-k];
}

int main()
{
  int x,y; cin >> x >> y;
  if(x > y) swap(x,y);
  int z = 2*x - y;
  Make_Fact();
  Make_InvFact();
  if(z < 0) {
    cout << 0 << "\n";
  }
  else {
    if(z % 3 == 0) {
      mint res = Comb(z/3 + z/3 + y - x, z/3);
      cout << res.x << "\n";
    }
    else {
      cout << 0 << "\n";
    }
  }
  
  return 0;
}


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

    long long a, b, k;
    cin >> a >> b >> k;

    if(k > a){
        b -= (k - a);
        if(b < 0){
            b = 0;
        }
        a = 0;
    }
    else{
        a -= k;
    }

    cout << a << ' ' << b << endl;

    return 0;
}

Measured memory_bytes: 256
N,A,B = map(int,input().split())

S = list(input())
counter = 0
oversea= 1
for i,s in enumerate(S):
    if(s == 'a'):
        if(counter < (A + B)):
            print("Yes")
            counter+=1
        else:
            print("No")
    elif(s == 'b'):
        if(counter < (A + B) and  oversea <= B):
            print("Yes")
            counter+=1
            oversea +=1
        else:
            print("No")
    else:
        print("No")

Measured memory_bytes: 4704
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 100000
using namespace std;

int main(){
  int n;  cin >> n;
  bool check = true;
  string before, now;
  map<string, int> mp;
  rep(i, 0, n){
    cin >> now;
    mp[now]++;
    if(mp[now]>1 || (now.front() != before.back() && i!=0)){
      check = false;
    }
    before = now;
  }
  if(check) cout << "Yes" << endl;
  else  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())
nei_list = [[] for i in range(n+1)]
for i in range(n - 1):
    a, b = map(int, input().split())
    nei_list[a].append(b)
    nei_list[b].append(a)
score = [0] * (n+1)
for i in range(q):
    p, x = map(int, input().split())
    score[p] += x
work_stack = [1]
visited = set()
while work_stack:
    i = work_stack.pop()
    visited.add(i)
    for j in nei_list[i]:
        if j not in visited:
            work_stack.append(j)
            score[j] += score[i]
print(*score[1:])


Measured memory_bytes: 63876
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  cin >> str;
  int i;
  int m,b;
  while(str!="-"){
    cin >> m;
    for(i=0;i<m;i++){
      cin >> b;
      str=str.substr(b,str.size()-b)+str.substr(0,b);
    }
    cout << str << endl;
    cin >> str;
  }
  
}



Measured memory_bytes: 3240
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int s[m];
	for( int i = 0; i < m; ++i ){
		s[i] = 0;
	}
	for( int i = 0; i < n; ++i ){
		int k; cin >> k;
		for( int j = 0; j < k; ++j ){
			int t; cin >> t;
			--t;
			++s[t];
		}
	}
	int cnt = 0;
	for( int i = 0; i < m; ++i ){
		if( s[i] == n ){
			++cnt;
		} 
	}
	cout << cnt << endl;
	return 0;
}

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

using namespace std;

int main()
{
  string dir;
  while(cin >> dir, dir != "#"){
    int mol = 0, den = 1;
    for(int i = dir.size()-1; i >= 0; i--){
      if(dir[i] == 'n'){
	if(i != dir.size()-5){
	  mol = mol*2 - 90;
	  den = den*2;
	} else {
	  mol = 0;
	  den = 1;
	}
      } else if(dir[i] == 'w'){
	if(i != dir.size()-4){
	  mol = mol*2 + 90;
	  den = den*2;
	} else {
	  mol = 90;
	  den = 1;
	}
      }
    }
    int gcd = __gcd(mol, den);
    mol /= gcd;
    den /= gcd;
    if(den == 1) cout << mol << endl;
    else cout << mol << "/" << den << endl;
  }
  return 0;
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
//さやかお姉ちゃんの写経コー
	int h , n ;
	cin >> h >> n ;
	vector<int> a(n) , b(n);
	rep(i,n) cin >> a[i] >> b[i];

	vector<vector<int>> dp(n+1,vector<int>(h+1,1e9+7));

	dp[0][0] = 0 ;
	rep(i,n){
		rep(j,h+1){
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			int next = min(j + a[i], h);
			dp[i][next] = min(dp[i][next],dp[i][j] + b[i] ) ;
		}
	}
	cout << dp.back().back() << endl;
}


Measured memory_bytes: 39424
import qualified Data.ByteString.Char8 as BS
import Data.Maybe
import Data.List

solve :: [Int] -> (Int, Int)
solve xs = let (a,b) = partition (< 3200) xs
               a' = length . nub $ map (`div` 400) a
            in (max 1 a', a'+ length b)

main :: IO ()
main = do
    _ <- getLine
    a <- map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
    let (mn,mx) = solve a
    print mn
    print mx


Measured memory_bytes: 508
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
#define _ << " " <<
#define all(X) (X).begin(), (X).end()
#define Pii pair<int, int>
#define Pll pair<ll, ll>
#define Tiii tuple<int, int, int>
#define Tlll tuple<ll, ll, ll>
#define PI 3.141592653589793

vector<int> Zalgorithm(string s) {
    int L = 0, R = 0, n = s.size();
    vector<int> z(n);
    for (int i = 1; i < n; i++) {
        if (i > R) {
            L = R = i;
            while (R < n && s[R - L] == s[R]) R++;
            z[i] = R - L;  R--;
        } else {
            int k = i - L;
            if (z[k] < R - i + 1) z[i] = z[k];
            else {
                L = i;
                while (R < n && s[R - L] == s[R]) R++;
                z[i] = R - L;  R--;
            }
        }
    }
    return z;
}

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

    vector<int> tmp(n, -1);
    vector<vector<int>> Z(n, tmp);
    for (int i = 0; i < n; i++) {
        vector<int> y = Zalgorithm(s.substr(i, n));
        for (int j = 1; j < y.size(); j++) {
            Z[i][i + j] = y[j];
        }
    }

    /*
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) cerr << Z[i][j] << " ";
        cerr << endl;
    }*/

    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (ans < Z[i][j] && j - i >= Z[i][j]) ans = Z[i][j];
        }
    }
    cout << ans << endl;    
}


Measured memory_bytes: 98176
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
	int weight;
	int i;
	int a[8];
	int cu;
	int cnt = 0;

	while (scanf("%d", &weight) != EOF){
		for (i = 0; i < 8; i++) a[i] = 0;
		cnt = 0;
		cu = 512;
		i = 0;
		while (weight != 0){
			while (cu > weight) cu /= 2;
			a[i++] = cu;
			weight -= cu;
			cnt++;
		}
		sort(a, a + cnt);
		printf("%d", a[0]);
		for (i = 1; i < cnt; i++){
			printf(" %d", a[i]);
		}
		printf("\n");
	}

	return (0);
}

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

int main()
{
    int N;
    cin >> N;
    for (int i = 1;; i++)
    {
        if (N < i * i)
        {
            cout << (i - 1) * (i - 1) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    char O[51],E[51],c[103];
    int i,j=0,l,x,max;
    scanf("%s%s",&O,&E);
       l=strlen(O);
       x=strlen(E);
       if(l>x)
          max=l;
       else
          max=x;
       for(i=0;i<=2*max;i=i+2)
       {
          c[i]=O[j];
          c[i+1]=E[j];
          j++;
       }
       printf("%s\n",c);
}

Measured memory_bytes: 128
/*
    AUTHOR:hruday pabbisetty
    NIT ROURKElA
*/
#include <bits/stdc++.h>
#include <tr1/unordered_map>
using namespace std;
using namespace std::tr1;
#define opt ios_base::sync_with_stdio(0)
#define lli long long int
#define ulli unsigned long long int
#define I int
#define S string
#define D double
#define rep(i,a,b) for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define in3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define out(n) printf("%lld\n",n)
#define inu(a) scanf("%lld",&a)
#define outu(a) printf("%llu",a)
#define ins(s) scanf("%s",&s)
#define outs(s) printf("%s",s)
#define mod 1000000007
#define inf 100000000000000
typedef long long       ll;
typedef pair<lli,lli>  plli;
typedef vector<lli>     vlli;
typedef vector<ulli>    vulli;
typedef vector<ll>      vll;
typedef vector<string>  vs;
typedef vector<plli>     vplli;
#define MM(a,x)  memset(a,x,sizeof(a));
#define ALL(x)   (x).begin(), (x).end()
#define P(x)       cerr<<"{"#x<<" = "<<(x)<<"}"<<endl;
#define P2(x,y)       cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<"}"<<endl;
#define P3(x,y,z)  cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<"}"<<endl;
#define P4(x,y,z,w)cerr<<"{"#x" = "<<(x)<<", "#y" = "<<(y)<<", "#z" = "<<(z)<<", "#w" = "<<(w)<<"}"<<endl;
#define PP(x,i)     cerr<<"{"#x"["<<i<<"] = "<<x[i]<<"}"<<endl;
#define TM(a,b)     cerr<<"{"#a" -> "#b": "<<1000*(b-a)/CLOCKS_PER_SEC<<"ms}\n";
#define UN(v)    sort(ALL(v)), v.resize(unique(ALL(v))-v.begin())
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sz() size()
#define nl cout<<"\n"
#define MX1 100005
#define MX2 1000005
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
lli dx[]={0,0,-1,1,-1,-1,1,1};
lli dy[]={1,-1,0,0,1,-1,-1,1};
lli power(lli a,lli b)
    {
    lli value;
    if(b==0)
        {
        return 1;
    }
    else if(b%2==0)
        {
        value=power(a,b/2)%mod;
        return(value*value)%mod;
    }
    else
        {
        value=power(a,b/2)%mod;
        return ((a*value)%mod*(value))%mod;
    }
}
int main()
{
      /*  #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        #endif*/
    opt;

    lli N,i;
    cin>>N;

    lli Q;
    cin>>Q;

    while(Q--)
    {
        lli a,b;
    cin>>a>>b;

        if(N==1)
        {
            cout<<min(a,b);
        }
        else
        {
            a--,b--;

            while(1)
            {
                if(a>b)
                {
                    a--;
                    a/=N;
                }

                if(a<b)
                {
                    b--;
                    b/=N;
                }

                if(a==b)
                {
                    cout<<a+1;
                    break;
                }
            }
        }
        cout<<'\n';
    }



    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main() {
    int n,m;
	cin >> n>> m;
    UnionFind tree(n);
    int p[n];
    fr(i,n){
      int t;
      cin >> t;
      p[i]=t-1;
    }
    int x,y;
    fr(i,m){
      cin >> x>>y;
      tree.unite(x-1,y-1);
    }
    int ans=0;
    fr(i,n){
      if(tree.same(i,p[i])==true)ans++;
    }
      cout << ans << endl;
}


Measured memory_bytes: 1024