akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define llin(a) cin >> a
#define llpr(a) cout << a << " "
#define llout(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define M 1000000007
#define N 100005  //check the limits, man
typedef long long int ll;
// read the constraint properly (ll vs int)
int main()
{
    int n;
    in(n);
    n=(n*n*n);
    out(n);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, 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;
  vector<int> Snuke(N, 0);

  rep(i,K) {
    int d; cin >> d;
    rep(i,d) {
      int A; cin>>A;
      Snuke[A-1]++;
    }
  }

  int ans = 0;
  rep(i,N) {
    if(Snuke[i]==0) ++ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3568
class Node(object):
    def __init__(self, a, b):
        self.a = a
        self.b = b
        if a <= 3 and b == 5:
            self.left = None
            self.right = None
        elif a == 5 and b <= 3:
            self.left = None
            self.right = None
        elif (a, b) in ((5, 5), (6, 4), (4, 6)):
            self.left = None
            self.right = None

        else:
            self.left = Node(a+1, b)
            self.right = Node(a, b+1)
    def prints(self):
        print "%d %d" % (self.a, self.b)

def parse(n, a, b, s):
    if n.a == a and n.b == b:
        print s
    else:
        if n.left != None:
            s1 = s +  'A'
            parse(n.left, a, b, s1)
            s2 = s + 'B'
            parse(n.right, a, b, s2)

read = map(int, raw_input().split())
n = Node(0, 0)
st = ""
parse(n, read[0], read[1], st)

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

char input[1025];
int count;
char left[16] = "qwertasdfgzxcvb";
char right[12] = "yuiophjklnm";

int check(char a);

int main(void)
{
    int i, j, now, tmp, len;
    scanf("%s",input);
    while (input[0] != '#') {
        len = strlen(input);
        count = 0;
        now = check(input[0]);
        for (i = 1; i < len; i++) {
            tmp = check(input[i]);
            if (tmp != now) {
                count++;
                now = tmp;
            }
        }
        printf("%d\n",count);
        scanf("%s",input);
    }
    return 0;
}
 
int check(char a)
{
    int i;
    for (i = 0; i < 16; i++) {
        if (a == left[i]) {
            return 1;
        } 
    }
    for (i = 0; i < 12; i++) {
        if (a == right[i]) {
            return -1;
        }
    }
    return 0;
}

Measured memory_bytes: 540
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;

int main(void) {
  int k,s;
  cin >> k >> s;
  int cnt = 0;
  rep(i,k+1)rep(j,k+1){
    if((s-i-j)>=0 && (s-i-j)<=k) cnt++;
  }
  cout << cnt << endl;
    
  
}




Measured memory_bytes: 256
def factorial(n, r, mod=10**9+7):
    a = 1
    for i in range(n, n-r, -1):
        a = a * i % mod
    return a


def power(n, r, mod=10**9+7):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod


def comb(n, k, mod=10**9+7):
    if n < k or k < 0:
        result = 0
    else:
        a = factorial(n, k, mod=mod)
        b = factorial(k, k, mod=mod)
        result = a * power(b, mod-2, mod=mod) % mod
    return result


n, a, b = map(int, input().split())
MOD = 10**9 + 7
ans = power(2, n) - comb(n, a) - comb(n, b) - 1
print(ans%MOD)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rg register
#define ll long long 
inline ll read()
{
    ll x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')
        {
            f=-1;
        }
        c=getchar();
    }
    while(c<='9'&&c>='0')
    {
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
    return x*f;
}
ll a,b;
ll tot;
int main()
{
	a=read();//当前的值 
	b=read();//预期的值
//	start: 
//	if(a==b)
//	{
//		cout<<0;
//	}
//	else if(b==0)
//	{
//		if(a>0)// 5 0==6
//		{
//			cout<<1+a;
//			return 0; 
//		}
//		else//a<0 -1 0==1
//		{
//			cout<<-a;
//			return 0;			
//		}
//	}
//	else if(a==0)
//	{
//		if(b>0)
//		{
//			cout<<b;
//			return 0;
//		}
//		else
//		{
//			cout<<-b+1;
//			return 0;
//		}
//	}
//	else if(a==-b)
//	{
//		cout<<1;
//	}
//	else if(b>0&&a<b&&a>=0)
//	{
//		cout<<b-a;
//	} 
//	else if(b>0&&a>b)
//	{
//		cout<<a-b+2;
//	}
//	else if(b>0&&a<0&&a<b&&-a<b)
//	{
//		cout<<b+a+1;
//	}
//	else if(b>0&&a<0&&a<b&&-a>b)
//	{
//		cout<<-a-b+1;
//	}
//	else 
//	{
//		a=-a;
//		b=-b;
//		goto start;
//	}
//----------------------------------------------------------------------------------	
	if(a==b)
	{
		cout<<0;
		return 0;
	}
	if(b==0)
	{
		if(a>0)// 5 0==6
		{
			cout<<1+a;
			return 0; 
		}
		else//a<0 -1 0==1
		{
			cout<<-a;
			return 0;			
		}
	}
	else if(a==0)
	{
		if(b>0) //0 5==5
		{
			cout<<b;
			return 0;
		}
		else// 0 -5 ==6
		{
			cout<<-b+1;
			return 0;
		}
	}
	else if(b>0)
	{
		if(a>0&&a<b)//3 4 == 1
		{
			cout<<b-a;
			return 0;
		}
		else if(a>0&&a>b)// 4 3==3
		{
			tot++;
			cout<<2+a-b;
			return 0;
		}
		else if(a<0&&-a<b)//-2 3==2
		{
			cout<<b+a+1;
			return 0;
		} 
		else if(a<0&&-a>b)// -3 2==2
		{
			cout<<-a-b+1;
			return 0;
		}
		else if(a<0&&-a==b)//-5 5=1
		{
			cout<<1;
			return 0;
		}
	}
	else if(b<0)
	{
		if(a>0)
		{
			if(-b>a)// 5 -6==2
			{
				cout<<(-b-a)+1;
				return 0;
			}
			else if(-b==a)// 6 -6==1
			{
				cout<<1;
				return 0;
			}
			else //5 -4 ==2
			{
				cout<<a+b+1;
				return 0;
			}
		}
		else //a<0
		{
			if(a>b)//-1 -3 ===3
			{
				cout<<-b+a+2;
				return 0;
			}
			else // a<b -5 -4 ==1
			{
				cout<<-a+b;
				return 0;
			}
		}
	}
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++){
		int j=i*27/25;
		if (j==n) {printf ("%d",i);return 0;}
	}
	puts(":(");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i = n; i < (int) N; i++)
#define p(s)		cout<<(s)<<endl
using namespace std;

int main() {
	int N,T;
	cin>>N>>T;
	int A[100010];
	REP(i,0,N) cin>>A[i];
	int mn=A[0],maxs=0,cnt;
	REP(i,1,N){
		if(A[i]-mn>maxs){
			maxs=A[i]-mn;
			cnt=1;
		}else if(A[i]-mn==maxs){
			cnt++;
		}
		mn=min(mn,A[i]);
	}
	p(cnt);
	return 0;
}


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

long long n,ans,mx;
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>n;
    for (long long i = 0,h; i < n; ++i) {
        cin>>h;
        mx = max(h,mx);
        ans += mx-h;
    }
    cout<<ans;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
    using namespace std;
         
    int main() {
      int N;
      cin >> N;
      vector<string> dataN(N);
      
      for(int i = 0 ; i < N ; i++){
        cin >> dataN.at(i);
      }
      
      int M;
      cin >> M;
      vector<string> dataM(M);
      
      for(int i = 0 ; i < M ; i++){
        cin >> dataM.at(i);
      }
      
      int max = 0;
      
      for(int i = 0 ; i < N ; i++){
        int cnt = 0;
        
        for(int j = 0 ; j < N ; j++){
          if(dataN.at(i) == dataN.at(j)){
            cnt++;
          }
        }
        for(int j = 0 ; j < M ; j++){
          if(dataN.at(i) == dataM.at(j)){
            cnt--;
          }
        }
        
        if(max < cnt){
          max = cnt;
        }
      }
      
      cout << max << endl;
      
    }

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

int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a<=b&&b<=c){cout<<a<<" "<<b<<" "<<c<<endl;
  }
  else if(a<=c&&c<=b){cout<<a<<" "<<c<<" "<<b<<endl;
  }
  else if(b<=a&&a<=c){cout<<b<<" "<<a<<" "<<c<<endl;
  }
  else if(b<=c&&c<=a){cout<<b<<" "<<c<<" "<<a<<endl;
  }
  else if(c<=a&&a<=b){cout<<c<<" "<<a<<" "<<b<<endl;
  }
  else if(c<=b&&b<=a){cout<<c<<" "<<b<<" "<<a<<endl;
  }
}

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

