akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

#define debug(x) cout << #x << ": " << x << endl;
#define ll long long
#define mod 1000000007

int N, A[1 << 20], num, B[1 << 20], C[1 << 20], D[1 << 20];

int main() {
 // freopen("input.in","r",stdin);
  //freopen("output.out","w",stdout);
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> num;
    A[num]++;
  }
  int counter = 0;
  for (size_t i = 1; i <= N; i++) {
    if(A[i] > 0) {
      counter++;
      B[A[i]]++;
    }
  }
  int l_counter = 0;
  int l_ans = 0;
  for (size_t i = 1; i <= N; i++) {
    l_counter += B[i];
    l_ans += B[i]*i;
    C[i] = ((counter-l_counter)*i + l_ans)/i;
  }

  // for(int i = 0;i < N;i++) cout<<C[i+1]<<" "
  for(int i = N; i > 0;i--) {
    if(D[C[i]] == 0) {
      D[C[i]] = i;
    }
  }

  for(int i = N-1;i > 0;i--) {
    if(D[i] == 0) D[i] = D[i+1];
  }

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

  return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s, t;
    cin >> s >> t;
    
    sort(all(s));
    sort(all(t));
    reverse(all(t));
    
    if(s >= t) cout << "No" << endl;
    else cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 3636
from itertools import permutations
import sys
input = sys.stdin.readline
N, C = map(int, input().split())

D = [tuple(map(int, input().split())) for _ in [0]*C]
K = [tuple(map(int, input().split())) for _ in [0]*N]

T = [[0]*C for _ in [0]*3]

for i, _k in enumerate(K):
    for j, k in enumerate(_k):
        z = (i+j) % 3
        T[z][k-1] += 1

ans = float('inf')
for a, b, c in permutations(range(C), 3):
    cost = 0
    cost += sum(t*D[i][a] for i, t in enumerate(T[0]))
    cost += sum(t*D[i][b] for i, t in enumerate(T[1]))
    cost += sum(t*D[i][c] for i, t in enumerate(T[2]))
    ans = min(ans, cost)
print(ans)


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

int main(void) {
    long long X, Y;
    scanf("%lld%lld", &X, &Y);

    if (X-Y <= 1LL && X-Y >= -1LL) printf("Brown\n");
    else printf("Alice\n");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>

typedef long long int ll;

int read_int()
{
	int i;
	scanf("%d", &i);
	return i;
}

int read_lint()
{
	ll i;
	scanf("%lld", &i);
	return i;
}

int conv[100010];

int main()
{
	int n = read_int();

	ll sum = 0;
	int *a = (int *)malloc(sizeof(int) * n);
	for (int i = 0; i < n; i++)
	{
		ll a = read_lint();
		conv[a]++;
		sum += a;
	}

	int q = read_int();
	for (int i = 0; i < q; i++)
	{
		ll b = read_lint();
		ll c = read_lint();
		if (conv[b] == 0)
		{
			printf("%lld\n", sum);
			continue;
		}
		int x = conv[b];
		sum = sum - b * x + c * x;
		printf("%lld\n", sum);
		conv[c] += conv[b];
		conv[b] = 0;
	}

	return 0;
}

Measured memory_bytes: 2100
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc  = new Scanner(System.in);

        int N = sc.nextInt();
        long power = 1;

        for (int i=1; i<=N; i++) {
            power = power * i % (1000000000 + 7);
        }
        System.out.println( power );
    }
}

Measured memory_bytes: 21716
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	m := make(map[int]int)
	sum := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		m[a[i]]++
		sum += a[i]
	}
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()
	Q := getInt()
	for i := 0; i < Q; i++ {
		B, C := getInt(), getInt()
		x := m[B]
		sum -= x * B
		sum += x * C
		fmt.Fprintln(w, sum)
		m[B] = 0
		m[C] += x
	}
}


Measured memory_bytes: 9448
package main

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

func main() {
	var n, t int
	fmt.Scan(&n, &t)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	as := make([][]int, n)
	for i := range as {
		as[i] = make([]int, 2)
		sc.Scan()
		as[i][0], _ = strconv.Atoi(sc.Text())
		sc.Scan()
		as[i][1], _ = strconv.Atoi(sc.Text())
	}
	sort.Slice(as, func(i, j int) bool { return as[i][0] < as[j][0] })

	dp := make([][]int, n+1)
	for i := range dp {
		dp[i] = make([]int, t+2)
	}

	for i := 1; i <= n; i++ {
		a, b := as[i-1][0], as[i-1][1]
		for j := 0; j <= t; j++ {
			dp[i][j] = dp[i-1][j]
			if j-a >= 0 {
				dp[i][j] = max(dp[i][j], dp[i-1][j-a]+b)
			}
		}
		dp[i][t+1] = max(dp[i-1][t+1], dp[i-1][t-1]+b)
	}
	fmt.Println(dp[n][t+1])
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  vector<int> a(5); REP(i, 5) cin >> a[i];
  for(int i = 0; i < 5; ++i) {
    if(a[i] == 0) {
      cout << i + 1 << endl;
      break;
    }
  }
}


