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

using namespace std;

int ans = 0;
int n;
const int INF = 1e6;
vector<vector<int>> X, Y;

int main(){
    cin >> n;
    X.resize(n);
    Y.resize(n);
    for (int i = 0; i < n; i++){
        int a;
        cin >> a;
        for (int j = 0; j < a; j++){
            int x, y;
            cin >> x >> y;
            X[i].push_back(--x);
            Y[i].push_back(y);
        }
    }

    int ans = 0;
    for (int bits = 0; bits < 1 << n; bits++){
        int res = 0;
        for (int i = 0; i < n; i++){
            if (!((bits >> i) & 1))
                continue;
            for (int j = 0; j < X[i].size(); j++){
                if ((bits >> X[i][j] & 1) != Y[i][j])
                    res = -INF;
            }
            res++;
        }
        ans = max(ans, res);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
	static final long MOD=1000000007;//998244353;
	public static void main(String[] args) {
		PrintWriter out = new PrintWriter(System.out);
		InputReader sc=new InputReader(System.in);
		char[] cs=sc.next().toCharArray();
		int c=0;
		for (int i = 0; i < cs.length; i++) {
			c+=Character.getNumericValue(cs[i]);
		}
		if (c%9==0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
 	}
	static class InputReader { 
		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;
		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}
 
		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}
 
		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}
 
		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}
 
		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}
 
		public boolean hasNext() {
			skip();
			return hasNextByte();
		}
 
		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
 
		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}
 
		public double nextDouble() {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}
 
		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
 
		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


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

int main(){
    int s; cin >> s;
    int n = 0;
    vector<string> ans = {"NA","YYMM","MMYY","AMBIGUOUS"};
    if(1 <= s%100 && s%100 <= 12) n += 1;
    if(1 <= s/100 && s/100 <= 12) n += 2;
    cout << ans[n] << endl;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);

		String a = sc.next();
		String b = sc.next();


		if ( a.equals(b) ) {

			System.out.println("H");

		} else {

			System.out.println("D");

		}
	}
}


Measured memory_bytes: 21716
import sys
from collections import deque

