akhauriyash/Code-Regression huggingface dataset:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

H, W = mapint()
query = [list(input()) for _ in range(H)]

rows = [0]*H
cols = [0]*W
for h in range(H):
    for w in range(W):
        if query[h][w]=='#':
            rows[h] = 1
            cols[w] = 1

for h in range(H):
    if not rows[h]:
        continue
    ans = []
    for w in range(W):
        if cols[w]:
            ans.append(query[h][w])
    print(''.join(ans))

Measured memory_bytes: 66060
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

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

	int ans = 0;
	ans += N * (N - 1) / 2;
	ans += M * (M - 1) / 2;
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <stdio.h>
#include <fstream>
using namespace std;

int main()
{
  string str;
  int num;
  int sum[26]={};
  // getline(cin,str);
  // fgets(str,stdin);
  while(getline(cin,str))
    {
  for(int i=0;i<str.size();i++)
    {
      if('a'<=str[i]&&str[i]<='z')
	  sum[str[i]-'a']++;
      if('A'<=str[i]&&str[i]<='Z')
	sum[str[i]-'A']++;
    }
    }

  for(int j=0;j<26;j++)
    {
      cout << (char)('a'+j) << " : " << sum[j] << endl;
    }

  return 0;
}

Measured memory_bytes: 1176
/* ex 7_1
   nabe9393 */

#include<stdio.h>

typedef struct point{
  int x_elem;
  int y_elem;
}point;

//qを中心にしてpを回す
point shift_point(point p, point q){
  point r;
  //複素数平面を考えて、各頂点をその他の頂点を中心に回転させる
  //cos270°+isin270°=-i
  r.x_elem = q.x_elem + p.y_elem - q.y_elem;
  r.y_elem = q.y_elem - p.x_elem + q.x_elem;
  return r;
}

int main(void){
  //各頂点の構造体
  point point_1,point_2,point_3,point_4;
  //入力
  scanf("%d %d",&point_1.x_elem,&point_1.y_elem);
  scanf("%d %d",&point_2.x_elem,&point_2.y_elem);

  //各頂点の計算
  point_3=shift_point(point_1, point_2);
  point_4=shift_point(point_2, point_3);
  
  //出力
  printf("%d %d %d %d\n", point_3.x_elem,point_3.y_elem,point_4.x_elem,point_4.y_elem);
  return 0;
}


Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;


int main(){
  double a, b, x;
  cin >> a >> b >> x;
  double s = x/a;
  double X, Y;
  if(s <= a*b/2) {
    X = b;
    Y = 2*s/b;
  }else{
    X = (a*b-s)*2/a;
    Y = a;
  }
  double rad = atan2(Y,X);
  double degree = 90 - rad * 180/ 3.1415926535;
  printf("%.10lf",degree);
}

Measured memory_bytes: 512
N = int(input())
A = input()
B = input()
C = input()

ans = 0
for i in range(N):
    if A[i]==B[i] and B[i]==C[i]: continue
    elif A[i]==B[i] and C[i]!=A[i]: ans += 1
    elif A[i]==C[i] and B[i]!=C[i]: ans += 1
    elif B[i]==C[i] and A[i]!=B[i]: ans += 1
    else: ans += 2
print(ans)

Measured memory_bytes: 3064
from datetime import datetime

s = list(map(int,input().split("/")))
y, m, d = s

d1 = datetime(year=y, month=m, day=d)
d2 = datetime(year=2019, month=4, day=30)

if d1 <= d2:
  print("Heisei")
else:
  print("TBD")


Measured memory_bytes: 3312
<?php

$a = fgets(STDIN);//2
$b = fgets(STDIN);//2
$c = fgets(STDIN);//2
$total = fgets(STDIN);//100
$num = 0;

for($i=0; $i<=$a; $i++){
    for($j=0; $j<=$b; $j++){
        for($k=0; $k<=$c; $k++){
            $sum = 500*$i + 100*$j + 50*$k;
            if($sum == $total){
                $num++;       
            }
        }
    }
}

echo $num;

Measured memory_bytes: 4340
using namespace std;
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define N 100001
struct dian{
	int x,y,no;
}xx[N],yy[N];
bool cmpx(dian hh,dian aa)
{
	return hh.x<aa.x;
}
bool cmpy(dian hh,dian aa)
{
	return hh.y<aa.y;
}
 
int x[N],y[N];
struct edge{
	int from,to,val;
}E[N];
bool cmp(edge hh,edge aa)
{
	return hh.val<aa.val;
}
int cnt=0;
int fa[N];
int ans;
int getf(int no)
{
	return fa[no]==no?no:fa[no]=getf(fa[no]);
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&x[i],&y[i]);
	}
	for(int i=1;i<=n;i++) 
	{
		xx[i].x=x[i];xx[i].y=y[i];xx[i].no=i;
	}
	sort(xx+1,xx+n+1,cmpx);
	for(int i=1;i<=n-1;i++)
	{
		E[++cnt].from=xx[i].no;
		E[cnt].to=xx[i+1].no;
		E[cnt].val=xx[i+1].x-xx[i].x;
	}
	sort(xx+1,xx+n+1,cmpy);
	for(int i=1;i<=n-1;i++)
	{
		E[++cnt].from=xx[i].no;
		E[cnt].to=xx[i+1].no;
		E[cnt].val=xx[i+1].y-xx[i].y;
	}
	sort(E+1,E+cnt+1,cmp);
	for(int i=1;i<=n;i++) fa[i]=i;
	int zkx=0;
	for(int i=1;i<=cnt;i++)
	{
		if(getf(E[i].from)!=getf(E[i].to))
		{
			fa[fa[E[i].from]]=fa[E[i].to];
			ans+=E[i].val;
			zkx++;
		}
		if(zkx==n-1) break;
	}
	cout<<ans<<endl; 
}

