akhauriyash/Code-Regression huggingface dataset:
s = input()[::-1]

sum_of_digits = 0
cnts = [0]*2019
cnts[0] = 1

d = 1

for c in s:
    sum_of_digits += int(c) * d
    sum_of_digits %= 2019
    d *= 10
    d %= 2019
    cnts[sum_of_digits] += 1

ans = 0
for cnt in cnts:
    ans += cnt * (cnt - 1) // 2

print(ans)

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for_each(begin(a), end(a), [](auto &e) {
    cin >> e;
  });

  // a1 ^ a3 == a2
  // a2 ^ a4 == a3
  // a3 ^ a5 == a4
  // a2 ^ a3 ^ a5 == a3
  // a2 ^ a5 == 0
  // a2 == a5
  
  if (set<int>(begin(a), end(a)).size() == 1 && a[0] == 0) {
    puts("Yes");
    return 0;
  }

  if (N % 3) {
    puts("No");
    return 0;
  }

  sort(begin(a), end(a));
  bool ok = true;
  int tmp[3];
  for (int i = 0; i < N / 3; i++) {
    for (int j = 0; j < 3; j++) {
      const int index = i + (N / 3) * j;
      if (i == 0) {
        tmp[j] = a[index];
      } else {
        if (tmp[j] != a[index]) {
          ok = false;
        }
      }
    }
  }
  if (tmp[0] ^ tmp[1] ^ tmp[2]) {
    ok = false;
  }
  puts(ok ? "Yes" : "No");
}


Measured memory_bytes: 4224
# import sys
# sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

from math import ceil

n = II()
a = II()
b = II()
c = II()
d = II()
e = II()

def solve():
    print(4 + ceil(n / min([a, b, c, d, e])))



if __name__ == '__main__':
    solve()


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