int main()
{
	int H[4][3][10];
	for(int i = 0; i < 4; ++i)
	{
		for(int j = 0; j < 3; ++j)
		{
			for(int k = 0; k < 10; ++k)
			{
				H[i][j][k] = 0;
			}
		}
	}
	
	int N, B, F, R, V;
	cin >>N;
	for(int i = 0; i < N; ++i)
	{
		cin >> B >> F >> R >> V;
		H[B - 1][F - 1][R - 1] += V;
	}
	
	for(int i = 0; i < 4; ++i)
	{
		if(i != 0)
		{
			cout << "####################" << endl;
		}
		
		for(int j = 0; j < 3; ++j)
		{
			for(int k = 0; k < 10; ++k)
			{
				cout << setw(2) << H[i][j][k];
			}
			cout << endl;
		}
	}

    return 0;
}



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

int main() {
	int cnt1 = 0, cnt2 = 0, n, a;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) {
		scanf("%d", &a);
		if(a & 1) cnt1++;
		else cnt2++;
	}
	if(n != 1 && cnt1 & 1) puts("NO");
	else puts("YES");
	return 0;
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <functional>
#include <numeric>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main(void) {
	int S, W;
	cin >> S >> W;

	if (W >= S) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <cmath>
#define ll long long
#define ull unsigned long long
using namespace std;
vector<vector<int>> g;
vector<int> len;
vector<vector<int>> col(2);
vector<int> ans;
vector<int> s;
void yn(bool a){
    if(a){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}

int main(){
 

        int n,m;
        cin>>n>>m;
        if(m%2){
            yn(0);
            
        }else{
            if((m>=(n*2))&&(m<=(n*4))){
                yn(1);
            }else{
                yn(0);
            }
        }
    
    
}


Measured memory_bytes: 3600
def judge(s)
  if s.size % 2 != 0 then
    return false
  end
  
  n = s.size / 2
  
  t1 = s[0..(n - 1)]
  t2 = s[n..(s.size - 1)]
  
  return t1 == t2
end

s = gets.chomp

(2..(s.size - 1)).each do |i|
  t = s[0..s.size - i]
  if judge(t) then
    puts t.size
    break
  end
end

Measured memory_bytes: 1788
#include<cstdio>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
map<pair<int,int>,bool>c;
int x[200005],y[200005],n,h,w,ans=2147483647;
bool check[200005];
vector<int>col[200005];
inline void dfs(int v,int r,bool flag) {
	if(!check[r]) {
		check[r]=true;
		if(col[r].size()) {
			int now=col[r][upper_bound(col[r].begin(),col[r].end(),v)-col[r].begin()]-1;if(now<v) goto loop;
			ans=min(ans,now);
			loop:;
		}
	}
	if(!flag)
		if(v==h||c[make_pair(v+1,r)]==true) return;
		else dfs(v+1,r,true);
	else
		if(r==w||c[make_pair(v,r+1)]==true) dfs(v,r,false);
		else dfs(v,r+1,false);
}
int main()
{
	scanf("%d%d%d",&h,&w,&n);
	for(int i=1;i<=w;++i) col[i].push_back(h+1);
	for(int i=1;i<=n;++i) {scanf("%d%d",&x[i],&y[i]);c[make_pair(x[i],y[i])]=true;col[y[i]].push_back(x[i]);}
	for(int i=1;i<=w;++i) sort(col[i].begin(),col[i].end());
	dfs(1,1,false);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 59008
#include <bits/stdc++.h>
#include <random>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<double, int> d_i;
 
int main() {
	random_device rd;
	mt19937 mt(rd());
	int N, M; cin >> N >> M;
	vector<string> a(N);
	rep(i, N) cin >> a[i];
	rep(t, 100000) {
		vector<vector<bool>> b(M, vector<bool>(M, true));
		rep(j1, M) for (int j2 = j1; j2 < M; j2++)
			rep(i, N) if (a[i][j1] != a[N - 1 - i][j2]) b[j1][j2] = false;
		vector<bool> dp(1<<M);
		dp[0] = true;
		rep(S, 1<<M) if (dp[S])
			rep(j1, M) for (int j2 = j1 + 1; j2 < M; j2++)
				if (!(S>>j1 & 1) && !(S>>j2 & 1) && b[j1][j2])
					dp[S | 1<<j1 | 1<<j2] = true;
		bool ok = false;
		if (M % 2 == 0) ok = dp.back();
		else {
			rep(j, M) if (dp[(1<<M) - 1 - (1<<j)] && b[j][j]) ok = true;
		}
		if (ok) {
			cout << "YES" << endl;
			return 0;
		}
		shuffle(a.begin(), a.end(), mt);
	}
	cout << "NO" << endl;
}


Measured memory_bytes: 256
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    long n = lread();
    // writeln(n);
    auto l = new long[](100);
    l[0] = 2;
    l[1] = 1;
    // writeln(l);
    foreach (i; 2 .. n + 1)
    {
        l[i] = l[i - 1] + l[i - 2];
    }
    writeln(l[n]);
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3644
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N, M;
int s[10], c[10];
int ans[10];

int main() {
    cin >> N >> M;
    rep(i, M) cin >> s[i] >> c[i];
    rep(i, N) ans[i] = -1;

    rep(i, 1000) {
        string str = to_string(i);
        if (N != str.length()) continue;
        bool check = true;
        rep(j, M) {
            int k = s[j] - 1;
            if (str[k] - '0' != c[j]) check = false;
        }
        if (check) {
            cout << str << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3660
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]

for i in range(N):
    a.append(a[i] + A[i])

for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N+1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)


Measured memory_bytes: 47508
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define LINF (ll)1e18
#define INF (int)1e9
struct aaa{aaa(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(10);};}aaaaaaa;
inline void in() {}
template <class Head, class... Tail>
inline void in(Head&& head,Tail&&... tail){
    cin>>head;
    in(move(tail)...);
}
template <class T>
inline void out(T t) {
    cout<<t<<'\n';
}
template <class Head, class... Tail>
inline void out(Head head,Tail... tail){
    cout<<head<<' ';
    out(move(tail)...);
}

int main(){
    int a[3];
    in(a[0],a[1],a[2]);
    sort(a, a+3);
    out(a[2]-a[0]);
}



















Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<string.h>
using namespace std;
#define pb push_back
#define all(v) v. begin(),v. end()
#define  rep(i,n,v) for(i=n;i<v;i++)
#define per(i,n,v) for(i=n;i>v;i--)
#define ff first 
#define ss second 
#define pp pair<ll,ll>
#define ll  long long
#define endl '\n'
void solve()
{
  ll n, a,m=0,b=1, c,k=0, i, j,l=1e9+7;
  string s, r, y;
  cin>>n>>a;
  cout<<max(n+a,max(n*a,n-a));
}
int main()
{
 ios_base::sync_with_stdio(false);
  cin. tie(0);cout. tie(0);
    ll t=1;
  // cin>>t;
    while(t--)
    {
      solve();
    }
    return 0;
}

Measured memory_bytes: 3612
N, M = map(int, input().split())
S = input()
T = input()

def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z

def lcm(m,n):
    return int(m * n /gcd(m,n))

d = gcd(N,M)
l = lcm(N,M)

s = [0 for i in range(0,d)]
t = [0 for i in range(0,d)]

a = int(l/M)
b = int(l/N)

for i in range(0,d):
    s[i] = S[i*a]
    t[i] = T[i*b]

if s == t:
    print(l)
else:
    print(-1)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
using ll = long long; 
using vpii = vector<pair<int, int>>;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep1(i, n) for (int i = 1; i < (int)n; i++)
ll inf = 1e9+7;

ll gcd(ll a, ll b){
  return (b != 0) ? gcd(b, a%b) : a;
}

ll lcm(ll a, ll b){
  return (a/gcd(a,b))*b;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<vector<char>> A(n+1, vector<char>(n+1)), B(m+1, vector<char>(m+1));
  rep(i, n){ rep(j, n) cin >> A[i+1][j+1]; }
  rep(i, m){ rep(j, m) cin >> B[i+1][j+1]; }
  
  rep1(i, n-m+2){
    rep1(j, n-m+2){
      bool can = true;
      rep(k, m){
        rep(l, m){
          if(A[i+k][j+l] != B[k+1][l+1]){can = false; break;}
        }
      }
      if(can){ cout << "Yes" << "\n"; return 0; }
    }
  }
  cout << "No" << "\n";
                                                   
  return 0;
}   

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int n,k,p,ans;
int main(){
	cin>>n>>k;
	for(int i=1,x;i<=n;i++){
		cin>>x;
		if(x==1) p=i;
	}
	int l,r,tmp;
	ans=2*n;
	for(int i=max(1,p-k+1);i<=p;i++){
		l=i-1;
		r=n-(i+k-1);
		tmp=1;
		tmp+=(l+k-2)/(k-1);
		tmp+=(r+k-2)/(k-1);
		ans=min(tmp,ans);
	}
	cout<<ans;
}

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

int main() {
  int N;
  cin >> N;
  
  int upper = N /100, lower = N % 100;
  
  if (upper > 0 && upper <= 12) {
    if (lower > 0 && lower <= 12) {
      cout << "AMBIGUOUS" << endl;
    } else {
      cout << "MMYY" << endl;
    }
  } else {
    if (lower > 0 && lower <= 12) {
      cout << "YYMM" << endl;
    } else {
      cout << "NA" << endl;
    } 
    
  }
  
  
  
}

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

ll vis[100001];
void dfs(vector<ll> v[],int e)
{
	vis[e]=1;
	for(auto itr: v[e])
	{
		if(!vis[itr])
		{
			dfs(v,itr);
		}
	}
}


int main()
{
	string s;
	cin>>s;
	string l(s.length(),'x');
	cout<<l;
	return 0;
}

Measured memory_bytes: 256
from collections import deque

n, l, t = map(int, input().split())
ants = [list(map(int, input().split())) for i in range(n)]

ants_t = [0]*n
count = 0
for i in range(n):
    ant = ants[i]
    if ant[1] == 1:
        c, ant_t = divmod(t + ant[0], l)
    else:
        c, ant_t = divmod(-t + ant[0], l)
    ants_t[i] = ant_t
    count += c
# print(ants_t, count)
ants_d = deque(sorted(ants_t))
# print(ants_d)

ants_d.rotate(-count)
# print(ants_d)
for ant in ants_d:
    print( (ant) % l )


Measured memory_bytes: 70104
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        input: [usize; 2],
    }

    let a = input[0];
    let b = input[1];

    let ans = check(a, b);

    println!("{}", ans);
}

fn check(a: usize, b: usize) -> usize {
    if b % a == 0 {
        return a + b;
    } else {
        return b - a;
    }
}

Measured memory_bytes: 4352
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    X, N = LI()
    P = LI()
    s = set(P)
    diff = inf
    ans_x = -1
    for x in range(-101, 300):
        if x in s:
            continue
        if abs(x-X) < diff:
            diff = abs(x-X)
            ans_x = x
    print(ans_x)





main()



Measured memory_bytes: 78152
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 


signed main(){
  int n,m;cin>>n>>m;int a[100001];
  rep(i,n){
    cin>>a[i];
    a[i] %= m;
  }
  repd(i,1,n){
    a[i] = (a[i] + a[i-1]) % m;
  }
  a[n] = 0;
  sort(a,a+n+1);
  int ans = 0,pre = m,seq = 1;
  rep(i,n+1){
    if(pre != a[i]){
      ans += (seq * (seq-1) / 2);
      pre = a[i];
      seq = 1;
    }else{
      seq++;
    }
  }
  ans += (seq * (seq-1) / 2);
  cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)

ll mod = 1e09;

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

  ll n;
  cin >> n;
  ll a[n];
  REP(i, n) cin >> a[i];

  vector<ll> b;
  ll h = n / 2;
  if(n % 2){
    REPR(i, h + 1) b.pb(a[2 * i]);
    REP(i, h) b.pb(a[2 * i + 1]);
  }
  else{
    REPR(i, h) b.pb(a[2 * i + 1]);
    REP(i, h) b.pb(a[2 * i]);
  }

  REP(i, n) cout << b[i] << " ";

  return 0;
}


