akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void)
{
  int W, H, x, y, r;
  scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
  if(x - r >= 0 && y - r >= 0 && x + r <= W && y + r <= H)
    {
      printf("Yes\n");
    }
  else
    {
      printf("No\n");
    }
  return 0;
}


Measured memory_bytes: 2128
import scala.io.Source.stdin

object Main {
  def main(args:Array[String]) = {
    val list = stdin.getLines.map { s=>
      val w = s.split(" ")
      (w(0),w(1).toInt)
    }.toList.groupBy(_._1).toArray.sortBy(_._1)

    list.foreach { l =>
      println(l._1)
      println(l._2.map(_._2).sorted.mkString(" "))
    }
  }
}

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

namespace ITP1
{
    class ITP1_5_D
    {
        static void Method(string[] args)
        {
            int n;

            n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                int x = i;
                if (x % 3 == 0)
                {
                    Console.Write(" " + i);
                }
                else
                {
                    while (x > 10)
                    {
                        if (x % 10 == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }
                        x /= 10;
                        if (x == 3)
                        {
                            Console.Write(" " + i);
                            break;
                        }
                    }
                    
                }
            }
            Console.WriteLine();
            Console.ReadLine();
        }
    }

    class ITP1_5_D_ex
    {
        static void Main(string[] args)
        {
            int n;

            n = int.Parse(Console.ReadLine());

            for (int i = 1; i <= n; i++)
            {
                int x = i;
                if ((x % 3 == 0) || (x.ToString().Contains('3')))
                {
                    Console.Write(" " + i);
                }
            }
            Console.WriteLine();
            Console.ReadLine();
        }
    }
}



Measured memory_bytes: 20204
import std.conv, std.stdio;
import std.algorithm, std.array, std.string, std.range;
void main()
{
    auto s = readln.chomp.to!dstring;
    if (s[0..$/2].isPalindrome && (s[0..$/2] == s[$/2+1..$]))
        "Yes".writeln;
    else
        "No".writeln;
}

auto isPalindrome(T)(in T[] a)
{
    return a.equal(a.retro);
}


Measured memory_bytes: 256
import math
import bisect
from queue import Queue
from collections import deque

n, w = [int(i) for i in input().split()]

nap = [[int(i) for i in input().split()] for j in range(n)]

dp = [[0 for _ in range(100001)] for _ in range(101)]

for i in range(1,n+1):
    for j in range(w+1):
        if(i == 1):
            if(j >= nap[i-1][0]):
                dp[i][j] = nap[i-1][1]
        else:
            if(j-nap[i-1][0]<0):
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = max(dp[i-1][j],dp[i-1][j-nap[i-1][0]]+nap[i-1][1])

print(dp[n][w])

Measured memory_bytes: 173572
X, Y = map(int, input().split(" "))

prize = [300000, 200000, 100000]
sump = 0

if X <= 3:
    sump += prize[X-1]
if Y <= 3:
    sump += prize[Y-1]

if X==1 and Y==1:
    sump += 400000
    
print(sump)

Measured memory_bytes: 38384
#import numpy as np
from sys import stdin,stdout

input = stdin.readline
print = stdout.write

vi = [0]
wi = [0]

n,W=map(int,input().split())
for i in range(n):
    a,b = map(int,input().split())
    vi.append(b)
    wi.append(a)
#print(str(vi),'\n',str(wi))
    #dp = np.zeros((n+1,MW+1),dtype=np.int64)
dp = [[0]*(W+1) for i in range(n+1)]
    
for j in range(1,n+1):
    for k in range(1,W+1):
        if(wi[j]>k) :
            dp[j][k] = dp[j-1][k]
        else:
            dp[j][k] = max(dp[j-1][k],dp[j-1][k-wi[j]]+vi[j])

print(str(dp[n][W]))
    
        
    





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

int gcd3(int a, int b, int c){
  return gcd(a, gcd(b,c));
}

int main(){
  int K;
  cin>>K;
  int gcd_sum=0;
  for (int a=1; a<=K; a++){
    for (int b=1; b<=K; b++){
      for (int c=1; c<=K; c++){
        gcd_sum+=gcd3(a,b,c);
      }
    }
  }
  cout<<gcd_sum<<endl;
}

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

#define ll long long
#define pb push_back
#define MP make_pair
#define F first
#define S second
#define MAX 1e18
#define MIN -1e9
#define MOD 1000000007
#define println(x) cout << "[" << #x << ":" << x << "]\n"; 
#define print(x) cout << "[" << #x << ":" << x << "] "; 

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 n, W; 
	scanf("%d%d", &n, &W);
	vector<int> w(n), v(n);
	for(int i=0; i<n; i++)
		scanf("%d%d", &w[i], &v[i]);
	int total_sum = 0;
	for(auto x: v)
		total_sum += x;
	vector<ll> dp(total_sum+1, MAX);
	dp[0] = 0;
	for(int i=0; i<n; i++){
		for(int j=total_sum-v[i]; j>=0; j--){
			dp[j+v[i]] = min(dp[j+v[i]], dp[j] + w[i]);
		}
	}

	ll ans = MIN;
	for(int i=0; i<=total_sum; i++){
		if(dp[i] <= W){
			ans = max(ans, (ll)i);
		}
	}

	printf("%lld\n", ans);
	return 0;
}

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

