akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
     int a, b, c, t, i, j;

     scanf("%d", &i);
     
     while(i>0){
	  a = 0;
	  b = 0;
	  c = 0;

	  for(j=1; j<=3; j++){
	       scanf("%d", &t);
	       t = t * t;
	       
	       if(c<=t){
		    if(b<=t){
			 if(a<=t){
			      c = b;
			      b = a;
			      a = t;
			 }
			 else{
			      c = b;
			      b = t;
			 }
		    }
		    else c = t;
		    
	       }
	  }
	  if(a != b + c) printf("NO\n");
	  else if(b == 0 || c == 0) printf("NO\n");
	  else printf("YES\n");

	  i--;	  
     }
     
     return 0;
}

Measured memory_bytes: 580
import itertools
def make_list(length, i):
    seq = []
    for j in range(length-1):
        seq.append(j)
    return list(itertools.combinations(seq, i))
if __name__ == '__main__':
    s = input()
    lst = []
    ans = 0
    for i in range(len(list(s))):
        lst += make_list(len(list(s)), i)
    expr = ''
    for l in lst:
        if len(l) == 0:
            expr = s
        else:
            before = 0
            expr = ''
            for i in range(len(l)):
                if before == l[i]:
                    expr += s[before] + '+'
                else:
                    expr += s[before:l[i]+1] + '+'
                before = l[i] + 1
                if i == len(l) - 1:
                    expr += s[before:]
        ans += eval(expr)
    print(ans)


Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)

	if abs(a-b) <= d && abs(b-c) <= d || abs(a-c) <= d {
		fmt.Println("Yes")
		return
	}
	fmt.Println("No")
}