Measured memory_bytes: 4992
MOD=10**9+7
H,W,A,B=map(int,input().split())

def invmod(a):
  return pow(a,MOD-2,MOD)
def comb_mod(n,r):
  return fact_dic[n]*fact_inv_dic[r]*fact_inv_dic[n-r]

fact_dic={0:1}
fact_inv_dic={0:1}
fact_mod=1
for i in range(1,H+W-1):
  fact_mod=(fact_mod*i)%MOD
  fact_dic[i]=fact_mod
  fact_inv_dic[i]=invmod(fact_mod)
  
answer=0
if H-A>=W-B:
  for i in range(B,W):
    answer+=comb_mod(H-A+B-1,i)*comb_mod(W+A-B-1,W-1-i)
    answer%=MOD
else:
  for j in range(H-A):
    answer+=comb_mod(H-A+B-1,B+j)*comb_mod(W+A-B-1,W-B-1-j)
    answer%=MOD
    
print(answer)

Measured memory_bytes: 90224
using System;

namespace ABC100_1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] st = Console.ReadLine().Split();
            int a = Int32.Parse(st[0]);
            int b = Int32.Parse(st[1]);
            if(a > 8 || b > 8)
            {
                Console.WriteLine(":(");
            } else
            {
                Console.WriteLine("Yay!");
            }
        }
    }
}

Measured memory_bytes: 11092
from collections import defaultdict
d = defaultdict(int)
n, k, q = map(int, input().split())
for i in range(q):
  d[int(input())] += 1

for i in range(n):
  p = k - q
  if i + 1 in d:
    p += d[i + 1]
  if p <= 0:
    print('No')
  else:
    print('Yes')

Measured memory_bytes: 9448
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    // 入力値の読み込み
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int L = sc.nextInt();
    int[] Ls = new int[N];
    int min = 100; // Lの最大値
    int sum = 0;
    // 絶対値最小を検出
    for(int i=0; i<Ls.length; i++){
      Ls[i] = L + i;
      if(Math.abs(Ls[i]) < Math.abs(min)){
        min = Ls[i];
      }
      sum += Ls[i];
    }
    sum -= min;
    System.out.println(sum);
  }
}

Measured memory_bytes: 22740
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n=II()
	a=pow(10,n,10**9+7)
	b=pow(9,n,10**9+7)
	c=pow(8,n,10**9+7)
	print((a-2*b+c)%(10**9+7))
	

if __name__=="__main__":
	main()


Measured memory_bytes: 9216
#include<iostream>
#include<algorithm>
#include<stack>
using namespace std;
string s;
int a,b,c,d;
int eval(int n)
{
	d=n%10;n/=10;c=n%10;n/=10;b=n%10;n/=10;a=n;
	stack<int>S;
	int A,B;
	for(int i=0;i<s.size();i++)
	{
		switch(s[i])
		{
			case'a':S.push(a);break;
			case'b':S.push(b);break;
			case'c':S.push(c);break;
			case'd':S.push(d);break;
			case'*':
				A=S.top();S.pop();
				B=S.top();S.pop();
				S.push(A&B);
				break;
			case'+':
				A=S.top();S.pop();
				B=S.top();S.pop();
				S.push(A|B);
				break;
			case'^':
				A=S.top();S.pop();
				B=S.top();S.pop();
				S.push(A^B);
				break;
		}
	}
	return S.top();
}
main()
{
	while(cin>>s,s!=".")
	{
		reverse(s.begin(),s.end());
		int p;cin>>p;
		int cnt[20]={};
		for(int i=0;i<1e4;i++)cnt[eval(i)]++;
		cout<<eval(p)<<" "<<cnt[eval(p)]<<endl;
	}
}



Measured memory_bytes: 3176
import java.io.IOException;
import java.util.Scanner;
public class Main {
	static int mod=1000000007;
	static Scanner scan=new Scanner(System.in);
	static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
	static long lcm (long a, long b) {return a*b/gcd(a,b);}
	static int max(int a,int b) {return a>b?a:b;}
	static int min(int a,int b) {return a<b?a:b;}
	static long factorial(int i) {return i==1?1:i*factorial(i-1);}
	static int lower_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<=key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static int upper_bound(int a[],int key) {
		int low=0,high=a.length;
		while(low<high) {
			int mid=((high-low)/2)+low;
			if(a[mid]<key)low=mid+1;
			else high=mid;
		}
		return high;
		}
	static boolean isPrime (int n) {
		if (n==2) return true;
		if (n<2 || n%2==0) return false;
		double d = Math.sqrt(n);
		for (int i=3; i<=d; i+=2)if(n%i==0){return false;}
		return true;
	}
	static int upper_division(int a,int b) {
		if(a%b==0) {
			return a/b;
		}
		else {
			return a/b+1;
		}
	}
	static long lupper_division(long a,long b) {
		if(a%b==0) {
			return a/b;
			}
		else {
			return a/b+1;
		}
	}
	static long lmax(long a,long b) {return Math.max(a, b);}
	static long lmin(long a,long b) {return Math.min(a, b);}
	static int[] setArray(int a) {
		int b[]=new int[a];
		for(int i=0;i<a;i++) {
			b[i]=scan.nextInt();
		}
		return b;
	}
	static String reverce(String str) {
		String strr="";
		for(int i=str.length()-1;i>=0;i--) {
			strr+=str.charAt(i);
		}
		return strr;
	}
	static long modpow(long a,long n) {
		if(n==0) return 1;
		else if(n==1)return a;
		long tmp=modpow(a,n/2);
		tmp%=mod;
		tmp*=tmp;
		tmp%=mod;
		if(n%2==0)return tmp;
		else return (tmp*a)%mod;
	}
	public static void main(String[] args) throws IOException {
		int a=scan.nextInt();
		if(a<=999) {
			System.out.println("ABC");
		}
		else {
			System.out.println("ABD");
		}
	}
}


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

