akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  int x,n; cin >> x >> n;
  vi p(n); rep(i,n) cin >> p[i];
  int mn = INF;
  int num = 0;
  for(int i = -100; i < 100+5; i++){
    bool ok = true;
    rep(j,n) if(i == p[j]) ok=false;
    if(ok && chmin(mn,abs(x-i))) num = i;
  }
  cout << num;
}


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

int main(){
    int n; cin >> n;
    vector<int>h(n);

    for(int i=0; i<n; i++){
        cin >> h[i];
        if(i>0 && i<n){
            if(h[i-1]<h[i]) h[i]--;
        }
    }

    for(int i=0; i<n-1; i++){
        if(h[i]>h[i+1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <cmath>
#include <iomanip>
 
 
int main()
{
    int n; std::string s;
    std::cin >> n >> s;
    for(int i=0; i<s.length(); i++)
    {
        std::cout << (char)(((int)(s[i]-'A')+n)%26 + (int)'A');
    }std::cout << "\n";
    return 0;
}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: isize,
        n: isize,
        ps: [isize; n],
    }

    let mut r: isize = 10isize.pow(4);
    // let mut diffmin: isize = 10isize.pow(4);
    // for p in ps {
    //     let diff = (p - x).abs();
    //     if diff < diffmin {
    //         diffmin = diff;
    //         r = p;
    //     } else if diff == diffmin {
    //         r = std::cmp::min(p, r);
    //     }
    // }

    for i in 0..100 {
        let mut j: isize = x - i;

        // println!("{}", j);
        if !ps.contains(&j) {
            r = j;
            break;
        }

        j = x + i;
        // println!("{}", j);
        if !ps.contains(&j) {
            r = j;
            break;
        }
    }

    // println!("---------");
    println!("{}", r)
}


Measured memory_bytes: 2132
#include <stdio.h>

int main(void)


{


    int a,b,c,i,cnt;


    cnt=0;


    scanf("%d %d %d",&a,&b,&c);


    for(i=a;i<=b;i++){


        if(c%i==0){


           cnt++;


        }


    }


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


    return 0;


}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_s(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

#define MOD 1000000007

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

  cout << n + n * n + n * n * n << endl;
}


Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))
    F = list(map(int, input().split()))

    A.sort()
    F.sort(reverse=True)
    r = A[-1]*F[0]
    l = -1
    while(r-l > 1):
        tmp = (l+r)//2
        k = 0
        for x, y in zip(A, F):
            if x*y > tmp:
                k += x - (tmp // y)
            #k += max(0, x - (tmp // y))
        if K >= k:
            r = tmp
        else:
            l = tmp
    print(r)
main()


Measured memory_bytes: 34196
a,b = map(int,input().split())
s = input()
ans = 'Yes'

for i in range(a):
    if s[i] == '-':
        ans = 'No'

if s[a] != '-':
    ans = 'No'

for i in range(a+1,a+b+1):
    if s[i] == '-':
        ans = 'No'

print(ans)

Measured memory_bytes: 3064
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

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

    vector<vector<ll> > mat(n, vector<ll>(3));

    rep (i, 0, n-1) 
    	rep (j, 0, 2)
    		cin >> mat[i][j];

    rep (i, 1, n-1) {
    	mat[i][0] = mat[i][0] + max(mat[i-1][1], mat[i-1][2]);
    	mat[i][1] = mat[i][1] + max(mat[i-1][0], mat[i-1][2]);
    	mat[i][2] = mat[i][2] + max(mat[i-1][0], mat[i-1][1]);
    	
    }

    cout << max(mat[n-1][0], max(mat[n-1][1], mat[n-1][2]));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 7680
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  lint n, k;
  cin >> n >> k;
  vector<lint> a;
  for (int i = 0; i < n; i++) {
    lint tmp;
    cin >> tmp;
    a.push_back(--tmp);
  }

  vector<lint> kako(n, -1);
  lint machi = 0;
  lint cnt = 0;
  lint p, q;
  while (true) {
    if (kako.at(machi) != -1) {
      p = kako.at(machi);
      q = cnt;
      break;
    }
    kako.at(machi) = cnt;
    machi = a.at(machi);
    cnt++;
  }

  if (k < p) {
    lint ans;
    machi = 0;
    for (lint i = 0; i < k; i++) {
      machi = a.at(machi);
    }
    ans = machi + 1;
    cout << ans << endl;
    return 0;
  }
  // cout << p << " " << q << endl;
  k -= p;
  k %= (q - p);
  // cout << k << endl;
  lint ans;
  for (lint i = 0; i < k; i++) {
    machi = a.at(machi);
  }
  ans = machi + 1;
  cout << ans << endl;
}

Measured memory_bytes: 6408
MOD = 10**9+7
N = int(input())
A = list(map(int, input().split()))
C = [0] * 100001
C[0] = 3
答 = 1
for x in A:
  答 *= C[x]
  答 %= MOD
  C[x] -= 1
  C[x+1] += 1
print(答)


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

