akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define for0(i, n) for (int i = 0; i < (int)(n); ++i) 
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) 
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i)
#define deb(x) cout << #x << "= " << x << endl
#define pb push_back
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define tr(x) for(auto it = x.begin(); x != x.end(); it++)
#define fast ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define MOD 1000000007

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
	fast;
    int t=1;
    while(t--){
        //begin code here
        int s,t,d;
        cin >> d>>t>>s;
        if(s*t>=d){
            cout << "Yes\n";
        }
        else{
            cout << "No\n";
        }
    }
}

Measured memory_bytes: 3648
def main():
    N = int(input())
    S = list(input().rstrip())
    ans = []
    for s in S:
        if ord(s) + N > 90:
            ans.append(chr(ord(s) + N - 26))
        else:
            ans.append(chr(ord(s) + N))
    print("".join(ans))


if __name__ == '__main__':
    main()


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

int main() {
 unordered_map<int,int> m1,m2;
  int n,ans=0,x[8]={0};
  cin >> n;
  r(i,n){
    int a;
    cin >> a;
    if(i%2==0)m1[a]++;
    else m2[a]++;
  }
  for(auto it1=m1.begin();it1!=m1.end();it1++){
    if((*it1).second>x[1]){
      x[1]=(*it1).second;
      x[0]=(*it1).first;
    }
  }
  for(auto it2=m2.begin();it2!=m2.end();it2++){
    if((*it2).second>x[3]){
      x[3]=(*it2).second;
      x[2]=(*it2).first;
    }
    }
  m1[x[0]]=0;
  m2[x[2]]=0;
  for(auto it1=m1.begin();it1!=m1.end();it1++){
    if((*it1).second>x[5]){
      x[5]=(*it1).second;
      x[4]=(*it1).first;
    }
  }
  for(auto it2=m2.begin();it2!=m2.end();it2++){
    if((*it2).second>x[7]){
      x[7]=(*it2).second;
      x[6]=(*it2).first;
    }
    }
  if(x[0]!=x[2])cout<<n-x[1]-x[3]<<endl;
  else cout << min(n-x[5]-x[3],n-x[7]-x[1])<<endl;
}


Measured memory_bytes: 4376
import sys
input = sys.stdin.readline
N, M = [int(i) for i in input().split()]
H = [int(i) for i in input().split()]
al = [[] for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    A -= 1
    B -= 1
    al[A].append(B)
    al[B].append(A)
ans = 0
for i in range(len(al)):
    h = H[i]
    for a in al[i]:
        if h <= H[a]:
            break
    else:
        ans += 1
print(ans)

Measured memory_bytes: 89248
#include <bits/stdc++.h>
// https://boostjp.github.io/tips/multiprec-int.html
// https://boostjp.github.io/tips/multiprec-float.html
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

using namespace std;

#define ll long long
const int MOD = 1e9 + 7;
#define INF 2e9

#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

#define MATCH(_str, _ptn) regex_match(_str, regex(_ptn))
#define REPLACE(_str, _ptn, _replacement) regex_replace(_str, regex(_ptn), _replacement)

# define pb push_back

# define INIT() cin.tie(0); ios::sync_with_stdio(false); cout << fixed << std::setprecision(20)

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

ll n,m,k,d,t,s;
int main() {
    INIT();

    cin >> d >> t >> s;
    cout << (d <= t * s ? "Yes" : "No");
}

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

using namespace std;

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

const int SIZE = 11 + 1;
//const int ASIZE = 200 + 10;

int mps[SIZE][SIZE] = {0};

//int as[ASIZE][ASIZE] = 0;

void floyd()
{
    for (int k = 0; k <= 9; k++)
        for (int i = 0; i <= 9; i++)
            for (int j = 0; j <= 9; j++)
                mps[i][j] = min(mps[i][j], mps[i][k] + mps[k][j]);
}

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

    int h, w;
    int res = 0;
    int t;

    cin >> h >> w;
    for (int i = 0; i <= 9; i++)
        for (int j = 0; j <= 9; j++)
            cin >> mps[i][j];

    floyd();

    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            cin >> t;
            if (t == -1 || t == 1)
                continue;
            res += mps[t][1];
        }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
// Problem : D - Teleporter
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
#define int long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
signed main(){
    fast;
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i = 1;i<=n;i++)
        cin>>a[i];
    int vis[n+1] = {};
    vector<int> path;
    int cur = 1;
    path.push_back(1);
    vis[1] =1;
    int cnt = 0;
    int last;
    while(1){
        cur = a[cur];
        if(vis[cur]){
            last = cur;
            break;
        }
        cnt++;
        if(cnt<=k){
            path.push_back(cur);
            vis[cur] = 1;
        }
        else break;
    }
    cnt = path.size();
    cnt--;
    if(k<=cnt){
        cout<<path[k];
    }
    else{
        int idx = 0;
        while(path[idx]!=last){
            k--;
            idx++;
        }
        cnt = (int)path.size() - idx;
        k = k%cnt;
        cout<<path[k+idx];
    }
}