func abs(x int) int {
	if x <0 {
		x = -x
	}
	return x
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  998244353
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
const int MAX = 300010;
ll fac[MAX], finv[MAX], inv[MAX];
void cinit() { // O(nlogn)
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  reps(i, 2, MAX){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll c(int n, int k){ // 二項係数計算
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//--MAIN-----------------------------------
void Main() {
    ll N,A,B,K; cin>>N>>A>>B>>K;
    cinit();
    ll ans=0;
    rep(i,N+1){
        ll anum=i;
        if((K-A*anum)%B!=0) continue;
        ll bnum=(K-A*anum)/B;
        if(bnum<0 or bnum>N) continue;

        ans+=c(N,anum)*c(N,bnum)%MOD;
        ans%=MOD;
    }
    cout<< ans<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 7296
import heapq

n = int(input())
w = list(map(int, input().split()))

answers = []
for i in range(1, len(w)):
  a = sum(w[:i])
  b = sum(w[i:])

  if(a-b >= 0):
    answers.append(a-b)
  else:
    answers.append(b-a)

print(min(answers))

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

int main(){
  int n;
  cin >> n;
  int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cout << a[n-1] << endl;
}

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

int main(void){
    int N;
    scanf("%d", &N);
    int x[N], y[N];
    for (int i = 0; i < N; i++)
    scanf("%d %d", &x[i], &y[i]);

    // for (int i = 0; i < N ; i++)
    // printf("%d ",x[i]);
    // printf("\n");

    int ave = 1;        //Nの階乗
    for (int i = 1; i < N+1; i++)
    ave = ave * i;

    double len = 0;
    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            double nakami;
            nakami = (x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j]);
            //nakami = (x[i] - x[j])^2;
            nakami = sqrt(nakami);
            //nakami = pow(nakami, 0.5);
            //printf("nakamiは%lf\n",nakami);
            len = len + nakami;
            //printf("lenは%lf\n",len);
        }
    }

    int kake = 2;
    for(int i=1;i<N;i++){
        kake = kake * i;
    }
    len = len * kake;

    double ans;
    ans = len / ave;



    //printf("aveは%d\n",ave);
    printf("%lf\n",ans);
    //sreturn 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;

vector<ll> G[500005];
vector<P> tree[500010];
priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj;
ll n,m;
ll a,b,c,d,e,g,h,r;
ll l,ans,num;
ll x[500005],y[500005],z[500005];
bool dame,flag;
char s[500005],t[500005];
bool used[500005];

int main(){
    cin >> n;
	for(i=0;i<n;i++){
		cin >> x[i];
		y[i] = x[i];
	}
	sort(x,x+n);
	sort(y,y+n);
	reverse(x,x+n);
	for(j=32;j>=0;j--){
		num = (1 << j);
		//p(num);
		for(i=0;i<n;i++){
			if(used[i])continue;
			a = num - x[i];
			b = lb(y,y+n,a+1) - lb(y,y+n,a);
			if(b >= 1){
				c = lb(y,y+n,a) - lb(y,y+n,-1);
				c = n - 1 - c;
				c -= (b - 1);
				while(i == c){
					c++;
				}
				while(used[c] && x[c+5000] == a && used[c + 5000]){
					c += 5000; 
				}
				while(used[c]){
					c++;
				}
				while(i == c){
					c++;
				}
				if(!used[c] && x[c] == a){
					used[c] = true;
					used[i] = true;
					ans++;
					//pe(i);p(c);
				}
			}
		}
	}
	p(ans);
    return 0;
}

Measured memory_bytes: 33024
N = int(input())
ans = 0
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
if A == B:
    print(0)
    exit()
b_min = 10**10
for a, b in zip(A, B):
    if a>b:
        b_min = min(b_min, b)
print((sum(A)+sum(B))//2-b_min)


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


int abs(int n){
  if (n < 0) return -n;
  return n;
}

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<int> ans(n-1);
  for (int i=0; i<n; i++){
    for (int j=i+1; j<n; j++){
      int a, b;
      a = j - i;
      b = abs(i - x) + 1 + abs(j - y);
      ans[min(a, b)-1]++;
    }
  }
  for (int i=0; i<n-1; i++) cout << ans[i] << endl;

  return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
    int N, X, Y; cin >> N >> X >> Y;
    vector<int> ans(N + 1);
    for(int i = 1; i <= N; ++i) {
        for(int k = 1; k <= N; ++k) {
            if(i == k) continue;
            int tmp = min(k - i, abs(X - i) + 1 + abs(Y - k));
            if(tmp < 0) continue;
            ans.at(tmp)++;
        }
    }
    for(int i = 1; i < N; ++i) {
        cout << ans.at(i) << endl;
    }
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
	ll N, A, B;
	cin >> N >> A >> B;
	ll ans = N / (A + B) *A +min(A,N%(A+B)) ;
	ce(ans)
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, x, t;
    int ans;
    scanf("%d %d %d", &n, &x, &t);

    if(n%x == 0){
        ans = n / x * t;
    } else {
        ans = (n / x + 1) * t;
    }

    printf("%d", ans);

    return 0;
}

Measured memory_bytes: 2172
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, ans, mi1,mi2,sum;
string s[50];
int main() {
	cin >> H >> W;
	for (int i = 0; i < H; i++) {
		cin >> s[i];
	}
	queue<pair<int, int>> point;
	LL dist[50][50];
	point.push(make_pair(0, 0));
	ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.') {
				ans++;
			}
			dist[i][j] = -1;
		}
	}
	dist[0][0] = 0;
	while (!point.empty()) {
		pair<int, int> now = point.front();
		point.pop();

		for (int i = 0; i < 4; i++) {
			if (now.first + dy[i]<H&&now.first + dy[i]>-1 && now.second + dx[i]<W&&now.second + dx[i]>-1) {
				if (s[now.first + dy[i]][now.second + dx[i]] == '.' && dist[now.first + dy[i]][now.second + dx[i]] == -1) {
					dist[now.first + dy[i]][now.second + dx[i]] = dist[now.first][now.second] + 1;
					point.push(make_pair(now.first + dy[i], now.second + dx[i]));
				}
			}
		}
	}
	if (dist[H - 1][W - 1] == -1) {
		cout << -1 << endl;
		return 0;
	}
	cout << ans - dist[H - 1][W - 1]-1 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;

int sum(int x)
{
    if (x < 10)
        return x;
    return (x % 10)  + sum(x / 10);
}

int main()
{
    int n;
    ni(n);
    int ans = INF;
    for (int i = 1; i < n; i++)
    {
        int b = n - i;
        ans = min(ans, sum(b) + sum(i));
    }
    pri(ans);
    return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
A = list(map(int,input().split()))
D = {0:1}
a = 0
ans = 0

for n in range(N):
  a = (a+A[n])%M
  ans+=D.get(a,0)
  D[a] = 1+D.get(a,0)

print(ans)

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

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //freopen("in.inp", "r", stdin);
    //freopen("ou.out", "w", stdout);
    int m,d;
    cin>>m>>d;
    int kq=0;
    for (int i=22;i<=d;i++)
    {
        int x=i;
        int d1=x%10;
        int d10=x/10;
        if (d1>=2&&d10>=2&&d1*d10<=m) kq++;
    }
    cout<<kq;
    return 0;
}


Measured memory_bytes: 256
program main
  implicit none
  integer::N,M
  integer::ANS(3)
  integer::s,c
  integer::i
  read*,N,M
  ANS=-1
  do i=1,M
    read*,s,c
    if(ANS(s)>=0.and.ANS(s)/=c)then
      print"(i0)",-1
      stop
    endif
    if(s==1.and.c==0 .and. N/=1)then
      print"(i0)",-1
      stop
    endif
    ANS(s)=c
  end do
  do i=1,N
    ANS(i)=max(ANS(i),merge(merge(0,1,N==1),0,i==1))
  end do
  do i=1,N
    write(*,"(i0)",advance="no") ANS(I)
  end do
  write(*,*)
end program main

Measured memory_bytes: 256
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int n,i,d[100010]={};
  int b[30];
  char s[1000010];
  for(i=0;i<30;i++)b[i]=-1;
  for(i=1;i<100010;i++)d[i]=1e9;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(i)d[i]=d[i-1]+1;
    if(b[s[0]-'a']+1)d[i]=MIN(d[i],d[b[s[0]-'a']]);
    b[s[0]-'a']=i;
  }
  //for(i=0;i<n;i++)printf("%d\n",d[i]);
  printf("%d\n",d[n-1]+1);
  return 0;
}



