akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
ans_list=[]
S=[]
C=[]
ans=0

for i in range(M):
  s,c = map(int, input().split())
  S.append(s)
  C.append(c)
#print(S,C)
for n in range(1000):
  flag=0
  if len(str(n)) != N:
    continue
  for i, s in enumerate(S):
    n = str(n)
    if int(n[s-1]) == C[i]:
      continue
    else:
      flag=1
      break
  if flag == 0:
    ans_list.append(int(n))
#print(ans_list)
if len(ans_list) == 0:
  ans = -1
if ans != -1:
  ans=min(ans_list)
  
print(ans)
  


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 1000000007LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}
ll modfact(ll a){ll b=1;FOR(i,2,a)b=b*i%MOD;return b;}
ll modpow(ll a, ll n){ll b=1;while (n>0){if(n&1)b=b*a%MOD;a=a*a%MOD;n>>=1;}return b;}
ll modcomb(ll n, ll k){ll b=1;k=min(n-k,k);DOWN(i,n,n-k+1)b=b*i%MOD;return b*modpow(modfact(k),MOD-2)%MOD;}

int N, M;
int S[2001], T[2001];
ll dp[2001] = {0}, dp2[2001] = {0};

int main() {
    fastio();
    cin >> N >> M;
    REP(i, N) cin >> S[i];
    REP(j, M) cin >> T[j];
    REP(i, N) {
        REP(j, M) {
            if(S[i] == T[j]) {
                dp[j] = 1;
                if(j > 0) dp[j] += dp2[j-1];
            } else dp[j] = 0;
        }
        ll s = 0;
        REP(j, M) {
            s = (s + dp[j]) % MOD;
            dp2[j] = (dp2[j] + s) % MOD;
        }
    }
    cout << (dp2[M-1] + 1) % MOD << endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;
import java.math.BigDecimal;

public class Main{
    static BigDecimal b = new BigDecimal("10");
    static BigDecimal c = new BigDecimal("0");
	
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      while (sc.hasNext()) {
        BigDecimal a = sc.nextBigDecimal();
        BigDecimal total = new BigDecimal("0");
        if (a.equals(c)) {
          break;
        }
          while(!a.equals(c)) {
            total = total.add(a.remainder(b));
            a = a.divide(b,0,BigDecimal.ROUND_DOWN);
          }
          System.out.println(total);
          }
	}
}


Measured memory_bytes: 59424
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define pb push_back
# define endl '\n'
# define pi 3.14159265359
void yeah()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int main()
{
  yeah();
    ll n,i;
    cin>>n;
    i=n%10;
        if(i==0||i==1||i==6||i==8)
            cout<<"pon"<<endl;
        else if(i==3)
            cout<<"bon"<<endl;
            else
                cout<<"hon"<<endl;
}



Measured memory_bytes: 3636
#include <cmath>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <iomanip>
#include <bitset>

using namespace std;

typedef long long ll;

mt19937 rnd(228);

int mod;

inline int add(int a, int b)
{
    a += b;
    if (a >= mod) a -= mod;
    if (a < 0) a += mod;
    return a;
}

inline int mul(int a, int b)
{
    return (a * (ll) b) % mod;
}

const int N = 5000;

int c[N][N];
int dp[N][N];
int ans[N];
int pw[N];
int real_pw[N];

inline int bin(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n % 2 == 0)
        {
            a = mul(a, a);
            n /= 2;
        }
        else
        {
            res = mul(res, a);
            n--;
        }
    }
    return res;
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
#endif
    int n;
    cin >> n;
    cin >> mod;
    c[0][0] = 1;
    dp[0][0] = 1;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i + 1 < N)
            {
                dp[i + 1][j] = add(dp[i + 1][j], add(mul(dp[i][j], j), dp[i][j]));
            }
            if (i + 1 < N && j + 1 < N)
            {
                dp[i + 1][j + 1] = add(dp[i + 1][j + 1], dp[i][j]);
            }
            if (i)
            {
                c[i][j] = c[i - 1][j];
            }
            if (i && j)
            {
                c[i][j] = add(c[i][j], c[i - 1][j - 1]);
            }
        }
    }
    pw[0] = 1;
    real_pw[0] = 1;
    for (int i = 1; i <= n; i++)
    {
        pw[i] = (pw[i - 1] + pw[i - 1]) % (mod - 1);
        real_pw[i] = (real_pw[i - 1] + real_pw[i - 1]) % mod;
    }
    for (int i = n; i >= 1; i--)
    {
        int ret = bin(2, pw[n - i]);
        int sum = 0;
        int num = real_pw[n - i];
        for (int j = 0; j <= i; j++)
        {
            sum = add(sum, mul(bin(num, j), dp[i][j]));
        }
        ans[i] = mul(c[n][i], mul(ret, sum));
        for (int j = i + 1; j <= n; j++)
        {
            ans[i] = add(ans[i], -mul(ans[j], c[j][i]));
        }
    }
    int result = bin(2, pw[n]);
    for (int i = 1; i <= n; i++)
    {
        result = add(result, -ans[i]);
    }
    cout << result << '\n';
}


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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