int main() {
  int N;
  int A;
  int B;
  
  cin >> N >> A >> B ;
  
  if (N*A == B){
    cout << B << endl;
  }
  else if(N*A > B ){
    cout << B << endl;
  }
  else if (N*A < B){
    cout << N*A << endl;
  }
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

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

	ll ans = 0;
	ll a;
	map<ll, ll> m;
	for (int i = 1; i <= n; i++) {
		cin >> a;
		ll x = i + a;
		m[x]++;
		ll y = i - a;
		ans += m[y];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 26340
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <cctype>
#include <cassert>
#include <limits>
#include <functional>
#include <iomanip>
#include <complex>
#include <bitset>
#include <stack>
 
using namespace std;
 
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#if defined(_MSC_VER) || __cplusplus > 199711L
#define aut(r,v) auto r = (v)
#else
#define aut(r,v) __typeof(v) r = (v)
#endif
#define each(it,o) for(aut(it, (o).begin()); it != (o).end(); ++ it)
#define all(o) (o).begin(), (o).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset(m,v,sizeof(m))
#define INF 0x3f3f3f3f3f3f3f3fLL
#define SIZE 200105
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
 
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
typedef pair<int,ll> pill; typedef pair<ll,int> plli; 
typedef pair<double, int> pdi;
template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
typedef complex<double> P;
//ll MOD = 1000000007;
ll MOD=998244353;
typedef ll Weight;
struct Edge {
	int src, dst;
	Weight weight;
};
bool operator < (const Edge &e, const Edge &f) {
	return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
	e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
int N;
ll dp[114514];
ll h[114514];
int main(){
	cin>>N;
	rep(i,N)cin>>h[i];
	dp[0]=0;
	for(int i=1;i<=N;i++){
		dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
		if(i>1)dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i]);
	}
	cout<<dp[N-1]<<endl;


}

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

int main() {
    int n,k; cin >> n >> k;
    vector<int> a(n);
    int pos_1=0;
    rep(i, n) {
        cin >> a[i];
        if (a[i] == 1) pos_1=i;
    }
    int ans = 0;
    ans = (n+k-3)/(k-1);

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
ll n, k;
vector<P> e;

signed main(){
	cin >> n >> k;
	if(k > (n-1)*(n-2)/2) cout << -1 << endl;
	else{
		REP(i, n) FOR(j, i+1, n){
			if(e.size() >= n*(n-1)/2 - k) break;
			e.pb(P(i, j));
		}
		cout << e.size() << endl;
		for(P edge: e){
			cout << edge.first + 1 << " " << edge.second + 1 << endl;
		}


		// // check
		// set<P> tmp;
		// REP(i, n) FOR(j, i+1, n){
		// 	REP(l, k){
		// 		if(find(ALL(e), P(i, j)) == e.end() && find(ALL(e), P(j, i)) == e.end())
		// 			if(find(ALL(e), P(i, l)) != e.end() || find(ALL(e), P(l, i)) != e.end())
		// 				if(find(ALL(e), P(j, l)) != e.end() || find(ALL(e), P(l, j)) != e.end())
		// 					tmp.insert(P(i, j));
		// 	}
		// }
		// cout << tmp.size() << endl;
		// assert(k == tmp.size());
	}
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
    using namespace std;
    
    long n, k ;
    vector<long> v;
    
    
    long gcd(long a, long b) {
        if(b == 0)
            return a;
        else
            return gcd(b, a % b);
    }

    
    bool check(){
        long t;
        t = gcd(v[0],v[1]);
        for(int i = 1 ; i < v.size() - 1; i++){
            t = gcd(t , v[i+1]);
        }
        if(t == 1){
            return true;
        }
        if(k % t == 0){
            k = k / t;
            for(int i = 0 ; i < v.size() ; i++ ){
                v[i] = v[i] / t;
            }
            return check();
        }
        return false;
    }
        
    int main(){
        cin >> n >> k;
        long a;
        bool flg;
        flg = false;
        for(int i = 0; i < n ; i++ ){
            cin >> a;
            v.push_back(a);
            if(k == a){
                cout << "POSSIBLE" << endl;
                return 0;
            }else if(k < a){
                 flg = true;
            }
        }
        if(flg){
        }else{
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        if(check()){
            cout << "POSSIBLE" << endl;
        }else{
            cout << "IMPOSSIBLE" << endl;
        }
        
        return 0;
    }

Measured memory_bytes: 1400
#include <cstdio>
#include <queue>
#include <map>
#include <algorithm>
#define Z(n)get<n>(z)
#define M make_pair
#define F first
#define S second
using namespace std;
typedef pair<int,int> pii;
typedef tuple<pii,pii,int> T;
int t[51][51],dx[]={-1,0,1,0},dy[]={0,-1,0,1},a,b,x,y,X,Y,i,j,k;
int main(){
	for(;scanf("%d%d",&a,&b),a;){
		map<pair<pii,pii>,int>m;
		scanf("%d%d%d%d",&x,&y,&X,&Y);x--,y--,X--,Y--;
		for(j=0;j<b;j++)for(i=0;i<a;i++)scanf("%d",t[i]+j);
		queue<T>q;
		m[M(M(x,y),M(X,Y))]=1;
		for(q.push(make_tuple(M(x,y),M(X,Y),0));!q.empty();){
			T z=q.front();q.pop();
			if(Z(0)==Z(1)){printf("%d\n",get<2>(z));goto OK;}
			if(Z(2)<100)for(i=0;i<4;i++){k=0;
				pii c1=make_pair(Z(0).F+dx[i],Z(0).S+dy[i]);
				if(!(0<=c1.F&&c1.F<a&&0<=c1.S&&c1.S<b&&!t[c1.F][c1.S]))c1=Z(0),k|=1;
				pii c2=make_pair(Z(1).F+dx[(i+2)%4],Z(1).S+dy[(i+2)%4]);
				if(!(0<=c2.F&&c2.F<a&&0<=c2.S&&c2.S<b&&!t[c2.F][c2.S]))c2=Z(1),k|=2;
				if(k<3&&!m[M(c1,c2)]){
					q.push(make_tuple(c1,c2,Z(2)+1));
					m[M(c1,c2)]=1;
				}
			}
		}
		puts("NA");
		OK:;
	}
}

Measured memory_bytes: 12132
fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val xyh = mutableListOf<Triple<Int, Int, Int>>()
    (1..N).forEach {
        val (x, y, h) = readLine()!!.split(" ").map { it.toInt() }
        xyh.add(Triple(x, y, h))
    }

    (0..100).forEach { cx ->
        (0..100).forEach { cy ->
            fun actualHeight(x: Int, y: Int, h: Int): Int {
                return Math.abs(x - cx) + Math.abs(y - cy) + h
            }

            val estimates = mutableListOf<Int>()
            val boundaries = mutableListOf<Int>()
            (0..(N - 1)).forEach {
                val (x, y, h) = xyh[it]
                if (h != 0) {
                    estimates.add(actualHeight(x, y, h))
                } else {
                    boundaries.add(actualHeight(x, y, 0))
                }
            }
            val h = estimates[0]
            var unique = true
            estimates.forEach {
                unique = unique && it == h
            }
            var valid = true
            boundaries.forEach {
                if (h > it) {
                    valid = false
                }
            }
            if (unique && h >= 1 && valid) {
                print(cx)
                print(' ')
                print(cy)
                print(' ')
                print(h)
                println("")
                return
            }
        }
    }
    println("Something is wrong")
}


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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const int MOD = 1e9 + 7;



#define INPUT(x)                freopen(x,"r",stdin)
#define OUTPUT(x)               freopen (x,"w",stdout)



#define pb                      push_back
#define endl                    '\n'
#define LCM(a,b)                (a/__gcd(a,b))*b
#define GCD(a,b)                __gcd(a,b)
#define SP(x,y)                 fixed<<setprecision((y))<<(x)
#define PI                      acos(-1.0)
#define distance(x1,y1,x2,y2)   sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1))

#define taratari                ios_base::sync_with_stdio(0);cin.tie(NULL);





int main()
{
    taratari

    string a,b;
    cin>>a;
    cin>>b;

    int c=0;

    for(int i=0;i<a.size();i++)
    {
        if(a[i]!=b[i])
            c++;
    }

    cout<<c;


    return 0;


}



Measured memory_bytes: 3788
using System;
using System.Linq;
using System.Collections.Generic;

class MainClass {
  public static void Main (string[] args) {
	  // 入力
    var str = Console.ReadLine().Split(' ');
    var list = new List<string>();
    var list2 = new List<string>();
    for(var i = 0; i < int.Parse(str[0]); i++){
      list.Add(Console.ReadLine());
    }
    //処理
    list2 = list.OrderBy(x=>x).ToList();

    //出力
    foreach(var s in list2){
      Console.Write(s);
    }
      Console.WriteLine("");
  }
}


Measured memory_bytes: 13664
def Find(x, par):
    if par[x] < 0:
        return x
    else:
        par[x] = Find(par[x], par)
        return par[x]

def Unite(x, y, par, rank):
    x = Find(x, par)
    y = Find(y, par)

    if x != y:
        if rank[x] < rank[y]:
            par[y] += par[x]
            par[x] = y
        else:
            par[x] += par[y]
            par[y] = x
            if rank[x] == rank[y]:
                rank[x] += 1

def Same(x, y, par):
    return Find(x, par) == Find(y, par)

def Size(x, par):
    return -par[Find(x, par)]

import sys
input = sys.stdin.readline

n, m, k = map(int, input().split())

par = [-1]* n
rank = [0]*n

C = [0]*n

for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    C[a] += 1
    C[b] += 1
    Unite(a, b, par, rank)

ans = [0]*n
for i in range(n):
    ans[i] = Size(i, par)-1-C[i]

for i in range(k):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    if Same(c, d, par):
        ans[c] -= 1
        ans[d] -= 1

print(*ans)


Measured memory_bytes: 84580
#include <stdio.h>

int check(int p, int *d, int n);
int get_c(int p, int *d, int n);
void change(int pos, int color, int *d, int n);
int skip(int *pos, int *d, int n);

int main(void)
{
	int c[10000];
	int t[10000];
	int n;
	int i, j;
	int min;
	int color;
	int remain;
	
    while (1){
    	scanf("%d", &n);
    	if (n == 0){
            break;
    	}
        
    	for (i = 0; i < n; i++){
    		scanf("%d", &c[i]);
    	}
    
    	min = n;
    	for (i = 0; i < n; i++){
    		color = check(i, c, n);
    /*		printf("<%d-%d>", i, color);
    */		
    		if (color != 0){
    			for (j = 0; j < n; j++){
    				t[j] = c[j];
    			}
    			
    /*			printf("<p=%d c=%d>", i, color);
    */			
    			change(i, color, t, n);
    			
    			remain = 0;
    			for (j = 0; j < n; j++){
    				if (t[j] != -1){
    					remain++;
    				}
    			}
    			
    /*			printf("[remain=%d]", remain);
    */
    			if (min > remain){
    				min = remain;
    			}
    		}
    	}
    	
    	printf("%d\n", min);
    }
   	return (0);
}
    
int check(int p, int *d, int n)
{
	int c;
	int i;
	
	c = get_c(p + 1, d, n);
	if (c != 0){
		for (i = 2; i <= 3; i++){
			if (c != get_c(p + i, d, n)){
				break;
			}
		}
		if (i == 4){
			return (c);
		}
	}
	
	c = get_c(p - 1, d, n);
	if (c != 0){
		for (i = 1; i <= 2; i++){
			if (c != get_c(p + i, d, n)){
				break;
			}
		}
		if (i == 3){
			return (c);
		}
	}
	
	c = get_c(p + 1, d, n);
	if (c != 0){
		for (i = -2; i <= -1; i++){
			if (c != get_c(p + i, d, n)){
				break;
			}
		}
		if (i == 0){
			return (c);
		}
	}
	
	c = get_c(p - 1, d, n);
	if (c != 0){
		for (i = -3; i <= -2; i++){
			if (c != get_c(p + i, d, n)){
				break;
			}
		}
		if (i == -1){
			return (c);
		}
	}
	return (0);
}

int get_c(int p, int *d, int n)
{
	if (p < 0 || p >= n){
		return (0);
	}
	
	return (d[p]);
}

void change(int pos, int color, int *d, int n)
{
	int flag;
	int i, j;
	int p;
	int c;
	int l;
	
	d[pos] = color;
	
	do {
		flag = 0;
		for (i = 0; i < n - 3; i++){
			
/*			for (j = 0; j < n; j++){
				printf("%d ", d[j]);
			}
			printf("\n");
*/			
			
			l = 1;
			if (skip(&i, d, n) == -1){
				break;
			}
			
			c = d[i];
			p = i;
			
			while (1) {
				p++;
				if (skip(&p, d, n) == -1){
					break;
				}
				if (c == d[p]){
					l++;
				}
				else {
					break;
				}
			}
			
/*			printf("<<l = %d>>", l);
*/			if (l >= 4){
				flag = 1;
				for (j = i; j < n; j++){
					if (d[j] != -1){
						if (d[j] == c){
/*							printf("[%d]", j);
*/							d[j] = -1;
						}
						else {
							break;
						}
					}
				}
			}
		}
	} while (flag == 1);
}
	
	
int skip(int *pos, int *d, int n)
{
	while (d[*pos] == -1){
		(*pos)++;
		if (*pos >= n){
			return (-1);
		}
	}
	
	return (0);
}

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

// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
	long long val;
	constexpr Fp(long long v = 0) noexcept : val(v% MOD) {
		if (val < 0) val += MOD;
	}
	constexpr int getmod() { return MOD; }
	constexpr Fp operator - () const noexcept {
		return val ? MOD - val : 0;
	}
	constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
	constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
	constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
	constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
	constexpr Fp& operator += (const Fp& r) noexcept {
		val += r.val;
		if (val >= MOD) val -= MOD;
		return *this;
	}
	constexpr Fp& operator -= (const Fp& r) noexcept {
		val -= r.val;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr Fp& operator *= (const Fp& r) noexcept {
		val = val * r.val % MOD;
		return *this;
	}
	constexpr Fp& operator /= (const Fp& r) noexcept {
		long long a = r.val, b = MOD, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	constexpr bool operator == (const Fp& r) const noexcept {
		return this->val == r.val;
	}
	constexpr bool operator != (const Fp& r) const noexcept {
		return this->val != r.val;
	}
	friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
		return os << x.val;
	}
	friend constexpr Fp<MOD> modpow(const Fp<MOD>& a, long long n) noexcept {
		if (n == 0) return 1;
		auto t = modpow(a, n / 2);
		t = t * t;
		if (n & 1) t = t * a;
		return t;
	}
};

const int MOD = 1000000007;
using mint = Fp<MOD>;

int main() {
	
	int n; ll k; cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	mint selfCnt = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j <= i) continue;
			if (a[i] > a[j]) selfCnt += 1;
		}
	}
	selfCnt *= k;
	mint mutualCnt = 0;
	vector<int> smallCntNum(n, 0);
	for (int i = 0; i < n; i++) {
		mint tmpSmallCntNum = 0;
		for (int j = 0; j < n; j++) {
			if (i == j) continue;
			if (a[j] < a[i]) tmpSmallCntNum += 1;
		}
		mutualCnt += tmpSmallCntNum * k * (k - 1) / 2;
	}
	mint ans = selfCnt + mutualCnt;
	cout << ans << endl;
	return 0;
}

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

