akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

using namespace std;
using ll = long long;
using ull = unsigned long long;
#define out(S) cout<<(S)<<endl;
#define REP(i,b) for(size_t i=0;i<(b);i++)
#define rREP(i,b) for(size_t i=(b)-1;i>=0;i--)
#define FOR(i,a,b) for(size_t i=(a);i<(b);i++)
#define rFOR(i,a,b) for(size_t i=(b)-1;i>=0;i--)
#define Foreach(item,collection) for(auto item:collection)
#define mod(i) ((i) % (ll)(1e9 + 7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a * modpow((ll)b,(ll)(1e9 + 5))))

int main(){
	ll x;
	cin >> x;
	ll di = 11;
	ll ans = ceil((long double)x / di);
	if (ans * 11 - 5 >= x) { ans = ans * 2 - 1; }
	else ans *= 2;
	out(ans);
    return 0;
}



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

typedef long long ll;

void testcase() {
	ll n, d;
	cin >> n >> d;
	int ans = 0;
	for (ll x, y, i = 0; i < n; ++i) {
		cin >> x >> y;
		double t = sqrt((double) ((x * x) + (y * y)));
		if (t <= d)
			++ans;	
	}
	cout << ans;
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
	
    int tt = 1;
    // cin >> tt;
    while(tt--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
 
public class Main {
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    void solve() throws IOException {
    	String S = ns();
    	out.println(S.substring(0,4) + ' ' + S.substring(4,12));
    }
 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 8276
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <map>
const int MOD = 1e9+7;
using namespace std;

int ctoi(char c){
	return c - '0';
}

int coun[10][10];

int main(){
	int n;
	long long ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++){
		string s = to_string(i);
		coun[ctoi(s[0])][ctoi(s[s.length()-1])]++;
	}
	for (int i = 0; i <= 9; i++){
		for (int j = 0; j <= 9; j++){
			ans += coun[i][j]*coun[j][i];
		}
	}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n,s;cin>>n;
  int m=101,c;
  for(int i=0;i<n;++i){
    cin>>s;
    if(s%10!=0)m=min(m,s);
    c+=s;
  }
  if(m==101)m=0;
  if(c%10!=0)cout<<c;
  else{
    c-=m;
    if(c&10!=0)cout<<c;
    else cout<<0;
  }
}

Measured memory_bytes: 256
import bisect,collections,copy,itertools,math,numpy,string
def I(): return int(input())
def S(): return input()
def LI(): return list(map(int,input().split()))
def LS(): return list(input().split())
##################################################
N,M = LI()
A = LI()
kijun = sum(A)/(4*M)
count = 0
for x in A:
    if x>=kijun:
        count += 1
print('Yes' if M<=count else 'No')

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

int main()
{
    string s,t,temp;
    int i,j,k;
    cin>>s>>t;
    set<int> sett[2];
    for(i=0;i<s.size();i++)
    {
        sett[0].insert(s[i]);
        sett[1].insert(t[i]);
    }
    if(sett[1].size() != sett[0].size())
    {
        printf("No\n");
        return 0;
    }
    temp = s;
    int len = s.size();i=0;
    char ch ;
    while(temp != t && i<len)
    {
        ch = temp[len-1];
        temp = temp.substr(0,len-1);
        temp=ch+temp;
       // cout<<temp<<endl;
        i++;
    }
    if(i<len)
    {
        printf("Yes\n");
    }
    else {
        printf("No");
    }
    return 0;
}


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


int main(void) {
	long long ans = 0;
	long long x, remain;
	cin >> x;

	ans = std::max((long long)0,(long long)(x-11))/11;
	remain  = x - (ans*11);

	ans *= 2;

	while (remain > 0) {
		remain -= 6;
		ans++;
		if (remain <= 0) break;
		remain -= 5;
		ans++;
	}

	cout << ans << endl;

	return 0;
}


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

int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int M = min(A, B);
  int m = max(A+B-N, 0);
  cout << M << " " << m << endl;
  return 0;
}


Measured memory_bytes: 256
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/irange.hpp>
#include "bits/stdc++.h"

namespace adaptor = boost::adaptors;

int64_t n, k;
int64_t T[100000];

int64_t check(int64_t p) {
    int64_t i = 0;
    for (int64_t j = 0; j < k; j++) {
        int64_t sum = 0;
        while (sum + T[i] <= p) {
            sum += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int64_t search() {
    int64_t left = 0;
    int64_t right = 100000 * 10000;
    int64_t mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int64_t v = check(mid);
        if (v >= n)
            right = mid;
        else
            left = mid;
    }
    return right;
}

void solve() {
    std::cin >> n >> k;
    for (int64_t i = 0; i < n; i++) {
        std::cin >> T[i];
    }
    int64_t ans = search();
    std::cout << ans << std::endl;
}

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



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

ll N;
ll B[100];
ll ans=0;

int main(void){
    cin >> N;
    rep(i,N-1)cin >> B[i];
    ans += B[0];
    for(int i =0 ;i<N-1;i++){
        ans += min(B[i],B[i+1]);
    }
    ans += B[N-2];
    cout << ans << endl;


    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repr(i, n) for(int i=n; i>=0; i--)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define inf 1e18
#define vsort(v) sort(v.begin(), v.end())
#define vsortr(v) sort(v.begin(), v.end(), greater<ll>())
#define sz(x) x.size()
#define ceil(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T &a, T b){ if(a<b){ a=b; return true; } return false; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a){ a=b; return true; } return false; }
template<typename T> T gcd(T a, T b){ if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b){ return a*b/gcd(a, b); }
template<typename T> T vdebug(vector<T> v){ for(auto vv : v){ cout << vv << " "; } cout << endl; }
template<typename T> T adebug(T arr[], int n){ rep(i, n){ cout << arr[i] << " "; } cout << endl; }
void ans(bool b){ if(b) cout << "Yes" << endl; else cout << "No" << endl; }
void ans2(bool b){ if(b) cout << "YES" << endl; else cout << "NO" << endl; }
int keta(ll num){ int k=0; while(num>0){ num/=10; k++; } return k; }
int dx[] = {1, -1, 0, 0, 1, -1, 1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};


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

    string s, t;
    cin >> s >> t;
    int len = s.length();
    int table[26][26];
    rep(i, 26){
        rep(j, 26){
            table[i][j] = 0;
        }
    }

    rep(i, len){
        rep(j, 26){
            //if(table[s[i]-'a'][j] != 0 && j != t[i]-'a') table[s[i]-'a'][j] = 0;
            table[s[i]-'a'][t[i]-'a'] = 1;
        }
    }

    rep(i, 26){
        int cnt = 0;
        rep(j, 26){
            if(table[i][j]) cnt++;
        }
        if(cnt > 1){
            ans(false);
            return 0;
        }
    }
    rep(i, 26){
        int cnt=0;
        rep(j, 26){
            if(table[j][i]) cnt++;
        }
        if(cnt > 1){
            ans(false);
            return 0;
        }
    }
    ans(true);

    // cout << "  ";
    // rep(i, 26){
    //     cout << char('a'+i) << " ";
    // }
    // cout << endl;
    // rep(i, 26){
    //     cout << char('a'+i) << " ";
    //     rep(j, 26){
    //         cout << table[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    // rep(i, len){
    //     rep(j, 26){
    //         if(table[s[i]-'a'][j] != 0){
    //             s[i] = char(j+'a');
    //             break;
    //         }
    //     }
    // }

    //ans(s==t);


    return 0;
}

Measured memory_bytes: 916
fun main(){
    val n = readLine()!!.split(" ")[0].toInt()
    val c = readLine()!!.split(" ")[0].toCharArray().toMutableList()
    var red = 0
    for (i in 0 until n){
        if (c[i] == 'R') red++
    }
    var ans = 0
    for (i in 0 until red){
        if (c[i] == 'W') ans++
    }
    println(ans)
}

Measured memory_bytes: 46464
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}

int k;
string s;

int main(){
  cin >> k >> s;
  if(s.size() <= k) cout<< s <<endl;
  else cout<< s.substr(0,k)+"..." <<endl;
}


Measured memory_bytes: 3728
let cnt = ref 0

let insertion_sort (a : int array) n g =
  for i = g to n - 1 do
    let v = a.(i) in
    let j = ref (i - g) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+g) <- a.(!j);
      j := !j - g;
      incr cnt;
    done;
    a.(!j+g) <- v;
  done

let generate_g n =
  let rec doit i g acc =
    if g > n then acc
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: acc) in
  doit 1 1 []

