akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
const int N=128,inf=0x7f7f7f7f;
int n,ans,s[N];
string a,b,c;
int main()
{
	cin>>n>>a>>b>>c;
	for(int i=0;i<n;i++)
	{
		memset(s,0,sizeof(s));
		s[a[i]]++;
		s[b[i]]++;
		s[c[i]]++;
		if(s[a[i]]==2||s[b[i]]==2||s[c[i]]==2)  ans++;
		else if(s[a[i]]==1||s[b[i]]==1||s[c[i]]==1)  ans+=2;
	}
	printf("%d",ans);
	return 0; 
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
	@SuppressWarnings("resource")
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int l = scanner.nextInt();
		List<String> list = new ArrayList<>();

		for(int i=0; i<n;i++) {
			list.add(scanner.next());
		}

		Collections.sort(list);

		for(String str :list) {
			System.out.print(str);
		}

	}
}

Measured memory_bytes: 24020
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
const ll MOD = 1000000007;
const int MAX = 100000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; 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 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;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }


int main(){
    int N; cin >> N;
    vector<ll> D(N); for(int i=0;i<N;i++){cin >> D[i];}
    int M; cin >> M;
    vector<ll> T(M); for(int i=0;i<M;i++){cin >> T[i];}
    if (N<M){
        cout << "NO" << endl;
        return 0;
    }
    int cnt=0;
    int j=0;
    bool f=true;
    sort(D.begin(),D.end());
    sort(T.begin(),T.end());
    
    for(int i=0;i<N;i++){
        cerr << D[i] << " " << T[j] << endl;
        if(T[j]==D[i]){
            j++;
        }
        if(j==M) break;
    }
    if(j==M){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


Measured memory_bytes: 3328
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  cin>>a[i];
  int c=0,m=0;
  for(int i=0;i<n-1;i++)
  {
      if(a[i+1]<=a[i])
      {
          c++;
          continue;
      }
     m=max(c,m);
     c=0;
  }
  m=max(c,m);
  cout<<m<<endl;
}


Measured memory_bytes: 640
N = gets.to_i
A = gets.split(' ').map(&:to_i)

l = 0
r = 0
sum = A[0]
cnt = 0
while l < N
  while r < (N - 1) && (sum + A[r + 1]) == (sum ^ A[r + 1])
    sum += A[r + 1]
    r += 1
  end
  cnt += r - l + 1
  sum -= A[l]
  l += 1
end

puts cnt

Measured memory_bytes: 15364
#include <bits/stdc++.h>
using namespace std;
// define
#define endl "\n"
#ifdef LOCAL
#define lout cerr
#else
ostream devnull(0);
#define lout devnull
#endif
#define AMULET cin.tie(0);ios::sync_with_stdio(false);
// https://github.com/kurokoji/.cpp-Template/blob/master/template/template2.cpp
#define GET_MACRO(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep4, rep3, rep2, rep1) (__VA_ARGS__)
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, d) rep5(i, a, n, d, <)
#define rep5(i, a, n, d, o) for (auto i = decltype(n)(a), _n = (n); i o _n; i += (d))

#define rrep(...) GET_MACRO(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rrep1(a) rrep2(_, a)
#define rrep2(i, a) rrep3(i, a, 0)
#define rrep3(i, a, n) rrep4(i, a, n, -1)
#define rrep4(i, a, n, d) rep5(i, (a) - 1, n, d, >=)

#define dump(x) lout << #x << " = " << x << endl;
// alias
typedef long long ll;
typedef long long lint;
typedef pair<int,int> pii;
typedef pair<lint,lint> pll;
// func
template <class C> inline void vcin(C &c);
template <class C,class D> inline void vcin(C &c,D &d);
template <class C> inline void vcout(const C &c,const string separate="\n");
template <class T=int> inline T in();

void solve()
{
  int n = in();
  vector<int> p(n);
  vcin(p);

  vector<int> q = p;
  sort(q.begin(),q.end());

  int cnt = 0;
  rep(i, n)
  {
    if(p[i]!=q[i])
      cnt++;
  }
  cout << (cnt==0||cnt==2?"YES":"NO") << endl;
}

signed main(){
  AMULET
  solve();
  return 0;
}

template <class C>inline void vcin(C &c){for(auto &a:c){cin>>a;}}
template <class C,class D> inline void vcin(C &c,D &d){for(auto it1=c.begin(),it2=d.begin();it1!=c.end()&&it2!=d.end();it1++,it2++){cin>>*it1>>*it2;}}
template <class C> inline void vcout(const C &c,const string separate){for(auto it=c.begin();it!=c.end();it++){if(it!=c.begin())cout<<separate;cout<<*it;}}
template <class T=int> inline T in(){T x;cin>>x;return (x);}


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