int main() {
  int N,C;
  cin >> N >> C;
  vector<vector<int>> D(C,vector<int> (C));
  vector<vector<int>> numc(3,vector<int> (C,0));
  for (int i=0; i<C; i++) {
    for (int j=0; j<C; j++) {
      cin >> D[i][j];
    }
  }
  int col;
  for (int i=0; i<N; i++) {
    for (int j=0; j<N; j++) {
      cin >> col;
      numc[(i+j)%3][col-1]++;
    }
  }
  int ans = 1000000007;
  int term = 0;
  for (int i=0; i<C; i++) {
    for (int j=0; j<C; j++) {
      if (i == j) {
        continue;
      }
      for (int k=0; k<C; k++) {
        if (i == k || j == k) {
          continue;
        }
        term = 0;
        for (int l=0; l<C; l++) {
          term += numc[0][l] * D[l][i];
          term += numc[1][l] * D[l][j];
          term += numc[2][l] * D[l][k];
        }
        ans = min(ans,term);
      }
    }
  }
  cout << ans << endl;
}

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

int main() {
    string s, t, u;
    int     a, b;

    cin >> s >> t;
    cin >> a >> b;
    cin >> u;

    if (s == u)
        a--;
    else
        b--;
    cout << a << " " << b;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 998244353
#define M 1000000007
using namespace std;
const int inf=4e18;
const int MX=100;
const int MN=-100;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int n;cin>>n;
	int a[n],i,o=0,j=1;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]!=j)
			o++;
		else
			j++;
	}
	if(o==n)
		o=-1;
	cout<<o<<endl;
}