def main():
    n = int(sys.stdin.readline().rstrip())
    ab = map(int, sys.stdin.read().split())
    ab = list(zip(ab, ab))

    G = [[] for _ in range(n + 1)]
    for a, b in ab:
        G[a].append(b)
        G[b].append(a)
    
    root = 1
    q = deque()
    q.append(root)
    parent = [None] * (n + 1)
    color = [0] * (n + 1) # color[y]はx = parent[y]としてcolor[x] に依存する。

    while q:
        x = q.popleft()
        c = 1
        for y in G[x]:
            if y == parent[x]:
                continue
            parent[y] = x
            if color[x] == c:
                c += 1
            color[y] = c
            c += 1
            q.append(y)

    res = []
    for a, b in ab:
        if a == parent[b]:
            res.append(color[b])
        else:
            res.append(color[a])
    
    k = max(color)
    print(k)
    print('\n'.join(map(str, res)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 37820
n = int(input())
a = sorted(list(map(int,input().split())))
ans = len(set(a))
s = 0
cnt = 1
pre = 0
a.append(10**9)
for x in a:
    if x != pre:
        s += (cnt+1)%2
        cnt = 1
        pre = x
    else:
        cnt += 1
s %= 2
print(ans-s)


Measured memory_bytes: 14548
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
const ll mod = (ll)10e9+7;
const int INF = 0x3f3f3f3f;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    string str;
    cin >> str;
    int n=str.length();
    int i=0;
    str+="yyyyyy";
    while(i<n)
    {
        if(str[i]=='e')
        {
            if(str.substr(i, 5)=="erase")
            {
                if(str[i+5]=='r') i+=6;
                else i+=5;
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }
        else if(str[i]=='d')
        {
            if(str.substr(i, 5)=="dream")
            {
                if(str[i+5]=='e'&&str[i+6]=='r')
                {
                    if(str.substr(i+5, 5)=="erase")
                    {
                        i+=5;
                    }
                    else i+=7;
                }
                else i+=5;
            }
            else
            {
                cout << "NO";
                return 0;
            }
        }
        else
        {
            cout << "NO";
            return 0;
        }
    }
    cout << "YES";
}

//TODO: 49


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

// [i,j]
ll dp[400][400] = {};
ll a[400] = {};
ll cum[401] = {};

ll memo(int i, int j)
{
  if (i == j || dp[i][j] != 0)
    return dp[i][j];
  ll ans = 10000000000000;
  FOR(k, i, j)
  {
    ans = min(ans, memo(i, k) + memo(k + 1, j) + cum[j + 1] - cum[i]);
  }
  dp[i][j] = ans;
  return dp[i][j];
}

int main()
{
  int n;
  cin >> n;
  cum[0] = 0;
  REP(i, n)
  {
    cin >> a[i];
    cum[i + 1] = cum[i] + a[i];
  }

  cout << memo(0, n - 1) << endl;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

//nの最大値が1e5の時とかは使える
const int MAX = 2000001;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理 O(MAX)
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}


int main(){
  // 前処理
  COMinit();
  ll k;
  string s;
  cin >> k;
  cin >> s;
  ll len1 = s.size();
  ll len = len1 + k;
  vector<ll> po1(len),po2(len);
  po1[0] = 1;
  po2[0] = 1;
  rep(i,len-1){
    po1[i+1] = po1[i] * 25;
    po1[i+1] %= mod;
    po2[i+1] = po2[i] * 26;
    po2[i+1] %= mod;
  }
  ll ans = 0;
  REP(i,len1-1,len){
    //cout << i+1 << " " << i-len1+1 << " " << len-i << endl;
    //cout << COM(i,i-len1+1) << " " << po1[i-len1+1] << " " << po2[len-i-1] << endl;
    ans += (COM(i,i-len1+1) * po1[i-len1+1] % mod) * po2[len-i-1];
    ans %= mod;
    //cout << ans << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 82468
#include <iostream>
#include <set>

using namespace std;

int main()
{

    int N, M;
    cin >> N;
    set<int> Set;
    
    for(int i = 0; i < N; ++i)
    {
        int Num;
        cin >> Num;
        Set.insert(Num);
    }
    
    cin >> M;
    
    for(int i = 0; i < M; ++i)
    {
        int Num;
        cin >> Num;
        if(Set.find(Num) != Set.end())
          cout << 1 << endl;
        else 
          cout << 0 << endl;
    }
    
    return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var n = input[0];
        var d = Console.ReadLine().Split(' ');

        Func<int, bool> check = x => 
        {
            var s1 = x.ToString();

            foreach (var s in d)
            {
                if (s1.IndexOf(s) >= 0)
                {
                    return false;
                }
            }

            return true;
        };

        while (!check(n))
        {
            n++;
        }

        Console.WriteLine(n);
    }

}


Measured memory_bytes: 5720
N, M = map(int, input().split())
a = []
c = []
for i in range(N):
  x, y = map(int, input().split())
  a.append([x, y])
for i in range(M):
  x, y = map(int, input().split())
  c.append([x, y])

for i in a:
  tmp = 10**9
  for l in range(M):
    j = c[l]
    x = abs(i[0]-j[0]) + abs(i[1]-j[1])
    if tmp > x:
      tmp = x
      ans = l + 1
  print(ans)

Measured memory_bytes: 9104
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;

int main(){
  int n;
  while(cin >> n, n){
    vector< vector<double> > P(3, vector<double>(3,0));
    char s, t, b;
    cin >> s >> t >> b;
    int S = s - 'A', T = t - 'A', B = b - 'A';
    P[S/3][S%3] = 1;
    const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
    for(int i = 0; i < n; ++i){
      vector< vector<double> > P_(3, vector<double>(3,0));
      for(int j = 0; j < 3; ++j){
        for(int k = 0; k < 3; ++k){
          for(int l = 0; l < 4; ++l){
            int j_ = j + dx[l], k_ = k + dy[l];
            if(j_ < 0 || j_ > 2 || k_ < 0 || k_ > 2 || j_*3 + k_ == B){
              P_[j][k] += P[j][k]*0.25;
            }else{
              P_[j_][k_] += P[j][k]*0.25;
            }
          }
        }
      }
      P = P_;
    }
    printf("%.12f\n", P[T/3][T%3]);
  }
  return 0;
}



Measured memory_bytes: 3080
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
using namespace std;
#define MOD 1000000007
#define MODSET(d) if ((d) >= MOD) d %= MOD;
#define MODNEGATIVESET(d) if ((d) < 0) d = (d % MOD + MOD) % MOD;
#define pii pair<long long ,long long >
#define ll  long long int
#define loop(i,n) for(ll i=0;i<n;i++)
#define loop2(i,n) for(ll i = 1;i<=n;i+=1)
#define pb push_back
#define mp make_pair
#define EPS 1e-7
using namespace std;
// JAI SHREE KRISHNA
//Winning is my right
//I.W.T.D.I.F.M.F



ll dp[100001],d[100001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    stack<char>s1;
    string s;
    cin>>s;
    ll y  = s.length();
    for(ll j = y-1;j>=0;j-=1)
    {
        
        if(s1.empty())
        {
            s1.push(s[j]);
        }
        else{
            char c = s1.top();
            s1.pop();
            if(c=='T'&&s[j]=='S')
            {
                //cout<<":) ";
                continue;
            }
            else{
                //cout<<":( ";
                s1.push(c);
                s1.push(s[j]);
            }
        }
    }
    
    cout<<s1.size()<<endl;
    return 0;
    
    
}


Measured memory_bytes: 720
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
 
class Program{
  static void Main(){
    var num = int.Parse(ReadLine());
    var num2 = ReadLine().Split(' ').GroupBy(a => a).ToArray().Length;
    if(num == num2){
      Write("YES");
    }else{
      Write("NO");
    }
  }
}

Measured memory_bytes: 55568
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  int h,w,cnt;
  char s[51][51];
  scanf("%d %d",&h,&w);
  for(int i=0;i<h;i++)
    scanf("%s",s[i]);
  for(int i=0;i<h;i++)
    for(int j=0;j<w;j++)
      if(s[i][j]=='.'){
        cnt=0;
        for(int k=max(0,i-1);k<min(h,i+2);k++)
          for(int l=max(0,j-1);l<min(w,j+2);l++)
            if(s[k][l]=='#')
              cnt++;
        s[i][j]=cnt+'0';
      }
  for(int i=0;i<h;i++)
    printf("%s\n",s[i]);
}

Measured memory_bytes: 128
use std::collections::VecDeque;

fn solve(uvs: &[(usize, usize)], s: usize, t: usize) -> Option<usize> {
    let mut graph: Vec<Vec<usize>> = vec![Vec::new(); 100001];

    for &(u, v) in uvs {
        graph[u].push(v);
    }

    let mut queue: VecDeque<((usize, usize /* 0,1,2 */), usize /*dist*/)> = VecDeque::new();

    queue.push_back(((s, 0), 0));

    let mut history = vec![false; 100001 * 3];
    history[3 * s] = true;

    while let Some(((next, index), dist)) = queue.pop_front() {
        if (next, index) == (t, 0) {
            return Some(dist / 3);
        }

        for &n in graph[next].iter() {
            let ni = (index + 1) % 3;
            if history[3 * n + ni] == false {
                history[3 * n + ni] = true;
                queue.push_back(((n, ni), dist + 1));
            }
        }
    }

    None
}

#[test]
fn solve_test() {
    assert_eq!(solve(&vec![(1, 2), (2, 3), (3, 4), (4, 1)], 1, 3), Some(2));
    assert_eq!(solve(&vec![(1, 2), (2, 3), (3, 1)], 1, 2), None);
    assert_eq!(solve(&vec![], 1, 2), None);
    assert_eq!(
        solve(
            &vec![
                (1, 2),
                (2, 3),
                (3, 4),
                (4, 5),
                (5, 1),
                (1, 4),
                (1, 5),
                (4, 6)
            ],
            1,
            6
        ),
        Some(2)
    );
}

#[allow(unused_macros)]
macro_rules! parse_line {
    ( $t:ty ) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            iter.next().unwrap().parse::<$t>().unwrap()
        }
    );

    ( $( $t:ty), +) => (
        {
            let mut line = String::new();
            ::std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            ( $(iter.next().unwrap().parse::<$t>().unwrap()),* )
        }
    );
}