Measured memory_bytes: 2260
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 2e5 + 5, inf = 1e9;
#define pb push_back
#define mp make_pair
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define sz(x) (int)x.size()
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

vi g[N];
int a[N];
int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n;
	cin >> n;
	for(int i = 2; i <= n; i++){
		cin >> a[i];
		g[a[i]].pb(i);
	}
	for(int i = 1; i <= n; i++){
		cout << sz(g[i]) << '\n';
	}
	return 0;
}



Measured memory_bytes: 15252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #define int long long

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int N;
    cin >> N;
    vi a(N);
    REP(i, N) cin >> a[i];
    sort(ALL(a));

    int Q;
    cin >> Q;
    vector<pii> bc(Q);
    REP(i, Q) {
        int b, c;
        cin >> b >> c;
        bc[i] = pii(b, c);
    }

    ll ans = accumulate(ALL(a), 0LL);
    map<int, int> cnt;
    REP(i, Q) {
        int dif = bc[i].second-bc[i].first;
        int num = distance(a.begin(), lower_bound(ALL(a), bc[i].first+1)) - distance(a.begin(), lower_bound(ALL(a), bc[i].first));
        num += cnt[bc[i].first];
        
        cnt[bc[i].second] += num;
        cnt[bc[i].first] -= num;
        
        ans += dif*num;
        cout << ans << endl;
        
    }

    return 0;
}


Measured memory_bytes: 8372
import java.util.Scanner;
import java.util.ArrayList;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    ArrayList<Integer> array = new ArrayList<Integer>();
    for(int a=0;a<n;a++){
      array.add(sc.nextInt());
      array.add(sc.nextInt());
    }
    for(int b=0;b<2*n;b=b+2){
      count += array.get(b+1)-array.get(b)+1;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 24788
n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort()

cur = 10**9
i = 0

while(i+k <= n):
    if(A[i+k-1] <= 0):
        tmp = -A[i]
    elif(A[i] <= 0):
        B = [-A[i], A[i+k-1]]
        B.sort()
        tmp = B[1] + 2 * B[0]
    else:
        tmp = A[i+k-1]
    cur = min(cur, tmp)
    i = i + 1

print(cur)


Measured memory_bytes: 14252
import java.util.*;

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

        int N = sc.nextInt();
        int[] As = new int[N];
        int[] sortedAs = new int[N];
        for (int i=0; i<N; i++) {
            As[i] = sc.nextInt();
        }

        System.arraycopy(As, 0, sortedAs, 0, As.length);
        Arrays.sort(sortedAs);
        

        int max = sortedAs[N-1];
        
        if (max == sortedAs[N-2]) {
            for (int i=0; i<N; i++) {
                System.out.println(max);
            }
        } else {
            for (int a : As) {
                if (a == max) {
                    System.out.println(sortedAs[N-2]);
                } else {
                    System.out.println(max);
                }
            }
        }
    }
}