Measured memory_bytes: 3624
#include <algorithm>
#include <climits>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <string.h>
#include <utility>
#include <vector>
using namespace std;

#define dlog(str) cout << "====" << str << endl;
#define INF 999999999
#define MOD 1000000009
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define REPR(i, n) for(int i = n - 1; 0 <= i; i--)
#define FOR(i, s, e) for(int i = s; i <= e; i++)
#define FORR(i, s, e) for(int i = s; e <= i; i--)
#define LLI long long int
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    int X,A;
    cin>>X>>A;
    if(X<A){
        cout<<0;
    }else{
            cout<<10;
    }

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())
R = []
G = []
for i in range(N):
  if S[i] == "R":
    R.append(i)
  elif S[i] == "G":
    G.append(i)
r = len(R)
g = len(G)
ans = r * g * (N - r - g)
for i in R:
  for j in G:
    a = 2 * i - j
    b = 2 * j - i
    c = i + j
    if 0 <= a < N and S[a] == "B":
      ans -= 1
    if 0 <= b < N and S[b] == "B":
      ans -= 1
    if c % 2 == 0 and S[c//2] == "B":
      ans -= 1
print(ans)

Measured memory_bytes: 9252
/*
　　　　 ∧＿∧　にっぽんちゃちゃちゃ
　／＼（　・∀・）／ヽ
（ ●　と　　　つ　● ）　にっぽんちゃちゃちゃ
　＼/⊂、 ノ　　＼ノ
　　　　　し'
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define Rep(j,n) for(int j=0;j<(int)(n);++j)
#define Repo(j,o,n) for(int j=o;j<(int)(n);++j)
#define Repone(j,n) for(int j=1;j<(int)(n);++j)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define int long long
#define MOD 1000000007
#define INF 9223372036854775807

signed main() {
 pair< int, pair<int,int> > p1, p2;
 cin >> p1.first >> p1.second.first >> p1.second.second;
 cin >> p2.first >> p2.second.first >> p2.second.second;
 if ( p1 > p2 ) swap( p1, p2 );

 if ( p1.second < p2.second )
 cout << p2.first - p1.first + 1 << endl;
 else cout << p2.first - p1.first << endl;

}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define F first
#define S second
#define lint long long
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lint, lint>
#define ld long double
#define inlld(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define vi vector<int>
#define sz(x) (int)x.size()
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int N=1e5+5, MOD=1e9+7;
const lint INF=1e18;

lint _add(lint x, lint y) {
    lint ret=x+y;
    while(ret<0LL) ret+=MOD;
    return ret;
}
lint _mult(lint x, lint y) {
    x%=MOD; y%=MOD;
    lint ret=x*y;
    ret%=MOD;
    while(ret<0LL) ret+=MOD;
    return ret;
}
inline int modpow(lint base, int exp, int modulo) {
  base %= modulo;  lint result = 1;
  while (exp > 0) {
    if (exp & 1) result = (result * base) % modulo;
    base = (base * base) % modulo; exp >>= 1;
  }
  return result;
}
using namespace std;
using namespace __gnu_pbds;
template <typename T> 
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int a, b, c;
signed main()
{
    cin >> a >> b >> c;
    if(a == b && a != c)
    {
        cout << "Yes";
        return 0;
    }
    if(c == b && a != c)
    {
        cout << "Yes";
        return 0;
    }
    if(a == c && a != b)
    {
        cout << "Yes";
        return 0;
    }
    cout << "No";
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
cnt4 = 0
cnt2 = 0
for x in A:
    if x%4 == 0:
        cnt4 += 1
    elif x%2 == 0:
        cnt2 += 1
if cnt4 >= N//2:
    print("Yes")
elif cnt2 >= N-2*cnt4:
    print("Yes")
else:
    print("No")

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;
typedef double ld;

template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1ll << 60;
const ll MOD = 1e9 + 7ll;
const double PI=3.14159265358979323846;

ll gcd(ll n, ll m) {  // 最大公約数を求めるプログラム
    // nとmの最大公約数を返す関数
    if(m > n) {
        ll c = n;
        n = m; 
        m = c;
    }
    if(n%m == 0ll) return m;
    else return gcd(m, n%m);
}

vector<ll> fpf_prepare(ll a) {  // fpfの前処理　O(alog(loga))
    vector<ll> res(a+1);
    rp(i, 2, a+1) {
        if(res[i] == 0) {
            for(int k = 1; i*k <= a; k++) {
                res[i*k] = i;
            }
        }
    }
    return res;
}



int main() {
    int n; cin >> n;
    vector<ll> A(n);
    auto D = fpf_prepare(1000010);
    vector<bool> p(1000010, false);
    bool flag = false;
    rp(i, 0, n) {
        ll a; scanf("%lld", &a); A.at(i) = a;
        ll m = 1000000ll;
        while(a > 1ll) {
            // cout << "a = " << a << " D[a] = " << D[a] << endl;
            if(D[a] < m && p[D[a]]) flag = true;
            p[D[a]] = true; m = D[a]; a /= D[a];
        }
    }

    if(!flag) {
        cout << "pairwise coprime" << endl;
        return 0;
    }

    ll g = A[0];
    rp(i, 1, n) {
        g = gcd(g, A[i]);
        if(g == 1) {
            cout << "setwise coprime" << endl;
            return 0;
        }
    }
    cout << "not coprime" << endl;
    return 0;
}




Measured memory_bytes: 19032
#include <iostream>
#include "memory.h"
#include <list>
using namespace std;
struct pos
{
	int x;
	int y;
	int tx;
	int ty;
};
int main(int argc, char *argv[])
{
	
	int h,w;
	while(cin>>h>>w)
	{
		list<pos> ll;
		list<pos> l2;
		pos p;
		int i,j;
		int count = 0;
		int shu[510][510];
		int from[4001];
		int to[4001];
		memset(shu,0,sizeof(shu));
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				int ss;
				cin>>ss;
				shu[i][j] = ss;
			}
		}
		int fc = 0;
		for(i=0;i<h;i++)
		{
			for(j=0;j<w;j++)
			{
				if(shu[i][j] %2 != 0)
				{
					if (shu[i][j+1] %2 != 0 && j +1<w)
					{
						pos f;
						shu[i][j +1] +=shu[i][j];
						f.x = i;
						f.y= j;
						f.tx = i;
						f.ty = j +1;
						ll.push_back(f);
						count +=1;
					}
					else if (shu[i +1][j] %2 != 0 && i +1<h)
					{
						pos f,t;
						shu[i+1][j] +=shu[i][j];
						f.x = i;
						f.y= j;
						f.tx = i +1;
						f.ty = j;
						ll.push_back(f);
						count +=1;
					}
					else if(j +1 < w)
					{
						pos f,t;
						shu[i][j +1] += shu[i][j];
						f.x = i;
						f.y= j;
						f.tx = i;
						f.ty = j +1;
						ll.push_back(f);
						count +=1;
					}
					else if(i +1 < h)
					{
						pos f,t;
						shu[i +1][j] += shu[i][j];
						f.x = i;
						f.y= j;
						f.tx = i +1;
						f.ty = j;
						ll.push_back(f);
						count +=1;
					}
				} 
			}
		}
		int r;
		cout<<count<<endl;
		while(!ll.empty())
       {
       		pos ps = ll.front();
            cout<<ps.x+1<<" "<<ps.y+1<< " "<<ps.tx+1<<" "<<ps.ty+1<<endl;
           ll.pop_front();
       }
	}
	return 0;
}

Measured memory_bytes: 8960
require 'set'

n = gets.strip.to_i
s = gets.strip.split('')
 
r_pos = Set.new(s.map.with_index { |e, i| e == 'R' ? i : nil }.compact)
g_pos = Set.new(s.map.with_index { |e, i| e == 'G' ? i : nil }.compact)
b_pos = Set.new(s.map.with_index { |e, i| e == 'B' ? i : nil }.compact)
 
num_ex = 0
 
r_pos.each{|r|
  g_pos.each{|g|
  
    # middle
    if (r+g)%2 == 0 and b_pos.include?((r+g)/2)
      num_ex = num_ex.next
    end
    
    # edge
    diff = (r-g).abs
    if r < g
      if b_pos.include?(r-diff) 
        num_ex = num_ex.next
      end
      if b_pos.include?(g+diff)
        num_ex = num_ex.next
      end
    else
      if b_pos.include?(g-diff)
        num_ex = num_ex.next
      end
      if b_pos.include?(r+diff)
        num_ex = num_ex.next
      end
    end
    
  }
}
 
puts (r_pos.size * g_pos.size * b_pos.size) - num_ex

Measured memory_bytes: 15032
#include<bits/stdc++.h>
using namespace std;
int a,b,c,x,ans;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(int i=0;i<=a&&500*i<=x;i++)
		for(int j=0;j<=b&&100*j+500*i<=x;j++)
			for(int k=0;k<=c&&50*k+100*j+500*i<=x;k++)
			if(500*i+100*j+50*k==x)
				ans++;
	printf("%d",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=500005;
const ll INF=0x3f3f3f3f;
const ll MOD=1000000007;
char S[MAX],T[MAX];
int s[MAX],t[MAX],s_len,t_len,q;
int main(){
    scanf(" %s %s",S,T);
    scanf("%d",&q);
    s_len=strlen(S);
    t_len=strlen(T);
    for(int i=0;i<s_len;i++) s[i+1]=s[i]+(S[i]-'A'+1);
    for(int i=0;i<t_len;i++) t[i+1]=t[i]+(T[i]-'A'+1);
    for(int i=0;i<q;i++){
        int a,b,c,d;
        scanf("%d%d%d%d",&a,&b,&c,&d);
        if((s[b]-s[a-1])%3==(t[d]-t[c-1])%3) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}


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

void main_()
{
    int A, B, K;
    cin >> A >> B >> K;

    for (int i = A; i <= B; ++i) {
        if (i < A + K || B - K < i) {
            cout << i << "\n";
        }
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


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

int main() {
    int64_t x;
    cin >> x;

    int64_t d = x / 11;
    int32_t m = x % 11;

    int64_t answer = d * 2;
    if (m > 6) {
        answer += 2;
    } else if (m > 0) {
        answer += 1;
    }
    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    multiset<int> st;
    rep(i,n){
        int a;
        cin >> a;
        st.insert(a);
    }
    int ans = 0;
    while(!st.empty()){
        int p = *(--st.end());
        st.erase(--st.end());
        rrep(i,31){
            auto it2 = st.find((1 << i) - p);
            if(it2 != st.end()){
                ans++;
                st.erase(it2);
                break;
            }
        }
    }
    cout << ans << "\n";
    return 0;
}

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

const int MOD = 1000000007;

char a[1010][1010];
long dp[1010][1010];

template<class T> void add_mod(T &a, const T b){
	a += b;
	if(a >= MOD) a -= MOD;
}

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	for(int i=0; i < h; i++) scanf("%s", a[i]);
	dp[0][0] = 1;
	for(int i=0; i < h; i++) {
		for(int j=0; j < w; j++) {
			for(int row: {i, i+1}) {
				int col = j;
				if(row == i) col++;
				if(row < h && col < w && a[row][col] == '.')
					add_mod(dp[row][col], dp[i][j]);
			}
		}
	}
	printf("%ld\n", dp[h-1][w-1]);
}


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

int main(){
  int N,M,a,b;
  cin>>N>>M;
  vector<int> V[110000];

  for(int i=0;i<N;i++){
    cin>>a>>b;
    V[a].push_back(b);
  }

  priority_queue<int> p;
  ll ans=0;
  for(int i=1;i<=M;i++){
    for(int j=0;j<V[i].size();j++){
      p.push(V[i][j]);
    }
    if(p.empty()) continue;
    ans+=p.top();
    p.pop();
    //cout<<ans<<endl;
  }
  cout<<ans<<endl;
}


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

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

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

def main():
  n,y=LI()

  for i in range(n+1):
    for j in range(n+1-i):
      if i*10000+j*5000+(n-i-j)*1000==y:
        print(i,j,n-i-j)
        exit()
  print(-1,-1,-1)

main()


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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    rr = []

    while True:
        n,m,a = LI()
        if n == 0:
            break
        t = sorted([LI_() for _ in range(m)], reverse=True)
        r = list(range(n))
        for h,p,q in t:
            r[p],r[q] = r[q],r[p]

        rr.append(r.index(a-1)+1)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		Scanner scan=new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		PrintWriter pw=new PrintWriter(System.out);
		int t=scan.nextInt();
		Set<String> set=new HashSet<String>();
		while((t--)!=0){
			String s=scan.next();
			String ch=scan.next();
			if(s.equals("insert")){
				set.add(ch);
			}else{
				if(set.contains(ch))
					pw.println("yes");
				else
					pw.println("no");
			}
		}
		pw.close();
	}


}

Measured memory_bytes: 227412
<?php
fscanf(STDIN,'%d%d%d',$e,$n,$x);
$a=explode(" ",trim(fgets(STDIN)));
$ans=0;
for($i=0;$i<$n;++$i){
  $a[$i]<$x?++$ans:$i+=$n;
}
echo min($ans,$n-$ans);

Measured memory_bytes: 4856
s = int(input())
a = []
a.append(s)

for i in range(1000000):
  if a[i]%2==0:
    a.append(a[i]/2)
  else:
    a.append(a[i]*3+1)
  for j in range(i):
    if a[j]==a[i]:
      print(i+1)
      exit()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

vll a(51,-1);
vll p(51,-1);
ll func(ll x,int l){
	if(x==0) return 0;
	if(l==0) return 1;
	if(x<(a[l]+1)/2) return func(x-1,l-1);
	else return p[l-1]+1+func(min(x-2-a[l-1],a[l-1]),l-1);
}

int main(void) {
	int n; cin >> n;
	ll x; cin >> x;
	a[0] = 1;
	p[0] = 1;
	rep(i,n) a[i+1] = a[i]*2+3;
	rep(i,n) p[i+1] = p[i]*2+1;
	cout << func(x,n) << endl;
}


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

using namespace std;

typedef long double ld;

int K;
ld P, E, T;
bool check(ld t) {
	return abs(t-T) <= E;
}
ld dfs(double l, double r, int k) {
	double m = (l + r) / 2;
	if (k == K) {
		return check(m) ? 1 : 0;
	}
	else {
		if (T-E <= l && r <= T+E) {
			return 1;
		}
		else if (r < T-E || l > T+E) {
			return 0;
		}
		else if (m >= T) {
			return (1-P) * dfs(l, m, k+1) + P * dfs(m, r, k+1);
		}
		else {
			return P * dfs(l, m, k+1) + (1-P) * dfs(m, r, k+1);
		}
	}
}
int main() {
	int L, R; cin >> K >> L >> R;
	cin >> P >> E >> T;
	cout << fixed << setprecision(12) << dfs(L, R, 0) << endl;
}

Measured memory_bytes: 1300
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
 
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
 
using namespace std;
 
#define int long long
//typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;
 
const int INF=1e+9;
const double EPS=1e-9;
const int MOD=1000000007;
 
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};

signed main(){
	int n,s[100];
	bool dp[101][10001] = {};
	cin >> n;
	dp[0][0] = true;
	for(int i = 0;i < n;i++){
		cin >> s[i];
		for(int j = 0;j <= 10000;j++){
			if(j + s[i] <= 10000) dp[i + 1][j + s[i]] = dp[i + 1][j + s[i]] | dp[i][j];
			dp[i + 1][j] = dp[i + 1][j] | dp[i][j];
		}
	}
	int ma = 0;
	for(int i = 0;i <= 10000;i++){
		if(i % 10 != 0 && dp[n][i]){
			ma = max(ma,i);
		}
	}
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int N,X,L,a,i,j;
      cin >> N >> X;
      	a = 0;	//跳ねる座標
      	i = 0;	//ループカウント
      	j = 1;	//X内で跳ねる回数
      while(i < N){
      	cin >> L;
        a += L;
        	if (a > X){
            	i ++;
            }    
        	else if (a <= X){
              j ++;
        	  i ++;
      		}
        }

        cout << j << endl;
    	
	}

Measured memory_bytes: 256
import sys
import itertools
import queue
import numpy as np
input = sys.stdin.readline
sys.setrecursionlimit(100000)
# mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    X, Y ,Z = read_values()
    print(Z, X, Y)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21676
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int main()
{
	int n;
	cin >> n;
	cout << 48 - n << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <tuple>
#include <cassert>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define mp(a,b) make_pair((a), (b))
#define mt(a,b,c) make_tuple((a),(b),(c))

typedef long long ll;

int main(){
    int n,k; cin >> n >> k;
    vector<bool> v(n);
    rep(i,n) v[i] = false;
    rep(i,k){
        int d; cin >> d;
        rep(j,d){
            int a; cin >> a;
            v[a-1] = true;
        }
    }
    int c = 0;
    for(auto x: v) if(!x)c++;
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <algorithm>
    
int main(){
    std::vector<int> a(4);
        
    while(std::cin >> a[0] >> a[1] >> a[2] >> a[3]){
        int hit = 0, blow = 0;
            
        for(int i = 0; i < 4; ++i){
            int b;
            std::cin >> b;
                
            auto it = std::find(a.begin(), a.end(), b);
            if(it == a.begin() + i){
                ++hit;
            }else if(it != a.end()){
                ++blow;
            }
        }
        std::cout << hit << " " << blow << std::endl;
    }
       
    return 0;
}


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

long long f[3010][3010][4];
int r, c, k;
int v[3010][3010];

int main() {
	scanf("%d%d%d", &r, &c, &k);
	while (k--) {
		int x, y; scanf("%d%d", &x, &y);
		scanf("%d", &v[x][y]);
	}
	for (int i = 1; i <= r; ++i)
		for (int j = 1; j <= c; ++j) {
			f[i][j][0] = max(f[i][j - 1][0], f[i - 1][j][3]);
			for (int k = 1; k <= 3; ++k)
				f[i][j][k] = max(f[i][j][k - 1],
						max(f[i][j - 1][k],
							max(f[i][j - 1][k - 1],
								f[i - 1][j][3]) + v[i][j]));
		}
	printf("%lld\n", f[r][c][3]);
	return 0;
}



Measured memory_bytes: 321072
import math
N, M = map(int, input().split())
nums = list(map(int, input().split()))
lcm = 1
b_cnt = -1
for num in nums:
  lcm = lcm*(num//2)//math.gcd(lcm, num//2)
  count = 0
  while num%2 == 0:
    count += 1
    num //= 2
  if b_cnt < 0:
    b_cnt = count
  elif count != b_cnt:
    print(0)
    exit()
print((M+lcm)//(lcm*2))

Measured memory_bytes: 84796
//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

int dp[10][10];

int
main(void){  
  int h, w;
  cin >> h >> w;

  REP(i, 10) REP(j, 10) cin >> dp[i][j];

  int a;
  int vec[11] = {};
  REP(i, h*w) {
    cin >> a;
    ++a;
    ++vec[a];
  }

  /*
  REP(i, 11){
    cout << vec[i] << endl;
  }
  */

  REP(k, 10){
    REP(i, 10){
      REP(j, 10){
	dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
      }
    }
  }

  /*
  REP(i, 10) {
    REP(j, 10) {  
      cout << dp[i][j] << " ";
    }
    cout << endl;
  }
  */

  int ans = 0;
  FOR(i, -1, 10){
    if(i != -1){
      while(vec[i+1]>0){
	ans += dp[i][1];
	vec[i+1]--;
      }
    }
    //cout << i << " " << ans << endl;
  }

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


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

//Short data-types declaration
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vector<int> > vii;  
typedef vector<vector<long long> >vll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vbb;

//Macros
#define MK make_pair
#define EB emplace_back
#define PB push_back
#define F first
#define S second
#define rep(i,start,end) for(int i=(int)start;i<(int)end;i++)

void solve()
{
	int n;
	cin>>n;
	vi num(1e5+7,0);
	ll sum=0ll;
	rep(i,0,n)
	{
		int x;
		cin>>x;
		sum+=x;
		num[x]++;
	}
	int q;
	cin>>q;
	while(q--)
	{
		int b,c;
		cin>>b>>c;
		sum=sum-num[b]*1ll*b+num[b]*1ll*c;
		num[c]+=num[b];
		num[b]=0;
		cout<<sum<<endl;
	}	
}
int main()
{
	auto start = high_resolution_clock::now();
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t=1;
	while(t--)
		solve();
	auto stop = high_resolution_clock::now(); 
	auto duration = duration_cast<microseconds>(stop - start); 
	cerr<<duration.count()<<" microseconds\n";
	return 0;
}

Measured memory_bytes: 3768
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
#define mp make_pair
typedef long long ll;
int main(){
    string S;
    cin >> S;
    int ans = 0;
    REP(i,3) if(S[i] == '1') ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long       ll;
const ll  big =1e7+2;

ll a[big];

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

ll n;
cin>>n;
for(int i=1;i<=n;++i){
    for(int j=i;j<=n;j+=i){
        a[j]++;
    }
}
ll sum=0;
for(int i=1;i<=n;++i)
  sum+=i*a[i];

cout<<sum;
    return 0;
}

Measured memory_bytes: 81744
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //ai>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //ai>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
#define TO(x,t,f) ((x)?(t):(f))
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define FILV(x,a) fill(x.begin(),x.end(),a)
#define FILA(ar,N,a) fill(ar,ar+N,a)
#define NEXTP(x) next_permutation(x.begin(),x.end())
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define pb push_back
#define pri(aa) cout<<(aa)<<endl
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
const ll INF=1e18+7;
const ll MOD=1e9+7;
const ll N = 1007;

int main(){
	ll n;
	cin>>n;
	if(n==0){
		pri(0);
	}else{
		string s;
		ll k=1;
		while(n!=0){
			if(abs(n)&abs(k)){
				n-=k;
				s += "1";
			}else{
				s += "0";
			}
			k *= -2;
		}
		REV(s);
		pri(s);
	}
}

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

rl = []
gl = []
bl = []
rld = [0]*(n)
gld = [0]*(n)
bld = [0]*(n)

for i in range(len(s)):
  if s[i] == 'R':
    rl += [i]
    rld[i] = 1 
  elif s[i] == 'G':
    gl += [i]
    gld[i] = 1 
  else:
    bl += [i]
    bld[i] = 1

rlds = rld[:]
glds = gld[:]
blds = bld[:]

for i in range(n-1, 0, -1):
  blds[i-1] += blds[i]
  rlds[i-1] += rlds[i] 
  glds[i-1] += glds[i] 

ans = 0 
for i in rl:
  for j in gl:
    if i >= j or j+1 >= n:
      continue
    ans += blds[j+1]
    if j+j-i < n:
      ans -= bld[j+j-i]

for i in rl:
  for j in bl:
    if i >= j or j+1 >= n:
      continue
    ans += glds[j+1]
    if j+j-i < n:
      ans -= gld[j+j-i]

for i in gl:
  for j in bl:
    if i >= j or j+1 >= n:
      continue
    ans += rlds[j+1]
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in gl:
  for j in rl:
    if i >= j or j+1 >= n:
      continue
    ans += blds[j+1]
    if j+j-i < n:
      ans -= bld[j+j-i]
for i in bl:
  for j in gl:
    if i >= j or j+1 >= n:
      continue
    ans += rlds[j+1]
    if j+j-i < n:
      ans -= rld[j+j-i]

for i in bl:
  for j in rl:
    if i >= j or j+1 >= n:
      continue
    ans += glds[j+1]
    if j+j-i < n:
      ans -= gld[j+j-i]
    
print(ans)



Measured memory_bytes: 74768
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  I n;
  cin >> n;
  V v(n);
  VIN(v);
  I c=1;
  REP(i,n){
    if (v.at(i) == c){
      c++;
    }
  }
  I t = 0;
  if (n - c + 1 == n){
    t = -1;
  }else{
    t = n - c + 1;
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<iostream>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define INF 1 << 30
#define MAX 1000000000
#define SIZE 1000000000

int main() {
	char s[11];
	scanf("%s", s);
	puts(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I' ? "Yes" : "No");
	return 0;
}

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

int main(){
   char S[20];
   char T[21];
   scanf("%s",S);
   scanf("%s",T);
   int sizeS=strlen(S);
   int sizeT=strlen(T);
   int cnt=0;
   
   if(sizeS>=1&&sizeS<=10&&sizeT==sizeS+1){
      for(int i=0;S[i]!='\0';i++){
         if(S[i]==T[i]){
            cnt++;
         }
      }
      if(cnt==sizeS&&T[sizeT-1]>=97&&T[sizeT-1]<=122){
         printf("Yes");
      }
      else{
         printf("No");
      }
   }
   return 0;
}

Measured memory_bytes: 1716
#E
N,P=map(int,input().split())
S=input()
ans=0
if P in (2,5):
    for i,s in enumerate(S):
        if int(s)%P==0:
            ans+=i+1
else:
    cnt=[0 for _ in range(P)]
    CS=0
    PLC=1
    for s in S[::-1]:
        tmp=(int(s)*PLC)%P
        CS=(CS+tmp)%P
        cnt[CS]+=1
        PLC=(PLC*10)%P
        # print(CS)
        # print(cnt)
    for c in cnt:
        ans+=c*(c-1)//2
    ans+=cnt[0]
print(ans)

Measured memory_bytes: 3500
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		ArrayList<Character> ans = new ArrayList<Character>();
		Scanner sc = new Scanner(System.in);
		String  s  = sc.next();
		char[]  _s = s.toCharArray();
		for(int i=0;i<_s.length;i++) 
			if(i % 2 == 0)	System.out.print(_s[i]);
		System.out.println("");
	}

}


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

int main() {
    int m,f,r;
    string grade;
    string grade_pattern[5]{
        "A","B","C","D","F"
    };
    while(1){
        cin >> m >> f >> r;
        if(m==-1&&f==-1&&r==-1) break;
        if(m<0||f<0){
            grade = grade_pattern[4];
        }else if((m+f)>=80){
            grade = grade_pattern[0];
        }else if((m+f)>=65){
            grade = grade_pattern[1];
        }else if((m+f)>=50){
            grade = grade_pattern[2];
        }else if((m+f)>=30){
            if(r>=50)grade = grade_pattern[2];
            else grade = grade_pattern[3];
        }else{
            grade = grade_pattern[4];
        }
        cout << grade << endl;
    }
    return 0;
}


Measured memory_bytes: 3128
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <utility>
#include <vector>

#define MAX_N (100000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long n, as[MAX_N], bs[MAX_N];
  scanf("%ld", &n);
  for (int i = 0; i < n; i++) {
    scanf("%ld %ld", &as[i], &bs[i]);
  }

  // solve
  long ans = 0, ti = n - 1, ai = n - 1;
  vector<pair<long, long>> taks, aoks;
  vector<int> us(n, 0);
  for (int i = 0; i < n; i++) {
    taks.push_back(make_pair(as[i] + bs[i], i));
    aoks.push_back(make_pair(bs[i] + as[i], i));
  }
  sort(taks.begin(), taks.end());
  sort(aoks.begin(), aoks.end());
  for (int i = 0; i < n; i++) {
    // printf("i = %d, ti = %ld, ai = %ld\n", i, ti, ai);
    if (i % 2 == 0) {
      while (us[taks[ti].second]) {
        ti--;
      }
      ans += as[taks[ti].second];
      us[taks[ti].second] = 1;
    } else {
      while (us[aoks[ai].second]) {
        ai--;
      }
      ans -= bs[aoks[ai].second];
      us[aoks[ai].second] = 1;
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 6504
#include"bits/stdc++.h"
#include"math.h"
using namespace std;

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

using ll = long long int;
using ld = long double;
using pii = pair<int,int>;

#define REP(i,m,n) for(ll i = m; i < (ll)(n);++i)
#define rep(i,n) REP(i,0,n)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
 
using vi=vc<int>;

const ll mod=1e9+7;
const ll INF = 1e18;
const int MAX = 8000;
const int MOD = 1000000007;

struct edge{
  ll to;
  ll id;
};

vector<vector<edge>> g;
vector<ll> ans;
// nowのv,親のp,色のcol
void dfs(ll v, ll p, ll col){
  ll num=1;
  rep(i,g[v].size()){
    ll x=g[v][i].to;
    ll y=g[v][i].id;
    if(x==p)continue;
    if(col==num)num++;
    ans[y]=num;
    num++;
    dfs(x,v,ans[y]);
  }
}

int main(){
  ll n;cin >> n;
  g.resize(n);
  ans.resize(n);
  rep(i,n-1){
    int a,b;cin >> a>> b;a--;b--;
    g[a].push_back((edge){b,i});
    g[b].push_back((edge){a,i});
  }
  dfs(0,-1,-1);
  ll k=0;
  rep(i,n-1){k=max(k,ans[i]);}
  cout << k << endl;
  rep(i,n-1) cout << ans[i] << endl;
}

Measured memory_bytes: 9728
// lcmとかはg++ -std=c++17 default.cppみたいなかんじで
//vector<vector<ll>> piyo(tate,vector<ll> (yoko));

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1000000000
#define ll long long
#define ln cout<<endl;
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define double long double
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
ll target;

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

    ll maxi=0,f=0,mini=INF,sum=0;
    string stra,str2;
    ll h,w;
    ll n,x,m;
    ll a,b,d,c;
    multiset<int> s;
    cin>>n>>a>>b;
    for(ll i=1;i<=n;i++){
        f=i;
        while(f){
            sum+=f%10;
            f/=10;
        }
        if(a<=sum&&sum<=b) maxi+=i;
        //cout<<i<<" ";
        sum=0;
    }
    cout<<maxi<<endl;


    return 0;
}


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

using namespace std;

int main()
{
    int a,b,t;
    cin>>a>>b>>t;
    int count=0;
    t=t+0.5;
    for(int i=a;i<=t;i=i+a)
    {
        count=count+b;
    }
    cout<<count<<endl;
    return 0;
}


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

#define deb(var) cout << "[" << (#var) << " : " << var <<"]" << " "
#define debv(v) cout << "[" << (#v) << " : {";for(int i = 0; i < v.size() - 1; ++i)\
					cout << v[i] <<", ";cout << v.back() << "}] "
#define deba(a,n) cout << "[" << (#a) << " : {";for(int i = 0; i < n - 1; ++i)\
					cout << a[i] << ", ";cout << a[n - 1] << "}] "
#define debp(p) cout << "[" << (#p) << " : {" << p.first << ", " << p.second << "}] "
#define debs(s) cout << "[" << (#s) << " : {";auto _itr = s.begin();\
					for(int k = s.size(); k > 1; --k) {cout << *_itr << ", "; ++_itr;} cout << *_itr << "}] "

typedef long long ll;

/*LETS BEGIN WITH THE NAME OF LORD MAHADEV*/
const int mxN = 1e5;
int ar[mxN];

int main(){
	long long arr[5];
	for(int i = 0; i < 5; ++i){
		cin >> arr[i];
		if(arr[i] == 0){
			cout << i + 1 << endl;
			exit(0);
		}
	}
	return 0;
}

Measured memory_bytes: 3676
a,b,c = map(int, input().split())
if(a>b):
  x=a
  a=b
  b=x 
else:
  pass

if(b>c):
  y=b
  b=c
  c=y
else:
  pass
if(a>b):
  z=a
  a=b
  b=z
else:
  pass
print(a,b,c)



Measured memory_bytes: 5596
#include <iostream>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    int a[100][2];
    for (int i=0; i<n; i++){
        cin >> a[i][0] >> a[i][1];
    }
    //ループの終了条件に注意
    for (int i=0; i<n-2; i++){
        if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3628
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int, int> P;
int n, w, d, p[100], s[100];

int H[101], W[101];

int main() {
  while (1) {
    scanf("%d%d%d", &n, &w, &d);
    if (w == 0) break;
    vector<P> ans;
    ans.push_back(P(w, d));
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &p[i], &s[i]);
      P temp = ans[p[i] - 1];
      ans.erase(ans.begin() + p[i] - 1);
      int w = temp.first, h = temp.second;
      s[i] %= (w + h);
      if (s[i] > w) {
        int h1 = s[i] - w, h2 = w + h - s[i];
        if (h1 > h2) ans.push_back(P(w, h2)),ans.push_back(P(w, h1));
        else ans.push_back(P(w, h1)),ans.push_back(P(w, h2));
      } else {
        int w1 = s[i], w2 = w - s[i];
        if (w1 > w2) ans.push_back(P(w2, h)),ans.push_back(P(w1, h));
        else ans.push_back(P(w1, h)),ans.push_back(P(w2, h));
      }
    }
    int size = ans.size();
    int mul[110];
    for (int i = 0; i < size; i++) mul[i] = ans[i].first * ans[i].second;
    sort(mul, mul + size);
    for (int i = 0; i < size; i++) printf("%d%c", mul[i], i == size - 1? '\n' : ' ');
  }
}



Measured memory_bytes: 2628
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <string>
#include <stdio.h>

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

using namespace std;

int main()
{
    int L;
    double tmp;

    cin >> L;

    tmp = (double)L / 3;
    tmp = tmp * tmp * ((double)L - 2*tmp);

    printf("%.7f\n", tmp);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
template<class T = int> using V = vector<T>;

int main() {
    int n; cin >> n;
    if (n == 1) {
        cout << "! 1" << endl;
        return 0;
    }
    int mx = -1, mi = -1;
    for (int i = 2; i <= n; ++i) {
        cout << "? 1 " << i << endl;
        int x; cin >> x;
        if (x > mx) {
            mx = x;
            mi = i;
        }
    }
    V<> res(n);
    for (int i = 1; i <= n; ++i) {
        cout << "? " << mi << ' ' << i << endl;
        int x; cin >> x;
        res[x] = i;
    }
    cout << "!";
    for (int e : res) cout << ' ' << e;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3620