#[allow(unused_macros)]
macro_rules! read_line {
    () => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        line.pop();
        line
    }};
}

#[allow(unused_macros)]
macro_rules! parse_vec {
    ( $t:ty ) => {{
        let mut line = String::new();
        ::std::io::stdin().read_line(&mut line).unwrap();
        let iter = line.split_whitespace();
        iter.map(|v| v.parse::<$t>().unwrap()).collect::<Vec<_>>()
    }};
}

fn main() {
    let (n, m) = parse_line!(usize, usize);
    let uvs = (0..m)
        .map(|_| parse_line!(usize, usize))
        .collect::<Vec<_>>();

    let (s, t) = parse_line!(usize, usize);

    println!(
        "{}",
        if let Some(n) = solve(&uvs, s, t) {
            n as isize
        } else {
            -1
        }
    );
}


Measured memory_bytes: 14588
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
 
int main(void){
	string o, e; cin >> o >> e;
	rep(i, o.size() + e.size()) cout << (i%2==0?o[i/2]:e[i/2]);
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void) {
  int x, y, z;
  cin>>x>>y>>z;
  //  X>=A*Y+(A+1)*Z
  for(int i=1; ; i++) {
    if(x<i*y+(i+1)*z) {
      cout<<i-1<<endl;      
      return 0;
    }
  }
  return 0;
}


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