Measured memory_bytes: 93672
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b[ohara],c[ohara],d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q,l;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll flo1[3000][3000];
ll flo2[3000][3000];
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n>>m>>l;
    rep(i,n){
        rep(j,n){
            if(i==j)flo1[i][j]=0;
            else flo1[i][j]=LINF;
        }
    }
    rep(i,m){
        cin>>a[i]>>b[i]>>c[i];
        a[i]--;b[i]--;
        flo1[a[i]][b[i]]=c[i];
        flo1[b[i]][a[i]]=c[i];
    }
    rep(i,n){
        rep(j,n){
            rep(k,n){
                flo1[j][k]=min(flo1[j][i]+flo1[i][k],flo1[j][k]);
            }
        }
    }
    //ここまでがW-F--------------------------------

    rep(i,n){
        rep(j,n){
            if(flo1[i][j]<=l)flo2[i][j]=1,flo2[j][i]=1;
            else flo2[i][j]=LINF,flo2[j][i]=LINF;
        }
    }

    rep(i,n){
        rep(j,n){
            rep(k,n){
                flo2[j][k]=min(flo2[j][i]+flo2[i][k],flo2[j][k]);
            }
        }
    }
    cin>>q;
    rep(i,q){
        cin>>tmp>>tmpp;
        tmp--;tmpp--;
        if(flo2[tmp][tmpp]==LINF)Cout(-1);
        else Cout(flo2[tmp][tmpp]-1);
    }
    return 0;
}

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

