akhauriyash/Code-Regression huggingface dataset:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    a, b, c = map(int, readline().split())

    if b - a == c - b:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61488
/*
  I_🧡🧡🧡_QMsh
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define x first
#define y second

using namespace std;
using namespace __gnu_pbds; // gp_hash_table<int, int> table;

template <typename T> void smin(T &a, const T &b) { a = (a < b ? a : b); }
template <typename T> void smax(T &a, const T &b) { a = (a > b ? a : b); }

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;

signed main()
{
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector <vector <bool>> g(n, vector <bool> (n));
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < n; j++)
    {
      char c;
      cin >> c;
      g[i][j] = (c == '1');
    }
  }

  int ans = 0;
  for (int s = 0; s < n; s++)
  {
    vector <int> d(n, n);
    queue <int> q;
    d[s] = 0;
    q.push(s);
    while (!q.empty())
    {
      int u = q.front();
      q.pop();
      for (int v = 0; v < n; v++)
      {
        if (!g[u][v])
          continue;
        if (d[v] == n)
        {
          d[v] = d[u] + 1;
          q.push(v);
        }
        if ((d[v] - d[u]) % 2 == 0)
        {
          return cout << -1, 0;
        }
      }
    }
    smax(ans, *max_element(all(d)));
  }
  cout << ans + 1;

  return 0;
}

Measured memory_bytes: 256
import os, sys, re, math

N = int(input())
A = [int(n) for n in input().split()]

answer = 'APPROVED'
for a in A:
    if a % 2 == 0:
        if not (a % 3 == 0 or a % 5 == 0):
            answer = 'DENIED'
            break

print(answer)


Measured memory_bytes: 9944
// use itertools::Itertools;
use proconio::marker::Usize1;

fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        q: usize,
        xs: [(Usize1,Usize1,usize,i32);q],
    }
    // global
    let mut ans = 0;
    let mut buf = vec![0;n];
    // FnMut closure to update the answer
    let mut update = |arr:&Vec<usize>| {
        let score = xs.iter()
            .map(|(a,b,c,d)|{ if arr[*b] - arr[*a] == *c { *d } else { 0 } })
            .sum::<i32>();
        ans = ans.max(score);
    };
    // dfs
    dfs(&mut buf, 0, m, &mut update);
    println!("{}", ans);
}

fn dfs<F>(buf:&mut Vec<usize>, depth:usize, m:usize, f: &mut F) where F: FnMut(&Vec<usize>) {
    if depth == buf.len() { // leaf
        f(buf);
    } else { // node
        for i in (if depth == 0 { 0 } else { buf[depth-1] })..m {
            buf[depth] = i;
            dfs(buf, depth+1, m, f);       
        }
    }
}

Measured memory_bytes: 2204
#include<bits/stdc++.h>
using namespace std;
  
 int main(){ 

 int A, B, C, D, E;

 cin >> A >> B >> C >> D >> E;

 int a = 10-A%10;  
 int b = 10-B%10;
 int c = 10-C%10;
 int d = 10-D%10;
 int e = 10-E%10;

 if (a==10) a=0;
 if (b==10) b=0;
 if (c==10) c=0;
 if (d==10) d=0;
 if (e==10) e=0;


 int ans = 0;
   
  if (A % 10 == 0) ans += A;
   else ans += (A + a);

  if (B % 10 == 0) ans += B;
   else ans += (B + b);

  if (C % 10 == 0) ans += C;
   else ans += (C + c);

  if (D % 10 == 0) ans += D;
   else ans += (D + d);

  if (E % 10 == 0) ans += E;
   else ans += (E + e);


  vector<int> waitingtime = {a, b, c, d, e};
  sort(waitingtime.begin(), waitingtime.end());
  

  ans -= waitingtime.at(4);

  cout << ans << endl;


 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n;
  cin >> n;
  int ans = 0;
  rep(i, n){
    if(n % (i+1)) ans += n/(i+1);
    else ans += n/(i+1)-1;
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
ll fac(ll a) { return a > 1 ? fac(a - 1) * a : 1; }
ll fang(ll a){
  return a > 1 ? fang(a - 1) + a : 1;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  int n;
  cin >> n;
  vector<int>v(n);
  rep(i,n)cin >> v[i];
  int count = INF;
  rep(i,n){
    int tmp = 0;
    while(v[i] % 2 == 0){
      tmp++;
      v[i] /= 2;
    }
    count = min(count,tmp);
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;


int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<vector<ll>> a(s.size()+1,vector<ll>(k+1,0)),b(s.size()+1,vector<ll>(k+1,0));
  b[0][0]=1;
  rep(i,s.size()){
      rep(j,k+1){
          ll u=s[i]-'0';
          a[i+1][j]+=a[i][j];
          if (u!=0) a[i+1][j]+=b[i][j];
          if (u==0) b[i+1][j]+=b[i][j];
          if (j!=k){
              a[i+1][j+1]+=a[i][j]*9;
              if (u!=0) a[i+1][j+1]+=b[i][j]*(u-1);
              if (u!=0) b[i+1][j+1]+=b[i][j];
          }
      }
  }
  cout << a[s.size()][k]+b[s.size()][k] << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    String s = sc.next();
    char[] c = s.toCharArray();
    StringBuilder val = new StringBuilder();

    if(k>=c.length){
      System.out.println(s);
    }else{
      for(int i=0; i<k; i++){
        System.out.print(c[i]);
      }
      System.out.println("...");
    }


  }
}

Measured memory_bytes: 35756
n = int(input())
x = n*[0]
u = n*[0]
for i in range(n):
    x[i], u[i] = list(map(str, input().split(" ")))


ans = 0
for i in range(n):
    if(u[i] == "JPY"): ans += float(x[i])
    else: ans += float(x[i]) * 380000

print(ans)

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

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  int ap=0,bp=0,cp=0;
  char next='a';
  char won;
  for(int i=0,l=a.size()+b.size()+c.size();i<l;i++){
    if(next=='a'){
      next = a.at(ap);
      ap++;
    }else if(next=='b'){
      next = b.at(bp);
      bp++;
    }else{
      next = c.at(cp);
      cp++;
    }
    if(ap==a.size()&&next=='a'){
      won='A';
      break;
    }
    if(bp==b.size()&&next=='b'){
      won='B';
      break;
    }
    if(cp==c.size()&&next=='c'){
      won='C';
      break;
    }
  }
  cout << won << endl;
}

Measured memory_bytes: 3604
using static System.Math;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var a = line[0];
            var v = line[1];
            line = ReadLine().Split(' ').Select(value => long.Parse(value)).ToArray();
            var b = line[0];
            var w = line[1];
            var t = long.Parse(ReadLine());

            if(v <= w)
            {
                WriteLine("NO");
                return;
            }

            var diffDistance = Abs(a - b);
            var diffMove = Abs(v - w);
            if(diffDistance <= t * diffMove)
            {
                WriteLine("YES");
            }
            else
            {
                WriteLine("NO");
            }
        }
    }
}


Measured memory_bytes: 19072
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353
dd = [(0,-1),(1,0),(0,1),(-1,0)]
ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        n = I()
        if n == 0:
            break

        a = [S().split(':') for _ in range(n)]
        ts = set([c[0] for c in a])
        ms = {}
        for t,m in a:
            ms[t] = m[:-1].split(',')

        fm = {}
        def f(c):
            if c in fm:
                return fm[c]
            if c in ts:
                s = set()
                for k in ms[c]:
                    s |= f(k)
                fm[c] = s
                return s
            fm[c] = set([c])
            return fm[c]

        r = f(a[0][0])

        rr.append(len(r))

    return '\n'.join(map(str,rr))


print(main())




Measured memory_bytes: 9516
#include<iostream>
using namespace std;
int main() {
  string t;cin>>t;
  int n=t.size();
  int cnt=0;
  for(int i=0;i<n;i++){
    if(t[i]=='?'){
      cout<<'D';
    }else{
      cout<<t[i];
    }
  }
  return 0;
}


Measured memory_bytes: 3732
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int main() {
    ll N, X;
    cin >> N >> X;

    vll n_layer(51), n_patty(51);
    n_layer[0] = 1;
    n_patty[0] = 1;
    rep(i, 50) {
        n_layer[i + 1] = 2 * n_layer[i] + 3;
        n_patty[i + 1] = 2 * n_patty[i] + 1;
    }

    ll ans = 0;
    ll n = N;
    ll x = X;
    for (; n;) {
        if (x == 0) {
            break;
        }
        else if (x == n_layer[n]) {
            ans += n_patty[n];
            break;
        }
        else if (x <= n_layer[n] / 2) {
            x--;
            n--;
        }
        else if (x == n_layer[n] / 2 + 1) {
            ans += n_patty[n - 1] + 1;
            break;
        }
        else {
            ans += n_patty[n - 1] + 1;
            x -= n_layer[n] / 2 + 1;
            n--;
        }
    }
    if (n == 0 && x == 1) ans++;

    write(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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;
}

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#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 repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1LL << 60;


const int MAX_N = 100010;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	int ans = 1;
	rep(i, n) {
		int a; cin >> a; ans = lcm(ans, a);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import collections
from math import gcd
import sys
input=sys.stdin.readline
def main():
    n=int(input())
    c=collections.Counter()
    mod=10**9+7
    for _ in range(n):
        a,b=map(int,input().split())
        g=abs(gcd(a,b))
        if g==0:
            g=1
        a//=g
        b//=g
        c[(a,b)]+=1
    ans=1
    s=set()
    for i,j in c:
        if (i,j)==(0,0):
            continue
        if (i,j) not in s:
            s.add((i,j))
            s.add((-i,-j))
            s.add((-j,i))
            s.add((j,-i))
            ans*=(pow(2,c[(i,j)]+c[(-i,-j)],mod)+pow(2,c[(j,-i)]+c[(-j,i)],mod)-1)%mod
    print((ans-1+c[(0,0)])%mod)

if __name__ == "__main__":
    main()


Measured memory_bytes: 182772
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int h,w;
    cin >>h>>w;
    char a[h+2][w+2];
    for(int i=0;i<h+2;i++)
    {
        for(int j=0;j<w+2;j++)
        {
            a[i][j]='#';
        }
    }
    for(int i=1;i<h+1;i++)
        for(int j=1;j<w+1;j++)
    {
        cin >> a[i][j];
    }
    for(int i=0;i<h+2;i++)
    {
        for(int j=0;j<w+2;j++)
        {
            cout << a[i][j];
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
from collections import deque
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()
d = deque(A)

#print(d)

# ans1[0] < ans1[1] > ans1[2] という大小関係になる配列を作成する
ans1 = []
for i in range(N):
    x = d.pop() if i % 2 == 0 else d.popleft()
    ans1.append(x)
x = ans1.pop()
ans1 = [x] + ans1

# ans2[0] > ans2[1] < ans2[2] という大小関係になる配列を作成する
ans2 = []
d = deque(A)
for i in range(N):
    x = d.popleft() if i % 2 == 0 else d.pop()
    ans2.append(x)
x = ans2.pop()
ans2 = [x] + ans2


def amount(array):
    ret = 0
    for i in range(N-1):
        ret += abs(array[i+1]-array[i])
    return ret

#print(ans)
print(max(amount(ans1), amount(ans2)))


Measured memory_bytes: 64984
s = input();
a = "abcdefghijklmnopqrstuvwxyz"
b = [0]*26
c = [0]*26
for i in s:
  for j in range(26):
    if i == a[j]:
      c[j] = max(c[j],b[j])
      b[j] = 0
    else:
      b[j] += 1
print(min([max(i,j) for i,j in zip(b,c)]))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VS vector<string>
int main(){
    ll H, W, K;
    cin >> H >> W >> K;
    VS s(H);
    rep(i, 0, H) 
      cin >> s[i];
    ll ans = 0;
    for(int hbit = 0; hbit < (1<<H); hbit++){
        for(int wbit = 0; wbit < (1<<W); wbit++){
            ll cnt = 0;
            rep(h, 0, H){
                rep(w, 0, W){
                    if((hbit & (1<<(int)h)) || (wbit & (1<<(int)w))) 
                      continue;
                    if(s[h][w] == '#') 
                      cnt+=1;
                }
            }
            if((cnt - K)==0){
                ans++;
            }
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 3612
public class Main {


  private static void solve() {
    long n = ni();
    String ret = "";
    while (n != 0) {
      if (n % 2 != 0) {
        n -= 1;
        ret = "1" + ret;
      } else {
        ret = "0" + ret;
      }
      n /= -2;
    }
    System.out.println(ret.equals("") ? "0" : ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b,k;
    cin >> a >> b >> k;
    
        if(a>=k){
        cout << a - k << ' ' << b <<endl;
        }
        else if(a<k && b>=k-a){
        cout << 0 << ' ' << b - (k-a) <<endl;

        }
        else{
        cout << 0 << ' ' << 0 <<endl;
    
        }
     
    
    }

Measured memory_bytes: 256
import std.conv, std.stdio;
import std.algorithm, std.array, std.range, std.string;
import std.functional;
void main()
{
    immutable inserts = readln.chomp.to!int;
    immutable original = readln.chomp.length;
    (inserts + 1).iota.map!(i => c(inserts+original, i) * Mod!10_0000_0007(25) ^^ i).sum.writeln;
}

private:

Mod!10_0000_0007 c(in ulong n, in ulong r)
{
    if (r == 0)
        return Mod!10_0000_0007(1);
    return memoize!c(n, r-1) * (n-r+1) / r;
}

struct Mod(ulong mod = 10_0000_0007)
{
    long v;
    auto opOpAssign(string op)(in long rhs)
        if (op == "+" || op == "*")
    {
mixin ("v "~op~"= rhs;");
        v %= mod;
        return this;
    }
    auto opOpAssign(string op)(in Mod!mod rhs)
        if (op == "+" || op == "*")
    {
        return opOpAssign!op(rhs.v);
    }
    auto opBinary(string op, T)(in T rhs) const
        if ((op == "+" || op == "*") &&
            (is (T : long) || is (T == Mod!mod)))
    {
        Mod!mod lhs = this;
        return lhs.opOpAssign!op(rhs);
    }
    auto opBinary(string op)(in long rhs) const
        if (op == "/")
    {
        return this * rhs.modinv!mod;
    }
    auto opBinary(string op)(in long rhs) const
        if (op == "^^")
    {
        if (rhs == 0)
            return Mod!mod(1);
        if (rhs == 1)
            return this;
        auto sq = this * this;
        return sq ^^ (rhs >> 1) * this ^^ (rhs & 1);
    }
    string toString() const
    {
        return "%d".format(v);
    }
}

/// from https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a#3-5-%E6%8B%A1%E5%BC%B5-euclid-%E3%81%AE%E4%BA%92%E9%99%A4%E6%B3%95%E3%81%AB%E3%82%88%E3%82%8B%E9%80%86%E5%85%83%E8%A8%88%E7%AE%97
ulong modinv(long mod)(long a)
{
    long b = mod, u = 1, v = 0;
    while (b)
    {
        immutable q = a / b;
        a -= q * b;
        a.swap(b);
        u -= q * v;
        u.swap(v);
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

unittest
{
    alias minv = modinv!10_0000_0007;
    foreach (i; 1..1000)
    {
        assert (i * minv(i) % 10_0000_0007 == 1, "1 / %d != %d".format(i, minv(1)));
    }
}


Measured memory_bytes: 80032
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
 
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.map!(to!int).array; }
 
void calc(string s) {
    int a = s[0] - '0';
    int b = s[1] - '0';
    int c = s[2] - '0';
    int d = s[3] - '0';
 
    int reduce(int lhs, int rhs, int op) {
        return op == 0 ? lhs + rhs : lhs - rhs;
    }
    char op(int op) {
        return op == 0 ? '+' : '-';
    }
 
    for (int i = 0; i < 2; i++) {
        int x = reduce(a, b, i);
        for (int j = 0; j < 2; j++) {
            int y = reduce(x, c, j);
            for (int k = 0; k < 2; k++) {
                int z = reduce(y, d, k);
                if (z == 7) {
                    // writeln(a, op(i), b, op(j), c, op(k), d, "=7");
                    writefln("%s%s%s%s%s%s%s%s", a, op(i), b, op(j), c, op(k), d, "=7");
                    return;
                }
            }
        }
    }
}
 
void main() {
    auto s = readln.chomp;
    calc(s);
}

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

int main(void)
{
	long long N, A, B;
	cin >> N >> A >> B;

	vector<long long> X(N);
	for(int i=0; i<N; i++)
		cin >> X[i];

	long long ret = 0;
	for(int i=1; i<N; i++)
		ret += min((X[i]-X[i-1])*A, B);

	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 1024
n, x, y = map(int, input().split())
l = [0] * n
for i in range(1,n+1):
    for j in range(i,n+1):
        l[min(abs(j-i), abs(i-x) + abs(y-j) + 1, abs(i-y) + abs(j-x) + 1)] += 1

for i in range(1, n):
    print(l[i])

Measured memory_bytes: 47580
import itertools
n=int(input())
a=0
for i in range(3,len(str(n))+1):
    for p in itertools.product((3,5,7),repeat=i):
        if (3 in p)and(5 in p)and(7 in p):
            if int("".join(list(map(str,p))))<=n:
                a+=1
print(a)

Measured memory_bytes: 42220
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>

int main() {

	int a[3];
	memset(a, 0, sizeof(a));

	std::cin >> a[0] >> a[1] >> a[2];

	std::sort(a, a + 3);

	std::cout << a[0] + a[1] << std::endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void)
{
	int i, j, k, l,m;
	scanf("%d", &i);
	j = 0;

	for (m = 0; m <= 10000; m++) {

		if (j * (j + 1) / 2 >= i) {
			k = -i + j * (j + 1) / 2;
			for (l = 1; l <= j; l++) {
				if (k != l) {
					printf("%d\n", l);
				}
			}break;
		}
		else {
			j++;
		}
	}


	return 0;
}

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

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

    ll H, W;
    cin >> H >> W;
    if (H == 1 || W == 1) {
        cout << 1 << endl;
    } else {
        cout << (H * W + 1) / 2 << endl;
    }

    return 0;
}

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

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define Set(i, v) memset(i, v, sizeof i)
#define pb push_back

using namespace std;

const int N = 2e5 + 10;
const int Mod = 1e9 + 7;

int n, pos[N];
char S[N], T[N];
int vis[30];

int main(){
	scanf("%s", S + 1);
	n = strlen(S + 1);
	int p = n, ans = 0;
	while(p >= 1){
		Set(vis, 0);
		int cnt = 0;
		while(cnt < 26 && p > 0){
			if(!vis[S[p] - 'a']) ++cnt, vis[S[p] - 'a'] = true;
			--p;
		}
		if(cnt < 26) break;
		pos[++ans] = p + 1;
	}
	int l = 0;
	//printf("%d %d\n", ans, pos[1]);
	p = 1;
	pos[0] = n + 1;
	Forr(i, ans, 0){
		Set(vis, 0);
		while(p < pos[i]) vis[S[p] - 'a'] = true, ++p;
		For(j, 0, 25) if(!vis[j]) {
			T[++l] = 'a' + j;
			break;
		}
		while(i && S[p] != T[l]) ++p;
		++p;
	}
	printf("%s\n", T + 1);
	return 0;
}

Measured memory_bytes: 512
n = gets.to_i
s = []
n.times { s << gets.chomp }

polls = s
tally = Hash.new { 0 }

polls.each do |poll|
  tally[poll] += 1
end

max = tally.values.max

answer =
  tally.to_a.map do |key, value|
    next unless value == max

    key
  end

puts answer.compact.sort


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

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

// -------------------------------------------


void solve(long long K, std::string S){
  if(S.size() <= K) {
    std::cout << S << std::endl;
    return ;
  } else {
    rep(i,K)
      std::cout << S[i];
    std::cout << "..." << std::endl;
  }
}

int main(){
    long long K;
  scanf("%lld",&K);
  std::string S;
  std::cin >> S;
    solve(K, S);
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	int X;
	cin >> X;
	if(X < 1200) Cout("ABC");
	else Cout("ARC");
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)

//* prime factorization in O(sqrt(n))
map<ll, ll> prime_factor(ll n){
    map<ll, ll> res;
    for(ll i=2; i*i <= n; i++){ //* n shrinks during the for-loop!
        while(n % i == 0){
            ++res[i];
            n /= i;
        }
    }
    if(n != 1) {
        ++res[n];
    }
    return res;
}

void solve(long long N, long long P){
    auto pmap = prime_factor(P);
    ll ans = 1;
    for(auto x: pmap){
        ll degree = x.second/N;
        if(degree>0){
            rep(i, degree)
                ans *= x.first;
        }
    }
    cout << ans << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long P;
    scanf("%lld",&P);
    solve(N, P);
    return 0;
}


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

#define ll long long
long long INF = 1e18;

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

	int n, k1;
	cin >> n >> k1;
	vector<int> p(n), c(n);
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		x--;
		p[i] = x;
	}
	for (int i = 0; i < n; i++) cin >> c[i];

	long long ans = -INF;
	for (int i = 0; i < n; i++) {
		int k = k1;
		long long sum = 0;
		queue<int> q;
		q.push(p[i]);
		vector<bool> visited(n);
		int start = p[i];
		visited[i] = true;
		while (k--) {
			int v = q.front();
			q.pop();
			sum += c[v];
			ans = max(ans, sum);
			if (visited[v]) {
				start = v;
				break;
			}
			visited[v] = true;
			q.push(p[v]);
		}
		if (k <= 0) continue; // no more k
		//updateshit and count cycle
		for (int i = 0; i < n; i++) visited[i] = false;
		while (!q.empty()) q.pop();
		long long length = 0, sumLength = 0;
		q.push(start);
		visited[start] = true;
		while (true) {
			int v = q.front();
			q.pop();
			length++;
			sumLength += c[p[v]];
			if (visited[p[v]]) break;
			visited[p[v]] = true;
			q.push(p[v]);
		}
		long long times = k / length;
		if (times) times--;
		sum += (times * sumLength);
		k -= (times * length);
		ans = max(ans, sum);
		//updateshit and count cycle
		for (int i = 0; i < n; i++) visited[i] = false;
		while (!q.empty()) q.pop();
		q.push(start);
		while (k--) {
			int v = q.front();
			q.pop();
			sum += c[p[v]];
			ans = max(ans, sum);
			q.push(p[v]);
		}

	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 3700
#include <stdio.h>

int a;
int b;
main(){
	scanf("%d%d",&a,&b);
	if(a>= -1000 && b <= 1000){
	 if(a<b){
		printf("a < b\n");
		}
		if(a>b){
			printf("a > b\n");
		}
		if(a==b){
			printf("a == b\n");
		}
	}
return 0;
}
	

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
typedef long long ll;

ll dp[100010];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,W; cin >> N >> W;
    vector<int> w(N),v(N);
    REP(i,N) cin >> w[i] >> v[i];
    REP(i,N){
        for(int j = W; j >= w[i]; --j){
            chmax(dp[j],dp[j-w[i]]+v[i]);
        }
    }
    cout << dp[W] << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long n, k;
    cin >> n >> k;
    long long h[n], s[n], step[k];
    s[0] = 0;
    for (long long i = 0; i < n; i++) cin >> h[i];
    for (long long i = 1; i < n; i++)
    {
        if (i >= k)
        {
            long long step[k], min = INT_MAX;
            for (long long j = 0; j < k; j++) 
            {
                step[j] = s[i - j - 1] + abs(h[i] - h[i - j - 1]);
                if (step[j] < min) min = step[j];
            }
            s[i] = min;
        }
        else
        {
            long long step[i], min = INT_MAX;
            for (long long j = 0; j < i; j++)
            {
                step[j] = s[i - j - 1] + abs(h[i] - h[i - j - 1]);
                if (step[j] < min) min = step[j];
            }
            s[i] = min;
        }
    }
    cout << s[n - 1];
}

Measured memory_bytes: 5128
#include<stdio.h>
int main()
{
	char l,r,p='A';
	while(scanf("%c,%c",&l,&r)!=EOF){
		if(l==p){
			p=r;
		}else if(r==p){
			p=l;
		}
	}
	printf("%c\n",p);
	return 0;
}

Measured memory_bytes: 2612
#include <stdio.h>

int main()
{
    int n,m;
    scanf("%d %d",&n,&m);
    int start[m],end[m];
    int startis[n],endis[n];
    for(int i=0; i<m; i++) scanf("%d %d",&start[i],&end[i]);
    for(int i=0; i<m; i++){
      if(start[i]==1)startis[end[i]-1]=1;
      if(end[i]==n)endis[start[i]-1]=1;
    }

    for(int i=0;i<m;i++){
      if(startis[i]==1 && endis[i]==1){
        printf("POSSIBLE\n");
        return 0;
      }
    }

    printf("IMPOSSIBLE\n");
    return 0;
}


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

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int n;
	cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
    	cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int maxMedian, minMedian;
    
    if (n % 2 == 1) {
    	maxMedian = b[n / 2];
    	minMedian = a[n / 2];
    	cout << maxMedian - minMedian + 1 << "\n";
    }
    else {
        maxMedian = b[n / 2] + b[(n / 2) - 1];
        minMedian = a[n / 2] + a[(n / 2) - 1];
        cout << maxMedian - minMedian + 1 << "\n";
    }
    return 0;
}

Measured memory_bytes: 4712
#include <iostream>
using namespace std;
static const int ARGC_MAX = 100;

struct Card { char suit, value; };

bool isStable(struct Card C1[], struct Card C2[], int N) {
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			for (int a = 0; a < N; a++) {
				for (int b = a + 1; b < N; b++) {
					if (C1[i].value == C1[j].value && C1[i].value == C2[b].value && C1[j].value == C2[a].value\
						&& C1[i].suit == C2[b].suit && C1[j].suit == C2[a].suit) {
						cout << "Not stable" << endl;
						return false;
					}
				}
			}
		}
	}
	cout << "Stable" << endl;
	return true;
}

void showCard(struct Card C1[], int N) {
	for (int i = 0; i < N; i++) {
		if (i != 0) cout << " ";
		cout << C1[i].suit << C1[i].value;
	}
	cout << endl;
}

void bubbleSort(struct Card C1[], int N) {
	for (int i = 0; i < N; i++) {
		for (int j = N - 1; j > i; j--) {
			if (C1[j - 1].value > C1[j].value) {
				Card t = C1[j];
				C1[j] = C1[j - 1];
				C1[j - 1] = t;
			}
		}
	}
}

void selectionSort(struct Card C1[], int N) {
	int minj;
	for (int i = 0; i < N; i++) {
		minj = i;
		for (int j = i + 1; j < N; j++) {
			if (C1[j].value < C1[minj].value) minj = j;
		}
		if (minj != i) {
			Card t = C1[i];
			C1[i] = C1[minj];
			C1[minj] = t;
		}
	}
}

int main(void) {
	int argc;
	Card C0[ARGC_MAX], C1[ARGC_MAX], C2[ARGC_MAX];

	cin >> argc;
	for (int i = 0; i < argc; i++) {
		cin >> C0[i].suit >> C0[i].value;
	}

	for (int i = 0; i < argc; i++) {
		C1[i] = C0[i];
		C2[i] = C0[i];
	}
	
	bubbleSort(C1, argc);
	showCard(C1, argc);
	isStable(C0, C1, argc);

	selectionSort(C2, argc);
	showCard(C2, argc);
	isStable(C0, C2, argc);

	return 0;
}

Measured memory_bytes: 3096
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
	vector<vector<int>>edges(100);
	int dfs(const int now, vector<int>&used) {
		int ans = 1;
		for (auto e : edges[now]) {
			if (!used[e]) {
				used[e] = true;
				ans = max(ans, dfs(e, used) + 1);
				used[e] = false;
			}
		}
		return ans;
	}
int main() {
	while (1) {
		edges.clear();
		edges.resize(100);
		int N; cin >> N;
		if (!N)break;
		for (int i = 0; i < N; ++i) {
			int a; cin >> a; int b; cin >> b; a--; b--;
			edges[a].push_back(b);
			edges[b].push_back(a);
		}
		int ans = 0;
		vector<int>used(100);
		for (int i = 0; i < 100; ++i) {
			used[i] = true;
			ans = max(ans, dfs(i, used));
			used[i] = false;
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
    int n = 3, count = 0;
    string temp;
    cin >> temp;
    while(n--)
    {
        if(temp[n] == '1')
        {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}


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

ll mod = 1e9 + 7;

int main() {
    int N; cin >> N;
    vector<ll> A(N);
    rep(i, N){
        cin >> A[i];
    }
    vector<ll> T(N+1);
    rep(i, N){
        T[i+1] = T[i] + A[i];
    }

    ll ans = 0;
    for (int i = 0; i < N-1; i++){
        ll total = T[N] - T[i+1];
        total %= mod;
        total *= A[i];
        total %= mod;
        ans += total;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A+B>=C) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int n,m,p,AC,WA;
bool state[maxn];
int WAA[maxn];
char judge[20];
signed main()
{
    cin>>n>>m;
    for(int i=1;i<=m;++i)
    {
        cin>>p>>judge;
        if(!state[p]&&judge[0]=='A')
        {
            state[p]=true;
            ++AC;
        }
        else if(!state[p])
            ++WAA[p];
    }
    for(int i=1;i<=n;i++)
        if(state[i])
            WA+=WAA[i];
    cout<<AC<<" "<<WA<<endl;
    return 0;
}


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

using namespace std;

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

#define mt make_tuple
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sqr(x) ((ll)(x) * (x))

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

    for(int i = 1; i <= 1000; ++i)
    {
        int prviIzraz = i * 0.08;
        int drugiIzraz = i * 0.1;

        if(prviIzraz == a && drugiIzraz == b)
        {
            cout << i << '\n';
            return 0;
        }
    }

    cout << -1 << '\n';

    return 0;
}


Measured memory_bytes: 256
import math

n = int(input())
xlist = list(map(int, input().split()))
ylist = list(map(int, input().split()))
d1 = sum([abs(x - y) for x, y in zip(xlist, ylist)])
d2 = sum([abs(x - y)**2 for x, y in zip(xlist, ylist)])**0.50
d3 = sum([abs(x - y)**3 for x, y in zip(xlist, ylist)])**(1/3)
dinf = max([abs(x - y) for x, y in zip(xlist, ylist)])
print(d1)
print(d2)
print(d3)
print(dinf)


Measured memory_bytes: 5704
#include <iostream>

using namespace std;

long long solve(long long i) {
  //cout << i << " -> ";
  if(i % 2 == 0) {
    long long num_of_one = i / 2;
    if(num_of_one % 2 == 0) {
      // cout << i << endl;
      return i;
    }
    // cout << i + 1 << endl;
    return i+1;
  }
  long long num_of_one = (i / 2) + 1;
  if(num_of_one % 2 == 0) {
    // cout << 0 << endl;
    return 0;
  }
  // cout << 1 << endl;
  return 1;
}

long long xor_world(long long a, long long b) {
  if(a == b)
    return a;

  if(a == 0)
    return solve(b);

  return solve(b) ^ solve(a-1);
}

int main() {
  long long a,b;
  cin >> a;
  cin >> b;
  cout << xor_world(a, b);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<set>
#include<map>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;

#define rep(i,x,y) for(int i=(x); i<(y); ++i)
const int INF = (1<<30);
const ll INFLL = 1LL<<62;
const long double EPS = 1e-12;

template <typename T>
void vec_print(vector<T> VEC){
  rep(i, 0, VEC.size()){
    cout << VEC[i] << " ";
  }
  cout << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  rep(i, 0, MAT.size()){
    rep(j, 0, MAT[i].size()){
      cout << MAT[i][j] << " ";
    }
    cout << endl;
  }
};

class HOGE{
  public:
    ll index;
    ll value;
    HOGE(ll index, ll value){
      this->index = index;
      this->value = value;
    };
    ~HOGE(void){
      return;
    };

    void print(void){
      cout << "index : " << index << ", value : " << value << endl;
      return;
    };
    
    bool operator==(const HOGE &obj){
      return (this->value == obj.value);
    };
    bool operator<(const HOGE &obj){
      return (this->value < obj.value);
    };
    bool operator>(const HOGE &obj){
      return (this->value > obj.value);
    };
};

int main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int> > s(H, vector<int>(W));
  rep(i, 0, H){
    rep(j, 0, W){
      char tmp;
      cin >> tmp;
      if(tmp=='#'){
        s[i][j] = 0;
      }else{
        s[i][j] = 1;
      }
    }
  }

  rep(i, 0, H){
    rep(j, 0, W){
      if(s[i][j]==1){
        continue;
      }
      bool flag=false;
      if(i > 0){
        if(s[i-1][j] == 0){
          flag = true;
        }
      }
      if(i < H-1){
        if(s[i+1][j] == 0){
          flag = true;
        }
      }
      if(j > 0){
        if(s[i][j-1] == 0){
          flag = true;
        }
      }
      if(j < W-1){
        if(s[i][j+1] == 0){
          flag = true;
        }
      }
      if(flag==false){
        cout << "No" << endl;
        return 0;
      }
    }
  }

  cout << "Yes" << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] num = new int[6];
		for (int i=0; i<6; i++) {
			num[i] = stdIn.nextInt();
		}
		String com = stdIn.next();

		Dice dice = new Dice();
		for (int i=0; i<com.length(); i++) {
			dice.change(com.charAt(i));
		}
		System.out.println(num[dice.isTop()-1]);
	}

	static class Dice {

		private int top = 1;
		private int front = 2;
		private int right = 3;
		private int left = 4;
		private int back = 5;
		private int bottom = 6;

		Dice(){
		}

		void change(char dir) {
			int temp = 0;
			switch(dir){
				case 'N': moveN(); break;
				case 'S': moveS(); break;
				case 'E': moveE(); break;
				case 'W': moveW(); break;
			}
		}

		void moveN(){
			int temp = top;
			top = front;
			front = bottom;
			bottom = back;
			back = temp;
		}

		void moveS(){
			int temp = top;
			top = back;
			back = bottom;
			bottom = front;
			front = temp;
		}

		void moveE(){
			int temp = top;
			top = left;
			left = bottom;
			bottom = right;
			right = temp;
		}

		void moveW(){
			int temp = top;
			top = right;
			right = bottom;
			bottom = left;
			left = temp;
		}

		int isTop(){
			return top;
		}
	}
}

Measured memory_bytes: 17184
#include <iostream>
#include <complex>
#include <cmath>
using namespace std;
 
//??????
double dot(complex<double> z1, complex<double> z2) {
    return z1.real()*z2.real() + z1.imag()*z2.imag();
}
 
int main(int argc, char** argv) {
    const double EPS = 1e-10;
    double xA, yA, xB, yB, xC, yC, xD, yD;
    complex<double> a, b, c, d;
    while(cin >> xA >> yA >> xB >> yB >> xC >> yC >> xD >> yD) {
        a.real(xA); a.imag(yA);
        b.real(xB); b.imag(yB);
        c.real(xC); c.imag(yC);
        d.real(xD); d.imag(yD);
        if(abs(dot(a-b, c-d)) < EPS) { //AB??¨CD????????????0????????°??´???
            cout << "YES" << endl;
        }else {
            cout << "NO" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1216
n = int(input()) 
ab = [tuple(map(int,input().split())) for i in range(n)]

push = 0
ab.reverse()

for i in range(len(ab)):
    mod = ( ab[i][0] + push ) % ab[i][1]
    if mod != 0:
        push += ab[i][1] - mod 

print(push)


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

int main(){
  ll n;
  cin >> n;
  ll k ;
  cin >> k;
  ll a[n];
  for(ll i = 0;i < n;i++){
  	cin >> a[i];
  }
  ll dp[n + 1];
  for(ll i = 0;i < n + 1;i++){
    dp[i] = 1e9;
  }
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(a[1] - a[0]); 
  for(ll i = 3;i <= n;i++){
  	for(ll j = 1;j <= k;j++){
    	if(i - j <= 0) break;
      	dp[i] = min(dp[i - j] + abs(a[i - 1] - a[i - 1 - j]),dp[i]);
    }
    //cout << dp[i] << endl;
  }
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;


int main(){
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 0; i < s.length(); i++){
		bool alpha[26];
		bool used[26];
		for (int j = 0; j < 26; j++){
			alpha[j] = false;
			used[j] = false;
		}
		int coun = 0;
		for (int j = 0; j < i; j++){
			alpha[s[j] - 'a'] = true;
		}
		for (int j = i; j < s.length(); j++){
			if (alpha[s[j] - 'a'] && !used[s[j] - 'a']){
				coun++;
				used[s[j] - 'a'] = true;
			}
		}
		ans = max(ans, coun);
	}
	cout << ans << endl;
	return 0;
}


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

const int N=234567;

int n;
int a[N],b[N];

int check(int x){
	for(int i=0; i<2*n-1; i++) b[i]=0;
	for(int i=0; i<2*n-1; i++) if(a[i]>=x) b[i]=1;
	int r=b[n-1],ri=N;
	for(int i=n; i<2*n-1; i++){
		if(r==b[i]){
			ri=i-(n-1)-1;
			break;
		}
		r=b[i];
	}
	int l=b[n-1],li=N;
	for(int i=n-2; i>=0; i--){
		if(l==b[i]){
			li=n-1-i-1;
			break;
		}
		l=b[i];
	}
	if(li<=ri) return l;
	else return r;
}

int main(){
 
cin>>n;

for(int i=0; i<2*n-1; i++) scanf("%d",&a[i]);

int l=1,u=2*n-1;
int mid;

while(u-l>1){
 mid=(l+u)/2;
 if(check(mid)) l=mid;
 else u=mid;
}

cout<<l<<endl;

return 0;
 
}

Measured memory_bytes: 1792
import re

s = input()
pattern = re.compile("(A?KIHA?BA?RA?)")

ret = pattern.findall(s)

ret2 = pattern.findall("[^AKIHBR]")


#print(ret)
if ret is not None and len(ret) ==  1 and len(ret[0]) == len(s):
    ans = "YES"
else:
    ans = "NO"

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  string S;
  cin >> N >> K >> S;
  if(S.at(K-1)== 'A') S.at(K-1) = 'a';
  else if(S.at(K-1)== 'B') S.at(K-1) = 'b';
  else if(S.at(K-1)== 'C') S.at(K-1) = 'c';
  cout << S <<endl;
}


Measured memory_bytes: 256
# Python3 function to  
# calculate nCr % p 
mod=pow(10,9)+7
def ncr(n, r, p): 
    # initialize numerator 
    # and denominator 
    num = den = 1 
    for i in range(r): 
        num = (num * (n - i)) % p 
        den = (den * (i + 1)) % p 
    return (num * pow(den,p - 2, p)) % p 
n,a,b=map(int,input().split())
ans=pow(2,n,mod)-1
ans =ans- ncr(n,a,mod)
ans += mod
ans =ans%mod
ans =ans -ncr(n,b,mod)+mod
ans=ans%mod
print(ans)

Measured memory_bytes: 38512