using namespace std;

int main(){
  int n;
  while(cin>>n&&n){
    vector<int> data((n+1)*(n+1));
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        cin>>data[i*(n+1)+j];
        data[i*(n+1)+n]+=data[i*(n+1)+j];
        data[n*(n+1)+j]+=data[i*(n+1)+j];
        data[(n+1)*(n+1)-1]+=data[i*(n+1)+j];
      }
    }
    for(int i=0;i<n+1;i++){
      for(int j=0;j<n+1;j++){
        cout<<setw(5)<<data[i*(n+1)+j];
      }
      cout<<endl;
    }
  }
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 998244353
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int calc(int x, int k){
	if( x < k )return 0;
	if( x % k == 0 ) return x/k;
	else{
		int amari = x % k;
		int subt = x/k + 1;
		if( amari % subt == 0 ) return x/k;
		return calc( x - (amari/subt + 1) * subt, k );
	}
}
signed main(){
	int n;
	cin>>n;
	int ans = 0;
	vector<int> vec;
	for(int i=0;i<n;i++){
		int x,k;
		cin>>x>>k;
		int tmp = calc(x,k);
		vec.pb(tmp);
	}
	for(int i=0;i<n;i++){
		//cout<<vec[i]<<endl;
		ans = ans ^ vec[i];
	}
	if( ans == 0 ){
		cout<<"Aoki"<<endl;
		return 0;
	}
	else{
		cout<<"Takahashi"<<endl;
		return 0;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (__typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(ALL(c), (e)) != (c).end())

VI a[100010];

void solve() {
  LL n, k;
  cin >> n>> k;
  REP(i, n-1) {
    int b, c;
    cin >> b >> c;
    b--;c--;
    a[b].push_back(c);
    a[c].push_back(b);
  }

  queue<pair<int,pair<int, int>>> q;
  q.push(make_pair(0, make_pair(0, -1)));
  LL res = k;
  while(SZ(q) > 0) {
    pair <int, pair<int, int>> node = q.front();
    q.pop();
    int depth = node.second.first;
    int d = depth;
    if (d > 1) d = 1;
    int parent = node.second.second;
    for(auto p : a[node.first]) if (p != parent){
      d++;
      // OUT2(a[node.first][i], d);
      res = (res * (k-d)) % 1000000007;
      q.push(make_pair(p, make_pair(depth+1, node.first)));
    }
  }
  cout << res << endl;
}

int main() {
	solve();
	return 0;
}


Measured memory_bytes: 7288
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();

            int cnt = 0;
            for (int i = 1; i <= n; i++) {
                if (i % 2 == 0) continue;

                int c = 0;
                for (int j = 1; j <= i; j++) {
                    if (i % j == 0) c++;
                }

                if (c == 8) {
                    cnt++;
                }
            }

            out.println(cnt);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



Measured memory_bytes: 21332
n = int(input())
h = list(map(int,input().split()))

'''
n番目の場所に到達する時
n-1番目から、1つ飛んでくる
n-2番目から、２つ飛んでくる
可能性がある　その時の最小値を考える

初期条件
dp[0] = 0
dp[1] = h[1] - h[0]

*** n-1
dp[n] = dp[n-1] + abs(h[n] - h[n-1])

*** n-2
dp[n] = dp[n-2] + abs(h[n] - h[n-2])

漸化式
n >= 2
dp[n] = min(dp[n-1] + abs(h[n] - h[n-1]) , dp[n-2] + abs(h[n] - h[n-2]))

'''

def choice_min(n0, n1):
    if n0 <= n1:
        return n0
    else:
        return n1


dp = [0, abs(h[1] - h[0])]

for i in range(2,n):
    dp.append(
        choice_min(
            dp[i-1] + abs(h[i] - h[i-1]),
            dp[i-2] + abs(h[i] - h[i-2])
        )
    )

#print(dp)
print(dp[n-1])


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

const int N = 2e5 + 7;

int a[N];

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for(int i = k + 1; i <= n; i++) {
		cout << (a[i] <= a[i - k] ? "No" : "Yes") << endl;
	}
}

Measured memory_bytes: 4432
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

#define rep(i,n) for(int i = 0; i < (int)(n); i++)

int main(void){
    int N;
    cin>>N;
    string s=to_string(N);
    int digit=s.length();
    int ans=0;
    if(digit%2==0){
        rep(i,digit/2){
            ans*=100;
            ans+=9;
        }
    }else{
        rep(i,digit/2){
            ans*=100;
            ans+=9;
        }
        int temp=1;
        rep(i,digit-1) temp*=10;
        ans+=N-temp+1;
    }
    cout<<ans<<endl;
    return 0;
}

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

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

    sort(v.begin(), v.end());
    double ans = 1.0*(v[0] + v[1])/2;
    for(int i=2; i<N; i++){
        ans = (ans + v[i])/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
//srinivas
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// #include <ext/pb_ds/assoc_container.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
// using namespace __gnu_pbds;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define fr(x,in,n,r) for(x=in;x<n;x+=r)
#define ifr(x,n) for(x=0;x<n;x++)
#define dfr(x,n) for(x=n;x>=1;x--)
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define pof(a) pop_front(a)
#define pob(a) pop_back(a)
#define eb(a) emplace_back(a)
#define ef(a) emplace_front(a)
typedef long long ll;
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007
#define N 100001
ll dp[101][N];

ll fun(pll a[],ll i,ll n,ll w)
{
	if(w<0)
		return -a[i-1].ss;
	if(w==0)
		return 0;
	if(i==n)
		return 0;
	if(dp[i][w]==-1)
	dp[i][w]=max(fun(a,i+1,n,w),a[i].ss+fun(a,i+1,n,w-a[i].ff));
	return dp[i][w];
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt","r",stdin);
    ll n,w,i,j;
    cin>>n>>w;
	pll a[n];
	ifr(i,n)cin>>a[i].ff>>a[i].ss;
	ifr(i,N)
		ifr(j,101)
			dp[j][i]=-1;
	fun(a,0,n,w);
	cout<<dp[0][w]<<endl;
	return 0;
}


Measured memory_bytes: 79232
#include<bits/stdc++.h>
using namespace std;
#define INF (1<<20)
typedef pair<int,int> P;

int m,g;
int card[7],num[7];
int dp[10][10000];
int n;

int solve(int idx,int sum){
  if(sum == n) return 1;
  if(idx == m) return 0;
  if(sum > n) return 0;
  
  int ret = 0;
  for(int i=0;i<=num[idx];i++){
    ret += solve(idx+1,sum+(card[idx]*i));
  }
  return ret;
}

int main(){
  while(cin >> m , m){
    for(int i=0;i<m;i++){
      cin >> card[i] >> num[i];
    }
    cin >> g;
    for(int i=0;i<g;i++){
      cin >> n;
      cout << solve(0,0) << endl;
    }
  }
}

Measured memory_bytes: 1164
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

#define size_t int

int main(int argc, char const *argv[]) {
  int N;
  scanf("%d", &N);
  int p[N];
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &p[i]);
  }
  sort(p, p + N);
  int r = p[N-1] / 2;
  for (size_t i = 0; i < N-1; i++) {
    r += p[i];
  }
  printf("%d\n", r);
  return 0;
}


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