Measured memory_bytes: 1792
using System;

class Program
{
    static void Main(string[] args)
    {
        var abc = Console.ReadLine().Split();
        var a = int.Parse(abc[0]);
        var b = int.Parse(abc[1]);
        var c = int.Parse(abc[2]);

        if (a == b + c ||
            b == a + c ||
            c == a + b)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>

using namespace std;

#define MAX 100005
#define NIL -1

struct Node {
  int parent;
  int leftChild;
  int rightSibling;
};

Node T[MAX];
int D[MAX];

void print(int u) {
  cout << "node " << u << ": ";
  cout << "parent = " << T[u].parent << ", ";
  cout << "depth = " << D[u] << ", ";

  if (T[u].parent == NIL) {
    cout << "root, ";
  } else if (T[u].leftChild == NIL) {
    cout << "leaf, ";
  } else {
    cout << "internal node, ";
  }

  cout << "[";

  int i, c;
  for (i = 0, c = T[u].leftChild; c != NIL; i++, c = T[c].rightSibling) {
    if (i) {
      cout << ", ";
    }
    cout << c;
  }
  cout << "]" << endl;
}

void rec(int u, int p) {
  D[u] = p;
  if (T[u].rightSibling != NIL) {
    rec(T[u].rightSibling, p);
  }
  if (T[u].leftChild != NIL) {
    rec(T[u].leftChild, p + 1);
  }
}

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

  for (int i = 0; i < N; i++) {
    T[i].parent = T[i].leftChild = T[i].rightSibling = NIL;
  }

  int child, v, d, left;
  for (int i = 0; i < N; i++) {
    cin >> v >> d;
    for (int j = 0; j < d; j++) {
      cin >> child;
      if (j == 0) {
        T[v].leftChild = child;
      } else {
        T[left].rightSibling = child;
      }
      left = child;
      T[child].parent = v;
    }
  }

  int root;
  for (int i = 0; i < N; i++) {
    if(T[i].parent == NIL) {
      root = i;
    }
  }

  rec(root, 0);

  for (int i = 0; i < N; i++) {
    print(i);
  }

  return 0;
}



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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int x, t;cin >> x >> t;
    cout << max(0, x-t) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
  //cin >> s;
  int i=0,n=0,a=0,b=0,c=0,d=0;
  cin >> n;
  for(i=0;i<n;i++){
  	cin >> s;
    if(s=="AC"){a++;}
    if(s=="WA"){b++;}
    if(s=="TLE"){c++;}
    if(s=="RE"){d++;}
  }
  cout << "AC x "<<a<<endl;
  cout << "WA x "<<b<<endl;
  cout << "TLE x "<<c<<endl;
  cout << "RE x "<<d<<endl;
}

