akhauriyash/Code-Regression huggingface dataset:
#pragma region Template
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b) * (static_cast<int>(a > b)*2 - 1); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion

signed main()
{	
	int N, K;
	cin >> N >> K;
	VI d(K);
	VVI A(K, VI(N, 0));
	rep(i, K) {
		cin >> d[i];
		rep(j, d[i]) {
			cin >> A[i][j];
		}
	}

	VI sunuke(N, 0);
	rbf(aa, A) {
		rbf(a, aa) {
			if (a == 0) break;
			sunuke[a - 1]++;
		}
	}

	int su0 = 0;
	rbf(s, sunuke) {
		if (s == 0) su0++;
	}

	COL(su0);
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#include<random>
#include<algorithm>
#include<math.h>
#define rep(i,n) for(int i = 0 ; i < (n) ; i++)
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int temp;
    cin>>temp;
    v.push_back(temp);
  }


  sort(v.begin(),v.end());

  vector<long long> r;
  for(int i=v.at(0);i<=v.at(v.size()-1);i++){
    int sum = 0;
    rep(j,N){
      sum = sum + (v.at(j) - i) * (v.at(j)-i);
    }
    r.push_back(sum);
  }

  sort(r.begin(),r.end());
  cout<< r.at(0) <<endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <int,int>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

vector <pair<int,int>> v[N];
int color[N];
void dfs(int s, int pr, int c)
{
	color[s] = c;
	for (auto g : v[s])
	{
		if(g.ff != pr)
		{
			if(g.ss % 2 == 0)
				dfs(g.ff, s, c);
			else
				dfs(g.ff, s, (c ^ 1));
		}
	}
}
int main()
{
	int n, x, y, w;
	cin >> n;
	for (int i = 0; i < n - 1; ++i)
	{
		cin >> x >> y >> w;
		v[x].push_back({y, w});
		v[y].push_back({x, w});
	}
	dfs(1, 0, 0);
	for (int i = 1; i <= n; ++i)
	{
		cout << color[i] << "\n";
	}
}	

Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define fill(x,y) memset(x,y,sizeof(x))
#define name(x) #x
using namespace std;