namespace AtCoder.Abc
{
    class QuestionC
    {
        static int max = 0;
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var inputIntArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            var n = inputIntArray[0];
            var m = inputIntArray[1];
            var q = inputIntArray[2];

            var abcd = new List<int[]>(q);
            for (int c = 0; c<q;c++)
            {
                var inputIArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
                abcd.Add(inputIArray);
            }

            max = 0;
            for (int c = 1; c<=m; c++)
            {
                Dfs(new List<int>() { c }, abcd, n, m);
            }

            Console.WriteLine(max);

            Console.Out.Flush();
        }

        static void Dfs(List<int> s, List<int[]> labcd, int n, int m)
        {
            if (s.Count == n)
            {
                var ans = GetTotal(labcd, s);
                max = Math.Max(max, ans);
                return;
            }
            s = new List<int>(s);
            s.Add(s.Last());
            while(s.Last() <= m)
            {
                Dfs(s,labcd, n, m);
                s[^1]++;
            }
        }

        static int GetTotal(List<int[]> labcd, List<int> s)
        {
            int total = 0;
            foreach(var abcd in labcd)
            {
                total += GetVal(abcd, s);
            }
            return total;
        }

        static int GetVal(int[] abcd, List<int> s)
        {
            if ((s[abcd[1]-1] - s[abcd[0]-1]) == abcd[2])
            {
                return abcd[3];
            }
            return 0;
        }
    }
}


Measured memory_bytes: 41336
#include <iostream>

using namespace std;

int main(void){

    long long int N, T;
    cin >> N >> T;

    long long int *event = new long long int[T];
    for(long long int i=0;i<T;i++) event[i] = 0;

    long long int l, r;
    for(long long int j=0;j<N;j++){
        cin >> l >> r;
        event[l] ++;
        event[r] --;
    }

    long long int now = 0, max = 0;

    for(long long int i=0;i<T;i++){
        now += event[i];
        if(now > max) max = now;
    }
    cout << max << endl;

    return 0;
}


