akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_P = 10020;
bool prime[MAX_P];
int twin_prime[MAX_P];
int size;

void init()
{
    for (int i = 0; i < MAX_P; i++)
        prime[i] = true;
    prime[0] = prime[1] = false;

    for (int i = 2; i * i < MAX_P; i++)
        if (prime[i]) 
            for (int j = 2 * i; j < MAX_P; j += i)
                prime[j] = false;

    for (int i = 0; i < MAX_P; i++) 
        if (prime[i] && prime[i + 2])
            twin_prime[size++] = i;
}


int main()
{
    init();

    int n;
    while (cin >> n, n) {
        n -= 2;
        for (int i = 0; i < MAX_P; i++)
            if (twin_prime[i] > n) {
                cout << twin_prime[i - 1] << " " << twin_prime[i - 1] + 2 << endl;
                break;
            }
    }

    return 0;
}

Measured memory_bytes: 1172
import math

A = int(input())
B = int(input())
C = int(input())
D = int(input())
E = int(input())

tlist = [A, B, C, D, E]
mod_list = [A % 10, B % 10, C % 10, D % 10, E % 10]
mod_list_2 = mod_list[:]
count = 0
already = 0

while 0 in mod_list_2:
  mod_list_2.pop(mod_list_2.index(0))
  
min_mod = 0
if mod_list_2:
  min_mod = min(mod_list_2)
  
if min_mod == 0:
  print(A + B + C + D + E)
else:
  for i in tlist:
    if (i % 10 == min_mod) and already == 0:
      already = i
    else:
      count += int(math.ceil(i / 10) * 10)
  else:
    count += already
    print(count)
  




Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)

    var (x,n) = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
    if(n==0)
        println(x)


    else {
        var arr = scan.nextLine().split(" ").map{ it.trim().toInt() }.toTypedArray()
        var p = x
        while (true) {
            if (!arr.contains(p))
                break
            else
                p++
        }
        var q = x
        while (true) {
            if (!arr.contains(q))
                break
            else
                q--
        }
        var s1 = Math.abs(p - x)
        var s2 = Math.abs(q - x)
        var ans = Math.min(s1, s2)
        if (ans == s2)
            println(q)
        else
            println(p)
    }
}


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

#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<ll>())
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);

    rep(i,n){
        cin >> a[i];
    }

    ll count=0;
    rsort(a);
    count+=a[0];
    int k=1;
    int i=1;
    while(i<n-1){
        rep(j,2){
            count+=a[k];
            ++i;
            if(i==n-1){
                break;
            }
        }
        ++k;
        
    }
    cout << count << endl;
}

Measured memory_bytes: 4848
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;
typedef long long ll;

int main(){
    int N;cin>>N;
    ll A[100010],X[100010];
    X[1]=0;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        if(i%2==1){
            X[1]+=A[i];
        }
        else{
            X[1]-=A[i];
        }
    }
    cout<<X[1];
    for(int i=2;i<N;i++){
        X[i]=(ll)2*A[i-1]-X[i-1];
        cout<<" "<<X[i];
    }
    cout<<" "<<(ll)2*A[N-1]-X[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 2816
N,M = map(int,input().split())
k = []
a = []
ans = 0
for i in range(N):
    templist = list(map(int,input().split()))
    k.append(templist[0])
    a.append(templist[1:])

for i in range(1,M+1):
    count = 0
    for j in range(N):
        if (i in a[j]):
            count += 1
            # print(i)
    if count == N:
        ans += 1

print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int a = Integer.parseInt(scan.nextLine());
		int b = Integer.parseInt(scan.nextLine());
		int ans;
		
		if ((a + b) % 3 == 0) {
			ans = 3;
		} else if ((a + b) % 3 == 1) {
			ans = 2;
		} else {
			ans = 1;
		}
		System.out.println(ans);
	}
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second

#define DUMP(x) cout<<#x<<":"<<(x)<<endl
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int C, N;
int f(VS& vs, int x, int y){
  vector<char> tmp = {vs[y][x], vs[N-1-y][x], vs[y][N-1-x], vs[N-1-y][N-1-x]};
  return count(ALL(tmp), '0')==0 ||count(ALL(tmp), '0')==4? 0: 1;
}

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

  cin >> C >> N;
  VS vs(N);
  cin >> vs;

  int diff = 0;
  REP(y,N/2) REP(x,N/2)
	diff += f(vs, x, y);

  int ans = diff == 0;
  REP(i,C-1){
	int D;
	cin >> D;
	vector<PII> qs, tmp;
	REP(d,D){
	  int y, x;
	  cin >> y >> x;
	  --y;
	  --x;
	  qs.EB(x, y);
	  tmp.EB(min(x,N-1-x), min(y,N-1-y));
	}
	SORT(tmp);
	UNIQ(tmp);

	for(auto& p: tmp)
	  diff -= f(vs, p.FF, p.SS);
	for(auto& p: qs)
	  vs[p.SS][p.FF] = ((vs[p.SS][p.FF] - '0')^1) + '0';
	for(auto& p: tmp)
	  diff += f(vs, p.FF, p.SS);

	ans += diff == 0;
  }
  cout << ans << endl;
  
  return 0;
}



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