#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define Int const int &

const int N=2*(1e5)+1;

int f;
inline void read(int &p) {
	char c=getchar();
	f=1;
	while (c<48 || c>57) {
		if (c=='-') {
			f=-1;
		}
		c=getchar();
	}
	p=0;
	while (c>47 && c<58) {
		p=p*10+c-48;
		c=getchar();
	}
	p*=f;
}

int a[N], b[N];

int main(void) {
	int n;
	read(n);
	for (int i=1; i<=n; i++) {
		read(a[i]);
	}
	for (int j=n; j>0; j-=2) {
		printf("%d ", a[j]);
	}
	int j = n%2 ? 2 : 1;
	while (j<=n) {
		printf("%d ", a[j]);
		j+=2;
	}
	return 0;
}


Measured memory_bytes: 2944
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

const int sz=150;
#define P(a) ((a)+sz/2)
int dy[]={1,1,0,-1,-1,0},dx[]={0,1,1,0,-1,-1};
int main(){
	int t,n;
	while(cin>>t>>n,t|n){
		vvi f(sz,vi(sz));
		REP(i,n){
			int x,y;
			cin>>x>>y;
			f[P(y)][P(x)]=1;
		}
		pii start;
		cin>>start.second>>start.first;
		queue<pii> q;
		vvi cost(sz,vi(sz,-1));
		q.push(start);
		cost[P(start.first)][P(start.second)]=0;
		while(!q.empty()){
			pii p=q.front();q.pop();
			REP(d,6){
				int y=p.first+dy[d];
				int x=p.second+dx[d];
				if(!f[P(y)][P(x)]&&cost[P(y)][P(x)]==-1){
					int newcost=cost[P(p.first)][P(p.second)]+1;
					cost[P(y)][P(x)]=newcost;
					if(newcost<t){
						q.push(make_pair(y,x));
					}
				}
			}
		}
		int ans=0;
		REP(i,sz){
			REP(j,sz){
				if(cost[i][j]!=-1){
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
}

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

int main() {
  vector<long long> A(3);
  for (int i = 0; i < 3; ++i) cin >> A[i];
  long long K;
  cin >> K;
  sort(A.begin(), A.end());
  for (int i = 0; i < K; ++i) A.back() *= 2;
  cout << A[0] + A[1] + A[2] << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define ss second
#define ff first
#define INF 300000000000001
#define ll_max 9000000000000000001
#define mod 998244353
#define PI 3.14159265358979323846L
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define db(args...) {string _ss = #args; replace(_ss.begin(), _ss.end(), ',' , ' '); stringstream ___s(_ss) ; debug(___s, args);}
using namespace std;
typedef vector<pair<ll,ll> > vll;
typedef vector<pair<int,int> > vii ;
typedef pair<ll,ll> pll;
const ll N = 500001;
const ll M = 21;
struct point {
    ll x, y;
    bool operator == (point b)
    {
        if(this -> x == b.x && this -> y == b.y) return 1;
        return 0;
    }
    bool operator != (point b)
    {
        return !(*this == b);
    }
};

void debug(stringstream &s){}
template <typename T, typename... Args>
void debug(stringstream &s, T a, Args... args)
{
    string word;
    s >> word;
    cout << word << " = " << a << endl;
    debug(s, args...);
}

ll fast_exp(ll x,ll n)
{
    if(n == 0) return 1;
    ll ans;
    if(n % 2 == 0)
    {
         ans = fast_exp(x, n / 2);
         ans = ans * ans;
    }
    else ans = fast_exp(x, n - 1) * x;
    return ans;
}

int main()
{
    fast;
    int _ = 1;
    //cin >> _;
    while(_--)
    {
        ll n, m = 1, x = 0, y = 0, ans = 0, k;
        cin >> n;
        if(n == 0)
        {
            cin >> x;
            if(x == 1) cout << 1;
            else cout << "-1";
            return 0;
        }
        ll a[n + 1], b[n + 1];
        b[0] = 1;
        for(int i = 0; i <= n; i++)
        {
            cin >> a[i];
            if(i > 0)
            {
                if(b[i - 1] * 2 > INF)
                    b[i] = INF - a[i];
                else b[i] = b[i - 1] * 2 - a[i];
            }
            if(b[i] < 0) m = 0;
            //cout << b[i] << " |\n";
        }
        m = (m & (!a[0]));
        ans = a[n];
        b[n] = 0;
        for(int i = n - 1; i > -1; i--)
        {
            b[i] = min(b[i + 1] + a[i + 1], b[i]);
            if(b[i] * 2 < b[i + 1] + a[i + 1]) m = 0;
            ans += b[i] + a[i];
        }
        if(m)
            cout << ans << "\n";
        else cout << "-1";
     }
    return 0;
}


Measured memory_bytes: 5176
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>

//同じコードでそんなにばらつくんですか

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 120000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = ((tmp & ma0) ^ ma0) ? 68 - __builtin_ctzll((tmp & ma0) ^ ma0) : 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

bool NG[100001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int N = getint(), M = getint();
	int H[100001];
	rep1(i, N) H[i] = getint();
	rep(i, M) {
		int a = getint(), b = getint();
		if (H[a] >= H[b]) NG[b] = 1;
		if (H[a] <= H[b]) NG[a] = 1;
	}
	int kotae = N;
	rep1(i, N) kotae -= NG[i];

	printf("%d", kotae);

	Would you please return 0;
}

Measured memory_bytes: 2208
def main():
    X = int(input())
    if X == 1000:
        return 1000

    beki = [1,]
    for i in range(2,35):
        for j in range(2,11):
            if i**j<= 1000:
                beki.append(i**j)
    beki.sort()
    for i in range(len(beki)):
        if beki[i]>X:
            return beki[i-1]

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main { 
	private int[] heap;
	private int counter = 1;
	
	public Main(int size) {
		heap = new int[size + 1];
	}
	
	
	public void insert(int num) {
		if (heap.length <= counter) {
			return;
		}
		heap[counter] = num;
		counter++;
	}
	
	public void printHeap() {
		
		for (int i = 1; i < heap.length; i++) {
			String ans = "node " + (i) + ": ";
			int key = i;
			int parent = (int) Math.floor(i/2);
			int left = 2 * i;
			int right = (2 * i) + 1;
			
			ans += "key = " + heap[key] + ", ";
			
			if (parent > 0) {
				ans += "parent key = " + heap[parent] + ", ";
			}
			
			if (left < heap.length) {
				ans += "left key = " + heap[left] + ", ";
			}
			
			if (right < heap.length) {
				ans += "right key = " + heap[right] + ", ";
			}
			
			System.out.println(ans);
		}
		
		
		return;
	}
	
	
	// Driver code 
	public static void main(String[] arg) { 
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		Main bHeap = new Main(n);
		for(int i = 0; i < n; i ++) {
			bHeap.insert(in.nextInt());
		}
		in.close();
		
		bHeap.printHeap();
	} 
}


Measured memory_bytes: 27904
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;

using namespace std;

int main(void){
    char ch[55];
    int N; string S;
    cin>>N;
    cin>>S;
    if(N%2==1){
        cout<<"No"<<endl;
    } else{
        bool OK=true;
        rep(i, N/2){
            if(S[i+N/2] != S[i])
                OK=false;
        }
        if(OK) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdlib.h>
#include <string.h>

using namespace std;

int main()
{
    int a,b,c,d,s,e;
    cin>>a>>b>>c>>d;
    if(a<=c)
        s=c;
    else
        s=a;

    if(b<=d)
        e=b;
    else
        e=d;

    if((e-s)> 0)
        cout<<e-s;
    else
        cout<<0;
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const static int n = 5;
char a[n][n];

int main() {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> a[i][j];
        }
    }
    cout << a[0][0];
    cout << a[1][1];
    cout << a[2][2] << endl;
    return 0;
}


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

int N;
vector<int> x[30][2];
int cnt[30];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    for(int i = 0; i < N; i++){
        int A;
        cin >> A;
        for(int j = 0; j <= 28; j++){
            int mask = (2 << j) - 1;
            x[j][(A >> j) & 1].push_back(mask & A);
        }
    }
    for(int i = 0; i <= 28; i++){
        for(int j = 0; j < 2; j++){
            sort(x[i][j].begin(), x[i][j].end());
        }
    }
    for(int i = 0; i < N; i++){
        int B;
        cin >> B;
        for(int j = 28; j >= 0; j--){
            B = B & ((2 << j) - 1);
            if((1 << j) <= B){
                int ub = x[j][1].size();                
                int lb = (3 << j) - B;
                lb = lower_bound(x[j][1].begin(), x[j][1].end(), lb) - x[j][1].begin();
                cnt[j] += (ub - lb) % 2;

                ub = (2 << j) - 1 - B;
                ub = upper_bound(x[j][0].begin(), x[j][0].end(), ub) - x[j][0].begin();
                lb = 0;
                cnt[j] += (ub - lb) % 2;
            }else{
                int ub = (2 << j) - 1 - B;
                ub = upper_bound(x[j][1].begin(), x[j][1].end(), ub) - x[j][1].begin();
                int lb = 0;
                cnt[j] += (ub - lb) % 2;

                ub = x[j][0].size();
                lb = (1 << j) - B;
                lb = lower_bound(x[j][0].begin(), x[j][0].end(), lb) - x[j][0].begin();
                cnt[j] += (ub - lb) % 2;
            }
        }
    }
    int ans = 0;
    for(int i = 0; i < 30; i++){
        if(cnt[i] % 2) ans |= 1 << i;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 29908
#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>;

ll comb(int n, int r) {
    if (r == 0 || r == n) return 1;
    else if (r == 1) return n;
    return comb(n-1, r-1) + comb(n-1, r);
}

int main() {
    int n, p;
    cin >> n >> p;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);
    int sum = 0, odd = 0;
    rep(i,n) {
        sum += a.at(i);
        if (a.at(i) % 2 == 1) odd++;
    }
    int r = sum%2;
    ll ans = 0;
    if (odd == 0) {
        if (p == r) ans = (ll) 1<<n;
        cout << ans << endl;
        return 0;
    }
    ans = (ll) 1<<(n-1);
    cout << ans << endl;
    
    return 0;
}

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

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

    int n;
    cin >> n;
    vector<int> c(n-1), s(n-1), f(n-1);
    for(int i = 0; i < n-1; ++i) cin >> c[i] >> s[i] >> f[i];

    vector<int> res(n, 0);
    for(int i = 0; i < n-1; ++i){
        int time = 0;
        for(int j = i; j < n-1; ++j){
            int sj = s[j];
            int fj = f[j];

            while(sj < time) sj += fj;
            time = sj;
            time += c[j];
        }

        res[i] = time;
    }

    for(int i = 0; i < n; ++i) cout << res[i] << endl;
}

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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll K, X;
  cin >> K >> X;

  repi(i, X-K+1, X+K){
    cout << i << (i == X+K-1 ? '\n' : ' ');
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>

using namespace std;
int main()
{
    string a;
    cin>>a;
    if(a == "Sunny"){
        cout<<"Cloudy";
    }
    else if(a == "Cloudy"){
        cout<<"Rainy";
    }
    else if(a == "Rainy"){
        cout<<"Sunny";
    }

    return 0;
}

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

using namespace std;

int main() {
  int n, m, q;
  cin >> n >> m >> q;
  vector< vector<int> > sums(n + 1, vector<int>(n + 1, 0));
  for (int i = 0; i < m; ++i) {
    int l, r;
    cin >> l >> r;
    sums[l][r]++;
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      sums[i][j] += sums[i][j - 1];
    }
  }

  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      sums[i][j] += sums[i - 1][j];
    }
  }
  for (int i = 0; i < q; ++i) {
    int l, r;
    cin >> l >> r;
    cout << sums[r][r] + sums[l - 1][l - 1] - sums[l - 1][r] - sums[r][l - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <set>
#include <vector>

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

int n, m;
UnionFind uf(100005);

int main(void)
{
	cin >> n >> m;
	int u, v, z;
	for(int i = 1; i <= m; i++){
		cin >> u >> v >> z;
		uf.unite(u, v);
	}
	set<int> S;
	for(int i = 1; i <= n; i++) S.insert(uf.root(i));
	cout << S.size() << endl;
	return 0;
}

Measured memory_bytes: 5376
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    int h, w; cin>>h>>w;
    vector<string> c(h);
    for(int i=0; i<h; i++) cin>>c[i];

    int ans = 0;
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            for(int k=0; k<h; k++){
                for(int l=0; l<w; l++){
                    if(c[i][j] == 'B' and c[k][l] == 'B'){
                        chmax(ans, abs(i - k) + abs(j - l));
                    }
                }
            }
        }
    }

    cout << ans << endl;
}


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

#define Set(a, b) memset(a, b, sizeof (a))
#define For(i, j, k) for (int i = j; i <= k; ++ i)
#define Forr(i, j, k) for (int i = j; i >= k; -- i)

using namespace std;

typedef long long ll;

inline int read() {
	int x = 0, p = 1; char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') p = -1;
	for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	return x * p;
}

template <typename T> inline bool chkmin(T &a, T b) { return a > b ? a = b, 1 : 0; }

inline void File() {
	freopen("g.in", "r", stdin);
	freopen("g.out", "w", stdout);
}

const int N = 2e5 + 10, inf = 0x3f3f3f3f;

int n, m, fa[N], cnt, val[N];

struct edge {
	int u, v, w;
	bool operator < (const edge &rhs) const {
		return w < rhs.w;
	}
} E[N << 1];

int find(int x) {
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main() {

	Set(val, inf);

	n = read(), m = read();
	For(i, 1, m) {
		int u = read(), v = read(), w = read();
		chkmin(val[u], w + 1), chkmin(val[v], w + 2);
		E[++ cnt] = (edge) {u, v, w};
	}

	For(i, 1, n << 1) chkmin(val[i % n], val[(i - 1) % n] + 2);

	For(i, 0, n - 1) E[++ cnt] = (edge) {i, i == n - 1 ? 0 : i + 1, val[i]}, fa[i] = i;

	sort(E + 1, E + 1 + cnt);

	int c = 0; ll ans = 0;
	For(i, 1, cnt) {
		int u = find(E[i].u), v = find(E[i].v);
		if (u ^ v) 
			++ c, ans += E[i].w; fa[u] = v;
		if (c == n - 1) break;
	}
	
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 8832
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T,class U> inline bool chmin(T&x,U y){if(x>y){x=y;return true;}return false;}
template<class T,class U> inline bool chmax(T&x,U y){if(x<y){x=y;return true;}return false;}
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

void solve(){
    int n,a;
    cin>>n;
    unordered_map<int,bool> mp;
    int g{};
    bool pa{true};
    fr(i,n){
        cin>>a;
        g=gcd(a,g);
        if(pa){
            for(int j=2;j*j<=a;++j) if(a%j==0){
                    while(a%j==0) a/=j;
                    if(mp[j]) pa=false;
                    mp[j]=true;
                }
            if(a>1){
                if(mp[a]) pa=false;
                mp[a]=true;
            }
        }
    }
    puts(pa?"pairwise coprime":g==1?"setwise coprime":"not coprime");
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t{1};
    //cin>>t;
    fr(i,t) solve();
}

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

int main(){
    ll N; cin >> N;
    string s;
    while(N > 0){
        s += (char)('a' + (--N)%26);
        N/=26;
    }
    for(int i = s.length()-1; i >= 0; i--) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
//https://atcoder.jp/contests/agc023/tasks/agc023_a
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    vector<ll> an(N+1,0);
    for(ll i=1;i<=N;++i){
        cin>>an[i];
    }
    vector<ll> sum(N+1,0);
    ll cur=0;
    for(ll i=1;i<=N;++i){
        cur+=an[i];
        sum[i]=cur;
    }
    sort(sum.begin(),sum.end());
    unordered_map<ll,ll> tbl;
    for(const auto& v:sum){
        ++tbl[v];
    }
    ll ans=0;
    for(auto& t: tbl){
        if(t.second>=2){
            ans += t.second*(t.second-1)/2;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11592
//import java.lang.Math;
import java.util.*;
//import java.util.ListIterator;
//import java.util.Iterator;
//import java.util.LinkedList;

class Main{

	public static void main(String[] arg) {

		Scanner sc = new Scanner(System.in);
		int cnt = sc.nextInt();
		List<Sorting> list = new ArrayList<Sorting>();

		for (int i = 0; i < cnt; i++) {
			int x = sc.nextInt();
			int y = sc.nextInt();

			list.add(new Sorting(x, y));

		}

		list.sort(Comparator.comparing(Sorting::getx).thenComparingInt(Sorting::gety));

		for (Sorting sorting : list) {
			System.out.println(sorting);
		}
	}
}

class Sorting{

	private int x;
	private int y;

	public Sorting(int x, int y) {
		this.x=x; 
		this.y=y;
		
	}	
	public int getx(){
		return x;
	}
	public int gety(){
		return y;
	}
	public String toString(){
		
		return x+" "+y;
	}
			
		}
		


Measured memory_bytes: 113232
#include<bits/stdc++.h>
// Begin Header {{{
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i,n) for(ll i=0; i<n; i++)
#define loop(i, j, n) for(ll i=j; i<n; i++)
#define all(x) (x).begin(), (x).end()
constexpr int INF  = 0x3f3f3f3f;
const long long mod=1e9+7;
const long double PI = acos(-1);
// }}} End Header
int main() {
	int x;
	cin >> x;
	if(x>=30) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3508
///#pragma GCC optimize("Ofast")
///#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")
///#pragma GCC optimize("unroll-loops")

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

///#include<ext/pb_ds/assoc_container.hpp>
///#include<ext/pb_ds/tree_policy.hpp>
///using namespace __gnu_pbds;
///template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
///(X).order_of_key(value) /// return lower_bound(value)
///(*X).find_by_order(index) /// return value (0 index)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /// mt19937_64 (long long)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<bool> vbb;

const int N = 100001;
const int MOD = 1000000007;
const ll INF = LLONG_MAX;

#define fast() ios_base::sync_with_stdio(false),cin.tie(NULL)
#define next(x) next_permutation(all(x))
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rev(a) reverse(all(a))
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define space ' '
#define nl '\n'
#define PI acos(-1)
#define Case(x) cout<<"Case "<<x<<": "
#define strtoint(a) atoi(a.c_str())
#define dbg(x) cerr<<#x<<" is "<<x<<'\n';
#define fix(x) cout<<fixed<<setprecision(x)
#define leastonepos(x) __builtin_ffs(x)
#define leadingoff(x) __builtin_clz(x)
#define trailingoff(x) __builtin_ctz(x)
#define numofone(x) __builtin_popcount(x)
#define time() cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'

#define coutv(v) for(auto it:v)cout<<it<<space;cout<<nl;
#define cinv(v) for(auto &it:v)cin>>it;

///................Graph's Move.................
///const int dx[] = {+1,-1,+0,+0}; ///Rock's Move
///const int dy[] = {+0,+0,+1,-1}; ///Rock's Move
///const int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's Move
///const int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int dx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's Move
///const int dy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's Move
///*.....................-_-........................*///

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


int main()
{
    fast();
    int tc=1,cs=0;
    //cin>>tc;
    while(tc--)
    {
        int x;
        cin>>x;
        cout<<LCM(x,360)/x<<nl;
    }
}


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

using namespace std;

int main() {
    int64_t n, m;
    cin >> n >> m;
    vector<pair<int64_t ,int64_t>> p(n); 

    for (int i = 0; i < n; i++) {
        cin >> p.at(i).first >> p.at(i).second;
    }

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

    int64_t count = 0;
    int64_t ans = 0;
    for (int i = 0; i < n; i++) {
        if(count + p.at(i).second <= m) {
            count += p.at(i).second;
            ans += p.at(i).first * p.at(i).second;
        }
        else {
            ans += p.at(i).first * (m - count);
            break;
        }
    }

    cout << ans << endl;


}

Measured memory_bytes: 4788
#include <iostream>
#include <cstdio>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
#include <list>
#include <stack>
#include <queue>
using namespace std;

typedef list<int> L;
typedef pair <int,int> P;
typedef vector<int> V;
typedef queue<int> Q;
typedef stack<int> S;
typedef map<string,int> M;

const int MAX = 20;

int n, m, p1, p2;
V v[MAX + 1];

int main()
{
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> p1 >> p2;
        v[p1].push_back(p2);
    }
    int res[MAX + 1], maxR = 0;
    for (int i = 1; i <= n; i++) res[i] = 1; //initialize rank

    int s;
    Q q;
    for (int j = 1; j <= n; j++) {
        q.push(j);
        while (q.size()) {
            s = q.front(); q.pop();
            for (int i = 0; i < v[s].size(); i++) {
                if (res[s] >= res[v[s][i]]) {
                    res[v[s][i]] = res[s] + 1;
                    maxR = max(maxR, res[v[s][i]]);
                    q.push(v[s][i]);
                }
            }
        }
    }

    for (int i = 1; i <= maxR; i++)
        for (int j = 1; j <= n; j++)
            if (res[j] == i)
                cout << j << endl;

    return 0;
}

Measured memory_bytes: 1220
#include<iostream>
using namespace std;
int main()
{int n,m,i,a,sum=0;
cin>>n>>m;
    for(i=1;i<=m;i++)
    {cin>>a;
    sum+=a;
    }
    if(n-sum>=0)
        cout<<n-sum;
    else cout<<"-1";
    return 0;
}


Measured memory_bytes: 3168
//
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define speed ios::sync_with_stdio(false)
using namespace std;

string gs(char x){
    string s(1,x);
    return s;
}

int main()
{
	speed;
	
	ll d,g;
	cin>>d>>g;
	ll p[d+1],c[d+1];
	for(ll i=1;i<=d;i++)
	{
		cin>>p[i]>>c[i];
	}
	
	ll tot,cnt;
	ll ans=INT_MAX;
	ll rest_max;
	ll one=1;
	ll k=one<<d;
	for(ll i=0;i<k;i++)
	{
		tot=0;
		cnt=0;
		// rest_max=0;
		for(ll j=0;j<d;j++)
		{
			if((one<<j)&i)
			{
				tot+=(100*(j+1)*p[j+1])+c[j+1];
				cnt+=p[j+1];
			}
			else
			{
				rest_max=j;
			}
		}
		if(tot<g)
		{
			float f=(float)(g-tot)/(100*(rest_max+1));
			f=ceil(f);
			ll extra=(ll)f;
			if(extra<=p[rest_max+1]){
				tot=g;
				cnt+=extra;
			}
		}
		if(tot>=g){
			ans=min(ans,cnt);
		}
	}
	cout<<ans;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}
int a[5],k,i;
int main(void){
    for(i = 0;i < 5;i++){
    scanf("%d",&a[i]);
    }
    scanf("%d",&k);
    qsort(a,5,sizeof(int),compare_int);
    
    if(a[0]-a[4] <= k){
        printf("Yay!");
    }else{
        printf(":(");
    }
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n;
	cin >> n;
	int a, b, c, d;
	a = n / 1000;
	b = (n - a * 1000) / 100;
	c = (n - a * 1000 - b * 100) / 10;
	d = n % 10;

	if(a + b + c + d == 7){
		printf("%d+%d+%d+%d=7\n", a, b, c, d);
		return 0;
	}
	if(a + b + c - d == 7){
		printf("%d+%d+%d-%d=7\n", a, b, c, d);
		return 0;
	}
	if(a + b - c + d == 7){
		printf("%d+%d-%d+%d=7\n", a, b, c, d);
		return 0;
	}
	if(a + b - c - d == 7){
		printf("%d+%d-%d-%d=7\n", a, b, c, d);
		return 0;
	}
	if(a - b + c + d == 7){
		printf("%d-%d+%d+%d=7\n", a, b, c, d);
		return 0;
	}
	if(a - b + c - d == 7){
		printf("%d-%d+%d-%d=7\n", a, b, c, d);
		return 0;
	}
	if(a - b - c + d == 7){
		printf("%d-%d-%d+%d=7\n", a, b, c, d);
		return 0;
	}
	if(a - b - c - d == 7){
		printf("%d-%d-%d-%d=7\n", a, b, c, d);
		return 0;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
inline int read() {
	int x = 0, fh = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fh = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		x = (x << 1) + (x << 3) + c - '0';
		c = getchar();
	}
	return x * fh;
}
string s;
int f1, f2, i, a[4];
int main() {
	cin >> s;
	for (i = 0; i < 4; i++) a[i] = s[i] - 48;
	if (a[2] * 10 + a[3] <= 12 && a[2] + a[3] != 0) f1 = 1;
	if (a[0] * 10 + a[1] <= 12 && a[0] + a[1] != 0) f2 = 1;
	if (f1 && !f2) cout << "YYMM\n";
	else if (!f1 && f2) cout << "MMYY\n";
	else if (f1 && f2) cout << "AMBIGUOUS\n";
	else if (!f1 && !f2) cout << "NA\n"; 
	return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define FOR(i, n) for (long long i = 0; i < (n); ++i)
#define pb push_back
#define int long long
#define debug(x) std::cout << #x << ": " << x << '\n';
typedef long long ll;

signed main() {
    std::ios::sync_with_stdio(false);
    std::string s;
    std::cin >> s;
    int cnt = 0;
    ll answ = 0;
    FOR(i, s.size()) {
    	if (s[i] == 'B') {
    		cnt++;
    	}
    	if (s[i] == 'W') {
    		answ +=  cnt;
    	}
    }
    std::cout << answ;
}

Measured memory_bytes: 720
import java.io.*;
import java.util.*;
public class Main
{
	final long mod=(long)(1e9+7);
	final int maxn=(int)(1e6);
	
	private void solve()throws IOException
	{
		HashSet<Integer> set=new HashSet<>();
		for(int i=1;i<=3;i++)
			set.add(nextInt());
		if(set.size()==2)
			out.println("Yes");
		else
			out.println("No");
	}

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

	public void run()throws IOException
	{
		br=new BufferedReader(new InputStreamReader(System.in));
		st=null;
		out=new PrintWriter(System.out);

		solve();

		br.close();
		out.close();
	}
	public static void main(String args[])throws IOException{
		new Main().run();
	}
	BufferedReader br;
	StringTokenizer st;
	PrintWriter out;
	String nextToken()throws IOException{
		while(st==null || !st.hasMoreTokens())
		st=new StringTokenizer(br.readLine());
		return st.nextToken();
	}
	String nextLine()throws IOException{
		return br.readLine();
	}
	int nextInt()throws IOException{
		return Integer.parseInt(nextToken());
	}
	long nextLong()throws IOException{
		return Long.parseLong(nextToken());
	}
	double nextDouble()throws IOException{
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#define N 200005
using namespace std;
typedef long long ll;

ll n, p, ans, x, mul[N], cnt[N]={1};
string s;
int main() {
	ll i;
	cin >> n >> p >> s;
	if(p==2 || p==5) {
		for(i=0; i<n; i++) {
			if((s[i]-'0') % p == 0) ans += i+1;
		}
	} else {
		mul[n-1] = 1;
		for(i=n-2; i>=0; i--) mul[i] = mul[i+1] * 10 % p;
		for(i=0; i<n; i++) {
			x = (x + (s[i] -'0') * mul[i]) % p;
			ans += cnt[x];
			cnt[x]++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int W, H;
vector<vector<char>> s;
vector<vector<int>> cost;

int bfs() {
    int dx[4] = {1, 0, 0, -1};
    int dy[4] = {0, -1, 1, 0};

    queue<pair<int, int>> que;
    que.push(make_pair(0, 0));
    cost[0][0] = 0;

    while(!que.empty()) {
        pair<int, int> p = que.front();
        que.pop();

        if (p == make_pair(H-1, W-1))
            return cost[p.first][p.second];
        
        rep (i, 4) {
            int ny = p.first + dx[i];
            int nx = p.second + dy[i];
            
            if (nx < 0 or ny < 0 or nx >= W or ny >= H) continue;
            if (s[ny][nx] == '#') continue;
            if (cost[ny][nx] != -1) continue;

            cost[ny][nx] = cost[p.first][p.second] + 1;
            que.push(make_pair(ny, nx));
        }
    }

    return -1;
}

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

    cin >> H >> W;
    s = vector<vector<char>>(H, vector<char>(W));

    int white = 0;
    rep (i, H) {
        rep (j, W) {
            cin >> s[i][j];
            if (s[i][j] == '.') ++white;
        }
    }

    cost = vector<vector<int>>(H, vector<int>(W, -1));
    int minCost = bfs();
    if (minCost == -1) cout << "-1" << "\n";
    else cout << white - minCost - 1 << "\n";
}

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

using namespace std;


int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> balls;
    for (int i = 0; i < N; ++i) {
        int x, y;
        cin >> x >> y;
        balls.push_back(make_pair(x, y));
    }

    map<pair<int, int>, int> distanceCounts;
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < N; ++j) {
            if (i == j) continue;

            int difX = balls[i].first - balls[j].first;
            int difY = balls[i].second - balls[j].second;
            pair<int, int> p(difX, difY);
            if (distanceCounts.find(p) == distanceCounts.end()) {
                distanceCounts[p] = 1;
            } else {
                distanceCounts[p]++;
            }
        }
    }

    int countMax = 0;
    for (pair<pair<int, int>, int> dist:distanceCounts) {
        countMax = max(countMax, dist.second);
    }

    cout << N - countMax << endl;
    return 0;
}

Measured memory_bytes: 384
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
[n,m]=i2()
e=[0 for i in range(n+1)]
for i in range(m):
 [a,b]=i2()
 e[a]+=1
 e[b]+=1
s="YES"
for i in range(1,n+1):
 if e[i]%2==1:
   s="NO"
print(s)

Measured memory_bytes: 48672
x, n = map(int,input().split())
L = list(map(int,input().split()))
l, r = x-1, x+1

if n == 0 or x not in L:
  print(x)
  exit()

while True:
  if l not in L:
    print(l)
    break
  elif r not in L:
    print(r)
    break
  l -= 1
  r += 1

Measured memory_bytes: 9120
using System;
using System.Collections.Generic;

namespace _20200412_ABC162C
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadStringList(1);

            int K = int.Parse(input[0]);

            long output = 0;

            for(int a = 1; a <= K; a++)
            {
                for (int b = 1; b <= K; b++)
                {
                    for (int c = 1; c <= K; c++)
                    {
                        output += gcd(a, b, c);
                    }

                }

            }

            Console.WriteLine(output);
        }

        private static int gcd(int a, int b, int c)
        {
            int d = gcd(a, b);
            return gcd(c, d);
        }

        private static int gcd(int a, int b)
        {
            if (a > b)
            {
                return gcd(b, a);
            }

            while (b != 0)
            {
                int s = a % b;
                a = b;
                b = s;
            }

            return a;
        }


        private static List<string> ReadStringList(int numberOfLines)
        {
            var stringList = new List<string>();

            for (int lineIndex = 0; lineIndex < numberOfLines; lineIndex++)
            {
                stringList.Add(Console.ReadLine().Trim());
            }

            return stringList;
        }

    }
}


Measured memory_bytes: 17652
import sys
read = sys.stdin.read
readline = sys.stdin.buffer.readline
INF = float('inf')


class FordFulkerson:
    def __init__(self, N):
        self.N = N
        self.G = [[] for i in range(N)]

    def add_edge(self, fr, to, cap):
        forward = [to, cap, None]
        forward[2] = backward = [fr, 0, forward]
        self.G[fr].append(forward)
        self.G[to].append(backward)

    def add_multi_edge(self, v1, v2, cap1, cap2):
        edge1 = [v2, cap1, None]
        edge1[2] = edge2 = [v1, cap2, edge1]
        self.G[v1].append(edge1)
        self.G[v2].append(edge2)

    def dfs(self, v, t, f):
        if v == t:
            return f
        used = self.used
        used[v] = 1
        for e in self.G[v]:
            w, cap, rev = e
            if cap and not used[w]:
                d = self.dfs(w, t, min(f, cap))
                if d:
                    e[1] -= d
                    rev[1] += d
                    return d
        return 0

    def flow(self, s, t):
        flow = 0
        f = INF
        N = self.N
        while f:
            self.used = [0]*N
            f = self.dfs(s, t, INF)
            flow += f
        return flow

def main():
    V, E = map(int, readline().split())
    FF = FordFulkerson(V)
    for _ in range(E):
        u, v, cap = map(int, readline().split())
        FF.add_edge(u,v,cap)

    ans = FF.flow(0,V-1)
    print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, a[55];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  if (is_sorted(a, a + n)) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      swap(a[i], a[j]);
      if (is_sorted(a, a + n)) {
        cout << "YES" << endl;
        return 0;
      }
      swap(a[i], a[j]);
    }
  }
  cout << "NO" << endl;
}

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

int main(void){
    string a,b,c;
    cin>>a>>b>>c;
    int acnt=0,bcnt=0,ccnt=0;
    int amax=a.size(),bmax=b.size(),cmax=c.size();
    char  next='a';
    int cnt=0;


    while(true){
        switch(next){
            case 'a':if(a.size()==0){cout<<"A"<<endl;return 0;}acnt++;next=a[0];a.erase(a.begin());break;
            case 'b':if(b.size()==0){cout<<"B"<<endl;return 0;}bcnt++;next=b[0];b.erase(b.begin());break;
            case 'c':if(c.size()==0){cout<<"C"<<endl;return 0;}ccnt++;next=c[0];c.erase(c.begin());break;
        }

    }
        return 0;
}


Measured memory_bytes: 256