akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

const int INF=0x3f3f3f3f;
const int MAXN=1e5+5;

int n,m,cnt;
int f[MAXN];

int find(int x)
{
	if(x==f[x])
	    return x;
	else
	    return f[x]=find(f[x]);
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	    f[i]=i;
	
	while(m--)
	{
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		int fx=find(x);
		int fy=find(y);
		if(fx!=fy)
		{
			f[fx]=fy;
			cnt++;
		}
	}
	printf("%d\n",n-cnt);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const int maxV = 90010;
const int maxN = 1e5+10;
const int inf = 0x3f3f3f3f;
const int MOD = 998244353;
const ll INF = 1000000000000000010LL;


int n;
int a[maxN],b[maxN];
int a1[maxN],b1[maxN];
pii c[maxN];
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		a1[i] = a[i];
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&b[i]);
		b1[i] = b[i]; 
	}
	sort(a1+1,a1+1+n);
	sort(b1+1,b1+1+n);
	for(int i=1;i<=n;i++)
	{
		if(a1[i] > b1[i])
		{
			puts("No");
			return 0;
		}
	}
	for(int i=1;i<n;i++)
	{
		if(a1[i+1] <= b1[i] && a1[i] <= b1[i+1])
		{
			puts("Yes");
			return 0;
		}
	}
	set<int> H1,H2;
	for(int i=1;i<=n;i++)
	{
		H1.insert(a[i]);
		H2.insert(b[i]);
		c[i] = pii(b[i],a[i]);
	}
	if(H1.size() < n || H2.size() < n)
	{
		puts("Yes");
		return 0;
	}
	sort(c+1,c+1+n);
	for(int i=1;i<=n;i++)
	{
		a[i] = c[i].second;
	}
	unordered_map<int,int> to;
	for(int i=1;i<=n;i++)
	{
		if(a[i] == a1[i])
		{
			puts("Yes");
			return 0;
		} 
		to[a[i]] = a1[i];
	}
	int x = a[1];
	int cnt = 1;
	x = to[x];
	while(x != a[1])
	{
		cnt++;
		x = to[x];
	}
	if(cnt < n)
	{
		puts("Yes");
		return 0;
	}
	puts("No");
	return 0;
}

Measured memory_bytes: 16036
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " is " << x << endl

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

const int INF = 1e9 + 7;

signed main()
{
	IO_OP;
	
	int x;
	cin >> x;
	int g = __gcd(x, 360);
	cout << 360 / g << endl;
	
}





Measured memory_bytes: 3636
n, m, r = gets.chomp.split(" ").map(&:to_i)
visit_town = gets.chomp.split(" ").map(&:to_i)
INF = 1 << 40
ans = INF
dist = Array.new(n).map{Array.new(n, INF)}
n.times do |i|
    dist[i][i] = 0
end

m.times do
    a, b, c = gets.chomp.split(" ").map(&:to_i)
    dist[a-1][b-1] = c
    dist[b-1][a-1] = c
end

n.times do |k|
    n.times do |i|
        n.times do |j|
            dist[i][j] = dist[i][k] + dist[k][j] if dist[i][j] > dist[i][k] + dist[k][j]
        end
    end
end

visit_town.permutation(r).each do |per|
    tmp = 0
    ptr = per[0]
    per.each do |node|
        tmp += dist[ptr-1][node-1]
        ptr = node
    end
    ans = ans > tmp ? tmp : ans
end

puts ans

Measured memory_bytes: 2428
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};
const int kx[] = {+1, +2, -1, -2, +1, +2, -1, -2};
const int ky[] = {+2, +1, +2, +1, -2, -1, -2, -1};
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }

#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif
bool isPrime(ll x){
  if(x==1)return false;
  for(ll i=2;i*i<=x;i++){
    if(x%i==0){
      return false;
    }
  }
  return true;
}
int main(){
  fastIO();
  ll n,ans=0,c=10;
  cin>>n;
  set<ll>factors;
  vector<ll>prime_factors;
  map<ll,ll>reps;
  map<ll,ll>seen_primes;
  factors.insert(n);
  for(int i=2;i<=sqrt(n)+c;i++){
    if(n%i==0){
      factors.insert(i);
      if(n%(n/i)==0){
        factors.insert(n/i);
      }
    }
  }
  for(set<ll>::iterator it=factors.begin();it!=factors.end();it++){
    ll value=*it;
    if(isPrime(value)){
      while(n%value==0){
        prime_factors.push_back(value);
        n/=value;
      }
    }
  }
  for(int i=0;i<prime_factors.size();i++){
    reps[prime_factors[i]]++;
  }
  for(int i=0;i<prime_factors.size();i++){
    ll take=1;
    if(seen_primes[prime_factors[i]]>0)continue;
    while(reps[prime_factors[i]]-take>=0){
      reps[prime_factors[i]]-=take,take++,ans++;
    }
    seen_primes[prime_factors[i]]++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3768
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
short line[103][103],list[103][103],f[103][103][103][103],n,m,op,sx,sy;
char s[103][103];
inline short min(short a,short b){
	if(a<b) return a;
	return b;
}
inline short max(short a,short b){
	if(a>b) return a;
	return b;
}
int main(){
    cin>>n>>m;
    for(short i=1;i<=n;i++){
    	cin>>(s[i]+1);
    }
    for(short i=1;i<=n;i++){
    	for(short j=1;j<=m;j++){
        	line[i][j]=line[i][j-1]+(s[i][j]=='o');
        	list[i][j]=list[i-1][j]+(s[i][j]=='o');
        	if(s[i][j]=='E'){
        		sx=i,sy=j;
			}
    	}
	}
    for(short i=sx;i;i--){
    	for(short j=sy;j;j--){
    		for(short k=sx;k<=n;k++){
    			for(short p=sy;p<=m;p++){
        			if(1<i&&k+1<sx+i){
        				f[i-1][j][k][p]=max(f[i-1][j][k][p],f[i][j][k][p]+line[i-1][min(p,m-sy+j)]-line[i-1][max(j-1,p-sy)]);
						op=max(op,f[i-1][j][k][p]);
					}
        			if(k<n&&sx+k<n+i){
        				f[i][j][k+1][p]=max(f[i][j][k+1][p],f[i][j][k][p]+line[k+1][min(p,m-sy+j)]-line[k+1][max(j-1,p-sy)]);
						op=max(op,f[i][j][k+1][p]);
					}
        			if(1<j&&p+1<sy+j){
        				f[i][j-1][k][p]=max(f[i][j-1][k][p],f[i][j][k][p]+list[min(k,n-sx+i)][j-1]-list[max(i-1,k-sx)][j-1]);
						op=max(op,f[i][j-1][k][p]);
					}
        			if(p<m&&sy+p<m+j){
        				f[i][j][k][p+1]=max(f[i][j][k][p+1],f[i][j][k][p]+list[min(k,n-sx+i)][p+1]-list[max(i-1,k-sx)][p+1]);
						op=max(op,f[i][j][k][p+1]);
					}
    			}
			}
		}
	}
    cout<<op<<endl;
    return 0;
}

Measured memory_bytes: 208640
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cmath>
#include <chrono>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int> ())
#define FOR(k, n) for(int k=0; k<n; k++)



using namespace std;


char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
const ll MOD = 1000000007;
char alphs[26] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };


void solve() {

    ll a, b;
    
    cin>>a>>b;
    if(b>a){
        ll temp=b;
        b=a;
        a=temp;
    }
    ll c,d;
    cin>>c>>d;
    if(d>c){
        ll temp=d;
        d=c;
        c=temp;
    }
    
    ll cn1=max(a*c, a*d);
    ll c2=max(b*c, b*d);
    
    cout<<max(cn1, c2)<<endl;
    
}

int main() {

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

    
        solve();


    return 0;
}


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

using namespace std;

int main(){
    int n,m, x,y,suma = 0;
    vector<int> a;
    cin >> n;   
    for(int i = 0; i < n; i++){
        cin >> x;
        a.push_back(x);
        suma += x;
    }
    cin >> m;
    for(int i = 0; i < m; i++){
        cin >> x >> y;
        cout << suma - (a[x-1] - y) << endl;
    }

        
    return 0;
}

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
 
## Library
 
import sys
from fractions import gcd
import math
from math import ceil,floor
import collections
from collections import Counter
import itertools
import copy

## input
 
# N=int(input())
# A,B,C,D=map(int, input().split())
# S = input()
# yoko = list(map(int, input().split()))
# tate = [int(input()) for _ in range(N)]
# N, M = map(int,input().split()) 
#    P = [list(map(int,input().split())) for i in range(M)]
#    S = []
#    for _ in range(N):
#        S.append(list(input()))

N=int(input())
A = list(map(int, input().split()))

B=[0]*N

for i in range(N):
  if i<(N+1)//2:
    B[i]=A[N-1-2*i]
  else:
    B[i]=A[N-2*(N-i)]

print(*B)

Measured memory_bytes: 108872
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
int main() {
  
  int N;
  cin>>N;
  
  vector<int> D(N);
  for(int i=0;i<N;i++){
    cin>>D[i];
  }
  
  set<int> S;
  for(int i=0;i<N;i++){
    S.insert(D[i]);
  }
  
  cout<<S.size()<<endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false); cin.tie(0); cout.precision(10); cout << fixed
#define endl '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

void solve(istream& cin, ostream& cout) {
  ll n, a, b;
  cin >> n >> a >> b;
  ll ans;
  if ((b - a) % 2 == 0) ans = (b - a) / 2;
  else
    ans = (2 * min(a - 1, n - b) + 1 + b - a) / 2;
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
  return 0;
}
#endif


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    int ans = 1e9;
    for(int i=0;i<n;i++){
        int t = k - (a[(i+1)%n] - a[i] + k)%k;
        if(t < ans) ans = t;
    }
    cout << ans << endl;
    
}


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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    long long K,ans,tmp,count=0;
    

    cin>>K;

    vector<int> check(K+5,0);

    ans=-1;
    tmp=0;
    while(1){
        tmp=tmp*10;
        tmp=tmp%K;
        tmp+=7;
        tmp=tmp%K;
        count++;

        if(tmp % K ==0){
            ans=count;
            break;
        }else{
            if(check[tmp%K] >0){
                break;
            }else{
                check[tmp%K]++;
            }
        }
    }

    cout<<ans<<endl;


    return 0;
}



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

int main(){

    string s;
    cin >> s;

    int q;
    cin >> q;
    bool f=true;
    string tt="";

    rep(i,q){
        int t;
        cin >> t;
        if(t==1){
            if(f){
                f=false;
            }else{
                f=true;
            }
        }else{
            string c;
            cin >> t >> c;
            if(t==1){
                if(f){
                    tt+=c;
                }else{
                    s+=c;
                }
            }else{
                if(f){
                    s+=c;
                }else{
                    tt+=c;
                }
            }
        }
    }

    if(f){
        rep(i,tt.size()){
            cout << tt[tt.size()-i-1];
        }
        cout << s << endl;
    }else{
        int ss=s.size();
        rep(i,ss){
            cout << s[ss-i-1];
        }cout << tt << endl;
    }

    return 0;
}

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