void Main(){
    char c; cin >> c;
    if('A'<=c && c<='Z') cout << "A" << en;
    else cout << "a" << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3636
N, W = list(map(int, input().split()))

weight = []
value = []

for i in range(N):
    w, v = list(map(int, input().split()))
    weight.append(w)
    value.append(v)

def dfs(index, v, w):
    x = 0
    if (index >= N):
        return v
    if (w + weight[index] <= W):
        x = dfs(index+1, v+value[index], w+weight[index])
    y = dfs(index+1,v,w)

    return max(x, y)


# ans = dfs(0, 0, 0)

dp = []

for i in range(N+1):
    dp.append([])
    for j in range(W+1):
        dp[i].append(0)
    
# max value = dp[何個まで見たか][現在の重さ]
for i in range(N):
    for j in range(W+1):
        # if j+weight[i] <= W:
        #     dp[i+1][j+weight[i]] = max(dp[i][j+weight[i]], dp[i][j]+value[i])
        # else:
        #     dp[i+1][j] = dp[i][j]
        # if 
        if j >= weight[i]:
            dp[i+1][j] = max(dp[i][j-weight[i]]+value[i], dp[i][j])
        else:
            dp[i+1][j] = dp[i][j]


print(dp[N][W])


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

int main() {

    int n, k;

    cin >> n >> k;

    vector<int> v(n);

    for(int i = 0; i < n; ++i)
        cin >> v[i];

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

    int sum = 0;

    for(int i = 0; i < k; ++i)
        sum += v[i];

    cout << sum << endl;

    return 0;

}

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

string str;

int cal(int x, int a0, int a1, int a2, int a3, int a4, int a5, int a6){
	int z = 0;
	z += ((x&(1<<a0))!=0)<<0;
	z += ((x&(1<<a1))!=0)<<1;
	z += ((x&(1<<a2))!=0)<<2;
	z += ((x&(1<<a3))!=0)<<3;
	z += ((x&(1<<a4))!=0)<<4;
	z += ((x&(1<<a5))!=0)<<5;
	z += ((x&(1<<a6))!=0)<<6;
	return str[z]-'0';
}

void solve(){
	bool ok = true;
	for(int i = 0; i < (1<<19); i++){
		int j = 0;
		j += (cal(i,0,1,3,4,5,8,9)<<0);
		j += (cal(i,1,2,4,5,6,9,10)<<1);
		j += (cal(i,3,4,7,8,9,12,13)<<2);
		j += (cal(i,4,5,8,9,10,13,14)<<3);
		j += (cal(i,5,6,9,10,11,14,15)<<4);
		j += (cal(i,8,9,12,13,14,16,17)<<5);
		j += (cal(i,9,10,13,14,15,17,18)<<6);
		if(cal(i,4,5,8,9,10,13,14) != cal(j,0,1,2,3,4,5,6)){
			ok = false;
			break;
		}
	}
	if(ok) puts("yes");
	else puts("no");
}

int main(){
	while(cin >> str,str[0]!='#'){
		solve();
	}
}

Measured memory_bytes: 1156
#include"bits/stdc++.h"
using namespace std;
int main(void){
  int n,m,p;
  string s;
  bool ac[100000];
  int AC=0,WA[100000],pen=0;
  cin>>n>>m;
  for(int i=0;i<n;++i){
    ac[i]=false;
    WA[i]=0;
  }
  for(int i=0;i<m;++i){
    cin>>p>>s;
    if(!ac[p-1]&&s=="WA"){
      ++WA[p-1];
    }
    if(s=="AC"&&!ac[p-1]){
      ac[p-1]=true;
      ++AC;
      pen+=WA[p-1];
    }
  }
    cout<<AC<<" "<<pen;
}


Measured memory_bytes: 768
#!/usr/bin/env ruby

# Generated by AtcoderGreedy on 2018-06-03
# AGC025 A

# my lib

module Enumerable
  # work just like String#split,
  # except this method does not use regex match
  # but check whether yield succeeds or not.
  def split
    current = nil
    ret = []
    each do |elem|
      if yield elem
        if current
          ret << current
          current = nil
        end
      elsif current
        current << elem
      else
        current = [elem]
      end
    end
    ret << current if current
    ret
  end
end

class Array
  # truncate tail, opposite of drop
  def clip(amount = 1)
    if amount < 0
      raise ArgumentError, "amount == #{amount}, cannot be negative!"
    end
    take_amount = size - amount
    take_amount < 0 ? [] : take(take_amount)
  end
end

def n_choose_k(n, k)
  return 0 unless (0..n).cover? k
  result = 1
  1.upto(k) do |d|
    result *= n
    result /= d
    n -= 1
  end
  result
end

# end of lib

# Your code here

N = gets.chomp.to_i

def sum_of_each_digits(n)
  ret = 0
  while n > 0
    ret += n % 10
    n /= 10
  end
  ret
end

ret = (1..N-1).map do |i|
  sum_of_each_digits(i) +
    sum_of_each_digits(N-i)
end.min

puts ret


Measured memory_bytes: 2684
#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
int main(){
    long n,ans=0;
    vector<long> w;
    char s[200010];
    scanf("%s",s);
    n=strlen(s);
    for(long i=0;i<n;i++){
        if(s[i]=='W'){
            w.push_back(i);
        }
    }
    for(long i=0;i<w.size();i++){
        ans+=w[i]-i;
    }
    printf("%ld\n",ans);
}

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

int main (){
	int cnt=0,n,a[55];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		if(a[i]!=i)cnt++;
    }
    if(cnt>=3)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

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

class Program
{
    static void Main(string[] args)
    {
        var a = new int[5];
        for (int i = 0; i < 5; i++)
        {
            a[i] = int.Parse(Console.ReadLine());
        }
        int k = int.Parse(Console.ReadLine());
        Console.WriteLine(a.Max() - a.Min() <= k ? "Yay!" : ":(");
    }
}

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

using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ldouble = long double;
 
const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s) cout << fixed << setprecision(10) << s << endl;


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

    if (b - a <= 0)
    {
        println("delicious");
    }
    else if (0 < b - a && b - a <= x)
    {
        println("safe");
    }
    else
    {
        println("dangerous");
    }
    
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"

