akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#define MAX 500001
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}
int H;
void maxHeapify(int A[],int i){
  int l=left(i),r=right(i),largest,tmp;
  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>=A[largest])largest=r;
  if(largest!=i){
    tmp=A[i];
    A[i]=A[largest];
    A[largest]=tmp;
    maxHeapify(A,largest);
  }
}
void buildMaxHeap(int A[]){
  int i;
  for(i=H/2;i>0;i--){
    maxHeapify(A,i);
  }
}
int main(){
  int i,A[MAX];
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  buildMaxHeap(A);
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 2552
import itertools
N = int(input().strip())
count = 0
for i in range(3, len(str(N))+1):
  for n in itertools.product('753', repeat=i):
    num = int(''.join(n))
    if num > N:
      continue
    if len(set(n)) == 3:
      count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
const int N=705;
int a[N][N],last[N],Next[N*N],to[N*N],edge,col[N],cnt,x,y,n,m,w[N],tot,V;
int f[N];
void add(int x,int y){
	to[++edge]=y;
	Next[edge]=last[x];
	last[x]=edge;
}
void dfs(int x,int c){
	col[x]=c;
	cnt+=(c==1?1:-1);
	for (int i=last[x];i;i=Next[i]){
		int u=to[i];
		if (col[u]){
			if (col[u]==c){
				puts("-1");
				exit(0);
			}else continue;
		}
		dfs(u,3-c);
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		a[x][y]=a[y][x]=1;
	}
	for (int i=1;i<=n;i++)
		for (int j=i+1;j<=n;j++)
			if (!a[i][j]) add(i,j),add(j,i);
	for (int i=1;i<=n;i++){
		if (col[i]) continue;
		cnt=0,dfs(i,1);
		w[++tot]=abs(cnt);
		V+=abs(cnt); 
	}
	for (int i=1;i<=tot;i++)
		for (int j=V/2;j>=w[i];j--) f[j]=std::max(f[j],f[j-w[i]]+w[i]);
	int n1=(n+V-f[V/2]-f[V/2])/2,n2=n-n1;
	printf("%d\n",n1*(n1-1)/2+(n2-1)*n2/2);
} 

Measured memory_bytes: 7484
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<stack>
using namespace std;
int n,a[100005];
bool cmp(const int x,const int y){
	return x>y;
}
int main(){
	scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++)
        if(a[i+1]<i+1){
            int ans=0;
            for(int j=i+1;a[j]==i;j++)ans^=1;
            ans|=(a[i]-i)%2;
            if(ans>0)printf("First");
            else printf("Second");
            exit(0);
    }
    return 0;
}

Measured memory_bytes: 640
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

# 一度たずねた場所はループが判明しているのでそのままにする(何度移動させるかに関係なくtree構造がつながっているかを調べたい)
ans = -10 ** 18
for i in range(N):
    x = i
    loop = []
    total = 0
    while True:
        x = P[x] - 1
        loop.append(C[x])
        total += C[x]
        if x == i:
            break

    T = len(loop)
    tmp = 0
    for j in range(T):
        tmp += loop[j]
        if K < j + 1:
            break
        now = tmp
        # 一周のループが正の時のみ何度も回す価値がある。それ以外のときはそれまでの最大をとる
        if total > 0:
            loop_times = (K - (j + 1)) // T
            now += total * loop_times

        ans = max(ans, now)
print(ans)


Measured memory_bytes: 81108
import Data.List
import Data.Bits
main=getLine>>getLine>>=putStr.(\xs->if length xs==1&&head(xs!!0)==0||length xs==2&&head(xs!!0)==0&&length(xs!!0)*2==length(xs!!1)||length xs==3&&length(xs!!0)==length(xs!!1)&&length(xs!!1)==length(xs!!2)&&head(xs!!0)`xor`head(xs!!1)`xor`head(xs!!2)==0 then"Yes"else"No").group.sort.map(read::String->Int).words


Measured memory_bytes: 43388
N = int(input())
D = list(map(int, input().split()))

if D[0] != 0:
	print(0)
	exit()

D = sorted(D)
V = [0]*(D[-1]+1)

for i in range (0, N):
	V[D[i]]+=1

if V[0] > 1:
	print(0)
	exit()
else:
	count = 1

for i in range (0, len(V)-1):
	if V[i] == 0 and V[i+1] > 0:
		print(0)
		exit()
	else:
		count*= V[i]**V[i+1]
        
print(count%998244353)

Measured memory_bytes: 20700
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

const int UF_MAX = 400010;

struct UF{
	int x[UF_MAX];
	
	UF(){
		for(int i = 0 ; i < UF_MAX ; ++i) x[i] = -1;
	}
	
	int boss(int a){
		int s = a;
		while(x[s] > -1) s = x[s];
		if(s != a) x[a] = s;
		return s;
	}
	
	void uni(int a , int b){
		int s = boss(a);
		int t = boss(b);
		if(s != t){
			if(x[s] < x[t]){
				x[s] += x[t];
				x[t] = s;
			} else {
				x[t] += x[s];
				x[s] = t;
			}
		}
	}
	
	bool find(int a , int b){
		return boss(a) == boss(b);
	}
	