#define ll long long
#define rep(i,n) for(ll i=(ll)(0); i<(ll)(n); ++i)
#define irep(i,m,n) for(ll i=(ll)(m); i<(ll)(n); ++i)
#define vi vector<int>

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }

const long long MOD = 1e9 + 7;

signed main()
{
  int n,y; cin>>n>>y;
  int i=0;
  while(i*10000<=y){
    int j=0;
    while((i*10000+j*5000)<=y){
      if((y-(i*10000+j*5000))/1000==(n-i-j)){
        cout<<i<<" "<<j<<" "<<(y-(i*10000+j*5000))/1000<<endl;
        return 0;
      }
      j++;
    }
    i++;
  }
  cout<<-1<<" "<<-1<<" "<<-1<<endl;
}

Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

//Area Separation
public class Main{

	final double EPS = 1e-10;
	
	double dot(double[] a, double[] b){
		return a[0]*b[0]+a[1]*b[1];
	}
	double cross(double[] a, double[] b){
		return a[0]*b[1]-a[1]*b[0];
	}
	double norm(double[] a){
		return Math.hypot(a[0], a[1]);
	}
	double norm(double[] a, double[] b){
		return Math.hypot(a[0]-b[0], a[1]-b[1]);
	}
	double[] sub(double[] a, double[] b){
		return new double[]{a[0]-b[0], a[1]-b[1]};
	}
	double area(double[] a, double[] b, double[] c){
		double res = cross(a, b)+cross(b, c)+cross(c, a);
		return Math.abs(res)/2;
	}
	double ex(double[] a, double[] b, double[] c){
		double[] s1 = sub(b, a), s2 = sub(c, a);
		return cross(s1, s2);
	}
	boolean crossing(double[] a, double[] b, double[] s, double[] t){
		if(Math.abs(cross(sub(b, a), sub(t, s)))<EPS){
			return Math.min(dist(a, b, s), Math.min(dist(a, b, t), Math.min(dist(s, t, a), dist(s, t, b))))<EPS;
		}
		if(ex(a, b, s)*ex(a, b, t)>0)return false;
		if(ex(b, a, s)*ex(b, a, t)>0)return false;
		if(ex(s, t, a)*ex(s, t, b)>0)return false;
		return ex(t, s, a)*ex(t, s, b)<EPS;
	}
	double dist(double[] a, double[] b, double[] p){
		if(dot(sub(b, a), sub(p, a))<EPS)return norm(a, p);
		if(dot(sub(a, b), sub(p, b))<EPS)return norm(b, p);
		return Math.abs(cross(sub(b, a), sub(p, a)))/norm(a, b);
	}
	double dist(double[] a, double[] b, double[] s, double[] t){
		if(crossing(a, b, s, t))return 0;
		return Math.min(dist(a, b, s), Math.min(dist(a, b, t), Math.min(dist(s, t, a), dist(s, t, b))));
	}
	double distLP(double[] a, double[] b, double[] p){
		return Math.abs(cross(sub(b, a), sub(p, a)))/norm(a, b);
	}
	double[] cp(double[] a, double[] b, double[] s, double[] t){
		double ds = distLP(a, b, s), dt = distLP(a, b, t);
		double k = ds/(ds+dt);
		double[] d = sub(t, s);
		return new double[]{s[0]+k*d[0], s[1]+k*d[1]};
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			double[][][] l = new double[n][2][2];
			int res = 1;
			for(int i=0;i<n;i++){
				for(int j=0;j<2;j++)for(int k=0;k<2;k++)l[i][j][k]=sc.nextDouble();
				List<double[]> s = new LinkedList<double[]>();
				for(int j=0;j<i;j++){
					if(!crossing(l[i][0], l[i][1], l[j][0], l[j][1]))continue;
					double[] cp = cp(l[i][0], l[i][1], l[j][0], l[j][1]);
					if(Math.abs(cp[0])==100||Math.abs(cp[1])==100)continue;
					s.add(cp);
				}
				for(int j=0;j<s.size();j++){
					for(int k=j+1;k<s.size();k++){
						if(norm(s.get(j), s.get(k))<EPS){
							s.remove(k); k--;
						}
					}
				}
				res+=s.size()+1;
			}
			System.out.println(res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
using namespace std;
int fa[2000010],n;
int findf(int x)
{
    if(fa[x]==x)
        return x;
    return (fa[x]=findf(fa[x]));
}
void unionf(int x,int y)
{
    fa[findf(x)]=findf(y);
}
int main()
{
    int m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        fa[i]=i;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        unionf(x,y);
    }
    int a[2000010];
    for(int i=1;i<=n;i++)
        a[findf(i)]++;
    int maxn=0;
    for(int i=1;i<=n;i++)
        maxn=max(maxn,a[i]);
    cout<<maxn<<endl;
    return 0;
}

Measured memory_bytes: 10520
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
typedef long long       ll;
#define pb                emplace_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define forr(i, b, e)     for (int i = b; i < e; i++)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);
const double EPS = 1e-9;
const double PI = acos(-1);
#define tam 100056
#define offset 10000000
typedef pair<int,short> par;
const int MOD=1e9+7;
vector<int> val,sum,val2,sum2;
void go(vector<int> &val,int n,string txt,vector<int> &sum)
{
    val.assign(n+1,0);
    sum.assign(n+1,0);
    int ant=0;
    forr(i,0,n)
    {
        if (txt[i]=='A')
            val[i+1]=1;
        else
            val[i+1]=2;
        sum[i+1]=ant+val[i+1];
        //cout<<sum[i+1]<<" ";
        ant=sum[i+1];
    }    
    //cout<<endl;
}
int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    string txt1,txt2;
    cin>>txt1>>txt2;
    int n,m;
    n=txt1.size();
    m=txt2.size();
    int ant=0;
    go(val,n,txt1,sum);
    go(val2,m,txt2,sum2);
    int q;
    cin>>q;
    int iz2,der2,iz,der;
    while(q--)
    {
        cin>>iz>>der>>iz2>>der2;
        if ((sum[der]-sum[iz-1])%3==(sum2[der2]-sum2[iz2-1])%3)
            cout<<"YES\n";
        else
            cout<<"NO\n";
    }
}
// PLUS ULTRA!

Measured memory_bytes: 2512
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

int main() {
	int t;
	cin >> t;
	
	for(int times = 0; times < t; times++) {
		int n, k;
		cin >> n >> k;
		
		vector<int> x(n);
		
		for(int i = 0; i < n; i++) {
			cin >> x[i];
		}
		
		vector<int> y(n-1);
		
		for(int i = 0; i < n - 1; i++) { 
			y[i] = x[i + 1] - x[i];
		}
		
		sort(y.begin(), y.end());
		
		cout << accumulate(y.begin(), y.end() - min(k, n) + 1, 0) << endl;
	}
}

Measured memory_bytes: 3560
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

#define MAXN (1 << 10)

int n, m;
vector<int> a[MAXN];
int v[MAXN];
int d[MAXN];
int p[MAXN];
queue<int> q;

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v1, v2;
		cin >> v1 >> v2;
		a[v1].push_back(v2);
	}
	vector<int> best;
	int bestlen = MAXN;
	for (int i = 1; i <= n; i++) {
		memset(v, 0, sizeof(v));
		memset(d, 63, sizeof(d));
		memset(p, -1, sizeof(p));
		q.push(i);
		d[i] = 0;
		while (!q.empty()) {
			int cur = q.front();
			q.pop();
			v[cur] = 1;
			for (auto& nnext: a[cur]) {
				if ((nnext == i) && (d[cur] < bestlen)) {
					bestlen = d[cur];
					best.clear();
					int t = cur;
					while (t != -1) {
						best.push_back(t);
						t = p[t];
					}
				}
				if (!v[nnext]) {
					q.push(nnext);
					if (d[nnext] > d[cur] + 1) {
						d[nnext] = d[cur] + 1;
						p[nnext] = cur;
					}
				}
			}
		}
	}
	if (bestlen == MAXN) {
		cout << -1 << endl;
		return 0;
	}
	cout << best.size() << endl;
	for (int i = 0; i < best.size(); i++) {
		cout << best[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3200
// author: tarang 
#include<bits/stdc++.h>
#define ll long long
#define endl  '\n'
#define fastio  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD=1000000007;
#define PI acos(-1)
using namespace std;
int vis[2*100005 + 5] ;
vector<int> adj[2*100005 + 5];
int dfs(int node , int ans){
	vis[node] = 1 ;
	ans++;
	for(auto child : adj[node]){
		if(vis[child]  == 0){
			ans = dfs(child , ans);
		}
	}
	return ans ; 
}
int main(){
	int n , m ;
	cin >> n >> m ;
	for(int i = 0 ; i < m ; i++){
		int x , y ;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	int maxx=0;
	for(int i = 1 ; i <= n ; i++){
		 if(!vis[i]){
		 	int ans = 0;
		 	int len = dfs(i , ans);
		 	//cout << len << endl;
		 	maxx= max(maxx, len);
		 }
	}
	cout << maxx << endl;
}


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

using namespace std; 

int main() { 

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

	int n;
	cin >> n;

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

	int count = 0;

	for(int i = 1; i < n - 1; i++) {
		int mn = min(v[i], min(v[i - 1], v[i + 1]));
		int mx = max(v[i], max(v[i - 1], v[i + 1]));
		if(v[i] != mn and v[i] != mx) {
			count++;
		}
	}

	cout << count;

	return 0; 
}

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

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

    int a, b;

    cin >> a >> b;

    if(a >= 13)
    {
        cout << b;
    } else if(a < 6)
    {
        cout << 0;
    } else {
        cout << b / 2;
    }
}

Measured memory_bytes: 888
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF 1001001001
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>n;
    //vector<vector<ll>> v(tate,vector<ll> (yoko));
    vector<ll> v(n);
    rep(i,n)   cin >> v[i];
    ll q;
    map<ll,ll>  ma;
    vector<pair<ll,ll>> p;
    ll num=1;
    for(ll i=0;i<n;i++) {
        ma[v[i]]++;
        //cout<<v[i]<<" "<<ma[v[i]]<<endl;
        /*
        if(v[i]!=v[i-1]){
            p.push_back(make_pair(v[i-1],num));
            num=1;
        }else{
            num++;
        }
        if(i==n-1){
                p.push_back(make_pair(v[i],num));
        }*/
        sum+=v[i];
    }
    //sum+=v[n-1];
    //cout<<sum<<endl;
    cin>>q;
    //cout<<q<<endl;
    rep(_,q){
        ll be,to;
        cin>>be>>to;
        sum-=ma[be]*be;
        //cout<<sum<<" ";
        //cout<<ma[be]<<" "<<ma[to]<<" to ";
        ma[to]=ma[to]+ma[be];
        //cout<<ma[to]<<endl;
        sum+=ma[be]*to;
        ma[be]=0;
        cout<<sum<<endl;
    }
    /*
    rep(i,p.size()){
        cout<<p[i].first<<" "<<p[i].second<<endl;
    }*/

    return 0;
}


Measured memory_bytes: 9964
#include<bits/stdc++.h>
#define taskname "VirtualACM"
#define int long long
using namespace std;

const int maxn = 2e5 + 10;
int a[maxn][21], b[maxn][21];
int n;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif // CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        int x;    cin >> x;
        for (int cnt = 1; x; ++cnt)
        {
            a[i][cnt] = x & 1;
            x >>= 1;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i)
    {
        int hold = 0;
        for (int j = 1; j <= 20; ++j)
        {
            b[i][j] = b[i - 1][j];
            if (a[i][j]) b[i][j] = i;
            if (b[i][j] == i) hold = max(hold, b[i - 1][j] + 1);
            else if (b[i][j]) hold = max(hold, b[b[i][j] - 1][j] + 1);
            else hold = max(hold, 1ll);
        }
        if (!hold) ++hold;
        ans += i - hold + 1;
    }

//
//    for (int i = 1; i <= n; ++i)
//    {
//        for (int j = 1; j <= 20; ++j) cerr << a[i][j] << ' ';
//        cerr << endl;
//    }
//    cerr << endl;
//    for (int i = 1; i <= n; ++i)
//    {
//        for (int j = 1; j <= 20; ++j) cerr << b[i][j] << ' ';
//        cerr << endl;
//    }
    cout << ans;
}