int main() {
  int n;
  int ans = 0;
  cin >> n;
  
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    ans += b - a + 1;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int X[100005];
vector<pair<int,int>> G[100005];
bool used[100005];

vector<int> ans;
int dfs(int v) {
	used[v] = true;
	int res = X[v];
	for (pair<int,int> e : G[v]) {
		if (used[e.first]) continue;
		int r = dfs(e.first);
		if (r) ans.push_back(e.second);
		res ^= r;
	}
	return res;
}


int main() {
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>>A(N);
	for (int n = 0; n < N; ++n) {
		cin >> A[n].first >> A[n].second;
	}
	sort(A.begin(), A.end());
	//累積和てきなやつ
	X[0] = A[0].second;
	for (int n = 0;n < N - 1;++n) {
		X[n + 1] = A[n].second ^ A[n + 1].second;
	}
	X[N] = A[N - 1].second;

	for (int i = 0;i<M;++i) {
		int L,R;
		cin >> L >> R;
		L = lower_bound(A.begin(), A.end(), make_pair(L, 0)) - A.begin();
		R = upper_bound(A.begin(), A.end(), make_pair(R, 1)) - A.begin(); 
		G[L].emplace_back(R, i + 1);
		G[R].emplace_back(L, i + 1);
	}

	for (int i = 0;i < N + 1; ++i) {
		if (used[i]) {
			continue;
		}
		if (dfs(i)) {
			cout << "-1" <<endl;
			return 0;
		}
	}

	cout << ans.size()<<endl;
	sort(ans.begin(), ans.end());
	for (int n = 0;n<ans.size();++n) {
		if (0 != n) {
			cout << " ";
		}
		cout <<ans[n];
	}
	return 0;
}

Measured memory_bytes: 18996
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
typedef long long ll;

const ll INFT = 1000000000;

ll p[100000];
ll hi[101010];
ll lo[101010];
ll n;
ll k;
vector<int> graph[101010];
ll dep[101010];
void dfs(ll p, ll rt, ll d){
  dep[p]=d;
  for(ll q: graph[p]){
    if(q != rt){
      dfs(q,p,d+1);
      lo[p]=max(lo[p], lo[q]-1);
      hi[p]=min(hi[p],hi[q]+1);
    }
  }
}
void dfs2(ll p, ll rt){
  for(ll q : graph[p]){
    if(q!=rt){
      lo[q]=max(lo[q], lo[p]-1);
      hi[q]=min(hi[q],hi[p]+1);
      dfs2(q,p);
    }
  }
}


int main(){
  cin >> n ;
  for(ll i =0;i<n-1;i++){
    ll x,y;
    cin >> x>>y;
    --x;--y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  for(ll i=0;i<n;i++){
    p[i]=-INFT;
    lo[i]=-INFT;
    hi[i]=INFT;
  }
  cin >> k;
  for(ll i=0;i<k;i++){
    ll v,t;
    cin >> v;
    cin >> t;
    v--;
    lo[v]=hi[v]=p[v]=t;
  }


  dfs(0,-1,0);
  dfs2(0,-1);

  int par=-1;

  
  for(ll i =0;i<n;i++){
    if(p[i]!=-INFT){
      int myp = (p[i] ^ dep[i])& 1;
      if( par==-1) par=myp;
      if(par != myp){
	cout <<"No"<<endl;
	return 0;
      }
    }
    if(lo[i] > hi[i]){
      cout <<"No"<<endl;
      return 0;
    }
  }
  cout <<"Yes"<<endl;
  for(ll i =0;i<n;i++)
    cout <<lo[i]<<endl;
  
  
}


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


int main(){
    int n;
    cin >> n;
    vector<vector<int>> g(n,vector<int>(n,-1));
    rep(i,n){
        int m;
        cin >> m;
        rep(j,m){
            int x,y;
            cin >> x >> y;
            --x;
            g[i][x] = y; //i banme no hito no x ni taisuru syougen
        }
    }

    int ans = 0;
    rep(i,1<<n){
        vector<int> d(n);
        rep(j,n) if(i>>j &1) d[j]=1;
        bool check = true;
        rep(j,n){
            if(d[j]){
                rep(k,n){
                    if(g[j][k] == -1) continue; //syougenn nasi
                    if(g[j][k] != d[k]) check = false;
                }
            }
        }
        if (check) ans = max(ans,__builtin_popcount(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main()
{
	int a, b, c, ty = 0, hi = 0;
	char d;

	while(cin >> a >> d >> b >> d >> c){
		if((a*a + b*b) == c*c)
			ty++;
		if(a == b)
			hi++;
	}

	cout << ty << endl << hi << endl;

	return 0;
}

Measured memory_bytes: 1160
use std::io::stdin;
use std::str::FromStr;

fn main(){
    let n: usize = get_one();
    let xs: Vec<i64> = get_vec();

    let min_i = argmin(&xs);
    let max_i = argmax(&xs);

    println!("{}", 2 * n as i64 - 1);

    if xs[min_i].abs() > xs[max_i].abs() {
        for i in 0..n {
            println!("{} {}", min_i+1, i+1);
        }
        for i in (1..n).rev() {
            println!("{} {}", i+1, i);
        }
    } else {
        for i in 0..n {
            println!("{} {}", max_i+1, i+1);
        }
        for i in (1..n) {
            println!("{} {}", i, i+1);
        }
    }
}

fn argmin(v: &Vec<i64>) -> usize {
    let mut ans = 0;
    let mut m = v[0];
    for i in 1..v.len() {
        if v[i] < m {
            ans = i;
            m = v[i];
        }
    }
    return ans;
}

fn argmax(v: &Vec<i64>) -> usize {
    let mut ans = 0;
    let mut m = v[0];
    for i in 1..v.len() {
        if v[i] > m {
            ans = i;
            m = v[i];
        }
    }
    return ans;
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


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

const int MAX = 510000;
const int MOD = 1000000007;

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

long long 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() {

    COMinit();

  int s,t;
  cin >> s;
  t=0;
 for (int i=0; s-3*i>=0; i++){
      t += COM(s-2*i-1, i-1);
     t=t%1000000007;
  }
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 15560
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7

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

int main() {
    int n;
    cin >> n;
    vector<int> x(n);
    rep(i, 0, n) cin >> x[i];

    int ans = INT_MAX;
    rep(pos, 1, 101)
    {
        int cost = 0;
        rep(i, 0, n)
        {
            int diff = x[i] - pos;
            cost += diff * diff;
        }
        chmin(ans, cost);
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

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

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

int m;
vector<int> A;

void add(int a,int b){
  A[m-1+a]+=b;
  int j=(m-1+a)/2;
  while(j>=1){
    A[j]=A[2*j]+A[2*j+1];
    j/=2;
  }  
}

int getsum(int a,int b,int k,int l,int r){
  if(b<=l || r<=a) return 0;
  else if(a<=l && b>=r) return A[k];
  else{
    int c1=getsum(a,b,2*k,l,(l+r)/2);
    int c2=getsum(a,b,2*k+1,(l+r)/2,r);
    return c1+c2;
  }
}         

int main(){
  int n,q;
  cin>>n>>q;
  
  m=1;
  while(m<n){
    m*=2;
  }
  
  A=vector<int>(2*m,0);
  
  int c,x,y;
  rep(i,q){
    cin>>c>>x>>y;
    if(c==0) add(x,y);
    else if(c==1) cout<<getsum(x,y+1,1,1,m+1)<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3892
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    odd = 0
    for i in a:
        if i%2 == 1:
            odd += 1
    if odd%2 == 0:
        print('YES')
    else:
        print('NO')


if __name__ == '__main__':
    main()

Measured memory_bytes: 14420
#include "bits/stdc++.h"

using namespace std;

int main() {
	int N,K;
	cin >> N >>K;
	long long nAns = K;
	for (int n = 1; n <N;++n) {
		nAns *= (K - 1);
	}
	cout << nAns << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
x = list(map(int,input().split()))
x = sorted(x)
m = 10**20
for p in range(x[0],x[n-1]+1):
    power = 0
    for i in range(n):
        power += (x[i]-p)**2
    m = min(m,power)
print(m)

Measured memory_bytes: 3060
#include<iostream>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<limits.h>
#include<utility>
#include<vector>
#include<tuple>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define ALL(A) A.begin(),A.end()
bool comparator(P a, P b) {
	return a.first / a.second < b.first / b.second;
}

int main() {
	int s, w;
	cin >> s >> w;
	if (s <= w) {
		cout << "unsafe" << endl;
		return 0;

	}
	cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3128
def f a, sgn
	s = 0
	t = 0
	r = sgn <=> 0
	a.each{|x|
		s += x
		if r * s <= 0
			t += (r - s).abs
			s = r
		end
		r *= -1
	}
	t
end

gets
a = gets.split.map(&:to_i)
puts [f(a, 1), f(a, -1)].min


Measured memory_bytes: 8580
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;
int main() {
  ll H;
  cin >> H;
  ll N = floor(log2(H));
  cout << (ll)pow(2, N+1)-1 << endl;
  return 0;
}


Measured memory_bytes: 512
w, x = input().split(" ")
a = int(w)
b = int(x)

def compute_gcd(x, y):
   while(y):
       x, y = y, x % y
   return x

def compute_lcm(x, y):
   lcm = (x*y)//compute_gcd(x,y)
   return lcm

print(compute_lcm(a, b))


Measured memory_bytes: 2940
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 1e5+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

int head[maxn], cnt, n;
bool vis[maxn];
ll dp[maxn];

struct edge
{
    int v, nxt;
} Edge[maxn];

void init()
{
    for(int i = 0; i <= n; i++)
        head[i] = -1;
    cnt = 0;
}

void addedge(int u, int v)
{
    Edge[cnt].v = v;
    Edge[cnt].nxt = head[u];
    head[u] = cnt++;
}

void dfs(int id)
{
    if(vis[id])
        return;
    vis[id] = true;
    for(int i = head[id]; i != -1; i = Edge[i].nxt)
    {
        int v = Edge[i].v;
        dfs(v);
        dp[id] = max(dp[id], dp[v] + 1);
    }
}

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    int m, u, v;
    scanf("%d%d", &n, &m);
    init();

    for(int i = 1; i <= m; i++)
    {
        scanf("%d%d", &u, &v);
        addedge(u, v);
    }

    for(int i = 1; i <= n; i++)
    {
        if(!vis[i])
            dfs(i);
    }

    ll answer = 0;
    for(int i = 1; i <= n; i++)
        answer = max(answer, dp[i]);

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

    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  string front = S.substr(0,2);
  string end = S.substr(2, 2);
  bool yy=false, mm=false;

  if(stoi(front)<=12 && stoi(front)>0){
    mm = true;
  }
  if(stoi(end)<=12 && stoi(end)>0){
    yy = true;
  }
  if(yy && mm){
    cout << "AMBIGUOUS" << endl;
  }
  else if(yy || mm) {
    if(yy)cout << "YYMM"<< endl;
    if(mm)cout << "MMYY" << endl;
  }
  else{
    cout << "NA" << endl;
  }
  return 0;
}


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

int main() {
    int phase, n, k;
    cin >> phase;
    for(int i = 0; i < phase; i++)
    {
        int length = 0;
        cin >> n >> k;
        int x[n];
        for(int j = 0;j<n;j++)
            cin >> x[j];
        if(n > 1 || n <= k)
        {
            int distance[n-1];
            for(int j = 0;j<n-1;j++)
            {
                distance[j] = x[j+1] - x[j];
            }
            sort(distance, distance+(n-1));
            int m = distance[0];
            m = 0;
            
            for(int j = 0; j<n-k;j++)
                length += distance[j];
        }

    
        cout << length << endl;
    }
        
    return 0;
}

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

using namespace std;

const int MAX_N = 605;

int evenp (int d) {
  int ans = 0;
  while (d % 2 == 0) {
    ans++;
    d /= 2;
  }
  return ans;
}

bool fits (int x, int y, int d) {
  if (d % 2 == 0) {
    int pd = 1 << (d / 2);
    return (x / pd + y / pd) % 2 == 0;
  } else {
    int pd = 1 << ((d - 1) / 2);
    return (x / pd) % 2 == 0;
  }
}

int main () {
  ios::sync_with_stdio(false);

  int n, d1, d2;
  cin >> n >> d1 >> d2;

  d1 = evenp(d1);
  d2 = evenp(d2);

  vector<pair<int, int>> ans;
  for (int i = 0; i < 2 * n; i++) {
    for (int j = 0; j < 2 * n; j++) {
      if (fits(i, j, d1) && fits(i, j, d2)) {
        ans.push_back(make_pair(i, j));
      }
    }
  }

  while ((int) ans.size() > n * n) {
    ans.pop_back();
  }

  for (auto pr : ans) {
    cout << pr.first << " " << pr.second << '\n';
  }
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class A { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		WriteLine(GetLong() ^ 1);
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


Measured memory_bytes: 27368
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
int fg(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
signed main(){
 int a;
 string b;
 cin>>a>>b;
   if(b.size()<=a){
    cout<<b;
   }
  else{
    rep(i,a){
     cout<<b.at(i);
    }
    cout<<"...";
  }
}
    

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

void print(string s){
	static const string t("apple");
	static const string t2("peach");
	string::iterator iter = search(s.begin(), s.end(), t.begin(), t.end());
	string::iterator iter2 = search(s.begin(), s.end(), t2.begin(), t2.end());
	if(iter != s.end()){
		for(string::iterator it = s.begin(); it != s.end(); it++){
			if(it == iter){
				cout << t2;
				it += 4;
			}else{
				cout << *it;
			}
		}
	}else if(iter2 != s.end()){
		for(string::iterator it = s.begin(); it != s.end(); it++){
			if(it == iter2){
				cout << t;
				it += 4;
			}else{
				cout << *it;
			}
		}
	}else{
		cout << s;
	}
}

int main(){
	vector<string> vs;
	string s;
	while(cin >> s) vs.push_back(s);
	for(vector<string>::size_type i = 0; i < vs.size(); i++){
		if(i != 0) cout << " ";
		print(vs[i]);
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  char s[n+1];
  cin >> s;
  int a[n],d[n];
  if(s[0]=='W')a[0]=1;
  else a[0]=0;
  for(int i=1;i<n;i++){
    a[i]=a[i-1];
    if(s[i]=='W')a[i]++;
  }
  if(s[n-1]=='E')d[n-1]=1;
  else d[n-1]=0;
  for(int i=n-2;i>-1;i--){
    d[i]=d[i+1];
    if(s[i]=='E')d[i]++;
  }
  int p=400000;
  for(int i=0;i<n;i++){
    if(i==0&&p>d[1])p=d[1];
    else if(i==n-1&&p>a[n-2])p=a[n-2];
    else{
      if(p>a[i-1]+d[i+1])p=a[i-1]+d[i+1];
    }
  }
  cout << p << endl;
}


Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		String s = scan.next();
		String t = scan.next();
		
		String ans = "";
		for (int i = 0; i < n; i++) {
			ans = ans.concat(s.substring(i, i + 1)).concat(t.substring(i, i + 1));
		}
		
		System.out.println(ans);
	
	}
}

Measured memory_bytes: 23760
import java.util.Scanner;

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

    int ans = 0;
    for(int i = 1; i <= N; i+=2){
      int count = 0;
      for(int j = 1; j <= i; j++){
        if(i % j == 0){
          count++;
        }
      }
      if(count == 8){
        ans++;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 21844
from collections import Counter

input()
values = tuple(map(int, input().split(' ')))
counter = Counter(values)

max_count = 0
best_x = None

for x in counter:
    count = counter[x - 1] + counter[x] + counter[x + 1]
    if count > max_count:
        max_count = count
        best_x = x

print(max_count)


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n;
  cin >> n;
  if (n == 0)
  {
    cout << 0;
    return;
  }
  string ans = "";
  while(n != 0)
  {
    ans += (n % 2 == 0 ? '0' : '1');
    n -= (n % 2 == 0 ? 0 : 1);
    n /= -2;
  }
  reverse(ans.begin(), ans.end());
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

int int_len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}

int int_sum(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}

int main() {
  int a,b,c;
  cin>>a>>b>>c;
  if(min(a,b)<=c && c<=max(a,b)){ 
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <climits>
#define ll long long

using namespace std;

int findlcs(vector<vector<int> >& b,string& sol,int ps,int pt,string& s,string& t){
  if( ps == 0 || pt == 0 ) return 0 ;
  if(b[ps][pt] == 1){
    findlcs(b,sol,ps-1,pt-1,s,t);
    sol.push_back(s[ps-1]);
    return 0;
  }
  else if( b[ps][pt] == 2 ){
    findlcs(b,sol,ps-1,pt,s,t);
  }
  else{
    findlcs(b,sol,ps,pt-1,s,t);
  }
  return 0;
}
string lcs( string& s , string& t ){
  int ret = 0;
  int ls = s.size();
  int lt = t.size();
  vector<vector<int> >  dp(ls + 1 , vector<int>( lt + 1 , 0 ));//record the value
  vector<vector<int> >  b(ls + 1 , vector<int>( lt + 1 , 0 ));//record the solution
  for( int i = 0 ; i < ls ; i++ ){
    for( int j = 0 ; j < lt ; j++ ){
      int ps = i + 1;
      int pt = j + 1;

      if( s[i] == t[j] ){
        dp[ps][pt] = max( dp[ps][pt] , dp[ps-1][pt-1] + 1 );
        b[ps][pt] = 1;
      }
      else if( dp[ps-1][pt] >= dp[ps][pt-1]  ){
        dp[ps][pt] = dp[ps-1][pt];
        b[ps][pt] = 2;
      }
      else{
        dp[ps][pt] =  dp[ps][pt-1];
        b[ps][pt] = 3;
      }
    }
  }
  string sol = "";
  findlcs(b,sol,ls,lt,s,t);
  return sol;
}
int main(){
  string s,t;
  cin >> s >> t;
  string ret = lcs(s,t);
  cout << ret << endl;
  return 0;
}


Measured memory_bytes: 71040
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define E 1e-6;
void open()
{
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
}

int h,w;
int n;
int a[10005];
int maps[105][105];
int c;
/*void paint(int i,int j)
{
    if(maps[i][j]!=0) return;
    if(a[c]==0) return;
    maps[i][j]=c;
    a[c]--;
    if(j+1<w) paint(i,j+1);
    if(i-1>=0) paint(i-1,j);
    if(i+1<h) paint(i+1,j);
    if(j-1>=0) paint(i,j-1);
}
*/
int main()
{
    while(~scanf("%d%d",&h,&w))
    {
        memset(a,0,sizeof(a));
        memset(maps,0,sizeof(maps));
        scanf("%d",&n);
        rep(i,1,n+1) scanf("%d",&a[i]);
        c=1;
        /*for(int j=0;j<w;j++)
        {
            for(int i=0;i<h;i++)
            {
                if(maps[i][j]!=0) continue;
                paint(i,j);
                c++;
            }
        }*/

        int num[100005];
        int t=1;
        for(int i=1;i<=n;i++)
        {
            for(int j=0;j<a[i];j++)
            {
                num[t++]=i;
            }
        }
        int i,j,cnt;
        cnt = maps[i = 1][j = w] = num[1];//赋初值，方向为：右->左
        while(cnt<h*w)
        {
            while(i<h && !maps[i+1][j]) maps[++i][j] = num[++cnt];//下
            while(j>1 && !maps[i][j-1]) maps[i][--j] = num[++cnt];//左
            while(i>1 && !maps[i-1][j]) maps[--i][j] = num[++cnt];//上
            while(j<w && !maps[i][j+1]) maps[i][++j] = num[++cnt];//右
        }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
vector<vector<ll> >G(200010);
vector<ll>color(200010);
void dfs(ll i,ll p,ll c){
    color[i]=c;
    for(auto e:G[i]){
        if(e==p)continue;
        dfs(e,i,1-c);
    }
}
signed main(){
    ll n;cin>>n;
    rep(i,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    dfs(0,-1,0);
    ll B=0,W=0;
    rep(i,n){
        if(color[i])B++;
        else W++;
    }
    ll a=n/3,b=n/3,c=n/3;
    if(n%3==1)a++;
    else if(n%3==2){
        a++,b++;
    }
    vector<ll>ans(n,-1);
    ll now=0;
    //cout<<B<<' '<<W<<' '<<a<<' '<<b<<' '<<c<<endl;
    if(c>=B){
        rep(i,n){
            if(color[i]==1&&ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(c==0)break;
            if(ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(a==0)break;
            if(ans[i]==-1){
                ans[i]=a*3-2;
                a--;
            }
        }
        rep(i,n){
            if(b==0)break;
            if(ans[i]==-1){
                ans[i]=b*3-1;
                b--;
            }
        }
    }else if(c>=W){
        rep(i,n){
            if(color[i]==0&&ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(c==0)break;
            if(ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(a==0)break;
            if(ans[i]==-1){
                ans[i]=a*3-2;
                a--;
            }
        }
        rep(i,n){
            if(b==0)break;
            if(ans[i]==-1){
                ans[i]=b*3-1;
                b--;
            }
        }
    }else{
        rep(i,n){
            if(b==0)break;
            if(color[i]==0&&ans[i]==-1){
                ans[i]=b*3-1;
                b--;
            }
        }
        rep(i,n){
            if(c==0)break;
            if(color[i]==0&&ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(c==0)break;
            if(ans[i]==-1){
                ans[i]=c*3;
                c--;
            }
        }
        rep(i,n){
            if(a==0)break;
            if(ans[i]==-1){
                ans[i]=a*3-2;
                a--;
            }
        }
        rep(i,n){
            if(b==0)break;
            if(ans[i]==-1){
                ans[i]=b*3-1;
                b--;
            }
        }
    }
    rep(i,n){
        cout<<ans[i]<<' ';
    }
    cout<<endl;
}

Measured memory_bytes: 20608
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
const ll LINF = 1e18;

int main()
{
  string S; cin >> S;
  ll ans = 0;
  for (int i = 0; i < S.size(); i++) {
    ans += S[i]-'0';
  }

  {
    ll sum = 0;
    sum += max(0, S[0]-'0'-1);
    sum += (S.size()-1)*9;
    ans = max(ans, sum);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <vector>
#include <iostream>
#include <ctime>
#include <unistd.h>

using namespace std;

#define TRACE(x) cerr << #x <<  " = " << x << endl
#define _ << " " <<
#define FOR(i, a, b) for (int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)

#define X first
#define Y second

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

const int MOD = 1e9 + 7;

int add(int a, int b) {
  a += b;
  if (a >= MOD) a -= MOD;
  return a;
}

int mul(int a, int b) {
  return (int) (((ll) a * b) % MOD);
}

int sub(int a, int b) {
  a -= b;
  if (a < 0) a += MOD;
  return a;
}

int inv(int a) {
  int r=1;
  for (int e=MOD-2; e; e/=2, a = mul(a, a))
    if (e & 1)
      r = mul(r, a);

  return r;
}

const int MAX = 2005;

int fak[4*MAX], invfak[4*MAX];

void gen() {
  fak[0] = invfak[0] = 1;
  FOR(i, 1, 4*MAX) {
    fak[i] = mul(fak[i-1], i);
    invfak[i] = inv(fak[i]);
  }  
}

int povrh(int a, int b) {
  if (b < 0 || a < b) return 0;
  return mul(fak[a], mul(invfak[b], invfak[a-b]));
}

int dp[MAX][MAX], g[MAX][MAX];
int pot2[4*MAX];
int prefpov[MAX][MAX];

int rek(int A, int B) {
  assert(min(A, B) >= 0);
  if (dp[A][B] != -1) return dp[A][B];
  int ret=0;

  if (!A || !B) return 1;

  ret = rek(A-1, B);
  REP(k, min(A+1, B)) {
    int tmp = povrh(B-1, k);
    if (!tmp) continue;
    ret = add(ret, mul(tmp, g[A-k][k]));
  }

  //  TRACE(A _ B _ ret);
  return dp[A][B] = ret;
}

int main()
{
  pot2[0] = 1;
  FOR(i, 1, 4*MAX)
    pot2[i] = mul(pot2[i-1], 2);    
  
  gen();

  REP(i, MAX) {
    REP(j, i+1) {
      if (j) prefpov[i][j] = prefpov[i][j-1];
      prefpov[i][j] = add(prefpov[i][j], povrh(i, j));
      // if (i < 5 && j < 5)
      // 	TRACE(i _ j _ prefpov[i][j]);
    }
  }

  g[0][0] = 1;
  REP(A, MAX) {
    REP(B, MAX) {
      if (!A || !B) {
	g[A][B] = 1;
	continue;
      }

      g[A][B] = add(g[A-1][B], prefpov[B-1][min(B-1, A)]);

      //  if (A < 5 && B < 5) TRACE(A _ B _ g[A][B]);
    }
  }

  int A, B;
  scanf("%d%d", &A, &B);
  memset(dp, -1, sizeof dp);
  printf("%d\n", rek(A, B));

  return 0;
}


Measured memory_bytes: 46720
s=int(input())
c=0
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))
if s - int(s/10)*10 ==2:
    c=c+1
s=int(int(s/10))

print(c)

Measured memory_bytes: 3064
#include<iostream>
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
using namespace std;
int main()
{
    fastio;
    long long n,i,val;
    map<long long, long long> mp;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>val;
        if(mp.find(val)==mp.end())
        {
            mp[val]=1;
        }
        else
        {
            mp.erase(val);
        }
    }
    cout<<mp.size();
    return 0;
}


Measured memory_bytes: 9852
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl
#define show2(a, n, m) rep(i, n) { rep(j, m) {cout << a[i][j] << ' ';} cout << endl;} 
#define chmin(a, b) a = min(a, b)
#define chmax(a, b) a = max(a, b)

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const int INF = 1 << 30;
const long long INFL = 1LL << 60;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

vector<vi> g;
vi dp;

int main() {
//	cout << fixed << setprecision(15);
	int n, m;
	cin >> n >> m;

	vector<vi> g = vector<vi>(n);
	vi deg(n);
	rep(i, m) {
		int x, y;
		cin >> x >> y;
		x--, y--;
		g[x].push_back(y);
		deg[y]++;
	}

	queue<int> q;
	rep(i, n) if(deg[i] == 0) q.push(i);

	vi dp(n);
	while(!q.empty()) {
		int i = q.front();
		q.pop();
		for(auto j: g[i]) {
			deg[j]--;
			if(deg[j] == 0) {
				dp[j] = dp[i] + 1;
				q.push(j);
			}
		}
	}

	int ans = 0;
	rep(i, n) chmax(ans, dp[i]);
	cout << ans << endl;
}


Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<algorithm>

using namespace std;

int x, y;

int main(){
	scanf("%d%d", &x, &y);
	if(y % 2 != 0){
		printf("No\n");
		return 0;
	}
	int k = y - (x * 2);
	if(k < 0){
		printf("No\n");
		return 0;
	}
	int ans = k - (x * 2);
	if(ans > 0){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	return 0;
}

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

int main() {
  long long int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  for (int i; i < N; i++) {
    int a;
    cin >> a;
    q.push(a);
  }
  for (int i = 0; i < M; i++) {
    int t = q.top();
    t /= 2;
    q.pop();
    q.push(t);
  }
  long long int sum = 0;
  for (int i = 0; i< N; i++) {
    sum += q.top();
    if (q.top() == 0) {
      break;
    }
    q.pop();
  }
  cout << sum <<endl;
}

Measured memory_bytes: 892
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	if ((a - b) % 2 == 0) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Borys" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n, k;
  int r;
  int d;
  double s = 0.0;
  int i;
  scanf("%d %d", &n, &k);
  if ( n >= k ) {
    s += (double)(n - k + 1) / n;
  }
  for ( i = 1; i <= n && i < k; i++ ) {
    r = i;
    d = 1;
    while ( r < k ) {
      d *= 2;
      r = i * d;
    }
    s += 1.0 / (n * d);
  }
  printf("%.12f", s);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
using namespace std;
using P = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = 998244353;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    string s;
    cin >> n >> s;
    if (n % 2) {
        cout << "No" << "\n";
        return 0;
    }
    for (int i = 0; i < n / 2; i++) {
        if (s[i] != s[i + n / 2]) {
            cout << "No" << "\n";
            return 0;
        }
    }
    cout << "Yes" << "\n";
    return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
from collections import Counter
def resolve():
    n = int(input())
    C = Counter(map(int, input().split()))
    total = 0
    for key, val in C.items():
        total += key * val

    for _ in range(int(input())):
        b, c = map(int, input().split())
        k = C[b]
        total += k * (c - b)
        C[b] = 0
        C[c] += k
        print(total)
resolve()

Measured memory_bytes: 88408
(N,M) = map(int,input().split())
H = list(map(int,input().split()))
L = [[]for i in range(N)]

for i in range(M):
    (A,B)=map(int,input().split())
    L[A-1].append(B)
    L[B-1].append(A)


count = 0
for i in range(N):
    flag = 0
    for j in range(len(L[i])):
        if H[i] <= H[L[i][j]-1]:
            flag = 1
            break
    if flag == 0:
        count += 1
print(count)

Measured memory_bytes: 29464
from itertools import permutations
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
p=[i for i in range(1,n+1)]
np=list(permutations(p))
edge=[[] for i in range(n)]
for i in range(m):
  edge[l[i][0]-1].append(l[i][1]-1)
  edge[l[i][1]-1].append(l[i][0]-1)
ans=0
for i in range(len(np)):
  if np[i][0]!=1:
    continue
  else:
    ok=True
    for j in range(n-1):
      if np[i][j]-1 not in edge[np[i][j+1]-1]:
        ok=False
    if ok:
      ans+=1
print(ans)

Measured memory_bytes: 8052
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int h[105];

  cin >> n;
  while(n != 0){
    for(int i = 0;i <= n;i++){
      cin >> h[i];
    }

    int diff = h[1] - h[0];
    int cnt = 0;
    int p;
    int ans;
    
    for(int i = 0;i < n;i++){
      if(h[i + 1] - h[i] != diff){
	ans = h[i + 1];
	p = i;
	cnt ++;
      }
    }

    if(cnt > 2){
      diff = h[n] - h[n - 1];
      if(h[2] - h[1] == diff){
	ans = h[0];
      }else{
	ans = h[1];
      }
    }else{
      if(p < n){
	if(diff != h[p] - h[p - 1]){
	  ans = h[p];
	}else{
	  ans = h[p + 1];
	}
      }else{
	if(diff != h[p - 1] - h[p - 2]){
	  ans = h[p - 1];
	}else{
	  ans = h[p];
	}
      }
    }

    cout << ans << endl;
    cin >> n;
  }
  
  return 0;
}




Measured memory_bytes: 3136
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
using namespace std;
 
//conversion
//------------------------------------------
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();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;



int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	int a,b,c,d;
	a = n/1000; n-=a*1000;
	b = n/100; n -=b*100;
	c = n / 10; n -=c*10;
	d = n;

	if(a == b && b ==c){cout << "Yes" << endl; return 0;}
	// if(a == b && b ==d){cout << "Yes" << endl; return 0;}
	// if(a == c && c ==d){cout << "Yes" << endl; return 0;}
	if(b == c && c ==d){cout << "Yes" << endl; return 0;}
	cout <<"No"<<endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t,p;
bool ch(int x){
  set<vector<int> >v;
  vector<int>y(26,0);

  for(int i=0;i+x<=s.size();i++){
    if(!i)for(int j=0;j<x;j++)y[s[j]-'a']++;
    else y[s[i+x-1]-'a']++,y[s[i-1]-'a']--;
      v.insert(y);
    }
  for(int i=0;i<26;i++)y[i]=0;
  for(int i=0;i+x<=t.size();i++){
    if(!i)for(int j=0;j<x;j++)y[t[j]-'a']++;
    else y[t[i+x-1]-'a']++,y[t[i-1]-'a']--;
      if(v.count(y))return 1;
    }
  return 0;
}
int main(){
  cin>>s>>t;
  int sum=min((int)s.size(),(int)t.size());
  while(!ch(sum))sum--;
  cout<<sum<<endl;
}

Measured memory_bytes: 3808
from sys import stdin

def main():
    input = stdin.readline
    n = int(input())
    a = [0] + list(map(int, input().split()))
    for i in range(n, 0, -1):
        a[i] = sum(a[i::i]) % 2
    print(sum(a))
    for i in range(1, n + 1):
        if a[i] == 1:
            print(i)
main()

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

using namespace std;

const int N_ = 100500;

int N, M;
int A[N_];

long long S[N_], T[N_];

void add(long long *arr, int s, int e, long long v) {
  arr[s] += v;
  arr[e+1] -= v;
}

int main() {
#ifdef IN_MY_COMPUTER
  freopen("e.in", "r", stdin);
#endif
  scanf("%d%d", &N, &M);
  for(int i = 1; i <= N; i++) scanf("%d", &A[i]), A[i] -= 1;

  for(int i = 2; i <= N; i++) {
    int a = A[i-1], b = A[i];

    int d = (b - a + M) % M;

    int p = (b - d + 1 + M) % M;
    
    if(p <= b) {
      add(T, 0, p-1, d);
      add(S, p, b, -1);
      add(T, p, b, b+1);
    }else {
      add(S, 0, b, -1);
      add(T, 0, b, b+1);
    }

    if(p <= b) {
      add(T, b+1, M-1, d);
    }else {
      add(T, b+1, p, d);

      add(S, p+1, M-1, -1);
      add(T, p+1, M-1, M+b+1);
    }
  }

  long long ans = 1e18;
  for(int i = 0; i < M; i++) {
    if(i > 0) {
      S[i] += S[i-1];
      T[i] += T[i-1];
    }
    ans = min(ans, S[i] * i + T[i]);
  }

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

Measured memory_bytes: 2176
#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}

 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
 
  long long x = 1;
 
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long, long long>;

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

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

  ll n;
  std::cin>>n;

  std::vector<long double> a(n);
  rep(i,0,n)std::cin>>a[i];

  long double sum=0;

  rep(i,0,n)sum+=a[i];

  sum/=(long double)n;

  long double min=1e9;

  rep(i,0,n)chmin(min,std::abs(a[i]-sum));

  rep(i,0,n){
    if(std::abs(a[i]-sum)==min){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  return 0;
}

Measured memory_bytes: 256
import math

pi = math.pi

n = int(input())
p1 = [0,0]
p2 = [100,0]

def koch(n, p1, p2):
    if n == 0:
        return
    s = [(2*p1[0]+p2[0])/3.0,(2*p1[1]+p2[1])/3.0]
    t = [(1*p1[0]+2*p2[0])/3.0,(p1[1]+2*p2[1])/3.0]
    u = [(t[0]-s[0])*math.cos(pi/3) - (t[1]-s[1])*math.sin(pi/3) + s[0], 
         (t[0]-s[0])*math.sin(pi/3) + (t[1]-s[1])*math.cos(pi/3) + s[1]]
         

    koch(n - 1, p1, s)
    print(*s)
    koch(n - 1, s, u)
    print(*u)
    koch(n - 1, u, t)
    print(*t)
    koch(n - 1, t, p2)

print(*p1)
koch(n, p1, p2)
print(*p2)


Measured memory_bytes: 5804
fn main() {
    let mut s = String::new();
    let mut t = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    std::io::stdin().read_line(&mut t).unwrap();

    let s = s.trim().chars();
    let mut t = t.trim().chars();

    let mut cnt = 0;

    for i in s{
        let tmps = i;
        let tmpt = t.next().unwrap();
        if tmps == tmpt{
            cnt += 1;
        }
    }
    println!("{}", cnt);
}


Measured memory_bytes: 4476