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

using namespace std;

int main() {
        string a, b;

        cin >> a >> b;

        for (int i = 0; i < 3; ++i) {
                if (a[i] != b[2 - i]) {
                        cout << "NO" << endl;
                        return 0;
                }
        }
        cout << "YES" << endl;
        return 0;
}

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

int dp[10][10];

int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; ++i){
        string s = to_string(i);
        int a = s[0]-'0', b = s[s.size()-1]-'0';
        dp[a][b]++;
    }
    ll ans = 0LL;
    rep(i,n){
        string s = to_string(i+1);
        int a = s[0]-'0', b = s[s.size()-1]-'0';
        ans += dp[b][a];
    }
    cout << ans << endl;
}

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

int main(){
  ll N;cin>>N;
  ll n=N-1;
  //N-1の約数列挙
   vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
 //Nの約数列挙
  vector< ll > reta;
  for(ll i = 1; i * i <= N; i++) {
    if(N% i == 0) {
      reta.push_back(i);
      if(i * i != N) reta.push_back(N / i);
    }
  }
  sort(begin(reta), end(reta));
  
  ll ans=0;
  rep(i,ret.size()){
  	if(N%ret[i]==1){ans++;}
  }
  rep(i,reta.size()){
  	ll p=N;
    ll q=reta[i];
    if(q==1){continue;}
    while(p%q==0){
      p/=q;
    }
    if(p%q==1){ans++;}
  }
  cout<<ans;
}


Measured memory_bytes: 3644
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
int main(){
	int n,x;
	cin>>n>>x;
	vector<int> l(n);
	rep(i,n)cin>>l[i];
	int d=0;
	int cnt=1;
	rep(i,n){
		d+=l[i];
		if(d<=x)cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, m;
  cin >> n >> m;
  
  vector<vector<char>> A(n, vector<char>(n));
  vector<vector<char>> B(m, vector<char>(m));
  
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> A.at(i).at(j);
    }
  }
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < m; j++) {
      cin >> B.at(i).at(j);
    }
  }
  
  bool ans = false;
  
  for (int i = 0; i < n-m+1; i++) {
    for (int j = 0; j < n-m+1; j++) {
      bool match = true;
      for (int y = 0; y < m; y++) {
        for (int x = 0; x < m; x++) {
          if(A.at(i+y).at(j+x) != B.at(y).at(x)){
            match = false;
          }
        }
      }
      if(match){
        ans = true;
      }
    }
  }
  
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }

 
}
             
 


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

const int MAX_N=1e5+10;
const int INF=1e9+10;

int N,U,V,distu[MAX_N],distv[MAX_N];
vector <int> g[MAX_N];
queue <int> Q;

void get_dist(bool f,int st){
	while(Q.size()) Q.pop();
	Q.push(st);
	if(!f) distu[st]=0;
	else distv[st]=0;
	while(Q.size()){
		int x=Q.front(); Q.pop();
		for(int i=0;i<g[x].size();i++){
			int to=g[x][i];
			if(!f){
				if(distu[to]!=INF) continue;
				distu[to]=distu[x]+1;
				Q.push(to);
			}
			else{
				if(distv[to]!=INF) continue;
				distv[to]=distv[x]+1;
				Q.push(to);
			}
		}
	}
}

int main(){
	for(int i=0;i<MAX_N;i++) distu[i]=distv[i]=INF;
	scanf("%d%d%d",&N,&U,&V); U--; V--;
	for(int i=0;i<N-1;i++){
		int u,v; scanf("%d%d",&u,&v);
		u--; v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	get_dist(0,U);
	get_dist(1,V);
//	for(int i=0;i<N;i++) cout<<distu[i]<<" "; cout<<endl;
//	for(int i=0;i<N;i++) cout<<distv[i]<<" "; cout<<endl;
	if(distu[V]<=2){
		printf("%d\n",distu[V]-1);
		return 0;
	}
	int ans=0;
	for(int i=0;i<N;i++){
		if(distu[i]<distv[i]){
		//	cout<<i+1<<endl;
			bool flag=false;
			for(int j=0;j<g[i].size();j++) 
				if(distv[g[i][j]]>distv[i]) flag=true;
		//	if(flag) cout<<i+1<<endl;
			if(flag) ans=max(ans,distv[i]);
		}
	}
	printf("%d\n",ans);
	return 0;
} 

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

int main (){
	int N,M,path[100][100];
	cin>>N>>M;

	for(int t=0;t<100;t++){
		for(int j=0;j<100;j++){
			path[t][j]=0;
		}
	}
	for(int t=0;t<M;t++){
		int a,b;
		cin>>a>>b;
		path[a][b]=path[b][a]=1;
	}

	int cont=0;
	vector<int>v(N-1);
	iota(v.begin(),v.end(),2);

	do{
		bool flag=true;
		if(path[1][v[0]]==0)continue;
		for(int t=0;t<N-2;t++){
			if(path[v[t]][v[t+1]]==0){
				flag=false;
				break;
			}
		}
		if(flag)cont++;

	}while(next_permutation(v.begin(),v.end()));

	cout<<cont<<"\n";
	return 0;
}



Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))