Measured memory_bytes: 65920
S = list(str(input()))

for i in range(len(S)-1):
    if i == 0 and S[0] == '?':
        if S[i+1] == 'P':
            S[0] = 'D'
        else:
            S[0] = 'P'
    if S[i] == '?':
        if S[i+1] == 'P':
            S[i] = 'D'
        else:
            if S[i-1] == 'P':
                S[i] = 'D'
            else:
                S[i] = 'P'

if S[len(S)-1] == '?':
    S[len(S)-1] = 'D'

strS = "".join(S)

print(strS)

Measured memory_bytes: 10796
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define INF 1234567890
#define pii pair<int,int>
#define LL long long
using namespace std;

int main () {
    //clock_t start = clock();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,k;
    cin >> n >> m >> k;
    char a[n+5][m+5];
    for (int i=1;i<=n;i++) {
        string s;
        cin >> s;
        for (int j=1;j<=m;j++) {
            a[i][j] = s[j-1];
        }
    }
    int ans = 0;
    for (int i=0;i<(1<<n);i++) {
        for (int j=0;j<(1<<m);j++) {
            vector<int> s,t;
            int x = i;
            while (s.size() < n) {
                s.pb(x%2);
                x/=2;
            }
            x = j;
            while (t.size() < m) {
                t.pb(x%2);
                x/=2;
            }
            char b[n+5][m+5];
            for (int k=1;k<=n;k++) {
                for (int l=1;l<=m;l++) {
                    if (s[k-1] == 1 || t[l-1] == 1) b[k][l] = '.';
                    else b[k][l] = a[k][l];
                }
            }
            int cnt = 0;
            for (int k=1;k<=n;k++) {
                for (int l=1;l<=m;l++) {
                    if (b[k][l] == '#') cnt++;
                }
            }
            if (cnt == k) ans++;
        }
    }
    cout << ans << endl;
    //cerr << fixed << setprecision(3) << (clock()-start)*1./CLOCKS_PER_SEC << endl;
    return 0;
}

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