Measured memory_bytes: 3632
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
using namespace std;
const int size1=21;
const int inf=1e9;
int h,w;
string grid[size1];

int r[]={0,0,1,-1};
int c[]={1,-1,0,0};

int dijkstra(int x1,int y1){
	vector<vector<int> > dist(h,vector<int>(w,-1));
	queue<pii> q;
	q.push(mkp(x1,y1));
	dist[x1][y1]=0;
	int mx=0;
	while(!q.empty()){
		int ui=q.front().first;
		int uj=q.front().second;
		q.pop();
		mx=max(mx,dist[ui][uj]);
		if(ui+1>=0 && ui+1<h && grid[ui+1][uj]!='#' && dist[ui+1][uj]==-1){
			dist[ui+1][uj]=dist[ui][uj]+1;
			q.push(mkp(ui+1,uj));
		}
		if(ui-1>=0 && ui-1<h && grid[ui-1][uj]!='#' && dist[ui-1][uj]==-1){
			dist[ui-1][uj]=dist[ui][uj]+1;
			q.push(mkp(ui-1,uj));
		}
		if(uj+1>=0 && uj+1<w && grid[ui][uj+1]!='#' && dist[ui][uj+1]==-1){
			dist[ui][uj+1]=dist[ui][uj]+1;
			q.push(mkp(ui,uj+1));
		}
		if(uj-1>=0 && uj-1<w && grid[ui][uj-1]!='#' && dist[ui][uj-1]==-1){
			dist[ui][uj-1]=dist[ui][uj]+1;
			q.push(mkp(ui,uj-1));
		}
	}
	return mx;
	
}

int solve()
{
	cin>>h>>w;	
	for(int i=0;i<h;i++){
		cin>>grid[i];
	}
	int mx=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(grid[i][j]!='#'){
				int x=dijkstra(i,j);
				mx=max(mx,x);
			}
		}
	}
	cout<<mx<<endl;
	return 0;
	
}
signed main()
{
	fastio;
//	test
		solve();
}

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

using namespace std;

using ll = long long;

int main() {
    string s;cin >> s;
    int r = 0, b = 0;
    for(int i = 0;i < s.size();i++){
        if(s[i] == '0')r++;
        else b++;
    }
    cout<<2 * min(r, b)<<endl;
    return 0;
}

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

int main(int argc, char const* argv[])
{
	int data[10000];
	int i;
	for (i=0 ;; i++) {
		cin >> data[i];
		if (data[i] == 0) {
			break;
		}
	} 

	for (int j=0; j<i; j++) {
		cout << "Case " << j+1 << ": " << data[j] << endl;
	}
	return 0;
}


Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define MAX_V 51
typedef pair<int, int> P;
int V,E,ans;

vector<P> p;
int G[MAX_V][MAX_V];
int h[MAX_V];

void init_graph(){
  REP(i,V) REP(j,V) G[i][j]=0;
}

void init_history(){
  REP(i,V) h[i+1]=0;
  h[1]=1;
}

void input_graph(){
  int s,t;
  REP(i,E){
    cin>>s>>t;
    p.push_back({s,t});
    G[s][t]=1;
    G[t][s]=1;
  }
}

void change_graph(P q){
  G[q.first][q.second]=0;
  G[q.second][q.first]=0;  
}

void rechange_graph(P q){
  G[q.first][q.second]=1;
  G[q.second][q.first]=1;  
}

void dfs(int i){
  REP(j,V){
    if(G[i][j+1]&&(!h[j+1])){
      h[j+1]=1;
      dfs(j+1);
    }
  }
}

