akhauriyash/Code-Regression huggingface dataset:
import itertools
def getCombList(xList):
  N = len(xList)
  result = []
  for n in range(1,N+1):
    for conb in itertools.combinations(xList, n):
      result.append(list(conb)) #タプルをリスト型に変換
  #print(result)
  return result

import numpy as np
L1 = input()
H, W, K = map(int, L1.split(" "))
mat = np.zeros([H,W], dtype="int32")
for i in range(H):
  Li = input()
  for j, s in enumerate(Li):
    if s == "#":
      mat[i,j] = 1

if np.sum(np.sum(mat)) < K:
  print(0)
else:
  if np.sum(np.sum(mat)) == K:
    c = 1
  else:
    c = 0
  matp = mat.copy()
  HList = list(range(H))
  WList = list(range(W))
  HcombList = getCombList(HList)
  WcombList = getCombList(WList)
  for Hcomb in HcombList:
    for Wcomb in WcombList:
      matp[Hcomb, :] = 0
      matp[:, Wcomb] = 0
      if np.sum(np.sum(matp)) == K:
        c = c + 1
      matp = mat.copy()
      
  for Hcomb in HcombList:
    matp[Hcomb, :] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

  for Wcomb in WcombList:
    matp[:, Wcomb] = 0
    if np.sum(np.sum(matp)) == K:
      c = c + 1
    matp = mat.copy()

  print(c)

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


int main(){
	int A, B;
	cin >> A >> B;
	if(B%A) Cout(B - A);
	else Cout(A + B);
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	m := make(map[int]int)
	for i := 0; i < n; i++ {
		var x int
		fmt.Scan(&x)
		m[x]++
	}

	switch len(m) {
	case 1:
		if m[0] == n {
			fmt.Println("Yes")
			return
		}
	case 2:
		if m[0] == n/3 {
			fmt.Println("Yes")
			return
		}
	case 3:
		x := 0
		for k, v := range m {
			if v != n/3 {
				fmt.Println("No")
				return
			}
			x ^= k
		}
		if x == 0 {
			fmt.Println("Yes")
			return
		}
	}
	fmt.Println("No")
}


Measured memory_bytes: 7936
S = input()
S_rvs = S[::-1]
texts = ["maerd", "remaerd", "esare", "resare"]

match = True
while len(S_rvs) > 0:
    if (S_rvs[0:5] == "maerd") or (S_rvs[0:5] == "esare"):
        S_rvs = S_rvs[5:]
    elif S_rvs[0:6] == "resare":
        S_rvs = S_rvs[6:]
    elif S_rvs[0:7] == "remaerd":
        S_rvs = S_rvs[7:]
    else:
        match = False
        break

if match:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<(ll)(n);++i)
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
auto z_alg(const string& s){
  ll n=s.size();
  vector<ll> z(n);
  z[0]=n;
  ll L=0,R=0;
  for(ll i=1;i<n;++i){
    if( i>R ){
      L=R=i;
      while( R<n && s[R-L]==s[R] )R++;
      z[i]=R-L;
      R--;
    }
    else{
      ll k=i-L;
      if( z[k]<R-i+1 )z[i]=z[k];
      else{
        L=i;
        while( R<n && s[R-L]==s[R] )R++;
        z[i]=R-L;
        R--;
      }
    }
  }
  return z;
}

main(){

  ll n;
  string s;
  cin>>n>>s;

  ll ans=0;
  rep(i,n){
    vector<ll> lcp=z_alg(s.substr(i,n-i));
    rep(j,lcp.size()){
      chmax(ans,min(lcp[j],j));
    }
  }
  cout<<(ans)<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(x)(x).begin(), (x).end() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int N;cin >> N;
    vector<int> A(N);rep(i,N)cin >> A[i];
    sort(all(A));
    bool ok = true;
    rep(i,N-1){
        if(A[i] == A[i+1])ok = false;
    }
    if(ok)cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    String S = scanner.nextLine();
    String answer = "No";
    if(S.charAt(0) != S.charAt(1) || S.charAt(1) != S.charAt(2))answer = "Yes";
    System.out.println(answer);
  }
}

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

