akhauriyash/Code-Regression huggingface dataset:
def main():
    N, A, B = map(int, input().split())
    ans = 0
    for i in range(N+1):
        tw = str(i)
        tn = 0
        for j in range(len(tw)):
            tn += int(tw[j])
        if A <= tn <= B:
            ans += i
    print(ans)
main()

Measured memory_bytes: 9172
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
#define forn(i,n) for(ll i=0;i < ll (n); i++)
vector<ll> graph[200003];
ll vis[200003];

void bfs(ll x, ll &ans)
{
    queue<ll>q;
    q.push(x);
    ll tem=0;
    vis[x]=1;
    while(!q.empty())
    {
        ll u=q.front(); q.pop();
        tem++;
        forn(i,graph[u].size())
        {
            ll v=graph[u][i];
            if(vis[v]==-1) q.push(v), vis[v]=1;
        }
    }
    //cout<<tem<<endl;
    ans=max(tem,ans);
    return;
}

int main()
{
    ll n,m,k,l;
    cin>>n>>m;
    ll ans=-1;
    forn(i,m)
    {
        cin>>k>>l;
        graph[k].push_back(l);
        graph[l].push_back(k);
    }
    forn(i,n) vis[i+1]=-1;
    forn(i,n)
    {
        if(vis[i+1]!=-1) continue;
        bfs(i+1, ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 18740
// Try AtCoder
// author: Leonardone @ NEETSDKASU

fn main() {
    let mut stdin = String::new();
    std::io::Read::read_to_string(
        &mut std::io::stdin(),
        &mut stdin).unwrap();
    let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
        ($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut vs = vec![];
    for _ in 0 .. n {
        vs.push(get!());
    }
    
    for i in 1 .. vs.len() {
        let i = (vs.len()-1) - i;
        let d = vs[i]-vs[i+1];
        if d > 1 {
            println!("No");
            return;
        } else if d > 0 {
            vs[i] -= 1;
        }
    }
    println!("Yes");
}

Measured memory_bytes: 8444
n, m = map(int, input().split())
num = [int(i) for i in input().split()]
num = sorted(num, reverse=True)
sum_num = sum(num)
for i in range(m):
    if num[i] < sum_num / (4 * m):
        print("No")
        break
else:
    print("Yes")



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

int main(){
  long long x,k,d; 
  cin >> x >> k >> d;
  if(x < 0)
    x = -x;
  long long ans = x%d;
  if(x/d < k){
    if((k-x/d)%2 == 1)
      ans -= d;
  }
  else{
    ans = x-k*d;
  }
 if(ans >= 0)
  cout << ans << endl;
 else{
  cout << -ans << endl;
  }
}

Measured memory_bytes: 3636
public class Main {
  public static void main(String[] args) {
    String S = new java.util.Scanner(System.in).nextLine();
    switch (S) {
      case "SSS":
        System.out.println("0");
        break;
      case "SSR":
      case "SRS":
      case "RSS":
      case "RSR":
        System.out.println("1");
        break;
      case "SRR":
      case "RRS":
        System.out.println("2");
        break;
      case "RRR":
        System.out.println("3");
    }
  }
}


Measured memory_bytes: 35356
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 1000000007;

// ----------------------DEBUG TEMPLATE--------------------------
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
	cerr << "[" << #x << "] = ["; \
	_print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------



int bu(vi &arr,int n,int k){
	int dp[n+2][k+2];
	memset(dp,0,sizeof(dp));
	for(int i =0;i <=n;i++){
		dp[i][0]=1;
	}
	for(int i =1;i <=n;i++){
		
		for(int j =1;j<=k;j++){
			if(i==1){
				if(j<=arr[i]){
					dp[i][j]=1;
				}
				else{
					dp[i][j]=0;
				}
				continue;
			}
			if(j-arr[i]-1>=0){
				dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-arr[i]-1] + mod)%mod;
			}
			else{
				dp[i][j] = (dp[i][j-1] + dp[i-1][j])%mod ;
			}
			// for(int m=0; m<=arr[i] && m<=j;m++){
			// 	dp[i][j] += dp[i-1][j-m];
			// }
		}
	}
	// for(int i =k;i>=0;i--){
	// 	if(dp[n][i] != 0){
	// 		return dp[n][i];
	// 	}
	// }
	// fo(i,n+1){
	// 	fo(j,k+1){
	// 		cout<<dp[i][j]<<" ";
	// 	}
	// 	cout<<endl;
	// }
	return dp[n][k];


}



void solve(){
	int n,k;
	cin>>n>>k;
	vi arr(n+1);
	Fo(i,1,n+1) cin>>arr[i];
	cout<<bu(arr,n,k)<<endl;
	
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t=1;
	// cin>>t;
	while(t--){
		solve();
	}


}

Measured memory_bytes: 83192
#include <bits/stdc++.h>
using namespace std;
using ll = long long; // ll は long long　と同じとする。
int main () {
    int N;
    cin >> N;
    vector <int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d.at(i);
    }
    sort(d.begin() , d.end());
    int T = N / 2;
    cout << d.at(T) - d.at(T - 1) << endl;
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int n,x; cin>>n>>x;
    vector <int> l(n);rep(i,n)cin>>l[i];
    int point = 0; int ans = 0;
    for(int i = 0; i<n&&point <= x; ++i){
        ++ans;
        point += l[i];
    }
    if(point <=x)++ans;
    cout<<ans<<endl;return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <stack>
#include <vector>
#include <utility>
#include <list>
#include <algorithm>
using namespace std;

#define N 1046257

class Hash
{
  private:
    string *a;

    unsigned long long getChar(char ch)
    {
        switch (ch)
        {
        case 'A':
            return 1;
        case 'C':
            return 2;
        case 'G':
            return 3;
        case 'T':
            return 4;
        default:
            return 0;
        }
    }

    unsigned long long getKey(string str)
    {
        unsigned long long x = 0;
        for (unsigned int i = 0; i < str.length(); i++)
        {
            x += getChar(str[i]);
            x *= 5;
        }
        return x;
    }

    int h1(int key)
    {
        return key % N;
    }

    int h2(int key)
    {
        return 1 + (key % (N - 1));
    }

  public:
    Hash()
    {
        a = new string[N];
        for (int i = 0; i < N; i++)
            a[i] = "";
    }

    void insert(string str)
    {
        unsigned long long key = getKey(str);
        unsigned long long h, i;
        for (i = 0;; i++)
        {
            h = (h1(key) + i * h2(key)) % N;
            if (a[h] == str)
            {
                return;
            }
            else if (a[h] == "")
            {
                a[h] = str;
                return;
            }
        }
    }

    bool find(string str)
    {
        unsigned long long key = getKey(str);
        unsigned long long h, i;
        for (i = 0;; i++)
        {
            h = (h1(key) + i * h2(key)) % N;
            if (a[h] == str)
                return true;
            else if (a[h] == "")
                return false;
        }
    }
};

int main()
{
    Hash H;
    int n;
    cin >> n;
    string str;
    for (int i = 0; i < n; i++)
    {
        //cout << i << "\n";
        cin >> str;
        if (str[0] == 'i')
        {
            cin >> str;
            H.insert(str);
        }
        else if (str[0] == 'f')
        {
            cin >> str;
            if (H.find(str))
                cout << "yes\n";
            else
                cout << "no\n";
        }
    }
}


Measured memory_bytes: 27780
#include<stdio.h>
#define MAX 500001 /*500000*/
#define INF 10000000

void merge(int A[],int left,int mid,int right,int *cnt){
int i,j,n1,n2;
int L[MAX];
int R[MAX];
int k;
n1=mid-left;
n2=right-mid;

for(i=0;i<n1;i++)L[i]=A[left+i];
for(i=0;i<n2;i++)R[i]=A[mid+i];

L[n1]=2147483647;
R[n2]=2147483647;

i=0;
j=0;

for(k=left;k<right;k++){
  if(L[i]<=R[j]){(*cnt)++;
    A[k]=L[i];
    i++;
  }
  else{(*cnt)++;
    A[k]=R[j];
    j++;
  }
}
}


void mergesort(int A[],int left,int right,int *cnt){
int mid;
 if(left+1 < right){
   mid=(left+right)/2;
   mergesort(A,left,mid,cnt);
   mergesort(A,mid,right,cnt);
   merge(A,left,mid,right,cnt);
 }
}



int main(){
int n,i;
int A[MAX];
int cnt=0;

scanf("%d",&n);
for(i=0;i<n;i++)scanf("%d",&A[i]);

mergesort(A,0,n,&cnt);

for(i=0;i<n-1;i++)printf("%d ",A[i]);
printf("%d\n",A[n-1]);

printf("%d\n",cnt);

return 0;
}



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

int main() {
	int N;
	cin >> N;
  
	for (int i = 0; i < N; i++){
		char c; 
		cin >> c;
		if ( c == 'Y') {
			cout << "Four" << endl;
			return 0;
		} 
	}
	cout << "Three" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
using namespace std;

int main() {
	
	int r, c;
	int a[101][101];

	cin >> r >> c;

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			cin >> a[i][j];
		}
	}
	int sum = 0;
	for (int i = 0; i < r; i++) {
		sum = 0;
		for (int j = 0; j < c; j++) {
			sum += a[i][j];
		}
		a[i][c] = sum;
	}
	for (int j = 0; j < c + 1; j++) {
		sum = 0;
		for (int i = 0; i < r; i++) {
			sum += a[i][j];
		}
		a[r][j] = sum;
	}

	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			printf("%d", a[i][j]);
			if (j != c)printf(" ");
		}
		printf("\n");
	}

	//system("pause");
	return 0;
}


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