int main(){
  ans=0;
  cin>>V>>E;
  init_graph();
  input_graph();
  REP(i,E){
    init_history();
    change_graph(p.at(i));
    dfs(1);
    int count=0;
    REP(j,V) count+=h[j+1];
    if(count!=V) ans++;
    rechange_graph(p.at(i));
  }
  cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define MAXSTRING 100000

int main(int argc,char const* argv[])
{
  string s;
  int check[26]={0};
  char correct[26];
  int i;
  for(i=0;i<26;i++)
    {
      correct[i]='a'+i;
    }
  cin >> s;
  int n=s.size();
  for(i=0;i<n;i++)
    {
      check[s[i]-'a']++;
    }
  for(i=0;i<26;i++)
    {
      if(check[i] == 0)
	{
	  cout << correct[i];
	  return 0;
	}
    }
  cout << "None";
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std; 
#define ll long long int
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define INF LLONG_MAX
#define PI acos(-1)
#define MOD 1e9 + 7
#define f first
#define s second
#define N 1e5 + 10
ll ok(ll n)
{
	if(pow(2,log2(n+1))==n+1)
	{
		return 1;
	}
	return 0;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	ll n;
	cin>>n;
	ll i=0,a=0,s1,s2;
	ll cv[n+1];
	cv[0]=0;
	ll min=999999999999999;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		cv[i]=cv[i-1]+a;
	}
	for(i=1;i<n;i++)
	{
		s1=cv[i];
		s2=cv[n]-cv[i];
		a=abs(s1-s2);
		if(a<min)
			min=a;
	}
	cout<<min;
}	

Measured memory_bytes: 256
import math

k, n = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]

res = n-1
top = (k - a[-1]) + a[0]
for i in range(n-1):
    if a[i+1] - a[i] > top:
        top = a[i+1] - a[i]
        res = i

print (k-top)

Measured memory_bytes: 26444
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<map>
 
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 pb push_back
#define pf push_front
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
 
ll gcd(ll x, ll y) {
	ll r;
	while ((r = x % y) != 0) {
		x = y;
		y = r;
	}
	return y;
	}
ll lcm(ll x, ll y) {
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x*y);
}

int main()
{
	int a,b;
	cin >> a >> b;
	cout << (b%a==0?a+b:b-a) << endl;
	return 0;
}


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

cost = []
key = []

for _ in range(m):
    k = ["0"] * n
    a, b = map(int, input().split())
    c = list(map(int, input().split()))
    for i in c:
        k[i - 1] = "1"

    k = int("".join(k), base=2)
    cost.append(a)
    key.append(k)


inf = 10**10
dp = [inf] * (1 << n)
dp[0] = 0

for i in range(1 << n):
    if dp[i] == inf:
        continue
    for a, k in zip(cost, key):
        m = k | i
        dp[m] = min(dp[m], dp[i] + a)

ans = -1 if dp[-1] == inf else dp[-1]
print(ans)


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

int w,h;
int filed[51][51];

void dfs(int x,int y){
  filed[x][y]=0;
  for(int dx=-1;dx<=1;dx++){
    for(int dy=-1;dy<=1;dy++){
      int nx=x+dx,ny=y+dy;
      if(0<=nx&&nx<h&&0<=ny&&ny<w&&filed[nx][ny]==1)dfs(nx,ny);
    }
  }
}

void solve(){
  int res=0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(filed[i][j]==1){
	dfs(i,j);
	res++;
      }
    }
  }
  cout<<res<<endl;
}

int main(){
  
while(1){
    cin>>w>>h;
    if(w+h==0)break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	cin>>filed[i][j];
      }
    }
    solve();
  }
  return 0;
}

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

int main(void)
{
	int n,cal[4];

	while(cin >> n, n){
		int d[1000][4] = {};

		for(int i = 0; i < n; i++){
			for(int j = 0; j < 4; j++){
				cin >> d[i][j];
			}
			d[i][1] *= 4;
			d[i][3] *= 4;
			d[i][2] *= 9;
		}

		for(int i = 0; i < 4; i++)
			cin >> cal[i];

		bool flag = false;
		for(int i = 0; i < n; i++){
//			for(int j = 0; j < 4; j++)
//				cout << d[i][j] << ' ';
//			cout << endl;
			if(cal[0] < d[i][1]/4 || cal[1] < d[i][2]/9 || cal[2] < d[i][3]/4)
				continue;
			if(cal[3] < (d[i][1] + d[i][2] + d[i][3]) )
				continue;

			flag = true;
			cout << d[i][0] << endl;
		}

		if(!flag)
			cout << "NA" << endl;
	}

	return 0;
}

Measured memory_bytes: 1184
#include <cstdio>
using namespace std;
int main()
{
  int a[4][3][10] = {{{}}};
  int n;
  scanf("%d", &n);
  int** d = new int* [n];
  for(int i = 0; i < n; i++)
    {
      d[i] = new int[4];
    }
  for(int i = 0; i < n; i++)
    {
      int b, f, r, v;
      scanf("%d %d %d %d", &b, &f, &r, &v);
      a[b - 1][f - 1][r - 1] += v;
    }
  for(int i = 0; i < 4; i++)
    {
      for(int j = 0; j < 3; j++)
	{
	  for(int k = 0; k < 10; k++)
	    {
	      printf(" %d", a[i][j][k]);
	    }
	  printf("\n");
	}
      if(i < 3)
	printf("####################\n");
    }
  for(int i = 0; i < n; i++)
    {
      delete[] d[i];
    }
  delete[] d;
}

Measured memory_bytes: 1052
INF = float("inf")
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, K = nl()
Vs = nl()

import bisect

R = min(K, N)
res = -INF
for l in range(R+1):
    for r in range(R+1-l):
        v = sorted(Vs[:l] + Vs[N-r:])
        i = bisect.bisect_left(v, 0)
        value = sum(v[min(i, K-l-r):])
        if value > res:
            res = value
print(res)


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

