akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(void){
  int K,N;
  cin>>K>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  vector<int> dist;
  for(int i=1;i<N;i++){
    dist.push_back(A[i]-A[i-1]);
  }
  dist.push_back(A[0]+K-A[N-1]);
  sort(dist.begin(),dist.end());
  cout<<K-dist[dist.size()-1]<<endl;
  return 0;
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
main(){
	int a,flag=0;
  	cin>>a;
  	for(int i=1;i<10;i++){
		for(int j=1;j<10;j++){
        	if(a==i*j){
              flag=1;
              goto ans;
            }
        }
    }
  	ans:
  	if(flag)cout<<"Yes\n";
    else cout<<"No\n";
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 10000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

int main(){
  bool flag=true,hantei=false;;
  string S,T;
  cin>>S>>T;

  for(int i=(int)S.size()-1;i>=(int)T.size()-1;i--,flag=true){
    for(int j=(int)T.size()-1;j>=0;j--){
      if(S[i-j]!=T[(int)T.size()-1-j] && S[i-j]!='?'){
        //cout<<S[i-j]<<endl;
        //cout<<"Unko"<<endl;
        flag=false;
        break;
      }
      //cout<<S[i-j]<<" "<<"unko"<<endl; 
    }
    if(flag){
      for(int j=(int)T.size()-1;j>=0;j--){
        S[i-j]=T[(int)T.size()-1-j];
        hantei=true;
      }
      
    }
    if(hantei) break;
  }

  if(hantei){
    for(int i=0;i<(int)S.size();i++){
      if(S[i]=='?') cout<<"a";
      else cout<<S[i];
    }
    cout<<endl;
  }else cout<<"UNRESTORABLE"<<endl;

  
}


Measured memory_bytes: 504
import sys

# sys.stdin = open('d1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_int():
    return int(input())


def read_str_list():
    return input().split()


def read_str():
    return input()


def solve():
    n = read_int()
    p = read_int_list()
    res = 0
    for i in range(n):
        if p[i] == i + 1:
            res += 1
            if i + 1 < n:
                p[i + 1] = -1
    return res


def main():
    res = solve()
    print(res)


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;

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

ll gcd(ll a, ll b){return b ? gcd(b, a % b) : a;}

int main(){

    ll X;
    
    cin >> X;

    cout << (X == 7 || X == 5 || X == 3 ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,m = readline() |> split |> parseMap
	s = readline() |> chomp
	t = readline() |> chomp
	x = lcm(n,m)
	y = div(x,n)
	z = div(x,m)
	l = 0
	r = 0
	f = 0
	while l<n&&r<m
		if l*y+1<r*z+1
			l+=1
		elseif l*y+1>r*z+1
			r+=1
		else
			if s[l+1]!=t[r+1]
				f = 1
				break
			end
			l += 1
			r += 1
		end
	end
	println(f==0?x:-1)
end

main()

Measured memory_bytes: 174476
#include <stdio.h>

int main()
{
  char s[11];
  scanf("%s",&s);
  int i;
  int counter;
  counter = 0;
  int max;
  max = 0;
  i = 0;
  while (s[i])
  {
    if (s[i] == 'A' || s[i] == 'G' || s[i] == 'C' || s[i] == 'T')
    {
      counter++;
      if (max < counter)
        max = counter;
    }
    else
      counter = 0;
    i++;
  }
  printf("%d\n",max);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
	EACH(x,vec) is >> x;
	return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
	REP(i,vec.size()) {
		if (i) os << " ";
		os << vec[i];
	}
	return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
	REP(i,vec.size()) {
		if (i) os << endl;
		os << vec[i];
	}
	return os;
}

struct Edge {
	int to, cap, rev;
};
vector< vector<Edge> > G;

void add_edge(int from, int to, int cap) {
	G[from].pb({to, cap, (int)G[to].size()});
	G[to].pb({from, 0, (int)G[from].size()-1});
};

vector<int> bfs(int s) {
	int N = G.size();
	vector<int> res(N, inf);
	queue<int> Q; Q.push(s); res[s] = 0;
	while ( !Q.empty() ) {
		int v = Q.front(); Q.pop();
		EACH(e, G[v]) {
			if (e.cap > 0 && res[v]+1 < res[e.to]) {
				res[e.to] = res[v]+1;
				Q.push(e.to);
			}
		}
	}
	return res;
}

int max_flow(int s, int t) {
	int N = G.size();
	int res = 0;
	while (1) {
		vector<int> dist = bfs(s);
		if (dist[t] == inf) break;
		int f = 0;
		while (1) {
			vector<bool> used(N, false);
			vector<int> prevV(N), prevE(N);
			queue<int> Q; Q.push(s); used[s] = true;
			while ( !Q.empty() ) {
				int v = Q.front(); Q.pop();
				REP(i, G[v].size()) {
					Edge& e = G[v][i];
					if (e.cap > 0 && dist[v]+1 == dist[e.to] && !used[e.to]) {
						used[e.to] = true;
						prevV[e.to] = v;
						prevE[e.to] = i;
						Q.push(e.to);
					}
				}
			}
			if (!used[t]) break;
			for (int v = t; v != s; v = prevV[v]) {
				Edge& e = G[prevV[v]][prevE[v]];
				--e.cap;
				++G[e.to][e.rev].cap;
			}
			++f;
		}
		res += f;
	}
	return res;
}

vector<bool> reach(vector< vector<int> >& g, int s) {
	int N = g.size();
	vector<bool> res(N, false); res[s] = true;
	queue<int> Q; Q.push(s);
	while ( !Q.empty() ) {
		int v = Q.front(); Q.pop();
		EACH(to, g[v]) {
			if ( !res[to] ) {
				res[to] = true;
				Q.push(to);
			}
		}
	}
	return res;
}

int main() {
	int N, M, s, t;
	while ( cin >> N >> M >> s >> t, N || M || s || t ) {
		--s, --t;
		G = vector< vector<Edge> >(N);
		vector< vector<int> > gr(N);
		REP(i, M) {
			int a, b; cin >> a >> b; --a, --b;
			gr[b].pb(a);
			add_edge(a, b, 1);
		}
		int flow = max_flow(s, t);
		vector< vector<int> > gs(N), gt(N);
		REP(i, N) EACH(e, G[i]) {
			if (e.cap > 0) {
				gs[i].pb(e.to);
				gt[e.to].pb(i);
			}
		}
		vector<bool> rs = reach(gs, s);
		vector<bool> rt = reach(gt, t);
		int ans = 0;
		REP(i, N) EACH(to, gr[i]) {
			if (rs[i] && rt[to]) {
				++ans;
			}
		}
		if (ans > 0) ++flow;
		cout << flow << " " << ans << endl;
	}
}

Measured memory_bytes: 3568
import sys
sys.setrecursionlimit(4100000)
import math
INF = 10**9
import itertools


def main():
    n = int(input())
    X = []
    Y = []
    for _ in range(n):
        x,y = map(int, input().split())
        X.append(x)
        Y.append(y)

    total = 0
    P = itertools.permutations(range(n))
    P = list(P)
    for i in range(len(list(P))):
        for j in range(n-1):
            total += math.sqrt((X[P[i][j]]-X[P[i][j+1]])**2 + (Y[P[i][j]]-Y[P[i][j+1]])**2)
    print(total/len(P))


if __name__ == '__main__':
    main()


Measured memory_bytes: 80412
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> ans(n-1,0);
    rep(i,n){
        for(int j = i+1;j < n;j++){
            int a = abs(i-j);
            int b = abs(i-x) + 1 + abs(j-y);
            int c = abs(i-y) + 1 + abs(j-x);
            int d = min(a,min(b,c));
            ans[d-1]++;
        }
    }
    rep(i,n-1)cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<ll> a(n + 1, 1);

  for (int i = 2; i < n + 1; i++) {
    int mp = i;
    while (mp < n + 1) {
      ++a[mp];
      mp += i;
    }
  }

  ll ans = 0;
  for (ll i = 1; i < n + 1; i++) {
    ans += i * a[i];
  }

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


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

public class Main {
    private static Scanner scr;
	public static void main(String args[]) throws IOException{
	    scr = new Scanner(System.in);
		while (true){
		    try{
		    	int n = Integer.parseInt(scr.nextLine());
				int[] data = new int[n];
				for(int i=0; i<n; i++){
					data[i] = Integer.parseInt(scr.nextLine());
				}
				if (n==0) break; //??\?????????
				System.out.println( SearchMax(data) );
			}catch(Exception e){
				System.err.println("Exception");
				break;
			}
        }
	}
	
	private static int SearchMax(int[] data){
		int max = Integer.MIN_VALUE;
		for(int i=0; i<data.length; i++){
			int sump=0;
			for(int j=i; j<data.length; j++){
				sump += data[j];
				if(sump>max) max=sump;
			}
		}
	    return max;
	}
}

Measured memory_bytes: 39276
import numpy as np
a, b, h, m = map(int, input().split())
m_v = 6
h_v = 0.5

time = h * 60 + m
h_pos = time * h_v
m_pos = m * m_v

rad = abs(min((min(h_pos, m_pos)+360)-max(h_pos, m_pos), max(h_pos, m_pos)- min(h_pos, m_pos)))
rad = rad / 180 * np.pi

ans = (a**2 + b**2 - 2*a*b*np.cos(rad))**0.5
print(ans)

Measured memory_bytes: 27208
#include<stdio.h>
int main(){
  int n,m,d[210][2],i,j,l,s[210],r[210],a,b;
  while(scanf("%d",&n),n){
    for(i=0;i<n;i++)scanf("%d %d",&d[i][0],&d[i][1]);
    for(i=0;i<n;i++)r[i]=i;
    scanf("%d",&m);
    for(i=n;i<m+n;i++){
      scanf("%d %d",&d[i][0],&d[i][1]);
      for(j=i;j&&d[r[j-1]][0]*2000-d[r[j-1]][1]>d[i][0]*2000-d[i][1];j--)r[j]=r[j-1];
      r[j]=i;
    }
    for(i=l=0;i<n+m;i++){
      s[i]=10000;//printf("%d %d\n",d[r[i]][0],d[r[i]][1]);
      for(j=l;j&&s[j-1]>=d[r[i]][1];j--);
      s[j]=d[r[i]][1];
      if(j==l)l++;
    }
    printf("%d\n",l);
  }
  return 0;
}

Measured memory_bytes: 600
N, M = map(int, input().split())
adj = [[] for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

used = [False] * N
used[0] = used[adj[0][0]] = True
start = [0]
goal = [adj[0][0]]

while True:
    for node in adj[start[-1]]:
        if not used[node]:
            start.append(node)
            used[node] = True
            break
    else:
        break

while True:
    for node in adj[goal[-1]]:
        if not used[node]:
            goal.append(node)
            used[node] = True
            break
    else:
        break

ans = start[::-1] + goal
print(len(ans))
print(*[elem + 1 for elem in ans])
    

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,k;

bool used[10010];

int check(string s){
	int l=0,r=n;
	while(r-l>1){

		int m=(l+r)/2;
		string next;

		for(int i=0;i<n;++i){
			if(l<=i&&i<m)
				next+=s[i];
			else
				next+="0";
		}

		printf("?%s\n",next.c_str());
		fflush(stdout);
		int res;
		scanf("%d",&res);

		if(res)
			r=m;
		else
			l=m;
	}
	return l;
}

int main(void){
	srand(time(NULL));
	scanf("%d %d",&n,&k);
	int num=0;
	while(num<k){
		string verify="";
		rep(i,n){
			if(used[i])
				verify+="0";
			else
				verify+=(rand()&1?"1":"0");
		}
		printf("?%s\n",verify.c_str());
		fflush(stdout);
		int res;
		scanf("%d",&res);

		if(res){
			used[check(verify)]=true;
			num++;
		}
	}
	string ans="";
	bool first=true;
	rep(i,n){
		if(used[i]){
			if(first)
				first=false;
			else
				ans+=" ";
			ans+=toString(i+1);
		}
	}
	printf("!%s\n",ans.c_str()); 
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1308
#include<bits/stdc++.h>
using namespace std;
int par[100000];

int root(int x){
	if(par[x] == x){
		return x;
	}else{
		return par[x] = root(par[x]);
	}
}

void unite(int x, int y){
	x = root(x);
	y = root(y);
	if(x!=y)	par[x] = y;
}

int main(){
	int n ,m; cin >> n >> m;
	for(int i=0;i<=n;i++)		par[i] = i;
	for(int i=0;i<m;i++){
		int x,y,z; cin >> x >> y >> z;
		unite(x,y);
	}
	int count = 0;
	for(int i=1;i<=n;i++)		if(par[i] == i)	count++;
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
def Projection(point, begin, end):
	tmp = (point-begin) / (end-begin)
	return tmp.real * (end-begin) + begin

a, b, c, d = map(int, input().split())
q, r = complex(a, b), complex(c, d)
n = int(input())
for _ in range(n):
	x, y = map(int, input().split())
	p = complex(x, y)
	proj = Projection(p, q, r)
	print(proj.real, proj.imag)


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }
int sub(int a, int b) { return (a -= b) < 0 ? a + mod : a; }

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  #ifdef LOCAL
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
  #endif

  int n;
  cin >> n;
  vi v(n), vv(n);
  for(int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[i] = x + y;
    vv[i] = x - y;
  }
  sort(all(v));
  sort(all(vv));
  cout << max(abs(v[n - 1] - v[0]), abs(vv[n - 1] - vv[0]));
}

Measured memory_bytes: 4780
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let patterns = ["eraser", "erase", "dreamer", "dream"];
    let s = patterns.iter().fold(
        read::<String>(),
        |s, x| s.replace(x, "")
    );
    println!("{}", if s.is_empty() { "YES" } else { "NO" });
}


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

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

	int ct = 0, cx = 0, cy = 0;
	for (int i = 0; i < n; ++i) {
		int t, x, y;
		std::cin >> t >> x >> y;
		t -= ct;

		t -= std::abs(x - cx);
		t -= std::abs(y - cy);
		
		if (t < 0 || t % 2 == 1) {
			std::cout << "No" << std::endl;
			return 0;
		}

		ct += t;
	}

	std::cout << "Yes" << std::endl;
}

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

int main(int argc, char const *argv[]) {
  int MAX=1000000;
  int MIN=-1000000;
  int k,x;
  cin>>k>>x;
  for(int i=0;i<2*k-1;i++){
    int tmp=x-k+1+i;
    if(tmp>=MIN&&tmp<=MAX)  cout<<tmp<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 	public static void main(String args[]){
     	Scanner sc=new Scanner(System.in);
      int a=sc.nextInt();
      int b=sc.nextInt();
      int c=sc.nextInt();
      for(int i=0;i<10;i++){
      
        c=a*c-b;
        System.out.println(c);
      }
    }
}

Measured memory_bytes: 22612
#include<iostream>
#include<cstdio>
using namespace std;
const int ok=2000;
int n,a,b,t,ans;
int main()
{
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		cin>>t;
		if(t<a || t>=b)
		 ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
bool dfs (int cur, int par, int target, const vector<vector<int>>& g, set<pair<int, int>>& st) {
  if (cur == target) return true;
  bool res = false;
  for (int child : g[cur]) if (child != par) {
    if (dfs (child, cur, target, g, st)) {
      res = true;
      st.insert({min(cur, child), max(cur, child)});
    }
  }
  return res;
}
long long power2 (long long x) {
  long long res = 1;
  long long c = 2;
  while (x > 0) {
    if (x & 1) res *= c;
    c *= c;
    x >>= 1;
  }
  return res;
}
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n;
  cin >> n;
  vector<vector<int>> g(n);
  vector<pair<int, int>> edges;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges.emplace_back(min(a, b), max(a, b));
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int m;
  cin >> m;
  vector<long long> path(m);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    set<pair<int, int>> st;
    dfs (u, -1, v, g, st);
    for (int j = 0; j < n - 1; j++) {
      if (st.count(edges[j])) path[i] |= (1LL << j);
    }
  }
  long long neg = 0;
  for (int mask = 0; mask < (1 << m); mask++) {
    int num = __builtin_popcount(mask);
    if (num == 0) continue;
    num--;
    long long e = 0;
    for (int i = 0; i < m; i++) {
      if ((mask & (1 << i)) == 0) continue;
      e |= path[i];
    }
    int all_w = __builtin_popcountll(e);
    //cerr << mask << " " << all_w << " " << e << endl;
    neg += power2((n - 1) - all_w) * (num % 2 == 0 ? 1 : -1);
  }
  // cerr << neg << endl;
  // cerr << n << " " << power2(n - 1) << endl;
  cout << power2(n - 1) - neg << '\n';
  return 0;
}

Measured memory_bytes: 256
from collections import deque
h,w = map(int, input().split())
s = [input() for i in range(h)]
root = [[0,1],[1,0],[0,-1],[-1,0]]
def bfs(x,y):
  v[x][y]=1
  cnt=1
  cnt1=0
  d = deque([[x,y]])
  while len(d):
    e,f = d.popleft()
    c = s[e][f]
    for a,b in root:
      x1 = e+a
      y1 = f+b
      if x1>=0 and x1<h and y1>=0 and y1 <w and v[x1][y1]==0:
        if c == '.' and s[x1][y1]=='#':
          v[x1][y1]=1
          d.append([x1,y1])
          cnt+=1
        if c == '#' and s[x1][y1]=='.':
          v[x1][y1]=1
          d.append([x1,y1])
          cnt1+=1
  return cnt*cnt1
v = [[0 for i in range(w)] for j in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if v[i][j]:
      continue
    if s[i][j]=='#':
      ans+= bfs(i,j)
print(ans)

Measured memory_bytes: 77996
#include<cstdio>
int m,n,t=0,s,k;
int main()
{
    scanf("%d%d",&m,&n);
    if(m*10000<n||m*1000>n||n%1000)
	{
        printf("-1 -1 -1");
        return 0;
    }
    for(;t<=m;t++)
    {
    	for(s=0;s<=m;s++)
    	{
    		for(k=0;k<=m,t+s+k<=m;k++)
    		{
    			if(t+s+k==m&&t*1000+s*5000+k*10000==n)
            	{
                	printf("%d %d %d",k,s,t);
                	return 0;
            	}
       		}
   		}
	}
    printf("-1 -1 -1");
}

Measured memory_bytes: 128
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n, m;
  cin >> n >> m;
  ll ans = 0;
  ans = m * 1900 + (n - m) * 100;
  rep (i, m) {
    ans *= 2;
  }

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

  return 0;
}


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

const long long int MOD = 1000000007;
const int MAX_K = 505050;

long long int fac[MAX_K], finv[MAX_K], inv[MAX_K];

void com_init() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_K; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long int com(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


ll perm(ll n, ll k)
{
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return (fac[n] * finv[n-k]) % MOD;
}

ll dp[MAX_K][2];

int main()
{
    ll n, m;
    cin >> n >> m;
    com_init();

    ll ans = 0;
    rep(i,n+1)
    {
        ll d;
        if(i & 1) d = -1;
        else d = 1;
        ll num =  ((((com(n,i) * perm(m,i)) % MOD ) * perm(m-i,n-i)) %MOD * perm(m-i,n-i)) % MOD;
        ans = (MOD + ans + num * d) % MOD;
    }

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

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

using namespace std;

//#define FILE_IO

int N;
int v[100005];

void yes() { printf("Yes\n"); exit(0); }
void no() { printf("No\n"); exit(0); }

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
        scanf("%d", &v[i]);
    sort(v + 1, v + N + 1);

    if(v[N] - v[1] > 1) no();
    if(v[N] == v[1])
    {
        if(v[1] == N - 1)   yes();
        if(v[1] * 2 <= N)   yes();
        no();
    }

    int dif = 0;
    for(int i = 1; i <= N; i++)
        if(v[i] == v[1])    dif++;

    int per = N - dif;

    if(per == 1)    no();
    if(v[N] < dif + 1)  no();

    int mx = dif + per / 2;
    if(v[N] > mx)  no();

    yes();

    return 0;
}


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

constexpr long long kInf = 1e18;

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

  long long a;
  cin >> a;
  long double b;
  cin >> b;
  long long c = b * 100 + 1e-5;
  cout << (a * c) / 100 << endl;
}

Measured memory_bytes: 3748
for _ in[0]*int(input()):
 X,Y,z=input(),input(),[]
 for y in Y:
  s=0
  for i,k in enumerate(z):
   t=X.find(y,s)+1
   if t<1:break
   if t<k:z[i]=t
   s=k
  else:
   t=X.find(y,s)+1
   if t:z+=[t]
 print(len(z))


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
int main(){
  int N,Q;
  string S;
  cin >> N >> Q >> S;
  vector<pair<int,int>> LR(110000);
  int countAC[110000] = {0};
  int cum[110000];
  
  rep(i,N){
    if(S[i-1] == 'A' && S[i] == 'C'){
      countAC[i] = 1;
    }
    //cout << countAC[i];
    cum[i] = cum[i-1] + countAC[i];
  }
  
  //cout << endl;
  
  rep(i,Q){
    int l,r;
    cin >> l >> r;
    cout << cum[r-1] - cum[l-1] << endl;
  }
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> A(H);
    pair<ll, ll> s;
    Rep (i, H) {
        cin >> A[i];
        Rep (j, W) {
            if (A[i][j] == 'S') {
                s = {i, j};
            }
        }
    }

    vec dy = {0, 1, 0, -1};
    vec dx = {1, 0, -1, 0};

    mat dist(H, vec(W, inf));
    dist[s.first][s.second] = 0;
    queue<pair<ll, ll>> q;
    q.push(s);
    while (q.size()) {
        auto v = q.front();
        ll y = v.first;
        ll x = v.second;
        q.pop();
        Rep (i, 4) {
            ll ny = y + dy[i];
            ll nx = x + dx[i];
            if (0 <= ny and ny < H and 0 <= nx and nx < W and dist[ny][nx] == inf and A[ny][nx] == '.') {
                dist[ny][nx] = dist[y][x] + 1;
                q.push({ny, nx});
            }
        }
    }

    Rep (i, H) {
        Rep (j, W) {
            if (dist[i][j] <= K) {
                dist[i][j] = K;
                q.push({i, j});
            } else {
                dist[i][j] = inf;
            }
        }
    }

    while (q.size()) {
        auto v = q.front();
        ll y = v.first;
        ll x = v.second;
        q.pop();
        Rep (i, 4) {
            ll ny = y + dy[i];
            ll nx = x + dx[i];
            if (0 <= ny and ny < H and 0 <= nx and nx < W and dist[ny][nx] == inf) {
                dist[ny][nx] = dist[y][x] + 1;
                q.push({ny, nx});
            }
        }
    }

    ll ans = inf;

    Rep (i, H) {
        chmin(ans, (dist[i][0]+K-1) / K);
        chmin(ans, (dist[i][W-1]+K-1)/K);
    }

    Rep (i, W) {
        chmin(ans, (dist[0][i]+K-1)/K);
        chmin(ans, (dist[H-1][i]+K-1)/K);
    }

    cout << ans << endl;
}

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

int N, M;
vector<vector<int>> G;
vector<int> V;
int ans;

void dfs(int v) {
  if (accumulate(V.begin(), V.end(), 0) == N - 1) {
    ans++;
    return;
  }
  V.at(v) = 1;
  for (auto g : G.at(v)) {
    if (V.at(g)) continue;
    dfs(g);
  }
  V.at(v) = 0;
}

int main() {
  cin >> N >> M;
  G.resize(N);
  V.resize(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  dfs(0);
  cout << ans << "\n";
}

Measured memory_bytes: 256
n,k,q=map(int,input().split())
l=[]
for i in range(n):
  v=[i,0]
  l.append(v)
for j in range(q):
  p=int(input())
  l[p-1][1]+=1
for m in range(n):
  if l[m][1]>q-k:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 17352
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	s = readline() |> chomp
	a,b,c = 0,0,0
	for i in 1:length(s)
		if s[i] == 'a'
			a += 1
		elseif s[i] == 'b'
			b += 1
		else
			c += 1
		end
	end
	println(max(a,b,c)-min(a,b,c)<=1?"YES":"NO")
end
main()


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

int main() {
  char ch;
  while (true) {
    scanf("%c", &ch);
    if (islower(ch)) ch = toupper(ch);
    else if (isupper(ch)) ch = tolower(ch);
    printf("%c", ch);
    if (ch == '\n') break;
  }

  return 0;
}


Measured memory_bytes: 2556
s = input()
d = {}
for letter in s:
  if letter in d:
    d[letter] += 1
  else:
    d[letter] = 1
flag = 1
for key in d:
  if d[key] % 2 != 0:
   
    flag = 0
if(flag == 1):
	print("Yes")
else:
	print("No")


Measured memory_bytes: 9040
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
ll rui[111111][30];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  string s;cin>>s;
  for(int i=0;i<n;i++){
    for(int j=0;j<26;j++)
      if(s[i]-'a' == j)rui[i+1][j] += rui[i][j]+1;
      else rui[i+1][j] += rui[i][j];
  }
  ll ans = 0;
  for(int i=0;i<n;i++){
    ll kosuu = 1;
    for(int j=0;j<26;j++){
      if(j == s[i]-'a')continue;
      kosuu *= (1+rui[n][j]-rui[i][j]);
      kosuu %=MOD;
    }
    ans += kosuu;
    ans %= MOD;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if (a > k) {
    cout << k << endl;
    return 0;
  }

  if (a + b >= k) {
    cout << a << endl;
    return 0;
  }
  
  long long tmp = a-(k-(a+b));
  cout << tmp << endl;
  return 0;
}

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

#define rep(i,l,r) for(int i=l;i<=r;++i)
const int N=2e5+5;
char s[N];int n;
deque<int>q;
bool fir;
void add()
{
	if(n==1){fir^=1;return ;}
	if(!fir)
	{
		fir=1;
		if(q.front()==1)
		{
			q.pop_front();
			++q.front();
		}
		else 
		{
			--q.front();
			q.push_front(1);
		}
	}
	else
	{
		if(fir^(q.size()%2))q.push_back(1);
		else ++q.back();
		if(q.front()==1)
		{
			q.pop_front();
		}
		else 
		{
			--q.front();
			fir=0;
		}
	}
}

int main()
{
	//freopen("1.in","r",stdin);
	int k;
	cin>>n>>k;
	scanf("%s",s+1);
	fir=s[1]=='B';
	for(int i=1;i<=n;)
	{
		int j=i+1;
		while(s[j]==s[i])++j;
		q.push_back(j-i);
		i=j;
	}
	while(q.size()<n)
	{
		if(!k)break;
		--k;
		add();
	}
	k%=2;
	if(k)add();
	bool now=fir;
	for(auto sz:q)
	{
		rep(j,1,sz)putchar(now?'B':'A');
		now^=1;
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define INF 1000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;


int main()
{
  ll N;
  cin >> N;
  unordered_map<ll, ll> odd;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i)
  {
    ll a;
    cin >> a;
    A.at(i) = a;
    if (i % 2 != 0)
    {
      odd[a] += 1;
    }
  }
  vector<ll> sort_A = A;
  sort(sort_A.begin(), sort_A.end());
  ll ans = 0;
  for (ll i = 0; i < N; ++i)
  {
    if (i % 2 == 0)
    {
      continue;
    }
    if (odd[sort_A.at(i)] == 0)
    {
      ans += 1;
    }
    else
    {
      odd[sort_A.at(i)] -= 1;
    }
  }
  cout << ans << endl;


  // for (ll i = 0; i < N; ++i)
  // {
  //   cout << A.at(i) << ' ';
  // }
  // cout << endl;
}


Measured memory_bytes: 5924
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int N;
ll A[400] = {}, sum[400] = {}, DP[400][400];
bool flag[400][400] = {};

ll Solve(int L, int R){
  if (flag[L][R]) return DP[L][R];
  flag[L][R] = 1;

  if (L == R) return 0;
  ll now = 1e16;
  for (int i = L; i < R; i++){
    now = min(now, Solve(L, i) + Solve(i + 1, R));
  }
  now += sum[R];
  if (L > 0) now -= sum[L - 1];
  return DP[L][R] = now;
}

int main(){
  cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];

  sum[0] = A[0];
  for (int i = 1; i < N; i++){
    sum[i] = A[i] + sum[i - 1];
  }
  cout << Solve(0, N - 1) << endl;
  
  return 0;
}



Measured memory_bytes: 1664
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=1e5+9;
const int mod=10000;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,m,a,sum=0;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)scanf("%d",&a),sum+=a;
	if(sum>n)puts("-1");
	else printf("%d\n",n-sum);
}

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

int main(){
    int N; cin>>N;
    vector<long long>H(N);
    for (int i=0;i<N;i++)cin>>H[i];
    int count=0;
    for(int i=0;i<N-1;i++){
        if(count>=2){
            break;
        }
        if(H[i]>=H[i+1]+2){
            count+=2;
            //cout<<"hihi"<<endl;
        }
        else if(H[i]==H[i+1]+1){
            count+=1;
            //cout<<"hihihi"<<endl;
        }
        else if(H[i]<H[i+1]){
            //cout<<"hihihihi"<<endl;
            count=0;
        }

    }
    //cout<<count<<endl;
    if(count>=2)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

}

Measured memory_bytes: 1024
if __name__ == "__main__":
    n = int(input())
    l = [int(i) for i in input().split(" ")]
    is_denied = False
    for i in l:
        if i % 2 == 0 and (i % 3 != 0 and i % 5 != 0):
            is_denied = True
            break

    if is_denied == False:
        print("APPROVED")
    else:
        print("DENIED")
    

Measured memory_bytes: 3060
K = int(input())
ary = [0]*(K+1)
for i in range(min(K+1, 10)):
    ary[i] = str(i)
bi = 1
n = 0
b = int(ary[bi][-1])
for i in range(10, K+1):
    if n > 9:
        bi += 1
        b = int(ary[bi][-1])
        n = b-1
    if n > b+1:
        bi += 1
        b = int(ary[bi][-1])
        n = b-1
    if n < 0:
        n = 0
    ary[i] = ''.join([ary[bi], str(n)])
    n += 1
print(ary[-1])


Measured memory_bytes: 50396
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val s = sc.next()
    val ans =
      if (s(2) == s(3) && s(4) == s(5)) "Yes" else "No"
    println(ans)
  }
}