Measured memory_bytes: 8464
n = int(input())
work = [None] * n
for i in range(n):
    work[i] = tuple(map(int, input().split()))
work = sorted(work, key=lambda x: x[1])
t = 0
f = True
for i, w in enumerate(work):
    t += w[0]
    if t > w[1]:
        f = False
        break
if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 33436
///
// File:  c.go
// Author: ymiyamoto
//
// Created on Wed May 30 22:17:54 2018
//
package main

import "fmt"

var H, W int

func main() {
	fmt.Scan(&H, &W)

	m := map[uint8]int{}
	for i := 0; i < H; i++ {
		var s string
		fmt.Scan(&s)
		for j := range s {
			m[s[j]]++
		}
	}

	counts := make([]int, 0)
	for _, v := range m {
		counts = append(counts, v)
	}

	var g4, g2, g1 int
	g4 = (H / 2) * (W / 2)
	if H%2 == 1 {
		g2 += W / 2
	}
	if W%2 == 1 {
		g2 += H / 2
	}
	if H%2 == 1 && W == 1 {
		g1 = 1
	}

	// fmt.Println(counts)
	// fmt.Println(g4, g2, g1)
	for g4 > 0 {
		var found bool
		for i := range counts {
			if counts[i] >= 4 {
				counts[i] -= 4
				g4--
				found = true
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}

	for g2 > 0 {
		var found bool
		for i := range counts {
			if counts[i] >= 2 {
				counts[i] -= 2
				g2--
				found = true
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}

	for g1 > 0 {
		var found bool
		for i := range counts {
			if counts[i] >= 1 {
				counts[i]--
				g1--
				found = true
			}
		}
		if !found {
			fmt.Println("No")
			return
		}

	}
	fmt.Println("Yes")
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var HWK = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (H, W, K) = (HWK[0], HWK[1], HWK[2]);
        var c = new int[6, 6];

        for (int i = 0; i < H; i++)
        {
            var l = ReadLine();
            for (int j = 0; j < W; j++)
            {
                if (l[j] == '#')
                    c[i, j] = 1;
            }
        }

        var ans = 0;
        for (int p = 0; p < (1 << (H + W)); p++)
        {
            var count = 0;

            for (int i = 0; i < H; i++)
            {
                if((p & (1 << (i + W))) != 0)
                {
                    continue;
                }
                for (int j = 0; j < W; j++)
                {
                    if((p & (1 << (j))) != 0)
                    {
                        continue;
                    }

                    if(c[i, j] == 1)
                    {
                        count++;
                    }
                }
            }

            if (count == K)
                ans++;
        }

        WriteLine(ans);
    }
}


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

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()

#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000

#define PB push_back
#define MP make_pair
#define F first
#define S second

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

using graph = vector<vector<pair<int,int>>>;

vector<int> color;
void dfs(const graph &g, int v,int cur) {

    color[v] = cur;

    for (auto next_v : g[v]) {
    	if(color[next_v.F]==-1){
    		if(next_v.S%2){
    			dfs(g,next_v.F,!cur);
    		}
    		else{
    			dfs(g,next_v.F,cur);
    		}
    		continue;
    	}
    }
}

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

    graph g(n);
    REP(i,n-1) {
        int a,b,c;
        cin >> a >> b >>c;
        a--;
        b--;
        g[a].push_back(MP(b,c));
        g[b].push_back(MP(a,c));
    }


    color.assign(n,-1);
    dfs(g,0,0);
    REP(i,n)cout<<color[i]<<endl;
}


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

int main()
{
    
    string s1;
    getline( cin, s1 );
    int n1 = s1.size();
    
    if( n1 == 1){
        cout << 'D' << endl;
        return 0;
    }
    if( s1.substr(0,1) == "?"){
        if( s1.substr(1,1) == "P"){
            //s1.substr(0,1) = "D";
            s1[0] = 'D';
        }
        else if( s1.substr(1,1) == "?"){
            //s1.substr(0,1) == "P";
            s1[0] = 'P';
        }
        else if( s1.substr(1,1) == "D"){
            //s1.substr(0,1) == "P";
            s1[0] = 'P';
        }
    }
    for( int i = 1; i < n1; i++ ){
        if( s1.substr(i,1) == "?"){
            if( s1.substr(i-1,1) == "P"){
                //s1.substr(i,1) == "D";
                s1[i] = 'D';
            }
            else if( s1.substr(i-1,1) == "D"){
                if( s1.substr(i+1,1) == "D"){
                    //s1.substr(i,1) == "P";
                    s1[i] = 'P';
                }
                else if( s1.substr(i+1,1) == "P"){
                    //s1.substr(i,1) == "D";
                    s1[i] = 'D';
                }
                else if( s1.substr(i+1,1) == "?"){
                    //s1.substr(i,1) == "D";
                    s1[i] = 'P';
                }
                else {
                    s1[i] = 'D';
                }

            }
        }
    }
      
    cout << s1 << endl;  
   
    return 0;
}


Measured memory_bytes: 3728
// WeirdBugsButOkay

# include <bits/stdc++.h>
 
# define ll long long
# define ld long double
# define pii pair <int,int>
# define pll pair <ll,ll>
# define mp make_pair
# define pb push_back
# define ff first
# define ss second
# define endl '\n'
 
using namespace std;

ll pow3(ll a, ll b, ll m = 1000000007)
{
    ll res = 1;
    while(b > 0)
    {
        if(b & 1)
            res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}

void solve()
{
    ll n, k;
    cin >> n >> k;
    ll lhs = (n * n + n) / 2;
    ll rhs = (k * k - k) / 2;
    ll maxc = lhs - rhs;
    ll inf = 1000000007;
    ll ans = 0;
    for(ll i = k; i < n + 2; i++)
    {
        ans = (ans + i * (n - i)) % inf;
        ans = (ans + i + 1) % inf;
    }
    cout << ans;
}

 
int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll q = 1;
    //cin >> q;
    for(ll i = 0; i < q; i++)
    {
        solve();
    }
    return 0;
}

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

int prime(int x){
	for(int i=2; i*i<=x; i++){
		if(x%i==0){
			return 0;
		}
	}
	return 1;
}
int main() {
	int a,b;
	cin>>a;
	b=a;
	for(int i=0; i<100; i++){
		if(prime(b)){
			cout<<b<<endl;
			return 0;
		}
		b++;
	}
}


Measured memory_bytes: 256
import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
for(;;){
int n=sc.nextInt();
int x =sc.nextInt();
if(n==0 && x==0) break;
int ans =0;
for(int i=1; i<=n; i++){
	for(int c=i+1; c<=n; c++){
		for(int b=c+1; b<=n; b++){
			if(i+c+b == x) ans++;
		}
	}
}
System.out.println(ans);
}
}
}

