akhauriyash/Code-Regression huggingface dataset:
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <numeric>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, x;
        cin >> n >> x;
        vector<ll> a(n);
        rep(i, n) cin >> a[i];

        ll ans = ll_inf;
        vector<ll> mina(n);
        rep(i, n) mina[i] = ll_inf;
        rep(k, n) {
            ll tmp = k * x;
            rep(i, n) {
                if (i + k <= n - 1) mina[i] = min(mina[i], a[i + k]);
                else mina[i] = min(mina[i], a[i + k - n]);
                tmp += mina[i];
            }
            ans = min(tmp, ans);
        }
        cout << ans << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
# 掛け算で求める，までは正しかった
# 式がよく分からない
# https://scrapbox.io/pocala-kyopro/D_-_Handstand_2 この考え方もやった

n = int(input())

if n <= 9:
    print(n)
    exit()

# cij = #{1 <= k <= N | kの先頭の桁の数はi，末尾の桁の数はjに等しい}
# ans = \sum_{i=0}^9 \sum_{j=0}^9 cij * cji

cij = [[0 for _ in range(10)] for _ in range(10)]

for k in range(1, n + 1):
    k0 = int(str(k)[0])
    kn = int(str(k)[-1])
    if k0 != 0 and kn != 0:
        cij[k0][kn] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cij[i][j] * cij[j][i]

print(ans)

Measured memory_bytes: 40428
#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if((a==5&&b==5&&c==7)||(a==7&&b==5&&c==5)||(a==5&&b==7&&c==5))
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int h,w;
	cin >> h >> w;
	char field[h][w];
	FOR(i,0,h)FOR(j,0,w)cin >> field[i][j];
	FOR(i,0,h)FOR(j,0,w){
		if(field[i][j] == '#')continue;
		int dx[8] = {0,-1,-1,-1,0,1,1,1};
		int dy[8] = {1,1,0,-1,-1,-1,0,1};
		int cnt = 0;
		FOR(k,0,8){
			int nx = j + dx[k];
			int ny = i + dy[k];
			if(nx < 0 || w <= nx)continue;
			if(ny < 0 || h <= ny)continue;
			if(field[ny][nx] == '#')cnt++;
		}
		field[i][j] = (char)('0' + cnt);
	}
	FOR(i,0,h){
		FOR(j,0,w){
			cout << field[i][j];
		}
		cout << 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;

const int MAX_N = 100005;
int N, M;
int Ps[100005];
int sum;

/* UNION FIND木 */
int par[MAX_N]; //親
int ch_rank[MAX_N]; //子

// n要素で初期化
void init(int n){
  for(int i=0; i<n; i++){
    par[i] = i;
    ch_rank[i] = 0;
  }
}

// 木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  } else {
    return par[x] = find(par[x]);
  }
}