let shell_sort (a : int array) n =
  cnt := 0;
  let g = generate_g n in
  List.iter (fun g -> insertion_sort a n g) g;
  g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  let g = shell_sort a n in
  Printf.printf "%d\n" (List.length g);
  match g with
  | [] -> assert false;
  | hd :: tl -> print_int hd; List.iter (fun x -> print_string " "; print_int x) tl;
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a

Measured memory_bytes: 12616
#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 = 1e9 + 7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  string K;  int D;
  cin >> K >> D;

  int L = K.size();
  
  vector<vector<vector<ll>>> dp(L+1, vector<vector<ll>>(D,vector<ll>(2, 0)));
  //dp[i][j][k] :  
  // 左からi桁目まで見て
  //桁和%D = j
  //k = 0: K未満が確定 1:o.w.
  dp[0][0][1]= 1;

  REP(i, L) REP(j, D) {
    REP(k, 10){
      (dp[i+1][(j+k)%D][0] += dp[i][j][0] ) %= MOD;
    }

    int d = K[i] - '0';
    REP(k, d){
      (dp[i+1][(j+k)%D][0] += dp[i][j][1]) %= MOD;
    }
    (dp[i+1][(j+d)%D][1] += dp[i][j][1] ) %= MOD;
  }

  // REP(i, L+1) REP(j, D) REP(k, 2){
  //   if(dp[i][j][k] == 0) continue;
  //   DUMP(i); DUMP(j); DUMP(k);
  //   DUMP(dp[i][j][k]);
  // } 

  //0を除くことに注意
  (dp[L][0][0] = dp[L][0][0] + MOD - 1) %= MOD;

  cout << (dp[L][0][0] + dp[L][0][1]) % MOD << endl;
}


Measured memory_bytes: 55296
def resolve():
    N = int(input())
    A = [int(input()) for _ in range(N)]
    maxA = max(A)
    countMax = A.count(maxA)
    if countMax > 1:
        [print(maxA) for _ in range(N)]
    else:
        next = -1
        maxIdx = A.index(maxA)
        if maxIdx == 0:
            next = max(A[1:])
        elif maxIdx == N - 1:
            next = max(A[:N - 1])
        else:
            next = max(A[0:maxIdx])
            next = max(next, max(A[maxIdx + 1:N]))
        for i in range(N):
            if not i == maxIdx:
                print(maxA)
            else:
                print(next)


resolve()


Measured memory_bytes: 14088
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
#define double long double
#define mod 1000000007
#define iP pair<int,int>
#define gcd(a,b) __gcd(a,b)
#define pb push_back
#define inf 1e15
#define mod1 998244353
#define pi 3.141592653589793238
#define lcm(a,b) a*b/__gcd(a,b)
#define sz(x) (int)x.size()
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define cmp complex<double>
int power(int x,int y){
    int res=1;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        x=(x*x)%mod;
        y/=2;
    }
    return res;
}
void precompute(){
}
void solve(int tc){
    int k;
    cin>>k;
    for(int i=0;i<k;i++)cout<<"ACL";
}
int32_t main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;cerr.tie(NULL);cout.precision(12);
    int t=1,ctr=0;
    // precompute();
    // cin>>t;
    while(t--){
        solve(ctr+1);
        ctr++;
    }
}

