akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[3003],dp[3009][3009][2];

ll solve(ll l,ll r,bool turn){
   if(l>r)
        return 0;
    ll &ret=dp[l][r][turn];
    if(ret!=-1)
        return ret;
    if(!turn)
        ret=max(solve(l+1,r,!turn)+a[l],a[r]+solve(l,r-1,!turn));

    else
        ret=min(solve(l+1,r,!turn),solve(l,r-1,!turn));

    return ret;
}
int main(){
    ll n,sum=0;
    cin>>n;
    for(ll i=1;i<=n;i++)
        cin>>a[i],sum+=a[i];

    memset(dp,-1,sizeof(dp));
    ll ans=solve(1,n,0);
    cout<<ans-(sum-ans)<<endl;
}

Measured memory_bytes: 141824
#include <iostream>
#include <vector>
using namespace std;
static const int tbl[] = {10, 50, 100, 500};

vector<int> solve(int n)
{
  vector<int> v(4);
  for (int i = 3; i >= 0; i--) {
    v[i] = n / tbl[i];
    n %= tbl[i];
  }
  return v;
}

int main()
{
  bool first = true;
  int N;
  while (cin >> N && N != 0) {
    vector<int> v(4);
    int s = 0;
    for (int i = 0; i < 4; i++) {
      cin >> v[i];
      s += v[i] * tbl[i];
    }

    const vector<int> w = solve(s - N);
    if (!first) {
      cout << endl;
    }
    for (int i = 0; i < 4; i++) {
      if (v[i] > w[i]) {
        cout << tbl[i] << ' ' << v[i] - w[i] << endl;
      }
    }
    first = false;
  }
  return 0;
}

Measured memory_bytes: 904
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1e+9;