Measured memory_bytes: 27332
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
#define N_ 101000
#define pii pair<int,int>
priority_queue<pii>PQ;
int D[N_];
using namespace std;
void Put(int a, int d) {
	if (D[a] <= d)return;
	D[a] = d;
	PQ.push({ -d,a });
}
int main() {
	int n, i;
	scanf("%d", &n);
	for (i = 0; i < n; i++)D[i] = 1e9;
	for (i = 1; i < 10; i++) {
		Put(i%n, i);
	}
	while (!PQ.empty()) {
		pii tp = PQ.top();
		PQ.pop();
		int x = tp.second;
		if (D[x] != -tp.first)continue;
		for (i = 0; i < 10; i++) {
			Put((x * 10 + i) % n, D[x] + i);
		}
	}
	printf("%d\n", D[0]);
}

Measured memory_bytes: 2804
#include <iostream>
#include <string>
#include <algorithm> 
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#include <cmath>
#include <limits>
#define ll long long
using namespace std;
int main(){
    ll N,P,h;
    cin >> N >> P;
    ll a=P;
    ll count=0,ans=-1,answer=1;
    for(ll i=2;i<1000005;i++){
        while(1){
            if(P%i==0){
                P = P / i;
                count++;
                if(count>=N){
                answer = i * answer;
                count=0;
                }
            }else{
                break;
            }
        }
        count=0;
    }
    if(N==1){
        cout << a << endl;
    }else if(a==1){
        cout << 1 << endl;
    }else{
        cout << answer << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
	string S;
	cin >> S;
	string t[] = {"dream", "dreamer", "erase", "eraser"};

	while(S.size() > 0) {
		bool f = false;
		for(int k = 0; k < 4; ++k) {
			if(S.size() >= t[k].size()
					&& S.substr(S.size() - t[k].size(), t[k].size()) == t[k]) {
				S = S.substr(0, S.size() - t[k].size());
				f = true;
			}
		}

		if(!f) {
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 512
def main():
    n, m = [int(_) for _ in raw_input().split()]
    g = [[] for _ in xrange(n)]
    for i in xrange(m):
        a, b = [int(_) - 1 for _ in raw_input().split()]
        g[a].append(b)
        g[b].append(a)

    for i in xrange(n):
        while g[i]:
            j = g[i].pop()
            g[j].remove(i)
            while g[j]:
                k = g[j].pop()
                g[k].remove(j)
                j = k
                if i == j:
                    break
            else:
                return "NO"

    return "YES"

if __name__ == '__main__':
    print(main())


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

ll N, W;
ll w[100], v[100];
ll dp[101][101][301];
ll ans = 0;

int main() {
    cin >> N >> W;
    rep(i,N) cin >> w[i] >> v[i];
    for (int i = 1; i <= N; i++) {
        ll ww = W-i*w[0];
        if (ww < 0) continue;
        memset(dp, -1, sizeof(dp));
        dp[0][0][0] = 0;
        rep(j,N) {
            ll tw = w[j]-w[0];
            dp[j+1][0][0] = 0;
            for (int k = 1; k <= i; k++) {
                for (int l = 0; l <= min(ww,3LL*i); l++) {
                    dp[j+1][k][l] = dp[j][k][l];
                    if (l >= tw && dp[j][k-1][l-tw] >= 0) dp[j+1][k][l] = max(dp[j+1][k][l], v[j]+dp[j][k-1][l-tw]);
                }
            }
        }
        for (int l = 0; l <= min(ww,3LL*i); l++) ans = max(ans, dp[N][i][l]);
    }
    cout << ans << endl;
}
































Measured memory_bytes: 24192
# coding: utf-8
x={}
n,k=map(int,input().split())
for i in range(n):
    a,b=map(int,input().split())
    if a in x:
        x[a]+=b
    else:
        x[a]=b
x=sorted(x.items(),key=lambda x:x[0])
a=0
for i in x:
    a+=i[1]
    if(a>=k):
        print(i[0])
        break;

Measured memory_bytes: 15076
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	vi P(N);
	for (auto &e : P)cin >> e;
	int a = 0;
	int b = 0;
	int c = 0;
	for (auto p : P){
		if (p <= A){
			a++;
		}
		else if (p <= B){
			b++;
		}
		else{
			c++;
		}
	}
	cout << min(a, min(b, c)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
#include<map>
#include<iomanip>
typedef long long int ll;
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	
  	a += b;
  	if(a>=24){
		a-=24;
    }
  	cout << a << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define mod 1000000007
#define pb push_back
#define inf 1000000000000000000
#define ff first
#define ss second
void checkpoint1()
{
	/******think more code less******/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
bool comp(pair< ll,ll > &a,pair< ll,ll > &b)
{
	if(a.ff!=b.ff)
		return a.ff<b.ff;
	else
	{
		if(a.ss>b.ss)
			return b.ss<a.ss;
		else if(a.ss<b.ss)
			return a.ss<b.ss;
	}
	return a.ff>b.ff;
}
int main()
{
	checkpoint1();
	ll n;
	cin>>n;
	string s;
	cin>>s;
	ll i=0,j=n-1;
	ll ans=0;
	while(i<j)
	{
		if(s[j]=='R'&&s[i]=='W')
		{
			ans++;
			i++;
			j--;
		}
		else if(s[i]=='R')
			i++;
		else if(s[j]=='W')
			j--;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3712
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define elif else if
#define cout_db cout << fixed

#define MOD 1000000007
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

int n, m, a[1230], b[1230];
bool check[50];

void bfs(int erase, int pos){
	if(check[pos-1]) return;
	check[pos-1] = 1;

	for (int i = 0; i < m; i++) {
		if(i == erase) continue;
		if(a[i] == pos){
			bfs(erase, b[i]);
		} else if(b[i] == pos){
			bfs(erase, a[i]);
		}
	}
}

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

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
	}

	int ans = 0;
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < 50; j++) {
			check[j] = 0;
		}
		bfs(i, 1);
		for (int j = 0; j < n; j++) {
			if(!check[j]){
				ans++;
				break;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

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

    ll n;
    cin >> n;

    ll ans;
    ans = n*(n+1);
    ans /= 2;
    ans -= n;

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


Measured memory_bytes: 256
import sys
from collections import deque
input = sys.stdin.readline


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.par = [-1]*(n+1)#それぞれの要素がどの要素の子であるか

    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]#それぞれの要素の根を再帰的に求める

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.par[x] > self.par[y]:
            x, y = y, x
        
        self.par[x] += self.par[y]
        self.par[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)#x,yが同じ集合に属するかどうか
    
    def size(self, x):
        return -self.par[self.find(x)]
    
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if root == self.find(i)]        


def main():
    n = int(input())
    town = [list(map(int, input().split())) + [i] for i in range(n)]

    town.sort()
    union = UnionFind(n)
    already = deque([])

    for x, y, i in town:
        if not already:
            already.append((y, i))
            continue
        key = already.pop()
        if key[0] > y:
            already.append(key)
            already.append((y, i))
            continue
        sub = key
        while already:
            union.union(sub[1], i)
            sub = already.pop()
            if sub[0] > y:
                break
        if not already and sub[0] < y:
            union.union(sub[1], i)
        else:
            already.append(sub)
        already.append(key)
    
    ans = [0]*n
    for i in range(n):
        ans[i] = union.size(i)
    
    print(*ans, sep="\n")





    
if __name__ == "__main__":
    main()



Measured memory_bytes: 117048
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fr(i,j,n)   for(int i=j;i<(n);++i)
#define bk(i,j,n)   for(int i=j;i>n;--i)
#define mset(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define pop pop_back
#define mod 1000000007
#define all(x) x.begin(),x.end()
#define inf 1e18
#define iosbase ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define bye return

int main()
{   
    ll l;
    string s;
    cin>>s;

    l=s.length();
    if(s[2]==s[3] && s[4]==s[5])
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    bye 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char **argv) {
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9;j ++) {
            cout << i << 'x' << j << '=' << i * j << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3072
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int a[100005];
int cnt[100005];

#define rep(i,s,t) for(int i=s;i<t;i++)
#define rrep(i,s,t) for(int i=s;i>=t;i--)

typedef long long ll;

ll mod=1000000007ll;

ll f[2010101], rf[2010101];

ll inv(ll x) {
	ll res = 1;
	ll k = mod - 2;
	ll y = x;
	while (k) {
		if (k & 1) res = (res * y) % mod;
		y = (y * y) % mod;
		k /= 2;
	}
	return res;
}
void init() {
	f[0] = 1;
	rep(i, 1, 2010101) f[i] = (f[i - 1] * i) % mod;
	rf[2010101 - 1] = inv(f[2010101 - 1]);
	rrep(i, 2010101 - 2, 0) rf[i] = (rf[i + 1] * (i + 1)) % mod;
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
	if (k < 0 || n < k) return 0;

	ll a1 = f[n]; // = n!
	ll b = rf[n - k]; // = (n-k)!
	ll c = rf[k]; // = k!

	ll bc = (b * c) % mod;

	return (a1 * bc) % mod;
}


int main(){

	init();

	int n;

	scanf("%d",&n);

	int i;

	int k1;
	int k2;

	int value;

	for(i=1;i<=n+1;i++){
		scanf(" %d",&a[i]);
		cnt[a[i]]++;
		if(cnt[a[i]]==2){
			k1=i;
			value=a[i];
		}
	}

	for(i=1;i<=n+1;i++){
		if(a[i]==value){
			k2=i;
			break;
		}
	}


	int x=k2-1;
	int y=n+1-k1;

	for(i=1;i<=n+1;i++){
		ll m=C(n+1,i);
		ll mm=C(x+y,i-1);
		ll ans;
		if(mm>m){
		ans=(mod+m-mm);
		}
		else{
		ans=m-mm;
		}
		printf("%lld\n",ans);
	}

	return 0;
}

Measured memory_bytes: 33408
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
    int H, W, D;
    cin >> H >> W >> D;
    vector< vector<int> > I(D, vector<int>(H*W/D + 1));
    vector< vector<int> > J(D, vector<int>(H*W/D + 1));
    for(int i=0; i<H; i++) {
        for(int j=0; j<W; j++) {
            int A;
            cin >> A;
            I[A%D][A/D] = i;
            J[A%D][A/D] = j;
        }
    }

    vector< vector<int> > distance(D, vector<int>(H*W/D + 1));
    for(int i=0; i<D; i++) {
        for(int j=1; j<distance[i].size(); j++) {
            distance[i][j] = distance[i][j-1] + abs(I[i][j] - I[i][j-1]) + abs(J[i][j] - J[i][j-1]);
        }
    }

    int Q;
    cin >> Q;
    for(int q=0; q<Q; q++) {
        int L, R;
        cin >> L >> R;
        cout << distance[L%D][R/D] - distance[L%D][L/D] << endl;
    }
    return 0;
}


Measured memory_bytes: 15232
module Main where

import           Data.Maybe                     ( fromJust )
import qualified Data.ByteString.Char8         as BS


bytestr2Int = fst . fromJust . BS.readInteger
getInt = bytestr2Int <$> BS.getLine
getIntLH = map bytestr2Int . BS.words <$> BS.getLine
getIntLV n = replicate n $ getInt
getInt2D n = replicate n $ getIntLH


main :: IO ()
main = do
    w <- getLine
    print $ checkWeek w

checkWeek s | s == "SUN" = 7
            | s == "SAT" = 1
            | s == "FRI" = 2
            | s == "THU" = 3
            | s == "WED" = 4
            | s == "TUE" = 5
            | s == "MON" = 6


Measured memory_bytes: 380
A, B, M = map(int, input().split())
An = list(map(int, input().split()))
Bn = list(map(int, input().split()))

res = 10**9
for i in range(M):
    x, y, c = map(int, input().split())
    x, y = x - 1, y - 1
    res = min(res, An[x] + Bn[y] - c)

a_m, b_m = min(An), min(Bn)

res = min(res, a_m + b_m)
print(res)

Measured memory_bytes: 18612
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int r,c,i,j;
	cin>>r>>c;
	char a[r][c];
	for(i=0;i<r;i++)
	for(j=0;j<c;j++)
	cin>>a[i][j];
	long long int dp[r+1][c+1];
	for(i=0;i<=r;i++)
	dp[i][0]=0;
	for(i=0;i<=c;i++)
	dp[0][i]=0;
	for(i=1;i<=r;i++)
	{
		for(j=1;j<=c;j++)
		{
			if(i==1 && j==1)
			dp[i][j]=1;
			else
			{
				if(a[i-1][j-1]=='.')
				dp[i][j]=(dp[i-1][j]%1000000007+dp[i][j-1]%1000000007)%1000000007;
				else
				dp[i][j]=0;
			}
		}
	}
	cout<<dp[r][c]%1000000007;
}

Measured memory_bytes: 9088
import scala.io.{ StdIn => in}
import scala.annotation.tailrec

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val a = Iterator.continually(in.readLine.toCharArray)
    .take(n)
    .toArray
  val b = Iterator.continually(in.readLine.toCharArray)
    .take(m)
    .toArray

  val res = for {
    i <- 0 to n-m
    j <- 0 to n-m
    } yield {
      val res0 = for {
        k <- 0 until m
        l <- 0 until m
      } yield {
        a(i+k)(j+l) == b(k)(l)
      }
      res0.forall(_ == true)
    }

  val ans = if(res.exists(_ == true)) "Yes" else "No"
  println(ans)
}

Measured memory_bytes: 35532