int main()
{
int n;
cin >> n;
int arr[n];

int j=0;
for(int i=0;i<n;i++)
{
    cin >> arr[i];
    if(arr[i]%2==0) {
        j++;
    }
}
int temp=0;
for(int i=0;i<n;i++)
{
    if(arr[i]%2==0)
    {
        if(arr[i]%3==0||arr[i]%5==0) temp+=1;
    }
}
if(temp==j) cout << "APPROVED";
else cout << "DENIED";
	return 0;
}


Measured memory_bytes: 3600
from itertools import accumulate
N,K = list(map(int,input().split()))
P = list(map(int,input().split()))
for i in range(N):
    P[i] = 1+(P[i]-1)/2
ruiseki = list(accumulate([0]+P))
ans = 0
for i in range(N-K+1):
    ans = max(ans,ruiseki[i+K]-ruiseki[i])
print(ans)

Measured memory_bytes: 85128
import java.io.PrintWriter;
import java.util.Scanner;

public class Main
{
	static Scanner in;
	static PrintWriter out;
	static void solve()
	{
		int N = in.nextInt();
		int[] a = new int[N];
		for(int i = 0; i < N; i++)
		{
			a[i] = in.nextInt();
		}
		int sum = 0;
		int sumi = 0;
		for(int i = 0; i < N; i++)
		{
			if(a[i] % 2 == 1)
			{
				sum += 1;
			}
			if(a[i] % 4 == 0)
			{
				sumi += 1;
			}
		}
		if(N % 2 == 1)
		{
			if(sumi + 1 < sum)
			{
				out.print("No");
			}
			else
			{
				out.print("Yes");
			}
		}
		else
		{
			if(sumi < sum)
			{
				out.print("No");
			}
			else
			{
				out.print("Yes");
			}
		}
	}
	public static void main(String[] args)
	{
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
		out.close();
		in.close();
	}
}

Measured memory_bytes: 50216
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int i = 0, sum = 0;
        String line = "";
        while (true) {
            line = sc.next();
            if(line.equals("0"))break;
            sum = 0;
            for (i = 0; i < line.length(); i++) {
                sum += (line.charAt(i) - '0');
            }
            System.out.println(sum);
        }
    }
}



Measured memory_bytes: 26180
#include <stdio.h>

int  A[10001];
int N,v,j;

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

  for(int i=0;i<N;i++){
    v = A[i];
    j = i-1;
    while(j>=0 && A[j]>v){
      A[j+1]=A[j];
      j--;
      A[j+1]=v;
    }

    for(int i=0;i<N;i++){
      printf("%d",A[i]);
      if(i<N-1){
        printf(" ");
    }

    }

  printf("\n");
}


      	return 0;

}



Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb(a) push_back(a)
#define pbp(a,b) push_back({a,b})
#define rep(p,a,b)    for(int p=a;p<b;p++)
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
#define INF 0x3f3f3f3f

ll nextPowerOf2(ll n)   
{ 
	n--; 
	n |= n >> 1ll; 
	n |= n >> 2ll; 
	n |= n >> 4ll; 
	n |= n >> 8ll; 
	n |= n >> 16ll; 
	n++; 
	return n; 
}