Measured memory_bytes: 3888
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int dp[10][2];

void printD(){
  for(int i=0;i<10;i++){
    for(int j=0;j<=15;j++){
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
}

int main(){
  int n,m;
  string id;
  int even=1;
  cin>>n>>id>>m;
  if(n&1)even=0;
  int a[m];
  memset(dp,0,sizeof(dp));
  for(int i=0;i<m;i++)cin>>a[i];
  dp[0][0]=1;
  for(int i=0;i<n;i++){
    int val;
    for(int j=0;j<10;j++){
      if(id[i]!='*'){
	val=(id[i]-'0')<<even;
	val=val%10 + val/10;
	dp[(j+val)%10][(i&1)^1]=dp[j][i&1];
      }else{
	for(int k=0;k<m;k++){
	  val=a[k]<<even;
	  val=val%10 + val/10;
	  dp[(j+val)%10][(i&1)^1]+=dp[j][i&1];
	}
      }
    }
  for(int j=0;j<10;j++)dp[j][i&1]=0;

    even=!even;
  }
  //printD();
  cout << dp[0][n&1] << endl;
  return 0;
}

Measured memory_bytes: 1340
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <utility>
#include <set>
#include <queue>


typedef long long ll;


#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#define pb push_back
#define all(v) v.begin(),v.end()

using namespace std;


// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
//const int mod = 1000000007;
const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }


mint dp[3010][3010];

int main()
{
    ll a, b; cin >> a >> b;
    ll c, d; cin >> c >> d;
    ll x = a; ll y = b;
    dp[a][b] = 1;

  
     while (x < c) {
         dp[x + 1][y] = dp[x][y] * y;
         x++;
     }
       

    for (int y = b + 1; y < d + 1; y++) {
        dp[a][y] = dp[a][y - 1] * a;
        for (int x = a + 1; x < c + 1; x++) {
            //dp[x][y] = dp[x][y - 1] + dp[x-1][y] + dp[x-1][y-1]*(x - 1) * (y - 1);
            dp[x][y] = dp[x][y - 1] * x + dp[x - 1][y] * y - dp[x - 1][y - 1] * (x - 1) * (y - 1);
        }
    }

    


    //while (x < c or y < d) {

    //    for (int i = x + 1; i <= c; i++) {
    //        dp[i][y] = dp[i - 1][y] * y;
    //    }
    //    for (int i = y + 1; i <= d; i++) {
    //        dp[x][i] = dp[x][i - 1] * x;
    //    }
    //    dp[x + 1][y + 1] = dp[x][y] * (x * y + x + y);

    //    //if(x < c)
    //    //    dp[x + 1][y] = dp[x][y] * y ;
    //    //if (y < d)
    //    //    dp[x][y + 1] = dp[x][y] * x;
    //    //if (x < c and y < d)
    //    //    dp[x + 1][y + 1] = dp[x][y] * (x * y + x + y);
    //    if(x < c)
    //       x++;
    //    if(y < d)
    //       y++;
    //}

    cout << dp[c][d] << endl;
}

Measured memory_bytes: 74404
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut cumsum = a.clone();
    for i in 1..n {
        cumsum[i] += cumsum[i - 1];
    }

    let mut l = 0;
    let mut r = 2;

    let mut ans = std::i64::MAX;

    let mut v = vec![0; 4];
    for i in 0..n - 2 {
        if i == 0 {
            continue;
        }
        while (cumsum[l + 1] - (cumsum[i] - cumsum[l + 1])).abs()
            < (cumsum[l] - (cumsum[i] - cumsum[l])).abs()
            && l + 1 < i
        {
            l += 1;
        }
        v[0] = cumsum[l];
        v[1] = cumsum[i] - cumsum[l];

        while ((cumsum[n - 1] - cumsum[r + 1]) - (cumsum[r + 1] - cumsum[i])).abs()
            < ((cumsum[n - 1] - cumsum[r]) - (cumsum[r] - cumsum[i])).abs()
            && l + 1 < n - 1
        {
            r += 1;
        }
        v[2] = cumsum[r] - cumsum[i];
        v[3] = cumsum[n - 1] - cumsum[r];

        ans = min(ans, v.iter().max().unwrap() - v.iter().min().unwrap());
    }
    println!("{}", ans);
}