MIN = P[0]
ans = 1
for i in range(2, N+1):
  if MIN < P[i-1]:
    pass
  else:
    ans += 1
    
  if MIN > P[i-1]:
    MIN = P[i-1]
print(ans)


Measured memory_bytes: 24872
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int W;
    int cnt = 0;
    while(cin >> W,W){
        int n;
        cin >> n;

        int v[1005], w[1005];
        rep(i,n){
            char g;
            cin >> v[i] >> g >> w[i];
        }

        int dp[2005] = {0};
        rep(i,W + 1) dp[i] = -1;
        dp[0] = 0;

        rep(i,n){
            for(int j = W; j >= 0; j--){
                if(j - w[i] < 0) continue;
                if(dp[j - w[i]] == -1) continue;
                dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
            }
        }

        int ans_v = 0, ans_w = 0;
        rep(i,W + 1){
            if(ans_v < dp[i]){
                ans_v = dp[i];
                ans_w = i;
            }
        }

        cout << "Case " << cnt + 1 << ":" << endl;
        cout << ans_v << endl;
        cout << ans_w << endl;
        cnt++;
    }
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

int main(){
    int ans=100;
    lint n;cin>>n;
    for(int a=1;a<=sqrt(n);a++){
        if(n%a==0){
            int tmp=(str(n/a)).size();
            ans=min(tmp,ans);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3704
n,m=map(int,input().split())
a=list(map(int,input().split()))
temp=[0,2,5,5,4,5,6,3,7,6]
dp=[-1]*(n+1)
dp[0]=0
for i in range(n+1):
  for j in a:
    if i+temp[j]<n+1:
      dp[i+temp[j]]=max(dp[i+temp[j]],dp[i]*10+j)
print(dp[n])

Measured memory_bytes: 14692
#include <iostream>
using namespace std;
int main(){
  int time,n;
  while( cin >> time,time ){
    cin >> n;
    int sum = 0;
    for(int i = 0 ; i < n ; i++ ){
      int a,b;
      cin >> a >> b;
      sum+=b-a;
    }
    if(sum < time)cout << time - sum << endl;
    else cout << "OK" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))

if(N==K):
    print("1")
elif(K>=(N/2)):
    print("2")
elif(3<=K and K<(N/2)):
    print((N-(K+1))//(K-1)+2)
else:
    print(N-1)


Measured memory_bytes: 13880
#include <stdio.h>
 
int main(void) {

	int n, a, b;
	scanf("%d %d %d", &n, &a, &b);
	    if(n == 1){
			printf("Hello World");
		}

		if(n == 2){
			printf("%d", a + b);
		}	
  
	return 0;
}

Measured memory_bytes: 128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(next(), 64)
	return f
}

func nextInts(n int) []int {
	slice := make([]int, n)
	for i := 0; i < n; i++ {
		slice[i] = nextInt()
	}
	return slice
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	a, b, c := next(), next(), next()
	ans := 0
	for i := 0; i < n; i++ {
		if a[i] == b[i] && b[i] == c[i] {
			continue
		}
		if a[i] == b[i] && a[i] != c[i] {
			ans++
		} else if b[i] == c[i] && c[i] != a[i] {
			ans++
		} else if c[i] == a[i] && a[i] != b[i] {
			ans++
		} else {
			ans += 2
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{   
    int N,L[10];
    int i,j,tmp,S=0;
  
    scanf("%d",&N);
    
    for(i=0;i<N;i++)
      scanf("%d",&L[i]);
  
    for(i=0;i<N;i++){
      for(j=i+1;j<N;j++){
        if(L[i]>L[j]){
          tmp=L[i];
          L[i]=L[j];
          L[j]=tmp;
        }
      }
    }
  
    for(i=0;i<N-1;i++)
      S+=L[i];
    
    if(S>L[N-1]) printf("Yes\n");
    else printf("No\n");
  
    return 0;
}


Measured memory_bytes: 1632
#include<iostream>
#include<algorithm>

using namespace std;

#define INF (1 << 29)

int n, m, ans;
int a[1080], b[1080], c[1080];
int dist[108][108];

int main(){
  cin >> n >> m;
  for(int i = 0;i < 108;i++)
    for(int j = 0;j < 108;j++)
      dist[i][j] = INF;
  
  for(int i = 0;i < m;i++){
    cin >> a[i] >> b[i] >> c[i];
    a[i]--,b[i]--;
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }

  for(int i = 0;i < n;i++)
    for(int j = 0;j < n;j++)
      for(int k = 0;k < n;k++)
	dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
  
  for(int i = 0;i < m;i++){
    if(dist[a[i]][b[i]] != c[i])ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import Counter
n, k = map(int, input().split())
a = list(map(int, input().split()))
c = Counter(a)

items = []
for key, value in c.items():
    items.append((key, value))
items.sort(key=lambda x: x[1])

ans = 0
for key, value in items[:max(0, len(items)-k)]:
    ans+=value
print(ans)


Measured memory_bytes: 43220
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int area = a * b;
		int length = a * 2 + b * 2;
		System.out.println(area +" "+ length);
	}
}


Measured memory_bytes: 26104
package main

import "fmt"

func main() {
	// Code for A - 12/22
	var N string
	fmt.Scanf("%s", &N)

	var count int
	for i := 0; i < 4; i++ {
		if N[i] == '2' {
			count++
		}
	}

	fmt.Println(count)
}


Measured memory_bytes: 1832
import bisect
n = int(input())
a, b= (int(i) for i in input().split())  
p = list(int(i) for i in input().split())
p1 = sorted(p,reverse=True)
ans1 = 0
ans2 = 0
ans3 = 0
for i in p1:
  if i <= a:
    ans1 += 1
  elif a<i and i<=b:
    ans2 += 1 
  else: 
    ans3 += 1
print (min([ans1,ans2,ans3]))

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	// sc.Split(bufio.ScanWords)
	// a := nextInt()

	var x, y int

	fmt.Scan(&x)
	fmt.Scan(&y)

	if y%2 == 1 {
		fmt.Println("No")
		return
	}

	a := y - x*2

	if a >= 0 && a%2 == 0 && a/2 <= x {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 1836
N,a,b=map(int,input().split())
MOD=10**9+7
def comb(n,k):
  tmp=1
  for i in range(n-k+1,n+1):
    tmp*=i
    tmp%=MOD
  for i in range(1,k+1):
    tmp*=pow(i,MOD-2,MOD)
    tmp%=MOD
  return tmp
ans = pow(2,N,MOD) - 1 - comb(N,a) - comb(N,b)
print(ans%MOD)

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
	
			var inputArray = retreiveLongArray();
			var inputCount = 4;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			var sx = (int)inputArray[0];
			var sy = (int)inputArray[1];
			var tx = (int)inputArray[2];
			var ty = (int)inputArray[3];

			var X = tx - sx;
			var Y = ty - sy;
			var isshume = new String('U', Y) + new String('R', X) + new String('D', Y) + new String('L', X);
			var nishumeIki = 'L' + new String('U', Y + 1) + new String('R', X + 1) + 'D';
			var nushumeKaeri = 'R'+ new String('D', Y+1) + new String('L', X+1)+'U';


			//答えの出力
			var ans = isshume + nishumeIki + nushumeKaeri;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}
	}
}


Measured memory_bytes: 13396
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    int N;
    cin >> N;
    int a[N];
    Fp(i, 0, N) cin >> a[i];
    int K = 1;
    Fp(i, 0, N){
        if(a[i] == K) K++;
        //cout << "a[i]: " << a[i] << ", K: " << K << endl;
    }
    if(K == 1) cout << -1 << endl;
    else cout << N - (K - 1) << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
const int maxn=112345;
int h,w,n,a[maxn],b[maxn];
long long num[10];
map<pii,int> mp;
int main()
{
    scanf("%d%d%d",&h,&w,&n);
    for (int i=1;i<=n;++i)
        scanf("%d%d",&a[i],&b[i]);
    for (int i=1;i<=n;++i) {
        int x=a[i],y=b[i];
        for (int j=x-1;j<=x+1;++j)
            for (int k=y-1;k<=y+1;++k) {
                if (j<=1||j>=h||k<=1||k>=w) continue;
                int id=mp[pii(j,k)]++;
                --num[id],++num[id+1];
            }
    }
    int sum=0;
    for (int i=0;i<10;++i) sum+=num[i];
    num[0]+=1ll*(h-2)*(w-2)-sum;
    for (int i=0;i<10;++i) cout<<num[i]<<endl;
    return 0;
}


Measured memory_bytes: 60736
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <iostream>
using namespace std;
string s;

int main() {
    cin >> s;
    if(s[2] == s[3] && s[4] == s[5])
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mul(a, b) (a = 1ll * a * b % mod)
#define add(a, b) (a += b, a >= mod ? a -= mod : 0)
using namespace std;

const int mod = 998244353;

struct node {
	int sum, b, c;
	node *son[2];
	node(): b(1), c(0) {}
} *root, pool[1048576 + 10];

int idx;
int n, q;
int a[524288 + 10];
void build(node*, const int&, const int&);
int query(node*, const int&, const int&, const int&, const int&);
void modify(node*, const int&, const int&, const int&, const int&, const int&, const int&);
void update(node*, const int&);

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	n = 1 << 32 - __builtin_clz(n - 1);
	build(root = &pool[idx++], 0, n);
	while (q--) {
		int f, l, r; scanf("%d%d%d", &f, &l, &r);
		if (f)
			printf("%d\n", query(root, l, r, 0, n));
		else {
			int b, c; scanf("%d%d", &b, &c);
			modify(root, l, r, 0, n, b, c);
		}
	}
	return 0;
}

void build(node *p, const int& l, const int& r) {
	if (l + 1 == r)
		p->son[0] = p->son[1] = nullptr,
			p->sum = a[l];
	else {
		const int mid = l + r >> 1;
		build(p->son[0] = &pool[idx++], l, mid);
		build(p->son[1] = &pool[idx++], mid, r);
		p->sum = p->son[1]->sum;
		add(p->sum, p->son[0]->sum);
	}
}

int query(node *p, const int &l, const int &r, const int &L, const int &R) {
	update(p, R - L);
	if (l == L && r == R)
		return p->sum;
	const int mid = L + R >> 1;
	if (r <= mid)
		return query(p->son[0], l, r, L, mid);
	else if (l >= mid)
		return query(p->son[1], l, r, mid, R);
	else {
		int ret = query(p->son[0], l, mid, L, mid);
		add(ret, query(p->son[1], mid, r, mid, R));
		return ret;
	}
}

inline void update(node *p, const int &siz) {
	if (p->b != 1) {
		mul(p->sum, p->b);
		if (siz > 1)
			mul(p->son[0]->b, p->b), mul(p->son[1]->b, p->b),
				mul(p->son[0]->c, p->b), mul(p->son[1]->c, p->b);
		p->b = 1;
	}
	if (p->c != 0) {
		p->sum = (p->sum + 1ll * p->c * siz) % mod;
		if (siz > 1)
			add(p->son[0]->c, p->c), add(p->son[1]->c, p->c);
		p->c = 0;
	}
}

void modify(node *p, const int &l, const int &r, const int &L, const int &R, const int &b, const int &c) {
	update(p, R - L);
	if (l == L && r == R) {
		p->b = b, p->c = c;
		update(p, R - L);
		return;
	}
	const int mid = L + R >> 1;
	if (r <= mid)
		modify(p->son[0], l, r, L, mid, b, c);
	else if (l >= mid)
		modify(p->son[1], l, r, mid, R, b, c);
	else {
		modify(p->son[0], l, mid, L, mid, b, c);
		modify(p->son[1], mid, r, mid, R, b, c);
	}
	update(p->son[0], R - L >> 1); update(p->son[1], R - L >> 1);
	p->sum = p->son[0]->sum + p->son[1]->sum;
	if (p->sum >= mod)
		p->sum -= mod;
}



Measured memory_bytes: 38476
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

int main() {
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    double ans = sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    printf("%.7f\n", ans);
}


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

#define f first
#define s second
#define ll long long
#define pb push_back
#define mp make_pair
#define inp(x) cin>>x
#define print(x) cout<<x
#define pii pair<int,int>
#define pll pair<ll,ll>
#define gcd(a,b) __gcd(a,b)
#define reset(d,val) memset(d,val,sizeof(d))
#define sort(v) sort(v.begin(),v.end())
#define sort_arr(arr,i,f) sort(arr+i,arr+f)
#define pq priority_queue<int,vector<int>,greater<int> >
#define pq1 priority_queue<pll,vector<pll>,greater<pll> >

const int mod = 1e9+7;

int h,w;
char arr[1001][1001];
ll dp[1001][1001];

int main(int argc, char const *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>h>>w;
	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin>>arr[i][j];
		}
	}
	dp[0][0] = 1;
	for (int i = 1; i < h; ++i)
	{
		if(arr[i][0]=='#') dp[i][0] = 0;
		else dp[i][0] = dp[i-1][0];
	}
	for (int i = 1; i < w; ++i)
	{
		if(arr[0][i]=='#') dp[0][i] = 0;
		else dp[0][i] = dp[0][i-1];
	}
	for (int i = 1; i < h; ++i)
	{
		for(int j=1;j<w;j++) {
			if(arr[i][j]=='#') dp[i][j] = 0;
			else dp[i][j] = (dp[i-1][j]+dp[i][j-1])%mod;
		}
	}
	cout<<dp[h-1][w-1];
	return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 305;
int f[MAXN][MAXN],val[MAXN][MAXN],n,m;
char mp[MAXN][MAXN];
long long ans=0;
inline int solve(int x,int y)
{
	for(int i=1;i<=n;++i)
		for(int j=1;j<=n;++j){
			val[i][j]=val[i-1][j-1]+(mp[i][x]==mp[j][y]);
		}
	memset(f,0x3f,sizeof(f));
	f[n][n]=0;
	for(int i=n;i>=0;--i)
		for(int j=n;j>=0;--j)
			(i>0?f[i-1][j]=min(f[i-1][j],f[i][j]+val[i][j]):0),(j>0?f[i][j-1]=min(f[i][j-1],f[i][j]+val[i][j]):0);
	return f[0][0];
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;++i){
		scanf("%s",mp[i]+1);
	}
	for(int i=1;i<m;++i){
		ans+=solve(i,i+1);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
//
//AtCoder Beginner Contest 145
//A - Circle
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <functional>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    int r;

    cin >> r;

    cout << r * r << endl;

    return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
typedef long long ll;
#define  rep(i,a,b)for(long long i=a;i<b;++i)
#define  rrep(i,a,b)for(int i=a;i>=b;--i)
#define  yesno(flag)if(flag)cout<<"Yes"<<endl; else cout<<"No"<<endl;
using namespace std;
const ll INF=100000000000000LL;
const ll r197=1000000007;
typedef pair<int,int>P;
typedef pair<int,P>Pa;
typedef pair<int,string> Q;
bool Inframe(int a,int b,int c,int d,int h,int w){
	if(a+b>=0&&a+b<h&&c+d>=0&&c+d<w)return true;
	return false;
}
//void swap(ll a,ll b){
//	ll d;
//	d=a;
//	a=b;
//	b=d;
//	return;
//}
ll mypow(ll x,int m){
	if(m==0)return 1;
	if(m%2==0){
		int x2=mypow(x,m/2);
		return x2*x2;
	}else{
		int x2=mypow(x,m/2);
		return x2*x2*x;
	}
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
//    	cout<<b<<endl;
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll t1,t2,a1,a2,b1,b2;
int a[100005];
int x[100005]={};

int main() {
	cin>>t1>>t2>>a1>>a2>>b1>>b2;
	if(a1*t1+a2*t2==b1*t1+b2*t2){
		cout<<"infinity"<<endl;
		return 0;
	}
	if(a1>b1){
		swap(a1,b1);
		swap(a2,b2);
	}
//	cout<<a1*t1+a2*t2<<" "<<b1*t1+b2*t2<<endl;
	if(a1*t1+a2*t2<b1*t1+b2*t2){
		cout<<0<<endl;
		return 0;
	}
	ll c=(b1-a1)*t1,d=a1*t1+a2*t2-b1*t1-b2*t2;
//	cout<<c<<" "<<d<<endl;
	ll ans=(c/d)*2+1;
	if(c%d==0)ans--;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAXN 1000
using namespace std;
std::vector < std::pair <int,int> > g[MAXN+1];
long long dist[MAXN+1];
int main(){
     int i,n,m,a,b,c,j;
     cin >> n >> m;
     for(i=1;i<=m;i++){
           cin >> a >> b >> c;
           g[a].push_back(std::make_pair(b,c));
     }
    for(i=2;i<=n;i++)
           dist[i]=-(1LL<<62);
   long long aux=dist[n];
    for(i=0;i<n+1;i++){
          for(j=1;j<=n;j++)
               for(auto it:g[j])
                  if(dist[j]+it.second>dist[it.first])
                          dist[it.first]=dist[j]+it.second;
          if(dist[n]!=aux&&i==n){
                  cout << "inf" << "\n";
                 return 0;
          }
          aux=dist[n];
    }
   cout  << dist[n] << "\n";
}


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

// #define int         long long 
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define endl        "\n"
#define mod         1000000007
#define PI          3.14159265 
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define print(x)    for(auto el: x) cout<<el<<" ";cout<<endl;





void solve(){
    
    int n;
    cin>>n;

    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];

    int dp[n] = {0};

    dp[1] = abs(a[1] - a[0]);

    for(int i=2; i<n; i++)
        dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]), dp[i-2] + abs(a[i] - a[i-2]));

    cout<<dp[n-1]<<endl;

    return;    
}




int32_t main() 
{
    
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    FIO;
    int test;

    // cin>>test;
    test = 1;
    
    while(test--)
        solve();

    return 0;
}

Measured memory_bytes: 4380
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

#include <math.h>
#define PI 3.14159265358979323846264338327950L
const int mxN = 1e9 + 7;

char s[100005];
long long dp[100005][13];

int main() {
    int n;
    cin >> n;
    cout << (3 * (n * n));
    return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>

int main(void){
    int a,b,c,d;
    
    scanf("%d %d %d %d",&a,&b,&c,&d);

    if(a+b>c+d)
        printf("Left\n");
    else if(a+b==c+d)
        printf("Balanced\n");
    else
        printf("Right\n");
}


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

int main() {
    int N;
    cin >> N;
    ll ans = 0;
    FOR(i, 1, N + 1) if (i % 3 != 0 && i % 5 != 0) ans += i;
    cout << ans << endl;
    return 0;
}

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



int main() {
	while (1) {
		int n, d; cin >> n >> d;
		if (!n)break;
		vector<vector<int>>missiles(n);
		for (int i = 0; i < n; ++i) {
			int k; cin >> k;
			for (int j = 0; j < k; ++j) {
				int a; cin >> a;
				missiles[i].push_back(a);
			}
			reverse(missiles[i].begin(), missiles[i].end());
		}
		vector<int>potesums(n);
		vector<int>produces(n, 0);
		int amin = 0;
		bool ok =true;
		while (ok) {
			ok = false;
			for (int i = 0; i < n; ++i) {
				if (produces[i] != missiles[i].size()) {
					if (potesums[i] + (*(missiles[i].end() - 1 - produces[i])) <= amin + d) {
						potesums[i] += (*(missiles[i].end() - 1 - produces[i]));
						amin = *min_element(potesums.begin(), potesums.end());
						produces[i]++;
						ok = true;
					}
					else{
						potesums[i] += (*(missiles[i].end() - 1 - produces[i]));
						if ((*max_element(potesums.begin(), potesums.end()) - *min_element(potesums.begin(), potesums.end())) <= d) {
							amin = *min_element(potesums.begin(), potesums.end());
							produces[i]++;
							ok = true;
						}
						else {
							potesums[i] -= (*(missiles[i].end() - 1 - produces[i]));
						}
					}
				}
				
			}
		}
		bool yes = true;
		for (int i = 0; i < n; ++i) {
			if (produces[i] != missiles[i].size()) {
				yes = false;
				break;
			}
		}
		if (yes) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

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

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;

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

	int A, B;
	cin >> A >> B;

	if (1 <= A && A <= 9 && 1 <= B && B <= 9)
	{
		cout << A * B << endl;
	}
	else
	{
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  string s;
  cin >> s;
  bool can=true;
  reverse(s.begin(),s.end());
  for(int i=0;i<s.size();){
    string tmp = s.substr(i,5);
    if(tmp=="maerd"||tmp=="esare"){
      i+=5;
      continue;
    }
    tmp = s.substr(i,6);
    if(tmp=="resare"){
      i+=6;
      continue;
    }
    tmp = s.substr(i,7);
    if(tmp=="remaerd"){
      i+=7;
      continue;
    }
    can=false;
    break;
  }
  if(can) cout <<"YES\n";
  else cout <<"NO\n";
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();
		
		String ans;
		if(a==b){
			ans="Draw";
		}else if(a==1){
			ans="Alice";
		}else if(b==1){
			ans="Bob";
		}else{
			ans = a>b ? "Alice":"Bob";
		}
			
		System.out.println(ans);
	
	}

}

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

#define int long long int 

signed main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    int sum = 0, base = 1, ans = 0;
    map<int, int> cnt;
    cnt[0]++;
    for(int i = 0; i < s.size(); i++) {
        sum += (base * (s[i] - '0'));
        sum %= 2019;
        base *= 10;
        base %= 2019;
        ans += cnt[sum];
        cnt[sum]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3736
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int K;
int X;
int main(){
  rd(K);
  rd(X);
  if(500*K>=X){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200112-1

// --- original code ---
// int K, X;
// {
//   rd(K,X);
//   wt(if[500K>=X,"Yes","No"]);
// }


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

typedef long long ll;

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

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

int main()
{
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll result = lcm(n, m);
    ll sMult = lcm(n, m) / n;
    ll tMult = lcm(n, m) / m;
    ll sidx = 0;
    ll tidx = 0;
    while (true)
    {
        if (sidx / sMult >= n || tidx / tMult >= m) {break;}
        if (sidx == tidx)
        {
            if (s.at(sidx / sMult) != t.at(tidx / tMult))
            {
                cout << -1 << endl;
                return 0;
            }
            sidx += sMult;
        }
        if (sidx < tidx)
        {
            sidx += sMult;
        }
        if (sidx > tidx)
        {
            tidx += tMult;
        }
    }
    cout << result << endl;
    return 0;
}


Measured memory_bytes: 512
package main

import "fmt"

func main() {
	// Code for B - ... (Triple Dots)
	var k int
	var s string
	fmt.Scan(&k)
	fmt.Scan(&s)
	if len(s) <= k {
		fmt.Println(s)
	} else {
		fmt.Println(s[:k] + "...")
	}
}


Measured memory_bytes: 1768
N = int(input())
H = list(map(int,input().split()))
for i in range(N-1)[::-1]:
    if H[i] > H[i+1]:
        H[i] -= 1
flag = True
for i in range(N-1):
    if H[i] > H[i+1]:
        flag = False
if flag == False:
    print("No")
else:
    print("Yes")


Measured memory_bytes: 15020
/*
 * 2664.cc: Shopping
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 5000;

/* typedef */

typedef map<string,int> msi;

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];

  void clear(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }

  UFT() {}
  UFT(int n) { clear(n); }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

UFT uft;
string as[MAX_N];
msi amap;
int xs[MAX_N];

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    cin >> as[i] >> xs[i];
    amap[as[i]] = i;
  }

  uft.clear(n);

  int m;
  cin >> m;
  
  for (int i = 0; i < m; i++) {
    string a0, a1;
    cin >> a0 >> a1;

    int i0 = amap[a0], i1 = amap[a1];
    int r0 = uft.root(i0), r1 = uft.root(i1);
    if (r0 != r1) {
      int r = uft.merge(r0, r1);
      xs[r] = (xs[r0] < xs[r1]) ? xs[r0] : xs[r1];
    }
  }

  int sum = 0;
  for (int i = 0; i < n; i++) sum += xs[uft.root(i)];
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 1900
#include <iostream>
using namespace std;
int main() {
  	int n; cin >> n;
  	int ans = -1;
  	int prev;
  	int cur = 0;
  	for (int i = 0; i < n; i++) {
      	int k; cin >> k;
      	if (i == 0) {
        	prev = k;
          	continue;
        }
      	if (k <= prev) {
        	cur++;
        } else {
        	ans = max(ans, cur);
          	cur = 0;
        }
      	prev = k;
    }
  	ans = max(ans, cur);
  	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from numba import jit
import sys
input = sys.stdin.readline


@jit
def solve(n, k, A):
    for _ in range(k):
        B = [0]*(n+1)
        for i, a in enumerate(A):
            B[max(0, i-a)] += 1
            B[min(n, i+a+1)] -= 1
        for j in range(1, n):
            B[j] += B[j-1]
        if A == B[:-1]:
            break
        A = B[:-1]
    return A


def main():
    n, k = map(int, input().split())
    A = list(map(int, input().split()))
    ans = solve(n, k, A)
    print(*ans)


if __name__ == '__main__':
    main()


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin>>s;
    if (s[0]==s[2]){
        cout<<"Yes\n";
    }else{
        cout<<"No\n";
    }
    return 0;
}


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

int main() {
  int n,m;
  cin>>n>>m;
  int a[m];
  for(int i=0; i<m; i++) cin>>a[i];

  int sum=0;
  for(int i=0; i<m; i++) sum+=a[i];

  if(n>=sum) cout<<n-sum<<endl;
  else cout<<-1<<endl;


  return 0;
}

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

int main()
{
	int n,m;

	scn(n); scn(m);

	int a[n],sum=0;

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

	sort(a,a+n,greater<int>());

	rep(i,0,m)
	{
		if(4*a[i]*m<sum)
		{
			printf("No"); return 0;
		}
	}

	printf("Yes");

    return 0;
}

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

p = 10**9 + 7

def cmb(n, r, p):
    x = 1
    y = 1
    for i in range(r):
        x = x*(n-i) % p
        y = y*(r-i) % p
    return x*pow(y, p-2, p) % p

ans = pow(2, n, p) - 1 - cmb(n, a, p) - cmb(n, b, p)

print(ans%p)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int W = scan.nextInt();

		long v[] = new long[n + 1];
		int w[] = new int[n + 1];

		for (int i = 1; i <= n; i++) {
			w[i] = scan.nextInt();
			v[i] = scan.nextInt();
		}

		long dp[][] = new long[n + 1][W + 1];
		
		for(int i=0;i<=n;i++) {
			for(int j=0;j<=W;j++) {
				if(i==0 || j ==0) {
					dp[i][j] = 0;
				} else if(w[i] > j) {
					dp[i][j] = dp[i-1][j];
				} else if((v[i] + dp[i-1][j-w[i]]) > dp[i-1][j]) {
					dp[i][j] =v[i] + dp[i-1][j-w[i]];
				} else {
					dp[i][j] = dp[i-1][j];
				}
			}
		}
		
		//System.out.println(Arrays.deepToString(dp));
		System.out.println(dp[n][W]);

	}

	public static long find(int cw, int ci, long[] v, int[] w, long dp[][]) {
		if (cw == 0) {
			return 0;
		}

		if (ci >= v.length) {
			return 0;
		}
		if (cw < w[ci]) {
			return 0;
		}

		if (dp[ci][cw] != 0) {
			return dp[ci][cw];
		}
		long with = v[ci] + find(cw - w[ci], ci + 1, v, w, dp);
		long without = find(cw, ci + 1, v, w, dp);

		dp[ci][cw] = Math.max(with, without);
		return dp[ci][cw];

	}
}


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

long long n, m, a, b, cnt[55];
int main(){
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        cin >> a >> b;
        cnt[a]++; cnt[b]++;
    }
    for(int i = 1; i <= n; i++) cout << cnt[i] << "\n";
}


Measured memory_bytes: 256
package main

import "fmt"

func isEven(a, b int) {
	if a * b % 2 == 0 {
		fmt.Println("Even")
	} else {
		fmt.Println("Odd")
	}
}

func main() {
	var a, b int
	fmt.Scan(&a, &b)
	isEven(a, b)
}

Measured memory_bytes: 512
n,m = map(int,input().split())

ac = [0 for i in range(n+1)]
tmp = [0 for i in range(n+1)]

cnt_ac = 0
cnt_pen = 0

for i in range(m):
    p,s = map(str,input().split())
    p = int(p)
    
    
    #まだ不正解の場合
    if ac[p] == 0:
        if s == 'WA':
            if tmp[p] >= 0:
                tmp[p] += 1

        if s=='AC':
            ac[p] = 1
            cnt_ac += 1
            if tmp[p] > 0:
                cnt_pen += tmp[p]
                tmp[p] = -1

    #すでに正解した問題の場合
    else:
        continue

print(cnt_ac, cnt_pen)

Measured memory_bytes: 52896
#include  "bits/stdc++.h"
using namespace std;
#define I_AM_SPEED  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#define mem(a,v)    memset((a), (v), sizeof (a))
#define mp(a , b)   make_pair(a , b)
#define eb(a)       emplace_back(a)
#define anal         '\n'
#define mod 1000000007
//const double PI = acos(-1.0);
typedef long long ll;


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
     


//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-


int main(){
I_AM_SPEED;

//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
      
      ll a;
      cin >> a;
      int b;
      cin >> b;
      ll ans = a * b;
      cout << ans << anal;
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
return  0 ;      
}        





Measured memory_bytes: 3648
N = int(input())
x = [0]*N
y = [0]*N
dist = [[0]*N]*N
ans = 0

for i in range(N):
  x[i],y[i]=map(int, input().split())

for i in range(N):
  for j in range(N):
    dist[i][j]=((x[i]-x[j])**2+(y[i]-y[j])**2)**0.5
    ans += dist[i][j]

print(ans/N)


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


//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君

long long n,k;

bool check(vector<long long> a,long long b){
    long long cnt=0;
    for(long long i=0  ;i<k  ;i++){
        long long weight=0;
        while (weight+a[cnt]<=b){
            weight+=a[cnt];
            cnt++;
            if (cnt==n){
                return true;
            }
        }
    }
    return false;
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); //printfとかと混ぜるな！
    
    cin>>n>>k;
    vector<long long> a(n,0);
    for(int i=0  ;i<n  ;i++) cin>>a[i];
    long long ok=100000*10000;
    long long ng=0;
    long long mid;
    while (abs(ok-ng)>1){
        mid=(ok+ng)/2;
        if (check(a,mid)){
            ok=mid;
        }else{
            ng=mid;
        }
    }
    cout<<ok<<endl;
    
}



Measured memory_bytes: 4564
#include <stdio.h> //ioはinputとoutput
#include <stdbool.h>
#include <ctype.h> //toupperとか文字に関するもの

bool is_lower(char s) //何かを探す時はis_～
{
    if ('a' <= s && s <= 'z')
    {
        return true;
    }
    return false;
}
char toggle_case(char s)
{
    if (is_lower(s))
    {
        return toupper(s);
    }
    return tolower(s);
}
void swap_string(char str[])
{
    int i = 0;
    while (str[i])
    {
        str[i] = toggle_case(str[i]);
        i++;
    }
}
int main(void)
{
    char str[1200];

    scanf("%[^\n]%*c", str); //空白を含む文字列の入力の仕方が分からなかったので調べたら、これが出てきた。

    swap_string(str);

    printf("%s\n", str);

    return 0;
}
//if文の条件式を関数にするという事が新鮮だった。
//ぱっと見て何をしてるか分かるようにすること！



Measured memory_bytes: 2696
# -*- coding: utf-8 -*-
from math import sqrt
n = int(input())
s = int(input())

def f(b, n):
    ans = 0
    while n >= b:
        ans += n%b
        n = n//b
    return ans + n

if n==s:
    print(n+1)
    exit()

for b in range(2, int(sqrt(n))+1):
    if f(b, n) == s:
        print(b)
        break
else:
    for p in range(1, int(sqrt(n))+1)[::-1]:
        d, m = divmod(p+n-s, p)
        if m == 0 and d >= 2 and f(d, n) == s:
            print(d)
            break
    else:
        print(-1)

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int,int> pint;

#define DE 1
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
#define ALL(s) (s).begin(),(s).end()
#define REP(i,n) for (int i = 0; i < (int)(n); ++i)
#define EACH(i,s) for (typeof((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl

template<class T1, class T2> ostream& operator<<(ostream &s, pair<T1,T2> P){return s<<'<'<<P.first<<", "<<P.second<<'>';}
template<class T> ostream& operator<<(ostream &s, vector<T> P) {s<<"{ ";for(int i=0;i<P.size();++i){if(i>0)s<<", ";s<<P[i];}return s<<" }"<<endl;}
template<class T1, class T2> ostream& operator<<(ostream &s, map<T1,T2> P) {s<<"{ ";for(typeof(P.begin()) it=P.begin();it!=P.end();++it){if(it!=P.begin())s<<", ";s<<'<'<<it->first<<"->"<<it->second<<'>';}return s<<" }"<<endl;}



map<string,int> ma;
int N, M;

int main() {
    //freopen( "/Users/macuser/Documents/Programming/Contest/input.in", "r", stdin );
    
    while (cin >> N) {
        if (N == 0) break;
        ma.clear();
        for (int i = 0; i < N; ++i) {
            string str;
            cin >> str;
            ma[str]++;
        }
        int mode = 0;
        cin >> M;
        for (int i = 0; i < M; ++i) {
            string str;
            cin >> str;
            if (ma[str] > 0) {
                if (mode == 0) cout << "Opened by " << str << endl;
                else cout << "Closed by " << str << endl;
                mode = 1-mode;
            }
            else cout << "Unknown " << str << endl;
        }
    }       
    
    return 0;
}


Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

int solve(){
    int n;
    cin>> n;
    vll v(n);
    rep(i, 0, n)
        cin>> v[i];
    ll ans = 0, mx = v[0];
    rep(i, 1, n){
        if(v[i] > mx)
            mx = v[i];
        else
            ans += mx - v[i];
    }
    cout<< ans<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  int N, K; scanf("%d %d", &N, &K);
  vector<int> X(N), Y(N);
  vector<int> px(N), py(N);
  for (int i = 0; i < N; ++i) {
    scanf("%d %d", &X[i], &Y[i]);
    px[i] = X[i];
    py[i] = Y[i];
  }
  sort(X.begin(), X.end());
  sort(Y.begin(), Y.end());
  ll ans = numeric_limits<ll>::max();
  for (int i = 0; i < N; ++i) {
    for (int j = i + 1; j < N; ++j) {
      int x1 = X[i], x2 = X[j];
      for (int k = 0; k < N; ++k) {
        for (int l = 0; l < N; ++l) {
          int y1 = Y[k], y2 = Y[l];
          int cnt = 0;
          for (int p = 0; p < N; ++p) {
            if (x1 <= px[p] and px[p] <= x2 and y1 <= py[p] and py[p] <= y2) {
              ++cnt;
            }
          }
          if (cnt >= K) {
            ans = min(ans, 1LL * (x2 - x1) * (y2 - y1));
          }
        }
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main() {
  long long ans = 1;
  int n;
  cin >> n;
  vector<long long> A(n);
  rep(i, n) { cin >> A[i]; }
  sort(A.begin(), A.end());
  rep(i, n) {
    if (A[i] != 0 && ans > (1000000000000000000 / A[i])) {
      ans = -1;
      break;
    }
    ans = ans * A[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4052