int main(void)
{
    long long D;
    cin >> D;
    vector<long long> c(26);
    vector<vector<long long>> used(26);
    for (long long i = 0; i < 26; i++)
    {
        cin >> c[i];
        used[i].push_back(-1);
    }
    vector<vector<long long>> s(D,vector<long long>(26));
    for (long long i = 0; i < D; i++)
    {
        for (long long j = 0; j < 26; j++)
        {
            cin >> s.at(i).at(j);
        }
    }

    long long lastnum = 0;
    vector<long long> ans(D);
    for (long long i = 0; i < D; i++)
    {
        long long pena = 0;
        for (long long j = 0; j < 26; j++)
        {
            pena += c[j] * (i - used.at(j).at(used[j].size() - 1));
        }
        ans[i] = -1;
        long long cnt = -100000000;
        for (long long j = 0; j < 26; j++)
        {
            pena -= c[j] * (i - used.at(j).at(used[j].size() - 1));
            if (s.at(i).at(j) - pena > cnt)
            {
                ans[i] = j;
                cnt = s.at(i).at(j) - pena;
            }
            pena += c[j] * (i - used.at(j).at(used[j].size() - 1));
        }
        used[ans[i]].push_back(i);
        lastnum += cnt;
    }

    while(clock() <  1.9 * CLOCKS_PER_SEC)
    {
        long long ranD = rand() % D;
        long long ranq = rand() % 26;

        used[ans[ranD]].erase(remove(used[ans[ranD]].begin(), used[ans[ranD]].end(), ranD), used[ans[ranD]].end());
        used[ranq].push_back(ranD);
        sort(used[ranq].begin(), used[ranq].end());
        long long oldans = ans[ranD];
        ans[ranD] = ranq;

        long long newnum = 0;
        for (long long i = 0; i< D; i++)
        {   
            newnum += s.at(i).at(ans[i]);
        }
        for (long long j = 0; j < 26; j++)
        {
            long long pena = 0;
            for (long long i = 1; i < used[j].size(); i++)
            {
                pena += c[j] * (used[j][i] - used[j][i - 1]) * (used[j][i] - used[j][i - 1] + 1) / 2;
            }
            newnum -= pena;
        }
        
        if(newnum <= lastnum)
        {
            used[ranq].erase(remove(used[ranq].begin(), used[ranq].end(), ranD), used[ranq].end());
            used[ans[ranD]].push_back(ranD);
            sort(used[ans[ranD]].begin(), used[ans[ranD]].end());
            ans[ranD] = oldans;
        }
        else
        {
            lastnum = newnum;
        }
    }

    for (long long i = 0; i < D; i++)
    {
        cout << ans[i]+1 << endl;
    }
}

Measured memory_bytes: 3892
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val sortedP = (1 to N).toArray
    val P = Array.fill(N)(sc.nextInt())

    def check(a: Array[Int], b: Array[Int], ii: Int, jj: Int): Boolean = {
      var i = 0
      var r = true
      while (i < N) {
        r &&= {
          if (i == ii) a(jj) == b(i)
          else if (i == jj) a(ii) == b(i)
          else a(i) == b(i)
        }
        i += 1
      }
      r
    }

    val results = for {
      i <- 0 until N
      j <- 0 until N
    } yield check(P, sortedP, i, j)
    if (results.exists(identity) || check(P, sortedP, 0, 0)) {
      println("YES")
    } else println("NO")
  }

}

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

ll pow(ll x,ll y){
  if(y==0){
    return 1;
  }else if(y==1){
    return x%MOD;
  }else if(y%2==0){
    return pow(x,y/2)*pow(x,y/2)%MOD;
  }else{
    return pow(x,y-1)*x%MOD;
  }
}

int main(){
  ll a,b,c,d;cin >> a >> b >> c >> d;
  vector<ll> S(4);
  S[0] = a*c;
  S[1] = a*d;
  S[2] = b*c;
  S[3] = b*d;
  sort(S.begin(),S.end());
  cout << S[3] << endl;
}

Measured memory_bytes: 3628
from functools import lru_cache


def main():
    while True:
        W, H = map(int, input().split(" "))
        if H == W == 0:
            break

        N = int(input())
        forbid = {tuple(map(int, input().split(" "))) for _ in range(N)}

        @lru_cache(maxsize=None)
        def route(x, y):
            if x == 0 or y == 0:
                return 0 
            if (x, y) in forbid:
                return 0
            if x == y == 1:
                return 1
            return route(x - 1, y) + route(x, y - 1)

        print(route(W, H))

if __name__ == "__main__":
    main()

Measured memory_bytes: 8160
n,m=map(int,input().split())
s=[input() for _ in range(n)]
t=[input() for _ in range(m)]
for i in range(n-m+1):
  for j in range(n-m+1):
    f=True
    for x in range(m):
      for y in range(m):
        if t[x][y]!=s[x+i][y+j]:
          f=False
          break
      if f is False:
        break
    if f:
      break
  if f:
    print("Yes")
    break
else:
  print("No")

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	
  	
	while(1){
		int ans, n, m;
		ans = 0;
	  	cin >> n >> m;
      	if(n==0&&m==0){
          break;
        }
		  for(int i=1;i<=n-2;i++){
		  	for(int j=i+1;j<=n-1;j++){
		  		for(int k=j+1;k<=n;k++){
		  			if(i+j+k==m){
		  				ans++;
		  			}
		  		}
		  	}
		  }

		  
		  cout << ans <<endl;
	}
}




Measured memory_bytes: 3088
#include <iostream>

using namespace std;

int main()
{
   int i, h, m, s;
   cin >> i;
   h = i / 3600;
   m = i / 60 - h * 60;
   s = i % 60;
   cout << h << ":" << m << ":" << s << endl;

   return 0;
}