	int size(int a){
		return -x[boss(a)];
	}
};

UF A,B,C;
vector<int> V[200010];
int N,K,L;
int ans[200010];

int main(){
	scanf("%d%d%d" , &N , &K , &L);
	repp(i,0,K){
		int x,y;
		scanf("%d%d" , &x , &y);
		A.uni(x,y);
	}
	repp(i,0,L){
		int x,y;
		scanf("%d%d" , &x , &y);
		B.uni(x,y);
	}
	repp(i,1,N+1){
		V[A.boss(i)].PB(i);
	}
	repp(i,1,N+1){
		if((int)V[i].size() == 0) continue;
		repv(int,it,V[i]){
			C.uni(B.boss(*it)+N,(*it));
		}
		repv(int,it,V[i]){
			ans[*it] = C.size(*it) - 1;
		}
		repv(int,it,V[i]){
			C.x[B.boss(*it)+N] = -1;
		}
	}
	repp(i,1,N+1){
		printf("%d%c" , ans[i] , i == N ? '\n' : ' ');
	}
	return 0;
}


Measured memory_bytes: 16512
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
 
#define pb push_back
#define mk make_pair
#define f0(i,b) for(int i=0;i<(b);i++)
#define f1(i,b) for(int i=1;i<=(b);i++)
#define f2(i,a,b) for(int i=(a);i<=(b);i++)
#define sf(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define pf(a) printf("%d\n",a);
#define pfl(a) printf("%lld\n",a);
#define TEST int test; cin >> test;while(test--)
#define ii pair<int,int>
#define iil pair<ll,ll>
#define loop(i,a,b) for(int i = a ; i < b ; i++)
#define INF 2147483647
 
 
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[] = {0, 0, 1, -1};
int dy4[] = {1, -1, 0, 0};
const double pi = acos(-1.0);
ll power(ll x, unsigned long long y)
{
    int res = 1;     // Initialize result
 
    while (y > 0)
    {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x);
 
        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x);  // Change x to x^2
    }
    return res;
}
 
ll n, m, x, k;
 
void solve()
{
    double a, b, c, h, m;
    cin >> a >> b >> h >> m;
 
    double hour_angle = 0.5 * (h * 60 + m);
    double minute_angle = 6.0 * m;
    double angle = abs(hour_angle - minute_angle);
    angle = min(360 - angle, angle);
   // cout << angle << " ";
    c = sqrt(a*a + b*b - 2*a*b*cos(angle*pi/180));
    cout << fixed << setprecision(20) << c << endl;
 
}
 
 
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    solve();
    return 0;
}

Measured memory_bytes: 4120
#include <iostream>
#include <string>
using namespace std;
int main()
{
    int N,T;
    int min=1001;
    scanf("%d%d\n",&N,&T);
    int c[N],t[T];
    for (int i = 0; i < N; i++) {
        scanf("%d%d\n",&c[i],&t[i]);
        if (t[i]<=T) {
            if (min >= c[i]){
                min = c[i];
            }
        }
    }
    if (min==1001) printf("TLE");
    else printf("%d\n",min);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 10005

int N;
int S[105];
bool dp[SIZE];

int main(){

	scanf("%d",&N);

	int sum = 0;

	for(int i = 0; i < N; i++){

		scanf("%d",&S[i]);
		sum += S[i];
	}

	for(int i = 0; i <= sum; i++){

		dp[i] = false;
	}
	dp[0] = true;

	for(int i = 0; i < N; i++){
		for(int k = sum; k-S[i] >= 0; k--){
			dp[k] |= dp[k-S[i]];
		}
	}

	int ans = 0;

	for(int i = 0; i <= sum; i++){
		if(i%10 == 0)continue;

		if(dp[i]){

			ans = i;
		}
	}

	printf("%d\n",ans);

	return 0;
}


Measured memory_bytes: 3784
#include <stdio.h>
#include <iostream>
using namespace std;
#include <stdio.h>
int main()
{
	int n, m, a[100][100], b[100], ans[100] = { 0 };
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++){
		cin >> b[i];
	}
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			ans[i]+=a[i][j]*b[j];
		}
	}
	for (int i = 0; i < n; i++){
		printf("%d\n", ans[i]);
	}
}

Measured memory_bytes: 1180
#include <iostream>
//#include <cstring>
//#include <cctype>
//#include <ctime>
using namespace std;


int main(){
    char c;
    while(1){
        scanf("%c",&c);
        if (isupper(c)) {
            cout << (char)tolower(c);
        }
        else{
            cout << (char)toupper(c);
        }
        if(c == '\n') break;
    }
    return 0;
}

Measured memory_bytes: 1104
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		UnionFind uf = new UnionFind(n);
		for(int i = 0; i < m; i++){
		    int a = sc.nextInt()-1;
		    int b = sc.nextInt()-1;
		    uf.union(a, b);
		}
		
		// 計算
		int result = 0;
		for(int i = 0; i < n; i++){
		    result = max(result, uf.cnt(i));
		}
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}
}

class UnionFind {
	int[] parent;
	int[] rank;
	int[] cnt;
	