int main(){
    int n, m;
    cin >> n >> m;
    double a[100];
    int sum = 0;
    for (int i = 0; i < n;i++){
        cin >> a[i];
        sum += a[i];
    }
    sort(a, a + n, greater<int>());
    for (int i = 0; i < m;i++){
        if(a[i] < sum/(4*(double)m)){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long C = sc.nextLong();
        long K = sc.nextLong();
        long ans;
        if(K%2==0) ans = A-B;
        else ans = B-A;
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
 
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()
#define all(a) (a).begin(),(a).end()
 
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
 
const D EPS = 1e-8;
const D PI = acos(-1);
 
inline D dot(P x, P y){return real(conj(x)*y);}
 
inline D cross(P x, P y){return imag(conj(x)*y);}
 
//for line(segment)
inline int ccw(P a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;   //counter clockwise
  if (cross(b,c)<-EPS) return -1; //clockwise
  if (dot(b, c)<-EPS) return 2;   //c--a--b on line
  if (abs(b)+EPS<abs(c)) return -2;   //a--b--c on line
  return 0;                       //on segment
}
 
inline bool para(L a,L b){return abs(cross(a.fs-a.sc,b.fs-b.sc))<EPS;}
 
inline P line_cp(L a,L b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}
 
inline bool is_cp(L a,L b){
  if(ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    if(ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0)return true;
  return false;
}
 
int main(){
  int n,m;
  cin >> n >> m;
 
  vector<Poly> vp(n);
  rep(i,n){
    int l; cin >> l;
    rep(j,l){
      int x,y; cin >> x >> y;
      vp[i].push_back( P(x,y) );
    }
  }
 
  vector<P> h(m);
  vector<L> vl;
  rep(i,m){
    int x,y; cin >> x >> y;
    h[i] = P(x,y);
 
    rep(j,n){
      for(auto x : vp[j]) vl.push_back( L(h[i], x) );
    }
  }
 
  vector<P> can;
  rep(i,m) can.push_back( h[i] );
  rep(i,vl.size()){
    rep(j,i){
      if( para(vl[i], vl[j]) ) continue;
      can.push_back( line_cp(vl[i], vl[j]) );
    }
  }
 
  int ans = 0;
  for(auto x : can){
    int tmp = 0;
    rep(i,m){
      if( EQ(h[i], x) ) tmp++;
      else{
	bool ok = true;
	L see = L(h[i],x);
	rep(j,n){
	  rep(k,vp[j].size()){
	    L edge = L(vp[j][k], vp[j][(k+1)%vp[j].size()]);
	    if( is_cp(see, edge) ){
	      P cp = line_cp(see, edge);
	      if( !EQ(cp, edge.first) && !EQ(cp, edge.second) && !EQ(cp, x) && !EQ(cp, h[i]) ) ok = false;
	    }
	    if(!ok) break;
	  }
	  if(!ok) break;
	}
	if(ok) tmp++;
      }
    }
    ans = max(ans, tmp);
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  int n;
  cin >> n;
  char arr[n];
  for(int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  string ret = "";
  for(int i = 0; i < n; i++) {
  	ret = ret + arr[i];
    while(i + 1 < n && arr[i] == arr[i + 1]) {
      i++;
    }
  }
  
  cout << ret.length();
  
  return 0;
}

Measured memory_bytes: 840
#include<bits/stdc++.h>
using namespace std;
pair<int,int> pii;
vector<string> vec;
map<string,int> mp;
int main()
{
  long long n,cnt=0;
  char s[100];
  cin>>n;

  for(int i=0; i<n; i++){
    cin>>s;
    sort(s,s+10);
    vec.push_back(s);
  }
  sort(vec.begin(),vec.end());
  //  vec.erase(unique(vec.begin(),vec.end()),vec.end());

  for(int i=0; i<vec.size(); i++){
    cnt+=mp[vec[i]]; 
    mp[vec[i]]++;
  }
  cout<<cnt<<'\n';

  return 0;
}


Measured memory_bytes: 12020
from itertools import product
n = int(input())
f = [list(map(int, input().split())) for _ in range(n)]
p = [list(map(int, input().split())) for _ in range(n)]
ans = -float('inf')
for v in product([0, 1], repeat=10):
    if v.count(1) == 0:
        continue
    tmp = 0
    for i in range(n):
        c = 0
        for j in range(10):
            if v[j] == 1 and f[i][j] == 1:
                c += 1
        tmp += p[i][c]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#include <utility>
using namespace std;

int index(const vector<int> &xs, int x){
	return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
}

int main(){
	int w, h, n;
	
	int dx[] = {-1, 0, 1, 0};
	int dy[] = {0, -1, 0, 1};
	
	while( scanf("%d%d%d", &w, &h, &n) == 3 ){
		vector<int> xs, ys;
		xs.reserve(3000);
		ys.reserve(3000);
		
		vector<int> x1(n), x2, y1, y2;
		x2 = y1 = y2 = x1;

		xs.push_back(w - 1);
		ys.push_back(h - 1);
		
		for(int i = 0; i < n; ++i){
			scanf("%d%d%d%d", &x1[i], &y1[i], &x2[i], &y2[i]);
			--x2[i];
			--y2[i];
			
			xs.push_back(x1[i]);
			ys.push_back(y1[i]);
			if( x1[i] > 0 ){ xs.push_back(x1[i] - 1); }
			if( y1[i] > 0 ){ ys.push_back(y1[i] - 1); }
			
			xs.push_back(x2[i]);
			ys.push_back(y2[i]);
		}
		
		sort(xs.begin(), xs.end());
		sort(ys.begin(), ys.end());
		xs.erase( unique(xs.begin(), xs.end()), xs.end());
		ys.erase( unique(ys.begin(), ys.end()), ys.end());

		vector<vector<char> > clr(xs.size(), vector<char>(ys.size()) );
		for(int i = 0; i < n; ++i){
			x1[i] = index(xs, x1[i]);
			x2[i] = index(xs, x2[i]);
			y1[i] = index(ys, y1[i]);
			y2[i] = index(ys, y2[i]);
			
			for(int j = x1[i]; j <= x2[i]; ++j)
			for(int k = y1[i]; k <= y2[i]; ++k){
				clr[j][k] = 1;
			}
		}

		int ans = 0;
		for(int i = 0; i < xs.size(); ++i)
		for(int j = 0; j < ys.size(); ++j){
			if( clr[i][j] == 0 ){
				++ans;
				clr[i][j] = 2;
				
				queue<pair<int,int> > q;
				q.push( make_pair(i, j) );
				while( !q.empty() ){
					for(int k = 0; k < 4; ++k){
						int x = q.front().first + dx[k];
						int y = q.front().second + dy[k];
						
						if( x >= 0 && x < xs.size() )
						if( y >= 0 && y < ys.size() )
						if( clr[x][y] == 0 ){
							clr[x][y] = 1;
							q.push( make_pair(x, y) );
						}
					}
					
					q.pop();
				}
			}
		}
		
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 1532
loop {
    n, m = gets.split.map &:to_i
    break if n == 0
    road = (1..n).map{ gets.split.map &:to_i }
    road.sort_by!(&:last).reverse!
    while !road.empty?
        if road[0][0] > m
            road[0][0] -= m
            break
        else
            m -= road[0][0]
            road.shift
        end
    end
    p road.map{|d, q| d * q}.inject(0, &:+)
}

Measured memory_bytes: 6940
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    writeln(-lread() + (2 * lread));
}


Measured memory_bytes: 256
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <bitset>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<pi, null_type, less<pi>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // BEFORE SUBMIT DON'T FORGET TO UNCOMMENT THIS
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();

    vector<vector<int>> dp(n+5, vector<int>(m+5));
    for(int i = 1; i <= n; ++i)
    {
        char charS = s[i-1];
        for(int j = 1; j <= m; ++j)
        {
            char charT = t[j-1];
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(charS == charT) dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
        }
    }

    string ans = "";
    int curri = n, currj = m;
    while(curri > 0 && currj > 0)
    {
        if(s[curri-1] == t[currj-1] && dp[curri][currj] == dp[curri-1][currj-1]+1)
        {
            ans += s[curri-1];
            --curri; --currj;
        }
        else if(dp[curri][currj] == dp[curri-1][currj])
        {
            --curri;
        }
        else
        {
            --currj;
        }
    }

    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0; 
}


Measured memory_bytes: 35712
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
using namespace std;


int main() {
	long long int n, k, h, a[200005], b[200005] = {0,1},result = 0, cou = 1,num=1;
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = n-1; i >=0; i-=2) {
		cout << a[i]<<" ";
	}
	if (n % 2 == 1) {
		for (int i = 1; i < n; i += 2) {
			cout << a[i] << " ";
		}
	}
	else {
		for (int i = 0; i < n; i += 2) {
			cout << a[i] << " ";
		}
	}
}



Measured memory_bytes: 3712
import sys
input = sys.stdin.readline
from collections import deque
from collections import Counter
def main():
    # 入力
    n, x, y = map(int, input().split())
    x -= 1
    y -= 1

    # 処理
    dis = deque()
    for i1 in range(n):
        if x < i1:
            right = i1 + 1
            while right < n:
                dis_now = min(right - i1, (i1 - x + abs(right - y) + 1))
                dis.append(dis_now)
                right += 1
        else:
            right = i1 + 1
            while right < n:
                if right < y:
                    dis_now = min(right - i1,(x - i1 + abs(y - right) + 1))
                    dis.append(dis_now)
                else:
                    dis.append(right - i1 - (y - x) + 1)
                right += 1
    dis_c = Counter(dis)
    dis_list = [0] * (n - 1)
    for i2 in range(1, n):
        dis_list[i2 - 1] = dis_c[i2]

    # 出力

    for edis in dis_list:
        print(edis)

if __name__ == '__main__':
    main()


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

using namespace std;
double a[55];
double Ans = 0;

int main()
{
    int n;
    cin >> n;
    for(int i = 0;i<n;i++)  cin >> a[i];
    sort(a , a + n);
    Ans = a[0];
    for(int i = 1;i<n;i++){
        Ans=(Ans + a[i])/2;
    }
    cout << setprecision(20) << fixed << Ans;
    return 0;
}


Measured memory_bytes: 256
def main():
    N,M = map(int,input().split())
    A = [int(i) for i in input().split()]
    A.sort(reverse=True)
    S = sum(A)
    border = S / (4 * M)
    flag = True
    for i in range(M):
        if border > A[i]:
            flag = False
    if flag:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n;
int a[20000];
int ans[101][101];
    
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  int h,w;cin>>h>>w;
  cin>>n;
  int nowi=0,nowj=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  bool flag=0;
  for(int i=0;i<n;i++){
    int j=0;
    while(j<a[i]){
      if(nowi<h && nowi>=0 && !flag){
        ans[nowi][nowj]=i+1;
        nowi++;
      }else if(nowi<h && nowi>=0 && flag){
        ans[nowi][nowj]=i+1;
        nowi--;
      }else if(!flag){
        nowi=h-1;
        nowj++;
        ans[nowi][nowj]=i+1;
        flag=1;
        nowi--;
      }else {
        nowi=0;
        nowj++;
        ans[nowi][nowj]=i+1;
        flag=0;
        nowi++;
      }
      j++;
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<ans[i][j];
      if(j!=w-1)cout<<" ";
    }
    cout<<"\n";
  }
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a="abcdefghijklmnopqrstuvwxyz.?! ";
	string b;
	while(cin>>b){
		string f="";
		if(b.length()%2==1) {
			cout<<"NA"<<endl;
			goto stop;
		}
		for(int i=0;i<b.length();i+=2){
			int c,d;
			c=(int)b[i]-'0';
			d=(int)b[i+1]-'0';
			if(c>6||d>5||c<1||d<1) {
				cout<<"NA"<<endl;
				goto stop;
			}
			c--;
			int e=c*5+d;
			f+=a[e-1];
		}
		cout<<f<<endl;
		stop:;
	}
}

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

const int M = 2e5 + 100;
int main () {
    char s[M];
    while (scanf("%s", s) == 1) {
        int n = strlen(s);
        for (int i = 0; i < n; i++) if (s[i] == '?') s[i] = 'D';
        printf("%s\n", s);
    }
}



Measured memory_bytes: 3996
#include<bits/stdc++.h>//---
using namespace std;
const int MAX_n=2e5;
int n;
int sum;//___
// bool yes=0;
// bool finished[MAX_n+10]={0};
struct aset{int a,b;};//---
aset tto[MAX_n+10];//___
bool comp(aset a,aset b)
{
    return a.b<b.b;
}
// void dfs(int ii,int time)
// {
//     if(yes) return;
//     if(ii>n)
//     {
//         yes=1;
//         return;
//     }
//     for(int i=0;i<n;i++)
//     {
//         if(!finished[i])
//         {
//             if(time+tto[i].a>tto[i].b)  continue;
//             finished[i]=1;
//             dfs(ii+1,time+tto[i].a);
//             finished[i]=0;
//         }
//     }
//     return;
// }
int main()//---
{
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>tto[i].a>>tto[i].b;
    }//___
    // dfs(1,0);
    // if(yes) cout<<"Yes";
    // else    cout<<"No";
    sort(tto,tto+n,comp);
    for(int i=0;i<n;i++)
    {
        sum+=tto[i].a;
    }
    for(int i=n;i>0;i--)
    {
        sum-=tto[i].a;
        if(sum>tto[i-1].b)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<bitset>
int main()
{
	const int N=10001;
	std::bitset<N>p;
	p.set();
	int i,j,x,r;
	p[0]=p[1]=0;
	for(i=2;i<N/2;++i)if(p[i])for(j=i*2;j<N;j+=i)p[j]=0;
	while(scanf("%d",&x)>0)
	{
		for(r=i=0;i<x;++i)if(p[i+1]&&p[x-i])++r;
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 0
l=[]
for i in range(5):
    l.append(int(input()))
tl=[]
for i in range(5):
    tl.append(l[i]%10)
nl=[]
for i in range(5):
    if l[i]%10==0:
        nl.append(l[i])
    else:
        nl.append((l[i]//10+1)*10)
ctr=0
a=tl[:]
a.sort()
for i in range(5):
    if a[i]>0:
        ctr=a[i]
        break
if a==[0,0,0,0,0]:
    print(sum(nl))
else:
    print(sum(nl)-10+ctr)


Measured memory_bytes: 3064
s=list(input())
t=[]
k=int(input())
n=len(s)
for i in range(n):
    t.append(s[i])
count=0
for i in range(1,n):
    if s[i]==s[i-1]:
        count+=1
        s[i]="!"
if s[0]==s[n-1]:
    t[0]="!"
    cnt=1
    for i in range(1,n):
        if t[i]==t[i-1]:
            cnt+=1
            t[i]="!"
    if cnt==count:
        print(count*k)
    elif t[0]==t[n-1]:
        print(cnt*(k//2)+count*(k-k//2))
    else:
        print(count+cnt*(k-1))
else:
    print(count*k)

Measured memory_bytes: 38256
N,M = map(int,input().split())
S = [1 for i in range(N)]
SS = 0
H = list(map(int,input().split()))
A = [0 for i in range(M)]
B = [0 for i in range(M)]
for i in range(M):
    A[i],B[i] = map(int,input().split())
for i in range(M):
    if H[A[i]-1] < H[B[i]-1]:
        S[A[i]-1] = 0
    elif H[A[i]-1] > H[B[i]-1]:
        S[B[i]-1] = 0
    else:
        S[A[i]-1] = 0
        S[B[i]-1] = 0
for i in range(N):
    if S[i] == 1:
        SS += 1
print(SS)

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



  int main(){
    int n;
    cin >> n;
    vector<int> vec(250);
    for(int i=1;i<=n;i++){
      cin>> vec[i];
    }

    for(int i=1;i<= n ; i++){
      cout<<"node "<<i<<": "<<"key = "<<vec[i]<<", ";
      if(i > 1){
      cout<<"parent key = "<<vec[i/2]<<", ";
      }
      if(2*i <= n){
      cout<<"left key = "<<vec[2*i]<<", ";
      }
      if(2*i+1 <= n){
        cout<<"right key = "<<vec[2*i+1]<<", ";
      }
     cout<<endl;
    }
    return 0;
  }



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

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)
#define deb(x)     cout << #x << " = "<<x<<endl

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)

int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 200005;


ll gcd(ll  a , ll b) {
	return (b == 0) ? a : gcd(b, a % b);
}
ll binpow(ll a, ll b) {
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a;
		a = a * a;
		b >>= 1;
	}
	return res;
}
ll powmod(ll a, ll b, ll m) {
	a %= m;
	ll res = 1;
	while (b > 0) {
		if (b & 1)
			res = res * a % m;
		a = a * a % m;
		b >>= 1;
	}
	return res;
}
ll modinv(ll n, ll p)
{
	return powmod(n, MOD - 2, MOD);
}
void max_self(ll &a, ll b) {
	a = max(a, b);
}
bool is_ap(vl v, int n) {
	ll d = v[1] - v[0];
	F0R(i, n) {
		if (v[i] != v[0] + i * d)
			return false;
	}
	return true;
}


int main(int argc, char const *argv[])
{
	// two magical lines to speed up IO
	cin.tie(0);
	ios_base::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif
	string S;
	cin >> S;
	int cntr;
	if (S[0] == 'R')
		cntr = 1;
	else
		cntr = 0;
	if (S[1] == 'R')
		cntr++;
	if (S[2] == S[1] && S[2] == 'R')
		cntr++;
	else if (S[2] == 'R')
		cntr = 1;
	cout << cntr << endl;
}




Measured memory_bytes: 3660
def resolve():
    S = input()
    T = input()
    s_n = len(S)
    t_n = len(T)

    ans = 1 << 60
    for i in range(s_n - t_n + 1):
        cnt = 0
        for j in range(t_n):
            if S[i + j] != T[j]:
                cnt += 1
        ans = min(ans, cnt)

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9112
#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 << 50;
const int NIL = -1;
const int MAX = 200005;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    int a, b;
    vector<bool> fromOne(N+1), fromN(N+1);
    for (int i = 0; i < M; i++) {
        cin >> a >> b;
        if (b < a) swap(a, b);
        if (a == 1) fromOne[b] = true;
        if (b == N) fromN[a] = true;
    }

    for (int i = 2; i < N+1; i++) {
        if (fromOne[i] && fromN[i]) {
            cout << "POSSIBLE" << '\n';
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << '\n';
}


Measured memory_bytes: 256
import sys
 
stdin = sys.stdin

mod = 1000000007
inf = 1 << 60
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n, x = na()
a = na()

def gcd(m, n):
    if n == 0:
        return m
    return gcd(n, m % n)

ans = abs(a[0] - x)
for i in range(n):
    ans = gcd(ans, abs(a[i] - x))

print(ans)

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

#define N 1000100

char s[N];

int n, z, p[N], zp[N], zm[N];

int calc(int m) {
    int mn = 0;
    for (int i = 1; i <= n; i ++) {
        p[i] = p[i-1];
        if(s[i] == '0') p[i] --;
        else if(s[i] == '1') p[i] ++;
        else if(p[i] + zm[i] - zp[i] < m) p[i] ++;
        else p[i] --;
        mn = min(mn, p[i]);
    }
    return m - mn;
}

int main() {
    scanf("%s", s + 1);
    n = strlen(s + 1);
    for(int i = 1; i <= n; i ++) {
        zp[i] = zp[i-1];
        if(s[i] == '1') zp[i] ++;
        else zp[i] --;
        z = max(z, zp[i]);
    }
    zm[n+1] = -1e9;
    for(int i = n; i >= 1; i --) zm[i] = max(zm[i+1], zp[i]);
    printf("%d\n", min(calc(z), calc(z + 1)));
}


Measured memory_bytes: 16532
#include <cstdio>

using namespace std;

int main() {
    int n, c4 = 0, c2 = 1, c1 = 0, a;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a);
        switch (a % 4) {
            case 0: ++c4; break;
            case 2: c2 = 0; break;
            default: ++c1; break;
        }
    }
    printf("%s\n", (c1 - c2 <= c4 ? "Yes" : "No"));
    return 0;
}


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX
#define N 1000001

int a[N]={0},b[N]={0};

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n,ans=0;
	cin>>n;
	vector<int> res(n);
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a[x]++;
		b[x]=1;
		res[i]=x;
	}
	for(int i=1;i<N;i++)
	{
		if(a[i]>1)
			b[i]=-1;
		for(int j=i+i;j<N;j+=i)
		{
			if(a[j]>0&&a[i]>0)
				b[j]=-1;
		}
	}
	for(int i=0;i<n;i++)
		if(b[res[i]]==1)
			ans++;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 20336
a = input()
a = int(a)
n = 0
for i in range(1,10):
    if a % i == 0:
        for j in range(1,10):
            if (a/i) < 10 and (a/i) % j == 0:
                n = n + 1

if n > 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

lli n, ar[N];

bool check(int x) {
	lli sz = ar[x];
	for(int i = 1; i <= n; i++) {
		if(i == x)
			continue;
		if(sz * 2 >= ar[i])
			sz += ar[i];
		else
			return false;
	}
	return true;
}

int bs(int x, int y) {
	if(x == y)
		return x;
	if(check(mid))
		return bs(x, mid);
	else
		return bs(mid + 1, y);
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> ar[i];
	sort(ar + 1, ar + n + 1);

	cout << n - bs(1, n) + 1;
}

Measured memory_bytes: 1024
#pragma GCC optimize("O4")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
//#define MOD (ll)(998244353)
#define MOD (ll)(1e9+7)
#define INF (1e15)
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p){
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
#ifdef LOCAL_TEST
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\input.in","r",stdin);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\output.out","w",stdout);
	freopen("E:\\Jimmy\\2 Coding\\1 C++\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);

	//code...
	int n; cin>>n;
	int ans=0,mn=INF;
	int t;
	For(i,0,n-1){
		cin>>t;
		ans+=t;
		if(t%10!=0) mn=min(mn,t);
	}
	if(ans%10==0) ans-=mn;
	cout<<max(0ll,ans)<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cstdio>
#include<climits>
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#include<string>
#include<queue>
#include<map>
#include<set>
#include<utility>
#include<queue>

using namespace std;
int n,m;
const int MAXN = 101;
int t[MAXN][MAXN];
int c[MAXN][MAXN];

void solve(){
  for(int k = 0;k < m; ++k){
    for(int i = 0;i < m; ++i){
      for(int j = 0;j < m; ++j){
	t[i][j] = min(t[i][j],t[i][k] + t[k][j]);
	c[i][j] = min(c[i][j],c[i][k] + c[k][j]);
      }
    }
  }
}
const int INF = INT_MAX/3;
void init(){
  for(int i = 0;i < m; ++i){
    for(int j = 0;j < m;j++){
      c[i][j] = t[i][j] = INF;
    }
  }
  for(int i = 0;i < m;i++){
    c[i][i] = t[i][i] = 0;
  }
}


int main(){
  ios::sync_with_stdio(false);

  while(cin >> n >> m && n+m > 0){
    init();
    int a,b,icost,itime;
    for(int i = 0;i < n;i++){
      cin >> a >> b >> icost >> itime;
      a--,b--;
      t[a][b] = t[b][a] = itime;
      c[a][b] = c[b][a] = icost;
    }
    solve();
    int k;
    cin >> k;
    for(int i = 0;i < k; ++i){
      int p,q,r;
      cin >> p >> q >> r;
      p--,q--;
      if(r == 1){
	cout << t[p][q] << endl;
      }else{
	cout << c[p][q] << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) int((x).size())
#define OUT(x) cout << (x) << endl
typedef long long ll;
typedef vector<int> V;
typedef vector<vector<int>> VV;
typedef pair<int, int> P;
typedef map<string, int> M;
typedef unordered_map<int, int> HM;
typedef set<int> S;
typedef queue<int> Q;

int main(){
    int n,m; cin>>n>>m;
    vector<S> s(m);
    for(int i=0; i<m; i++){
        int k; cin>>k;
        for(int j=0; j<k; j++){
            int tmp; cin>>tmp;
            tmp--;
            s[i].insert(tmp);
        }
    }
    V p(m);
    for(int i=0; i<m; i++) cin>>p[i];
    int ans=0;
    for(int bit=0; bit<(1<<n); bit++){
        bool flag=true;
        for(int i=0; i<m; i++){
            int cnt=0;
            for(int j=0; j<n; j++){
                if(bit & (1<<j)){
                    if(s[i].find(j) != s[i].end()) cnt++;
                }
            }
            if(cnt%2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }
    OUT(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T,ans;
  cin >>S;
  T=S;
  int K;
  cin >>K;
  sort(T.begin(), T.end());
  auto IT=unique(T.begin(), T.end());
  T.erase(IT, T.end());
  bool finish=false;
  for(int i=0; i<T.size(); i++){
  vector<string> Z;
    for(int j=0; j<S.size(); j++){
//      cout<<"i:"<<i<<" j:"<<j;
//      cout<<"T[i]:"<<T[i]<<" S[j]:"<<S[j]<<endl;
      if(T[i]==S[j]){
        string a="";
        int b=S.size()-j;
//        cout<<"b:"<<b;
        for(int k=0; k<min(K,b); k++){
          a+=S[j+k];
//          cout<<" a:"<<a<<endl;
          Z.push_back(a);
        }
      }
      if(j==S.size()-1){
        sort(Z.begin(), Z.end());
        auto IT=unique(Z.begin(), Z.end());
        Z.erase(IT, Z.end()); 
//        cout<<"K:"<<K<<" Zs:"<<Z.size()<<endl;
        if(Z.size()>=K){
          ans=Z[K-1];
          finish=true;
        }
        else K-=Z.size();        
      }
      if(finish) break;
    }
    if(finish) break;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep2(i, m, n) for(int i=int(m); i<int(n); i++)
#define rep(i, n) rep2(i, 0, n)
#define all(a) a.begin(), a.end()
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
const int INF = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS = 1e-10;
const int MOD = int(1e9)+7;
template<typename T> inline bool chmin(T& a, T b) {if(a>b) {a=b; return true;} return false;}
template<typename T> inline bool chmax(T& a, T b) {if(a<b) {a=b; return true;} return false;}


bool check_1d(V &a, V &b, int m, int s) {
  reverse(all(a));
  reverse(all(b));
  int n = a.size();
  int l = 0, r = m-1;
  rep(i, n) {
    if (b[i] ==  1) l = max(l-1, 0);
    if (b[i] == -1) r = min(r+1, m-1);
    if (a[i] ==  1) r--;
    if (a[i] == -1) l++;
    if (l > r) return false;
  }
  if (s < l || s > r) return false;
  return true;
}


int main() {
  int H, W, N; cin >> H >> W >> N;
  int r, c; cin >> r >> c;
  r--; c--;
  string s, t; cin >> s >> t;

  V a(N), b(N);
  rep(i, N) {
    if (s[i] == 'D') a[i] = 1;
    if (s[i] == 'U') a[i] = -1;
    if (t[i] == 'D') b[i] = 1;
    if (t[i] == 'U') b[i] = -1;
  }
  bool ans1 = check_1d(a, b, H, r);

  a = V(N); b = V(N);
  rep(i, N) {
    if (s[i] == 'R') a[i] = 1;
    if (s[i] == 'L') a[i] = -1;
    if (t[i] == 'R') b[i] = 1;
    if (t[i] == 'L') b[i] = -1;
  }
  bool ans2 = check_1d(a, b, W, c);

  if (ans1 && ans2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
	int n, t;
	cin >> n >> t;

	vector<int> a(n);
	vector<int> b(n);

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

	for (int i = 0; i < n; i++)
	{
		int max = 0;
		for (int j = i+1; j < n; j++)
		{
			if(a[j]-a[i] > max )
			{
				max = a[j] - a[i];
			}
		}
		b[i] = max;
	}

	int s_max = 0;
	for (int i = 0; i < n; i++)
	{
		if(s_max <= b[i])
			s_max = b[i];
	}

	int counter = 0;

	for (int i = n-1; i >= 0; i--)
	{
		if(s_max == b[i])
			counter++;
	}

	cout << counter << endl;

	return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sc(n) scanf("%d",&n)
#define scl(n) scanf("%lld",&n)
#define pr(n) printf("%d",n)
#define prl(n) printf("%lld",n)
#define nl printf("\n")
#define fr(i,n) for(i=0;i<n;i++)
#define rep(i,st,en) for(i=st;i<=en;i++)
#define repv(i,st,en) for(i=en;i>=st;i--)
#define fout cout<<fixed<<setprecision(7)
#define bi(n) __builtin_popcount(n)
#define bil(n) __builtin_popcountll(n)


typedef long long ll;
typedef pair<int,int> pii;
const int N = 100010;
ll mod = 1e9+7;
ll fmod(ll b,ll exp){
    ll res =1;
    while(exp){if(exp&1ll)res=(res*b)%mod;
    b =(b*b)%mod;exp/=2ll;
    }
    return res;
}


vector<int> v;
vector<pii> adj[65];
int pw[100];
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //ios_base::sync_with_stdio(false);cin.tie(NULL);
    int t=1,n,i,j;
    int l;
    cin>>l;
    int tp = l;
    while(tp>0)
    {
        v.pb(tp%3);
        tp/=3;
    }
    reverse(v.begin(),v.end());
    int sz = v.size();
    int cur = 1;
    for(int i=sz+1;i>2;i--)
    {
        int st = i-1,en =i;
        for(int j=0;j<3;j++)adj[st].pb(mp(en,cur*j));
        cur=(cur*3);
    }
    pw[0]=1;
    for(int i=1;i<=20;i++)pw[i]=(pw[i-1]*3);
    cur = 0;
    for(int i=0;i<sz;i++)
    {
        int num = i+2;
        int cur_pw = pw[sz-i-1];
        for(int j=1;j<=v[i];j++)
        {

            adj[1].pb(mp(num,cur+(j-1)*cur_pw));
        }
        cur+= (v[i]*cur_pw);
    }
    int ans = 0;
    fr(i,21)ans+=adj[i].size();

    cout<<sz+1<<" "<<ans<<"\n";
    fr(i,21){
        if(adj[i].size()){
            for(auto ve:adj[i])cout<<i<<" "<<ve.f<<" "<<ve.s<<"\n";
        }

    }
    fr(i,21)adj[i].clear();
    v.clear();







    
    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val k = sc.nextInt()
  val s = sc.nextLong()

  val max = 1_000_000_000L
  val tmp = if (s == max) 1 else s + 1

  val list = mutableListOf<Long>()
  for (i in 0 until n) {
    if (i < k) {
      list.add(s)
    } else {
      list.add(tmp)
    }
  }

  println(list.joinToString(" "))

}

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

int main() {
    int S,h,m,s;
    cin >> S;
    if(S>=3600){
        h=S/3600;
        m=(S-3600*h)/60;
        s=S-(3600*h+60*m);
        cout << h << ":" << m << ":" << s << endl;
    }
    if(60<=S && S<3600){
        m=S/60;
        s=S-60*m;
        cout << 0 << ":" << m << ":" << s << endl;
    }
    if(S<60){
        cout << 0 << ":" << 0 << ":"  << S << endl;
    }
}



Measured memory_bytes: 3084
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        String T = scan.next();
        char[] s = S.toCharArray();
        char[] t = T.toCharArray();
        int[] hs = new int[26];
        int[] ht = new int[26];
        for(char x : s) {
            hs[x - 'a'] += 1;
        }
        Arrays.sort(hs);
        for(char x : t) {
            ht[x - 'a'] += 1;
        }
        Arrays.sort(ht);
        boolean answer = true;
        for (int i = 0; i < 26; i++) {
            if (hs[i] != ht[i]) {
                answer = false;
                break;
            }
        }
        System.out.println(answer ? "Yes" : "No");
    }
}


Measured memory_bytes: 29128
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#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()
#define decp(n) cout<<fixed<<setprecision((int)n)
const int inf=1e9+7;
const ll INF=1e18;

int main(){
    int n;cin>>n;
    int ans=0;bool tmp=false;
    int p;
    rep(i,n){
        cin>>p;
        if(p==i+1){
            if(tmp){
                ans++;
                tmp=false;
            }
            else tmp=true;
        }
        else if(tmp){
            ans++;
            tmp=false;
        }
    }
    if(tmp)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int a[100009];
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  k--;
  int ans=(n-1)/k;
  if((n-1)%k!=0)ans++;
  cout<<ans<<endl;
  return(0);
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long in;
typedef pair<in,in> ii;
#define F first
#define S second
#define sqr(x) (x)*(x)
#define pb(x) push_back(x)
#define sz(x) (in)x.size()
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,x,y) for(in i=x;i<(y);++i)
#define per(i,x,y) for(in i=y;i>=(x);--i)
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
/* start */

int main()
{
	IOS;
	in a,b,c;
	cin >> a >> b >> c;
	if (a+b+c >= 22) cout << "bust\n";
	else cout << "win\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int a[10],b[10],s[9]={0,1,2,3,4,5,6,7,8};
int main()
{
	int n,i,t=0,a1,a2;
	bool f1,f2;
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
		cin>>b[i];
	do
	{
		t++;
		f1=0;
		for(i=1;i<=n;i++)
			if(s[i]!=a[i])
				f1=1;
		if(!f1)
			a1=t;
		f2=0;
		for(i=1;i<=n;i++)
			if(s[i]!=b[i])
				f2=1;
		if(!f2)
			a2=t;
	}while(next_permutation(s+1,s+n+1));
	cout<<abs(a1-a2);
	return 0;
}

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

int main(void){

  int pepl,gtrn;
  int tar[100] = {0};
  int res[100] = {0};
  int buff,wrong;

  cin >> pepl >> gtrn;
  for(int i = 0;i<gtrn;i++) cin >> tar[i];

  for(int i = 0;i<gtrn;i++){
    wrong = 0;
    for(int j = 0;j<pepl;j++){
      cin >> buff;
      buff;
      if(buff == tar[i]) res[j]++;
      else wrong++;
    }
    res[tar[i]-1] += wrong;
  }

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

  return 0;
}

Measured memory_bytes: 3136
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    #divisors.sort()
    return divisors

ans = 2
N = int(input())

div = make_divisors(N)
div_1 = make_divisors(N-1)
ans = 0
for i in div:
    p = N
    if i == 1:
        continue
    while p%i == 0:
        p = p//i
    if p%i == 1:
        ans +=1

print(ans + len(div_1)-1)

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

int main(){
    unsigned long N, Q;
    cin >> N >> Q;
    vector<unsigned long> A(N), AS(N + 2), S(N), X, a;
    for(auto& i : A)cin >> i;
    partial_sum(A.rbegin(), A.rend(), S.begin());
    for(unsigned long i{0}; i < N; ++i)AS[i + 2] = A[i] + AS[i];
    for(unsigned long i{(N + 1) / 2}; i--;)a.push_back(S[i] + AS[N - i * 2 - 1]);
    for(unsigned long i{(N + 1) / 2}; --i;)X.push_back(A[N - i - 1] + A[N - i * 2 - 1]);
    auto beg = begin(X), edn = end(X);
    for(long long i{0}, x; i < Q; ++i){
        cin >> x;
        cout << a[lower_bound(beg, edn, x * 2) - beg] << endl;
    }
    return 0;
}

Measured memory_bytes: 4984
A, B, C = map(int, input().split())
cnt=0
memo=[]
while True:
    tmp = (A,B,C)
    if (A%2==0 and B%2==0 and C%2==0):
        if tmp not in memo:
            memo.append(tmp)
            cnt+=1
            A,B,C = (B+C)//2, (C+A)//2, (A+B)//2
        else:
            cnt=-1
            break
    else:
        break
print(cnt)

Measured memory_bytes: 3064
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, rr := r.nextInt(), r.nextInt()

	if n < 10 {
		rr += 100 * (10 - n)
	}

	fmt.Fprintln(stdout, rr)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  int x3, y3, x4, y4;
  x3 = x2 - (y2 - y1), y3 = y2 + x2 - x1;
  cout << x3 << " " << y3 << " ";
  x4 = x3 - (x2 - x1), y4 = y3 - (y2 - y1);
  cout << x4 << " " << y4 << endl;
  return 0;
}

Measured memory_bytes: 256
N = int(input())
S = [input() for _ in range(N)]
ans = 'Yes'
for i in range(1, N):
    if S[i-1][-1:] != S[i][:1]:
        ans = 'No'
        break
if len(S) != len(set(S)):
    ans = 'No'
print(ans)

Measured memory_bytes: 3060
import numpy as np

primes = np.array([2,3,5,7,11,13,17,19,23,29,
                   31,37,41,43,47,53,59,61,67,71,73,79,83,97
                  ],dtype=np.int)

def pw(N,p):
    ans = 0
    while N > 0:
        N = N // p
        ans = ans + N
    return ans

N = int(input())
powers = np.vectorize(lambda p: pw(N,p))(primes)

n75 = len(np.where(powers >= 74)[0])
n25 = len(np.where(powers >= 24)[0])
n15 = len(np.where(powers >= 14)[0])
n5 = len(np.where(powers >= 4)[0])
n3 = len(np.where(powers >= 2)[0])

ans75 = n75
ans253 = n25 * (n3-1)
ans553 = ((n5*(n5-1))//2) * (n3-2)
ans515 = n15 * (n5-1)

print(ans75 + ans253 + ans553 + ans515)

Measured memory_bytes: 12500
#include <bits/stdc++.h>
#include <string>
using namespace std;
using ll=long long;
using P = pair<int,int>;
using T = tuple<ll,ll,int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int INF = 1001001001;
const ll LINF = 1001001001001001001;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int main()
{
   int n;
   cin >> n;
   vector<T> p(n);
   rep(i,n)
   {
      ll x, y;
      cin >> x >> y;
      p[i] = T(x,y, i);
   }
   vector<pair<int,ll>> E[n];
   vector<pair<ll, P>> memo;
   //xから見ていく
   sort(p.begin(), p.end());
   rep(i,n-1)
   {
      auto now = p[i];
      auto next = p[i+1];
      ll e = get<0>(next) - get<0>(now);
      E[get<2>(now)].push_back(make_pair(get<2>(next),e));
      E[get<2>(next)].push_back(make_pair(get<2>(now),e));
      memo.push_back(make_pair(e,P(get<2>(now), get<2>(next))));
   }

   //xとyを入れ替える
   rep(i,n) 
   {
      ll x = get<0>(p[i]);
      ll y = get<1>(p[i]);
      p[i] = T(y,x,get<2>(p[i]));
   }

   sort(p.begin(), p.end());
   rep(i,n-1)
   {
      auto now = p[i];
      auto next = p[i+1];
      ll e = get<0>(next) - get<0>(now);
      E[get<2>(now)].push_back(make_pair(get<2>(next),e));
      E[get<2>(next)].push_back(make_pair(get<2>(now),e));
      memo.push_back(make_pair(e,P(get<2>(now), get<2>(next))));
   }
   UnionFind uf(n);
   //全ての辺を含むグラフE完成行こう　クラスカル法で解く
   sort(memo.begin(), memo.end());
   //小さい順に
   ll ans = 0;
   rep(i,memo.size())
   {
      int point1 = memo[i].second.first;
      int point2 = memo[i].second.second;
      if(uf.same(point1, point2)) continue;
      uf.unite(point1, point2);
      ll target = INF;
      for(auto tmp : E[point1]) if(tmp.first == point2) target = min(target,tmp.second);
      if(target != INF) ans += target;
   }

   cout << ans << endl;
}

Measured memory_bytes: 18412
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
#include <functional>

using namespace std;

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

int N, W;
int v[105],w[105],dp[105][10005];

int sagasitehappy(int i, int j)
{
	if (dp[i][j] >= 0) return dp[i][j];
	int res;
	if (i == N) res = 0;
	else if (w[i] > j) res = sagasitehappy(i + 1, j);
	else
	{
		res = max(sagasitehappy(i + 1, j), sagasitehappy(i + 1, j - w[i]) + v[i]);
	}
	dp[i][j] = res;
	return res;
}

int main()
{
	cin >> N >> W;
	REP(i, N) cin >> v[i] >> w[i];
	REP(i, 105)REP(j, 10005) dp[i][j] = -1;
	cout << sagasitehappy(0, W) << endl;
	return 0;

}

Measured memory_bytes: 5268