Measured memory_bytes: 3108
array = gets.split("").map(&:to_i)

option1 = ["+", "-"]
option2 = ["+", "-"]
option3 = ["+", "-"]

option1.product(option2, option3).each { |option|
    answer = array[0]
    
    array.length.times { |i|
        if option[i] == "+" then
            answer += array[i + 1]
        elsif option[i] == "-" then
            answer -= array[i + 1]
        end
    }
    if answer == 7 then
        print array[0].to_s + option[0] + array[1].to_s + option[1] + array[2].to_s + option[2] + array[3].to_s + "=" + answer.to_s
        break
    end
}

Measured memory_bytes: 1788
import java.util.Arrays;
import java.util.Scanner;

/*
絶対値の和の最小
|x−B1|+|x−B2|+⋯+|x−BN| を最小にする x は、B1,B2,…,BN のメディアン *式変形
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[(int)N];
        int[] b = new int[(int)N];
        for(int i = 0; i < N; i++) {
            a[i] = sc.nextInt();
            b[i] = a[i] - i;
        }
        Arrays.sort(b);
        int mid = b[N/2];
        long min = 0;
        for(int i = 0; i < N; i++) {
            min += Math.max(mid - b[i], - mid + b[i]);
        }
        System.out.println(min);

    }
}


Measured memory_bytes: 61576
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define MOD (1000000007l)
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)

using namespace std;

void solve() {
  double N;
  cin >> N;

  ll ans = ceil(N / 1.08);
  ll tmp = ans * 1.08;

  if (tmp == N) cout << ans << endl;
  else cout << ":(" << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
constexpr ll INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
constexpr ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ld n, cnt, ans, a, b, c, d, tmp, m, h, w, x, y, sum, k, q;

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

  cin >> a >> b;
  ll anss;
  anss = floor(a * b);
  Cout(anss);
  return 0;
}

Measured memory_bytes: 3784
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
#define bas 2600
int n,ave,a[60];
ll f[51][5250];

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

int main()
{
	n=read();ave=read();
	rep(i,1,n) a[i]=read()-ave;
	f[0][bas]=1;
	rep(i,1,n)
	{
		rep(j,a[i],bas*2)
		{
			f[i][j]=f[i-1][j]+f[i-1][j-a[i]];
		}
	}
	printf("%lld",f[n][bas]-1);
	return 0;
}


Measured memory_bytes: 2304
def a_getting_difference(N, K, A):
    import fractions # 3.5以降はmath.gcd()を使う
    gcd_a = A[0]
    max_a = max(A)
    for i in range(1, N):
        gcd_a = fractions.gcd(gcd_a, A[i])

    ans = 'POSSIBLE' if K <= max_a and K % gcd_a == 0 else 'IMPOSSIBLE'
    return ans

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
print(a_getting_difference(N, K, A))

Measured memory_bytes: 14252
while True:
 
    H,W =[int(i) for i in input().split()]
 
    if H == W == 0:
        break
 
    for h in range(H):
        for w in range(W):
            if (h+w) % 2 ==0:
                print('#', end='')
            else :
                print('.' ,end='')
        print()
    print()

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

using namespace std;

const int mod = 2019;
typedef long long ll;


int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    ll d1 = 0;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        if (i & 1){
            d1 -= a[i];
        } else {
            d1 += a[i];
        }
    }
    vector<ll> d(n);
    d[0] = d1;
    for (int i = 1; i < n; i++){
        d[i] = 2LL * a[i -  1] - d[i - 1];
    }
    for (int i = 0; i < n; i++){
        cout << d[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5+5;
int n, p[N];
vector<int> adj[N];

void dfs(int v, int u) {
    p[v] = u;
    for(int w : adj[v]) {
        if(w == u)  continue;
        dfs(w, v);
    }
}

main() {
    // freopen("in.txt", "r", stdin);
    cin >> n;
    for(int i=1; i<n; i++) {
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, -1);
    int x = n*(n+1)/2;
    for(int i=1; i<=n; i++) {
        x += ((i-1)*i + (n-i)*(n-i+1))/2 * (adj[i].size()-1);
        if(i > 1) {
            int l = min(p[i], i),
                r = max(p[i], i);
            x -= (l*(l-1) + (n-r)*(n-r+1) + (r-l)*(r-l-1))/2;
        }
    }
    cout << x;
}

Measured memory_bytes: 25464
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
typedef long long int lli;
#define optimize ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define F first
#define S second
#define forn(i,n) for(int i = 0; i<n; i++)
#define forab(i,a,b) for(int i = a; i<b; i++)
#define forll(i,a,b) for(lli i = a; i<b; i++)
#define mp make_pair
#define pb emplace_back
#define sortv(v) sort(v.begin(), v.end())
#define debug(x) cout<<#x<<" : "<<x<<endl
#define all(x) x.begin(),x.end()
const int mod1 = 1000000007;
const int mod2 = 998244353;

int main()
{
	optimize
	#ifndef ONLINE_JUDGE
	freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
	#endif

	string s;
	cin>>s;

	int ans = 0;
	for(int i = 0; i<3; i++)
	{
		int cnt = 0;
		if(s[i] == 'S')
			continue;
		else
			cnt++;
		for(int j = i+1; j<3; j++)
		{
			if(s[j] == 'S')
				break;
			else
				cnt++;
		}
		ans = max(ans, cnt);
	}    

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

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, x; cin >> n >> x;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i = 0; i < n; i++){
		if(x >= a[i]){
			x -= a[i];
			ans++;
		} else {
			x = 0;
		}
	}
	if(x) ans--;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
using System;

public class B
{
	public static void Main()
	{
		string[] s = Console.ReadLine().Split();
		int num = int.Parse(s[0]);
		int money = int.Parse(s[1]);
		for(int i = 0; i <= num; i++)
		{
			for(int j = 0; j + i <= num; j++)
			{
				int k = num - i - j;
				if(i * 10000 + j * 5000 + k * 1000 == money)
				{
					Console.WriteLine(i.ToString() + " " + j.ToString() + " " + k.ToString());
					return;
				}
			}
		}
		Console.WriteLine("-1 -1 -1");
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};
 
int main(){
  string s;
  cin>>s;
  vector<bool> visited(26,false);
  int num;
  REP(i,s.size()){
    num = s[i]-'a';
    if(!visited[num]){
      visited[num]=true;
    }else{
      cout<<"no"<<endl;
      return 0;
    }
  }
  cout<<"yes"<<endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
(h, w, m), *s = [[*map(int, i.split())] for i in open(0)]
r = [0] * (h + 1)
c = [0] * (w + 1)
for x, y in s:
    r[x] += 1
    c[y] += 1
R = max(r)
nr = {i for i, x in enumerate(r) if x == R}
C = max(c)
nc = {i for i, x in enumerate(c) if x == C}
count = sum(x in nr and y in nc for x, y in s)
print(R + C - (len(nr) * len(nc) == count))


Measured memory_bytes: 110456
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int gcd(int x, int y) {
    if (x < y) return gcd(y, x);
    else if (y == 0) return x;
    else return gcd(y, x % y);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    cin >> N >> K;
    int A[N];
    int maxnum = 0;
    int minnum = INF;
    rep(i, N) {
        cin >> A[i];
        maxnum = max(maxnum, A[i]);
        minnum = min(minnum, A[i]);
    }
    if (N == 1) {
        if (A[0] == K) {
            cout << "POSSIBLE" << endl;
        } else {
            cout << "IMPOSSIBLE" << endl;
        }
        return 0;
    }

    int G = gcd(A[0], A[1]);
    for (int i = 2; i < N; i++) {
        G = gcd(G, A[i]);
    }
    if (K % G == 0 && minnum <= K && K <= maxnum) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

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

  ll ans = -1;
  for (int i = 0; i <= max(x, y); i++) {
    ll cc = i * 2 * c;
    ll ac = max(x - i, 0) * a;
    ll bc = max(y - i, 0) * b;

    ll total = ac + bc + cc;

    if (ans == -1 || ans > total) {
      ans = total;
    }
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
static const int INFTY = 1000000010;

class Card {
    public:
        char suit;
        int num;
        Card();
};
Card::Card() {
    suit = '\0';
    num = 0;
}
Card A[MAX], B[MAX];

/*------------------------
    Quick Sort
------------------------*/