const int INF = INT_MAX-100;
const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int N,W;
    cin >> N >> W;
    VV(ll) vec(N+1,vector<ll>(2,0));
    
    for(auto i = 1; i<=N; i++){
        cin >> vec[i];
    }
    
    VV(ll) dp(N+1,vector<ll>(100000+1,1LL<<40));
    
    for(auto i = 0; i<=N; i++){
        dp[i][0] = 0;
    }
    
    for(auto i =1; i<=N;i++){
        
        for(auto v = 0; v<=100000; v++){
            
            if (v-vec[i][1] >= 0){
                dp[i][v] = min(dp[i-1][v],dp[i-1][v-vec[i][1]]+vec[i][0]);
            }else{
                dp[i][v] = dp[i-1][v];
            }
        }
        
    }
    
    for(auto v = 100000; v>=0; v--){
        
        if (dp[N][v] <=W){
            cout << v << endl;
            return 0;
        }
        
    }
    

    
    return 0;
}




Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;++i)
using namespace std;
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
bool gchar(){
	char ch=getchar();
	while(ch<65||ch>90) ch=getchar();
	return ch=='B'?1:0;
}
#define N 2005
int a,b,c,d[2005][2005],w[2005][2005],bq[N][N],wq[N][N],x,y,ans;
int main(){
	int n=read(),k=read(),k2=k<<1,z,ww;
	For(i,1,n){
		a=read()%k2+1,b=read()%k2+1,c=gchar();
		if (c) d[a][b]++,++x; else w[a][b]++,++y;
	}
	For(i,1,k2)
		For(j,1,k2){
			bq[i][j]=bq[i][j-1]+bq[i-1][j]-bq[i-1][j-1]+d[i][j];
			wq[i][j]=wq[i][j-1]+wq[i-1][j]-wq[i-1][j-1]+w[i][j];
		}
	For(i,1,k)
		For(j,1,k){
			z=bq[i][j]+bq[i][k2]-bq[i][j+k]+bq[k2][j]-bq[i+k][j]+bq[i+k][j+k]-bq[i+k][j]-bq[i][j+k]+bq[i][j]+bq[k2][k2]+bq[i+k][j+k]-bq[i+k][k2]-bq[k2][j+k];
			ww=wq[i][j]+wq[i][k2]-wq[i][j+k]+wq[k2][j]-wq[i+k][j]+wq[i+k][j+k]-wq[i+k][j]-wq[i][j+k]+wq[i][j]+wq[k2][k2]+wq[i+k][j+k]-wq[i+k][k2]-wq[k2][j+k];
			ans=max(ans,z+y-ww); ans=max(ans,n-z-y+ww);
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 62976
#include<stdio.h>
int main(void)
{
  int i,j,h,w;
  scanf("%d %d",&h,&w);
  while(h!=0 || w!=0){
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        if((i+j)%2==0)  printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
    scanf("%d %d",&h,&w);
  }

  return 0;
}

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


int main()
{
	ll i, j, n, m, res=0;

	scanf("%lld", &n);

	for(i=1; i<=n; i++)
	{
		scanf("%lld", &m);
		if(i%2==1 && m%2==1) res++;
	}

	printf("%lld\n", res);



	return 0;
}

Measured memory_bytes: 3824
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <limits>
#include <set>
#include <map>

int main()
{
    int n{}, m{};
    int total{};
    std::cin >> n >> m;
    std::vector<int> nums(n);
    for (int i = 0; i < n; i++) {
        std::cin >> nums[i];
        total += nums[i];
    }
    int tmp{};
    for (int i = 0; i < n; i++) {
        if (nums[i] * 4 * m >= total) {
            tmp++;
            if (tmp >= m) {
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }
    std::cout << "No" << std::endl;
    return 0;
}


Measured memory_bytes: 256
n=list(map(int,input().split()))
s=0
k=n[3]
a=n[0]
b=n[1]
d=k-a

if k-a<=0:
    s=k
if k-a>0:
    if k-a-b<=0:
        s=a;
    else:
        s=a-k+a+b
print(s)


Measured memory_bytes: 9060
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

class node {
  public:
    int key;
    node *p;
    node *l;
    node *r;
};
node *NIL, *root;

void insert(int k) {
    node *y = NIL;
    node *x = root;
    node *z = new node;
    z->key = k;
    z->l = NIL;
    z->r = NIL;
    while(x != NIL) {
        y = x;
        if(z->key < x->key)
            x = x->l;
        else
            x = x->r;
    }

    z->p = y;

    if(y == NIL) {
        root = z;
    } else if(z->key < y->key) {
        y->l = z;
    } else {
        y->r = z;
    }
}

void traverse(node *now, int order) {

    if(order == 0) cout << " " << now->key; // preorder
    if(now->l != NIL) traverse(now->l, order);
    if(order == 1) cout << " " << now->key; // inorder
    if(now->r != NIL) traverse(now->r, order);
    if(order == 2) cout << " " << now->key; // postorder
}

node *find(int k) {
    node *x = root;
    while(x != NIL && x->key != k) {
        x = x->key > k ? x->l : x->r;
    }
    return x;
}

void print() {
    traverse(root, 1);
    cout << endl;
    traverse(root, 0);
    cout << endl;
}

node *next(node *k) {
    node *x;
    if(k->r != NIL) {
        x = k->r;
        while(x->l != NIL)
            x = x->l;
        return x;
    } else {
        cout << "error";
        return NIL; // error..
    }
}

void dele(node *k) {
    node *x, *y;
    if(k->l == NIL || k->r == NIL)
        y = k;
    else
        y = next(k);

    if(y->l != NIL)
        x = y->l;
    else
        x = y->r;

    if(x != NIL) x->p = y->p;

    if(y->p == NIL)
        root = x;
    else if(y == y->p->l)
        y->p->l = x;
    else
        y->p->r = x;

    if(y != k) k->key = y->key;
    delete(y);
}

int main() {
    int n, k;
    string o;
    cin >> n;
    node *a;

    rep(i, n) {
        cin >> o;
        if(o == "insert") {
            cin >> k;
            insert(k);
        } else if(o == "find") {
            cin >> k;
            a = find(k);
            cout << (a != NIL ? "yes\n" : "no\n");
        } else if(o == "print") {
            print();
        } else if(o == "delete") {
            cin >> k;
            dele(find(k));
        }
    }
}



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

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

  if (N==1) cout << 1 << endl;
  else if (N%2==0) cout << N/2 << endl;
  else cout << N/2 +1 << endl;
}

Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Data.List
import Data.Maybe
import Data.Function (fix)
import Data.Array (Array, array, (!))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8

modular :: Integer
modular = 1000000007
 
getInts :: IO [Int]
getInts = (map parseInt . BS8.words) <$> BS.getLine 
    where parseInt = fst . fromJust . BS8.readInt

solve :: Int -> Integer
solve n = go [2..n] `mod` modular

go :: [Int] -> Integer
go [] = 1
go (x:xs) = if x == 1 then go xs else (counts xs + 2) * go xs'
    where counts xs = foldl (\acc k -> acc + snd (f k)) 0 xs
          f k = if k `mod` x == 0 then let (a, r) = f (k `div` x) in (a, r+1) else (k, 0)
          xs' = map (fst . f) xs


main :: IO ()
main = do
    [n] <- getInts
    print $ solve n

Measured memory_bytes: 3324
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define MIN -10000000
#define MAX 10000000
#define debug printf("%d",__LINE__)
using namespace std;
int main()
{
	//freopen("sb.out", "w", stdout);
	//for(int n = 1; n<=10000; n++)
	//{
	int n;
	cin >> n;
	if(n <= 1000)
	{
		if(n == 0) cout << 0 << endl;
		else cout << 1000 - n << endl;
	}
	else if(n % 1000 == 0) cout << 0 << endl;
	else if(n % 1000 != 0)
	{
		int shengXiaLaiDe;
		shengXiaLaiDe = n % 1000;
		cout << 1000 - shengXiaLaiDe << endl;
	//} 
}
}


Measured memory_bytes: 3592
import Data.Word

main :: IO ()
main = do
  c <- getContents
  putStrLn . init . unlines . map swap $ init . lines $ c 
                                                   
swap :: String -> String
swap xs = if (read $ first xs :: Int) < (read $ second xs :: Int)
                   then first xs ++ " " ++ second xs
                   else second xs ++ " " ++ first xs
                 
first :: String -> String
first wd = head $ words wd

second :: String -> String
second wd = last $ words wd



Measured memory_bytes: 4436
#include<stdio.h>
#include<limits.h>

#define N 20001
#define nil -1
#define WHITE 0
#define BLACK 1
#define INF 9999999

int n,G[N][N],d[N];

void dijkstra(int , int);
void initializeSingleSource(int);

int main(){

  int i,j,u,k,c,v,w=INF,r;
  
  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=-1;
    }
  }
  
  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&c,&v);
      G[u][c]=v;
      if(v<w && u==0) w=v;
    }
  }
 
  dijkstra(w,0);

  for(i=0;i<n;i++) printf("%d %d\n",i,d[i]);
  
  return 0;
}


