akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cctype>
#include <cstring>

using namespace std;

string puzzle[9];
int pl2id[9], pl2rot[9];

bool check(char a, char b) {
  return toupper(a) == toupper(b) && a != b;
}

int dfs(int k, bool *used) {
  if(k == 9) return 1;
  
  /*
  for(int i=0; i<9; i++) {
    cout << " " << used[i];
  }
  cout << endl;
  */
  
  int ret = 0;
  for(int id=0; id<9; id++) {
    if(used[id]) continue;

    for(int rot=0; rot<4; rot++) {
      bool ok = true;
      // 上と一致
      if(k >= 3) ok &= check(puzzle[id][(rot+1)%4], puzzle[pl2id[k-3]][(pl2rot[k-3]+3)%4]);
      // 左と一致
      if(k%3 > 0) ok &= check(puzzle[id][rot], puzzle[pl2id[k-1]][(pl2rot[k-1]+2)%4]);
      
      if(ok) {
	pl2id[k] = id;
	pl2rot[k] = rot;
	used[id] = true;
	ret += dfs(k+1, used);
	used[id] = false;
      }
    }
  }
  
  return ret;
}

int main() {
  int n;
  cin >> n;
  while(n--) {
    for(int i=0; i<9; i++) {
      cin >> puzzle[i];
    }
    
    bool used[9] = {};
    cout << dfs(0, used) << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
#define X first
#define Y second
#define mp make_pair
using namespace std;
typedef long long ll;
const int N = 100010;
char s[N];
int n,a[N];
int fa[N],S[N];
int find(int x){
	if(fa[x]==x) return x;
	return fa[x] = find(fa[x]);
}
inline void merge(int x,int y){
	x=find(x),y=find(y);
	fa[x]=y;
}
int main(){
	scanf("%s",s+1);
	int len = strlen(s+1);
	int m = len/2;
	for(int i =1;i<=m;i++) a[i] = (s[i]-s[len-i+1]+26)%26;
	for(int i =m+1;i>=2;i--) a[i] = (a[i]-a[i-1]+26)%26;
	for(int i =1;i<=m+2;i++) fa[i] = i;
	scanf("%d",&n);
	int l,r;
	for(int i = 1;i<=n;i++){
		scanf("%d%d",&l,&r);
		if(r<=m) merge(l,r+1);
		else if(l>m) merge(len-r+1,min(m+1,len-l+1+1));
		else {
			//merge(1,2);
			r  = len-r+1;
			//cout<<l<<' '<<r<<endl;
			if(r<l) merge(r,l);
			else if(r>l) merge(l,r);
			//merge(min(l,len-r+1),max(l,len-r+1)+1);
		}
	}
	for(int i = 1;i<=m+1;i++)  (S[find(i)]+=a[i])%=26;
	//for(int i =1;i<=m+1;i++) cout<<find(i)<<endl;
	S[find(m+1)] = 0;
	bool flag = true;
	for(int i =1;i<=m;i++) if(S[find(i)]!=0) flag = false;
	if(flag) puts("YES"); else puts("NO");
	return 0;
}

Measured memory_bytes: 896
import sys
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(10**7)

n, k, q = map(int, input().split())
dd = defaultdict(int)
for _ in range(q):
    dd[int(input())] += 1

border = q-k+1
for i in range(1, n+1):
    if dd[i] >= border:
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 16152
#include <iostream>

using namespace std;

#define loop(i,a,b) for(int i=int(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define all(c) (c).begin(), (c).end()

int main(){
    for(int z; cin>>z,z;){
        int ans = 1e9;
        for(int x=1; x*x*x<=z*z*z; x++){
            for(int y=1; y*y*y + x*x*x <= z*z*z; y++){
                ans = min(z*z*z - x*x*x - y*y*y, ans);
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1160
///******* In the name of Allah *******///

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int m = 65,n,i,j,k,l;
    char a[53],b[10013];
    for(i=0; i<=25; i++)
    {
        a[i] = m;
        m++;
    }
    m = 65;
    for(i=26; i<=51; i++)
    {
        a[i] = m;
        m++;
    }
//    for(i=0;i<=51;i++)
//    {
//        cout<<a[i]<<endl;
//    }
    cin>>n;
    cin>>b;
    l = strlen(b);
    for(i=0; i<l; i++)
    {
        for(j=0; j<=51; j++)
        {
            if(b[i]==a[j])
            {
                k = j+n;
                b[i] = a[k];
                break;
            }
        }
    }
    for(i=0; i<l; i++)
    {
        cout<<b[i];
    }

    return 0;
}


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

int main()
{
    string s;
    cin >> s;
    int ans;
    if(s == "SUN") ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else if(s == "SAT") ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, SCC[1010], v[1010], ord[1010], cnt;
vector<int>E[1010], F[1010], L1[1010], L2[1010];
void DFS1(int a) {
	v[a] = 1;
	for (auto &t : E[a])if (!v[t])DFS1(t);
	ord[++cnt] = a;
}
void DFS2(int a) {
	SCC[a] = cnt;
	for (auto &t : F[a])if (!SCC[t])DFS2(t);
}
struct Edge {
	int a, b;
}w[201000];
vector<int>T;
void DFS3(int a) {
	v[a] = 1;
	for (int i = 0; i < E[a].size(); i++) {
		if (!v[E[a][i]]) {
			T.push_back(L1[a][i]);
			DFS3(E[a][i]);
		}
	}
}
void DFS4(int a) {
	v[a] = 1;
	for (int i = 0; i < F[a].size(); i++) {
		if (!v[F[a][i]]) {
			T.push_back(L2[a][i]);
			DFS4(F[a][i]);
		}
	}
}
int Q[1010];
bool BFS(int a, int chk, int cc) {
	int head = 0, tail = 0, i;
	for (i = 1; i <= n; i++)v[i] = 0;
	v[a] = 1, Q[++tail] = a;
	while (head < tail) {
		int x = Q[++head];
		for (i = 0; i < E[x].size(); i++) {
			if (L1[x][i] == chk)continue;
			int t = E[x][i];
			if (!v[t]) {
				Q[++tail] = t;
				v[t] = 1;
			}
		}
	}
	if (tail != cc)return true;
	for (i = 1; i <= n; i++)v[i] = 0;
	head = tail = 0;
	v[a] = 1, Q[++tail] = a;
	while (head < tail) {
		int x = Q[++head];
		for (i = 0; i < F[x].size(); i++) {
			if (L2[x][i] == chk)continue;
			int t = F[x][i];
			if (!v[t]) {
				Q[++tail] = t;
				v[t] = 1;
			}
		}
	}
	return tail != cc;
}
int Res[201000];
void Do(int a) {
	int i, cc = 0;
	for (i = 1; i <= n; i++) {
		E[i].clear();
		F[i].clear();
		L1[i].clear();
		L2[i].clear();
		if (SCC[i] == a)cc++;
	}
	T.clear();
	int rt = 0;
	for (i = 1; i <= m; i++) {
		if (SCC[w[i].a] != a || SCC[w[i].b] != a)continue;
		rt = w[i].a;
		E[w[i].a].push_back(w[i].b);
		F[w[i].b].push_back(w[i].a);
		L1[w[i].a].push_back(i);
		L2[w[i].b].push_back(i);
	}
	for (i = 1; i <= n; i++)v[i] = 0;
	DFS3(rt);
	for (i = 1; i <= n; i++)v[i] = 0;
	DFS4(rt);
	for (auto &t : T) {
		if (BFS(rt, t, cc)) {
			Res[t] = 1;
		}
	}
}
int D[1010][1010], Mod = 1000000007;
int main() {
	int i, j, a, b;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++) {
		scanf("%d%d", &a, &b);
		w[i] = { a,b };
		E[a].push_back(b);
		F[b].push_back(a);
	}
	for (i = 1; i <= n; i++) {
		if (!v[i]) {
			DFS1(i);
		}
	}
	cnt = 0;
	for (i = n; i >= 1; i--) {
		if (!SCC[ord[i]]) {
			cnt++;
			DFS2(ord[i]);
		}
	}
	for (i = 1; i <= cnt; i++) {
		Do(i);
	}
	for (i = 1; i <= cnt; i++) {
		D[i][i] = 1;
		E[i].clear();
	}
	for (i = 1; i <= m; i++) {
		if (SCC[w[i].a] != SCC[w[i].b]) {
			E[SCC[w[i].a]].push_back(SCC[w[i].b]);
		}
	}
	for (i = 1; i <= n; i++) {
		for (auto &t : E[i]) {
			for (j = 1; j <= i; j++) {
				D[t][j] = (D[t][j] + D[i][j]) % Mod;
			}
		}
	}
	for (i = 1; i <= m; i++) {
		if (SCC[w[i].a] != SCC[w[i].b]) {
			if (D[SCC[w[i].b]][SCC[w[i].a]] != D[SCC[w[i].a]][SCC[w[i].a]])Res[i] = 1;
		}
	}
	for (i = 1; i <= m; i++) {
		if (Res[i])puts("diff");
		else puts("same");
	}
}

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

const ll mod = 1e9 + 7;

int main() {
  int a, b;
  cin >> a >> b;
  if ((a % 3 == 0) || (b % 3 == 0) || ((a+b) % 3 == 0)) {
    cout << "Possible\n";
  } else {
    cout << "Impossible\n";
  }
  return 0;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int n, m;
    cin >> n >> m;
    vector<ll> a(n);
    vector<pair<ll, ll>> cb(m);
    ll mi = INF;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        mi = min(mi, a[i]);
    }
    for (int i = 0; i < m; i++)
    {
        ll b, c;
        cin >> b >> c;
        cb[i] = make_pair(c, b);
    }
    cb.push_back(make_pair(-1, n));
    sort(a.begin(), a.end(), greater<ll>());
    sort(cb.begin(), cb.end(), greater<pair<ll, ll>>());
    int i = 0;
    int j = 0;
    ll ans = 0;
    while (n)
    {
        if (a[i] > cb[j].first)
        {
            ans += a[i];
            i++;
            n--;
        }
        else
        {
            int tmp = cb[j].second;
            if (cb[j].second > n)
                tmp = n;
            ans += cb[j].first * tmp;
            j++;
            n -= tmp;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5632
N = gets.to_i

def calc(list)
	prev = list[0]
	sum = 0
	list[1..-1].each{|n|
		sum += (prev - n).abs
		prev = n
	}
	sum
end

list = []
N.times{
	list << gets.to_i
}

list.sort!

def arrange(list)
	first = 0
	last = N - 1
	result = [list[first]]
	first += 1
	while first <= last
		result << list[last]
		last -= 1
		break if first > last
		result.unshift(list[last])
		last -= 1
		break if first > last
		result << list[first]
		first += 1
		break if first > last
		result.unshift(list[first])
		first += 1
	end
	result
end

c1 = calc(arrange(list))
c2 = calc(arrange(list.reverse))

puts [c1, c2].max


Measured memory_bytes: 7016
#include <iostream>
int main(){
	int a[28],b[30]={};
	for(int i=0;i<28;i++){
		std::cin>>a[i];
	}
	for(int i=1;i<=30;i++){
		for(int j=0;j<28;j++){
			if(a[j]==i){
				b[i-1]=i;
			}
		}
	}
	for(int i=0;i<30;i++){
		if(b[i]==0){
			std::cout<<i+1<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string sS = Console.ReadLine().Trim();
            int iN = int.Parse(sS);
            sS = Console.ReadLine().Trim();

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<int> lstRt = new List<int>();
            for (int i = 1; i < sS.Length - 1; i++)
            {
                string sF = sS.Substring(0, i);
                string sB = sS.Substring(i, sS.Length - i);
                sF = new string(sF.ToCharArray().Distinct().ToArray());                 // charからstringへ変換  // 文字列内から重複文字削除
                sB = new string(sB.ToCharArray().Distinct().ToArray());                 // charからstringへ変換  // 文字列内から重複文字削除
                int iCnt = 0;
                for (int j = 0; j < sF.Length; j++)
                {
                    string sO = sF.Substring(j, 1);
                    if (sB.Contains(sO)) { iCnt += 1; }
                }
                lstRt.Add(iCnt);
            }
            lstRt.Sort(delegate (int mca1, int mca2) { return (int)(mca2 - mca1); });  // 降順
            if (lstRt.Count == 0) { lstRt.Add(0); }

            // 出力
            Console.WriteLine("{0}", lstRt[0].ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 13408
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		for(;;)
		{
			String in = scanner.next();
			//String out = "";
			if(in.equals("0"))
			{
				break;
			}
			
			int sum = 0;
			for(int i=0; i<in.length(); i++)
			{
				char c = in.charAt(i);
				sum += c - '0';
			}
			
			System.out.println(sum+"");
		}
	}
}

Measured memory_bytes: 26236
#include <stdio.h>
#define swap(x, y) {int z; z=y; y=x; x=z;}
int main ()
{
	double a, b;	
	scanf("%lf %lf", &a, &b);
	int x=a, y=b;
	printf("%d %d %.5lf\n", x/y, x%y, a/b);	
	return 0; 
} 


Measured memory_bytes: 2756
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception {
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		String line=in.readLine();
		
		int[]world=new int[26];
		
		for (int i = 0; i < line.length(); i++) {
			char c=line.charAt(i);
			world[c-'a']++;
		}
		
		for (int i = 0; i < world.length; i++) {
			if(world[i]%2!=0){
				System.out.println("No");
				return;
			}
				
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 21584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,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 mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int 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 POSR(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int n,m;
vector<int>vec;

struct maintain_interval{
	int bit[(1<<18)+5];
	void init(){
		memset(bit,0,sizeof(bit));
	}
	int f(int x)
	{
		return x&-x;
	}
	void add(int i,int x)
	{
		for(int s=i;s<=(1<<18);s+=f(s)) bit[s]+=x;
	}
	int sum(int i)
	{
		int res=0;
		for(int s=i;s>0;s-=f(s)) res+=bit[s];
		return res;
	}
}mt;

P forbid[200005][2];
bool ok[200005],ok2[200005];
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<2*n;i++){
		int a; scanf("%d",&a); vec.pb(a);
	}
	SORT(vec);
	
	int lb = -1,ub = m-1;
	while(ub-lb > 1){
		int mid = (lb+ub)/2;
		for(int i=0;i<2*n;i++){
			//vec[i]と足してmod mでmidより大な区間
			for(int j=0;j<2;j++){
				//[mid+1+m*j,m*(j+1)-1]
				int L = mid+1+m*j-vec[i];
				int R = m*(j+1)-1-vec[i];
				L = POSL(vec,L);
				R = POSR(vec,R); R--;
				if(L <= R) forbid[i][j] = mp(L+i,R+i);
				else forbid[i][j] = mp(-1,-1);
			}
		}
		mt.init();
		for(int i=0;i<2*n;i++){
			for(int j=0;j<2;j++) if(forbid[i][j].fi >= 0){
				mt.add((forbid[i][j].fi+2)/2,1);
				mt.add((forbid[i][j].sc+1)/2+1,-1);
			}
			if(i%2 == 1){
				ok[i] = !mt.sum((i+1)/2);
			}
		}
		mt.init();
		for(int i=2*n-1;i>=0;i--){
			for(int j=0;j<2;j++) if(forbid[i][j].fi >= 0){
				mt.add((forbid[i][j].fi+2)/2,1);
				mt.add((forbid[i][j].sc+1)/2+1,-1);
			}
			if(i%2 == 0){
				ok2[i] = !mt.sum((2*n+i)/2);
			}
		}
		ok2[2*n] = true;
		bool flag = 0;
		for(int i=0;i<2*n;i++){
			if(i%2 == 1){
				if(ok[i] && ok2[i+1]){
					flag = 1;
					break;
				}
			}
		}
		if(flag) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
}


Measured memory_bytes: 5876
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#define INF 100000000
#define MOD 1000000007
using namespace std;



int main(){
    int N,M;
    cin >> N;
    string sn[N];
    for(int i=0; i<N; i++){
        cin>>sn[i];
    }
    
    cin >> M;
    string sm[M];
    for(int i=0; i<M; i++){
        cin>>sm[i];
    }
    
    pair<string,int> cards[N+M];
    for(int i=0; i<N; i++){
        cards[i].first=sn[i];
        cards[i].second=1;
    }
    for(int i=0; i<M; i++){
        cards[N+i].first=sm[i];
        cards[N+i].second=-1;
    }
    
    sort(cards,cards+N+M);
    
    
    int ans=-101;
    string temp=cards[0].first;
    int temp_ans=0;
    for(int i=0; i<N+M; i++){
        if(temp==cards[i].first){
            temp_ans+=cards[i].second;
        }else{
            ans=max(ans,temp_ans);
            temp_ans=cards[i].second;
            temp=cards[i].first;
        }
    }
    ans=max(ans,temp_ans);
    
    if(ans>=0){
        cout<<ans<<endl;
    }else{
        cout<<0<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String... args) {
		Scanner sc = new Scanner(System.in);
		while(true) {
		int n = sc.nextInt();
		int x = sc.nextInt();
			if(n == 0 && x == 0) break;
		int s = 0;
		for(int i = 1; i <= n; i++) {
			for(int j = i + 1; j <= n; j++) {
				for(int k = j + 1; k <= n; k++) {
					if(i + j + k == x) s++;
				}
			}
		}
		System.out.println(s);
		}
	}
}



Measured memory_bytes: 26336
#include<bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
bool comp(vector<ll> a, vector<ll> b)
{
   return *max_element(a.begin(), a.end())>*max_element(b.begin(), b.end());
}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a, b, c;
    cin>>a>>b>>c;
    if((a==b && b!=c) || (c==b && b!=a) || (a==c && b!=c))
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF 1e18L
#define INF 1e9L
#define EPS 1e-9
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define pb push_back
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
typedef long long ll;
typedef pair<int, int> pii;

int n;
vector<map<string,int>> memo;

bool check(string s){
    if(s.size() != 4) return false;
    if(s[0]=='A' && s[1]=='G' && s[2]=='C') return true;
    if(s[0]=='A' && s[1]=='C' && s[2]=='G') return true;
    if(s[0]=='G' && s[1]=='A' && s[2]=='C') return true;
    if(s[1]=='A' && s[2]=='G' && s[3]=='C') return true;
    if(s[1]=='A' && s[2]=='C' && s[3]=='G') return true;
    if(s[1]=='G' && s[2]=='A' && s[3]=='C') return true;
    if(s[0]=='A' && s[1]=='G' && s[3]=='C') return true;
    if(s[0]=='A' && s[2]=='G' && s[3]=='C') return true;
    return false;
}

int dfs(int cur, string last3){
    if(memo[cur].count(last3)) return memo[cur][last3];
    if(cur==n) return 1;
    int ret = 0;
    string agct="AGCT";
    REP(i, 4){
        char c = agct[i];
        if(!check(last3 + c)){
            string s = "aaa";
            s[0]=last3[1];
            s[1]=last3[2];
            s[2]=c;
            ret = (ret + dfs(cur+1,s)) % 1'000'000'007;
        }
    }
    memo[cur][last3] = ret;
    return ret;
}

int main(void)
{
    cin >> n;
    memo = vector<map<string,int>>(n+1);
    pr(dfs(0,"TTT"));
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
int main(){

    int n;
    cin >> n;
    vector<int> h(n);

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

    bool f = 1; 

    for(int i = n-1; i > 0; --i){
        if(h[i-1] > h[i]){
            --h[i-1];
        }
        if(h[i-1] > h[i]){
            f = 0;
        }
    }

    if(f)cout << "Yes" << endl;
    else cout << "No" << endl;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
  int n,minus=0;
  cin>>n;
  vector<int> p(n);
  rep(i,n){
    cin>>p[i];
  }
  int x=p[0];
    for(int i=1;i<n;i++){
      if(p[i]<x){
        x=p[i];
      }else{
        minus++;
      }
    }
    cout<<n-minus<<endl;
}

Measured memory_bytes: 1024
//ThakurAnurag
//TemplateCode

#include<bits/stdc++.h>
using namespace std;

#define ll long long int
#define ull unsigned long long int
#define fo(i,a,n) for(ll i=a;i<n;i++)
#define fo2(i,a,n) for(ll i=n;i>=a;i--)
#define endl "\n"
#define sp " "
#define f first
#define s second
#define pb push_back
#define buffer ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define lower(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define upper(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
#define init(arr,val) memset(arr,val,sizeof(arr))
#define vecl(v) vector<ll> v
#define vecs(v) vector<string> v
#define vecp(v) vector < pair <ll,ll> > v

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

	if(n+m<=16 && n<=8 && m<=8){
		cout<<"Yay!"<<endl;
	}
	else{
		cout<<":("<<endl;
	}

	return 0;
}

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

int main() {
	int n, k; cin >> n >> k;
	while(k--) {
		int x; cin >> x;
		n -= x;
	}
	if(n > 0) cout << "No"; 
	else cout << "Yes";
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final long n = scanner.nextLong();
        final long a = scanner.nextLong();
        final long b = scanner.nextLong();

        final long div = n / (a + b);
        final long mod = n % (a + b);
        System.out.println(a * div + Math.min(mod,a));
    }
}


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

typedef long long ll;
ll dp[100010]={0},a[100010]={0};
ll inf=0x3fffffff;

int main(){
   int n,k;
   scanf("%d%d",&n,&k);
   fill(dp,dp+100010,inf);
   for(int i=0;i<n;i++){
    scanf("%lld",a+i);
   }
   dp[0]=0;
   dp[1]=abs(a[1]-a[0]);
   for(int i=2;i<=n;i++){
    for(int j=1;j<=k;j++){
        if(i<j){
            break;
        }
        else dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
    //printf("%d %lld\n",i,dp[i-1]);
   }
   printf("%lld",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int h, w; cin >> h >> w;
    vector<vector<bool>> goal_black(h, vector<bool>(w, false));
    REP(i, h) REP(j, w){
        char c; cin >> c;
        if(c == '#') goal_black[i][j] = true;
    }
    bool okay = true;
    
    REP(i, h) REP(j, w){
        if(!goal_black[i][j]) continue;
        bool okaysquare = false;
        if(i != 0)  if(goal_black[i-1][j]) okaysquare = true;
        if(j != 0)  if(goal_black[i][j-1]) okaysquare = true;
        if(i < h-1) if(goal_black[i+1][j]) okaysquare = true;
        if(j < w-1) if(goal_black[i][j+1]) okaysquare = true;
        if(!okaysquare) okay = false;
    }
    cout << (okay ? "Yes" : "No") << "\n" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define MOD 1000000007
#define PMOD 998244353
#define pb(x) push_back(x)
using namespace std;

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> plii;
typedef pair<int, pii> piii;
const int INF = 1e9+10;
const ll LINF = 1LL*INF*INF;
const int MAXN = 2e5+10;
const int MAXM = 5e3+10;

priority_queue<int> pq;
vector<vector<int> > graph;
queue<int> que;

int A[MAXN];
char S[MAXN];

int main()
{
    int n,m,k,a,b,x,y,q;
    int sum = 0;
    int cnt = 0;
    int mx = 0;
    int mn = INF;
    int cur = 0, idx = -1;
    int tc;

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin>>n;

    n--;

    cout<<(n>>1)<<"\n";


    return 0;
}


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

int main()
{
    int N;
    string S;
    cin >> N >> S;

    vector<int> count_w(N);
    int cnt_w = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        if (S.at(i) == '.')
            cnt_w++;
        count_w.at(i) = cnt_w;
    }

    int res = N + 1;
    int cnt = 0;
    for (int i = 0; i < N - 1; i++)
    {
        if (S.at(i) == '#')
        {
            res = min(res, cnt + count_w.at(i + 1));
            cnt++;
        }
    }
    cout << min(res, cnt) << endl;
    return 0;
}


Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n;
	long long k;
	long long ans;
	cin>>n>>k;
	ans = 1;
	ans *= k;
	for(int i = 0; i < n - 1; ++i){
		ans *= k - 1;
	}
	cout<<ans<<endl;
	return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
#define chmax(x, v) do { x = max(x, v); } while (0)
#define chmin(x, v) do { x = min(x, v); } while (0)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

// {{{ Modint
// using mint = modint<1000000007>;
// mint x = 2;
// std::cout << x.a << std::endl;
template <std::int64_t M>
class modint {
  public:
    int64_t a;

    explicit constexpr modint(const int64_t x = 0) noexcept :
      a((x % M + M) % M) {}
    constexpr int64_t &value() noexcept { return a; }
    constexpr const int64_t &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept {
      return modint(*this) += rhs;
    }
    constexpr modint operator-(const modint rhs) const noexcept {
      return modint(*this) -= rhs;
    }
    constexpr modint operator*(const modint rhs) const noexcept {
      return modint(*this) *= rhs;
    }
    constexpr modint operator/(const modint rhs) const noexcept {
      return modint(*this) /= rhs;
    }
    constexpr modint &operator+=(const modint rhs) noexcept {
      a += rhs.a;
      if (a >= M) {
        a -= M;
      }
      return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
      if (a < rhs.a) {
        a += M;
      }
      a -= rhs.a;
      return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
      a = a * rhs.a % M;
      return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
      int64_t exp = M - 2;
      while (exp) {
        if (exp % 2) {
          *this *= rhs;
        }
        rhs *= rhs;
        exp /= 2;
      }
      return *this;
    }
    constexpr modint pow(ll t) const {
      if (!t) return modint(1);
      modint a = pow(t>>1);
      a *= a;
      if (t&1) a *= *this;
      return a;
    }
};
// }}}
using mint = modint<1000000007>;

ll N;
string s;
mint dp[5000][5000];
mint psum[5000];

signed main() {
  cin >> N >> s;
  rep(i, N)
    dp[0][i] += mint(1);
  rep(i, N) {
    ll bi = i-1;
    if (bi < 0) continue;
    psum[0] = dp[bi][0];
    for (ll j=1; j<N; j++)
      psum[j] = psum[j-1] + dp[bi][j];
    rep(j, N) {
      if (s[i-1] == '>') dp[i][j] = psum[N-i] - psum[j];
      if (s[i-1] == '<') dp[i][j] = psum[j];
    }
  }
  cout << dp[N-1][0].value() << endl;
  return 0;
}


Measured memory_bytes: 118400
def digit_sum(num)
  sum = 0
  while num > 0 do
    sum += num % 10
    num /= 10
  end
  sum
end

n = gets.to_i

min = n
1.upto(n / 2) do |i|
  digit_sum = digit_sum(i) + digit_sum(n - i)
  min = digit_sum if min > digit_sum
end

puts min


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

const int D = 10;
const int MAXD = 10;
int dist[MAXD][MAXD];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int H, W; cin >> H >> W;
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < D; j++) {
			cin >> dist[i][j];
		}
	}
	for (int k = 0; k < D; k++) {
		for (int i = 0; i < D; i++) {
			for (int j = 0; j < D; j++) {
				dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			int v; cin >> v;
			if (v >= 0) {
				ans += dist[v][1];
			}
		}
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    ll n;
    cin >> n;
    ll ans = 0;
    rep(i,1,n+1){
        ans += (n-1)/i;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
constexpr ld PI = 3.14159265358979323846;

void solve() {
    ll n, m, x;
    cin >> n >> m >> x;
    vll c(n);
    vvll a(n, vll(m));
    rep(i, n) {
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    ll ans = INFL;
    for(ll i = 0; i < (1 << n); i++) {
        vll b(m);
        ll ans_ = 0;
        for(ll j = 0; j < n; j++) {
            if(!(i & (1 << j))) continue;
            ans_ += c[j];
            for(ll k = 0; k < m; k++) b[k] += a[j][k];
        }
        bool ok = true;
        for(ll j = 0; j < m; j++) {
            if(b[j] < x) {
                ok = false;
                break;
            }
        }
        if(ok) chmin(ans, ans_);
    }
    if(ans == INFL) ans = -1;
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 3660
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>

#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int d[100];

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

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

	return 0;
}


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

using namespace std;

int main(){
  int n;
  int m;
  bool flag = false;
  cin >> n >> m;
  vector< pair<int, int> > a;
  vector<int> num(n);

  for(int i=0;i<n;i++){
    num.at(i) = -1;
  }

  for(int i=0;i<m;i++){
    int s;
    int c;
    cin >> s >> c;
    if(num.at(s-1) == -1){
      num.at(s-1) = c;
    }
    else{
      if(num.at(s-1) != c){
        flag = true;
        break;
      }
    }
  }

  if(num.at(0) == 0 && !(num.size()==1) ){
    flag = true;
  }

  if(flag){
    cout << -1 << endl;
    return 0;
  }

  for(int i=0;i<n;i++){
    if(num.at(i) == -1){
      if(i == 0 && num.size()!=1){
        num.at(i)=1;
      }
      else{
        num.at(i)=0;
      }
    }
    cout << num.at(i);
  }
  cout << endl;


  return 0;
}


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

int main(){
  int N, count = 0;
  scanf("%d",&N);
  for (int i = 1; i <= N; i++)
    if((to_string(i)).length() % 2 == 1)
      count++;
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 256
N,M = map(int,input().split())
H = list(map(int,input().split()))
road = []
for i in range(M):
    road.append(list(map(int,input().split())))

bad_ob = []

for i in range(M):
    if H[road[i][0]-1] > H[road[i][1]-1]:
        bad_ob.append(road[i][1]-1)
    elif H[road[i][0]-1] < H[road[i][1]-1]:
        bad_ob.append(road[i][0]-1)
    else:
        bad_ob.append(road[i][0]-1)
        bad_ob.append(road[i][1]-1)


print(N-len(set(bad_ob)))


Measured memory_bytes: 37764
#include <iostream>
typedef long long int lli;
using namespace std;

int main(void)
{
	lli x; cin >> x;
	lli ans = (x / 11) * 2;
	if (x % 11 >= 7)ans += 2;
	else if (x % 11 >= 1)ans ++;

	cout << ans << endl;

	return 0;
}


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

int main(){
  int N;
  cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
    a[i]--;
  }
  int point=0;
  for(int i=0;i<N;i++){
    point=a[point];
    if(point==1){
      cout<<i+1<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n, a;
    cin >> n >> a;
    cout << n * n - a << endl;

    return 0;
}






Measured memory_bytes: 256
#include "bits/stdc++.h"
 
using namespace std;
 
typedef long long ll;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
    
 #define sz(x) (int)(x).size()
 #define mp make_pair
 #define pb push_back
 #define all(x) x.begin(), x.end()
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
 
int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    string s;cin>>s;
    
    ll sum=0;
    for(auto i : s)
    {
        sum+=(i-'0');
    }
    if(sum%9==0) cout<<"Yes";
    else cout<<"No";
}


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

inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}

const int N=2e3+5;

int n,m,is[N][N],ls[N][N],L[N],R[N];
int stak[N],a[N][N],ans,top;
char ch[N][N];

inline int max(int x,int y)
{
    if(x>y) return x;
    return y;
}

int main()
{
	n=read();
	m=read();
	ans=max(ans,max(n,m));
	for ( int i=1;i<=n;i++ )
	{
		scanf("%s",ch[i]+1);
		for ( int j=1;j<=m;j++ ) 
			a[i][j]=(ch[i][j]=='#');
	}
	for ( int i=1;i<n;i++ ) 
		for ( int j=1;j<m;j++ ) 
		{
			int gs=a[i][j]+a[i+1][j]+a[i][j+1]+a[i+1][j+1];
			if(!(gs&1)) is[i][j]=1;
		}
	for ( int i=1;i<=n;i++ )
		for ( int j=1;j<=m;j++ ) 
			ls[i][j]=(is[i][j])?ls[i-1][j]+1:0;
	for ( int i=1;i<=n;i++ )
	{
		stak[top=1]=0;
		for ( int j=1;j<m;j++ ) 
		{
			while(top&&ls[i-1][stak[top]]>=ls[i-1][j]) top--;
			L[j]=stak[top];
			stak[++top]=j;
		}
		stak[top=1]=m;
		for ( int j=m-1;j>=1;j-- ) 
		{
			while(top&&ls[i-1][stak[top]]>=ls[i-1][j]) top--;
			R[j]=stak[top];
			stak[++top]=j;
		}
		for ( int j=1;j<m;j++ ) 
			ans=max(ans,(R[j]-L[j])*(ls[i-1][j]+1));
	}
	printf("%d\n",ans);
	return 0;
}
			 

Measured memory_bytes: 51328
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x%y)
    
def factorize(n):
    a = 2
    b = []
    while a*a <= n:
        while n%a == 0:
            b.append(a)
            n //= a
        a += 1
    if n > 1:
        b.append(n)
    return b

A, B = map(int, input().split())
print (len(set(factorize(gcd(A, B))))+1)

Measured memory_bytes: 3188
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 100000;

int n;
int A[MAX + 1];
int L[MAX + 1], P[MAX + 1];

int lis() {
   L[0] = 0;
   P[0] = -1;
   int k = 0;
   int max = 0;
   for( int i = 1; i <= n; i++) {
   	    k = 0;
     	for( int j = 1; j < i; j++) {
     		if( A[j] < A[i] && L[k] < L[j] ) k = j;
     	}
     	L[i] = L[k] + 1;
     	P[i] = k;
     	if( L[max] < L[i] ) max = i;
   }
  int i = max;
  while( P[i] != -1){
  		cout << A[i] << " ";
  		i = P[i];
  }
   return L[max];
}
int lis2() {
    L[0] = A[0];
    int len = 1;

    for( int i = 1; i < n; i++ ) {
      	if( L[len-1] < A[i]) L[len++] = A[i];
        else *lower_bound(L, L+len, A[i]) = A[i];
    }
    return len;
}
int main() {
	cin >> n;
	//
    for(int i = 0; i < n; i++ ) cin >> A[i];
    cout << lis2() << endl;
	
	return 0;
}


Measured memory_bytes: 3808
import * as fs from 'fs';

const input = fs.readFileSync('/dev/stdin', 'utf8');
//const input = fs.readFileSync('./input.txt', 'utf8');

_a(input);

function _a(input: string) {
  const [N, X, T] = input.split(' ').map((s) => parseInt(s));

  console.log(Math.ceil(N / X) * T);
}


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

#define mx 100005

using namespace std;

vector<int> pa[mx], ch[mx];
stack<int> st;
int th[mx], n, m, a, b, rt, nm[mx], j;

int main(){
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n + m - 1; i++) {
		scanf("%d%d", &a, &b);
		pa[b].push_back(a);
		ch[a].push_back(b);
		nm[b]++;
	}
	for(rt = 1; !pa[rt].empty(); rt++);
	th[rt] = ++j;
	st.push(rt);
	while(!st.empty()){
		int i = st.top(); st.pop();
		for(int it : ch[i]){
			nm[it]--;
			if(!nm[it]){
				th[it] = ++j;
				st.push(it);
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		int ans = 0;
		for(int it : pa[i]) if(th[ans] < th[it]) ans = it;
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 12544
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAX 300010
ll mypow(ll x, ll y, ll p){ll ret = 1;while(y){if(y & 1) ret = (ret * x) % p;x = (x * x) % p; y /= 2;}return ret;}
ll inv(ll x, ll p){if(!x)   return 1;return mypow(x, p - 2, p);}
const ll mod = 998244353;
ll N, A, B, K, ans, fact[MAX], invv[MAX];

int main(){
    scanf("%lld %lld %lld %lld", &N, &A, &B, &K);
    fact[0] = fact[1] = 1;
    for(int i = 1; i <= N; i++)
        fact[i] = (fact[i - 1] * i) % mod;
    invv[0] = 1;
    for(int i = 1; i <= N; i++)
        invv[i] = inv(fact[i], mod);
    for(int i = 0; i <= N; i++){
        if(K - A * i < 0 || (K - A * i) % B != 0)   continue;
        ll X = i, Y = (K - A * i) / B;
        if(X > N || Y > N)  continue;
        ll c1 = (((fact[N] * invv[X]) % mod) * invv[N - X]) % mod;
        ll c2 = (((fact[N] * invv[Y]) % mod) * invv[N - Y]) % mod;
        ans = (ans + (c1 * c2) % mod) % mod;
    }
    printf("%lld\n", ans);
    return 0;
}

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

struct Network
{
    int N = 2, source = 0, sink = 1;
    struct Edge { int source, target, id, reverse; };
    vector<vector<Edge>> adjacency_lists;
    vector<int> capacities, flows;

    Network() : adjacency_lists(2) {}

    int add_vertex()
    {
        adjacency_lists.push_back({});
        return N++;
    }

    void add_edge(const int source, const int target, const int capacity)
    {
        if (source == target) return;
        const auto id = int(capacities.size());
        const auto reverse = id+1;
        adjacency_lists[source].push_back({source, target, id, reverse});
        adjacency_lists[target].push_back({target, source, reverse, id});
        capacities.insert(end(capacities), {capacity, capacity});
        flows.insert(end(flows), {0, 0});
    }

    int maxflow()
    {
        auto seen = vector<bool>(N);
        const function<int(int, int)> dfs = [&](const int v, const int flow)
        {
            if (v == sink) return flow;

            if (seen[v]) return 0;
            else seen[v] = true;

            for (const auto e : adjacency_lists[v])
            {
                const auto residual = capacities[e.id] - flows[e.id];
                if (residual == 0) continue;
                if (const auto x = dfs(e.target, min(flow, residual)))
                {
                    flows[e.id] += x;
                    flows[e.reverse] -= x;
                    return x;
                }
            }
            return 0;
        };

        auto flow = 0;
        while (true)
        {
            fill(begin(seen), end(seen), false);
            const auto delta = dfs(source, numeric_limits<int>::max());
            if (delta > 0) flow += delta;
            else break;
        }
        return flow;
    }
};

int main()
{
    int R, C; cin >> R >> C;

    auto network = Network();

    auto rows = vector<int>(R);
    for (auto r = 0; r < R; r++)
        rows[r] = network.add_vertex();

    auto columns = vector<int>(C);
    for (auto c = 0; c < C; c++)
        columns[c] = network.add_vertex();

    const auto infinity = R + C;
    for (auto r = 0; r < R; r++)
    {
        string row; cin >> row;
        for (auto c = 0; c < C; c++)
        {
            if (row[c] == '.') continue;
            if (row[c] == 'S') network.source = rows[r];
            if (row[c] == 'T') network.sink = columns[c];
            const auto capacity = row[c] == 'o' ? 1 : infinity;
            network.add_edge(rows[r], columns[c], capacity);
        }
    }

    const auto mincut = network.maxflow();
    cout << (mincut >= infinity ? -1 : mincut) << endl;
}


Measured memory_bytes: 896
#include <stdio.h>
int main(){
	int t,n,j,maxv,minv,R[200000];
	scanf("%d",&n);
	for(t=0;t<n;t++)
		scanf("%d",&R[t]);
	maxv=-2000000000;
	minv=R[0];
	for(j=1;j<n;j++){
		if(maxv<R[j]-minv)
			maxv=R[j]-minv;
		if(minv>R[j])
			minv=R[j];
	}
	printf("%d\n",maxv);
	return 0;
}


Measured memory_bytes: 2516
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

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


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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int> >v;
    while(m--)
    {
        int a,b;
        cin>>a>>b;
        v.push_back(make_pair(a,b));
    }
   int arr[n+5]={0};
   for(int i=0;i<v.size();i++)
   {
       int x=v[i].first;
       int y=v[i].second;
       arr[x]=y;
   }
  if(n>1&&arr[1]==0) arr[1]=1;
   int flag=0;
    for(int i=0;i<v.size();i++)
   {
       int x=v[i].first;
       int y=v[i].second;
       if(arr[x]!=y)flag++;
   }
   if(flag==0)
   {
       for(int i=1;i<=n;i++)cout<<arr[i];cout<<"\n";
   }
   else
   {
       cout<<-1<<endl;
   }
}


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

using namespace std;

vector<int> tree(4*100005,0);

void update(int idx,int l,int r,int pos,int val)
{
    if(l==r) tree[idx]=val;
    else
    {
        int m=(l+r)/2;
        if(pos<=m) update(2*idx,l,m,pos,val);
        else update(2*idx+1,m+1,r,pos,val);
        tree[idx]=max(tree[2*idx],tree[2*idx+1]);
    }
}

int query(int idx,int l,int r,int ql,int qr)
{
    if(ql>qr) return 0;
    if(l==ql&&r==qr) return tree[idx];
    int m=(l+r)/2;
    return max(query(2*idx,l,m,ql,min(qr,m)),query(2*idx+1,m+1,r,max(ql,m+1),qr));
}

int main()
{
    int n;
    scanf("%d",&n);
    vector<pair<int,int>> v(n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&v[n-i].first);
        v[n-i].second=i;
    }
    stable_sort(v.begin(),v.end(),[](pair<int,int> a,pair<int,int> b){return a.first<b.first;});
    int res=0;
    for(pair<int,int> p:v)
    {
        int pos=p.second;
        int id=query(1,1,n,1,pos);
        if(id==0) res++;
        else update(1,1,n,id,0);
        update(1,1,n,pos,pos);
    }
    printf("%d\n",res);
    return 0;
}


Measured memory_bytes: 3328