akhauriyash/Code-Regression huggingface dataset:
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(usize);

    let ans = N.to_string()
        .chars()
        .map(
            |d| if d == '2' {
                1
            } else {
                0
            }
        )
        .sum::<usize>();

    println!("{}", ans);
}


Measured memory_bytes: 4352
N,K=map(int, input().split())
#1~NのKで割ったあまり
ks=0
k2s=0
for i in range(1,N+1):
    if K%2==0:
        if i%K==0:
            ks+=1
        elif i%(K//2)==0:
            k2s+=1
    else:
        if i%K==0:
            ks+=1
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


ans=0
if ks>=1:
    ans+=cmb(ks,1)
if ks>=2:
    ans+=cmb(ks,2)*6
if ks>=3:
    ans+=cmb(ks,3)*6
#print(ks,k2s)
if k2s>=1:
    ans+=cmb(k2s,1)
if k2s>=2:
    ans+=cmb(k2s,2)*6
if k2s>=3:
    ans+=cmb(k2s,3)*6
print(ans)

Measured memory_bytes: 3828
def main():
    N, K = map(int, input().split())
    MOD = 10**9 + 7
    ans = 0

    # 0, 0, 1, 3, 6, ...
    sub_sum = [0] * (N+2)
    for i in range(2, N+2):
        sub_sum[i] = sub_sum[i-1] + i-1
    
    for i in range(K, N+2):
        min_val = sub_sum[i]
        max_val = sub_sum[N+1] - sub_sum[N+1-i]
        ans += max_val - min_val + 1
        ans %= MOD
        
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 16788
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
long long dp[2010];
int main()
{
    int S;
    cin >> S;
    dp[0] = 1LL;
    dp[1] = 0LL;
    dp[2] = 0LL;
    for (int i = 3; i <= S; i++)
    {
        dp[i] = (dp[i - 3] + dp[i - 1]) % mod;
    }
    cout << dp[S] << endl;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#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;
using ll = long long;
using pi = pair<int,int>;
constexpr ll mod = 1000000007;
void pPRINTl(ostream& ost) { ost << endl; }
template <class T>void pPRINTL(ostream& ost,T t){ost<<t<<endl;}
template <class T, class... U>void pPRINTl(ostream& ost, T t, U... u) {ost << t << " ";pPRINTl(ost, u...);}
template <class... T>void PRINTl(T... t) { pPRINTl(cout, t...); }
void pPRINT(ostream& ost) {}
template <class T>void pPRINT(ostream& ost, T t){ost<<t;}
template <class T, class... U>void pPRINT(ostream& ost, T t, U... u) {ost << t << " ";pPRINT(ost, u...);}
template <class... T>void PRINT(T... t) { pPRINT(cout, t...); }

ll dfs(int from,int on,vector<vector<int>>& v,int K){
  ll eK = (from==-1?K-1:K-2);
  ll count=(from==-1?K:1);
  //PRINTl(count,from,on,eK,K,"init");
  for(auto&& e: v[on]){
    if(e==from)continue;
    if(eK<1){count=0;break;}
    count*=eK--;
    count%=mod;
    //PRINTl(count,from,on,e,eK,K,"root");
  }
  for(auto&& e: v[on]){
    if(e==from)continue;
    if(K>1)count*=dfs(on,e,v,K);
    count%=mod;
    //PRINTl(count,from,on,e,eK,K,"child");
  }
  return count;    
}
  

int main() {
  ll n,k;
  cin>>n>>k;
  auto v = vector<vector<int>>(n);
  REP(i,n-1){
    ll a,b;
    cin>>a>>b;a--;b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  /*REP(i,n){
    cout<<i+1<<" : ";
    for(auto&& e:v[i])cout<<e+1<<" ";
    cout<<endl;
  }*/
  cout<<dfs(-1,0,v,k)%mod;
  return 0;
}



Measured memory_bytes: 11520
S = input()
N = len(S)
#dp[i][j] ... 先頭i文字として考えられるもののうち13で割った余りがjになる個数
dp = [[0] * 13 for _ in range(N+1)]
dp[0][0] = 1
mod = 10**9+7
#1?2?3   0 -> 3 -> ?3 -> 2?3 -> ...
mul = 1
for i in range(N): #全ての桁
    for k in range(13): #0~12
        if S[N-i-1] == "?":
            for j in range(10): #?に当てはめる数字
                dp[i+1][(k + j*mul) % 13] += dp[i][k]
                dp[i+1][(k + j*mul) % 13] %= mod
        else:
            j = int(S[N-i-1])
            dp[i+1][(k + j*mul) % 13] += dp[i][k]
            dp[i+1][(k + j*mul) % 13] %= mod
    mul *= 10
    mul %= 13
print(dp[N][5])
#print(dp)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

bool X[300100];
int SB[300100];
int SW[300100];
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    REP(i,N){
        char s = S[i];
        X[i] = s == '.';
    }

    int start = 0;
    int end = N-1;

    REP(i,N){
        if(X[i]) start++;
        else break;
    }

    for(int i = N-1; i >= 0; i--){
        if(!X[i]) end--;
        else break;
    }

    //cout << start << endl;
    //cout << end << endl;
    int white = 0;
    int black = 0;
    for(int i = start; i <= end; i++){
        if(X[i]) SW[i]++;
        else SB[i]++;

        if(i != 0){
            SW[i] += SW[i-1];
            SB[i] += SB[i-1];
        }
    }

    int ans;
    ans = min(SW[end], SB[end]);
    for(int i = start; i <= end; i++){
        int num = SB[i];
        int x = SW[end] - SW[i];
        int y = SB[end]-SB[i];
        num += min(x, y);
        //printf("%d, %d, %d, %d, %d\n", i, num, ans, x, y);
        chmin(ans, num);
    }

    //ans = min(black, white);

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


Measured memory_bytes: 2308
public class Main{
  public void run(java.io.InputStream in, java.io.PrintStream out){
    java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
    int s;
    s = sc.nextInt();
    System.out.println((s / 3600) + ":" + ((s % 3600) / 60) + ":" + (s % 60));
/*fin*/
    sc.close();
  }
  public static void main(String[] args){
    (new Main()).run(System.in, System.out);
  }
}


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

int main(void){
	int a,b,n;
	while(cin >> a >> b >> n){
		if(cin.eof()) break;
		int sum=0;
		a-=a/b*b;
		a*=10;
		rep(i,n){
			int add=a/b;
			sum+=add,a-=add*b;
			a*=10;
		}
		cout << sum << endl;
	}
	return 0;
}

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

using namespace std;

#define td typedef
td long long ll;

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

int main()
{
    int n=in(),a=in(),b=in();
    if((b-a)%2==0)
        printf("Alice\n");
    else if((b-a)%2==1)
        printf("Borys\n");
}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

n,m=MI()
ls=[]
rs=[]
for i in range(m):
    line=input().rstrip().split()
    ls.append(int(line[0]))
    rs.append(int(line[1]))
mx=0
mn=10**6
for l in ls:
    if l>mx:
        mx=l
#print(mx)
for r in rs:
    if r<mn:
        mn=r
#print(mn)
ans=max(mn-mx+1,0)
print(ans)

Measured memory_bytes: 50012
s=input()
n=len(s)
m=int((n-1)/2)
r=1
for i in range (0,m):
  if s[i]!=s[m-1-i]:
    r=0
  elif s[i]!=s[m+1+i]:
    r=0
  elif s[i]!=s[2*m-i]:
    r=0
if r==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
int main(){
  int N;
  double tmp;
  char kind[10];
  double sum = 0.0;
  scanf("%d\n",&N);
  for(int i=0;i<N;i++){
    scanf("%lf %s\n",&tmp,kind);
    if(!strcmp(kind,"JPY")) sum += tmp;
    else sum += tmp*380000.0;
  }
  printf("%lf",sum);
  return 0;
}

Measured memory_bytes: 128
a, b, m = list(map(int, input().split()))
refrigerator_list = list(map(int, input().split()))
microwave_list = list(map(int, input().split()))
coupon_list = list()
for _ in range(m):
    coupon_list.append(list(map(int, input().split())))

ans = min(refrigerator_list) + min(microwave_list)
for coupon in coupon_list:
    ans = min(refrigerator_list[coupon[0] - 1] + microwave_list[coupon[1] - 1] - coupon[2], ans)

print(ans)


Measured memory_bytes: 38848
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

dp = [[0 for i in range(10)] for j in range(10)]

for i in range(1,n+1):
    num = str(i)
    dp[int(num[0])][int(num[-1])] += 1
su = 0

for i in range(10):
    for j in range(10):
            su += dp[j][i] * dp[i][j]
print(su)









Measured memory_bytes: 40428
#pragma GCC Optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define lp(i,begin,end) for (int i=begin;i<end;i++)
const int N=30,M=N*N,OO=0x3f3f3f3f;
int freq[30];
int main(){
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d",((a+b)*c)/2);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
char s[100010];
int x[100010],k;
int main(){
	int n,i,k,M;
	scanf("%s",s+1);
	n=strlen(s+1);
	#define wa {puts("-1");return 0;}
	if(s[1]=='0'||s[n]=='1')wa
	for(i=1;i<n;i++){
		if(s[i]!=s[n-i])wa
	}
	k=0;
	for(i=1;i<n;i++){
		if(s[i]=='1')x[++k]=i;
	}
	M=k+1;
	for(i=1;i<=k;i++)printf("%d %d\n",i,i+1);
	for(i=2;i<=k;i++){
		n=x[i]-x[i-1]-1;
		while(n--)printf("%d %d\n",i,++M);
	}
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
string s;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> s;
    long long aa = 0;
    int ca = 0;
    set<int>ll;
    for(int i = 0; i + 2 < s.size();)
    {
        if(ll.find(i) != ll.end())
            --ca;
        if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C')
        {
            ++ca, aa += ca, s[i+2] = 'A';
            ll.insert(i + 2);
            i = i+2;
        }
        else
            if(s[i] == 'A')
                ++ca, ++i;
            else
                ca = 0, ++i;
    }
    cout << aa;
    return 0;
}


Measured memory_bytes: 3604
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)

int main() {
	int N; cin >> N;
	int sum = 0;
	rep(i, 0, N) {
		int l, r; cin >> l >> r;
		sum += r - l + 1;
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <regex>
#include <cmath>
#include <vector>
#include <queue>
#include <functional>
#include <numeric>
#include <iomanip>
#include <stack>
#include <string>
#include <map>
#include <set>
using namespace std;
typedef long long ll;

int main () {
    ll R, G, B, N;
    cin >> R >> G >> B >> N;
    ll ans;
    for (int r = 0; r <= N; r++)
    {
        for (int g = 0; g <= N; g++)
        {
            ll b = N - R * r - G * g;
            if(b >= 0 && b % B == 0) {
                ans++;
            }
        }
        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
def P(n, r):
    return math.factorial(n)//math.factorial(n-r)
def C(n, r):
    return P(n, r)//math.factorial(r)

N = int(input())
moji =[]
for i in range(N):
    a = sorted(input())
    moji.append(''.join(a))


dic = {}
for i in moji:
    if i in dic:
        dic[i] += 1
    else:
        dic[i] = 1

ans = 0
for value in dic.values():
    if value >=2:
        ans+=C(value, 2)

print(ans)

Measured memory_bytes: 101800
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
INIT_VAL = 0
def DD2(d1,d2): return [[INIT_VAL]*d2 for _ in range(d1)]
def DD3(d1,d2,d3): return [DD2(d2,d3) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left

#======================================================#

def main():
    n = II()
    aa = MII()
    minv = 10**5
    for a in aa:
        cnt = 0
        while a%2 == 0:
            cnt += 1
            a //= 2
        minv = min(minv, cnt)
    print(minv)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  string str;
  cin>>str;
  int l=str.size();
  for(int i=0;i<l;i++)
    cout<<"x";
  return 0;
}


Measured memory_bytes: 256
// ref: https://img.atcoder.jp/abc104/editorial.pdf
// ref: https://atcoder.jp/contests/abc104/submissions/2954675

#include <bits/stdc++.h>
using namespace std;
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    uint D, G; cin >> D >> G;
    vector<int> vP(D), vC(D);
    for(uint i=0; i<D; ++i){
        cin >> vP[i] >> vC[i];
    }
    
    int ans=INT_MAX;
    for(uint d=0; d<((uint)1<<D); ++d){
        int64 sum=0ll;
        int rest_max=D-1;
        int num=0;
        
        for(uint i=0, dTmp=d; i<D; ++i, dTmp>>=1){
            if(dTmp&1){ rest_max=i; continue; }
            sum += 100*(i+1)*vP[i] + vC[i];
            num += vP[i];
        }
        if(sum<G){
            int64 restSize = 100 * (rest_max+1);
//            int64 need = ceil(((double)G - (double)sum)/(double)restSize);
            int64 need = (G - sum + restSize - 1)/restSize;
            if(need>=vP[rest_max]){ continue; }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
template <typename T>
string to_string(const T &n){ostringstream stm;stm << n;return stm.str();}
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
using ll = long long;
const ll mod = LLONG_MAX;
 #define int long long
 int a[3010];
 int ans;
signed main(){
    int R,G,B,N;
    cin>>R>>G>>B>>N;
    rep(i,3001){
        if(N-R*i<0)break;
        a[N-R*i]++;
    }

    rep(i,3001){
        rep(j,3001){
            if(G*i+B*j>3000)continue;
            if(a[G*i+B*j]){
                ans++;
            }
        }
    }
    cout<<ans<<endl;
}

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

int main() {
  char s;
  
  cin >> s;
  
  switch(s){
    case 'a':
    case 'i':
    case 'u':
    case 'e':
    case 'o':
      cout << "vowel" << endl;
      break;
    default:
      cout << "consonant" <<endl; 
      break;
  }
}


Measured memory_bytes: 3592
#include<stdio.h>
static const int N = 501;
static const int INFTY = (1<<21);
int main(){
  int M[N][N];
  int p, u, k, v; 
  int l, m;
  scanf("%d", &p);
  for ( l = 0; l <p; l++ ){
    for ( m = 0; m <p; m++ ) M[l][m] = 0;
  }
  for ( l = 0; l < p; l++ ){
    scanf("%d %d", &u, &k);
    u--;
    for ( m = 0; m < k; m++ ){
      scanf("%d", &v);
      v--;
      M[u][v] = 1;
    }
  }
  for ( l = 0; l < p; l++ ){
    for ( m = 0; m < p; m++ ){
      if ( m ) printf(" ");
      printf("%d", M[l][m]);
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2148
import math
n, h = map(int, input().split())
s = []
for i in range(n):#h:高さ
    s.append([int(m) for m in input().split()])#a,b
t = []
for i in range(n):
    t.append(["a", i + 1, s[i][0]])
    t.append(["b", i + 1, s[i][1]])
t.sort(key=lambda x:(x[2]),reverse=True)

count = 0
p = 0
for i in range(n + 1):
    if t[i][0] == "b":
        h -= t[i][2]
        count += 1
        if h <= 0:
            break
    else:
        count += math.ceil(h / t[i][2])
        break
print(count)


Measured memory_bytes: 51152
N, K = map(int,input().split())

if N > K:
  N = N % K

min_N = float("inf")
while min_N != N:
  min_N = min(N,min_N)
  if N == K or N == 0 or K == 0:
    print(0)
    exit(0)
  
  N = abs(N - K)
  
print(min_N)

Measured memory_bytes: 9096
#include<iostream>
#include<bits/stdc++.h>
#define pq priority_queue
#define Pi acos(-1.0)
#define MOD 1000000007
using namespace std;
int q[100005];
int l;
int n,c,k;
int main()
{
    l=0;
    int ans=0;
    scanf("%d%d%d",&n,&c,&k);
    for(int i=0;i<n;i++)
        scanf("%d",q+i);
    sort(q,q+n);
    for(int i=0;i<n;i++)
    {
        if(l<i && q[i]>q[l]+k)
        {
            ans++;
            l=i;
        }
        if(i+1-l==c)
        {
            ans++;
            l=i+1;
        }
    }
    if(l<n)
        ans++;
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define END getchar();getchar();return 0

signed main() {
	char h;
	cin >> h;
	if (h == 'A') {
		cout << 'T' << endl;
	}
	else if (h == 'C') {
		cout << "G" << endl;
	}
	else if (h == 'G') {
		cout << "C" << endl;
	}
	else {
		cout << "A" << endl;
	}

	END;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

bool check(int k){
    string s=to_string(k),t=s;
    reverse(ALL(t));
    return s==t;
}

signed main()
{
    int A,B; cin>>A>>B;
    int ans=0;
    for(int i=A;i<=B;i++){
        if(check(i)) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int N;
    std::string S;
    std::cin >> N;
    std::cin >> S;

    std::vector<int> east_bits(N);
    std::vector<int> west_bits(N);
    for (int i = 0; i < N; i ++) {
        east_bits[i] = S[i] == 'E';
        west_bits[i] = S[i] == 'W';
    }
    std::vector<int> east_cumsum;
    std::partial_sum(east_bits.begin(), east_bits.end(), std::back_inserter(east_cumsum));
    std::vector<int> west_cumsum;
    std::partial_sum(west_bits.begin(), west_bits.end(), std::back_inserter(west_cumsum));

    int min_changes = N;
    for (int i = 0; i < N; i ++) {
        if (i == 0) {
            int changes = east_cumsum[N - 1] - east_cumsum[0];
            min_changes = std::min(min_changes, changes);
        } else if (i == N - 1) {
            int changes = west_cumsum[N - 2];
            min_changes = std::min(min_changes, changes);
        } else {
            int changes_r = east_cumsum[N - 1] - east_cumsum[i];
            int changes_l = west_cumsum[i - 1];
            min_changes = std::min(min_changes, changes_r + changes_l);
        }
    }
    std::cout << min_changes << std::endl;
}


Measured memory_bytes: 7160
/// WA

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using ordered_set = tree<T, null_type,
less<T>, rb_tree_tag, 
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int a, b;
    cin >> a >> b;
    if (a > b)
        swap(a, b);
    while (b--)
        cout << a;
    return 0;
}


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

using namespace std;

#define whole(xs) (xs).begin(), (xs).end()

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<int> A;
    void input() {
        cin >> N;
        A.resize(N); cin >> A;
    }

    const int INF = 1<<28;

    int cost(int x, int y) {
        int ret = 0;
        int c = 0;
        for (int i = 0; ; i++) {
            if (x == 0 && y == 0 && c == 0) break;
            int xi = x % 10; x /= 10;
            int yi = y % 10; y /= 10;
            ret += xi * yi + c;
            if (xi + yi + c >= 10) c = 1;
            else c = 0;
        }
        return ret;
    }

    void solve() {

        vector<int> sum(N + 1, 0);
        for (int i = 0; i < N; i++) {
            sum[i + 1] = sum[i] + A[i];
        }

        vector< vector<int> > dp = vector< vector<int> >(N, vector<int>(N + 1, INF));

        for (int i = 0; i + 1 <= N; i++) {
            dp[i][i + 1] = 0;
        }

        for (int k = 2; k <= N; k++) {
            for (int i = 0; i + k <= N; i++) {
                for (int j = 1; j < k; j++) {
                    //cerr << k << " " << i << " " << j<< endl;
                    dp[i][i + k] = 
                        min (
                            dp[i][i + k], 
                            dp[i][i + j] + dp[i + j][i + k] + cost(sum[i + j] - sum[i], sum[i + k] - sum[i + j])
                        );
                }
            }
        }
        cout << dp[0][N] << endl;
    }
}

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

Measured memory_bytes: 3284
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>


using namespace std;


int main()
{
    long long x,t;
    cin>>x>>t;
    if(x>=t)
    cout<<x-t;
    else
    cout<<"0";

    return 0;
}     

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

using namespace std;

int main() {
    int N, A, B;
    cin >> N >> A >> B;
    string S;
    cin >> S;

    int a = 0;
    int b = 0;
    
    for(int i=0; i<N; i++) {
        switch(S.at(i)) {
            case 'a':
                if(a+b < A+B) {
                    cout << "Yes" << endl;
                    a++;
                } else {
                    cout << "No" << endl;
                }
            break;
            case 'b':
                if(a+b < A+B && b < B) {
                    cout << "Yes" << endl;
                    b++;
                } else {
                    cout << "No" << endl; 
                }
            break;
            case 'c':
                cout << "No" << endl;
            break;
        }
    }

}

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

using namespace std;

int lg, N, L, Q, x[100009], nxt[18][100009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    scanf ("%d", &x[i]);
scanf ("%d", &L);
int j = 1;
for (int i=1; i<=N; i++)
{
    while (j < N && x[j + 1] - x[i] <= L) j ++;
    nxt[0][i] = j;
}
for (int i=1; (1 << i) < N; lg = i, i++)
    for (int j=1; j<=N; j++)
        nxt[i][j] = nxt[i - 1][nxt[i - 1][j]];
scanf ("%d", &Q);
while (Q --)
{
    int st, dr, ans = 0;
    scanf ("%d %d", &st, &dr);
    if (st > dr) swap (st, dr);
    for (int i=lg; i>=0; i--)
        if (nxt[i][st] < dr) ans |= 1 << i, st = nxt[i][st];
    printf ("%d\n", ans + 1);
}
return 0;
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int n = Integer.parseInt(W);


		System.out.println(n*n*n);
	}
}


Measured memory_bytes: 22100
s = str(input())
n = int(input())
num = []
cnt = 1
for i in range(len(s)-1):
    if s[i+1] != s[i]:
        num.append(cnt)
        cnt = 1
    else:
        cnt += 1
num.append(cnt)
if len(num) == 1:
    print((num[0] * n)//2)
    exit()
ans = 0
for nu in num:
    ans += nu//2
if s[0] != s[-1]:
    ans *= n
else:
    ans -= num[0]//2
    ans -= num[-1]//2
    ans *= n
    ans += num[0]//2
    ans += num[-1]//2
    ans += ((num[0]+num[-1])//2)*(n-1)
print(ans)

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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
int a,b,c;cin>>a>>b>>c;
cout<<a*b/2<<endl;


  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int n = sc.nextInt();
        String[][] ans = new String[h][w];
        int[] color = new int[n];
        for(int i = 0; i < n; i++){
            color[i] = sc.nextInt();
        }
        boolean isReverse = false;
        int nowx = 0;
        int nowy = 0;
        for(int i = 0; i < n; i++){
            while(color[i] > 0){
                ans[nowy][nowx] = String.valueOf((i+1));
                color[i]--;
                if(isReverse){
                    if(nowx == 0){
                        nowy++;
                        isReverse = false;
                    }else{
                        nowx--;
                    }
                }else{
                    if(nowx == w-1){
                        nowy++;
                        isReverse = true;
                    }else{
                        nowx++;
                    }
                }
            }
        }
        for(int i = 0; i < h; i++){
            for(int j = 0; j < w; j++){
                System.out.print(ans[i][j]+" ");
            }
            System.out.println();
        }
    }
}

Measured memory_bytes: 32548
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	int dp[n]={0};
    for(int i=1;i<n;i++)
    {
        int ans1=INT_MAX;
        int ans2=INT_MAX;
        if(i>=1)
        {
             ans1=dp[i-1]+abs(a[i]-a[i-1]);
        }
        if(i>=2)
        {
            ans2=dp[i-2]+abs(a[i]-a[i-2]);
        }
        dp[i]=min(ans1,ans2);
    }
    cout<<dp[n-1]<<endl;
	
}

Measured memory_bytes: 4420
from functools import lru_cache
h, w, d = map(int, input().split())
pos = [[] for j in range(h*w)]
for a in range(h):
    s = list(map(int, input().split()))
    for g in range(w):
        pos[s[g] -1] = [s[g], a+1, g+1]
q = int(input())

def soo(now, start):
    next = now + d
    prevy, prevx = pos[now - 1][1], pos[now - 1][2]
    nexty, nextx = pos[next - 1][1], pos[next - 1][2]
    return ((abs(nexty - prevy) + abs(nextx - prevx)))

def solve(start, end):
    now = 0
    ans = 0
    for i in range(int((end - start) / d)):
        now = start if not now else now + d
        ans += soo(now, start)
    return ans

time = [0 for h in range(h*w)]
for l in range(h*w - d):
    if not time[l + d]:
        time[l+d] = time[l] + (abs(pos[l+d][1] - pos[l][1]) + abs(pos[l+d][2] - pos[l][2]))


@lru_cache(maxsize=None)
def ask(st, en):
    return time[en-1] - time[st-1]


for rr in range(q):
    dd, ff = map(int, input().split())
    print(ask(dd, ff))

Measured memory_bytes: 51936
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	ll n;
	cin >> n;

	vector<ll> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	vector<ll> dp = a;
	for (ll i = 1; i < n; i++) {
		dp[i] += dp[i - 1];
	}

	map<ll, ll> mp;
	mp[0]++;

	ll ans = 0;
	for (auto v : dp) {
		if (mp.count(v) != 0) {
			ans += mp[v];
		}

		mp[v]++;
	}

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


Measured memory_bytes: 15872
#include <stdio.h>
#include <stdlib.h>
#define repl(a, b) for(int a=0; a<b; ++a)
#define max(a,b) ((a > b) ? a : b)
#define min(a,b) ((a > b) ? b : a)

const int big = 1000000000;

int main () {
    int n, mini, maxi, stami = 0, min_sta = big;
    scanf("%d", &n);
    int vec[n];
    repl(i, n) scanf("%d", &vec[i]);
    maxi = mini = vec[0];
    repl(i,n) {
        maxi = max(maxi, vec[i]);
        mini = min(mini, vec[i]);
    }
    for(int i=mini; i<=maxi; ++i) {
        stami = 0;
        repl(j, n) {
            stami += (vec[j]-i) * (vec[j]-i);
            //printf("%d\n", stami);
        }
        min_sta = min(min_sta, stami);
    }
    printf("%d\n", min_sta);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <tr1/unordered_map>
#define ri register int
#define ptf printf
using namespace std;
typedef double db;
typedef long double ld;
typedef long long ll;
typedef vector <int> poly;
typedef pair <int, int> pii;
typedef pair <ll, int> pli;
typedef pair <int, ll> pil;
typedef pair <ll, ll> pll;
typedef unsigned long long ulll;
typedef unsigned int uii;
typedef string strr;
#define fi first
#define se second
#define pb push_back
#define ppp pop_back
#define rez resize
const ll Inf = 2e18;
const int rlen = 1 << 20, inf = 0x3f3f3f3f;
char buf[rlen], *ib = buf, *ob = buf;
#define gc() getchar()//(((ib == ob) && (ob = (ib =  buf) + fread(buf, 1, rlen, stdin)), ib == ob) ? -1 : *ib++)
inline int read() {
  static int ans, f;
  static char ch;
  ans = 0, ch = gc(), f = 1;
  while (!isdigit(ch)) f ^= ch == '-', ch = gc();
  while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = gc();
  return f ? ans: -ans;
}
inline ll readl() {
  static ll ans;
  static char ch;
  for (ans = 0, ch = gc(); !isdigit(ch); ch = gc());
  while (isdigit(ch)) ans = ((ans << 2) + ans << 1) + (ch ^ 48), ch = gc();
  return ans;
}
inline int Read(char *s) {
  static int top;
  static char ch;
  top = 0, ch = gc();
  while (!isalpha(ch) && !isdigit(ch)) ch = gc();
  while (isalpha(ch) || isdigit(ch)) s[++top] = ch, ch = gc();
  return top;
}
namespace modular {
  const int mod = 998244353;//= 1e9 + 7;
  //int mod;
  int ret;
  inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
  inline int dec(int a, int b) { return a < b ? a - b + mod : a - b; }
  inline int mul(int a, int b) { return (ll) a * b % mod; }
  inline void Add(int &a, int b) { a = a + b < mod ? a + b : a + b - mod; }
  inline void Dec(int &a, int b) { a = a < b? a - b + mod : a - b; }
  inline void Mul(int &a, int b) { a = (ll) a * b % mod; }
  inline int ksm(int a, int p) {
    for (ret = 1; p; p >>= 1, Mul(a, a)) (p & 1) && (Mul(ret, a), 1);
    return ret;
  }
  inline int Inv(int a) { return ksm(a, mod - 2); }
  inline int sqr(int a) { return (ll) a * a % mod; }
  inline int cub(int a) { return (ll) a * a % mod * a % mod; }
} using namespace modular;
template <typename T> inline void ckmax(T &a, T b) { a < b ? a = b : 0; }
template <typename T> inline void ckmin(T &a, T b) { a > b ? a = b : 0; }
template <typename T> inline T Abs(T a) { return a < 0 ? -a : a; }
template <typename T> inline T gcd(T a, T b) {
  T t;
  while (b) t = a, a = b, b = t - t / a * a;
  return a;
}
template <typename T> inline void exgcd(T a, T b, T &x, T &y) {
  if (!b) {
    x = 1, y = 0;
    return;
  }
  exgcd(b, a - a / b * b, y, x);
  y -= a / b * x;
}
const int N = 1e6 + 5;
int n;
char s[N];
int a[N];
int main() {
  #ifdef ldxcaicai
  freopen("lx.in", "r", stdin);
  #endif
  //n = read();
  for (ri i = 1; i <= 5; ++i) {
    int x = read();
    if (!x) return cout << i, 0;
  }
  return 0;
}

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

int main() {
    int a,b;
    cin >> a >> b;
    rep2(i,1,10000) {
        if(i*8/100 == a && i*10/100 == b) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    while (true) {
        val inputString = readLine()!!
        if (inputString == "-") break

        var deck = inputString
        for (i in (0 until readLine()!!.toInt())) {
            val num = readLine()!!.toInt()
            deck = deck.substring(num) + deck.substring(0, num)
        }
        println("$deck")
    }
}



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

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

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct ban
{
    int i;
    string s;
    int p;
};
bool operator<(const ban& a, const ban& b)
{
    if (a.s < b.s)
        return true;
    if (a.s > b.s)
        return false;
    return a.p > b.p;
}

int n;
ban a[N];

int main()
{
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        a[i].i = i;
        cin >> a[i].s >> a[i].p;
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
        cout << a[i].i << endl;
    return 0;
}


Measured memory_bytes: 2560
// #include <ext/pb_ds/assoc_container.hpp> 
    // #include <ext/pb_ds/tree_policy.hpp> 
    #include <iostream>
    #include <iomanip>
    #include <sstream>
    #include <cstring>
    #include <vector>
    #include <deque>
    #include <queue>
    #include <set>
    #include <map>
    #include <valarray>
    #include <iterator>
    #include <functional>
    #include <limits>
    #include <algorithm>
    #include <numeric>
    #include <cmath>
    #include <cassert>
    #include <unordered_map>
    #include <unordered_set>
    #include <stack>
    using namespace std;
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define trace(x) cerr << #x << ": " << x << " " << endl;
     
    typedef int64_t ll;
     
    #define endl '\n'
    #define int ll
    ll mod=1e18;
    ll mod1=1e9+5;
     
    ll power(ll a,ll b)
    {
        if(b==0) return 1;
        else if(b%2==0)
            return power((((a%mod)*(a%mod))%mod),b/2)%mod;
        else return ((a%mod)*(power((((a%mod)*(a%mod))%mod),b/2)%mod))%mod;
    }
     
    // using namespace __gnu_pbds;
    // #define ordered_set tree<pair<int,pair<int,int>>, null_type,less<pair<int,pair<int,int>>>, rb_tree_tag,tree_order_statistics_node_update>
    //find_by_order(k)  returns iterator to kth element starting from 0;
    //order_of_key(k) returns count of elements strictly smaller than k;
    //erase,insert same as normal set
    
    
    
    int32_t main()
    {
        IOS
      
        
       int a[3];
       cin>>a[0]>>a[1]>>a[2];
       sort(a,a+3);
       if(a[0]==a[2])
       {
        cout<<"No";
        return 0;
       }
       if(a[0]==a[1])
       {
        cout<<"Yes";
        return 0;
       }
       if(a[1]==a[2])
       {
        cout<<"Yes";
        return 0;
       }
       cout<<"No";

    }       

Measured memory_bytes: 256
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $ans = [];
  for ($i=0; $i<$n; $i++) {
    list($a) = explode(" ", trim(fgets(STDIN)));
    if(!isset($ans[$a])) $ans[$a]=0;
    $ans[$a]++;
  }
  
  echo count($ans);

Measured memory_bytes: 16056
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int top, S[1000];

void push(int x) {
	S[++top] = x;
}

int pop() {
	top--;
	return S[top + 1];
}

int main() {
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
		}
	}

	printf("%d\n", pop());

	return 0;
}


Measured memory_bytes: 2692
using System;
using static System.Console;
using static System.Math;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            bool ans = true;
            var a = new int[6];
            for(int i = 0; i < 6; i ++)
            { 
                a[i] = int.Parse(ReadLine()); 
            }
            WriteLine(a[4] - a[0] > a[5]? ":(":"Yay!");
        }
    }
}

Measured memory_bytes: 13140
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>

//void swap(int* a, int* b)
//{
//	int t = *a;
//	*a = *b;
//	*b = t;
//}
//
//int partition(int array[], int l, int r) {
//	int pivot = array[r];
//	int i = (l - 1);
//
//	for (int j = l; j <= r - 1; j++) {
//		if (array[j] <= pivot) {
//			i++;
//			swap(&array[i], &array[j]);
//		}
//	}
//	swap(&array[i + 1], &array[r]);
//	return (i + 1);
//}
//
//void quickSort(int array[], int l, int r) {
//	if (l < r) {
//		int pivot = partition(array, l, r);
//		quickSort(array, l, pivot - 1);
//		quickSort(array, pivot + 1, r);
//	}
//}
//
//int main() {
//	int N;
//	int* A = (int*)malloc(sizeof(int) * 200000);
//	int count = 0;
//	std::cin >> N;
//	for (int i = 0;i < N;i++) {
//		std::cin >> A[i];
//	}
//
//	quickSort(A, 0, N - 1);
//	
//	for (int i = 0;i < N;i++) {
//		for (int j = 0;j < N;j++) {
//			if (i == j)continue;
//			
//
//			if (A[i] % A[j] == 0 ) {
//				count++;
//				break;
//			}
//
//			if (j == i + 1)break;
//		}
//	}
//	printf("%d", N - count);
//
//
//	return 0;
//}

const int M = 1000005;

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

	for (int i = 0;i < n;i++) {
		std::cin >> a[i];
	}
	std::vector<int> cnt(M);

	for (int x : a) {
		if (cnt[x] != 0) {
			cnt[x] = 2;
			continue;
		}
		for (int i = 0;i < M;i += x) {
			cnt[i]++;
		}
	}

	int ans = 0;
	for (int x : a) {
		if (cnt[x] == 1) {
			ans++;
		}
	}

	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 8008
main = do
  n <- readLn :: IO Int
  dat <- getContents >>= return . (map ((map read) . words)) . lines :: IO [[Int]]


  mapM_ print [func (drop i dat) 0 | i<-[0..n-1]]


  where
    func [] cr = cr
    func ((c:s:f:_):xs) cr
      | cr < s = func xs (s+c)
      | otherwise = func xs ((ceiling ((fromIntegral cr) / (fromIntegral f)) * f) + c)


Measured memory_bytes: 1276
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e6 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	string s1, s2;
	cin >> s1 >> s2;
	int l = 0, r = 2;
	while (l < 3)
	{
		if (s1[l++] != s2[r--])
			puts("NO"), exit(0);
	}
	puts("YES");
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define endl '\n'
#define M 1000000007
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define f first
#define s second
#define b begin
#define e end
#define pb push_back
#define mp make_pair
#define FOR(i,a,b) for(i=a;i<b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define itfr(it,x) for(it=x.begin();it!=x.end();it++)
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;

int main()
{
    flash;
    //sieve();
    ll T=1,t,n,m,x,k,i,j;
    // cin>>T;
    while(T--)
    {
        cin>>n>>x;
        ll a[n];
        FOR(i,0,n)  cin>>a[i];
        ll ans = 0;
        if(a[0]>x){
            ans = a[0]-x;
            a[0]=x;
        }
        FOR(i,1,n)
        {
            if((a[i]+a[i-1])>x){
                ans += a[i] - x + a[i-1];
                a[i] = x-a[i-1];
            }
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 4348
import collections
N, M = map(int, input().split())
G = collections.defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)

dist = [-1] * (N + 1)
que = collections.deque()
 
dist[1] = 0
que.append(1)
 
while len(que):
    v = que.popleft()
    for nv in G[v]:
        if dist[nv] != -1:
            continue
        dist[nv] = v
        que.append(nv)
if -1 in dist[2:]:
    print('No')
else:
    print('Yes')
    for value in dist[2:]:
        print(value)

Measured memory_bytes: 39256
N = int(input())
A = [int(a) for a in input().split()]
P = 10**9+7
X = [1] * (1<<20) # 0
Y = [0] * (1<<20) # 1
Z = [0] * (1<<20) # Cnt of Zeros at Last update
Z[0] = 1
X[0] = (P+1) // 2

s = 0
for i in range(N):
    s ^= A[i]
    if s == 0:
        X[0] = (X[0] * 2) % P
        Z[0] += 1
    else:
        X[s] = (X[s] + Y[s] * (Z[0] - Z[s])) % P
        Y[s] = (X[s] + Y[s]) % P
        Z[s] = Z[0]

print((X[s] + sum(Y)*(s==0)) % P)


Measured memory_bytes: 59324
#include <iostream>
#include <algorithm>

int main(){
    int arr[3];
    for (int i = 0; i < 3; ++i) {
        std::cin >> arr[i];
    }
    std::sort(arr,arr+3);
    if(arr[0]==arr[1]&&arr[1]!=arr[2]){
        std::cout << "Yes";
        return 0;
    }
    if(arr[0]!=arr[1]&&arr[1]==arr[2]){
        std::cout << "Yes";
        return 0;
    }
    std::cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define N 100
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.141592653
#define cot cout.tie(0)
#define endl "\n"
using namespace std;
/**
        * @author :: Sawlani
        *
        */

 

int main()
{
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        #endif
        double r;
        cin >> r;
        cout << fixed <<  setprecision(10) ;
         double ans = 2.0*PI*r;

         cout << ans;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
#include <queue>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }

ll f(ll N, ll X) {
    if (N==0) return 1;
    ll a = (1LL<<(N+1)) - 3;
    ll p = (1LL<<N) - 1;
    if (X==1) return 0;

    else if (X <= a + 1)
      return f(N-1, X-1);

    else if (X == a + 2)
      return p + 1;

    else if (X <= a * 2 + 4)
      return p + 1 + f(N-1, X-(a+2));

    else return p * 2 + 1;
}

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

    ll N; cin >> N;
    ll X; cin >> X;

    cout << f(N, X) << '\n';

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin >> s;
    int len = s.length();
    int r[len];
    int l[len];
    r[0] = 0;
    l[len-1] = len-1;
    for (int i = 0; i < len-1; i++) {
        if(s[i] == 'L')
            l[i] = i;
        else
            r[i] = i;
    }
    for(int i = 1; i < len; i++)
    {
        if(s[i] == 'L')
        {
            r[i] = r[i-1];
        }
    }
    for(int i = len - 2; i >= 0; i--)
    {
        if(s[i] == 'R')
        {
            l[i] = l[i+1];
        }
    }
    
    int pos[len];
    memset(pos,0,sizeof(pos));
    for (int i = 0; i < len; i++) {
        if(s[i] == 'L')
        {
            int j = r[i] + 1;
                    if((i-j) % 2 == 0)
                    {
                        pos[j]++;
                    }
                    else
                    {
                        pos[j-1]++;
                    }
            
        }
        
        if(s[i] == 'R')
        {
            int j = l[i]-1;
                    if((j-i) % 2 == 0)
                    {
                        pos[j]++;
                    }
                    else
                    {
                        pos[j+1]++;
                    }
            
        }
    }
    for (int i = 0; i < len; i++) {
        cout << pos[i] << ' ';
    }
    cout <<  endl;
    return 0;
}



Measured memory_bytes: 1792