void check(){
    if(false)
    {
        cout<<"check"<<endl;
    }
}
void solve(){
    
   long long n;
   cin>>n;
   string s="ACL",ans="";
   while(n--){
       ans+=s;
   }
   cout<<ans;








    
    
    
    
}






int32_t main(){
    solve();
}

Measured memory_bytes: 3628
import java.util.*;

public class Main {
  public static void main(String[] args) {
	  Scanner sc = new Scanner(System.in);
	  int A = Integer.parseInt(sc.next());
	  int B = Integer.parseInt(sc.next());
	  String[] S = sc.next().split("-");
	  
	  if(S.length == 2) {
		  if(S[0].length() == A && S[1].length() == B) {
			  System.out.println("Yes");
			  sc.close();
			  System.exit(0);
		  }
		  	
	  }
	  
	  System.out.println("No");
	  sc.close();
	  
  }
}


Measured memory_bytes: 23380
use std::cmp::*;
use std::io::*;

fn check(n: usize, x: usize) -> bool {
    let mut m = n;
    while m % x == 0 {
        m /= x;
    }
    (m - 1) % x == 0
}

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();

    let mut x = 2;
    let mut ans = 1;
    while x * x <= n {
        if n % x == 0 {
            ans += check(n, x) as usize;
            if x != n / x {
                ans += check(n, n / x) as usize;
            }
        }
        x += 1;
    }

    let m = n - 1;
    let mut y = 2;
    if m > 1 {
        ans += 1;
    }
    while y * y <= m {
        if m % y == 0 {
            ans += 1;
            if y != m / y {
                ans += 1
            }
        }
        y += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2136
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
#include<map>
#include<iomanip>

using namespace std;
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define RED 3
int N;
int ans=0;
vector <int> A;

void dfs(){
 bool check7=false;
 bool check5=false;
 bool check3=false;
 long long int number=0;
 long long int digit=1;

 for(int i=A.size()-1; i>=0; i--){
  number+=(A[i]*digit); 
  digit*=10;
  if(A[i]==7)check7=true;
  else if(A[i]==5)check5=true;
  else if(A[i]==3)check3=true;
 }
 if(number>N)return ;
 else if(check7 && check5 && check3==true)ans++;
  
 A.push_back(7);
 dfs();
 A.pop_back();

 A.push_back(5);
 dfs();
 A.pop_back();
 
 A.push_back(3);
 dfs();
 A.pop_back();
 return ;
}
int main(void){
 cin>>N;
 dfs();

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


Measured memory_bytes: 256
#include <iostream>
#include <map>

int main()
{
    std::map<int, int> s;
    for (int i = 0; i < 6; i++) {
        int a; std::cin >> a;
        s[a]++;
    }
    bool b = true;
    for (const auto& ss: s) {
        if (ss.second >= 3) {
            b = false;
        }
    }
    std::cout << (b?"YES":"NO") << std::endl;
    return 0;
}


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

int memo[10000001];

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(m);
  for (auto &e : a)
    cin >> e;
  for (auto &e : b)
    cin >> e;
  a.push_back(0), b.push_back(0);
  sort(a.begin(), a.end(), greater<int>());
  sort(b.begin(), b.end(), greater<int>());

  ll ans = 1;
  int i = 0, j = 0;
  for (int x = n * m; x > 0; --x)
  {
    if (a[i] > x || b[j] > x)
    {
      ans = 0;
      break;
    }
    else if (a[i] == x && b[j] == x)
      i++, j++;
    else if (a[i] == x)
    {
      ans = (ans * j) % MOD;
      i++;
    }
    else if (b[j] == x)
    {
      ans = (ans * i) % MOD;
      j++;
    }
    else
      ans = (ans * (i * j - (n * m - x))) % MOD;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <list>
#include <iomanip>
#include <vector>
#include <functional>
#include <algorithm>
#include <cstdio>
#include <random>
#include <ctime>
#include <cstdlib>
#include <unordered_map>
#include <string.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef pair<int, int> Pint;
typedef pair<ll, ll> Pll;
#define rep(begin, i, end) for (ll i = begin; i < (ll)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll N;
    cin >> N;
    ll t, x, y, t_b = 0, x_b = 0, y_b = 0;
    rep(0, i, N)
    {
        cin >> t >> x >> y;
        ll dis = abs(x - x_b) + abs(y - y_b);
        ll time = t - t_b;
        if (time < dis || (dis - time) % 2 != 0)
        {
            cout << "No" << endl;
            return 0;
        }
        t_b = t;
        x_b = x;
        y_b = y;
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3624
import java.util.*;

class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        final int N = Integer.parseInt(sc.next());
        final int D = Integer.parseInt(sc.next());
        final int A[][] = new int[N][D];
        for (int i=0; i<N; i++) {
            for (int j=0; j<D; j++)
                A[i][j] =  Integer.parseInt(sc.next());
        }
        sc.close();

        int cnt = 0;
        long sum = 0;
        for (int i=0; i<N; i++) {
            for (int j=i+1; j<N; j++) {
                sum = 0;
                for (int k=0; k<D; k++) {
                    sum += Math.pow(A[i][k]-A[j][k], 2);
                }
                int d1 = (int)Math.sqrt(sum);
                if ((int)sum==(int)Math.pow((double)d1, 2))
                    cnt++;
            }
        }

        System.out.println(cnt);
    }
}

Measured memory_bytes: 21844
import math
N = int(input())
ans = []
ans_len = 1
ans.append(2)
for i in range(1, 55556):
    flag = 0
    if i % 10 != 7:
        continue
    for j in range(2, math.ceil(math.sqrt(i))):
        if i % j == 0:
            flag = 1
            break
    if flag == 0:
        ans.append(i)
        ans_len += 1
        if ans_len == N:
            break

print(*ans, sep=" ")


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

using namespace std;
inline int popcnt(int bits) {
  return __builtin_popcount(bits);
}

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

  int n;
  cin >> n;
  vector<int> opens(n);
  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    for (int j = 0; j < 10; ++j) {
      tmp <<= 1;
      int t;
      cin >> t;
      tmp += t;
    }
    opens[i] = tmp;
  }
  vector<vector<int>> profits(n);
  for (int i = 0; i < n; ++i) {
    profits[i].resize(11);
    for (int j = 0; j < 11; ++j) {
      cin >> profits[i][j];
    }
  }

  int64_t max_profit = INT64_MIN;
  for (int i = 1; i < 1024; ++i) {
    vector<int> matches(n);
    for (int j = 0; j < n; ++j) {
      matches[j] = popcnt(opens[j] & i);
    }
    int64_t prof = 0;
    for (int j = 0; j < n; ++j) {
      prof += profits[j][matches[j]];
    }
    max_profit = max(max_profit, prof);
  }
  cout << max_profit << "\n";
}


