akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <ios>
#include <iomanip>
#include <stack>
#include <queue>
#include <algorithm>

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

using namespace std;

const int INF = 100000001;

int main(){
  int t[5];

  int ind = -1;
  int max = 0;

  REP(i,5){
    cin >> t[i];
    REP(j,14){
      if (10 * j - t[i] >= 0) {
        if (10 * j - t[i] >= max) {
          ind = i;
          max = 10 * j - t[i];
        }
        break;
      }
    }
  }

  int ans = 0;
  REP(i,5){
    if (i == ind) {
      continue;
    }
    REP(j,13){
      if (10 * j < t[i] && t[i] <= 10 * j + 10) {
        ans += 10 *j + 10;
        break;
      }
    }
  }
  ans += t[ind];

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

Measured memory_bytes: 256
import collections
import sys

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

if N == 0:
    print(X)
    exit()

p = list(map(int, input().split()))

if X not in p:
    print(X)
    exit()

queue = collections.deque([X-1, X+1])

while True:
  cur = queue.popleft()
  if cur in p:
    if cur < X:
    	queue.append(cur-1)
    else:
    	queue.append(cur+1)
  else:
  	print(cur)
  	break

Measured memory_bytes: 64944
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

bool _flg[8];
double _sum = 0;

int N;
int X[10];
int Y[10];

void func(int n, int prev, double l)
{
	if (n == N)
	{
		_sum += l;
		return;
	}

	for (int i = 0; i < N; i++)
	{
		if (!_flg[i])
		{
			_flg[i] = true;
			int dx = X[i] - X[prev];
			int dy = Y[i] - Y[prev];
			double len = sqrt(dx * dx + dy * dy);
			func(n + 1, i, l + len);
			_flg[i] = false;
		}
	}
}

signed main()
{
	cin >> N;
	REP(i, N) cin >> X[i] >> Y[i];

	for (int i = 0; i < N; i++)
	{
		_flg[i] = true;
		func(1, i, 0);
		_flg[i] = false;
	}

	int n = 1;
	REP(i, N) n *= (i + 1);
	double ave = _sum / (double)n;
	cout << fixed << setprecision(10) << ave << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main()
{
	int a, b, c;
	
	while(scanf("%d %d %d", &a, &b, &c) != EOF)
	{
		if(a == -1 && b == -1 && c == -1)
		{
			break;
		}
		if((a == -1 || b == -1) && c == -1)
		{
			printf("F\n");
		}
		else
		{
			int sum = 0, k = 0;
			if(a >= 0)
			{
				sum += a;
			}
			if(b >= 0)
			{
				sum += b;
			}
			if(sum >= 80)
			{
				printf("A\n");
			}
			else if(sum >= 65 && sum < 80)
			{
				printf("B\n");
			}
			else if((sum >= 50 && sum < 65) || c >= 50)
			{
				printf("C\n");
			}
			else if(sum >= 30 && sum < 50)
			{
				printf("D\n");
			}
			else
			{
				printf("F\n");
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 2032
import java.util.*;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int k = sc.nextInt();

        for (int i = 0; i < k; i++) {
            if (a >= b) {
                b *= 2;
            } else if (b >= c) {
                c *= 2;
            } else {
                break;
            }
        }

        System.out.println(a < b && b < c ? "Yes" : "No");
    }
}

Measured memory_bytes: 35528
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000002

int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector<map<int,vector<int>>> E(N);
	
	for(int i=0;i<M;i++){
		int p,q,c;
		scanf("%d %d %d",&p,&q,&c);
		p--;q--;
		E[p][c].push_back(q);
		E[q][c].push_back(p);
	}
	
	map<pair<int,int>,int> dis;
	dis[make_pair(0,0)]=0;
	deque<pair<int,int>> Q;
	Q.push_back(make_pair(0,0));
	set<pair<int,int>> visited;
	while(Q.size()!=0){
		int x = Q.back().first;
		int u = Q.back().second;
		Q.pop_back();
		if(visited.count(make_pair(x,u)))continue;
		if(x==0){
			for(auto a:E[u]){
				int v = a.first;
				if(dis.count(make_pair(v,u)))continue;
				dis[make_pair(v,u)] = dis[make_pair(x,u)]+1;
				Q.emplace_front(v,u);
			}
		}
		else{
			for(int i=0;i<E[u][x].size();i++){
				int v = E[u][x][i];
				if(dis.count(make_pair(x,v))&&dis[make_pair(x,v)]<=dis[make_pair(x,u)])continue;
				dis[make_pair(x,v)]=dis[make_pair(x,u)];
				Q.emplace_back(x,v);
			}
			int v = u;
			if(dis.count(make_pair(0,v))&&dis[make_pair(0,v)]<=dis[make_pair(x,u)])continue;
			dis[make_pair(0,v)]=dis[make_pair(x,u)];
			Q.emplace_back(0,v);
		}
	}
	
	pair<int,int> ans(0,N-1);
	if(dis.count(ans))cout<<dis[ans]<<endl;
	else cout<<-1<<endl;
	
	return 0;
}

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

int main()
{
    int m1,m2,d1,d2;
    std::cin >> m1 >>  d1;
    std::cin >> m2 >>  d2;

    int ans = (m1 == m2) ? 0 : 1;
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
const string YES = "Yes";
const string NO = "No";

void solve(){
    ll n;cin>>n;
    vec a(n);rep(i,n)cin>>a[i];
    vec b(n);rep(i,n)cin>>b[i];

    ll sum1=0;
    ll sum2=0;
    rep(i,n){
        if(a[i]<b[i])sum1+=(b[i]-a[i])/2;
        else sum2+=a[i]-b[i];
    }
    //cerr<<sum1<<' '<<sum2<<'\n';
    cout<<(sum1>=sum2?YES:NO)<<'\n';
}

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


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

int n,m;

void solve()
{
	vector<int> veg(n);
	int ans = 0;
	for(int i = 0; i < n; i++)
		cin >> veg[i];

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

	for(int i = 1; i <= n; i++){
		int d = veg.back();
		veg.pop_back();
		if(i % m)
			ans += d;
	}
	
	cout << ans << endl;
}


int main(void)
{
	while(cin >> n >> m, n | m){
		solve();
	}

	return 0;
}

Measured memory_bytes: 1216
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;



int main() {

	int n;
	cin >> n;
	vector<int>a(n), b(n);
	vector<int>x(n), y(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		x[i] += a[i];
		if(i<n-1)x[i + 1] = x[i];
	}

	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}
	for (int j = n - 1; j >= 0; j--) {
		y[j] += b[j];
	
		if (j)y[j - 1] += y[j];
	}	
	int ans = 0;
	for (int i = 0; i < n; i++) {
		ans = max(ans, x[i] + y[i]);
	}
	cout << ans << endl;
	return 0;

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		(new Main()).execute();
	}
	public void execute() {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		String S = sc.next();
		String ans = getAnswer(S) ;
		System.out.println(ans);
	}

	public String getAnswer(String S) {
		String ans = "Yes" ;


		for(int i = 0 ; i < S.length(); i ++) {
			char c = S.charAt(i) ;
			if((i + 1)%2 == 1) {//奇数文字目
				if(c != 'R' && c != 'U' && c != 'D') {
					ans = "No" ;
					break ;
				}
			}else {
				if(c != 'L' && c != 'U' && c != 'D') {
					ans = "No" ;
					break ;
				}
			}
		}
		return ans ;
	}


}


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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

int check(const vector<vector<int>> &z)
{
    int Z=z.size();
    if(Z==1) return z[0][0];

    int ret=0;
    rep(i,Z)
    {
        bool ok=true;
        rep(j,Z)
        {
            if(z[i][j]==0) ok=false;
        }
        if(ok) ++ret;
    }
    rep(i,Z)
    {
        bool ok=true;
        rep(j,Z)
        {
            if(z[j][i]==0) ok=false;
        }
        if(ok) ++ret;
    }

    bool ok=true;
    rep(i,Z)
    {
        if(z[i][i]==0) ok=false;
    }
    if(ok) ++ret;

    ok=true;
    rep(i,Z)
    {
        if(z[i][Z-1-i]==0) ok=false;
    }
    if(ok) ++ret;

    return ret;
}


int main()
{
    int n,m,win[2];
    int num[100000];

    map<int,pi> f[2];

    scanf(" %d %d %d %d", &n, &win[0], &win[1], &m);
    rep(i,2)rep(j,n)rep(k,n)
    {
        int c;
        scanf(" %d", &c);
        f[i][c] = pi(j,k);
    }
    rep(i,m) scanf(" %d", &num[i]);

    int l=-1,r=m;
    while(r-l>1)
    {
        int mid=(l+r)/2;

        vector<vector<int>> v[2];
        rep(i,2) v[i]=vector<vector<int>>(n,vector<int>(n,0));

        rep(i,mid+1)
        {
            rep(j,2)if(f[j].find(num[i]) != f[j].end())
            {
                pi p=f[j][num[i]];
                v[j][p.fi][p.se]=1;
            }
        }

        int a[2];
        rep(i,2) a[i]=check(v[i]);

        if(win[0]<=a[0] || win[1]<=a[1]) r=mid;
        else l=mid;
    }

    string ans="DRAW";
    if(r<m)
    {
        vector<vector<int>> v[2];
        rep(i,2) v[i]=vector<vector<int>>(n,vector<int>(n,0));

        rep(i,r+1)
        {
            rep(j,2)if(f[j].find(num[i]) != f[j].end())
            {
                pi p=f[j][num[i]];
                v[j][p.fi][p.se]=1;
            }
        }

        int a[2];
        rep(i,2) a[i]=check(v[i]);

        if(win[0]<=a[0] && win[1]<=a[1]) ans="DRAW";
        else
        {
            if(win[0]<=a[0]) ans="USAGI";
            if(win[1]<=a[1]) ans="NEKO";
        }
    }

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

Measured memory_bytes: 22096
S=input()
T=input()
minchange=len(T)
if len(S)==len(T):
    temp=0
    for i in range(len(S)):
        if S[i]!=T[i]:
            temp+=1
    minchange=min(minchange,temp)

for i in range(len(S)-len(T)):
    temp=0
    for j in range(len(T)):
        if S[i+j]!=T[j]:
            temp+=1
    minchange=min(minchange,temp)
print(minchange)

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

long long com(int n, int k){
    if(k==1) return n;
    else if(k==2) return n*(n-1)/2;
    else return n*(n-1)*(n-2)/3/2;
}

long long pow_int(long long x, long long n){
    long long ret = 1;
    for (int i = 0; i < n; i++) ret *= x;
    return ret;    
}

long long calc_pattern(std::string &s, int digit, int n, int k, bool is_small){
    if(k==0) return 1;
    if(k>n) return 0;
    if(is_small) return pow_int(9, k) * com(n, k);
    long long ret = 0;
    if(s[digit]=='0'){
        return calc_pattern(s, digit+1, n-1, k, false);
    } else {
        ret += calc_pattern(s, digit+1, n-1, k-1, false);
        ret += calc_pattern(s, digit+1, n-1, k, true);
        ret += ( (int) s[digit] - '1' ) * calc_pattern(s, digit+1, n-1, k-1, true);
    }
    return ret;
}

int main(){
    using namespace std;
    string s; cin >> s;
    int k; cin >> k;
    int n = s.size();
    long long ans = 0;
    ans = calc_pattern(s, 0, n, k, false);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long 
#define ul unsigned long
#define ll long long
#define pb push_back
#define sodayoda_C  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define f(i,a,b) for(int i = a;i<b;i++)
#define fb(i,a,b) for(int i = a;i>b;i--)
#define endl "\n"
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define mp make_pair
//memset(name,'',size)
//reverse(s,begin(),s.end())

using namespace std;

int main(){	
	sodayoda_C;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	int t;
	//cin>>t;
	t = 1;
	while(t--){
		int n,x,m;
		cin>>n>>x>>m;
		cout<<((n/x)+(n%x!=0))*m<<endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;
 
void Main() {
  int n;
  R n;
  int x=1;
  while(x*2<=n) x*=2;
  pr(x);
}
 
int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}

Measured memory_bytes: 256
use proconio::*;

fn main() {
    input! {
        n: usize
    };
    let mut shop = Vec::new();
    for i in 0..n {
        input! {
            s: String,
            p: u32
        };
        shop.push((s, p, i + 1));
    }

    shop.sort_by(|a, b| a.0.cmp(&b.0).then(b.1.cmp(&a.1)));
    for i in 0..n {
        println!("{}", shop[i].2);
    }
}


Measured memory_bytes: 2100
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

#define FOR(i,b,n) for(int i=b;i<n;i++)
#define RFOR(i,b,n) for(int i=n-1;i>=b;i--)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define NCLR(mat) memset(mat, -1, sizeof(mat))

using namespace std;

static const double EPS = 1e-9;
typedef long long ll;
typedef pair<int, int> paii;

int coin[18] = {0}; 
int n, res = 0;

void solve_rec(int sum, int i)
{
	if( i <= 17)
	{
		if( sum == n)
			res++;
		else if(sum < n)
		{
			solve_rec(sum+coin[i], i);
			solve_rec(sum, i+1);
		}
	}
	
	return;
}

int solve()
{
	res = 0;
	solve_rec(0, 1);
	return res;
}

void init()
{
	FOR(i, 1, 18)
	{
		coin[i] = i*i;
	}
	
	return;
}

int main()
{
	init();
	
	while(cin >> n, n)
	{
		cout << solve() << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1168
#include <stdio.h> 
int main(){
  int i,j,n,min,minj,total=0,A[100][100],f[100],a[100];
  scanf("%d",&n);
  
  for(i = 0;i < n;i++){
    for(j = 0;j < n;j++){
      scanf("%d",&A[i][j]);
    }
  }

    for(i = 0;i < n; i++){
    f[i] = 0;
    a[i] = 2000;
  }
  a[0] = 0;

  for(i = 0;i < n - 1;i++){
    min = 2000;
    for(j = 0;j < n;j++){
      if(a[j] < min && f[j] == 0){
    min = a[j];
    minj = j;
      }
    }

    f[minj] = 1;
    for(j = 0;j < n;j++){
      if(A[minj][j] != -1 && A[minj][j] < a[j] && f[j] == 0){
    a[j] = A[minj][j];
      }
    }
  }
  
  for(i = 0;i < n;i++){
    total += a[i];
  }

  printf("%d\n",total);
  return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;

int N;

const double EPS = 1e-9;

string getBits(int num){
  string ret;
  if(num == 0)return "0000";
  while(num){
    if(num % 2)ret += '1';
    else ret += '0';
    num /= 2;
  }
  while(ret.size() < 4)ret += '0';
  reverse(ret.begin(),ret.end());
  return ret;
}

string make(string str){
  string ret;
  for(int i = 0 ; i < str.size() ; i++){
    ret += getBits((isdigit(str[i])?str[i] - '0':str[i] - 'a' + 10));    
  }
  return ret;
}

double func(string str){
  double ret = 0.0;
  double val = (1 << 23);
  for(int i = 0 ; i < str.size() ; i++){
    if(str[i] == '1'){
      ret += val;
    }
    val /= 2.0;
  }
  return ret;
}

void solve(string str){
  str = make(str);
  double res = (str[0] == '1'?-1:1) * func(str.substr(1));

  char buf[20];
  sprintf(buf,"%.20lf",res);
  int len;
  for(int i = 0 ; i < 40 ; i++){
    if(buf[i] == '\0'){
      len = i;
      break;
    }
  }

  len--;
  while(buf[len--] == '0');
  len++;
  if(buf[len] == '.'){
    len += 2;
    buf[len] = '\0';
    buf[len-1] = '0';
  }
  else buf[len+1] = '\0';

  cout << buf << endl;
  //printf("%.20lf\n",res);
  
}

int main(){
  string str;
  cin >> N;
  for(int i = 0 ; i < N ; i++){
    cin >> str;
    solve(str);
  }
  return 0;
}

Measured memory_bytes: 1288
N,M = map(int, input().split())
d = ['x']*N

flg = 0
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if d[s] == 'x':
    d[s] = c
  if d[s] != c or (s==0 and c==0 and N>1):
    flg = -1

ans = 0
for j in range(N):
  N-=1
  if d[j]=='x':
    if j == 0 and N>0:
      d[j] = 1
    else:
      d[j] = 0
  ans += d[j]*(10**N)

print(flg if flg == -1 else ans)

Measured memory_bytes: 3064
"""
keyword: 二項係数

与えられた文字列sの最後の文字以降は何を置いても(26通り)良い一方で、最後の文字より前は同じ文字は置けない(25通り)
そこで最後の文字より後と前で分けて場合の数を考える


"""

import sys
sys.setrecursionlimit(10**6)

k = int(input())
s = input()

mod = 10**9+7

n = len(s)
fact = [1, 1] # あとでnの階乗を求める初期値　[0!, 1!]

# n!を求める
for i in range(2, 2*(10**6)+1):
    fact.append(fact[-1]*i % mod)

# 二項係数nCrを求める nCr = n!/r!(n-r)!
def nCr(n, r, mod=10**9+7):
    return pow(fact[n-r]*fact[r] % mod, mod-2, mod)*fact[n] % mod # modの世界では逆元はpow(x,mod-2)をかけることと同じ

ans = 0
#for i in range(k+1):
#    ans = (ans+nCr(n+k, i)*pow(25, i, mod)) % mod
#print(ans)

for i in range(k+1):
    now = pow(26, k-i, mod) * pow(25, i, mod) * nCr(i+n-1, n-1)
    ans = (ans+now) % mod
print(ans)

Measured memory_bytes: 218876
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
	int N; cin >> N;
	
	ll pos[N];
	
	F0R(i, N) {
		int cur; cin >> cur; cur--;
		pos[cur] = i;
		
	}
	
	ll ans = 0;
	
	multiset<ll> used;
	used.insert(-1); used.insert(-1); used.insert(N); used.insert(N);
	F0Rd(i, N) {
		
		used.insert(pos[i]);
		auto it = used.find(pos[i]);
		it--;
		ll s1 = *it;
		it--;
		ll s2 = *it;
		it++; it++; it++;
		ll e1 = *it;
		it++;
		ll e2 = *it; 
		ll curVal = i+1;
		ll numPos = 0;
		numPos += (e2 - e1) * (pos[i] - s1);
		numPos += (s1 - s2) * (e1 - pos[i]);
		//cout << numPos << endl;
		//cout << s1 << " " << s2 << " " << e1 << " " << e2 << endl;
		ans += curVal * numPos;
	}
	
	cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef map<ll,ll>::iterator itll;
typedef long double ld;
typedef map<ll,ll> mapll;

#define con continue
#define pb push_back
#define fi first
#define se second
#define fr front()
#define INF 1000000000000000000
#define all(vl) vl.begin(),vl.end()
#define m_p make_pair 
#define sz(a) sizeof(a)
#define forn(mp,it) for(it = mp.begin();it!=mp.end();it++)
#define FOR(i,a,n) for(int i=a;i<n;i++) 
#define FORE(i,a,n) FOR(i,a,n+1)
#define Endl endl
#define eNdl endl
#define enDl endl
#define endL endl

int main()
{
	ll a;
	cin>>a;
	ll yu = a%500;
	ll ans = a/500*1000;
	ll plus = yu/5*5;
	cout<<ans+plus<<endl;
	return 0;
} 


Measured memory_bytes: 3568
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>

using namespace std;

typedef long long ll;

int main() {
  int n;
  cin >> n;

  ll heights[n];
  for (int i = 0; i < n; i++) {
    cin >> heights[i];
  }

  ll sum = 0;
  ll crt = heights[0];
  for (int i = 1; i < n; i++) {
    if (heights[i] < crt) {
      sum += crt - heights[i];
    } else {
      crt = heights[i];
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 4724
#include<cstdio>
using namespace std;

int main(){
  int r,c,q,a[50000],b[50000],o[50000];
  int nr,nc;
  bool row[50000],col[50000];
  long long int ans;

  while(1){
    scanf("%d %d %d",&r,&c,&q);
    if(!r && !c && !q)break;

    for(int i=0;i<r;i++)row[i] = false;
    for(int i=0;i<c;i++)col[i] = false;

    ans = nr = nc = 0;
    for(int i=0;i<q;i++)scanf("%d %d %d",&a[i],&b[i],&o[i]);

    for(int i=q-1;i>=0;i--){
      if(a[i]){
	if(!col[b[i]]){
	  if(o[i])ans += r-nr;
	  col[b[i]] = true;
	  nc++;
	}
      }else{
	if(!row[b[i]]){
	  if(o[i])ans += c-nc;
	  row[b[i]] = true;
	  nr++;
	}
      }
    }
 
    printf("%lld\n",ans);
  }
}

Measured memory_bytes: 1452
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define int ll
typedef vector<int> vi;
typedef pair<int,int> pii;

signed main(void) {
  int i,j;
  int n;
  cin>>n;
  vector< vector<pii> > v(n+1);
  rep(i,n-1){
    int a,b,c;
    cin>>a>>b>>c;
    v[a].push_back(pii(b,c));
    v[b].push_back(pii(a,c));
  }
  int q,k;
  cin>>q>>k;
  vi d(n+1,-1);
  queue<int> que; 
  que.push(k);
  d[k]=0;
  while(que.size()){
    int now=que.front();
    que.pop();
    rep(i,v[now].size()){
      int next=v[now][i].first;
      int cost=v[now][i].second;
      if(d[next]<0){
	d[next]=d[now]+cost;
	que.push(next);
      }
    }
  }
  rep(i,q){
    int x,y;
    cin>>x>>y;
    cout<<d[x]+d[y]<<endl;
  }
}



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

int main(){
	while(1){
		int t;
		cin >> t;
		if(t==0) break;
		
		int n;
		cin >> n;
		int sum=0;
		for(int i=0; i<n; i++){
			int s,f;
			cin >> s >> f;
			sum += f-s;
		}
		if(sum >= t){
			cout << "OK" << endl;
		}else{
			cout << t-sum << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3112
#include<cstdio>
#include<map>
#include<functional>
using namespace std;
const int MAX = 200000 + 10;

int pa[MAX];
int pb[MAX];
int find(int *p, int x) { return x == p[x] ? x : p[x] = find(p, p[x]); }
map<pair<int,int>, int> mp;

int main() {
    int n, m, k;
    scanf("%d %d %d", &n, &m, &k);
    for(int i = 1 ; i <= n ; i++) pa[i] = pb[i] = i;

    while(m--) {
        int x, y;
        scanf("%d %d", &x, &y);
        if(find(pa, x) != find(pa, y)) {
            pa[find(pa, x)] = find(pa, y);
        }
    }

    while(k--) {
        int x, y;
        scanf("%d %d", &x, &y);
        if(find(pb, x) != find(pb, y)) {
            pb[find(pb, x)] = find(pb, y);
        }
    }

    for(int i = 1 ; i <= n ; i++) {
        mp[make_pair(find(pa, i), find(pb, i))]++;
    }

    for(int i = 1 ; i <= n ; i++) {
        printf("%d ", mp[make_pair(find(pa, i), find(pb, i))]);
    }

    return 0;
}

Measured memory_bytes: 13568
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
string s;
using MIte = multimap<int, int>::iterator;




int main() {
	long N, K;
	cin >> N >> K;

	if (K == 1) {
		cout << "0" << endl;
	}
	else {
		cout << N - K << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int V,E,num_visit;
int POW[9],to_visit[8];
int min_dist[205][205];
int dp[512][8];

int main(){

	POW[0] = 1;
	for(int i = 1; i <= 8; i++){

		POW[i] = POW[i-1]*2;
	}

	scanf("%d %d %d",&V,&E,&num_visit);

	for(int i = 0; i < num_visit; i++){

		scanf("%d",&to_visit[i]);
		to_visit[i]--;
	}

	for(int i = 0; i < V; i++){
		for(int k = 0; k < V; k++){
			if(k == i){
				min_dist[i][k] = 0;
			}else{
				min_dist[i][k] = BIG_NUM;
			}
		}
	}

	int from,to,cost;

	for(int loop = 0; loop < E; loop++){

		scanf("%d %d %d",&from,&to,&cost);
		from--;
		to--;

		min_dist[from][to] = cost;
		min_dist[to][from] = cost;
	}

	//ワーシャルフロイド
	for(int mid = 0; mid < V; mid++){
		for(int start = 0; start < V; start++){
			if(min_dist[start][mid] == BIG_NUM)continue;
			for(int goal = 0; goal < V; goal++){
				if(min_dist[mid][goal] == BIG_NUM)continue;

				min_dist[start][goal] = min(min_dist[start][goal],min_dist[start][mid]+min_dist[mid][goal]);
			}
		}
	}

	//dp[訪問状態][最後に訪れた町] = 最小コスト
	for(int i = 0; i < num_visit; i++){
		for(int state = 0; state < POW[num_visit]; state++){
			dp[state][i] = BIG_NUM;
		}
		dp[POW[i]][i] = 0; //出発点
	}

	//TSP
	int next_cost,next_state;

	for(int state = 1; state < POW[num_visit]-1; state++){
		for(int town = 0; town < num_visit; town++){
			if(dp[state][town] == BIG_NUM)continue;

			for(int loop = 0; loop < num_visit; loop++){
				if(state & (1 << loop))continue; //訪問済

				next_state = state+POW[loop];
				next_cost = dp[state][town]+min_dist[to_visit[town]][to_visit[loop]];

				dp[next_state][loop] = min(dp[next_state][loop],next_cost);
			}
		}
	}

	int ans = BIG_NUM;

	for(int final_town = 0; final_town < num_visit; final_town++){
		ans = min(ans,dp[POW[num_visit]-1][final_town]);
	}

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

	return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
int num;

int main(void) {
    cin >> num;
    int array[num] = {};
    array[0] = 1;
    array[1] = 1;
    for (int i= 2; i <= num; i++) array[i] = array[i - 1] + array[i - 2];
    cout << array[num] << endl;
}




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

using namespace std;

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

    int x, k;
    cin >> x >> k;
    if(500*x >= k){
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(){

  int N, c = 0, ans = 0;

  cin >> N;

  for(int j = 1; j <= N; j+=2){
    c = 0;
    for(int i = 1; i <= j; i++){
      if(j % i == 0) c++;
    }
    if(c == 8) ans++;

  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	unsigned int a, b;
	cin >> a >> b;
	
	unsigned int sum = 0;
	unsigned int result = 0;
	for (unsigned int i = 1; i <= 999; ++i) {
		sum += i;
		if (result) {
			if (sum - b == result) {
				break;
			} else {
				result = 0;
			}
		}
		
		if (a < sum) {
			result = sum - a;
		}
	}
	
	cout << result << endl;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : GURUTEJA *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second

void debug(){
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif 

}

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


     if(n==0){
          cout<<1<<endl;
     }else{
     	cout<<0<<endl;
     }





    return 0;
  }

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    set<char> A;
    rep(i, S.size()){
        A.insert(S[i]);
    }
    if(A.size() == S.size()) cout << "yes";
    else cout << "no";
    cout << endl;
    return 0;
}




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


int main(){
	long long a,b,cnt=0;
	cin >> a >> b;
	if(a<=b) cnt=1;
	for(long long i=1;;i++){
		a*=2;
		if(a>b){
			cout << cnt << endl;
			return 0;
		}
		cnt++;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int k,s;
    cin>>k>>s;
    int count=0;
    for (int i=0;i<=k;i++) {
        for (int j=0;j<=k;j++) {
            int tmp=s-i-j;
            if (tmp<=k&&tmp>=0) {
                count++;
            }
        }
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
N, A, B = list(map(int, input().split()))

# b = [None] * N
# b[A-1] = 'A'
# b[B-1] = 'B'

ans = ''
while True:
    if A + 1 == B:
        A -= 1
        if A == 0:
            ans = 'Borys'
            break
    else:
        A += 1

    if B - 1 == A:
        B += 1
        if B == N+1:
            ans = 'Alice'
            break
    else:
        B -= 1

print(ans)

Measured memory_bytes: 3060
#include <iostream>
using namespace std;
int main() {

int D,T,S;
cin>>D>>T>>S;
int hour=D/S;
if(D%S!=0)hour++;
if(hour<=T){
  cout<<"Yes"<< endl;
}
else{
  cout<<"No"<< endl;
}
 return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
int main(){     
        int n;
        cin >> n;
        vector<int> a(n);
        int s = 0;
        for(int i=0;i<n;i++){
                cin >> a[i];
                s += a[i];
        }
        int ans = 0;
        int mindiff = 100000000;
        for(int i = 0;i<n;i++){
                if (abs(s-n*a[i]) < mindiff){
                    mindiff = abs(s-n*a[i]);
                    ans = i;
                }
        }
        cout << ans << endl;
}




Measured memory_bytes: 3620
n,W = map(int, input().split())
wv = [list(map(int, input().split())) for i in range(n)]
dp = [[-(10 ** 18)] * (W+1) for i in range(n+1)]
dp[0][0] = 0
for i,(w,v) in enumerate(wv):
  for j in range(W-w+1):
    dp[i+1][j+w] = max(dp[i+1][j+w],dp[i][j]+v)
    dp[i+1][j] = max(dp[i+1][j],dp[i][j])
  for j in range(W-w+1,W):
    dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print(max(dp[n]))

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

using namespace std;

int main()
{
  	int n,m,a;
  	cin>>n>>m;
  	vector<int>v;
  	for(int i=0;i<m;i++)
    {
      cin>>a;
      v.push_back(a);
    }
  	sort(v.begin(),v.end());
  	int ans=0;
  	vector<int>v1;
  	for(int i=1;i<m;i++)
    {
      ans+=v[i]-v[i-1];
      v1.push_back(v[i]-v[i-1]);
    }
  	sort(v1.rbegin(),v1.rend());
  	int r=min(n-1,m-1);
  	for(int i=0;i<r;i++)
    {
      ans-=v1[i];
    }
  cout<<ans<<endl;
  return 0;
}


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

typedef long long int ll;
const ll MOD = 1000000007;

int bit[300010][61];

void binary(ll num, ll i){
    // ll ans = 0;
    for (ll j = 0; num>0 ; j++)
    {
        // ans = ans+(bina%2)*pow(10,i);
        bit[i][j] = num % 2;
        num = num/2;
    }
    // return ans;
}

ll bitmod(ll i){
    if(i==0){
        return 1;
    }
    ll a=1;
    for(ll j=0; j<i; j++){
        a = (a*2) % MOD;
    }
    return a;
}

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

    vector<ll> A(N);

    for(ll i=0; i<N; i++){
        cin >> A[i];
    }
    for(ll i=0; i<N; i++){
        for(ll j=0; j<61; j++){
            bit[i][j] = 0;
        }
    }
    for(ll i=0; i<N; i++){
        for(ll j=0; j<61; j++){
            binary(A[i], i);
        }
    }

    ll C[61];
    for(ll i=0; i<61; i++){
        C[i] = 0;
    }

    for(ll i=0; i<N; i++){
        for(ll j=0; j<61; j++){
            if(bit[i][j] == 1){
                C[j]++;
            }
        }
    }
    ll ans=0;
    for(ll i=0; i<61; i++){
        ans += ((((C[i]) * ((N-C[i])) %MOD) * bitmod(i))) % MOD;
        // cout << i << ":" << C[i] << ":" << bitmod(i) << endl;
        // cout << ans << endl;
        ans = ans % MOD;
    }
    cout << ans % MOD << endl;
}


Measured memory_bytes: 74112
import bisect as bi

N=int(input())
A=list(map(int,input().split()))
s=sum(A)

B=[0]
for Ai in A:
    B.append(B[-1]+Ai)
# print(B) #DB

l=bi.bisect_left(B,s/2);r=bi.bisect_right(B,s/2)
# print(l,r) #DB
ans=-1
if l<r:
    ans=0
else:
    B1=B[l-1];B2=B[l]
    d1=abs((s-B1)-B1);d2=abs((s-B2)-B2)
    ans=min(d1,d2)

print(ans)

Measured memory_bytes: 100172
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'


int lcm(int a,int b){
	int x = a/ __gcd(a,b) *b;
	return x;
}
	


int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
     // int t;
     // cin >> t;

     // while(t--){
	 	
     string s;
     cin >> s;
     int n = s.length();
     int x = 0;
     fo(i,0,n){
     	int a = s[i]-'0';
     	x += a;
     }
     if(x%3 ==0)cout << "Yes" << endl;
     else cout << "No" << endl;


     // }







return 0;
}




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


bool fun(int a,int b,int c)
{
    if(a+b>c && b+c>a && a+c>b)return true;
    return false;
}
 
 bool fun1(int a,int b,int c)
{
    if(a!=b && b!=c)return true;
    return false;
}
 
int main() {
    int n; cin>>n;
    vector<int> arr(n,0);
    for(int i=0;i<n;i++)cin>>arr[i];
    sort(arr.begin(),arr.end());
    
    
    int ans=0;
    for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
    for(int k=j+1;k<n;k++)
    if(fun1(arr[i],arr[j],arr[k])&&fun(arr[i],arr[j],arr[k])){ans++;}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < n; i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define REPEACH(i, k) for (auto &i : k)
#define all(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

signed main()
{
    int n;
    cin >> n;
    vector<int> h(n);
    vector<int> dp(n);
    REP(i,n){
        cin >> h[i];
        if(i!=0){
            if(i==1){
                dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
            }
            else{
                dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),dp[i-2]+abs(h[i]-h[i-2]));
            }
        }
    }
    cout << dp[n-1] << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  if(m > n){
    cout << "No" << endl;
    return 0;
  }
  char a[n][n], b[m][m];
  for(int i = 0; i < n; i++)
    for(int j = 0; j < n; j++)
      cin >> a[i][j];
  for(int i = 0; i < m; i++)
    for(int j = 0; j < m; j++)
      cin >> b[i][j];
  for(int i = 0; i < n-m+1; i++){
    for(int j = 0; j < n-m+1; j++){
      int c = 0;
      for(int k = 0; k < m; k++)
        for(int l = 0; l < m; l++)
          if(a[k+i][l+j] == b[k][l]) c++;
      if(c == m*m){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int P = 998244353, N = 1000010;

int cnt[N];
int inv[N];

void sub(int&x,int y) {
  if ((x -= y) < 0)
    x += P;
}

void add(int&x, int y) {
  if ((x += y) >= P)
    x -= P;
}

int norm(int x) { return x >= P ? x - P :x; }

int mpow(int x, int k, int p = P) {
  int ret = 1;
  while (k) {
    if (k & 1)
      ret = ret * (ll)x % p;
    x = x * (ll)x % p;
    k >>= 1;
  }
  return ret;
}

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif

  int n, m = 0;
  scanf("%d", &n);
  while (n--) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
    m = max(x, m);
  }
  inv[1] = 1;
  for (int i = 2; i <= m; ++i)
    inv[i] = -(P / i) * (ll)inv[P % i] % P + P;
  for (int i = 1; i <= m; ++i)
    for (int j = i + i; j <= m; j += i)
      sub(inv[j], inv[i]);
  int ans = 0;
  for (int i = 1; i <= m; ++i) {
    int sum = 0;
    for (int j = i; j <= m; j += i)
      add(sum, cnt[j] * (ll)j % P);
    add(ans, sum * (ll)sum % P * inv[i] % P);
  }
  for (int i = 1; i <= m; ++i)
    sub(ans, cnt[i] * (ll)i % P);
  ans = ans * (ll)mpow(2, P - 2) % P;
  printf("%d\n", ans);

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 8064
// user:halahen
#include<bits/stdc++.h>
using namespace std;
const int maxn=200010;
int i,j,k;
int read(){
	int tot=0,fh=1;
	char c=getchar();
	while ((c<'0')||(c>'9')){ if(c=='-') fh=-1; c=getchar(); }
	while ((c>='0')&&(c<='9')){ tot=tot*10+c-'0'; c=getchar(); }
	return tot*fh;
}
int n;
char c=' ';
int a[maxn];
int b[maxn];
int ans;
int main(){
	n=read();
	while ((c!='.')&&(c!='#')) c=getchar();
	for (i=1;i<=n;i++){
		if (c=='.') a[i]=0;
		if (c=='#') a[i]=1;
		b[i]=b[i-1]+a[i];
		c=getchar();
	}
	ans=1e9;
	for (i=1;i<=n+1;i++){
		ans=min(ans,b[i-1]+(n-i+1-(b[n]-b[i-1])));
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1792
from collections import OrderedDict

cards = OrderedDict({
    "S": set(list(range(1,14))),
    "H": set(list(range(1,14))),
    "C": set(list(range(1,14))),
    "D": set(list(range(1,14)))})

n = int(input())
for _ in range(n):
    mark, num = input().strip().split()
    cards[mark].remove(int(num))

for mark,nums in cards.items():
    for num in nums:
        print(mark,num)



Measured memory_bytes: 5996
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
const int mod=998244353;
inline int pl(int a,int b){return (a+=b)>=mod?a-mod:a;}
int kpow(int a,int b)
{
	int s=1;
	for(;b;b>>=1,a=1ll*a*a%mod)
		if(b&1)s=1ll*s*a%mod;
	return s;
}
void fwt(int f[],int opt,int lim)
{
	int x,y;
	for(int len=1;len<lim;len<<=1)
		for(int j=0;j<lim;j+=len<<1)
			for(int k=0;k<len;++k)
			{
				x=f[j+k],y=f[j+k+len];
				f[j+k]=pl(x,y);
				f[j+k+len]=pl(x,mod-y);
			}
	if(opt==-1)
	{
		int inv=kpow(lim,mod-2);
		for(int i=0;i<lim;++i)f[i]=1ll*f[i]*inv%mod;
	}
}
int n,ans,lim;
int po[100010],s[131072];
struct graph
{
	int m;
	vector<int>E[100010];
	int sg[100010];
	int st[100010],tp,a[131072];
	void init()
	{
		scanf("%d",&m);
		for(int i=1,x,y;i<=m;++i)
		{
			scanf("%d %d",&x,&y);
			if(x>y)swap(x,y);
			E[x].emplace_back(y);
		}
		for(int i=n;i;--i)
		{
			tp=0;
			for(auto u:E[i])st[++tp]=sg[u];
			sort(st+1,st+1+tp);
			int cur=-1;
			for(int j=1;j<=tp;++j)
			{
				if(st[j]==cur||st[j]==cur+1)cur=st[j];
				else break;
			}
			sg[i]=cur+1;
			a[sg[i]]=(a[sg[i]]+po[i])%mod;
		}
		fwt(a,1,lim);
	}
}g1,g2,g3;
int main()
{
	po[0]=1;
	int w=1000000000000000000%mod;
	for(int i=1;i<=100000;++i)po[i]=1ll*po[i-1]*w%mod;
	scanf("%d",&n);
	lim=1;
	while(lim<n)lim<<=1;
	g1.init();
	g2.init();
	g3.init();
	for(int i=0;i<lim;++i)s[i]=1ll*g1.a[i]*g2.a[i]%mod*g3.a[i]%mod;
	fwt(s,-1,lim);
	printf("%d",s[0]);
	return 0;
}


Measured memory_bytes: 17280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

ll a[55], b[55], c[55], d[55];

int main(){
    int n, m, q;
    cin >> n >> m >> q;
    rep(i, q) cin >> a[i] >> b[i] >> c[i] >> d[i];

    queue<vector<int>> que;
    vector<vector<int>> A;
    rep(i, m) que.push({i + 1});
    while(!que.empty()){
        vector<int> now = que.front();
        que.pop();
        int len = now.size();
        if (len == n) A.push_back(now);
        else {
            int last = now[len - 1];
            for (int add = last; add <= m; add++){
                now.push_back(add);
                que.push(now);
                now.pop_back();
            }
        }
    }
    ll ans = 0;
    rep(i, A.size()){
        vector<int> tmp = A[i];
        // rep(j, n) cout << tmp[j] << " ";
        // cout << endl;

        ll cnt = 0;
        rep(j, q){
            if (tmp[b[j] - 1] - tmp[a[j] - 1] == c[j]) cnt += d[j];
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 12952
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	amat := nextIntMat(3, 3)
	n := nextInt()
	blist := make([]int, n)

	for i := 0; i < n; i++ {
		blist[i] = nextInt()

		// 着色
		for j := 0; j < 3; j++ {
			for k := 0; k < 3; k++ {
				if amat[j][k] == blist[i] {
					amat[j][k] = 0
				}
			}
		}
	}

	// 横確認
	for j := 0; j < 3; j++ {
		if amat[j][0] == 0 && amat[j][1] == 0 && amat[j][2] == 0 {
			fmt.Println("Yes")
			return
		}
	}

	// 縦確認
	for j := 0; j < 3; j++ {
		if amat[0][j] == 0 && amat[1][j] == 0 && amat[2][j] == 0 {
			fmt.Println("Yes")
			return
		}
	}

	// 右ななめ確認
	if amat[0][0] == 0 && amat[1][1] == 0 && amat[2][2] == 0 {
		fmt.Println("Yes")
		return
	}
	// 左ななめ確認
	if amat[0][2] == 0 && amat[1][1] == 0 && amat[2][0] == 0 {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")

}

// ---- readfunc
func nextIntMat(a int, b int) [][]int {
	mat := make([][]int, a)
	for i := 0; i < a; i++ {
		mat[i] = make([]int, b)
		for j := 0; j < b; j++ {
			mat[i][j] = nextInt()
		}
	}
	return mat
}
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  long double t, x;
  cin >> t >> x;
  cout << t/x << endl;
}

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

/**
 ____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|

**/

using namespace std;

typedef long long ll;

const int N_MAX = 102;

int n;

int v[N_MAX];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++)
        cin >> v[i];
    int ans = 0;
    for(int a = 1; a <= n; a++)
        for(int b = a + 1; b <= n; b++)
            for(int c = b + 1; c <= n; c++)
                ans += (v[a] + v[b] > v[c] && v[a] + v[c] > v[b] && v[b] + v[c] > v[a] && v[a] != v[b] && v[b] != v[c] && v[c] != v[a]);
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3644
results = []
while True:
    m, f, r = map(int, input().split())
    result = ""
    if m == f == r == -1:
        break
    elif m == -1 or f == -1:
        result = "F"
    else:
        if 80 <= m + f:
            result = "A"
        elif 65 <= m + f < 80:
            result = "B"
        elif 50 <= m + f < 65:
            result = "C"
        elif 30 <= m + f < 50:
            if 50 <= r:
                result = "C"
            else:
                result = "D"
        else:
            result = "F"
    results.append(result)

for result in results:
    print(result)



Measured memory_bytes: 5600