akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll u(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll d(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll z(ll a){
  if(a<0)return -a;
  return a;
}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;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;
  }
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(void){
  char s[4];
  scanf("%s",s);
  char w[22]={"SATFRITHUWEDTUEMONSUN"};
  FOR(19){
    if(s[0]==w[i]&&s[1]==w[i+1]&&s[2]==w[i+2]){
      PRN(i/3+1);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 128
K = int(input())

def S(x) :
    ret = 0
    while x :
        ret += x % 10
        x //= 10
    return ret

L = set()
nine = ''
for i in range(16) :
    for j in range(1, 1000) :
        x = int(str(j) + nine)
        L.add(x)
    nine += '9'
    
L = list(L)
L.sort()

v = [1]
n = [1]

for l in L[1:] :
    x = l / S(l)
    while v[-1] > x :
        v.pop()
        n.pop()
    v.append(x)
    n.append(l)

for i in range(K) :
    print(n[i])


Measured memory_bytes: 44892
#include <bits/stdc++.h>
#define int long long
#define cerr if(false) cerr 
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define watch(x) cerr << "\n" << (#x) << " is " << (x) << endl

using namespace std;

void solve(){
	int l , r ; cin >> l >> r ;
	int ans=2018; 
	if(r-l>=2019) ans = 0;
	else{
		for(int i=l;i<=r;i++){
			for(int j=l;j<=r;j++){
				if(i==j) continue;
				ans=min(ans,(i*j)%2019);
			}
		}
	}
	cout << ans << endl;	
}

int32_t main(){IOS;
	
	int t = 1 ;
	//cin >> t ;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
LR = [[int(x)-1 for x in input().split()] for _ in range(Q)]
AC = []
pre = None
cnt = 0
for s in S:
  if s == "A":
    pre = "A"
  elif pre == "A" and s == "C":
    cnt += 1
    pre = None
  elif pre == "A": # 次の処理の為、初期化
    pre = None
  AC.append(cnt)

for l, r in LR:
  print(AC[r] - AC[l])

Measured memory_bytes: 24424
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;


const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main() {
    int h,w; cin >> h >> w;
    vector<vector<char>> v(h+2,vector<char> (w+2));
    for(int i=0;i<h+2;i++){
        for(int j=0;j<w+2;j++){
            if(i==0||i==h+1||j==0||j==w+1) v[i][j] = '.';
            else cin >> v[i+1][j+1];
        }
    }

    string ans = "Yes";
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            if(v[i][j] == '#'){
                if(v[i-1][j]=='.'&&v[i+1][j]=='.'&&v[i][j-1]=='.'&&v[i][j+1]=='.') ans = "No";
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n)repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
typedef pair<int,int> P;
typedef pair<int, P> PP;
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb(x) push_back(x)
#define fi first
#define se second
const int inf = 1e9+7;
const int INF = 1e18+7;
int mod = 1e9+7;

signed main(){
	int sx[2], sy[2];
	rep(i,2)scanf("%lld%lld", &sx[i], &sy[i]);
	int x = sx[1]-sx[0], y = sy[1]-sy[0];
	
	rep(i,x)printf("R");
	rep(i,y)printf("U");
	rep(i,x)printf("L");
	rep(i,y)printf("D");
	
	printf("D");
	rep(i,x+1)printf("R");
	rep(i,y+1)printf("U");
	printf("L");
	
	printf("U");
	rep(i,x+1)printf("L");
	rep(i,y+1)printf("D");
	printf("R");
	
	printf("\n");
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i,n,x;
	int a[100];
	scanf("%d",&n);
	for(i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}
	for(x = n - 1;x >= 0;x--){
		if(x != n-1){
			printf(" ");
		}
	        printf("%d",a[x]);
        }
	printf("\n");
	return 0;
}

Measured memory_bytes: 600
n = int(input())
a = list(map(int, input().split(' ')))

dic = {}
for i in range(n):
    dic[i] = 0
for i in range(len(a)):
    a[i] -= 1
    dic[a[i]] += 1
dic = sorted(dic.items())

for item in dic:
    first, second = item
    print(second)


Measured memory_bytes: 47620
N=str(input())
if int(N[-1])==3:
    print("bon")
elif int(N[-1])==0:
    print("pon")
elif int(N[-1])==1:
    print("pon") 
elif int(N[-1])==6:
    print("pon") 
elif int(N[-1])==8:
    print("pon") 
else:
    print("hon")

Measured memory_bytes: 9192
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
  int i,ans[200010],a[200010];
  string s;
  cin >> s;
  int n=s.size();
  for(i=0;i<n;i++){
    ans[i]=0;
    if(s[i]=='R'){
      a[i]=0;
    }
    else{
      a[i]=1;
    }
  }
  int b=0;
  for(i=0;i<n;i++){
    if(a[i]==0){
      b++;
    }
    else{
      ans[i]+=b/2;
      ans[i-1]+=(b+1)/2;
      b=0;
    }
  }
  b=0;
  for(i=n-1;i>=0;i--){
    if(a[i]==1){
      b++;
    }
    else{
      ans[i]+=b/2;
      ans[i+1]+=(b+1)/2;
      b=0;
    }
  }
  for(i=0;i<n;i++){
    if(i==0){
      printf("%d",ans[i]);
    }
    else{
      printf(" %d",ans[i]);
    }
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 1408
x,k,d=map(int,input().split())
if x>=k*d:
    print(x-k*d)
elif -x>=k*d:
    print(abs(x+k*d))
else:
    x=abs(x)
    a,b=divmod(x,d)
    if k%2==a%2:
        print(b)
    else:
        print(abs(b-d))

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

int main() {
    int n,m,k;
    cin >> n >> m >> k;
    for(int i = 0; i < n+1; i++) {
        for(int j = 0; j < m+1; j++) {
            if(m*i+(n-i)*j-i*j==k){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    

    return 0;
}

Measured memory_bytes: 3616
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);

String s =sc.next();
StringBuffer s1=new StringBuffer(s);
s1.reverse();
if(s.equals(s1.toString()))
{
int n=s.length();
int r=(n-1)/2;
String a=s.substring(0,r);
StringBuffer s2=new StringBuffer(a);
s2.reverse();
if(a.equals(s2.toString()))
{
int r1=(n+3)/2;
String b=s.substring(r1-1,n);
StringBuffer s3=new StringBuffer(b);
s3.reverse();
if(b.equals(s3.toString()))
System.out.println("Yes");
else
System.out.println("No");
}
else
System.out.println("No");
}
else
System.out.println("No");



}

}

Measured memory_bytes: 21972
#coding:utf-8
#1_5_D

def merge(array, left, mid, right):
    global cnt
    L = array[left:mid]  + [SENTINEL]
    R = array[mid:right] + [SENTINEL]
    i = j = 0

    for k in range(left, right):
        if L[i] <= R[j]:
            array[k] = L[i]
            i += 1
        else:
            array[k] = R[j]
            j += 1
            cnt += len(L) - 1 - i

def merge_sort(array, left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(array, left, mid)
        merge_sort(array, mid, right)
        merge(array, left, mid, right)

n = int(input())
numbers = list(map(int, input().split()))
cnt = 0
SENTINEL = 10 ** 9 + 1
merge_sort(numbers, 0, len(numbers))
print(cnt)

Measured memory_bytes: 30392
import itertools
N = int(input())
L = list(map(int,input().split()))
l_list = list(itertools.combinations(L, 3))
counter = 0
for n in l_list:
    i = n[0]
    j = n[1]
    k = n[2]
    if i != j and j != k and k != i:
        if (i < j + k) and (j < i + k) and (k < i + j):
            counter += 1
print(counter)

Measured memory_bytes: 20484
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        if(line.equals("a") ||line.equals("i")||line.equals("u")||line.equals("e")|| line.equals("o")){
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 21332
#include <iostream>
#include <cmath>

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

int main() {
    int n;
    double t, a;
    double h;
    double diff = 1e6, ans;

    std::cin >> n >> t >> a;
    rep(i, n) {
        std::cin >> h;
        double tmp = t - (h * 0.006);
        if (fabs(tmp - a) < diff) {
            diff = fabs(tmp - a);
            ans = i+1;
        }
    }

    std::cout << ans << std::endl;

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main( void ) 
{
	int a[101][101];
	int b[101][101];
	long c[101][101]={{0}};
	int n,m,l;
	int i,j,k;
	
	scanf( "%d%d%d", &n, &m, &l );
	for( i=0; i<n; i++ ) {
		for( j=0; j<m; j++ ) {
			scanf( "%d", &a[i][j] );
		}
	}
	for( i=0; i<m; i++ ) {
		for( j=0; j<l; j++ ) {
			scanf( "%d", &b[i][j] );
		}
	}

	for( i=0; i<n; i++ ) {
		for( k=0; k<m; k++ ) {
			for( j=0; j<l; j++ ) {
				c[i][j]+=a[i][k]*b[k][j];
			}
		}
	}	


	for( i=0; i<n; i++ ) {
		for( j=0; j<l; j++ ) {
			printf( "%ld", c[i][j] );
			if( l-1 == j ) {
				printf( "\n" );
			} else {
				printf( " " );
			}
		}
	}


	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pr;
 
int price[3];
 
int main()
{
	for (int i = 0; i < 3; i++)
		cin >> price[i];
	sort(price, price + 3);
	cout << price[0] + price[1] << endl;
 
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
if 0 in a or len(a[a < 0]) % 2 == 0:
    print(int(np.abs(a).sum()))
else:
    m = np.abs(a).min()
    print(int(np.abs(a).sum() - 2 * m))

Measured memory_bytes: 23300
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#include <bitset>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < (n); i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  cout << (N - 1) / 2 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
import math

a,b,x=map(int, input().split())

if x<=a*a*b/2:
    Ans=a*b*b/2/x
else:
    Ans=(2*a*b-2*x/a)/a**2

rad = math.atan(Ans)
deg = math.degrees(rad)
print(deg)

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

int main()
{
  int n;
  cin >> n;
  int nap[n + 1][3];

  nap[0][0] = 0;
  nap[0][1] = 0;
  nap[0][2] = 0;

  for (int i = 1; i <= n; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> nap[i][j];
    }
  }

  for (int i = 1; i <= n; i++)
  {
    long long dt = nap[i][0] - nap[i-1][0];
    long long dx = abs(nap[i][1] - nap[i-1][1]);
    long long dy = abs(nap[i][2] - nap[i-1][2]);
    if (dx + dy > dt || (dt - (dx + dy)) % 2 != 0)
    {
      cout << "No" << endl;
      exit(0);
    }
  }

  cout << "Yes" << endl;

}


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

int main() {
	
	int n;
	cin >> n;
	
	vector<ll> a(n + 1), b(n);
	for(int i = 0; i < n + 1; ++i) {
		cin >> a[i];
	}
	
	for(int i = 0; i < n; ++i) {
		cin >> b[i];
	}
	
	ll ans = 0;
	ll tmp = 0;
	for(int i = 0; i < n; ++i) {
		
		tmp = min(a[i], b[i]);
		ans += tmp;
		a[i] -= tmp;
		b[i] -= tmp;
		
		tmp = min(a[i + 1], b[i]);
		ans += tmp;
		a[i + 1] -= tmp;
		b[i] -= tmp;
	}
	
	cout << ans << endl;
	
	return 0; 
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = 998244353;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


// modint: mod 計算を int を扱うように扱える構造体
template<int MOD> struct Fp {
  long long val;
  constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
    if (val < 0) val += MOD;
  }
  constexpr int getmod() { return MOD; }
  constexpr Fp operator - () const noexcept {
    return val ? MOD - val : 0;
  }
  constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
  constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
  constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
  constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
  constexpr Fp& operator += (const Fp& r) noexcept {
    val += r.val;
    if (val >= MOD) val -= MOD;
    return *this;
  }
  constexpr Fp& operator -= (const Fp& r) noexcept {
    val -= r.val;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr Fp& operator *= (const Fp& r) noexcept {
    val = val * r.val % MOD;
    return *this;
  }
  constexpr Fp& operator /= (const Fp& r) noexcept {
    long long a = r.val, b = MOD, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    val = val * u % MOD;
    if (val < 0) val += MOD;
    return *this;
  }
  constexpr bool operator == (const Fp& r) const noexcept {
    return this->val == r.val;
  }
  constexpr bool operator != (const Fp& r) const noexcept {
    return this->val != r.val;
  }
  friend constexpr ostream& operator << (ostream &os, const Fp<MOD>& x) noexcept {
    return os << x.val;
  }
  friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, long long n) noexcept {
    if (n == 0) return 1;
    auto t = modpow(a, n / 2);
    t = t * t;
    if (n & 1) t = t * a;
    return t;
  }
};
using mint = Fp<MOD>;


int main() {
  ll N, S; cin >> N >> S;
  V a(N);
  rep(i, N) cin >> a[i];

  vector<vector<mint>> dp(N+1, vector<mint>(S+1, mint(0)));
  rep(r, N+1) dp[r][0] = r;

  rep(r, N) rep(s, S+1) {
    if (s == 0) continue;
    dp[r+1][s] = dp[r][s];
    if (s-a[r] >= 0) dp[r+1][s] += dp[r][s-a[r]];
    dp[r+1][s] += (s == a[r]) ? 1 : 0;
  }
  mint ans = 0;
  rep(r, N) ans += dp[r+1][S];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 70784
import numpy as np
a, b, x = map(int, input().split())
if x >= a*a*b/2:
    l = 2*b - 2*x/(a**2)
    print(np.rad2deg(np.arctan(l/a)))
else:
    l = 2*x/(a*b)
    print(np.rad2deg(np.arctan(b/l)))

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> P;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main(){
  int MOD = 1000000007;
  int n; cin >>n;
  string s; cin >> s;
  vector <ll> num(26);
  rep(i, 26) num[i] = 0;
  for (char c:s){
    num[c-'a'] += 1;
  }
  ll ans = 1;
  rep(i, 26){
    if (num[i] != 0){
      ans *= (num[i]+1);
      ans %= MOD;
    }
  }
  cout << ans-1 << endl;
}

Measured memory_bytes: 3728
CON_TYPE = 26
# 問題文の入力
D = gets.to_i
C = gets.split.map(&:to_i)
S = []
D.times do |d|
    S.push(Array.new(gets.split.map(&:to_i)))
end

def calc_one_day(open_type, day)
    sat_day = 0
    # puts "open_type: #{open_type}"
    CON_TYPE.times do |type|
        if(open_type == type)
            sat_day += S[day][type]
            @lasts[type] = day
            # puts "sat_day: #{sat_day}"
            # puts "#{type.to_s} held. sat+=#{S[d][type]}"
        else
            sat_day -= C[type] * (day - @lasts[type])
            # puts "sat-=#{C[type] * (d - @lasts[type])}"
        end
    end
    sat_day
end

def calc_score(arg_array)
    opens = []
    D.times do |d|
        opens.push (arg_array[d].to_i - 1)
    end

    # 得点計算
    sat_list = [0]
    sat = 0
    @lasts = Array.new(CON_TYPE, -1)
    D.times do |d|
        sat += calc_one_day(opens[d], d)
        sat_list.push sat
    end
    sat_list[1..-1] # 最初は0
end

# puts calc_score([1,17,13,14,13])

# 貪欲法
opens = []
@lasts = Array.new(CON_TYPE, -1)
D.times do |d|
    max_sat = -99999999999
    max_type = -1
    CON_TYPE.times do |type|
        sat = calc_one_day(type, d )
        if max_sat < sat
            max_sat = sat
            max_type = type
        end
    end
    opens.push (max_type+1)
end
# puts "SCORE:"
# puts( calc_score(opens) )
# p "LASTS: #{@lasts}"
# puts "ANS:"
puts opens


Measured memory_bytes: 14452
#include <bits/stdc++.h>
using namespace std;
int n;
void lia(string s,char c){
    if(s.size()==n) cout << s << endl;
    else{
       for(char i='a';i<=c;i++){
           if(c==i) lia(s+i,c+1);
           else lia(s+i,c);
       }
    }
}
int main(){
    cin >> n;
    lia("",'a');
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int k;
  string s;
  cin >> k >> s;
  
  if(s.size() <= k){
    cout << s << endl;
  }else{
    for(int i = 0; i < k; i++){
    cout << s.at(i);
    }
    cout << "..." << endl;
  }
    
}

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

public class BinarySearch{
	public static void Main()
	{
		Console.ReadLine();
		var sList = ReadLineAndToIntList().ToList();
		Console.ReadLine();
		var tList = ReadLineAndToIntList();
	
		int count = 0;
	
		foreach (var t in tList)
		{
			if(sList.BinarySearch(t) > -1) count++;
		}
		
		Console.WriteLine(count);
	}
	
	//??????????????????????????????
	public static IEnumerable<int> ReadLineAndToIntList()
	{
		return Console.ReadLine().Split().Select (c => int.Parse(c));
	}
}

Measured memory_bytes: 15816
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);
    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


const int inf = 1<<30;

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

    int n, m;
    string s;
    cin >> n >> m >> s;

    vector<int> dp(n+1, inf);
    dp[n] = 0;

    queue<int> q; 
    q.push(0);
    
    reprev(i, n){
        while(1){
            if(q.size() == 0) { cout << -1 << endl; return 0; }
            if(q.front() != inf && q.size() <= m) break;
            q.pop();
        }
        if(s[i] == '0') dp[i] = q.front()+1;
        q.push(dp[i]);
    }

    vector<int> ans;
    int x = 0;
    int rest = dp[0];
    while(x < n){
        --rest;
        int i = 1;
        while(dp[x+i] != rest) ++i;
        ans.push_back(i);
        x += i;
    }
    for(int i=0; i<ans.size(); ++i){
        if(i) cout << ' ';
        cout << ans[i] << endl;
    }
    cout << endl;
}


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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

//通常
struct UnionFind {
    V par, rank;
    UnionFind(int size) { init(size); }
    void init(int size) {
        REP(i, size) {
            par.push_back(i);
            rank.push_back(0);
        }
    }
    int root(int x) {
        if(par[x] == x)
            return x;
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if(x == y) return;
        if(rank[x] < rank[y]) {
            swap(x, y);
        } else {
            if(rank[x] == rank[y]) rank[x]++;
        }
        par[y] = x;
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

ll N, M;
map<ll, ll> val;
map<string, ll> memo;

signed main() {
    cin >> N;
    auto uf = UnionFind(N);
    REP(i, N) {
        SCIN(a);
        LCIN(x);
        memo[a] = i;
        val[i] = x;
    }
    cin >> M;
    REP(i, M) {
        SCIN(s, t);
        uf.unite(memo[s], memo[t]);
    }
    FOREACH(m, memo) {
        ll ro = uf.root(memo[m.first]);
        val[ro] = min(val[ro], val[memo[m.first]]);
    }
    ll ans = 0;
    FOREACH(m, memo) {
        ll ro = uf.root(memo[m.first]);
        ans += val[ro];
    }
    cout << ans << "\n";
    return 0;
}



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

int main() {
  int a, b, c, d, e, f, g, h, k, n;
  cin >> a >> b >> c >> d >> e >> f >> g >> h >> k >> n;
  
  vector<int> j(n);
  
  for (int i = 0; i < n; i++) {
    cin >> j.at(i);
  }
  
  for (int i = 0; i < n; i++) {
    if ( a == j.at(i) ) {
      a = 0;
    }
    else if ( b == j.at(i) ) {
      b = 0;
    }
    else if ( c == j.at(i) ) {
      c = 0;
    }
    else if ( d == j.at(i) ) {
      d = 0;
    }
    else if ( e == j.at(i) ) {
      e = 0;
    }
    else if ( f == j.at(i) ) {
      f = 0;
    }
    else if ( g == j.at(i) ) {
      g = 0;
    }
    else if ( h == j.at(i) ) {
      h = 0;
    }
    else if ( k == j.at(i) ) {
      k = 0;
    }
    else {
    }
  }
  
 
  
  if ( a+b+c == 0 || d+e+f == 0 || g+h+k == 0 || a+d+g == 0 || b+e+h == 0 || c+f+k == 0 || a+e+k == 0 || c+e+g == 0 ) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
   
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>

#define ll long long

using namespace std;

int main(){
    int N,K;
    cin>>N>>K;
    vector<int> x(N,0);
    for(int i=0;i<N;i++){
        cin >> x[i];
    }
    if(N==1){
        cout << abs(x[0]) << endl;
        return 0;
    }
    vector<int> ans;
    for(int i=0;i<N-K+1;i++){
        ans.push_back(min(abs(x[i])+abs(x[i]-x[i+K-1]),(abs(x[i+K-1])+abs(x[i+K-1]-x[i]))));
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int calc(int x) {
  int ret = 0;
  while (x % 100 == 0) {
    x /= 100;
    ++ret;
  }
  return ret;
}
int main() {
  int D, N;
  cin >> D >> N;
  int cnt = 0, val = 0;
  while (cnt < N) {
    ++val;
    if (calc(val) == D)
      ++cnt;
  }
  cout << val << endl;
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
count = [0] * M
for i in range(N):
    Food = list(map(int,input().split()))
    for j in range(1,len(Food)):
        count[Food[j]-1] += 1

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

Measured memory_bytes: 3060
N = int(input())
A = [list(map(int, input().split())) for _ in range(N)]
AX = [A[i][0] for i in range(N)]
BX = [A[i][1] for i in range(N)]
AX.sort()
BX.sort()
if N % 2 == 1:
  L = AX[(N-1)//2]
  R = BX[(N-1)//2]
  print(R-L+1)
else:
  L = AX[N//2-1] + AX[N//2]
  R = BX[N//2-1] + BX[N//2]
  print(R-L+1)


Measured memory_bytes: 129268
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


/******************************************************************************************/


//繋げる方向を一方向にする
typedef struct union_find {

	vector<ll> pa;//親
	vector<ll> ra;//木の深さ
	vector<ll> siz;
	//n要素で初期化
	void init(ll n) {
		pa.resize(n);
		ra.resize(n);
		siz.resize(n);
		for (ll i = 0; i < n; i++) {
			pa[i] = i;/*各ノードに番号を振る,この時par[x]=xとなる時は木の根となる*/
			ra[i] = 0LL;/*各ノード自体の高さは0*/
			siz[i] = 1LL;
		}
	}
	//木の根を求める
	ll find(ll x) {
		if (pa[x] == x) {
			return x;/*根ならそのノードの番号を返す*/
		}
		else {
			return pa[x] = find(pa[x]);/*根でないならさらにノードの根を探す*/
		}
	}

	//xとyの属する集合を併合する
	void unite(ll x, ll y) {
		x = find(x);//xの根の番号を探す
		y = find(y);//yの根の番号を探す
		if (x == y) {//一致すればつながっている
			return;
		}
		pa[y] = x;
		siz[x] += siz[y];
	}

	//xとyが同じ集合に属するか判定
	bool same(ll x, ll y) {
		return find(x) == find(y);//同じ集合なら1、違うなら0が返る
	}
}UF;


int main() {

	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)
	{
		int k;
		cin >> k;
		cout << lower_bound(a.begin(), a.end(), k) - a.begin() << endl;
	}
	

	
	return 0;
}


Measured memory_bytes: 3128
/* in the name of Anton */

/*
  Compete against Yourself.
  Author - Aryan Choudhary (@aryanc403)
*/

#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize ("-ffloat-store")

#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define endl "\n"

typedef long long int lli;
typedef long double mytype;
typedef pair<lli,lli> ii;
typedef vector<ii> vii;
typedef vector<lli> vi;


const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
#ifdef ARYANC403
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
#endif
}

#ifdef ARYANC403
#include "/home/aryan/codes/PastCodes/header.h"
#else
    #define dbg(args...)
#endif

const lli INF = 0xFFFFFFFFFFFFFFFL;

lli seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli mod = 1000000007L;
// const lli maxN = 1000000007L;

    lli T,n,i,j,k,in,cnt,l,r,u,v,x,y;
    lli m;
    string s;
    vi a;
    //priority_queue < ii , vector < ii > , CMP > pq;// min priority_queue .

const lli N=8005;
bool chk(lli c,vi a)
{
    // c=abs(c);
    if(abs(c)>N)
        return false;
    bitset<2*N+5> bt;
    bt[N]=1;
    for(auto x:a)
        bt=(bt<<x)|(bt>>x);
    dbg(a,c)
    return bt[c+N];
}

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// cin>>T;while(T--)
{

    cin>>s;
    cin>>x>>y;
    n=sz(s);
    fo(i,n)
    {
        if(s[i]=='T')
        {
            s=s.substr(i);
            break;
        }
        x--;
    }

    if(i==n)
    {
        if(x==0&&y==0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
        return 0;
    }

    vi a[2];
    j=0;
    cnt=0;
    for(auto x:s)
    {
        if(x=='T')
        {
            a[j].pb(cnt);
            j^=1;
            cnt=0;
        }
        else
            cnt++;
    }

    a[j].pb(cnt);
    cout<<(chk(x,a[0])&&chk(y,a[1])?"Yes":"No")<<endl;
}   aryanc403();
    return 0;
}


Measured memory_bytes: 3764
import java.util.*;
import java.util.stream.Collectors;
import static java.lang.System.*;

public class Main extends CodingSupport {
    protected void solve() {
        while(sc.hasNext()) {
            Long[] inputs = scanLongs();
            Long greatestCommonDivisor = 1l;
            greatestCommonDivisor = euclidsDeductionMethod(inputs[0], inputs[1]);
            Long leastCommonMultiple = (inputs[0] * inputs[1]) / greatestCommonDivisor;
            print(greatestCommonDivisor + " " + leastCommonMultiple);
        }
        
    }
    
    private long euclidsDeductionMethod(long op1, long op2) {
        long n =0, m = 0;
        if( op1 > op2 ) {
            m = op1;
            n = op2;
        } else {
            m = op2;
            n = op1;
        }
        long greatestCommonDivisor = 1l;
        while(true) {
            if(n == 0) {
                greatestCommonDivisor = m;
                break;
            }
            long nNew = m % n;
            long mNew = n;
            n = nNew;
            m = mNew;
        }
        return greatestCommonDivisor;
    }
}

abstract class CodingSupport {
    protected Scanner sc;
    protected CodingSupport() {
        sc = new Scanner(in);
    }
    
    public static void main(String[] args) throws Exception {
        new Main().solve();
    }
    
    protected abstract void solve();
    
    protected void print(Object o) {
        out.println(o);
    }
    
    protected Long[] scanLongs() {
        return 
          Arrays
              .stream(scanInts())
              .map(Integer::longValue)
              .toArray(Long[]::new);
    }
    
    protected Double[] scanDoubles() {
        return 
          Arrays
              .stream(scanInts())
              .map(Integer::doubleValue)
              .toArray(Double[]::new);
    }
    
    protected Integer[] scanInts() {
       return strArrayToIntArray(sc.nextLine().split(" "));
    }
    
    protected String[] scanLineToTokens(String delimiter) {
        return sc.nextLine().split(delimiter);
    }
    
    protected int scanInt() {
       return sc.nextInt();
    }

    protected List<Integer> strArrayToIntList(String[] strArray) {
        List<Integer> intList =
          Arrays
            .stream(strArray)
            .map(Integer::valueOf)
            .collect(Collectors.toList());
        return intList;
    }
    
    protected Integer[] strArrayToIntArray(String[] strArray) {
        Integer[] intArray =
        Arrays
            .stream(strArray)
            .map(Integer::valueOf)
            .toArray(Integer[]::new);
        return intArray;
    }
}


Measured memory_bytes: 32384
#include<iostream>
#include<vector>
#include<string.h>
#include<cstdio>
using namespace std;
int main()
{
    char s[12],a;
    int i,j,len,num;
    vector<char>str;
    cin.get(s,12);
    len=strlen(s);
    for(i=0;i<len;i++){
        if(str.empty()==false && s[i]=='B') str.pop_back();
        else if(s[i]=='1' || s[i]=='0') str.push_back(s[i]);
    }
    for(i=0;i<str.size();i++){
        cout<<str[i];
    }
    cout<<endl;
}


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

double length(double x1, double y1, double x2, double y2) {
  double l;
  l = sqrt ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
  return l;
}

double f(int k){
    int s = 1.0;
    for (int i = 1; i <= k; ++i)
    {
        s *= i;
    }
    return (double)s;
}

int main() {
  double N;
  cin >> N;
  vector<double> x(N), y(N);
  for (int i = 0; i < N; i++) {
    cin >> x.at(i) >> y.at(i);
  }
  
  double sum = 0.0;
  double Ans = 0.0;
  double a = f(N-1);
  for (int i = 0; i < N - 1; i++) {
    for (int j = i + 1; j < N; j++) {
      sum += length(x.at(i), y.at(i), x.at(j), y.at(j)) * a * 2.0;
    }
  }
  Ans = sum / f(N);
  printf("%8.7f\n", Ans);
}

Measured memory_bytes: 256
<?php
    $n = trim(fgets(STDIN));
    for($i=1;$i<=$n;$i++){
        $data = explode(" ", trim(fgets(STDIN)));
        $a[$i] = $data[0];
        $b[$i] = $data[1];
    }
	
	$ans = 0;
	for($i=$n; $i>0; $i--){
	    $a[$i] += $ans;
	    if($a[$i] != 0){
	        $a[$i] %= $b[$i];
	        if($a[$i] == 0) $a[$i] = $b[$i];
	        $ans += $b[$i] - $a[$i];
	    }
	}
	echo $ans;
?>

Measured memory_bytes: 20212
import queue

N, Q  = map(int,input().split())

ki = [[0,[]] for _ in range(N)]

for i in range(N-1):
    a,b  = map(int,input().split())
    a -= 1
    b -= 1
    ki[a][1].append(b)
    ki[b][1].append(a)

for i in range(Q):
    p,x = map(int,input().split())
    p -= 1
    ki[p][0] += x 

seen = [False for _ in range(N)]
que = queue.Queue()
que.put(0)
while not(que.empty()):
    now = que.get()
    seen[now] = True
    # print(ki[now][1])
    for i in range(len(ki[now][1])):
        nxt = ki[now][1][i]
        if seen[nxt]:
            continue
        else:
            ki[nxt][0] += ki[now][0]
            que.put(nxt)

for i in range(N):
    print("{} ".format(ki[i][0]),end="")
print()


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

int main() {
	int n;
	cin >> n;
	vector<int> b(n,0), a(n);
	int result = 0;
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			a.at(0) = b.at(0);
		}
		else if (i == n - 1) {
			a.at(i) = b.at(i - 1);
		}
		else {
			a.at(i) = min(b.at(i - 1), b.at(i));
		}
	}
	for (int i : a) {
		result += i;
	}
	cout << result << endl;
}

Measured memory_bytes: 256
class Main
  def self.run
    chessborads = read_inputs
    puts chessborads.map(&:draw).join("\n")
    puts "\n"
  end

  private

  def self.read_inputs
    chessborads = []
    while true do
      h, w = gets.split(" ").map(&:to_i)
      case [h, w]
        when [0, 0] then break
        else chessborads << Chessboard.new(h, w)
      end
    end
    chessborads
  end
end

class Chessboard
  def initialize(height, width)
    @height, @width = height, width
  end

  def draw
    output = ""
    (1..@height).each {|i|
      line = (i % 2 == 0 ? ".#" : "#.") * (@width / 2 + 1)
      output << "#{line.slice(0, @width)}\n"
    }
    output
  end
end

Main.run

Measured memory_bytes: 8952
n = int(input())
s = input()
ans = 0
a_list=[]
for i in sorted(list(set(s[:-2]))):
    index = s.index(str(i))
    for j in sorted(list(set(s[index+1:-1]))):
        index_2 = s[index+1:].index(j)+index+1
        ans += len(set(s[index_2+1:]))

print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
/// TONI BO$$ was here
/// #MLC

using namespace std;

int main()
{
    int n,k,i;
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
    scanf("%d%d",&n,&k);
    if(k>=(1<<n))
    {
        printf("-1");
        return 0;
    }
    if(n==1 && k==1)
    {
        printf("-1");
        return 0;
    }
    if(n==0)
    {
        printf("0 0");
        return 0;
    }
    if(k==0)
    {
        for(i=0; i<(1<<n); i++)
            printf("%d %d ",i,i);
        return 0;
    }
    for(i=0; i<(1<<n); i++)
        if(i!=k)
            printf("%d ",i);
    printf("%d ",k);
    for(i=(1<<n)-1; i>=0; i--)
        if(i!=k)
            printf("%d ",i);
    printf("%d",k);

    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cmath>
#include <stdlib.h>
using namespace std;
typedef long long ll;
int a[200010];
int main()
{
    int i, j, k;
    int n, t, m;
    cin >> k >> n;
    for(i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int mx = 0;
    for(i = 1; i < n; i++) {
        mx = max(mx, a[i]-a[i-1]);
    }
    mx = max(mx, k+a[0]-a[n-1]);
    cout << k-mx << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main(){
    string s;
    cin>>s;
    if(s=="Sunny")
        cout<<"Cloudy"<<endl;
    else if(s=="Cloudy")
        cout<<"Rainy"<<endl;
    else if(s=="Rainy")
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

int x,y;
vector<int>es[100010];
vector<int> topology;
stack<int> st;
int h[100010];
int longest[100010];

int main(){ _;
  int n,m;cin>>n>>m;
  REP(i,m){
    cin>>x>>y;
    x--;y--;
    es[x].push_back(y);
    h[y]++;
  }

  REP(i,n){
    if(h[i]==0){
      st.push(i);
    }
  }

  while(st.size()){
    int i=st.top();st.pop();
    topology.push_back(i);
    for(auto& e:es[i]){
      h[e]--;
      if(h[e]==0)st.push(e);
    }
  }

  for(auto f:topology){
    for(auto t:es[f]){
      longest[t]=max(longest[t],longest[f]+1);
    }
  }

  int result=0;
  REP(i,n){
    result=max(result,longest[i]);
  }
  cout<<result<<endl;
}


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

int main() {
   
  int N;
  cin >> N;
  vector<int> A(N);
  
  
  for (int i=0; i<N; i++){
	cin >> A.at(i);
  }
    int maximum = A.at(0);
    int minimum = A.at(0);
  for (int i=0; i<N; i++){
   
    if (maximum < A.at(i)) maximum = A.at(i);
    if (A.at(i) < minimum) minimum = A.at(i);
  }
  
  cout << maximum - minimum << endl;

}


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

using namespace std;

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;*/

    string s;cin>>s;
    map<char,int> m;
    char c='0';
    for(int i=0;i<10;i++){
        m[c]=i;
        c++;
    }
    if(m[s[0]]*10+m[s[1]]<=12&&m[s[0]]*10+m[s[1]]>0&&m[s[2]]*10+m[s[3]]<=12&&m[s[2]]*10+m[s[3]]>0){
        cout<<"AMBIGUOUS";
    }
    else if(m[s[0]]*10+m[s[1]]<=12&&m[s[0]]*10+m[s[1]]>0){
        cout<<"MMYY";
    }
    else if(m[s[2]]*10+m[s[3]]<=12&&m[s[2]]*10+m[s[3]]>0){
        cout<<"YYMM";
    }
    else {
        cout<<"NA";
    }


    return 0;
}

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

#define int ll
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 998244353;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e6 + 5;

int P[N];
bool MARK[N];

void DFS(int v) {
	MARK[v] = true;
	if (!MARK[P[v]]) DFS(P[v]);
}

int32_t main() {
 
	sync;

	int n; cin >> n;
	vector<pii> A, B;
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		A.push_back(make_pair(a, i));
	}
	for (int i = 1; i <= n; i++) {
		int b; cin >> b;
		B.push_back(make_pair(b, i));
	}
	sort(all(A));
	sort(all(B));
	for (int i = 0; i < n; i++) if (A[i].first > B[i].first) die("No");
	for (int i = 0; i < n - 1; i++) if (A[i + 1].first <= B[i].first) die("Yes");
	for (int i = 0; i < n; i++) P[A[i].second] = B[i].second;
	DFS(1);
	for (int i = 1; i <= n; i++) if (!MARK[i]) die("Yes");
	cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 5360
#include<set>
#include<map>
#include<deque>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<string>
#include<vector>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<complex>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;

const int maxn = 210000;

int n,m;
vector<int>V[maxn];
struct edge{int y,nex;}a[maxn]; int len,fir[maxn];
inline void ins(const int x,const int y){a[++len]=(edge){y,fir[x]};fir[x]=len;}

int rt,d[maxn],d2[maxn];
int v[maxn],oth[maxn];
int t[maxn],tp;
void dfs(const int x)
{
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) dfs(y);
	tp=0;
	for(int k=fir[x],y=a[k].y;k;k=a[k].nex,y=a[k].y) t[++tp]=oth[y];
	for(int i=2;i<=tp;i+=2)
	{
		int x=t[i-1],y=t[i];
		V[x].push_back(y); V[y].push_back(x);
	}
	if(d[x]&1) oth[x]=t[tp];
	else oth[x]=x;
}
void col(const int x)
{
	for(int i=0;i<V[x].size();i++)
	{
		const int y=V[x][i];
		if(v[y]==2) v[y]=-v[x],col(y);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		int x; scanf("%d",&x);
		if(x==-1) rt=i;
		else ins(x,i),d[x]++;
	}
	dfs(rt);
	
	memset(fir,0,sizeof fir); len=0;
	for(int i=1;i<=n;i++)
	{
		int x; scanf("%d",&x);
		if(x==-1) rt=i;
		else ins(x,i),d2[x]++;
	}
	for(int i=1;i<=n;i++) if((d[i]&1)!=(d2[i]&1)) { puts("IMPOSSIBLE");return 0; }
	for(int i=1;i<=n;i++) if(!(d[i]&1)) v[i]=2;
	dfs(rt);
	
	for(int i=1;i<=n;i++) if(v[i]==2) v[i]=1,col(i);
	puts("POSSIBLE");
	for(int i=1;i<=n;i++) printf("%d ",v[i]);
	
	return 0;
}


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

namespace abc154_e
{
  class Program
  {
    static void Main(string[] args)
    {
      var N = CIn.Read().Select(e => e - '0').ToArray();
      var K = CIn.ReadInt();

      var dp = new long[N.Length + 1, 2, K + 2];
      dp[0, 0, 0] = 1;

      for (int i = 1; i <= N.Length; i++)
      {
        for (int j = 0; j <= K; j++)
        {
          if (N[i - 1] == 0)
          {
            dp[i, 0, j] += dp[i - 1, 0, j];
          }
          else
          {
            dp[i, 0, j + 1] += dp[i - 1, 0, j];
            dp[i, 1, j] += dp[i - 1, 0, j];
            dp[i, 1, j + 1] += dp[i - 1, 0, j] * (N[i - 1] - 1);
          }

          dp[i, 1, j] += dp[i - 1, 1, j];
          dp[i, 1, j + 1] += dp[i - 1, 1, j] * 9;
        }
      }

      Console.WriteLine(dp[N.Length, 0, K] + dp[N.Length, 1, K]);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(int n)
    {
      var array = new string[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(int n)
    {
      var array = new int[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(int n)
    {
      var array = new long[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(int n)
    {
      var array = new double[n];
      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(int h, int w)
    {
      var array = new char[h, w];
      for (var i = 0; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


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

int N, M, Q;
vector<vector<int>> ABCD;
int ans;

void dfs (vector<int> A, int dep, int pre) {
  if (dep == N) {
    int sum = 0;
    for (auto a : ABCD) {
      if (A.at(a.at(1)) - A.at(a.at(0)) == a.at(2)) {
        sum += a.at(3);
      }
    }
    ans = max(ans, sum);
    return;
  }
  for (int i = pre; i <= M; i++) {
    vector<int> NA = A;
    NA.at(dep) = i;
    dfs(NA, dep + 1, i);
  }
}

int main() {
  cin >> N >> M >> Q;
  for (int a, b, c, d; cin >> a >> b >> c >> d;) {
    ABCD.push_back({--a, --b, c, d});
  }
  vector<int> A(N);
  dfs(A, 0, 1);
  cout << ans << "\n";
}

Measured memory_bytes: 3604