akhauriyash/Code-Regression huggingface dataset:
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
ulong bignum = 1_000_000_007;
alias SugarWater = Tuple!(long, "swater", long, "sugar");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void main()
{
    auto n = lread();
    long[string] dict;
    foreach (_; iota(n))
    {
        auto s = sread();
        auto tmp = (cast(ubyte[]) s);
        tmp.sort();
        s = cast(string) tmp;
        if (s in dict)
            dict[s]++;
        else
            dict[s] = 1;
    }
    long ans;
    foreach (e; dict)
        if (e > 1)
            ans += e * (e - 1) / 2;
            
    ans.writeln();
}

Measured memory_bytes: 9980
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b;
  b=a/1000;
  int c;
  c=a%1000;
  int d;
  d=c/100;
  int e;
  e=c%100;
  int f;
  f=e/10;
  int g;
  g=e%10;
  if(b==d&&d==f){
    cout<<"Yes"<<endl;
  }
  else if(d==f&&f==g){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
int n,k,i,a,ans;
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a);
ans=(n-1)/(k-1);
if((n-1)%(k-1)!=0)
ans++;
printf("%d\n",ans);
return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int sum = 0;
  
  for(int j=1; j<N; j++){
    sum += vec.at(j);
  }
  
  if(sum > vec.at(0)){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
  
  
}
    




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int main() {
    int N;
    cin >> N;
    int count = 0;
    bool passed = false;
    for (int i = 1; i <= N; i++) {
        int a;
        cin >> a;
        if (a != i - count) {
            count++;
        } else {
            passed = true;
        }
    }
    cout << (passed ? count : -1) << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
// 型シノニム
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
// 定数
constexpr ll INF   = 1e16;
constexpr ll INM   = 114514;
constexpr ll MOD   = 1e9 + 7;
constexpr ld EPS   = 1e-12;
constexpr ll dx[4] = {1, 0, -1, 0};
constexpr ll dy[4] = {0, 1, 0, -1};
// 便利関数
void IOS() { ios::sync_with_stdio(false), cin.tie(0); }
template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, ll t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll mod) {
	if (a > 0) return a % mod;
	if (a % mod == 0) return 0;
	ll x = -a / mod + 1;
	a += x * mod;
	return a % mod;
}
ll powm(ll a, ll b, ll m) {
	if (b == 0) {
		return 1;
	} else if (b % 2 == 0) {
		ll d = powm(a, b / 2, m);
		return (d * d) % m;
	} else {
		return (powm(a, b - 1, m) * a) % m;
	}
}

// 本体


int main() {
	IOS();
	ll n;
	cin >> n;
	ll now = 1;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		if(a == now) {
			now++;
		}
	}
	if(now == 1) {
		dump(-1);
	}else {
		dump(n - now + 1);
	}
}

Measured memory_bytes: 3600
#include<stdio.h>




int main()
{
  unsigned long int a[5],n;
  int i,min;

  scanf("%lu",&n);
  min=0;
  for(i=0;i<5;i++)
    {
      scanf("%lu",&a[i]);
      if(a[i]<a[min])
	{
	  min=i;
	}
    }

  unsigned long int k;
  k=(a[min]+n-1)/a[min]+4;

  printf("%lu\n",k);
  return 0;
}



Measured memory_bytes: 128
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors



n = int(input())
x = make_divisors(n)

if len(x) % 2 == 0:
    a = x[int((len(x)-1)/2)]
    b = x[int((len(x)+1)/2)]
else:
    a = x[int(len(x)/2)]
    b = x[int(len(x)/2)]

print(a+b-2)
    


 

 


                                        




    




        


    







        



Measured memory_bytes: 3296
#include <algorithm>
#include <iostream>
#include <set>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;

set<int> divisorList(int n) {
    set<int> div;
    for (int i = 1; i <= n; i++) {
        if (n % i == 0){
            div.insert(i);
            if (i * i != n)
                div.insert(n / i);
        }
    }
    return div;
}

set<int> commonDivList(int a, int b) {
    set<int> aDiv = divisorList(a);
    set<int> bDiv = divisorList(b);
    set<int> res;
    set_intersection(aDiv.begin(), aDiv.end(),
            bDiv.begin(), bDiv.end(),
            inserter(res, res.end()));
    return res;
}