int main()
{
    int n;
    char buf[30];

    fgets(buf, sizeof(buf), stdin);
    n = atoi(buf);

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


Measured memory_bytes: 1708
// Problem : C - Forbidden List
// Contest : AtCoder - AtCoder Beginner Contest 170
// URL : https://atcoder.jp/contests/abc170/tasks/abc170_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl '\n'
#define pb push_back
#define mod 1000000007
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
ll fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[100000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
            for (ll i=p*p;i<=n;i+=p)
                prime[i]=false;
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll x,n;
	cin>>x>>n;
	vector<ll> a(n);
	ll b[101];
	memset(b,0,sizeof(b));
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		b[a[i]]=1;
	}
		ll ans;
		ll diff=INT_MAX;
		int j=x;
		while(j<101&&b[j]==1)
		{
			j++;
		}
		if(j-x<diff)
		{
			diff=j-x;
			ans=j;
		}
		j=x;
		while(j>=0&&b[j]==1)
		{
			j--;
		}
		if(x-j<=diff)
		{
			diff=x-j;
			ans=j;
		}
		cout<<ans<<endl;
		
	
	
	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e6 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
#define mst(x) memset(x, 0, sizeof(x))
priority_queue <int> qua;
ll a[maxx];
vector <ll> vec;
int n, k;
ll ans;

void Init() {
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) {
		ll sum = 0;
		for(int j = i; j <= n; j++) {
			sum += a[j];
			vec.push_back(sum);
		}
	}
}

void solve() { //要让按位与最大, 则让最高位尽可能高且1尽可能多, 从高到低枚举
	for(int bit = 59; bit >= 0; bit--) {
		int cnt = 0; //当前位1的个数
		int sz = vec.size();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) cnt++;
		}
		if(cnt < k) continue; //不足k个1, 继续枚举二进制位
		vector <ll> tmp;
		tmp.clear();
		for(int i = 0; i < sz; i++) {
			ll dd = 1ll << bit;
			if(vec[i] & dd) tmp.push_back(vec[i]);
		}
		vec = tmp; //替换新的vec, 在新的vec内接着从高位到低位枚举
		ans += 1ll << bit; //累加当前位1的个数不少于k
	}
}

int main() {
	Init();
	solve();
	cout << ans << endl;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

int main() {
    long long x, m, ans;
    cin >> x;
    if (x == 5){
        cout << "YES" << endl;
        return 0;
    }
    if (x == 7){
        cout << "YES" << endl;
        return 0;
    }
    if (x == 3){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
}

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

int N,H,W;
int visited[26] = {};
char F[51][51];

bool dfs(int n,vector<vector<int>>& v){
    visited[n] = -1;
    bool ok = true;
    for(auto x:v[n]){
        if(visited[x]==0) ok = (ok & dfs(x,v));
        if(visited[x]==-1) return false;
    }
    visited[n] = 1;
    return ok;
}

int main(){
    cin >> N;
    for(int t=0;t<N;t++){
        cin >> H >> W;
        bool ok = true;
        map<char,int> mi_x,mi_y,ma_x,ma_y;
        vector<char> a;
        vector<vector<int>> v(26);
        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                cin >> F[i][j];
                if(F[i][j]!='.'){
                    if(!mi_x.count(F[i][j])){
                        mi_x[F[i][j]] = i; a.push_back(F[i][j]);
                    }else mi_x[F[i][j]] = min(mi_x[F[i][j]],i);
                    if(!ma_x.count(F[i][j])) ma_x[F[i][j]] = i;
                    else ma_x[F[i][j]] = max(ma_x[F[i][j]],i);
                    if(!mi_y.count(F[i][j])) mi_y[F[i][j]] = j;
                    else mi_y[F[i][j]] = min(mi_y[F[i][j]],j);
                    if(!ma_y.count(F[i][j])) ma_y[F[i][j]] = j;
                    else ma_y[F[i][j]] = max(ma_y[F[i][j]],j);
                }
            }
        }
        int n = v.size();
        for(auto x:a){
            for(int r=mi_x[x];r<=ma_x[x];r++){
                for(int c=mi_y[x];c<=ma_y[x];c++){
                    if(F[r][c]=='.') ok = false;
                    else if(F[r][c]!=x){
                        v[x-'A'].push_back(F[r][c]-'A');
                    }
                }
            }
        }
        for(int i=0;i<26;i++){
            for(int j=0;j<26;j++) visited[j] = 0;
            if(!dfs(i,v)) ok = false;
        }
        cout << (ok? "SAFE":"SUSPICIOUS") << endl;
    }
}


Measured memory_bytes: 3152
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath> 
#include<memory.h> 
#include<sstream>
#include<time.h>
using namespace std;
const long long BIGER=1000000000000000;
const int BIG=1000000000;
const int MOD=1000000007;
int main()
{
    string st;
    cin>>st;
	string st2="AKIHABARA";
	int j=0;
	for(int i=0;i<=st.size();i++)
	{
		if(st[i]==st2[j])
		{
			j++;
			continue;
		}
		if(st[i]!=st2[j]&&st2[j]=='A')
		{
			j++;
			i--;
			continue;
		}
		if(st[i]!=st2[j]&&st2[j]!='A')
		{
			cout<<"NO";
			return 0;
		}
	}
	cout<<"YES";
    return 0;
}

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