Measured memory_bytes: 3580
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

struct Combination {
    int a;
    int b;
    int c;
};

using namespace std;

vector<Combination> v_c; 

void recursive_comb(vector<int>& indexes, int s, int rest, std::function<void(vector<int> &)> f) {
	if (rest == 0) {
		f(indexes);
	} else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
	return;
}

void foreach_comb(int n, int k, std::function<void(vector<int> &)> f) {
	vector<int> indexes(k);
	recursive_comb(indexes, n - 1, k, f);
	return;
}

int main() {
	int n;
	cin >> n;
	
	vector<long long int> v_num(5, 0);
	for (int i = 0; i < n; ++i) {
		string str; cin >> str;
		if (str[0] == 'M') v_num[0]++;
		if (str[0] == 'A') v_num[1]++;
		if (str[0] == 'R') v_num[2]++;
		if (str[0] == 'C') v_num[3]++;
		if (str[0] == 'H') v_num[4]++;
	}

	v_c.reserve(10);
	foreach_comb(5, 3, [](vector<int>& indexes) {
		Combination c{ indexes[0], indexes[1], indexes[2] };
		v_c.push_back(c);
	});

	long long int score = 0;
	for (int i = 0; i < v_c.size(); i++) {
		score += (v_num[v_c[i].a] * v_num[v_c[i].b] * v_num[v_c[i].c] );
	}

	cout << score << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
static const int N = 1000;
 
void trace(int A[], int n){
  for ( int i = 1; i <= n; i++ ){
    if ( i >1 ) cout << " ";
    cout << A[i];
  }
  cout << endl;
}
 
main(){
  int n;
  int A[N+1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) cin >> A[i];
   
  trace(A, n);
  for ( int j = 2; j <= n; j++ ){
    int key = A[j];
    int i = j - 1;
    while( i > 0 && A[i] > key ){
      A[i+1] = A[i];
      i--;
    }
    A[i+1] = key;
 
    trace(A, n);
  }
}

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int check_text (string s, char x) ;
int main() {
    int a , t = 0 ;
    string text , smal;
    char x ;
    smal = "abc" ;
    cin >> text ;
    for(int i = 0 ; i < 3 ; i++){
        x = smal[i] ;
        t += check_text (text,x) ;
    }
    if ( t == 3 ) {
        cout << "Yes" ;
    }
    else {
        cout << "No" ;
    }
    return 0 ;
}

int check_text (string s, char x){
    for(int i = 0 ; i < 3 ; i++){
        if(s[i] == x){
            return 1;
        }
  }
        return 0;
}


Measured memory_bytes: 3620
//NAME-DEEPESH BHATT
//Institute-IIT Dhanbad
//MOTTO-THINK FIRST,CODE LATER

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1E9+7  ;
/*#define endl '\n'*/
#define pb push_back
#define mp make_pair

//Check for signed int overflow
// use __builtin_popcount(num) to calculate no.of setbits in num
//s.lower_bound() works in O(logn) whereas lower_bound(s.begin(),s.end(),x) works in O(n)

//Euclid's Algo
ll gcd(ll a,ll b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}
//Extended Euclid's Algo
ll gcd_ex(ll a,ll b,ll&x,ll&y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll g=gcd_ex(b,a%b,x1,y1);
    x=y1;
    y=x1-y1*(a/b);
    return g;
}
//Multiplicative Modulo Inv
ll multi_mod_inv(ll a,ll m){
    ll x,y;
    ll g=gcd_ex(a,m,x,y);
    if(g!=1){
        return -1;
    }
    x=(x%m+m)%m;
    return x;
}
//Mod division
ll mod_div(ll a,ll b,ll m){
    //(a/b)mod m?
    if(multi_mod_inv(b,m)!=-1){
        return (a%m*multi_mod_inv(b,m)%m)%m;
    }
    else{
        return -1;
    }
}
//lcm
ll lcm(ll a ,ll b)
{
    return a/gcd(a,b)*b;
}
//Binary Exponentiation
ll power(ll a,ll n){
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p)%MOD;
    if (n % 2)
        return (p * a)%MOD;
    else
        return p%MOD;
}
//Euler Totient Function
ll phi[1000001]={0};
void euler_totient(ll n){
    for(ll i=0;i<=n;i++){
        phi[i]=i;
    }
    phi[1]=1;
    for(ll i=2;i<=n;i++){
        if(i==phi[i]){
            phi[i]=i-1;//For a prime number phi(p)=p-1
            for(ll j=2*i;j<=n;j+=i){
                phi[j]=phi[j]*(i-1)/i;
            }
        }
    }
}
int32_t main()
{
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(nullptr);
    ll t=1;
    /*cin>>t;*/
    while(t--){
        ll n;
        cin>>n;
        ll count=0;
        bool flag=false;
        while(n--){
            ll a,b;
            cin>>a>>b;
            if(a==b){
                count++;
            }
            else{
                count=0;
            }
            if(count==3){
                flag=true;
            }
        }
        if(flag){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3652
S = input()
a = int(S[:2])
b = int(S[2:])

# YYMM
f1 = 1 <= b <= 12

# MMYY
f2 = 1 <= a <= 12

if f1 and f2:
    print('AMBIGUOUS')
elif f1:
    print('YYMM')
elif f2:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3060
#include <cstdio>
using namespace std;

int a, b, c, r = 0, d = 0;

int main(){
	while (scanf("%d,%d,%d", &a, &b, &c) != EOF) {
		if (a*a + b*b == c*c) {
			r++;
		}
		if (a == b) {
			d++;
		}
	}
	printf("%d\n%d\n", r, d);

	return 0;
}

Measured memory_bytes: 2640
r = 51
wc = [[15,2244],[10,1520],[12,1870],[5,850],[3,550],[2,380]]
dp = [0]*r
for w,c in wc:
	dp[w] = c
	for i in range(r - w):
		if dp[i] > 0 and (dp[i + w] == 0 or dp[i + w] > dp[i] + c):
			dp[i + w] = dp[i] + c

while 1:
	n = input()
	if n == 0: break
	print dp[n/100]

Measured memory_bytes: 4236
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <utility>
#include <random>
#include <chrono>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//const int mod = 1e9+7;
unordered_map<string, int> cnt;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    quickread();
    int n;
    cin >> n;
    string str;
    while(n --) {
        cin >> str;
        cnt[str] ++;
    }
    cout << "AC x " << cnt["AC"] << endl;
    cout << "WA x " << cnt["WA"] << endl;
    cout << "TLE x " << cnt["TLE"] << endl;
    cout << "RE x " << cnt["RE"] << endl;
    return 0;
}


Measured memory_bytes: 3664
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>
#include <deque>
using ll = long long;
using namespace std;

int main(){
    bool flag[26];
    for (int i = 0; i < 26; i++) {
        flag[i] = true;
    }
    char c;
    int n, m;
    string ans = "yes", s;
    cin >> s;
    m = s.size();
    for (int i = 0; i < m; i++) {
        c = s[i];
        n = c-'a';
        if(flag[n]) flag[n] = false;
        else{
            ans = "no";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
  int H, W;
  std::cin >> H >> W;

  std::vector<std::vector<int>> C(10, std::vector<int>(10));

  for (int i=0; i<10; i++) {
    for (int j=0; j<10; j++) {
      std::cin >> C[i][j];
    }
  }

  for (int k=0; k<10; k++) {
    for (int i=0; i<10; i++) {
      for (int j=0; j<10; j++) {
        C[i][j] = std::min(C[i][j], C[i][k] + C[k][j]);
      }
    }
  }

  int ans = 0;

  for (int y=0; y<H; y++) {
    for (int x=0; x<W; x++) {
      int a;
      std::cin >> a;
      if (a > -1) ans += C[a][1];
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	static int r;
	static int s;
	static int p;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] nkArr = sc.nextLine().split(" ");
		int n = Integer.parseInt(nkArr[0]);
		int k = Integer.parseInt(nkArr[1]);
		String[] rspArr = sc.nextLine().split(" ");
		r = Integer.parseInt(rspArr[0]);
		s = Integer.parseInt(rspArr[1]);
		p = Integer.parseInt(rspArr[2]);
		
		long ans = 0;
		
		String[] gameStrategyList = sc.nextLine().split("");
		
		sc.close();
		
		for(int i = 0; i < k; i++) {
			String beforeStrategy = gameStrategyList[i];
			ans += getPoint(beforeStrategy);
			for(int j = i+k; j < gameStrategyList.length; j=j+k) {
				if(gameStrategyList[j].equals(beforeStrategy)) {
					beforeStrategy = "";
				}else {
					beforeStrategy = gameStrategyList[j];
					ans += getPoint(beforeStrategy);
				}
			}
		}
		
		System.out.println(ans);
	}
	
	static int getPoint(String str) {
		switch(str) {
			case "r":
				return p;
			case "s":
				return r;
			case "p":
				return s;
			default:
				return 0;
		}
	}
	
}


Measured memory_bytes: 34364
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n,m,x;
  cin >> n >> m >> x;
  ll mae = 0;
  ll ato = 0;
  for(int i = 0;i < m;i++){
    ll in = 0;
    cin >> in;
    if(in <= x)mae++;
    else ato++;
  }
  cout << min(mae,ato) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int n, f;
char s[15];
void dfs(int x) {
	if (x == n) {
		printf("%s\n", s);
		return;
	}
	int t[10];
	char c;
	for (int i = 0; i < 10; i++)t[i] = 0;
	for (int i = 0; i < x; i++) {
		c = s[i];
		if (t[c - 'a'] == 0) {
			s[x] = c;
			dfs(x + 1);
		}
		t[c - 'a'] = 1;
	}
	f = 0;
	while (t[f])f++;
	s[x] = f + 'a';
	dfs(x + 1);
}
int main() {
	scanf("%d", &n);
	s[0] = 'a';
	s[n] = NULL;
	dfs(1);
}

Measured memory_bytes: 1408
/*#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
#define ll long long
#define N 500005
#define inf 1000000005
#define mod 1000000007
#define put putchar('\n')
#define F(i,a,b) for (int i=(a);i<=(b);i++)
#define D(i,a,b) for (int i=(a);i>=(b);i--)
#define go(i,t) for (int i=head[t];i;i=Next[i])
#define sqr(x) ((x)*(x))
#define re register
#define mp make_pair
#define fi first
#define se second
using namespace std;
inline int read(){char c=getchar();int tot=1;while ((c<'0'|| c>'9')&&c!='-') c=getchar();if (c=='-'){tot=-1;c=getchar();}
int sum=0;while (c>='0'&&c<='9'){sum=sum*10+c-'0';c=getchar();}return sum*tot;}
inline void wr(int x){if (x<0) {putchar('-');wr(-x);return;}if(x>=10)wr(x/10);putchar(x%10+'0');}
inline void wrn(int x){wr(x);put;}inline void wri(int x){wr(x);putchar(' ');}
inline void wrn(int x,int y){wri(x);wrn(y);}inline void wrn(int a,int b,int c){wri(a);wrn(b,c);}
int n,m,k,f[N][27],g[N][21],a[N],x,y;
char str[N];
void pre(){
	F(i,1,n+2){
		F(j,0,26) f[i][j]=n+2;
		F(j,0,20) g[i][j]=n+2;
	}
	D(i,n,1){
		f[i][a[i]]=i+1;
		F(j,a[i]+1,26) f[i][j]=f[f[i][j-1]][j-1];
		g[i][0]=f[i][26];
		F(j,1,20) g[i][j]=g[g[i][j-1]][j-1];
		F(j,0,25) if (f[i][j]==n+2) f[i][j]=f[g[i][0]][j];
	}
}
bool solve(int x,int y){
	D(i,20,0){
		if (g[x][i]==y+1) return 1;
		if (g[x][i]<y) x=g[x][i];
	}
	return 0;
}
signed main(){
	//freopen("fusion.in","r",stdin);
	//freopen("fusion.out","w",stdout);
	scanf("%s",str+1);
	n=strlen(str+1);
	F(i,1,n) a[i]=str[i]-'a';
	pre();
	m=read();
	F(i,1,m){
		x=read();y=read();
		if (solve(x,y)) puts("Yes");
		else puts("No");
	}
	return 0;
}

Measured memory_bytes: 96896
def match(s, t):
    res = 0
    for i, j in zip(s, t):
        res += (i == j)
    
    return res

s = input()
t = input()

lens = len(s)
lent = len(t)

maxmc = 0
for i in range(0, lens - lent + 1):
    maxmc = max(maxmc, match(t, s[i: i + lent]))

print(lent - maxmc)

Measured memory_bytes: 9120
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repeq(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define rep1eq(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using Int = long long;

const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int n;
    string s;
    cin >> n;
    cin >> s;

    if(n>=3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
    return 0;

}

Measured memory_bytes: 256
import sys
import itertools
N = int(input())
S = [sys.stdin.readline() for _ in range(N)]
caps = ['M', 'A', 'R', 'C', 'H']
a = [0] * 5
ans = 0
for s in S:
    if s[0] in caps:
        a[caps.index(s[0])] += 1
c = list(itertools.combinations((0, 1, 2, 3, 4), 3))
for i in range(len(c)):
    ans += a[c[i][0]] * a[c[i][1]] * a[c[i][2]]
print(ans)

Measured memory_bytes: 9904
N,Q = map(int, input().split())
parentNodes = [0] * (N+1) #i番目のノードの親番号
counter = [0] * (N+1)

for i in range(N-1):
	a, b = map(int, input().split())
	parentNodes[b] = a
 
for _ in range(Q):
	p,x = map(int, input().split())
	counter[p] += x
 
for i in range(1,N+1):
	counter[i] += counter[parentNodes[i]]
 
print(*counter[1:])

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

int main()
{
    int ans = 0;
    char S[3],T[3];
    cin >> S;
    cin >> T;
    for (int i; i < 3;i++)
    {
        if (S[i]== T[i]){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int n, r[1000],w[1000];
bool dp[1001][1001];

int main(){
  while(cin >> n,n){
    int sumr = 0, sumw = 0, id = 0;
    for(int i=0;i<n;i++){
      cin >> r[i] >> w[i];
      sumr += r[i]; sumw += w[i];
      if(r[id] < r[i])id = i;
    }

    if(sumr-r[id] >= r[id]){
      cout << sumr + sumw << endl;
      continue;
    }

    int lim = 2*r[id]-sumr;
    for(int i=1;i<=n;i++){
      for(int j=0;j<=lim;j++)dp[i][j] = false;
    }
    dp[0][0] = true;
    
    for(int i=0;i<n;i++){
      for(int j=0;j<=lim;j++){
	if(dp[i][j]){
	  dp[i+1][j] = true;
	  if(i!=id && j+w[i]<=lim)dp[i+1][j+w[i]] = true;
	}
      }
    }
    
    int tmp = 0;
    for(int i=0;i<=lim;i++){
      if(dp[n][i])tmp = i;
    }
    cout << sumr + sumw + lim - tmp << endl;
  }
}

Measured memory_bytes: 2144
#include<bits/stdc++.h>
using namespace std;
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T>
struct rbtree: tree<T,null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>{};
#define IN freopen("in.txt", "r", stdin);
#define endl '\n'
#define mp make_pair
#define pb push_back
#define lowb lower_bound
#define eb emplace_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define mem0(a) memset((a), 0, sizeof(a))
#define mem(a, b) memset((a), (b), sizeof(a))
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 0x3f3f3f3f;
const int N = 1e5+10;

VI g[N];
int deep[N], MaxDeep[N];

int ans = 0;
bool F = false;
int n, u, v;
int res[N];

void dfs(int son, int f, int depth){
    deep[son] = depth;
    if(son == u)res[son]++, F=1;
    if(g[son].size() == 1)MaxDeep[son] = depth;
    for(auto it : g[son]){
        if(it == f)continue;
        if(son == v)res[son]++, F=0;
        dfs(it, son, depth+1);
        if(res[it])res[son]++;
        MaxDeep[son] = max(MaxDeep[son], MaxDeep[it]);
    }
    if(res[son]){
        if(deep[u]-deep[son] < deep[son]-deep[v]){
            ans = max(ans, MaxDeep[son]-2);
        }
    }
}


int main(){
    IOS;
    //IN;
    cin>>n>>u>>v;
    for(int i = 1; i <= n-1; i++){
        int x, y; cin>>x>>y; g[x].eb(y), g[y].eb(x);
    }
    dfs(v, 0, 1);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 13312
#include <stdio.h>

int bit_table[10000];

void bit_init(void) {
	int i;
	for(i=0;i<10000;i++)bit_table[i]=0;
}

void bit_add(int pos,int num) {
	while(pos<=10000) {
		bit_table[pos-1]+=num;
		pos+=pos & (-pos);
	}
}

int bit_sum(int pos) {
	int result=0;
	while(pos>0) {
		result+=bit_table[pos-1];
		pos-=pos & (-pos);
	}
	return result;
}

int main(void) {
	int n,k,m;
	int i,pos;
	int all_nokori;
	int rest,kizyun;
	int k2;
	int left,right,mid;
	while(1) {
		scanf("%d%d%d",&n,&k,&m);
		if(n==0 && k==0 && m==0)break;
		bit_init();
		for(i=1;i<=n;i++)bit_add(i,1);
		pos=m;
		bit_add(pos,-1);
		while((all_nokori=bit_sum(n))>1) {
			kizyun=bit_sum(pos-1);
			rest=all_nokori-kizyun;
			k2=k;
			if(k2>all_nokori)k2=(k2-1)%all_nokori+1;
			if(rest<k2) {
				pos=1;
				rest=k2-rest;
				kizyun=0;
			} else rest=k2;
			left=pos;right=n;
			while(left<=right) {
				mid=(left+right)/2;
				if(bit_sum(mid)-kizyun>=rest)right=mid-1;
				else left=mid+1;
			}
			pos=right+1;
			bit_add(pos,-1);
		}
		left=1;right=n;
		while(left<=right) {
			mid=(left+right)/2;
			if(bit_sum(mid)>=1)right=mid-1;
			else left=mid+1;
		}
		printf("%d\n",right+1);
	}
	return 0;
}

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

using ll = long long;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	string S; cin >> S;
	ll ans = 0;
	stack<int> stk;
	stk.push(1);
	stack<int> opStack;
	for (char c : S) {
		if (c == '(') {
			stk.push(1);
			opStack.push(-1);
		} else if (c == ')') {
			if (stk.empty()) {
				stk.push(0);
			}
			// TODO: record it
			opStack.push(stk.top());
			stk.pop();
			if (stk.empty()) {
				stk.push(0);
			}
			ans += stk.top();
			stk.top()++;
		} else if (c == '-') {
			int lastOp = opStack.top(); opStack.pop();
			if (lastOp == -1) {
				stk.pop();
			} else {
				stk.top()--;
				ans -= stk.top();
				stk.push(lastOp);
			}
		} else assert(false);
		cout << ans << '\n';
	}

	return 0;
}



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

using namespace std;

int main() {
    int t; cin >> t;
    int a[4] = {0};
    while (t--) {
        string str; cin >> str;
        if (str == "AC") a[0] += 1;
        else if (str == "WA") a[1] += 1;
        else if (str == "TLE") a[2] += 1;
        else if (str == "RE") a[3] += 1; 
    }
    cout << "AC x " << a[0] << "\n";
    cout << "WA x " << a[1] << "\n";
    cout << "TLE x " << a[2] << "\n";
    cout << "RE x " << a[3] << "\n"; 
    return 0;
}

Measured memory_bytes: 3592
#include<iostream>
 #include<string>
using namespace std;
int main(){
 int n;
 cin>>n;
 long long int arr[n];
 long long int ans=0;
 for(int i=0;i<n;i++){
     cin>>arr[i];
     if(i!=0){
         if(arr[i]<arr[i-1]){
             
             ans=ans+arr[i-1]-arr[i];
             arr[i]=arr[i-1];
         }
     }
    
 }
 cout<<ans;
}

Measured memory_bytes: 5132
import numpy as np
def main():
    N,W = map(int,input().split())
    w,v = [],[]
    for _ in range(N):
        w_,v_ = map(int,input().split())
        w.append(w_)
        v.append(v_)

    dp = np.zeros((N+1,W+1),dtype=np.int64)
    for i in range(N):
        tmp = np.zeros(W+1,dtype=int)
        tmp[w[i]:] = dp[i][:-w[i]] + v[i]
        dp[i+1] = np.maximum(dp[i],tmp)

    print(dp[N][W])
main()

Measured memory_bytes: 106248
#include<iostream>
#include<cstdio>
#include<cmath> 
#include<algorithm>
using namespace std;
int N,K,h[100001],f[100001];
int main()
{
	int minimun,k;
	scanf("%d%d",&N,&K);
	for(int i=0;i<N;i++) scanf("%d",&h[i]);
	f[0]=0;f[1]=abs(h[1]-h[0]);
	for(int i=2;i<N;i++)
	{
		k=max(0,i-K);
		minimun=f[k]+abs(h[i]-h[k]);
		for(int j=k+1;j<i;j++)
		{
			minimun=min(minimun,f[j]+abs(h[i]-h[j]));
		}
		f[i]=minimun;
	}
	printf("%d",f[N-1]);
	return 0;
}


Measured memory_bytes: 1024
use proconio::input;

fn main() {
	input!(s: String);

	let mut v: Vec<char> = s.chars().collect();
	let length = v.len();

	if length == 1 {
		println!("{}", s);
		return;
	}
	for i in 0.. v.len()-1 {
		v.insert(i*2+1, ' ');
	}
	//println!("{:?}", v);

	let mut sum = 0;
	for bit in 0..2usize.pow(length as u32 -1) {
		for j in 0..length-1 {
			let d = bit >> j & 1;
			if d == 1 {
				v[j*2+1] = '+';
			}
			else {
				v[j*2+1] = ' ';
			}
		}
		//println!("{:?}", v);

		let mut num = 0;
		let mut tmp = vec![];
		for k in 0..v.len() {
			if v[k] == ' ' {
				continue;
			}
			if v[k] == '+' {
				tmp.push(num);
				num = 0;
			}
			else {
				num = (num * 10) + v[k] as usize - '0' as usize;
			}
		}
		tmp.push(num);

		//println!("{:?}", tmp);

		for s in 0..tmp.len() {
			sum += tmp[s];
		}
	}
	println!("{}", sum);
}



Measured memory_bytes: 2224
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  rep(i,N) cin >> a[i];
  sort(a.begin(),a.end());
  int ans = a[(int)a.size()-1] - a[0];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <utility>
#include <functional>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_map>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const int MOD = 1000000007;
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; }

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    for(auto &a : A) cin >> a;
    int q;
    cin >> q;
    rep(i, q){
        int b,e;
        cin >> b >> e;
        reverse(A.begin()+b, A.begin()+e);
    }
    rep(i, n){
        cout << A[i];
        if(i != n-1) cout << " ";
    }
    cout << "\n";

    return 0;
}


Measured memory_bytes: 3100
#include<bits/stdc++.h>
//#include<iostream>
//#include<cstdio>
//#include<cstring>
//#include<cstdlib>
//#include<cmath>
//#include<algorithm>
//#include<vector>
//#include<queue>
//#include<stack>
//#include<map>
//#include<set>
using namespace std;
#define SC scanf
#define PR printf
#define pb push_back
#define mp make_pair
#define SZ(v) ((int)(v).size())
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define db double
#define ldb long double
#define uint unsigned
#define ll long long
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef pair<pii,pii> ppp;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef map<int,int> mii;
const int INF=0x3f3f3f3f;
const ll LL_INF=0x3f3f3f3f3f3f3f3f;
const int xx[4]={1,-1,0,0};
const int yy[4]={0,0,1,-1};
int inline in(){
	int x=0,c;
	for(;(uint)((c=getchar())-'0')>=10;){
		if(c=='-')return -in();
		if(!~c)throw ~0;
	}
	do{
		x=(x<<3)+(x<<1)+(c-'0');
	}while((uint)((c=getchar())-'0')<10);
	return x;
}
ll dp[100005][13];
int main(){
    cin.sync_with_stdio(false);cin.tie(0);
    const ll mod=1e9+7;
	string s;
	cin>>s;
	dp[0][0]=1;
	rep(i,SZ(s))rep(j,13){
		if(s[i]=='?'){
			rep(k,10){
				dp[i+1][(j*10+k)%13]+=dp[i][j];
				dp[i+1][(j*10+k)%13]%=mod;
			}
		}else{
			int d=s[i]-'0';
			dp[i+1][(j*10+d)%13]+=dp[i][j];
			dp[i+1][(j*10+d)%13]%=mod;
		}
	}
	cout<<dp[SZ(s)][5]<<endl;
	return 0;
}

Measured memory_bytes: 10704
import sys
input = lambda: sys.stdin.readline().rstrip()

#MOD
P = 10**9 + 7
N = 200001 #使う最大値+1以上にする、値に注意3*10^5とかにしとくと安心
inv = [0] + [1] # 1/x
finv = [1] + [1] # 1/x!
fac = [1] + [1] # x!
for i in range(2, N):
  inv += [inv[P % i] * (P - int(P / i)) % P]
  fac += [(fac[i-1] * i) % P]
  finv += [(finv[i-1] * inv[i]) % P]

def comb(a, b): return (fac[a] * ((finv[b] * finv[a-b]) % P)) %P

#全方位木dp
#-------------------------------------------------------------------
#扱うクラス
class T:
    num = 1
    child = 0

    def __init__(self, a, b):
        self.num = a
        self.child = b

#零元
zero = T(1, 0)
#一個上に遷移した時の変化
def step(x):
    return T(x.num, x.child+1)
#マージ
def merge(x, y):
    return T((x.num*y.num*comb(x.child+y.child, x.child))%P, x.child+y.child)

G = [[] for _ in range(N)]
down_data = [zero] * N
dat = [zero] * N
rev_data = [zero] * N

class p:
    num = -1
    parent = -1

    def __init__(self, x, y):
        self.num = x
        self.parent = y
node_list = []
def makeNodeList(root):
    #dfsでの探索順の作成
    stack = []
    stack.append(p(root, -1))
    while len(stack) != 0:
        now = stack.pop()
        node_list.append(now)
        for to in G[now.num]:
            if to == now.parent: continue
            stack.append(p(to, now.num))
    node_list.reverse()

def dfs(root):
    for now in node_list:
        for to in G[now.num]:
            if to == now.parent: continue
            down_data[now.num] = merge(down_data[now.num], step(down_data[to]))

def dfs_rev(root):
    for now in node_list:
        #累積
        rev = rev_data[now.num]
        left = []
        right = []
        cnt = 0
        for to in G[now.num]:
            if to==now.parent: continue
            if len(left)==0: left.append(step(down_data[to]))
            else: left.append(merge(left[cnt-1], step(down_data[to])))
            cnt += 1
        cnt = 0
        for to in reversed(G[now.num]):
            if to==now.parent: continue
            if len(right)==0: right.append(step(down_data[to]))
            else: right.append(merge(right[cnt-1], step(down_data[to])))
            cnt += 1
        dat[now.num] = merge(rev, down_data[now.num])
        cnt = 0
        for to in G[now.num]:
            if to==now.parent: continue
            x = zero if cnt==0 else left[cnt-1]
            y = zero if cnt==len(right)-1 else right[len(right)-2-cnt]
            rev_data[to] = step(merge(rev, merge(x, y)))
            cnt += 1

def calc(data_num):
    root = -1
    for i in range(1, data_num+1):
        if len(G[i]) == 1:
            root = i
            break
    makeNodeList(root)
    dfs(root)
    node_list.reverse()
    dfs_rev(root)
#-------------------------------------------------------------------
def main():
    n = int(input())
    for i in range(n-1):
        a, b = map(int, input().split())
        G[a].append(b)
        G[b].append(a)
    calc(n)

    for i in range(1, n+1): print(dat[i].num)

if __name__ == "__main__": main()


Measured memory_bytes: 222904
#include<bits/stdc++.h>
using namespace std;
#define ma 100010
int n,m,c;
int oya[ma],fukasa[ma];
int p[ma],x[ma],y[ma];
int find(int i){
  if(oya[i]==i){
    return i;
  }else{
    return oya[i]=find(oya[i]);
  }
}
void unite(int i,int j){
  i=find(i);
  j=find(j);
  if(i==j) return;
  if(fukasa[i]<fukasa[j]){
    oya[i]=j;
  }else{
    oya[j]=i;
    if(fukasa[i]==fukasa[j]) fukasa[i]++;
  }
}
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>p[i];
    oya[p[i]]=p[i];
  }
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    unite(x[i],y[i]);
  }
  for(int i=1;i<=n;i++){
    if(find(i)==find(p[i])) c++;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int l[200200], r[200200], rose[200200];
int main()
{
	int n,i,j,k,x,y,ans,curr,temp;
	string a;
	cin >> a;
	n = a.length();
	int cnt = 0;
	l[0] = r[0] = 1;
	for(i=0;i<n;i++)
	{
		if(a[i] == 'R')
		{
			if(l[cnt] > 0)
			{
				cnt++;
			}
			r[cnt]++;
		}
		else
		{
			l[cnt]++;
		}
	}
	int last = 0;
	for(i=1;i<=cnt;i++)
	{
		int sum = l[i] + r[i];
		int jisoo = r[i] / 2 + l[i] / 2;
		if(r[i] % 2 == 1)
			jisoo++;
		rose[last+r[i]] = jisoo;
		rose[last+r[i]+1] = sum - jisoo;
		last += sum;
	}
	for(i=1;i<=n;i++)
	{
		printf("%d ",rose[i]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int V,E,G[15][15],dp[1<<15][15];
const int INF = 1000000;

int solve() {
  for (int s=(1<<V)-1;s>=0;--s) {
    for (int t=0;t<V;++t) {
      dp[s][t] = INF;
    }
  }
  dp[(1<<V)-1][0] = 0;
  for (int s=(1<<V)-2;s>=0;--s) {
    for (int t=0;t<V;++t) {
      for (int u=0;u<V;++u) {
        if (!(s>>u&1)) {
          dp[s][t] = min(dp[s][t],dp[s|(1<<u)][u]+G[t][u]);
        }
      }
    }
  }
  return (dp[0][0] != INF)?dp[0][0]:-1;
}

int main() {
  for (int i=0;i<15;++i) {
    for (int j=0;j<15;++j) {
      G[i][j] = INF;
    }
  }
  cin>>V>>E;
  for (int i=0;i<E;++i) {
    int s,t,d;
    cin>>s>>t>>d;
    G[s][t] = d;
  }
  cout<<solve()<<endl;
  return 0;
}


Measured memory_bytes: 5016
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

int main(void) {
    int N;
    cin >> N;
    cout << ((N + 1) / 2) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;

const int MAXV = 2005;
const int MAXE = 505 * 505;
const int INF = 1<<29;

struct BiparateMatching {
    int N, M, E, match[MAXV+1], dist[MAXV+1];
    int last[MAXE], prev[MAXE], to[MAXE];
    BiparateMatching(int n, int m) : N(n), M(m), E(0) {
        memset(last, -1, sizeof(last));
    }
    void add_edge(int x, int y) { // x \in [0, N), y \in [0, M)
        to[E] = y + N; prev[E] = last[x]; last[x] = E; E++;
    }
    bool bfs() {
        queue<int> q;
        for (int i=0; i<N; ++i) {
            if (match[i] == -1) {
                q.push(i); dist[i] = 0;
            } else dist[i] = INF;
        }

        bool ret = false;
        while(!q.empty()) {
            int v = q.front(); q.pop();
            for (int e = last[v]; e != -1; e = prev[e]) {
                if (match[to[e]] == -1) ret = true;
                else if (dist[match[to[e]]] == INF) {
                    dist[match[to[e]]] = dist[v] + 1;
                    q.push(match[to[e]]);
                }
            }
        }
        return ret;
    }
    bool dfs(int v) {
        for (int e = last[v]; e != -1; e = prev[e]) {
            bool update = false;
            if (match[to[e]] == -1) {
                match[to[e]] = v; match[v] = to[e];
                update = true;
            } else if (dist[match[to[e]]] == dist[v] + 1) {
                if (dfs(match[to[e]])) {
                    match[to[e]] = v; match[v] = to[e];
                    update = true;
                }
            }
            if (update) return true;
        }
        dist[v] = INF;
        return false;
    }
    int matching() {
        int ret = 0;
        memset(match, -1, sizeof(match));
        while(bfs()) {
            for (int i=0; i<N; ++i)
                if (match[i] == -1 && dfs(i)) ret++;
        }
        return ret;
    }
};

int gcd(int x, int y) {
    if (y == 0) return x;
    return gcd(y, x%y);
}

int b[501], r[501];
int main() {
    int m,n;
    while(scanf("%d %d", &m, &n), m|n) {
        BiparateMatching bm(m, n);
        for (int i=0; i<m; ++i) scanf("%d", &b[i]);
        for (int i=0; i<n; ++i) scanf("%d", &r[i]);
        for (int i=0; i<m; ++i) {
            for (int j=0; j<n; ++j)
                if (gcd(b[i], r[j]) > 1) bm.add_edge(i, j);
        }
        printf("%d\n", bm.matching());
    }
}

Measured memory_bytes: 2972
import sys

N, Y = list(map(int, input().split()))

nm = Y // 10000

for y in range(N + 1):
    for z in range(N - y + 1):
        temp = Y - 5000*y - 1000*z
        if temp//10000 == N - y - z and temp%10000 == 0:
            print(temp//10000, y, z)
            sys.exit()
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
c = input()

az = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(len(az)) :
    if az[i] == c :
        print(az[i+1])


Measured memory_bytes: 2940