int partition(Card A[], int p, int r) {
    int x = A[r].num;
    int i = p-1; // i以下がxより小さな値
    for (int j = p; j < r; j++) { // A[j]がxと比べる値
        if (A[j].num <= x) {
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

void quickSort(Card A[], int p, int r) {
    if (p < r) {
        int q = partition(A, p, r);
        quickSort(A, p, q-1);
        quickSort(A, q+1, r);
    }
}

/*----------------------------
    Merge Sort
----------------------------*/

Card L[MAX/2 + 2], R[MAX/2 + 2];
void merge(Card A[], int left, int mid, int right) {
    int n1 = mid - left; // left の添え字が0 mid-1 がn1-1
    int n2 = right - mid; // mid の添え字が0 right -1 がn2-1
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1].num = INFTY;
    R[n2].num = INFTY;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        if (L[i].num <= R[j].num) {
            A[k] = L[i];
            i++;
        } else {
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(Card A[], int left, int right) {
    if (right - left > 1) {
        int mid = (left + right) / 2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
    return;
}

int main() {
    int n;
    bool isStable = true;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> A[i].suit >> A[i].num;
        B[i].suit = A[i].suit;
        B[i].num = A[i].num;
    }
    quickSort(A, 0, n-1);
    mergeSort(B, 0, n);

    for (int i = 0; i < n; i++) {
        if (A[i].suit != B[i].suit) {
            isStable = false;
            break;
        }
    }
    
    if (isStable) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    
    for (int i = 0; i < n; i++) {
        cout << A[i].suit << " " << A[i].num << endl;
    }
    return 0;
}


Measured memory_bytes: 5444
from itertools import product
h, w, k = map(int, input().split())
m = []
br = []
bc = []
for i in range(h):
    i = input()
    m.append(list(i))
    br.append(i.count('#'))
mm = list(zip(*m))
for c in mm:
    bc.append(c.count('#'))
b = sum(br)
p = 0
for r in product([0, 1], repeat=h):
    for c in product([0, 1], repeat=w):
        ris = [i for i, x in enumerate(r) if x == 1]
        cis = [i for i, x in enumerate(c) if x == 1]
        c = 0
        for ri in ris:
            c += br[ri]
            for ci in cis:
                c -= 1 if m[ri][ci] == '#' else 0
        for ci in cis:
            c += bc[ci]
        if c == b - k:
            p += 1
print(p)

Measured memory_bytes: 74580
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}

const int N=1e5+10;
const ll INF=1e9+7;
ll a[N<<4];
int sum[11];
main(){
    ios
    int h,w,n;scanf("%d%d%d",&h,&w,&n);
    int x,y;
    int cnt=0;
    ll m=(ll)(h-2)*(w-2);
    rep(iii,n){
        scanf("%d%d",&x,&y);
        rep(i,3)if( x-i>=1 && x-i<=h-2){
            rep(j,3)if(y-j>=1 && y-j<=w-2){
            a[cnt++]=INF*(x-i)+(y-j);
            }
        }
    }
    sort(a,a+cnt);
    ll t=1;
    rep(i,cnt){
        if(a[i]==a[i+1])t++;
        else sum[t]++,t=1,m--;
    }
    cout<<m<<" ";
    rep2(i,1,9)cout<<sum[i]<<" ";
}



Measured memory_bytes: 8448
using System;
using System.Collections.Generic;
using System.Linq;
public class AtCoder
{
    public static void Main()
    {
        //入力を保持する
        var AB = Console.ReadLine().Split().Select(v => int.Parse(v)).ToArray();
        var A = AB[0];
        var B = AB[1];

        Console.WriteLine((A * B).ToString());
    }
}


Measured memory_bytes: 28244
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {

  int N;

  cin >> N;

  vector<int> a = {1,2,3,5,6,9,10,13,17};

  for (int i = 0; i < a.size(); i++){
    if (N == a[i]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

typedef long long LL;
const int MN = 200005;

int N, stk[MN], tp;
LL A[MN], B[MN], C[MN], f[MN], Ans;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%lld", &A[i]);
	for (int i = 1; i <= N; ++i) scanf("%lld", &B[i]);
	int p = std::max_element(A + 1, A + N + 1) - A;
	std::rotate(A + 1, A + p, A + N + 1);
	std::rotate(B + 1, B + p, B + N + 1);
	A[N + 1] = A[1];
	for (int i = 2; i <= N; ++i) C[i + 1] = 2 * (C[i] + B[i]) - C[i - 1];
	for (int i = 1; i <= N + 1; ++i) {
		A[i] -= C[i];
		while (tp > 1 && (A[stk[tp]] - A[stk[tp - 1]]) * (i - stk[tp]) <= (A[i] - A[stk[tp]]) * (stk[tp] - stk[tp - 1])) --tp;
		stk[++tp] = i;
	}
	for (int i = 2; i <= tp; ++i) {
		int c = stk[i] - stk[i - 1];
		Ans += A[stk[i - 1]] * (c + 1) + A[stk[i]] * (c - 1);
	}
	for (int i = 1; i <= N; ++i) Ans += 2 * C[i];
	printf("%.12lf\n", Ans / (2. * N));
	return 0;
}

Measured memory_bytes: 7184
from sys import stdin,stdout
#for _ in range(int(stdin.readline())):
n=int(stdin.readline())
#a=list(map(int,stdin.readline().split()))
dividend=7;ans=-1
for add in range(10**6+5):
    rem=dividend%n
    if rem==0:
        ans=add+1
        break
    dividend=rem*10+7
print(ans)


Measured memory_bytes: 9076
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string T;
	cin >> T;

	for (int i=0; i<T.size(); i++) {
		if (T[i] == '?') T[i] = 'D';
	}

	cout << T << endl;

	return 0;
}

Measured memory_bytes: 3752
//
//  main.cpp
//  atcoder
//
//  Created by Hisaki Kobayashi on 2020/04/14.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
typedef long long ll;
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
const int MAX_N = 200000;

int N;
int W[200];
int V[200];

int dp[201][201];

int dfs(int i,int j){
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res;
    if(i==N) return 0;
    if(j<W[i]){
        res = dfs(i+1,j);
    }
    else{
        res = max(dfs(i+1,j), dfs(i+1,j-W[i])+V[i]);
    }
    return dp[i][j]=res;
}

int main(int argc, const char * argv[]) {
    
    int A,B,C,D;
    cin >> A >> B >> C >> D;
    
    while(true){
        C-=B;
        if(C<=0){
            cout << "Yes" << endl;
            break;
        }
        A-=D;
        if(A<=0){
            cout << "No" << endl;
            break;
        }
    }
    
    return 0;
    
}




Measured memory_bytes: 3636
def main():
    #print = out.append
    ''' Cook your dish here! '''
    h, w, k = get_list()
    mat = [list(input()) for _ in range(h)]
    res = [[0 for _ in range(w)] for _ in range(h)]
    xstart, ystart = 0, 0

    def fill(x1, y1, x2, y2, va):
        for i in range(y1, y2+1):
            for j in range(x1, x2+1):
               res[i][j] = va
    for i in range(h):
        hash_enc = False
        if k==0:
            res[i] = res[i-1]
        for j in range(w):
            if mat[i][j]=='#':
                hash_enc = True
                fill(xstart, ystart, j, i, k)
                xstart = j+1
                k -= 1
        if hash_enc:
            if xstart<w:
                fill(xstart, ystart, w-1, i, k+1)
            ystart = i+1
            xstart = 0
        #print(xstart, ystart)
    [print(" ".join(map(str, li))) for li in res]


''' Coded with love at India by Satyam Kumar '''
import sys
#from collections import defaultdict
import math
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
out = []
get_int = lambda: int(input())
get_list = lambda: list(map(int, input().split()))
main()
#[main() for _ in range(int(input()))]
print(*out, sep='\n')


Measured memory_bytes: 48604
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>

using namespace std;

typedef long long ll;

int main(){
    int N;
    ll W;

    cin >> N >> W;

    vector<ll> wts(N);
    vector<ll> vals(N);

    for(int i=0;i<N;i++){
        cin >> wts[i] >> vals[i];
    }

    ll w0 = wts[0];
    vector<ll> V[4];


    for(int i=0;i<N;i++){
        V[wts[i]-w0].push_back(vals[i]);
    }

    for(int i=0;i<4;i++){
        sort(V[i].begin(), V[i].end());
        reverse(V[i].begin(), V[i].end());
    }

    vector<ll> C[4];
    for(int i=0;i<4;i++){
        C[i].push_back(0);
        for(int j=0;j<V[i].size();j++){
            C[i].push_back(V[i][j]+C[i][j]);
        }
    }

    ll best = 0;
    for(int i0=0;i0<C[0].size();i0++){
        for(int i1=0;i1<C[1].size();i1++){
            for(int i2=0;i2<C[2].size();i2++){
                ll cur = i0*w0 + i1*(w0+1) + i2*(w0+2);
                if(cur <= W){
                    int i3 = (int)min((ll)(C[3].size()-1), (W-cur)/(w0+3));
                    best = max(best, C[0][i0]+C[1][i1]+C[2][i2]+C[3][i3]);
                }
            }
        }
    }

    cout << best << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<int,int> P;
typedef pair<ll,P> PP;
typedef vector<vector<int> > Graph;
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; }
const ll INF = 1e18;

int main(){
    ll n;
    cin >> n;
    if(n==0){
        cout << 0 << endl;
        return 0;
    }
    string ans = "";
    while(n!=0){
        ll amari = abs(n%2);
        ans += to_string(amari);
        if(n==-1){
            ans += '1';
            break;
        }
        if(n<0){
            if(amari==1){
                n = -(n-2)/2;
            }
            else{
                n = n/-2;
            }
        }
        else n=-n/2;
    }
    reverse(ans.begin(),ans.end());
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3612
def gcd(a,b):
  if a == 0:
    return b
  return gcd(b%a,a)

N,X = list(map(int,input().split()))
x = list(map(int,input().split()))
xx = [abs(x[i]-X) for i in range(N)]
xx.sort()
res = xx[0]
for i in range(N):
  res = gcd(res,xx[i])
print(res)

Measured memory_bytes: 14252
use std::io;


/// https://beta.atcoder.jp/contests/abc089/tasks/abc089_c
/// March
fn main() {
    let n = read_one::<usize>();
    let mut m: u64 = 0;
    let mut a: u64 = 0;
    let mut r: u64 = 0;
    let mut c: u64 = 0;
    let mut h: u64 = 0;
    for _ in 0..n {
        let s = read_one::<String>().chars().collect::<Vec<char>>();
        match s[0] {
            'M' => m += 1,
            'A' => a += 1,
            'R' => r += 1,
            'C' => c += 1,
            'H' => h += 1,
            _ => {},
        }
    }
    // 5C3 -> 10
    let mut ans = 0;
    ans += m * a * r;
    ans += m * a * c;
    ans += m * a * h;
    ans += m * r * c;
    ans += m * r * h;
    ans += m * c * h;
    ans += a * r * c;
    ans += a * r * h;
    ans += a * c * h;
    ans += r * c * h;

    println!("{}", ans);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
    std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define all(v) (v).begin(), (v).end()

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

    int64_t ans=0;

    for(int i=1; i<=n; i++){
        if(i % 3 == 0 || i % 5 == 0){
            continue;
        }
        ans += (int64_t)i;
    }

    cout << ans;
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
struct trump{
    char kind;
    int num;
};
int main(void){
    int n,min,flag=0;
    cin>>n;
    struct trump TRUMP1[n],TRUMP2[n],temp;
    for(int i=0;i<n;i++){
        cin>>TRUMP1[i].kind>>TRUMP1[i].num;
        TRUMP2[i]=TRUMP1[i];
    }
    for(int i=0;i<n-1;i++){
        for(int j=n-2;j>=0;j--){
            if(TRUMP1[j].num>TRUMP1[j+1].num){
                temp=TRUMP1[j];
                TRUMP1[j]=TRUMP1[j+1];
                TRUMP1[j+1]=temp;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<TRUMP1[i].kind<<TRUMP1[i].num;
        if(i<n-1)cout<<' ';
    }
    cout<<endl;
    if(flag==0)cout<<"Stable"<<endl;
    
    
    for(int i=0;i<n;i++){
        min=i;
        for(int j=i;j<n;j++){
            if(TRUMP2[min].num>TRUMP2[j].num){
                min=j;
            }
        }
        temp=TRUMP2[i];
        TRUMP2[i]=TRUMP2[min];
        TRUMP2[min]=temp;
        for(int j=i+1;j<min;j++){
            if(TRUMP2[min].num==TRUMP2[j].num){
                flag=1;
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<TRUMP2[i].kind<<TRUMP2[i].num;
        if(i<n-1)cout<<' ';
    }
    cout<<endl;
    if(flag==0)cout<<"Stable"<<endl;
    else cout<<"Not stable"<<endl;
    return 0;
}



Measured memory_bytes: 3096
# coding: utf-8
# Your code here!

n = int(input())
print(n, ": ", sep = "", end = "")

pri = []
while n % 2 == 0:
   pri.append(2)
   n //= 2

for i in range(3, int(n ** 0.5 + 1)):
   while n % i == 0:
      pri.append(i)
      n //= i
   i += 2

if n != 1:
   pri.append(n)

for i in range(len(pri)):
   print(pri[i], end = "")
   if i < len(pri) - 1:
      print(" ", end = "")
print("")



Measured memory_bytes: 5644
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p.sort(reverse=True)
q.sort(reverse=True)
r.sort(reverse=True)

pqr = []

for i in range(x):
    pqr.append(p[i])
for i in range(y):
    pqr.append(q[i])
for i in range(c):
    pqr.append(r[i])

pqr.sort(reverse=True)

delicious = 0
for i in range(x+y):
    delicious += pqr[i]

print(delicious)

Measured memory_bytes: 23328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n=0;
string N;
cin>>N;
for(int i=0;i<4;i++){
  if(N.at(i)=='2'){
    n++;
  }
}
cout<< n <<endl;
}
    

   
  
   


Measured memory_bytes: 256
# 2つの入力を空白で分割し、数値化
n, x = map(int, input().split())

# 空白区切りの数値をリスト化
l = list(map(int, input().split()))
l.insert(0, 0) # 0 start


distance = 0
result = 0

for d in l:
   if distance + d <= x:
       distance += d
       result += 1
   else:
       break
print(result)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {

    int n;
    int a, b, c;
    int temp[3];
    vector<int> dp(3);

    cin >> n;

    cin >> a >> b >> c;

    dp[0] = a;
    dp[1] = b;
    dp[2] = c;

    for (int i = 1; i < n; i++) {
        cin >> a >> b >> c;

        temp[0] = max(dp[1] + a, dp[2] + a);
        temp[1] = max(dp[0] + b, dp[2] + b);
        temp[2] = max(dp[0] + c, dp[1] + c);


        for (int i = 0; i < 3; i++) {
            dp[i] = temp[i];
        }
    }
  
    cout << *max_element(dp.begin(), dp.end()) << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

int isEmpty(){
  if(head == tail) {
    return 1;
  }
  else return 0;
}

int isFull(){
  if(head == (tail + 1) % LEN) {
    return 1;
  }
  else return 0;
}

void enqueue(P x){
  if(isFull() == 1) {
      printf("error\n");
  }
  Q[tail] = x;
  if(tail + 1 == LEN) {
    tail = 0;
  }
  else { 
    tail++;
  }
}

P dequeue( ){
  P x;
  if(isEmpty() == 1) {
    printf("error\n");
  }
  x = Q[head];
  if(head + 1 == LEN) {
    head = 0;
  }
  else {
    head++;
  }
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;
  while(1) {
    u = dequeue();
    if(u.t - q > 0) {
      elaps += q;
      u.t = u.t - q;
      enqueue(u);
    }
    else {
      elaps += u.t;
      printf("%s %d\n", u.name, elaps);
    }
    if(isEmpty() == 1) break;
  }
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  char ch; ch = getchar();
  ++ch; putchar(ch);

  return 0;
}

// created by Daniel yuan


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}
 
 
	public void run() {
		Scanner sc = new Scanner(System.in);
		int A[] =new int[3];
        
        
        
        for(int i=0;i<3;i++){
            A[i]=sc.nextInt();
            
        }
		int five=0;
		int seven=0;
		
		for(int i=0;i<3;i++){
		    if(A[i]==5){
		        five++;
		    }else if(A[i]==7){
		        seven++;
		    }
		}
		
		if(five==2 && seven==1){
		    System.out.println("YES");
		}else{
		    System.out.println("NO");
		}
		
	}
		
}


Measured memory_bytes: 35744
from collections import defaultdict
import itertools

march = set('MARCH')
count = defaultdict(int)
n = int(input())
for _ in range(n):
    name = input()
    if name[0] in march:
        count[name[0]] += 1


num_of_people = []
for s in 'MARCH':
    num_of_people.append(count[s])


ans = 0
for a, b, c in itertools.combinations(num_of_people, 3):
    ans += a * b * c

print(ans)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007

int main(){
    int w,h,n;
    int ox=0;
    int oy=0;
    cin >> w >> h >> n;
    rep(i,n){
        int x,y,a;
        cin >> x >> y >> a;
        if(a==1) {
            if(ox<x)ox=x;
        }
        else if(a==2) {
            if(x<w)w=x;
        }
        else if(a==3) {
            if(y>oy)oy=y;
        }
        else {
            if(y<h)h=y;
        }
    }

    int ans=(w-ox)*(h-oy);
    if(w>ox&&h>oy) cout << ans << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Security.Policy;

class Program3
{
	static void Main() => new Program3().Solve();

	void Solve()
	{
		var xy = ReadLongArray();
		var x = xy[0];
		var y = xy[1];

		for (var a = 0; a <= x; a++) {
			if (y == a * 2 + (x - a) * 4) {
				Console.WriteLine("Yes");
				return;
			}
		}

		Console.WriteLine("No");
	}

	#region Console.Read 関係
	long[] ReadLongArray() => Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
	long ReadLong() => long.Parse(Console.ReadLine());
	#endregion
}


Measured memory_bytes: 27332
#include <cstdio>
#include <cstdlib>
#include <cstring>

struct Node {
    int key;
    Node *next, *prev;
};

Node *nil;

Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur != nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}

void init(){
    nil = (Node *)malloc(sizeof(Node));
    nil->next = nil;
    nil->prev = nil;
}

void printList(){
    Node *cur = nil->next;
    int isf = 0;
    while(1){
        if(cur == nil) break;
        if(isf++ > 0) printf(" ");
        printf("%d", cur->key);
        cur = cur->next;
    }
    printf("\n");
}

void deleteNode(Node *t){
    if(t == nil) return;
    t->prev->next = t->next;
    t->next->prev = t->prev;
    free(t);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
    Node *x = (Node *)malloc(sizeof(Node));
    x->key = key;
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
}

int main(void){
    // Your code here!
    int key, n, i;
    int size = 0;
    char com[20];
    int np = 0, nd = 0;
    
    scanf("%d", &n);
    init();
    
    for(i = 0; i < n; i++){
        scanf("%s%d", com, &key);
        if(com[0] == 'i'){insert(key); np++; size++;}
        else if(com[0] == 'd'){
            if(strlen(com) > 6){
                if(com[6] == 'F') deleteFirst();
                else if(com[6] == 'L') deleteLast();
            }else{
                deleteKey(key); nd++;
            }
            size--;
        }
    }

    printList();

    return 0;
}



Measured memory_bytes: 33804
#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>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>
#include <atcoder/all>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
using namespace atcoder;
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;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N, Q;
    cin >> N >> Q;

    dsu d(N);

    while (Q--) {
        ll t, u, v;
        cin >> t >> u >> v;
        if (t) {
            cout << d.same(u, v) << "\n";
        } else {
            d.merge(u, v);
        }
    }
}

Measured memory_bytes: 4020
int A[100010];
int B[100010];
int C[100010];
int D[100010];
int E[100010];
int F[100010];
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
	int N;
	int ans =0;
	
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> A[i];
		cin >> B[i];
		cin >> C[i];
	}
	D[0]=A[0];
	E[0]=B[0];
	F[0]=C[0];
	for(int j=1; j<N; j++){
		D[j]=A[j]+max({E[j-1],F[j-1]});
		E[j]=B[j]+max({F[j-1],D[j-1]});
		F[j]=C[j]+max({D[j-1],E[j-1]});
	}
	ans = max({D[N-1],E[N-1],F[N-1]});
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2560