akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int qzh[100005];
int main()
{
	vector<pair<int,int>> vi;
	int n,q;
	cin>>n>>q;
	string s;
	cin>>s;
	for(int i=0;i<q;i++)
	{
		int a,b;cin>>a>>b;vi.push_back(make_pair(a-1,b-1));
	}
	for(int i=0;i<n-1;i++)
	{
		qzh[i+1] = qzh[i];
		if(s[i] == 'A'&&s[i+1] == 'C')
		{
			qzh[i+1]++;
		}
	}
	for(int i=0;i<q;i++)
	{
		int pos,pos1;
		pos = vi[i].first;
		pos1 = vi[i].second;
		cout<<qzh[pos1]-qzh[pos]<<endl;
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    const int m = 1000000007;
    ll ans=0;
    ll x=0;
    rep(i,n){
        ans = (ans + A[i]*x)%m;
        x = (x+A[i])%m;
    }
    ans = ans%m;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <math.h> 
#include <iomanip>
#include <string.h>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define PI 3.14159265358979323846264338327950L

#define INF 0x3f3f3f3f
//const int N = 2e5 + 5;
   
int sum(int l, int r) {

	return (l + r)*(r - l + 1) / 2;

}

int gcd(int a, int b) {

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

}

int arr[100001];
int f[100001];
int ma[100001];
int ans[100001];

int Find(int x) {

	if (x == f[x])
		return x;

	return f[x] = Find(f[x]); 

}
const int Mod = 1e9 + 7;

long long fastPower(long long base, long long power) {
	long long result = 1;
	while (power > 0) {
		if (power & 1) { 
			result = result * base % Mod;
		}
		power >>= 1; 
		base = (base * base) % Mod;
	}
	return result;
}
 
int Inv(int x) {
	return fastPower(x, Mod - 2);
}


int nChoosek(int n, int k) {
 
	int ans = 1;

	for (int i = 1; i <= k; ++i) 
		ans = ans * Inv(i) % Mod *(n - i + 1) % Mod;

	return ans % Mod;

}
char maze[21][21];

int visit[22][22];

struct Point{

	int x;
	int y;
	int d;
};
int H, W;
int depth = 0;
void bfs(int x,int y) {

	queue<Point> q;

	Point p;
	p.x = x;
	p.y = y;
	p.d = 0;
	q.push(p); 
	visit[x][y] = 1;
	while (!q.empty()) {

		Point tmp = q.front();

		q.pop();

		int x1 = tmp.x;
		int y1 = tmp.y;
		int d1 = tmp.d;
		
		depth = max(depth,d1);
		//cout << depth << endl;
		if (x1 + 1 < H ) {
			if (maze[x1 + 1][y1] == '.' && visit[x1 + 1][y1] == 0) {
				Point p2;
				p2.x = x1+1;
				p2.y = y1;
				p2.d = d1 + 1;
				visit[x1+1][y1] = 1;
				q.push(p2);
			}
		}
		if (y1 + 1 < W ) {
			if (maze[x1][y1 + 1] == '.' && visit[x1][y1 + 1] == 0) {
				Point p2;
				p2.x = x1;
				p2.y = y1 + 1;
				p2.d = d1 + 1;
				visit[x1][y1+1] = 1;
				q.push(p2);
			}
		}
		if (x1 - 1 >= 0) {
			if (maze[x1 - 1][y1] == '.' && visit[x1-1][y1] == 0) {
				Point p2;
				p2.x = x1-1;
				p2.y = y1;
				p2.d = d1 + 1;
				visit[x1-1][y1] = 1;
				q.push(p2);
			}
		}
		if (y1 - 1 >= 0) {
			if (maze[x1][y1 - 1] == '.' && visit[x1][y1-1] == 0) {
				Point p2;
				p2.x = x1;
				p2.y = y1 - 1;
				p2.d = d1 + 1;
				visit[x1][y1-1] = 1;
				q.push(p2);
			}
		}



	}
}

map<int, int> m;
int32_t  main() {

	IOS;

	cin >> H >> W;

	for (int i = 0; i < H; i++) {

		for (int j = 0; j < W; j++) {

			cin >> maze[i][j];

		}
	}


	for (int i = 0; i < H; i++) {

		for (int j = 0; j < W; j++) {
			
			if (maze[i][j] == '.') {
				memset(visit, 0, sizeof(visit));
				bfs(i, j); 
			}

		}
	}


	cout << depth << endl;

}


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

long long a,b;

int main(){
	cin>>a>>b;
	if(b != 100){
		if(a == 0){
			cout<<b<<endl;
		}else if(a == 1){
			cout<<100 * b<<endl;
		}else{
			cout<<10000 * b<<endl;
		}
	}else{
		if(a == 0){
			cout<<101<<endl;
		}else if(a == 1){
			cout<<10100<<endl;
		}else{
			cout<<1010000<<endl;
		}
	}
}

Measured memory_bytes: 256
###############################################################################

from bisect import bisect_left as binl

def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * sy) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    n = intin()
    ablist = intinl(n-1)

    linklist = make_linklist(ablist)
    diameter = calc_tree_diameter(linklist)

    if diameter % 3 == 1:
        print('Second')
    else:
        print('First')


if __name__ == '__main__':
    main()


Measured memory_bytes: 155716
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    String ans = "";
    switch(str) {
      case "Sunny":
        ans = "Cloudy";
        break;
      case "Cloudy":
        ans = "Rainy";
        break;
      case "Rainy":
        ans = "Sunny";
        break;
    }
    System.out.println(ans);
  }
}


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