	UnionFind(int n){
		this.parent = new int[n];
		this.rank = new int[n];
		this.cnt = new int[n];
		for(int i = 0; i < n; i++){
			parent[i] = i;
			rank[i] = 0;
			cnt[i] = 1;
		}
	}
	
	public int find(int i){
		if(i == parent[i]) return i;
		parent[i] = find(parent[i]);
		return parent[i];
	}
	
	public boolean union(int x, int y){
		int xRoot = find(x);
		int yRoot = find(y);
		if(xRoot == yRoot) return false;
		if(rank[xRoot] < rank[yRoot]){
			parent[xRoot] = yRoot;
			cnt[yRoot] += cnt[xRoot];
		}else if(rank[xRoot] > rank[yRoot]){
			parent[yRoot] = xRoot;
			cnt[xRoot] += cnt[yRoot];
		}else{
			parent[yRoot] = xRoot;
			rank[xRoot]++;
			cnt[xRoot] += cnt[yRoot];
		}
		return true;
	}
	
	public boolean same(int x, int y){
		return find(x) == find(y);
	}

	public int cnt(int x){
		return cnt[find(x)];
	}
}



Measured memory_bytes: 49848
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define NL '\n'
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define sz(x) x.size()
#define all(x) (x).begin(), (x).end()
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(ii,aa,bb) for(ll (ii)=ll(aa);(ii)<(ll)(bb);++(ii))
#define _fastIO() ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0)

//#define LOCAL
vector<string>vec_spltr(string s){s+=',';vector<string>res;while(!s.empty())
res.push_back(s.substr(0, s.find(','))),s=s.substr(s.find(',')+1);return res;}
void dbg_out(vector<string>__attribute__((unused))args,__attribute__((unused))int idx,
__attribute__((unused))int LINE_NUM){cerr<<endl;}template<typename Head,typename... Tail>
void dbg_out ( vector <string> args, int idx, int LINE_NUM, Head H, Tail... T)
{if(idx>0)cerr<<", ";else cerr << "Line(" << LINE_NUM << ") ";stringstream ss;ss<<H;
cerr<<args[idx]<<" = "<<ss.str();dbg_out(args,idx+1,LINE_NUM, T...);}
#ifdef LOCAL
#define debug(...) dbg_out(vec_spltr(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 6660999
#endif


void absinthe() {
    ll n, m, l, r; cin >> n >> m;
    string s; cin >> s;
    vector<int>end(n+1);
    for(int i = 1; i < n; i++) {
        if(s[i-1] == 'A' && s[i] == 'C') {
            end[i] = 1;
        }
    }
    rep(i, 1, n) end[i] += end[i-1];
   // rep(i, 0, n+1) cerr << end[i] << " "; cerr << NL;
    while(m--){
        cin >> l >> r; l--, r--;
        cout << end[r] - end[l] << NL;
    }
}
 
int main(){
  _fastIO();
  int tx = 1; 
  //cin >> tx;
  while(tx--) absinthe();
}  

Measured memory_bytes: 1488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };
static const char Move[] = { 'E', 'W', 'N', 'S' };

int N, M, P, ans;
double Return = 0;
VI X;

