akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; typedef long long ll; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T, class U>bool chmax(T& a, U&& b) { return a < b ? a = b, 1 : 0; }
template<class T, class U>bool chmin(T& a, U&& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

int N, M;
vv<int> graph, igraph;
vector<int> tomax, frommax;

void dfs_to(int v) {
    tomax[v] = 0;
    for (int u : graph[v]) {
        if (tomax[u] == -1) dfs_to(u);
        tomax[v] = max(tomax[v], tomax[u] + 1);
    }
}
void dfs_from(int v) {
    frommax[v] = 0;
    for (int u : igraph[v]) {
        if (frommax[u] == -1) dfs_from(u);
        tomax[v] = max(frommax[v], frommax[u] + 1);
    }
}

int main() {
    cin >> N >> M;
    graph.resize(N);
    igraph.resize(N);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        graph[x].push_back(y);
    }

    tomax.resize(N, -1);
    frommax.resize(N, -1);
    int ans = 0;
    rep(v, N) {
        if (tomax[v] == -1) dfs_to(v);
        if (frommax[v] == -1) dfs_from(v);
        ans = max(ans, tomax[v] + frommax[v]);
    }

    write(ans);
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 2e5 + 7;
const int Inf = 1 << 30;
int n, m;
int a[maxx];
map <int, bool> vis;
map <int, int> mp;
int ans;

struct PP {
	int num;
	int cnt;
} p[maxx];

bool cmp(PP x, PP y) {
	if(x.cnt == y.cnt) return x.num < y.num;
	return x.cnt < y.cnt;
}

void Init() {
	cin >> n >> m;
	for(int i = 1; i <= n; i++) cin >> a[i];
}

int main() {
	Init();
	vis.clear();
	int t = 0;
	for(int i = 1; i <= n; i++) mp[a[i]]++;
	for(int i = 1; i <= n; i++) {
		if(!vis[a[i]]) {
			p[++t].num = a[i];
			vis[a[i]] = 1;
		}
	}
	for(int i = 1; i <= t; i++) p[i].cnt = mp[p[i].num];
	sort(p + 1, p + t + 1, cmp);
	//for(int i = 1; i <= t; i++) cout << p[i].cnt << endl;
	if(t <= m) ans = 0;
	else {
		int dd = 0;
		while(t > m) {
			t--;
			ans += p[++dd].cnt;
		}
	}
	cout << ans << endl;
}

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

using namespace std;
//frog problem
inline int abs(int a){ return a>0?a:-a;}
inline long long min(long long a,long long b){ return a>b?b:a; }
long long cost_paid(vector<int> &height_array,int N,vector<int> &cost_array){
    //base case
    cost_array[1] = abs(height_array[0]-height_array[1]);
    for(int i=2;i<N;i++){
        cost_array[i] = min(cost_array[i-1]+abs(height_array[i]-height_array[i-1]),cost_array[i-2]+abs(height_array[i]-height_array[i-2]));
    }
    return cost_array[N-1];
}


int main(){
    int N=0;cin>>N;
    vector<int> height_array(N),cost_array(N);
    for(int i=0;i<N;i++)
        scanf("%d",&height_array[i]);

    printf("%d\n",cost_paid(height_array,N,cost_array));

    return 0;
}

Measured memory_bytes: 1024
buildings = []
4.times do |i|
  buildings[i] = []
  3.times {|j| buildings[i][j] = [0] * 10 }
end
gets.to_i.times do
  b, f, r, v = gets.split.map(&:to_i)
  current = buildings[b - 1][f - 1][r - 1]
  buildings[b - 1][f - 1][r - 1] = [[0, current + v].max, 9].min
end

buildings.each.with_index do |building, i|
  building.each do |floor|
    print ' '
    puts floor.join(' ')
  end
  puts '#' * 20 unless i == 3
end


Measured memory_bytes: 6900
N, M = map(int, input().split())
N, M = min(N, M), max(N, M)
mod = 10**9+7

g = [1, 1]
for i in range(2, M+1):
    g.append((g[-1] * i) % mod)

if M-N > 1:
    print(0)
elif M-N == 1:
    print(g[M]*g[N] % mod)
else:
    print(g[M]**2*2 % mod)


Measured memory_bytes: 7060
#include <stdio.h>
int main(void)
{
	int a,b;
	char op;
	
	scanf("%d %c %d",&a,&op,&b);
	
	while(op!='?')
	{
		
		switch (op)
		{
			case '+':
				printf("%d\n",a+b);
				break;
			case '-':
				printf("%d\n",a-b);
				break;
			case '*':
				printf("%d\n",a*b);
				break;
			case '/':
				printf("%d\n",a/b);
				break;
			default:
				break;
		}
		scanf("%d %c %d",&a,&op,&b);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define endl    '\n'
using namespace std;

typedef long long ll;

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

    int n, c;

    cin >> n;

    while (n != 0) {
        int hist[10] = {};

        for (int i = 0; i < n; ++i) {
            cin >> c;

            hist[c]++;
        }

        for (int i = 0; i < 10; i++) {
            if (hist[i] == 0) {
                cout << "-" << endl;
            } else {
                for (int j = 0; j < hist[i]; ++j) {
                    cout << "*";
                }
                cout << endl;
            }
        }

        cin >> n;
    }

    return 0;
}




Measured memory_bytes: 3132
h=[]; w=[]; i=0
loop do
  h0,w0=gets.split.map &:to_i
  h0==0&&break
  h<<h0; w<<w0
  i+=1
end
h.size.times do|i|
  puts "#"*w[i]
  (h[i]-2).times{print "#","."*(w[i]-2),"#\n"}
  puts "#"*w[i]
  print "\n"
end



Measured memory_bytes: 6880
N = int(input())
S = input()
length = len(S)
S0 = ''
abc_list = ['A','B','C','D','E','F','G','H','I','J','K','L','M',
            'N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
for i in range(length):
    for j in range(26):
        if S[i] == abc_list[j]:
            if j+N<=25:
                S0 += abc_list[j+N]
            else:
                k = j+N-26
                S0 += abc_list[k]
            break
print(S0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define lson rt<<1
#define rson rt<<1|1
#define scd(x) scanf("%d",&x)
#define scdd(x,y) scanf("%d%d",&x,&y)
const int maxn=3e5+10;
typedef long long ll;
typedef pair<int,int> pii;
const int INF=0x3f3f3f3f;
int arr[maxn],sum[maxn*4],val[maxn*4];
void push_up(int rt) {
    int l=lson,r=rson;
    sum[rt]=sum[l]+sum[r];
    val[rt]=min(val[l],val[r]);
}
void build(int rt,int l,int r) {
    if(l==r) {
        sum[rt]=1;
        val[rt]=l;
        return ;
    }
    int mid=(l+r)/2;
    build(lson,l,mid);
    build(rson,mid+1,r);
    push_up(rt);
}
void update(int rt,int l,int r,int pos) {
    if(l==r) {
        sum[rt]=0;
        val[rt]=INF;
        return ;
    }
    int mid=(l+r)/2;
    if(pos<=mid)update(lson,l,mid,pos);
    else update(rson,mid+1,r,pos);
    push_up(rt);
}
pii query(int rt,int l,int r,int ql,int qr) {
    if(ql<=l&&qr>=r) {
        return pii(sum[rt],val[rt]);
    }
    int mid=(l+r)/2;
    pii ans=pii(0,0);
    if(ql<=mid)ans=query(lson,l,mid,ql,qr);
    if(qr>mid&&ans.first==0)ans=query(rson,mid+1,r,ql,qr);
    return ans;
}
vector<int>vec;
int find_pos(int x,int l,int r){
    int ans=-1;
    while(r>=l){
        int mid=(l+r)/2;
        if(arr[mid]>=x){
            ans=mid;
            l=mid+1;
        }
        else r=mid-1;
    }
    return ans;
}
int main() {
#ifdef LOCAL
    freopen("in.txt","r",stdin);
#endif // LOCAL
    int n;
    //cout<<(1<<18)<<endl;
    scd(n);
    int la=1<<n;
    for(int i=1; i<=la; i++) {
        scd(arr[i]);
    }
    sort(arr+1,arr+la+1,greater<int>() );
    build(1,1,la);
    bool flag=false;
    vec.clear();
    vec.push_back(arr[1]);
    update(1,1,la,1);
    while(!flag) {
        if(vec.size()==la) {
            flag=true;
            break;
        }
        int siz=vec.size();
        sort(vec.begin(),vec.end(),greater<int>() );
        //cout<<"?"<<endl;
        for(int i=0; i<siz; i++) {
            int pos=find_pos(vec[i],1,la);
            //cout<<pos<<endl;
            if(pos==la){
                flag=true;break;
            }
            pii ans=query(1,1,la,pos+1,la);
            if(ans.first==0){
                flag=true;break;
            }
            update(1,1,la,ans.second);
            vec.push_back(arr[ans.second]);
        }
    }
    //for(int i=0;i<vec.size();i++)cout<<vec[i]<<endl;
    if(vec.size()==la)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 11768
import sys
read = sys.stdin.read
def main():
    h, n = map(int, input().split())
    m = map(int, read().split())
    mm = zip(m, m)

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for a, b in mm:
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 39536
#include <stdio.h>

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

    scanf("%lld %lld", &n, &m);

    if (n == 1 && m == 1) {
        puts("1");
    } else if (n == 1) {
        printf("%lld\n", m - 2);
    } else if (m == 1) {
        printf("%lld\n", n - 2);
    } else {
        printf("%lld\n", (n - 2) * (m - 2));
    }
}


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



signed main() {
    int n;
    cin >> n;
    vector<P> v;
    for (int i = 0; i < n; i++) {
        double x, y;
        cin >> x >> y;
        v.emplace_back(x, y);
    }
    sort(v.begin(), v.end());
    double d = 0;
    do {
        for (int i = 0; i < n - 1; i++) {
            d += sqrt((pow(v[i].first - v[i + 1].first, 2) + pow(v[i].second - v[i + 1].second, 2)));
        }
    } while (next_permutation(v.begin(), v.end()));
    double fact = 1;
    for (int i = 2; i <= n; i++) {
        fact *= (double)i;
    }
    double ave = d / fact;
    cout << setprecision(10) << ave << "\n";
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N, sum;
    cin >> N;
    sum = 0;
    
    for(int i = 0; i < N; i++){
        
        int l, r;
        cin >> l >> r;
        
        r -= l;
        sum +=r;
        sum++;
        
    }
    
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  int ans = pow(2, m) * (1900*m+100*(n-m));
  cout << ans << endl;
  return 0;
}

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

double cost[101][101];
double mincost[101];
bool used[101];
double x[101], y[101], z[101], r[101];
double INF = numeric_limits<double>::max();
int main(void){
    int n;
    while(cin >> n && n) {
        rep(i, n) {
            cin >> x[i] >> y[i] >> z[i] >> r[i];
        }
        rep(i, n) rep(j, n) {
            cost[i][j] = max(sqrt(pow(x[i]-x[j], 2.0) + pow(y[i]-y[j], 2.0) + pow(z[i]-z[j], 2.0)) - r[i] - r[j], 0.0);
        }
        // prim
        rep(i, n) {
            mincost[i] = INF;
            used[i] = false;
        }
        mincost[0] = 0;
        double res = 0;

        while(true) {
            int v = -1;
            rep(u, n) {
                if(!used[u] && (v==-1 || mincost[u] < mincost[v])) v = u;
            }
            if(v == -1) break;
            used[v] = true;
            res += mincost[v];

            rep(u, n) {
                mincost[u] = min(mincost[u], cost[v][u]);
            }
        }
        printf("%.3lf\n", res);
    }
}


Measured memory_bytes: 3244
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        for(int i = 1; ; ++i) {
            int n = ReadInt();
            if( n == 0 ) break;
            System.out.println("Case " + i + ": " + n);
        }
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

Measured memory_bytes: 39876
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		String S = stdIn.next();
		
		String[] s = S.split("",0);
		
		s[K-1] = s[K-1].toLowerCase();
		
		String a = String.join("", s);
		
		System.out.println(a);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    int ans = 1, last = 0, op = 0;
    cin >> last;
    for (int i = 0; i < N-1; i++) {
        int curr; cin >> curr;
        if (op == 0 && last != curr) {
            op = last < curr ? +1 : -1;
        } else if ((last < curr && op == -1) || (last > curr && op == +1)) {
            ans++;
            op = 0;
        } 
        last = curr;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;

int main() {
    ll N;
    cin >> N;
    for (int h = 1; h <= 3500; h++) {
        for (int n = 1; n <= 3500; n++) {
            if (4 * h * n > N * (h + n) && N * h * n % (4 * h * n - N * (h + n)) == 0) {
                cout << h << " " << n << " " << N * h * n / (4 * h * n - N * (h + n)) << endl;
                return 0;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())

if N % 10 == 0:
    print(10)
    exit()
    
wa=0
ans=N
for A in range(N):
    wa=sum(map(int, list(str(A))))+sum(map(int, list(str(N-A))))
    if wa <= ans:
        ans = wa

print(ans)

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

using namespace std;
#define ll long long int
ll a[50] , b[50] , c[50] , d[50]; 
ll n , m , q;
ll ans = 0;

void find(int start , int end , int temp[] , int index)
{
    if(index == n)
    {
        ll total = 0;
        for(int i = 0; i <q ; i ++)
        {
            if(temp[b[i] - 1] - temp[a[i] - 1] == c[i])
            total += d[i];
        }
        ans = max(total ,ans);
        return ;
    }
    for(int i = start ; i <= end ; i ++)
    {
        temp[index] = i;
        find(i , end , temp , index + 1);
    }

}
int main()
{
   ll t;
   t = 1;	
   //cin t;
   while(t--){
        cin >> n >> m >> q;
        
        for(int i =0 ; i <q  ; i ++)
        cin >> a[i] >> b[i] >> c[i] >> d[i];

        int temp[n] = {0};
        find(1 , m , temp , 0);
        cout << ans << endl;
   }
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    ll h;
    cin >> h;
    ll ans = 0;
    ll num = 1;
    while (h >= 1) {
        ans += num;
        h /= 2;
        num *= 2;
    }
    cout << ans << endl;
    return 0;
}


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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  long long n,k,sum = 0;
  cin >> n >> k;
  int h[n];
  for (int i = 0; i < n; i++){
    cin >> h[i];
  }
  sort(h,h+n,greater<int>());
  for (int i = k; i < n; i++){
    sum += h[i];
  }
  cout << sum << '\n';
  return 0;
}

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

int main(){
  string s;
  cin >> s;
  int ans = 0;
  rep(i,int(s.size()))if(s[i]=='R')ans++;
  if(ans==0 || ans==1 || ans==3)cout << ans << endl;
  else if(s[1]=='S')cout << "1" << endl;
  else cout << "2" << endl;
  return 0;
}

Measured memory_bytes: 3564
N,M=map(int,input().split())
S=[list(map(int,input().split())) for n in range(N)]
C=[list(map(int,input().split())) for m in range(M)]
for s in S:
    l=[]
    for c in C:
        l.append(abs(s[0]-c[0])+abs(s[1]-c[1]))
    print(l.index(min(l))+1)


Measured memory_bytes: 3060
#include <cstdio>

long long Q, H, S, D;
long long N;
long long res;

void solve()
{
	Q *= 8;
	H *= 4;
	S *= 2;
	if(Q<=H && Q<=S && Q<=D){
		res = Q*(N/2);
	}
	else if(H<=Q && H<=S && H<=D){
		res = H*(N/2);
	}
	else if(S<=Q && S<=H && S<=D){
		res = S*(N/2);
	}
	else{
		res = D*(N/2);
	}
	if(N % 2 == 1){
		Q /= 2;
		H /= 2;
		S /= 2;
		if(Q<=H && Q<=S)
			res += Q;
		else if(H<=Q && H<=S)
			res += H;
		else
			res += S;
	}
	printf("%lld\n", res);
}

int main()
{
	scanf("%lld %lld %lld %lld", &Q, &H, &S, &D);
	scanf("%lld", &N);
	solve();
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

#define NIL -1
#define MAX 30

using namespace std;

struct Node {
	int parent, left, right;
};

Node node[MAX];

void preorder(int u) {
	if (u == NIL) return;

	cout << " " << u;
	preorder(node[u].left);
	preorder(node[u].right);
}

void inorder(int u) {
	if (u == NIL) return;
	inorder(node[u].left);
	cout << " " << u;
	inorder(node[u].right);
}

void postorder(int u) {
	if (u == NIL) return;
	postorder(node[u].left);
	postorder(node[u].right);
	cout << " " << u;
}

void init() {
	for (int i = 0; i < MAX; i++) {
		node[i].left = node[i].right = node[i].parent = NIL;
	}
}

signed main() {
	int n;
	int id, l, r;
	cin >> n;
	init();
	for (int i = 0; i < (int)n; i++) {
		cin >> id >> l >> r;
		node[id].left = l;
		node[id].right = r;

		if (l != NIL) node[l].parent = id;
		if (r != NIL) node[r].parent = id;
	}

	int root = 0;
	for (int i = 0; i < (int)n; i++) {
		if (node[i].parent == NIL) {
			root = i;
			break;
		}
	}
	cout << "Preorder" << endl;
	preorder(root);
	cout << "\n";
	cout << "Inorder" << endl;
	inorder(root);
	cout << "\n";
	cout << "Postorder" << endl;
	postorder(root);
	cout << "\n";

}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_H 310
#define MAX_W MAX_H

// 一次元累積和
// テンプレートであることに注意
template< typename T >
class CumulativeSum
{
public:
    vector< T > m_data;
    CumulativeSum() {};
    CumulativeSum(int sz) : m_data(sz, 0) {};

    // k に x を加える O(1)
    void Add(int k, int x) {
        assert(m_data.size() >= k);
        if(m_data.size() <= k) { m_data.push_back(x); }
        else { m_data[k] += x; }
    }

    // 累積和の構築 O(m_data.size())
    void Build() { for(int i = 1; i < m_data.size(); i++) { m_data[i] += m_data[i - 1]; } }

    // 区間 [0, k] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int k) {
        if(k < 0) { return 0; }
        return (m_data[min(k, (int) m_data.size() - 1)]);
    }

    // 区間 [l, h] の和を返す O(1)
    // 閉区間なので k が含まれることに注意
    T Query(int l, int h) { return this->Query(h) - this->Query(l-1); }
};

ll H, W, D, Q;
ll A[MAX_H][MAX_W] = {};
pair<ll, ll> Table[MAX_H * MAX_W] = {};   // 番号の位置
vector< pair<ll, ll> > LR;
map<ll, CumulativeSum<ll> > cs_map;

signed main()
{
    cin >> H >> W >> D;
    REP(i, H) {
        REP(j, W) {
            cin >> A[i][j];
            Table[A[i][j]] = make_pair(i, j);
        }
    }
    cin >> Q;
    REP(i, Q) {
        pair<ll, ll> tmp;
        cin >> tmp.first >> tmp.second;
        LR.push_back(tmp);
    }
    REP(i, Q) {
        ll key = LR[i].first % D;
        ll l = LR[i].first / D, r = LR[i].second / D;
        if(key == 0) {
            l = LR[i].first / D - 1;
            r = LR[i].second / D - 1;
        }
        //DBG("i: %lld key: %lld l: %lld r: %lld\n", i, key, l, r);
        if(cs_map.count(key) == 0) {
            // 累積和の作成
            CumulativeSum<ll> cs_tmp(H * W / D + 100);
            for(ll j = 0; j <= H * W / D - 1; ++j) {
                ll ind = j * D + key;
                if(key == 0) { ind = (j + 1) * D; }
                if(ind+D > H * W) { break; }
                ll magic = abs(Table[ind+D].first - Table[ind].first) + abs(Table[ind+D].second - Table[ind].second);
                cs_tmp.Add(j, magic);
            }
            cs_tmp.Build();
            cs_map[key] = cs_tmp;
        }
        if(l == r) { printf("0\n"); }
        else { printf("%lld\n", cs_map[key].Query(l, r-1)); }
    }
    return 0;
}


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

#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 SORTASC(c) sort((c).begin(),(c).end())
#define SORTDESC(c,t) sort((c).begin(),(c).end(), std::greater<t>());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define VMAX(a) *max_element(ALL(a))
#define VMIN(a) *min_element(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double PI  = acos(-1.0);

template <class T, class S>
using umap = std::unordered_map<T, S>;
using ll = long long;
using namespace std;

int main() {

    string s;

    cin >> s;

    if (s[2]==s[3] && s[4]==s[5]){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define lli long long int
#define endl "\n"
 
using namespace std;
 
typedef long long int LLI;
typedef double DB;
 
void fastio()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
}
 
 
bool comparator(pair<lli,lli> a,pair<lli,lli> b)
{
    if(a.first>b.first)
        return true;
    else if (a.first==b.second)
    {
        if(a.second>=b.second)
            return false;
        return true;
    }
    return false;
}
 
int mods(int x)
{
    if(x>0)
        return x;
    return -x;
}
 
lli gcd(lli a,lli b)
{
    return __gcd(a,b);
}
 
lli lcm(lli x,lli y,lli z)
{
    lli j=gcd(x,y);
    lli k=gcd(y*x/j,z);
    return (((x*y)/j)*z)/k;
} 

int isprime(int n)
{
    for(int i=2;i<=sqrt(n);++i)
    {
        if(n%i==0) return 0;
    }
    return 1;
}

int main()
{
    fastio();
    int n; cin>>n; 
    for(;;)
    {
        if(isprime(n)) {cout<<n; return 0;} ++n;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
s = []
n.times do
  s << gets.chomp
end

ac = 0
wa = 0
tle = 0
re = 0

s.each do |e|
  if e == "AC"
    ac += 1
  elsif e == "WA"
    wa += 1
  elsif e == "TLE"
    tle += 1
  elsif e == "RE"
    re += 1
  end
end

puts("AC x #{ac}")
puts("WA x #{wa}")
puts("TLE x #{tle}")
puts("RE x #{re}")

Measured memory_bytes: 21712
#include <stdio.h>

int main(void)
{
    int i, n, d[100];
    int a[100]={0}, c=0;

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

    for (i=0; i<n; i++) {
        if (a[d[i]]==0) {
            a[d[i]]=1;
            c++;
        }
    }

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

    return 0;
}

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

int r[101][101];
int d[101], f[101], num, visit[101], p=0;

void dfs(int n){
    if(!visit[n]){
        visit[n]++;
        d[n] = ++p;
        for(int i=1; i<num+1; i++)
            if(r[n][i]) dfs(i);
        f[n] = ++p;
    }
}

int main(void){
    int u, k, v;
    cin >> num;
    for(int i=0; i<num; i++){
        cin >> u >> k;
        for(int j=0; j<k; j++){
            cin >> v;
            r[u][v]++;
        }
    }
    for(int i=1; i<num+1; i++){
        if(!visit[i]) dfs(i);
    }
    for(int i=1; i<num+1; i++)
        cout << i << " " << d[i] << " " << f[i] << endl;
}



Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  string s, t;
  cin >> s >> t;
  int ans = 0;
  rep(i, s.size()) {
    if (s[i] == t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
int a, b;
  cin >> a >> b;
  if(a%3 ==0) cout << "Possible" << endl;
  else if(b%3 == 0)  cout << "Possible" << endl;
  else if((a+b)%3 == 0)cout << "Possible" << endl;
  else cout <<"Impossible" << endl;



}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 1001;
const int MOD = 1e9 + 7;

int add(int a, int b) {
	return (a + b) % MOD;
}

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

int binpow(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) res = mul(res, a);
		a = mul(a, a);
		b >>= 1;
	}
	return res;
}

int divv(int a, int b) {
	return mul(a, binpow(b, MOD - 2));
}

int f[N];
int C[N][N];

void init() {
	for (int n = 0; n < N; n++) {
		C[n][0] = 1;
		C[n][n] = 1;
		for (int k = 1; k + 1 <= n; k++) {
			C[n][k] = add(C[n - 1][k], C[n - 1][k - 1]);
		}
	}
	f[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = mul(f[i - 1], i);
	}
}

int dp[N][N];

int solve(int n, int cnt, int sz) {
	int sel = C[n][cnt * sz];
	//
	int all = sz * cnt;
	int c = 1;
	while (all > 0) {
		c = mul(c, C[all][sz]);
		all -= sz;
	}
	c = divv(c, f[cnt]);
	//
	return mul(sel, c);
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	init();
	int n, a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	dp[0][n] = 1;
	for (int i = 1; i <= n; i++) {
		for (int tk = 0; i * tk <= n; tk++) {
			if (tk > 0 && (i < a || i > b)) continue;
			if (tk > 0 && (tk < c || tk > d)) continue;
			// if (i == 1 && tk == 1) {
			// 	cerr << -1 << endl;
			// }
			for (int prev = 0; prev + i * tk <= n; prev++) {
				if (dp[i - 1][prev + i * tk] == 0) continue;
				// += dp[i - 1][prev] * prob
				int prob = solve(prev + i * tk, tk, i);
				// cerr << prev + i * tk << endl;
				// if (i == 1 && tk == 1 && prev + i * tk == n) {
				// 	cerr << "hr " << endl;
				// } 
				dp[i][prev] = add(dp[i][prev], mul(dp[i - 1][prev + i * tk], prob));
			}
		}
	}
	cout << dp[n][0] << endl;
	// cout << dp[1][n - 1] << endl;
	// cout <
}


Measured memory_bytes: 15872
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        while(H!=0||W!=0){
            for(int j=1;j<=H;j++){
                if(j%2!=0) {
                    for(int i=1;i<=W;i++){
                        if(i%2==0) System.out.print(".");
                        else       System.out.print("#");
                    }
                }else{ 
                    for(int i=1;i<=W;i++){
                        if(i%2==0) System.out.print("#");
                        else       System.out.print(".");
                    }
                }
                System.out.println();
            }
            System.out.println();
            H = sc.nextInt();
            W = sc.nextInt();
        }
    }
}


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

constexpr int INF = numeric_limits<int>::max() / 4;

#define REP(i, stop) for (signed i = 0; i < stop; ++i)

#define S(i, j) ip[i * (N + 1) + j]

const signed is = 1 << 16;
char ib[is], *ip = ib, it;
signed main() {
	fread_unlocked(ib, 1, is, stdin);
	int N = 0;
	while ((it = *ip++) != '\n') {
		N = N * 10 + it - '0';
	}
  queue<int> que;
  que.push(0);
  vector<bool> used(N, false);
  used[0] = 1;
  vector<int> parity(N, -1);
  parity[0] = 0;
  while (que.size()) {
    int i = que.front();
    que.pop();
    REP(j, N) {
      if (S(i, j) == '1') {
        if (used[j]) {
          if (parity[i] == parity[j]) {
		puts("-1\n");
		return 0;
          }
        } else {
          que.push(j);
          used[j] = true;
          parity[j] = 1 - parity[i];
        }
      }
    }
  }
	vector<vector<int>> d(N, vector<int>(N));
	REP(i, N) REP(j, N) {
		d[i][j] = i == j ? 0 : S(i, j) == '1' ? 1 : INF;
	}
	int ik, kj;
	REP(k, N)
	REP(i, N)
	if ((ik = d[i][k]) != INF)
	REP(j, N)
	if ((kj = d[k][j]) != INF)
	{
		d[i][j] = min(d[i][j], ik + kj);
	}
	int ans = 0;
	REP(i, N) REP(j, N) {
		if (d[i][j] < INF)
			ans = max(ans, d[i][j]);
	}
	printf("%d\n", ans + 1);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <chrono>
//#pragma GCC optimize("Ofast")
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
typedef pair<ll, ll> P;
const ll INF = (1LL<<60);

int main() {
    vec a(2), b(2);
    cin>>a[0]>>a[1]>>b[0]>>b[1];
    ll res = -INF;
    rep(i, 2) rep(j, 2) res = max(res, a[i] * b[j]);
    cout<<res<<endl;
}

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

bool CheckPayable(int x, vector<int> D){
  // x中にDが含まれていなければtrue,含まれていればfalse
  while(x>0){
    for(int i=0;i<D.size();i++){
      if(x%10 == D[i])return false;
    }
    x /= 10;
  }
  return true;
}

int main(){
  int N,K;
  cin >> N >> K;
  // N < 10000なので全列挙でもイケる？
  vector<int> D(K);
  rep(i,K)cin >> D[i];

  int ans = N;
  while(true){
    if(CheckPayable(ans, D)){
      cout << ans << endl;
      break;
    }
    ans++;
  }

}

/*
1:条件から支払い可能な数字を列挙してN以上であれば出力する
2:Nから支払額を1ずつ大きくして支払い可能であれば出力する全列挙
1の組み合わせのCpp実装むずそうなので2の方針で

数字の支払い可能か如何をどうやって判別しよう
*/

Measured memory_bytes: 3612
import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, M = LI()
AB = [[] for i in range(N)]
ABm = [[] for _ in range(M+1)]
for i in range(N):
    AB[i] = LI()
    if AB[i][0]<=M:
        ABm[AB[i][0]].append(AB[i][1])
#AB.sort(key=lambda x: x[1],reverse = True)
#print(ABm)
ans = []
cou = []
heapq.heapify(cou)
loop = M
for i in range(loop):
    for j in ABm[i+1]:
        heapq.heappush(cou, -j)
#    print(cou)
    if cou:
        ans.append(heapq.heappop(cou)*(-1))

#print(ans)
if ans:
    print(sum(ans))
else:
    print(0)

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

class Problem
{
private:
	// Variables
	int n;
	string s;

	int ans;
	
public:
	// Methods
	void input ()
	{
		cin >> n;
		cin >> s;
	}
	
	void process ()
	{
		vector<int> ws(n), es(n);
		int w = 0;
		int e = 0;
		for (int i=0; i<n; ++i) {
			ws[i] = w;
			es[n-1-i] = e;
			if ('W' == s[i]) {
				++w;
			}
			if ('E' == s[n-1-i]) {
				++e;
			}
		}

		ans = 0x7FFFFFFF;
		for (int i=0; i<n; ++i) {
			ans = min(ans, ws[i] + es[i]);
		}
	}
	
	void output ()
	{
		cout << ans << endl;
	}
};

int main ()
{
	Problem problem;
	problem.input();
	problem.process();
	problem.output();
	return 0;
}

Measured memory_bytes: 2948
#include<stdio.h>
int main(){
	int num[101][101]={0,};
	int r,c,i,j;
	int n,m,x,y;
	int b,d;
	scanf("%d %d",&r,&c);
	
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			scanf("%d ",&num[i][j]);
		}
	}
	for(x=0;x<c;x++){
		for(y=0;y<r;y++){
			num[r][x] += num[y][x];
		}
	}
	for(n=0;n<=r;n++){
		for(m=0;m<c;m++){
			num[n][c] += num[n][m];
		}
	}
	for(b=0;b<=r;b++){
		for(d=0;d<=c;d++){
			if(d==c){
			    printf("%d",num[b][d]);
			}else{
			    printf("%d ",num[b][d]);
			}
		}
		    printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2040
n,a,b,c,d = map(int,input().split())
s = input()
flg = False
if c < d:
    #最後まで動かす
    flg = True
else:#c>d
    if '...' in s[b-2:d+1]:
        flg = True
if '##' in s[a-1:max(d,c)-1]:
    flg = False
if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k; cin >> n >> k;
  string s; cin >> s;
  int cnt = 0;
  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == s[i + 1]) ++cnt;
  }
  cout << min(n - 1, cnt + 2 * k) << endl;
}

Measured memory_bytes: 512
/**
 * Title: D - Line++
 * Url: https://atcoder.jp/contests/abc160/tasks/abc160_d
 */
#include<bits/stdc++.h>

using namespace std;

#define ll long long

const int MAX_N = 2000;

int g[MAX_N+1][MAX_N+1];

int main() {
    int n, x, y; cin >> n >> x >> y;
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=n; j++) {
            g[i][j] = abs(j-i);
        }
    }

    for(int i=1; i<=n-1; i++) {
        for(int j=i+1; j<=n; j++) {
            g[i][j] = min(g[i][j], min(g[i][x]+1+g[y][j], g[i][y]+1+g[x][j]));
        }
    }

    map<int, int> dic;
    for(int i=1; i<=n-1; i++) {
        for(int j=i+1; j<=n; j++) {
            if(dic.count(g[i][j])==0) {
                dic[g[i][j]] = 1;
            } else {
                dic[g[i][j]]++;
            }
        }
    }

    for(int i=1; i<=n-1; i++) {
        cout << dic[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 16000
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[20],i,f=0,s=0;
    for(i=1;i<=3;i++)
    {
        cin>>a[i];
        if(a[i]==5)
            f++;
        else
            s++;
    }
    if(f==2 && s==1)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 10000007
#define PI 3.14159265359
typedef long long ll;
//

int main(){
    int n,k;cin>>n>>k;
    vector<bool> flag;
    vector<int> v,vv;
    rep(i,n){
        int a;cin>>a;
        v.push_back(a);
    }
    FOR(i,0,n-k-1){
        
        if(v[i+k]>v[i])flag.push_back(true);
        else flag.push_back(false);
    }
    for(auto e:flag){
        if(e)cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
}

Measured memory_bytes: 4312
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i++)

using namespace std;

int main(){
  int A,B ; cin >> A >> B;

  int ans = -100;
  ans = max(ans,A+B);
  ans = max(ans,A-B);
  ans = max(ans,A*B);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
	char a[3];
	char b[3];
	int x = 0;
	scanf("%s %s",a,b);
	if(a[0]==b[0]){x = x + 1;}
	if(a[1]==b[1]){x = x + 1;}
	if(a[2]==b[2]){x = x + 1;}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(void)
{
	int n,j,m,day[12]={31,29,31,30,31,30,31,31,30,31,30,31};
	while(1){
		scanf("%d",&n);
		scanf("%d",&j);
		if(n==0&&j==0)
		break;
		for(m=1;m<n;m++){
			j=j+day[m-1];
		}
		j=j%7;
		if(j==1)
		printf("Thursday\n");
		else if(j==2)
		printf("Friday\n");
		else if(j==3)
		printf("Saturday\n");
		else if(j==4)
		printf("Sunday\n");
		else if(j==5)
		printf("Monday\n");
		else if(j==6)
		printf("Tuesday\n");
		else
		printf("Wednesday\n");
	}
	return 0;
}

Measured memory_bytes: 584
import collections

n = int(input())
a = list(map(str, input().split()))
x1 = []
x2 = []
x3 = []
for i in range(n):
    tmp = str(int(a[i]) + 1)
    x1.append(tmp)
    tmp = a[i]
    x2.append(tmp)
    tmp = str(int(a[i]) - 1)
    x3.append(tmp)

x1.extend(x2)
x1.extend(x3)
x1.sort()
set_x1 = set(x1)
c = collections.Counter(x1)
Max = 0
for i in set_x1:
    if int(c[str(i)]) > Max:
        Max = int(c[str(i)])
print(Max)


Measured memory_bytes: 42456
#include<iostream>
#include<algorithm>
using namespace std;
#define INF ( 1 << 30 )
int data[10000], n;
int solve(int right){
  int left = right + 1, size = n;
  while("Misuya"){
    int dis = 0, now = data[right];
    while(right >= 0 && data[right] == now ) dis++,right--;
    while(left < n && data[left] == now ) dis++,left++;
    if(dis < 4) break;
    else size -= dis;
  }
  return size;
}
int main(){
  while(cin >> n , n){
    for(int i = 0 ; i < n ; i++ ) cin >> data[i];
    int ret = INF;
    for(int i = 0 ; i < n ; i++ ){
      for(int j = 0 ; j < 4 ; j++ ){
        swap(data[i],j);
        ret = min( ret, solve(i));
        swap(data[i],j);
      }
    }
    cout << ret << endl;
  }
}

Measured memory_bytes: 1200
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
import std.bigint, std.functional;

void main() {
  auto Ni = readln.chomp;
  auto K = readln.chomp.to!(ulong);
  auto N = BigInt(Ni);
  auto Ns = Ni.length;
  ulong ans;

  char[] keta_base;
  foreach(i; 0..Ns-1) keta_base ~= "0";

  void solve1() {
    foreach(i; 1..Ns) ans += 9;
    foreach(i; 1..10) {
      if (BigInt(i.to!(char[]) ~ keta_base) <= N) ans++;
    }
  }

  void solve2() {
    foreach(i; 1..Ns) ans += (i-1)*81;
    foreach(i; 1..10) {
      foreach(k; 1..Ns) {
        char[] num = i.to!(char[]) ~ keta_base;
        if (BigInt(num) > N) break;

        foreach(o; 1..10) {
          num[k] = cast(char)(o + '0');
          if (BigInt(num) <= N) {
            ans++;
          }
        }
      }
    }
  }

  void solve3() {
    ulong sigma;
    foreach(i; 3..Ns) {
      sigma += i - 2;
      ans += sigma*729;
    }
    foreach(h; 1..10) {
      foreach(k; 1..Ns-1) {
      foreach(l; k+1..Ns) {
        char[] num = h.to!(char[]) ~ keta_base;
        foreach(i; 1..10) {
          for(int o = 9; o > 0; o--) {
            num[k] = cast(char)(i + '0');
            num[l] = cast(char)(o + '0');
            if (BigInt(num) <= N) {
              ans += o;
              break;
            }
          }
        }
      }
      }
    }
  }

  void solve() {
    if (K == 1) solve1();
    if (K == 2) solve2();
    if (K == 3) solve3();
    writeln(ans);
  }

  solve();
}


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

using namespace std;

bool is_decreasing(int v)
{
    int d = v % 10;
    v /= 10;
    while (v > 0)
    {
        if (d - 1 != v % 10)
        {
            return false;
        }
        d = v % 10;
        v /= 10;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    vector<int> vs(n);
    for (int &v : vs)
    {
        cin >> v;
    }
    int max_val = -1;
    for (int i = 0; i < n; i++)
    {
        for (int j = i + 1; j < n; j++)
        {
            if (is_decreasing(vs[i] * vs[j]))
            {
                max_val = max(max_val, vs[i] * vs[j]);
            }
        }
    }
    cout << max_val << endl;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define int ll
#define ff first
#define ss second
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll, ll>
using namespace std;

const ll INF = 1e18+7;
const int maxN = 300005;


main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i=0;i<n;i++)
        cin>>a[i];
    vector<pii> res;
    pii mx={a[0], 0}, mn = {a[0], 0};
    for (int i=1;i<n;i++)
    {
        pii cur = {a[i], i};
        mx = max(cur, mx);
        mn = min(cur, mn);
    }
    if (abs(mn.ff) > abs(mx.ff))
    {
        for (int i=n-2;i>=0;i--)
        {
            while (a[i] > a[i+1])
            {
                a[i] += mn.ff;
                res.pb({mn.ss, i});
                mn = min(mn, {a[i], i});
            }
        }
    }
    else
    {
        for (int i=1;i<n;i++)
        {
            while (a[i]<a[i-1])
            {
                a[i] += mx.ff;
                res.pb({mx.ss, i});
                mx = max(mx, {a[i], i});
            }
        }
    }
    cout<<res.size()<<endl;
    for (int i=0;i<res.size();i++)
        cout<<res[i].ff+1<<' '<<res[i].ss+1<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <cmath>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cstdio>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LL_MAX = numeric_limits<ll>::max();
constexpr ull ULL_MAX = numeric_limits<ull>::max();
constexpr ll I_MAX = numeric_limits<int>::max();
constexpr ull UI_MAX = numeric_limits<unsigned int>::max();

#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)


struct product {
	ll w;
	ll v;
};

int main() {

	int n, w;
	cin >> n >> w;

	vector<ll> empty(100001, I_MAX);
	vector<vector<ll>> dp(n+1,empty);
	vector<product> p(n + 1);
	rep(i, 0, n) {
		ll tw, tv;
		cin >> tw >> tv;
		p[i + 1] = product{tw, tv};
	}
	rep(i, 0, n + 1) {
		dp[i][0] = 0;
	}
	rep(i, 1, n + 1) {

		rep(j, 0, 100001) {
			if (j - p[i].v >= 0) {
				dp[i][j] = min(dp[i - 1][j - p[i].v] + p[i].w, dp[i - 1][j]);
			}
			else {
				dp[i][j] = dp[i - 1][j];
			}
		}
	}
	int ans = 0;
	rep(i, 0, 100001) {
		if (dp[n][i] <= w) {
			ans = i;
		}
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b;
  cin>>n;
  a=n/10;
  b=n;
  for (;b>=1000;b=b-1000){}
  if(a%111==0||b%111==0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 256
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
 
class Program {
    static void Main(string[] args) {
        var NK = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        double N = NK[0];
        double K = NK[1];
        double res = 0;
        for(int i = 1;i <= N;i++){
            var count = 0;
            while(i*Math.Pow(2,count) < K){
                count++;
            }
            res += (1/N)*(1/Math.Pow(2,count));
        }
        Console.WriteLine(res);
    }             
     }


Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));

int main(){
	int c[5][5]; REP(i,0,3) REP(j,0,3) cin >> c[i][j];
	
	int a[5], b[5];
	a[0] = c[0][0];
	b[0] = 0;
	a[1] = c[1][0];
	b[1] = c[1][1] - a[1];
	a[2] = c[2][1] - b[1];
	b[2] = c[2][2] - a[2];
	
	int pos[5][5];
	REP(i,0,3) REP(j,0,3) pos[i][j] = a[i] + b[j];
	REP(i,0,3) REP(j,0,3) if(c[i][j] != pos[i][j]){cout << "No" << endl; return 0;}
	
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<string>


long long  INF=1000000000000000000;
using namespace std;


int main(){

long long  N,K;
cin>>N>>K;

long long ans=0;
if(K==0){
    ans=N*N;
    cout<<ans<<endl;
    return 0;
}
/*
for( int i=K;i<=N;i++){
    for(int l=K+1;l<=N;l++){
        if(i>l && )

        if(i<l){
            ans+=N-l+1;
            break;  
            }     
        if(i%l>=K ){
            ans++;   
        }
    }
}
*/
for(long long  l=K+1;l<=N;l++){
        ans+=(N/l)*(l-K);
        long long  t=N%l;
        long long p=0;
        if(t>=K){
        ans+=max(p,t-K+1);
        }
}

cout<<ans<<endl;
 return 0;
}
/*
5 2

7

10 0

100

31415 9265

287927211
*/

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

class Stack {
public:
    void initialize();
    void push(int x);
    int pop();
private:
    int a[100];
    int top;
};

void Stack::initialize() {
    top = 0;
}

void Stack::push(int x) {
    a[++top] = x;
}

int Stack::pop() {
    top--;
    return a[top+1];
}

//???????????¢??°
int main() {
    int a, b;
    Stack stack;
    stack.initialize();
    string str;

    while (cin >> str, ! cin.eof()) {
        if (str == "+") {
            a = stack.pop();
            b = stack.pop();
            stack.push(a + b);
        } else if (str == "-") {
            a = stack.pop();
            b = stack.pop();
            stack.push(b - a);
        } else if (str == "*") {
            a = stack.pop();
            b = stack.pop();
            stack.push(a * b);
        } else {
            stack.push(atoi(str.c_str()));
        }
    }

    cout << stack.pop() << endl;
}

Measured memory_bytes: 3192
//include
//------------------------------------------
#include <bits/stdc++.h>
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> P;
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);
const ll INF = 1000000007;
//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;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int n;
    cin >> n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];

    VVI v(n, VI(26, 0));
    REP(i,n){
        REP(j,s[i].size()){
            v[i][s[i][j] - 'a']++;
        }
    }

    string ans = "";
    REP(i,26){
        int min = 50;
        REP(j,n){
            chmin(min, v[j][i]);
        }
        ans += string(min, i+'a');
    }

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

Measured memory_bytes: 256
import sys
import time
import math
import itertools as it
def inpl():
    return list(map(int, input().split()))
st = time.perf_counter()
# ------------------------------

A, B, H, M = inpl()
h = 360 * H / 12 + 30 * M / 60
m = 360 * M / 60
sa = abs(h - m)
sa = min(sa, 360-sa)

print((A*A + B*B - 2*A*B*math.cos(sa*math.pi/180))**0.5)

# ------------------------------
ed = time.perf_counter()
print('time:', ed-st, file=sys.stderr)


Measured memory_bytes: 9488
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int mod = 1e9+7;
const int maxn = 2e5+5;
int main() {
	ll x,y,z;
	cin>>x>>y>>z;
	if((x==y&&x!=z)||(x==z&&x!=y)||(y==z&&x!=y)){
		cout<<"Yes\n";
	} 
	else {
		cout<<"No\n";
	}
    return 0;
}



Measured memory_bytes: 256