using namespace std;

long long ans;
int a[200010];
int n;
//int d[200010];
int main()
{
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for(int i = 2; i <= n; i++)
	{
		if(a[i] < a[i-1])
		{
			ans += (a[i-1] - a[i]);
			a[i] = a[i-1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4400
# from itertools import product

INF = 10**18

N, M = map(int, input().split())
XYZ = [list(map(int, input().split())) for _ in range(N)]

# i番目までのケーキの内、j個食べた時のpointの最大値
# (ただしpointの計算時には、8通りのmaskを乗算する)

def mul_mask(l, mask):
    p = []
    for i, m in enumerate(l):
        p.append(m*mask[i])
        # print(p)
    return p
    # return [a*b for a, b in zip(l, mask)]

dp_std = [[-INF for _ in range(M+1)] for _ in range(N+1)]
for i in range(N+1):
    dp_std[i][0] = 0
# print(dp_std)

max_p = -INF
# masks = product([-1, 1], repeat=3)
masks = []
for i in [1, -1]:
    for j in [1, -1]:
        for k in [1, -1]:
            masks.append([i, j, k])
# print(masks)
for mask in masks:
    dp = dp_std[:]
    for i in range(1, N+1):
        score = sum(mul_mask(XYZ[i-1], mask))
        for j in range(1, M+1):
            # print(i, j, XYZ[i-1], mask)
            dp[i][j] = max(
                dp[i-1][j],
                dp[i-1][j-1] + score
            )
            # for dp_i in dp:
            #     print(dp_i)
    p = dp[N][M]
    max_p = max(max_p, p)
    # print(p)

print(max_p)

Measured memory_bytes: 54236
#include<bits/stdc++.h>
using namespace std;
main(){
  const int ans=[]{
    const int k=[]{
      const vector<bool> exists=[]{
        const int N=[]{int N;cin>>N;return N;}();
        vector<bool> exists(100001);
        for(int i=1;i<=N;++i){
          int A;
          cin>>A;
          exists[A]=true;
        }
        return exists;
      }();
      int k;
      for(bool x:exists)if(x)++k;
      return k;
    }();
    return k%2?k:k-1;
  }();
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
using namespace std;
 
int h, w;
 
int main(void)
{
	scanf("%d %d", &h, &w);
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			char str[10];
			scanf("%s", str);
			if (strcmp(str, "snuke") == 0)
			{
				printf("%c",'A' + j);
				printf("%d\n", i + 1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <math.h> 
using namespace std;
int main() {
  int n,idx = 0;;
  double t,a;
  double minv = 100000;
  double h[1001];
  double ave[1001];
  cin >> n >> t >> a;

  for(int i=0; i<n; i++){
    cin >> h[i];
    ave[i]=t-(h[i]*0.006);
  }

  for(int i=0; i<n; i++){
    if(minv > fabs(ave[i]-a)){
      minv = fabs(ave[i]-a);
	idx = i;
    }
  }
  cout << idx+1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int n, k;
	ll ans1, ans2;
	ll m = 100000000000, num;
	cin >> n;
	vector<ll>a(n);
	REP(i, n) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	ans1 = a[n - 1];
	num = (a[n - 1] + 1) / 2;
	REP(i, n) {
		ll l = abs(num - a[i]);
		if (l < m) {
			m = l;
			k = i;
		}
	}
	ans2 = a[k];
	cout << ans1 << " " << ans2 << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int t; cin >> t; cin.ignore(); while(t--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main(){
	ll n;
	cin >> n;
	cout << (n-1)*n/2 << endl;
}

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

#[fastout]
fn main() {
  input!{
    n: i64
  }
  let x = prime_factorization(n);
  let mut ans = 0;
  for a in x{
    let mut c = a;
    let mut i = 1;
    while !(c < i){
        ans += 1;
        c -= i;
        i += 1;
    }
  }
  println!("{}",ans);
}

fn prime_factorization(mut n:i64) -> Vec<i64>{
    let mut primes = Vec::new();
    let mut i = 2;

    while i*i <= n {
        let mut c = 0;
        while n%i == 0 {
            c += 1;
            n /= i;
        }
        primes.push(c);
        i += 1;
    }
    if n != 1 {
        primes.push(1);
    }
    primes
}


Measured memory_bytes: 9948
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);
static const int INF = 1e9+7;



int main(){
  string s;
  cin >> s;
  int n = s.size();
  string t;
  int len = 1;
  int mxlen = 0;


while(len <= n/2-1){
  //cout << len << endl;
  bool ok = true;
  for(int i = 0; i < len ; i++){
      if(s[i] != s[i+len]) {
        ok = false;
        break;
      }
    }
   if(ok) mxlen = len*2;
   len++;
 }

  cout << mxlen << endl;


  return 0;
}


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

int x, y;
const int MOD = 1e9 + 7;
const int MAX = 1e6;

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

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    cin >> x >> y;
    int s = x + y;
    if (s % 3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int n = s / 3;
    if ((x < n) || (2 * n < x)) {
        cout << 0 << endl;
        return 0;
    }
    int r = x - n;
    COMinit();
    cout << COM(n, r) << endl;
}


Measured memory_bytes: 23680
#include<stdio.h>
#include<string.h>

int main(){
    int n,i,j,d[100],t,x[100];
    char s[100][100];
    scanf("%d",&n);
    for(i=0;i<n;++i){
        scanf("%s %d",s[i],&d[i]);
        for(j=i;j>0;--j){
            t=strcmp(s[i],s[x[j-1]]);
            if(t<0 || (t==0&&d[i]>d[x[j-1]])){
                x[j] = x[j-1];
            }else{
                break;
            }
        }
        x[j]=i;
    }
    for(i=0;i<n;++i){
        printf("%d\n",x[i]+1);
    }
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
//---------------------------------------------------------------------------------------------------
struct Data {
    int n, mi;
    Data() {
        n = 1;
        mi = 10101010;
    }
    void add(Data &d) {
        n += d.n;
        mi = min(mi, d.mi);
    }
};
struct UnionFindWithData {
    vector<int> par; vector<Data> dat;
    UnionFindWithData(int NV) { par.clear(); dat.resize(NV); rep(i, 0, NV) par.push_back(i); }
    void reset() { rep(i, 0, dat.size()) dat[i] = Data(); rep(i, 0, par.size()) par[i] = i; }
    pair<int, Data> operator[](int x) { if (par[x] == x) return { x, dat[x] };
        auto p = operator[](par[x]);par[x] = p.first;return p;}
    void operator()(int x, int y) {
        x = operator[](x).first; y = operator[](y).first;if(x!=y)par[x]=y,dat[y].add(dat[x]);}};
/*---------------------------------------------------------------------------------------------------
????????????????????????????????? ??§?????§  
??????????????? ??§?????§ ???????´<_??? ?????? Welcome to My Coding Space!
???????????? ??? ?´_???`??????/??? ???i     
?????????????????????????????? ???  |???|     
????????? /?????? /??£??£??£??£/??????|  
??? ???_(__??????/???    ???/ .| .|????????????  
??? ????????????/????????????/??????u??????  
---------------------------------------------------------------------------------------------------*/




int N, M;
map<string, int> dic;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N;

    UnionFindWithData uf(N);
    rep(i, 0, N) {
        string s; int x; cin >> s >> x;
        dic[s] = i;
        uf.dat[i].mi = x;
    }

    cin >> M;

    rep(i, 0, M) {
        string a, b; cin >> a >> b;
        int aa = dic[a], bb = dic[b];
       // printf("%d-%d\n", aa, bb);
        uf(aa, bb);
    }

    int ans = 0;
    rep(i, 0, N) if (uf[i].first == i) {
        auto data = uf[i].second;
        ans += data.mi * data.n;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3808
from collections import Counter


def f(mod):
    ret = [0]
    power = 1
    num = 0
    for i, e in enumerate(s, 1):
        num *= 10
        num += int(e)
        num %= mod

        power *= 10
        power %= mod
        inv = pow(power, mod - 2, mod)

        ret.append(num * inv % mod)

    return ret


s = input()

mod3 = f(3)
mod673 = f(673)

li = [10 * e673 + e3 for e3, e673 in zip(mod3, mod673)]

c = Counter(li)
ans = 0
for v in c.values():
    ans += v * (v - 1) // 2
print(ans)


Measured memory_bytes: 24420
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int x;
    cin>>x;
    int ans = 1-x;
    cout<<ans<<"\n";

    return 0;
}

Measured memory_bytes: 3608
N = int(input())
ali = list(map(int,input().split()))
sali = sorted(ali)
now = None
num = []
suu = []
kari = 0 
for i in range(N):
    if sali[i] == now:
        kari += 1
    else:
        if kari > 0:
            suu.append(kari)
        kari = 1 
        num.append(sali[i])
        now = sali[i]
suu.append(kari)
kari = 0 
for i in range(len(suu)):
    if num[i] > suu[i]:
        kari += suu[i]
    elif num[i] < suu[i]:
        kari += suu[i] - num[i]
print(kari)


Measured memory_bytes: 14616
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<double> vd;
typedef pair<double,double> PD;
typedef pair<int,P> ed;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
const double eps = 1e-10;

int main() {
  int H,W;
  cin >> H >> W;
  v(string) G(H);
  rep(i,H) {
    cin >> G[i];
  }
  vvi dp(H,vi(W,0));
  if(G[0][0] == '#') dp[0][0]++;
  rep(i,H) {
    rep(j,W) {
      if(!i&&!j) continue;
      if(!i) {
        if(G[i][j]=='#' && G[i][j-1] == '.') {
          dp[i][j] = dp[i][j-1]+1;
        } else {
          dp[i][j] = dp[i][j-1];
        }
        continue;
      }
      if(!j) {
        if(G[i][j]=='#' && G[i-1][j] == '.') {
          dp[i][j] = dp[i-1][j]+1;
        } else {
          dp[i][j] = dp[i-1][j];
        }
        continue;
      }
      
      if(G[i][j]=='.') {
        dp[i][j] = min(dp[i-1][j],dp[i][j-1]);
        continue;
      }
      int r = INF;
      if(G[i-1][j]=='.') {
        chmin(r,dp[i-1][j]+1);
      } else {
        chmin(r,dp[i-1][j]);
      }
      if(G[i][j-1]=='.') {
        chmin(r,dp[i][j-1]+1);
      } else {
        chmin(r,dp[i][j-1]);
      }
      dp[i][j] = r;
    }
  }
  cout << dp[H-1][W-1] << endl;
  return 0;
}

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(i = 0; i < n; i++)

const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

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

typedef long long ll;

// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

int main()
{
	int a, b, c, k;
	cin >> a >> b >> c >> k;

	int ans = a + b + c;
	int max_ = max({ a, b, c });

	for (int i = 0; i < k; i++)
	{
		ans += max_;
		max_ *= 2;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ffor( i,a,b) for(ll i=a;i<b;i++)
const int ma=1e5+10;
ll kp[ma];
ll n,w,v,V;
ll wt[102],vt[102];
ll dp[ma];
int main()
{   
    ll n,W;
    cin>>n>>W;
    ll V=0;
    
    ffor(i,0,n)
    {
        cin>>wt[i]>>vt[i];
        V+=vt[i];
    }
   ffor(i,0,V+1)
    dp[i]=INT_MAX; 
    dp[0]=0;
     ffor(i,0,n)
        {
         w=wt[i];
         v=vt[i];
         for(int j=V;j>=v;j--)
         {
            dp[j]=min(dp[j],dp[j-v]+w);
         }
        }
     for(int i=V;i>=0;i--)
     {
         if(dp[i]<=W)
         {
             cout<<i<<endl;
             break;
         }
     }
    
}

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


#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ a=max(a,b);}

ll  fct[100100], inv[100100];
void finit(int cmx, ll mod =MD){
	auto bin_pows =[](ll x, ll n, ll mod){
		ll res = 1LL;
		for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
		return res;
	};
	fct[0] = fct[1] = inv[1] = 1;
	for(int i=2;i<cmx+3;i++) fct[i] = fct[i-1] * i % mod;
	inv[cmx] = bin_pows(fct[cmx], mod-2, mod);
	for(int i=cmx;i>=1;i--) inv[i-1] = inv[i] * i % mod;
}
ll nCk(ll n, ll k, ll mod =MD) {
	if(k > n ) return 0;
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VL a(n);
	rep(i, n) cin >>a[i];
	sort(all(a));
	finit(100050);
	ll ans =0;
	rep(i, n){
		(ans += a[i] * nCk(i, k-1)) %=MD;
		(ans += MD - (a[i] * nCk(n-1-i, k-1)) % MD ) %=MD;
	}
	cout << ans <<"\n";
	return 0;

}



Measured memory_bytes: 2560
from sys import stdin

if __name__ == '__main__':
    N = int(stdin.readline().strip())
    a = [int(x) for x in stdin.readline().rstrip().split()]
    
    current_num = 1
    broken_num = 0
    for i in range(N):
        if a[i] != current_num:
            broken_num += 1
        else:
            current_num += 1
    if current_num > 1:
        print(broken_num)
    else:
        print(-1)


Measured memory_bytes: 25768
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	string s;
	cin >> s;
	if (!cin) return false;

	for (int i = 0; i < s.size(); ++i) cout << 'x';
	cout << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c,d;
bool vi[100001];
vector<int> ca[100001];
int dp[100001];
int f(int x){
    if(vi[x]) return dp[x];
    vi[x]=true;
    int u=0;
    for(int n=0;n<ca[x].size();n++){
	u=max(u,f(ca[x][n])+1);
    }
    return dp[x]=u;
}
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >>a>>b;
    for(int n=0;n<b;n++){
	cin >>c>>d;
	ca[c].push_back(d);
    }
    int ans=0;
    for(int n=1;n<=a;n++){
	ans=max(ans,f(n));
    }
    cout <<ans<<'\n';
    return (0);
}


Measured memory_bytes: 8320
/*"Success isn't permanent, failure isn't fatal,
                                      it's the courage to continue that counts"*/
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=1e5+4;

int par[N],sz[N];

int find(int x)
{
	if(par[x]==x)return x;

	return par[x]=find(par[x]);
}

void merge(int i,int j)
{
	int pi=find(i),pj=find(j);

	if(pi==pj)return;

	sz[pj]+=sz[pi];

	par[pi]=pj;
}

int main()
{
	iota(par,par+N,0);

	fill(sz,sz+N,1);

	int n,m,k;

	scn(n); scn(m); scn(k);

	vector<int> ans(n+1,0);

	rep(i,0,m)
	{
		int a,b; scn(a); scn(b);

		merge(a,b);

		ans[a]--; ans[b]--;
	}

	rep(i,1,n+1)
	ans[i]+=sz[find(i)];

	rep(i,0,k)
	{
		int a,b; scn(a); scn(b);

		if(find(a)==find(b))
		ans[a]--,ans[b]--;
	}

	rep(i,1,n+1)
	printf("%d ",ans[i]-1); //subtract 1 as I have counted i as a friend candidate for i itself

	return 0;
}


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

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

  vector<int> a(M), b(M);
  rep(i, M) {
    cin >> a[i] >> b[i];
  }

  vector<int> ans(N, 0);
  rep(i, M) {
    ans[a[i] - 1]++;
    ans[b[i] - 1]++;
  }

  rep(i, N) {
    cout << ans[i] << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }

// 剰余演算クラス
struct ModInt{
    static const LL MOD = 998244353;
    LL v;
    ModInt():v(0){}
    ModInt(LL op):v(op){}
    ModInt operator+(ModInt op) const{ return (v + op) % MOD; }
    ModInt operator-(ModInt op) const{ return (v - op + MOD) % MOD; }
    ModInt operator*(ModInt op) const{ return (v * op) % MOD; }
    ModInt operator/(ModInt op) const{ return (v * op.inverse()) % MOD; }
    ModInt operator%(LL op) = delete;
    ModInt operator+=(ModInt op){ return v = (v + op) % MOD; }
    ModInt operator-=(ModInt op){ return v = (v - op + MOD) % MOD; }
    ModInt operator*=(ModInt op){ return v = (v * op) % MOD; }
    ModInt operator/=(ModInt op){ return v = (v * op.inverse()) % MOD; }
    ModInt operator-() const{ return MOD - v; }
    bool operator==(ModInt op) const{ return v == op.v; }
    bool operator!=(ModInt op) const{ return v != op.v; }
    ModInt inverse() const{ return pow(MOD-2); }
    ModInt pow(LL n) const{
        if(n < 0) return pow(MOD-1 + n);
        if(n == 0) return 1;
        ModInt res = pow(n/2);
        return res * res * ((n&1)?ModInt(v): ModInt(1));
    }
    LL get() const{ return v; }
private:
    operator LL() const{ return v; }
};
istream& operator>>(istream& st, ModInt& m){ st>>m.v; return st; }
ostream& operator<<(ostream& st, const ModInt& m){ st<<m.v; return st; }


int main(){
    LL n, s;
    cin >> n >> s;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    vector<vector<ModInt>> dp(n+1, vector<ModInt>(s+1));
    dp[0][0] = ModInt(1);
    for(LL i = 0; i < n; ++i){
        for(LL j = 0; j <= s; ++j){
            dp[i+1][j] += dp[i][j]*ModInt(2);
            if(j+a[i] <= s){
                dp[i+1][j+a[i]] += dp[i][j];
            }
        }
    }
    cout << dp[n][s] << endl;
    return 0;
}



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

int n, target;

int binserch(int* s, int* e) {
	if (s == e) return 0;
	int* c = s + (e - s - 1) / 2;
	if (*c < target) {
		return binserch(c + 1, e) + 1;
	}
	else if (target < *c) {
		return binserch(s, c) + 1;
	}
	else {
		return 1;
	}
}

int main() {
	while (cin >> n, n) {
		int a[n];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		cin >> target;
		cout << binserch(a, a + n) << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
using namespace std;
typedef long long ll;
const int maxn = 100005;

ll a, b, k;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "w", stdout);
#endif
  cin>>k>>a>>b;
  ll ret = 0;
  if (b < a + 2){
    ret = k + 1;
  } else {
    if (k + 1 <=a+1){
      ret = k + 1;
    } else {
      ll lt = k - a  + 1;
      ret = a + lt/2 * (b-a);
      if(lt&1LL)ret++;
    }
  }
  cout<<ret<<endl;
  return 0;
}

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

int main(){
  int N;
  long long D;
  cin >> N >> D;
  int ans = 0;
  for(int i = 0; i < N; ++i){
    long long x, y;
    cin >> x >> y;
    if(x*x+y*y <= D*D)
      ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long
#define pb push_back
const int MOD=1e9+7;
const int INF=1e15;


signed main(){
    int A,B,X;cin>>A>>B>>X;
    if(A<=X&&X<=A+B)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#define SIZE10 100000

typedef long long int ll;
typedef unsigned char u8;

int main(void){
    int A[SIZE10];
    int B[SIZE10];
    int N = 0;
    int K = 0;
    int Q = 0;
    int i = 0, j = 0;
    int sum = 0;

    scanf("%d %d %d", &N, &K, &Q);

    for(i = 0; i < Q; i++){
        scanf("%d", &A[i]);
    }
    for(i = 0; i < N; i++){
        B[i] = 0;
    }

    for(i = 0; i < Q; i++){
        B[A[i]-1]++;
    }

    for(i = 0; i < N-1; i++){
        if((B[i]-Q+K) <= 0){
            printf("No\n");
        }else{
            printf("Yes\n");
        }
    }

    if((B[i]-Q+K) <= 0){
        printf("No");
    }else{
        printf("Yes");
    }

    return 0;
}

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

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;

void dfs(int v, VI &val, VB &vis, VVP &g) {
    vis[v] = true;
    
    for (auto &e : g[v]) {
        int u, d;
        tie(u, d) = e;
        
        if (!vis[u]) {
            val[u] = val[v] + d;
            dfs(u, val, vis, g);
        }
    }
}

/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n, m;
    cin >> n >> m;
    
    VVP g(n);
    while (m--) {
        int u, v, d;
        cin >> u >> v >> d; u--; v--;
        
        g[u].pb({v, d});
        g[v].pb({u, -d});
    }
    
    VB vis(n, false);
    VI val(n);
    
    FOR(i,0,n-1) if (!vis[i]) {
        dfs(i, val, vis, g);
    }
    
    FOR(i,0,n-1) for (auto &e : g[i]) {
        int j, d;
        tie(j, d) = e;
        
        if (val[j] != val[i] + d) {
            cout << "No";
            return 0;
        }
    }
    
    cout << "Yes";

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 13824
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N=nextInt();
		int M=nextInt();
		int[] a = new int[M];
		int[] b = new int[M];
		HashMap<Integer,ArrayList<Integer>> map = new HashMap<>();
		for(int i=0;i<M;i++){
			a[i]=nextInt();
			b[i]=nextInt();
			if(map.containsKey(a[i])){
				map.get(a[i]).add(b[i]);
			}else{
				ArrayList<Integer> list = new ArrayList<>();
				list.add(b[i]);
				map.put(a[i], list);
			}
		}

		if(map.containsKey(1)){
			for(int key:map.get(1))
				if(map.containsKey(key)){
					for(int key2:map.get(key)){
						if(key2==N){
							System.out.println("POSSIBLE");
							return;
						}
					}
				}
		}
		System.out.println("IMPOSSIBLE");


	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 76220
from bisect import bisect_right
s = input()
t = input()
alpha = [[] for _ in range(26)]
def f(c): return ord(c)-ord("a")

for i,c in enumerate(s): alpha[f(c)].append(i)
idx = -1
roop = 0
for c in t:
    lst = alpha[f(c)]
    if not lst:
        ans = -1
        break
    i = bisect_right(lst,idx)
    if i == len(lst):
        roop += 1
        idx = lst[0]
    else:
        idx = lst[i]
else:
    ans = len(s)*roop+idx+1
print(ans)

Measured memory_bytes: 7796
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut scanner = Scanner::new(cin);
  loop {
    scanner.new_line();
    let s = scan!(scanner; String);
    if s == "0" {
      break;
    }
    let ans: Vec<i64> = s.chars()
      .map(|c| ((c as u8) - ('0' as u8)) as i64)
      .collect();
    println!("{}", ans.iter().sum::<i64>());
  }
}



Measured memory_bytes: 5036
#define __mode_debug__
/*   ξ
     ll
   ＿ll＿
 ／  ∞  ＼
│*  Ａ  *│
│*  Ｃ  *│
│*  祈  *│
│*  願  *│
│*      *│
 ￣￣￣￣￣    */
//C++14 (GCC 5.4.1)
#include <bits/stdc++.h>
using namespace std;
#ifdef __mode_debug__
    #define DBG
#else
    #define DBG if(false)
#endif

#define LLINF (1LL<<60)
using ll = long long;
#define mod  1000000007

#define whole(a) (a).begin(),(a).end()
#define rwhole(a) (a).rbegin(),(a).rend()

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)
#define each(itr,ds) for(auto itr=(ds).begin();itr!=(ds).end();itr++)

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

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); }

//DUMP
//  ostream vector<T> , vector<vector<T>> , set<T> ,queue<T> , priority_queue<T> , pair<T,U> , map<T,U>
template<class T> ostream& operator<<(ostream&os,vector<T>&vec){os<<"{ ";rep(i,vec.size()) os<<((i==0)?"":", ")<<i<<":"<<vec[i];os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,vector<vector<T>>&vec){os<<"{"<<endl;rep(i,vec.size())os<<"\t   "<<i<<":"<<vec[i]<<((i==vec.size()-1)? "":",")<<endl;os<<"\t }";return os;}
template<class T> ostream& operator<<(ostream&os,set<T>&p){os<<"{ ";each(itr,p)  os<<((itr==p.begin())?"":", ")<<*itr;os<<" }";return os;}
template<class T> ostream& operator<<(ostream&os,queue<T>&p){queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.front();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T> ostream& operator<<(ostream&os,priority_queue<T>&p){priority_queue<T> q(p);os<<"[< "<<(q.empty()?" <]":"");while(!q.empty()){os<<q.top();q.pop();os<< (q.empty() ? " <]" : ", ");}return os;}
template<class T,class U> ostream& operator<<(ostream&os,pair<T,U>&p){os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T,class U> ostream& operator<<(ostream&os,map<T,U>&p){os<<"{ ";each(itr,p)os<<((itr==p.begin())?"":", ")<<itr->first<<":"<<itr->second;os<<" }";return os;}
void dump_f(string &nm,char t){cerr<<endl;}
template<class T,class... Ts> void dump_f(string &nm,char t,T &&x,Ts&&... ts){int l=nm.find_first_of(',');string name(nm,0,l),nx(nm,l+1,-1);if(t=='\n') cerr<<"  "<<name<<"\t: "<<x<<t;else cerr << name<<": "<<x<<","<<t;dump_f(nx,t,forward<Ts>(ts)...);}
template<class... Ts> void dump_m(int &&ln,string &&nm,char t,Ts&&... ts){cerr<<"[ln: "<<ln<<"]"<<t;dump_f(nm,t,forward<Ts>(ts)...);}
#define dump(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\n',__VA_ARGS__)
#define dl(...) DBG dump_m(__LINE__,#__VA_ARGS__,'\t',__VA_ARGS__)

#define lower_bound_idx(V,c) distance(V.begin(),lower_bound(whole(V),c))

int main() {
    ios::sync_with_stdio(false);//stdout<=>cout
    cin.tie(nullptr);//cin<=>cout


    ll H,W;
    cin >>H>>W;
    if(H==1 || W==1) cout << 1 << endl;
    else cout << ((H+1)/2)*((W+1)/2) + (H/2)*(W/2) <<endl;


    return (0);
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define sort(vec) sort((vec).begin(),(vec).end());
#define rever(vec) reverse((vec).begin(),(vec).end());
#define cout(n) cout<<(n)<<endl;
using namespace std;

int main() {
  string s;
  cin>>s;
  ll e=s.size()-1;
  ll ans=0;
  for(int i=0;i<e;i++) {
    if(s.at(i)!=s.at(i+1)) {
      ans++;
    }
  }
  cout(ans);
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
ans = [[0]*2 for _ in range(n)]
for i in range(n):
    ans[i][0] = a[i]
    ans[i][1] = i+1
ans.sort()
for i in range(n):
    print(str(ans[i][1]), end=" ")
print()

Measured memory_bytes: 21952
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

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

    if(k == 0){
        cout << n * n << endl;
        return 0;
    }

    int ans = n * k;
    for(int i = k + 1; i <= n; i++){
        int div = n / i;
        int mod = n % i;
        ans += k * div + min(mod, k - 1);
    }

    cout << n * n - ans << endl;

    return 0;
}


Measured memory_bytes: 888
import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

class Main {
    public static void main(String[] args) throws IOException {
       Scanner in = new Scanner(System.in);
       int n = in.nextInt();
       for(int i=0;i<n;i++) {
           ArrayList<Integer>intArr = new ArrayList<Integer>();
           for(int j=0;j<3;j++)
               intArr.add(in.nextInt());
           Collections.sort(intArr);
           Collections.reverse(intArr);
           int c = intArr.get(0);
           int a = intArr.get(1);
           int b = intArr.get(2);
           if(a*a + b*b == c*c) {
               System.out.println("YES");
           } else {
               System.out.println("NO");
           }
       }
    }
}

Measured memory_bytes: 23376
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,x;
  cin >> n >> x;
  int sum = 0;
  int min = 1001;
  int m;
  for(int i = 0;i < n;i++) {
    cin >> m;
    sum += m;
    if(min > m) {
      min = m;
    }
  }
  cout << n + (x - sum) / min << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n,h,w;
    cin >> n >> h >> w;
    int ans = 0;
    rep(i,n){
        int a,b;
        cin >> a >> b;
        ans += (a>=h&&b>=w);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
#include <cstdio>
int arr[100005];
int main() {
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=0;i<n;++i) scanf("%d",&arr[i]);
	printf("%d\n",(n-1)/(k-1)+((n-1)%(k-1)==0?0:1));
	return 0;
}


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

int main()
{
    char a,b,c;
    scanf("%c%c%c",&a,&b,&c);
    if(a=='R'&&b=='R'&&c=='R')
        printf("3");
    else if((a=='R'&&b=='R')||(b=='R'&&c=='R'))
        printf("2");
    else if(a=='R'||b=='R'||c=='R')
        printf("1");
    else
        printf("0");
    return 0;
}


Measured memory_bytes: 1548
#include <iostream>
using namespace std;
int findSum(int n){
	int sum=0;
	while(0<n){
		sum+=n%10;
		n/=10;
	}
	return sum;
}
int main() {
	int n,a,b;
	cin >>n>>a>>b;
	int total=0;
	for(int i=1;i<=n;++i){
		int sum=findSum(i);
		if(a<=sum && sum<=b){
			total+=i;
		}
	}
	cout <<total<<endl;
	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
    string s;
    getline(cin,s);
    string arr[] = {"abc","acb","bac","bca","cab","cba"};
    int n = sizeof(arr)/sizeof(arr[0]);
    bool flag = false;
    for(int i = 0 ; i < n ; i++){
        if(s == arr[i]){
            cout<<"Yes";
            flag = true;
        }
    }
    if(!flag){
        cout<<"No";
    }

}


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

int main(){
  int W, H;
  while(1){
    cin >> H >> W;
    cin.ignore();
    if((H == 0)&&(W == 0)){
      break;
    }
    else{
      for(int i = 0;i < W;i++){
	cout << "#";
      }
      cout << endl;
      for(int j = 0; j < (H-2);j++){
	for(int k = 0;k < W; k++){
	  if((k == 0)||(k == (W-1))){
	    cout << "#";
	  }else{
	    cout << ".";
	  }
	}
	cout << endl;
      }
      for(int l = 0;l < W; l++){
	cout << "#";
      }
      cout << endl;
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3056
# -*- coding: utf-8 -*-

import sys
import os
import math

N, M = map(int, input().split())

A = [0] * N
for i in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1

    A[a] += 1
    A[b] += 1

for i in range(N):
    print(A[i])

Measured memory_bytes: 3060