void solve(long long A, long long B, long long K){
    set<int> ans;
    ans = commonDivList(A, B);
    auto itr = ans.end();
    REP(i, K) itr--;
    cout << *itr << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  int r, g, b, n;
  cin >> r >> g >> b >> n;

  int count = 0;
  for(int i = 0; i * r <= n; i++){
    for(int j = 0; j * g + i * r <= n; j++){
      int tar = n - (i * r + j * g);
      if(tar >= 0 && tar % b == 0) ++count;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector < long long > vll;
typedef pair <long long, long long> pll;
typedef pair <int, int> pii;
typedef vector < int > vii;
typedef complex < double > Point;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define fst first
#define snd second

ll t, n, m, u, v, q, r, ql, qr, k, l, w, x, y, d, c, a, s;
const int N = 1e5 + 500;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 61LL;

vector <int> adj[N];
// visible means there's no bigger label b/w path from node in subtree of v to v
int solve(int v, int p) { // returns mask of visible node labels
  int vis[30] = {0};
  int assign = 0; // minimum possible label for v
  for (int u : adj[v]) {
    if (u == p) continue;
    int mask = solve(u, v);
    for (int j = 0; j < 30; ++j) {
      if (mask & (1 << j)) {
        vis[j]++;
        if (vis[j] == 2) assign = max(assign, j + 1);
      }
    }
  }
  while (vis[assign] > 0) assign++;
  int ret = (1 << assign); // will be visible to parent
  for (int j = assign + 1; j < 30; ++j) {
    if (vis[j]) ret |= (1 << j); // will still be visible to parent
  }
  return ret;
}// when the answer for root is returned the tree is splitted into regions which are connected by single edges
// merge trees with smaller node labels to ones with larger
// in the end we will have a single tree with node label = largest node lable visible to root
int main() {
  csl;
  cin >> n;
  for (int i = 0; i < n - 1; ++i) {
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  
  int get = solve(1, 0);
  int cnt = -1;
  while (get) {
    cnt++;
    get /= 2;
  }// highest visible node label
  cout << cnt << '\n';
  return 0;
}























Measured memory_bytes: 19456
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair< int, int > Pi;
typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const long long INF = 5e18;
const int di[4] = { 1,0,-1,0 };
const int dj[4] = { 0,1,0,-1 };

#define fr first
#define sc second
#define pb push_back
#define eb emplace_back
#define ALL(x) (x).begin(),(x).end()

ll n,rui[1000010],mc[1000010],mm[1000010];
string s;
ll q,k;

void input(){
	cin>>n>>s>>q;
	return;
}


void solve(){
	while(q--){
		cin>>k;
		ll ans=0;
		queue<ll>d,m;		
		for(int i=0;i<s.size();i++){
			if(s[i]=='C')rui[i+1]=rui[i]+1;
			else rui[i+1]=rui[i];
			if(s[i]=='M')mm[i+1]=mm[i]+1;
			else mm[i+1]=mm[i];
		}
		for(int i=0;i<s.size();i++){
			if(s[i]=='M')mc[i+1]=mc[i]+rui[i+1];
			else mc[i+1]=mc[i];
		}
		for(ll i=0;i<s.size();i++){
			if(s[i]!='D')continue;
			int nex=min(n-1,i+k-1);
			ll t=(mm[nex+1]-mm[i+1])*rui[nex+1];
			t-=mc[nex+1]-mc[i+1];
			ans+=t;
		}
		cout<<ans<<endl;
	}
	return;
}

int main(){
	input();
	solve();
	return 0;
}


Measured memory_bytes: 24836
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1001001001
#define LINF 1001001001001001001
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

int main() {

    int N, P;
    cin >> N >> P;
    string S;
    cin >> S;

    vector<int> A(N), M(N + 1, 0);

    rep(i,N) A[i] = S[N - 1 - i] - '0';

    ll ans = 0;
    if (P == 2 || P == 5) {
        rep(i,N) if (A[i] % P == 0) ans += N - i;
        cout << ans << endl;
        return 0;
    }

    ll ten = 1;
    rep(i,N) {
        M[i + 1] = M[i] + ten * A[i];
        M[i + 1] %= P;
        ten *= 10;
        ten %= P;
    }
    vector<int> modCount(P, 0);
    rep(i,N + 1) {
        ans += modCount[M[i]];
        modCount[M[i]]++;
    }

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

Measured memory_bytes: 5224
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = map(int, read().split())

    E = [0]* (N)
    for a in A:
        E[a-1] += 1

    for e in E:
        print(e)



if __name__ == "__main__":
    main()


Measured memory_bytes: 32448
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    double n, m, d, ans;
    cin >> n >> m >> d;

    if(d == 0) {
        ans = (m-1)/n;
    }
    else {
        ans = 2.0*(n-d)*(m-1)/(n*n);
    }

    printf("%.7f\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

/////////////

map<int,int> m;
map<int,int> si;
int find(int x)
{
	if(m[x]==x)
		return x;
	m[x]=find(m[x]);
	return m[x];
}
void mer(int a,int b)
{
	a=find(a);
	b=find(b);
	if(a==b)
		return;
	if(si[a]<si[b])
		swap(a,b);
	m[b]=a;
	si[a]+=si[b];
}
signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int n;
	cin>>n;
	int p[n][2];
	map<int,vector<int>> y;
	map<int,vector<int>> x;
	for(int i=0;i<n;++i)
	{
		cin>>p[i][0]>>p[i][1];
		y[p[i][1]].push_back(p[i][0]);
		x[p[i][0]].push_back(p[i][1]);
		m[p[i][0]]=p[i][0];
		si[p[i][0]]=1;
	}
	for(auto r:y)
	{
		for(int i=1;i<r.S.size();++i)
		{
			mer(r.S[i],r.S[i-1]);
		}
	}
	map<int,set<int>> xmi,ymi;
	for(auto r:x)
	{
		int a=find(r.F);
		xmi[a].insert(r.F);
		for(auto rr:r.S)
		{
			ymi[a].insert(rr);
		}
	}
	int ans=-n;
	for(auto r:xmi)
	{
		ans+=r.S.size()*(ymi[r.F].size());
	}
	cout<<ans;
}

Measured memory_bytes: 26624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		sc.nextLine();
		String s = sc.nextLine();
		Board b = new Board(s);
		int maxGcd = 0;
		int gcd;
		for(int i = 0; i < b.length; i++) {
			gcd = b.getBoardGcd(i);
			if(maxGcd < gcd) {
				maxGcd = gcd;
			}
		}
		System.out.println(maxGcd);
	}
}
class Board{
	int[] board;
	int length;
	boolean[] dup;
	int dupGcd = -1;
	Board(String s){
		String[] sAry = s.split(" ");
		board = new int[sAry.length];
		dup = new boolean[sAry.length];
		length = board.length;
		for(int i = 0; i < sAry.length; i++) {
			board[i] = Integer.parseInt(sAry[i]);
			dup[i] = false;
			for(int i2 = 0; i2 < i; i2++) {
				if(board[i] == board[i2]){
					dup[i] = true;
					break;
				}
			}
		}
	}
	int getBoardGcd(int n) {
		if(dup[n] && dupGcd > 0) {
			return dupGcd;
		}
		int gcd = -1;
		for (int i = 0; i < board.length; i++) {
			if(i != n) {
				gcd = getGcd(gcd, board[i]);
			}
		}
//		System.out.println(gcd);
		if(dup[n]) {
			dupGcd = gcd;
		}
		return gcd;
	}
	int getGcd(int i, int i2) {
		int max = Math.max(i, i2);
		int min = Math.min(i, i2);
		if(min < 0) {
			return max;
		}
		int mod = max % min;
		if(mod == 0) {
			return min;
		}
		return getGcd(min, mod);
	}
}


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

#define N 15

int main() {
	static int aa[N], xx[N][N - 1], yy[N][N - 1], honest[N];
	int n, i, j, b, k, yes, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", &aa[i]);
		for (j = 0; j < aa[i]; j++)
			scanf("%d%d", &xx[i][j], &yy[i][j]), xx[i][j]--;
	}
	ans = -1;
	for (b = 0; b < 1 << n; b++) {
		memset(honest, 0, n * sizeof *honest);
		for (i = 0; i < n; i++)
			if (b & 1 << i)
				honest[i] = 1;
		yes = 1;
		k = 0;
		for (i = 0; i < n; i++)
			if (honest[i]) {
				k++;
				for (j = 0; j < aa[i]; j++)
					if (honest[xx[i][j]] != yy[i][j])
						yes = 0;
			}
		if (yes && ans < k)
			ans = k;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
using System;

class icpc2007dA{
  static void Main(){
    int i, n, s, ma, mi, sum;
    while(true){
      ma=0; mi=1000; sum=0;
      n=int.Parse(Console.ReadLine());
      if(n==0)return;
      for(i=0;i<n;i++){
        s=int.Parse(Console.ReadLine());
        ma=ma>s?ma:s;
        mi=mi<s?mi:s;
        sum+=s;
      }
      Console.WriteLine((sum-ma-mi)/(n-2));
    }
  }
}

Measured memory_bytes: 5652
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>

using namespace std;

// common
#define X real()
#define Y imag()

using Vector2 = complex<double>;
using Line = pair<Vector2, Vector2>;
using Segment = pair<Vector2, Vector2>;
const double EPS = 1e-10;
const double PI = 3.14159265359;

bool isSame(double a, double b){
    if(abs(a - b) < EPS){
        return true;
    }
    else{
        return false;
    }
}

// struct

struct Circle{
    Vector2 c;
    double r;
    Circle(Vector2 c, double r){
        this->c = c;
        this->r = r;
    }
};

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

// isOrthogonal
double isArg90(Vector2 a, Vector2 b){
    return isSame(dot(a, b), 0.0);
}

double isArg90(Line l1, Line l2){
    return isArg90(l1.second - l1.first, l2.second - l2.first);
}

// isParallel
double isArg180(Vector2 a, Vector2 b){
    return isSame(cross(a, b), 0.0);
}

double isArg180(Line l1, Line l2){
    return isArg180(l1.second - l1.first, l2.second - l2.first);
}

int main(){

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;

        Segment s1(Vector2(x0, y0), Vector2(x1, y1));
        Segment s2(Vector2(x2, y2), Vector2(x3, y3));

        if(isArg180(s1, s2)){
            cout << 2 << endl;
        }
        else if(isArg90(s1, s2)){
            cout << 1 << endl;
        }
        else{
            cout << 0 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3088
from operator import itemgetter
n,m=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
l.sort(key=itemgetter(1))
mini,ans=l[0][1],1
for i in range(1,m):
  if mini<=l[i][0]:
    ans+=1
    mini=l[i][1]
print(ans)

Measured memory_bytes: 29152
#include <iostream>
#include <vector>
using namespace std;
int N, M, Q;
int a[50], b[50], c[50], d[50];
int max_score = 0;

int calc_score(vector<int> s) {
    int score = 0;
    for (int i = 0; i < Q; i++) {
        if ((s[b[i] - 1] - s[a[i] - 1]) == c[i]) {
            score += d[i];
        }
    }
    return score;
}

void dfs(int n, vector<int> s) {
    if (s.size() >= N) {
        int score = calc_score(s);
        if (score > max_score) {
            max_score = score;
        }
        return;
    }
    for (int i = n; i < M; i++) {
        vector<int> ss = s;
        ss.push_back(i + 1);
        dfs(i, ss);
    }
}

void solve() {
    //dfsで数列を生成する
    for (int i = 0; i < M; i++) {
        vector<int> seq; seq.push_back(i+1);
        dfs(i, seq);
    }
}

int main() {
    cin >> N >> M >> Q;
    for (int i = 0; i < Q; i++) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    solve();
    cout << max_score;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF  = 0x3f3f3f3f;
const ll  mod  = 1e9 + 7;
const ll  N = 1e6 + 5;

ll n,a[N],cnt[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	sort(a+1,a+1+n);
	// n=unique(a+1,a+1+n)-a-1;
	// // for(int i=1;i<=n;i++){
	// // 	cout<<a[i]<<" \n"[i==n];
	// // }
	ll ans=0;
	for(int i=1;i<=n;i++){
		if(cnt[a[i]]>1) continue;
		bool ok=true;
		for(ll j=1;j*j<=a[i];j++){
			if(a[i]%j==0){
				// cout<<"j="<<j<<'\n';
				if(cnt[j] && j!=a[i]) {
					// cout<<"fk111   \n";
					ok=false;break;
				}
				if(cnt[a[i]/j] && a[i]/j!=a[i]) {
					// cout<<"fk2222   \n";
					ok=false;break;
				}
				// cout<<"ok="<<ok<<'\n';
			}
		}
		if(ok){
			ans++;
			// cout<<a[i]<<'\n';
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 12960
n, m = gets.chomp.split.map(&:to_i)
result = "No"
if n >= m
    a = []
    n.times{a << gets.chomp}
    b = []
    m.times{b << gets.chomp}
    for y in 0..(n-m)
        for x in 0..(n-m)
            c = []
            m.times{|i| c << a[y+i][x, m]}
            if c == b
                result = "Yes"
                break
            end
        end
    end
end
puts result

Measured memory_bytes: 2044
#include<cstdio>
#include<cstring>
using namespace std;
int Fst[100005][26],cnt[26],ls,lt,zj1,zj2;
long long ans;
char S[100005],T[100005];
int main()
{
	scanf(" %s %s",S+1,T+1);
	ls=strlen(S+1);
	lt=strlen(T+1);
	for(int i=ls;i>=1;i--)
	for(int j=0;j<26;j++)
	Fst[i][j]=(S[i]-'a'==j?i:Fst[i+1][j]);
	for(int i=1;i<=lt;i++)
	if(!Fst[1][T[i]-'a'])
	{
		printf("-1");
		return 0;
	}
	zj1=1;
	while(zj1!=lt+1)
	{
		zj2=0;
		while(Fst[zj2+1][T[zj1]-'a']&&zj1!=lt+1)
		zj2=Fst[zj2+1][T[zj1]-'a'],zj1++;
		if(zj1==lt+1)
		ans+=zj2;
		else
		ans+=ls;
	}
	printf("%lld",ans);
	return 0;
}

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

typedef long long ll;

const ll MOD = 1e9 + 7;
ll N, M;
vector<bool> Ok;
vector<ll> Dp;

int main() {
  cin >> N >> M;
  Ok.resize(N + 1, true);
  for (ll i = 0; i < M; ++i) {
    ll a;
    cin >> a;
    Ok[a] = false;
  }
  Dp.resize(N + 1);
  Dp[0] = 1;
  for (ll i = 1; i <= N; ++i) {
    if (Ok[i - 1]) (Dp[i] += Dp[i - 1]) %= MOD;
    if (i >= 2 && Ok[i - 2]) (Dp[i] += Dp[i - 2]) %= MOD;
  }
  cout << Dp[N] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, a[100];
    cin >> n;
    REP(i, n){
        cin >> a[i];
    }
    REP(i, n) {
        if (i) {
            cout << " ";
        }
        cout << a[n - i - 1];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3220
using System;
using System.Linq;

namespace A___Apple_Pie
{
    class Program
    {
        static void Main(string[] args)
        {
            var AP = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = AP[0], P = AP[1];

            Console.WriteLine((3 * A + P) / 2);
        }
    }
}


Measured memory_bytes: 11348
#include<stdio.h>

int main(){
  int cou,i,j,k,l,val;

  while((scanf("%d",&val)) != EOF){
    cou=0;
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	for(k=0;k<10;k++){
	  for(l=0;l<10;l++){
	    if(i+j+k+l == val)cou++;
	  }
	}
      }
    }
    printf("%d\n",cou);
  }
  return 0;
}

Measured memory_bytes: 0
N,K,Q = map(int, input().split())
P = [0 for _ in range(N)]
for q in range(Q):
    num = int(input())
    P[num - 1] += 1

val = K - Q
if val > 0:
    for i in range(N):
        print('Yes')
else:
    standard = abs(val) + 1
    for i in range(N):
        if P[i] >= standard:
            print('Yes')

        else:
            print('No')

Measured memory_bytes: 4604
#include <stdio.h>
#include <algorithm>

int A, B, C, D, P;
int X, Y;

int main(void) {
	scanf("%d%d%d%d%d", &A, &B, &C, &D, &P);
	X = P*A;
	if (C >= P) { Y = B; }
	else { Y = B + (P - C)*D; }
	printf("%d\n", std::min(X, Y));
	return 0;
}

Measured memory_bytes: 2708
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = n;i >= m;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define ALL(n) n.begin(),n.end()

int main() {
	string s, ans = {};
	cin >> s;
	REP(i, s.size()) {
		if (s[i] == '0') ans = ans + '0';
		else if (s[i] == '1') ans = ans + '1';
		else if(ans.size()!=0)ans.erase(ans.end() - 1);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ 0022
#include <cstdio>
#include <cstring>

int main(void)
{
    int n;
    int num[5001];
    int sum;
    int max;
    
    while (scanf("%d", &n)){
        if (n == 0) break;
        
        memset(num, 0, 5001);
        for (int i = 0; i < n; i++){
            scanf("%d", &num[i]);
        }
        max = num[0];
        
        for (int i = 0; i < n; i++){
            sum = 0;
            for (int j = i; j < n; j++){
                sum += num[j];
                if (max < sum) max = sum;
            }
        }
        
        printf("%d\n", max);
    }
}

Measured memory_bytes: 1044
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,a,b;
    cin>>n>>a>>b;
    if(n>1&&b>=a||n==1&&a==b) cout<<(n-2)*(b-a)+1<<endl;
    else cout<<0<<endl;
    return 0;
    /*hfgjcybrfewkucvyrewkrhadgjsahdgjsadhsajdhgajdhs
    aidyaufgdjafbjhcbsftgyaeuf覅十多个努我有hisUK十二*/
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
      
        

		// 出力
		System.out.println(2 * b - a);
	}
}

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

using ll = long long;

ll N;

int rec(ll v = 0, int f753 = 0)
{
    if (v > N) return 0;

    int res = 0;

    if (f753 == 7)
        res++;

    res += rec(v * 10 + 3, f753 | 1);
    res += rec(v * 10 + 5, f753 | 2);
    res += rec(v * 10 + 7, f753 | 4);

    return res;
}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
 
    cin >> N;
    cout << rec() <<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const ll MAX=200005;
const ll MOD=2100000000;
ll a[MAX],b[MAX],sum,m=MOD,n;
int main(){
    ll t;
    scanf(" %lld",&n);
    for(ll i=0;i<n;i++){ scanf(" %lld %lld",&a[i],&b[i]);
        sum+=a[i];
        if(a[i]>b[i]) m=min(b[i],m);
    }
    if(m==MOD) printf("0\n");
    else printf("%lld\n",sum-m);
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;

// a^n MOD を計算する
long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

int main(){
  ll N; cin >> N;
  vector<ll> a(N); rep(i,N) cin >> a[i];

  ll s = 0, x = 0;
  s = a[0] + a[1];
  for(ll i = 2; i < N; i++){
    x ^= a[i];
  }

  ll d = s - x;
  if(d < 0 or d % 2 == 1) cout << -1 << endl;
  else{
    d /= 2;
    // 関係ないところで消さなきゃいけない
    if((d & x) != 0) cout << -1 << endl;
    else{
      bitset<50> bs(x);
      // maxの値はxの中からa[0] - dの値
      ll ans = a[0] - d;
      for(ll i = 49 ; i >= 0; i--){
        if(bs.test(i) and ans > modpow(2, i)){
          ans -= modpow(2, i);
        }
      }
      if(ans == a[0] or ans < 0) cout << -1 << endl;
      else cout << ans << endl;
    }
  }
}


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

using namespace std;
#define int long long
const int p=(1e9+7);
int po(int a,int b)
{
    if(b==0)
    {
        return 1;
    }
    if(b==1)
    {
        return a;
    }
    if(b%2==0)
    {
        int u=po(a,b/2);
        return (u*u)%p;
    }
    int u=po(a,b-1);
    return (a*u)%p;
}
int inv(int x)
{
    return po(x,p-2);
}
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n;
    cin>>n;
    vector <int> a(n);
    for(int i=0;i<n;++i)
    {
        cin>>a[i];
    }
    int ans=0;
    int d[n+2];
    d[0]=0;
    for(int i=1;i<=n;++i)
    {
        d[i]=d[i-1]+inv(i);
        d[i]%=p;
    }
    for(int i=0;i<(n-1);++i)
    {
        ans+=(a[i+1]-a[i])*d[i+1];
        ans%=p;
    }
    for(int i=1;i<=(n-1);++i)
    {
        ans*=i;
        ans%=p;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>


#define int  long long
#define rep(i,begin,end) for(__typeof(end)i=(begin)-((begin)>(end));i!=(end)-((begin)>(end));i+=1-2*((begin)>(end)))
// rep(i,1,10) is from 1 to 9 and rep(I,10,1) is from 9 to 1
#define F first
#define S second
#define sz(x) ((int)x.size())
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define pf push_front
#define eb emplace_back 
#define all(v) (v).begin(), (v).end()
#define mod 1000000007
#define mi multiset<int>
#define mii multiset<pii>
#define what_is(x) cerr << #x << " is " << x <<"\n";
#define sortA(v) sort(v.begin(), v.end())
#define sortD(v) sort(v.rbegin(), v.rend())
#define PI 3.14159265358979323846
#define vout(a) for(auto x:a) cout<<x<<" ";

// #define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>


// using namespace __gnu_pbds;
using namespace std;

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

int modp(int a,int n)
{
    n=n%(mod-1);
    a=a%mod;
    int res=1;
    while(n>0)
    {
        if(n&1) res=(res*a)%mod;
        a=(a*a)%mod;
        n>>=1;
    }
    return res;
}


vi adj[100005],color(100005);
vector<bool> vis(100005,false);
int cnt=0;

void dfs(int s)
{
    vis[s]=true;
    cnt++;
    // color[s]=clr;
    for(int u:adj[s])
    {
        if(!vis[u])
        {
            vis[u]=true;
            dfs(u);
        }
    }
    // order.pb(s);
}


void solve()
{
    int t,n,m,i,k,l,r,u,v,w,j,s,sum=0,flag=0,count=0;
    string S,T,U;
    // int a,b,c,d;
    cin>>k>>S;
    n=sz(S);
    if(n<=k) cout<<S;
    else
    {
        rep(i,0,k) cout<<S[i];
        cout<<"...";
    }

}




signed main()
{
    #ifndef ONLINE_JUDGE 
       freopen("input.txt","r",stdin);
       freopen("output.txt","w",stdout);
    #endif
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 6236
class Q1150
  @@field = nil;
  @@dp = nil;
  @@w = 0;
  @@h = 0;
  @@pos = Struct.new("Pos", :x, :y, :bRight)
  @@queue = Array.new
  LEFTFOOT = [[1,2],[1,1],[1,0],[1,-1],[1,-2],[2,1],[2,0],[2,-1],[3,0]]
  RIGHTFOOT = [[-1,2],[-1,1],[-1,0],[-1,-1],[-1,-2],[-2,1],[-2,0],[-2,-1],[-3,0]]
  MAX_COST = 100000000
  def climb x,y,bRight
    dir = bRight ? RIGHTFOOT : LEFTFOOT
    foot = bRight ? 1 : 0
    nfoot = bRight ? 0 : 1
    #puts "y = #{y}, x = #{x}, foot = #{foot}"
    dir.length.times do |i|
      nx = x + dir[i][0]
      ny = y + dir[i][1]
      if((0 <= nx && nx < @@w) && (0 <= ny && ny < @@h))
        if(@@field[ny][nx] == "T")
          @@dp[ny][nx][nfoot] = (@@dp[y][x][foot] < @@dp[ny][nx][nfoot]) ? @@dp[y][x][foot] : @@dp[ny][nx][nfoot]
        elsif("1" <= @@field[ny][nx] && @@field[ny][nx] <= "9") 
          n = @@field[ny][nx].to_i
          if(@@dp[y][x][foot] + n < @@dp[ny][nx][nfoot])
            @@dp[ny][nx][nfoot] = @@dp[y][x][foot] + n
            #puts "dp[#{ny}][#{nx}][#{nfoot}] = #{@@dp[ny][nx][nfoot]}"
            @@queue.push @@pos.new(nx,ny,!bRight)
          end
        end
      end
    end
  end
  def doIt
    arg = gets.split(" ").map{|x| x.to_i}
    while(0 < arg[0] + arg[1])
      @@w = arg[0]
      @@h = arg[1]
      @@field = Array.new(@@h)
      @@h.times do |i|
        #puts  i
        @@field[i] = gets.split(" ")
      end
      @@dp = Array.new(@@h).map!{Array.new(@@w).map!{Array.new(2, MAX_COST)}}
      #climing simulation
      @@h.times do |j|
        @@w.times do |i|
          if(@@field[j][i] == "S")
            #puts @@field[j][i]
            @@dp[j][i][0] = @@dp[j][i][1] = 0
            @@queue.push @@pos.new(i,j,true) 
            @@queue.push @@pos.new(i,j,false)
          end
        end     
      end
      #exec Dijkstra
      while(@@queue.length > 0)
        t = @@queue.shift
        climb(t.x,t.y,t.bRight)
      end
      #solve min
      min = MAX_COST
      @@h.times do |j|
        @@w.times do |i|
          if(@@field[j][i] == "T")
            min = (@@dp[j][i][0] < min) ? @@dp[j][i][0] : min
            min = (@@dp[j][i][1] < min) ? @@dp[j][i][1] : min
          end
        end     
      end
      puts(min == MAX_COST ? -1 : min)
      arg = gets.split(" ").map{|x| x.to_i}
    end
  end
end

Q1150.new.doIt

Measured memory_bytes: 5676
#include <bits/stdc++.h>
#include <limits.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int





int main(void)
{
    ll n, k;
    cin >> n >> k;
    ll h[n];
    for(ll i = 0; i < n; i++) cin >> h[i];

    ll dp[n];
    for(ll i = 0; i < n; i++) dp[i] = LLONG_MAX;
    dp[0] = 0;

    for(ll i = 1; i < n; i++){

        // dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        // dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        // j = 1 ~ k で回す
        // i - j == 0 になったら終了
        
        for(ll j = 1; j <= k; j++){
            dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            if(i - j == 0) break;
        }
    }

    cout << dp[n - 1] << endl;
    

 

    
    
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h1  = sc.nextInt();
        int m1  = sc.nextInt();
        int h2  = sc.nextInt();
        int m2  = sc.nextInt();
        int k  = sc.nextInt();
        
        int sa = (h2-h1) * 60 + (m2 - m1);
        System.out.println(sa - k);
        
    }
}


Measured memory_bytes: 35740
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#include <iostream>
#include <iomanip>    
#include <cstring>
#include <cmath>

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define eprintf(...) fprintf(stderr,__VA_ARGS__)

using namespace std;

template<class T> inline void umax(T &a,T b){if(a < b) a = b;}
template<class T> inline void umin(T &a,T b){if(a > b) a = b;}
template<class T> inline T abs(T a){return a > 0 ? a : -a;}

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int inf = 1e9 + 143;
const ll longinf = 1e18 + 143;

inline int read(){int x;scanf(" %d",&x);return x;}

int main() {
  int n = read();
  string s, t;
  cin >> s >> t;
  int ans = 0;
  for (int both = 1; both <= n; both++) {
    if (s.substr(n - both, both) == t.substr(0, both)) {
      ans = both;
    }
  }
  printf("%d\n", 2 * n - ans);
  return 0;    
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N;
vector<ll> a;
unordered_map<ll,ll> um;

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        ll c;
        cin >> c;
        a.push_back(c);
        um[c] = i%2;
    }
    sort(a.begin(),a.end());
    ll ans = 0;
    for(int i=0;i<N;i+=2){
        if(i%2 != um[a[i]]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, k;
deque<int> q;
char s[222222];
bool rev;
int main() {
	scanf("%d%d", &n, &k);
	k = k <= n * 2 ? k : n * 2 + (k - n * 2) % 2;
	scanf("%s", s + 1);
	for (int i = 1; i <= n; ++i) q.push_back(s[i] == 'B');
	while (k--) {
		int p = q.front(); q.pop_front();
		if (p ^ rev) {
			rev ^= 1; q.push_back(rev);
		} else q.push_front(p ^ 1);
	}
	while (!q.empty()) {
		printf("%c", (q.front() ^ rev) ? 'B' : 'A');
		q.pop_front();
	}
}


Measured memory_bytes: 1536
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

def dfs(s,d,i):
    for j in range(i+1):
        s[d] = chr(ord('a')+j)
        if d < len(s) - 1:
            dfs(s, d+1, max(j+1, i))
        else:
            a.add("".join(s))

n = INT()
s = ['a']*n
a = set()
dfs(s, 0, 0)
b = sorted(list(a))
for x in b:
    print(x)

Measured memory_bytes: 23608
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n = I()
L = [deque(LI()) for _ in range(n)]

match_set = set()
for i in range(n):
    opponent = L[i][0] - 1
    if i in match_set or opponent in match_set:
        continue
    elif L[opponent][0] - 1 == i:
        L[i].popleft()
        L[opponent].popleft()
        match_set.add(i)
        match_set.add(opponent)


pre_match_set = match_set


cnt = 1
while pre_match_set:
    match_set = set()
    flag = 0
    for j in pre_match_set:
        if not L[j]:
            continue
        opponent = L[j][0] - 1
        if not L[opponent]:
            continue
        if j in match_set or opponent in match_set:
            continue
        if L[opponent][0] - 1 == j:
            flag = 1
            L[j].popleft()
            L[opponent].popleft()
            match_set.add(j)
            match_set.add(opponent)
    if flag:
        cnt += 1
    pre_match_set = match_set



if any([i for i in L]):
    print(-1)
else:
    print(cnt)

Measured memory_bytes: 72668
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=1000000007;
int main()
{
    int n;cin>>n;
    vector<pair<int,int> > v;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        v.push_back(make_pair(a,0));
    }
    for(int i=0;i<n;i++){
        int b;cin>>b;
        v.push_back(make_pair(b,1));
    }
    sort(v.begin(),v.end());
    int ac=0;int bc=0;ll ans=1;
    for(int i=0;i<2*n;i++){
        if(v[i].second){
            bc++;
        }else{
            ac++;
        }
        if(bc&&ac){
            (ans*=ac*bc)%=MOD;
            ac--;bc--;
        }
    }
    cout<<ans<<endl;
}



Measured memory_bytes: 2420
A, B, C = gets.split.map(&:to_i)

if A.even? && C.odd?
  puts('NO')
  exit
end

if A == 1
  puts('YES')
  exit
end

n = A
100_000.times do
  div, mod = n.divmod(B)
  if mod == C
    puts('YES')
    exit
  end
  n += A
end

puts('NO')

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    char c;
    cin >> c;
    c++;
    cout << c << endl;
} 

Measured memory_bytes: 256
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int x, a, b;
        x = int.Parse(str[0]);
        a = int.Parse(str[1]);
        b = int.Parse(str[2]);
        if (b <= a)
            Console.WriteLine("delicious");
        else if (b <= a + x)
            Console.WriteLine("safe");
        else
            Console.WriteLine("dangerous");
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<vector>
#include<cstdlib>
using namespace std;
int n,m;
int dis[16][16];
int dp[1<<16][16];
int sum;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		x--;y--;
		dis[x][y]=dis[y][x]=z;
		sum+=z;
	}
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)dp[i][j]=-1;
	}
	for(int i=1;i+1<(1<<n);i++)
	{
		if(i>>(n-1)&1)continue;
		if(i&1)
		{
			dp[i][0]=0;
			for(int j=0;j<n;j++)
			{
				if(i>>j&1)
				{
					for(int k=j+1;k<n;k++)
					{
						if(i>>k&1)dp[i][0]+=dis[j][k];
					}
				}
			}
		}
	}
	for(int i=1;i+1<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(dp[i][j]==-1)continue;
			int st=((1<<n)-1)^i;
			if(dis[j][n-1])
			{
				int res=0;
				for(int k=0;k<n;k++)
				{
					if(st>>k&1)
					{
						for(int l=k+1;l<n;l++)
						{
							if(st>>l&1)res+=dis[k][l];
						}
					}
				}
				dp[(1<<n)-1][n-1]=max(dp[(1<<n)-1][n-1],dp[i][j]+res+dis[j][n-1]);
			}
			for(int k=(st-1)&st;k;k=(k-1)&st)
			{
				if(k>>(n-1)&1)continue;
				int res=0;
				for(int l1=0;l1<n;l1++)
				{
					if(k>>l1&1)
					{
						for(int l2=l1+1;l2<n;l2++)
						{
							if(k>>l2&1)
							{
								res+=dis[l1][l2];
							}
						}
					}
				}
				for(int l=0;l<n;l++)
				{
					if(k>>l&1)
					{
						if(dis[j][l])
						{
							dp[i|k][l]=max(dp[i|k][l],dp[i][j]+res+dis[j][l]);
						}
					}
				}
			}
		}
	}
	printf("%d",sum-dp[(1<<n)-1][n-1]);
	return 0;
}

Measured memory_bytes: 4352
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto t = 1L, a = 1L;
  foreach (_; 0..n) {
    auto rd = readln.split.to!(long[]), ti = rd[0], ai = rd[1];
    auto k = max((t+ti-1)/ti, (a+ai-1)/ai);
    t = k*ti;
    a = k*ai;
  }

  writeln(t+a);
}


Measured memory_bytes: 508
use std::io::stdin;

fn read_line() -> Vec<i32> {
    let mut a_str = String::new();
    stdin().read_line(&mut a_str).expect("read error");
    a_str.split_whitespace()
        .map(|x| x.parse::<i32>().expect("parse error"))
        .collect::<Vec<i32>>()
}

fn main() {
    let v = read_line();
    let n = v[0] as usize;
    let k = v[1] as usize;
    let mut h = read_line();

    if n <= k {
        println!("0");
        return;
    }

    h.sort();
    let c = h.iter().take(n-k).fold(0, |c, x| c + *x as u64);
    println!("{}", c);
}

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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
ostream &operator<<(ostream &os, vector<T> &v)
{
    os << "{";
    rep(i, v.size()) os << v[i] << (i == (int)v.size() - 1 ? "" : ", ");
    os << "}";
    return os;
}
template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }
struct in
{
    const size_t n = 0;
    in() = default;
    in(size_t n) : n(n){};
    template <typename T>
    operator T()
    {
        T ret;
        cin >> ret;
        return ret;
    }
    template <typename T>
    operator vector<T>()
    {
        assert(n != 0);
        vector<T> ret(n);
        for (auto &x : ret)
            cin >> x;
        return ret;
    }
};

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

vector<pint> rle(vint v)
{
    vector<pint> ret;
    ret.reserve(100000);
    rep(i, v.size())
    {
        if (i == 0 || ret.back().first != v[i])
        {
            ret.emplace_back(v[i], 1);
        }
        else
        {
            ret.back().second++;
        }
    }
    return ret;
}

void Main()
{
    int n = in();
    vint a = in(n);
    sort(ALL(a), greater<int>());
    auto v = rle(a);

    ll x = 0, y = 0;
    rep(i, n)
    {
        if (x == 0)
        {
            if (v[i].second >= 4)
            {
                x = y = v[i].first;
                break;
            }
            else if (v[i].second >= 2)
            {
                x = v[i].first;
                continue;
            }
        }
        else
        {
            if (v[i].second >= 2)
            {
                y = v[i].first;
                break;
            }
        }
    }
    cout << x * y << endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main(){
  int n;
  std::cin >> n;
  int v[n];
  for(int i = 0; i< n; i++){
    std::cin >> v[i];
  }

  for(int i = n-1; 0 < i; i--){
    std::cout << v[i] << " ";
  }
  std::cout << v[0] << std::endl;
  return 0;
}

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

int len(int n){
    if(n==0){
        return 1;
    }
    return len(n-1)*2+3;
}
int pti(int n){
    if(n==0){
        return 1;
    }
    return pti(n-1)*2+1;
}
bool koe(int n,int x){
    if(x>len(n-1)+1){
        return true;
    }
    return false;
}



signed main(){
    int n,x;
    cin >> n >> x;
    if(x==1){
        cout << 0;
        return 0;
    }
    int ans = 0;
    for(int i = n;i > 0;i--){
        if(koe(i,x)){
            x -= len(i-1)+2;
            ans += pti(i-1)+1;
        }
        else{
            x--;
        }
    }
    if(x>0){
        ans ++;
    }
    cout << ans << endl;

    return 0;
}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if ( a+b > c+d ) {
    cout << "Left" << endl;
  } else if (a+b == c+d) {
    cout << "Balanced" << endl;
  } else {
    cout << "Right" << endl; 
  }
}

Measured memory_bytes: 256