void dijkstra(int w , int s){

  int i,u,v,pi[N],color[N],mincost,sum=0;

 
  for(u=0;u<n;u++){
    d[u]=INF;
    pi[u]=nil;
    color[u]=WHITE;
  }
  d[s]=0;

  while(1){

    mincost=INF;
    for(i=0;i<n;i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
      if(mincost==INF) break;

      color[u]=BLACK;

      for(v=0;v<n;v++){
	if(G[u][v]!=-1) w=G[u][v];
	else continue;
		
	if(color[v]!=BLACK && w+d[u]<d[v]){
	  pi[v]=u;
	  d[v]=w+d[u];
	}
      }
  }
  
}

Measured memory_bytes: 6868
import java.util.*;

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

    int count = sc.nextInt();

    int[] v = new int[count];
    int[] c = new int[count];

    for (int i = 0; i < count; i++ ) {
      v[i] = sc.nextInt();
    }

    for (int i = 0; i < count; i++) {
        c[i] = sc.nextInt();
    }

    int result = 0;
    for (int i = 0; i < count; i++) {
      if (v[i] > c[i]) {
        result += v[i] - c[i];
      }
    }

    System.out.println(result);
  }
}


Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
string a[3] = {"Sunny", "Cloudy", "Rainy"};
int main(void){
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s==a[i]){
            cout<<a[(i+1)%3];
        }
    }
}

Measured memory_bytes: 256
num = int(input())
m=0
a=0
r=0
c=0
h=0
for _ in range(num):
  w = input()
  if w[0] == "M":
    m = m+1  
  elif w[0] == "A":
    a = a+1    
  elif w[0] == "R":
    r = r+1
  elif w[0] == "C":
    c = c+1
  elif w[0] == "H":
    h = h+1
  else:
    None
k = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(k)


  

Measured memory_bytes: 3064
import java.util.*;
import java.io.*;
import java.math.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        ArrayList<Integer> li = new ArrayList<Integer>();
        for(int i = 0; i < k; i++){
            li.add(sc.nextInt());
        }
        int ans = n;
        while(true){
            boolean bool = true;
            int tmp = ans;
            while(tmp != 0){
                int chk = tmp % 10;
                if(li.contains(chk)){
                    bool = false;
                    break;
                }
                tmp /= 10;
            }
            if(bool){
                break;
            }else{
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21972
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード（貪欲法よる解法）
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[] a = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int[] b = IntStream.range(0, n).map(i -> scanner.nextInt()).toArray();
			int j = 0, bef = -1;
			for (int i = 0; i < n; i++) {
				if (bef != a[i]) {
					j = 0;
				}
				if (a[i] == b[i]) {
					for (; j < n; j++) {
						if ((a[j] != a[i]) && (b[j] != a[i])) {
							swap(b, i, j);
							break;
						}
					}
					if (a[i] == b[i]) {
						System.out.println("No");
						return;
					}
				}
				bef = a[i];
			}
			System.out.println("Yes");
			System.out.println(Arrays.stream(b).mapToObj(String::valueOf).collect(Collectors.joining(" ")));
		}
	}

	/**
	 * 配列のi番目のものとj番目のものを交換する
	 * 
	 * @param array 配列
	 * @param i
	 * @param j
	 */
	private static void swap(int[] array, int i, int j) {
		int temp = array[i];
		array[i] = array[j];
		array[j] = temp;
	}
}


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

using namespace std;
 
using tint = long long;
using ld = long double;
 
#define forsn(i, s, n) for(int i = int(s); i < int(n); i++)
#define forn(i, n) forsn(i, 0, n)
 
using vi = vector<tint>;
 
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
 
using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair
 
#define DBG(x) cerr << #x << " = " << x << endl;
 
const int MOD = 1e9+7;
const int MX = 3005;
const int INF = 1e9;
const ld PI = acos(ld(-1)); 
 
const int dx[8] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[8] = {0, 0, 1, -1, 1, -1, -1, 1};
 
bool valid(int x, int y, int n, int m){
	return (0<=x && x<n && 0<=y && y<m);
}
 