int main()
{
	std::string s;
	while( std::cin >> s )
	{
		std::string::size_type i;
		for( i = 0; i < s.size(); ++i )
		{
			if( s[i] != '@' )
				std::cout << s[i];
			else
			{
				++i;
				int rep = s[i] - '0';
				++i;
				for( int j = 0; j != rep; ++j )
					std::cout << s[i];
			}
		}

		std::cout << std::endl;
	}

	return 0;
}

Measured memory_bytes: 1172
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author CodeMonk
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int length = in.nextInt();
            String s1 = in.next();
            String s2 = in.next();
            long x = 3, y = 6;
            int mod = 1000000007;
            int prev = s1.charAt(0) == s2.charAt(0) ? 0 : 1;
            long ans = s1.charAt(0) == s2.charAt(0) ? x : y;
            for (int i = 1; i < length; i++) {
                if (s1.charAt(i - 1) == s1.charAt(i) && s2.charAt(i - 1) == s2.charAt(i)) {

                    continue;
                }
                int curr = s1.charAt(i) == s2.charAt(i) ? 0 : 1;
                if (prev == 0 && curr == 0) {
                    ans = (ans % mod * 2) % mod;
                } else if (prev == 1 && curr == 0) {
                    ans = (ans % mod * 1) % mod;
                } else if (prev == 0 && curr == 1) {
                    ans = (ans % mod * 2) % mod;
                } else if (prev == 1 && curr == 1) {
                    ans = (ans % mod * 3) % mod;
                }
                prev = curr;
            }
            out.println(ans);
        }

    }
}