int main(){
  long long H,N;
  cin >> H >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  long long a=0;
  int flag=0;
  for(int i=0;i<N;i++){
    a+=A.at(i);
    if(H<=a){
      flag=1;
      break;
    }
  }
  if(flag==1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main(){
    long long N,A,B,C,D;
    cin>>N>>A>>B>>C>>D;
    if(A>B) swap(A,B);
    bool ok=false;
    REP(m,N+1){
        if(C*(N-1-m)-D*m<=B-A&&B-A<=-C*m+(N-1-m)*D) ok=true;
    }
    if(ok) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main()
{
    int a,b,c,d;

    cin >>a >>b;
    cin >>c >>d;

    if(a==c){
        cout << 0 <<endl;
    }

    else if(a!=c){
        cout <<1<<endl;
    }
}

Measured memory_bytes: 256
#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--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi a(n);
    cin >> a;
    vi ans(n);
    rep(i,31) {
        vi now(n);
        rep(j,n) now[j] = a[j]>>i&1;
        rep(k,2) {
            vi v(n);
            v[0] = k;
            rep2(j,1,n) v[j] = v[j-1]^now[j-1]^now[j];
            int l = 0,r = 0;
            rep(j,n) r ^= v[j];
            bool ok = true;
            rep(j,n) {
                r ^= v[j];
                if((l^r) != now[j]) ok = false;
                l ^= v[j];
            }
            if(!ok) continue;
            rep(j,n) if(v[j]) ans[j] |= 1<<i;
        }
    }
    rep(i,n) cout << ans[i] << (i == n-1 ? "\n" : " ");
}

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



int main() {
    int n;
    cin >> n;
    
    vector<double> a(n);
    double c = 1;
    rep(i,n) {
        cin >> a[i];
        c *= a[i];
    }
    
    double p = 0;
    rep(i,n) {
        p += c / a[i];
    }
    
    cout << fixed << setprecision(7) << c / p << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3820
#include <bits/stdc++.h>
 using namespace std;
 #define rep(i,N) for(int i=0;i<int(N);++i)
 using ll = long long;
 const int INF = 2147483647;
 const ll MOD = 1000000007;
 // const ll INF = 1000000000000000000LL;
 
 int main(){
   int n;
   cin >> n;
   vector<int> a(n);
   rep(i,n) cin >> a[i];
   int ans = 0;
   rep(i,n){
     if(i%2==0&&a[i]%2==1)
      ans++;
   }
   cout << ans << endl;
   return 0;
 }

Measured memory_bytes: 3620
function Main (input) {
    input = input.split(' ');
    var a = parseInt(input[0]);
    var b = parseInt(input[1]);

    var ans = (a > 1 ? a * (a-1) / 2: 0) + (b > 1 ? b * (b-1) / 2: 0);

    console.log(ans)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<iostream>
#include<map>
using namespace std;
 
int main()
{
  int n;
  cin >> n;
  map<int,int> ans;
  for(int i=0;i<n;i++)
    {
      int num;
      cin >> num;
      for(int j=1;j<=num/2;j++)
      if(num%j == 0)
        ans[j]++;
      ans[num]++;
    }
 
  for(map<int,int>::iterator it = ans.begin();it != ans.end();it++)
    if((*it).second >= n)
      cout << (*it).first << endl;
     
  return 0;
}

Measured memory_bytes: 1200
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int n, d;
  cin >> n >> d;
  int ans = 0;
  int t = 2 * d + 1;
  cout << (n + t - 1) / t << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String s = sc.next();
    String t = sc.next();
    
    sc.close();
    
    String temp = t.substring(0, t.length() - 1);
    String answer = s.equals(temp) ? "Yes" : "No";
    System.out.println(answer);
  }
}

Measured memory_bytes: 35676
def func(arr)
  prev = 1
  minus_count = 0

  arr.each do |n|
    if n == 0
      return 0
    end

    if n < 0
        minus_count += 1
    end
  end

  arr.each do |n|
    if Math.log10(prev) + Math.log10(n.to_i) >= 18
      if n * prev == 10 ** 18
        return 10 ** 18
      end

      return -1
    end
    
    prev = n * prev
  end

  prev
end

lines = []
2.times do
    line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

num = lines[0]

puts func(lines[1])

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


void solve(long long N, long long M, std::vector<long long> p, std::vector<std::string> S){
    vector<ll> flag(N);
    vector<ll> pena(N);
    rep(i,N){flag[i]=0;}
    rep(i,N){pena[i]=0;}
    ll ans=0;
    rep(i,M){
        if(S[i]=="AC"){
            flag[p[i]-1]=1;
        }
        else{
            if(flag[p[i]-1]==0){
            pena[p[i]-1]+=1;
            }
        }
    }
    ll penal =0;
    rep(i,N){
        if(flag[i]){
            ans++;
            penal+=pena[i];
        }
    }
    cout<<ans<<" "<<penal<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> p(M);
    std::vector<std::string> S(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&p[i]);
        std::cin >> S[i];
    }
    solve(N, M, std::move(p), std::move(S));
    return 0;
}


Measured memory_bytes: 8064
H,W,K=map(int,input().split())
Square=[0]*H
for i in range(H):
    C=input()
    Square[i]=C
ans=0
nowH=[0]*H
nowW=[0]*W
for j in range(2**H):
    for p in range(H):
        nowH[p]=j%2
        j//=2
    for k in range(2**W):
        kouho=0#この縦・横の選び方で残る黒の数
        for q in range(W):
            nowW[q]=k%2
            k//=2
        for s in range(H):
            for t in range(W):
                if nowH[s]==0 and nowW[t]==0 and Square[s][t]=="#":
                    kouho+=1
        if kouho==K:
            ans+=1
print(ans)
            

Measured memory_bytes: 9176
#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--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> p(n);
  rep(i, n){ cin>>p[i]; p[i]--; }

  vector<ll>c(n, n+1);
  rep(i, n) c[p[i]]+=n*n+i+1;

  vector<ll>a(n), b(n);;
  rep(i, n)a[i]=i+1;
  rep(i, n)b[i]=c[i]-a[i];

  rep1(i, n-1){
    if(b[i-1]<=b[i]){
      ll d = b[i]-b[i-1]+1;
      for(int j=i; j<n; j++) { a[j]+=d; b[j]-=d; }
    }
  }

  ll md=0;
  for(auto c: b)md=min<ll>(md, c);
  rep(i, n)b[i]+=(1-md);

//  cout<<endl;
  rep(i, n)cout<<a[i]<<' ';cout<<endl;
  rep(i, n)cout<<b[i]<<' ';cout<<endl;
//  rep(i, n)cout<<a[i]+b[i]<<' ';cout<<endl;

  return 0;
}