Measured memory_bytes: 256
s = list(input())

x = ord('a')
n = len(s)
ans = n
for i in range(26):
    z = chr(x + i)
    t = [] + s
    for j in range(n):
        if t.count(z) == n:
            ans = min(j, ans)
        for k in range(len(s) - 1):
            if t[k] == z or t[k+1] == z:
                t[k] = z
        t[n-1-j] = z

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#define N 100

int main()
{
  int num,i,v,j,k,A[1000];
  scanf("%d",&num);         //数列の長さ

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


  for(i=0;i<num;i++)
    {
      v = A[i];
      j = i-1;
      while(j>=0 && A[j]>v)
	{
	  
	  A[j+1] = A[j];
	  j--;
	  A[j+1] = v;
	  
	}
      for(k=0;k<num;k++)
	{
	  if(k == num-1)printf("%d",A[k]);
	  else printf("%d ",A[k]);
	}
     
        printf("\n");
    
    }
  
  
  return 0;
}



Measured memory_bytes: 2128
import fractions
import functools

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N, K = ZZ()
    A = ZZ()
    g = functools.reduce(fractions.gcd, A)
    print('POSSIBLE' if K <= max(A) and K%g == 0 else 'IMPOSSIBLE')
    return

if __name__ == '__main__':
    main()



Measured memory_bytes: 16064
from collections import deque

d = deque(input())
w = input()
ac = False
for i in range(len(d)):
  word = ""
  a = d.pop()
  d.appendleft(a)
  word = "".join(d)
  if word == w:
    ac = True
    break
if ac:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3316
N = int(input())
H_ = list(map(int,input().split()))
count = 0
H_ = H_[::-1]
for i in range(N):
  flg = 0
  for j in range(i,N):
    if H_[i] < H_[j]:
      flg = 1
  if flg == 0:
    count += 1
print(count)

Measured memory_bytes: 3060
package main

import "fmt"

func main() {
    var N int
    fmt.Scan(&N)
    ans := 0
    for i := 0; i < N; i++ {
        var l, r int
        fmt.Scan(&l)
        fmt.Scan(&r)
        ans += r - l + 1
    }
    fmt.Println(ans)
}

Measured memory_bytes: 640
import math
def calc_combi(n,m):
    if n<=1:
        return 0
    return math.factorial(n)/(math.factorial(m)*(math.factorial(n-m)))