Measured memory_bytes: 19608
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

int main() {
	int n;
	int l_t;
	int max=0;
	vector<int> l;

	cin >> n;
	for (int i = 0; i < 2*n; i++) {
		cin >> l_t;
		l.push_back(l_t);
	}

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

	for (int i = 0; i < n; i++) {
		max += l[i * 2];
	}
	cout << max << endl;

}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long n;
    cin >> n;
    long ret = 0;
    for (long i=0; i<n; i++) {
        long l, r;
        cin >> l >> r;
        ret += r-l+1;
    }
    cout << ret << '\n';
    return 0;
}


Measured memory_bytes: 256
from bisect import bisect_right

def cumsum(a):
    res = [0] * (len(a) + 1)
    for i, v in enumerate(a):
        res[i + 1] = res[i] + v
    return res

n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
ca = cumsum(a)
cb = cumsum(b)

ans = 0
x = bisect_right(ca, k)
for i in range(x):
    y = bisect_right(cb, k - ca[i])
    ans = max(ans, i + y - 1)

print(ans)

Measured memory_bytes: 47452
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 7;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;

#define LSOne(S) (S & (-S))
#define isBitSet(S, i) ((S >> i) & 1)



void solve() 
{
    int n,x,t;
    cin>>n>>x>>t;
    int times = n/x;
    if(n%x == 0)
        cout<<times*t;
    else
    {
        cout<<(times+ 1) *t;
    }
    
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int tc = 1; 
    //cin >> tc;
    for (int t = 1; t <= tc; t++) {
        // cout << "Case #" << t  << ": ";
        solve();
    }
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <cstring>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define REP(i,k,n) for(int i = k; i < (int)(n); i++)
using namespace std;

bool d[100][100];
int rx = 10,ry = 10;

int main(){
    int N,M;
    int X,Y,l[100];
    char dir[100];
    while(true) {
        cin >> N;
        if (N == 0) break;
        rx = 10,ry = 10;
        memset(d,false,sizeof(d));
        rep(i,N) cin >> X >> Y, d[20 - Y][X] = true;
        cin >> M;
        rep(i,M) cin >> dir[i] >> l[i];
        rep(i,M){
            switch (dir[i]) {
            case 'N':
                rep(j,l[i]){
                    ry--;
                    d[ry][rx] = false;
                }
                break;
            case 'S':
                rep(j,l[i]){
                    ry++;
                    d[ry][rx] = false;
                }
                break;
            case 'W':
                rep(j,l[i]){
                    rx--;
                    d[ry][rx] = false;
                }
                break;
            case 'E':
                rep(j,l[i]){
                    rx++;
                    d[ry][rx] = false;
                }
                break;
            }
        }

        string ans = "Yes";
        rep(y,21) {
            rep(x,21) {
                // cout << d[y][x] << " ";
                if(d[y][x] == true) ans = "No";
            }
            // cout << endl;
        }
        cout << ans << endl;
    }

    return 0;
}



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

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

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == t.at(0) && s.substr(i) + s.substr(0, i) == t) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


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

/*
モンスターバトル
再帰で解いていく
*/

int gcd(int a, int b);
int gcd(vector<int> a);


int main() {
  int n;
  cin >> n;
  vector<int> a(n);//モンスターの体力
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  
  int ans = gcd(a);
  cout << ans << endl;
}

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