Measured memory_bytes: 1152
n= int(input())
if n == 1:
  print(1)
  exit()
ab = [list(map(int,input().split())) for _ in range(n)]
pq = {}
for i in range(n-1):
  for j in range(i+1,n):
    a1,b1 = ab[i]
    a2,b2 = ab[j]
    p = a1-a2
    q = b1-b2
    if p<0 or p==0 and q<0:
      p = -p
      q = -q
    if (p,q) in pq:
      pq[(p,q)] += 1
    else:
      pq[(p,q)] = 1
print(n-max(pq.values()))

Measured memory_bytes: 9220
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;

int main(){
	int a=0, ans=0;
	string x;
	cin >> x;
	for(int i=0; x[i]; i++){
		if(x[i]=='S'){
			a++;
		} else {
			if(a>0){
				a--;
			} else {
				ans++;
			}
		}
	}
	cout << ans*2 << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, x, y; std::cin >> n >> x >> y;
    x--; y--;
    std::vector<int> cnt(n);
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            int d = std::min(abs(i - j), abs(i - x) + abs(j - y) + 1);
            cnt[d]++;
        }
    }
    for (int i = 1; i < n; i++) std::cout << cnt[i] << std::endl;
    return 0;
}


Measured memory_bytes: 256
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

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

#define MOD 1000000007LL
#define INF (1LL<<60LL)
#define int long long
#define MAX_N (100001)
typedef long long ll;

using namespace std;





signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k; cin >> n >> k;
	vector<int> v(3);
	rep(i, 3)cin >> v[i];
	string s; cin >> s;
	rep(i, n - k) {
		if (s[i] == s[i + k]) s[i + k] = '#';
	}
	int ans = 0;
	for (auto a : s) {
		switch (a)
		{
		case's':
			ans += v[0];
			break;
		case'p':
			ans += v[1];
			break;
		case'r':
			ans += v[2];
			break;
		default:
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 512
import sys

F = sys.stdin
search_word = F.readline()
search_word = search_word.rstrip()
sentence = []
cnt = 0

for line in F:
    if line == F:
        continue
    if line == "END_OF_TEXT":
        break
    
    line = line.rstrip()
    line = line.split()
    tmp = []
    for j in line:
        j = j.lower()
        tmp.append(j)
    sentence.extend(tmp)
    
for i in sentence:
    if search_word == i:
        cnt += 1
        
print(cnt)
        


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,D;
  cin >>A>>B>>C>>D;
  int L=A+B;
  int R=C+D;
  if (L>R){  
  cout<<"Left"<<endl;
  }else if (L<R){
    cout<<"Right"<<endl;
  }else{
    cout<<"Balanced"<<endl;
  }
}

Measured memory_bytes: 256
use std::cmp::{max, min};
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let x: i32 = read();
    let y: i32 = read();

    println!(
        "{}",
        [
            min(x, y) * c * 2 + if x > y { (x - y) * a } else { (y - x) * b },
            a * x + b * y,
            max(x, y) * 2 * c
        ]
        .iter()
        .min()
        .unwrap()
    );
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin(); it!=(c).end(); it++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define pr(a) cout << (a) << endl
#define PR(a,b) cout << (a) << " " << (b) << endl
#define F first
#define S second
typedef long long ll;
typedef pair<int,int> P;
const int MAX=1000000001;
const ll MAXL=1000000000000000001LL;
const ll mod=1000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int main() {
  int n,m;
  cin >> n >> m;
  int ans=0;
  rep(i,n) {
    int cnt=0;
    rep(j,m) {
      int x;
      cin >> x;
      cnt+=(x==1);
    }
    ans=max(ans,cnt);
  }
  pr(ans);
  return 0;
}


Measured memory_bytes: 1164
(N, T), *D,  = [list(map(int, s.split())) for s in open(0)]

min_cost = 1e10
idx = 0
for i in range(len(D)):
    if T >= D[i][1] and D[i][0] < min_cost:
        idx = i
        min_cost = D[i][0]

if min_cost == 1e10:
    print("TLE")
else:
    print(min_cost)

Measured memory_bytes: 3060
import itertools
F=list(map(int, input().split()))
s = [list(map(int,input().split())) for i in range(int(F[2]))]

# print(s)
flist=list(range(1,F[1]+1))
comb=list(itertools.combinations_with_replacement(flist,F[0]))
result=[0]*len(comb)
# print(comb)

for i,a in enumerate(comb):
    for row in s:
        if a[row[1]-1]-a[row[0]-1]==row[2]:
            result[i]+=row[3]

print(max(result))
# print(comb[result.index(max(result))])



Measured memory_bytes: 25072
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <random>
#include <fstream>
#include <time.h>
// #define int long long
#define debug(x) cerr << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const ll LINF = 1e18;
const double EPS = 1e-9;

// 2整数の最大公約数を求める関数
ll gcd(ll x, ll y) {
  if(y == 0) return x;
  else return gcd(y, x % y);
}

// 2整数の最小公倍数を求める関数
ll lcm(ll x, ll y) {
  return y / gcd(x, y) * x;
}

// 3個以上の整数の最大公約数を求める関数
ll gcdary(ll a[], ll n) {
  if(n == 1) return (a[0]);
  else if(n == 2) return (gcd(a[0], a[1]));
  else return (gcd(a[0], gcdary(&a[1], n - 1)));
}

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

  ll n;
  cin>>n;
  ll a[n];
  rep(i,n) {
    cin>>a[i];
  }
  ll ans = gcdary(a, n);
  cout << ans << endl;


  return 0;
}


Measured memory_bytes: 2560
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
ab = [list(li()) for _ in range(n)]
ab.sort(reverse=True)
print(sum(ab[0]))

Measured memory_bytes: 27836
#include <algorithm>
#include <map>
#include <vector>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <string>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define IREP(it,array) for(vector<int>::iterator it=array.begin(); it!=array.end(); ++it)
#define SREP(it,array) for(vector<string>::iterator it=array.begin(); it!=array.end(); ++it)


int main()
{
  cout.setf(ios::fixed, ios::floatfield);
  cout.precision(10);

  int INF = 1000000;

  double a;
  while(cin>>a){
    cout << (135.0+76)/27 * a << endl;
  }

  return 0;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 5*(int)1e5 + 10;

int n, a[N];
int32_t main(){_

   int a, b, c;
   cin>>a>>b>>c;

   if (a == b and b == c){
      cout<<"Yes\n";
   }
   else{
      cout<<"No\n";
   }

   #warning make sure N size is correct!
   return 0;
}

Measured memory_bytes: 256
# ABC 064 C
N = int(input())
from collections import Counter
def get_color(a):
    if a<400:
        return 1
    elif a<800:
        return 2
    elif a<1200:
        return 3
    elif a<1600:
        return 4
    elif a<2000:
        return 5
    elif a<2400:
        return 6
    elif a<2800:
        return 7
    elif a<3200:
        return 8
    else:
        return 999

A = [get_color(int(j)) for j in input().split()]
C_A = Counter(A)

if set(A)=={999}:
    print(1,len(A))
elif C_A[999]>0:
    print(len(set(A))-1,len(set(A))-1+C_A[999])
else:
    print(min(len(set(A)),8),min(len(set(A)),8))

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

vector<bool> reacheable_s;
vector<bool> reacheable_e;
vector<bool> r;

void dfs(ll s, const vector<vector<ll>> &edges, vector<bool> &reacheable) {
  reacheable[s] = true;
  for (auto nxt: edges[s]) {
    if (!reacheable[nxt]) {
      dfs(nxt, edges, reacheable);
    }
  }
}

class BellmanFord {
 const ll INF = 1e18;
 struct edge { ll from, to, cost; };
 public:
  BellmanFord(ll n): n(n) {}
  void AddEdge(ll from, ll to, ll cost) {
    es.push_back(edge{from, to, cost});
  }
  vector<ll> ShortestPath(ll start) {
    vector<ll> d(n, INF);
    d[start] = 0;
    for (ll i=0; i<n; i++) {
      for (auto e: es) {
        if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
          d[e.to] = d[e.from] + e.cost;
          // printf("i=%d e.to = %d\n",i,e.to);
          if (i == n-1 && r[e.to])
            return vector<ll>();
        }
      }
    }
    return d;
  }
 private:
  ll n;
  vector<edge> es;
};