n,m=map(int,input().split())
ans=int(calc_combi(n,2)+calc_combi(m,2))
print(ans)

Measured memory_bytes: 3060
# Problem https://atcoder.jp/contests/abc051/tasks/abc051_b
# Ruby 1st Try
k,s = gets.chomp().split(' ').map(&:to_i)
answer = 0
for j in 0..k do
    for m in 0..k do
        ncheck = s - j - m
        if 0 <= ncheck and ncheck <= k
            answer = answer + 1
        end
    end
end
puts(answer)

Measured memory_bytes: 1788
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner sc = new Scanner(System.in);
      	int result = 0;
      	for (int i = 0; i < 3; i++) result += sc.nextInt();
      	if (result < 22) System.out.println("win");
      	else System.out.println("bust");
        
    }
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
 
int main() {
  std::ios::sync_with_stdio(false);
  long long N;
  std::cin >> N;
  std::string str;
  while (N > 0) {
    N -= 1;
    str += 'a' + N % 26;
    N /= 26;
  }
  std::reverse(str.begin(), str.end());
  std::cout << str;
  return 0;
}

Measured memory_bytes: 3588
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i=1; i<=9; i++) {
    for(int j=1; j<=9; j++) {
      if(i*j==n) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}


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

vector<int> biconnected_component(const graph& G) {
	int n = G.size(), idx = 0, t = 0, k = 0;
	vector<int> ord(n, -1), stk, rts(n), cmp(n);
	vector<bool> onS(n);
	function<void(int, int)> dfs = [&](int v, int u) {
		ord[v] = idx++;
		stk.push_back(v);
		onS[v] = true;
		rts[t++] = v;
		for (int w : G[v]) {
			if (ord[w] == -1) dfs(w, v);
			else if (u != w && onS[w])
				while (ord[rts[t - 1]] > ord[w]) --t;
		}
		if (v == rts[t - 1]) {
			while (true) {
				int w = stk.back(); stk.pop_back();
				onS[w] = false; cmp[w] = k;
				if (v == w) break;
			}
			--t;
			++k;
		}
	};
	for (int u = 0; u < n; ++u) {
		if (ord[u] == -1) dfs(u, -1);
	}
	return cmp;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m;
	cin >> n >> m;
	graph G(n);
	vector<pair<int, int>> es;
	for (int i = 0; i < m; i++) {
		int s, t;
		cin >> s >> t;
		if (s > t) swap(s, t);
		G[s].push_back(t);
		G[t].push_back(s);
		es.emplace_back(s, t);
	}
	auto bc = biconnected_component(G);
	sort(es.begin(), es.end());
	for (auto& p : es) if (bc[p.first] != bc[p.second]) {
		printf("%d %d\n", p.first, p.second);
	}
	return 0;
}



Measured memory_bytes: 4876
N = int(input())
s = [input() for i in range(N)]

enda = 0
startb = 0
btoa = 0
ans = 0

for i in s:
    if i[0] == 'B' and i[-1] == 'A':
        btoa += 1
    elif i[-1] =='A':
        enda += 1
    elif i[0] == 'B':
        startb += 1
    ans += i.count('AB')

# print('-a:', enda, 'b-:', startb, 'b-a:', btoa, 'ans:',ans)

if btoa >= 1:
    ans += btoa - 1
    btoa = 1
    if enda > 0 and startb > 0:
        ans += 2
        btoa = 0
        enda -= 1
        startb -= 1
    elif enda > 0:
        ans += 1
        enda -= 1
    elif startb > 0:
        ans += 1
        startb -= 1

if enda < startb:
    enda, startb = startb, enda
ans += startb
enda -= startb
startb = 0

print(ans)

Measured memory_bytes: 3700
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int N, M, ans = 0;
vector<vector<int>> v;

void dfs(int i, int p, vector<bool> vis) {
  if (i == N - 1) {
    ans++;
    return;
  }

  for (auto vv : v[p]) {
    vector<bool> viss = vis;
    if (viss[vv])
      continue;
    viss[vv] = true;
    dfs(i + 1, vv, viss);
  }
}

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

  cin >> N >> M;
  v.resize(N);
  rep(i, 0, M) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }

  vector<bool> vis(N, false);
  vis[0] = true;
  dfs(0, 0, vis);
  cout << ans << endl;
}


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

int main()
{
    int size, number, num_swap = 0, count = 0;
    cin >> size;
    for (int i = 1; i <= size; i++)
    {
        cin >> number;
        if(number!= i)
            count++;
    }
    if(count <=2)
        cout<<"YES" << endl;
    else
        cout<<"NO" << endl;
}

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

using namespace std;
#define int long long int
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define vi vector <int>
#define sz(s) (int)s.size()
#define pii pair<int,int>
#define piii pair< int,pair<int,int> >
#define tiii tuple <int,int,int>
#define debug(x) cout<<#x<<" "<<x<<endl;
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(v) v.rbegin(),v.rend()
#define endl '\n'
#define matrix vector <vector <int> >
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define NAYAN freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define N 3005
#define mod 1000000007
#define mod2 998244353
#define inf 1e17


