akhauriyash/Code-Regression huggingface dataset:
n,m = map(int,input().strip().split())

arr = [0]*(n+2)

for i in range(m):
    l,r = map(int,input().strip().split())

    arr[l-1]+=1
    arr[r]-=1

for i in range(1,len(arr)):
    arr[i] += arr[i-1]


ans = 0

for i in range(len(arr)):
    if arr[i]==m:
        ans+=1

print(ans)


Measured memory_bytes: 6900
#include<bits/stdc++.h>
#define llong long long
#define mkpr make_pair
#define x first
#define y second
#define iter iterator
#define riter reverse_iterator
#define y1 Lorem_ipsum_
#define tm dolor_sit_amet_
using namespace std;

inline int read()
{
	int x = 0,f = 1; char ch = getchar();
	for(;!isdigit(ch);ch=getchar()) {if(ch=='-') f = -1;}
	for(; isdigit(ch);ch=getchar()) {x = x*10+ch-48;}
	return x*f;
}

const int mxN = 1e6;
const int S = 26;
char str[mxN+3];
int fa[mxN+3],son[mxN+3][S+3],vn[mxN+3],sz[mxN+3],f[mxN+3][S+3],g[mxN+3],lst[mxN+3][S+3];
int pos[mxN+3];
int n,siz,rtn; llong ans;

int insert(int len,char str[])
{
	int u = rtn;
	for(int i=len; i>=1; i--)
	{
		if(!son[u][str[i]]) {son[u][str[i]] = ++siz; fa[siz] = u;}
		u = son[u][str[i]];
	}
	vn[u]++; return u;
}
void dfs1(int u)
{
	for(int i=1; i<=S; i++) {f[u][i] = f[fa[u]][i]+(u==son[fa[u]][i]?0:vn[son[fa[u]][i]]);}
	g[u] = g[fa[u]]+vn[u];
	for(int i=1; i<=S; i++) if(son[u][i])
	{
		memcpy(lst[son[u][i]],lst[u],sizeof(lst[u])); lst[son[u][i]][i] = son[u][i];
		dfs1(son[u][i]);
	}
}