int main() {
	
	#ifndef ONLINE_JUDGE
	// for getting input from input.txt
	freopen("input.txt", "r", stdin);
	// for writing output to output.txt
	freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	// ll n,t,i,k,sum;
	// //cin>>t;
	// t=1;
	// while(t--)
	// {

	// 	cin>>n>>k;
	// 	vector<int> v(n);
	// 	rep(p,0,n)cin>>v[p];

	// 	sort(v.begin(),v.end());
	// 	sum=0;
	// 	i=0;
	// 	while(k--)sum+=(v[i++]);

	// 	cout<<sum<<"\n";
	// }
	ll n,r;
	string s="";
	cin>>n;
	while(n)
	{
		r = n%26;
		if(r==0){r+=26;n--;}
		s += (char)(r+96);
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout<<s;

	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef vector<int> VI;

int main() {
  int N; cin >> N;
  VI A(N);
  int even_count = 0;
  REP(i, N) {
    cin >> A[i];
    if(A[i] % 2 == 0) { even_count++; }
  }
  int odd_similar_count = even_count > 0 ? pow(2, even_count) : 1;
  cout << pow(3, N) - odd_similar_count << endl;
  return 0;
}


Measured memory_bytes: 512
import math

a, b, h, m = map(int, input().split())

deg_a = (h+m/60)*30
deg_b = m*6
deg = deg_a-deg_b
cos_deg = math.cos(math.radians(deg))
ans = (a**2+b**2-2*a*b*cos_deg)**(1/2)

print(ans)

Measured memory_bytes: 9512
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"
#include "map"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

const ll mod = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  cout << (n + 1) / 2 << "\n";
}


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

int main() {
    int n, m, c;
    cin >> n >> m >> c;

    int a[n][m];
    int b[m];

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        int t = c;
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            t += a[i][j] * b[j];
        }

        if (t > 0) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


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

long long n, k;

int main()
{
    cin >> n >> k;
    cout << k * (long long)(pow(k - 1, n - 1));
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
#define INF 1000000000 // 1 billion, safer than 2B for Floyd Warshall’s
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pcont(x) for(auto i: x){cout << i << " ";} cout << "\n";

int main(){
    IOS;
    int r, c, k;
    cin >> r >> c >> k;

    int blk = 0;
    vector<vector<char>> grid(r, vector<char>(c));
    for(int i = 0; i<r; i++){
        for(int j = 0; j<c; j++){
            cin >> grid[i][j];
            if(grid[i][j] == '#')blk++;
        }
    }

    int ans = 0;

    for(int mskR = 0; mskR < 1<<r; mskR++){
        for(int mskC = 0; mskC < 1<<c; mskC++){
            int black = 0;
            for(int i = 0; i<r; i++){
                for(int j = 0; j<c; j++){
                    if(((mskR >> i) & 1) == 0 && ((mskC >> j) & 1) == 0){
                        if(grid[i][j] == '#')black++;
                    }
                }
            }
            if(black == k)ans++;
        }
    }

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

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

signed main() {
	IOS();
	ll n, a, b;
	string s;
	cin >> n >> a >> b >> s;
	vector<bool> ok(n, false);
	ll cnt = 0, cntb = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == 'a' && cnt < a + b) {
			ok[i] = true;
			cnt++;
		}
		if (s[i] == 'b' && cntb < b && cnt < a + b) {
			ok[i] = true;
			cnt++;
			cntb++;
		}
	}
	for (int i = 0; i < n; i++) {
		dump(ok[i] ? "Yes" : "No");	
	}

	return 0;
}

Measured memory_bytes: 848
fun main(args: Array<String>){
    val n = readLine()!!.toLong()
    val list = mutableListOf<Long>()
    for(i in 1..Math.sqrt(n.toDouble()).toInt()){
        if(n % i == 0L){
            list.add(i.toLong())
            list.add(n / i)
        }
    }

    var min = Long.MAX_VALUE / 10
    list.forEach {
        val a = it
        val b = n / it
        min = Math.min(min, Math.max(a.toString().length, b.toString().length).toLong())
    }

    println(min)
}

Measured memory_bytes: 33660
N = int(input())
xlist = []
ylist = []
pqlist = []
pqcount = {}
for i in range(N):
  x, y = map(int, input().split(" "))
  xlist.append(x)
  ylist.append(y)

for i in range(N):
  for j in range(i+1, N):
    p = xlist[i] - xlist[j]
    q = ylist[i] - ylist[j]
    tuple_pq = (p, q,)
    if (-p, -q,) in pqlist:
      tuple_pq = (-p, -q)
    if not (tuple_pq in pqlist):
      pqlist.append(tuple_pq)
      pqcount[tuple_pq] = 1
    else:
      pqcount[tuple_pq] += 1

if N == 1:
  print(1)
else:
  print(N - max(pqcount.values()))


Measured memory_bytes: 3188
from math import factorial
def comb(n,r):
  return factorial(n)//factorial(n-r)//factorial(r)
N=int(input())
S=[]
for i in range(N):
  s=list(input())
  s.sort()
  S+=[s]
S.sort()  
ans=0
anssub=1
for i in range(N-1):
  if S[i]==S[i+1]:
    anssub+=1
  else:
    if anssub!=1:
      ans+=comb(anssub,2)
    anssub=1
  if i==N-2 and anssub!=1:
    ans+=comb(anssub,2)
print(ans)    

Measured memory_bytes: 25512
#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);
    int n,m; cin>>n>>m;
    if (n&1){
        rep(i,m){
            cout<<i+1<<" "<<n-(i+1)<<"\n";
        }
    }else{
        for(int i=0; i<(m+1)/2; i++){
            cout<<i+1<<" "<<n-i<<"\n";
        }
        for(int i=(m+1)/2; i<m/2+(m+1)/2; i++){
            cout<<i+1<<" "<<n-i-1<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 3652
package main

import (
	"fmt"
	"math"
)

var N int

func main() {
	fmt.Scan(&N)
	S := make([]string, N)
	xxx := make(map[string]int, N)

	for i := 0; i < N; i++ {
		fmt.Scan(&S[i])
	}
	for i := 0; i < N; i++ {
		xxx[S[i]]++
	}
	if len(xxx) == 3 {
		fmt.Println("Three")
	} else {
		fmt.Println("Four")
	}
}

/*  ----------------------------------------  */

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }

// type LR []int

// func (a SortBy) Len() int           { return len(a) }
// func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
// func (a SortBy) Less(i, j int) bool { return a[i] < a[j] }


Measured memory_bytes: 512
#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;
#define Khela ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define llu long long unsigned int
#define pf printf
#define sf scanf
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define pii pair<int ,int>
#define PII pair<ll ,ll>
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
 
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
int Set(int N,int pos){return N=N | (1<<pos);}
int reset(int N,int pos){return N= N & ~(1<<pos);}
bool check(int N,int pos){return (bool)(N & (1<<pos));}
const int max=1e9+100;
const ll  MAX=1e18+500;
const int sz=1e5+100;
const ll mod=1e9+7;
int mark[sz];
ll dp[sz][14];
ll n;
string str;
ll cholo(ll id,ll sum)
{
    if(id>=n){
        if(sum%13==5) return 1;
        else return 0;
    }

    ll &ret=dp[id][sum];
    if(~ret) return ret;
    ll tot=0;
    if(str[id] != '?') ret=cholo(id+1,(sum*10+(str[id]-'0'))%13);
    else{
        for(ll i=0;i<=9;i++) tot=(tot+cholo(id+1,(sum*10+i)%13))%mod;
        ret=tot;
    }

    return ret;
    
    
}
int main()
{
    Khela
    ll a,b,c,i,j,k,q,p,x,y,ct,ct1,m,l,r,x1,y1,mn,h,sum1,in,z,mid,mx;
    char ch;
    double d;
    //string str1;
    bool bl,bl1;
    int t,cs=1;
    while(cin>>str)
    {
        memset(dp,-1,sizeof dp);
        n=str.length();
        ll ans=cholo(0,0);
        cout<<ans<<endl;
      
        
    }





}

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

int N, M;
int K[30];
// int A[30][30];
map<int, int> mp;

int main() {
    cin >> N >> M;
    rep(i, N) {
        cin >> K[i];

        rep(j, K[i]) {
            int tmp;
            cin >> tmp;
            mp[tmp]++;
        }
    }

    int ans = 0;
    for (int i = 1; i <= M; i++) {
        // cout << mp[i] << endl;
        if (N == mp[i]) {
            ans++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256