akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1e17
#define ninf -1e17
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
ll dp[200005][5];
ll a[200005];
ll l;
ll compute(int i, int cur)
{
    if(cur>4) return inf;
    if(i==l+1)
    {
        if(cur==4)
            return 0;
        return inf;
    }
    if(dp[i][cur]!=-1) return dp[i][cur];
    ll ans = inf;
    ll par = a[i+1]%2;
    ll off = 0;
    if(cur==0||cur==4)
        off = a[i+1];
    else if((cur==1&&par)||(cur==2&&!par)||(cur==3&&par))
        off = 1;
    else if((cur==1&&!a[i+1])||(cur==3&&!a[i+1]))
        off = 2;
    ans = MIN2(ans , compute(i, cur+1));
    ans = MIN2(ans, off + compute(i+1, cur));
    return dp[i][cur] = ans;
}
int main()
{
    she_told_me_dont_worry
    memset(dp, -1, sizeof dp);
    cin>>l;
    int i;
    FOR(i, 1, l+1)
    {
        cin>>a[i];
    }
    ll ans = compute(0, 0);
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 19200
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

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

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

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll divc, divd;
    if(a%c == 0) divc = ((b-b%c)-(a-a%c))/c +1;
    else divc = ((b-b%c)-(a-a%c+c))/c +1;
    if(a%d == 0) divd = ((b-b%d)-(a-a%d))/d +1;
    else divd = ((b-b%d)-(a-a%d+d))/d +1;
    ll num = 1, tmp = c;
    // while(c % d != 0){
    //     num++;
    //     c = tmp * num;
    // }
    gcd(c, d);
    c = lcm(c, d);
    ll div;
    //cout << "gcd: " << c << endl;
    if(a%d == 0) div = ((b-b%c)-(a-a%c))/c +1;
    else div = ((b-b%c)-(a-a%c+c))/c +1;
    //cout << "div: " << div << endl;
    cout << (b-a+1) - (divc + divd - div) << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i,a,b) for(int(i)=(a);(i)<(b);++(i))
#define RREP(i,a,b) for(int(i)=(a)-1;(i)>=(b);--(i))
#define ALL(x) (x).begin(),(x).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
using namespace std;
typedef long long ll;

int N,Y;