double p[N];
int n;

double dp[N][N];


int32_t main()  
{
    boost
    // #ifndef ONLINE_JUDGE 
    // NAYAN
    // #endif

    cin >> n;
    int i,j;
    for(i=1;i<=n;i++)
    {
    	cin >> p[i];
    }

    dp[0][0]=1;

    dp[1][0]=1-p[1];
    dp[1][1]=p[1];

    for(i=2;i<=n;i++)
    {
    	for(j=0;j<=i;j++)
    	{
    		
    		dp[i][j]=dp[i-1][j]*(1.0-p[i]);
    		if(j>0)
    			dp[i][j]+=(dp[i-1][j-1]*p[i]);
    	}
    }

    double ans=0;
    for(i=0;i<=n;i++)
    { 
    	j=n-i;
    	if(i>j)
    	{
    		ans+=dp[n][i];
    	}

    }

    cout << fixed << setprecision(10) <<  ans <<  endl;


    
   

    
}

Measured memory_bytes: 49960
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int s[n];
	for(int i=0;i<n;i++)
		cin >> s[i];
	int q;
	cin >> q;
	int t[q];
	for(int i=0;i<q;i++)
		cin >> t[i];
	int ans=0;
	for(int i=0;i<q;i++){
		for(int j=0;j<n;j++){
			if(s[j]==t[i]){
				ans++;
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  int ans = 0;
  for (int i = 2; i < n; i++) {
    if (s[i - 2] == 'A' && s[i - 1] == 'B' && s[i] == 'C') {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  vector<int> c(n);
  rep(i,n) cin >> c[i];
  sort(all(c));
  ll sum = 0;
  rep(i, k) sum += c[i];
  cout << sum << endl;
  return 0;
}

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

int main() {
	int s; cin >> s;
	set<int> st;
	st.insert(s);
	int n = 1;
	while(true) {
		int fa;
		if (s % 2 == 0) {
			fa = s / 2; 
		} else {
			fa = 3 * s + 1;
		}
		++n;
		s = fa;
		if (st.find(fa) == st.end()) {
			st.insert(fa);
		} else {
			break;
		}
	}
	cout << n << endl;
	return 0;
}

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

int D,G;
int p[10],c[10];

int solve(bool comp[], int score){
  int res = 0;
  for(int i=0;i<D;i++)
    if(comp[i]) res += p[i];
  if(score >= G) return res;
  int v = D - 1;
  while(comp[v]) v--;
  for(int i=0;i<p[v]-1;i++){
    score += v+1;
    res++;
    if(score >= G) return res;
  }
  return 1e5;
}

int dfs(bool comp[], int score, int cur){
  if(cur == D)
    return solve(comp, score);
  bool nxcomp[10] = {};
  for(int i=0;i<D;i++)
    if(comp[i]) nxcomp[i] = true;
  int ret = dfs(nxcomp, score, cur + 1);
  nxcomp[cur] = true;
  int ret2 = dfs(nxcomp, score + p[cur]*(cur+1) + c[cur], cur + 1);
  return min(ret, ret2);
}

int main(){
  cin>>D>>G;
  G /= 100;
  for(int i=0;i<D;i++)
    cin>>p[i]>>c[i];
  for(int i=0;i<D;i++)
    c[i] /= 100;
  bool comp[D] = {};
  cout<<dfs(comp, 0, 0);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // K
    int N;
    cin >> N;
    if (N % 1000 != 0){
        cout << 1000 - N % 1000 << endl;
    }
    else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 3636
IDENTIFICATION DIVISION.
PROGRAM-ID. PROGRAM_ID.

DATA DIVISION.
WORKING-STORAGE SECTION.
01 N          PIC 9(10).
01 q          PIC 9(10).
01 ans        PIC 9(1)V9(10).

PROCEDURE DIVISION.
  ACCEPT N.
  COMPUTE q = (N + 1) / 2.
  COMPUTE ans = q / N.
  DISPLAY ans.
  STOP RUN.


Measured memory_bytes: 3872
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define P pair<ll, ll>
using ll = long long;
#define ALL(v) (v).begin(),(v).end()
#define endl "\n"
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define co(x) cout << x << endl
#define coel cout << endl
#define pb push_back
#define sz(v) ((ll)(v).size())
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define pp pair<ll, pair<ll, ll>> 




////////////////////////////////////////////////////////

const int MAX = 1000000;
// const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[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 x, y; cin >> x >> y;
    if((x*2 < y) || (y*2 < x)){
        co(0);
        return 0;
    }
    if((x+y)%3 != 0){
        co(0);
        return 0;
    }
    ll s = x+y;
    ll x1 = s/3*2;
    ll n = s/3 + 1;
    ll ans = COM(n-1, x1-x);
    co(ans);


    return 0;
}


Measured memory_bytes: 23680
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

string s;
int n;
int pos[100100];


int solve(int i) {
   if (i == n) return 1;
   if (pos[i] != -1) return pos[i];
   pos[i] = 0;

   if (i+4 < n && s.substr(i, 5) == "dream") {
      if (solve(i+5) == 1) {
         pos[i] = 1;
      }
   }

   if (i+6 < n && s.substr(i, 7) == "dreamer") {
      if (solve(i+7) == 1) {
         pos[i] = 1;
      }
   }

   if (i+4 < n && s.substr(i, 5) == "erase") {
      if (solve(i+5) == 1) {
         pos[i] = 1;
      }
   }

   if (i+5 < n && s.substr(i, 6) == "eraser") {
      if (solve(i+6) == 1) {
         pos[i] = 1;
      }
   }

   return pos[i];
}

int main() {
   cin >> s;
   n = s.length();
   memset(pos, -1, sizeof pos);
   if (solve(0)) cout << "YES" << endl;
   else cout << "NO" << endl;
}


Measured memory_bytes: 2432
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define rgi register int
#define rgl register long long
#define il inline

using namespace std;

const int oo = 0x3f3f3f3f;
const int N = 1e5 + 10;

int n, last, ans = -oo, tmp;
int h[N];

il int read()
{
	rgi x = 0, f = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x; 
}

int main()
{
	cin >> n;
	for(rgi i = 1; i <= n; ++i)
		cin >> h[i];
	for(rgi i = 1; i <= n; ++i)
	{
		if(h[i] <= last)
		{
			last = h[i];
			tmp++;
		}
		else
		{
			last = h[i];
			ans = max(ans, tmp);
			tmp = 1;
		}
	}
	ans = max(ans, tmp);
	cout << ans - 1;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int64_t pattern(int64_t n){
    if(n==1){
        return 1;
    }
    return n * (n-1) / 2;
}

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int n;
    cin >> n;
    vector<string> s(n);
    string s_in;
    for(int i=0; i<n; i++){
        cin >> s_in;
        sort(s_in.begin(), s_in.end());
        s.at(i) = s_in;
    }
    sort(s.begin(), s.end());
    int counter = 0;
    int64_t res = 0;
    for(int i=0; i<n-1; i++){
        if(s.at(i) == s.at(i+1)){
            counter++;
        } else if(counter != 0){
            res += pattern((int64_t)counter + 1);
            counter = 0;
        }
    }
    if(counter != 0){
        res += pattern((int64_t)counter + 1);
    }
    cout << res << endl;
}


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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;
    int max = A;
    int min1 = B, min2 = C;
    if (B > max)
    {
        min1 = max;
        max = B;
    }
    if (C > max)
    {
        min2 = max;
        max = C;
    }

    cout << max * 10 + min1 + min2 << endl;
    return 0;
}


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
MOD=10**9+7

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

dp=[0]*(2*k+1)
dp[0]=1
for a in aa:
    l=k-a
    s=sum(dp[l:k+1])%MOD
    for i in range(k,-1,-1):
#        print(s,i,l)
        s-=dp[i]
        s%=MOD
        dp[i] += s
        l-=1
        s+=dp[l]
#    print(dp)
        
    
print(dp[k]%MOD)


Measured memory_bytes: 46616
S=input()

tmp1=int(S[0:2])
tmp2=int(S[2:4])

if(1 <= tmp1 <= 12 and 1 <= tmp2 <= 12):
    print("AMBIGUOUS")
elif((1 <= tmp1 <= 12)==False and  1 <=tmp2 <= 12):
    print("YYMM")
elif((1 <= tmp2 <= 12)==False and  1 <=tmp1 <= 12):
    print("MMYY")
else:
    print("NA")


Measured memory_bytes: 3060
import java.io.*;

public class Main{
	public static void main(String[] args){
		String s;
		int d,n,number,x;
		int sum=0;
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		try{
			while((s=r.readLine()) !=null){
				x=0;
				d=Integer.parseInt(s);
				number=600/d;
				for(int i=0;i<number;i++){
					sum +=d*x*x;
					x +=d;
				}
				System.out.println(sum);
				sum=0;
				continue;
			}
		}catch(IOException e){
			System.out.println(e);
		}
	}
}

Measured memory_bytes: 16864
#include<stdio.h>
int main(void){
    int n;
    int a[100000];
    scanf("%d",&n);
    int max=0;
    for(int i=0;i<n;i++){
        scanf("%d",&a[i]);
        if(max<a[i]){
            max=a[i];
        }
    }
    
    int cost;
    int ans=99999999;
    for(int i=-100;i<=100;i++){
        cost=0;
        for(int j=0;j<n;j++){
            cost+=(a[j]-i)*(a[j]-i);
        }
        //printf("i=%d cost=%d\n",i,cost);
        if(ans>cost){
            ans=cost;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.*;

class Node {
    public int parent;
    public int left;
    public int right;
}

public class Main implements Runnable {
    static final int MAX = 100005;
    static final int NIL = -1;
    Node[] T = new Node[MAX];
    int[] D = new int[MAX];

    public static void main(String[] args) throws Exception {
        new Thread(null, new Main(), "", 16 * 1024 * 1024).start();
    }

    public void run() {
        // 入力
        int nodeTotalCount = 0;
        int id;
        int degree;
        int child;
        int sibling = 0;
        int root = 0;
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            nodeTotalCount = Integer.parseInt(br.readLine());
            for (int i = 0; i < nodeTotalCount; i++) {
                T[i] = new Node();
                T[i].parent = T[i].left = T[i].right = NIL;
            }
            for (int i = 0; i < nodeTotalCount; i++) {
                String line = br.readLine();
                String[] tokens = line.split(" ");
                id = Integer.parseInt(tokens[0]);
                degree = Integer.parseInt(tokens[1]);
                for (int j = 0; j < degree; j++) {
                    child = Integer.parseInt(tokens[2 + j]);
                    if (j == 0) {
                        // leftはT[i]の子
                        T[id].left = child;
                    } else {
                        // rightはT[sibling]の兄弟
                        T[sibling].right = child;
                    }
                    sibling = child;
                    T[child].parent = id;
                }
            }

            for (int i = 0; i < nodeTotalCount; i++) {
                if (T[i].parent == NIL) {
                    root = i;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 深さ
        setDepth(root, 0);

        // 出力
        for (int i = 0; i < nodeTotalCount; i++) {
            print(i);
        }
    }

    void print(int id) {
        StringBuilder sb = new StringBuilder();
        sb.append("node ").append(id);
        sb.append(": parent = ").append(T[id].parent);
        sb.append(", depth = ").append(D[id]).append(", ");

        if (T[id].parent == NIL) {
            sb.append("root, [");
        } else if (T[id].left == NIL) {
            sb.append("leaf, [");
        } else {
            sb.append("internal node, [");
        }

        for (int i = 0, child = T[id].left; child != NIL; i++, child = T[child].right) {
            if (i > 0) {
                sb.append(", ");
            }
            sb.append(child);
        }
        sb.append("]");
        System.out.println(sb.toString());
    }

    void setDepth(int id, int depth) {
        D[id] = depth;
        if (T[id].right != NIL) {
            setDepth(T[id].right, depth);
        }
        if (T[id].left != NIL) {
            setDepth(T[id].left, depth + 1);
        }
    }
}



Measured memory_bytes: 109876
ans=Array.new(4).map{Array.new(3).map{|aa|Array.new(10,0)}}
gets.to_i.times{n=gets.chomp.split.map(&:to_i)
ans[n[0]-1][n[1]-1][n[2]-1]+=n[3]
}
4.times{|i|ans[i].map{|e|puts " #{e.join(' ')}"}
puts "#"*20 if i!=3
}


Measured memory_bytes: 6900
import collections

N = int(input())
xy = [list(map(int, input().split())) for _ in range(N)]
ans = N
if N == 1:
  print(1)
  exit()
pq = []

for i in range(N):
  for j in range(N):
    pq.append((xy[j][0]-xy[i][0], xy[j][1]-xy[i][1]))
c = collections.Counter(pq)
if c.most_common()[0][0] == (0,0):
  ans -= c.most_common()[1][1]
else:
  ans -= c.most_common()[0][1]
print(ans)

Measured memory_bytes: 3956
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace contest18
{
    class Program
    {
        static void Main(string[] args)
        {
            List<int> nums = new List<int>();

            var read_line_origin = Console.ReadLine();
            string[] read_line = read_line_origin.Split();

            foreach(string read in read_line)
            {
                int num = int.Parse(read);
                nums.Add(num);
            }

            nums.Sort();
            nums.Reverse();

            for(int i = 0; i < 4; i++)
            {
                Console.Write("{0} ",nums[i]);
            }
            Console.WriteLine("{0}", nums[4]);
            //            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 5800
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__;
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int A,B; cin >> A >> B;
    bool f=false;
    for(int i=1;i<=10000;i++){
        int x=i*0.08;
        int y=i*0.1;
        if(A==x && B==y){
            f=true;
            cout << i << endl;
            break;
        }
    }
    if(!f){
        cout << -1 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/C-GuessTheNumber.py
#
k, s = map(int, input().split())
pattern = 0

if s == 0 or s == 1:
    print(1)
    exit()

if s <= k:
    print((s+2)*(s+1)//2)
    exit()

# elif 2*k < s <= 3*k:
#     for i in range(k+1):
#         x = k - i
#         y = k
#         z = s - x - y
#         if z <= k:
#             pattern += (y - z + 1)
#         else:
#             break

for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k:
            pattern += 1


# for x in range(k+1):
#     x_tmp = x
#     for y in range(x_tmp, k+1):
#         y_tmp = y
#         for z in range(y_tmp, s+1-x_tmp-y_tmp):
#             if x_tmp + y_tmp + z == s:
#                 if x_tmp == y_tmp == z:
#                     pattern += 1
#                 elif x_tmp == y_tmp or x_tmp == z or y_tmp == z:
#                     pattern += 3
#                 else:
#                     pattern += 6
#                 break

print(pattern)

Measured memory_bytes: 3060
s = list(input())

flag = False
k = 0
_t = 0

for s_i in s:
    if s_i == "A" or s_i == "T" or s_i == "G" or s_i == "C":
        flag = True
        _t += 1
    else:
        if flag:
            _t = 0
            flag = False
    if _t > k:
        k = _t

print(k)


Measured memory_bytes: 2940