signed main() {
  ll N,M,P;
  cin>>N>>M>>P;
  BellmanFord bf(N);
  reacheable_s.resize(N, false);
  reacheable_e.resize(N, false);
  r.resize(N, false);
  vector<vector<ll>> edges_s(N);
  vector<vector<ll>> edges_e(N);

  rep(i,M){
    ll from, to, cost;
    cin >> from >> to >> cost;
    from--;
    to--;
    cost = -(cost -P);
    bf.AddEdge(from, to, cost);

    edges_s[from].push_back(to);
    edges_e[to].push_back(from);
  }

  // 0とN-1から到達可能な点rを求める
  dfs(0, edges_s, reacheable_s);
  dfs(N-1, edges_e, reacheable_e);
  rep(i,N){
    r[i] = reacheable_s[i] & reacheable_e[i];
    // printf("r[%d]=%x\n",i,r[i]);
  }

  auto d = bf.ShortestPath(0);
  if (d.size() == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << max((ll)0, -d[N-1])<< endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
using pi = pair<int, int>;
const int MAXN = 18;

int n, a[1 << MAXN];
int minv[1 << MAXN];
int maxv[1 << MAXN];
vector<int> gph[1 << MAXN];
vector<pi>  ev [1 << MAXN];

int main(){
	scanf("%d",&n);
	for(int i=0; i<(1<<n); i++){
		scanf("%d",&a[i]);
		minv[i] = 1;
		maxv[i] = (1<<n);
		if(a[i]) minv[i] = a[i], maxv[i] = a[i];
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<(1<<n); j++){
			if((j >> i) & 1) continue;
			gph[j].push_back(j | (1<<i));
		}
	}
	for(int i=0; i<(1<<n); i++){
		for(auto &j : gph[i]){
			minv[j] = max(minv[j], minv[i] + 1);
		}
	}
	for(int i=(1<<n)-1; i>=0; i--){
		for(auto &j : gph[i]){
			maxv[i] = min(maxv[i], maxv[j] - 1);
		}
	}
	for(int i=0; i<(1<<n); i++){
		if(minv[i] > maxv[i]){
			puts("NO");
			return 0;
		}
		ev[minv[i]].emplace_back(maxv[i], i);
	}
	priority_queue<pi, vector<pi>, greater<pi> > pq;
	for(int i=1; i<=(1<<n); i++){
		for(auto &j : ev[i]) pq.push(j);
		while(!pq.empty() && pq.top().first < i) pq.pop();
		if(pq.empty()){
			puts("NO");
			return 0;
		}
		a[pq.top().second] = i;
		pq.pop();
	}
	int j = 0;
	for(int i=1; i<(1<<n); i++){
		int bit = ((1<<n) >> 1);
		while(j >= bit){
			j -= bit;
			bit >>= 1;
		}
		j += bit;
		if(i < j) swap(a[i], a[j]);
	}
	puts("YES");
	for(int i=0; i<(1<<n); i++){
		printf("%d ", a[i]);
	}
}


Measured memory_bytes: 43136
#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 ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define DBG_N(hoge) cerr<<" "<<(hoge)<<endl;
#define DBG cerr<<"!"<<endl;
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll h,w;cin>>h>>w;
  ll n;cin>>n;
  ll x,y;cin>>x>>y;
  string t,a;cin>>t>>a;
  bool ans=true;
  ll nx=x,ny=y;
  for(int i=0;i<n;i++){
    if(t[i]=='R'){
      ny++;
    }
    if(ny>w)ans=false;
    if(a[i]=='L'&&ny>1)
      ny--;
  }
  nx=x;ny=y;
  for(int i=0;i<n;i++){
    if(t[i]=='L'){
      ny--;
    }
    if(ny<1)ans=false;
    if(a[i]=='R'&&ny<w)
      ny++;
  }
  nx=x;ny=y;
  for(int i=0;i<n;i++){
    if(t[i]=='U'){
      nx--;
    }
    if(nx<1)ans=false;
    if(a[i]=='D'&&nx<h)
      nx++;
  }
  nx=x;ny=y;
  for(int i=0;i<n;i++){
    if(t[i]=='D'){
      nx++;
    }
    if(nx>h)ans=false;
    if(a[i]=='U'&&nx>1)
      nx--;
  }
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  return 0;
}


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

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) ((v).begin(),(v).end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    ll n,k;
    cin >> n >> k;
    ll num = k;
    n--;
    while(n!=0){
        num*=(k-1);
        n--;
    }
    COUT(num);
    return 0;
}

