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

int main() {
  int N, D;
  cin >> N >> D;
  vector<vector<int>>X(N, vector<int>(D));
  for(int i=0; i<N; i++){
    for(int j=0; j<D; j++){
      cin >> X.at(i).at(j);
    }
  }
  
  int count =0;
  for(int i=0; i<N; i++){
    for(int j=i+1; j<N; j++){
      int kyori=0;
      for(int k=0; k<D; k++){
        kyori += (X.at(i).at(k)-X.at(j).at(k))*(X.at(i).at(k)-X.at(j).at(k));
      }
      int r=sqrt(kyori);
      if(r*r==kyori)count++;
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3652
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	a := nextInt()
	s := next()
	if a >= 3200 {
		fmt.Fprintln(out, s)
	} else {
		fmt.Fprintln(out, "red")
	}
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

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

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
  {int X, N; cin >> X >> N;
  vector<int> ps(N); for (auto &p : ps) cin >> p;
  if (find(begin(ps), end(ps), X) == ps.end()) {cout << X << endl; return 0;}
  ps.push_back(X); ps.push_back(-100); ps.push_back(200); sort(begin(ps), end(ps));
  auto l = find(begin(ps), end(ps), X);
  auto r = find(ps.rbegin(), ps.rend(), X);
  int a = X - 1, b = X + 1;
  for (--l, --r;; --l, --r, --a, ++b)
    {if (*l != a) {cout << a << endl; return 0;}
    if (*r != b) {cout << b << endl; return 0;}}}

Measured memory_bytes: 3604
#include <stdio.h>
 
int main(void){
  char st[3]={};
  scanf("%s",&st);
  if(st[0]=='M')
    printf("6");
  if(st[0]=='T'){
    if(st[1]=='U')
    printf("5");
    else
      printf("3");
  }
  if(st[0]=='W')
    printf("4");
  if(st[0]=='F')
    printf("2");
  if(st[0]=='S'){
    if(st[1]=='A')
      printf("1");
    else
      printf("7");
  }
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
string alphabet = "abcdefghijklmnopqrstuvwxyz";
string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(){
  int a , b , c;
  cin >> a >> b >> c;
  if(a == b)cout << c << endl;
  else if(a == c)cout << b << endl;
  else cout << a << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;

int mod_pow(int x,int y,int m=mod){
	int res=1;
	while(y>0){
		if(y&1)res=res*x%m;
		y>>=1;x=x*x%m;
	}
	return res;
}
int perm[1000001],inv[1000001];
void init_perm(){
	perm[0]=1;
	REP(i,1000001)perm[i]=perm[i-1]*i%mod;
	inv[1000000]=mod_pow(perm[1000000],mod-2);
	for(int i=999999;i>=0;i--){
		inv[i]=inv[i+1]*(i+1)%mod;
	}
}
int nCk(int x,int y){
	if(x<y)return 0;
	return perm[x]*inv[x-y]%mod*inv[y]%mod;
}

signed main(){
	init_perm();
	int N,K;
	cin>>N>>K;
	int ans=0;
	rep(i,min(N+1,K+1)){
		ans+=nCk(N-1,N-i-1)*nCk(N,i)%mod;
		ans%=mod;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 15872
import bisect
a, b, q = map(int, input().split())
inf = float('inf')
S = [- inf] + [int(input()) for i in range(a)] + [inf]
T = [- inf] + [int(input()) for i in range(b)] + [inf]

for i in range(q):
    x = int(input())
    s_idx = bisect.bisect_left(S, x)
    s1, s2 = S[s_idx - 1], S[s_idx]
    
    t_idx = bisect.bisect_left(T, x)
    t1, t2 = T[t_idx - 1], T[t_idx]
    
    ans = inf
    for i in s1, s2:
        for j in t1, t2:
            ans = min(ans, abs(x - i) + abs(i - j))
            ans = min(ans, abs(x - j) + abs(i - j))
                
    print(ans)

Measured memory_bytes: 13860
#include <bits/stdc++.h>
#define endl '\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define cont continue
#define rep(i, n) for(int i = 0 ; i < (n) ; i++)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 987654321;

int T;
map<ll, ll> m;
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int x, y;
  cin >> x >> y;
  bool flag = true;
  if(y % 2 == 1) {
    flag = false;
  }
  if(x * 4 < y || x * 2 > y) {
    flag = false;
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i * 2 < n; ++i) {
    ++ans;
  }
  cout << ans << endl;
}

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

int main() {

  long long A,B,K;
  cin >> A >> B >> K;

  if(A >= K) A -= K;
  else {
    K -= A;
    A = 0;
    B = max(0LL,B-K);
  }

  cout << A << " " << B << endl;

  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

struct Edge{
  int to, cost; // 辺の接続先頂点, 辺の重み
  Edge(int to, int cost) : to(to), cost(cost){} // コンストラクタ
};

const int INF = 1e9;
vector<int> d; // 最短距離

// ベルマンフォード法
// 戻り値がtrueなら負の閉路を含む
bool bellmanford(int n, int s, vector<vector<Edge> > graph) { // nは頂点数、sは開始頂点
  d.assign(n, INF);
  d[s] = 0; // 開始点の距離は0
  REP(i, n) REP(v, n) REP(k, graph[v].size()){
    Edge e = graph[v][k];
    if(d[v] != INF && d[e.to] > d[v] + e.cost){
      d[e.to] = d[v] + e.cost;
      if (i == n - 1) return true; // n回目にも更新があるなら負の閉路が存在
    }
  }
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, E, s; cin >> N >> E >> s;
  vector<vector<Edge> > G(N, vector<Edge>());
  REP(i, E){
    int from, to, cost; cin >> from >> to >> cost;
    G[from].push_back(Edge(to, cost));
  }
  
  if(bellmanford(N, s, G)){
    cout << "NEGATIVE CYCLE" << endl;
    return 0;
  };
  
  for(int i = 0; i < N; i++){
    if(d[i] != INF){
      cout << d[i] << endl;
    }else{
      cout << "INF" << endl; 
    }
  }
}



Measured memory_bytes: 3260
#include<stdio.h>

int main() {
	int high[3] = { 0,0,0 };
	int h;

	scanf("%d", &high[0]);
	
	for (int i = 1;i < 10;i++) {
		scanf("%d",&h);
		if (high[0] < h) {
			high[2] = high[1];
			high[1] = high[0];
			high[0] = h;
		}
		else if (high[1] < h) {
			high[2] = high[1];
			high[1] = h;
		}
		else if (high[2] < h) {
			high[2] = h;
		}
	}

	for (int i = 0;i < 3;i++) {
		printf("%d\n", high[i]);
	}

	return 0;
}


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

int main() {
  int A, B, counter = 0;
  cin >> A >> B;
  for (int i = A; i<=B; i++){
    if(i/1000 ==  (i%10) * 10 +  i/10 - (i/100) *10){
      counter++;
    }
  }
  cout << counter << endl;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.immutable.Queue

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  @tailrec
  private def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}


object Main {
  def solve(sc: => Scanner): Unit = {
    val N = sc.nextInt
    for (_ <- 0 until N) {
      val x, y = sc.nextInt
      val A = Array.fill(x + 1)(Array.fill(y + 1)(0L))
      A(0)(0) = 1
      val matatabi = Array.fill(sc.nextInt)((sc.nextInt, sc.nextInt), (sc.nextInt, sc.nextInt))

      for (i <- 0 to x) {
        for (j <- 0 to y) {
          if (i - 1 >= 0 && matatabi.find(x => x == ((i, j), (i - 1, j))) == None && matatabi.find(x => x == ((i - 1, j), (i, j))) == None) {
            A(i)(j) += A(i - 1)(j)
          }
          if (j - 1 >= 0 && matatabi.find(x => x == ((i, j), (i, j - 1))) == None && matatabi.find(x => x == ((i, j - 1), (i, j))) == None) {
            A(i)(j) += A(i)(j - 1)
          }
        }
        //println(A(i).mkString(" "))
      }
      println(if (A(x)(y) == 0) ("Miserable Hokusai!") else (A(x)(y)))
    }
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)

    solve(sc)
  }

}

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

using namespace std;

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

    string n;
    cin >> n;
    int sum = 0;
    for (char c: n)
        sum += c - '0';
    if (sum % 9 == 0)
        cout << "Yes";
    else
        cout << "No";

    return 0;
}


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

using namespace std;

#define ll long long

signed main() {
	int n, l;
	cin >> n >> l;
	ll taste = (ll)n * ((ll)l - 1) + (ll)n * ((ll)n + 1) / 2; // 元の味の総和
	if (l <= 0 && 1 - l <= n) { // 味0のリンゴが存在する場合
		cout << taste;
		return 0;
	}
	if (l < 0) { // すべてのリンゴの味が負の場合
		taste -= (ll)l + (ll)n - 1; // 最も0に近いリンゴを食べる
		cout << taste;
		return 0;
	}
	taste -= l; // 最も0に近いリンゴを食べる
	cout << taste;
	return 0;
}

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

int main(){
  string A,B,C;
  cin >> A >> B >> C;
  int a=A.size(),b=B.size(),c=C.size();
  int i=-1,j=-1,k=-1;
  char x='a';
  while(1){
    if(x=='a'){
      i++;
      if(i==a){
        cout << 'A' << endl;
        break;
      }
      x=A.at(i);
    }
    else if(x=='b'){
      j++;
      if(j==b){
        cout << 'B' << endl;
        break;
      }
      x=B.at(j);
    }
    else if(x=='c'){
      k++;
      if(k==c){
        cout << 'C' << endl;
        break;
      }
      x=C.at(k);
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <cmath>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int h, m, s;
		char c;
		priority_queue< P, vector<P>, greater<P> > pq;
		int start, end;
		for (int i = 0; i < n; i++) {
			cin >> h >> c >> m >> c >> s;
			start = h*3600+m*60+s;
			cin >> h >> c >> m >> c >> s;
			end = h*3600+m*60+s;
			P p = P(end, start);
			pq.push(p);
		}
		vector<int> data[2];
		while (!pq.empty()) {
			P pp = pq.top();
			pq.pop();
			data[0].push_back(pp.first);
			data[1].push_back(pp.second);
		}
		int MAX = 0;
		int counter = 0;
		for (int i = 0; i < n; i++) {
			counter = 0;
			for (int j = i; j < n; j++) {
				if (data[0][i] > data[1][j]) {
					counter++;
				}
			}
			MAX = max(MAX, counter);
		}
		cout << MAX << endl;
	}
	return 0;
}

Measured memory_bytes: 1420
#include<iostream>
using namespace std;
int main(){
int n,a,b,c,i;
cin>>n;
for(i=0;i<n;i++){
cin>>a>>b>>c;
if(a*a==b*b+c*c)cout<<"YES"<<endl;else if(b*b==a*a+c*c)cout<<"YES"<<endl;else if(c*c==a*a+b*b)cout<<"YES"<<endl;else cout<<"NO"<<endl;
}
return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main()
{
    int n,a,b;

    while(~scanf("%d",&n))
    {
        if(n==1)
        printf("Hello World\n");
        if(n==2)
        {
           scanf("%d %d",&a,&b);
           printf("%d\n",a+b);
        }


    }
    return 0;
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int a,b,c,d,e;
	string f,g,h,i,j;
	cin >> f;
	if(f[0] == 'S')cout << "Cloudy" << endl;
	else if(f[0] == 'C')cout << "Rainy" << endl;
	else cout << "Sunny" << endl;
	return 0;
}
 

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

int main(void) {
  int i, max = 0, sum = 0, n, *l;

  scanf("%d", &n);
  l = malloc(sizeof(int) * n);

  for (i = 0; i < n; i++) {
    scanf("%d", &l[i]);
  }

  for (i = 0; i < n; i++) {
    sum += l[i];
    if (max < l[i]) {
      max = l[i];
    }
  }

  if (max < (sum-max)) {
    printf("Yes\n");
  }else {
    printf("No\n");
  }

  return 0;


}

Measured memory_bytes: 128
H,W = map(int, input().split())
S = [list(input()) for i in range(H)]
S=[[0 if j == "." else "#" for j in i] for i in S]

for i in range(H):
          for j in range(W):
            if S[i][j]=='#':

                try:S[i-1][j-1]
                except IndexError:pass
                else:
                    if  i-1>=0 and j-1>=0 and S[i-1][j-1]!='#':
                        S[i-1][j-1]+=1

                try:S[i-1][j]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j]!='#':
                        S[i-1][j]+=1

                try:S[i-1][j+1]
                except IndexError:pass
                else:
                    if i-1>=0 and S[i-1][j+1]!='#':
                        S[i-1][j+1]+=1

                try:S[i][j-1]
                except IndexError:pass
                else:
                    if  j-1>=0 and S[i][j-1]!='#':
                        S[i][j-1]+=1
                        
                try:S[i][j+1]
                except IndexError:pass
                else:
                    if  S[i][j+1]!='#':
                        S[i][j+1]+=1

                try:S[i+1][j-1]
                except IndexError:pass
                else:
                    if j-1>=0 and S[i+1][j-1]!='#':
                        S[i+1][j-1]+=1

                try:S[i+1][j]
                except IndexError:pass
                else:
                    if S[i+1][j]!='#':
                        S[i+1][j]+=1

                try:S[i+1][j+1]
                except IndexError:pass
                else:
                    if S[i+1][j+1]!='#':
                        S[i+1][j+1]+=1
for i in S:
    print(*i,sep="")

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define typeof(x) __typeof__(x)
#define int long long int
#define double long double
#define mod(x) ((x % MOD) + MOD) % MOD
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define RREP(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SZ(c) (int)((c).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define LB(c,x) (int)(lower_bound(ALL(c),x)-(c).begin())
#define UB(c,x) (int)(upper_bound(ALL(c),x)-(c).begin())
#define COUNT(c,x) UB(c,x)-LB(c,x)
#define UNIQUE(c) SORT(c); (c).erase(unique(ALL(c)),(c).end());
#define COPY(c1,c2) copy(ALL(c1),(c2).begin())
#define EXIST(s,e) (s).find(e)!=(s).end()
#define PB push_back
#define MP make_pair
#define vec vector
#define dump(x)  cerr << #x << " = " << (x) << endl;

using namespace std;

typedef pair<int,int> P;
struct edge { int from, to; double cost; };
ostream& operator << (ostream& s, const edge& e) {
   s << "(" << e.from << "->" << e.to << ": " << e.cost << ")";
   return s;
}
bool operator< (const edge &edge1, const edge &edge2){
   return edge1.cost < edge2.cost;
};

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

template<typename T> ostream& operator << (ostream& s, const vector<T>& v) {
   s << "[";
   for (int i = 0; i < v.size(); i++) { s << v[i]; if (i < v.size() - 1) s << " "; }
   s << "]";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const pair<T1,T2>& p) {
   s << "(" << p.first << "," << p.second << ")";
   return s;
}
template<typename T1, typename T2> ostream& operator << (ostream& s, const map<T1,T2>& m) {
   s << "{";
   for (auto i = m.begin(); i != m.end(); ++i) {
      s << i->first << ":" << i->second;
      if (next(i) != m.end()) s << ", ";
   }
   s << "}";
   return s;
}

signed main()
{
   string S; cin >> S;
   int Bnum = 0, ans = 0;
   REP(i, 0, SZ(S)) {
      if (S[i] == 'B') {
         Bnum++;
      } else {
         ans += Bnum;
      }
   }
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 640
// OBïÄh2011 Day4 F : eÌ

#include <iostream>
#include <vector>
#include <cmath>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef vector< vector<double> > Matrix;

Matrix mul(Matrix A, Matrix B){
	int n = A.size();
	Matrix res(n, vector<double>(n,0));
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			for(int k=0;k<n;k++)
				res[i][j] += A[i][k]*B[k][j];
	return res;
}

Matrix pow(Matrix A, int p){
	if(p==1) return A;
	Matrix res = pow(A, p/2);
	res = mul(res, res);
	if(p%2) res = mul(res, A);
	return res;
}

void gaussianElimination(Matrix &a){
	int n = a.size();
	for(int i=0;i<n;i++){
		int pivot = i;
		for(int j=i+1;j<n;j++)
			if(abs(a[j][i])>abs(a[pivot][i])) pivot = j;
		swap(a[i], a[pivot]);
		double div = a[i][i];
		for(int j=0;j<=n;j++) a[i][j] /= div;
		for(int j=i+1;j<n;j++){
			double mul = a[j][i];
			for(int k=0;k<=n;k++)
				a[j][k] -= a[i][k]*mul;
		}
	}
	for(int i=n-1;i>=0;i--)
		for(int j=0;j<i;j++)
			a[j][n] -= a[j][i]*a[i][n];
}

int main(){
	int S, N, K;
	double prob[11][100];
	while(cin >> S >> N >> K){
		S = abs(S);
		if(N==1){
			if(S%K==0) cout << S/K << endl;
			else       cout << -1 << endl;
			continue;
		}
		for(int i=0;i<=K;i++)
			for(int j=0;j<=N*K;j++) prob[i][j] = 0;
		// KñÅÇê¾¯Ì£iÞ©ÉÂ¢ÄAm¦ðßé
		prob[0][0] = 1.0;
		for(int i=0;i<K;i++)
			for(int j=0;j+N<=N*K;j++)
				for(int k=1;k<=N;k++)
					prob[i+1][j+k] += prob[i][j]/N;
		// A§ûö®Å[0,N*K-1]ÌÍÍÌúÒlðßé
		vector< vector<double> > a(N*K, vector<double>(N*K+1, 0));
		a[0][0] = 1;
		for(int i=1;i<N*K;i++){
			a[i][i] = a[i][N*K] = 1.0;
			for(int j=1;j<=N*K;j++){
				int next = abs(i-j);
				a[i][next] -= prob[K][j];
			}
		}
		gaussianElimination(a);
		if(S < N*K) printf("%.6lf\n", a[S][N*K]);
		// S>=N*KÈçúÒlÍN*KÌQ»®Å\¹éÌÅAsñÏÅúÒlðßé
		else {
			Matrix A(N*K+1, vector<double>(N*K+1,0));
			for(int i=0;i<N*K;i++) A[0][i] = prob[K][i+1];
			A[0][N*K] = 1.0;
			for(int i=1;i<N*K;i++) A[i][i-1] = 1.0;
			A[N*K][N*K] = 1.0;
			A = pow(A, S-N*K+1);
			double res = A[0][N*K];
			for(int i=0;i<N*K;i++) res += A[0][i]*a[N*K-1-i][N*K];
			printf("%.6lf\n", res);
		}
	}
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    vector<ll> a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];
    vector<ll> sa(n + 1), sb(m + 1);
    rep(i, n) sa[i + 1] = sa[i] + a[i];
    rep(i, m) sb[i + 1] = sb[i] + b[i];

    int ans = 0;
    rep(i, n + 1) {
        if (sa[i] > k) break;
        int now = i;
        now += (--upper_bound(all(sb), k - sa[i])) - sb.begin();
        chmax(ans, now);
    }
    cout << ans << endl;
}

Measured memory_bytes: 9560
/**
 *    author:  tourist
 *    created: 11.05.2020 14:27:12       
**/
#include <bits/stdc++.h>

using namespace std;

template <typename T>
class graph {
 public:
  struct edge {
    int from;
    int to;
    T cost;
  };

  vector<edge> edges;
  vector<vector<int>> g;
  int n;

  graph(int _n) : n(_n) {
    g.resize(n);
  }

  virtual int add(int from, int to, T cost) = 0;
};

template <typename T>
class digraph : public graph<T> {
 public:
  using graph<T>::edges;
  using graph<T>::g;
  using graph<T>::n;

  digraph(int _n) : graph<T>(_n) {
  }

  int add(int from, int to, T cost = 1) {
    assert(0 <= from && from < n && 0 <= to && to < n);
    int id = (int) edges.size();
    g[from].push_back(id);
    edges.push_back({from, to, cost});
    return id;
  }

  digraph<T> reverse() const {
    digraph<T> rev(n);
    for (auto &e : edges) {
      rev.add(e.to, e.from, e.cost);
    }
    return rev;
  }
};

template <typename T>
vector<T> dijkstra(const graph<T> &g, int start) {
  assert(0 <= start && start < g.n);
  vector<T> dist(g.n, numeric_limits<T>::max());
  priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> s;
  dist[start] = 0;
  s.emplace(dist[start], start);
  while (!s.empty()) {
    T expected = s.top().first;
    int i = s.top().second;
    s.pop();
    if (dist[i] != expected) {
      continue;
    }
    for (int id : g.g[i]) {
      auto &e = g.edges[id];
      int to = e.from ^ e.to ^ i;
      if (dist[i] + e.cost < dist[to]) {
        dist[to] = dist[i] + e.cost;
        s.emplace(dist[to], to);
      }
    }
  }
  return dist;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, s;
  cin >> n >> m >> s;
  const int MAX = (n - 1) * 50;
  s = min(s, MAX);
  digraph<long long> g(n * (MAX + 1));
  for (int i = 0; i < m; i++) {
    int u, v, a, b;
    cin >> u >> v >> a >> b;
    --u; --v;
    for (int j = a; j <= MAX; j++) {
      g.add(u * (MAX + 1) + j, v * (MAX + 1) + (j - a), b);
      g.add(v * (MAX + 1) + j, u * (MAX + 1) + (j - a), b);
    }
  }
  for (int i = 0; i < n; i++) {
    int c, d;
    cin >> c >> d;
    for (int j = 0; j < MAX; j++) {
      g.add(i * (MAX + 1) + j, i * (MAX + 1) + min(j + c, MAX), d);
    }
  }
  vector<long long> dist = dijkstra(g, 0 * (MAX + 1) + s);
  for (int i = 1; i < n; i++) {
    long long ans = (long long) 1e18;
    for (int j = 0; j <= MAX; j++) {
      ans = min(ans, dist[i * (MAX + 1) + j]);
    }
    cout << ans << '\n';
  }
  return 0;
}


Measured memory_bytes: 27692
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, n) for (int i = 1; i <= (int)(n); i++)
#define ll long long
#define umap unordered_map
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

ll mod(ll x, ll y){if(x>=0||x%y==0) return x%y;return y+x%y;} //mod including minus
ll dv0(ll x, ll y){if(x>=0||x%y==0)return x/y;return x/y-1;} //rnd down
ll dv1(ll x, ll y){if(x%y==0) return dv0(x,y);return dv0(x,y)+1;} //rnd up
ll M=1e9+7;
int quick_pow(int x,int p){
    int a=1,po=x;
    while(p){
        if(p&1)  a=1ll*a*po%M;
        po=1ll*po*po%M;p>>=1;
    }
    return a;
}
int cnt=0;
int ans=0;
vector<int> A;

void count(int N, int M, int Q, vector<int> a, vector<int> b, vector<int> c, vector<int> d, vector<int> A){
    if(A.size()==N){
        cnt=0;
        rep(i, Q){
            if(A.at(b.at(i)-1)-A.at(a.at(i)-1)==c.at(i)){
                cnt+=d.at(i);
            }
            
        }
        ans=max(ans, cnt);
    }else if(A.size()==0){
        for(int j=1;j<=M;j++){
            vector<int> B=A;
            B.push_back(j);
            count(N, M, Q,a, b, c, d, B);
        }
    }
    else{
        for(int j=A.at(A.size()-1);j<=M;j++){
            vector<int>B=A;
            B.push_back(j);
            count(N, M, Q,a, b, c, d, B);
        }
    }
}

//Start from Here
int main(){
    int N, M, Q;
    cin>>N>>M>>Q;
    vector<int> a, b, c, d;
    rep(i, Q){
        int x, y, z, w;
        cin>>x>>y>>z>>w;
        a.push_back(x);
        b.push_back(y);
        c.push_back(z);
        d.push_back(w);
    }
    count(N, M, Q,a, b, c, d, A);
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
from functools import reduce
import sys
import numpy as np


mod = 10 ** 9 + 7
buffer = sys.stdin.buffer
h, w = map(int, buffer.readline().split())
s = np.frombuffer(buffer.read(h*(w+1)), dtype='B') == ord('.')
s = s.reshape((h, w+1))[:, :-1]
l = np.empty((h, w), dtype='i4')
r = np.empty((h, w), dtype='i4')
u = np.empty((h, w), dtype='i4')
d = np.empty((h, w), dtype='i4')
l[:, 0] = s[:, 0]
for i in range(1, w):
    l[:, i] = (l[:, i-1] + 1) * s[:, i]
r[:, -1] = s[:, -1]
for i in range(1, w):
    r[:, -1-i] = (r[:, -i] + 1) * s[:, -1-i]
u[0] = s[0]
for i in range(1, h):
    u[i] = (u[i-1] + 1) * s[i]
d[-1] = s[-1]
for i in range(1, h):
    d[-1-i] = (d[-i] + 1) * s[-1-i]
score = l + r + u + d - 3
print(int(score.max()))

Measured memory_bytes: 110084
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
#define mod 1000000007
#define pi 3.1415926535
typedef long long ll;

int main(){
    int H,W;
    cin>>H>>W;
    vector<vector<char>>C(H,vector<char>(W));
    rep(i,H){
        rep(j,W){
            cin>>C[i][j];
        }
    }

    rep(i,H){
        rep(k,2){
            rep(j,W){
                cout<<C[i][j];
                }
                cout<<endl;
            }
        }
    return 0;
}

Measured memory_bytes: 256
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

#define N 100000

int a[N];
ll s[N+1];
ll s2[N/2+1];
int n;

ll odds(int m) {
    return (m%2 ? s[m] - s2[m/2] : s2[m/2]);
}

int solve2(int x, int t) {
    int l = t-1, r = n-1;
    while (1) {
        int i2 = (l+r)/2;
        int i1 = i2-t+1;
        if (i2 < n-1 && abs(x-a[i2+1]) < abs(x-a[i1])) {
            l = i2+1;
            continue;
        }
        if (i1 > 0 && abs(x-a[i1-1]) <= abs(x-a[i2])) {
            r = i2-1;
            continue;
        }
        return i2;
    }
    return 0;
}

ll solve(int x) {
    if (x >= a[n-2])
        return odds(n);
    int l = 1, r = n;
    while (1) {
        int m = (l+r)/2;
        int i2 = solve2(x, m);
        int th = n-m;
        if (i2 > th-1)
            r = m-1;
        else if (i2 == th-1)
            return s[n] - s[n-m] + odds(n-2*m);
        else if (i2 == th-2)
            return s[n] - s[n-m-1] + s[n-2*m-1] - odds(n-2*m-1);
        else
            l = m+1;
    }

    return 0;
}

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

    n = gi();
    int q = gi();
    s[0] = 0;
    s2[0] = 0;
    for (int i = 0; i < n; i++) {
        int x = gi();
        a[i] = x;
        s[i+1] = s[i] + x;
        if (i%2)
            s2[i/2+1] = s2[i/2] + x;
    }

    for (int i = 0; i < q; i++)
        cout << solve(gi()) << endl;

    return 0;
}


Measured memory_bytes: 3328
ls=list(input())
n=int(input())

end_str=ls[-1]
divide_idx=0
for i in range(len(ls)-1,0,-1):
    if ls[i]!=end_str:
        divide_idx=i+1
        break
#print(divide_idx)
#print(ls[divide_idx:])
#print(ls[:divide_idx])

start_ls=ls[:divide_idx]
middle_ls=ls[divide_idx:]+ls[:divide_idx]
end_ls=ls[divide_idx:]

#print(start_ls,middle_ls,end_ls)

def get_count(req_list):
    ls=req_list[:]
    count=0
    for i in range(len(ls)-1):
        a,b=ls[i],ls[i+1]
        if a==b:
            ls[i+1]='!'
            count+=1
    return count

start_counts=get_count(start_ls)
middle_counts=get_count(middle_ls)*(n-1)
end_counts=get_count(end_ls)
#print(start_counts,middle_counts,end_counts)
if divide_idx==0:
    print(len(ls)*n//2)
else:
    print(start_counts+middle_counts+end_counts)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	int right = 0;
	int sum = 0;
	long long ans = 0;
	for (int left = 0; left < N; ++left) {
		while (right < N && (sum^A[right]) == (sum + A[right])) {
			sum += A[right]; 
			right++;
		}
		ans += right - left; 
		sum -= A[left];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4012
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        for (int i = 1; i <= b - 1; ++i)
        {
            if (a * i % b == c)
            {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }
}


Measured memory_bytes: 24276
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <algorithm>

using namespace std;

int main()
{
  int N;
  cin >> N;
  long long minVal = __INT_MAX__;
  long long ans = 0;
  int count = 0;
  for (int i=0;i<N;i++) {
    long long a;
    cin >> a;
    if (a < 0) {
      a *= -1;
      count = 1 - count;
    }
    if (a < minVal) minVal = a;
    ans += a;
  }
  if (count) ans -= (minVal*2);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define FILL(i,n) memset(i,n,sizeof(i));
#define X first
#define Y second
#define pb push_back
#ifdef brian
#define  debug(...) do{\
    fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename t> void _do(t &&x){cerr<<x<<endl;}
template<typename t,typename ...T> void _do(t &&x,T &&...tail){cerr<<x<<", ";_do(tail...);}
#else
#define debug(...)
#endif // brian

const ll INF=ll(1e15);

const ll MAXn=100005;
ll a[MAXn],b[MAXn];
ll n,ans=0;

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    REP(i,n)cin>>a[i]>>b[i];
    for(int i=n-1;i>=0;i--)
    {
        a[i]+=ans;
        ll tmp=a[i]%b[i];
        if(tmp!=0)ans+=b[i]-tmp;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int N, Q;
  cin >> N >> Q;

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

  sort(a.begin(), a.end());

  while (Q--) {
    int l, r;
    cin >> l >> r;
    cout << (upper_bound(a.begin(), a.end(), r) -
             lower_bound(a.begin(), a.end(), l))
         << endl;
  }

  return 0;
}


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

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.size();
    for(int i=0;i<n;++i){
        if(s[i]!=t[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }

    cout<<"Yes"<<endl;
}

Measured memory_bytes: 3572
#define _USE_MATH_DEFINES
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <typeinfo>

#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REP1(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREP1(i, x) for (int i = ((int)(x)); i > 0; i--)
/*
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define all(x) (x).begin(),(x).end()
*/

using namespace std;

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

    int n;
    cin >> n;

    bool ans = true;

    string w[200];
    for (int i = 0; i < n; i++)
    {
        cin >> w[i];
        if (i && w[i-1][w[i - 1].size() - 1] != w[i][0])
            ans = false;
        for (int j = 0; j < i; j++)
        {
            if (w[i] == w[j])
            ans = false;
        }
    }

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

Measured memory_bytes: 256
S=input()
a=int(S[0:4])
b=int(S[5:7])
c=int(S[8:])

if(a<2019):
    print("Heisei")
elif(a==2019 and b<4):
    print("Heisei")
elif(a==2019 and b==4 and c<31):
    print("Heisei")
else:
    print("TBD")

Measured memory_bytes: 3060
function Main(input) {
	let[,Arr] = input.split('\n')
    Arr = Arr.split(' ').map(e=>Number(e))
  	const temp = Arr.map((e,i)=>{
    	if(i===0){return 0}
      	if(Arr[i-1]===e){
          return 0
        }else if(e<Arr[i-1]){
        	let diff = Arr[i-1]-e
            Arr[i] = Arr[i]+diff
            return diff
        }else{
        	return 0
        }
    })
  console.log(temp.reduce((a,b)=>a+b))
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 51852
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

ll power(ll x, ll pw, ll mod) {
    ll res = 1;
    x = x % mod;  // if it x >= p
    while (pw > 0) {
        if (pw & 1)
            res = (res*x) % mod;
        pw /= 2;
        x = (x*x) % mod;
    }
    return res;
}

unordered_map<int, int> get_prime_fac(ll n) {
    unordered_map<int, int> facs;
    ll n2 = n;
    for(ll i = 2; i*i <= n; i++) {
        while (n2 % i == 0) {
            facs[i] += 1;
            n2 /= i;
        }
    }
    if (n2 > 1)
        facs[n2] += 1;
    return facs;
}
vector<int> get_facs(unordered_map<int, int>& primes) {
    vector<int> nums, cnt;
    for(auto p: primes) {
        nums.push_back(p.first);
        cnt.push_back(p.second);
    }
    vector<int> ans;
    auto dfs = [&] (auto self, int d, int cur) -> void{
        if (d == nums.size()) {
            ans.push_back(cur);
            return;
        }
        int compute = 1;
        for(int i = 0; i <= cnt[d]; i++) {
            self(self, d+1, cur*compute);
            compute *= nums[d];
        }
    };
    dfs(dfs, 0, 1);
    return ans;
}
int main() {
    // https://img.atcoder.jp/abc162/editorial.pdf
    ll N, K, mod = 1e9 + 7;
    cin >> N >> K;
    vector<ll> cnt(K+1, 0);
    vector<ll> pre_sub(K+1, 0);
    for(int k = K; k >= 1; k--) {
        cnt[k] = power(K/k, N, mod);
        cnt[k] = (cnt[k] - pre_sub[k] + mod*2) % mod;

        auto primes = get_prime_fac(k);
        for(int fac: get_facs(primes)) {
            if (fac == k) continue;
            pre_sub[fac] += cnt[k];
            pre_sub[fac] %= mod;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= K; i++) {
        ans += cnt[i] * i;
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 4792
#include<iostream>
#include<fstream>
#include<algorithm>
#include<string>
#include<cstring>

using namespace std;

const int MAXN = 50 + 5;

int N;
int Ans = 0;
int A[MAXN], B[MAXN], Used[MAXN];



void DFS(int depth) {
	if (depth == N + 1) {
		int C[MAXN];
		memcpy(C, B, sizeof(int) * (N + 1));
		sort(C, C + N + 1);
		int tmp = C[1] - C[0];
		for (int i = 1; i < N + 1; i++) {
			if (tmp > C[i] - C[i - 1]) {
				tmp = C[i] - C[i - 1];
			}
		}
		tmp = min(tmp, 24 - C[N]);
		if (Ans < tmp)
			Ans = tmp;
		return;
	}
	if (Used[depth]) {
		DFS(depth + 1);
		return;
	}
		

	B[depth] = A[depth];
	DFS(depth + 1);
	B[depth] = 24 - A[depth];
	DFS(depth + 1);
	return;
}

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

	bool flag = true;
	if (N >= 24) cout << 0 << endl;
	else {
		A[N] = 0;
		sort(A, A + N + 1);
		if (A[1] == 0)
			cout << 0 << endl;
		else {
			for (int i = 0; i < N; i++) {
				if (A[i] == A[i + 1]) {
					if (Used[i]) {
						cout << 0 << endl;
						flag = false;
						break;
					}
					Used[i] = 1;
					Used[i + 1] = 1;
					B[i] = A[i];
					B[i + 1] = 24 - A[i];
				}
			}
			if (flag) {
				DFS(1);
				cout << Ans << endl;
			}
			
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

static const ll MOD = 1000000007;

ll dp[2005][2005];

int main(){
  int N, M;
  cin >> N >> M;
  vector<int> S, T;
  rep(i,N){
    int a;
    cin >> a;
    S.push_back(a);
  }
  rep(i,M){
    int a;
    cin >> a;
    T.push_back(a);
  }

  rep(i,N){
    rep(j,M){
      dp[i][j] += ((j-1>=0?dp[i][j-1]:0)-(i-1>=0&&j-1>=0?dp[i-1][j-1]:0)+MOD)%MOD;
      dp[i][j] += ((i-1>=0?dp[i-1][j]:0)-(i-1>=0&&j-1>=0?dp[i-1][j-1]:0)+MOD)%MOD;
      dp[i][j] %= MOD;
      if(S[i] == T[j]){
        dp[i][j] += 2*(i-1>=0&&j-1>=0?dp[i-1][j-1]:0) + 1;
        dp[i][j] %= MOD;
      }else{
        dp[i][j] += (i-1>=0&&j-1>=0?dp[i-1][j-1]:0);
        dp[i][j] %= MOD;
      }
    }
  }
  dp[N-1][M-1] += 1;
  dp[N-1][M-1] %= MOD;

  cout << dp[N-1][M-1] << endl;
  
  return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
char s[100];
int p[100];
int main(){
	scanf("%s",s);
	int len=strlen(s);
	if (len<26)
	{
		for (int i=0;i<len;i++) printf("%c",s[i]),p[s[i]-'a']=1;
		for (int i=0;i<26;i++) if (!p[i]) {
			printf("%c",'a'+i); return 0;
		}
	}
	else {
		int t=len-1;
		p[s[t]-'a']=1;
		for (int i=len-2;i>=0;i--)
			if (s[i]<s[i+1])
			{
				t=i; p[s[i]-'a']++; break;
			}  else p[s[i]-'a']++;
		if (t==len-1) {
			printf("%d\n",-1); return 0;
		}	
        for (int i=s[t]-'a'+1;i<26;i++) if (p[i]) {s[t]='a'+i; p[i]=0; break;}
        for (int i=0;i<=t;i++) printf("%c",s[i]);
	}
}

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

inline void read(int &x){
	x=0;int f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	x*=f;
}
/*******************************head*******************************/

const int N=200005;
int n,a[N],b[N];
inline bool check(int k){
	for(int i=1;i<2*n;i++) b[i]=(a[i]>=k);
	int l=n,r=n;
	while(l>1 && b[l-1]!=b[l]) l--;
	while(r<2*n-1 && b[r+1]!=b[r]) r++;
	if(l==1 && r==2*n-1){
		if(n&1) return b[n];
		else return (b[n]^1);
	}
	if(n-l<r-n)return b[l];
	else return b[r];
}
int main(){
	read(n);
	for(int i=1;i<2*n;i++) read(a[i]);
	int l=1,r=2*n-1,ans;
	while(l<=r){
		int mid=(l+r)/2;
		if(check(mid)){
			ans=mid;
			l=mid+1;
		}
		else r=mid-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
bool ok[32];
bool map[32][32];
int main(){
	int n;
	ll k;
	cin>>n>>k;
	for(int i=0;i<32;i++){
		if(k%2==1)ok[i]=true;
		else ok[i]=false;
		k/=2;
	}
	for(int i=0;i<32;i++){
		lol(j,32)map[i][j]=ok[j];
		if(ok[i]==true){
			map[i][i]=false;
			for(int j=i-1;j>=0;j--)map[i][j]=true;
		}
	}
	ll sum[32]={0};
	ll ans=0;
	
	lol(u,n){
		ll a,b;
		cin>>a>>b;
		bool t[32];
		for(int i=0;i<32;i++){
			if(a%2==1)t[i]=true;
			else t[i]=false;
			a/=2;
		}
		
		for(int i=0;i<32;i++){
			bool cando=true;
			for(int j=0;j<32;j++){
				if(map[i][j]==false&&t[j]==true){
					cando=false;
				}
			}
			if(cando)sum[i]+=b;
		}
		
		bool cando=true;
		for(int j=0;j<32;j++){
			if(ok[j]==false&&t[j]==true){
				cando=false;
			}
		}
		if(cando)ans+=b;
	}
	lol(i,32)ans=max(ans,sum[i]);
	cout<<ans<<endl;
	return 0;
}


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

int main ()
{
  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++) cin >> A.at(i).at(j);
  }
  int N;
  cin >> N;
  vector<int> b(N);
  for(int i = 0; i < N; i++) cin >> b.at(i);
  vector<vector<bool>> C(3, vector<bool>(3, false));
  for (int i = 0; i < 3; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      for (int k = 0; k < N; k++)
      {
        if (A.at(i).at(j) == b.at(k))
        {
          C.at(i).at(j) = true;
          break;
        }
      }
    }
  }

  if (C.at(0).at(0) == true && C.at(0).at(1) == true && C.at(0).at(2) == true ||
      C.at(1).at(0) == true && C.at(1).at(1) == true && C.at(1).at(2) == true ||
      C.at(2).at(0) == true && C.at(2).at(1) == true && C.at(2).at(2) == true ||
      C.at(0).at(0) == true && C.at(1).at(0) == true && C.at(2).at(0) == true ||
      C.at(0).at(1) == true && C.at(1).at(1) == true && C.at(2).at(1) == true ||
      C.at(0).at(2) == true && C.at(1).at(2) == true && C.at(2).at(2) == true ||
      C.at(0).at(0) == true && C.at(1).at(1) == true && C.at(2).at(2) == true ||
      C.at(0).at(2) == true && C.at(1).at(1) == true && C.at(2).at(0) == true)
  {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
using namespace std;
#define ll long long
map<int, int>m;
const int maxn = 1e5 + 5;
int a[maxn];
int main()
{
	char c;
	cin >> c;
	if (c >= 'A' && c <= 'Z')cout << "A" << endl;
	else if (c >= 'a' && c <= 'z')cout << "a" << endl;
}

Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int H, W;
vector<vector<int>> cost;
vector<vector<int>> A;

void warshall_floyd()
 {
   for (int k = 0; k <= 9; k++ ) {
     for (int i = 0; i <= 9; i++) {
       for (int j = 0; j <= 9; j++) {
         cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
       }
     }
   }
 }
int main() {
  int magical_power = 0;
  cin >> H >> W;
  cost = vector<vector<int>>(10, vector<int>(10));
  for (int i = 0; i < 10; i++) {
    for (int j = 0; j < 10; j++) {
      cin >> cost[i][j];
    }
  }
  A = vector<vector<int>>(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> A[i][j];
     }
  }
  warshall_floyd();
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (A[i][j] == -1) continue;
      magical_power += cost[A[i][j]][1];
    }
  }
  cout << magical_power << endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    string odd,even; cin >> odd >> even;
    rep(i,even.size()){
        cout << odd[i] << even[i];
    }
    if(odd.size()!=even.size()){
        cout << odd[odd.size()-1];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

int main() {
    ll x; cin>>x;
    ll n = x/11, r = x%11;
    if(r>6) cout<<n*2 + 2;
    else if(r>0) cout<<n*2 + 1;
    else cout<<n*2;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
    int a, b, c, d;
    int sum1, sum2;

    scanf("%2d %2d %2d %2d", &a, &b, &c, &d);
    sum1 = a + b;
    sum2 = c + d;
    if (sum1 > sum2){
        printf("Left");
    } else if (sum2 > sum1){
        printf("Right");
    } else {
        printf("Balanced");
    }
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include <numeric>
#include<map>
#include<unordered_map>
#include <queue>
 
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

int main(){
    ll cnt[26] = {};
    ll h, w;
    cin >> h >> w;
    rep(i, h)rep(i, w){
        char a;
        cin >> a;
        cnt[a-'a']++;
    }
    ll f, t, o;
    f = t = o = 0; 
    rep(i, 26){
        f += cnt[i]/4;
        cnt[i] %= 4;
        t += cnt[i]/2;
        o += cnt[i]%2;
    }
    ll flt = ((h/2)*2)/2*((w/2)*2)/2;
    if(o > 1)cout << "No";
    else if(f < flt)cout << "No";
    else cout << "Yes";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int64_t l=1000000007;
int64_t pow(int64_t a,int64_t b) {
  int64_t c;
  if(b==0) return 1;
  else {
    c=(((pow(a,b/2)+l)%l)*((pow(a,b/2)+l)%l)+l)%l;
    if(b%2==1) c=(c*a+l)%l;
    return (c+l)%l;
  }
}
int main() {
  int64_t n,k,s,i,j,m;
  cin>>n>>k;
  vector<int64_t> c(k+1);
  s=0;
  for(i=k;i>0;i--){
    m=k/i;
    c.at(i)=(pow(m,n)+l)%l;
    for(j=2;j<=m;j++) c.at(i)=(c.at(i)-c.at(i*j)+l)%l;
    s=(s+i*c.at(i)+l)%l;
  }
  cout<<s<<endl;
}

Measured memory_bytes: 4060