Measured memory_bytes: 23764
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
#include<type_traits>
#include<numeric>
#include<limits>
#include<iomanip>
#include<set>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;

//define
#define INF 100000000
#define NUM 1000000007


int main() {
	int n;
	int cnty,ans=0;
	cin >> n;

	for (int i = 1; i <= n; i += 2) {
		cnty = 0;
		for (int j = 1; j < sqrt(i); j++) {
			if (i%j == 0 && j!=sqrt(i)){
				cnty += 2;
			}else if (i%j == 0 && j == sqrt(i)) {
				cnty++;
			}
		}

		if (cnty == 8) {
			ans++;
		}
	}

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


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

int main(){
  int n, k;
  cin >> n >> k;
  int a[15];
  REP(i, n) cin >> a[i];
  ll res = 1e11;
  REP(i, 1<<n){
    ll tmpres = 0;
    bitset<15> target(i);
    if(target.count()!=k) continue;
    int required = 0;
    REP(j, n) {
      if(target[j]) tmpres += max(0, required-a[j]+1);
      chmax(required, max(a[j], required+target[j]));
    }
    chmin(res, tmpres);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3604
#include <stdio.h>

int main(void)
{
	int h, w, H, W;
	while(1)
	{
		scanf("%d %d", &H, &W);
		if(H == 0 && W == 0)
		{
			break;
		}else {
			for(h = 0; h < H; h++)
			{
				for(w = 0; w < W; w++)
				{
					printf("%c",'#');
				}
				printf("\n");
			}
		}
		putchar('\n');
	}
		return 0;
}

Measured memory_bytes: 576
/*
title:C - Linear Approximation

url:https://abc102.contest.atcoder.jp/tasks/arc100_a

1.A_i - i　をしておくことで、関数を単純にする
2.グラフを考えればわかるが、真ん中あたりでさいしょうになる。
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int n;
    cin >> n;
    int data[n];
    REP(i, n)
    {
        cin >> data[i];
        data[i] -= i + 1;
    }
    sort(data, data + n);
    int b = data[n / 2];
    ll res = 0;
    for (int i = 0; i < n; i++)
    {
        res += abs(data[i] - b);
    }
    cout << res << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll, ll> P;
using VP = vector<P>;
using VVP = vector<VP>;
using VI = vector<ll>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
const int inf = 1e9 + 7;
const ll INF = 1LL << 61;
const ll 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() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int i, j;
    VI v(10101010,0);
    ll m = 10101010;
    for(i=1;i<m;i++){
        for(j=1;i*j<m;j++){
            v[i*j]++;
        }
    }
    ll n;
    cin>>n;
    ll ans = 0;
    for(i=1;i<=n;i++) ans += v[i] * i;
    cout<<ans<<endl;
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;

const int N = 1e5 + 10, INF = 0x3f3f3f3f , MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

int f[N][15];
int p[N][15];
int temp[N];

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
    ios_base::sync_with_stdio(0);
    int n;cin>>n;
    for(int i = 0;i < n;i++) {
        for(int j = 0;j < 10;j++) {
            cin>>f[i][j];
        }
    }
    for(int i = 0;i < n;i++) {
        for(int j = 0;j <= 10;j++) {
            cin>>p[i][j];
        }
    }
    ll res = -INF;
    for(int i = 1;i < (1<<10);i++) {
        memset(temp,0,sizeof temp);
        for(int j = 0;j < n;j++) {
            for(int k = 0;k < 10;k++) {
                if(f[j][9-k] & ((i>>k)&1)) {
                    temp[j]++;
                }
            }
        }
        ll t = 0;
        for(int j = 0;j < n;j++) {
            t += p[j][temp[j]];
        }
        res = max(res,t);
       // cout<<temp[0]<<endl;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 2688
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if __name__ == '__main__':
    s =input()


    if "C" in s and "F" in s and "F" in  s[s.index("C"):] :
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n,k;cin>>n>>k;
  vi l(n);
  rep(i,n)cin>>l[i];
  rvisort(l);
  int ans=0;
  rep(i,k)ans+=l[i];
  cout(ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        char[] cl = sc.next().toCharArray();
        if(cl[2] == cl[3] && cl[4] == cl[5]){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }

}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    int N; cin >> N;
    vector<string> S(N);
    rep(i,N){
        cin >> S[i];
    }

    vector<ll> counter(5,0);

    rep(i,N){
        char lead_char = S[i][0];
        switch(lead_char){
            case 'M':
                counter[0]++;
                break;
            case 'A':
                counter[1]++;
                break;
            case 'R':
                counter[2]++;
                break;
            case 'C':
                counter[3]++;
                break;
            case 'H':
                counter[4]++;
                break;
        }
    }
    ll ans = 0;
    for (int i = 0; i < 5; i++){
        for (int j = i+1; j < 5; j++){
            for (int k = j+1; k < 5; k++){
                ans += counter[i]*counter[j]*counter[k];
            }
        }
    }
    cout << ans << endl;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i >= 0; i--)
#define all(x) (x).begin(),(x).end()
 
using namespace std;
using ll = long long;
 
struct edge { int to, cost; };
 
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int MOD = 1e9+7;
const double EPS = 1.0e-10;
const double PI = acos(-1.0);
 
const int mx4[] = {0,1,0,-1};
const int my4[] = {1,0,-1,0};
const int mx8[] = {0,1,1,1,0,-1,-1,-1};
const int my8[] = {1,1,0,-1,-1,-1,0,1};

int main() {
	int n,k;
	cin >> n >> k;
	int cnt = 0;
	while(n){
		cnt++;
		n /= k;
	}
	cout << cnt << endl;
	return 0;
}


Measured memory_bytes: 256
//cod2017_qualB_a.cpp
//Sat Oct 20 22:36:34 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	for (int i=0;i<s.size()-8;i++){
		cout << s[i];
	}
	printf("\n");
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);

    auto adj = new int[][](n, 0);
    foreach (i ; 0 .. n - 1 + m) {
        int ai, bi;
        scan(ai, bi);
        ai--, bi--;
        adj[bi] ~= ai;
    }

    auto ld = new int[](n);
    ld[] = -1;
    auto par = new int[](n);

    int dfs(int v) {
        if (ld[v] != -1) {
            return ld[v];
        }

        ld[v] = 0;

        foreach (u ; adj[v]) {
            if (ld[v] < dfs(u) + 1) {
                ld[v] = dfs(u) + 1;
                par[v] = u + 1;
            }
        }

        return ld[v];
    }

    foreach (v ; 0 .. n) {
        dfs(v);
    }

    writefln("%(%s\n%)", par);
}









void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 13436
fun main() {
    val (a, b) = nextIntList()
    println(if (a <= 8 && b <= 8) {
        "Yay!"
    } else {
        ":("
    })
}
// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)
// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }
inline fun <reified T> sized2DArray(row: Int, column: Int, default: T) = Array(row) { Array(column) { default } }
// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}

fun gcd(x: Int, y: Int): Int {
    fun innerGcd(x: Int, y: Int): Int {
        return if (x % y == 0) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

fun gcd(x: Long, y: Long): Long {
    fun innerGcd(x: Long, y: Long): Long {
        return if (x % y == 0L) y else innerGcd(y, x % y)
    }
    return if (x >= y) innerGcd(x, y) else innerGcd(y, x)
}

// classes
class UnionFindTree(val size: Int) {
    private val r = sizedArray(size, -1)
    fun root(x: Int): Int {
        if (r[x] < 0) return x
        return root(r[x])
    }

    fun unite(x: Int, y: Int) {
        var rx = root(x)
        var ry = root(y)
        if (rx == ry) return
        if (r[rx] > r[ry]) {
            rx = ry.also { ry = rx }
        }
        r[rx] += r[ry]
        r[ry] = rx
    }

    fun size(x: Int) = -r[root(x)]

    override fun toString(): String {
        return r.joinToString(separator = ", ")
    }
}

Measured memory_bytes: 36372
n,a,b,*h=map(int,open(0).read().split())
i,j=0,2**30
while~i+j:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c<0:i=k
 else:j=k
print(j)

Measured memory_bytes: 14092
import java.io.*;
 
class Main {
  public static void main(String[] args)throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    double r = Double.parseDouble(br.readLine());
    
    double pi = Math.PI;
    double S = r*r*pi;
    double R = 2*r*pi;
    System.out.printf("%.6f %.6f", S, R);
  }
}

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

int main(void){
    string str;
    cin >> str;

    string ans="";

    for(int i=0; i<str.size(); i++){
        if(str[i]=='0') ans+='0';
        if(str[i]=='1') ans+='1';
        if(str[i]=='B'){
            
            if(ans.empty()){
                continue;
            }
            else{
                ans.pop_back();
            }
        }
    }

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


Measured memory_bytes: 256
"チェビシェフの定理"


def eratostenes(n):
    primes = [1] * (n+1)
    primes[0] = 0
    primes[1] = 0
    for i in range(2, int(n**(1/2))):
        if primes[i] == 0:  # 素数ではないならスルー
            continue
        else:
            for j in range(i*2, n+1, i):
                primes[j] = 0
    return primes


primes = eratostenes(250000)

while True:
    N = int(input())
    if N == 0:
        break
    print(sum(primes[N+1:2*N+1]))



Measured memory_bytes: 8964
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
using vll = vector<vl>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const ll INF = 2e15;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  vl a(n);
  ll maxi = -1;
  ll sum = 0;
  rep(i, n)
  {
    cin >> a[i];
    if(maxi>a[i]){
      sum += maxi - a[i];
    }
    chmax(maxi, a[i]);
  }
  print(sum);
}

Measured memory_bytes: 4840
<?php

while (true) {
    list($H, $W) = array_map("intval", explode(' ', trim(fgets(STDIN))));

    if ($H == 0 && $W == 0) break;

    $line = str_repeat('#', $W). "\n";
    $rectangle = str_repeat($line, $H);

    echo $rectangle."\n";
}



Measured memory_bytes: 9332
#include<bits/stdc++.h>
#define N 500000
using namespace std;
#define int long long

int n;
int A[N],X[N];

bool check(int i,int x){
  int len = X[n-1];
  int a  = lower_bound(X+i,X+3*n,X[i]+x) - X;
  int la = X[a]-X[i];
  int b = lower_bound(X+a,X+3*n,X[a]+x)-X;
  int lb = X[b]-X[a];
  int lc = len - la-lb;
  return lc>=x;
}

signed main(){

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

  X[0] = A[0];
  for(int i=1;i<3*n;i++) X[i] += A[i%n] + X[i-1];

  int ans = 0;
  for(int i=0;i<=n;i++){
    
    int L = 0 , R = X[n-1];
    while(L+1<R){
      int M =(L+R)/2;
      if(!check(i,M)) R = M;
      else L = M;
    }
    ans = max(ans,L);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 6216
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] input = new long[n];
        for(int i = 0; i < n; i++){
            input[i] = sc.nextLong();
        }
        System.out.println(gcd(input));
    }
    
    private static long gcd(long a, long b){
        while (b > 0)
        {
            long temp = b;
            b = a % b; // % is remainder
            a = temp;
        }
        return a;
    }
    
    private static long gcd(long[] input){
        long result = input[0];
        for(int i = 1; i < input.length; i++)
        {
            result = gcd(result, input[i]);
        }
        return result;
    }
}

Measured memory_bytes: 50792
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

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

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

	int ans = 0;
	for (int i = 2; i < nums.size(); i++) {
		ans = max(ans, nums[i-2] + nums[i-1] + nums[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int mx = 2*(160*80+10);
const int zero = mx/2;
bool dp[81][81][mx];
const int pm[2] = {-1,1};
int main(){
    int h,w; cin >> h >> w;
    int a[81][81];
    int b[81][81];
    int c[81][81];

    rep(i,h)rep(j,w) cin >> a[i][j];
    rep(i,h)rep(j,w) cin >> b[i][j];
    rep(i,h)rep(j,w) c[i][j] = abs(a[i][j]-b[i][j]);

    rep(i,2){dp[0][0][zero+pm[i]*c[0][0]]=true;}
    rep(i,h)rep(j,w)rep(k,mx){
        if(!dp[i][j][k]) continue;
        rep(l,2){
            int ni=i+1;
            if(ni<h) dp[ni][j][k+pm[l]*c[ni][j]] = true;
            int nj=j+1;
            if(nj<w) dp[i][nj][k+pm[l]*c[i][nj]] = true;
        }
    }

    int ans = mx;
    rep(i,mx){
        //if(dp[h-1][w-1][i]) cout << i-zero << endl;
        if(dp[h-1][w-1][i] && abs(i-zero) < ans) ans = abs(i-zero);
    }
    cout << ans << endl;
    return 0;
}

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

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

    std::string tmp_s;

    tmp_s = s.substr(0, 1);
    for ( int i = 1; i < 4; i++ ) {
        if ( s.substr(i, 1) == tmp_s ) {
            cout << "Bad" << endl;
            return 0;
        }
        tmp_s = s.substr(i, 1);
    }

    cout << "Good" << endl;

}


Measured memory_bytes: 256
from sys import stdin


def main():
    N, K, Q = [int(x) for x in stdin.readline().rstrip().split()]
    As = [int(stdin.readline().rstrip()) for _ in range(Q)]
    score = [0] * N
    for A in As:
        score[A - 1] += 1
    for s in score:
        x = K - (Q - s)
        print('Yes' if 0 < x else 'No')


if __name__ == "__main__":
    main()


Measured memory_bytes: 8624
#include <stdlib.h>
#include <stdio.h>
#define min(a,b) a<=b?a:b
int main()
{
    int n,k,i;
    long long t,ans=11451919810,x[100001];
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%lld",&x[i]);
    }
    for(i=0;i<=n-k;i++){
        if(x[i]>=0){
        t=abs(x[i+k-1]);    }
            else if(x[i+k-1]<0){
            t=abs(x[i]);
        }else if(x[i]<0&&x[i+k-1]>0){
            t=min((-2*x[i]+x[i+k-1]),(2*x[i+k-1]-x[i]));
        }
    ans=min(ans,t);    
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const double pi=acos(-1);
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
//cout << fixed << setprecision(12);
string s,t;
cin>>s>>t;
ll ca=0;
ll cb=0;
ll n = s.size();
ll a[n]={};
ll b[30]={};
char q;
rep(i,n){
ll k = t.at(i)-'a';
//cout << k << endl;
a[i]=k;}
//rep(i,n){
//cout << a[i] << endl;}
rep(i,30){
rep(j,n){
//cout << "i " << i << endl;
if(a[j]==i&&ca==0){
ca++;
q = s.at(j);
//cout << q << endl;
continue;}
if((a[j]==i&&s.at(j)!=q)||(a[j]!=i&&s.at(j)==q)){
cb++;
//cout << i << " " << j << endl;
goto asd;}
}
ca=0;
q ='6';
}
asd:
if(cb>0){
cout << "No" << endl;}
else{
cout << "Yes" << endl;}}


Measured memory_bytes: 5416
#create date: 2020-06-30 09:30

import sys
stdin = sys.stdin

def ns(): return stdin.readline().rstrip()
def ni(): return int(ns())
def na(): return list(map(int, stdin.readline().split()))

def main():
    a, b = na()
    print(a*b)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9160
# Author : Fuad Ashraful Mehmet 
#Date: 18th April


n,k=gets.chop.split.map(&:to_i)

def main(num,kk,cnt)

    if num==0
        return 0
    end

    return 1+main(num/kk,kk,cnt)
end
puts main(n,k,0)

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

using namespace std;

int main(){
    double A, B;
    int H, M;
    cin >> A >> B >> H >> M;

    double A_rad = M_PI * (60 * H + M) / 360;
    double B_rad = M_PI * M / 30;

    double cosine = cosl(B_rad - A_rad);

    double ans = sqrt(A*A + B*B - 2*A*B*cosine);

    cout << fixed << setprecision(10) << ans << endl;    

    return 0;
}



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

int a[100]={0,1800,1600,1400,1200,1000,800,600,400};
int x;
int main(){
	scanf("%d",&x);
	for(int i=1;i<=8;++i){
		if(x>=a[i]){
			printf("%d\n",i);return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3824
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr ll INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll N,T;cin >> N >> T;
    vector<pair<ll,ll>> V(N);
    REP(i,N) cin >> V[i].first >> V[i].second;
    sort ALL(V);
    ll dp[3100][6100] = {};
    int A[N],B[N];
    REP(i,N){
        A[i] = V[i].first;B[i] = V[i].second;
        REP(j,6100){
            if(j < T){
                dp[i+1][j+A[i]] = max(dp[i+1][j+A[i]],dp[i][j] + B[i]);
            }
            dp[i+1][j] = max(dp[i+1][j],dp[i][j]);
        }
    }
    ll maxv = 0;
    REP(j,N+1){
        REP(i,6100){
            maxv = max(maxv,dp[j][i]);
        }
    }
    cout << maxv << endl;
}

Measured memory_bytes: 148096
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    vector<string> week{"SUN","MON","TUE","WED","THU","FRI","SAT"};
    for (int i = 0; i < 7; i++)
    {
        if(week[i]==s)
        {
            cout << 7-i <<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
input = sys.stdin.buffer.readline
K, Q= map(int,input().split())
D = np.array(list(map(int,input().split()))).astype(np.int64)
QUERY = [list(map(int,input().split())) for i in range(Q)]

#K,Q = 5,2
#D = np.array([13,13,13,13,13])
#QUERY=[(11,1,2)]

def simple(N,X,M):
    S = [X]
    for i in range(N-1):
        S.append((S[-1] + D[i % K]))
    temp = 0
    modS = [s % M for s in S]
    for a,b in zip(modS,modS[1:]):
        if a < b:
            temp += 1
    return temp

ans = []
for query in QUERY: 
    N,X,M = query
    temp = 0
    tD = D % M
    sumtD = np.sum(tD)
    cumsumtD = np.cumsum(tD)
    zerocount = np.cumsum([tD == 0])
    #print(tD)
    #print(cumsumtD)
    #print(zerocount)
    nloop = (N-1)//K
    rsd = (N-1) - K*nloop
    #print(nloop,rsd)
    temp += nloop * zerocount[-1] + (zerocount[rsd-1] if rsd else 0)
    #print(temp)
    first = X % M
    last = first + sumtD * nloop + (cumsumtD[rsd-1] if rsd else 0)
    #print(sumtD,nloop, cumsumtD,rsd)
    temp += last//M - first//M
    #print(temp)
    ans.append(N-temp-1)
    #print(simple(N,X,M))

for a in ans:
    print(a)




Measured memory_bytes: 13844
#include<bits/stdc++.h>
using namespace std;
#define int long long
void a(vector<vector<int>> &A,vector<int> &B,vector<bool> &C,int n){
  for(int i:A[n])
    if(C[i]){
      C[i]=false;
      a(A,B,C,i);
    }
  B.push_back(n);
}
signed main(){
  int N,M;
  cin>>N>>M;
  vector<vector<int>> A(N,vector<int>(0));
  for(int i=0;i<M;i++){
    int x,y;
    cin>>x>>y;
    A[y-1].push_back(x-1);
  }
  vector<int> B(0);
  vector<bool> C(N,true);
  for(int i=0;i<N;i++){
    if(C[i]){
      C[i]=false;
      a(A,B,C,i);
    }
  }
  vector<int> D(N,0);
  for(int i=1;i<N;i++){
    for(int j:A[B[i]])
      D[B[i]]=max(D[B[i]],D[j]+1);
  }
  int ans=0;
  for(int i=0;i<N;i++)
    ans=max(ans,D[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 17628
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

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

    vector<pair<string, int> > playList;
    for(int i = 0; i < n; i++){
        string title;
        int sec;
        cin >>title >>sec;
        playList.push_back(make_pair(title, sec));
    }
    string slept;
    cin >>slept;

    bool count = false;
    int sum = 0;
    for(int i = 0; i < n; i++){
        if(count){
            sum += playList[i].second;
        }
        if(playList[i].first == slept){
            count = true;
        }
    }

    printf("%d\n", sum);

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int col, row, colmax, rowmax;
    do {
        scanf("%d %d", &rowmax ,&colmax);
        for (row = 1; row <= rowmax; row++) {
            for (col = 1; col <= colmax; col++) {
                if (row % 2 == 0) {
                    if (col % 2 == 0) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                } else {
                    if (col % 2 == 1) {
                        printf("#");
                    } else {
                        printf(".");
                    }
                }
            } printf("\n");
        } if(colmax != 0 && rowmax != 0){
            printf("\n");
        }
    } while (colmax != 0 && rowmax != 0);
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
using namespace std;
long long N,a[100001],ans;
int main(){
    cin.tie(0);ios_base::sync_with_stdio(false);
    cin>>N;
    for(int i{1};i<=N;++i)cin>>a[i];
    for(int i{1};i<=N;++i)
        ans+=i==a[a[i]];
    cout<<ans/2<<endl;
}


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

int main() {
int N;
  int K;
  cin>>N>>K;
  vector<int>H(N);
  for(int i=0;i<N;i++)
  {int m;
   cin>>m;
   H.at(i)=m;
  }
 sort(H.begin(), H.end());
  int64_t p=0;
  if(K>=N)
  {cout<<0<<endl;
  }
  else if(K<N)
  {for(int i=0;i<N-K;i++)
  {p=p+H.at(i);
 } cout<<p<<endl;
}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_N 10000

int n;
vector<int> G[MAX_N];
vector<int> c;
bool visited[MAX_N];
int ans[MAX_N];
int cnt = 0;

void dfs(int now){
    ans[now] = c[cnt++];
    visited[now] = true;
    for(auto v : G[now]){
        if(!visited[v]) dfs(v);
    }
}

signed main(){
    cin >> n;
    REP(i,n - 1){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    REP(i,n){
        int t;
        cin >> t;
        c.emplace_back(t);
    }
    sort(ALL(c));
    reverse(ALL(c));
    dfs(0);
    int m = 0;
    for(int i = 1; i < n; i++){
        m += c[i];
    }
    cout << m << endl;
    REP(i,n){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main(void) {
  int n;
  cin >> n;
  map<int,int> m[2];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[i%2][x]++;
  }

  int v1[2] = {0},c1[2]={0}, c2[2]={0};
  for (int i = 0; i < 2; i++) {
    for (auto j: m[i]) {
      if(j.second > c1[i]){
	c2[i] = c1[i];
	v1[i] = j.first;
	c1[i] = j.second;
      } else if(j.second > c2[i]) {
	c2[i] = j.second;
      }
    }
  }

  if(v1[0]!=v1[1]){
    cout << n - c1[0] - c1[1] << endl;
  } else {
    cout << min(n-c1[0]-c2[1],n-c2[0]-c1[1]) << endl;
  }
  
  return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
#define MAXN 15
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

int n,m;
vector<int> A[MAXN];
int p[MAXN];
int cnt=0;
int dp[(1<<12)];


void brute(int bitset){
		//já olhou todas;
		 if(dp[bitset]!=-1)return;
//		 cout<<bitset<<endl;
		for(int i=0;i<m;i++){
			   int num=0;
			   for(int j=1;j<=A[i][0];j++){
			   	//	cout<<A[i][j]<<" "<<(1<<A[i][j])<<" "<<bitset<<endl;
				   if((bitset&(1<<A[i][j]))>0){num++;
				//   	cout<<"entrou"<<A[i][j]<<" "<<(1<<A[i][j])<<" "<<bitset<<endl;
				   }
			   }
		//	   cout<<i<<" "<<num<<" "<<p[i]<<" "<<bitset<<endl;	
			if((num)%2!=p[i]){
				dp[bitset]=0;
				return;
			}
		}
	   	   cnt++;	
	   	 dp[bitset]=1;  
	return;
	
	
}

void bit(int bitset,int pos){
	if(pos==n+1)return;
	bit(bitset|(1<<pos),pos+1);
	bit(bitset,pos+1);
	brute(bitset|(1<<pos));
	brute(bitset);
	
}


int32_t main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int k;cin>>k;
		A[i].push_back(k);
		for(int j=0;j<k;j++){
			int a;cin>>a;
			A[i].pb(a);
		}
	}
	for(int i=0;i<m;i++){
		cin>>p[i];
	}

	bit(0,1);
	cout<<cnt<<endl;
	
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=(int)1e9+7;
		static void Main(){
		Sc sc=new Sc();
		int n=sc.I;
		long[] a=sc.La;
		Stack<Tuple<long,int>> stk=new Stack<Tuple<long,int>>();
		long ans=0;
		int p=0;
		for(int i = 0;i<n;i++) {
			p=i;
			while(stk.Count>0&&stk.Peek().Item1>a[i]){
				ans=Math.Max(ans,stk.Peek().Item1*(i-stk.Peek().Item2));
				p=stk.Peek().Item2;
				stk.Pop();
			}
			if(stk.Count==0||stk.Peek().Item1<a[i]){stk.Push(Tuple.Create(a[i],p));}
		}
		while(stk.Count>0){
			ans=Math.Max(ans,stk.Peek().Item1*(n-stk.Peek().Item2));
			stk.Pop();
		}
		Console.WriteLine("{0}",ans);
	}
}

public class Sc{
	private string[] a;
	private int n=-1,m=0;
	public int I{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return int.Parse(a[n]);}}
	public long L{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return long.Parse(a[n]);}}
	public double D{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return double.Parse(a[n]);}}
	public string S{get{if(n==-1||n==a.Length-1){n=-1;a=Console.ReadLine().Split();}n++;return a[n];}}
	public int[] Ia{get{if(n!=-1&&n!=a.Length-1){m=n;n=-1;return Array.ConvertAll(a.Skip(m+1).ToArray(),int.Parse);}return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}


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

shoki = X // D
if X >= K * D:
  print(abs(X - K * D))
elif (K-shoki) % 2 == 1:
  ans = X - (D * shoki) - D
  print(abs(ans))
else:
  ans = X - (D * shoki)
  print(abs(ans))


Measured memory_bytes: 9184