int main()
{
	n = read(); rtn = siz = 1;
	for(int i=1; i<=n; i++)
	{
		scanf("%s",str+1); int len = strlen(str+1); for(int j=1; j<=len; j++) str[j] -= 96;
		pos[i] = insert(len,str);
	}
	dfs1(1);
	for(int i=1; i<=n; i++)
	{
		for(int j=1; j<=S; j++)
		{
			ans += f[fa[lst[pos[i]][j]]][j];
		}
		ans += g[fa[pos[i]]];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 393784
#!/usr/bin/env python3
import sys, math, fractions, itertools, heapq

def solve(N: int, k: int, t: "List[int]", d: "List[int]"):
    arr = sorted(zip(t, d), key=lambda x: x[1], reverse=True)
    q = [] # ヒープ
    v = set() # ネタの種類
    s = 0 # 美味しさの合計
    for t,d in arr[:k]:
        s += d
        if t in v:
            heapq.heappush(q,d)
        else:
            v.add(t)
    s += len(v)**2
    ans = s # arr[:k]での点数
    for t,d in arr[k:]: # 使っていない寿司について考える
        if t not in v and len(q)!=0: # 新規のネタのとき
            z = heapq.heappop(q) # 最小値を一つ捨てる
            s += d + 2*len(v) + 1 - z # 差分を計算する
            v.add(t)
            ans=max(ans,s) #結果として大きかった方を取る
    print(ans)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    t = [int()] * (N)  # type: "List[int]" 
    d = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        t[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, K, t, d)

if __name__ == '__main__':
    main()


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

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

// 素因数分解
vector<pair<Int, Int>> factorization(Int n) {
    vector<pair<Int, Int>> ret;
    for (Int i = 2; i * i <= n; i++) {
        Int cnt = 0;
        while (n % i == 0) {
            n /= i;
            cnt++;
        }
        if (cnt > 0) {
            ret.emplace_back(i, cnt);
        }
    }
    if (n > 1) {
        ret.emplace_back(n, 1);
    }
    return ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Int n;
    cin >> n;
    vector<Int> a(n);
    for (Int i = 0; i < n; i++) {
        cin >> a[i];
    }
    unordered_map<Int, Int> mp;
    mp.reserve(n);
    for (Int i = 0; i < n; i++) {
        bool check = true;
        vector<pair<Int, Int>> v = factorization(a[i]);
        for (Int j = 0; j < (Int)v.size(); j++) {
            if (mp.find(v[j].first) != mp.end()) {
                check = false;
                break;
            }
            mp[v[j].first]++;
        }
        if (not check) {
            Int x = a[0];
            for (Int j = 1; j < n; j++) {
                x = gcd(x, a[j]);
            }
            if (x == 1) {
                print("setwise coprime");
            } else {
                print("not coprime");
            }
            return 0;
        }
    }
    print("pairwise coprime");
    return 0;
}


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

const int N=1e5+20,MOD=1e9+7;

int n,k,a[N],f[N],ie[N],ans;

int power(int a,int b)
{
	int num=a,ans=1;
	for(int i=0;i<31;i++)
	{
		if(b&(1<<i)) ans=(1ll*ans*num)%MOD;
		num=(1ll*num*num)%MOD;
	}
	return ans;
}

int inverse_euler(int n)
{
	return power(n,MOD-2);
}

int ncr(int n,int r)
{
	return (1LL*f[n]*((1LL*ie[r]*ie[n-r])%MOD))%MOD;
}

void precompute()
{
	f[0]=1;
	for(int i=1;i<N;i++) f[i]=(1LL*f[i-1]*i)%MOD;
	for(int i=0;i<N;i++) ie[i]=inverse_euler(f[i]);
}

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

void add(int &a,int b)
{
	a=(a+b)%MOD;
}

int main()
{
	precompute();

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

	sort(a,a+n);
	for(int i=0;i<n;i++)
	{
		if(i+k<=n) sub(ans,(1ll*a[i]*ncr(n-i-1,k-1))%MOD);
		if(i>=k-1) add(ans,(1ll*a[i]*ncr(i,k-1))%MOD);
	}
	printf("%d",ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


struct Info{
	int x;
	long double h;
};

long double calc(long double tmp_x,long double tmp_distance){
	return sqrt(tmp_x*tmp_x + (tmp_distance/(2*tmp_x))*(tmp_distance/(2*tmp_x)));
}

int main(){

	double distance;
	int N,bounce_limit;

	scanf("%lf %d %d",&distance,&N,&bounce_limit);

	Info info[N];

	for(int i = 0; i < N ;i++){
		cin >> info[i].x >> info[i].h;
	}

	long double tmp_distance;

	long double ans = 1000000.0;
	long double left,right,m,tmp_x,max_x,tmp_y,tmp_dist,tmp_h;

	bool FLG;

	for(int b_count = 1; b_count <= bounce_limit+1; b_count++){

		tmp_distance = (double)distance/b_count;

		left = 0.0,right = DBL_MAX,m = (left+right)/2;

		while(left <= right){

			tmp_x = m;
			tmp_y = tmp_distance/(2*tmp_x);

			FLG = true;

			for(int i = 0; i < N; i++){
				tmp_dist = info[i].x;

				while(tmp_dist >= tmp_distance)tmp_dist -= tmp_distance;

				tmp_h = (tmp_y/tmp_x)*tmp_dist-1.0/(2*tmp_x*tmp_x)*(tmp_dist*tmp_dist);

				if(info[i].h > tmp_h){
					FLG = false;
					break;
				}
			}
			if(FLG){
				left = m+EPS;
			}else{
				max_x = m;
				right = m-EPS;
			}
			m = (left+right)/2;
		}

		ans = min(ans,calc(max_x,tmp_distance));

		left = 0.0,right = max_x;

		while(true){
			if(right-left < EPS){
				ans = min(ans,calc((right-left)/2,tmp_distance));
				break;
			}

			long double mid1 = left + (right-left)/3;
			long double mid2 = left + (right-left)/3*2;

			long double v_1 = calc(mid1,tmp_distance);
			long double v_2 = calc(mid2,tmp_distance);

			ans = min(ans,min(v_1,v_2));

			if(v_1 < v_2){
				right = mid2-EPS;
			}else{
				left = mid1+EPS;
			}
		}
	}

	printf("%.12Lf\n",ans);

	return 0;
}

Measured memory_bytes: 3248
I=lambda:[int(i)for i in input().split()]
F=1<<65
r=range
n,m=I()
X=set([0,F,-F])
Y=set(X)
R=[((-F,F),F),((-F,F),-F)]
H=[(F,(-F,F)),(-F,(-F,F))]
for i in r(n):a,b,c=I();R.append(((a,b),c));Y.add(c);X.add(a);X.add(b)
for i in r(m):a,b,c=I();H.append((a,(b,c)));X.add(a);Y.add(b);Y.add(c)

s=dict(enumerate(sorted(X)))
nx=len(s)
t=dict(enumerate(sorted(Y)))
ny=len(t)
 
h=dict(zip(s.values(),s.keys()))
w=dict(zip(t.values(),t.keys()))
 
V=[[0]*-~nx for i in r(ny+1)]
U=[i[:]for i in V]
v=[i[:]for i in V]

for (a,b),c in R:U[w[c]][h[a]]+=1;U[w[c]][h[b]]+=-1
for i in r(ny+1):
 for j in r(nx):
  U[i][j+1]+=U[i][j]
        
for d,(e,f) in H:V[w[e]][h[d]]+=1;V[w[f]][h[d]]+=-1
for j in r(nx+1):
 for i in r(ny):
  V[i+1][j]+=V[i][j]

q=[(h[0],w[0])]
v[w[0]][h[0]]=1

a=0
while q:
 x,y=q.pop();a+=(s[x]-s[x+1])*(t[y]-t[y+1])
 for e,f in[(-1,0),(1,0),(0,1),(0,-1)]:
  k=0;c=x+e;d=y+f
  if(0<=c<nx)*(0<=d<ny)*v[d][c]==0:k=U[-~f//2+y][x]==0if f!=0else V[y][-~e//2+x]==0
  if k:q.append((c,d));v[d][c]=1
if a>=F:a='INF'
print(a)


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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int A, B, C;
    cin >> A >> B >> C;

    if (A == B && B == C && C == A) {
        print("No");
    } else if (A != B && B != C && C != A){
        print("No");
    } else {
        print("Yes");
    }
}

signed main() {
    solve();
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>

using namespace std;

int main() {

    int N;
    cin >> N;
    int a[N];
    for(int i = 0; i < N; i++){
        a[i] = 0;
        int b = 0;
        cin >> b;
        while(b > 0){
            if(b % 2 == 1) break;
            else a[i]++;
            b /= 2;
        }
    }
    int out = 1000;
    for(int i = 0; i < N; i++){
        if(a[i] < out) out = a[i];
    }
    cout << out << endl;
    return 0;
}


Measured memory_bytes: 256
// --https://kenkoooo.com/atcoder/#/table/soma62jp
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstring>

#define	MOD	1000000007

using namespace std;

int main(int argc, char* argv[]) {

	int N, M, flg, i, j, ans = 0;

	cin >> N >> M;

	vector<string>A(N);
	vector<string>B(M);

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	for (int i = 0; i < M; i++) {
		cin >> B[i];
	}

	if (N == M) {
		i = 0;
		j = 0;
		goto START;
	}

	for (i = 0; i < N - M; i++) {
		for (j = 0; j < N - M; j++) {
START:
			flg = 1;
			for (int k = 0; k < M; k++) {
				for (int l = 0; l < M; l++) {
					if (A[i + k][j + l] != B[k][l]) {
						flg = 0;
					}
				}
			}
			if (flg) {
				ans = 1;
				goto END;
			}
		}
	}

END:

	if (ans) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;

}

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

using namespace std;
typedef long long int ll;
int main() {
    
    ll n, k, i, a[200001], big, end, mid;
    cin>>n>>k;
    for(i=1;i<=n;i++){
    scanf("%lld", &a[i]);
    a[i]*=2;
}
    big=1;
    end=300000000000;
    while(big!=end)
    {
        mid=(big+end)/2;
        ll imsi=0;
        for(i=1;i<=n;i++)
        {
            imsi+=(((a[i]+mid-1)/mid)-1);
        }
        if(imsi<=k)
        end=mid;
        
        else
        big=mid+1;
    }
    
    cout<<(big+1)/2;
    
    return 0;
}

Measured memory_bytes: 5240
N = int(input())
A = [int(a) for a in input().split()]

L1 = [0]*N
L2 = [0]*N
for i in range(N):
    L1[i] = i+1-A[i]
    L2[i] = i+1+A[i]

L1.sort()
L2.sort()

import bisect

ans = 0
for l in L1:
    a = bisect.bisect_right(L2, l)
    b = bisect.bisect_left(L2, l)
    ans += a-b

print(ans)

Measured memory_bytes: 103372
N, K = map(int, input().split())
R, S, P = map(int, input().split())
s = input()

wn = {'r': 'p', 's': 'r', 'p': 's'}
pt = {'r': P, 's': R, 'p': S}

ans = 0
t = [''] * len(s)
for i in range(len(s)):
    if i + 1 <= K:
        ans += pt[s[i]]
        t[i] = wn[s[i]]
    else:
        if wn[s[i]] != t[i-K]:
            ans += pt[s[i]]
            t[i] = wn[s[i]]

print(ans)


Measured memory_bytes: 4084
K,S = map(int, input().split(" "))

combo_count = 0
for X in range(max(0, S-K*2), min(S//3, K)+1):
    S2 = S-X
    for Y in range(max(X,S2-K), min(S2//2, K)+1):
        Z = S2 - Y
        if X == Y and Y == Z:
            combo_count += 1
        elif X == Y or Y == Z:
            combo_count += 3
        else:
            combo_count += 6
print(combo_count)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	char in;
	for (;;) {
		scanf("%c", &in);
		switch (!islower(in)) {
		case 0:
			printf("%c", toupper(in));
			break;
		default:
			printf("%c", in);
		}
		if (in == '\n')
			return 0;
	}
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

const int INF = 100000;

int main(void) {
    int H,W;
    cin >> H >> W;
    int c[10][10];
    for (int i=0; i<10; i++) {
        for (int j=0; j<10; j++) cin >> c[i][j];
    }
    int A[H][W];
    for (int i=0; i<H; i++) {
        for (int j=0; j<W; j++) cin >> A[i][j];
    }

    for (int i=0; i<10; i++)
        for (int j=0; j<10; j++)
            for (int k=0; k<10; k++)
                c[j][k] = min(c[j][k], c[j][i] + c[i][k]);

    int ans = 0;
    for (int i=0; i<H; i++)
        for (int j=0; j<W; j++) {
            if (A[i][j] == -1) continue;
            ans += c[A[i][j]][1];
        }

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


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
class Trees{
    vector<long> par;
    vector<long> rank;
public:
    long root(long i){
        long rt;
        if(par[i]==i){rt=i;rank[i]=1;}
        else{rt=root(par[i]);par[i]=rt;rank[i]=2;}
        return rt;
    }
    void unite(long i,long j){
        long rki=rank[i];long rkj=rank[j];
        if(rki<rkj){par[root(i)]=root(j);rank[i]++;}
        else{par[root(j)]=root(i);rank[j]++;}
    }
    bool same(long i,long j){
        return root(i)==root(j);
    }
    Trees(long n){
        for(long i=0;i<n;i++) {par.push_back(i);rank.push_back(1);};
    }
};
struct Point{
    long x,y;
    long id;
};
bool cmpx(const Point& left, const Point& right){
    return left.x<right.x;
}
bool cmpy(const Point& left, const Point& right){
    return left.y<right.y;
}
bool cmpid(const Point& left, const Point& right){
    return left.id<right.id;
}
struct Group{
    long num;
    set<long>X,Y;
    Group(){
        num=0;
    }
};
int main(){
    long N;cin>>N;
    Trees trees(N);
    vector<Point>points(N);
    for(long i=0;i<N;i++){cin>>points[i].x>>points[i].y;points[i].id=i;}
    //xでまとめる
    sort(points.begin(),points.end(),cmpx);
    long last=0;
    for(long i=0;i<N;i++){
        if(points[i].x!=points[last].x)last=i;
        else trees.unite(points[i].id,points[last].id);
    }
    //yでまとめる
    sort(points.begin(),points.end(),cmpy);
    last=0;
    for(long i=0;i<N;i++){
        if(points[i].y!=points[last].y)last=i;
        else trees.unite(points[i].id,points[last].id);
    }
    //配列順序をもとに戻す
    sort(points.begin(),points.end(),cmpid);
    
    vector<Group> group(N);//root基準でやる
    for(long i=0;i<N;i++){
        group[trees.root(i)].num++;
        group[trees.root(i)].X.insert(points[i].x);
        group[trees.root(i)].Y.insert(points[i].y);
    }
    long ans=0;
    for(long i=0;i<N;i++){
        ans+=group[i].X.size()*group[i].Y.size()-group[i].num;
    }
    while(ans<0);
    cout<<ans;
}

//union findが楽か?
//最初に, x座標でソートして, 同じものを同じに分類する
//なんで負?











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

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

#ifndef __MACRO_H__
#define __MACRO_H__

#define all(collection)  (collection).begin(), (collection).end()		// begin to end
#define rep(i, begin, end) for (ll i = begin; i < end; i++)				// repeat
#define repr(i, begin, end) for (ll i = end - 1; begin <= i; i--)		// repeat reverse

#endif

namespace NyaGadgetUnionFind
{
	struct Vertex
	{	// 頂点を表現する構造体
		ll root;
		ll size;
	};

	template <class V> struct Graph
	{	// グラフを表現する構造体
		vector<V> vertex;
		Graph(ll v_size)
		{	// グラフ構造を構造体に格納する
			vertex.resize(v_size);
			rep(i, 0, (ll)vertex.size())
			{	// 各頂点の根を自分自身で初期化、各頂点の木サイズは１で初期化
				vertex[i].root = i;
				vertex[i].size = 1;
			}
		}
		Vertex& FindRoot(ll v_index)
		{
			// 自分自身が根のとき
			if (v_index == vertex[v_index].root)
				return vertex[vertex[v_index].root];
			// 根の探索をすると同時に次からO(1)で根を参照できるようにする
			vertex[v_index].root = FindRoot(vertex[v_index].root).root;
			return vertex[vertex[v_index].root];
		}
		void UnionTree(ll v1_index, ll v2_index)
		{
			ll tree1_root = FindRoot(v1_index).root;
			ll tree2_root = FindRoot(v2_index).root;

			if (tree1_root == tree2_root)
				return;

			// サイズの小さい木の根をサイズの大きい木の根に繋いで結合する
			if (vertex[tree1_root].size < vertex[tree2_root].size)
			{
				vertex[tree1_root].root = tree2_root;
				vertex[tree2_root].size += vertex[tree1_root].size;
			}
			else
			{
				vertex[tree2_root].root = tree1_root;
				vertex[tree1_root].size += vertex[tree2_root].size;
			}
		}
	};
}

using namespace NyaGadgetUnionFind;

// test

class ABC120D
{
public:
	ABC120D()
	{
		cin >> n >> m;
		a.resize(m);
		b.resize(m);
		rep(i, 0, m)
		{
			cin >> a[i] >> b[i];
			a[i]--; b[i]--;
		}
	}
	void Run(void)
	{
		Graph<Vertex> g(n);

		vector<ll> ans(m);
		ans[m-1] = n * (n - 1) / 2;
		repr(i, 1, m)
		{
			if (g.FindRoot(a[i]).size == n)
				break;

			if (g.FindRoot(a[i]).root == g.FindRoot(b[i]).root)
				ans[i - 1] = ans[i];
			else
				ans[i - 1] = ans[i] - g.FindRoot(a[i]).size * g.FindRoot(b[i]).size;

			g.UnionTree(a[i], b[i]);
		}
		for (const auto& e : ans)
			cout << e << endl;
	}
private:
	ll n;
	ll m;
	vector<ll> a;
	vector<ll> b;
};

int main(void)
{
	ABC120D abc120d;
	abc120d.Run();

	return 0;
}


Measured memory_bytes: 5248
n, p = map(int, input().split())
A = list(map(int, input().split()))
even = 0
odd = 0

for i in range(n):
    if A[i] % 2 == 0:
        even += 1
    else:
        odd += 1

even_answer = 2 ** even

check = p


def kaijo(i):
    if (i == 1) or (i == 0):
        return 1
    return i * kaijo(i - 1)


odd_answer = 0
while check <= odd:
    # print(kaijo(n) / kaijo(check) / kaijo(n - check))
    odd_answer = odd_answer + (kaijo(odd) / kaijo(check) / kaijo(odd - check))
    # print(odd_answer)
    check += 2

print(int(odd_answer * even_answer))


Measured memory_bytes: 9208
#include<iostream>
#include<vector>
#include<set>
#include<unordered_set>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<tuple>
#include<iomanip>
#include<climits>
#define ll long long int
#define mod 1000000007
#define pi acos(-1)
using namespace std;

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n ,k;
  cin>>n;
  int arr[n];
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  ll ans=LLONG_MAX;
  for(int i=1;i<=100;i++)
  {
    ll tmp=0;
    for(int j=0;j<n;j++)
    {
      tmp+= (arr[j]-i)*(arr[j]-i);
    }
    ans = min(ans, tmp);
  }
  cout<<ans;
}

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

int main(){
  int n;
  cin >> n;
  for (int i = 0; i < n/4+ 1; i++){
    int a = n - 4 * i;
    if (a % 7 == 0){
      cout << "Yes" << endl;
      break;
    }
    else if ( i == n/4){
      cout << "No" << endl;
    }
    else
      continue;
  }
}

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

// 順列全探索は分かるけど、実装に工夫が必要
int main() {
  int n;
  cin >> n;

  vector<int> p(n), q(n);
  rep(i, n) cin >> p[i];
  rep(i, n) cin >> q[i];

  vector<int> v(n);
  rep(i, n) v[i] = i + 1;

  map<vector<int>, int> mp;
  do {
    mp[v] = mp.size();
  } while(next_permutation(v.begin(), v.end()));
  
  int ans = abs(mp[p] - mp[q]);

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


Measured memory_bytes: 8644
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define F first
#define in insert
#define mp make_pair
#define S second
#define ll long long int
#define YES cout<<"YES"<<"\n";
#define NO cout<<"NO"<<"\n";
#define ld long double
#define yes cout<<"yes"<<"\n";
#define no cout<<"no"<<"\n";
#define No cout<<"No"<<"\n";
#define Yes cout<<"Yes"<<"\n";
#define f(i,a) for(i=0;i<a;i++)
#define fo(i,a) for(i=1;i<=a;i++)
#define fa(i,a) for(auto i:a)
#define r(i,a) for(auto i=a.rbegin();i!=a.rend();i++)
#define ull unsigned long long int
#define pr(n) cout<<fixed<<setprecision(n);
#define  gcd(a,b)    __gcd(a,b)
#define bs  binary_search
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define test ll t;cin>>t;while(t-->0)
const ll Mod = 998244353;
#define mod 1000000007
#define re return 0;



int main()
{
   fast
   ll n,a=0,w=0,t=0,r=0,i;
   cin>>n;
   f(i,n){
       string s;
       cin>>s;
       if(s=="AC"){
           a++;
       }
       if(s=="WA"){
           w++;
       }
       if(s=="TLE"){
           t++;
       }
       if(s=="RE"){
           r++;
       }
   }
   cout<<"AC"<<" x "<<a<<"\n";
    cout<<"WA"<<" x "<<w<<"\n"; cout<<"TLE"<<" x "<<t<<"\n";
   cout<<"RE"<<" x "<<r<<"\n";
    re
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
#include <map>
#include <string>

using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define ll long long
#define rn(i,n) for(int i=1;i<=n;i++)
#define INF 1000000010
const int mo=1e9+7;


int main()
{
  ll n,a,b;
  scanf("%d%d%d", &n,&a,&b);

  vector<ll> x(n),y(n,0);
  ll sum=0;
  ll dis;

  r(i,n){
    cin>>x.at(i);
    //printf("%d\n", x.at(i));
    if(i==0)continue;
    else{
      dis=a*(x.at(i)-x.at(i-1));
    }
    sum+=min(dis,b);
  }

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

  return 0;
}


Measured memory_bytes: 1792
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;

public class Main {

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

	FastScanner sc;

	void run() {
		sc = new FastScanner();
		String S = sc.next();
		int[] tmp = new int[4]; // 0番目からN,W,S,Eで管理
		int size = S.length();
		for (int i = 0; i < size; i++) {
			switch (S.charAt(i)) {
			case 'N':
				tmp[0] = tmp[0] + 1;
				break;
			case 'W':
				tmp[1] = tmp[1] + 1;
				break;
			case 'S':
				tmp[2] = tmp[2] + 1;
				break;

			default:
				tmp[3] = tmp[3] + 1;
				break;
			}
		}

		String ans = "";
		if (tmp[0] != 0 && tmp[2] == 0 || tmp[2] != 0 && tmp[0] == 0 || tmp[1] != 0 && tmp[3] == 0
				|| tmp[3] != 0 && tmp[1] == 0) {
			ans = "No";
		} else {
			ans = "Yes";
		}
		System.out.println(ans);
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 8020
import sys
readline = sys.stdin.readline

S = readline().rstrip()
DIV = 2019

cur = 0
from collections import defaultdict
dic = defaultdict(int)
for i in range(len(S) - 1, -1, -1):
  cur += ((int(S[i]) % DIV) * pow(10, (len(S) - 1 - i), DIV)) % DIV
  cur %= DIV
  dic[cur] += 1

ans = 0
# 0は単独でもよい
for key, val in dic.items():
  if key == 0:
    ans += val
  ans += (val * (val - 1)) // 2

print(ans)

Measured memory_bytes: 9592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)
        {
            var xy = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (xy[0] > xy[1]) Console.WriteLine("safe");
            else Console.WriteLine("unsafe");

          





        }

        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }
        
        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 28080
//Jai Bhole Ki
#include <bits/stdc++.h>
using namespace std;
#define fast static int fastline = []() { std::ios::sync_with_stdio(false); cin.tie(NULL); return 0; }();
#define ll long long
#define LL unsigned ll
#define pb push_back
#define pi pair<ll,ll>
#define debug(x) cout<<x<<"\n";
#define debug cout<<"debugged\n";
#define minval -2e9
#define maxval 2e9
long double PI =3.14159265358979323846;
 
const ll M=1e9+7;
const ll inf=1e18;
const ll ms=2e5+5;
fast;
ll ans;
void solve()
{
    ll n,m;cin>>n; 
    ans=n*(n+1)/2;
    ll c3=n/3,c5=n/5,c15=n/15;
    ans-=(c3*(c3+1)/2)*3;ans-=(c5*(c5+1)/2)*5;ans+=(c15*(c15+1)/2)*15;
    cout<<ans<<endl;
}
int main()
{
 // freopen("input.txt","r",stdin);
//  freopen("output.txt","w",stdout);
    //int t;cin>>t;while(t--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
using namespace std;
int main()
{
 int a, b, c;
 cin >> a >> b >> c;
 if ( a > b)
 {
   a += b;
   b = a - b;
   a = a - b;
 }
 if ( a > c)
 { 
   a += c;
   c = a - c;
   a = a - c;
 }
 if ( b > c)
 { 
   b += c;
   c = b - c;
   b = b - c;
 }
 cout << a << " " << b << " " << c << endl;
 return 0;
}

Measured memory_bytes: 3100
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int n; cin >> n;
    int a[1<<n];
    for (int i = 0; i < 1<<n; i++) cin >> a[i];
    sort(a, a+(1<<n));
    vector<int> A({a[(1<<n)-1]});
    multiset<int> B(a, a+(1<<n)-1);
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < 1<<k; i++) {
            auto j = B.lower_bound(A[i]);
            if (j == B.begin()) { cout << "No\n"; return 0; }
            j--;
            A.push_back(*j);
            B.erase(j);
        }
    }
    cout << "Yes\n";
}


Measured memory_bytes: 13696
# 解説通りに組んでみた
H, W = gets.split.map(&:to_i)
# ＃で埋めた配列を作る
b = Array.new(H + 2){Array.new(W + 2,"#")}
# 入力された文字列を挿入する
H.times do |i|
    a = gets.chomp.split("")
    b[i + 1][1..W] = a
end
# 配列を展開して出力
b.each do |s|
    puts s.join
end


Measured memory_bytes: 2300
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        int k = Integer.parseInt(sc.next());
        sc.close();

        // 主処理
        int max = Math.min(a + k - 1, b);
        List<Integer> list = new ArrayList<>();
        for (int i = a; i <= max; i++) {
            list.add(i);
        }
        int min = Math.max(a, b - k + 1);
        for (int i = b; min <= i; i--) {
            list.add(i);
        }
        list = new ArrayList<>(new HashSet<>(list));
        Collections.sort(list);

        // 出力
        for (int num : list) {
            System.out.println(num);
        }
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

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

    ll output = 0;
    if (K % 2 == 1) {
        output = pow(N / K, 3);
    } else {
        output += pow(N / (K / 2) - N / K, 3);
        output += pow(N / K, 3);
    }

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 4076
#include<bits/stdc++.h>
using namespace std;
//type
typedef long long ll;
using pii = pair<int, int>;
using vi = vector<int>;
//x * y * 1.0 can cause overflow
//constant
#define inf (int)(1e9+7)
#define mod (ll)(1e9+7)
#define eps 1e-10
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
//omission
#define eb emplace_back
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define all(v) v.begin(), v.end()
//manip
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end(), v.end());
#define fill(x, y) memset(x, y, sizeof(x))
#define ceil(a, b) a / b + !!(a % b)
template<class T> T power(T a, T b)
{return b ? power(a * a % inf, b / 2) * (b % 2 ? a : 1) % inf : 1;}
#define LB(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define UB(v, x) (int)(upper_bound(v.begin(), v.end(), x) - v.begin())
//loop
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep3(i, st, n) for (int i = st; i < n; ++i)
//algorithm
//double pointer, l start, how many adds, can be 0 -> init r = l, sum = 0
//bfs, not x, y, i, j
//not !(i % 2), i % 2 == 0


bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second < b.second;
}


int main() {
    //cast caution
    //look constraints always
    cin.tie(0); ios::sync_with_stdio(false);
    
    
    
    int ans = 0;
    string s; cin >> s;
    rep(i, SZ(s)) {
        int flgj = 0, flgo = 0, flgi = 0;
        while (s[i] == 'J') {i++; flgj++;}
        //cout << "flgj " << flgj << endl;
        if (flgj == 0) continue;
        while (s[i] == 'O') {i++; flgo++;}
        //cout << "flgo " << flgo << endl;
        if (flgo == 0) continue; //Iが来た
        if (flgo > flgj) {i--; continue;}
        while (s[i] == 'I') {i++; flgi++;}
        //cout << "flgi " << flgi << endl;
        if (flgi == 0) {i--; continue;} //Jがきてる
        if (flgo > flgi) {i--; continue;}
        chmax(ans, min({flgj, flgo, flgi}));
        i--;
        //cout << flgj << " " << flgo << " " << flgi << endl;
    }
    cout << ans << endl;
    
    
    
    
   
    
    
    
    
    
    
    
    
    
}
//cast caution




Measured memory_bytes: 4548
/*
  #問題：
  


  #分析：
  #オブジェクト：
  
  #条件：
  

  #要求：
  

  #解法：
  
*/

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;


const unsigned int BIT_FLAG_0 = (1<<0);
const unsigned int BIT_FLAG_1 = (1<<1);
const unsigned int BIT_FLAG_2 = (1<<2);
const unsigned int BIT_FLAG_3 = (1<<3);
const unsigned int BIT_FLAG_4 = (1<<4);
const unsigned int BIT_FLAG_5 = (1<<5);
const unsigned int BIT_FLAG_6 = (1<<6);
const unsigned int BIT_FLAG_7 = (1<<7);


#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
namespace mp = boost::multiprecision;

using Bint = mp::cpp_int;

uLL kiriage(uLL a,uLL b){
  return (a + (b - 1)) / b;
}


int main(void){
  uLL N;
  cin>>N;
  
  vector<uLL> L(5);
  vector<uLL> C(6,0);           // C_iはCity_iにいる人間の人数を表す．
  C[0]=N;
  
  FOR(i,0,5){
    cin>>L[i];
  }

  uLL minx=*min_element(L.begin(),L.end());
  cout<<kiriage(N,minx)+4<<endl;
  return 0;
}  
  // uLL cnt=0;


  
//   while(1){
//     for(auto x:C)cerr<<x<<" ";
//     cout<<endl;
    
//     if(C[5]==N) break;
//     // if(cnt>100) break;
//     FORD(i,5,0){             // iは今考えているCityの番号
//       //Ciからci+1への移動について
//       if(C[i]>=L[i]){// もしCity_iに，L_i以上の人数がいるならばL_i人だけ移動
//         C[i+1]+=L[i];
//         C[i]=C[i]-L[i];
        
//       }else{// もしCity_iに，L_iより少ない人数しかいないなら，全員移動
//         C[i+1]+=C[i];
//         C[i]=0;
//       }
      
//     }

//     cnt++;
//   }
//   cout<<cnt<<endl;
//   return 0;
// }



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Graph = vector<vector<int>>;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;

ll mod(ll a, int m) {
    return ((a % m) + m) % m;
}

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

    int N, K;
    cin >> N >> K;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i)
        cin >> A[i];
    sort(A.begin(), A.end());

    if (N == 1 || K == 1) {
        cout << 0 << endl;
        return 0;
    }

    vector<ll> fac(N), inv(N), finv(N);
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < N; ++i) {
        fac[i] = (fac[i - 1] * i) % MOD;
        inv[i] = MOD - (MOD / i) * inv[MOD % i] % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

    int r = K - 1;
    ll mas = 0, mis = 0;
    for (int i = 0; i < N - K + 1; ++i) {
        int n = N - i - 1;
        ll tmp = fac[n] * (finv[n - r] * finv[r] % MOD) % MOD;
        mis += A[i] * tmp % MOD;
        mis %= MOD;
    }
    for (int i = 0; i < N - K + 1; ++i) {
        int n = N - i - 1;
        ll tmp = fac[n] * (finv[n - r] * finv[r] % MOD) % MOD;
        mas += A[N - i - 1] * tmp % MOD;
        mas %= MOD;
    }
    cout << mod(mas - mis, MOD) << endl;
    return 0;
}


Measured memory_bytes: 3456
#encoding:utf-8 No.0532 2014.11.13
3.times do
  time = gets.chomp.split.map{|item| item.to_i}
  start = time[0]*3600 + time[1]*60 + time[2]
  finish = time[3]*3600 + time[4]*60 + time[5]

  h = (finish-start)/3600
  m = ((finish-start)%3600)/60
  s = (finish-start)%60

  printf("%d %d %d\n",h,m,s)
end

Measured memory_bytes: 6116
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define ios       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,a,n) for (ll i = a; i < (ll)(n); i++)
#define fon(i,n) for (ll i = (ll)n-1; i >=0; i--)
#define vi          vector<ll>
#define vii vector<pair<ll,ll>>
#define all(a)      (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ciin(v) forn(i,0,v.size()) cin>>v[i]
#define coutt(v) forn(i,0,v.size()) cout<<v[i]<<" "
using namespace std;
int main(){
    ios
    ll test;
    test=1;
    // cin>>test;
    while(test--){
 string a,b;
 cin>>a>>b;
 int n=a.length();
 int m= b.length();
 int dp[n+1][m+1];
 for(int i=0;i<n+1;i++){
    for(int j=0;j<m+1;j++){
        if(i==0 || j==0) dp[i][j]=0;
        else if(a[i-1]==b[j-1]) dp[i][j]=1+dp[i-1][j-1];
        else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  }} 
  int ind=dp[n][m];
  char ans[dp[n][m]+1];
  ans[dp[n][m]]='\n';
  int i=n,j=m;
  while(i && j){
    if(a[i-1]==b[j-1]){
        ans[ind-1]=a[i-1];
        i--;
        j--;
        ind--;
    }
    else if(dp[i-1][j]>dp[i][j-1]) i--;
    else j--;
  } 
  forn(i,0,dp[n][m]) cout<<ans[i];
 }
    }


Measured memory_bytes: 38796
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
//#include "graph.cpp"
#define ll long long
#define loop(i,n) for(int i=0 ; i<n ; ++i)
#define rep(i,x,n) for(int i=x ; i<=n ; ++i)
#define iteloop(type,data,name,it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)
using namespace std;
using namespace __gnu_pbds;
const int N=2e5 + 5;
int n,k;
int main(){
    cin.sync_with_stdio(false), cin.tie(0) , cout.tie(0);
  ///  freopen("in.txt","rt",stdin);
    cin>>n>>k;
    int mx=(n-1)*(n-2)/2;
    if(mx<k){
        cout<<-1<<endl;
        return 0;
    }
    cout<<(n-1) + (mx-k)<<endl;
    for(int i=2 ; i<=n ; i++){
        cout<<1<<" "<<i<<endl;
    }
    int x=2,y=3;
    loop(i,mx-k){
        cout<<x<<" "<<y<<endl;
        y++;
        if(y>n){
            x++;
            y=x+1;
        }
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		int i=1;
		while(true){
			int x=cin.nextInt();
			if(x==0)break;
			System.out.println("Case "+i+": "+x);
			i++;
		}
	}

}



Measured memory_bytes: 41620
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#pragma comment(linker,"/STACK:102400000,102400000")
#define inf 0x3f3f3f3f
#define maxm 100000
typedef long long ll;
using namespace std;
int main()
{
    int v[maxm],w[maxm];
    int f[maxm];
    memset(f,0,sizeof(f));
    int N,W;
    cin>>N>>W;
    for(int i=1;i<=N;i++)
        scanf("%d%d",&v[i],&w[i]);
    for(int i=1;i<=N;i++)
    {
        for(int j=W;j>=w[i];j--)
        {
            f[j]=max(f[j],f[j-w[i]]+v[i]);
        }
    }
    cout<<f[W]<<endl;
}



Measured memory_bytes: 3612
import sys

A = int(input())

wordlist = []
tmplist = []
lastword = ""

for b in range(A):
    wordlist.append(input())
    tmpstr = wordlist[-1]

    if(lastword != ""):
        if(tmpstr[0] != lastword):
            print("No")
            sys.exit()
    lastword = tmpstr[-1]

if(len(wordlist) == len(set(wordlist))):
    print("Yes")
else:
    print("No")



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

int main(void)
{
	int n;
	int i;
	int x[100];
	int y[100];
	int z[100];
	double L_1 = 0, L_2 = 0, L_3 = 0, L_inf;
	
	scanf("%d\n", &n);
	for(i = 0; i<n; i++)
		scanf("%d", &x[i]);
	for(i = 0; i<n; i++)
		scanf("%d", &y[i]);
	for(i = 0; i<n; i++) {
		z[i] = (x[i] - y[i]>0)? x[i] - y[i]: y[i] - x[i];
		if(i == 0) L_inf = z[0];
		else {
			if(z[i] > L_inf) L_inf = z[i];
		}
	}
	
	for(i=0; i<n; i++) {
		L_1 += z[i];
		L_2 += z[i] * z[i];
		L_3 += z[i] * z[i] * z[i];
	}
	
	L_2=pow(L_2, 1.0/2);
	L_3=pow(L_3, 1.0/3);
	
	printf("%f\n%f\n%f\n%f\n", L_1, L_2, L_3, L_inf);
	
	return 0;
}


Measured memory_bytes: 680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

int main(){
  int n, k;
  cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n - k << endl;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn is_m(i : u32) -> bool {
    i >= 1 && i <= 12
}

fn main() {
    let s = read::<String>();
    let (s1, s2) = s.split_at(2);
    let i1 = s1.parse::<u32>().unwrap();
    let i2 = s2.parse::<u32>().unwrap();

    let ans = match (is_m(i1), is_m(i2)) {
        (true, true) => "AMBIGUOUS",
        (true, false) => "MMYY",
        (false, true) => "YYMM",
        (false, false) => "NA",
    };
    println!("{}", ans);
}


Measured memory_bytes: 4352
program main
  implicit none
  integer :: n, i, cnt = 1
  character(200000) :: s
  logical :: skip = .false., skipped = .false.

  read *, s
  n = len_trim(s)

  do i = 2, n
    if (skip) then
      skip = .false.
      skipped = .true.
      cycle
    end if
    cnt = cnt + 1
    if (s(i:i) == s(i-1:i-1)) then
      if (skipped) then
        skipped = .false.
      else
        skip = .true.
      end if
    else
      skipped = .false.
    end if
  end do
  if (skip) cnt = cnt - 1
  print '(i0)', cnt
end program

Measured memory_bytes: 1468
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int n = scanner.nextInt();
    int[] a = new int[n + 2];
    a[0] = 0;
    a[n + 1] = 0;
    long s = 0;
    for (int i = 0; i < n; i++) {
      a[i + 1] = scanner.nextInt();
      s += Math.abs(a[i + 1] - a[i]);
    }
    s += Math.abs(a[n + 1] - a[n]);
    s -= Math.abs(a[1] - a[0]);
    for (int i = 1; i <= n; i++) {
      if (i > 1) s += Math.abs(a[i - 1] - a[i - 2]);
      s += Math.abs(a[i + 1] - a[i - 1]);
      if (i > 1) s -= Math.abs(a[i] - a[i - 2]);
      s -= Math.abs(a[i + 1] - a[i]);
      System.out.println(s);
    }
  }
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  string S;
  int K;
  cin >> N >> S >> K;
  char t = S[K - 1];
  for(int i = 0; i < S.size(); i++) {
    if(S[i] != t) { S[i] = '*'; }
  }
  cout << S << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> edge[100];
bool visit[100];
int solve(int n) {
	int mx=1;
	visit[n]=1;
	for(int i=0;i<edge[n].size();i++) {
		if(!visit[edge[n][i]]) {
			mx=max(mx,solve(edge[n][i])+1);
		}
	}
	visit[n]=0;
	return mx;
}
int main() {
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<100;i++) edge[i].clear();
		for(int i=0;i<n;i++) {
			int a,b;
			scanf("%d %d",&a,&b);
			a--;b--;
			edge[a].push_back(b);
			edge[b].push_back(a);
		}
		int mx=0;
		for(int i=0;i<100;i++) mx=max(mx,solve(i));
		printf("%d\n",mx);
	}
}

Measured memory_bytes: 1056
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////

ll ans(ll a, ll b) {
	if (a > b) { return ans(b, a); }
	if (a == b) { return 2 * a - 2; }

	ll s = sqrt(a*b - 1);

	if (s*(s + 1) <= a * b - 1) { s++; }//(s-1)*sがab-1以下になる最大のs

	ll t = (a*b - 1) / s;

	return a - 1 + s + t - a - 1;
}

int main() {

	ll q;
	cin >> q;

	repn(i, q) {
		ll a, b;
		cin >> a>> b;
		cout << ans(a, b) << endl;
	}

	
	

	system("PAUSE");

	

}


Measured memory_bytes: 504
use whiteread::parse_line;

fn main() {
    let (_a, _b, m): (usize, usize, usize) = parse_line().unwrap();
    let ap: Vec<u32> = parse_line().unwrap();
    let bp: Vec<u32> = parse_line().unwrap();
    let mut min_cost: u32 = ap.iter().min().unwrap() + bp.iter().min().unwrap();
    for _ in 0..m {
        let (xi, yi, ci): (usize, usize, u32) = parse_line().unwrap();
        if ap[xi - 1] + bp[yi - 1] - ci < min_cost {
            min_cost = ap[xi - 1] + bp[yi - 1] - ci;
        }
    }
    println!("{}", min_cost);
}


Measured memory_bytes: 3404
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a;
	cin>>a;
	string b;
	b=a;
	reverse(b.begin(),b.end());
	int n=b.size();
	for(int i=0;i<n;i++){
		if(b[i]=='b')b[i]='d';
		else if(b[i]=='p')b[i]='q';
		else if(b[i]=='d')b[i]='b';
		else if(b[i]=='q')b[i]='p';
	}
	if(a==b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
import numpy as np

N,C = map(int,input().split())
XV = np.array([input().split() for _ in range(N)],dtype=np.int64)
X = XV[:,0]
V = XV[:,1]

Xrev = C - X[::-1]
Vrev = V[::-1]

answer = 0

# ある方向に k in [0,N)個食べた後、逆方向に[1,N-k]個食べる
for X,V,Xrev,Vrev in [(X,V,Xrev,Vrev),(Xrev,Vrev,X,V)]:
  # 順方向に0個以上食べた後、逆方向に進む
  # 順方向に食べて戻ってくるまでの価値
  v1 = np.cumsum(V) - 2*X
  # 逆方向に食べる価値
  v2 = np.cumsum(Vrev) - Xrev
  # 逆方向に食べる番号の上限を決めた場合の最大価値
  v2 = np.maximum.accumulate(v2)
  # 順方向に0個
  x = v2.max()
  if answer < x:
    answer = x
  # 順方向に1～N-1個
  for k in range(1,N):
    x = v1[k-1] + v2[N-k-1]
    if answer < x:
      answer = x
print(answer)
  
  

Measured memory_bytes: 55440