int main() {
    int n;
    cin>>n;
    
    vector<pair<int,int> > a(n);
    for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
    int check=0;
    for(int i=0;i<n-2;i++) {
        if(a[i].first==a[i].second && a[i+1].first==a[i+1].second && a[i+2].first==a[i+2].second) {
            check=1;
            break;
        }
    }
    if(check) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3604
INF = 1000000007


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    res = 0
    mod = a % INF
    while b > 0:
        if b & 1 == 1:
            res += mod
            if res > INF:
                res -= INF
        mod <<= 1
        if mod > INF:
            mod -= INF
        b >>= 1
    return res


N = int(input())

ans = 1

for i in range(1, N + 1):
    ans = modmulti(ans, i)

print(ans)

Measured memory_bytes: 3188
#include <stdio.h>
#include <math.h>

int main(void){
	int flag[1000000],i,j,count,n;
	flag[0] = 1; flag[1] = 1;
	while((scanf("%d",&n)) != EOF){
		count = 0;
		for(i = 2;i <= n;i++)
			flag[i] = 0;
		for(i = 2;i <= sqrt(n);i++){
			if(flag[i] == 0){
				for(j = i;j <= n;j += i){
					if(i != j)
						flag[j] = 1;
				}
			}
		}
		for(i = 0;i <= n;i++){
			if(flag[i] == 0)
				count++;
		}
		printf("%d\n",count);
	}
	return 0;
}

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

typedef long long ll;

constexpr int MAX = 5000000;
constexpr ll MOD = 1000000007;
// fac[i] = i!;
// facinv[i] = (i!)^-1 (mod MOD)

constexpr ll extgcd(ll a, ll b, ll &x, ll &y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  // ll d = extgcd(b, a % b, x, y);
  // ll temp = x;
  // x = y;
  // y = temp - (a / b) * x;
  ll d = extgcd(b, a % b, y, x);
  y -= (a / b) * x;
  return d;
}

constexpr ll modinv(ll a, ll m) {
  // Need: gcd(a, m) = 1;
  // a^-1(mod. m)は
  // ax+my=gcd(a, m)=1;
  // を満たすxである。(それはそう,両辺をmodを法としてmodを考えてみよう)
  ll x = 0, y = 0;
  extgcd(a, m, x, y);
  return (x % m + m) % m;
}

template <int N> struct ComCalc {
  ll fac[N + 1];
  ll facinv[N + 1];

  constexpr ComCalc() {
    fac[0] = 1;
    for (int i = 1; i <= N; i++) {
      fac[i] = fac[i - 1] * i % MOD;
    }
    facinv[N] = modinv(fac[N], MOD);
    for (int i = N; i >= 1; i--) {
      facinv[i - 1] = facinv[i] * i % MOD;
    }
  }

  ll comb(ll n, ll r) {
    return (fac[n] * facinv[r]) % MOD * facinv[n - r] % MOD;
  }
};

int main() {
  auto calc = ComCalc<MAX>();
  ll x, y;
  cin >> x >> y;
  if ((2 * x - y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if ((2 * y - x) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  ll a = (2 * x - y) / 3;
  ll b = (2 * y - x) / 3;
  if (a < 0 || b < 0) {
    cout << 0 << endl;
    return 0;
  }
  a %= MOD;
  b %= MOD;
  cout << calc.comb((a + b) % MOD, a) << endl;
}


Measured memory_bytes: 78336
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define EACH(t,i,c) for(t::iterator i=(c).begin(); i!=(c).end(); ++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);

struct tag{
	string name;
	int x1,y1,x2,y2;
	vector<tag> children;

	tag *getClickedTag(int x,int y){
		REP(i,children.size()){
			tag *t=children[i].getClickedTag(x,y);
			if(t!=NULL){
				return t;
			}
		}
		if(x1<=x&&x<=x2&&y1<=y&&y<=y2){
			return this;
		}else{
			return NULL;
		}
	}
};

tag read(string &s, int &pos){
	tag me;
	//タグ構造 ::= 開始タグ タグ値 {タグ構造}* 終了タグ
	//開始タグ ::= <タグ名>
	assert(s[pos]=='<');
	pos++;
	while(s[pos]!='>'){
		me.name.push_back(s[pos]);
		pos++;
	}
	assert(s[pos]=='>');
	pos++;

	//タグ値   ::= 整数,整数,整数,整数
	REP(i,4){
		string num;
		while(isdigit(s[pos])){
			num.push_back(s[pos]);
			pos++;
		}
		switch(i){
		case 0:me.x1=toInt(num);break;
		case 1:me.y1=toInt(num);break;
		case 2:me.x2=toInt(num);break;
		case 3:me.y2=toInt(num);break;
		}
		assert(s[pos]==','||s[pos]=='<');
		pos++;
	}
	pos--;
	while(s[pos+1]!='/'){
		tag t=read(s,pos);
		me.children.push_back(t);
	}

	//終了タグ ::= </タグ名>
	assert(s[pos]=='<');
	pos++;
	assert(s[pos]=='/');
	pos++;
	while(s[pos]!='>'){
		pos++;
	}
	assert(s[pos]=='>');
	pos++;

	return me;
}

int main(){
	int n;
	while(cin>>n,n){
		string s;
		cin>>s;
		int pos=0;
		tag root=read(s,pos);

		REP(i,n){
			int x,y;
			cin>>x>>y;
			tag *t=root.getClickedTag(x,y);
			if(t==NULL){
				cout<<"OUT OF MAIN PANEL 1"<<endl;
			}else{
				cout<<t->name<<" "<<t->children.size()<<endl;
			}
		}
	}
}

Measured memory_bytes: 1248
/*
    author: Salam_35
    Created at :

*/

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

/*        speed up       */
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define sci(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define load(array,size)  for(ll i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(ll i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF    1LL<<19
#define pll pair<ll,ll>
#define mst(arr,value) memset(arr,value,sizeof(arr));
#define tst() _fastio;int testsalam;cin >> testsalam;while(testsalam--)
#define Mod 100000007
#define YES cout<<"Yes"<<endl;
#define NO cout<<"No"<<endl;
#define endl '\n'
//void inversemod(ll n, ll mod, ll invmod[],ll MOD){for(int i=2; i<=n; ++i) invmod[i]=MOD-MOD/i*invmod[MOD%i]%MOD;}
//void bigmod( ll a, ll b ,ll mod){ll r = 1;a = a%mod;while(b){if( b%2 ) r = (r*a)%mod;b = b/2;a = (a*a)%mod; }return (ll)r;}
string inttostr(ll n){std::stringstream ss;ss << n;string out=ss.str();return out;}
ll stringtoint(string s){istringstream iss (s);ll n;iss >> n;return n;}
template <typename T> T gcd(T a,T b){if(a < 0)return gcd(-a,b);if(b < 0)return gcd(a,-b);return (b == 0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {if(a < 0)return lcm(-a,b);if(b < 0)return lcm(a,-b);return a*(b/gcd(a,b));}
typedef vector<ll>vec;
typedef pair<ll,ll> pii;
typedef map<ll,ll>mpll;
typedef set<ll>seet;

int main()
{
    
    char c;
  cin >> c;
  if(islower(c))cout<<'a'<<endl;
  else cout<<'A'<<endl;
}
/*
 		remember:
 		ll vs int
 		array size
 		case for 1 2 3 
*/


Measured memory_bytes: 3628
from math import factorial


def perm(n, r):
    return factorial(n) // factorial(n - r)


def comb(n, r):
    return perm(n, r) // factorial(r)


def ball_spliting_variations(n, i):
    if i == 1:
        return 1
    return comb(n - 1, i - 1)


def inserting_variations(n, i):
    n -= i - 1
    if n < 0:
        return 0
    return comb(n + i, i)


DIV = (10 ** 9) + 7
n, k = map(int, input().split())
blue, red = k, n - k
for i in range(1, k + 1):
    ball = ball_spliting_variations(blue, i)
    inst = inserting_variations(red, i)
    print((ball * inst) % DIV)


Measured memory_bytes: 3316
#[allow(unused_imports)]
use std::cmp::*;

// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    
    input! {
        d: usize,
        c: [i32; 26],
        s: [[i64; 26]; d],
    }

    let t = (0..d).map(|i| i % 26 + 1);
    for e in t {
        println!("{}", e);
    }
    
}


Measured memory_bytes: 2260
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	while(cin>>m>>n,n+m){
		vvi in(n,vi(m));
		int sx,sy,gx,gy;
		rep(i,n)rep(j,m){
			string s;
			cin>>s;
			if(s==".")in[i][j]=0;
			else if(s=="G"){gx=i,gy=j;}
			else if(s=="S"){sx=i;sy=j;}
			else in[i][j]=atoi(&s[0]);

		}
		vector<pii>now;
		now.pb(pii(sx*10000+sy,0));
		int co=1;
		while(1){
			vector<pii>next;
			bool h=false;
			rep(i,n)rep(j,m)if(in[i][j]==co){
				h=true;
				int mi=inf;
				rep(k,now.size()){
					mi=min(mi,
					now[k].second+abs(i-now[k].first/10000)+abs(j-now[k].first%10000));
				}
				next.pb(pii(i*10000+j,mi));
			}
			if(!h)break;
			co++;
			now=next;
		}
		int mi=inf;
		rep(i,now.size())mi=min(mi,abs(gx-now[i].first/10000)+abs(gy-now[i].first%10000)+now[i].second);
		cout<<mi<<endl;
	}
}

Measured memory_bytes: 1280
gets
A = gets.split.map &:to_i
b = Array.new(A.size)
c = Array.new(10001,0)
A.each { |e|
    c[e] += 1
}

(1..10000).each { |i|
    c[i] += c[i-1]
}

A.reverse_each { |e|
    c[e] -= 1
    b[c[e]] = e
}
puts b * ' '

Measured memory_bytes: 333172
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root=NIL;
Node treeMinimum(Node x){
  if(x->left == NIL) return x;
  else treeMinimum(x->left);
}

Node treeMaximum(Node x){
  if(x->right == NIL) return x;
  else treeMaximum(x->right);
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key) return u;
  else if(k < u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while(y != NIL && x->key == y->right->key){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if(y->left!=NIL) x = y->left;
  else x = y->right;

  if(x!=NIL) x->parent = y->parent;

  if(y->parent == NIL) root = x;
  else if(y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if(y!=z) z->key = y->key;
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else x = x->right;
    
  }
  z->parent = y;
  if(y == NIL) root = z;
  else if(z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }
}
void preorder(Node u){
  if(u==NIL) return ;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25168
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string.h>
#include <stack>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
typedef pair<int,int> P;
int main() {
    int n,m;
    cin >> n;
    map<string, int>blue;
    map<string, int>red;
    rep(i, 0, n){
        string in;
        cin >> in;
        blue[in]++;
    }
    cin>>m;
    rep(i, 0, m){
        string in;
        cin >> in;
        red[in]++;
    }
    int ans = 0;
    for(auto i: blue){
        int blucnt =i.second;
        if(red[i.first] != 0){
            blucnt-=red[i.first];
        }
        ans = max(ans, blucnt);
    }
    cout << ans << endl;
    return 0;
}


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

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

    vector<string> S(N);
    for (int i=0; i<N; i++) cin >> S.at(i);

    sort(S.begin(),S.end());
    string ans;

    for (int i=0; i<N; i++) ans+=S[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    int N,M,C;cin>>N>>M>>C;
    int ans=0;
    vector<int>B(M);
    rep(i,M){
        cin>>B.at(i);
    }
    vector<vector<int>>A(N,vector<int>(M));
    rep(i,N)rep(j,M){
        cin>>A.at(i).at(j);
    }
    rep(i,N){
        int a=0;
        a+=C;
        rep(j,M){
            a+=A.at(i).at(j)*B.at(j);
        }
        if(a>0)ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3600
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdarg>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <utility>
#include <algorithm>
#include <fstream>
using namespace std;

namespace Namespace_Random_Generator {
	class Random_Generator {
	public:
		inline unsigned int get_random_value() const {
			return (((rand()) & 65535UL) << 16UL) + ((rand()) & 65535UL);
		}
	};
};
using namespace Namespace_Random_Generator;
Random_Generator QQ;

int const MAX_N = 3010;
double const EPS = 1e-8;
double const PI = 3.1415926535897932384626433832795;

int dp[MAX_N][MAX_N];

int const MODULE = 998244353;

void add(int& x, int y, int mul) {
	long long res = y;
	res *= mul;
	x = ((x + res) % MODULE + MODULE) % MODULE;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	dp[a][b] = 1;
	for (int i=a; i<=c; i++)
		for (int j = b; j <= d; j++)
			if (i > a || j > b) {
				add(dp[i][j], dp[i - 1][j], j);
				add(dp[i][j], dp[i][j - 1], i);
				add(dp[i][j], -dp[i - 1][j - 1], (i-1) * (j-1));
			}
	cout << dp[c][d];
	return 0;
}


Measured memory_bytes: 38824
open String

let is s =
  let len = length s in
  if len mod 2 = 0 then
    let half = len / 2 in
    sub s 0 half = sub s half half
  else false

let rec solve s =
  let len = length s in
  if is s then len else solve (sub s 0 (pred len))

let () =
  let s = read_line () in
  let len = pred @@ length s in
  solve (sub s 0 len) |> Printf.printf "%d\n"

Measured memory_bytes: 384
n,q=map(int,input().split())
s =input()
y = "0"
acs =[0]
for x in s:
    if y=='A' and x =='C':
        acs.append(acs[-1]+1)
    else:
        acs.append(acs[-1])
    y = x
s = '0'+s
for i in range(q):
    l,r = map(int,input().split())
    ans = acs[r]-acs[l-1]
    if s[l-1] == 'A' and s[l] =='C':
        ans -=1
    print (ans) 


Measured memory_bytes: 6164
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ld Calc_Dist (ld X1, ld Y1, ld X2, ld Y2){
  ld ans = (X1 - X2) * (X1 - X2) + (Y1 - Y2) * (Y1 - Y2);
  ans = sqrtl(ans);
  return ans;
}

pair <ld, ld> Calc_P (ld X1, ld Y1, ld R1, ld R2){
  ld A = (X1 * X1 + Y1 * Y1 + R1 * R1 - R2 * R2) / 2;

  ld X = A * X1 + Y1 * sqrtl((X1 * X1 + Y1 * Y1) * R1 * R1 - A * A);
  X /= X1 * X1 + Y1 * Y1;

  ld Y = A * Y1 - X1 * sqrtl((X1 * X1 + Y1 * Y1) * R1 * R1 - A * A);
  Y /= X1 * X1 + Y1 * Y1;

  return make_pair(X, Y);
}

pair <ld, ld> Calc_Q (ld X1, ld Y1, ld R1, ld R2){
  ld A = (X1 * X1 + Y1 * Y1 + R1 * R1 - R2 * R2) / 2;

  ld X = A * X1 - Y1 * sqrtl((X1 * X1 + Y1 * Y1) * R1 * R1 - A * A);
  X /= X1 * X1 + Y1 * Y1;

  ld Y = A * Y1 + X1 * sqrtl((X1 * X1 + Y1 * Y1) * R1 * R1 - A * A);
  Y /= X1 * X1 + Y1 * Y1;

  return make_pair(X, Y);
}

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

  ld X[N], Y[N], C[N];
  for (int i = 0; i < N; i++){
    cin >> X[i] >> Y[i] >> C[i];
  }

  ld L = 0, R = 1e10;
  while (R - L > 1e-8){
    ld now = (L + R) / 2;

    vector <pair<ld, ld>> Cand;


    for (int i = 0; i < N; i++){
      Cand.push_back(make_pair(X[i], Y[i]));
      for (int j = i + 1; j < N; j++){
        ld Ri = now / C[i], Rj = now / C[j];
        ld Dist = Calc_Dist(X[i], Y[i], X[j], Y[j]);

        if (Dist < abs(Ri - Rj) - 1e-8) continue;
        if (Dist > Ri + Rj + 1e-8) continue;

        pair <ld, ld> P = Calc_P(X[j] - X[i], Y[j] - Y[i], Ri, Rj);
        P.first += X[i]; P.second += Y[i];
        pair <ld, ld> Q = Calc_Q(X[j] - X[i], Y[j] - Y[i], Ri, Rj);
        Q.first += X[i]; Q.second += Y[i];
        Cand.push_back(P);
        Cand.push_back(Q);
      }
    }
    
    bool flag = false;
    for (int i = 0; i < Cand.size(); i++){
      int cnt = 0;
      ld X_now = Cand[i].first, Y_now = Cand[i].second;

      for (int j = 0; j < N; j++){
        ld Dist = Calc_Dist(X_now, Y_now, X[j], Y[j]);
        if (Dist <= now / C[j] + 1e-8) cnt++;
      }
      if (cnt >= K) flag = true;
    }
    
    if (flag == true) R = now;
    else L = now;

  }
  cout << setprecision(16) << (L + R) / 2 << endl;

  return 0;
}


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


long get_min_element(vector<long>& in_vec){
    long min_element = in_vec[0];
    for(int i = 1; i < in_vec.size(); ++i)
        if(in_vec[i] < min_element)
            min_element = in_vec[i];
    return min_element;
}


int main(){
    // def inputs
    long res = 0, num_in, N, min_throughput, stuck_num;
    vector<long> cities(6);

    // parse inputs
    for(int i = 0; i < 6; ++i){
        cin >> num_in;
        cities[i] = num_in;
    }
    // the first element is N
    N = cities[0];
    min_throughput = get_min_element(cities);
    // get stuck_num
    stuck_num = long(N / min_throughput);
    if(N % min_throughput != 0)
        ++stuck_num;
    res = 5 + stuck_num - 1;

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const int INF = 1 << 30;
const uint64_t MOD = 1000000000 + 7;

int main()
{
	vector<string> a(3);
	for (int i = 0; i < 3; i++)
	{
		cin >> a.at(i);
	}

	int x = 0;

	for (; ;)
	{
		int y = a.at(x).at(0) - 'a';

		a.at(x).erase(0, 1);
		x = y;
		if (a.at(x).length() == 0)
		{
			break;
		}
	}

	if (x == 0)
	{
		cout << "A" << endl;
	}
	else if (x == 1)
	{
		cout << "B" << endl;
	}
	else
	{
		cout << "C" << endl;
	}
}

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

int main() {

char b;
cin >> b;
if(b=='A'){
    cout << "T"<< endl;
}
else if(b=='T'){
    cout << "A" << endl;
}
else if(b=='G'){
    cout << "C" << endl;
}
else if(b=='C'){
    cout << "G" << endl;
}

}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

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

struct Mobile {
	int l, r, left, right, parent;
};

int n;
Mobile m[100];

int solve(int x) {
	int Left, Right;

	if (m[x].left == 0)Left = 1;
	else Left = solve(m[x].left - 1);
	if (m[x].right == 0)Right = 1;
	else Right = solve(m[x].right - 1);
	return lcm(Left * m[x].l, Right * m[x].r) / m[x].r + lcm(Left * m[x].l, Right * m[x].r) / m[x].l;
}

int main() {
	while (cin >> n, n) {

		for (int i = 0; i < n; i++) {
			m[i].l = 0, m[i].r = 0, m[i].left = 0, m[i].right = 0;
			m[i].parent = -1;
		}

		for (int i = 0; i < n; i++) {
			cin >> m[i].l >> m[i].r >> m[i].left >> m[i].right;
			if (m[i].left != 0)m[m[i].left - 1].parent = i;
			if (m[i].right != 0)m[m[i].right - 1].parent = i;
			{
				int l = m[i].l, r = m[i].r;
				m[i].l = m[i].l / gcd(l, r), m[i].r = m[i].r / gcd(l, r);
			}
		}
		int x = 0;
		while (1) {
			if (m[x].parent == -1) {
				break;
			}
			x = m[x].parent;
		}
		cout << solve(x) << endl;
	}

	return 0;
}

Measured memory_bytes: 3072
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] nl = sc.intarr;
            int n = nl[0];
            int l = nl[1];

            //りんごi=1の味
            int first = l;
            int last = l + n - 1;

            int sum = 0;

            if(first < 0 && last < 0)
            {
                for(int i=0; i<n-1; i++)
                {
                    sum += l + i;
                }
            }
            else if(first > 0 && last > 0)
            {
                for (int i=1; i<n; i++)
                {
                    sum += l + i;
                }
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    sum += l + i;
                }
            }

            wr.wri(sum);

        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 13396
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define INF 1000000007
using namespace std;

int main(void) {
	int grid[3][3];
	for(int i=0; i<3; i++)for(int j=0; j<3; j++)cin >> grid[i][j];
	int a[3],b[3];
	a[0]=0;
	for(int i=0; i<3; i++){
		b[i]=grid[i][0]-a[0];
	}
	for(int i=1; i<3; i++){
		a[i]=grid[0][i]-b[0];
	}
	for(int i=0; i<3; i++){
		for(int j=0; j<3; j++){
			if(a[j]+b[i]!=grid[i][j]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
import bisect

N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
MOD = 10**9+7

n0, n1 = bisect.bisect_left(A, 0), bisect.bisect_left(A, 1)
if N - (n1 - n0) < K:
    print(0)
    exit()

m, z, p= n0, n1 - n0, N - n1
if K - p == min(K, m) and (K - p) % 2 == 1:
    ans = 1
    for a in sorted([abs(x) for x in A])[:K]:
        ans = (ans * a) % MOD
    print((-ans) % MOD)
else:
    if K % 2 != 0:
        ans, i, j = A[-1], N-2, 0
    else:
        ans, i, j = 1, N-1, 0
    
    for _ in range(K//2):
        if i <= n1:
            pos = False
        elif j >= n0-1:
            pos = True
        elif A[i] * A[i-1] > A[j] * A[j+1]:
            pos = True
        else:
            pos = False

        if pos:
            ans = (ans * ((A[i] * A[i-1]) % MOD)) %MOD
            i -= 2
        else:
            ans = (ans * ((A[j] * A[j+1]) % MOD)) %MOD
            j += 2
    print(ans)

Measured memory_bytes: 31964
#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(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const ll mod = 1e9+7;

inline int id(char c)
{
    if('a'<=c && c<='z') return c-'a';
    return 26+c-'A';
}

ll dp[52][3][3]={};
int dx[3]={1,0,0}, dy[3]={0,-1,1};

int main()
{
    int n;
    cin >>n;
    string s[2];
    rep(i,2) cin >>s[i];

    int p = 0;
    if(s[0][0]==s[1][0])
    {
        rep(i,3) dp[0][i][i]=1;
        ++p;
    }
    else
    {
        rep(i,3)rep(j,3)if(i!=j)
        {
            dp[0][i][j]=1;
            dp[1][i][j]=1;
        }
        p+=2;
    }

    while(p<n)
    {
        bool yoko = true;
        if(p==n-1) yoko=false;
        else
        {
            if(s[0][p]!=s[0][p+1]) yoko=false;
        }

        if(yoko)
        {
            rep(i,3)rep(j,3)if(i!=j)
            {
                rep(k,3)if(k!=i && k!=j) (dp[p][i][j]+=dp[p-1][k][k])%=mod;

                rep(k,3)rep(l,3)if(k!=l && k!=i && l!=j) (dp[p][i][j]+=dp[p-1][k][l])%=mod;

                dp[p+1][i][j] = dp[p][i][j];
            }
            p+=2;
        }
        else
        {
            rep(i,3)
            {
                rep(k,3)if(k!=i) (dp[p][i][i]+=dp[p-1][k][k])%=mod;

                rep(k,3)rep(l,3)if(k!=l && k!=i && l!=i) (dp[p][i][i]+=dp[p-1][k][l]%=mod);
            }
            ++p;
        }
    }

    ll ans = 0;
    rep(i,3)rep(j,3) (ans+=dp[n-1][i][j])%=mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,m,n) for(int i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define push_back pb
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; }



int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int H,W;
    char A[1010][1010];
    int D[1010][1010] = {};
    int ans = 0;
    cin >> H >> W;

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            cin >> A[i][j];
        }
    }
    
    
    for(int i = 0; i < 1002; i++){
        D[0][i] = D[i][0] = D[H+1][i] = D[i][W+1] = 3000;
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(A[i][j] == '#'){  
                D[i][j] = 0;
            }
            else{
                D[i][j] = min(D[i-1][j],D[i][j-1]) +1;
            }
        }
    }
    for(int i = H; i > 0; i--){
        for(int j = W; j > 0;j--){
            D[i][j] = min(D[i][j], min(D[i+1][j], D[i][j+1]) + 1);
        }
    }
    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            ans = max(ans,D[i][j]);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
        static NODE node;
        static NODE root;
        public static void main(String[] args) throws IOException{
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); 
                int n=Integer.parseInt(br.readLine());
                
                for(int i=0;i<n;i++){
                        String[] str=br.readLine().split(" ");
                
                        if("print".equals(str[0])) {
                                inorder(root);
                                System.out.println(""); 
                                preorder(root);
                                System.out.println(""); 
                        }
                        else if("insert".equals(str[0])){
                                int key=Integer.parseInt(str[1]);
                                NODE newnode=new NODE();
                                newnode.key=key;
                                insert(newnode);
                        }
                        
                        else if("find".equals(str[0])){
                                int key=Integer.parseInt(str[1]);
                                if(findnum(root,key)!=null) System.out.println("yes");
                                else System.out.println("no");
                        }

                }
        }
        
        static NODE findnum(NODE node,int key){
                NODE x = node;
              while (x != null && x.key != key) {
                if (x.key > key)
                    x = x.left;
                else
                    x = x.right;
            }
            return x;
        }

        static void inorder(NODE node){
                if(node==null) return;
                inorder(node.left);
                System.out.print(" " + node.key);
                inorder(node.right);
        }
        
        static void preorder(NODE node){                
                if(node==null) return;
                System.out.print(" " + node.key);
                preorder(node.left);
                preorder(node.right);   
        }
        
        static void insert(NODE node){
        if(root==null){
            root = node;
            return;
        }
        NODE tnode = root;
        NODE parent = null;
        while(tnode != null) {
            parent = tnode;
            if(tnode.key > node.key)
                tnode = tnode.left;
            else
                tnode = tnode.right;
        }
        if(parent.key > node.key)
            parent.left = node;
        else
            parent.right = node;
                
        }
}

class NODE{
        int key;
        NODE left;
        NODE right;;
        NODE(){
                key=-1;
                left=null;
                right=null;
        }
}

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

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(){
    int S,W;
    cin >> S >> W;
    if (W>=S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	vector<int> vec(n);
	vector<int> dp(n,0);
	for(int i=0;i<n;i++){
		int temp;
		cin>>temp;
		vec[i]=temp;
	}
	for(int i=0;i<k;i++){
		dp[i]=abs(vec[i]-vec[0]);
	}
	for(int i=k;i<n;i++){
		int minCost=INT_MAX;
		for(int j=1;j<=k;j++){
			minCost=min(minCost,dp[i-j]+abs(vec[i]-vec[i-j]));
		}
		dp[i]=minCost;
	}
	cout<<dp[n-1];
	return 0;
	
}


Measured memory_bytes: 3980
#include <stdio.h>

int total, a[10];
int i = 0;

int main(void) {
	while (true) {
		scanf("%d", &total);
		if (total == 0) { break; }
		for (int i = 0; i < 9; ++i) { scanf("%d", &a[i]); }
		for (int i = 0; i < 9; ++i) { total -= a[i]; }
		printf("%d\n", total);
	}
	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int n;
  ll c, k;
  cin >> n >> c >> k;

  vector<ll> t(n);
  rep(i, n) cin >> t[i];

  sort(t.begin(), t.end());

  int ans = 0;
  ll  start = t[0];
  ll now = 0;

  rep(i, n){

    if(now < c && t[i]-start <= k){
      now++;
    }else{

      ans++;
      now = 1;
      start = t[i];

    }
    
  }

  ans++;
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 1024
s = input()

length = len(s)-1
bit = 0
re = 0
for i in range(2**length):
    count = 0
    temp_list = list(s)
    for j in range(length):
        if (bit >> j) & 1 == 1:
            # print('bit {}, j {}'.format(bin(bit), j))
            temp_list.insert(j + 1 + count, '+')
            count += 1
    temp_str = 're += ' + ''.join(temp_list)
    # print('bit {}, temp_str {}'.format(bin(bit), temp_str))
    exec(temp_str)
    bit += 1
print(re)


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

int main()
{
    int n;
    cin >> n;
    vector<int> t, x, y;
    t.push_back(0);
    x.push_back(0);
    y.push_back(0);
    for (int i = 1; i <= n; ++i)
    {
        int ti, xi, yi;
        cin >> ti >> xi >> yi;
        t.push_back(ti);
        x.push_back(xi);
        y.push_back(yi);
    }

    bool able = true;
    for (int i = 0; i < n; ++i)
    {
        int time = t[i + 1] - t[i];
        int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
        if (time < dist)
        {
            able = false;
            break;
        }
        if (time % 2 != dist % 2)
        {
            able = false;
            break;
        }
    }
    if (able)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    cout << endl;
    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define SP << " " 
#define LLi long long int

using namespace std;

int imax=2147483647;
long long int llimax=9223372036854775807;
LLi mod=1000000007;
vector<LLi> fac(1), facin(1);

//int型vectorを出力
void PV(vector<int> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

//LLi型vectorを出力
void PVL(vector<LLi> pvv) {
	rep(i, pvv.size()) cout << pvv[i] SP;
	cout << endl;
}

int main(){

	LLi n, k;
	LLi ans=0, mi, ma;

	cin>> n >> k;

	for(LLi i=k;i<=n+1;i++){
		mi=i*(i-1)/2;
		ma=i*(2*(n-i+1)+i-1)/2;
		ans+=ma-mi+1;
		ans=ans%mod;
		//cout<< mi SP << ma SP << ans <<endl;
	}

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

Measured memory_bytes: 3616
N = int(input())
dic ={}

for i in range(N):
    line = input().split()
    dic[i] = [line[0], int(line[1])]


ans = []
for index, i in enumerate(sorted(dic.items(), key= lambda x: (x[1][0],-x[1][1]))):
    ans.append([i])

for i in ans:
  print(i[0][0] + 1)

Measured memory_bytes: 3064
#include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    char a[100][100];
    int main()
    {
    	ll h,w;
    	cin>>h>>w;
    	bool sign=false;
    
    	for(int i=1;i<=h;i++)
    		for(int j=1;j<=w;j++)
    			cin>>a[i][j];
    	for(int i=1;i<=h;i++){
    		for(int j=1;j<=w;j++){
    			if(a[i][j]=='#')
    			{
    
    				if( (a[i+1][j]=='.'||i+1>h) && (a[i][j+1]=='.'||j+1>w)&&(a[i-1][j]=='.'||i-1<0)&&(a[i][j-1]=='.'||j-1<0)){
    					sign=true;
    			
    				}
    			}
    		}
    	}
    
    	if(sign)
    		puts("No");
    	else 
    		puts("Yes");
    		
    	return 0;
    }

Measured memory_bytes: 256
#include <stdio.h>
int i,N,R[200000],max,min;
int main(void){
    for(scanf("%d",&N);i<N;scanf("%d",&R[i++]));
    max=R[1]-R[0];
    min=R[0];
    for(i=1;i<N;i++){
        if(max<R[i]-min)max=R[i]-min;
        if(min>R[i])min=R[i];
    }
    printf("%d\n",max);
}

Measured memory_bytes: 2572
#include<bits/stdc++.h>
using namespace std;
using Int = long long;

template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE

const Int MAX = 114514;
Int dp[2][MAX];

signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n);
  for(Int i=0;i<n;i++) cin>>a[i];
  a.emplace(a.begin(),1);
  a.emplace_back(1);
  n=a.size();

  vector<Int> b(n),c(n);
  for(Int i=0;i<n;i++){
    while((1LL<<(b[i]+1))<=a[i]) b[i]++;
    while((1LL<<c[i])<a[i]) c[i]++;
    //cout<<b[i]<<" "<<c[i]<<endl;
  }

  const Int INF = 1e15;
  for(Int i=0;i<MAX;i++)
    dp[0][i]=dp[1][i]=INF;

  dp[0][0]=dp[1][0]=0;
  for(Int i=0;i+1<n;i++){
    //cout<<i<<":"<<dp[0][i]<<" "<<dp[1][i]<<endl;
    
    chmin(dp[0][i+1],dp[0][i]+abs(c[i]-b[i+1])+(c[i]-b[i]));
    chmin(dp[0][i+1],dp[1][i]+abs(b[i]-b[i+1])+(c[i]-b[i]));
    chmin(dp[1][i+1],dp[0][i]+abs(c[i]-c[i+1])+(c[i]-b[i]));
    chmin(dp[1][i+1],dp[1][i]+abs(b[i]-c[i+1])+(c[i]-b[i]));
  }
  
  //cout<<n-1<<":"<<dp[0][n-1]<<" "<<dp[1][n-1]<<endl;
  cout<<dp[0][n-1]/2<<endl;
  return 0;
}


Measured memory_bytes: 4464
import java.util.*;

public class Main {
    public static void main(String[] args) {
 		Scanner sc = new Scanner(System.in);

    int n=sc.nextInt();
    int k=sc.nextInt();
    int h[]=new int[n];
    for(int i=0;i<n;i++){
      h[i]=sc.nextInt();
    }

    int dif=1000000000;

    Arrays.sort(h);
    for(int i=0;i<=n-k;i++){
      if(dif>h[i+k-1]-h[i]){
        dif=h[i+k-1]-h[i];
      }
    }
    System.out.println(dif);

	}
}


Measured memory_bytes: 52436
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)

using namespace std;

typedef long long ll;

int main()
{
  int n;
  ll dp[4][4001]={};
  fill_n(dp[0],1001,1);
  FOR(i,1,3) REP(j,4001) FOR(k,0,min(j,1000)) dp[i][j] += dp[i-1][j-k];
  while(cin >> n) cout << dp[3][n] << endl;
  return 0;
}

Measured memory_bytes: 1288
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;
 
int main(){
	long long n;
	string ans;
	char c;

	cin >> n;

//aからzの26文字を経て文字の長さが1つ増える＝26で位が1つ増える＝26進数かな？と捉える
//10進数が0~9だから26進数で使うのは0~25？
//0=a,1=b,...,25=zとすると
//26=baとなるべき（9の次は10なので）だけど、今回は26=aaとなっていてただの26進数ではない

//一の位は文字の長さに関わらずa,b,...,y,z,a,b,...,z,a,...の26を繰り返す
//よってN % 26によって一の位の文字を特定できる

//十の位以降は少し違って、桁上りする前の状態があるため、' ',a,b,...,z,a,b,...,z,a,...となる
//Nを1回26で割ると次の位の文字を % 26で調べられる（10進数の数を10で割ると位が1つ下がる）
//よってN = N / 26 を行い、その後1を引いた上で % 26を計算する（1引くのは今回が普通の26進数とズレているから）
//もしN / 26の結果が0だったら（＝26も残ってない）なら桁上りできないので終了

//一の位の場合だけ % 26の前に1引かないのめんどくさいな
//名前'a'の前に空文字' 'があると考えると分けて処理しなくてもよくなる

	while(n != 0){
		n--;
		
		//0~25がa~zになるようにasciiコードに直す
		//c = (char)((n % 26) + 97);

		//直接的に書いても大丈夫みたい、視覚的に分かりやすいね
		c = (char)('a' + (n % 26));
		//一番下の位の文字が特定できたので回答用のstringにくっつける
		ans += c;
		//26で割ってひとつ上の位を特定する準備をする（小数点以下切り捨て）
		n /= 26;
		//商が0ならループ終わり
	}	
	//一の位の文字から順にくっつけているので最後にreverseでひっくり返す（#include<algorithm>）
	reverse(ans.begin(), ans.end());

	cout << ans << endl;

}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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(){
    cin.tie(0);
   	ios::sync_with_stdio(false);

    int N;
    ll M;
    cin >> N >> M;
    
    vector<ll> modsumA(N+1);
    map<ll, ll> cntModmap;

    modsumA[0] = 0;

    ll tmp_A;
    for(int i = 0; i < N; i++){
        cin >> tmp_A;
        modsumA[i+1] = (modsumA[i] + tmp_A) % M;
    }

    for(int i = 0; i <= N; i++){
        if(cntModmap.count(modsumA[i])) cntModmap.at(modsumA[i])++;
        else cntModmap.emplace(modsumA[i], 1);
    }

    ll ans = 0;
    for(auto itr = cntModmap.begin(); itr != cntModmap.end(); ++itr){
        ans += (itr->second) * (itr->second-1) / 2;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992