int main() {
    string N; cin >> N;
    for (int i = 1; i < N.size(); i++) {
        if (N.at(i) == '9') continue;
        else {
            cout << 9 * (N.size() - 1) + N.at(0) - '0' - 1 << endl;
            return 0;
        }
    }
    cout << 9 * (N.size() - 1) + N.at(0) - '0' << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll zero = 0;
const ll INF = 10000000000000000; //10^16
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;


int main(void){
    ll N,M;
    cin >> N >> M;
    vector<ll> H(N);

    ll tmpa,tmpb;
    for(ll i = 0; i < N; i++){
        cin >> H.at(i);
    }
    
    ll cnt = 0;
    vector<ll> checked(N,1);
    for(ll i = 0; i < M; i++){
        cin >> tmpa >> tmpb;
        tmpa--; tmpb--;
        if(H.at(tmpa) >= H.at(tmpb)) checked.at(tmpb) = 0;
        if(H.at(tmpa) <= H.at(tmpb)) checked.at(tmpa) = 0;
    }
    
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ans += checked.at(i);
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
#include <cstring>
#include <limits>
using namespace std;
#define ll long long int
#define X first
#define Y second
#define fw(i, start, end) for (ll i = start; i < end; ++i)
#define fe(i, start, end) for (ll i = start; i <= end; ++i)
#define L(T)  \
    ll T;     \
    cin >> T; \
    while (T--)
#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);            \
    cout.tie(nullptr);
#define endl "\n"
#define mem(a, i) memset(a, i, sizeof(a))
int main()
{
    FASTIO
    double n, m;
    cin >> n >> m;
    cout << (ll)((n * m)+0.001) << endl;

    return 0;
}


Measured memory_bytes: 3736
#include <iostream>
#include <set>
#include <string>

using namespace std;

#define Rep(i, n) for(int i = 0; i < (int)(n); ++i)

int main() {
  int n;
  cin >> n;
  set<string> kinds;
  Rep(i, n) {
    string s;
    cin >> s;
    kinds.insert(s);
  }
  cout << kinds.size() << endl;
  return 0;
}


Measured memory_bytes: 19272
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>

using std::cin;
using std::cout;
using std::endl;

int main(int argc, char* argv[])
{
  int n;
  cin >> n;
  std::vector<int> vec(n);
  std::vector<int> result(n, -1);
  for (size_t i = 0; i < n; ++i)
  {
    std::scanf("%d", &vec[i]);
  }

  size_t cnt = 1;
  result[0] = vec[0];
  if (vec[0] == 1)
  {
    cnt = std::count(vec.begin(), vec.end(), 1);
  }
  else
  {
    for (size_t i = 1; i < vec.size(); ++i)
    {
      if (vec[i] == 1)
      {
        cnt += std::count(vec.begin() + i, vec.end(), 1);
        break;
      }
      if(std::min(vec[i], result[i-1]) == vec[i])
      {
        cnt++;
        result[i] = vec[i];
      }
      else
      {
        result[i] = result[i-1];
      }
    }
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>

using namespace std;

int main() {
  int days[] = { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
  const char* wdays[] = {
    "Wednesday",
    "Thursday",
    "Friday",
    "Saturday",
    "Sunday",
    "Monday",
    "Tuesday"
  };

  int month, day;
  while (true) {
    scanf("%d %d", &month, &day);
    if (month == 0) { break; }

    int acc_days = 0;
    for (int i = 0; i < month; ++i) { acc_days += days[i]; }
    acc_days += day;
    puts(wdays[acc_days % 7]);
  }

  return 0;
}

Measured memory_bytes: 996
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>

using namespace std;

int pos[][2] = {3,3,0,0,0,1,0,2,
                0,3,1,0,1,1,1,2,
                1,3,2,0,2,1,2,2,
                2,3,3,0,3,1,3,2};

int dx[] = {0,1,-1,0};
int dy[] = {1,0,0,-1};
char dir[] = {'R','D','U','L'};
int en[16] = {1,2,3,4,
                5,6,7,8,
                9,10,11,12,
                13,14,15,0};
char path[100];
int puz[16];

int hstar()
{
    int h = 0;
    for(int i = 0; i < 16; ++i){
        int x = puz[i];
        if(x == 0) continue;
        h += abs(i / 4 - pos[x][0]) + abs(i % 4- pos[x][1]);
    }
    return h;
}


bool dfs(int p,int pre,int d, int maxd)
{
    if(d + hstar() > maxd) return false;

    if(d == maxd)
        return memcmp(puz,en,sizeof(en)) == 0;

    int x = p / 4, y = p % 4;
    for(int j = 0; j < 4; ++j)
    {
        if(pre + j == 3) continue;
        int nx = x + dx[j], ny = y + dy[j];
        int nz = 4 * nx + ny;
        if(nx >= 0 && nx < 4 && ny >= 0 && ny < 4)
        {
            swap(puz[p],puz[nz]);
            path[d] = dir[j];
            if(dfs(nz,j,d+1,maxd)) return true;
            swap(puz[p],puz[nz]);
        }
    }
    return false;
}

bool solvable()
{
    int cnt = 0;
    for(int i = 0; i < 16; ++i){
        if(puz[i] == 0)
            cnt += 3 - i / 4;
        else{
            for(int j = 0; j < i; ++j)
                if(puz[j] && puz[j] > puz[i])
                    cnt++;
        }
    }
    return !(cnt&1);
}

int main(void)
{
    int T,p;
        for(int i = 0; i < 16; ++i)
        {
            scanf("%d",&puz[i]);
            if(puz[i] == 0)
                p = i;
        }
        if(solvable())
        {
            int maxd = 0;
            for(;!dfs(p,-1,0,maxd); ++maxd);
            path[maxd] = 0;
            printf("%d\n",maxd);
        }
    return 0;
}



Measured memory_bytes: 2732
#include <bits/stdc++.h>
using namespace std;
#define double long double
typedef complex<double> P;
  
int W,H,N;
P ps[200];
map<double,double> memo;
double f(double y_off){
    if( memo.count(y_off) ) return memo[y_off];
    vector<double> s;
    for(int i = 0 ; i < 2 * N ; i++){
        double x = ps[i].real();
        double y = ps[i].imag() - y_off;
        double t = atan2(y,x);
        s.push_back(t);
    }
    sort(s.begin(),s.end());
    double Y_L = max<double>(0.0  , y_off + tan(s[N-1]) );
    double Y_H = min<double>(1.0, y_off + tan(s[N]) );
    return memo[y_off] = max<double>(0,Y_H - Y_L);
}
double g(double l,double r){
    return (f(l) + 4 * f((l+r)/2) + f(r)) * (r-l) / 6;
}
double EPS = 1e-13;
double G(double l,double r,int k=4){
    double m = (l+r) / 2;
    double S1 = g(l,r);
    double S2 = g(l,m) + g(m,r);
    if( fabs(S1-S2) < EPS and k <= 0){
        return S1;
    }else{
        return G(l,m,k-1) + G(m,r,k-1);
    }
}
int main(){
    while( cin >> W >> H >> N && N){  
        vector<double> tp;
        tp.push_back(0);
        tp.push_back(1);
        for(int i = 0 ; i < 2 * N ; i++){
            double x,y;
            cin >> x >> y;
            x /= W;
            y /= H;
            ps[i] = P(x,y);
            if( x < EPS ) tp.push_back(y);
        }
        sort(tp.begin(),tp.end());
        tp.erase(unique(tp.begin(),tp.end()),tp.end());
        memo.clear();
        double ans = 0;
        for(int i = 0 ; i+1 < tp.size() ; i++){
            ans += G(tp[i],tp[i+1]);
        }
        printf("%.15Lf\n",ans);
    }
}

Measured memory_bytes: 3988
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

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

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(int i = 0; i < n; i++)


int main() {
    int n;
    
    cin >> n;
    
    int m = 1;
    for(;;){
        if(pow(2, m) - 1 > n){
            break;
        }
        m++;
    }
    
    cout << m - 1 << endl;
}


Measured memory_bytes: 3276
// Problem : D - Maze Master
// Contest : AtCoder Beginner Contest 151
// URL : https://atcoder.jp/contests/abc151/tasks/abc151_d
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor2)

#include<bits/stdc++.h>
#define pb push_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define f first
#define se second
using namespace std;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
//int m=1000000007;
int abst(int a)
{return a<0?-a:a;}
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};


int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
int n,m;
int BFS(pii p1,string s[])
{
	map<pii,int> mp;
	mp[p1]=0;
	queue<pii> q;
	q.push(p1);
	while(!q.empty())
	{
		pii pt=q.front();
		int x=pt.f,y=pt.se;
		q.pop();
		for(int i=-1;i<=1;i++)
		for(int j=-1;j<=1;j++)
		{
		 if(i==0 || j==0)
			{
			if(x+i<0 || x+i>n-1 || y+j<0 || y+j>m-1 || s[x+i][y+j]=='#')
			continue;
			if(!mp.count({x+i,y+j}))
			{
			mp[{x+i,y+j}]=mp[pt]+1;
			q.push({x+i,y+j});
		 }
			}
	}
	}
	int ans=INT_MIN;
	for(auto it=mp.begin();it!=mp.end();it++)
	{
	ans=max(ans,it->se);//cout<<it->se<<" ";}
//	cout<<"\n";
}
	return ans;
}
void solve()
{
cin>>n>>m;
string s[n];
for(int i=0;i<n;i++)
cin>>s[i];
int ans=INT_MIN;
for(int i=0;i<n;i++)
for(int j=0;j<s[i].size();j++)
{
	if(s[i][j]=='.')
	{
	ans=max(ans,BFS({i,j},s));
//	cout<<i<<" "<<j<<"\n";
	}
}
cout<<ans;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t;
//in>>t;
t=1;
while(t--)
{
    solve();
}
}


Measured memory_bytes: 256
//============================================================================
// Name        : b.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int x,y;cin>>x>>y;
	for(int i=0;i<=x;i++){
		int j=x-i;
		if(i*2+j*4==y){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define SWAP(x, y) {int z; z = x; x = y; y = z;}

void dispNumsLn(int *nums, int length) 
{
    int i;

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

void reverseArray(int *array, int length) 
{
    int head, tail;

    for(head = 0, tail = length - 1;
            head < tail;
            head++, tail--) {
        SWAP(array[head], array[tail]);
    }
}

int *supplyGArray(int n, int *interval_length)
{
    int i, j, length = n, GValue = 1;
    int *array, *tmp_array;

    array = malloc(sizeof(int) * length);
    array[0] = GValue;
    for(i = 1, length = i + 1, GValue = 3 * GValue + 1; 
            GValue < n; 
            GValue = GValue * 3 + 1, i++, length = i + 1) {
        tmp_array = malloc(sizeof(int) * length);
        memcpy(tmp_array, array, (length - 1)*sizeof(int));
        tmp_array[i] = GValue;
        free(array);
        array = malloc(sizeof(int) * length);
        memcpy(array, tmp_array, (length)*sizeof(int));
        free(tmp_array);
    }
    length--;
    *interval_length = length;
    reverseArray(array, length);
    return array;
}

int insertionSort(int *nums, int length, int interval) 
{
    int i, j, target, cnt = 0;

    for(i = interval; i < length; i++) {
        j = i - interval;
        target = nums[i];

        while(j >= 0 && nums[j] > target) {
            nums[j + interval] = nums[j];
            j -= interval;
            cnt++;
        }
        nums[j + interval] = target;
    }
    return cnt;
}

int shellSort(int *nums, int length)
{
    int i, cnt = 0, interval_length;
    int *intervals;

    intervals = supplyGArray(length, &interval_length);

    printf("%d\n", interval_length);
    for(i = 0; i < interval_length; i++) {
        printf("%d ", intervals[i]);
        cnt += insertionSort(nums, length, intervals[i]);
    }
    printf("\n");

    return cnt;
}

int main(void) 
{
    int n, i, cnt;
    int *nums;

    scanf("%d", &n);
    nums = malloc(sizeof(int) * n);
    for(i = 0; i < n; i++) {
        scanf("%d", nums + i);
    }
    cnt = shellSort(nums, n);	
    printf("%d\n", cnt);
    dispNumsLn(nums, n);

    return 0;
}

Measured memory_bytes: 4524
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            int a = scn.nextInt();
            int b = scn.nextInt();
            int c = scn.nextInt();
            int d = scn.nextInt();
            int p = scn.nextInt();
            int x = a * p;
            int y = p < c ? b : b + (p - c) * d;
            System.out.println(x < y ? x : y);
        }
    }
}

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

using namespace std;

int n, h[(int)1e5];

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> h[i];
	
	for(int i = n - 1; i >= 0; --i){
		if(h[i-1] > h[i]){
			h[i-1]--;
			if(h[i-1] > h[i]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())
#define AsceSort(a) sort(a.begin(),a.end())

using namespace std;
typedef long long ll;

int main(void) {
	int x1, x2, y1, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int X, Y;
	X = x2 - x1; Y = y2 - y1;
	int x3, y3, x4, y4;
	x3 = x2 - Y; y3 = y2 + X;
	x4 = x1 - Y; y4 = y1 + X;
	cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
	return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf (ll)(1e18)
#define mod 1000000007

int main()
{
    int t=1;
    //cin>>t;

    while( t-- )
    {
        int n,m,x;
        cin>>n>>m>>x;

        int cost[n];
        int skill[n][m];

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

            for( int j=0 ; j<m ; j++ )
                cin>>skill[i][j];
        }

        bool f=1;

        for( int i=0 ; i<m ; i++ )
        {
            int cur=0;
            for( int j=0 ; j<n ; j++ )
            {
                cur+=skill[j][i];
            }
            if( cur<x )
            {
                f=0;
                break;
            }
        }

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

        ll ans=inf;

        for( int i=1 ; i<(1<<n) ; i++ )
        {
            int temp=i;
            ll total[m]={0};
            int idx=0;
            ll cc=0;
            while( temp )
            {
                bool active=temp%2;

                if(active)
                {
                    cc+=cost[idx];
                    for( int j=0 ; j<m ; j++ )
                        total[j]+=skill[idx][j];
                }
                temp/=2;
                idx++;

            }

            bool chk=1;

            for( int j=0 ; j<m ; j++ )
            {
                if( total[j]<x )
                {
                    chk=0;
                    break;
                }
            }

            if( chk )
                ans=min(ans,cc);
        }
        cout<<ans;
    }
    return 0;
}












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

using pii = pair<int, int>;
using ll = long long;

int main() {
    int n, q; cin >> n >> q;
    vector<ll> a(n);
    vector<vector<ll>> sum(n + 1, vector<ll>(2));
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        sum[i + 1] = sum[i];
        sum[i + 1][i & 1] += a[i];
    }
    auto tsum = [&sum] (int l, int r) { // 偶奇を無視した累積和
        return sum[r][0] + sum[r][1] - (sum[l][0] + sum[l][1]);
    };

    vector<pii> qs(q);
    for(int i = 0; i < q; ++i) {
        cin >> qs[i].first;
        qs[i].second = i;
    }
    sort(begin(qs), end(qs));

    int it = n - 1;
    vector<ll> ans(q);
    for(int lp = 0; lp < q; ++lp) {
        const int x = qs[lp].first;
        auto check = [&] (int w) { // 末尾からいくつ取れるか
            auto check2 = [&] (int y) { // 衝突するかどうか
                const int idx = upper_bound(begin(a), end(a), x + y) - begin(a);
                return n - w <= idx;
            };
            int lb = -1, ub = 1'000'000'001;
            while(ub - lb > 1) {
                const int mid = (ub + lb) >> 1;
                (check2(mid) ? ub : lb) = mid;
            }
            const int cnt = upper_bound(begin(a), end(a), x + ub) - lower_bound(begin(a), end(a), x - ub);
            return cnt > w; // cnt > w なら、青木くんがとりすぎ
        };
        while(!check(it)) {
            --it;
        }
        ans[qs[lp].second] = tsum(n - it - 1, n) + sum[max(0, n - 2 * (it + 1))][n % 2 == 0];
    }

    for(int i = 0; i < q; ++i) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 9472
import Control.Applicative

main = do
    getLine
    xs <- map read . lines <$> getContents
    let (_, n, _) = solve (head xs, (-1) * (10 ^ 9), tail xs)
    print n

-- (min, max, rest)
solve :: (Integer, Integer, [Integer]) -> (Integer, Integer, [Integer])
solve (min, max, [])     = (min, max, [])
solve (min, max, (x:xs)) | x < min   = if x - min > max
                                         then solve (x, x - min, xs)
                                         else solve (x, max,     xs)
                         | otherwise = if x - min > max
                                         then solve (min, x - min, xs)
                                         else solve (min, max,     xs)


Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int n;
    cin >> n;
    if (n == 0) cout << 1 << '\n';
    else cout << 0 << '\n';
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define int			long long
#define ll 			long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<int,int>
#define vi          vector<int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define dep(i,a,b)	for(int i=a;i>=b;i--)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  100005

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	rep(i,0,n)cin>>a[i];
	ll ans=0;
	ll prev=a[0];
	rep(i,1,n){
		if(a[i]<prev){
			ans+=prev-a[i];
		}
		else{
			prev=a[i];
		}
	}	
	cout<<ans<<endl;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	while(TESTS--)
	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 5124
s = input()
if s.find("W") == -1 or s.find("B") == -1:
    print(0)
elif len(s) == 1:
    print(2)
else:
    res = 0
    c = s[0]
    for i in range(len(s) - 1):
        if c != s[1+i]:
            c = s[1+i]
            res += 1
    print(res)

Measured memory_bytes: 39408