Measured memory_bytes: 256
x = int(input())
if x % 2 == 0 or x % 5 == 0:
  print(-1)
else:
  s = 1
  m = 7
  
  while m%x != 0:
    n = m % x
    m = n * 10 +7
    s += 1
    
  
  print(s)  



Measured memory_bytes: 9200
#include <bits/stdc++.h>
using namespace std;
/**
  BBBB
  12 34
  BWWB
  14
  23
  **/
const int mod = 1'000'000'007;
int mul(long long a, long long b){
	return a * b % mod;
}
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	int open = 1;
	int res = 1;
	if(s[0] != 'B'){
		cout << 0 << endl;
		return 0;
	}
	for(int i = 1; i < 2 * n; i++){
		int sign = s[i] == 'B' ? 1 : 0;
		if((open % 2) == sign) {
			res = mul(res, open);
			open--;
		} else {
			open++;
		}
		if(open < 0)
			res = 0;	
	}
	if(open != 0)
		res = 0;
	for(int i = 1; i <= n; i++)
		res = mul(res, i);
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<atcoder/all>
#define ll long long

ll a, n, l, i;

void f(ll x, ll y) {
  if ((i = std::__gcd(x,y) > 1 ? 0 : atcoder::inv_mod(x,y)) > 0)
    a = std::min({a, i * x - 1, (y-i) * x});
}

int main() {
  std::cin >> n; a = n + (n & 1 ^ 1);
  for (ll d = 1; d * d <= n; d++)
    if (n % d == 0)
      f(2 * d, n / d), f(2 * n / d, d);
  std::cout << a << "\n";
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
int main(){
  int N,Q;
  cin>>N>>Q;
  deque<pair<string,int> > que;
  FOR(i,0,N){
    string S;
    int A;
    cin>>S>>A;
    que.push_back(MA(S,A));
  }
  int now=0;
  while(que.size()){
    if(que.front().SE<=Q){
      cout<<que.front().FI<<" "<<now+que.front().SE<<endl;
      now+=que.front().SE;
      que.pop_front();
    }else{
      pair<string,int> P=que.front();
      que.pop_front();
      now+=Q;
      P.SE-=Q;
      que.push_back(P);
    }
  }
  return 0;
}


Measured memory_bytes: 6312
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, M;
vector<int> B[10005];
int cost[9] = {2,5,5,4,5,6,3,7,6};
typedef pair<vector<int>, bool> P;

// 0.制作可能 1.桁数が大きい 2.番号が大きいの順にreturnする
P dfs(int rest, vector<int> &A) { // 残りcost
  vector<int> ret;
  if (rest==0) return P(ret, true);
  if (rest<0) return P(ret, false);
  if (B[rest].size()>0) return P(B[rest], true);
  int c = 0;
  rep(i, M) {
    P p = dfs(rest-cost[A[i]], A);
    if (p.second && p.first.size()>=ret.size()) {
      ret = p.first;
      c=A[i]+1;
    }
  }
  if (c == 0) return P(ret, false);
  ret.push_back(c);
  B[rest] = ret;
  return P(ret, true);
}

int main() {
  INCANT;
  cin >> N >> M;
  vector<int> A(M);
  int a; 
  rep(i, M) {
    cin >> a;
    a--;
    A[i] = a;
  }
  sort(ALL(A));
  P p = dfs(N, A);
  int sz =B[N].size();
  rep(i, sz) cout << B[N][sz-1-i];
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 115712
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
char S[20][20];
int D[20][20];

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    ll H, W;
    int ans = 0;
    cin >> H >> W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> S[i][j];
        }
    }



    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            queue<pair<int , int>> que;
            for(int k = 0; k < H; k++){
                for(int l = 0; l < W; l++){
                    D[k][l] = -1;
                }
            }
            if(S[i][j] == '#') continue;
            D[i][j] = 0;// 初期条件 (頂点 0 を初期ノードとする)

            que.push(make_pair(i ,j)); // 0 を橙色頂点にする


            // BFS 開始 (キューが空になるまで探索を行う)
            while (!que.empty()) {
                int v = que.front().first; // キューから先頭頂点を取り出す
                int w = que.front().second;
                que.pop();

                // v から辿れる頂点をすべて調べる
                if(v + 1 >= 0 && S[v + 1][w] == '.'){
                    if (D[v + 1][w] != -1){
                        
                    }
                    else{
                        D[v + 1][w] = D[v][w] + 1;
                        que.push(make_pair(v + 1 , w));
                    }
                    
                }   

                if(v - 1 >= 0 && S[v - 1][w] == '.'){
                    if (D[v - 1][w] != -1){
                        
                    }
                    else{
                        D[v - 1][w] = D[v][w] + 1;
                        que.push(make_pair(v - 1 , w));
                    }
                }
                
                if(w - 1 >= 0 && S[v][w - 1] == '.'){
                    if (D[v][w - 1] != -1){
                        
                    }
                    else{
                        D[v][w - 1] = D[v][w] + 1;
                        que.push(make_pair(v, w - 1));
                    }

                } 

                if(w + 1 < W && S[v][w + 1] == '.'){
                    if (D[v][w + 1] != -1){
                        
                    } 
                    else{
                        D[v][w + 1] = D[v][w] + 1;
                        que.push(make_pair(v, w + 1));
                    }

                }

            }
            for(int k = 0; k < H; k++){
                for(int l = 0; l < W; l++){
                    ans = max(ans , D[k][l]);
                }
            }
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>