// xとyの属する集合を併合
void unite(int x, int y){
  x = find(x);
  y = find(y);
  if(x == y) {
    return;
  }
  if(ch_rank[x] < ch_rank[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(ch_rank[x] == ch_rank[y]){
      ch_rank[x]++;
    }
  }
}

// xとyが同じ集合に属するか否か
bool same(int x, int y){
  return find(x) == find(y);
}

int main() {
  cin >> N >> M;
  int x,y;
  rep(i, N) {
    scanf("%d", &Ps[i]);
    Ps[i]--;
  }
  init(N);
  rep(i, M) {
    scanf("%d %d", &x, &y);
    x--; y--;
    unite(x, y);
  }
  rep(i, N) {
    find(i);
  }
  rep(i, N) {
    if(same(i, Ps[i]) || Ps[i]==i) sum++;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18
#define PI 3.14159265358979

using namespace std;

int main(void){
  ll n;
  cin >> n;
  
  vector<ll> a(n);
  ll sum = 0;
  ll m = INF;
  for (int i = 0; i < n; i++){
    cin >> a[i];
    sum += a[i];
    m = min(m, a[i]);
  }

  ll l = n * (n + 1)/2;
  if (sum % l != 0 || sum / l > m){
    cout << "NO" << endl;
  }
  else {
    ll k = sum / l;
    bool ok = 1;
    for (int i = 0; i < n; i++){
      if (a[(i + 1) % n] % n != (a[i] + k) % n){
        ok = 0;
      }
    }

    if(ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
    


  return 0;
}


Measured memory_bytes: 1024
import           Control.Applicative
import           Control.Monad
import           Data.List
import           Text.Printf

powMod::Integer->Integer->Integer->Integer
powMod a d n= fun a d where
    fun a 1 = mod a n
    fun a 2 = mod (a^2) n
    fun a d = let
            p=fun (mod (a^2) n) (div d 2)
            q=if odd d then mod (a*p) n else p
          in mod q n

main = do
    [n,m]<- map (read::String->Integer) . words <$> getLine
    print $ powMod n m 1000000007


Measured memory_bytes: 3732
n, m = map(int, input().split())
ctr = [-1 for _ in range(n)]
flag = True
for i in range(m):
  p, q = map(int, input().split())
  p -= 1
  if ctr[p] == -1:
    ctr[p] = q
  else:
    if(ctr[p] != q):
      flag = False
      break

if ctr[0] == 0 and n > 1:
  flag = False

if ctr[0] == -1:
  ctr[0] = 0 if n == 1 else 1
if flag:
  for i in ctr:
    print(0 if i == -1 else i, end="")
else:
  print(-1)


Measured memory_bytes: 3064
A, B, C, D, E, F = map(int, input().split())

y = 0
yx = 100*A
ys= 0
W = {}
for a in range(F//100 + 1):
    for b in range(F//200 + 1):
        w = 100*A*a + 100*B*b
        if w <= F:
            W[w] = 0
        
for w in W.keys():
    for c in range(min(F-w, (E*w//100)) + 1):
        for d in range(min(F-w, (E*w//100))//2 + 1):
            s = C*c + D*d
            x = w + s
            try:
                if s+w <= F and s/x <= E/(100+E):
                    if s/x > y:
                        y = s/x
                        ys = s
                        yx = x
            except ZeroDivisionError:
                pass
                
print(yx, ys)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    string s, w;
    cin>>s;
    cin>>w;
    int n = s.length();
    int m = w.length();
    int d[n+1][m+1];
    for (int i = 0; i <= n; i++) d[i][0] = 0;
    for (int i = 0; i <= m; i++) d[0][i] = 0;
    int l = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            if (s[i-1] == w[j-1]) d[i][j] = 1 + d[i-1][j-1];
            else d[i][j] = max(d[i-1][j], d[i][j-1]);
            l = max(l, d[i][j]);
        }
    }
    string an = "";
    int p = n, q = m;
    while (l > 0) {
        if (s[p-1] == w[q-1]) {
            an = s[p-1] + an;
            p--;
            q--;
            l--;
        } else if (d[p-1][q] > d[p][q-1]) {
            p--;
        } else q--;
    }
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 35456
H, N = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

# 個数制限なしナップサック
# i番目までの魔法を使ったときにHダメージを実現できるときの最小の魔力
dp = [[float('inf')]*(H+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N):
    for j in range(H+1):
        # i番目の魔法を使わない時
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])
        # i番目の魔法を使う時
        dp[i+1][min(H, j+A[i])] = min(dp[i][j]+B[i], dp[i+1][j]+B[i], dp[i+1][min(j+A[i], H)])

print(dp[N][H])


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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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 gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll N; cin >> N;
  ll ans = -INF;
  
  vector<vector<ll>> f(N, vector<ll>(10));
  rep(i, N) {
    rep(j, 10) {

      cin >> f[i][j];

    }
  }


  vector<vector<ll>> p(N, vector<ll>(10));
  rep(i, N) rep(j, 11) cin >> p[i][j];

  for(int bit = 1; bit < (1 << 10); bit++) {
    ll ttl = 0;
    rep(i, N) {
      ll cnt = 0;
      rep(j , 10) {
	if( (bit >> j) & f[i][j]) {
	  cnt ++ ;
	}
      }
      ttl += p[i][cnt];
    }
    chmax(ans, ttl);
  }

  cout << ans << endl;

}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	char C[2][3];
	for(int i = 0; i < 2; i++){
		for(int j = 0; j < 3; j++){
			cin >> C[i][j];
		}
	}
	if(C[0][2] == C[1][0] && C[1][2] == C[0][0] && C[1][1] == C[0][1]) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<string,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

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

    int ans = 0, m = 0;
    rep(i, n){
        if(s[i] == 'I'){
            m++;
        }else{
            m--;
        }

        ans = max(ans, m);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
  int xperl, ybasic, ylimit, yperl, usedl;
  cin >> xperl >>  ybasic >> ylimit>>  yperl>> usedl;
  int xcost, ycost;
  xcost = xperl * usedl;
  (usedl <= ylimit) ? (ycost = ybasic) : ycost = ybasic + yperl * (usedl - ylimit);
  cout << min(xcost, ycost) << endl;
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

ll A[112345];

int main2() {
  int N = nextInt();
  ll T = nextInt();
  REP(i, N) A[i] = nextInt();
  int ans = 0;
  ll max_diff = 0;
  ll minA = 1LL << 58;
  REP(i, N) {
    ll diff = A[i] - minA;
    if (max_diff < diff) {
      max_diff = diff;
      ans = 1;
    } else if (max_diff == diff) {
      ans++;
    }
    chmin(minA, A[i]);
  }
  cout << ans << endl;
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



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

int main(){
  int A,B,X;
  cin >> A >> B >> X;
  if(A+B<X){
    cout << "NO" << endl;
    return 0;
  }
  if(A>X){
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}


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

ll gcd(ll a, ll b){
	if(a < b) swap(a,b);
	if(a%b==0) return b;
	else return gcd(a%b,b);
}

int main(){
	ll a,b,c,d;
	cin >> a >> b >> c >> d;
	ll g = gcd(c,d);
	ll cd = g * c/g * d/g;
	ll ans = (b-a+1) - (b/c - a/c) - (b/d - a/d) + (b/cd - a/cd);
	if(a % c == 0) ans--;
	if(a % d == 0) ans--;
	if(a % cd == 0) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
int n,sta;
int main()
{
	ios::sync_with_stdio(false);
	cin>>s;
	n=s.size();
	if(n%2){
		sta=s[n/2];
		for(int i=n/2-1;i>=0;--i){
			if(s[i]!=s[n-1-i]||s[i]!=sta){
				cout<<n-i-1;
				return 0;
			}
		}
	}
	else{
		sta=s[n/2];
		for(int i=n/2;i<n;++i){
			if(s[i]!=s[n-1-i]||s[i]!=sta){
				cout<<i;
				return 0;
			}
		}
	}
	cout<<n;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
#define N 11
int push();
int pop();
 int top=0;
  int buffer[N];
  int num;
  int out[N];
  int status;


int main(void){
 
  while(1){
    
    status = scanf("%d", &num);
    if(status == EOF)break;
    if(num != 0)push();
    else if(num == 0){
      cout << pop() << endl;
    }
  }
  
  
  return 0;
}

int push(){
  
  top++;
  buffer[top]=num;
}

int pop(){
  int x=buffer[top];
  top--;
  return x;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

#define MAX_LENGTH 1001

int main(void) 
{
	int i, n;
	char sentence[MAX_LENGTH + 1];
	char *hoshino;

	scanf("%d\n", &n);

	for (i = 0; i < n; i++) {
		hoshino = sentence;

		fgets(sentence, MAX_LENGTH + 1, stdin);

		while ((hoshino = strstr(hoshino, "Hoshino")) != NULL) 
			hoshino[6] = 'a';
		
		printf("%s", sentence);
	}
	return 0;
}

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

ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int main() {
   ll i,j,k;
    string s,t,u;
ll a,b;
    cin >> s>>t>>a>>b>>u;

    if(s==u )
    {
       cout <<  a-1<<' ' << b<< endl;
    }else if(t==u)
    {
       cout << a<<' ' <<b-1<< endl;
    }else 
    {
       cout << a<<' ' <<b<< endl;
    }
 
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        E solver = new E();
        solver.solve(1, in, out);
        out.close();
    }

    static class E {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int W = in.nextInt();
            E.Item[] items = new E.Item[N];
            int V = 0;
            for (int i = 0; i < N; i++) {
                items[i] = new E.Item(in.nextInt(), in.nextInt());
                V += items[i].v;
            }

            long[][] sum = new long[N + 1][V + 1];
            long max = (long) 1e15;
            for (int i = 0; i <= N; i++) {
                Arrays.fill(sum[i], max);
                sum[i][0] = 0;
            }
            for (int i = 1; i <= N; i++) {
                E.Item item = items[i - 1];
                for (int j = 0; j <= V; j++) {
                    if (j < item.v) {
                        sum[i][j] = sum[i - 1][j];
                    } else {
                        sum[i][j] = Math.min(sum[i - 1][j], sum[i - 1][j - item.v] + item.w);
                    }
                }
            }
            long ans = 0;
            for (int i = V; i > 0; i--) {
                if (sum[N][i] <= W) {
                    ans = i;
                    break;
                }
            }
            out.println(ans);
        }

        static class Item {
            int w;
            int v;

            Item(int w, int v) {
                this.w = w;
                this.v = v;
            }

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    ll mod = 998244353;

    ll N, M, K;

    cin >> N >> M >> K;

    if(M == 1) {
        if(N - 1 == K) {
            cout << 1 << endl;
            return 0;
        }
    }

    ll a = M;

    for(ll i = 0; i < N - 1; i++) {
        a *= M - 1;
        a %= mod;
    }

    ll base = 1LL;

    ll u = N - 1LL;
    ll d = 0LL;

    ll ans = 0;

    for(ll i = 0; i <= K; i++) {
        ll x = (a % mod) * (base % mod);
        x %= mod;
        ans += x;
        ans %= mod;

        d++;
        base *= u;
        base %= mod;
        base *= modpow(d, mod - 2LL, mod);
        base %= mod;
        u--;

        a *= modpow(M - 1, mod - 2LL, mod);
        a %= mod;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3664
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
d = {}
for a_i in a:
    if a_i not in d.keys():
        d[a_i] = 0
    d[a_i] += 1
d = list(sorted(d.items(), key=lambda x:x[1])[::-1])
if len(d) <= k: print(0)
else: print(sum([v[1] for v in d[k:]]))

Measured memory_bytes: 40068
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1LL<<59)

#define int ll

signed main(){
    int n,m;
    cin>>n>>m;
    vector<int> less(m);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        if(a>=n)less[i]=0;
        else less[i] = n-a;
    }
    sort(all(less));
    int sum = 0;
    rep(i,m-1){
        sum+=less[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3096
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  int A = input();
  int B = input();

  output(max(A - B*2, 0));

  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return a % 1000000007;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}


int main(){
  ll n; cin >> n; map<string,ll> table;
  
  for(ll i=0; i < n; i++){
    string s; cin >> s;
    if(table.count(s)) table[s]++;
    else table[s] = 1;
  }
  
  ll maxvote = 0;
  
  for(auto p : table){
    ll vote = p.second;
    maxvote = max(maxvote,vote);
  }
  
  for(auto p : table){
    if(p.second == maxvote){
      cout << p.first << endl;
    }
  }
  
}


Measured memory_bytes: 25216
N=int(input())
div=1000000007

primelist=list(range(2,N+1))

for i in range(2,N+1):
        j=2
        while i*j<=N:
                if i*j in primelist:
                        primelist.remove(i*j)
                j+=1

primecntdict={p:0 for p in primelist}

for n in range(2,N+1):
        for p in [p for p in primelist if p <= n]:
                while n%p==0:
                        n/=p
                        primecntdict[p]+=1

res=1
for p in primelist:
        res*=primecntdict[p]+1
        res%=div

print(res)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <queue>
#include <deque>
#include <cmath>
#include <iomanip>
#include <cstdio>

using namespace std;

int main(){
    int n, m; cin >> n >> m;
    vector<int> as(n);
    for(int i=0; i<n; ++i){
        cin >> as[i];
    }
    vector<int> rems(n+1);
    for(int i=0; i<n; ++i){
        rems[i+1]=((long long)rems[i]+as[i])%m;
    }
    unordered_map<int, int> freq;
    long long ans=0;
    for(int i=0; i<n+1; ++i){
        ans+=freq[rems[i]];
        ++freq[rems[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4492
n = int(input())
rec = {}
for i in range(n):
    a = int(input())
    rec[i + 1] = a

i = 1
rec2 = [1]
num = 0
while i != 2 and num < n:
    i = rec[i]
    num += 1

if num == n:
    print(-1)
else:
    print(num)

Measured memory_bytes: 17892
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pii pair<int,int>
const long long MOD=1e9+7;



int main() {
    string s,t;
    cin>>s>>t;
    bool ans=true;
    rep(i,s.size()){
        if(s[i]!=t[i])
        ans=false;
    }
    if(ans) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 3624
#include<bits/extc++.h>
#ifdef _debug 
#define dout(i) cout << #i << ' ' << i << ' '
#else 
#include<bits/stdc++.h>
#define dout(i) 0&&0
#endif
#pragma GCC optimize("unroll-loops,no-stack-protector,O3")
#define priority_queue __gnu_pbds::priority_queue
#define unordered_map __gnu_pbds::gp_hash_table
#define rep(_n) for(int __i = _n;__i--;)
#define rep0(_i, _n) for(int _i = 0; (_i)<(_n) ;++_i)
#define rep1(_i, _n) for(int _i = 1; (_i)<=(_n) ;++_i)
#define yn(i) ((i)?"Yes" : "No")
#define eout(i) {cout << (i) << '\n';exit(0);}
#define rout(i) {return cout << (i) << '\n', 0;}
#define multi int _T;for(cin >> _T;_T--;)
using namespace std;
using ll = long long;using ull = unsigned long long;using ul = unsigned;using db = double;
using __gnu_pbds::null_type;
inline void read(char &a){static char p; while(isspace(p = getchar_unlocked())); a = p; }
inline void read(string &a){static char p; while(isspace(p = getchar_unlocked())); a = p; while(!isspace(p = getchar_unlocked()))a.push_back(p);}
template<typename T> inline void read(T& a){static char p; static bool b; while (!isdigit(p = getchar_unlocked()))b = p == '-'; a = p ^ '0'; while (isdigit(p = getchar_unlocked())) a *= 10, a += p ^ '0'; if(b)a *= -1; }
template<typename T> inline void read(T begin, const T &end){while(begin != end)read(*begin), ++begin;}
template<typename T> inline void write(T begin, const T &end){while(begin != end)cout << *begin << " \n"[next(begin) == end], ++begin;}
template<typename T> using rbtree = __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<typename T> inline ostream& operator << (ostream &ou, const vector<T> &a){for(auto it = a.begin();it != a.end();++it)ou << (it != a.begin() ? " " : "") << *it;return ou;}
template<typename T1, typename T2>inline istream& operator >> (istream &in, pair<T1, T2> &a){return in >> a.first >> a.second;}
template<typename T1, typename T2>inline ostream& operator << (ostream &ou, const pair<T1, T2> &b){return ou << b.first << ' ' << b.second;}
template<typename T> inline long long pow(long long v, long long t, const T &p){long long res = 1;for(;t;t >>= 1, v = v * v % p)if(t & 1)res = res * v % p;return res;}
template<typename T> inline vector<vector<T>> operator * (const vector<vector<T>> &a, const vector<vector<T>> &b){assert(a.front().size() == b.size());vector<vector<T>> res(a.size(), vector<T>(b.front().size()));for(int i = 0;i < a.size();++i)for(int j = 0;j < b.front().size();++j)for(int k = 0;k < a.front().size();++k)res[i][j] += a[i][k] * b[k][j];return res;}
template<typename T> inline vector<vector<T>> pow(vector<vector<T>> v, long long t){vector<vector<T>> res;for(;t;t >>= 1, v = v * v)if(t & 1)res = (res.empty() ? v : res * v);return res;}

const int maxn = 300010;
int a[maxn], n;
int cnt[3];
signed main(){
	ios_base::sync_with_stdio(0), cin.tie(0);
	read(n);
	read(a, a+n);
	rep0(i, n){
		if(a[i]&1)++cnt[0];
		else if(a[i]&2)++cnt[1];
		else ++cnt[2];
	}
	n -= cnt[1];
	cnt[1] = bool(cnt[1]);
	rout(yn(cnt[0]-1 <= cnt[2]-cnt[1]));
}

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

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

using namespace std;

int main() {
    int r,g,b,n,cnt = 0;
    cin >> r >> g >> b >> n;
    rep(i, (n / r) + 1){
        rep(j, (n / g) + 1){
            if(((n - (i * r + j * g)) % b == 0) && n >= (i * r + j * g)){
                cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
	double set[2][8] = { {0,35.5,37.5,40,43,50,55,70},
						  {0,71,77,83,89,105,116,148} };
	double time[2];
	while(cin>>time[0]>>time[1]){
		int class_m[2]={7,7};
		int classs;
		for(int i=0;i<2;i++){
			for(int j=0;j<7;j++){
				if(set[i][j]<=time[i]&time[i]<set[i][j+1]){
					class_m[i] = j;
					break;
				}
			}
			
		}
		classs = max(class_m[0],class_m[1]);
		switch(classs){
			case 0:
			cout << "AAA" << endl;
			break;
			case 1:
			cout << "AA" << endl;
			break;
			case 2:
			cout << "A" << endl;
			break;
			case 3:
			cout << "B" << endl;
			break;
			case 4:
			cout << "C" << endl;
			break;
			case 5:
			cout << "D" << endl;
			break;
			case 6:
			cout << "E" << endl;
			break;
			default:
			cout << "NA" << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
public class Main {
    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int N=sc.nextInt();
        int[] a=new int[N];
        for(int i=0;i<N;i++){
            a[i]=sc.nextInt();
        }
        Arrays.sort(a);
        if(a.length%3!=0){
            if(a[N-1]==0){
                System.out.println("Yes");
            }else{
                System.out.println("No");
            }
            return;
        }

        if(a[0]==a[N/3-1]&&a[N/3]==a[N/3*2-1]&&a[N/3*2]==a[N-1]){
            if((a[0]^a[N/3])==a[N/3*2]){
                System.out.println("Yes");
                return;

            }
            System.out.println("No");
            return;

        }else{
            System.out.println("No");
            return;

        }


    }
}


Measured memory_bytes: 49180
#define ONLINE_JUDGE
#include <algorithm>
#include <fstream>
#include <iostream>
#include <vector>
#include <cmath>
#include <iterator>
#include <map>
#include <set>
#ifndef ONLINE_JUDGE
#include <prettyprint/prettyprint.hpp>
#endif

#define FOR(i, n) for(int i = 0; i < n; ++i)
#define TEST int T; std::cin >> T; while(T--)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vll = std::vector<ll>;
using vull = std::vector<ull>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
#ifndef ONLINE_JUDGE
	ifstream fin("in.txt");
	ofstream fout("out.txt");
	auto cinbuf = cin.rdbuf(fin.rdbuf());    // save and redirect
	auto coutbuf = cout.rdbuf(fout.rdbuf()); // save and redirect
#endif	
	int N;
	cin >> N;
	int vals[N];
	for (int i = 0; i < N; ++i) {
		cin >> vals[i];
	}
	long long DP[N][N];
	for(int i =  0; i < N; ++i) {
		DP[i][i] = vals[i];
	}
	for(int L = N - 1; L >= 0; --L) {
		for(int R = L + 1; R < N; ++R) {
			DP[L][R] = max(vals[L] - DP[L + 1][R], vals[R] - DP[L][R - 1]);
		}
	}
	cout << DP[0][N - 1] << endl;
#ifndef ONLINE_JUDGE
	cin.rdbuf(cinbuf);    // restore
	cout.rdbuf(coutbuf); // restore
#endif	
}


Measured memory_bytes: 70272
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int size = in.nextInt(), arr[] = new int[size];

		arr[0] = Integer.parseInt(in.next());
		int tail = 0;

		for(int i = 1; i < size; i++) {
			int x = Integer.parseInt(in.next());

			if(x != arr[tail]) {
				arr[++tail] = x;
			}
		}

		for(int i = 0; i <= tail; i++) {
			out.printf("%d%s", arr[i], (i < tail) ? " " : "\n");
		}
		out.flush();
		in.close();
	}

}



Measured memory_bytes: 78360
#include <stdio.h>

int main(void)
{
	int a[200][200],m,n,b[200],i,j;
	int c[200]={};
	scanf("%d %d",&n,&m);
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=m;i++){
		scanf("%d",&b[i]);
	}
	for(i=1;i<=n;i++){
		for(j=1;j<=m;j++){
			c[i]=c[i]+a[i][j]*b[j];
		}
	}
	for(i=1;i<=n;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}

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

int h,w;
char g[2005][2005];
int lh[2005][2005];
int lw[2005][2005];
int ans;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>g[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        int l=1;
        for(int j=1;j<=w;j++){
            if(g[i][j]=='#'){
                for(int k=l;k<j;k++){
                    lh[i][k]=j-l;
                }
                l=j+1;
            }
        }
        for(int k=l;k<=w;k++){
            lh[i][k]=w-l+1;
        }
    }
    for(int i=1;i<=w;i++){
        int l=1;
        for(int j=1;j<=h;j++){
            if(g[j][i]=='#'){
                for(int k=l;k<j;k++){
                    lw[k][i]=j-l;
                }
                l=j+1;
            }
        }
        for(int k=l;k<=h;k++){
            lw[k][i]=h-l+1;
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            ans=max(ans,lh[i][j]+lw[i][j]-1);
        }
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 35584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int k, s;
  cin >> k >> s;
  int ans = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k && y <= s-x; y++) {
      if (s-x-y <= k) ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*
	Name:
	Author: xiaruize
	Date:
*/

#include<bits/stdc++.h>
using namespace std;

#define ull  unsigned long long
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ll long long
#define form(i,j,n) for(int i=int(j);i<=int(n);i++)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pis pair<int,string>

inline ll read() {
	ll f=1,x=0;
	char ch=getchar();
	while(!isdigit(ch))
	{
	 	if(ch=='-')
		 	f=-1;
		ch=getchar();
	}
	while(isdigit(ch))
	{
	 	x=x*10+ch-'0';
		ch=getchar();
	}
	return x*f;
}
const int maxn=1e5+5;
const ll mod=1e9+7;

ll a[maxn];
ll inv[maxn];

ll qPow(ll a,int b){
	ll ans=1;
	while(b){
		if(b&1) ans=(ans*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return ans;
}

int main(){
	int n=read(),k=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
	}
	sort(a+1,a+1+n);
	
	for(int i=1;i<=n;i++){
		inv[i]=qPow(i,mod-2);
	}
	
	ll ans=a[k];ll p=1;
	for(int i=k+1;i<=n;i++)
	{
		p=(p*(i-1))%mod;
		p=(p*inv[i-k])%mod;
		ans=(ans+a[i]*p%mod)%mod;
	}
	ans=(ans+mod-a[n-k+1])%mod;
	p=1;
	for(int i=k+1;i<=n;i++){
		p=(p*(i-1))%mod;
		p=(p*inv[i-k])%mod;
		ans=(ans+mod-a[n-i+1]*p%mod)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

#include <stack>
#include <vector>
using namespace std;
typedef pair<int, int> P;

// careful!!!!!!!!
// 1-indexed
int GetMaxRectange(const vector<vector<int>>& xs) {
  int h = xs.size() - 1;
  int w = xs[0].size() - 1;
  int ans = max(h, w);
  rep(i, 1, h - 1) {
    stack<P> s;
    rep(j, 1, w - 1) {
      int lj = j;
      while (!s.empty() && s.top().first > xs[i][j]) {
        ans = max(ans, (s.top().first + 1) * (j - s.top().second + 1));
        lj = s.top().second;
        s.pop();
      }
      if (xs[i][j]) s.emplace(xs[i][j], lj);
    }
    while (!s.empty()) {
      ans = max(ans, (s.top().first + 1) * (w - s.top().second + 1));
      s.pop();
    }
  }
  return ans;
}

int H,W;

vector<vector<int>> fie;

int main(){
  cin >> H >> W;
  fie.resize(H + 1,vector<int>(W + 1,0));
  rep(i,1,H){
    string s;
    cin >> s;
    rep(j,1,W){
      fie[i][j] = (s[j - 1] == '#') ? 1 : 0;
    }
  }

  vector<vector<int>> xs(H + 1,vector<int>(W + 1,0));

  rep(i,1,H - 1){
    rep(j,1,W - 1){
      int cnt = 0;
      rep(x,i,i + 1)rep(y,j,j + 1) cnt += fie[x][y];
      if(cnt == 0 || cnt == 2 || cnt == 4){
        if(i == 1) xs[i][j] = 1;
        else xs[i][j] = xs[i - 1][j] + 1;
      }
    }
  }

  cout << GetMaxRectange(xs) << endl;
}


Measured memory_bytes: 31744
n, k = map(int, input().split())
h = tuple(map(int, input().split()))

INF = 10**10
dp = [INF] * n
dp[0] = 0
# dp[i] = (足場iにたどり着いた時点でのコストの最小値)

for i in range(1, n):
    dp[i] = min(
        dp[j] + abs(h[j] - h[i])
        for j in range(max(0, i - k), i)
    )

print(dp[n - 1])


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

using namespace std;

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

constexpr int MAX_SOLID = 10000;

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

    int N;
    cin >> N;

    vector<tuple<int, int, ll> > blocks(N);
    for(int i=0;i<N;i++){
        int w, s;
        ll v;
        cin >> w  >> s >> v;
        blocks[i] = make_tuple(-(s+w), w, v);
    }

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

    vll dprow(MAX_SOLID+1, 0);
    vvll dp(N, dprow);

    for(int i=0;i<N;i++){
        int cs = -get<0>(blocks[i]);
        int cw = get<1>(blocks[i]);
        ll cv = get<2>(blocks[i]);

        cs -= cw;

        // cout << cs << " " << cw << " " << cv << endl;

        dp[i][cs] = max(dp[i][cs], cv);

        if (i > 0) {
            for(int c=0; c<=MAX_SOLID; c++) {
                dp[i][c] = max(dp[i][c], dp[i-1][c]);
            }

            for(int c=cw; c<=MAX_SOLID; c++){
                int nc = min(c-cw, cs);
                dp[i][nc] = max(dp[i][nc], dp[i-1][c] + cv);
            }
        }

        for (int c=MAX_SOLID-1; c>=0; c--) {
            dp[i][c] = max(dp[i][c], dp[i][c+1]);
        }
    }

    ll ans = 0;
    for(int c=0;c<=MAX_SOLID;c++) ans = max(ans, dp[N-1][c]);
    cout << ans << endl;

    return 0;
}

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

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

struct item
{
    int w, v;
};

int n, W;
vector<item> items;
vector<vector<lint>> dp;

lint rec_dp(int i, int w)
{
    if (dp[i][w] != -1)
    {
        return dp[i][w];
    }
    lint result;
    if (i == n)
    {
        result = 0;
    }
    else if (w < items[i].w)
    {
        result = rec_dp(i + 1, w);
    }
    else
    {
        result = max(
            rec_dp(i + 1, w),
            rec_dp(i + 1, w - items[i].w) + items[i].v);
    }
    dp[i][w] = result;
    return result;
}

int main()
{
    cin >> n >> W;
    items.resize(n);
    rep(i, n)
    {
        int w, v;
        cin >> items[i].w >> items[i].v;
    }
    dp.resize(n + 1);
    rep(i, n + 1)
    {
        dp[i].resize(W + 1);
        rep(w, W + 1)
        {
            dp[i][w] = -1;
        }
    }
    cout << rec_dp(0, W) << endl;
}

Measured memory_bytes: 79488
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
const long long INF = 1LL<<60;

int main () {
    
    string s,t;cin>>s>>t;

    int ans =0;
    rep(i,3) {
        if (s[i]==t[i]) {
            ans++;
        }
    }
    cout<<ans<<endl;

}

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

const int64_t MAX_N = 100;
const int64_t MAX_W = 1e5;

bool isCalc[MAX_N + 5][MAX_W + 5];
int64_t n, v[MAX_N + 5], w[MAX_N + 5];
int64_t dp[MAX_N + 5][MAX_W + 5];

int64_t CalcDp(int64_t ind, int64_t curr) {
	if(curr < 0) { 
		return -1;
	}
	else if(ind == n) {
		return 0;
	}
	else if(isCalc[ind][curr]) {
		return dp[ind][curr];
	}

	int64_t aux = CalcDp(ind + 1, curr - w[ind]);
	if(aux != -1) {
		dp[ind][curr] = aux + v[ind];
	}

	dp[ind][curr] = std::max(dp[ind][curr], CalcDp(ind + 1, curr));

	isCalc[ind][curr] = true;
	return dp[ind][curr];
}

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

	int64_t m;
	std::cin >> n >> m;

	for(int64_t i = 0; i < n; i++) {
		std::cin >> w[i] >> v[i];
	}
	
	std::cout << CalcDp(0, m) << '\n';
}



Measured memory_bytes: 88320
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

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

bool vis[50][50][50][50];

void move(int& x, int& y, int dir, vector<string>& a) {
	int H = a.size(), W = a[0].length();
	x += dx[dir]; y += dy[dir];
	if (x >= 0 && x < W && y >= 0 && y < H && a[y][x] != '#')
		return;
	x -= dx[dir]; y -= dy[dir];
}

int main() {
	for (;;) {
		int W, H; cin >> W >> H;
		if (W == 0 && H == 0) break;
		vector<string> al(H), ar(H);
		int xsl, ysl, xtl, ytl, xsr, ysr, xtr, ytr;
		for (int y = 0; y < H; y++) {
			cin >> al[y] >> ar[y];
			reverse(ar[y].begin(), ar[y].end());
			for (int x = 0; x < W; x++) {
				if (al[y][x] == 'L') {
					xsl = x; ysl = y;
				}
				if (al[y][x] == '%') {
					xtl = x; ytl = y;
				}
				if (ar[y][x] == 'R') {
					xsr = x; ysr = y;
				}
				if (ar[y][x] == '%') {
					xtr = x; ytr = y;
				}
			}
		}
		for (int yl = 0; yl < H; yl++)
			for (int xl = 0; xl < W; xl++)
				for (int yr = 0; yr < H; yr++)
					for (int xr = 0; xr < W; xr++)
						vis[xl][yl][xr][yr] = false;
		vis[xsl][ysl][xsr][ysr] = true;
		queue<int> XL, YL, XR, YR;
		XL.push(xsl); YL.push(ysl); XR.push(xsr); YR.push(ysr);
		while (!XL.empty()) {
			int xl = XL.front(); XL.pop();
			int yl = YL.front(); YL.pop();
			int xr = XR.front(); XR.pop();
			int yr = YR.front(); YR.pop();
			for (int dir = 0; dir < 4; dir++) {
				int _xl = xl, _yl = yl, _xr = xr, _yr = yr;
				move(_xl, _yl, dir, al);
				move(_xr, _yr, dir, ar);
				if (vis[_xl][_yl][_xr][_yr]) continue;
				vis[_xl][_yl][_xr][_yr] = true;
				if ((_xl == xtl && _yl == ytl) || (_xr == xtr && _yr == ytr)) continue;
				XL.push(_xl); YL.push(_yl); XR.push(_xr); YR.push(_yr);
			}
		}
		cout << (vis[xtl][ytl][xtr][ytr] ? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 8276
#include <iostream>
using namespace std;
#define in(v) v; cin >> v;
#define rep(i,n) for(int i=0;i<(n);++i)

template<int MOD> struct MInt {
  long long val;
  MInt(long long val = 0) : val(val % MOD) { if (val < 0) val += MOD; }
  MInt operator-() const { return MInt(-val); }
  MInt operator+(const MInt& n) const { return MInt(val) += n; }
  MInt operator-(const MInt& n) const { return MInt(val) -= n; }
  MInt operator*(const MInt& n) const { return MInt(val) *= n; }
  MInt operator/(const MInt& n) const { return MInt(val) /= n; }
  MInt& operator+=(const MInt& n) { val = (val + n.val) % MOD; return *this; }
  MInt& operator-=(const MInt& n) { val = (MOD + val - n.val) % MOD; return *this; }
  MInt& operator*=(const MInt& n) { val = (val * n.val) % MOD; return *this; }
  MInt& operator/=(const MInt& n) { val = (*this * n.inv()).val; return *this; }
  bool operator==(const MInt& n) { return val == n.val; }
  bool operator!=(const MInt& n) { return val != n.val; }
  MInt pow(long long n) const {
    MInt pow = val, ans = 1;
    for (long long p = n; p > 0; p >>= 1) {
      if (p & 1) ans *= pow;
      pow *= pow;
    }
    return ans;
  }
  MInt inv() const { return pow(MOD-2); }
  friend ostream& operator<<(ostream& os, const MInt& n) { os<<n.val; return os; }
  friend istream& operator>>(istream& os, MInt& n) { os>>n.val; return os; }
};
using mint = MInt<1000000007>;

mint fac[1000001], inv[1000001];
int main() {
  int in(X); int in(Y);

  if ((X + Y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  int k = (X + Y) / 3;
  if (k > X || k > Y) {
    cout << 0 << endl;
    return 0;
  }
  X -= k; Y -= k;
  fac[0] = inv[0] = 1;
  rep(i, 1e6) {
    fac[i+1] = fac[i] * (i+1);
    inv[i+1] = inv[i] / (i+1);
  }
  cout << fac[X + Y] * inv[X] * inv[Y] << endl;

  return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define loop(n, i) for(int i=0;i<n;i++)
#define loop1(n, i) for(int i=1;i<=n;i++)
#define rloop(n, i) for(int i=n;i;i++)
#define HERE cout << "HERE: " << __LINE__ << endl;
#define INSP(v) cout << v << " at " << __LINE__ << endl;
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;

int main() {
    int n, l; cin >> n >> l;
    int s = 0, m = 1<<29;
    loop (n, i) {
        s += l + i;
        if (abs(m) > abs(l + i)) {
            m = l + i;
        }
    }

    cout << s - m << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)n; i++)
#define REPll(i, n) for (decltype(n) i = 0; i < n; i++)
#define REPvec(itr, mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007 //1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool> vecbool;
typedef vector<int> vecint;
typedef vector<ll> vecll;
typedef vector<string> vecstr;
typedef vector<vecint> vec2int;
typedef vector<vecbool> vec2bool;
int dx[4]{-1, +1, 0, 0};
int dy[4]{0, 0, -1, +1};
//////////////////////////////////////////
int main()
{
    int n; cin >> n;
  vector<pair<ll, ll> > v(n);
  for(auto&e: v) cin >> e.first >> e.second;
  vector<vector<pair<ll, ll> > > g(n, vector<pair<ll, ll>>(n));
  map<pair<ll, ll>,int > mp;
  REP(i,n){
    REP(j,n){
      if(i == j) continue;
      g[i][j] = make_pair(v[i].first - v[j].first, v[i].second -v[j].second);
      mp[g[i][j]]++;
    }
  }
  int maxnum = 0;
  REPvec(itr,mp){
    // cout << itr->first.first << " " << itr->first.second << endl;
    maxnum = max(itr->second,maxnum);
  }
  

  // sort(all(v));
  // // for(auto e: v) cout << e.first << " " << e.second << endl;
  // int ans = n;
  // for(int i = 0; i < n; i ++){
  //   for(int j = i + 1; j < n; j ++){
  //     ll p = v[j].first - v[i].first;
  //     ll q = v[j].second - v[i].second;
  //     int now = 1;
  //     for(int k = 1; k < n ; k ++){
  //       if(v[k].first - v[k - 1].first == p&&v[k].second - v[k - 1].second == q){
          
  //       }else{
  //         now ++;
  //       }
  //     }
  //     ans = min(now, ans);
  //   }
  // }
  cout << n - maxnum<< endl;
}

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

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

def main():
  n,k=LI()
  l=LS()

  ans=1
  while True:
    if ans>=n:
      s=str(ans)

      f=True
      for x in s:
        if x in l:
          f=False
          break

      if f:
        return ans

    ans+=1

print(main())


Measured memory_bytes: 6304
def main():
    a, b, m = map(int, input().split())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    xyc = [list(map(int, input().split())) for _ in [0]*m]
    ans = min(a)+min(b)
    for x, y, c in xyc:
        ans = min(ans, a[x-1]+b[y-1]-c)
    print(ans)


main()

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

using namespace std;

int main()
{
  string S;
  cin >> S;
  for(int i = 0; i < (1 << 4); i++) {
    string s;
    s += S[0];
    int sum = S[0] - '0';
    for(int j = 1; j < 4; j++) {
      if((i >> j) & 1) s += "+", sum += S[j] - '0';
      else s += "-", sum -= S[j] - '0';
      s += S[j];
    }
    if(sum == 7) {
      cout << s << "=7" << endl;
      return (0);
    }
  }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;

int main(int argc, char* argv[])
{
    int i;
    for(i=0; i<10000; i++) {
        int a;
        scanf("%d", &a);
        printf("Case %d: %d\n", i+1, a);
        if(a==0) break;
    }
    return 0;
}



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

const int maxn = 3e5+2;

struct node{
	ll w;
	int id;
	bool operator< (const node&x)const{
		return w<x.w;
	}
};
int main() {
	ios::sync_with_stdio(0);
	ll x,y,a,b,c;
	ll p;
	cin>>x>>y>>a>>b>>c;
	priority_queue<node>q;
	for(int i=1; i<=a; ++i) {
		cin>>p;
		q.push({p,1});
	}
	for(int i=1; i<=b; ++i) {
		cin>>p;
		q.push({p,2});
	}
	for(int i=1; i<=c; ++i) {
		cin>>p;
		q.push({p,3});
	}
	ll ans = 0;
	int k1=0,k2=0,k3=0;
	while(k1+k2+k3<x+y)
	{
		node p = q.top(); q.pop();
//		cout<<p.w<<"\n";
		if(p.id == 1) {
			if(k1==x) continue;
			++k1; ans+=p.w; 
		}
		else if(p.id == 2 ) {
			if(k2==y) continue;
			++k2; ans+=p.w;
		}
		else {
			++k3; ans+=p.w;
		} 
	}

	cout<<ans<<"\n";
}

Measured memory_bytes: 10604
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  ll a, b, k;
  cin >> a >> b >> k;
  ll mn = min(a, k);
  a = a - mn;
  k = k - mn;
  if(a == 0){
    b = max(b-k, (ll)0);
    cout << a << " " << b << endl;
  }else{
    cout << a << " " << b << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s = str(input())

L = s[0:n]
R = s[n:]
R = list(R)
R.reverse()
R = ''.join(R)

DL = {}
for i in range(2**n):
    p = ''
    q = ''
    for j in range(n):
        if (i >> j)&1:
            p += L[j]
        else:
            q += L[j]
    if (p, q) in DL:
        DL[(p, q)] += 1
    else:
        DL[(p, q)] = 1

DR = {}
for i in range(2**n):
    p = ''
    q = ''
    for j in range(n):
        if (i >> j)&1:
            p += R[j]
        else:
            q += R[j]
    if (p, q) in DR:
        DR[(p, q)] += 1
    else:
        DR[(p, q)] = 1

#print(DL)
#print(DR)
ans = 0
for k, v in DL.items():
    if k in DR:
        ans += v*DR[k]
print(ans)


Measured memory_bytes: 139148