int main(void){
    int N, K;
    cin >> N >> K;
    int H[210000];
    for(int i=0; i<N ; i++){
        cin >> H[i];
    }
    sort(H, H+N, greater<int>());
    long int res = 0;
    for(int j=K; j<N; j++){
        res += H[j];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>

const int mod = 1e9 + 7;
const int kmax = 510000;

long long fact[kmax], fact_inv[kmax], inv[kmax];

int gcd(int a, int b)
{
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
}

void init_comb()
{
    fact[0] = fact[1] = 1;
    fact_inv[0] = fact_inv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < kmax; i++) {
        fact[i] = fact[i - 1] * i % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
    }
}

long long comb(int n, int r)
{
    if (n < r) {
        return 0;
    }

    if (n < 0 || r < 0) {
        return 0;
    }

    return fact[n] * (fact_inv[r] * fact_inv[n - r] % mod) % mod;
}

template <typename T, T N>
class UnionFind {
    T parent_[N];
    T rank_[N];
    T size_[N];

public:
    UnionFind();
    T Root(T idx);
    bool IsSame(T x, T y);
    void Unite(T x, T y);
    T GetSize(T idx);
};

template <typename T, T N>
UnionFind<T, N>::UnionFind()
{
    for (T i = 0; i < N; i++) {
        parent_[i] = i;
        rank_[i] = 0;
        size_[i] = 1;
    }
}

template <typename T, T N>
T UnionFind<T, N>::Root(T idx)
{
    return parent_[idx] == idx ? idx : parent_[idx] = Root(parent_[idx]);
}

template <typename T, T N>
bool UnionFind<T, N>::IsSame(T x, T y)
{
    return Root(x) == Root(y);
}

template <typename T, T N>
void UnionFind<T, N>::Unite(T x, T y)
{
    x = Root(x);
    y = Root(y);
    if (x == y) {
        return;
    }

    if (rank_[x] < rank_[y]) {
        parent_[x] = y;
        size_[y] += size_[x];
    } else {
        parent_[y] = x;
        size_[x] += size_[y];
        if (rank_[x] == rank_[y]) {
            rank_[x]++;
        }
    }
}

template <typename T, T N>
T UnionFind<T, N>::GetSize(T idx)
{
    return size_[Root(idx)];
}

long long pow_mod(long long n, long long p, long long m)
{
    if (p == 0) {
        return 1;
    }

    if (p % 2 == 0) {
        long long t = pow_mod(n, p / 2, m);
        return t * t % m;
    }
    return n * pow_mod(n, p - 1, m) % mod;
}

long long nCr_mod(long long n, long long r)
{
    long long x = 1;
    for (long long i = n - r + 1; i <= n; i++) {
        x *= i;
        x %= mod;
    }

    long long a = 1;
    for (long long i = 1; i <= r; i++) {
        a *= i;
        a %= mod;
    }

    long long y = pow_mod(a, mod - 2, mod) % mod;

    return x * y % mod;
}

int main()
{
    int k, a, b;
    std::cin >> k >> a >> b;

    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define Cout(n) cout<<(n)<<endl
#define INF 1000000000000000000LL

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;
typedef vector<string> vs;
const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << ", ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

int main()
{
	ll n;
	string ans="";
	cin >> n;
	vs s(n);
	rep(i,n) cin >> s[i];
	for(char c='a';c<='z';++c){
		ll tmp=INF;
		rep(j,n){
			ll cnt=0;
			rep(k,SIZE(s[j])){
				if(s[j][k]==c){
					cnt++;
				}
			}
			tmp=min(tmp,cnt);
		}
		rep(i,tmp) ans+=c;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
from itertools import accumulate, product, permutations, combinations

N = int(input())
l = [i+1 for i in range(N)]
c_list = list(permutations(l))
P = tuple(int(_) for _ in input().split())
Q = tuple(int(_) for _ in input().split())
P_value = 0
Q_value = 0
for index, item in enumerate(c_list):
    if P == item:
        P_value = index+1
    if Q == item:
        Q_value = index+1

print(abs(P_value - Q_value))


Measured memory_bytes: 8052
#include<bits/stdc++.h>
using namespace std;
template <typename T> void max_self(T& a,T b){
    a=max(a,b);
}

int main()
{
    string s,t;
    cin>>s>>t;
    int len1=s.length(),len2=t.length();
    vector<vector<pair<int,pair<int,int>>>> dp(len1+1,vector<pair<int,pair<int,int>>>(len2+1,{0,{0,0}}));
    for(int i=1;i<=len1;i++){
        for(int j=1;j<=len2;j++){
            if(s[i-1]==t[j-1]) max_self(dp[i][j],{dp[i-1][j-1].first+1,{i-1,j-1}});
            else{
               max_self(dp[i][j],{dp[i-1][j].first,{i-1,j}});
               max_self(dp[i][j],{dp[i][j-1].first,{i,j-1}});
            }
        }
    }
     string ans="";
     //cout<<"hello"<<"\n";
    pair<int,pair<int,int>> answer={0,{0,0}};
    for(int i=0;i<=len1;i++){
        for(int j=0;j<=len2;j++){
            max_self(answer,{dp[i][j].first,{i,j}});
        }
    }
    //cout<<"hi"<<"\n";
    pair<int,int> cur=answer.second;
     while(cur.first>0 && cur.second>0){
        int i=cur.first;
        int j=cur.second;
       // cout<<"i ="<<i<<"j="<<j<<"\n";
        pair<int,int> prev=dp[i][j].second;
        if(prev==make_pair(i-1,j-1)){
           ans+=s[i-1];
        }
        cur=prev;
     }
    reverse(ans.begin(),ans.end());
    cout<<ans;
}


Measured memory_bytes: 108796
let a, b, c = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let rec f n a b c = if a mod 2 = 1 || b mod 2 = 1 || c mod 2 = 1 then n else if a = b && b = c then -1 else f (n + 1) (b / 2 + c / 2) (c / 2 + a / 2) (a / 2 + b / 2)
let _ = Printf.printf "%d\n" @@ f 0 a b c

Measured memory_bytes: 384
fun main(args : Array<String>) {
    val (a, b, m) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }
    val bb = readLine()!!.split(" ").map { it.toInt() }

    var min = aa.min()!! + bb.min()!!

    repeat(m) {
        val (x, y, c) = readLine()!!.split(" ").map { it.toInt() }
        val discounted = aa[x-1] + bb[y-1] - c
        if (discounted < min) {
            min = discounted
        }
    }

    println(min)
}

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

using namespace std;

int main(int argc, char **argv)
{
	int a[3], n;
	
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a+3);
		if(a[0]*a[0]+a[1]*a[1] == a[2]*a[2]){
			cout << "YES" << endl;
		} else {
			cout << "NO" << endl;
		}
	}
	
	return 0;
}

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

int main(){
  uint64_t money;
  uint64_t a(0),b(0);

  cin >> money;

  a = money / 500;
  a *= 1000;
  money %= 500;

  b = money / 5;
  b *= 5;

  cout << fixed << setprecision(10) << a + b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi h(N);
    cin >> h;
    int mx = h[0] - 1;
    bool flag = 1;
    for (int i = 1; i < h.size(); i++) {
        if (h[i] > mx) {
            h[i]--;
            mx = h[i];
        } else if (mx == h[i]) {
            continue;
        } else {
            flag = 0;
            break;
        }
    }
    if (flag)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

ll power(ll x,ll n) {
  ll result=1;
  while(n>0){
    if(n&1)result = ((result) * (x));
    
    x=((x)*(x));
    
    n >>= 1;
  }
  return result;
}
ll gcd(ll a,ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}

int main() {
  #ifdef AVI  
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  
  string s;
  cin >> s;
  ll res = 0;
  for(ll i=0 ; i<(s.length()/2) ; i++){
    if(s[i]!=s[s.length()-i-1])res++;
  }
  cout << res;
}

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

using namespace std;

#define MOD 1000000007
#define N 102
#define M 100005
#define ll long long 
#define ld long double
#define pb push_back
#define ff first
#define ss second

ll dp[N][M];
ll v[N], w[N];

int main(){
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll n, W; cin>>n>>W;
	ll i, j, ans;
	for(i=1; i<=n; i++){
		cin>>w[i]>>v[i];
	}
	memset(dp, 0, sizeof dp);
	for(j=0; j<=W; j++){
		for(i=1; i<=n; i++){
			dp[i][j] = max(dp[i][j], dp[i-1][j]);
			if(j >= w[i]){
				dp[i][j] = max(dp[i][j], dp[i-1][j-w[i]] + v[i]);
			}
		}
	}
	ans = 0;
	for(j=0; j<=W; j++){
		ans = max(ans, dp[n][j]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 80000
let first = readLine()!.split(separator: " ")
let N = Int(first[0])!
let M = Int(first[1])!

var graph: [[Int]] = .init(repeating: [], count: N)

for i in 0..<M {
  let line = readLine()!.split(separator: " ")
  let A = Int(line[0])!
  let B = Int(line[1])!
  graph[A-1].append(B-1)
  graph[B-1].append(A-1)
}

var anchor: [Int] = .init(repeating: -1, count: N)
var fixed = 0

var queue: [Int] = [0]

while !queue.isEmpty {
  var tmp: [Int] = []
  for top in queue {
  	for nei in graph[top] {
      if anchor[nei] == -1 {
        fixed += 1
        anchor[nei] = top
        tmp.append(nei)
      }
    }
  }
  queue = tmp
}

if fixed == N - 1 {
  print("No")
} else {
  print("Yes")
  for i in 1..<N {
    print(anchor[i] + 1)
  }
}


Measured memory_bytes: 18860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = (int)1e3 +10;
 
int main()
{
    int n;
    cin>>n;
    int arr[60];
    int pos = 0;
    for(int i = 1; i <= n; i++)
    {
        cin>>arr[i];
        if(arr[i] != i) pos++;
    }
    if(pos == 0 || pos == 2) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
 
    return 0;
}


Measured memory_bytes: 256
// Author: Harshdeep Sharma , IIT  Indore
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
// #define MOD  998244353
#define ll long long
const double PI = atan(1.0) * 4;
// const ll INF = (int)1e9 ;
const int di[4] = { -1, 0, 1, 0} ;
const int dj[4] = {0, -1, 0, 1} ;
const ll INF = (ll)2e18 + 50;
const int maximum  = numeric_limits<int>::max();
const int minimum  = numeric_limits<int>::min();
// const int N = 1e5 + 5 ;
const int mod = 1e9 + 7 ;
// const int N = 3e5 + 5 ;

ll power(ll a , ll e) {
	ll res = 1LL ;
	while (e > 0) {
		if (e % 2 == 1) res = res * a;
		a =  a * a  ;
		e /= 2 ;
	}
	return res ;
}






int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int t ;
	// cin >> t ;
	t = 1 ;
	while (t--) {
		// int n;
		int n , x , t ;
		cin >> n >> x >> t ;
		if (n % x == 0) {
			int num = n / x ;
			cout << num * t << "\n";
		} else {
			int num = n / x ;
			num++ ;
			cout << num*t << "\n";
		}



	}



	return 0 ;
}





Measured memory_bytes: 3648
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int dx[] = { -1, 0, 1, 0 }; const int dy[] = { 0, 1, 0, -1 };

int main() {
	vector<string> vvc;
	vvc.push_back(".,!? ");
	vvc.push_back("abc");
	vvc.push_back("def");
	vvc.push_back("ghi");
	vvc.push_back("jkl");
	vvc.push_back("mno");
	vvc.push_back("pqrs");
	vvc.push_back("tuv");
	vvc.push_back("wxyz");
	int n;
	cin >> n;
	while (n--){
		string s;
		string ans = "";
		cin >> s;
		int renzoku=0;
		char current='0';
		REP(i,s.length()){
			if (current!=s[i]){
				if (current != '0'){
					ans += vvc[current - '0' - 1][renzoku%vvc[current - '0' - 1].size()];
				}
				current = s[i];
				renzoku = 0;
			}
			else{
				renzoku++;
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 1216
#include <stdio.h>

int main () {
  char a[5];
  scanf("%s", a);

  if (a[0]==a[1] && a[1]==a[2] && a[2]==a[3]){
    printf("No\n");
  }
  else if (a[0]==a[1] && a[2]== a[3])
  {
    printf("Yes\n");
  }
  else if (a[0]==a[2] && a[1]== a[3])
  {
    printf("Yes\n");
  }
  else if (a[0]==a[3] && a[1]==a[2])
  {
    printf("Yes\n");
  }
  else
  {
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
X,N = map(int,input().split())
arr = list(map(int,input().split()))
if X not in arr:
    print(X)
    exit()
sx = X+1
mx = X-1
ans = []
while 1:
    if sx not in arr:
        ans.append(sx)
        break
    sx += 1
while 1:
    if mx not in arr:
        ans.append(mx)
        break
    mx -= 1
if abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[0])
elif abs(ans[0]-X) < abs(ans[1]-X):
    print(ans[1])
else:
    print(min(ans))


Measured memory_bytes: 9208
str = gets
gets.to_i.times do
  ins = gets.chomp.split(' ')
  case ins[0]
  when 'replace'
    str[ins[1].to_i..ins[2].to_i] = ins[3]
  when 'reverse'
    str[ins[1].to_i..ins[2].to_i] = str[ins[1].to_i..ins[2].to_i].reverse
  when 'print'
    puts str[ins[1].to_i..ins[2].to_i]
  end
end


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}



void solve()
{
  ll N; cin >> N;
  vector<ll> a(N);
  vector<int> scheck(1000010, 0);
  vector<int> bcheck(1000010, 0);
  ll amax = 0;
  rep(i, N) {
    cin >> a[i];
    scheck[a[i]] ++;
    chmax(amax, a[i]);
  }
  sort(a.begin(), a.end());

  rep(i, N) {
    for(ll j = a[i]; j <= amax; j += a[i]) {
      bcheck[j] ++;
    }
  }

  ll ans = 0;
  rep(i, N) {
    //    cout << a[i] << " " << scheck[a[i]] << " " << bcheck[a[i]] << endl;
    if(scheck[a[i]] == 1 && bcheck[a[i]] == 1) {
      ans ++;
    }
  }
  cout << ans << endl;
}


int main(void)
{
  // ll t; cin >> t; rep(i, t)
  solve();
}


Measured memory_bytes: 12772
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;
int dy[] = {0, 1, 0, -1};
int dx[] = {1, 0, -1, 0};

const static int MAX_N = 160001;

llong c1[MAX_N], c2[MAX_N];
int par[MAX_N], rank_t[MAX_N];

void init(int n) {
    for (int i = 0; i <= n; ++i) {
        par[i] = i;
        rank_t[i] = 0;
    }
}

int root(int x) {
    return par[x] == x ? x : par[x] = root(par[x]);
}

bool same(int x, int y) {
    return root(x) == root(y);
}

void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;

    if (rank_t[x] < rank_t[y]) {
        par[x] = y;
    } else {
        par[y] = x;
        if (rank_t[x] == rank_t[y]) rank_t[x]++;
    }
}

int main() {
    int h, w;
    char field[401][401];
    cin >> h >> w;
    rep(i, h) {
        string s;
        cin >> s;
        rep(j, w) {
            field[i][j] = s[j];
        }
    }

    init(h * w);
    rep(i, h) {
        rep(j, w) {
            rep(k, 4) {
                if (0 <= i + dx[k] && i + dx[k] <= h - 1 && 0 <= j + dy[k] && j + dy[k] <= w - 1) {
                    if (field[i][j] != field[i + dx[k]][j + dy[k]]) unite(i * w + j, (i + dx[k]) * w + (j + dy[k]));
                } else {
                    continue;
                }
            }
        }
    }

    rep(i, h) {
        rep(j, w) {
            if (field[i][j] == '.') ++c1[root(i * w + j)];
            else ++c2[root(i * w + j)];
        }
    }

    llong ans = 0;
    rep(i, h * w) {
        ans += c1[i] * c2[i];
    }

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

Measured memory_bytes: 4096
#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>	vec(N);
	rep(i, N)
		cin >> vec.at(i);
	int	count;
	count = 1;
	bool	up;
	bool	down;
	up = down = true;
	for (int i = 1; i < N; i++)
	{
		up &= vec.at(i - 1) <= vec.at(i);
		down &= vec.at(i - 1) >= vec.at(i);
		if (!(up | down))
		{
			count++;
			up = down = true;
		}
	}
	cout << count << endl;
}


Measured memory_bytes: 640
N=int(input())
An=list(map(int,input().split()))

t = 0
for n in range(0,N-1):
    t += abs(An[n] - An[n+1])
t += abs(An[0]) + abs(An[N-1])

for n in range(0, N):
    if n == 0:
        old_cost = abs(An[0]) + abs(An[1] - An[0])
        new_cost = abs(An[1])
    elif n == N-1:
        old_cost = abs(An[N-2] - An[N-1]) + abs(An[N-1])
        new_cost = abs(An[N-2])
    else:
        old_cost = abs(An[n-1] - An[n]) + abs(An[n] - An[n+1])
        new_cost = abs(An[n-1] - An[n+1])
    print(t - old_cost + new_cost)


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

typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { //最大公約数
  if (b==0) return a;
  else return gcd(b, a%b);
}

ll lcm(ll a, ll b) { //最小公倍数
  return a * b / gcd(a, b);
}

ll digit_sum(ll a){ //10進桁和
  ll ans=0;
  while(a>0){
    ans+=a%10;
    a/=10;
  }
  return ans;
}



int main()
{
  ll a,b,c,d;
  cin>>a>>b>>c>>d;

  cout<<min(min(a+c,a+d),min(b+c,b+d))<<endl;

  return 0;
}


Measured memory_bytes: 3624
from collections import defaultdict
import sys
input = sys.stdin.readline

H, W, N = map(int, input().split())
count = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    for da in range(3):
        for db in range(3):
            na, nb = a - da, b - db
            if 1 <= na <= H - 2 and 1 <= nb <= W - 2:
                count[(na, nb)] += 1
ans = [0] * 10
for k, v in count.items():
    ans[v] += 1
ans[0] = (H-2) * (W-2) - sum(ans)
print(*ans, sep='\n')


Measured memory_bytes: 150904
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

 
 
const ll N = 515;
const ll mod = 998244353;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   
void fastIO(void);
 
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);





int main(){
   // fastIO();
  
  char c;
  cin>>c;
  cout<<(char)(c+1)<<endl;






   

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll mod = 1e9 + 7;

const double PI=3.14159265358979323846;

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

    double r;
    cin >> r;

    double res = 2 * PI * r;
    cout << fixed << setprecision(4) << res << endl;
    return 0;
}

Measured memory_bytes: 3804
def main():
    N, P = (int(i) for i in input().split())
    A = [int(i) % 2 for i in input().split()]
    from collections import Counter
    c = Counter(A)
    if all(a == 0 for a in A):
        print(2**N if P == 0 else 0)
    else:
        print(2**(c[1]-1) * 2**c[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
'use strict'
function Main(input) {
	input = input.split("\n");
	let nums = input[1].split(" ");
  	let max = Math.max.apply(null, nums);  // → 9
    let min = Math.min.apply(null, nums);  // → 9
  	let a = parseInt(nums[0]);
  	let result = (a - min) + (max - a);

	console.log(result);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29684
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<tuple>
#include<utility>
#include<stack>

using namespace std;



int main() {

	long long int r, d, x;
	cin >> r >> d >> x;

	for (int i = 0; i < 10; i++) {
		x = r * x - d;
		cout << x << endl;
	}

	return 0;
}




Measured memory_bytes: 256
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 K=sc.nextInt();
		if(K*2>=B-A+1) {
			for(int i=A;i<B+1;i++) {
				System.out.println(i);
			}
		}else {
			for(int i=A;i<A+K;i++) {
				System.out.println(i);
			}
			for(int i=B-K+1;i<B+1;i++) {
				System.out.println(i);
			}
		}
	}
}

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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  int n;
  cin >> n;
  int z = 0, zt = 0;
  rep(i, 0, n) {
    int t, x, y;
    cin >> t >> x >> y;
    int s = x + y;
    if((t - zt) < (s - z)) {
      cout << "No" << endl;
      return 0;
    }
    if((t - zt) % 2) {
      if((s - z) % 2 == 0) {
        cout << "No" << endl;
        return 0;
      }
    }else {
      if((s - z) % 2) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace AOJ
{
	class Program
	{
		public static void Main(string[] args)
		{
			foreach(var i in Enumerable.Range(1, 9))
			{
				foreach(var j in Enumerable.Range(1, 9))
				{
					Console.WriteLine("{0}x{1}={2}", i, j, i*j);
				}
			}
		}
	}
}

Measured memory_bytes: 5768