void NACHO(string name = "", bool file = 0){
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(file){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}
 
int main(){
    NACHO();
	int n; cin >> n;
	if(n >= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3656
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

int n,x;

int main()
{
	scanf("%d",&n);
	bool flag=true;
	for (int i=1;i<=n;i++) {
		scanf("%d",&x);
		if (x&1) continue;
		if (x%3!=0&&x%5!=0) flag=false;
	}
	if (flag) puts("APPROVED");
	else puts("DENIED");
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,k;
  cin >> n >> k;
  int arr[n+1];
  for(int i = 0; i <= n; i++){
    arr[i] = 0;
  }
  for(int i = 0; i < k; i++){
    int d;
    cin >> d;
    for(int j = 0; j < d; j++){
      int t;
      cin >> t;
      arr[t]++;
    }
  }
  int count = 0;
  for(int i = 1; i <=n; i++){
    if(arr[i] == 0){
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 3636
# すぬけくんは 3匹のヤギにクッキーを渡したいです。
# すぬけくんは A枚のクッキーが入った缶と、
# B枚のクッキーが入った缶を持っています。
# すぬけくんは A, B, A + B のいずれかの枚数のクッキーを
# ヤギたちに渡すことができます。
# 3匹のヤギが同じ枚数ずつ食べられるように
# クッキーを渡すことが可能かどうか判定してください。

# 制約
# 1 ≦ A, B ≦ 100
# A, B はいずれも整数

# 標準入力から A, B を取得する
a, b = map(int, input().split())


result = "ret"

# 以下、判定処理
if a % 3 == 0:  # Aの缶だけを渡して、3等分できる
    result = "Possible"
elif b % 3 == 0:  # Bの缶だけを渡して、3等分できる
    result = "Possible"
elif (a + b) % 3 == 0:  # A + B 缶を渡して、3等分できる
    result = "Possible"
else:
    result = "Impossible"

print(result)


Measured memory_bytes: 9084
#include <iostream>
#include <bitset>
#include <iomanip>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <algorithm>
#include <sstream>

using namespace std;

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vec2bool vector<vector<bool>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s >= 0;s--)

int main()
{
	ll n,ans=0,a=0,b=0;
	string s;

	cin >> n;

	ll buf=0;

	while (1)
	{
		a++;
		buf = pow(a, 5);

		ll buf2 = abs(n - buf);

		double buf3 = pow((double)buf2, 0.2);

		if (round(floor(buf3)*pow(10,4)) == round(buf3*pow(10,4)))
		{
			if (n > buf)
				b = -buf3;
			else
				b = buf3;

			break;
		}
	}

	cout << a << " " << b;

}


Measured memory_bytes: 4028
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
typedef pair<int,int> P;	//cost,node

struct node{
	vector<int> et;
	int size;
}*f;
int cost[500];

void BFS(int start ){
	queue<P> que;
	P now;
	que.push( P(0,start) );
	
	while( !que.empty() ){
		now = que.front();
		que.pop();
		if( cost[now.second] != 10000 )
			continue;
		cost[now.second] = now.first;
		
		node *no = &f[now.second];				
		for( int i = 0;i < no->size;i++ ){
			que.push( P(now.first+1,no->et[i]) );
		}
	}
}

int main(){
	int N,M,a,b,i;
	int ans;
	while(1){
		cin >> N >> M;
		if( N == 0 && M == 0 )break;
		
		f = new node[N];
		ans = 0;		
		for( i = 0;i < N;i++ ){
			cost[i] = 10000;
			f[i].size = 0;
		}
		
		for( i = 0;i < M;i++ ){
			cin >> a >> b;
			a--;b--;
			f[a].et.push_back(b);
			f[b].et.push_back(a);
			f[a].size++;
			f[b].size++;
		}
		BFS( 0 );
		
		for( i = 1;i < N;i++ ){
			if( cost[i] <= 2 )
				ans++;
		}
		cout << ans << endl;
		
		delete[] f;
	}
	return 0;
}

Measured memory_bytes: 1500
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 200010;

int a[N];

int main(){
	int n;
	cin >> n;
	for(int i = 0 ; i < n; i++)	cin >> a[i];
	int minv = a[0];
	int maxv = -0x3f3f3f3f;
	for(int i = 1; i < n; i++){
		maxv = max(maxv, a[i] - minv);
		minv = min(minv, a[i]);
	}
	cout << maxv << endl;
	return 0;
}


Measured memory_bytes: 3880
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int n;
int step[35];

int main()
{
	step[0] = 0;
	step[1] = 1;
	step[2] = 2;
	step[3] = 4;
	FOR(i, 1, 30)
	{
		step[i + 3] = step[i + 2] + step[i + 1] + step[i];
	}
	while (1)
	{
		cin >> n; if (n == 0) return 0;
		if (step[n] % 3650 == 0) cout << step[n] / 3650 << endl;
		else cout << step[n] / 3650 + 1 << endl;
	}

}

Measured memory_bytes: 1160
n = int(input())
a = input()
alphabet = {}
for i in a:
    alphabet.update({i: a.count(i)})
for i in range(n-1):
    b = input()
    for j in alphabet:
        alphabet[j] = min(alphabet[j], b.count(j))
ans = []
for i in alphabet:
    ans += [i]*alphabet[i]
print(''.join(sorted(ans)))
    
    
    


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

int main(){
  int n;
  cin>>n;
  long double a[n];
  string s[n];

  long double sum=0;
  for(int i=0;i<n;i++){
     cin>>a[i]>>s[i];
     if(s[i][0]=='J')
        sum+=a[i];

     else
        sum+=a[i]*380000.0;
  }

  cout<<setprecision(8)<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
n = str(input())

li,li_1 = [],[]
for i in range(len(n)):
    li.append(int(n[i]))

for i in range(len(li)-1):
    li_1.append(li[i+1]-li[i])

if (0 in li_1) == True:
    print("Bad")
else:
    print("Good")


Measured memory_bytes: 2940
// Try AtCoder
//author: Leonardone @ NEETSDKASU

fn main() {
	let mut stdin = String::new();
    std::io::Read::read_to_string(
    	&mut std::io::stdin(),
        &mut stdin).unwrap();
	let mut stdin = stdin.split_whitespace();
    let mut get = || stdin.next().unwrap();
    macro_rules! get {
    	($t:ty) => (get().parse::<$t>().unwrap());
        () => (get!(i64));
    }
    
    let n = get!();
    let mut x = get!();
    let mut ks = vec![];
    for _ in 0..n {
    	ks.push(get!());
    }
    ks.sort();
    let mut ans = 0;
    for &k in ks.iter() {
    	if x < k {
        	break;
        }
        x -= k;
        ans += 1;
    }
    if x > 0 && ans == n {
    	ans -= 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
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)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    h,w = LI()
    c = LIR(10)
    for k in range(10):
        for i in range(10):
            for j in range(10):
                nc = c[i][k]+c[k][j]
                if nc < c[i][j]:
                    c[i][j] = nc
    a = LIR(h)
    ans = 0
    for i in a:
        for j in i:
            if j < 0:
                continue
            ans += c[j][1]
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 39280
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstdio>
#include <stack>
#include <functional>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main() {
	ll a, b, x;
	cin >> a >> b >> x;

	if (x - a <= b && x - a >= 0)
	{
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

}

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

int main() {
  int N, M;
  cin >> N >> M;
  string S;
  cin >> S;
  if (S.at(M-1) == 'A') {
    S.at(M-1) = 'a';
  } else if (S.at(M-1) == 'B') {
    S.at(M-1) = 'b';
  } else {
    S.at(M-1) = 'c';
  }
  cout << S << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define triplerep(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;

int N, M, nums[100009], uni[100009];

int root( int a) {
    if (uni[a] == a) return a;
    uni[a] = root(uni[a]);
    return uni[a];
}

void connect( int a, int b){
    int pa = root(a);
    int pb = root(b);
    
    if (pa==pb) return;
    else uni[pb] = pa;
}

int main() {
    
    cin >> N >> M;
    
    rep(i,N+1) uni[i] = i;
    
    for ( int i = 1; i <= N; i++) scnd1( nums[i]);
    
    int x, y;
    rep(i,M) {
        scnd2( x, y);
        connect( x, y);
    }
    
    int ans = 0;
    for ( int i = 1; i <= N; i++) {
        if( root(uni[i]) == root(uni[nums[i]]) ) ans++;
        //prtd2(uni[i], uni[nums[i]]);
    }
    prtd1(ans);
}


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

long BIG = 1000000007;

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

int main() {
  long N, K;
  long long ans = 0;
  cin >> N >> K;

  vector<long> vec(K + 10, -1);
  for (int i = K; i > 0; i--) {
    vec[i] = modpow(K / i, N, BIG);
    for (int j = i * 2; j <= K; j += i) {
      vec[i] = (vec[i] - vec[j] + BIG) % BIG;
    }
    ans = (ans % BIG + vec[i] * i % BIG) % BIG;
    // cout << ans << endl;
  }

  cout << ans << endl;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    int n, r;
    cin >> n >> r;
    if (n >= 10) {
        out(r);
    } else {
        out(r + (100 * (10 - n)));
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>


int main(void)
{
	char	str[20] = {0}, str_copy[21] = {0};
	int			i,j=0;
	
	scanf("%s",str);

	while(1){
		if(str[j] == 0) break;
		j++;
	}

	for(i=0;i<j;i++){
		str_copy[i]=str[j-1-i];
	}

	printf("%s\r\n", str_copy);
	return 0;
}

Measured memory_bytes: 532
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
    class Program {
        static void Main(string[] args) {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            new Program().Solve(new ConsoleInput(Console.In, ' '));
            Console.Out.Flush();
        }
		public void Solve(ConsoleInput cin) {
			var line = cin.ReadLongArray(4);
			long x1 = line[0], y1 = line[1], x2 = line[2], y2 = line[3];
			long dx = x2 - x1, dy = y2 - y1;
			var lenSq = dx * dx + dy * dy;
			var q = cin.ReadInt;
			for(int i = 0; i < q; i++) {
				var p = cin.ReadLongArray(2);
				var px = p[0] - x1;
				var py = p[1] - y1;
				var outer = px * dy - py * dx;
				string state;
				switch(outer.CompareTo(0)) {
					case 1:
						state = "CLOCKWISE";
						break;
					case -1:
						state = "COUNTER_CLOCKWISE";
						break;
					default:
						var inner = px * dx + py * dy;
						if(inner < 0) state = "ONLINE_BACK";
						else {
							var lenSqP = px * px + py * py;
							if(lenSqP > lenSq) state = "ONLINE_FRONT";
							else state = "ON_SEGMENT";
						}
						break;
				}
				Console.WriteLine(state);
			}
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
	}
}



Measured memory_bytes: 18444
#include <bits/stdc++.h>
#define PB push_back
#define LL long long
#define SZ(a) (int)(a.size())
using namespace std;
string s[100005];
int ma[4];
int main() {
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> s[i];
        for(int j = 0; j < SZ(s[i]) - 1; j++)
            ans += s[i][j] == 'A' && s[i][j + 1] == 'B';
        int mask = (s[i][0] == 'B') << 1;
        mask |= s[i].back() == 'A';
        ma[mask]++;
    }
    //cout << ans << endl;
    int x = ma[1] , z = ma[2] , y = ma[3];
    int m = min(min(x , z) , y);
    ans += m * 2;
   // cout << ans << endl;
    x -= m , z -= m , y -= m;
    if(m)
        ans += y;
    if(!m)
    {
        ans += max(y - 1 , 0);
        ans += x != 0 && y != 0;
        ans += y != 0 && z != 0;
    }
    //cout << x << " " << z << endl;
   // cout << ans << endl;
    if(y == 0)
        ans += min(x , z);
    cout << ans;
    return 0;
}


Measured memory_bytes: 1536
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>

#define For(i, j, k) for(int i = j; i <= k; i++)
#define Forr(i, j, k) for(int i = j; i >= k; i--)
#define pb push_back
#define x first
#define y second
#define mp make_pair

using namespace std;

const int N = 132000;

typedef long long LL;
typedef pair<LL, LL> PII;

int lc[N], rc[N];
int val[N], fa[N], n;
vector<PII> c[N];
LL lim;

bool cmp(PII u, PII v){
	return u.x ^ v.x ? u.x < v.x : u.y < v.y;
}

bool DFS(int o){
	if(!lc[o]){
		c[o].pb(mp(val[o], val[o]));
		return true;
	}

	if(!DFS(lc[o])) return false;
	if(!DFS(rc[o])) return false;
	if(c[lc[o]].size() > c[rc[o]].size()) swap(lc[o], rc[o]);

	int u = lc[o], v = rc[o];
	int m = c[v].size(), p = m - 1;
	for(PII i : c[u]){
		while(p >= 0 && i.x + c[v][p].x > lim) --p;
		if(p < 0) break;
		//printf("%lld %lld %d\n", i.x, c[v][p].x, p);
		c[o].pb(mp(i.y, c[v][p].y)), c[o].pb(mp(c[v][p].y, i.y));
	}
	sort(c[o].begin(), c[o].end(), cmp);
	m = c[o].size() - 1;
	For(i, 1, m) if(c[o][i].y > c[o][i - 1].y) c[o][i] = c[o][i - 1];
	unique(c[o].begin(), c[o].end());

	if(!c[o].size()) return false;

	for(PII& i : c[o]) i.x += val[o], i.y += val[o];
	return true;
}

int main(){
	scanf("%d", &n);
	For(i, 2, n){
		scanf("%d%d", &fa[i], &val[i]);
		if(lc[fa[i]]) rc[fa[i]] = i;
		else lc[fa[i]] = i;
	}
	LL L = 0, R = 1ll << 35;
	while(L < R){
		lim = (L + R) >> 1;
		For(i, 1, n) c[i].clear();
		//printf("------\n%lld\n", lim);
		if(DFS(1)) R = lim;
		else L = lim + 1;
	}
	printf("%lld\n", L);
	return 0;
}

Measured memory_bytes: 25464
#include<stdio.h>
int main()
{
    long long int a,b,k;
    scanf("%lld %lld %lld",&a,&b,&k);
    if(a>k){
        a=a-k;
    }
    else{
        b=b-(k-a);
        a=0;
    }
    if(b<0)b=0;
    printf("%lld %lld",a,b);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    int w = sc.nextInt();
    int n = sc.nextInt();
    
    int [] p = new int [w];
    int i;

    for(i=0;i<w;i++){
      p[i]=i+1;
    }

    for(i=0;i<n;i++){
      String str = sc.next();
      String[] ab = str.split(",");
      int a = Integer.parseInt(ab[0]) - 1;
      int b = Integer.parseInt(ab[1]) - 1;

      int x;
      x = p[a];
      p[a] = p[b];
      p[b] = x;


    }

    for(i=0;i<w;i++){
      System.out.println(p[i]);
    }
    sc.close();
  }
}


Measured memory_bytes: 26160
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
using namespace std;
 
int main(){
    
    int A,B,C,ans=0,tmp=0;
    cin >> A>>B>>C;

    if((B/A)>=C){
        ans = C;
    }else{
        while(1){
            tmp+=A;
            if(tmp<=B){
                ans +=1;
            }else{
                break;
            }
        }
    }
  
    cout << ans ;

    return 0;

}

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

int main(){
    int N;
    scanf("%d", &N);
    int t, x, y;
    int t_pre = 0, x_pre = 0, y_pre = 0;
    for(int i = 0; i < N;i++){
        scanf("%d %d %d", &t, &x, &y);
        if(!((t - t_pre >= abs(x - x_pre)+ abs(y -y_pre)) && ((t - t_pre - (x-x_pre)  - (y-y_pre)) % 2 == 0))){
            printf("No");
            return 0;
        }
        t_pre = t;
        x_pre = x;
        y_pre = y;
    }
    printf("Yes");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> va(n, 0), vb(n, 0);
    unordered_map<int, int> um;
    for (int i = 0; i < n; i++) {
        cin >> va[i];
        um[va[i]]++;
    }
    for (int i = 0; i < n; i++) {
        cin >> vb[i];
        um[vb[i]]++;
    }
    for (auto p : um) {
        if (p.second > n) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    deque<pair<int, int>> dq;
    for (int i = 0; i < n; i++) {
        if (va[i] == vb[i]) {
            if (dq.size() > 0 && dq.front().first != va[i]) {
                int index = dq.front().second;
                dq.pop_front();
                swap(vb[i], vb[index]);
            } else {
                dq.push_back(make_pair(va[i], i));
            }
        }
    }
    for (int i = 0; i < n && dq.size() > 0; i++) {
        if (va[i] != dq.front().first && vb[i] != dq.front().first) {
            swap(vb[i], vb[dq.front().second]);
            dq.pop_front();
        }
    }
    for (int i = 0; i < n; i++) {
        cout << vb[i] << " ";
    }
    cout << endl;
}




Measured memory_bytes: 12932
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define pi acos(-1.0)
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
typedef long long LL;
typedef unsigned long long ULL;

int main()
{
    LL n,a,b;
    cin>>n>>a>>b;
    if(a>b||(n==1&&a!=b)||(n==2&&a==b))
    {
        cout<<0<<endl;
    }
    else if((n==1&&a==b)||(n==2&&a!=b))
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<(n-2)*(b-a)+1<<endl;
    }
    return 0;
}





















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

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){//最大公約数
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

    if( a % b == 0 ) return b;
    return gcd( b, a % b );
}

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

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

    return true;
}


//入力

int a, b, c, d;

int main(){

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

    while(1){
        c -= b;
        if(c <= 0){
            cout << "Yes" << endl;
            break;
        }

        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            break;
        }
    }


    return 0;
}

Measured memory_bytes: 3596
from math import factorial
 
N, M = map(int, input().split())
if N != 0 and M != 0 and N != 1 and M != 1:
  Ncon = factorial(N) // factorial(2) // factorial(N - 2)
  Mcon = factorial(M) // factorial(2) // factorial(M - 2)
  print(Ncon+Mcon)
if N ==0 or N == 1:
  if M!=1:
    print(factorial(M) // factorial(2) // factorial(M - 2))
if M == 0 or M==1:
  if N!=1:
    print(factorial(N) // factorial(2) // factorial(N - 2))
if N==1 and M==1:
  print(0)

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

static int count = 0;

void bubbleSort(int A[], int n){
    bool flag = 1;
    int i = 0;
    while(flag){
        flag = 0;
        for(int j = n - 1; j > i; j--){
            if(A[j] < A[j-1]){
                swap(A[j], A[j-1]);
                flag = 1;
                count++;
            }
        }
        i++;
    }
    
}

int main(void){
    int n;
    cin >> n;
    int A[n];
    for(int i = 0; i < n; i++) cin >> A[i];
    bubbleSort(A, n);
    for(int i = 0; i < n; i++){
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << count << endl;
    
}

Measured memory_bytes: 3060
n = int(input())
x = 10**9 + 7
if n<3:
    print(0)
else:
    dp = [1]*(n+1)
    for i in range(6,n+1):
        for j in range(3,i-2):
            dp[i]+=dp[i-j]
    print(dp[-1]%x)

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

int main(){

  char str[100000];
  int al[26]={};
  scanf("%s",str);
  int i;
  for(i=0;i<=strlen(str);i++){
    int a=str[i];
    al[a-97]=3;
  }

  for(i=0;i<26;i++){
    if(al[i]==0){
      printf("%c\n",i+97);
      break;
    }
    else if(i==25)printf("None\n");
  }

  return 0;

}



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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn int

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  int n;
  cin >> n;
  vector<string> v(n, "@");
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }

  for (int i = 1; i < n; i++) {
    if(v[i-1][int(v[i-1].size())-1] != v[i][0])
    {
      cout << "No" << endl;
      return 0;
    }
    for (int j = 0; j < n; j++) {
      if(v[i] == v[j] && i != j)
      {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;


}

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

int main(){
    int N;
    cin >> N;
    int ans = 1;
    for (int64_t i = 0; i <= 100000; i++){
        if (i * i <= N){
            ans = i * i;
        }
    }
    cout << ans << endl;   
}

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

using namespace std;

typedef long long  ll;

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

    int n, q, time;
    string s;

    cin >> n >> q;
    queue<pair<int, string>> que;

    // Input
    for (int i = 0; i < n; ++i) {
        cin >> s >> time;
        que.push(make_pair(time, s));
    }

    int take_time = 0;
    while (!que.empty()) {
        pair<int, string> now = que.front(); que.pop();
        if (now.first - q <= 0) {
            take_time += now.first;
            cout << now.second << " " << take_time << "\n";
        }
        else {
            take_time += q;
            now.first -= q;
            que.push(now);
        }
    }

    return 0;
}

Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    int n;
    scanf("%d",&n);
    string s;
    cin >> s;
    int q;
    scanf("%d",&q);
    while(q--){
        int k;
        scanf("%d",&k);
        deque<P> dq;
        ll ans = 0;
        ll sum = 0;
        ll c = 0;
        rep(i,n){
            if(!dq.empty()){
                if(dq[0].first<=i-k){
                    sum -= dq[0].second;
                    dq.pop_front();
                }
            }

            if(s[i]=='D'){
                dq.push_back(P(i,-c));
                sum += -c;
            }else if(s[i]=='M'){
                ++c;
            }else if(s[i]=='C'){
                ans += sum + (ll)(dq.size())*c;
            }

        }
        printf("%lld\n",ans);
    }
    return 0;
}

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

int main() {
    int n, t; cin >> n >> t;
    int dp_m[n+1][t], dp[n+1][t];
    memset(dp, 0, sizeof(dp));
    memset(dp_m, 0, sizeof(dp_m));
    for (int i = 0; i < n; i++) {
        int a, b; cin >> a >> b;
        for (int j = 0; j < t; j++) {
            if (j + a < t) {
                dp_m[i+1][j+a] = max(dp_m[i+1][j+a], dp_m[i][j] + b);
                dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j]+b);
            }
            dp_m[i+1][j] = max(dp_m[i+1][j], dp_m[i][j]);
            dp[i+1][j] = max({dp[i+1][j], dp[i][j], dp_m[i][j]+b});
        }
    } 
    int ans = 0;
    for (int i = 0; i < t; i++) ans = max(ans, dp[n][i]);
    cout << ans << endl;
    return 0;
}

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

    queue<long long int> que;
    for (int i = 1; i < 10; i++)
    {
        que.push(i);
    }

    long long int X;    
    for (int i = 0; i < K; i++)
    {
        X = que.front();
        que.pop();
        if(X % 10 != 0) que.push(10 * X + (X % 10) - 1);
        que.push(10 * X + (X % 10));
        if(X % 10 != 9) que.push(10 * X + (X % 10) + 1);
    }
    
    cout << X << endl;
}

Measured memory_bytes: 1792
N = int(input())
ans = [0 for i in range(N)]


arr1 = [[0 for i in range(N)] for j in range(3)]
for i in range(N):
	num = list(map(int, input().split()))
	arr1[0][i] = num[0]
	arr1[1][i] = num[1]
	arr1[2][i] = num[2]


for i in range(3):
	check = [0 for i in range(100)]
	for j in range(N):
		check[arr1[i][j]-1] += 1
		
	for j in range(N):
		if check[arr1[i][j]-1] == 1:
			ans[j] += arr1[i][j]

		

for i in range(N):
	print(ans[i])
	




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


int main()
{
  int x;
  cin >> x;
  rep(i, x)
  {
    ll a = i * i;
    a *= a * i;
    int l = -1000;
    int r = 1000;
    while (l + 1 < r)
    {
      int mid = (l + r) / 2;
      ll b = mid * mid;
      b *= b * mid;
      if (a - b == x)
      {
        printf("%d %d\n", i, mid);
        return 0;
      }
      else if(a - b > x)
        l = mid;
      else
        r = mid;
    }
  }
  return 0;
}

Measured memory_bytes: 3772
#include <bits/stdc++.h>
#define pb push_back
#define Int long long
using namespace std;

const int MAXN=500005;
const int NAX=1005;
const long MOD=(long)(1e9+7);

Int N,M,K;
Int X,Y,Z;
Int H,W;
Int perform(Int x){
    return (x*(x+1))/2LL;
}
vector<Int> A;
vector<int> adj[MAXN];
using D=long double;

int main()
{
    cin>>N;
    cout<<(!N ? 1:0)<<"\n";
}


Measured memory_bytes: 15352
S = input()
T = input()
t =1

if len(T)==len(S)+1:
  t*=1
else:
  t*=0

for i in range(len(S)):
  if S[i] ==T[i]:
    t *=1
  else:
    t *=0

if t ==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SIZE 200005
#define INF 100000000000000000LL

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

int main(){
    int N,K;
    vector<int> h;
    cin>>N>>K;
    h.resize(N);
    rep(i,N){
        cin>>h[i];
    }
    sort(h.begin(),h.end());
    int ans = -1;
    for(int i = 0;i + K - 1 < N;i++){
        int temp = h[i+K-1]-h[i];
        ans = ((ans<0||ans>temp)?temp:ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
// Aizu Vol-5 0544: Sugoroku
// 2017.8.31 bal4u@uu

#include <stdio.h>

int s[1003], x[1003];

int main()
{
	int n, m, i, p;

	while (scanf("%d%d", &n, &m) && n) {
		for (i = 1; i <= n; i++) scanf("%d", s+i);
		for (i = 1; i <= m; i++) scanf("%d", x+i);
		for (p = 1, i = 1, p = 1; p < n; ) p += x[i++], p += s[p];
		printf("%d\n", i-1);
	}
	return 0;
}

Measured memory_bytes: 608
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0;i<(int)(n);i++)
typedef long long ll;
////////////////////////////////////////////////
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: 3600