int main() {
	while ( scanf( "%d %d %d", &N, &M, &P ) && N && M ) {
		X.resize( N );
		for ( int i = 0; i < N; i++ ) {
			scanf( "%d", &X[ i ] );
			Return += X[ i ] * 100;
		}
		Return -= P * 0.01 * Return;
		if ( X[ M - 1 ] ) {
			Return /= X[ M - 1 ];
		}
		else {
			Return = 0;
		}
		ans = Return;
		Return = 0;
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1204
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
typedef pair<int,string> P;
bool nya(const P& pf,P&ps){
  if(pf.first == ps.first){
    return pf.second < ps.second;
  }
  return pf.first > ps.first;
}
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n;cin>>n;
  map<string,int> A;
  for(int i = 0; n > i; i++){
    string s;cin>>s;
    A[s]++;
  }
  vector<P> B;
  for(auto x:A){
    B.push_back({x.second,x.first});
  }
  sort(B.begin(),B.end(),nya);
  for(int i = 0; B.size() > i && B[i].first == B[0].first; i++){

    cout << B[i].second << endl;
  }
}

Measured memory_bytes: 27376
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.Char

data Dice = Dice [Int] deriving Show

rollDice :: Char -> Dice -> Dice
rollDice 'N' (Dice [a,b,c,d,e,f]) = Dice [b,f,c,d,a,e]
rollDice 'E' (Dice [a,b,c,d,e,f]) = Dice [d,b,a,f,e,c]
rollDice 'S' d = foldr1 (.) (replicate 3 $ rollDice 'N') $ d
rollDice 'W' d = foldr1 (.) (replicate 3 $ rollDice 'E') $ d

topDice :: Dice -> Int
topDice (Dice (a:_)) = a


main = do
  as <- map read . words <$> getLine
  getLine >>= return . topDice . foldl (flip rollDice) (Dice as) >>= print

Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  string d = "dream";
  reverse(d.begin(), d.end());
  string dr = "dreamer";
  reverse(dr.begin(), dr.end());
  string e = "erase";
  reverse(e.begin(), e.end());
  string er = "eraser";
  reverse(er.begin(), er.end());
  
  if (s.size() < 5){
    cout << "NO" << endl;
  }
  else {
  while (s.size() >= 5){
    if (s.substr(0,7) == dr){
      s = s.substr(7);
    }
    else if (s.substr(0,6) == er){
      s = s.substr(6);
    }
    else if (s.substr(0,5) == d || s.substr(0,5) == e){
      s = s.substr(5);
    }
    else break;
  }
  if (s.size() == 0){
    cout << "YES" << endl;
  }
  else cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long n, i;
	cin >> n ;
	long long h[n];
	for(i=0;i<n;i++) {
		cin >> h[i];
	}
	long long  men[n], h1, h2;
	for(i=0;i<n;i++) men[i]=1000000001;
	men[0]=0;
	men[1]=h[0]-h[1];
	if(men[1]<0) men[1]*=-1;
	for(i=2;i<n;i++) {
		h1=h[i]-h[i-1];
		if(h1<0) h1*=-1;
		h2=h[i]-h[i-2];
		if(h2<0) h2*=-1;
		men[i]=min((men[i-1]+h1), (men[i-2]+h2));
	}
	cout << men[n-1];
	return 0;
}


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

int main() {
  int k,n;cin>>k>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  a.push_back(a[0]+k);
  int cnt=0;
  rep(i,n)cnt=max(cnt,a[i+1]-a[i]);
  cout<<k-cnt<<endl;
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n,d;
  cin>>n>>d;
  long long int ans=0;
  long long int a,b;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    long long int temp=(a*a)+(b*b);
    double temp2=sqrt(temp);
    ans+=(temp2<=d);
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
int a, b, q;
vector<long long> s;
vector<long long> t;

bool isOK(vector<long long>& x, int index, long long key) {
    if(x.at(index) >= key) return true;
    else return false;
}

int binary_search(vector<long long>& x, long long key) {
    int ng = -1;
    int ok = (int)x.size()-1;

    while(abs(ok-ng) > 1) {
        int mid = (ok+ng) / 2;
        if(isOK(x, mid, key)) ok = mid;
        else ng = mid;
    }
    return ok;
}

int main() {
    cin >> a >> b >> q;
    s.push_back(-1e18);
    for(int i = 0; i < a; ++i) {
        long long ins;
        cin >> ins;
        s.push_back(ins);
    }
    s.push_back(1e18);

    t.push_back(-1e18);
    for(int j = 0; j < b; ++j) {
        long long tin;
        cin >> tin;
        t.push_back(tin);
    }
    t.push_back(1e18);

    for(int i = 0; i < q; ++i) {
        long long x;
        cin >> x;
        long long ans = 1e12;
        int cs = binary_search(s, x);
        int ct = binary_search(t, x);

        vector<long long> xs(2,0);
        vector<long long> xt(2,0);
        xs.at(0) = s.at(cs-1);
        xs.at(1) = s.at(cs);
        xt.at(0) = t.at(ct-1);
        xt.at(1) = t.at(ct);

        for(int i = 0; i < 2; ++i) {
            ans = min(ans, abs(xs.at(i)-x)+abs(xt.at(0)-xs.at(i)));
            ans = min(ans, abs(xs.at(i)-x)+abs(xt.at(1)-xs.at(i)));
        }
        for(int i = 0; i < 2; ++i) {
            ans = min(ans, abs(xt.at(i)-x)+abs(xs.at(0)-xt.at(i)));
            ans = min(ans, abs(xt.at(i)-x)+abs(xs.at(1)-xt.at(i)));
        }

        cout << ans << endl;
    }
}

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>

using namespace std;

int main(void)
{
    int ab, bc, ca;
    cin >> ab >> bc >> ca;
    cout << (bc * ab) / 2 << endl;
    return 0;
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template <class T> bool chmin(T & a, const T & b) { if (a > b) { a = b; return true; } return false; }
template <class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	string s; cin >> s;
	vector<pair<char, int>> v;
	int cnt = 0;
	char now = '2';
	if (s[0] == '0')v.push_back({ '1',0 });
	v.push_back({ s[0],1 });
	FOR(i, 1, n) {
		if (v.back().first != s[i])v.push_back({ s[i],1 });
		else v.back().second++;
	}
	if (v.size() % 2 == 1) {
		v.push_back({ '0',0 });
	}
	assert(v.size() % 2 == 0);
	vector<pii> p;

	REP(i, v.size() / 2) {
		p.push_back({ v[i * 2].second,v[i * 2 + 1].second });
	}
	int m = p.size();
	vi sum(m + 1, 0);
	REP(i, m)sum[i + 1] = sum[i] + p[i].first + p[i].second;
	p.push_back({ 0,0 });
	int ans = 0;
	REP(i, m) {
		chmax(ans, sum[min((ll)m, i + k)] - sum[i] + p[min((ll)m, i + k)].first);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2116
import collections

n = int(input())
arr = list(map(int, input().split()))

eve = []
odd = []
for i in range(n):
    if i % 2 == 0:
        odd.append(arr[i])
    else:
        eve.append(arr[i])

odd_c = collections.Counter(odd)
eve_c = collections.Counter(eve)

odd_key = odd_c.most_common()[0][0]
odd_value = odd_c.most_common()[0][1]
eve_key = eve_c.most_common()[0][0]
eve_value = eve_c.most_common()[0][1]

if odd_key == eve_key:
    if odd_value > eve_value:
        if len(eve_c.most_common()) == 1:
            eve_value = 0
        else:
            eve_key = eve_c.most_common()[1][0]
            eve_value = eve_c.most_common()[1][1]
    elif odd_value > eve_value:
        if len(odd_c.most_common()) == 1:
            odd_value = 0
        else:
            odd_key = odd_c.most_common()[1][0]
            odd_value = odd_c.most_common()[1][1]
    elif odd_value == eve_value:
        if len(odd_c.most_common()) == 1 or len(eve_c.most_common()) == 1:
            odd_value = 0
        else:
            if odd_c.most_common()[1][1] >= eve_c.most_common()[1][1]:
                odd_key = odd_c.most_common()[1][0]
                odd_value = odd_c.most_common()[1][1]
            else:
                eve_key = eve_c.most_common()[1][0]
                eve_value = eve_c.most_common()[1][1]
else:
    pass

ans = int(n/2 - eve_value + n/2 - odd_value)
print(ans)

Measured memory_bytes: 20568
package main

import (
        "fmt"
)

func solution(n int) string {
        for n > 0 {
                if n%10 == 7 {
                        return "Yes"
                }
                n /= 10
        }
        return "No"
}

func main() {
        var n int
        fmt.Scan(&n)
        fmt.Printf(solution(n))
}

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

/**
 * https://atcoder.jp/contests/abc089/tasks/abc089_b
 */
int main() {
    int N;
    cin >> N; 

    for (int i = 0; i < N; i++) {
        char c;
        cin >> c; 
        if (c == 'Y') {
            cout << "Four" << endl;
            return 0;
        }
    }
    cout << "Three" << endl;

    return 0;
}

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

int main() {
  double N,K;
  cin >> N >> K;
  double ans = 0;
  for(int i=1; i<=N;i++){
    double x=1.0/N , y = i;
		while (y < K) {
			y *= 2;
			x /= 2;
		}
		ans += x;
  }
  cout << fixed << setprecision(20) << ans << endl;
}


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

int main()
{
	int n, k;
	cin >> k >> n;
	int d[n], z[n];
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	for (int j = 0; j < n; j++) {
		if (j != n - 1) {
			z[j] = d[j + 1] - d[j];
		} else {
			z[j] = d[0] + k - d[j];
		}
	}
	int l{};
	long long ans{};
	for (int i = 0; i < n; i++) {
		if (z[i] > l)
			l = z[i];
		ans += z[i];
	}
	cout << ans - l;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int n,m,x;
ll dp[101010];
bool b[101010];
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	cin>>n>>m;
	fo(i,0,m){
		cin>>x;
		b[x]=1;
	}
	dp[0]=0;
	dp[1]=(b[1]?0:1);
	dp[2]=(b[2]?0:dp[1]+1);
	ll M=1e9+7;
	fo(i,3,n+1)dp[i]=(b[i]?0:(dp[i-2]+dp[i-1])%M);
	cout<<dp[n]<<endl;
	return 0;
}


Measured memory_bytes: 1152
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep3(i,a,b) for(int i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define tii tuple<int,int,int>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define edge(v,a,b) v[a].pb(b);v[b].pb(a);
ll MOD=1e9+7;
#define INF 1e9+7
#define N 200001
#define MAX_V 400010
#define vec vector<int>
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
template<typename A, size_t NNN, typename T>
void Fill(A (&array)[NNN], const T &val){
    fill( (T*)array, (T*)(array+NNN), val );
}
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umap unordered_map<ll,int,custom_hash>
struct pair_hash
{
    template<class T1,class T2>
    size_t operator() (const pair<T1,T2> &p)const{
        return hash<T1>()(p.first)^hash<T2>()(p.second);
    }
};

main(){
    int n=in();
    if(n==7||n==5||n==3)cout<<"YES";
    else cout<<"NO";
}

Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <cctype>

int read() {
	int x=0; char c=getchar();
	while (!isdigit(c)) c=getchar();
	while (isdigit(c)) x=x*10+c-'0', c=getchar();
	return x;
}
int main() {
	int n=read();
	int cnt=0;
	for(int i=1; i<=n; i++) if(i&1) cnt++;
	printf("%.10f", 1.0*cnt/n);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    long long a, v, b, w, t;
    cin>>a>>v>>b>>w>>t;
    if(w>=v) cout<<"NO\n";
    else if(abs(a-b)>abs(v-w)*t) cout<<"NO\n";
    else cout<<"YES\n";
    return 0;
}

Measured memory_bytes: 3656
#include <cmath>
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int a,b,c,d;
int main()
{
	scanf("%d%d%d%d",&a,&b,&c,&d);
	printf("%d\n",max(a*b,c*d));
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,b,c,d=0;
  cin>>a>>b;
  rep(i,a){
    cin>>c;
    d+=min(b-c,c)*2;
  }
  cout<<d;
}


Measured memory_bytes: 256
import sys
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

MOD = int(1e+9) + 7
from collections import deque  # 双方向キュー

def perm(n, k):
    r = 1
    for i in range(n, n-k, -1):
        r = (r * i) % MOD
    return r

def main():
    N, K = i2nn()
    edges = ii2nnn(N-1)
    # 木を構築
    T = [[] for _ in range(N+1)]
    B = [False] * (N+1)
    for a, b in edges:
        T[a].append(b)
        T[b].append(a)
    # カウント
    n = K
    q = deque()
    i = 1
    B[i] = True
    k = 0
    for j in T[i]:
        q.append(j)
        B[j] = True
        k += 1
    n = (n * perm(K-1, k)) % MOD
    while q:
        i = q.pop()
        k = 0
        for j in T[i]:
            if B[j] == False:
                q.append(j)
                B[j] = True
                k += 1
        n = (n * perm(K-2, k)) % MOD
    print(n)

main()


Measured memory_bytes: 83036
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<string>
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main(){
    string s;
    cin >> s;
    vector<bool> used(27, false);
    rep(i, (int)s.length()) {
        used[s[i]-'a'] = 1;
        used[s[i]-'a'] = 1;
    }
    if ( (int)s.length() < 26 ) {
        rep(i, 26) {
            if ( !used[i] ) {
                s += char('a'+i);
                break;
            }
        }
        cout << s << endl;
    }
    else {
        int id = -1;
        for ( int i = (int)s.length()-2; i >= 0; --i ) {
            if ( s[i] < s[i+1] ) {
                id = i;
                break;
            }
        }
        if ( id == -1 ) {
            cout << -1 << endl;
        }
        else {
            string t = s.substr(0, id);
            int idx2 = id + 1;
            for ( int i = id + 1; i < (int)s.length(); ++i ) {
                if ( s[i] < s[idx2]  && s[i] > s[id] ) {
                    idx2 = i;
                }
            }
            t += s[idx2];
            cout << t << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    vec a(N), inv(N);
    rep(i,N) cin>>a[i], --a[i];
    rep(i,N) inv[a[i]] = i;
    set<ll> id;
    id.insert(-1);
    id.insert(N);
    ll ans = 0;
    rep(i,N){
        id.insert(inv[i]);
        auto ite = id.find(inv[i]), ite2 = ++id.find(inv[i]);
        ll temp = *ite2 - *ite;
        --ite2; --ite;
        temp *= *ite2 - *ite;
        ans += temp * (i + 1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12800
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;
//using namespace std;
class DisjointSet{
    public:
    vector<ll> rank,p,sz;
    DisjointSet(){}
    DisjointSet(ll size){ //作られうる木の頂点数の最大値を入れる。
        rank.resize(size,0);
        p.resize(size,0);
        sz.resize(size,0);
        rep(i,size) makeSet(i);
    }
    void makeSet(ll x){ //xだけが属する木を作る。
        p[x]=x;
        rank[x]=0;
    }
    bool same(ll x,ll y){ //xとyが同じ木に属するかどうか
        return findSet(x)==findSet(y);
    }
    void unite(ll x, ll y){
        link(findSet(x),findSet(y));
    }
    void link(ll x, ll y){ //rankが大きい方の根に小さい方の根をつける。
        if(rank[x]>rank[y]){
            p[y]=x;
        }
        else{
            p[x]=y;
            if(rank[x]==rank[y]){
                rank[y]++; //xとyの木のrankが同じであれば、統合するとrankが1増える。
            }
        }
        sz[x]+=sz[y];
        sz[y]=sz[x];
    }
    ll findSet(ll x){ //xが属する木の根の番号を返す
        if(x!=p[x]){
            p[x]=findSet(p[x]);
        }
        return p[x];
    }
};



const ll mod=1e9+7;

int main(){
    ll n,m;
    cin >> n >> m;
    DisjointSet ds=DisjointSet(n);
    rep(i,m){
        ll a,b;
        cin >> a >> b;
        a--; b--;
        if(!ds.same(a,b)){
            ds.unite(a,b);
        }
    }
    set<ll> ans;
    rep(i,n){
        ans.insert(ds.findSet(i));
    }
    cout << ans.size()-1 << endl;
    return 0;
}


Measured memory_bytes: 9244
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
const int MAX = 210000;
const int MAX_NUM = 999999999;
void solve() {
	int a, b, c; cin >> a >> b >> c;
	int ab = a + b;
	int bc = b + c;
	int ca = c + a;
	cout << min(ca, min(ab, bc)) << endl;
	return;
}
int main() {
	solve();
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int n = Integer.parseInt(sa[0]);
		int m = Integer.parseInt(sa[1]);
		List<List<Integer>> list = new ArrayList<>(m + 1);
		for (int i = 0; i <= m; i++) {
			list.add(new ArrayList<>());
		}
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			int a = Integer.parseInt(sa[0]);
			if (a <= m) {
				int b = Integer.parseInt(sa[1]);
				list.get(a).add(b);
			}
		}
		br.close();

		PriorityQueue<Integer> pq = new PriorityQueue<>(new Comparator<Integer>() {
			public int compare(Integer o1, Integer o2) {
				return o2 - o1;
			}
		});

		int ans = 0;
		for (int i = 1; i <= m; i++) {
			for (Integer o : list.get(i)) {
				pq.add(o);
			}
			if (!pq.isEmpty()) {
				ans += pq.poll();
			}
		}
		System.out.println(ans);
	}
}


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

int main () {
  int N;
  cin >> N;
  vector<string> blue(N);
  for (int i = 0; i < N; i++)
    cin >> blue.at(i);
  
  int M;
  cin >> M;
  vector<string> red(M);
  for (int i = 0; i < M; i++)
    cin >> red.at(i);
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    int b_sum = 0, r_sum = 0;
    for (int j = 0; j < N; j++) {
      if (blue.at(i) == blue.at(j))
        b_sum++;
    }
    for (int j = 0; j < M; j++) {
      if (blue.at(i) == red.at(j))
        r_sum++;
    }
    if (sum < b_sum - r_sum)
      sum = b_sum - r_sum;
  }
  
  cout << sum << endl;
}

Measured memory_bytes: 256
import sys
from functools import lru_cache
sys.setrecursionlimit(10**7)
INF = 10 ** 18
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def II(): return int(sys.stdin.readline())

N = II()
A_li = LI()
N = len(A_li)

@lru_cache(maxsize=None)
def dp(i,j):
    if i == 0:
        if j == 0: return 0
        elif j == 1: return -INF
    else:
        if j == 0: return max(dp(i-1,0) + A_li[i-1], dp(i-1,1) - A_li[i-1])
        if j == 1: return max(dp(i-1,0) - A_li[i-1], dp(i-1,1) + A_li[i-1])

print(dp(N,0))


Measured memory_bytes: 303028
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,d;
  cin>>a>>b;
  for(int i=0;i<b;i++){
    int c;
    cin>>c;
    d+=c;
  }
  if(d<a){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }
}
    
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int w, h, n;
  cin >> w >> h >> n;
  int x1 = 0, x2 = w, y1 = 0, y2 = h;
  rep(i, 0, n) {
    int x, y, a;
    cin >> x >> y >> a;
    if (a == 1)
      chmax(x1, x);
    if (a == 2)
      chmin(x2, x);
    if (a == 3)
      chmax(y1, y);
    if (a == 4)
      chmin(y2, y);
  }
  cout << (max(0, x2 - x1)) * (max(0, y2 - y1)) << endl;
}


Measured memory_bytes: 256
from itertools import product
import sys

S = str(input())
A = list(product(['+', '-'], repeat=3))

for a in A:
    ans = 0
    tmp = ""
    for i in range(len(S)-1):
        tmp += S[i]+a[i]
    tmp += S[len(S)-1]
    ans += eval(tmp)
    if ans == 7:
        print(tmp+"=7")
        sys.exit()


Measured memory_bytes: 62204
def floor_sum(n, m, a, b)
    ans = 0
    if a >= m
        ans += (n - 1) * n * (a / m) / 2
        a %= m;
    end

    if b >= m
        ans += n * (b / m)
        b %= m
    end

    y_max = (a * n + b) / m
    x_max = (y_max * m - b)

    return ans if y_max == 0
    ans += (n - (x_max + a - 1) / a) * y_max
    ans += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ans
end

n = gets.to_i
n.times do
    puts floor_sum(*gets.split.map(&:to_i))
end

Measured memory_bytes: 14416
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int N;
  cin>>N; 
  vector<long>a(N);
  
  for(int i=0;i<N;++i){
    cin>>a.at(i);
  }
  vector<long>b(N+1);
  for(int i=0;i<N;++i){
    b.at(a.at(i))++;
  }
  long an=0;
  for(int i=0;i<N+1;++i){
    if(b.at(i)>0){
      an+=b.at(i)*(b.at(i)-1)/2;
    }
  }
  for(int i=0;i<N;++i){
    cout<<an-b.at(a.at(i))*(b.at(a.at(i))-1)/2+(b.at(a.at(i))-2)*(b.at(a.at(i))-1)/2<<endl;
  }
}



Measured memory_bytes: 5760
import sys

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))

    ans = [False for i in range(n)]

    for i in range(n-1, -1, -1):
        num = i + 1
        j = 2
        accum = 0
        while num * j <= n:
            accum = (accum + ans[num * j - 1]) % 2
            j += 1
        ans[i] = (not accum == a[i])

    out = list()
    for i in range(n):
        if ans[i]:
            out.append(i + 1)
    print(len(out))
    print(*out)


        

Measured memory_bytes: 14132
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define uni(e) e.erase(unique(e.begin(),e.end()),e.end())
#define double long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int INF=1e10;
int MOD=1e9+7;
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
}
int gcd(int a,int b){
  if(a%b==0)
    return b;
  return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool sosuu(int a){
  bool b=1;
  if(a<=1)
    return 0;
  else{
  rep1(i,sqrt(a)-1){
  if(a%(i+1)==0)
  b=0;
  }
  return b;
  }
}
int modpow(int a,int b,int m=MOD){
	if(!b)return 1;	if(b&1)return modpow(a,b-1,m)*a%m;
	int memo = modpow(a,b>>1,m);
	return memo*memo%m;
}
int fact_mod(int n) {
    int f=1; 
for(int i=2;i<n+1;i++) f=f*(i%MOD)% MOD;
    return f;
}
int mod_pow(int x,int n) {
    int res=1;
    while(n>0){
        if(n&1) res=(res*x)%MOD; 
        x=(x*x)%MOD;        
n>>=1; 
    }
    return res;
}
int c_mod(int n, int r) {
    if(r>n-r) r=n-r;
    if(r==0) return 1;
    int a=1;
    rep(i,r) 
a=a*((n-i)%MOD)%MOD;
    int b=mod_pow(fact_mod(r), MOD-2);
    return (a%MOD)*(b%MOD)%MOD;
}
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> d(a),e(a);
  rep(i,a)
    cin>>d[i]>>e[i];
  int f=0;
  rep(i,a){
  if(d[i]>=b&&e[i]>=c)
    f++;
  }
  cout<<f<<endl;
}

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

int main(){
 string s;
  cin >> s;
  int a=s.size();
  int ans=0;
  for(int i=1;i<a;i++){
    if(s[i-1] !=s[i]){ans++;}
  }
  cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;

#define REP(i, a, n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lwb lower_bound
#define N 100010
#define M 200010
#define endl "\n"

ll gcd(ll a_,ll b_){if(b_>a_)swap(b_,a_);return (b_==0?a_:gcd(b_,a_%b_));}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(NULL);
	
	ll x, y;
	
	cin >> x >> y;
	
	ll ans = 1, a = x;
	for(ll i = x * 2; i <= y; i *= 2){
		ans++;
		a = i * 2;
	}
	
	cout << ans << endl;
	
	return 0;
}

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

#define int long long

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

  vector<int> a(n);
  for ( int i = 0; i < n; i++ ) cin >> a[i];

  int cnt = 0;
  for ( int i = 0; i < n; i++ ) {
    int minj = i;
    for ( int j = i; j < n; j++ ) {
      if ( a[j] < a[minj] ) {
	minj = j;
      }
    }
    if ( a[i] != a[minj] ) {
      swap(a[i], a[minj]);
      cnt++;
    }
  }

  for ( int i = 0; i < n; i++ ) {
    if ( i ) cout << " ";
    cout << a[i];
  }
  cout << endl;

  cout << cnt << endl;
  
  return 0;
}