int gcd(vector<int> a){
  int ans = a[0];
  for(int i=1;i<a.size();i++)
    ans = gcd(ans, a[i]);
  return ans;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int t[58],n,f,ans,d;
int main(){
	cin>>n>>d;
	for(int i=0;i<n;i++){
		cin>>f;
		t[f]++;
	}
	for(int i=50;i>=0;i--){
		while(t[i]!=0&&d!=0){
			t[i]--;
			ans+=i;
			d--;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import math


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1:
            continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1:
                return 0
            t <<= 1
    return 1


def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        def f(x): return (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g):
                return g
            elif isPrimeMR(n // g):
                return n // g
            return findFactorRho(g)


def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k:
            ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1:
        ret[n] = 1
    if rhoFlg:
        ret = {x: ret[x] for x in sorted(ret)}
    return ret


N = int(input())
A = [int(i) for i in input().split()]

a = A[0]
p = set(primeFactor(A[0]).keys())
flg = False

for i in range(1, N):
    a = math.gcd(a, A[i])
    for x in primeFactor(A[i]):
        if x in p:
            flg = True
        else:
            p.add(x)


if a >= 2:
    print('not coprime')
elif flg:
    print('setwise coprime')
else:
    print('pairwise coprime')


Measured memory_bytes: 190448
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int k = scanner.nextInt();
			scanner.nextLine();
			Map<Integer, Integer> numberCountMap = new HashMap<>();
			for (int i = 0; i < n; i++) {
				int number = scanner.nextInt();
				if (null == numberCountMap.get(number)) {
					numberCountMap.put(number, 1);
				} else {
					numberCountMap.put(number, numberCountMap.get(number) + 1);
				}
			}
			int size = numberCountMap.size();
			if (size <= k) {
				System.out.println(0);
			} else {
				System.out.println(
						numberCountMap.entrySet().stream().mapToInt(x -> x.getValue()).sorted().limit(size - k).sum());
			}
		}
	}
}

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

#define all(x) 		 (x).begin(),(x).end()
#define mp     		 make_pair
#define pb 				 push_back
#define fi 				 first
#define se 				 second
#define sz(x) 		 ((int)(x).size())
#define rep(x,y,z) for(int x=y;x<z;x++)
#define per(x,z,y) for(int x=z-1;x>=y;x--)
#define trav(y,x)  for(auto& y:x)
#define pii 			 pair<int,int>
#define vi 				 vector<int>

int dbg = 0;
#define cri   		 if(0)
#define shame 		 cri cerr<<(++dbg)<<"\n\n";

// aaaaaaaaaaaaaaaa
const int N = 2e5 + 1;
const int lg = 20;
const ll mod = 0xfffff;


void solve() {
  int n; cin >> n;
  vi a(n, 0), f(n, 0);
  rep(i, 0, n) {
    cin >> a[i];
    --a[i];
    f[a[i]]++;
  }

  ll tot = 0;
  rep(i, 0, n) {
    ll x = f[i];
    x = (x * (x - 1)) >> 1;
    tot += x;
  }
  rep(i, 0, n) {
    ll x = f[a[i]];
    x = (x * (x - 1)) >> 1;
    ll y = f[a[i]] - 1;
    y = (y * (y - 1)) >> 1;
    cout << (tot - x + y) << "\n";
  }
}

int main() {
  // freopen("input.in", "r", stdin);
  // freopen("input.out", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// cout<<setprecision(15);
	// int t; cin>>t; while(t--)
	solve();
	return 0;
}



Measured memory_bytes: 4224
#include <bits/stdc++.h>
 
#define loop(n, i) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;

using namespace std;
typedef long long ll;

vector<string> del(vector<string> b, int n)
{
    int h = b.size(), w = b[0].size();
    loop (h-1, i) loop (w, j) {
        int ii = h-2-i;
        int t = ii + 1;
        for (; t < h && b[t][j] == '.'; t++);
        swap(b[t-1][j], b[ii][j]);
    }
    vector<vector<int>> dl(h, vector<int>(w));
    loop (h, i) loop (w, j) {
        for (int ii = i+1; ii < h; ii++) {
            if (b[ii][j] != b[i][j]) break;
            if (ii - i == n - 1) {
                loop (n, k) dl[i+k][j] = 1;
            }
            if (ii - i > n - 1) dl[ii][j] = 1;
        }
        for (int jj = j+1; jj < w; jj++) {
            if (b[i][jj] != b[i][j]) break;
            if (jj - j == n - 1) {
                loop (n, k) dl[i][j+k] = 1;
            }
            if (jj - j > n - 1) dl[i][jj] = 1;
        }
    }

    loop (h, i) loop (w, j) if (dl[i][j]) b[i][j] = '.';
    return b;
}

void show(vector<string> s) {
    for (auto p : s) {
        cout << p << endl;
    }
    cout << endl;
}

int main()
{
    int h, w, n; cin >> h >> w >> n;

    vector<string> B;
    loop (h, i) {
        string s; cin >> s;
        B.push_back(s);
    }

    loop (h, i) loop (w-1, j) {
        vector<string> curr = B;
        swap(curr[i][j], curr[i][j+1]);
        vector<string> next = del(curr, n);
        while (next != curr) {
            curr = next;
            next = del(curr, n);
        }
        int y = 1;
        loop (h, i) loop (w, j) if (curr[i][j] != '.') y = 0;
        if (y) {
            cout << "YES" << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3220
//---------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                        NEVER  GIVE  UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug cout<<"Hello\n";
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//------------------------------------------------------------------------------------------------------------------------------

vector<vector<int>> g;
vector<bool> visited;
int dfs(int u) {
	visited[u] = true;
	int ans = 1;
	for(auto it: g[u]) {
		if(!visited[it])
			ans += dfs(it);
	}
	return ans;
}
int main()
{
	
	#ifndef ONLINE_JUDGE
	freopen("C:/Users/DELL/Desktop/input.txt", "r", stdin);
	#endif

	fast;
	int n,m,u,v;
	cin>>n>>m;
	g.resize(n);
	visited.resize(n,false);
	for(int i=0;i<m;i++) {
		cin>>u>>v;
		--u;
		--v;
		g[u].pb(v);
		g[v].pb(u);
	}
	vector<int> size;
	for(int i=0;i<n;i++) {
		if(!visited[i]) {
			size.push_back(dfs(i));
		}
	}
	priority_queue<int,vector<int>, greater<int>> pq;
	for(auto it: size) {
		pq.push(it);
	}
	int sub = 0;
	while(!pq.empty()) {
		int x = pq.top();
		pq.pop();
		x -= sub;
		sub += max(0,x);
	}
	cout<<sub<<"\n";
	return 0;
}


Measured memory_bytes: 23420
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef vector<vector<ll> > Graph;
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; }
const ll INF = 1e18;


int main(){
    int n,k;
    cin >> n >> k;
    vector<ll>a(n);
    rep(i,n){
        cin>>a[i];
        a[i]--;
    }
    vector<ll>s(n+1,0);
    rep(i,n){
        s[i+1]=(s[i]+a[i])%k;
    }
    queue<ll>q;
    ll cnt = 0;
    map<int,int>mp;
    for(int j=0;j<=n;j++){
        ll now = s[j];
        cnt += mp[now];
        q.push(now);
        mp[now]++;
        if(q.size()==k){
            ll e = q.front();q.pop();
            mp[e]--;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 14336
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n, k , q = inpm()
al = inplm(q)
l = []
for i in range(0, n):
    l.append(k)
for i in range(0, q):
    l[al[i] - 1] += 1
for i in range(0, n):
    print('Yes' if l[i] - q > 0 else 'No')


Measured memory_bytes: 88860
A, B, C, D, E, F = map(int, input().split())

W = set()
for a in range(F // (100 * A) + 1):
    for b in range(F // (100 * B) + 1):
        if a == b == 0: continue
        w = 100 * (A * a + B * b)
        if w <= F:
            W.add(w)

S = set()
for c in range(F // C + 1):
    for d in range(F // D + 1):
        s = C * c + D * d
        if s <= F:
            S.add(s)

max_density = -1
max_ws = 0
max_s = 0
for w in W:
    for s in S:
        if w + s > F or E * w / 100 < s: continue
        density = s / (w + s)
        if density > max_density:
            max_density = density
            max_ws = w + s
            max_s = s

print(max_ws, max_s)


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

int main() {
    int W, H, N; cin >> W >> H >> N;
    int x, y, a;
    vector<int> w = {0, W};
    vector<int> h = {0, H};
    for (int i = 0; i < N; i++) {
        cin >> x >> y >> a;
        if (a == 1) {
            w.at(0) = max(w.at(0), x);
        } else if (a == 2) {
            w.at(1) = min(w.at(1), x);
        } else if (a == 3) {
            h.at(0) = max(h.at(0), y);
        } else if (a == 4) {
            h.at(1) = min(h.at(1), y);
        }
    }
    if (w.at(1)-w.at(0) > 0 && h.at(1) - h.at(0) > 0) {
        cout << (w.at(1)-w.at(0))*(h.at(1)-h.at(0)) << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

long long n,m,b;

int main(){
    cin >> n >> m;
    if(n * 2 == m){
        cout << n << endl;
    }else if(n * 2 > m){
        cout << m / 2 << endl;
    }else{
        m = m - 2 * n;
        b = m / 4 + n;
        cout << b << endl;
    }
}

Measured memory_bytes: 256
k,n = map(int,input().split())
a = list(map(int,input().split()))

#k,n = 20,5
#a = [1,2,3,4,19]

s = []
for i in range(1,n):
  s.append(a[i]-a[i-1])

s.append(k - a[n-1] + a[0])

print(k - max(s))

Measured memory_bytes: 26420
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
const int mod=1e9+7;
#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,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
#define nepe(v) next_permutation(all(v))
#define F first 
#define S second
#define PB push_back 
#define MP make_pair
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
using vl=vector<long long>;
using vvl = vector<vl>;
using vp =vector<pair<int,int>>;

typedef pair<int,int> P;
string s;
int k;
ll INF = 1000000000000;

int main(){
    int N,A,B,C,D;
    string S;
    cin >>N>>A>>B>>C>>D>>S;
    if(C<D){
        string ans ="Yes";
        rep2(i,A-1,D-1){
            if(S[i]=='#'&&S[i+1]=='#'){
                ans ="No";
                break;
            }
        }
        cout <<ans<<endl;
    }
    else {
        string ans ="No";
        rep2(i,B-2,D-1){
            if(S[i]=='.'&&S[i+1]=='.'&&S[i+2]=='.'){
                ans ="Yes";
                break;
            }
        }
        rep2(i,A-1,C-1){
            if(S[i]=='#'&&S[i+1]=='#'){
                ans ="No";
                break;
            }
        }
        cout <<ans <<endl;
    }
}


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

int n, x, t=0;

int main() {
    cin >> n;

    for(int i = 1; i<n+1; i++){
        if(i%2!=0){
            for(int j = 1; j<i; j++){
                if(i%j==0){
                    x=x+1;
                }
            }
            if(x==7){
               t=t+1; 
            }
            x=0;
        }
    }

    cout << t;
}

Measured memory_bytes: 256
import sys

input = sys.stdin.readline


def main():
    X = int(input())

    for A in range(-119, 120 + 1):
        for B in range(-119, 120 + 1):
            if A ** 5 - B ** 5 == X:
                print(A, B)
                exit()


if __name__ == "__main__":
    main()


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

using namespace std;

string S;
int K;
int dp[300][300][300];

int rec(int left, int right, int rest) {
  if(left >= right) return left == right;
  if(~dp[left][right][rest]) return dp[left][right][rest];
  int ret = max(rec(left + 1, right, rest), rec(left, right - 1, rest));
  if(rest > 0) ret = max(ret, rec(left + 1, right - 1, rest - 1) + 2);
  if(S[left] == S[right]) ret = max(ret, rec(left + 1, right - 1, rest) + 2);
  return dp[left][right][rest] = ret;
}

int main() {
  cin >> S >> K;
  memset(dp, -1, sizeof(dp));
  cout << rec(0, S.size() - 1, K) << endl;
}

Measured memory_bytes: 105728
from operator import mul
from functools import reduce

def nCr(n, r):
    r = min(n-r, r)
    if r == 0: return 1
    if r < 0: return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def read():
    N, K = list(map(int, input().strip().split()))
    return N, K

def solve(N, K):
    for i in range(1, K + 1):
        count = nCr(N - K + 1, i) * nCr(K - 1, i - 1)
        print(count % (10**9 + 7))

if __name__ == '__main__':
    inputs = read()
    solve(*inputs)


Measured memory_bytes: 3944
#include <iostream>

using namespace std;
 
#define MAX 1000000
 
int main()
{
    int prime[MAX];
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++) {
        if (prime[i]) {
            for (int j = 2*i; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
    
    for (int i = 1; i < MAX; i++) {
	prime[i] = prime[i] + prime[i-1];
    }
    
    int N;
    while (cin >> N) {
	cout << prime[N] << endl;
    }
    return 0;
}

Measured memory_bytes: 6984
mod = 1000000007

def mul(a, b):
    return ((a % mod) * (b % mod)) % mod

def power(x, y):
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return power(x, y/2)**2 % mod
    else            : return power(x, y/2)**2 * x % mod

def div(a, b):
    return mul(a, power(b, mod-2))


# def gcd(a_gcd, b_gcd):
#     while b_gcd != 0:
#         a_gcd, b_gcd = b_gcd, a_gcd % b_gcd
#     return a_gcd
#
#
# def lcm(a_lcm, b_lcm):
#     return a_lcm * b // gcd(a_lcm, b_lcm)
#
#
# def max_sum(N_max_sum, a_max_sum):
#     dp = [0] * (N_max_sum + 1)
#     for i in range(N_max_sum):
#         dp[i + 1] = max(dp[i], dp[i] + a_max_sum[i])
#     return dp[N]
#
#
# def knapsack(N_knapsack, W, weight, value):
#     inf = float("inf")
#     dp = [[-inf for _ in range(W+1)] for j in range(N_knapsack + 1)]
#     for i in range(W+1):
#         dp[0][i] = 0
#
#     for i in range(N_knapsack):
#         for w in range(W+1):
#             if weight[i] <= w:
#                 dp[i+1][w] = max(dp[i][w-weight[i]]+value[i], dp[i][w])
#             else:
#                 dp[i+1][w] = dp[i][w]
#     return dp[N_knapsack][W]
#
#
# class UnionFind:
#     def __init__(self, n):
#         self.par = [i for i in range(n+1)]
#         self.rank = [0] * (n+1)
#
#     # 検索
#     def find(self, x):
#         if self.par[x] == x:
#             return x
#         else:
#             self.par[x] = self.find(self.par[x])
#             return self.par[x]
#
#     # 併合
#     def union(self, x, y):
#         x = self.find(x)
#         y = self.find(y)
#         if self.rank[x] < self.rank[y]:
#             self.par[x] = y
#         else:
#             self.par[y] = x
#             if self.rank[x] == self.rank[y]:
#                 self.rank[x] += 1
#
#     # 同じ集合に属するか判定
#     def same_check(self, x, y):
#         return self.find(x) == self.find(y)


S = input()
# N = int(input())
# A = list(map(int, input().split()))
# X = [int(input()) for _ in range(N)]

# A, B = map(int, input().split())

ans = 0
count = 0
for s in S:
    if s == 'x':
        count += 1

if count >= 8:
    print("NO")
else:
    print("YES")












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

int shouw(long long a)
{
  long long nokori = a;
  int shou = 0;
  while (nokori % 2 == 0) {
    shou++;
    nokori /= 2;
  }
//cout << "shou: " << shou << endl;
 return shou;
  
}
int main()
{
  int N;
  cin >> N;
  vector<long long> a;
  long long tmp;
  int minnum = 1000;
  for (int i=0; i<N; i++) {
    cin >> tmp;
    a.push_back(tmp);
  }
  double integral = 0.0;
  for (int i=0; i<N; i++) {
  //  double loga = log2(a[i]);
  //  double frac = modf(loga, &integral);
  //  bool   is  = frac == 0.0;
  //  cout << "input: " << a[i] << ", log2: " << loga << endl;
    int shou = shouw(a[i]);
      minnum = min(minnum, (int)shou);
    //if (is) {
    //  minnum = min(minnum, (int)loga);
    //} else {
    //}
  }
  cout << minnum << endl;

}

Measured memory_bytes: 256
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]
ttl_cnds = []
for i in range(N):
    l = 0
    for j in A[0][:i+1]:
        l += j
    for k in A[1][i:]:
        l += k
    ttl_cnds.append(l)
print(max(ttl_cnds))


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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

// 重複する数字をd、その数字の位置をl,r(l<r)とすると、長さiの部分列の数え上げは
// (1)dを含まない選び方 (2)dを1個だけ含む選び方 (3)dを2個とも含む選び方
// に分解できる (1)と(3)は普通にやればok
// (2)で問題になるのは区間(l,r)の数字を1つも採用していない数列
// 例えば1234536とあったとき1234--6と12-4-36は区別できても123---6と12---36は区別できない
// これを引いてやればいい

ll n, f[100100], a[100100], l, r, s;
int u[100100];

ll mpow(ll x, ll n=mod-2, ll m=mod) {
	ll res = 1;
	while (n>0) {
		if (n&1) res = res * x %m;
		x = x * x %m;
		n >>= 1;
	}
	return res;
}

ll comb(int n, int k) {
	if (n<k) return 0;
	return f[n] * mpow(f[k]) %mod * mpow(f[n-k]) %mod;
}

signed main() {
	cin >> n;
	memset(u, -1, sizeof(u));
	rep(i,n+1) {
		cin >> a[i];
		if (u[a[i]]!=-1) l = u[a[i]], r = i;
		u[a[i]] = i;
	}
	
	f[0] = f[1] = 1;
	for (ll i = 2; i <= 100000; ++i) f[i] = f[i-1]*i %mod;
	s = r - l + 1;
	cout << n << ln;
	repst(k,2,n+1) {
		// type1, 3
		ll res = (comb(n-1, k) + comb(n-1, k-2)) %mod;
		// type2
		(res += 2*comb(n-1, k-1) + mod - comb(n+1-s, k-1)) %= mod;
		cout << res << ln;
	}
}

Measured memory_bytes: 3200
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define re register
#define ll long long
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=(sum<<3)+(sum<<1)+ch-'0';ch=getchar();}
	return f*sum;
}
char s[500010];
int main(){
	scanf("%s",s+1);int n=strlen(s+1);
	for(int i=1;i<n;i++)
		if(s[i]==s[i+1]){printf("%d %d\n",i,i+1);return 0;}
		else if(i+1!=n && s[i]==s[i+2])return printf("%d %d\n",i,i+2),0;
	puts("-1 -1");
	return 0;
}

Measured memory_bytes: 384
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(int i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define ALL(a) begin(a),end(a)
#define ifnot(a) if(not (a))
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

// #define int ll
#ifdef _MSC_VER
const bool test = true;
#else 
const bool test = false;
#endif

int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define INF (1 << 28)
ull mod = (int)1e9 + 7;
//.....................
const int MAX = (int)2e5 + 5;

int dayofweek(int year, int month, int day) {
	struct tm t;
	t.tm_year = year - 1900;
	t.tm_mon = month - 1;
	t.tm_mday = day;
	t.tm_hour = 0;
	t.tm_min = 0;
	t.tm_sec = 0;
	t.tm_isdst = -1;
	if (mktime(&t) == -1) {
		puts("!");
		exit(1);
	}
	return t.tm_wday;
}

int main() {
	vector<string> week_name = { "Sunday", "Monday", "Tuesday", "Wednesday",
		"Thursday","Friday","Saturday" };
	while (1) {
		int m, d;
		cin >> m >> d;
		if (m == 0) break;
		cout << week_name[dayofweek(2004, m, d)] << endl;
	}
	return 0;
}

Measured memory_bytes: 3300
import java.util.*;

public class Main {
    private static final Scanner sc = new Scanner(System.in);

    private void solve() {
        String s = sc.next();
        int n = s.length();
        Map<Integer, Integer> count = new HashMap<>();
        count.put(0, 1);
        int total = 0;
        final int M = 2019;
        int pr = 0;
        int br = 1;
        for (int i = n - 1; i >= 0; --i) {
            int d = s.charAt(i) - '0';
            int r = (((br * d) % M) + pr) % M;

            total += count.getOrDefault(r, 0);
            count.put(r, count.getOrDefault(r, 0) + 1);

            pr = r;
            br = (br * 10) % M;
        }
        System.out.println(total);
    }

    public static void main(String[] args) {
        new Main().solve();
    }
}


Measured memory_bytes: 51704
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
#define int long long
typedef pair<char,int>P;
int uni[100009],r[100009];
int find(int a){
    if(a!=uni[a])a=find(uni[a]);
    return a;
}
bool same(int a,int b){
    return find(a)==find(b);
}
void unit(int a,int b){
    int c=find(a),d=find(b);
    if(r[c]>r[d])uni[d]=c;
    else{
      uni[d]=c;
      r[d]++;
    }

}
 
int M[100007];
vector<int>v[100007];
 
void dfs(int x,int col){
  if(M[x]!=-1)col=x;
  uni[x]=col;
  r(i,v[x].size()){
    dfs(v[x][i],col);
  }
}
int n,m,x,sum;
vector<P>query;
int xx[100009];


main(){
  while(cin>>n>>m,n){
    sum=0;
    memset(uni,0,sizeof(uni));
    memset(r,0,sizeof(r));
    memset(M,-1,sizeof(M));
    query.clear();
    r(i,100007)v[i].clear();
    r(i,n-1){
      cin>>xx[i+2];
      v[xx[i+2]].push_back(i+2);
    }
    xx[1]=1;
    set<P>s;
    r(i,m){
      char c;
      cin>>c>>x;
      if(c=='M'&&s.count(P(c,x)))continue;
      if(c=='M')M[x]=x;
      s.insert(P(c,x));
      query.push_back(P(c,x));
    }
    dfs(1,1);
    reverse(query.begin(),query.end());
    r(i,query.size()){
      if(query[i].first=='Q') sum += find(query[i].second);
      else{
        unit(xx[query[i].second],query[i].second);
      }
    }
    cout<<sum<<endl;
  }
}

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

const long long int lim = 1e9 + 7;
int H, N, tmp, a[1000], b[1000], out[10001];

void solve() {
    std::cin >> H >> N;
    for (int i=0; i<N; ++i)
        std::cin >> a[i] >> b[i];
    for (int i=0; i<10001; ++i)
        out[i] = lim*2;
    out[0] = 0;
    for (int i=0; i<N; ++i) {
        for (int j=0; j<H; ++j) {
            tmp = std::min(H, j + a[i]);
            if (out[tmp] > (out[j] + b[i]))
                out[tmp] = out[j] + b[i];
        }
    }
    std::cout << out[H] << std::endl;
}

int main() {
    std::ios_base::sync_with_stdio(false);
    solve();
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


#define MAX_N 99'999
i64 N;
i64 dam[MAX_N + 1]; // ダムiの貯水量
i64 rainfall[MAX_N + 1]; // 山iに降った量

void solve() {
  fill(rainfall, rainfall + N + 1, 0);

  i64 s_dam = 0;
  REPS(i, N) s_dam += dam[i];

  rainfall[1] = s_dam;
  for (i64 i = 2; i < N; i += 2) {
    rainfall[1] -= 2 * dam[i];
  }

  for (i64 i = 2; i <= N; i++) {
    rainfall[i] = 2 * dam[i - 1] - rainfall[i - 1];
  }

  REPS(i, N) {
    cout << rainfall[i] << " ";
  }
  cout << endl;
}

int main() {
  cin >> N;
  REPS(i, N) cin >> dam[i];

  solve();

  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

vector<int> div(int n){
    vector<int> res;
    for(int i=1; i*i<=n; i++){
        if(n%i==0){
            res.pb(i);
            if(i!=n/i) res.pb(n/i);
        }
    }
    sort(all(res));
    return res;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, m;
    cin >> n >> m;
    vector<int> d = div(m);
    reverse(all(d));
    for(auto &i:d){
        if(1LL*i*n > m) continue;
        cout << i << endl;
        break;
    }
}



Measured memory_bytes: 256
def check(s,t):
    for i in range(s,s+M):
        for j in range(t,t+M):
            if A[i][j] != B[i-s][j-t]:
                return False
    return True


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

A = [list(input()) for _ in range(N)]
B = [list(input()) for _ in range(M)]

for i in range(N-M+1):
    for j in range(N-M+1):
        if check(i,j):
            print("Yes")
            exit()

print("No")

Measured memory_bytes: 3064