using namespace std;
#define rep(i, s, e) for (int(i) = (s); (i) < (e); (i)++)

int main()
{
	int b1, b2, b3, a2, a3;
	vector<vector<int>> c(3, vector<int>(3));
	rep(i, 0, 3)
	{
		rep(j, 0, 3)
		{
			cin >> c[i][j];
		}
	}
	b1 = c[0][0];
	b2 = c[0][1];
	b3 = c[0][2];
	a2 = c[1][0] - b1;
	a3 = c[2][0] - b1;
	if (c[1][1] == a2 + b2 && c[1][2] == a2 + b3 && c[2][1] == a3 + b2 && c[2][2] == a3 + b3)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {

	public static void main(String[] args) throws FileNotFoundException {
		FS fs = new FS();
		int n=fs.nextInt();
		int a=n/500;
		n%=500;
		int b=n/5;
		System.out.println(a*1000+b*5);
	}
	
	static class FS {
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try { st = new StringTokenizer(br.readLine());}
				catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			 return Integer.parseInt(next());
		}
	}

}

Measured memory_bytes: 21972
#include<iostream>
using namespace std;
const int N=2e5+10;
const long long M=998244353;
typedef long long ll;
ll a[N],b[N];
ll qmod(ll a,ll b){
	ll k=1;
	while(b){
		if(b&1) k=k*a%M;
		a=a*a%M;
		b>>=1;
	}
	return k;
}
ll C(ll c,ll d){
	return ((((a[c]*b[d])%M)*b[c-d])%M);
}
int main(){
	ll n,m,k;
	cin>>n>>m>>k;
	a[0]=b[0]=1;
	for(int i=1;i<=n;i++){
		a[i]=(a[i-1]*i)%M;
		b[i]=(qmod(a[i],M-2));
	}
	ll ans=0;
	for(int i=0;i<=k;i++){
		ll f=(m*qmod(m-1,n-i-1))%M;
		f=(f*C(n-1,i))%M;
		ans=(ans+f)%M;
	}
	cout<<ans;
	return 0;
}


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

int main() {
    int n; cin >> n;
    vector<string> s(n);
    for (auto &si: s) cin >> si;
    map<string, int> ma;
    for (auto si: s) {
        sort(si.begin(), si.end());
        ma[si] += 1;
    }
    long long cnt = 0;
    for (auto c: ma) {
        if (c.second > 1) cnt += 1LL * c.second * ~-c.second / 2;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 18176
#include<iostream>
using namespace std;
int main()
{
  int k,a,b;
  cin>>k>>a>>b;
  if(a%k==0 || b%k==0)
    cout<<"OK\n";
  else
  {
  a/=k;
  b/=k;
  if(a==b)
    cout<<"NG\n";
  else
    cout<<"OK\n";
  }
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = long long;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||debg||local||debug
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}
template<class T>vector<T> _vec(size_t a,T v){return vector<T>(a,v);}
template<class T, class... Ts>auto _vec(size_t a, Ts... ts){return vector<decltype(_vec<T>(ts...))>(a, _vec<T>(ts...));}

int main(){

  ll n,m,k;
  cin>>n>>m>>k;
  for(ll r=0;r<=n;++r){
    for(ll c=0;c<=m;++c){
      ll cnt = r*(m-c)+c*(n-r);
      if(cnt==k){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;

}

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

typedef long long ll;

using namespace std;

int isPrime(ll x) {
  for(ll i=2; i*i<=x; i++) {
    if(x%i == 0) return false;
  }
  
  return true;
}

int main() {
  ll n, N;
  
  cin >> N;
  cout << N << ":";

  if(isPrime(N)) {
    cout << ' ' << N << endl;
    return 0;
  }
  
  n = N;
  
  ll cnt = 2;

  while(1) {
    if(n <= 1) break;
    for(ll j = cnt; j<=N; j++) {
      if(n % j == 0) {
	cout << " " << j;
	n/=j;
	cnt = j;
	break;
      }
    }
  }
  cout << endl;
  
  return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
int a[123456];
int n;
bool vis[1009];
map<int,int>Mp;
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        if(a[i]==i){
            Mp[i]=1;
        }
    }
    int sum=0;
    for(int i=1;i<=n;i++){
        if(Mp[i]==1){
            sum++;
            Mp[i]=0;
            Mp[i+1]=0;
        }
    }
    cout<<sum<<endl;
	return 0;
}


Measured memory_bytes: 5376