int main()
{
  cin >> N >> Y;
  bool found = false;
  REP(i,0,N+1) {
    REP(j,0,N+1-i) {
      // 1万i枚・5千j枚
      int k = N-i-j;
      if(10000 * i + 5000 * j + 1000 * k == Y) {
        printf("%d %d %d\n", i, j, k);
        found = true;
        goto endloop;
      }
    }
  }
 endloop:
  if (!found) cout << "-1 -1 -1" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
typedef long long int lli;
const lli mod = 1e9 +7;
const lli inf = 1e18;
typedef pair<lli, lli> pll;

int main(){
	lli n,k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	lli ans = 0;
	for(int i=0; i<n; i++){
		for(int j=0; j<i; j++){
			if(a[j] < a[i]){
				ans += k*(k-1)/2;
				ans %= mod;
			}
		}
		for(int j=i; j<n; j++){
			if(a[j] < a[i]){
				ans += k*(k+1)/2;
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>

using namespace std;

struct point {
    double x, y, c;
};

using vp = vector<point>;

const int M = 50;
const double EPS = 1e-10;

double dis(point a, point b) {
    double dx = a.x - b.x;
    double dy = a.y - b.y;
    return sqrt(dx * dx + dy * dy);
}

vp cyc_intersec(point a, point b) {
    double d = dis(a, b);
    if (d > a.c + b.c + EPS || d < abs(a.c - b.c) - EPS) {
        return {};
    }

    double p = acos(max(-1.0, min(1.0, (a.c * a.c + d * d - b.c * b.c) / (2 * a.c * d))));
    double t = atan2(b.y - a.y, b.x - a.x);

    point p1, p2;
    p1.x = a.x + a.c * cos(t + p);
    p1.y = a.y + a.c * sin(t + p);
    p2.x = a.x + a.c * cos(t - p);
    p2.y = a.y + a.c * sin(t - p);

    return {p1, p2};
}

int calc(point x, const vp &cyc) {
    int r = 0;
    for (point y : cyc) {
        if (dis(x, y) < y.c + EPS) {
            r++;
        }
    }
    return r;
}

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

    int n, k;
    cin >> n >> k;
    vp p(n);
    for (int i = 0; i < n; i++) {
        cin >> p.at(i).x >> p.at(i).y >> p.at(i).c;
    }

    double l = 0, r = 2e5;
    for (int q = 0; q < M; q++) {
        double mid = (l + r) / 2;

        vp cyc(n);
        for (int i = 0; i < n; i++) {
            cyc.at(i).x = p.at(i).x;
            cyc.at(i).y = p.at(i).y;
            cyc.at(i).c = mid / p.at(i).c;
        }

        bool f = false;

        for (point x : p) {
            if (calc(x, cyc) >= k) {
                f = true;
            }
        }

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                vp t = cyc_intersec(cyc.at(i), cyc.at(j));
                for (point x : t) {
                    if (calc(x, cyc) >= k) {
                        f = true;
                    }
                }
            }
        }

        if (f) {
            r = mid;
        } else {
            l = mid;
        }
    }

    cout << fixed << setprecision(7) << r << endl;

    return 0;
}


Measured memory_bytes: 4468
#include <iostream>
using namespace std;
int main(){
	int width, height, r, x, y;
	cin >> width >> height >> x >> y >> r;
	if ((x - r >= 0) && (x + r <= width )&& (y - r >= 0) && (y + r <= height))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String card;
		String tmp1,tmp2;
		int n;
		int num;
		while(true) {
			card = sc.next();
			if(card.equals("-")) break;
			n = sc.nextInt();

			for(int i=0;i < n;i++) {
				num = sc.nextInt();
				tmp1 = card.substring(0, num);
				tmp2 = card.substring(num,card.length());
				card = tmp2+tmp1;
			}

			System.out.println(card);
		}

		sc.close();

	}

}


Measured memory_bytes: 26436
n, k = map(int,input().split())
a = list(map(int,input().split()))

s = 1
seen = [False for _ in range(n+1)]
d = []
while not seen[s]:
    seen[s] = True
    d.append(s)
    s = a[s-1]

noncyi = d.index(s)
cyi = len(d) - noncyi
if k < noncyi:
    print(d[k])
else:
    k -= noncyi
    print(d[noncyi + k%cyi])

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

int main(void){
    int deg;
    double a,b,rad;
    double menseki,syuui,takasa,katei;
    double PI = acos(-1); 

    scanf("%lf%lf%d",&a,&b,&deg);

    rad = deg*PI /180;

    menseki=0.5*a*b*sin(rad);
    katei=pow(a,2)+pow(b,2)-2*a*b*cos(rad);
    syuui=a+b+pow(katei,0.5);
    takasa=b*sin(rad);
    printf("%lf\n",menseki);
    printf("%lf\n",syuui);
    printf("%lf\n",takasa);
    return 0;
}


Measured memory_bytes: 2072
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define INF LONG_LONG_MAX
#define pb push_back
#define mp make_pair
#define MAXN 1000009
#define MOD 1000000007
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define left(x) x<<1
#define right(x) (x<<1)|1
#define PI acos(-1.0)
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef map<string,ll> msi;
typedef set<ll> si;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> 
ordered_set;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> 
ordered_multiset;

ll solve(){
    string s;
    int n;
    cin>>s>>n;
    for(int i=0;i<s.size();i+=n)
        cout<<s[i];
    return 0;
}

int main(){
    
    int T=1;
    //scanf("%d",&T);
    for(int i=1;i<=T;++i){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l=1;r=max(h)//b+1
while l!=r:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=((a-b-1)+max(0,h[i]-b*x))//(a-b)
  if ct>x:
    l=x+1
  else:
    r=x
print(l)

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

//RRLLLLRLRRLL 0 0 3 2 0 2 1 0 0 0 4 4 0 0 0 0



int h[100005][2] = { 0 };

int main(){
	int n=1;

	char c;
	while (cin>>c) {

		if (c == 'R')h[n][0] = 1;
		if (c == 'L')h[n][0]= -1;
		n++;
	}
  n--;
	int pe = 0;
	for (int i = 1; i <= n; i++) {
		if(h[i][0]==1)pe++;

		if (h[i][0]== -1&&h[i-1][0]==1) {
			h[i][1] += (pe/2);
			h[i - 1][1] += (pe - pe / 2);
			pe = 0;
		}
	}
	pe = 0;
	for (int i = n; i > 0; i--) {
		if (h[i][0] == -1)pe++;

		if (h[i][0] == 1 && h[i + 1][0] == -1) {
			h[i][1] += (pe / 2);
			h[i+1][1] += (pe - pe / 2);
			pe = 0;
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << h[i][1] <<" " ;
	}
cout<<endl;
}


Measured memory_bytes: 1280
from collections import deque

d = deque(list(input()))
flag = 1
for _ in range(int(input())):
    a = input()
    if a[0] == '1':
        flag *= -1
    elif a[2] == '1' and flag == 1:
        d.appendleft(a[4])
    elif a[2] == '1' and flag == -1:
        d.append(a[4])
    elif a[2] == '2' and flag == 1:
        d.append(a[4])
    else:
        d.appendleft(a[4])
if flag == -1:
    d.reverse()
print(*d, sep='')


Measured memory_bytes: 12256
#include <cstdio>
#include <algorithm>

int main()
{
  long long a[100000];
  long long b[100000];
  long long c[100000];
  long long n;
  scanf("%lld", &n);
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", a + i);
  }
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", b + i);
  }
  for (long long i = 0; i < n; ++i)
  {
    scanf("%lld", c + i);
  }
  
  std::sort(a, a + n);
  std::sort(b, b + n);
  std::sort(c, c + n);

  long long btoc[100001];
  btoc[n] = 0;
  for (long long i = n - 1; i >= 0; --i)
  {
    btoc[i] = btoc[i + 1] + (c + n) - std::upper_bound(c, c + n, b[i]);
  }
  long long ans = 0;
  for (long long i = 0; i < n; ++i)
  {
    long long *p = std::upper_bound(b, b + n, a[i]);
    ans += btoc[p - b];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 3328
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int []A = new int[N];
        int sum = 0;
//        Arrays.sort(A);
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        for( int i = 0; i < K; i++){
            sum += A[i];
        }
        System.out.println(sum);
    }

}


Measured memory_bytes: 38716
import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val sn = Iterator.continually(in.readLine).take(n).toArray

  val tar = "AB"
  var sum1 = sn.map(_.sliding(2).count(_ == tar)).sum

  val b_ = sn.count(s => s.head == 'B' && s.last != 'A')
  val _a = sn.count(s => s.head != 'B' && s.last == 'A')
  val ba = sn.count(s => s.head == 'B' && s.last == 'A')

  val sum2 = ba match {
    case x if x == 0 => _a min b_
    case x if _a + b_ == 0 => ba - 1
    case _ => ba + (_a min b_)
  }
  // debug(sum1, ba, b_, _a)

  val ans = sum1 + sum2
  println(ans)

  def debug(any:Any*):Unit = {
    if(this.getClass.toString != "class Main$")
      println(any.mkString(" "))
  }
}

Measured memory_bytes: 52104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
// Welcome to my source code!

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    map<string, int> mp;
    for (int i = 0; i <= n - m; i++) {
        string c = s.substr(i, m);
        bool flag = true;
        for (int j = 0; j < m; j++) {
            if (c[j] != '?' && c[j] != t[j]) flag = false;
        }
        if (flag) {
            string tmp = s;
            for (int j = i; j < i + m; j++) {
                if (tmp[j] == '?') tmp[j] = t[j - i];
            }
            for (int j = 0; j < n; j++) {
                if (tmp[j] == '?') tmp[j] = 'a';
            }
            mp[tmp]++;
        }
    }
    for (auto x : mp) {
        cout << x.first << endl;
        return 0;
    }
    cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
  
int main()
{
  ll N, M;
  cin >> N >> M;

  if(N!=1&&M!=1){
    cout << (N-2)*(M-2) << endl;
  }else if(N==1&&M!=1){
    cout << M-2 << endl;
  }else if(M==1&&N!=1){
    cout << N-2 << endl;
  }else{
    cout << 1 << endl;
  }
}

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

int main() {
  int n,t,s;
  cin >> n >> t;
  s = 0;
  vector<int> a(n),b(n-1);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  for(int i=0;i<n-1;i++){
    b.at(i) = a.at(i+1) - a.at(i);
    if(b.at(i) < t){
      s += t-b.at(i);
    }
  }
  
  int ans = t*n - s;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
void main() {
	auto ip = readAs!(int[]), a = ip[0], b = ip[1], c = ip[2];
	auto div = getDivisors(c).assumeSorted;
	auto u = div.lowerBound(b+1);
	auto l = div.lowerBound(a);
	debug u.writeln;
	debug l.writeln;
	debug div.writeln;
	writeln(u.length - l.length);
}

ulong[] getDivisors(ulong N) {
	if(N == 0) return [];
	if(N == 1) return [1];
	ulong[] lower_part, upper_part;
	foreach(i; 1..N.to!real.sqrt.ceil.to!ulong) {
		if(N % i == 0) {
			lower_part ~= i;
			upper_part ~= N / i;
		}
	}
	upper_part.reverse();
	if(N.to!real.sqrt.to!ulong ^^ 2 == N) return lower_part ~ N.to!real.sqrt.to!ulong ~ upper_part;
	else return lower_part ~ upper_part;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 2532
#coding:utf-8
N=input()
A=map(int,raw_input().split())
A.sort()
n=A[-1]
med=n/2
p=0
mi=1145141919810
for i,a in enumerate(A):
    b=min(a,n-a)
    if abs(b-med) < mi:
        p=i; mi=abs(b-med)
print("%d %d"%(n,A[p]))


Measured memory_bytes: 11308
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <cstdlib>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
#include <cassert>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int main(){
    iostream::sync_with_stdio(false);
    
    int N,K;
    cin >> N >> K;
    LL a[1000];
    LL wa[1000];
    for(int i=0; i<N; i++){
        cin >> a[i];
        if(i == 0) wa[i] = a[i];
        else wa[i] = wa[i-1] + a[i];
    }
    vector<LL> all;
    for(int i=0; i<N; i++){
        for(int j=i; j<N; j++){
            if(i==0) all.push_back(wa[j]);
            else all.push_back(wa[j] - wa[i-1]);
        }
    }
    
    vector<LL> tmp;
    LL one = 1;
    for(LL i=(one<<54); i>=0; i=(i>>1)){
        //cout << i << " " << all.size() << endl;
        for(int j=0; j<all.size(); j++){
            if((all[j] & i) > 0) tmp.push_back(all[j]);
        }
        if(tmp.size() < K) tmp.clear();
        else{
            all = tmp;
            tmp.clear();
        }
        if(i == 0) break;
    }

    LL ans = all[0];
    for(int i=1; i<all.size(); i++){
        ans = ans & all[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6384
def main():
	while True:
		a = []
		n, k = [int(x) for x in input().split()]
		if n == 0 and k == 0: break
		for i in range(n): a.append(int(input()))
		l = [0]
		for i in range(1, n - k + 1): l.append(a[i + k - 1] - a[i - 1])
		maxsum = 0
		maxi = 0
		s = 0
		for i, x in enumerate(l):
			s += x
			if s >= maxsum:
				maxsum = s
				maxi = i
		print(sum(a[maxi:maxi + k]))
main()

Measured memory_bytes: 13972
import java.util.*;

class Main {
	public static void main (String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();   //行定義
        int m = sc.nextInt();   //列定義

        int[][] A = new int[n][m];  //行列A定義
        int[] b = new int[m];  //行列b定義

        /* 行列Aの値代入 */
        for(int i = 0;i < n;i++){
            for(int j = 0;j < m;j++){
                A[i][j] = sc.nextInt();
            }
        }

        /* 行列bの値代入 */
        for(int i = 0;i < m;i++){
            b[i] = sc.nextInt();
        }

        /* 演算処理 */
        int sum;    //計算結果
        for(int i = 0;i < n;i++){
            sum = 0;
            for(int j = 0;j < m;j++){
                sum += A[i][j] * b[j];
            }
            System.out.println(sum);
        }
    }
}



Measured memory_bytes: 40104
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll; const ll MM = 1000000000;ll mod = MM + 7;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;


bool IsPrime(ll num){
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  double sqrtNum = sqrt(num);
  for (ll i = 3; i <= sqrtNum; i += 2){
    if(num % i == 0) return false;
  }
  return true;
}

bool g[1000000010];

int main() {
  ll n; cin >> n;
  rep(i, n) {
    ll a; cin >> a;
    if(g[a] == 1) {
      cout << "NO" << endl;
      return 0;
    }
    g[a] = 1;
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 975360
#include<stdio.h>
#include<math.h>
int main(void)
{
    double x,h,t,ans;
    while(1){
        scanf("%lf%lf",&x,&h);
        if(x==0&&h==0) break;
        t=sqrt((x/2)*(x/2)+(h*h));
        ans=x*x+x*t*2;
        printf("%lf\n",ans);
    }
    return 0;
}

Measured memory_bytes: 644
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

class Main {
    public static void main(String[] args) {
        try {
        	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        	int verticalLineNum = Integer.parseInt(br.readLine());
        	int horizontalLineNum = Integer.parseInt(br.readLine());

        	List<Integer> numberList = new ArrayList<>();

        	for(int i = 1; i <= verticalLineNum; i++) {
        		numberList.add(i);
        	}

        	for(int j = 0; j < horizontalLineNum; j++) {
        		String line = br.readLine();
                String[] dataSet = line.split(",");

                numberList = swap(numberList, Integer.parseInt(dataSet[0]), Integer.parseInt(dataSet[1]));
        	}


        	for(int k = 0; k < verticalLineNum; k++) {
        		System.out.println(numberList.get(k));
        	}

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

	private static List<Integer> swap(List<Integer> numberList, int a, int b) {
		int temp = numberList.get(a-1);
		numberList.set(a-1, numberList.get(b-1));
		numberList.set(b-1, temp);
        return numberList;
	}

}

Measured memory_bytes: 24052
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K,sum=0,a;
  cin >> N>>K;
  a=N;
  for(int i=N;i< K+1;i++){
    
    if(a/10000 == a%10 && a%10000/1000 == a%100/10){
      sum++;
    }
    a++;
  }
  cout << sum << endl;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int num  = sc.nextInt();
        int arr[] = new int[num];
        for(int i = 0; i < num; i++){
            arr[i] = sc.nextInt();
        }
        for(int i = 0; i < num; i++){
            int changeArr[] = new int[i + 1];
            for(int j = 0; j <= i; j++){
                changeArr[j] = arr[j];
            }
            Arrays.sort(changeArr);
            for(int k = 0; k <= i; k++){
                arr[k] = changeArr[k];
            }
            for(int l = 0; l < num; l++){
                System.out.print(arr[l]);
                if(l != num - 1){
                    System.out.print(" ");
                }
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 34696
#include <iostream>
using namespace std;
int main(void){
    long long int n,a[1000],color[10]={},min=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]>=3200){color[8]++;}
        else if(a[i]>=2800){color[7]++;}
        else if(a[i]>=2400){color[6]++;}
        else if(a[i]>=2000){color[5]++;}
        else if(a[i]>=1600){color[4]++;}
        else if(a[i]>=1200){color[3]++;}
        else if(a[i]>=800){color[2]++;}
        else if(a[i]>=400){color[1]++;}
        else if(a[i]>=0){color[0]++;}
    }
    
     for(int i=0;i<8;i++){
       if(color[i]>0){min++;}
    }
    if(min==0){cout<<1<<" "<<color[8];return 0;}
    
    cout<<min<<" "<<min+color[8];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

using ll = long long;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

constexpr int INF = 1e9+5;
constexpr long long INFLL = 1LL<<60;
constexpr double eps = (1e-9);

constexpr ll mod = 1000000007;

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

  int n;
  cin >> n;

  map<int, int> mp;

  bool flag = true;

  rep(i, n) {
    int a; cin >> a;
    if ((n % 2 == 0 && a % 2 == 0) || (n % 2 != 0 && a % 2 != 0)) {
      cout << 0 << endl;
      return 0;
    }
    mp[a]++;
    if (mp[a] > 2) flag = false;
  }

  if (!flag || (n % 2 != 0 && mp[0] != 1)) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 1;
  for (int i = 1; i <= n; i++) {
    if (((n % 2 == 0 && i % 2 != 0) || (n % 2 != 0 && i % 2 == 0))) {
      if (mp[i] == 2) {
        ans *= 2;
        ans %= mod;
      } else {
        cout << 0 << endl;
        return 0;
      }
    } else if (mp[i] != 0) {
      cout << 0 << endl;
      return 0;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4992
a, b, c, d = gets.split.map(&:to_i)

taka = true
while a > 0 && c > 0
  if taka
    c -= b
  else
    a -= d
  end
  taka = !taka
end 

if a > 0
  puts 'Yes'
else
  puts 'No'
end

Measured memory_bytes: 14268
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()

int main () {
    int k;
    string s;
    cin >> k >> s;
    if (s.size() <= k) {
        cout << s << endl;
        return 0;
    }
    string t = s.substr(0, k);
    t += "...";
    cout << t << endl;

    return 0;
}

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

int main() {
	int A, B;
	cin >> A >> B;
	string winner = "Alice";
	if (A != B) {
		if (B == 1 || (B > A && A != 1)) {
			winner = "Bob";
		}
		cout << winner << endl;
		return 0;
	}
	cout << "Draw" << endl;
	return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

int A[3];
int B[3];

int in[4];
int main(){

    for(int i = 0; i < 3; i++){
        cin >> A[i] >> B[i];
        A[i]--; B[i]--;
        in[A[i]]++;
        in[B[i]]++;
    }

    int odd = 0;
    int even = 0;
    for(int i = 0; i < 4; i++){
        if(in[i] % 2 == 0) even++;
        else odd++;
    }
    if(odd == 2){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array([0] + list(map(int, input().split())))
B = np.cumsum(A)
B.sort()
cnt = 1
out = 0
for k in range(N):
  if B[k] == B[k+1]:
    cnt += 1
    if k == N-1:
      out += (cnt * (cnt - 1)) // 2
  else:
    out += (cnt * (cnt - 1)) // 2
    cnt = 1
print(out)

Measured memory_bytes: 34560
using System;


class moji
{
    static void Main()
    {

        string[] ss = Console.ReadLine().Split(' ');
        int a = int.Parse(ss[0]);
        string b = Console.ReadLine();
        if (a % 2 != 0)
            Console.WriteLine("No");
        else if (b == b.Substring(0, a / 2) + b.Substring(0, a / 2))
            Console.WriteLine("Yes");
        else
            Console.WriteLine("No");


    }
}



Measured memory_bytes: 11092
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, now = 0;
  scanf("%lld%lld", &n, &k);
  ll f[n], a[n];
  for(i = 0; i < n; ++i) scanf("%lld", &a[i]), a[i]--, f[i] = -1;
  f[0] = 0;
  while( 1 ) {
    if(f[a[now]] != -1) break;
    f[a[now]] = f[now] + 1;
    now = a[now];
  }
  if(f[a[now]] > k) {
    now = 0;
    for(i = 0; i < k; ++i) now = a[now];
  } else {
    k -= f[a[now]];
    k %= f[now] - f[a[now]] + 1;
    now = a[now];
    for(i = 0; i < k; ++i) now = a[now];
  }
  printf("%lld", now + 1);
  return 0;
}

Measured memory_bytes: 4856
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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







#include <algorithm>
#include <vector>


class UnionFind{
    int n;
    std::vector<int> par;//根ならマイナス*要素数

public:
    UnionFind(): n(0){}
    UnionFind(int N): n(N), par(n){
        for(int i(0); i < n; ++i){
            par[i] = -1;
        }
    }

    void resize(int N){
        n = N;
        par.resize(n, -1);
    }

    int find(int x){
        if(par[x] < 0) return x;
        else return par[x] = find(par[x]);
    }

    bool unit(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;

        if(-par[x] < -par[y]) std::swap(x, y); 
        par[x] += par[y];
        par[y] = x;
        return true;
    }

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

    int howmany(int x){ //同じグループに属すものの個数(自分を含む)
        return -par[find(x)];
    }

    std::vector<std::vector<int>> groups(){
        std::vector<int> rtbuf(n), gsz(n);
        for(int i(0); i < n; ++i){
            rtbuf[i] = find(i);
            ++gsz[rtbuf[i]];
        }
        std::vector<std::vector<int>> ret(n);
        for(int i(0); i < n; ++i){
            ret[i].reserve(gsz[i]);
        }
        for(int i(0); i < n; ++i){
            ret[rtbuf[i]].push_back(i);
        }
        ret.erase(
            std::remove_if(std::begin(ret), std::end(ret),
                [&](const std::vector<int>& v) { return v.empty(); }),
            std::end(ret));
        return ret;
    }
};


int main(){
    int N, Q; std::cin >> N >> Q;
    UnionFind d(N);
    std::vector<std::vector<int>> ls;
    {
        int t, u, v;
        for(int i(0); i < Q; ++i){
            std::cin >> t >> u >> v;
            if(t){
                std::cout << d.same(u, v) << "\n";
            }else d.unit(u, v);
        }
    }
    return 0;
}


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

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

int main(){
  int n;
  cin >> n;
  if (n <= 999){
    cout << "ABC\n";
  }
  else{
    cout << "ABD\n";
  }
  return 0;
}

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

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)
#define leng(n) (int)(log10(n)+1)


typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

Vi yakusuu(int n){
    Vi ret;
    for(int i=1 ; i*i<=n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i!=n) ret.push_back(n/i);
        }
    }
    sort(ALL(ret));
    return ret;
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(12);
    string s;
    cin>>s;
    int n=s.size();
    VVi dp(n+1,Vi(2));
    dp[0][0]=1;

    REP(i,0,n){
        int D=s[i]-'0';
        REP(j,0,2){
            if(j==1){
                dp[i+1][j] = (dp[i+1][j]+3*dp[i][j])%MOD;
            }else{
                if(D==0) dp[i+1][j] = (dp[i+1][j]+dp[i][j])%MOD;
                else{
                    dp[i+1][1] = (dp[i+1][1]+dp[i][j])%MOD;
                    dp[i+1][0] = (dp[i+1][0]+2*dp[i][j])%MOD;
                }
            }
        }
    }
//    vvout(dp);
    cout<<(dp[n][1]+dp[n][0])%MOD<<endl;
    return 0;
}


Measured memory_bytes: 5840
#include<stdio.h>
int main(){
    int H,W,i,j;
    while(1){
        scanf("%d %d",&H,&W);
        if(H==0 && W==0){
            break;
        }
    for (j=1; j<=H; j++) {
    for(i=1; i<=W; i++) {
    if(j == 1 || j == H) {
	  printf("#");
	}else if(j!=1&&j!=H&&i==1||i==W){
	  printf("#");
	}else{
	  printf(".");
	}
      }

    printf("\n");
    }
    printf("\n");
    }
    return 0;
}


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

int main() {
  string S;
  cin >> S;
  bool s = 0, n = 0, w = 0, e = 0;
  for(int i = 0; i < S.size(); i++) {
    if(S[i] == 'S') {
      s = 1;
    }
    if(S[i] == 'E') {
      e = 1;
    }
    if(S[i] == 'W') {
      w = 1;
    }
    if(S[i] == 'N') {
      n = 1;
    }
  }
  bool f = 1;
  if(s == 0) {
    if(n) f = 0;
  }
  if(n == 0) {
    if(s) f = 0;
  }
  if(w == 0) {
    if(e) f = 0;
  }
  if(e == 0) {
    if(w) f = 0;
  }
  if(f) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys
h,w=map(int,input().split())
s_list=[]
for i in range(h):
    s_list.append(input())
op=[(1,0),(0,1),(-1,0),(0,-1)]
for i in range(h):
    for j in range(w):
        if s_list[i][j]=='#':
            count=1
            for k in op:
                if 0<=i+k[0]<=h-1 and 0<=j+k[1]<=w-1:
                    if s_list[i+k[0]][j+k[1]]=='#':
                        count=0
                    else:
                        pass
            if count==1:
                print('No')
                sys.exit()
print('Yes')
                


Measured memory_bytes: 39536
#include<bits/stdc++.h>
using namespace std;
int n,A[50];
int solve(int i,int m){
	//cout<<i<<" "<<m<<" "<<A[i]<<endl;
	if(m == 0)return 1;
	if(i>=n || m < 0) return 0;

	int res = solve(i+1,m) || solve(i+1,m-A[i]);
	return res;
}
int main(){
	int q,m,i;
	cin>>n;
	for(int i = 0;i<n;i++){
		cin>>A[i];
	}
	cin>>q;
	for(int i = 0;i<q;i++){
		cin>>m;
		if(solve(0,m)){
			cout<<"yes"<<endl;
		}
		else{
			cout<<"no"<<endl;
	    }
	}
	return 0;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

using value = int;
const value id = 0;
value marge(value a, value b) { return std::max(a, b); }

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n - 1), b(n - 1), c(n);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d%d", &a[i], &b[i], &c[i]);

		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
	}

	std::vector<std::map<int, value>> dp(n);
	auto solve = [&](auto&& solve, int v, int par, bool flag) -> value {
		if(dp[v].count(par)) return dp[v][par];

		value res = id;
		if(par == -1 or flag) {
			std::vector<value> ret;
			for(int i = 0; i < g[v].size(); i++) {
				int id = g[v][i];
				int to = a[id] ^ b[id] ^ v;
				if(to == par) continue;
				
				ret.push_back(solve(solve, to, v, flag) + c[id]);
			}
			
			std::vector<value> R(ret.size() + 1, id);
			for(int i = (int)R.size() - 1; i > 0; i--) R[i - 1] = marge(R[i], ret[i - 1]);
			if(par == -1) {
				value L = id;
				for(int i = 0; i < g[v].size(); i++) {
					int id = g[v][i];
					int to = a[id] ^ b[id] ^ v;
					
					dp[v][to] = marge(L, R[i + 1]);
					L = marge(L, ret[i]);
				}
			}

			res = R[0];
		} else {
			solve(solve, v, -1, flag);

			res = solve(solve, v, par, flag);
		}

		return dp[v][par] = res;
	};
	solve(solve, 0, -1, true);

	int ans = 0;
	for(int i = 0; i < n; i++) ans = marge(ans, solve(solve, i, -1, false));
	printf("%d\n", ans);
	return 0;
}



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

int main()
{
  int n;
  while (cin >> n, n)
  {
    vector<double> a(n);
    for (auto &e : a)
      cin >> e;

    double m = accumulate(a.begin(), a.end(), 0.0) / n;
    double sum = 0;
    for (auto &e : a)
      sum += pow(e - m, 2);
    sum /= n;
    cout << sqrt(sum) << endl;
  }

  return 0;
}



Measured memory_bytes: 3216
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	string S,y,m,d,ans = "Heisei";
	cin>>S;
	//y = S.substr(0,4);
	//m = S.substr(5,2);
	//d = S.substr(8,2);
	//if(y<="2019"&&m<="04"&&d<=30)
	if(S>"2019/04/30")ans ="TBD";
	cout<<ans<<endl;
}

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

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var seek = spr(RL()).Select(x => c2i(x));
            var hide = spr(RL()).Select(x => c2i(x));
            var left = c2i(RL());
            var posseek = seek.First();
            var moveseek = seek.Last();
            var poshide = hide.First();
            var movehide = hide.Last();

            var ret = movehide < moveseek;

            if (ret)
            {
                ret = Math.Abs(poshide - posseek) <= (moveseek - movehide) * left;
            }


            Console.WriteLine(bool2ret(ret));
            Console.ReadLine();

        }

        static string RL() { return Console.ReadLine().Trim(); }
        static IEnumerable<string> spr(string s) { return s.Split(' '); }
        static Int64 c2i(string c) { return Int64.Parse(c); }
        //static double c2d(string c) { return double.Parse(c); }
        static string bool2ret(bool b) { return b ? "YES" : "NO"; }
    }
}

Measured memory_bytes: 28256
import sys
from functools import reduce
from operator import mul
import math

def nCr(n, r):
    r = min(r, n-r)
    upper = reduce(mul, range(n, n-r, -1), 1)
    lower = reduce(mul, range(r, 0, -1), 1)
    return upper // lower


def oddCaseK(n, k):
    cand = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand += 1
    
    number_of_possibles = 0
    if cand >= 1:
        number_of_possibles += cand
    if cand >= 2:
        number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
    if cand >= 3:
        number_of_possibles += nCr(cand, 3) * math.factorial(3)
    
    return number_of_possibles



def evenCaseK(n, k):
    cand1 = 0
    cand2 = 0
    for x in range(1, n+1):
        if x % k == 0:
            cand1 += 1
        elif x % k == k // 2:
            cand2 += 1
    
    number_of_possibles = 0
    for cand in [cand1, cand2]:
        if cand >= 1:
            number_of_possibles += cand
        if cand >= 2:
            number_of_possibles += nCr(cand, 2) * nCr(2, 1) * 3
        if cand >= 3:
            number_of_possibles += nCr(cand, 3) * math.factorial(3)

    return number_of_possibles


def main():
    n, k = [int(x) for x in sys.stdin.readline().split()]
    if k % 2 == 0:
        ans = evenCaseK(n, k)
    else:
        ans = oddCaseK(n, k)
    
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<vector<int> > testimony(N, vector<int>(N, -1));
    for(int n=0; n<N; n++) {
        int A;
        cin >> A;
        for(int a=0; a<A; a++) {
            int x, y;
            cin >> x >> y;
            testimony[n][x-1] = y;
        }
    }
    
    int maxc=0;
    for(int bit=0; bit<(1<<N); bit++) {
        int counter=0;
        bool flag=true;
        for(int i=0; i<N; i++) {
            if(bit & (1<<i)) {
                counter++;
                for(int n=0; n<N; n++) {
                    if(testimony[i][n]==-1) {
                        continue;
                    }
                    if(bit & (1<<n)) {
                        if(testimony[i][n]!=1) {
                            flag = false;
                            break;
                        }
                    } else {
                        if(testimony[i][n]!=0) {
                            flag = false;
                            break;
                        }
                    }
                }
            }
            if(!flag) break;
        }
        
        if(flag) maxc = max(maxc, counter);
    }
    
    cout << maxc << endl;

    return 0;
    
}

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

using namespace std;

typedef long long int ll;

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

  ll h, w, d;
  cin >> h >> w >> d;
  ll a[h + 1][w + 1];
  vector < pair < ll, ll > > pos(h * w + 1);
  vector < ll > cst(h * w + 1, 0);
  for(int i = 1; i <= h; i++){
    for(int j = 1; j <= w; j++){
      cin >> a[i][j];
      pos[a[i][j]] = {i, j};
    }
  }

  for(int i = d + 1; i <= h * w; i++){
    cst[i] = cst[i - d] + abs(pos[i].first - pos[i - d].first) + abs(pos[i].second - pos[i - d].second);
  }

  ll q;
  cin >> q;
  while(q--){
    ll l, r;
    cin >> l >> r;
    cout << cst[r] - cst[l] << '\n';
  }
}


Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#include "string"

int32_t main(){
	boost;
	int n;
	cin>>n;
	map<string,int>mp;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
	}	
	cout<<"AC x"<<" "<<mp["AC"]<<endl;
	cout<<"WA x"<<" "<<mp["WA"]<<endl;
	cout<<"TLE x"<<" "<<mp["TLE"]<<endl;
	cout<<"RE x"<<" "<<mp["RE"]<<endl;	
}



Measured memory_bytes: 3668
#include<iostream>
using namespace std;
void output(int n,int a[]){
	for(int i=0;i<n;i++){
		if(i==n-1)
		printf("%d\n",a[i]);
		else
		printf("%d ",a[i]);
	}
}
void insertion_sort(int n,int a[]){
	int v,j;
	output(n,a);
	for(int i=1;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;
		}
		
		output(n,a);}
}

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



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


template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for(int i=0; i<(int)n; i++)
#define ll long long
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define COUT(x) cout << x << endl;
#define PB(x) push_back(x)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF = 1e9;
const int MOD = 1e9+7;

int main(){
    int n; cin >> n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> b[i];
    rep(i,n) cin >> c[i];
    sort(all(a)); sort(all(b)); sort(all(c));
    ll ans=0;
    

    rep(i,n){
        auto itr1=lower_bound(all(a),b[i]);
        auto itr2=upper_bound(all(c),b[i]);

        ll up=itr1-a.begin();
        ll down=c.end()-itr2;
        ans+=up*down;
    }

    COUT(ans);
}

Measured memory_bytes: 1408
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
    ($line:expr,$name:ident,$t:tt) => {
        let $name=value!($line,$t);
    };
    }

    macro_rules! values_def {
    ($lines:expr,$n:expr,$name:ident,$t:tt) => {
        let $name={
        let mut vec=Vec::new();
        for i in 0..$n{
            let mut next=$lines.next().unwrap().split_whitespace();
            vec.push(value!(next,$t));
        }
        vec
        };
    };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize a:usize)(list:[usize]));
    let mut v1 = Vec::with_capacity(50);
    v1.resize(51 * 51, None);

    let mut v2 = Vec::with_capacity(50);
    v2.resize(51, v1);

    let mut v3 = Vec::with_capacity(50);
    v3.resize(51, v2);

    rec(&mut v3, &list, a, 0, 0, 0).to_string()
}

fn rec(
    dp: &mut Vec<Vec<Vec<Option<usize>>>>,
    list: &Vec<usize>,
    a: usize,
    i: usize,
    count: usize,
    sum: usize,
) -> usize {
    if let Some(res) = dp[i][count][sum] {
        return res;
    }

    let res = if list.len() == i {
        if count != 0 && a * count == sum {
            1
        } else {
            0
        }
    } else {
        //選ぶ
        rec(dp, list, a, i + 1, count + 1, sum + list[i]) + rec(dp, list, a, i + 1, count, sum)
    };

    dp[i][count][sum] = Some(res);

    res
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "4 8\n7 9 8 9" => "5",
    test2: "3 8\n6 6 9" => "0",
    test3: "8 5\n3 6 2 8 7 6 5 9" => "19",
    test4: "33 3\n3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3" => "8589934591",
}


Measured memory_bytes: 143612