class Program
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        ulong m, n, a, b;
        string[] s;
        a = 1;
        b = 1;

        for (int i = 0; i < N; i++)
        {
            s = Console.ReadLine().Split(' ');
            m = ulong.Parse(s[0]);
            n = ulong.Parse(s[1]);
            ulong pa,pb;
            if (a % m == 0)
                pa = a / m;
            else
                pa = a / m + 1;

            if (b % n == 0)
                pb = b / n;
            else
                pb = b / n + 1;

            if (pa > pb)
            {
                a = m * pa;
                b = n * pa;
            }
            else
            {
                a = m * pb;
                b = n * pb;
            }
        }
        Console.WriteLine(a + b);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; 
const int N = 2e5+10;

void solve() {
    int n, k; cin >> n >> k;
    vector<int> v;
    for (int i = 0; i < n; ++i) {
        int in; cin >> in;
        v.push_back(in);
    }

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

    int ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += v[i];
    }

    cout << ans << endl;
}


int main(void) {
    int t; t = 1;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define FasterIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define ff first
#define ss second
#define mk make_pair
#define pi pair<int,int>
#define vi vector<int>
#define pL pair<ll,ll>
#define vL vector<ll>
#define vp vector<pi>
#define vpL vector<pL>

const int MX=3000;

ll dp[MX][2][10], n;
string s;
ll call(int p, int f, int k)
{
    if(p==n) return !k;
    ll &ret=dp[p][f][k];
    if(!k)   return ret=1;
    if(~ret) return ret;
    ret=0;
    if(f)
    {
        ret+=call(p+1, 1, k);
        for(int i=1; i<10; i++)
        {
            ret+=call(p+1, 1, k-1);
        }
    }
    else
    {
        for(int i=0; i<s[p]-'0'; i++)
        {
            ret+=call(p+1, 1, (i)?k-1:k);
        }
        ret+=call(p+1, f, (s[p]!='0')?k-1:k);
    }
    return ret;
}

int main()
{
    FasterIO;

    int m, k;
    cin>>s>>k; n=s.size();
    mem(dp, -1);
    ll r1=call(0, 0, k);
    cout<<r1<<endl;
    return 0;
}


Measured memory_bytes: 768
n, q = gets.split.map(&:to_i)
tree = Array.new(n + 1) {[]}
(n - 1).times do
  a, b = gets.split.map(&:to_i)
  tree[a] << b
  tree[b] << a
end

total = Array.new(n + 1, 0)
q.times do
  p, x = gets.split.map(&:to_i)
  total[p] += x
end

visited = Array.new(n + 1)
queue = [1]
until queue.empty?
  c = queue.shift
  visited[c] = true
  tree[c].each do |q|
    next if visited[q]
    total[q] += total[c]
    queue << q
  end
end

puts total[1..n].join(" ")

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

using ll = long long;
const int inf = 99999999;

using namespace std;

int main(){
	
	string s;
	cin >> s;
	int n = s.size();
	if(s[n - 1] == 's')s+="es";
	else s += "s";
	cout << s << endl;
	return 0;
}
 

Measured memory_bytes: 3624
def dfs(start, n, len_n):
    queue = [start]

    cnt = 0
    while queue:
        parent = queue.pop()
        for c in '357':
            cc = parent+c
            if int(cc) <= n and '3' in cc and '5' in cc and '7' in cc:
                cnt += 1
            if  len(cc) < len_n:
                queue.append(cc)
    return cnt

n = input()
len_n = len(n)
n = int(n)
print(dfs('', n, len_n))


Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>

int main()
{
	int n, a, ma = -1000000, mi = 1000000;
	long int su = 0;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> a;
		if(ma < a){
			ma = a;
		}
		if (mi > a) {
			mi = a;
		}
		su += a;
	}
	std::cout << mi << " " << ma << " " << su << std::endl;
    return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

bool isin(int x, int y, int z, int a, int b, int c){
    return x >= 0 && y >= 0 && z >= 0 && x < a && y < b && z < c;
}

int main() {
    ll a, b, c;
    int n;
    cin >> a >> b >> c >> n;
    ll ans = 2 * (a*b + b*c + c*a) + 6 * n;
    set<pair<int, P> > st;
    REP(i,n){
        int x, y, z;
        cin >> x >> y >> z;
        st.insert(make_pair(x, P(y, z)));
    }
    int dx[] = {1,-1,0,0,0,0}, dy[] = {0,0,1,-1,0,0}, dz[] = {0,0,0,0,1,-1};
    for (auto p : st){
        int x = p.first, y = p.second.first, z = p.second.second;
        REP(k,6){
            int xx = x + dx[k], yy = y + dy[k], zz = z + dz[k];
            if (!isin(xx,yy,zz,a,b,c)) ans -= 2;
            else if (st.find(make_pair(xx, P(yy, zz))) != st.end()) ans -= 1;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3140
import copy
from collections import deque


def bfs(H, W, maze, dist, sh, sw):
    queue = deque([[sh, sw]])
    dist[sh][sw] = 0
    while queue:
        h, w = queue.popleft()
        for i, j in [(1, 0), (-1, 0), (0, -1), (0, 1)]:
            next_h, next_w = h + i, w + j
            if not ((0 <= next_h <= H - 1) and (0 <= next_w <= W - 1)):
                continue
            if (maze[next_h][next_w] == ".") and (dist[next_h][next_w] == -1):
                dist[next_h][next_w] = dist[h][w] + 1
                queue.append([next_h, next_w])
    ret = 0
    for i in range(H):
        tmp = max(dist[i])
        if tmp > ret:
            ret = tmp
    return ret


if __name__ == "__main__":
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]

    dist = [[-1 for _ in range(W)] for _ in range(H)]
    ans = 0
    for sh in range(H):
        for sw in range(W):
            if S[sh][sw] == "#":
                continue
            d = copy.deepcopy(dist)
            max_move = bfs(H, W, S, d, sh, sw)
            if max_move > ans:
                ans = max_move
    print(ans)


Measured memory_bytes: 3532
import java.util.Scanner;
import java.math.*;

public class Main {

	/*
	 * 余りの最大値を求める。
	 */
	public static void main(String[] args) {

		/*
		 * Scannerで値取得。
		 */
		Scanner s = new Scanner(System.in);
		int number = s.nextInt();
		s.close();

		int odd = number / 2;
		if(number % 2 == 1) {
			odd++;
		}
		
		BigDecimal bans = new BigDecimal(number);
		BigDecimal bodd = new BigDecimal(odd);
		BigDecimal divide = bodd.divide(bans,7,BigDecimal.ROUND_UP);
		
		System.out.println(divide);

	}

}


Measured memory_bytes: 22100
def main():
    c=[list(map(int,input().split())) for i in range(3)]
    a=[0,0,0]
    b=[0,0,0]
    for i in range(1,101):
        a[0]=i
        a[1]=-1
        a[2]=-1
        b[0]=c[0][0]-a[0]
        b[1]=c[0][1]-a[0]
        b[2]=c[0][2]-a[0]
        for j in range(1,3):
            if c[j][0]-b[0]!=c[j][1]-b[1] or c[j][1]-b[1]!=c[j][2]-b[2]:
                break
            a[j]=c[j][0]-b[0]
            if j == 2:
                print('Yes')
                return
    print('No')

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main(void)
    {
      int a,b,h;
      cin>>a>>b>>h;
      
      int ans = min(a,b)*h;
       
      ans = ans + ((max(a,b)-min(a,b))*h)/2;
     
    cout<<ans;
     
    }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

struct SegTree{
    public:
        int n;
        vector<int> dat;

        SegTree(int n_){
            n=1;
            while(n<n_) n*=2;
            dat.assign(2*n-1,0);
        }

        void update(int k,int a){
            k+=n-1;
            dat[k]+=a;
            while(k>0){
                k = (k-1)/2;
                dat[k] = dat[k*2+1]+dat[k*2+2];
            }
        }

        // [a,b)
        int query(int a,int b,int k,int l,int r){
            if(r<=a or b<=l) return 0;

            if(a<=l and r<=b){
                return dat[k];
            }else{
                int vl = query(a,b,k*2+1,l,(l+r)/2);
                int vr = query(a,b,k*2+2,(l+r)/2,r);
                return vl+vr;
            }
        }

        int query(int a,int b){
            return query(a,b,0,0,n);
        }
};

int main(){
    int n,q;
    cin>>n>>q;
    SegTree seg(n);
    rep(i,q){
        int q,x,y;
        cin>>q>>x>>y;
        if(q==0){   //add
            seg.update(x-1,y);
        }else{
            cout << seg.query(x-1,y) << endl;
        }
    }
}

Measured memory_bytes: 3784
import math
a,b,x=map(int,input().split())
s=2*x/a**2
s_=s-b
if 0<=s_<b:
  print(90-360/2/math.pi*math.atan(a/(b-s_)))
elif s_==b:
  print(0)
else:
  u=2*x/a/b
  print(90-360/2/math.pi*math.atan(u/b))
  

Measured memory_bytes: 3060
import math
N, D = map(int, input().split())
nlist = []
anslist = []
for i in range(N):
    llist = list(map(int, input().split()))
    nlist.append(llist)
a = 0
for x in range(N - 1):
    for i in range(x, N - 1):
        tmp = 0
        for j in range(D):
            tmp += (abs(nlist[x][j] - nlist[i + 1][j]) ** 2)
        anslist.append(int(math.sqrt(tmp)) - math.sqrt(tmp))

cnt = 0
for i in anslist:
    if i == 0.0:
        cnt += 1
print(cnt)

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

#define int long long
#define pii pair<int,int> 

int N,M;
pii a[100010];

int par[100010];
int sz[100010];

int fd(int x)
{
	if(par[x]!=x) par[x]=fd(par[x]);
	return par[x];
}

stack<int> ans;

main()
{
	cin>>N>>M;
	for(int i=1;i<=M;i++)
	{
		cin>>a[i].first>>a[i].second;
	}
	
	for(int i=1;i<=N;i++)
	{
		par[i]=i;
		sz[i]=1;
	}
	
	int c=N*(N-1)/2;
	ans.push(c);
	for(int i=M;i>=2;i--)
	{
		int fu=fd(a[i].first),fv=fd(a[i].second);
		if(fu!=fv)
		{
			c-=sz[fu]*sz[fv];
			sz[fu]+=sz[fv];
			par[fv]=fu;
		}
		ans.push(c);
	}
	while(!ans.empty())
	{
		cout<<ans.top()<<endl;
		ans.pop();
	}
	return 0;
}








Measured memory_bytes: 5020
import java.util.*;

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

        String S = sc.next();
        int l = S.length();
        int max = 0;
        String X ="ACGT";
        char A = X.charAt(0);
        char C = X.charAt(1);
        char G = X.charAt(2);
        char T = X.charAt(3);

        for(int i=0; i<l-1; i++){
            for(int j=i+2; j<=l; j++){
                String sub = S.substring(i, j);
                int lsub = sub.length();
                for(int k=0; k<lsub; k++){
                    if(sub.charAt(k)==A || sub.charAt(k)==C || sub.charAt(k)==G || sub.charAt(k)==T){
                        
                    }
                    else{
                        break;
                    }
                    if(k==lsub-1){
                        max = Math.max(max, lsub);
                    }
                }
            }
        }
        if(max>1){
            System.out.println(max);
        }

        else if(max==0){
            for(int i=0; i<l; i++){
                if(S.charAt(i)==A || S.charAt(i)==C || S.charAt(i)==G || S.charAt(i)==T){
                    max = 1; 
                    System.out.println(max);
                    break;
                }
            }
        }
        if(max==0){
            System.out.println(max);
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
int main() {
    int S;
    cin >> S;
    int kami = S/100;
    int shimo = S%100;
    
    bool YYMM = false, MMYY = false;
    
    if(0<=kami && kami<=99 && 1<=shimo && shimo<=12) YYMM = true;
    if(0<=shimo && shimo<=99 && 1<=kami && kami<=12) MMYY = true;
    
    if(YYMM && MMYY) cout << "AMBIGUOUS" << endl;
    else if(YYMM) cout << "YYMM" << endl;
    else if(MMYY) cout << "MMYY" << endl;
    else cout << "NA" << endl;
}

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

using namespace std;
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

ll MOD = 1000000007;
int MAX_COLORS = 200000;

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

    for(int i=0;i<N;i++) cin >> C[i];

    //uniqify
    vi D;
    D.push_back(C[0]);
    for(int i=1;i<N;i++) {
        if(C[i]!=C[i-1]) D.push_back(C[i]);
    }
 
    N = D.size();

    vll sums(MAX_COLORS+1, 0);
    vll dp(N+1, 0);
    dp[0] = 1;
    for(int i=1;i<=N;i++) {
        int c = D[i-1];
        sums[c] += dp[i-1];
        sums[c] %= MOD;
        dp[i] = sums[c];
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 5108
import java.util.*;
import static java.lang.System.*;

class Main {
  public static final int MOD = 1000000007;
  public static final int INF = 1000000000;
  public static void main(String[] args) {
    Scanner sc = new Scanner(in);
    int N = sc.nextInt();
    Integer A[] = new Integer[N];
    for(int i=0; i<N; i++) A[i] = sc.nextInt();
    Arrays.sort(A, Comparator.reverseOrder());
    long height = 0;
    long width = 0;
    for(int i=0; i<N-1; i++){
      if(height != 0 && width != 0) break;
      if(A[i].equals(A[i+1])){
        if(height == 0) height = A[i];
        else width = A[i];
        i++;
      }
    }
    long ans = height * width;
    out.println(ans);
  }

  public static int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
  }
}

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

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

  int a_x[N], a_y[N], a_h[N];
  for (int i = 0; i < N; ++i)
    cin >> a_x[i] >> a_y[i] >> a_h[i];

  for (int X = 0; X <= 100; ++X) {
    for (int Y = 0; Y <= 100; ++Y) {
      int H = 0, H_MAX = -1;
      for (int i = 0; i < N; ++i) {
        int h = abs(a_x[i] - X) + abs(a_y[i] - Y) + a_h[i];
        if (a_h[i] != 0) {
          if (H == 0) {
            H = h;
            continue;
          }
          if (H != h)
            break;
        } else {
          if (H_MAX == -1 || h < H_MAX)
            H_MAX = h;
        }
        if (1 <= H && (H_MAX == -1 || H <= H_MAX) && i == N - 1) {
          cout << X << " " << Y << " " << H << endl;
          return 0;
        }
      }
    }
  }
}

Measured memory_bytes: 256
/*
  AtCoder Beginner Contest 106
  A - Garden

  方針
    全体の面積から道の面積を引く。

  実装
    道の重複部分に注意する。
*/

#include<iostream>
using namespace std;

int A, B;

int main() {
  scanf("%d%d", &A, &B);
  printf("%d\n", A * B - (A + B - 1));
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

const d = 1000000007

func main() {
	var n, p int
	fmt.Scan(&n)
	fmt.Scan(&p)

	mdans := map[int64]int64{}
	for index := 0; index < p; index++ {
		var n1 int64
		fmt.Scan(&n1)
		mdans[n1] = n1
	}

	dp := make([]int64, n+1, n+1)
	dp[0] = 1
	dp[1] = 1

	if _, ok := mdans[1]; ok {
		dp[1] = 0
	}

	for i := 2; i <= n; i++ {
		if _, ok := mdans[int64(i)]; ok {
			continue
		}
		dp[i] = (dp[i-1] + dp[i-2]) % d

	}

	fmt.Printf("%#v\n", dp[n])
}


Measured memory_bytes: 7936
// C - Bugged
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N; cin>>N;
	int sumS = 0;
	int minS = INT_MAX;
	for(int i=1; i<=N; ++i){
		int s; cin>>s;
		sumS += s;
		if(s%10) minS = min(minS, s);
	}
	if(sumS%10==0) sumS = max(0, sumS - minS);
	cout<< sumS <<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>

#define X first
#define Y second
#define PB push_back

using namespace std;

typedef long long ll;
typedef pair < int, int > pii;
typedef vector < int > vi;

const int N = 1e5 + 500;
const int M = 1e6 + 500;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;

int h, w, a, b;

int main(){
	scanf("%d%d%d%d", &h, &w, &a, &b);
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			printf("%d", (i < b) ^ (j < a));
		}
		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1280
def cal(t, u)
  num = 0
  t.length.times do |i|
    num += u[i] / 2
  end
  num
end

s = gets.chomp.split('')
k = gets.to_i
t = [s[0]]
u = []
y = s[0]
num = 1
s[1..-1].each do |x|
  if x != y
    u << num
    t << x
    y = x
    num = 1
  else
    num += 1
  end
end
u << num

if t.length == 1
  puts k * u[0] / 2
elsif t[0] == t[-1]
  num = cal(t, u) * k
  x = u[0]/2 + u[-1]/2 - (u[0] + u[-1]) / 2
  num -= x * (k-1)
  puts num
else
  puts cal(t, u) * k
end

Measured memory_bytes: 14268
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int A = sc.nextInt();
    	int B = sc.nextInt();
    	int count = 0;
    	for (int i = A; i <= B; i++) {
    		String num = Integer.toString(i);
    		if (num.charAt(0) == num.charAt(4) && num.charAt(1) == num.charAt(3)) {
    			count++;
    		}
    	}
    	System.out.println(count);
    }
}

Measured memory_bytes: 26068
#include <iostream>

void f(std::string& s , int k) {
    s[k - 1] ^= 32;
}

int main() {

    int n, k;
    std::cin >> n >> k;

    std::string s;
    std::cin >> s;

    f(s, k);

    std::cout << s << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = 100000000;
#define rep1(i, n) for (ll i=0; i<(n); i++) 
#define rep2(i, k, n) for (ll i=k; i<(n); i++)
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; }

ll a, b, c, d;
ll findans(ll num){
    ll cnt = std::lcm(c, d);
    ll ans = num/cnt*(cnt+1-(cnt/c)-(cnt/d));
    ll res = num%cnt;
    ans += res - (res/c + res/d);
    return ans;
}



int main() {
    cin >> a >> b >> c >> d;
    ll ans = findans(b) - findans(a-1);
    cout << ans << endl;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    int dish[5];
    int tmp, m = 100;
    int finalfood;
    rep(i, 5){
        cin >> dish[i];
        tmp = dish[i] % 10;
        if(tmp < m && tmp != 0){
            m = tmp;
            finalfood = i;
        }
    }

    int ans = dish[finalfood];
    rep(i, 5){
        if(i != finalfood){
            if(dish[i] % 10 != 0){
                dish[i] /= 10;
                dish[i] += 1;
                dish[i] *= 10;
            }
            ans += dish[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define rep2(i, a)for(auto i : a)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x, std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll co(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main()
{
	ll n, d, ans = 0ll, x, y;
	cin >> n >> d;
	rep(i, 0, n) {
		cin >> x >> y;
		if (x * x + y * y <= d * d)ans++;
	}
	printf("%lld\n", ans);
	return 0;
}


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

char s[55];

int subsq(const char *s, const char *t){
    int n = strlen(t);
    int m = strlen(s);
    for(int i = 0, j = 0; i < n; i++){
        if(s[j] == t[i]) j++;
        if(j == m) return 1;
    }
    return 0;
}

int main(){
    scanf("%s", s);
    if(subsq(s, "AKIHABARA") && subsq("KIHBR", s)) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int n,num,max=-1,ans[101],a=0,b=0;
    vector<int>count(101,0);
    while(cin>>num){
            count[num]++;
            
        }
        for(int i=100;i>=0;i--){
            if(count[i]>max && count[i]!=0){
                b=count[i];
                max=count[i];
            }
        }
    for(int i=0;i<101;i++){
        if(count[i]==b){
            cout<<i<<endl;
        }
    }
    for(int i=0;i<a;i++){
        
    }
    return 0;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
ll pow1(ll a, ll b)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
		{
			ans=ans*a;
		}
		a=a*a;
		b=b>>1;
	}
	return ans;
}
int main()
{
	int n,i,j,k;
	int ans = 0;
	cin>>n>>k;
	int arr[n];
	for(i=0;i<n;i++)
	{
		cin>>arr[i];
		if(arr[i]>=k)
			ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
def chmax(dp, i, x):
  if dp[i] < x:
    dp[i] = x
    return True
  return False

n, W = map(int, input().split())
dp = [-10**9]*(W+1)
dp[0] = 0
for i in range(n):
  w, v = map(int, input().split())
  for i in range(W-w,-1,-1):
    chmax(dp, i+w, dp[i] + v) 
print(max(dp))

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

int main(){

    while(true){
        
        int n,x;
        int ans=0;
        cin>>n>>x;
        if(n==0&&x==0)break;
        
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int u=j+1;u<=n;u++){
                    int p=i+j+u;
                    if(p==x){
                        ans++;
                       // cout<<i<<j<<u<<endl;
                    }
                }
            }
        }
        
        cout<<ans<<endl;
        
        
        
    }
	
	return 0;
	
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
long h;
int main() {
    cin>>h;
    long count = 1;
    long n = 1;
    while(h>1){
      h = h/2;
      count = count * 2;
      n += count;
    }
    cout<<n<<endl;
    return 0;
}


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

long long int gcd(long long int a, long long int b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

int main() {
	long long int A,B,C,D; cin >> A >> B >> C >> D;
	
	long long int ans = B-A+1;
  
	ans -= (B)/C-(A-1)/C;
	ans -= (B)/D-(A-1)/D;
    
	ans += (B)/((C*D)/gcd(C,D))-(A-1)/((C*D)/gcd(C,D));

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld EPS = 1.0e-14;//-9
const ld PI = 3.141592653589;
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}

signed main(){
    cout << fixed << setprecision(10);
    intl a,b,n;
    cin >> a >> b >> n;
    intl x = min(b - 1,n);
    cout << (intl)(floor((double)a * x / b) - a * floor((double)x / b)) << endl;
    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
using namespace std;
int main(int argc, char* argv[])
{
	int N,L,i;
	cin>>N>>L;
	vector<int> aj(N+1);
	int Sum=0;
	for (i=1;i<=N;i++){
		aj[i]=L+i-1;
		Sum+=aj[i];
	}
	int Min=1e10;
	int MinI=0;
	for (i=1;i<=N;i++){
		int x=Sum-aj[i];
		int y=Sum-x;
		if (y<0){
			y=-y;
		}
		if (Min>y){
			Min=y;
			MinI=i;
		}
	}
	cout<<Sum-aj[MinI]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int c[21],v[21];
int main()
{
	int n,i,s=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&v[i]);
	for(i=0;i<n;i++)
		scanf("%d",&c[i]);
	for(i=0;i<n;i++)
		s+=max(v[i]-c[i],0);
	printf("%d",s);
	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 REP(i,n) for(int i=1;i<=n;i++)
typedef long long ll;

int main(){
	int N;
	cin >> N;
	vector<ll> A(N);
	vector<ll> B(N);
	vector<ll> C(N);
	rep(i,N){
		cin >> A[i];
	}
	rep(i,N){
		cin >> B[i];
	}
	rep(i,N){
		cin >> C[i];
	}
	
	sort(A.begin(),A.end());
	sort(B.begin(),B.end());
	sort(C.begin(),C.end());
	
	ll ans = 0;
	
	rep(i,N){
		auto itr1 = lower_bound(A.begin(),A.end(),B[i])-A.begin();
		auto itr2 = C.end()-upper_bound(C.begin(),C.end(),B[i]);
		ans += itr1*itr2;
	}
	
	cout << ans << endl;
    return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 110
int dis[maxn],head[maxn],deg[maxn];
struct Edge{
	int st,to,next,len;
}edge[maxn*maxn*2];
int n,m,p,num;
double hav[maxn];
int pos[maxn],pre[maxn][maxn],cnt[maxn],mark[maxn];
double ans[maxn];
int l,h,q[maxn];
void addedge(int a,int b ,int c)
{
	edge[num].st=a;edge[num].to=b;edge[num].len=c;
	edge[num].next=head[a];head[a]=num++;
}
void dij()
{
	int i,j,k;
	int id,now;
	memset(dis,-1,sizeof(dis));
	memset(mark,0,sizeof(mark));
	memset(cnt,0,sizeof(cnt));
	dis[0]=0;
	while(1){
		now=-1;
		for(i=0;i<n;i++){
			if(dis[i]==-1)continue;
			if((dis[i]<now||now==-1)&&!mark[i]){
				now=dis[i];
				id=i;
			}
		}
		if(now==-1)break;
		mark[id]=1;
		for(i=head[id];i!=-1;i=edge[i].next){
			j=edge[i].to;
			if(dis[j]==-1||dis[id]+edge[i].len<dis[j]){
				dis[j]=dis[id]+edge[i].len;
				cnt[j]=1;
				pre[j][cnt[j]]=id;
			}else if(dis[id]+edge[i].len==dis[j]){
				cnt[j]++;
				pre[j][cnt[j]]=id;
			}
		}
	}
}
void dfs(int now)
{
	if(mark[now])return;
	if(now==0){
		ans[now]=1;
		mark[now]=1;
		return;
	}
	int i;
	ans[now]=0;
	for(i=1;i<=cnt[now];i++){
		dfs(pre[now][i]);
		ans[now]+=ans[pre[now][i]]*1.0*hav[now]/hav[pre[now][i]];
	}
	mark[now]=1;
}
void dfs1(int now)
{
	if(mark[now])return;
	int i,j;
	for(i=1;i<=cnt[now];i++){
		j=pre[now][i];
		deg[j]++;
		dfs1(j);
	}
	mark[now]=1;
}
void work()
{
	int i,j,k;
	memset(hav,0,sizeof(hav));
	hav[n-1]=1;
	l=h=0;
	q[h++]=n-1;
	while(l<h){
		k=q[l++];
		for(i=1;i<=cnt[k];i++){
			j=pre[k][i];
			deg[j]--;
			hav[j]+=hav[k];
			if(deg[j]==0){
				q[h++]=j;
			}
		}
	}
}
			
int main()
{
	int i,j,k;
	int st,to,cost;
	while(scanf("%d%d%d",&n,&m,&p),n+m+p){
		num=0;
		memset(head,-1,sizeof(head));
		while(m--){
			scanf("%d%d%d",&st,&to,&cost);
			addedge(st,to,cost);
			addedge(to,st,cost);
		}
		for(i=1;i<=p;i++){
			scanf("%d",&pos[i]);
		}
		dij();
		if(dis[n-1]==-1)while(1);
		memset(mark,0,sizeof(mark));
		memset(deg,0,sizeof(deg));
		dfs1(n-1);
		work();
		/*for(i=0;i<n;i++){
			printf("%d %d %d\n",i,deg[i],cnt[i]);
		}*/
		for(i=0;i<n;i++){
			ans[i]=0;
		}
		
		memset(mark,0,sizeof(mark));
		dfs(n-1);
		for(i=1;i<=p;i++){
			printf("%.8f\n",ans[pos[i]]);
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
N, M = map( int, input().split() )

# その食べ物を好きだと答えた人の人数
X = [0] * (M+1)

for i in range(N):
    A = list( map( int, input().split() ) )
    for i in A[1:]:
        X[i] += 1

print( X.count(N) )

Measured memory_bytes: 3060
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#include"debug_deque.hpp"
#define vector DebugDeque
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printe) FUNC(printw) FUNC(printew) FUNC(printb) FUNC(printd) FUNC(printde);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ in >> p.first >> p.second; return in; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
template <char d = ' ', class T>
ostream& operator << (ostream& out, vector<T>& v){ for(auto& e : v){ out << e << d; } return out; }

struct Stuple {
    int y; int x; int len;
    Stuple() = default;
    Stuple(int y, int x, int len): y(y), x(x), len(len){ }
    operator tuple<int, int, int> () const { return make_tuple(y, x, len); }
    bool operator < (const Stuple& e) const { return tie(y, x) < tie(e.y, e.x); }
    ostream& operator >> (ostream& out) const { prints(tie(y, x, len)); return out; }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    vector<vector<char>> ss(h, vector<char>(w)); cin >> ss;
    pair<int, int> dyxs[4] = {{1, 0},  {0, 1}, {0, -1}, {-1, 0}};
    queue<Stuple> q;
    q.emplace(0, 0, 1);
    int mlen = -1;
    set<Stuple> visited;
    while(q.size()){
        auto e = q.front(); q.pop();
        if(visited.count(e)){ continue; }
        visited.insert(e);
        if(e.y == h - 1 && e.x == w - 1){
            mlen = e.len;
            break;
        }else if(e.y < 0 || h <= e.y || e.x < 0 || w <= e.x || ss[e.y][e.x] == '#'){
            continue;
        }
        for(auto& dyx : dyxs){
            q.emplace(e.y + dyx.first, e.x + dyx.second, e.len + 1);
        }
    }
    if(mlen == -1){
        cout << -1 << '\n';
        return 0;
    }
    int ws = 0;
    for(auto& s : ss){
        for(auto& e : s){
            ws += e == '#';
        }
    }
    cout << h * w - mlen - ws << '\n';
}


Measured memory_bytes: 384
import sys
sys.setrecursionlimit(1000000000)

def main():
    N,M = map(int,input().split())
    e = [[] for i in range(N)]
    t = 0
    a = []
    for i in range(M):
        r,l,d = map(int,input().split())
        e[r-1].append((l-1,d))
        e[l-1].append((r-1,-d))
        a.append(r-1)
        a.append(l-1)
        t = r-1

    col = [ float("inf") for i in range(N) ]
    def dfs(i,c):
        for node in e[i]:
            if col[node[0]] == float("inf"):
                col[node[0]] = c + node[1]
                dfs(node[0],c+node[1])
            elif col[node[0]] != c + node[1]:
                print("No")
                exit()


    dfs(t,0)
    a = list(set(a))
    for i in a:
        if col[i] == float("inf"):
            dfs(i,0)


    print("Yes")


if __name__ == '__main__':
    main()


Measured memory_bytes: 153216
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

string str;

map<string, llong> mp;

int main() {
    mp["SUN"] = 7;
    mp["MON"] = 6;
    mp["TUE"] = 5;
    mp["WED"] = 4;
    mp["THU"] = 3;
    mp["FRI"] = 2;
    mp["SAT"] = 1;

    cin >> str;

    cout << mp[str] << endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio,std.string,std.conv,std.bigint;
import std.regex;

void main(){
	
	auto S = num!(BigInt,"")();
	BigInt sum = 0;
	BigInt buf = 0;
	
	foreach( bit ; 0..1<<(S.length-1) ){

		buf = 0;
		foreach( ptr ; 0..S.length ){

			buf = (buf)? buf*10 : BigInt(0) ;
			buf += S[ptr];
			
			if( bit&(1<<ptr) ){
				continue;
			}else{
				sum += buf;
				buf = 0;
				continue;
			}
		}
		if( buf ){sum+=buf;}
	}
	writeln(sum);
}

char[] str(){
	char[] ret;
	foreach( elm ; readln().chomp().split() ){
		//ret ~= elm.to!char();
		ret ~= elm;
	}
	return ret;
}
T[] num( T , string S = " " )(){
	T[] ret;
	foreach( elm ; readln().chomp().split(S) ){
		ret ~= elm.to!T();
	}
	return ret;
}

Measured memory_bytes: 508
#include <iostream>

int main()
{
    std::int64_t target = 0;
    std::cin >> target;

    std::int64_t current = 100;
    std::int64_t year = 0;
    for (; target > current; ++year)
    {
        std::int64_t append = (current * 0.01);
        current += append;
    }

    std::cout << year;
}

Measured memory_bytes: 3636
n, y = map(int, input().split())
tf = False
ans = ""
for i in range(n+1):
  a = y - i * 10000
  for j in range(n-i+1):
    b = a - j * 5000
    tf = True if b == 1000 * (n - i - j) else False
    if tf:
      print('{0} {1} {2}'.format(i, j, n-i-j))
      break
  if tf:
    break
if not(tf):
  print('-1 -1 -1')

Measured memory_bytes: 9224
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	string s; cin >> s;
	for( int i = 0; i < s.l_ength(); i += 2 ){
		cout << s[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i += 2) {
    int c = 0;
    for (int j = 1; j <= i; j++) {
      if (i % j == 0) {
        c++;
      }
    }
    if (c == 8) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,k;
    cin>>n>>k;
    ll ans=k;
    ans=ans*(ll)pow(k-1,n-1);
    cout<<ans<<endl;
}

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

using namespace std;

int n;
int col[100010];
vector<pair<int, int> > adj[100010];

void dfs(int u, int p, bool par){
	if(par) col[u] = 1;
	else col[u] = 0;

	for(auto v : adj[u]){
		if(v.first == p) continue;

		bool tmp = v.second & 1;

		dfs(v.first, u, tmp ^ par);
	}
}

int main(){
	scanf("%d", &n);

	for(int i = 0; i < n - 1; i++){
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);

		adj[u].emplace_back(v, w);
		adj[v].emplace_back(u, w);
	}

	dfs(1, -1, 0);

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

Measured memory_bytes: 8320
#include<cstdio>
#include<cctype>
#include<map>
#include<utility>
#define RI register int
#define CI const int&
#define Tp template <typename T>
#define fi first
#define se second
using namespace std;
typedef pair <int,int> pi;
const int N=100005;
int n,x,size; map <int,int> C;
class FileInputOutput
{
	private:
		static const int S=1<<21;
		#define tc() (A==B&&(B=(A=Fin)+fread(Fin,1,S,stdin),A==B)?EOF:*A++)
		char Fin[S],*A,*B;
	public:
		Tp inline void read(T& x)
		{
			x=0; char ch; while (!isdigit(ch=tc()));
			while (x=(x<<3)+(x<<1)+(ch&15),isdigit(ch=tc()));
		}
		#undef tc
}F;
int main()
{
	//freopen("CODE.in","r",stdin); freopen("CODE.out","w",stdout);
	RI i; for (F.read(n),i=1;i<=n;++i)
	F.read(x),(!C.count(x))&&(++size),++C[x];
	if (size>3) return puts("No"),0; pi a,b,c;
	a=*C.begin(); C.erase(C.begin());
	if (size==1) return puts(a.fi?"No":"Yes"),0;
	if (n%3) return puts("No"),0; b=*C.begin(),C.erase(C.begin());
	if (size==2) return puts(!a.fi&&(a.se==n/3&&b.se==n/3*2)?"Yes":"No"),0;
	c=*C.begin(),C.erase(C.begin());
	if ((a.fi^b.fi)!=c.fi) return puts("No"),0;
	if (a.se!=b.se||a.se!=c.se) puts("No"); else puts("Yes"); return 0;
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(abs(a-c) <= d) cout << "Yes" << endl;
  else if(abs(c-b) <= d && abs(b-a) <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include<numeric>
#include<cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> pll;
const ll inf = 1LL << 60;
const ll comp = 1e18;

int main(){
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
    ll N; cin>>N;
    vector<ll> A(N);
    REP(i,N){   
        cin>>A[i];
        if(A[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    bool flag = true;
    REP(i,N){
        if(log10(ans) + log10(A[i]) > 18) {
            flag = false; break;
        }
        ans *= A[i];
        if(ans > comp){
            flag = false; break;
        }
    }
    cout<<(flag ? ans : -1) << endl;
}

Measured memory_bytes: 3992
module P = Map.Make(struct type t = int let compare = (-) end)
let _ = Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0))
  |> Array.fold_left (fun (v, (s, m)) x ->
      let c = try P.find (s+x) m with | _ -> 0 in
      (v+c, (s+x, P.add (s+x) (c+1) m))) (0, (0, P.singleton 0 1))
  |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 17280
#include <iostream>
#define DIV 1000000007
using namespace std;

int A[100000];
int T[100000];


int main(){
	int N;
	long long pat=1;
	
	cin >> N;
	for(int i=0;i<N;i++){
		cin >> T[i];
	}
	for(int i=0;i<N;i++){
		cin >> A[i];
	}

	for(int i=0;i<N;i++){
		int min,max;
		if(T[i]>A[i]){
			min=A[i];
			max=T[i];
		}else{
			min=T[i];
			max=A[i];
		}

		if(T[i]<T[i-1] || A[i]<A[i+1]){
			cout << 0 << endl;
			return 0;
		}
		if(T[i]>T[i-1] && A[i]>A[i+1] && max!=min){
			cout << 0 <<endl;
			return 0;
		}
		if(T[i]>T[i-1] && A[i]<T[i]){
			cout << 0 << endl;
			return 0;
		}
		if(A[i]>A[i+1] && T[i]<A[i]){
			cout << 0 << endl;
			return 0;
		}

		if(i>0 && i<N-1 && T[i]<=T[i-1] && A[i]<=A[i+1]){
			pat*=min;
			pat%=DIV;
		}
	}

	cout << pat << endl;
	
	return 0;
}


Measured memory_bytes: 1024
$<.gets.to_i.times do
  h, m = $<.gets.split(":").map(&:to_r)
  l = m * 6
  s = (h * 60 + m) / 2
  r = (l - s).abs
  r = 360 - r if r > 180
  st = if 0 <= r and r < 30
    "alert"
  elsif 90 <= r and r <= 180
    "safe"
  else
    "warning"
  end
  puts st
end


Measured memory_bytes: 6920