Measured memory_bytes: 3096
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        int[] A = new int[N];
        int[] B = new int[N];

        for (int i = 0; i < N; i++) {
            A[i]= sc.nextInt();
            B[i]= sc.nextInt();
        }


        Arrays.sort(A);
        Arrays.sort(B);

        if(N%2==1){
            int min = A[N/2];
            int max = B[N/2];
            System.out.println(max-min+1);
        }else{
            int min2 = (A[N/2-1]+A[N/2]);
            int max2 = (B[N/2-1]+B[N/2]);
            System.out.println((max2-min2)+1);
        }
    }



}

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

void printArray(int a[], int n) {
  for (int i = 0; i < n; i++) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

void bubbleSort(int a[], int n) {
  bool flag = true;
  int count = 0;
  while (flag) {
    flag = false;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] < a[i - 1]) {
        swap(a[i], a[i - 1]);
        flag = true;
        count++;
      }
    }
  }
  printArray(a, n);
  cout << count << endl;
}

int main() {
  int n, a[100];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  bubbleSort(a, n);
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
using namespace std ;
using ll = long long ;

ll dsum(ll n){
    string s = to_string(n) ;
    ll res = 0 ;
    for(int i=0;i<s.size();i++) res += s.at(i)-'0' ;
    return res ;
}

string yorn(bool a){
    if(a) return "Yes" ;
    return "No" ;
}

int main(){
    ll n ; cin >> n ;
    cout << yorn(n%dsum(n)==0) << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/rope>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll long long
//#define int long long
#define pb push_back
#define x first
#define ld long double
#define y second
#define mk(a,b) make_pair(a,b)
#define rr return 0
#define sqr(a) ((a)*(a))
#define all(a) a.begin(),a.end()

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<class value, class cmp = less<value> >
using ordered_set = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class value, class cmp = less_equal<value> >
using ordered_multiset = tree<value, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
template<class key, class value, class cmp = less<key> >
using ordered_map = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;

/// find_by_order()
/// order_of_key()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline int randll(int l = INT_MIN, int r = INT_MAX) {
    return uniform_int_distribution<int>(l, r)(rng);
}

main()
{
    ios::sync_with_stdio(0);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int x;
    cin >> x;
    int g = 360 * x / __gcd(360, x);
    cout << g / x << '\n';
}


Measured memory_bytes: 3616
#include<cstdio>
using namespace std;

int A[2000], n;

int solve(int i, int m) {
    if (m == 0) return 1;
    if (i >= n) return 0;
    int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
    return res;
}

int main() {
    int q, m;
    scanf("%d", &n);
    for(int i = 0; i < n; i++) scanf("%d", &A[i]);
    scanf("%d", &q);
    for(int i = 0; i < q; i++) {
        scanf("%d", &m);
    
        if(solve(0, m)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2700