Measured memory_bytes: 8444
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

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

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
    using namespace std;

    int n;
    cin >> n;

    for (int i = 111; i <= 999; i += 111)
    {
        if (n <= i)
        {
            cout << i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World\n";
    }
    else{
        int a,b;
        cin >> a >> b;
        cout << a+b << endl;
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define MAX_N 8

vector<string> m(8);
bool visited[MAX_N][MAX_N];
int x, y;
int dx[] = {1,0,-1,0}, dy[] = {0,1,0,-1};

void dfs(int x, int y) {
    m[y][x] = '0';
    visited[y][x] = true;

    rep(i,4) {
        for(int n=1; n<=3; n++) {
            int nx = x + n * dx[i];
            int ny = y + n * dy[i];
            if(visited[ny][nx]) continue;
            if(0<=nx and nx<8 and 0<=ny and ny<8 and m[ny][nx]=='1')
                dfs(nx, ny);
        }
    }
}

int main() {
    int n; cin >> n;
    rep(data,n) {
        rep(i,8) cin>>m[i];
        memset(visited, 0, sizeof(visited));
        cin >> x >> y; x--; y--;
        dfs(x, y);

        printf("Data %d:\n", data+1);
        rep(i,8) cout << m[i] << "\n";
    }

    
    return 0;
}

Measured memory_bytes: 1216
def binarySearch(S, key):
	left = 0
	right = len(S)
	while left < right:
		mid = (left + right) / 2
		if S[mid] == key:
			return True		
		elif key < S[mid]:
			right = mid
		else:
			left = mid + 1
	return False


n = int(raw_input())
S = []
S = map(int, raw_input().split())

q = int(raw_input())
T = []
T = map(int, raw_input().split())
count = 0
for key in T:
	if binarySearch(S, key):
		count += 1
print count

Measured memory_bytes: 12880
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int a[30];

int main()
{
	
	string str;cin >>str;
	
	REP(i,str.size())
	{
		a[str[i] - 'a']++;
	}
	
	REP(i,27)
	{
		if(a[i] > 1)
		{
			cout << "no" << endl;
			return 0;
		}
	}
	cout << "yes" << endl;

	
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll H,W;
vector<string> S;
ll mk[111][111];

void bfs(ll h,ll w,ll a){
    char c = (a == 0 ? '.' : '#');
    queue<pll> q;
    q.push({h, w});
    while(q.size()){
        auto qa = q.front();
        q.pop();
        ll x, y;
        y = qa.first;
        x = qa.second;
        if(y+1<H&&c==S[y+1][x]){
            if(mk[y + 1][x]>mk[h][w] + a){
                mk[y + 1][x] = mk[h][w] + a;
                q.push({y+1,x});
            }
        }
        if(x+1<W&&c==S[y][x+1]){
            if (mk[y][x + 1] > mk[h][w] + a)
            {
                mk[y][x + 1] = mk[h][w] + a;
                q.push({y, x + 1});
            }
        }
    }
}

ll i, j, k;
int main(){
    scanf("%lld%lld", &H, &W);
    fornum(i,0,H){
        string s;
        cin >> s;
        S.push_back(s);
    }
    fornum(i,0,H){
        fornum(j,0,W){
            mk[i][j] = mk[i][j] = 1e9;
        }
    }
    mk[0][0] = 0;
    fornum(i,0,H){
        fornum(j,0,W){
            //printf("%lld ", mk[i][j]);
            if(i==0&&j==0){
                bfs(i, j, 1);
                if(S[i][j]=='#'){
                    mk[i][j] = 1;
                }
                bfs(i, j, 0);
                continue;
            }
            if(S[i][j]=='#'){
                bfs(i, j, 0);
            }else{
                bfs(i, j, 1);
            }
        }
        //printf("\n");
    }
    printf("%lld\n", mk[H - 1][W - 1]);

    return 0;
}

Measured memory_bytes: 384
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var xs = (1..n).map { readLine()!!.toLong() }.sorted().reversed()

    if (n % 2 == 0) {
        var ans: Long = 0
        (0 until (n/2 - 1)).forEach { ans += 2 * xs[it] }
        ans += xs[n/2 - 1]
        ans -= xs[n/2]
        ((n/2 + 1) until n).forEach { ans -= 2 * xs[it] }

        println(ans)
    } else {
        var ans1: Long = 0
        (0 until n/2 - 1).forEach { ans1 += 2 * xs[it] }
        ans1 += xs[n/2 - 1] + xs[n/2]
        ((n/2 + 1) until n).forEach { ans1 -= 2 * xs[it] }

        var ans2: Long = 0
        (0 until n/2).forEach { ans2 += 2 * xs[it] }
        ans2 -= xs[n/2] + xs[n/2 + 1]
        ((n/2 + 2) until n).forEach { ans2 -= 2 * xs[it] }

        println(Math.max(ans1, ans2))
    }
}

Measured memory_bytes: 50316
N=int(input())
List=list(map(int,input().split())) # 1行N列・・・Nは任意


List.sort()
sumList = [] # List初期化

for i in range(1,100):
	sumList.append(0)
	for j in List:
		sumList[i - 1] += (j - i)**2

sumList.sort()

print(sumList[0])

Measured memory_bytes: 3060
#include<stdio.h>
int main(void)
{
  int n,key,i,j;
  scanf("%d",&n);
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i<n-1)
      printf(" ");
  }
  printf("\n");
  for(j=1;j<n;j++){
    key=a[j];
    i=j-1;
    while(i>=0 && a[i]>key){
      a[i+1]=a[i];
      i--;
    }
    a[i+1]=key;
    
    for(i=0;i<n;i++){
      printf("%d",a[i]);
      if (i+1!=n)
	printf(" ");
    }
  printf("\n");
  }  
  return 0;
}