Measured memory_bytes: 5488
#include <iostream>
#include <string>
using namespace std;
int main() {
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  cout<<string(ty - sy, 'U')<< string(tx - sx + 1, 'R') << string(ty - sy + 1, 'D') << string(tx - sx + 1, 'L') << 'U';
  cout << string(tx - sx, 'R') << string(ty - sy + 1, 'U') << string(tx - sx + 1, 'L') << string(ty - sy + 1, 'D') << 'R';
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<Z A,Z...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  string s,t;
  cin >> s >> t;
  if(t.substr(0,s.size())==s) pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 3644
// source from https://codeforces.com/contest/787/submission/25744630
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <queue>
#include <functional>
#include <utility>
using namespace std;
const int MAXN = 505050, MAXM = 8080808;
const long long oo = 1020304050607080ll;
class Edge
{
public:
	int to, v, next;
};
Edge e[MAXM];
int head[MAXN], en = 1, numtot;
void insert(int u, int v, int w)
{
	e[++en].to = v;
	e[en].v = w;
	e[en].next = head[u];
	head[u] = en;
}
class Segment_tree
{
public:
	int st, ed, num;
	Segment_tree *l, *r;
	void build(int st_, int ed_)
	{
		st = st_;
		ed = ed_;
		if(st == ed)
		{
			num = st;
			return;
		}
		num = ++numtot;
		l = new Segment_tree();
		l->build(st, (st + ed) >> 1);
		r = new Segment_tree();
		r->build(((st + ed) >> 1) + 1, ed);
	}
	void work(int st_, int ed_, int to, int v, bool rev) const
	{
		if(st >= st_ && ed <= ed_)
		{
			if(rev)
				insert(to, num, v);
			else
				insert(num, to, v);
			return;
		}
		if(l->ed >= st_)
			l->work(st_, ed_, to, v, rev);
		if(r->st <= ed_)
			r->work(st_, ed_, to, v, rev);
	}
	void dfs(bool tp) const
	{
		if(st == ed)
			return;
		if(tp)
		{
			insert(num, l->num, 0);
			insert(num, r->num, 0);
		}
		else
		{
			insert(l->num, num, 0);
			insert(r->num, num, 0);
		}
		l->dfs(tp);
		r->dfs(tp);
	}
}*rt1, *rt2;
int n, qq, s;
long long dist[MAXN];
priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > > q;
void dijkstra()
{
	memset(dist, 63, sizeof(dist));
	q.push(make_pair(dist[s] = 0, s));
	while(!q.empty())
	{
		int now = q.top().second;
		if(dist[now] != q.top().first)
		{
			q.pop();
			continue;
		}
		q.pop();
		for(int i = head[now]; i > 0; i = e[i].next)
			if(dist[e[i].to] > dist[now] + e[i].v)
				q.push(make_pair(dist[e[i].to] = dist[now] + e[i].v, e[i].to));
	}
}
int main()
{
	scanf("%d%d", &n, &qq); s = 1;
	memset(head, -1, sizeof(head));
	numtot = n;
	rt1 = new Segment_tree();
	rt1->build(1, n);
	rt1->dfs(true);
	rt2 = new Segment_tree();
	rt2->build(1, n);
	rt2->dfs(false);
	for(int i = 1; i <= qq; i++)
	{
		int t = 3, v, l, r, w;
		if(t == 1)
		{
			scanf("%d%d%d", &v, &l, &w);
			insert(v, l, w);
		}
		else if(t == 2)
		{
			scanf("%d%d%d%d", &v, &l, &r, &w);
			rt1->work(l, r, v, w, true);
		}
		else if(t == 3)
		{
			scanf("%d%d%d", &l, &r, &w);
			rt2->work(l, r, r, w, false);
		}
	}
	dijkstra();
	for(int i = n; i <= n; i++)
		printf("%lld ", dist[i] > oo ? -1 : dist[i]);
	return 0;
}
 


Measured memory_bytes: 47992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int,int> P;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 1000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
template<class T> void chmin(T& a,const T& b){if(a>b)a=b;}
template<class T> void chmax(T& a,const T& b){if(a<b)a=b;}
int N,K;
int a[100100];
vector<int> g[100100];
P dp[100100];
void rec(int v){
	P ret = P(0,0);
	for(int i=0;i<g[v].size();i++){
		int u = g[v][i];
		rec(u);
		ret.fi += dp[u].fi;
		ret.sec = max(ret.sec,dp[u].sec+1);
	}
	if(a[v]!=0&&ret.sec==K-1){
		ret.fi++;
		ret.sec = -1;
	}
	dp[v]=ret;
	return;
}
int main(){
	cin >> N >> K;
	for(int i=0;i<N;i++){
		cin >> a[i];
		a[i]--;
		if(i>0){
			g[a[i]].pb(i);
		}
	}
	int ans = 0;
	if(a[0]!=0)ans++;
	a[0]=0;
	rec(0);
	ans += dp[0].fi;
	cout << ans << endl;
	/*for(int i=0;i<N;i++){
		cout << i << ' ' << dp[i].fi << ' ' << dp[i].sec << endl;
	}*/
	return 0;
}

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> b(n-1);
  for(int i=0;i<n-1;i++){
    cin>>b[i];
  }
  vector<int> a(n);
  a[0]=b[0];
  a[n-1]=b[n-2];
  for(int i=1;i<n-1;i++){
    a[i]=min(b[i-1],b[i]);
  }
  int sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod = 1e9+7;
const int maxn = 3e5+10;
const int inf = 0x3f3f3f3f;
ll qpow(ll a,int b) {
    ll ans=1;
    while(b) {
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n;
    cin>>n;
    ll sum0=qpow(10,n),sum9=qpow(9,n),sum8=qpow(8,n);
    sum0=sum0-2*sum9+sum8;
    sum0%=mod;
    cout<<(sum0+mod)%mod<<'\n';
    return 0;
}


Measured memory_bytes: 3648
n, k = gets.split.map(&:to_i)
xs = gets.split.map(&:to_i)

ans = 10**18
(n - k + 1).times do |i|
  xl = xs[i]
  xr = xs[i + k - 1]

  lr = xl.abs + (xr - xl).abs
  rl = xr.abs + (xl - xr).abs

  t = [lr, rl].min
  ans = t if t <= ans
end
puts ans


Measured memory_bytes: 11012
#include <stdio.h>
#include <math.h>

int main(void){
	float a,b,c,d,e;int k;
	
	scanf("%f %f %f %f %f",&a,&b,&c,&d,&e);
	b=ceil(b/d);c=ceil(c/e);
	if(b>c){
		a-=b;
	}
	else{
		a-=c;
	}
	
	k=a;
	printf("%d\n",k);
	return 0;
}
	

Measured memory_bytes: 624
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int a[310][310];

vector<int> b[310];
int idx[310];
bool rem[310];

bool check(int k) {
    memset(idx, 0, sizeof(idx));
    memset(rem, true, sizeof(rem));
    vector<int> s;
    for (int i = 0; i < m; i++) b[i].clear();
    for (int i = 0; i < n; i++) {
        b[a[i][0]].push_back(i);
    }
    while (true) {
        s.clear();
        for (int i = 0; i < m; i++) {
            if (b[i].size() > k) {
                s.push_back(i);
                rem[i] = false;
            }
        }
        if (s.size() == 0) return true;
        for (int i = 0; i < s.size(); i++) {
            int v = s[i];
            for (int j = 0; j < b[v].size(); j++) {
                int w = b[v][j];
                while (idx[w] < m && !rem[a[w][idx[w]]]) idx[w]++;
                if (idx[w] >= m) return false;
                b[a[w][idx[w]]].push_back(w);
            }
            b[v].clear();
        }
    }
    return false;
}

int solve() {
    int lb = 0, ub = n;
    while (ub - lb > 1) {
        int mid = (lb + ub) / 2;
        if (check(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            cin >> a[i][j];
            a[i][j]--;
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>

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

int main(void){
    int A;
    int B;
    cin >> A >> B;
    if(A <= 8 && B <= 8){
        cout << "Yay!" << endl;
    }else{
        cout << ":(" << endl;        
    }

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <typeinfo>
#include <list>
#include <queue>
#include <stack>
#include <limits.h>
#include <unordered_set>
#include <map>
#include <cstring>

using namespace std;

typedef long long ll;

int mod = 1e9 + 7;

void Solve(vector<pair<int, int> > A, int N) {
    vector<int> dp(N + 1, -1);
    dp[0] = 0;
    vector<vector<int> > record(N + 1);
    int n = A.size();
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= N; j++) {
            if (j >= A[i].second && dp[j - A[i].second] != -1) {
                dp[j] = max(dp[j], dp[j - A[i].second] + 1);
            }
        }
    }
    int m = dp[N];
    for (int i = 0; i < m; i++) {
        for (int j = n - 1; j >= 0; j--) {
            if (N >= A[j].second && dp[N - A[j].second] == dp[N] - 1) {
                cout << A[j].first;
                N -= A[j].second;
                break;
            }
        }
    }
}


int main() {
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > A(M);
    int tmp[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    for (int i = 0; i < M; i++) {
        int f;
        cin >> f;
        A[i] = {f, tmp[f]};
    }
    sort(A.begin(), A.end());
    Solve(A, N);
    return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N,ans=0;
  cin>>N;
  int A[N];
  REP(i,N) cin>>A[i];
  
  for(int i=1; i<N; ++i){
    if(A[i]==A[i-1]){
      ans++;
      A[i]=1000;
    }
  }
  
  co(ans);
  return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n,sizeof(int));
  int i;
  for(i=0;i<n;i++) scanf("%d",a+i);
  for(i=0;i<n;i++){
    if(a[i]%2==1) break;
  }
  printf("%s\n",i<n?"first":"second");
}

int main(void){
  run();
  return 0;
}


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

void show_array(vector<int> &arr){
    for(int i=0; i<arr.size() ; i++) cout << arr.at(i) << " ";
    cout << endl ;
}

void merge(vector<int> &arr,int left,int mid,int right,int &count){
    int n1 = mid - left;
    int n2 = right - mid;
    vector<int> left_array(n1);
    vector<int> right_array(n2);
    for(int i=0; i<n1; i++){
        //cout << left + i << endl;
        left_array.at(i) = arr.at(left + i);
    }
    for(int i=0; i<n2; i++){
        //cout << right + i << endl;
        right_array.at(i) = arr.at(mid + i);
    }
    int i=0, j=0;
    left_array.push_back(2147483647);
    right_array.push_back(2147483647);
    for(int k=left; k<right; k++){
        count++;
        if (left_array.at(i) <= right_array.at(j)){
            arr.at(k) = left_array.at(i);
            i++;
        }else{
            arr.at(k) = right_array.at(j);
            j++;
        }
    }
}

void merge_sort(vector<int> &arr, int left, int right,int &count){
    if(left + 1 < right){
        int mid = (left + right) / 2;
        merge_sort(arr,left,mid,count);
        merge_sort(arr,mid,right,count);
        merge(arr,left,mid,right,count);
        //show_array(arr);
    }
}

int main(){
    int n;
    cin >> n;
    vector<int> array(n);
    for(int i=0; i<n; i++) cin >> array.at(i);
    int count=0;
    merge_sort(array,0,n,count);
    for(int i=0; i<n; i++) {
        if(i != n-1){
            cout << array.at(i) << " ";
        }else{
            cout << array.at(i);
        }
    }
        
    cout << endl << count << endl;
}


Measured memory_bytes: 8684
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
#include <stdio.h>
#include <bits/stdc++.h>
 
using namespace std;
 
#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;
  
#define pb push_back
#define mp make_pair
#define in insert
#define f first
#define s second
#define ll long long
#define ld long double
  
const int mod = 1e9 + 7;
const int N = 2e5 + 7;
const int inf = 2e9;
const ll INF = 1e18;

int a[N], dp[N];

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	// freopen("*.in", "r", stdin);freopen("*.out", "w", stdout);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	dp[1] = 0;
	dp[2] = abs(a[2] - a[1]);
	for(int i = 3; i <= n + 1; i++) {
		dp[i] = min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
	}
	cout << dp[n];
}

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

const std::string YES = "YES";
const std::string NO = "NO";

void solve(std::array<unsigned, 3>& a)
{
    std::sort(a.begin(), a.end());
    std::cout << (a[0] == 5 && a[1] == 5 && a[2] == 7 ? YES : NO) << '\n';
}

int main()
{
    std::array<unsigned, 3> a;
    std::cin >> a[0] >> a[1] >> a[2];
    solve(a);
    return 0;
}



Measured memory_bytes: 3636
import sys

def main():
    tmp = input().replace('\n','').split(' ')
    n = int(tmp[0])
    r = int(tmp[1])
    if n >= 10:
        print(r)
    else:
        res = r + 100 * (10-n)
        print(res)
if __name__ == '__main__':
    input = sys.stdin.readline
    main()

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

using namespace std;

int main()
{
    long int N, W;
    long long d[2][100020], w[102], v[102];

    cin >> N >> W;

    long int sv = 0;

    for(int i = 0; i < N; i++)
    {
        cin >> w[i] >> v[i];
        sv += v[i];
    }

     for(int j = 0; j <= sv; j++)
     {
         d[0][j] = -1;
         d[1][j] = -1;
     }

    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j <= sv; j++)
        {
            
            if(j == v[i])
              {
                if(d[i%2][j]==-1)
                  d[i%2][j] = w[i];  
                else
                  d[i%2][j] = min(w[i], d[(i+1)%2][j]);
              }
            else
            { 
                if(j <= v[i])
                    d[i%2][j] = d[!(i%2)][j];
                else
                {
                    if(d[!(i%2)][j-v[i]] == -1 && d[!(i%2)][j] == -1)
                        d[i%2][j] = -1;
                    else if(d[!(i%2)][j-v[i]] != -1 && d[!(i%2)][j] == -1)
                        d[i%2][j] = d[!(i%2)][j-v[i]] + w[i];
                    else if(d[!(i%2)][j-v[i]] == -1 && d[!(i%2)][j] != -1)
                        d[i%2][j] = d[!(i%2)][j];
                    else
                    {
                    d[i%2][j] = min(d[!(i%2)][j-v[i]] + w[i], d[!(i%2)][j]);
                    }
                    
                }          
            }
        }

        //  for(int j = 0; j <= sv; j++)
        //      cout << d[i%2][j] << " ";
        // cout << endl;
    }
   // cout << "SV : " << sv << " END ";
   long int r = 0;
    for(int q = sv; q > 0; q--)
    {
        if(d[(N-1)%2][q] <= W && d[(N-1)%2][q] != -1)
        {
            r = q; 
            break;
        }
    }
    cout << r;

    return 0;
}


Measured memory_bytes: 1792
void main() {
    string s = readln.chomp;
    long k = readln.chomp.to!int;
    auto g = s.group.array;
    long ans;
    if (g.length == 1) {
        ans = k * g[0][1].to!long / 2;
    } else {
        foreach (x; g) {
            ans += x[1] / 2;
        }
        ans *= k;
        if (s[0] == s[$-1]) {
            long tmp = (g[0][1] + g[$-1][1]) / 2;
            tmp -= g[0][1] / 2 + g[$-1][1] / 2;
            ans += (k - 1) * tmp;
        }
    }
    ans.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.container;
import std.typecons;

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

void insert(int);
int heapExtractMax(void);
void heapIncreaseKey(int); 
void maxHeapify(int i);
int parentNode(int i);
int leftChild(int i);
int rightChild(int i);

int A[2000001];
int heap_size;

main(){

  int i, key;
  char com[8];

  while(scanf("%s",com), strcmp(com,"end")){
    if(com[0]=='i'){
      scanf("%d",&key);
      insert(key);
    }
    if(com[0]=='e'){
      printf("%d\n",heapExtractMax());
    }
  }

  return 0;

}

void insert(int key){

  heap_size++;
  A[heap_size] = -1;
  heapIncreaseKey(key);

}

void heapIncreaseKey(int key){

  int i = heap_size, tmp;

  if(key < A[i]){
    printf("Error ??属????????????????????即????????????????属???????");
    return;
  }
  A[i] = key;
  while(i > 1 && A[parentNode(i)] < A[i]){
    tmp = A[parentNode(i)];
    A[parentNode(i)] = A[i];
    A[i] = tmp;
    i = parentNode(i);
  }

}

int heapExtractMax(void){

  int max;
  if(heap_size < 1){
    printf("Error ???????????蔵??????????????????");
    return;
  }
  max = A[1];
  A[1] = A[heap_size];
  heap_size--;
  maxHeapify(1);
  return max;

}
 
void maxHeapify(int i){
    int l = leftChild(i);
    int r = rightChild(i);
    int largest, tmp;
     
    if(l <= heap_size && A[l] > A[i]){
        largest = l;    
    }else{
        largest = i;
    }
    if(r <= heap_size && A[r] > A[largest]){
        largest = r;    
    }
    if(largest != i){
        tmp = A[i];
        A[i] = A[largest];
        A[largest] = tmp;
        maxHeapify(largest);
    }
}

int parentNode(int i){
    return (int)i/2;
}
 
int leftChild(int i){
    return 2*i;
}
 
int rightChild(int i){
    return 2*i+1;
}

Measured memory_bytes: 4336