Measured memory_bytes: 604
#include <cstdio>

int main() {
    int n, m, a, b;
    scanf("%d%d%d%d", &n, &m, &a, &b);
    for (int i = 1; i <= n; i++, puts(""))
        for (int j = 1; j <= m; j++)
            putchar((j <= a) == (i <= b) ? '0' : '1');
    return 0;
}


Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<numeric>
#include<utility>

using namespace std;

int par[100001];
long long d[100001];

int find(int x){
  if(par[x]==x)return x;
  find(par[x]);
  d[x]+=d[par[x]];
  return par[x]=par[par[x]];
}

void unite(int a,int b,int w){
  find(a);
  find(b);
  d[par[b]]=w+d[a]-d[b];
  par[par[b]]=par[a];
}

int main(){
  for(int n,m;cin>>n>>m,n;){
    iota(begin(par),end(par),0);
    fill(begin(d),end(d),0);
    while(m--){
      char c;
      int a,b;
      cin>>c>>a>>b;
      if(c=='!'){
	int w;
	cin>>w;
	unite(a,b,w);
      }else{
	if(find(a)!=find(b)){
	  cout<<"UNKNOWN"<<endl;
	}else{
	  cout<<d[b]-d[a]<<endl;
	}
      }
    }
  }
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x;
    cin>>x;
    if(x==0)cout<<1<<endl;
    else cout<<0<<endl;

    return 0;
}

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

int main() {
  int64_t A, B, K;
  cin >> A >> B >> K;
  if(K >= A+B){
    cout << 0 << " " << 0 << endl;
  }
  else if(K > A){
    cout << 0 << " " << A + B - K << endl;
  }
  else{
    cout << A - K << " " << B << endl;
  }
}

Measured memory_bytes: 256
from collections import Counter
n=int(input())
V=list(map(int,input().split()))
E=Counter(V[::2]).most_common()+[(0,0)]
O=Counter(V[1::2]).most_common()+[(0,0)]
print(n-E[0][1]-O[0][1] if E[0][0]!=O[0][0] else n-max(E[0][1]+O[1][1],O[0][1]+E[1][1]))

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

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

  int X = 1; //掲示板の初期値
  for(int i=0; i<N ; i++){
    if(X<K){
      X *= 2;
    }
    else{
      X += K;
    }
  }

  cout << X << endl;
}


Measured memory_bytes: 256
from collections import Counter

def list2str(l):
    s = ""
    for c in l:
        s += c
    return s

n = int(input())

s = []
for _ in range(n):
    s.append(list2str(sorted(input())))

"""
# TLE
cnt = 0
for i in range(1, n):
    for j in range(i):
        if s[j] == s[i]:
            cnt += 1
"""

print(sum([x * (x - 1) // 2 for x in Counter(sorted(s)).values()]))


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

int main(){
  int N; cin >> N;
  int W[100];
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> W[i];
    sum+=W[i];
  }
  
  int a=1000000;
  int temp=0;
  for(int i=0; i<N; i++){
    temp+=W[i];
    a=min(a,abs((sum-temp)-temp));
  }
  cout << a << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.Char


main = do
    s <- getLine
    putStrLn $ ans s

ans :: String -> String
ans s = if (s !! 0) == 'A' && (length $ filter (== 'C') (reverse . drop 1 . reverse $ drop 2 s)) == 1 && all (\c -> c == 'A' || c == 'C' || isLower c) s then "AC" else "WA"


Measured memory_bytes: 380
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		long i = sc.nextLong();
		long money = 100;
		int count = 0;

		while (money < i) {
			money = (long) (money * 1.01);
			count++;
		}

		System.out.println(count);

	}

}

Measured memory_bytes: 35796